@shapeshiftoss/swapper 19.0.0 → 20.0.0

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 (93) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/exactOutputFiltering.test.d.ts +1 -0
  3. package/dist/cjs/exactOutputFiltering.test.js +70 -0
  4. package/dist/cjs/swapper.d.ts +3 -3
  5. package/dist/cjs/swapper.js +29 -6
  6. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
  7. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
  8. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -0
  9. package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
  10. package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
  11. package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -0
  12. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
  13. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
  14. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
  15. package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +2 -0
  16. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
  17. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -9
  18. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
  19. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +14 -9
  20. package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +3 -1
  21. package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
  22. package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.js +61 -0
  23. package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
  24. package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
  25. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
  26. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
  27. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
  28. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
  29. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
  30. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
  31. package/dist/cjs/swappers/RelaySwapper/endpoints.js +6 -0
  32. package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
  33. package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +5 -2
  34. package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
  35. package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.js +5 -2
  36. package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
  37. package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.js +22 -10
  38. package/dist/cjs/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
  39. package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +4 -1
  40. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
  41. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
  42. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
  43. package/dist/cjs/types.d.ts +19 -2
  44. package/dist/cjs/types.js +2 -0
  45. package/dist/cjs/utils/helpers.d.ts +6 -0
  46. package/dist/cjs/utils/helpers.js +5 -1
  47. package/dist/esm/.tsbuildinfo +1 -1
  48. package/dist/esm/exactOutputFiltering.test.d.ts +1 -0
  49. package/dist/esm/exactOutputFiltering.test.js +68 -0
  50. package/dist/esm/swapper.d.ts +3 -3
  51. package/dist/esm/swapper.js +29 -6
  52. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
  53. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
  54. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +1 -0
  55. package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
  56. package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
  57. package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +1 -0
  58. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
  59. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
  60. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
  61. package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +4 -2
  62. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
  63. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -3
  64. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
  65. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +7 -3
  66. package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +3 -1
  67. package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
  68. package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.js +59 -0
  69. package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
  70. package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
  71. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
  72. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
  73. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
  74. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
  75. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
  76. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
  77. package/dist/esm/swappers/RelaySwapper/endpoints.js +8 -2
  78. package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
  79. package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +3 -1
  80. package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
  81. package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.js +3 -1
  82. package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
  83. package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.js +23 -11
  84. package/dist/esm/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
  85. package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +4 -1
  86. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
  87. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
  88. package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
  89. package/dist/esm/types.d.ts +19 -2
  90. package/dist/esm/types.js +2 -0
  91. package/dist/esm/utils/helpers.d.ts +6 -0
  92. package/dist/esm/utils/helpers.js +3 -0
  93. package/package.json +5 -5
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const constants_1 = require("./constants");
5
+ const swapper_1 = require("./swapper");
6
+ const types_1 = require("./types");
7
+ const assets_1 = require("./utils/test-data/assets");
8
+ // Exact-output support is structural - a swapper cannot claim it without implementing it
9
+ (0, vitest_1.describe)('exact output capability', () => {
10
+ (0, vitest_1.it)('is implemented by the swappers whose upstream API can honour an exact buy amount', () => {
11
+ for (const swapperName of [types_1.SwapperName.NearIntents, types_1.SwapperName.Relay]) {
12
+ (0, vitest_1.expect)(constants_1.swappers[swapperName]?.getExactOutputTradeRate).toBeDefined();
13
+ (0, vitest_1.expect)(constants_1.swappers[swapperName]?.getExactOutputTradeQuote).toBeDefined();
14
+ }
15
+ });
16
+ (0, vitest_1.it)('is absent everywhere else', () => {
17
+ const exactOutputCapable = Object.values(types_1.SwapperName).filter(swapperName => constants_1.swappers[swapperName]?.getExactOutputTradeRate !== undefined);
18
+ (0, vitest_1.expect)(exactOutputCapable).toEqual([types_1.SwapperName.Relay, types_1.SwapperName.NearIntents]);
19
+ });
20
+ });
21
+ const exactOutputInput = {
22
+ sellAsset: assets_1.ETH,
23
+ buyAsset: assets_1.BTC,
24
+ buyAmountCryptoBaseUnit: '100000',
25
+ affiliateBps: '0',
26
+ allowMultiHop: true,
27
+ receiveAddress: undefined,
28
+ accountNumber: undefined,
29
+ quoteOrRate: 'rate',
30
+ };
31
+ const deps = {};
32
+ (0, vitest_1.describe)('getTradeRates on an exact buy amount', () => {
33
+ // Silently omitting these would read as the swapper being unavailable rather than unable
34
+ (0, vitest_1.it)('reports an error for a swapper that cannot quote one', async () => {
35
+ const result = await (0, swapper_1.getTradeRates)(exactOutputInput, types_1.SwapperName.Thorchain, deps);
36
+ (0, vitest_1.expect)(result).toBeDefined();
37
+ (0, vitest_1.expect)(result?.isErr()).toBe(true);
38
+ (0, vitest_1.expect)(result?.unwrapErr().code).toEqual(types_1.TradeQuoteError.ExactOutputNotSupported);
39
+ (0, vitest_1.expect)(result?.swapperName).toEqual(types_1.SwapperName.Thorchain);
40
+ });
41
+ (0, vitest_1.it)('skips entirely on a zero buy amount', async () => {
42
+ const result = await (0, swapper_1.getTradeRates)({ ...exactOutputInput, buyAmountCryptoBaseUnit: '0' }, types_1.SwapperName.Thorchain, deps);
43
+ (0, vitest_1.expect)(result).toBeUndefined();
44
+ });
45
+ // The base-unit regex upstream admits padded zeros, so the check can't be a string comparison
46
+ (0, vitest_1.it)('skips entirely on a padded zero buy amount', async () => {
47
+ const result = await (0, swapper_1.getTradeRates)({ ...exactOutputInput, buyAmountCryptoBaseUnit: '00' }, types_1.SwapperName.Thorchain, deps);
48
+ (0, vitest_1.expect)(result).toBeUndefined();
49
+ });
50
+ });
51
+ // Quotes dispatch on the same input shape as rates, so they gate the same way
52
+ (0, vitest_1.describe)('getTradeQuotes on an exact buy amount', () => {
53
+ const exactOutputQuoteInput = {
54
+ ...exactOutputInput,
55
+ receiveAddress: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
56
+ accountNumber: 0,
57
+ quoteOrRate: 'quote',
58
+ };
59
+ (0, vitest_1.it)('reports an error for a swapper that cannot quote one', async () => {
60
+ const result = await (0, swapper_1.getTradeQuotes)(exactOutputQuoteInput, types_1.SwapperName.Thorchain, deps);
61
+ (0, vitest_1.expect)(result).toBeDefined();
62
+ (0, vitest_1.expect)(result?.isErr()).toBe(true);
63
+ (0, vitest_1.expect)(result?.unwrapErr().code).toEqual(types_1.TradeQuoteError.ExactOutputNotSupported);
64
+ (0, vitest_1.expect)(result?.swapperName).toEqual(types_1.SwapperName.Thorchain);
65
+ });
66
+ (0, vitest_1.it)('skips entirely on a zero buy amount', async () => {
67
+ const result = await (0, swapper_1.getTradeQuotes)({ ...exactOutputQuoteInput, buyAmountCryptoBaseUnit: '0' }, types_1.SwapperName.Thorchain, deps);
68
+ (0, vitest_1.expect)(result).toBeUndefined();
69
+ });
70
+ });
@@ -1,3 +1,3 @@
1
- import type { GetTradeQuoteInput, GetTradeRateInput, QuoteResult, RateResult, SwapperDeps, SwapperName } from './types';
2
- export declare const getTradeQuotes: (getTradeQuoteInput: GetTradeQuoteInput, swapperName: SwapperName, deps: SwapperDeps) => Promise<QuoteResult | undefined>;
3
- export declare const getTradeRates: (getTradeRateInput: GetTradeRateInput, swapperName: SwapperName, deps: SwapperDeps, quoteTimeoutMs?: number) => Promise<RateResult | undefined>;
1
+ import type { GetExactOutputTradeQuoteInput, GetExactOutputTradeRateInput, GetTradeQuoteInput, GetTradeRateInput, QuoteResult, RateResult, SwapperDeps, SwapperName } from './types';
2
+ export declare const getTradeQuotes: (getTradeQuoteInput: GetTradeQuoteInput | GetExactOutputTradeQuoteInput, swapperName: SwapperName, deps: SwapperDeps) => Promise<QuoteResult | undefined>;
3
+ export declare const getTradeRates: (getTradeRateInput: GetTradeRateInput | GetExactOutputTradeRateInput, swapperName: SwapperName, deps: SwapperDeps, quoteTimeoutMs?: number) => Promise<RateResult | undefined>;
@@ -2,19 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTradeRates = exports.getTradeQuotes = void 0;
4
4
  const utils_1 = require("@shapeshiftoss/utils");
