@shapeshiftoss/swapper 18.1.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 (191) 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/constant.js +2 -1
  7. package/dist/cjs/swappers/AcrossSwapper/endpoints.js +1 -1
  8. package/dist/cjs/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
  9. package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
  10. package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.js +5 -1
  11. package/dist/cjs/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +1 -1
  12. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
  13. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
  14. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
  15. package/dist/cjs/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +2 -0
  16. package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
  17. package/dist/cjs/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
  18. package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
  19. package/dist/cjs/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +1 -0
  20. package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +5 -2
  21. package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
  22. package/dist/cjs/swappers/BebopSwapper/types.d.ts +2 -2
  23. package/dist/cjs/swappers/BebopSwapper/types.js +2 -0
  24. package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
  25. package/dist/cjs/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
  26. package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
  27. package/dist/cjs/swappers/BebopSwapper/utils/getBebopTradeContext.js +2 -0
  28. package/dist/cjs/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
  29. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
  30. package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
  31. package/dist/cjs/swappers/ButterSwap/utils/helpers.js +10 -8
  32. package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
  33. package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -0
  34. package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -1
  35. package/dist/cjs/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
  36. package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
  37. package/dist/cjs/swappers/DebridgeSwapper/constant.js +10 -8
  38. package/dist/cjs/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
  39. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
  40. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
  41. package/dist/cjs/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
  42. package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +5 -1
  43. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
  44. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +21 -9
  45. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
  46. package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +14 -9
  47. package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +3 -1
  48. package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
  49. package/dist/cjs/swappers/NearIntentsSwapper/utils/exactOutput.test.js +61 -0
  50. package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
  51. package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
  52. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
  53. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
  54. package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +11 -0
  55. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
  56. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
  57. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
  58. package/dist/cjs/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
  59. package/dist/cjs/swappers/RelaySwapper/constant.js +4 -3
  60. package/dist/cjs/swappers/RelaySwapper/endpoints.js +12 -2
  61. package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
  62. package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +7 -2
  63. package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
  64. package/dist/cjs/swappers/RelaySwapper/getTradeRate/getTradeRate.js +5 -2
  65. package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.js +1 -1
  66. package/dist/cjs/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
  67. package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
  68. package/dist/cjs/swappers/RelaySwapper/utils/getRelayTradeContext.js +22 -10
  69. package/dist/cjs/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
  70. package/dist/cjs/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +1 -1
  71. package/dist/cjs/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
  72. package/dist/cjs/swappers/RelaySwapper/utils/relayService.js +3 -1
  73. package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
  74. package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +6 -3
  75. package/dist/cjs/swappers/StonfiSwapper/endpoints.js +40 -14
  76. package/dist/cjs/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
  77. package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
  78. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
  79. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
  80. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
  81. package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
  82. package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
  83. package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +1 -0
  84. package/dist/cjs/swappers/ZrxSwapper/types.d.ts +1 -1
  85. package/dist/cjs/swappers/ZrxSwapper/types.js +1 -0
  86. package/dist/cjs/swappers/ZrxSwapper/utils/constants.js +1 -0
  87. package/dist/cjs/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
  88. package/dist/cjs/swappers/ZrxSwapper/utils/helpers.js +5 -0
  89. package/dist/cjs/types.d.ts +22 -2
  90. package/dist/cjs/types.js +2 -0
  91. package/dist/cjs/utils/helpers.d.ts +8 -0
  92. package/dist/cjs/utils/helpers.js +18 -1
  93. package/dist/cjs/utils/helpers.test.js +17 -0
  94. package/dist/cjs/utils/test-data/setupSwapQuote.js +1 -0
  95. package/dist/cjs/utils/thorchain/getThorL1TradeQuote.js +3 -0
  96. package/dist/esm/.tsbuildinfo +1 -1
  97. package/dist/esm/exactOutputFiltering.test.d.ts +1 -0
  98. package/dist/esm/exactOutputFiltering.test.js +68 -0
  99. package/dist/esm/swapper.d.ts +3 -3
  100. package/dist/esm/swapper.js +29 -6
  101. package/dist/esm/swappers/AcrossSwapper/constant.js +4 -3
  102. package/dist/esm/swappers/AcrossSwapper/endpoints.js +2 -2
  103. package/dist/esm/swappers/AcrossSwapper/getTradeQuote/getTradeQuote.js +2 -1
  104. package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +6 -3
  105. package/dist/esm/swappers/AcrossSwapper/utils/acrossService.js +3 -0
  106. package/dist/esm/swappers/AcrossSwapper/utils/fetchAcrossTrade.js +2 -2
  107. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.d.ts +1 -0
  108. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossStepData.js +2 -2
  109. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.d.ts +1 -0
  110. package/dist/esm/swappers/AcrossSwapper/utils/getAcrossTradeContext.js +3 -1
  111. package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
  112. package/dist/esm/swappers/AvnuSwapper/swapperApi/getTradeQuote.js +3 -1
  113. package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.d.ts +1 -0
  114. package/dist/esm/swappers/AvnuSwapper/utils/getAvnuTradeContext.js +2 -1
  115. package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +3 -0
  116. package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -1
  117. package/dist/esm/swappers/BebopSwapper/types.d.ts +2 -2
  118. package/dist/esm/swappers/BebopSwapper/types.js +2 -0
  119. package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.d.ts +1 -0
  120. package/dist/esm/swappers/BebopSwapper/utils/getBebopStepData.js +2 -2
  121. package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.d.ts +1 -0
  122. package/dist/esm/swappers/BebopSwapper/utils/getBebopTradeContext.js +3 -1
  123. package/dist/esm/swappers/BebopSwapper/utils/helpers.d.ts +1 -1
  124. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +2 -0
  125. package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -0
  126. package/dist/esm/swappers/ButterSwap/utils/helpers.js +10 -8
  127. package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +2 -0
  128. package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -0
  129. package/dist/esm/swappers/ChainflipSwapper/constants.js +2 -0
  130. package/dist/esm/swappers/ChainflipSwapper/swapperApi/getTradeQuote.js +2 -0
  131. package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -0
  132. package/dist/esm/swappers/DebridgeSwapper/constant.js +11 -9
  133. package/dist/esm/swappers/DebridgeSwapper/getTradeQuote/getTradeQuote.js +2 -0
  134. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.d.ts +1 -0
  135. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeStepData.js +2 -2
  136. package/dist/esm/swappers/DebridgeSwapper/utils/getDebridgeTradeContext.js +1 -0
  137. package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +7 -3
  138. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.d.ts +2 -1
  139. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +14 -3
  140. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.d.ts +2 -1
  141. package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +7 -3
  142. package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +3 -1
  143. package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.d.ts +1 -0
  144. package/dist/esm/swappers/NearIntentsSwapper/utils/exactOutput.test.js +59 -0
  145. package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.d.ts +2 -2
  146. package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsTradeContext.js +4 -2
  147. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.d.ts +3 -3
  148. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +27 -23
  149. package/dist/esm/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +12 -1
  150. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.d.ts +1 -0
  151. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsStepData.js +3 -3
  152. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.d.ts +1 -0
  153. package/dist/esm/swappers/PortalsSwapper/utils/getPortalsTradeContext.js +7 -1
  154. package/dist/esm/swappers/RelaySwapper/constant.js +6 -5
  155. package/dist/esm/swappers/RelaySwapper/endpoints.js +15 -5
  156. package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.d.ts +2 -1
  157. package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +5 -1
  158. package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.d.ts +2 -1
  159. package/dist/esm/swappers/RelaySwapper/getTradeRate/getTradeRate.js +3 -1
  160. package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.js +2 -2
  161. package/dist/esm/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.js +3 -1
  162. package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.d.ts +2 -2
  163. package/dist/esm/swappers/RelaySwapper/utils/getRelayTradeContext.js +23 -11
  164. package/dist/esm/swappers/RelaySwapper/utils/helpers.d.ts +2 -2
  165. package/dist/esm/swappers/RelaySwapper/utils/notifyTransactionIndexing.js +2 -2
  166. package/dist/esm/swappers/RelaySwapper/utils/relayService.d.ts +6 -3
  167. package/dist/esm/swappers/RelaySwapper/utils/relayService.js +1 -0
  168. package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +5 -0
  169. package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +6 -3
  170. package/dist/esm/swappers/StonfiSwapper/endpoints.js +41 -15
  171. package/dist/esm/swappers/StonfiSwapper/swapperApi/getTradeQuote.js +2 -0
  172. package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +2 -0
  173. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +1 -0
  174. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +2 -2
  175. package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +6 -1
  176. package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +2 -0
  177. package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailQuote.js +2 -0
  178. package/dist/esm/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +2 -1
  179. package/dist/esm/swappers/ZrxSwapper/types.d.ts +1 -1
  180. package/dist/esm/swappers/ZrxSwapper/types.js +1 -0
  181. package/dist/esm/swappers/ZrxSwapper/utils/constants.js +1 -0
  182. package/dist/esm/swappers/ZrxSwapper/utils/helpers.d.ts +1 -1
  183. package/dist/esm/swappers/ZrxSwapper/utils/helpers.js +5 -0
  184. package/dist/esm/types.d.ts +22 -2
  185. package/dist/esm/types.js +2 -0
  186. package/dist/esm/utils/helpers.d.ts +8 -0
  187. package/dist/esm/utils/helpers.js +15 -0
  188. package/dist/esm/utils/helpers.test.js +18 -1
  189. package/dist/esm/utils/test-data/setupSwapQuote.js +1 -0
  190. package/dist/esm/utils/thorchain/getThorL1TradeQuote.js +3 -0
  191. package/package.json +7 -7
