Skip to content

Commit 9c1e75d

Browse files
authored
Merge pull request #158 from rsksmart/feature/FLY-2047
feat: add recommended operation feature
2 parents a9373aa + c1f956d commit 9c1e75d

20 files changed

Lines changed: 761 additions & 27 deletions

integration-test/test/pegin.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { assertTruthy, ethers, BlockchainReadOnlyConnection } from '@rsksmart/br
44
import { integrationTestConfig } from '../config'
55
import { fakeTokenResolver, getUtxosFromMempoolSpace } from './common/utils'
66
import { Transaction, payments, networks } from 'bitcoinjs-lib'
7-
import { TEST_CONTRACT_ABI } from './common/constants'
7+
import { EXTENDED_TIMEOUT, TEST_CONTRACT_ABI } from './common/constants'
88

99
describe('Flyover pegin process should', () => {
1010
let flyover: Flyover
@@ -190,6 +190,20 @@ describe('Flyover pegin process should', () => {
190190
expect(result).toBe('')
191191
})
192192

193+
test('get recommended value for quote total', async () => {
194+
const result = await flyover.estimateRecommendedPegin(
195+
FlyoverUtils.getQuoteTotal(quote),
196+
{
197+
data: quote.quote.data,
198+
destinationAddress: quote.quote.contractAddr
199+
}
200+
);
201+
expect(result.estimatedCallFee.toString()).toEqual(quote.quote.callFee.toString());
202+
expect(result.estimatedGasFee.toString()).toEqual(quote.quote.gasFee.toString());
203+
expect(result.estimatedProductFee.toString()).toEqual(quote.quote.productFeeAmount.toString());
204+
expect(result.recommendedQuoteValue.toString()).toEqual(quote.quote.value.toString());
205+
}, EXTENDED_TIMEOUT)
206+
193207
test('get a smart contract interaction quote', async () => {
194208
const smartContractData = new ethers.utils.Interface(TEST_CONTRACT_ABI)
195209
.encodeFunctionData('save', [integrationTestConfig.rskAddress])

integration-test/test/pegout.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ describe('Flyover pegout process should', () => {
168168
expect(creationData.feeRate).not.toBeUndefined()
169169
}, EXTENDED_TIMEOUT)
170170

171+
test('get recommended value for quote total', async () => {
172+
const result = await flyover.estimateRecommendedPegout(
173+
FlyoverUtils.getQuoteTotal(selectedQuote),
174+
{ destinationAddressType: 'p2pkh' }
175+
);
176+
expect(result.estimatedCallFee.toString()).toEqual(selectedQuote.quote.callFee.toString());
177+
expect(result.estimatedGasFee.toString()).toEqual(selectedQuote.quote.gasFee.toString());
178+
expect(result.estimatedProductFee.toString()).toEqual(selectedQuote.quote.productFeeAmount.toString());
179+
expect(result.recommendedQuoteValue.toString()).toEqual(selectedQuote.quote.value.toString());
180+
}, EXTENDED_TIMEOUT)
181+
171182
test.skip('[DISABLED: until we have a way to force a quote expiration] execute refungPegout to get back amount', async () => {
172183
const txHash = await flyover.refundPegout(selectedQuote)
173184
expect([null, undefined, '']).not.toContain(txHash)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rsksmart/flyover-sdk",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "SDK that simplifies interaction between Flyover's Liquidity Provider Server and client applications",
55
"main": "lib/index.js",
66
"private": false,

src/api/bindings/PeginRoute.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
PeginConfigurationRequest,
2121
PeginQuoteRequest,
2222
PeginQuoteStatusDTO,
23+
RecommendedOperationDTO,
2324
} from "./data-contracts";
2425

2526
export namespace Pegin {
@@ -119,6 +120,38 @@ export namespace Pegin {
119120

120121
export const PostGetQuotePath = "/pegin/getQuote";
121122

123+
/**
124+
* @description Returns the recommended quote value to create a quote whose total payment is the input amount
125+
* @name RecommendedList
126+
* @summary Recommended pegin
127+
* @request GET:/pegin/recommended
128+
*/
129+
export namespace RecommendedList {
130+
export type RequestParams = {};
131+
export type RequestQuery = {
132+
/**
133+
* Amount in wei expected to use as total payment for the quote
134+
* @format string
135+
*/
136+
amount: string;
137+
/**
138+
* Destination address for the pegin. Is optional, but if provided, it will increase the estimation accuracy.
139+
* @format string
140+
*/
141+
destination_address?: string;
142+
/**
143+
* Hex-encoded data payload to include in the pegin transaction. Is optional, but if provided, it will increase the estimation accuracy.
144+
* @format string
145+
*/
146+
data?: string;
147+
};
148+
export type RequestBody = never;
149+
export type RequestHeaders = {};
150+
export type ResponseBody = RecommendedOperationDTO;
151+
}
152+
153+
export const RecommendedListPath = "/pegin/recommended";
154+
122155
/**
123156
* @description Returns the status of an accepted pegin quote
124157
* @name StatusList

src/api/bindings/PegoutRoute.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
PegoutConfigurationRequest,
2121
PegoutQuoteRequest,
2222
PegoutQuoteStatusDTO,
23+
RecommendedOperationDTO,
2324
} from "./data-contracts";
2425

2526
export namespace Pegout {
@@ -119,6 +120,33 @@ export namespace Pegout {
119120

120121
export const PostGetQuotesPath = "/pegout/getQuotes";
121122

123+
/**
124+
* @description Returns the recommended quote value to create a quote whose total payment is the input amount
125+
* @name RecommendedList
126+
* @summary Recommended pegout
127+
* @request GET:/pegout/recommended
128+
*/
129+
export namespace RecommendedList {
130+
export type RequestParams = {};
131+
export type RequestQuery = {
132+
/**
133+
* Amount in wei expected to use as total payment for the quote
134+
* @format string
135+
*/
136+
amount: string;
137+
/**
138+
* Destination address type for the pegout. Is optional, but if provided, it will increase the estimation accuracy. Must be one of: p2pkh, p2sh, p2wpkh, p2wsh, p2tr
139+
* @format string
140+
*/
141+
destination_type?: string;
142+
};
143+
export type RequestBody = never;
144+
export type RequestHeaders = {};
145+
export type ResponseBody = RecommendedOperationDTO;
146+
}
147+
148+
export const RecommendedListPath = "/pegout/recommended";
149+
122150
/**
123151
* @description Returns the status of an accepted pegout quote
124152
* @name StatusList

src/api/bindings/ReportsRoute.ts

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/* eslint-disable */
2+
/* tslint:disable */
3+
/*
4+
* ---------------------------------------------------------------
5+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
6+
* ## ##
7+
* ## AUTHOR: acacode ##
8+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
9+
* ---------------------------------------------------------------
10+
*/
11+
12+
import { GetTransactionsResponse, SummaryResultDTO } from "./data-contracts";
13+
14+
export namespace Reports {
15+
/**
16+
* @description Get the asset information for the LPS.
17+
* @name AssetsList
18+
* @summary Get asset Reports
19+
* @request GET:/reports/assets
20+
*/
21+
export namespace AssetsList {
22+
export type RequestParams = {};
23+
export type RequestQuery = {};
24+
export type RequestBody = never;
25+
export type RequestHeaders = {};
26+
export type ResponseBody = void;
27+
}
28+
29+
export const AssetsListPath = "/reports/assets";
30+
31+
/**
32+
* @description Get the last pegins on the API. Included in the management API.
33+
* @name PeginList
34+
* @summary Get Pegin Reports
35+
* @request GET:/reports/pegin
36+
*/
37+
export namespace PeginList {
38+
export type RequestParams = {};
39+
export type RequestQuery = {
40+
/**
41+
* Start date for the report. Supports YYYY-MM-DD (expands to full day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
42+
* @format string
43+
*/
44+
startDate: string;
45+
/**
46+
* End date for the report. Supports YYYY-MM-DD (expands to end of day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
47+
* @format string
48+
*/
49+
endDate: string;
50+
};
51+
export type RequestBody = never;
52+
export type RequestHeaders = {};
53+
export type ResponseBody = void;
54+
}
55+
56+
export const PeginListPath = "/reports/pegin";
57+
58+
/**
59+
* @description Get the last pegouts on the API. Included in the management API.
60+
* @name PegoutList
61+
* @summary Get Pegout Reports
62+
* @request GET:/reports/pegout
63+
*/
64+
export namespace PegoutList {
65+
export type RequestParams = {};
66+
export type RequestQuery = {
67+
/**
68+
* Start date for the report. Supports YYYY-MM-DD (expands to full day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
69+
* @format string
70+
*/
71+
startDate: string;
72+
/**
73+
* End date for the report. Supports YYYY-MM-DD (expands to end of day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
74+
* @format string
75+
*/
76+
endDate: string;
77+
};
78+
export type RequestBody = never;
79+
export type RequestHeaders = {};
80+
export type ResponseBody = void;
81+
}
82+
83+
export const PegoutListPath = "/reports/pegout";
84+
85+
/**
86+
* @description Get the revenue for the specified period.
87+
* @name RevenueList
88+
* @summary Get revenue Reports
89+
* @request GET:/reports/revenue
90+
*/
91+
export namespace RevenueList {
92+
export type RequestParams = {};
93+
export type RequestQuery = {
94+
/**
95+
* Start date for the report. Supports YYYY-MM-DD (expands to full day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
96+
* @format string
97+
*/
98+
startDate: string;
99+
/**
100+
* End date for the report. Supports YYYY-MM-DD (expands to end of day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
101+
* @format string
102+
*/
103+
endDate: string;
104+
};
105+
export type RequestBody = never;
106+
export type RequestHeaders = {};
107+
export type ResponseBody = void;
108+
}
109+
110+
export const RevenueListPath = "/reports/revenue";
111+
112+
/**
113+
* @description Returns financial data for a given period
114+
* @name SummariesList
115+
* @summary Summaries
116+
* @request GET:/reports/summaries
117+
*/
118+
export namespace SummariesList {
119+
export type RequestParams = {};
120+
export type RequestQuery = {
121+
/**
122+
* Start date in YYYY-MM-DD format
123+
* @format string
124+
*/
125+
startDate: string;
126+
/**
127+
* End date in YYYY-MM-DD format
128+
* @format string
129+
*/
130+
endDate: string;
131+
};
132+
export type RequestBody = never;
133+
export type RequestHeaders = {};
134+
export type ResponseBody = SummaryResultDTO;
135+
}
136+
137+
export const SummariesListPath = "/reports/summaries";
138+
139+
/**
140+
* @description Get a paginated list of individual transactions of a specific type processed by the liquidity provider within a specified time period
141+
* @name TransactionsList
142+
* @summary Get Transaction Reports
143+
* @request GET:/reports/transactions
144+
*/
145+
export namespace TransactionsList {
146+
export type RequestParams = {};
147+
export type RequestQuery = {
148+
/**
149+
* Transaction type filter: 'pegin' or 'pegout'
150+
* @format string
151+
*/
152+
type: string;
153+
/**
154+
* Start date for the report. Supports YYYY-MM-DD (expands to full day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
155+
* @format string
156+
*/
157+
startDate?: string;
158+
/**
159+
* End date for the report. Supports YYYY-MM-DD (expands to end of day) or ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
160+
* @format string
161+
*/
162+
endDate?: string;
163+
/**
164+
* Page number to retrieve (1-indexed, default: 1)
165+
* @format int64
166+
*/
167+
page?: number;
168+
/**
169+
* Number of transactions per page (max: 100, default: 10)
170+
* @format int64
171+
*/
172+
perPage?: number;
173+
};
174+
export type RequestBody = never;
175+
export type RequestHeaders = {};
176+
export type ResponseBody = GetTransactionsResponse;
177+
}
178+
179+
export const TransactionsListPath = "/reports/transactions";
180+
}

0 commit comments

Comments
 (0)