5
+ const monads_1 = require("@sniptt/monads");
5
6
  const constants_1 = require("./constants");
6
7
  const types_1 = require("./types");
7
8
  const utils_2 = require("./utils");
9
+ const EXACT_OUTPUT_NOT_SUPPORTED_ERROR = (0, utils_2.makeSwapErrorRight)({
10
+ code: types_1.TradeQuoteError.ExactOutputNotSupported,
11
+ message: 'This swapper cannot derive a sell amount from an exact buy amount',
12
+ });
8
13
  const getTradeQuotes = async (getTradeQuoteInput, swapperName, deps) => {
9
14
  if ((0, utils_1.bnOrZero)(getTradeQuoteInput.affiliateBps).lt(0))
10
15
  return;
11
- if (getTradeQuoteInput.sellAmountIncludingProtocolFeesCryptoBaseUnit === '0')
12
- return;
13
16
  const swapper = constants_1.swappers[swapperName];
14
17
  if (swapper === undefined)
15
18
  return;
19
+ // Compared numerically so a padded zero can't slip through as an amount
20
+ const drivingAmount = 'buyAmountCryptoBaseUnit' in getTradeQuoteInput
21
+ ? getTradeQuoteInput.buyAmountCryptoBaseUnit
22
+ : getTradeQuoteInput.sellAmountIncludingProtocolFeesCryptoBaseUnit;
23
+ if ((0, utils_1.bnOrZero)(drivingAmount).isZero())
24
+ return;
25
+ const quotePromise = 'buyAmountCryptoBaseUnit' in getTradeQuoteInput
26
+ ? swapper.getExactOutputTradeQuote?.(getTradeQuoteInput, deps)
27
+ : swapper.getTradeQuote(getTradeQuoteInput, deps);
28
+ if (!quotePromise)
29
+ return { ...(0, monads_1.Err)(EXACT_OUTPUT_NOT_SUPPORTED_ERROR), swapperName };
16
30
  try {
17
- const quote = await (0, utils_1.timeoutMonadic)(swapper.getTradeQuote(getTradeQuoteInput, deps), constants_1.QUOTE_TIMEOUT_MS, constants_1.QUOTE_TIMEOUT_ERROR);
31
+ const quote = await (0, utils_1.timeoutMonadic)(quotePromise, constants_1.QUOTE_TIMEOUT_MS, constants_1.QUOTE_TIMEOUT_ERROR);
18
32
  return {
19
33
  ...quote,
20
34
  swapperName,
@@ -30,13 +44,22 @@ exports.getTradeQuotes = getTradeQuotes;
30
44
  const getTradeRates = async (getTradeRateInput, swapperName, deps, quoteTimeoutMs = constants_1.QUOTE_TIMEOUT_MS) => {
31
45
  if ((0, utils_1.bnOrZero)(getTradeRateInput.affiliateBps).lt(0))
32
46
  return;
33
- if (getTradeRateInput.sellAmountIncludingProtocolFeesCryptoBaseUnit === '0')
34
- return;
35
47
  const swapper = constants_1.swappers[swapperName];
36
48
  if (swapper === undefined)
37
49
  return;
50
+ // Compared numerically so a padded zero can't slip through as an amount
51
+ const drivingAmount = 'buyAmountCryptoBaseUnit' in getTradeRateInput
52
+ ? getTradeRateInput.buyAmountCryptoBaseUnit
53
+ : getTradeRateInput.sellAmountIncludingProtocolFeesCryptoBaseUnit;
54
+ if ((0, utils_1.bnOrZero)(drivingAmount).isZero())
55
+ return;
56
+ const ratePromise = 'buyAmountCryptoBaseUnit' in getTradeRateInput
57
+ ? swapper.getExactOutputTradeRate?.(getTradeRateInput, deps)
58
+ : swapper.getTradeRate(getTradeRateInput, deps);
59
+ if (!ratePromise)
60
+ return { ...(0, monads_1.Err)(EXACT_OUTPUT_NOT_SUPPORTED_ERROR), swapperName };
38
61
  try {
39
- const { timed, original } = (0, utils_1.timeoutMonadicWithOriginal)(swapper.getTradeRate(getTradeRateInput, deps), quoteTimeoutMs, (0, utils_2.makeSwapErrorRight)({
62
+ const { timed, original } = (0, utils_1.timeoutMonadicWithOriginal)(ratePromise, quoteTimeoutMs, (0, utils_2.makeSwapErrorRight)({
40
63
  code: types_1.TradeQuoteError.Timeout,
41
64
  message: `quote timed out after ${quoteTimeoutMs / 1000}s`,
42
65
  }));
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
3
3
  import type { AcrossSwapTx } from './types';
4
4
  type BaseArgs = {
5
5
  swapTx: AcrossSwapTx;
6
+ sellAmountCryptoBaseUnit: string;
6
7
  spenderAddress: string;
7
8
  fallbackNetworkFeeCryptoBaseUnit: string;
8
9
  };
@@ -10,7 +10,7 @@ const utils_2 = require("../../../utils");
10
10
  const evm_1 = require("../../../utils/evm");
11
11
  const solana_1 = require("../../../utils/solana");
12
12
  async function getAcrossStepData(args) {
13
- const { swapTx, sellAsset, spenderAddress, from, type, input, fallbackNetworkFeeCryptoBaseUnit, deps, } = args;
13
+ const { swapTx, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, from, type, input, fallbackNetworkFeeCryptoBaseUnit, deps, } = args;
14
14
  const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
15
15
  switch (swapTx.ecosystem) {
16
16
  case 'evm': {
@@ -25,7 +25,7 @@ async function getAcrossStepData(args) {
25
25
  };
26
26
  const stateOverride = {
27
27
  sellAsset,
28
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
28
+ sellAmountCryptoBaseUnit,
29
29
  spenderAddress,
30
30
  };
31
31
  if (type === 'rate') {
@@ -173,6 +173,7 @@ const getAcrossTradeContext = async ({ input, deps, depositor, recipient, }) =>
173
173
  stepDataArgs: {
174
174
  swapTx: quote.swapTx,
175
175
  sellAsset,
176
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
176
177
  from: depositor,
177
178
  spenderAddress: allowanceContract,
178
179
  fallbackNetworkFeeCryptoBaseUnit: quote.fees.originGas.amount,
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
3
3
  import type { BebopQuoteResponse } from '../types';
4
4
  type BaseArgs = {
5
5
  tx: BebopQuoteResponse['tx'];
6
+ sellAmountCryptoBaseUnit: string;
6
7
  spenderAddress: string;
7
8
  };
8
9
  export type GetBebopStepDataArgs = StepDataArgs<BaseArgs, {
@@ -8,7 +8,7 @@ const viem_1 = require("viem");
8
8
  const utils_2 = require("../../../utils");
9
9
  const evm_1 = require("../../../utils/evm");
10
10
  async function getBebopStepData(args) {
11
- const { tx, spenderAddress, sellAsset, type, input, from, deps } = args;
11
+ const { tx, spenderAddress, sellAsset, sellAmountCryptoBaseUnit, type, input, from, deps } = args;
12
12
  const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
13
13
  const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
14
14
  if (type === 'rate') {
@@ -43,7 +43,7 @@ async function getBebopStepData(args) {
43
43
  supportsEIP1559,
44
44
  stateOverride: {
45
45
  sellAsset,
46
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
46
+ sellAmountCryptoBaseUnit,
47
47
  spenderAddress,
48
48
  },
49
49
  });
@@ -78,6 +78,7 @@ const getBebopTradeContext = async ({ input, deps, from, receiver, }) => {
78
78
  tx: quote.tx,
79
79
  spenderAddress: allowanceContract,
80
80
  sellAsset,
81
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
81
82
  from,
82
83
  deps,
83
84
  },
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
3
3
  import type { DebridgeTx } from './types';
4
4
  type BaseArgs = {
5
5
  tx: DebridgeTx;
6
+ sellAmountCryptoBaseUnit: string;
6
7
  gasLimit: string | undefined;
7
8
  spenderAddress: string;
8
9
  fallbackNetworkFeeCryptoBaseUnit: string | undefined;
@@ -6,7 +6,7 @@ const monads_1 = require("@sniptt/monads");
6
6
  const utils_1 = require("../../../utils");
7
7
  const evm_1 = require("../../../utils/evm");
8
8
  async function getDebridgeStepData(args) {
9
- const { tx, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
9
+ const { tx, sellAmountCryptoBaseUnit, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
10
10
  const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
11
11
  const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
12
12
  const transactionData = {
@@ -19,7 +19,7 @@ async function getDebridgeStepData(args) {
19
19
  };
20
20
  const stateOverride = {
21
21
  sellAsset,
22
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
22
+ sellAmountCryptoBaseUnit,
23
23
  spenderAddress,
24
24
  };
25
25
  if (type === 'rate') {
@@ -84,6 +84,7 @@ const getDebridgeTradeContext = async ({ input, deps, senderAddress, recipientAd
84
84
  protocolFees: quote.protocolFees,
85
85
  stepDataArgs: {
86
86
  tx: quote.tx,
87
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
87
88
  gasLimit: quote.gasLimit,
88
89
  fallbackNetworkFeeCryptoBaseUnit: quote.fallbackNetworkFeeCryptoBaseUnit,
89
90
  sellAsset,
@@ -14,6 +14,8 @@ const oneClickService_1 = require("./utils/oneClickService");
14
14
  exports.nearIntentsApi = {
15
15
  getTradeQuote: (input, deps) => (0, getTradeQuote_1.getTradeQuote)(input, deps),
16
16
  getTradeRate: (input, deps) => (0, getTradeRate_1.getTradeRate)(input, deps),
17
+ getExactOutputTradeQuote: (input, deps) => (0, getTradeQuote_1.getExactOutputTradeQuote)(input, deps),
18
+ getExactOutputTradeRate: (input, deps) => (0, getTradeRate_1.getExactOutputTradeRate)(input, deps),
17
19
  getUnsignedEvmTransaction: evm_1.getUnsignedEvmTransaction,
18
20
  getEvmTransactionFees: evm_1.getEvmTransactionFees,
19
21
  getUnsignedUtxoTransaction: utxo_1.getUnsignedUtxoTransaction,
@@ -1,4 +1,5 @@
1
1
  import type { Result } from '@sniptt/monads';
2
2
  import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types';
3
- import type { NearIntentsTradeQuoteInput } from '../types';
3
+ import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsTradeQuoteInput } from '../types';
4
4
  export declare const getTradeQuote: (input: NearIntentsTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
5
+ export declare const getExactOutputTradeQuote: (input: NearIntentsExactOutputTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote[], SwapErrorRight>>;
@@ -1,37 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTradeQuote = void 0;
3
+ exports.getExactOutputTradeQuote = exports.getTradeQuote = void 0;
4
4
  const monads_1 = require("@sniptt/monads");
5
5
  const utils_1 = require("../../../utils");
6
+ const helpers_1 = require("../../../utils/helpers");
6
7
  const types_1 = require("../types");
7
8
  const getNearIntentsStepData_1 = require("../utils/getNearIntentsStepData");
8
9
  const getNearIntentsTradeContext_1 = require("../utils/getNearIntentsTradeContext");
9
- const helpers_1 = require("../utils/helpers");
10
+ const helpers_2 = require("../utils/helpers");
10
11
  const oneClickService_1 = require("../utils/oneClickService");
11
- const getTradeQuote = async (input, deps) => {
12
- const { sellAsset, buyAsset, accountNumber, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, } = input;
12
+ const getQuote = async (input, deps) => {
13
+ const { sellAsset, buyAsset, accountNumber, affiliateBps } = input;
13
14
  const addresses = (0, utils_1.assertQuoteAddresses)(input);
14
15
  if (addresses.isErr())
15
16
  return (0, monads_1.Err)(addresses.unwrapErr());
16
17
  const { sendAddress, receiveAddress } = addresses.unwrap();
17
18
  (0, oneClickService_1.initializeOneClickService)(deps.config.VITE_NEAR_INTENTS_API_KEY);
18
- const maybeAssets = await (0, helpers_1.resolveNearIntentsAssets)({ sellAsset, buyAsset });
19
+ const amount = (0, helpers_1.getTradeAmount)(input);
20
+ const maybeAssets = await (0, helpers_2.resolveNearIntentsAssets)({ sellAsset, buyAsset });
19
21
  if (maybeAssets.isErr())
20
22
  return (0, monads_1.Err)(maybeAssets.unwrapErr());
21
23
  const { originAsset, destinationAsset } = maybeAssets.unwrap();
22
- const quoteRequest = (0, helpers_1.buildNearIntentsQuoteRequest)({
24
+ const quoteRequest = (0, helpers_2.buildNearIntentsQuoteRequest)({
23
25
  originAsset,
24
26
  destinationAsset,
25
- sellAmountCryptoBaseUnit: sellAmount,
27
+ amount,
26
28
  slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
27
29
  affiliateBps,
28
30
  refundTo: sendAddress,
29
31
  recipient: receiveAddress,
30
32
  refundType: types_1.QuoteRequest.refundType.ORIGIN_CHAIN,
31
33
  recipientType: types_1.QuoteRequest.recipientType.DESTINATION_CHAIN,
32
- deadline: (0, helpers_1.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
34
+ deadline: (0, helpers_2.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
33
35
  });
34
- const maybeQuoteResponse = await (0, helpers_1.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
36
+ const maybeQuoteResponse = await (0, helpers_2.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
35
37
  if (maybeQuoteResponse.isErr())
36
38
  return (0, monads_1.Err)(maybeQuoteResponse.unwrapErr());
37
39
  const { quote } = maybeQuoteResponse.unwrap();
@@ -75,4 +77,7 @@ const getTradeQuote = async (input, deps) => {
75
77
  };
76
78
  return (0, monads_1.Ok)([tradeQuote]);
77
79
  };
80
+ const getTradeQuote = (input, deps) => getQuote(input, deps);
78
81
  exports.getTradeQuote = getTradeQuote;
82
+ const getExactOutputTradeQuote = (input, deps) => getQuote(input, deps);
83
+ exports.getExactOutputTradeQuote = getExactOutputTradeQuote;
@@ -1,4 +1,5 @@
1
1
  import type { Result } from '@sniptt/monads';
2
2
  import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types';
3
- import type { NearIntentsTradeRateInput } from '../types';
3
+ import type { NearIntentsExactOutputTradeRateInput, NearIntentsTradeRateInput } from '../types';
4
4
  export declare const getTradeRate: (input: NearIntentsTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
5
+ export declare const getExactOutputTradeRate: (input: NearIntentsExactOutputTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate[], SwapErrorRight>>;
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTradeRate = void 0;
3
+ exports.getExactOutputTradeRate = exports.getTradeRate = void 0;
4
4
  const monads_1 = require("@sniptt/monads");
5
+ const helpers_1 = require("../../../utils/helpers");
5
6
  const types_1 = require("../types");
6
7
  const getNearIntentsStepData_1 = require("../utils/getNearIntentsStepData");
7
8
  const getNearIntentsTradeContext_1 = require("../utils/getNearIntentsTradeContext");
8
- const helpers_1 = require("../utils/helpers");
9
+ const helpers_2 = require("../utils/helpers");
9
10
  const oneClickService_1 = require("../utils/oneClickService");
10
- const getTradeRate = async (input, deps) => {
11
- const { accountNumber, sellAsset, buyAsset, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, receiveAddress, sendAddress, } = input;
11
+ const getRate = async (input, deps) => {
12
+ const { accountNumber, sellAsset, buyAsset, affiliateBps, receiveAddress, sendAddress } = input;
12
13
  (0, oneClickService_1.initializeOneClickService)(deps.config.VITE_NEAR_INTENTS_API_KEY);
13
- const maybeAssets = await (0, helpers_1.resolveNearIntentsAssets)({ sellAsset, buyAsset });
14
+ const amount = (0, helpers_1.getTradeAmount)(input);
15
+ const maybeAssets = await (0, helpers_2.resolveNearIntentsAssets)({ sellAsset, buyAsset });
14
16
  if (maybeAssets.isErr())
15
17
  return (0, monads_1.Err)(maybeAssets.unwrapErr());
16
18
  const { originAsset, destinationAsset } = maybeAssets.unwrap();
17
- const quoteRequest = (0, helpers_1.buildNearIntentsQuoteRequest)({
19
+ const quoteRequest = (0, helpers_2.buildNearIntentsQuoteRequest)({
18
20
  originAsset,
19
21
  destinationAsset,
20
- sellAmountCryptoBaseUnit: sellAmount,
22
+ amount,
21
23
  slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
22
24
  affiliateBps,
23
25
  refundTo: sendAddress ?? 'check-price',
@@ -28,9 +30,9 @@ const getTradeRate = async (input, deps) => {
28
30
  recipientType: sendAddress
29
31
  ? types_1.QuoteRequest.recipientType.DESTINATION_CHAIN
30
32
  : types_1.QuoteRequest.recipientType.INTENTS,
31
- deadline: (0, helpers_1.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
33
+ deadline: (0, helpers_2.getNearIntentsQuoteDeadline)({ sellAsset, buyAsset }),
32
34
  });
33
- const maybeQuoteResponse = await (0, helpers_1.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
35
+ const maybeQuoteResponse = await (0, helpers_2.fetchNearIntentsQuote)({ quoteRequest, sellAsset });
34
36
  if (maybeQuoteResponse.isErr())
35
37
  return (0, monads_1.Err)(maybeQuoteResponse.unwrapErr());
36
38
  const { quote } = maybeQuoteResponse.unwrap();
@@ -61,4 +63,7 @@ const getTradeRate = async (input, deps) => {
61
63
  };
62
64
  return (0, monads_1.Ok)([tradeRate]);
63
65
  };
66
+ const getTradeRate = (input, deps) => getRate(input, deps);
64
67
  exports.getTradeRate = getTradeRate;
68
+ const getExactOutputTradeRate = (input, deps) => getRate(input, deps);
69
+ exports.getExactOutputTradeRate = getExactOutputTradeRate;
@@ -1,7 +1,9 @@
1
1
  import { KnownChainIds } from '@shapeshiftoss/types';
2
- import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetNearTradeQuoteInput, GetNearTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetStarknetTradeQuoteInput, GetStarknetTradeRateInput, GetSuiTradeQuoteInput, GetSuiTradeRateInput, GetTonTradeQuoteInput, GetTonTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types';
2
+ import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetNearTradeQuoteInput, GetNearTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetStarknetTradeQuoteInput, GetStarknetTradeRateInput, GetSuiTradeQuoteInput, GetSuiTradeRateInput, GetTonTradeQuoteInput, GetTonTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../types';
3
3
  export type NearIntentsTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput | GetSolanaTradeQuoteInput | GetTronTradeQuoteInput | GetSuiTradeQuoteInput | GetStarknetTradeQuoteInput | GetNearTradeQuoteInput | GetTonTradeQuoteInput;
4
4
  export type NearIntentsTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput | GetSuiTradeRateInput | GetStarknetTradeRateInput | GetNearTradeRateInput | GetTonTradeRateInput;
5
+ export type NearIntentsExactOutputTradeQuoteInput = WithExactBuyAmount<NearIntentsTradeQuoteInput>;
6
+ export type NearIntentsExactOutputTradeRateInput = WithExactBuyAmount<NearIntentsTradeRateInput>;
5
7
  export type NearIntentsMetadata = {
6
8
  name: 'nearIntents';
7
9
  depositAddress: string;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const types_1 = require("../types");
5
+ const helpers_1 = require("./helpers");
6
+ const BASE_ARGS = {
7
+ originAsset: 'nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near',
8
+ destinationAsset: 'nep141:btc.omft.near',
9
+ amount: { direction: 'exactIn', cryptoBaseUnit: '65000000' },
10
+ slippageTolerancePercentageDecimal: '0.01',
11
+ affiliateBps: '10',
12
+ refundTo: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
13
+ recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
14
+ refundType: types_1.QuoteRequest.refundType.ORIGIN_CHAIN,
15
+ recipientType: types_1.QuoteRequest.recipientType.DESTINATION_CHAIN,
16
+ deadline: '2026-08-10T23:59:00.000Z',
17
+ };
18
+ const EXACT_OUTPUT_AMOUNT = {
19
+ direction: 'exactOut',
20
+ cryptoBaseUnit: '100000',
21
+ };
22
+ (0, vitest_1.describe)('buildNearIntentsQuoteRequest', () => {
23
+ (0, vitest_1.describe)('exact input', () => {
24
+ (0, vitest_1.it)('requests EXACT_INPUT with the sell amount', () => {
25
+ const request = (0, helpers_1.buildNearIntentsQuoteRequest)(BASE_ARGS);
26
+ (0, vitest_1.expect)(request.swapType).toEqual(types_1.QuoteRequest.swapType.EXACT_INPUT);
27
+ (0, vitest_1.expect)(request.amount).toEqual('65000000');
28
+ });
29
+ (0, vitest_1.it)('passes the requested slippage through untouched', () => {
30
+ const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
31
+ ...BASE_ARGS,
32
+ slippageTolerancePercentageDecimal: '0',
33
+ });
34
+ (0, vitest_1.expect)(request.slippageTolerance).toEqual(0);
35
+ });
36
+ });
37
+ (0, vitest_1.describe)('exact output', () => {
38
+ (0, vitest_1.it)('requests EXACT_OUTPUT with the buy amount', () => {
39
+ const request = (0, helpers_1.buildNearIntentsQuoteRequest)({ ...BASE_ARGS, amount: EXACT_OUTPUT_AMOUNT });
40
+ (0, vitest_1.expect)(request.swapType).toEqual(types_1.QuoteRequest.swapType.EXACT_OUTPUT);
41
+ (0, vitest_1.expect)(request.amount).toEqual('100000');
42
+ });
43
+ // A tighter band is the user's call - the failure mode is a refund, not a loss
44
+ (0, vitest_1.it)('passes a requested zero slippage through untouched, as exact input does', () => {
45
+ const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
46
+ ...BASE_ARGS,
47
+ amount: EXACT_OUTPUT_AMOUNT,
48
+ slippageTolerancePercentageDecimal: '0',
49
+ });
50
+ (0, vitest_1.expect)(request.slippageTolerance).toEqual(0);
51
+ });
52
+ (0, vitest_1.it)('honours a requested slippage', () => {
53
+ const request = (0, helpers_1.buildNearIntentsQuoteRequest)({
54
+ ...BASE_ARGS,
55
+ amount: EXACT_OUTPUT_AMOUNT,
56
+ slippageTolerancePercentageDecimal: '0.05',
57
+ });
58
+ (0, vitest_1.expect)(request.slippageTolerance).toEqual(500);
59
+ });
60
+ });
61
+ });
@@ -1,7 +1,7 @@
1
1
  import type { Asset } from '@shapeshiftoss/types';
2
2
  import type { Result } from '@sniptt/monads';
3
3
  import type { QuoteFeeData, SwapErrorRight, SwapperDeps, TradeCommon, TradeStepCommon } from '../../../types';
4
- import type { NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types';
4
+ import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsExactOutputTradeRateInput, NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types';
5
5
  type NearIntentsTradeContext = {
6
6
  tradeCommon: TradeCommon;
7
7
  stepCommon: Omit<TradeStepCommon, 'feeData'>;
@@ -14,7 +14,7 @@ type NearIntentsTradeContext = {
14
14
  };
15
15
  };
16
16
  export declare const getNearIntentsTradeContext: ({ input, deps, quote, }: {
17
- input: NearIntentsTradeQuoteInput | NearIntentsTradeRateInput;
17
+ input: NearIntentsTradeQuoteInput | NearIntentsTradeRateInput | NearIntentsExactOutputTradeQuoteInput | NearIntentsExactOutputTradeRateInput;
18
18
  deps: SwapperDeps;
19
19
  quote: QuoteResponse['quote'];
20
20
  }) => Result<NearIntentsTradeContext, SwapErrorRight>;
@@ -10,7 +10,7 @@ const types_1 = require("../../../types");
10
10
  const utils_2 = require("../../../utils");
11
11
  const affiliateFee_1 = require("../../../utils/affiliateFee");
12
12
  const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
13
- const { sellAsset, buyAsset, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit, slippageTolerancePercentageDecimal, } = input;
13
+ const { sellAsset, buyAsset, affiliateBps, slippageTolerancePercentageDecimal } = input;
14
14
  if (!quote.depositAddress)
15
15
  return (0, monads_1.Err)((0, utils_2.makeTradeStepBuildFailedErr)('getNearIntentsTradeContext'));
16
16
  const rate = (0, utils_2.getInputOutputRate)({
@@ -19,11 +19,13 @@ const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
19
19
  sellAsset,
20
20
  buyAsset,
21
21
  });
22
+ const isExactOutput = 'buyAmountCryptoBaseUnit' in input;
22
23
  return (0, monads_1.Ok)({
23
24
  tradeCommon: {
24
25
  id: (0, uuid_1.v4)(),
25
26
  rate,
26
27
  swapperName: types_1.SwapperName.NearIntents,
28
+ isExactOutput,
27
29
  affiliateBps,
28
30
  slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
29
31
  (0, constants_1.getDefaultSlippageDecimalPercentageForSwapper)(types_1.SwapperName.NearIntents),
@@ -54,7 +56,7 @@ const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
54
56
  stepDataArgs: {
55
57
  deps,
56
58
  sellAsset,
57
- sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
59
+ sellAmountCryptoBaseUnit: quote.amountIn,
58
60
  depositAddress: quote.depositAddress,
59
61
  },
60
62
  });
@@ -1,7 +1,7 @@
1
1
  import type { Asset } from '@shapeshiftoss/types';
2
2
  import { TxStatus } from '@shapeshiftoss/unchained-client';
3
3
  import type { Result } from '@sniptt/monads';
4
- import type { SwapErrorRight } from '../../../types';
4
+ import type { SwapErrorRight, TradeAmount } from '../../../types';
5
5
  import type { GetExecutionStatusResponse, QuoteResponse } from '../types';
6
6
  import { QuoteRequest } from '../types';
7
7
  export declare const getNearIntentsAsset: ({ nearNetwork, contractAddress, }: {
@@ -20,10 +20,10 @@ export declare const getNearIntentsQuoteDeadline: ({ sellAsset, buyAsset, }: {
20
20
  sellAsset: Asset;
21
21
  buyAsset: Asset;
22
22
  }) => string;
23
- export declare const buildNearIntentsQuoteRequest: ({ originAsset, destinationAsset, sellAmountCryptoBaseUnit, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }: {
23
+ export declare const buildNearIntentsQuoteRequest: ({ originAsset, destinationAsset, amount, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }: {
24
24
  originAsset: string;
25
25
  destinationAsset: string;
26
- sellAmountCryptoBaseUnit: string;
26
+ amount: TradeAmount;
27
27
  slippageTolerancePercentageDecimal: string | undefined;
28
28
  affiliateBps: string;
29
29
  refundTo: string;
@@ -134,29 +134,33 @@ const getNearIntentsQuoteDeadline = ({ sellAsset, buyAsset, }) => {
134
134
  return new Date(Date.now() + deadlineMs).toISOString();
135
135
  };
136
136
  exports.getNearIntentsQuoteDeadline = getNearIntentsQuoteDeadline;
137
- const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, sellAmountCryptoBaseUnit, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }) => ({
138
- dry: false,
139
- swapType: types_2.QuoteRequest.swapType.EXACT_INPUT,
140
- slippageTolerance: slippageTolerancePercentageDecimal
141
- ? (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal).times(10000).toNumber()
142
- : constants_1.DEFAULT_SLIPPAGE_BPS,
143
- originAsset,
144
- destinationAsset,
145
- amount: sellAmountCryptoBaseUnit,
146
- depositType: types_2.QuoteRequest.depositType.ORIGIN_CHAIN,
147
- refundTo,
148
- refundType,
149
- recipient,
150
- recipientType,
151
- deadline,
152
- referral: 'shapeshift',
153
- appFees: [
154
- {
155
- recipient: utils_1.DAO_TREASURY_NEAR,
156
- fee: Number(affiliateBps),
157
- },
158
- ],
159
- });
137
+ const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, amount, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }) => {
138
+ return {
139
+ dry: false,
140
+ swapType: amount.direction === 'exactOut'
141
+ ? types_2.QuoteRequest.swapType.EXACT_OUTPUT
142
+ : types_2.QuoteRequest.swapType.EXACT_INPUT,
143
+ slippageTolerance: slippageTolerancePercentageDecimal
144
+ ? (0, utils_1.bnOrZero)(slippageTolerancePercentageDecimal).times(10000).toNumber()
145
+ : constants_1.DEFAULT_SLIPPAGE_BPS,
146
+ originAsset,
147
+ destinationAsset,
148
+ amount: amount.cryptoBaseUnit,
149
+ depositType: types_2.QuoteRequest.depositType.ORIGIN_CHAIN,
150
+ refundTo,
151
+ refundType,
152
+ recipient,
153
+ recipientType,
154
+ deadline,
155
+ referral: 'shapeshift',
156
+ appFees: [
157
+ {
158
+ recipient: utils_1.DAO_TREASURY_NEAR,
159
+ fee: Number(affiliateBps),
160
+ },
161
+ ],
162
+ };
163
+ };
160
164
  exports.buildNearIntentsQuoteRequest = buildNearIntentsQuoteRequest;
161
165
  // One retry loop for the SDK's flaky WebSocket transport; maps provider errors to swap errors
162
166
  const fetchNearIntentsQuote = async ({ quoteRequest, sellAsset, }) => {
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
3
3
  import type { PortalsTx } from './fetchPortalsTradeOrder';
4
4
  type BaseArgs = {
5
5
  tx: PortalsTx;
6
+ sellAmountCryptoBaseUnit: string;
6
7
  spenderAddress: string;
7
8
  };
8
9
  export type GetPortalsStepDataArgs = StepDataArgs<BaseArgs, {