@shapeshiftoss/swapper 17.7.1 → 17.7.3

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.
Files changed (41) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/index.js +1 -0
  4. package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
  5. package/dist/cjs/swappers/NearIntentsSwapper/constants.js +2 -1
  6. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +5 -2
  7. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +5 -1
  8. package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +10 -0
  9. package/dist/cjs/thorchain-utils/checkTradeStatus.js +8 -1
  10. package/dist/cjs/thorchain-utils/cosmossdk/getThorTxData.d.ts +12 -0
  11. package/dist/cjs/thorchain-utils/cosmossdk/getThorTxData.js +19 -0
  12. package/dist/cjs/thorchain-utils/cosmossdk/index.d.ts +1 -0
  13. package/dist/cjs/thorchain-utils/cosmossdk/index.js +1 -0
  14. package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +35 -10
  15. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +3 -2
  16. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +21 -14
  17. package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +11 -5
  18. package/dist/cjs/thorchain-utils/index.d.ts +1 -0
  19. package/dist/cjs/thorchain-utils/index.js +12 -1
  20. package/dist/cjs/types.d.ts +6 -0
  21. package/dist/esm/.tsbuildinfo +1 -1
  22. package/dist/esm/index.d.ts +1 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
  25. package/dist/esm/swappers/NearIntentsSwapper/constants.js +1 -0
  26. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -4
  27. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +5 -1
  28. package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +10 -0
  29. package/dist/esm/thorchain-utils/checkTradeStatus.js +8 -1
  30. package/dist/esm/thorchain-utils/cosmossdk/getThorTxData.d.ts +12 -0
  31. package/dist/esm/thorchain-utils/cosmossdk/getThorTxData.js +15 -0
  32. package/dist/esm/thorchain-utils/cosmossdk/index.d.ts +1 -0
  33. package/dist/esm/thorchain-utils/cosmossdk/index.js +1 -0
  34. package/dist/esm/thorchain-utils/getL1RateOrQuote.js +35 -10
  35. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +3 -2
  36. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +20 -13
  37. package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +12 -6
  38. package/dist/esm/thorchain-utils/index.d.ts +1 -0
  39. package/dist/esm/thorchain-utils/index.js +11 -1
  40. package/dist/esm/types.d.ts +6 -0
  41. package/package.json +2 -2
@@ -14,6 +14,7 @@ export * from './swappers/PortalsSwapper';
14
14
  export * from './swappers/ThorchainSwapper';
15
15
  export * from './swappers/MayachainSwapper';
16
16
  export * from './swappers/ButterSwap';
17
+ export * from './swappers/RelaySwapper';
17
18
  export * from './swappers/utils/helpers/helpers';
18
19
  export * from './thorchain-utils';
19
20
  export * from './types';
package/dist/cjs/index.js CHANGED
@@ -43,6 +43,7 @@ __exportStar(require("./swappers/PortalsSwapper"), exports);
43
43
  __exportStar(require("./swappers/ThorchainSwapper"), exports);
44
44
  __exportStar(require("./swappers/MayachainSwapper"), exports);
45
45
  __exportStar(require("./swappers/ButterSwap"), exports);
46
+ __exportStar(require("./swappers/RelaySwapper"), exports);
46
47
  __exportStar(require("./swappers/utils/helpers/helpers"), exports);
47
48
  __exportStar(require("./thorchain-utils"), exports);
48
49
  __exportStar(require("./types"), exports);
@@ -1,3 +1,4 @@
1
1
  export declare const ONE_CLICK_BASE_URL = "https://1click.chaindefuser.com";
2
2
  export declare const DEFAULT_SLIPPAGE_BPS = 50;
3
3
  export declare const DEFAULT_QUOTE_DEADLINE_MS: number;
4
+ export declare const BTC_QUOTE_DEADLINE_MS: number;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_QUOTE_DEADLINE_MS = exports.DEFAULT_SLIPPAGE_BPS = exports.ONE_CLICK_BASE_URL = void 0;
3
+ exports.BTC_QUOTE_DEADLINE_MS = exports.DEFAULT_QUOTE_DEADLINE_MS = exports.DEFAULT_SLIPPAGE_BPS = exports.ONE_CLICK_BASE_URL = void 0;
4
4
  exports.ONE_CLICK_BASE_URL = 'https://1click.chaindefuser.com';
