Skip to content

Commit 8f5f8cf

Browse files
committed
Streaming and missing parameters for QuoteSwap type
1 parent e3544ed commit 8f5f8cf

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

packages/xchain-mayachain-amm/src/mayachain-amm.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export class MayachainAMM {
7373
affiliateAddress,
7474
affiliateBps,
7575
toleranceBps,
76+
streamingInterval,
77+
streamingQuantity,
7678
}: QuoteSwapParams): Promise<QuoteSwap> {
7779
const errors = await this.validateSwap({
7880
fromAsset,
@@ -82,6 +84,8 @@ export class MayachainAMM {
8284
destinationAddress,
8385
affiliateAddress,
8486
affiliateBps,
87+
streamingInterval,
88+
streamingQuantity,
8589
})
8690

8791
if (errors.length > 0) {
@@ -94,6 +98,8 @@ export class MayachainAMM {
9498
asset: destinationAsset,
9599
affiliateFee: new CryptoAmount(baseAmount(0), destinationAsset),
96100
outboundFee: new CryptoAmount(baseAmount(0), destinationAsset),
101+
liquidityFee: new CryptoAmount(baseAmount(0), destinationAsset),
102+
totalFee: new CryptoAmount(baseAmount(0), destinationAsset),
97103
},
98104
outboundDelayBlocks: 0,
99105
outboundDelaySeconds: 0,
@@ -103,6 +109,7 @@ export class MayachainAMM {
103109
errors,
104110
slipBasisPoints: 0,
105111
totalSwapSeconds: 0,
112+
expiry: 0,
106113
warning: '',
107114
}
108115
}
@@ -116,6 +123,8 @@ export class MayachainAMM {
116123
affiliateAddress,
117124
affiliateBps,
118125
toleranceBps,
126+
streamingInterval,
127+
streamingQuantity,
119128
})
120129
}
121130

@@ -133,6 +142,8 @@ export class MayachainAMM {
133142
amount,
134143
affiliateAddress,
135144
affiliateBps,
145+
streamingInterval,
146+
streamingQuantity,
136147
}: QuoteSwapParams): Promise<string[]> {
137148
const errors: string[] = []
138149

@@ -168,6 +179,14 @@ export class MayachainAMM {
168179
errors.push(...approveErrors)
169180
}
170181

182+
if (streamingQuantity && streamingQuantity < 0) {
183+
errors.push('streaming quantity can not be lower than 0')
184+
}
185+
186+
if (streamingInterval && streamingInterval < 0) {
187+
errors.push('streaming interval can not be lower than 0')
188+
}
189+
171190
return errors
172191
}
173192

