@xchainjs/xchain-aggregator 2.0.28 → 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 CHANGED
@@ -1,12 +1,12 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
2
  import { CachedValue, isSynthAsset, isTradeAsset, CryptoAmount, baseAmount, isSecuredAsset, assetToString, eqAsset, assetFromStringEx, assetFromString, isTokenAsset } from '@xchainjs/xchain-util';
3
3
  import { SwapSDK } from '@chainflip/sdk/swap';
4
+ import { assetUSDC, ThorchainCache, Thornode, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
4
5
  import { AssetCacao, MAYAChain } from '@xchainjs/xchain-mayachain';
5
6
  import { MayachainAMM } from '@xchainjs/xchain-mayachain-amm';
6
7
  import { MayachainCache, Mayanode, MayachainQuery } from '@xchainjs/xchain-mayachain-query';
7
8
  import { AssetRuneNative as AssetRuneNative$1, THORChain } from '@xchainjs/xchain-thorchain';
8
9
  import { ThorchainAMM } from '@xchainjs/xchain-thorchain-amm';
9
- import { ThorchainCache, Thornode, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
10
10
 
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -141,11 +141,25 @@ class ChainflipProtocol {
141
141
  amount: params.amount.baseAmount.amount().toString(),
142
142
  affiliateBrokers: this.affiliateBrokers,
143
143
  });
144
- // Find either DCA or REGULAR quote, prioritizing DCA
145
- const selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
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: selectedQuote,
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: selectedQuote,
179
+ quote: quoteToUse,
164
180
  destAddress: params.destinationAddress,
165
181
  srcAddress: params.fromAddress,
166
182
  fillOrKillParams: {
@@ -176,26 +192,38 @@ class ChainflipProtocol {
176
192
  else {
177
193
  console.error('No suitable quote found or destination/refund address missing');
178
194
  }
179
- const outboundFee = selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.includedFees.find((fee) => fee.type === 'EGRESS');
180
- const brokerFee = selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.includedFees.find((fee) => fee.type === 'BROKER');
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;
181
203
  return {
182
204
  protocol: this.name,
183
205
  toAddress,
184
206
  memo: '',
185
- expectedAmount: new CryptoAmount(baseAmount(selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
207
+ expectedAmount: new CryptoAmount(baseAmount(actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
186
208
  dustThreshold: new CryptoAmount(baseAmount(srcAssetData.minimumSwapAmount, srcAssetData.decimals), params.fromAsset),
187
- totalSwapSeconds: (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.estimatedDurationSeconds) ? selectedQuote.estimatedDurationSeconds : 0,
209
+ totalSwapSeconds: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.estimatedDurationSeconds) ? actualQuote.estimatedDurationSeconds : 0,
188
210
  maxStreamingQuantity: undefined,
189
211
  canSwap: toAddress !== '',
190
- warning: (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.lowLiquidityWarning)
212
+ warning: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.lowLiquidityWarning)
191
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%)'
192
- : 'Do not cache this response. Do not send funds after the expiry.',
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.',
193
217
  errors: [],
194
- 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,
195
221
  fees: {
196
- asset: params.destinationAsset,
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),
197
225
  outboundFee: new CryptoAmount(baseAmount(outboundFee ? outboundFee.amount : 0, destAssetData.decimals), params.destinationAsset),
198
- affiliateFee: new CryptoAmount(baseAmount(brokerFee ? brokerFee.amount : 0, destAssetData.decimals), params.destinationAsset),
226
+ affiliateFee: new CryptoAmount(baseAmount(brokerFee ? brokerFee.amount : 0, 6), assetUSDC),
199
227
  },
200
228
  depositChannelId,
201
229
  };
@@ -216,7 +244,8 @@ class ChainflipProtocol {
216
244
  fees: {
217
245
  asset: params.destinationAsset,
218
246
  outboundFee: new CryptoAmount(baseAmount(0, destAssetData.decimals), params.destinationAsset),
219
- affiliateFee: new CryptoAmount(baseAmount(0, destAssetData.decimals), params.destinationAsset),
247
+ networkFee: new CryptoAmount(baseAmount(0, 6), assetUSDC),
248
+ affiliateFee: new CryptoAmount(baseAmount(0, 6), assetUSDC),
220
249
  },
221
250
  depositChannelId: undefined,
222
251
  };
@@ -225,7 +254,7 @@ class ChainflipProtocol {
225
254
  }
226
255
  /**
227
256
  * Perform a swap operation between assets.
228
- * @param {QuoteSwapParams} quoteSwapParams Swap parameters
257
+ * @param {QuoteSwapParams} params Swap parameters
229
258
  * @returns {TxSubmitted} Transaction hash and URL of the swap
230
259
  */
231
260
  doSwap(params) {
package/lib/index.js CHANGED
@@ -3,12 +3,12 @@
3
3
  var xchainClient = require('@xchainjs/xchain-client');
4
4
  var xchainUtil = require('@xchainjs/xchain-util');
5
5
  var swap = require('@chainflip/sdk/swap');
6
+ var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
6
7
  var xchainMayachain = require('@xchainjs/xchain-mayachain');
7
8
  var xchainMayachainAmm = require('@xchainjs/xchain-mayachain-amm');
8
9
  var xchainMayachainQuery = require('@xchainjs/xchain-mayachain-query');
9
10
  var xchainThorchain = require('@xchainjs/xchain-thorchain');
10
11
  var xchainThorchainAmm = require('@xchainjs/xchain-thorchain-amm');
11
- var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
12
12
 
13
13
  /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
@@ -143,11 +143,25 @@ class ChainflipProtocol {
143
143
  amount: params.amount.baseAmount.amount().toString(),
144
144
  affiliateBrokers: this.affiliateBrokers,
145
145
  });
146
- // Find either DCA or REGULAR quote, prioritizing DCA
147
- const selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
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: selectedQuote,
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: selectedQuote,
181
+ quote: quoteToUse,
166
182
  destAddress: params.destinationAddress,
167
183
  srcAddress: params.fromAddress,
168
184
  fillOrKillParams: {
@@ -178,26 +194,38 @@ class ChainflipProtocol {
178
194
  else {
179
195
  console.error('No suitable quote found or destination/refund address missing');
180
196
  }
181
- const outboundFee = selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.includedFees.find((fee) => fee.type === 'EGRESS');
182
- const brokerFee = selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.includedFees.find((fee) => fee.type === 'BROKER');
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;
183
205
  return {
184
206
  protocol: this.name,
185
207
  toAddress,
186
208
  memo: '',
187
- expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
209
+ expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.egressAmount, destAssetData.decimals), params.destinationAsset),
188
210
  dustThreshold: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(srcAssetData.minimumSwapAmount, srcAssetData.decimals), params.fromAsset),
189
- totalSwapSeconds: (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.estimatedDurationSeconds) ? selectedQuote.estimatedDurationSeconds : 0,
211
+ totalSwapSeconds: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.estimatedDurationSeconds) ? actualQuote.estimatedDurationSeconds : 0,
190
212
  maxStreamingQuantity: undefined,
191
213
  canSwap: toAddress !== '',
192
- warning: (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.lowLiquidityWarning)
214
+ warning: (actualQuote === null || actualQuote === void 0 ? void 0 : actualQuote.lowLiquidityWarning)
193
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%)'
194
- : 'Do not cache this response. Do not send funds after the expiry.',
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.',
195
219
  errors: [],
196
- 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,
197
223
  fees: {
198
- asset: params.destinationAsset,
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),
199
227
  outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(outboundFee ? outboundFee.amount : 0, destAssetData.decimals), params.destinationAsset),