@@ -29,6 +29,7 @@ export const getCowSwapTradeQuote = async (input, deps) => {
29
29
  const tradeQuote = {
30
30
  ...tradeCommon,
31
31
  quoteOrRate: 'quote',
32
+ deadline: stepDataArgs.cowswapQuoteResponse.quote.validTo * 1000,
32
33
  receiveAddress,
33
34
  steps: [
34
35
  {
@@ -1,28 +1,30 @@
1
- import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hyperEvmChainId, lineaChainId, mantleChainId, megaethChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, seiChainId, sonicChainId, storyChainId, } from '@shapeshiftoss/caip';
1
+ import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, cronosChainId, ethChainId, flowEvmChainId, gnosisChainId, hyperEvmChainId, lineaChainId, mantleChainId, megaethChainId, monadChainId, optimismChainId, plasmaChainId, polygonChainId, robinhoodChainId, seiChainId, sonicChainId, storyChainId, } from '@shapeshiftoss/caip';
2
2
  import invert from 'lodash/invert';
3
3
  import { zeroAddress } from 'viem';
4
+ import { arbitrum, avalanche, base, bsc, linea, mainnet as ethereum, optimism, polygon, robinhood, } from 'viem/chains';
4
5
  export const chainIdToDebridgeChainId = {
5
- [ethChainId]: 1,
6
- [optimismChainId]: 10,
7
- [bscChainId]: 56,
6
+ [ethChainId]: ethereum.id,
7
+ [optimismChainId]: optimism.id,
8
+ [bscChainId]: bsc.id,
8
9
  [gnosisChainId]: 100000002,
9
- [polygonChainId]: 137,
10
+ [polygonChainId]: polygon.id,
10
11
  [monadChainId]: 100000030,
11
12
  [hyperEvmChainId]: 100000022,
12
13
  [seiChainId]: 100000027,
13
- [baseChainId]: 8453,
14
+ [baseChainId]: base.id,
14
15
  [plasmaChainId]: 100000028,
15
- [arbitrumChainId]: 42161,
16
- [avalancheChainId]: 43114,
16
+ [arbitrumChainId]: arbitrum.id,
17
+ [avalancheChainId]: avalanche.id,
17
18
  [mantleChainId]: 100000023,
18
19
  [cronosChainId]: 100000019,
19
20
  [berachainChainId]: 100000020,
20
- [lineaChainId]: 59144,
21
+ [lineaChainId]: linea.id,
21
22
  [bobChainId]: 100000021,
22
23
  [sonicChainId]: 100000014,
23
24
  [storyChainId]: 100000013,
24
25
  [flowEvmChainId]: 100000009,
25
26
  [megaethChainId]: 100000031,
27
+ [robinhoodChainId]: robinhood.id,
26
28
  };
27
29
  export const debridgeChainIdToChainId = invert(chainIdToDebridgeChainId);
28
30
  export const DEBRIDGE_SUPPORTED_CHAIN_IDS = Object.keys(chainIdToDebridgeChainId);
@@ -1,5 +1,6 @@
1
1
  import { Err, Ok } from '@sniptt/monads';
2
2
  import { assertQuoteAddresses } from '../../../utils/index.js';
3
+ import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
3
4
  import { getDebridgeStepData } from '../utils/getDebridgeStepData.js';
4
5
  import { getDebridgeTradeContext } from '../utils/getDebridgeTradeContext.js';
5
6
  export const getTradeQuote = async (input, deps) => {
@@ -23,6 +24,7 @@ export const getTradeQuote = async (input, deps) => {
23
24
  const tradeQuote = {
24
25
  ...tradeCommon,
25
26
  quoteOrRate: 'quote',
27
+ deadline: Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
26
28
  receiveAddress,
27
29
  steps: [
28
30
  {
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.j
3
3
  import type { DebridgeTx } from './types.js';
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;
@@ -3,7 +3,7 @@ import { Err, Ok } from '@sniptt/monads';
3
3
  import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
4
4
  import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
5
5
  export async function getDebridgeStepData(args) {
6
- const { tx, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
6
+ const { tx, sellAmountCryptoBaseUnit, gasLimit, spenderAddress, fallbackNetworkFeeCryptoBaseUnit, sellAsset, from, type, input, deps, } = args;
7
7
  const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
8
8
  const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
9
9
  const transactionData = {
@@ -16,7 +16,7 @@ export async function getDebridgeStepData(args) {
16
16
  };
17
17
  const stateOverride = {
18
18
  sellAsset,
19
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
19
+ sellAmountCryptoBaseUnit,
20
20
  spenderAddress,
21
21
  };
22
22
  if (type === 'rate') {
@@ -81,6 +81,7 @@ export const getDebridgeTradeContext = async ({ input, deps, senderAddress, reci
81
81
  protocolFees: quote.protocolFees,
82
82
  stepDataArgs: {
83
83
  tx: quote.tx,
84
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
84
85
  gasLimit: quote.gasLimit,
85
86
  fallbackNetworkFeeCryptoBaseUnit: quote.fallbackNetworkFeeCryptoBaseUnit,
86
87
  sellAsset,
@@ -4,13 +4,15 @@ import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/ev
4
4
  import { getSolanaTransactionFees, getUnsignedSolanaTransaction } from '../../utils/solana/index.js';
5
5
  import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
6
6
  import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
7
- import { getTradeQuote } from './swapperApi/getTradeQuote.js';
8
- import { getTradeRate } from './swapperApi/getTradeRate.js';
7
+ import { getExactOutputTradeQuote, getTradeQuote } from './swapperApi/getTradeQuote.js';
8
+ import { getExactOutputTradeRate, getTradeRate } from './swapperApi/getTradeRate.js';
9
9
  import { getNearIntentsStatusMessage, mapNearIntentsStatus } from './utils/helpers.js';
10
10
  import { initializeOneClickService, OneClickService } from './utils/oneClickService.js';
11
11
  export const nearIntentsApi = {
12
12
  getTradeQuote: (input, deps) => getTradeQuote(input, deps),
13
13
  getTradeRate: (input, deps) => getTradeRate(input, deps),
14
+ getExactOutputTradeQuote: (input, deps) => getExactOutputTradeQuote(input, deps),
15
+ getExactOutputTradeRate: (input, deps) => getExactOutputTradeRate(input, deps),
14
16
  getUnsignedEvmTransaction,
15
17
  getEvmTransactionFees,
16
18
  getUnsignedUtxoTransaction,
@@ -163,7 +165,9 @@ export const nearIntentsApi = {
163
165
  const message = getNearIntentsStatusMessage(statusResponse.status);
164
166
  // Extract buyTxHash from destination chain transactions
165
167
  const buyTxHash = statusResponse.swapDetails?.destinationChainTxHashes?.[0]?.hash;
166
- const actualBuyAmountCryptoBaseUnit = statusResponse.swapDetails?.amountOut;
168
+ // amountOut is only meaningful destination-denominated on terminal success - in-flight and
169
+ // refund states may carry settlement-internal or refund values
170
+ const actualBuyAmountCryptoBaseUnit = statusResponse.status === 'SUCCESS' ? statusResponse.swapDetails?.amountOut : undefined;
167
171
  return {
168
172
  status: txStatus,
169
173
  buyTxHash,
@@ -1,4 +1,5 @@
1
1
  import type { Result } from '@sniptt/monads';
2
2
  import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
3
- import type { NearIntentsTradeQuoteInput } from '../types.js';
3
+ import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsTradeQuoteInput } from '../types.js';
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,17 +1,19 @@
1
1
  import { Err, Ok } from '@sniptt/monads';
2
2
  import { assertQuoteAddresses } from '../../../utils/index.js';
3
+ import { getTradeAmount } from '../../../utils/helpers.js';
3
4
  import { QuoteRequest } from '../types.js';
4
5
  import { getNearIntentsStepData } from '../utils/getNearIntentsStepData.js';
5
6
  import { getNearIntentsTradeContext } from '../utils/getNearIntentsTradeContext.js';
6
7
  import { buildNearIntentsQuoteRequest, fetchNearIntentsQuote, getNearIntentsQuoteDeadline, resolveNearIntentsAssets, } from '../utils/helpers.js';
7
8
  import { initializeOneClickService } from '../utils/oneClickService.js';
8
- export const getTradeQuote = async (input, deps) => {
9
- const { sellAsset, buyAsset, accountNumber, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, } = input;
9
+ const getQuote = async (input, deps) => {
10
+ const { sellAsset, buyAsset, accountNumber, affiliateBps } = input;
10
11
  const addresses = assertQuoteAddresses(input);
11
12
  if (addresses.isErr())
12
13
  return Err(addresses.unwrapErr());
13
14
  const { sendAddress, receiveAddress } = addresses.unwrap();
14
15
  initializeOneClickService(deps.config.VITE_NEAR_INTENTS_API_KEY);
16
+ const amount = getTradeAmount(input);
15
17
  const maybeAssets = await resolveNearIntentsAssets({ sellAsset, buyAsset });
16
18
  if (maybeAssets.isErr())
17
19
  return Err(maybeAssets.unwrapErr());
@@ -19,7 +21,7 @@ export const getTradeQuote = async (input, deps) => {
19
21
  const quoteRequest = buildNearIntentsQuoteRequest({
20
22
  originAsset,
21
23
  destinationAsset,
22
- sellAmountCryptoBaseUnit: sellAmount,
24
+ amount,
23
25
  slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
24
26
  affiliateBps,
25
27
  refundTo: sendAddress,
@@ -45,9 +47,16 @@ export const getTradeQuote = async (input, deps) => {
45
47
  if (maybeStepData.isErr())
46
48
  return Err(maybeStepData.unwrapErr());
47
49
  const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
50
+ const requestDeadlineMs = Date.parse(quoteRequest.deadline);
51
+ const responseDeadlineMs = Date.parse(quote.deadline ?? '');
48
52
  const tradeQuote = {
49
53
  ...tradeCommon,
50
54
  quoteOrRate: 'quote',
55
+ // Deposits mined after our requested refund deadline refund instead of executing as quoted;
56
+ // the response deadline (when the deposit address goes inactive, ~72h) only binds if tighter
57
+ deadline: Number.isFinite(responseDeadlineMs)
58
+ ? Math.min(requestDeadlineMs, responseDeadlineMs)
59
+ : requestDeadlineMs,
51
60
  receiveAddress,
52
61
  steps: [
53
62
  {
@@ -65,3 +74,5 @@ export const getTradeQuote = async (input, deps) => {
65
74
  };
66
75
  return Ok([tradeQuote]);
67
76
  };
77
+ export const getTradeQuote = (input, deps) => getQuote(input, deps);
78
+ export const getExactOutputTradeQuote = (input, deps) => getQuote(input, deps);
@@ -1,4 +1,5 @@
1
1
  import type { Result } from '@sniptt/monads';
2
2
  import type { SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
3
- import type { NearIntentsTradeRateInput } from '../types.js';
3
+ import type { NearIntentsExactOutputTradeRateInput, NearIntentsTradeRateInput } from '../types.js';
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,12 +1,14 @@
1
1
  import { Err, Ok } from '@sniptt/monads';
2
+ import { getTradeAmount } from '../../../utils/helpers.js';
2
3
  import { QuoteRequest } from '../types.js';
3
4
  import { getNearIntentsStepData } from '../utils/getNearIntentsStepData.js';
4
5
  import { getNearIntentsTradeContext } from '../utils/getNearIntentsTradeContext.js';
5
6
  import { buildNearIntentsQuoteRequest, fetchNearIntentsQuote, getNearIntentsQuoteDeadline, resolveNearIntentsAssets, } from '../utils/helpers.js';
6
7
  import { initializeOneClickService } from '../utils/oneClickService.js';
7
- export const getTradeRate = async (input, deps) => {
8
- const { accountNumber, sellAsset, buyAsset, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit: sellAmount, receiveAddress, sendAddress, } = input;
8
+ const getRate = async (input, deps) => {
9
+ const { accountNumber, sellAsset, buyAsset, affiliateBps, receiveAddress, sendAddress } = input;
9
10
  initializeOneClickService(deps.config.VITE_NEAR_INTENTS_API_KEY);
11
+ const amount = getTradeAmount(input);
10
12
  const maybeAssets = await resolveNearIntentsAssets({ sellAsset, buyAsset });
11
13
  if (maybeAssets.isErr())
12
14
  return Err(maybeAssets.unwrapErr());
@@ -14,7 +16,7 @@ export const getTradeRate = async (input, deps) => {
14
16
  const quoteRequest = buildNearIntentsQuoteRequest({
15
17
  originAsset,
16
18
  destinationAsset,
17
- sellAmountCryptoBaseUnit: sellAmount,
19
+ amount,
18
20
  slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal,
19
21
  affiliateBps,
20
22
  refundTo: sendAddress ?? 'check-price',
@@ -58,3 +60,5 @@ export const getTradeRate = async (input, deps) => {
58
60
  };
59
61
  return Ok([tradeRate]);
60
62
  };
63
+ export const getTradeRate = (input, deps) => getRate(input, deps);
64
+ export const getExactOutputTradeRate = (input, deps) => getRate(input, deps);
@@ -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.js';
2
+ import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetNearTradeQuoteInput, GetNearTradeRateInput, GetSolanaTradeQuoteInput, GetSolanaTradeRateInput, GetStarknetTradeQuoteInput, GetStarknetTradeRateInput, GetSuiTradeQuoteInput, GetSuiTradeRateInput, GetTonTradeQuoteInput, GetTonTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput, WithExactBuyAmount } from '../../types.js';
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,59 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { QuoteRequest } from '../types.js';
3
+ import { buildNearIntentsQuoteRequest } from './helpers.js';
4
+ const BASE_ARGS = {
5
+ originAsset: 'nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near',
6
+ destinationAsset: 'nep141:btc.omft.near',
7
+ amount: { direction: 'exactIn', cryptoBaseUnit: '65000000' },
8
+ slippageTolerancePercentageDecimal: '0.01',
9
+ affiliateBps: '10',
10
+ refundTo: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
11
+ recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
12
+ refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
13
+ recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
14
+ deadline: '2026-08-10T23:59:00.000Z',
15
+ };
16
+ const EXACT_OUTPUT_AMOUNT = {
17
+ direction: 'exactOut',
18
+ cryptoBaseUnit: '100000',
19
+ };
20
+ describe('buildNearIntentsQuoteRequest', () => {
21
+ describe('exact input', () => {
22
+ it('requests EXACT_INPUT with the sell amount', () => {
23
+ const request = buildNearIntentsQuoteRequest(BASE_ARGS);
24
+ expect(request.swapType).toEqual(QuoteRequest.swapType.EXACT_INPUT);
25
+ expect(request.amount).toEqual('65000000');
26
+ });
27
+ it('passes the requested slippage through untouched', () => {
28
+ const request = buildNearIntentsQuoteRequest({
29
+ ...BASE_ARGS,
30
+ slippageTolerancePercentageDecimal: '0',
31
+ });
32
+ expect(request.slippageTolerance).toEqual(0);
33
+ });
34
+ });
35
+ describe('exact output', () => {
36
+ it('requests EXACT_OUTPUT with the buy amount', () => {
37
+ const request = buildNearIntentsQuoteRequest({ ...BASE_ARGS, amount: EXACT_OUTPUT_AMOUNT });
38
+ expect(request.swapType).toEqual(QuoteRequest.swapType.EXACT_OUTPUT);
39
+ expect(request.amount).toEqual('100000');
40
+ });
41
+ // A tighter band is the user's call - the failure mode is a refund, not a loss
42
+ it('passes a requested zero slippage through untouched, as exact input does', () => {
43
+ const request = buildNearIntentsQuoteRequest({
44
+ ...BASE_ARGS,
45
+ amount: EXACT_OUTPUT_AMOUNT,
46
+ slippageTolerancePercentageDecimal: '0',
47
+ });
48
+ expect(request.slippageTolerance).toEqual(0);
49
+ });
50
+ it('honours a requested slippage', () => {
51
+ const request = buildNearIntentsQuoteRequest({
52
+ ...BASE_ARGS,
53
+ amount: EXACT_OUTPUT_AMOUNT,
54
+ slippageTolerancePercentageDecimal: '0.05',
55
+ });
56
+ expect(request.slippageTolerance).toEqual(500);
57
+ });
58
+ });
59
+ });
@@ -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.js';
4
- import type { NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types.js';
4
+ import type { NearIntentsExactOutputTradeQuoteInput, NearIntentsExactOutputTradeRateInput, NearIntentsTradeQuoteInput, NearIntentsTradeRateInput, QuoteResponse } from '../types.js';
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>;
@@ -7,7 +7,7 @@ import { SwapperName } from '../../../types.js';
7
7
  import { getInputOutputRate, makeTradeStepBuildFailedErr } from '../../../utils/index.js';
8
8
  import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
9
9
  export const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
10
- const { sellAsset, buyAsset, affiliateBps, sellAmountIncludingProtocolFeesCryptoBaseUnit, slippageTolerancePercentageDecimal, } = input;
10
+ const { sellAsset, buyAsset, affiliateBps, slippageTolerancePercentageDecimal } = input;
11
11
  if (!quote.depositAddress)
12
12
  return Err(makeTradeStepBuildFailedErr('getNearIntentsTradeContext'));
13
13
  const rate = getInputOutputRate({
@@ -16,11 +16,13 @@ export const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
16
16
  sellAsset,
17
17
  buyAsset,
18
18
  });
19
+ const isExactOutput = 'buyAmountCryptoBaseUnit' in input;
19
20
  return Ok({
20
21
  tradeCommon: {
21
22
  id: uuid(),
22
23
  rate,
23
24
  swapperName: SwapperName.NearIntents,
25
+ isExactOutput,
24
26
  affiliateBps,
25
27
  slippageTolerancePercentageDecimal: slippageTolerancePercentageDecimal ??
26
28
  getDefaultSlippageDecimalPercentageForSwapper(SwapperName.NearIntents),
@@ -51,7 +53,7 @@ export const getNearIntentsTradeContext = ({ input, deps, quote, }) => {
51
53
  stepDataArgs: {
52
54
  deps,
53
55
  sellAsset,
54
- sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
56
+ sellAmountCryptoBaseUnit: quote.amountIn,
55
57
  depositAddress: quote.depositAddress,
56
58
  },
57
59
  });
@@ -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.js';
4
+ import type { SwapErrorRight, TradeAmount } from '../../../types.js';
5
5
  import type { GetExecutionStatusResponse, QuoteResponse } from '../types.js';
6
6
  import { QuoteRequest } from '../types.js';
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;
@@ -127,29 +127,33 @@ export const getNearIntentsQuoteDeadline = ({ sellAsset, buyAsset, }) => {
127
127
  : DEFAULT_QUOTE_DEADLINE_MS;
128
128
  return new Date(Date.now() + deadlineMs).toISOString();
129
129
  };
130
- export const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, sellAmountCryptoBaseUnit, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }) => ({
131
- dry: false,
132
- swapType: QuoteRequest.swapType.EXACT_INPUT,
133
- slippageTolerance: slippageTolerancePercentageDecimal
134
- ? bnOrZero(slippageTolerancePercentageDecimal).times(10000).toNumber()
135
- : DEFAULT_SLIPPAGE_BPS,
136
- originAsset,
137
- destinationAsset,
138
- amount: sellAmountCryptoBaseUnit,
139
- depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
140
- refundTo,
141
- refundType,
142
- recipient,
143
- recipientType,
144
- deadline,
145
- referral: 'shapeshift',
146
- appFees: [
147
- {
148
- recipient: DAO_TREASURY_NEAR,
149
- fee: Number(affiliateBps),
150
- },
151
- ],
152
- });
130
+ export const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, amount, slippageTolerancePercentageDecimal, affiliateBps, refundTo, recipient, refundType, recipientType, deadline, }) => {
131
+ return {
132
+ dry: false,
133
+ swapType: amount.direction === 'exactOut'
134
+ ? QuoteRequest.swapType.EXACT_OUTPUT
135
+ : QuoteRequest.swapType.EXACT_INPUT,
136
+ slippageTolerance: slippageTolerancePercentageDecimal
137
+ ? bnOrZero(slippageTolerancePercentageDecimal).times(10000).toNumber()
138
+ : DEFAULT_SLIPPAGE_BPS,
139
+ originAsset,
140
+ destinationAsset,
141
+ amount: amount.cryptoBaseUnit,
142
+ depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
143
+ refundTo,
144
+ refundType,
145
+ recipient,
146
+ recipientType,
147
+ deadline,
148
+ referral: 'shapeshift',
149
+ appFees: [
150
+ {
151
+ recipient: DAO_TREASURY_NEAR,
152
+ fee: Number(affiliateBps),
153
+ },
154
+ ],
155
+ };
156
+ };
153
157
  // One retry loop for the SDK's flaky WebSocket transport; maps provider errors to swap errors
154
158
  export const fetchNearIntentsQuote = async ({ quoteRequest, sellAsset, }) => {
155
159
  const maxRetries = 3;
@@ -2,7 +2,7 @@ import { BigNumber, bn } from '@shapeshiftoss/utils';
2
2
  import { Err, Ok } from '@sniptt/monads';
3
3
  import { TradeQuoteError } from '../../../types.js';
4
4
  import { assertQuoteAddresses, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
5
- import { getTreasuryAddressFromChainId } from '../../../utils/helpers.js';
5
+ import { FALLBACK_QUOTE_DEADLINE_MS, getTreasuryAddressFromChainId, normalizeEpochToMs, } from '../../../utils/helpers.js';
6
6
  import { fetchPortalsTradeOrder, PortalsError } from '../utils/fetchPortalsTradeOrder.js';
7
7
  import { getPortalsStepData } from '../utils/getPortalsStepData.js';
8
8
  import { getPortalsTradeContext } from '../utils/getPortalsTradeContext.js';
@@ -125,9 +125,20 @@ export const getPortalsTradeQuote = async (input, deps) => {
125
125
  if (maybeStepData.isErr())
126
126
  return Err(maybeStepData.unwrapErr());
127
127
  const { transactionData, networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
128
+ // Nullable in practice (live validated orders return null) - numeric or ISO when supplied
129
+ const expiryMs = (() => {
130
+ if (!orderContext.expiry)
131
+ return undefined;
132
+ const numeric = Number(orderContext.expiry);
133
+ if (Number.isFinite(numeric))
134
+ return normalizeEpochToMs(numeric);
135
+ const parsed = Date.parse(orderContext.expiry);
136
+ return Number.isNaN(parsed) ? undefined : parsed;
137
+ })();
128
138
  const tradeQuote = {
129
139
  ...tradeCommon,
130
140
  quoteOrRate: 'quote',
141
+ deadline: expiryMs ?? Date.now() + FALLBACK_QUOTE_DEADLINE_MS,
131
142
  receiveAddress,
132
143
  steps: [
133
144
  {
@@ -3,6 +3,7 @@ import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.j
3
3
  import type { PortalsTx } from './fetchPortalsTradeOrder.js';
4
4
  type BaseArgs = {
5
5
  tx: PortalsTx;
6
+ sellAmountCryptoBaseUnit: string;
6
7
  spenderAddress: string;
7
8
  };
8
9
  export type GetPortalsStepDataArgs = StepDataArgs<BaseArgs, {
@@ -4,7 +4,7 @@ import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
4
4
  import { estimateGasWithStateOverride, getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
5
5
  import { fetchPortalsTradeEstimate } from './fetchPortalsTradeOrder.js';
6
6
  export async function getPortalsStepData(args) {
7
- const { tx, sellAsset, spenderAddress, input, deps } = args;
7
+ const { tx, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, input, deps } = args;
8
8
  const adapter = deps.assertGetEvmChainAdapter(sellAsset.chainId);
9
9
  const supportsEIP1559 = 'supportsEIP1559' in input ? input.supportsEIP1559 : false;
10
10
  if (args.type === 'rate') {
@@ -15,7 +15,7 @@ export async function getPortalsStepData(args) {
15
15
  try {
16
16
  const gasLimit = await estimateGasWithStateOverride({
17
17
  sellAsset,
18
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
18
+ sellAmountCryptoBaseUnit,
19
19
  from: tx.from,
20
20
  spenderAddress,
21
21
  to: tx.to,
@@ -65,7 +65,7 @@ export async function getPortalsStepData(args) {
65
65
  supportsEIP1559,
66
66
  stateOverride: {
67
67
  sellAsset,
68
- sellAmountCryptoBaseUnit: input.sellAmountIncludingProtocolFeesCryptoBaseUnit,
68
+ sellAmountCryptoBaseUnit,
69
69
  spenderAddress,
70
70
  },
71
71
  });
@@ -10,6 +10,7 @@ type PortalsTradeContext = {
10
10
  stepDataArgs: {
11
11
  deps: SwapperDeps;
12
12
  sellAsset: Asset;
13
+ sellAmountCryptoBaseUnit: string;
13
14
  spenderAddress: string;
14
15
  tx: PortalsTx;
15
16
  };
@@ -74,6 +74,12 @@ export const getPortalsTradeContext = ({ input, deps, sellChainId, inputToken, o
74
74
  }),
75
75
  },
76
76
  protocolFees,
77
- stepDataArgs: { deps, sellAsset, spenderAddress: allowanceContract, tx },
77
+ stepDataArgs: {
78
+ deps,
79
+ sellAsset,
80
+ sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
81
+ spenderAddress: allowanceContract,
82
+ tx,
83
+ },
78
84
  });
79
85
  };
@@ -1,7 +1,7 @@
1
- import { abstractChainId, arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, etherealChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, scrollChainId, seiChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, tronChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
1
+ import { abstractChainId, arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, blastChainId, bobChainId, bscChainId, btcChainId, celoChainId, cronosChainId, ethChainId, etherealChainId, flowEvmChainId, gnosisChainId, hemiChainId, hyperEvmChainId, inkChainId, katanaChainId, lineaChainId, mantleChainId, megaethChainId, modeChainId, monadChainId, optimismChainId, plasmaChainId, plumeChainId, polygonChainId, robinhoodChainId, scrollChainId, seiChainId, solanaChainId, soneiumChainId, sonicChainId, storyChainId, tronChainId, unichainChainId, worldChainChainId, zkSyncEraChainId, } from '@shapeshiftoss/caip';
2
2
  import invert from 'lodash/invert';
3
3
  import { zeroAddress } from 'viem';
4
- import { arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, flowMainnet, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, mode, monad, optimism, plasma, plumeMainnet, polygon, scroll, sei, soneium, sonic, story, unichain, worldchain, zksync, } from 'viem/chains';
4
+ import { abstract, arbitrum, avalanche, base, berachain, blast, bob, bsc, celo, cronos, flowMainnet, gnosis, hemi, hyperEvm, ink, katana, linea, mainnet as ethereum, mantle, megaeth, mode, monad, optimism, plasma, plumeMainnet, polygon, robinhood, scroll, sei, soneium, sonic, story, tron, unichain, worldchain, zksync, } from 'viem/chains';
5
5
  import { TradeQuoteError } from '../../types.js';
6
6
  import { RelayErrorCode } from './utils/types.js';
7
7
  // https://docs.relay.link/resources/supported-chains
@@ -16,12 +16,12 @@ export const chainIdToRelayChainId = {
16
16
  [gnosisChainId]: gnosis.id,
17
17
  [avalancheChainId]: avalanche.id,
18
18
  [bscChainId]: bsc.id,
19
- [tronChainId]: 728126428,
19
+ [tronChainId]: tron.id,
20
20
  [monadChainId]: monad.id,
21
21
  [hyperEvmChainId]: hyperEvm.id,
22
22
  [mantleChainId]: mantle.id,
23
23
  [inkChainId]: ink.id,
24
- [megaethChainId]: 4326,
24
+ [megaethChainId]: megaeth.id,
25
25
  [plasmaChainId]: plasma.id,
26
26
  [katanaChainId]: katana.id,
27
27
  [etherealChainId]: 5064014,
@@ -43,7 +43,8 @@ export const chainIdToRelayChainId = {
43
43
  [modeChainId]: mode.id,
44
44
  [soneiumChainId]: soneium.id,
45
45
  [seiChainId]: sei.id,
46
- [abstractChainId]: 2741,
46
+ [abstractChainId]: abstract.id,
47
+ [robinhoodChainId]: robinhood.id,
47
48
  };
48
49
  export var RelayStatusMessage;
49
50
  (function (RelayStatusMessage) {
@@ -6,11 +6,11 @@ import { getUnsignedSolanaTransaction } from '../../utils/solana/getUnsignedSola
6
6
  import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
7
7
  import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
8
8
  import { chainIdToRelayChainId } from './constant.js';
9
- import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
10
- import { getTradeRate } from './getTradeRate/getTradeRate.js';
9
+ import { getExactOutputTradeQuote, getTradeQuote } from './getTradeQuote/getTradeQuote.js';
10
+ import { getExactOutputTradeRate, getTradeRate } from './getTradeRate/getTradeRate.js';
11
11
  import { getLatestRelayStatusMessage } from './utils/getLatestRelayStatusMessage.js';
12
12
  import { notifyTransactionIndexing } from './utils/notifyTransactionIndexing.js';
13
- import { relayService } from './utils/relayService.js';
13
+ import { getRelayRequestConfig, relayService } from './utils/relayService.js';
14
14
  // Keep track of the trades we already notified the relay indexer about
15
15
  const txIndexingMap = new Map();
16
16
  export const relayApi = {
@@ -20,6 +20,12 @@ export const relayApi = {
20
20
  getTradeRate: (input, deps) => {
21
21
  return getTradeRate(input, deps, chainIdToRelayChainId);
22
22
  },
23
+ getExactOutputTradeQuote: (input, deps) => {
24
+ return getExactOutputTradeQuote(input, deps, chainIdToRelayChainId);
25
+ },
26
+ getExactOutputTradeRate: (input, deps) => {
27
+ return getExactOutputTradeRate(input, deps, chainIdToRelayChainId);
28
+ },
23
29
  getEvmTransactionFees,
24
30
  getUnsignedEvmTransaction,
25
31
  getUnsignedUtxoTransaction,
@@ -61,7 +67,7 @@ export const relayApi = {
61
67
  // relay.link tracks the swap by its origin chain transaction
62
68
  const swapperTxId = txHash;
63
69
  const swapperTxLink = `https://relay.link/transaction/${txHash}`;
64
- const maybeStatusResponse = await relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v2?requestId=${relayMetadata.relayId}`);
70
+ const maybeStatusResponse = await relayService.get(`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`, getRelayRequestConfig(config));
65
71
  if (maybeStatusResponse.isErr()) {
66
72
  return {
67
73
  buyTxHash: undefined,
@@ -76,9 +82,13 @@ export const relayApi = {
76
82
  switch (statusResponse.status) {
77
83
  case 'success':
78
84
  return TxStatus.Confirmed;
85
+ case 'waiting':
86
+ case 'delayed':
79
87
  case 'pending':
88
+ case 'depositing':
89
+ case 'submitted':
80
90
  return TxStatus.Pending;
81
- case 'failed':
91
+ case 'failure':
82
92
  case 'refund':
83
93
  return TxStatus.Failed;
84
94
  default:
@@ -1,5 +1,6 @@
1
1
  import type { Result } from '@sniptt/monads';
2
2
  import type { SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
3
3
  import type { chainIdToRelayChainId as relayChainMapImplementation } from '../constant.js';
4
- import type { RelayTradeQuoteInput } from '../utils/types.js';
4
+ import type { RelayExactOutputTradeQuoteInput, RelayTradeQuoteInput } from '../utils/types.js';
5
5
  export declare const getTradeQuote: (input: RelayTradeQuoteInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeQuote[], SwapErrorRight>>;
6
+ export declare const getExactOutputTradeQuote: (input: RelayExactOutputTradeQuoteInput, deps: SwapperDeps, relayChainMap: typeof relayChainMapImplementation) => Promise<Result<TradeQuote[], SwapErrorRight>>;