packages/xchain-mayachain-query/src/mayachain-query.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,27 @@ export class MayachainQuery {
128128
baseAmount(0, toAssetString === assetToString(CacaoAsset) ? 10 : 8),
129129
destinationAsset,
130130
),
131+
liquidityFee: new CryptoAmount(
132+
baseAmount(0, toAssetString === assetToString(CacaoAsset) ? 10 : 8),
133+
destinationAsset,
134+
),
135+
totalFee: new CryptoAmount(
136+
baseAmount(0, toAssetString === assetToString(CacaoAsset) ? 10 : 8),
137+
destinationAsset,
138+
),
131139
},
132140
outboundDelayBlocks: 0,
133141
outboundDelaySeconds: 0,
134142
inboundConfirmationSeconds: 0,
135143
inboundConfirmationBlocks: 0,
136144
canSwap: false,
137145
errors: [`Mayanode request quote: ${response.error}`],
146+
expiry: 0,
138147
slipBasisPoints: 0,
139148
totalSwapSeconds: 0,
149+
streamingSwapSeconds: 0,
150+
streamingSwapBlocks: 0,
151+
maxStreamingQuantity: 0,
140152
warning: '',
141153
}
142154
}
@@ -159,13 +171,26 @@ export class MayachainQuery {
159171
asset: feeAsset,
160172
affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate, isFeeAssetCacao ? 10 : 8), feeAsset),
161173
outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound, isFeeAssetCacao ? 10 : 8), feeAsset),
174+
liquidityFee: new CryptoAmount(baseAmount(swapQuote.fees.liquidity, isFeeAssetCacao ? 10 : 8), feeAsset),
175+
totalFee: new CryptoAmount(baseAmount(swapQuote.fees.total, isFeeAssetCacao ? 10 : 8), feeAsset),
162176
},
177+
expiry: swapQuote.expiry,
178+
recommendedMinAmountIn: new CryptoAmount(
179+
baseAmount(swapQuote.recommended_min_amount_in || '0', eqAsset(fromAsset, CacaoAsset) ? 10 : 8),
180+
fromAsset,
181+
),
182+
router: swapQuote.router,
183+
recommendedGasRate: swapQuote.recommended_gas_rate,
184+
gasRateUnits: swapQuote.gas_rate_units,
163185
slipBasisPoints: swapQuote.fees.slippage_bps,
164186
outboundDelayBlocks: swapQuote.outbound_delay_blocks,
165187
outboundDelaySeconds: swapQuote.outbound_delay_seconds,
166188
inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
167189
inboundConfirmationBlocks: swapQuote.inbound_confirmation_blocks,
168-
totalSwapSeconds: (swapQuote.inbound_confirmation_seconds || 0) + swapQuote.outbound_delay_seconds,
190+
maxStreamingQuantity: swapQuote.max_streaming_quantity,
191+
streamingSwapBlocks: swapQuote.streaming_swap_blocks,
192+
streamingSwapSeconds: swapQuote.streaming_swap_seconds,
193+
totalSwapSeconds: swapQuote.total_swap_seconds || 0,
169194
canSwap: !(!swapQuote.memo || errors.length > 0),
170195
errors,
171196
warning: '',

packages/xchain-mayachain-query/src/types.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export type Fees = {
99
asset: Asset // The asset for which fees are calculated
1010
affiliateFee: CryptoAmount // The affiliate fee amount
1111
outboundFee: CryptoAmount // The outbound fee amount
12+
/**
13+
* The liquidity fees paid to pools
14+
*/
15+
liquidityFee: CryptoAmount
16+
/**
17+
* Total fees
18+
*/
19+
totalFee: CryptoAmount
1220
}
1321

1422
/**
@@ -26,6 +34,38 @@ export type QuoteSwap = {
2634
outboundDelayBlocks: number // The outbound delay time in blocks
2735
totalSwapSeconds: number // The total time for the swap operation
2836
slipBasisPoints: number // The slip basis points for the swap
37+
/**
38+
* The EVM chain router contract address
39+
*/
40+
router?: string
41+
/**
42+
* Expiration timestamp in unix seconds
43+
*/
44+
expiry: number
45+
/**
46+
* The recommended minimum inbound amount for this transaction type & inbound asset. Sending less than this amount could result in failed refunds.
47+
*/
48+
recommendedMinAmountIn?: CryptoAmount
49+
/**
50+
* The recommended gas rate to use for the inbound to ensure timely confirmation
51+
*/
52+
recommendedGasRate?: string
53+
/**
54+
* The units of the recommended gas rate
55+
*/
56+
gasRateUnits?: string
57+
/**
58+
* The maximum amount of trades a streaming swap can do for a trade
59+
*/
60+
streamingSwapSeconds?: number
61+
/**
62+
* The number of blocks the streaming swap will execute over
63+
*/
64+
streamingSwapBlocks?: number
65+
/**
66+
* Approx the number of seconds the streaming swap will execute over
67+
*/
68+
maxStreamingQuantity?: number
2969
canSwap: boolean // Indicates whether the swap can be performed
3070
errors: string[] // Any errors encountered during the swap operation
3171
warning: string // Any warning messages associated with the swap

0 commit comments

Comments
 (0)