5
5
  exports.DEFAULT_SLIPPAGE_BPS = 50;
6
6
  exports.DEFAULT_QUOTE_DEADLINE_MS = 30 * 60 * 1000;
7
+ exports.BTC_QUOTE_DEADLINE_MS = 60 * 60 * 1000;
@@ -52,6 +52,9 @@ const getTradeQuote = async (input, deps) => {
52
52
  message: `Asset ${buyAsset.symbol} on ${buyAsset.networkName || buyAsset.chainId} is not supported by NEAR Intents`,
53
53
  }));
54
54
  }
55
+ const quoteDeadline = sellAsset.chainId === caip_1.btcChainId || buyAsset.chainId === caip_1.btcChainId
56
+ ? constants_2.BTC_QUOTE_DEADLINE_MS
57
+ : constants_2.DEFAULT_QUOTE_DEADLINE_MS;
55
58
  const quoteRequest = {
56
59
  dry: false,
57
60
  swapType: types_2.QuoteRequest.swapType.EXACT_INPUT,
@@ -66,7 +69,7 @@ const getTradeQuote = async (input, deps) => {
66
69
  refundType: types_2.QuoteRequest.refundType.ORIGIN_CHAIN,
67
70
  recipient: receiveAddress,
68
71
  recipientType: types_2.QuoteRequest.recipientType.DESTINATION_CHAIN,
69
- deadline: new Date(Date.now() + constants_2.DEFAULT_QUOTE_DEADLINE_MS).toISOString(),
72
+ deadline: new Date(Date.now() + quoteDeadline).toISOString(),
70
73
  referral: 'shapeshift',
71
74
  appFees: [
72
75
  {
@@ -259,7 +262,7 @@ const getTradeQuote = async (input, deps) => {
259
262
  steps: [
260
263
  {
261
264
  accountNumber,
262
- allowanceContract: quote.depositAddress,
265
+ allowanceContract: '',
263
266
  buyAmountBeforeFeesCryptoBaseUnit: quote.amountOut,
264
267
  buyAmountAfterFeesCryptoBaseUnit: quote.amountOut,
265
268
  buyAsset,
@@ -50,6 +50,7 @@ exports.getNearIntentsAsset = getNearIntentsAsset;
50
50
  const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron', 'monad', 'plasma'];
51
51
  const TOKEN_LOOKUP_CHAINS = ['sui', 'starknet', 'ton'];
52
52
  const NEAR_CHAIN = 'near';
53
+ const BTC_CHAIN = 'btc';
53
54
  const WNEAR_CONTRACT_ADDRESS = 'wrap.near';
54
55
  const isNep245Chain = (chain) => {
55
56
  return NEP245_CHAINS.includes(chain);
@@ -61,6 +62,9 @@ const assetToNearIntentsAsset = async (asset) => {
61
62
  const nearNetwork = types_1.chainIdToNearIntentsChain[asset.chainId];
62
63
  if (!nearNetwork)
63
64
  return null;
65
+ // https://partners.near-intents.org/omni-migration#partners
66
+ if (nearNetwork === BTC_CHAIN)
67
+ return `1cs_v1:btc:native:coin`;
64
68
  // NEAR chain requires special handling
65
69
  // Native NEAR maps to wNEAR (wrap.near)
66
70
  if (nearNetwork === NEAR_CHAIN) {
@@ -96,7 +100,7 @@ const assetToNearIntentsAsset = async (asset) => {
96
100
  }
97
101
  return match.assetId;
98
102
  }
99
- // NEP-141 chains (ETH, ARB, BASE, GNOSIS, BTC, DOGE): use predictable format
103
+ // NEP-141 chains (ETH, ARB, BASE, GNOSIS, DOGE): use predictable format
100
104
  const contractAddress = (0, utils_1.isToken)(asset.assetId)
101
105
  ? (0, caip_1.fromAssetId)(asset.assetId).assetReference
102
106
  : viem_1.zeroAddress;
@@ -78,6 +78,11 @@ const expectedQuoteResponse = [
78
78
  thorchainSpecific: {
79
79
  maxStreamingQuantity: undefined,
80
80
  },
81
+ thorchainTransactionMetadata: {
82
+ to: '0x3624525075b88B24ecc29CE226b0CEc1fFcB6976',
83
+ data: '0x',
84
+ value: '0',
85
+ },
81
86
  },
82
87
  ],
83
88
  },
@@ -121,6 +126,11 @@ const expectedQuoteResponse = [
121
126
  thorchainSpecific: {
122
127
  maxStreamingQuantity: undefined,
123
128
  },
129
+ thorchainTransactionMetadata: {
130
+ to: '0x3624525075b88B24ecc29CE226b0CEc1fFcB6976',
131
+ data: '0x',
132
+ value: '0',
133
+ },
124
134
  },
125
135
  ],
126
136
  },
@@ -68,7 +68,14 @@ const checkTradeStatus = async ({ txHash, chainId, address, fetchIsSmartContract
68
68
  return { buyTxHash, status: unchained_client_1.TxStatus.Pending, message };
69
69
  }
70
70
  catch (e) {
71
- console.error(e);
71
+ const message = (() => {
72
+ if (axios_1.default.isAxiosError(e))
73
+ return e.response?.data?.message ?? e.message;
74
+ if (e instanceof Error)
75
+ return e.message;
76
+ return String(e);
77
+ })();
78
+ console.error(`checkTradeStatus(${nativeChain}, ${txHash}): ${message}`);
72
79
  return { buyTxHash: undefined, status: unchained_client_1.TxStatus.Unknown, message: undefined };
73
80
  }
74
81
  };
@@ -0,0 +1,12 @@
1
+ import type { Asset } from '@shapeshiftoss/types';
2
+ import type { SwapperConfig, SwapperName } from '../../types';
3
+ type GetThorTxDataArgs = {
4
+ sellAsset: Asset;
5
+ config: SwapperConfig;
6
+ swapperName: SwapperName;
7
+ };
8
+ type GetThorTxDataReturn = {
9
+ vault: string;
10
+ };
11
+ export declare const getThorTxData: ({ sellAsset, config, swapperName, }: GetThorTxDataArgs) => Promise<GetThorTxDataReturn>;
12
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getThorTxData = void 0;
4
+ const getInboundAddressDataForChain_1 = require("../getInboundAddressDataForChain");
5
+ const index_1 = require("../index");
6
+ const getThorTxData = async ({ sellAsset, config, swapperName, }) => {
7
+ // Native assets on the swapper's own chain (RUNE on THORChain, CACAO on MAYAChain)
8
+ // deposit via MsgDeposit and have no recipient address.
9
+ if (sellAsset.chainId === (0, index_1.getChainIdBySwapper)(swapperName))
10
+ return { vault: '' };
11
+ // Everything else (e.g. ATOM via THORChain, RUNE via MAYAChain) sends via MsgSend
12
+ // to the swapper's inbound vault on that chain.
13
+ const daemonUrl = (0, index_1.getDaemonUrl)(config, swapperName);
14
+ const res = await (0, getInboundAddressDataForChain_1.getInboundAddressDataForChain)(daemonUrl, sellAsset.assetId, true, swapperName);
15
+ if (res.isErr())
16
+ throw res.unwrapErr();
17
+ return { vault: res.unwrap().address };
18
+ };
19
+ exports.getThorTxData = getThorTxData;
@@ -1 +1,2 @@
1
1
  export * from './getCosmosSdkTransactionFees';
2
+ export * from './getThorTxData';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getCosmosSdkTransactionFees"), exports);
18
+ __exportStar(require("./getThorTxData"), exports);
@@ -33,8 +33,10 @@ const tronweb_1 = require("tronweb");
33
33
  const uuid_1 = require("uuid");
34
34
  const index_1 = require("../index");
35
35
  const affiliateFee_1 = require("../swappers/utils/affiliateFee");
36
+ const helpers_1 = require("../swappers/utils/helpers/helpers");
36
37
  const types_1 = require("../types");
37
38
  const utils_2 = require("../utils");
39
+ const cosmossdk = __importStar(require("./cosmossdk"));
38
40
  const evm = __importStar(require("./evm"));
39
41
  const getLimitWithManualSlippage_1 = require("./getLimitWithManualSlippage/getLimitWithManualSlippage");
40
42
  const getQuote_1 = require("./getQuote");
@@ -154,7 +156,7 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
154
156
  affilate: (0, index_2.getAffiliate)(swapperName),
155
157
  });
156
158
  };
157
- const makeThorTradeRateOrQuote = ({ route, memo, allowanceContract, feeData, data, router, vault, }) => {
159
+ const makeThorTradeRateOrQuote = ({ route, memo, allowanceContract, feeData, data, router, vault, thorchainTransactionMetadata, }) => {
158
160
  const buyAmountAfterFeesCryptoBaseUnit = (0, utils_1.convertPrecision)({
159
161
  value: route.expectedAmountOutThorBaseUnit,
160
162
  inputExponent: buyAssetNativePrecision,
@@ -208,6 +210,7 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
208
210
  thorchainSpecific: {
209
211
  maxStreamingQuantity: route.quote.max_streaming_quantity,
210
212
  },
213
+ thorchainTransactionMetadata,
211
214
  },
212
215
  ],
213
216
  };
@@ -239,6 +242,11 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
239
242
  data,
240
243
  router,
241
244
  vault,
245
+ thorchainTransactionMetadata: {
246
+ to: router,
247
+ data,
248
+ value: (0, helpers_1.isNativeEvmAsset)(sellAsset.assetId) ? sellAmountCryptoBaseUnit : '0',
249
+ },
242
250
  feeData: {
243
251
  protocolFees: getProtocolFees(route.quote),
244
252
  networkFeeCryptoBaseUnit,
@@ -286,6 +294,11 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
286
294
  route,
287
295
  allowanceContract: '0x0',
288
296
  memo,
297
+ thorchainTransactionMetadata: {
298
+ to: vault,
299
+ memo,
300
+ value: sellAmountCryptoBaseUnit,
301
+ },
289
302
  feeData,
290
303
  });
291
304
  }));
