Skip to content

Commit 8a37092

Browse files
committed
updating chainflip to v1.7.0
1 parent 2ed6c98 commit 8a37092

File tree

7 files changed

+368
-181
lines changed

7 files changed

+368
-181
lines changed

packages/xchain-aggregator/__mocks__/@chainflip/sdk/swap.ts

+144-111
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
DepositAddressRequest,
77
DepositAddressResponse,
88
QuoteRequest,
9-
QuoteResponse,
9+
QuoteResponseV2,
1010
} from '@chainflip/sdk/swap'
1111

1212
class SwapSDK {
@@ -159,7 +159,7 @@ class SwapSDK {
159159
throw Error('Can not get deposit address')
160160
}
161161

162-
async getQuote({ srcAsset, srcChain, destAsset, destChain, amount }: QuoteRequest): Promise<QuoteResponse> {
162+
async getQuote({ srcAsset, srcChain, destAsset, destChain, amount }: QuoteRequest): Promise<QuoteResponseV2> {
163163
if (
164164
srcChain === 'Ethereum' &&
165165
srcAsset === 'ETH' &&
@@ -168,52 +168,59 @@ class SwapSDK {
168168
amount === '10000000000000000'
169169
) {
170170
return {
171-
srcAsset,
171+
amount,
172172
srcChain,
173-
destAsset,
173+
srcAsset,
174174
destChain,
175-
amount,
176-
quote: {
177-
type: 'REGULAR',
178-
intermediateAmount: '36115119',
179-
egressAmount: '51193',
180-
includedFees: [
181-
{
182-
type: 'INGRESS',
183-
chain: 'Ethereum',
184-
asset: 'ETH',
185-
amount: '689176257450000',
186-
},
187-
{
188-
type: 'NETWORK',
189-
chain: 'Ethereum',
190-
asset: 'USDC',
191-
amount: '36115',
192-
},
193-
{
194-
type: 'NETWORK',
195-
chain: 'Ethereum',
196-
asset: 'ETH',
197-
amount: '4655411871275',
198-
},
199-
{
200-
type: 'NETWORK',
201-
chain: 'Ethereum',
202-
asset: 'USDC',
203-
amount: '18057',
204-
},
205-
{
206-
type: 'EGRESS',
207-
chain: 'Bitcoin',
208-
asset: 'BTC',
209-
amount: '1599',
210-
},
211-
],
212-
lowLiquidityWarning: false,
213-
estimatedDurationSeconds: 702,
214-
poolInfo: [],
215-
estimatedPrice: '2300',
216-
},
175+
destAsset,
176+
quotes: [
177+
{
178+
srcAsset: { chain: 'Ethereum', asset: 'ETH' },
179+
destAsset: { chain: 'Bitcoin', asset: 'BTC' },
180+
depositAmount: '1000000',
181+
type: 'REGULAR',
182+
intermediateAmount: '36115119',
183+
estimatedDurationsSeconds: { deposit: 1800, swap: 264, egress: 12 },
184+
egressAmount: '51193',
185+
includedFees: [
186+
{
187+
type: 'INGRESS',
188+
chain: 'Ethereum',
189+
asset: 'ETH',
190+
amount: '689176257450000',
191+
},
192+
{
193+
type: 'NETWORK',
194+
chain: 'Ethereum',
195+
asset: 'USDC',
196+
amount: '36115',
197+
},
198+
{
199+
type: 'NETWORK',
200+
chain: 'Ethereum',
201+
asset: 'ETH',
202+
amount: '4655411871275',
203+
},
204+
{
205+
type: 'NETWORK',
206+
chain: 'Ethereum',
207+
asset: 'USDC',
208+
amount: '18057',
209+
},
210+
{
211+
type: 'EGRESS',
212+
chain: 'Bitcoin',
213+
asset: 'BTC',
214+
amount: '1599',
215+
},
216+
],
217+
lowLiquidityWarning: false,
218+
estimatedDurationSeconds: 702,
219+
recommendedSlippageTolerancePercent: 1,
220+
poolInfo: [],
221+
estimatedPrice: '2300',
222+
},
223+
],
217224
}
218225
}
219226

@@ -225,40 +232,59 @@ class SwapSDK {
225232
amount === '20000000'
226233
) {
227234
return {
228-
srcAsset,
235+
amount,
229236
srcChain,
230-
destAsset,
237+
srcAsset,
231238
destChain,
232-
amount,
233-
quote: {
234-
type: 'REGULAR',
235-
intermediateAmount: '13560635',
236-
egressAmount: '2063188201000691',
237-
includedFees: [
238-
{
239-
type: 'INGRESS',
240-
chain: 'Ethereum',
241-
asset: 'USDT',
242-
amount: '6433935',
243-
},
244-
{
245-
type: 'NETWORK',
246-
chain: 'Ethereum',
247-
asset: 'USDC',
248-
amount: '13560',
249-
},
250-
{
251-
type: 'EGRESS',
252-
chain: 'Ethereum',
253-
asset: 'ETH',
254-
amount: '1447621978320000',
255-
},
256-
],
257-
lowLiquidityWarning: false,
258-
estimatedDurationSeconds: 114,
259-
poolInfo: [],
260-
estimatedPrice: '1',
261-
},
239+
destAsset,
240+
quotes: [
241+
{
242+
srcAsset: { chain: 'Ethereum', asset: 'USDT' },
243+
destAsset: { chain: 'Ethereum', asset: 'ETH' },
244+
depositAmount: '2000000',
245+
type: 'REGULAR',
246+
intermediateAmount: '36115119',
247+
estimatedDurationsSeconds: { deposit: 1800, swap: 264, egress: 12 },
248+
egressAmount: '51193',
249+
includedFees: [
250+
{
251+
type: 'INGRESS',
252+
chain: 'Ethereum',
253+
asset: 'ETH',
254+
amount: '689176257450000',
255+
},
256+
{
257+
type: 'NETWORK',
258+
chain: 'Ethereum',
259+
asset: 'USDC',
260+
amount: '36115',
261+
},
262+
{
263+
type: 'NETWORK',
264+
chain: 'Ethereum',
265+
asset: 'ETH',
266+
amount: '4655411871275',
267+
},
268+
{
269+
type: 'NETWORK',
270+
chain: 'Ethereum',
271+
asset: 'USDC',
272+
amount: '18057',
273+
},
274+
{
275+
type: 'EGRESS',
276+
chain: 'Ethereum',
277+
asset: 'ETH',
278+
amount: '1599',
279+
},
280+
],
281+
lowLiquidityWarning: false,
282+
estimatedDurationSeconds: 702,
283+
recommendedSlippageTolerancePercent: 1,
284+
poolInfo: [],
285+
estimatedPrice: '2300',
286+
},
287+
],
262288
}
263289
}
264290

@@ -270,44 +296,51 @@ class SwapSDK {
270296
amount === '10000000000000000'
271297
) {
272298
return {
273-
srcAsset,
299+
amount,
274300
srcChain,
275-
destAsset,
301+
srcAsset,
276302
destChain,
277-
amount,
278-
quote: {
279-
type: 'REGULAR',
280-
intermediateAmount: '33919877',
281-
egressAmount: '24884030',
282-
includedFees: [
283-
{
284-
type: 'INGRESS',
285-
chain: 'Ethereum',
286-
asset: 'ETH',
287-
amount: '1284811335100000',
288-
},
289-
{
290-
type: 'NETWORK',
291-
chain: 'Ethereum',
292-
asset: 'USDC',
293-
amount: '33919',
294-
},
295-
{
296-
type: 'EGRESS',
297-
chain: 'Ethereum',
298-
asset: 'USDT',
299-
amount: '8988369',
300-
},
301-
],
302-
lowLiquidityWarning: false,
303-
estimatedDurationSeconds: 114,
304-
poolInfo: [],
305-
estimatedPrice: '2300',
306-
},
303+
destAsset,
304+
quotes: [
305+
{
306+
srcAsset: { chain: 'Ethereum', asset: 'ETH' },
307+
destAsset: { chain: 'Ethereum', asset: 'USDT' },
308+
depositAmount: '1000000',
309+
type: 'REGULAR',
310+
intermediateAmount: '33919877',
311+
estimatedDurationsSeconds: { deposit: 1800, swap: 114, egress: 12 },
312+
egressAmount: '24884030',
313+
includedFees: [
314+
{
315+
type: 'INGRESS',
316+
chain: 'Ethereum',
317+
asset: 'ETH',
318+
amount: '1284811335100000',
319+
},
320+
{
321+
type: 'NETWORK',
322+
chain: 'Ethereum',
323+
asset: 'USDC',
324+
amount: '33919',
325+
},
326+
{
327+
type: 'EGRESS',
328+
chain: 'Ethereum',
329+
asset: 'USDT',
330+
amount: '8988369',
331+
},
332+
],
333+
lowLiquidityWarning: false,
334+
estimatedDurationSeconds: 114,
335+
recommendedSlippageTolerancePercent: 1,
336+
poolInfo: [],
337+
estimatedPrice: '2300',
338+
},
339+
],
307340
}
308341
}
342+
309343
throw Error('Quote not mocked')
310344
}
311345
}
312-
313346
export { SwapSDK, Asset, AssetData, Chains }

packages/xchain-aggregator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"directory": "release/package"
3030
},
3131
"dependencies": {
32-
"@chainflip/sdk": "1.6.0",
32+
"@chainflip/sdk": "1.7.0",
3333
"@xchainjs/xchain-client": "workspace:*",
3434
"@xchainjs/xchain-mayachain": "workspace:*",
3535
"@xchainjs/xchain-mayachain-amm": "workspace:*",

packages/xchain-aggregator/src/protocols/chainflip/chainflipProtocol.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -86,45 +86,47 @@ export class ChainflipProtocol implements IProtocol {
8686

8787
try {
8888
let toAddress = ''
89-
if (params.destinationAddress) {
90-
const { depositAddress } = await this.sdk.requestDepositAddress({
91-
srcChain: srcAssetData.chain,
92-
srcAsset: srcAssetData.asset,
93-
destChain: destAssetData.chain,
94-
destAsset: destAssetData.asset,
95-
destAddress: params.destinationAddress,
96-
amount: params.amount.baseAmount.amount().toString(),
97-
})
98-
99-
toAddress = depositAddress
100-
}
101-
102-
const { quote } = await this.sdk.getQuote({
89+
const { quotes } = await this.sdk.getQuoteV2({
10390
srcChain: srcAssetData.chain,
10491
srcAsset: srcAssetData.asset,
10592
destChain: destAssetData.chain,
10693
destAsset: destAssetData.asset,
10794
amount: params.amount.baseAmount.amount().toString(),
10895
})
96+
const quote = quotes.find((quote) => quote.type === 'DCA')
97+
if (params.destinationAddress && quote) {
98+
const { depositAddress } = await this.sdk.requestDepositAddressV2({
99+
quote: quote,
100+
destAddress: params.destinationAddress,
101+
fillOrKillParams: {
102+
slippageTolerancePercent: quote.recommendedSlippageTolerancePercent,
103+
refundAddress: params.fromAddress ? params.fromAddress : '',
104+
retryDurationBlocks: 100,
105+
},
106+
})
107+
108+
toAddress = depositAddress
109+
}
109110

110-
const outboundFee = quote.includedFees.find((fee) => fee.type === 'EGRESS')
111-
const brokerFee = quote.includedFees.find((fee) => fee.type === 'BROKER')
111+
const outboundFee = quote?.includedFees.find((fee) => fee.type === 'EGRESS')
112+
const brokerFee = quote?.includedFees.find((fee) => fee.type === 'BROKER')
112113

113114
return {
114115
protocol: this.name,
115116
toAddress,
116117
memo: '',
117118
expectedAmount: new CryptoAmount(
118-
baseAmount(quote.egressAmount, destAssetData.decimals),
119+
baseAmount(quote?.egressAmount, destAssetData.decimals),
119120
params.destinationAsset,
120121
),
121122
dustThreshold: new CryptoAmount(
122123
baseAmount(srcAssetData.minimumSwapAmount, srcAssetData.decimals),
123124
params.fromAsset,
124125
),
125-
totalSwapSeconds: quote.estimatedDurationSeconds,
126+
totalSwapSeconds: quote?.estimatedDurationSeconds ? quote.estimatedDurationSeconds : 0,
127+
maxStreamingQuantity: undefined,
126128
canSwap: toAddress !== '',
127-
warning: quote.lowLiquidityWarning
129+
warning: quote?.lowLiquidityWarning
128130
? 'Do not cache this response. Do not send funds after the expiry. The difference in the chainflip swap rate (excluding fees) is lower than the global index rate of the swap by more than a certain threshold (currently set to 5%)'
129131
: 'Do not cache this response. Do not send funds after the expiry.',
130132
errors: [],
@@ -152,6 +154,7 @@ export class ChainflipProtocol implements IProtocol {
152154
params.fromAsset,
153155
),
154156
totalSwapSeconds: 0,
157+
maxStreamingQuantity: 0,
155158
canSwap: false,
156159
warning: '',
157160
errors: [e instanceof Error ? e.message : 'Unknown error'],

packages/xchain-aggregator/src/protocols/mayachain/mayachainProtocol.ts

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class MayachainProtocol implements IProtocol {
107107
fees: estimatedSwap.fees,
108108
totalSwapSeconds: estimatedSwap.inboundConfirmationSeconds || 0 + estimatedSwap.outboundDelaySeconds,
109109
slipBasisPoints: estimatedSwap.slipBasisPoints,
110+
maxStreamingQuantity: estimatedSwap.maxStreamingQuantity,
110111
canSwap: estimatedSwap.canSwap,
111112
errors: estimatedSwap.errors,
112113
warning: estimatedSwap.warning,

packages/xchain-aggregator/src/protocols/thorchain/thorchainProtocol.ts

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class ThorchainProtocol implements IProtocol {
104104
totalSwapSeconds:
105105
estimatedSwap.txEstimate.inboundConfirmationSeconds || 0 + estimatedSwap.txEstimate.outboundDelaySeconds,
106106
slipBasisPoints: estimatedSwap.txEstimate.slipBasisPoints,
107+
maxStreamingQuantity: estimatedSwap.txEstimate.maxStreamingQuantity,
107108
canSwap: estimatedSwap.txEstimate.canSwap,
108109
errors: estimatedSwap.txEstimate.errors,
109110
warning: estimatedSwap.txEstimate.warning,

0 commit comments

Comments
 (0)