@xchainjs/xchain-aggregator 2.0.29 → 2.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +41 -15
- package/lib/index.js +41 -15
- package/lib/protocols/chainflip/chainflipProtocol.d.ts +1 -1
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
package/lib/index.esm.js
CHANGED
|
@@ -141,11 +141,25 @@ class ChainflipProtocol {
|
|
|
141
141
|
amount: params.amount.baseAmount.amount().toString(),
|
|
142
142
|
affiliateBrokers: this.affiliateBrokers,
|
|
143
143
|
});
|
|
144
|
-
// Find
|
|
145
|
-
|
|
144
|
+
// Find quote based on user preference for boost
|
|
145
|
+
let selectedQuote;
|
|
146
|
+
if (params.enableBoost) {
|
|
147
|
+
// User wants boost - prioritize DCA with boost > REGULAR with boost > DCA > REGULAR
|
|
148
|
+
selectedQuote =
|
|
149
|
+
quotes.find((quote) => quote.type === 'DCA' && quote.boostQuote) ||
|
|
150
|
+
quotes.find((quote) => quote.type === 'REGULAR' && quote.boostQuote) ||
|
|
151
|
+
quotes.find((quote) => quote.type === 'DCA') ||
|
|
152
|
+
quotes.find((quote) => quote.type === 'REGULAR');
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// User wants regular quotes - prioritize DCA > REGULAR (ignore boost quotes)
|
|
156
|
+
selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
|
|
157
|
+
}
|
|
146
158
|
if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'DCA' && params.fromAddress) {
|
|
159
|
+
// Use boost quote only if user enabled boost and it's available
|
|
160
|
+
const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
|
|
147
161
|
const resp = yield this.sdk.requestDepositAddressV2({
|
|
148
|
-
quote:
|
|
162
|
+
quote: quoteToUse,
|
|
149
163
|
destAddress: params.destinationAddress,
|
|
150
164
|
srcAddress: params.fromAddress,
|
|
151
165
|
fillOrKillParams: {
|
|
@@ -159,8 +173,10 @@ class ChainflipProtocol {
|
|
|
159
173
|
depositChannelId = resp.depositChannelId;
|
|
160
174
|
}
|
|
161
175
|
else if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'REGULAR' && params.fromAddress) {
|
|
176
|
+
// Use boost quote only if user enabled boost and it's available
|
|
177
|
+
const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
|
|
162
178
|
const resp = yield this.sdk.requestDepositAddressV2({
|
|
163
|
-
quote:
|
|
179
|
+
quote: quoteToUse,
|
|
164
180
|
destAddress: params.destinationAddress,
|
|
165
181
|
srcAddress: params.fromAddress,
|
|
166
182
|
fillOrKillParams: {
|
|
@@ -176,26 +192,36 @@ class ChainflipProtocol {
|
|
|
176
192
|
else {
|
|
177
193
|
console.error('No suitable quote found or destination/refund address missing');
|
|
178
194
|
}
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
const
|
|
195
|
+
// Determine which quote to use for fee calculations
|
|
196
|
+
const actualQuote = params.enableBoost && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.boostQuote) ? selectedQuote.boostQuote : selectedQuote;
|
|
197
|
+
const outboundFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'EGRESS');
|
|
198
|
+
const brokerFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'BROKER');
|
|
199
|
+
const networkFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'NETWORK');
|
|
200
|
+
const boostFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'BOOST');
|
|
201
|
+
// Check if boost is actually being used
|
|
202
|
+
const isUsingBoost = params.enableBoost && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.boostQuote) && actualQuote === selectedQuote.boostQuote;
|
|
182
203
|
return {
|
|
183
204
|
protocol: this.name,
|
|
184
205
|
toAddress,
|
|
185
206
|
memo: '',
|
|
186
|
-
expectedAmount: new CryptoAmount(baseAmount(
|
|
207
|
+
expectedAmount: new CryptoAmount(baseAmount(actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
|
|
187
208
|
dustThreshold: new CryptoAmount(baseAmount(srcAssetData.minimumSwapAmount, srcAssetData.decimals), params.fromAsset),
|
|
188
|
-
totalSwapSeconds: (
|
|
209
|
+
totalSwapSeconds: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.estimatedDurationSeconds) ? actualQuote.estimatedDurationSeconds : 0,
|
|
189
210
|
maxStreamingQuantity: undefined,
|
|
190
211
|
canSwap: toAddress !== '',
|
|
191
|
-
warning: (
|
|
212
|
+
warning: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.lowLiquidityWarning)
|
|
192
213
|
? '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%)'
|
|
193
|
-
:
|
|
214
|
+
: isUsingBoost
|
|
215
|
+
? 'Do not cache this response. Do not send funds after the expiry. Boost enabled for faster processing.'
|
|
216
|
+
: 'Do not cache this response. Do not send funds after the expiry.',
|
|
194
217
|
errors: [],
|
|
195
|
-
slipBasisPoints: 0
|
|
218
|
+
slipBasisPoints: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.recommendedSlippageTolerancePercent)
|
|
219
|
+
? (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.recommendedSlippageTolerancePercent) * 100
|
|
220
|
+
: 0,
|
|
196
221
|
fees: {
|
|
197
|
-
asset: assetUSDC, //
|
|
198
|
-
networkFee: new CryptoAmount(baseAmount(networkFee ? networkFee.amount : 0
|
|
222
|
+
asset: assetUSDC, // networkFee & broker fee paid in usdc
|
|
223
|
+
networkFee: new CryptoAmount(baseAmount((networkFee ? parseInt(networkFee.amount) : 0) +
|
|
224
|
+
(isUsingBoost && boostFee ? parseInt(boostFee.amount) : 0), isUsingBoost && boostFee ? srcAssetData.decimals : 6), isUsingBoost && boostFee ? params.fromAsset : assetUSDC),
|
|
199
225
|
outboundFee: new CryptoAmount(baseAmount(outboundFee ? outboundFee.amount : 0, destAssetData.decimals), params.destinationAsset),
|
|
200
226
|
affiliateFee: new CryptoAmount(baseAmount(brokerFee ? brokerFee.amount : 0, 6), assetUSDC),
|
|
201
227
|
},
|
|
@@ -228,7 +254,7 @@ class ChainflipProtocol {
|
|
|
228
254
|
}
|
|
229
255
|
/**
|
|
230
256
|
* Perform a swap operation between assets.
|
|
231
|
-
* @param {QuoteSwapParams}
|
|
257
|
+
* @param {QuoteSwapParams} params Swap parameters
|
|
232
258
|
* @returns {TxSubmitted} Transaction hash and URL of the swap
|
|
233
259
|
*/
|
|
234
260
|
doSwap(params) {
|
package/lib/index.js
CHANGED
|
@@ -143,11 +143,25 @@ class ChainflipProtocol {
|
|
|
143
143
|
amount: params.amount.baseAmount.amount().toString(),
|
|
144
144
|
affiliateBrokers: this.affiliateBrokers,
|
|
145
145
|
});
|
|
146
|
-
// Find
|
|
147
|
-
|
|
146
|
+
// Find quote based on user preference for boost
|
|
147
|
+
let selectedQuote;
|
|
148
|
+
if (params.enableBoost) {
|
|
149
|
+
// User wants boost - prioritize DCA with boost > REGULAR with boost > DCA > REGULAR
|
|
150
|
+
selectedQuote =
|
|
151
|
+
quotes.find((quote) => quote.type === 'DCA' && quote.boostQuote) ||
|
|
152
|
+
quotes.find((quote) => quote.type === 'REGULAR' && quote.boostQuote) ||
|
|
153
|
+
quotes.find((quote) => quote.type === 'DCA') ||
|
|
154
|
+
quotes.find((quote) => quote.type === 'REGULAR');
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// User wants regular quotes - prioritize DCA > REGULAR (ignore boost quotes)
|
|
158
|
+
selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
|
|
159
|
+
}
|
|
148
160
|
if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'DCA' && params.fromAddress) {
|
|
161
|
+
// Use boost quote only if user enabled boost and it's available
|
|
162
|
+
const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
|
|
149
163
|
const resp = yield this.sdk.requestDepositAddressV2({
|
|
150
|
-
quote:
|
|
164
|
+
quote: quoteToUse,
|
|
151
165
|
destAddress: params.destinationAddress,
|
|
152
166
|
srcAddress: params.fromAddress,
|
|
153
167
|
fillOrKillParams: {
|
|
@@ -161,8 +175,10 @@ class ChainflipProtocol {
|
|
|
161
175
|
depositChannelId = resp.depositChannelId;
|
|
162
176
|
}
|
|
163
177
|
else if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'REGULAR' && params.fromAddress) {
|
|
178
|
+
// Use boost quote only if user enabled boost and it's available
|
|
179
|
+
const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
|
|
164
180
|
const resp = yield this.sdk.requestDepositAddressV2({
|
|
165
|
-
quote:
|
|
181
|
+
quote: quoteToUse,
|
|
166
182
|
destAddress: params.destinationAddress,
|
|
167
183
|
srcAddress: params.fromAddress,
|
|
168
184
|
fillOrKillParams: {
|
|
@@ -178,26 +194,36 @@ class ChainflipProtocol {
|
|
|
178
194
|
else {
|
|
179
195
|
console.error('No suitable quote found or destination/refund address missing');
|
|
180
196
|
}
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
const
|
|
197
|
+
// Determine which quote to use for fee calculations
|
|
198
|
+
const actualQuote = params.enableBoost && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.boostQuote) ? selectedQuote.boostQuote : selectedQuote;
|
|
199
|
+
const outboundFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'EGRESS');
|
|
200
|
+
const brokerFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'BROKER');
|
|
201
|
+
const networkFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'NETWORK');
|
|
202
|
+
const boostFee = actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.includedFees.find((fee) => fee.type === 'BOOST');
|
|
203
|
+
// Check if boost is actually being used
|
|
204
|
+
const isUsingBoost = params.enableBoost && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.boostQuote) && actualQuote === selectedQuote.boostQuote;
|
|
184
205
|
return {
|
|
185
206
|
protocol: this.name,
|
|
186
207
|
toAddress,
|
|
187
208
|
memo: '',
|
|
188
|
-
expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(
|
|
209
|
+
expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
|
|
189
210
|
dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(srcAssetData.minimumSwapAmount, srcAssetData.decimals), params.fromAsset),
|
|
190
|
-
totalSwapSeconds: (
|
|
211
|
+
totalSwapSeconds: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.estimatedDurationSeconds) ? actualQuote.estimatedDurationSeconds : 0,
|
|
191
212
|
maxStreamingQuantity: undefined,
|
|
192
213
|
canSwap: toAddress !== '',
|
|
193
|
-
warning: (
|
|
214
|
+
warning: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.lowLiquidityWarning)
|
|
194
215
|
? '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%)'
|
|
195
|
-
:
|
|
216
|
+
: isUsingBoost
|
|
217
|
+
? 'Do not cache this response. Do not send funds after the expiry. Boost enabled for faster processing.'
|
|
218
|
+
: 'Do not cache this response. Do not send funds after the expiry.',
|
|
196
219
|
errors: [],
|
|
197
|
-
slipBasisPoints: 0
|
|
220
|
+
slipBasisPoints: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.recommendedSlippageTolerancePercent)
|
|
221
|
+
? (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.recommendedSlippageTolerancePercent) * 100
|
|
222
|
+
: 0,
|
|
198
223
|
fees: {
|
|
199
|
-
asset: xchainThorchainQuery.assetUSDC, //
|
|
200
|
-
networkFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(networkFee ? networkFee.amount : 0
|
|
224
|
+
asset: xchainThorchainQuery.assetUSDC, // networkFee & broker fee paid in usdc
|
|
225
|
+
networkFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount((networkFee ? parseInt(networkFee.amount) : 0) +
|
|
226
|
+
(isUsingBoost && boostFee ? parseInt(boostFee.amount) : 0), isUsingBoost && boostFee ? srcAssetData.decimals : 6), isUsingBoost && boostFee ? params.fromAsset : xchainThorchainQuery.assetUSDC),
|
|
201
227
|
outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(outboundFee ? outboundFee.amount : 0, destAssetData.decimals), params.destinationAsset),
|
|
202
228
|
affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(brokerFee ? brokerFee.amount : 0, 6), xchainThorchainQuery.assetUSDC),
|
|
203
229
|
},
|
|
@@ -230,7 +256,7 @@ class ChainflipProtocol {
|
|
|
230
256
|
}
|
|
231
257
|
/**
|
|
232
258
|
* Perform a swap operation between assets.
|
|
233
|
-
* @param {QuoteSwapParams}
|
|
259
|
+
* @param {QuoteSwapParams} params Swap parameters
|
|
234
260
|
* @returns {TxSubmitted} Transaction hash and URL of the swap
|
|
235
261
|
*/
|
|
236
262
|
doSwap(params) {
|
|
@@ -39,7 +39,7 @@ export declare class ChainflipProtocol implements IProtocol {
|
|
|
39
39
|
estimateSwap(params: QuoteSwapParams): Promise<QuoteSwap>;
|
|
40
40
|
/**
|
|
41
41
|
* Perform a swap operation between assets.
|
|
42
|
-
* @param {QuoteSwapParams}
|
|
42
|
+
* @param {QuoteSwapParams} params Swap parameters
|
|
43
43
|
* @returns {TxSubmitted} Transaction hash and URL of the swap
|
|
44
44
|
*/
|
|
45
45
|
doSwap(params: QuoteSwapParams): Promise<TxSubmitted>;
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-aggregator",
|
|
3
3
|
"description": "Protocol aggregator to make actions in different protocols",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.30",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.esm.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"directory": "release/package"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@chainflip/sdk": "1.11.
|
|
32
|
+
"@chainflip/sdk": "1.11.2",
|
|
33
33
|
"@trpc/server": "^10.45.2",
|
|
34
34
|
"@xchainjs/xchain-client": "2.0.9",
|
|
35
35
|
"@xchainjs/xchain-mayachain": "4.1.0",
|