@@ -301,11 +314,18 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
301
314
  case caip_1.CHAIN_NAMESPACE.CosmosSdk: {
302
315
  const cosmosChainAdapter = assertGetCosmosSdkChainAdapter(sellAsset.chainId);
303
316
  const { fast } = await cosmosChainAdapter.getFeeData({});
317
+ const { vault } = await cosmossdk.getThorTxData({ sellAsset, config, swapperName });
304
318
  return (0, monads_1.Ok)(perRouteValues.map((route) => {
319
+ const memo = getMemo(route);
305
320
  return makeThorTradeRateOrQuote({
306
321
  route,
307
- memo: getMemo(route),
322
+ memo,
308
323
  allowanceContract: '0x0',
324
+ thorchainTransactionMetadata: {
325
+ to: vault,
326
+ memo,
327
+ value: sellAmountCryptoBaseUnit,
328
+ },
309
329
  feeData: {
310
330
  networkFeeCryptoBaseUnit: fast.txFee,
311
331
  protocolFees: getProtocolFees(route.quote),
@@ -319,13 +339,13 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
319
339
  case caip_1.CHAIN_NAMESPACE.Solana: {
320
340
  const adapter = assertGetSolanaChainAdapter(sellAsset.chainId);
321
341
  const sendAddress = input.sendAddress;
342
+ const { vault } = await solana.getThorTxData({ sellAsset, config, swapperName });
322
343
  const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
323
344
  const memo = getMemo(route);
324
345
  const protocolFees = getProtocolFees(route.quote);
325
346
  const feeData = await (async () => {
326
347
  if (!sendAddress)
327
348
  return { networkFeeCryptoBaseUnit: undefined, protocolFees };
328
- const { vault } = await solana.getThorTxData({ sellAsset, config, swapperName });
329
349
  const memoInstruction = new web3_js_1.TransactionInstruction({
330
350
  keys: [],
331
351
  programId: new web3_js_1.PublicKey(SOLANA_MEMO_PROGRAM_ID),
@@ -351,6 +371,11 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
351
371
  route,
352
372
  allowanceContract: '0x0',
353
373
  memo,
374
+ thorchainTransactionMetadata: {
375
+ to: vault,
376
+ memo,
377
+ value: sellAmountCryptoBaseUnit,
378
+ },
354
379
  feeData,
355
380
  });
356
381
  }));
@@ -364,20 +389,15 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
364
389
  return (0, monads_1.Ok)(routes);
365
390
  }
366
391
  case caip_1.CHAIN_NAMESPACE.Tron: {
392
+ const { vault } = await tron.getThorTxData({ sellAsset, config, swapperName });
367
393
  const maybeRoutes = await Promise.allSettled(perRouteValues.map(async (route) => {
368
394
  const memo = getMemo(route);
369
395
  let networkFeeCryptoBaseUnit = undefined;
370
396
  // Calculate fees for rates when we have a receive address (wallet connected)
371
- if (input.quoteOrRate === 'rate' && input.receiveAddress) {
397
+ if (input.quoteOrRate === 'rate' && input.receiveAddress && vault) {
372
398
  try {
373
399
  const { sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit } = input;
374
400
  const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
375
- // Get vault address
376
- const { vault } = await tron.getThorTxData({
377
- sellAsset,
378
- config,
379
- swapperName,
380
- });
381
401
  // Estimate fees using the receive address for accurate energy calculation
382
402
  const tronWeb = new tronweb_1.TronWeb({
383
403
  fullHost: deps.config.VITE_TRON_NODE_URL,
@@ -426,6 +446,11 @@ const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType, swapp
426
446
  route,
427
447
  allowanceContract: '0x0',
428
448
  memo,
449
+ thorchainTransactionMetadata: {
450
+ to: vault,
451
+ memo,
452
+ value: sellAmountCryptoBaseUnit,
453
+ },
429
454
  feeData: {
430
455
  networkFeeCryptoBaseUnit,
431
456
  protocolFees: getProtocolFees(route.quote),
@@ -1,7 +1,8 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
1
2
  import type { Asset } from '@shapeshiftoss/types';
2
3
  import type { SwapperConfig, SwapperName } from '../../types';
3
- export declare const getOutboundFeeInSellAssetThorBaseUnit: (runePerAsset: string, swapperName: SwapperName) => BigNumber;
4
- export declare const getExpectedAffiliateFeeSellAssetThorUnit: (sellAmountCryptoBaseUnit: string, sellAsset: Asset, affiliateBps: string, swapperName: SwapperName) => BigNumber;
4
+ export declare const getOutboundFeeSellAssetThorBaseUnit: (runePerAsset: string, sellAssetId: AssetId, swapperName: SwapperName) => BigNumber;
5
+ export declare const getExpectedAffiliateFeeSellAssetThorBaseUnit: (sellAmountCryptoBaseUnit: string, sellAsset: Asset, affiliateBps: string, swapperName: SwapperName) => BigNumber;
5
6
  export declare const getThresholdedAffiliateBps: ({ sellAsset, affiliateBps, sellAmountCryptoBaseUnit, config, swapperName, }: {
6
7
  sellAsset: Asset;
7
8
  affiliateBps: string;
@@ -1,26 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getThresholdedAffiliateBps = exports.getExpectedAffiliateFeeSellAssetThorUnit = exports.getOutboundFeeInSellAssetThorBaseUnit = void 0;
3
+ exports.getThresholdedAffiliateBps = exports.getExpectedAffiliateFeeSellAssetThorBaseUnit = exports.getOutboundFeeSellAssetThorBaseUnit = void 0;
4
4
  const utils_1 = require("@shapeshiftoss/utils");
5
5
  const index_1 = require("../index");
6
- const getOutboundFeeInSellAssetThorBaseUnit = (runePerAsset, swapperName) => {
7
- return (0, utils_1.bn)((0, index_1.getNativeFee)(swapperName)).dividedBy(runePerAsset);
6
+ // Convert native fee to sell asset's native precision before dividing by `assetPrice`.
7
+ // MAYA's CACAO is 10-dec but pool assets are 8-dec — skip this and the result is 100x off.
8
+ const getOutboundFeeSellAssetThorBaseUnit = (runePerAsset, sellAssetId, swapperName) => {
9
+ const nativeFeeSellAssetThorBaseUnit = (0, utils_1.convertPrecision)({
10
+ value: (0, index_1.getNativeFee)(swapperName),
11
+ inputExponent: (0, index_1.getNativePrecision)((0, index_1.getSwapperNativeAssetId)(swapperName), swapperName),
12
+ outputExponent: (0, index_1.getNativePrecision)(sellAssetId, swapperName),
13
+ });
14
+ return nativeFeeSellAssetThorBaseUnit.dividedBy(runePerAsset);
8
15
  };
9
- exports.getOutboundFeeInSellAssetThorBaseUnit = getOutboundFeeInSellAssetThorBaseUnit;
10
- const getExpectedAffiliateFeeSellAssetThorUnit = (sellAmountCryptoBaseUnit, sellAsset, affiliateBps, swapperName) => {
11
- const sellAmountThorUnit = (0, utils_1.convertPrecision)({
16
+ exports.getOutboundFeeSellAssetThorBaseUnit = getOutboundFeeSellAssetThorBaseUnit;
17
+ const getExpectedAffiliateFeeSellAssetThorBaseUnit = (sellAmountCryptoBaseUnit, sellAsset, affiliateBps, swapperName) => {
18
+ const sellAmountThorBaseUnit = (0, utils_1.convertPrecision)({
12
19
  value: sellAmountCryptoBaseUnit,
13
20
  inputExponent: sellAsset.precision,
14
21
  outputExponent: (0, index_1.getNativePrecision)(sellAsset.assetId, swapperName),
15
22
  });
16
23
  const affiliatePercent = (0, utils_1.convertBasisPointsToDecimalPercentage)(affiliateBps);
17
- return sellAmountThorUnit.times(affiliatePercent);
24
+ return sellAmountThorBaseUnit.times(affiliatePercent);
18
25
  };
19
- exports.getExpectedAffiliateFeeSellAssetThorUnit = getExpectedAffiliateFeeSellAssetThorUnit;
26
+ exports.getExpectedAffiliateFeeSellAssetThorBaseUnit = getExpectedAffiliateFeeSellAssetThorBaseUnit;
20
27
  // don't apply an affiliate fee if it's below the outbound fee for the inbound pool
21
28
  const getThresholdedAffiliateBps = async ({ sellAsset, affiliateBps, sellAmountCryptoBaseUnit, config, swapperName, }) => {
22
29
  const midgardUrl = (0, index_1.getMidgardUrl)(config, swapperName);
23
- const outboundFeeSellAssetThorUnit = await (async () => {
30
+ const outboundFeeSellAssetThorBaseUnit = await (async () => {
24
31
  if ((0, index_1.isNativeAsset)(sellAsset.assetId, swapperName))
25
32
  return (0, index_1.getNativeFee)(swapperName);
26
33
  const sellPoolId = (0, index_1.getPoolAssetId)({ assetId: sellAsset.assetId, swapperName });
@@ -29,12 +36,12 @@ const getThresholdedAffiliateBps = async ({ sellAsset, affiliateBps, sellAmountC
29
36
  if (res.isErr())
30
37
  throw res.unwrapErr();
31
38
  const pool = res.unwrap().data;
32
- // calculate the rune outbound fee denominated in the sell asset, in native units
33
- return (0, exports.getOutboundFeeInSellAssetThorBaseUnit)(pool.assetPrice, swapperName);
39
+ // calculate the rune outbound fee denominated in the sell asset, in thor base units
40
+ return (0, exports.getOutboundFeeSellAssetThorBaseUnit)(pool.assetPrice, sellAsset.assetId, swapperName);
34
41
  })();
35
- // calculate the expected affiliate fee, in native units
36
- const expectedAffiliateFeeSellAssetThorUnit = (0, exports.getExpectedAffiliateFeeSellAssetThorUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, swapperName);
37
- const isAffiliateFeeBelowOutboundFee = expectedAffiliateFeeSellAssetThorUnit.lte(outboundFeeSellAssetThorUnit);
42
+ // calculate the expected affiliate fee, in thor base units
43
+ const expectedAffiliateFeeSellAssetThorBaseUnit = (0, exports.getExpectedAffiliateFeeSellAssetThorBaseUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, swapperName);
44
+ const isAffiliateFeeBelowOutboundFee = expectedAffiliateFeeSellAssetThorBaseUnit.lte(outboundFeeSellAssetThorBaseUnit);
38
45
  return isAffiliateFeeBelowOutboundFee ? '0' : affiliateBps;
39
46
  };
40
47
  exports.getThresholdedAffiliateBps = getThresholdedAffiliateBps;
@@ -26,18 +26,24 @@ vitest_1.vi.mock('../service', () => {
26
26
  thorService: mockAxios.default.create(),
27
27
  };
28
28
  });
29
- (0, vitest_1.describe)('getOutboundFeeInSellAssetThorBaseUnit', () => {
29
+ (0, vitest_1.describe)('getOutboundFeeSellAssetThorBaseUnit', () => {
30
30
  (0, vitest_1.it)('should return 0.02 rune denominated in the target asset, in thor units', () => {
31
31
  const assetPricePrecision = '4.00000'; // 1 token is 4x as valuable as 1 rune
32
- (0, vitest_1.expect)((0, getThresholdedAffiliateBps_1.getOutboundFeeInSellAssetThorBaseUnit)(assetPricePrecision, types_1.SwapperName.Thorchain).toNumber()).toEqual(Number(chain_adapters_1.thorchain.NATIVE_FEE) / 4);
32
+ (0, vitest_1.expect)((0, getThresholdedAffiliateBps_1.getOutboundFeeSellAssetThorBaseUnit)(assetPricePrecision, test_data_1.ETH.assetId, types_1.SwapperName.Thorchain).toNumber()).toEqual(Number(chain_adapters_1.thorchain.NATIVE_FEE) / 4);
33
+ });
34
+ (0, vitest_1.it)('should scale CACAO 10-dec native fee down to non-CACAO 8-dec sell asset precision on MAYA', () => {
35
+ // 1 eth = 100 cacao, NATIVE_FEE = 2e9 (10-dec CACAO = 0.2 CACAO)
36
+ // 0.2 CACAO / 100 (CACAO/ETH) = 0.002 ETH = 200_000 at 8-dec ETH
37
+ const assetPrice = '100';
38
+ (0, vitest_1.expect)((0, getThresholdedAffiliateBps_1.getOutboundFeeSellAssetThorBaseUnit)(assetPrice, test_data_1.ETH.assetId, types_1.SwapperName.Mayachain).toNumber()).toEqual(200_000);
33
39
  });
34
40
  });
35
- (0, vitest_1.describe)('getExpectedAffiliateFeeSellAssetThorUnit', () => {
41
+ (0, vitest_1.describe)('getExpectedAffiliateFeeSellAssetThorBaseUnit', () => {
36
42
  (0, vitest_1.it)('should return the correct affiliate fee in thor base units', () => {
37
43
  const sellAmountCryptoBaseUnit = '1000000000000000000'; // 1 eth
38
44
  const affiliateBps = '35';
39
45
  const sellAsset = test_data_1.ETH;
40
- const result = (0, getThresholdedAffiliateBps_1.getExpectedAffiliateFeeSellAssetThorUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, types_1.SwapperName.Thorchain);
46
+ const result = (0, getThresholdedAffiliateBps_1.getExpectedAffiliateFeeSellAssetThorBaseUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, types_1.SwapperName.Thorchain);
41
47
  const expectation = (0, utils_1.bn)('100000000').times('0.0035').toFixed(0);
42
48
  (0, vitest_1.expect)(result.toFixed(0)).toEqual(expectation);
43
49
  });
@@ -45,7 +51,7 @@ vitest_1.vi.mock('../service', () => {
45
51
  const sellAmountCryptoBaseUnit = '1000000000000000000'; // 1 eth
46
52
  const affiliateBps = '0';
47
53
  const sellAsset = test_data_1.ETH;
48
- const result = (0, getThresholdedAffiliateBps_1.getExpectedAffiliateFeeSellAssetThorUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, types_1.SwapperName.Thorchain);
54
+ const result = (0, getThresholdedAffiliateBps_1.getExpectedAffiliateFeeSellAssetThorBaseUnit)(sellAmountCryptoBaseUnit, sellAsset, affiliateBps, types_1.SwapperName.Thorchain);
49
55
  const expectation = '0';
50
56
  (0, vitest_1.expect)(result.toFixed(0)).toEqual(expectation);
51
57
  });
@@ -23,6 +23,7 @@ export declare const getDaemonUrl: (config: SwapperConfig, swapperName: SwapperN
23
23
  export declare const getMidgardUrl: (config: SwapperConfig, swapperName: SwapperName) => string;
24
24
  export declare const isNativeAsset: (assetId: AssetId, swapperName: SwapperName) => boolean;
25
25
  export declare const getNativePrecision: (assetId: AssetId, swapperName: SwapperName) => 8 | 10;
26
+ export declare const getSwapperNativeAssetId: (swapperName: SwapperName) => AssetId;
26
27
  export declare const getNativeFee: (swapperName: SwapperName) => "2000000" | "2000000000";
27
28
  export declare const getAffiliate: (swapperName: SwapperName) => "ss" | "ssmaya";
28
29
  export declare const getPoolAssetId: ({ assetId, swapperName, }: {
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getSwapSource = exports.getPoolAssetId = exports.getAffiliate = exports.getNativeFee = exports.getNativePrecision = exports.isNativeAsset = exports.getMidgardUrl = exports.getDaemonUrl = exports.isThorTradeQuote = exports.isThorTradeRate = exports.getChainIdBySwapper = exports.utxo = exports.tron = exports.solana = exports.evm = exports.cosmossdk = void 0;
29
+ exports.getSwapSource = exports.getPoolAssetId = exports.getAffiliate = exports.getNativeFee = exports.getSwapperNativeAssetId = exports.getNativePrecision = exports.isNativeAsset = exports.getMidgardUrl = exports.getDaemonUrl = exports.isThorTradeQuote = exports.isThorTradeRate = exports.getChainIdBySwapper = exports.utxo = exports.tron = exports.solana = exports.evm = exports.cosmossdk = void 0;
30
30
  const caip_1 = require("@shapeshiftoss/caip");
31
31
  const adapters = __importStar(require("@shapeshiftoss/chain-adapters"));
32
32
  const MayachainSwapper_1 = require("../swappers/MayachainSwapper");
@@ -105,6 +105,17 @@ const getNativePrecision = (assetId, swapperName) => {
105
105
  }
106
106
  };
107
107
  exports.getNativePrecision = getNativePrecision;
108
+ const getSwapperNativeAssetId = (swapperName) => {
109
+ switch (swapperName) {
110
+ case types_1.SwapperName.Thorchain:
111
+ return caip_1.thorchainAssetId;
112
+ case types_1.SwapperName.Mayachain:
113
+ return caip_1.mayachainAssetId;
114
+ default:
115
+ throw new Error(`Invalid swapper: ${swapperName}`);
116
+ }
117
+ };
118
+ exports.getSwapperNativeAssetId = getSwapperNativeAssetId;
108
119
  const getNativeFee = (swapperName) => {
109
120
  switch (swapperName) {
110
121
  case types_1.SwapperName.Thorchain:
@@ -327,6 +327,12 @@ export type TradeQuoteStep = {
327
327
  thorchainSpecific?: {
328
328
  maxStreamingQuantity?: number;
329
329
  };
330
+ thorchainTransactionMetadata?: {
331
+ to: string;
332
+ data?: string;
333
+ value?: string;
334
+ memo?: string;
335
+ };
330
336
  relayTransactionMetadata?: RelayTransactionMetadata;
331
337
  butterSwapTransactionMetadata?: {
332
338
  to: string;