200
- affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(brokerFee ? brokerFee.amount : 0, destAssetData.decimals), params.destinationAsset),
228
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(brokerFee ? brokerFee.amount : 0, 6), xchainThorchainQuery.assetUSDC),
201
229
  },
202
230
  depositChannelId,
203
231
  };
@@ -218,7 +246,8 @@ class ChainflipProtocol {
218
246
  fees: {
219
247
  asset: params.destinationAsset,
220
248
  outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, destAssetData.decimals), params.destinationAsset),
221
- affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, destAssetData.decimals), params.destinationAsset),
249
+ networkFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 6), xchainThorchainQuery.assetUSDC),
250
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0, 6), xchainThorchainQuery.assetUSDC),
222
251
  },
223
252
  depositChannelId: undefined,
224
253
  };
@@ -227,7 +256,7 @@ class ChainflipProtocol {
227
256
  }
228
257
  /**
229
258
  * Perform a swap operation between assets.
230
- * @param {QuoteSwapParams} quoteSwapParams Swap parameters
259
+ * @param {QuoteSwapParams} params Swap parameters
231
260
  * @returns {TxSubmitted} Transaction hash and URL of the swap
232
261
  */
233
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} quoteSwapParams Swap parameters
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
@@ -15,6 +15,7 @@ type Fees = {
15
15
  asset: Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset;
16
16
  affiliateFee: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset>;
17
17
  outboundFee: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset>;
18
+ networkFee?: CryptoAmount<Asset | TokenAsset | SynthAsset | TradeAsset | SecuredAsset>;
18
19
  };
19
20
  /**
20
21
  * Protocols supported by the Aggregator
@@ -111,6 +112,7 @@ type QuoteSwapParams = {
111
112
  liquidityToleranceBps?: number;
112
113
  streamingQuantity?: number;
113
114
  streamingInterval?: number;
115
+ enableBoost?: boolean;
114
116
  };
115
117
  type SwapHistoryParams = {
116
118
  chainAddresses: {
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.28",
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.0",
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",