@shapeshiftoss/swapper 20.1.1 → 20.3.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 (213) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
  3. package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
  4. package/dist/cjs/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
  5. package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +10 -1
  6. package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +2 -33
  7. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
  8. package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
  9. package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +3 -3
  10. package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
  11. package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +8 -5
  12. package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
  13. package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +30 -34
  14. package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
  15. package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +117 -0
  16. package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
  17. package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
  18. package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +36 -31
  19. package/dist/cjs/swappers/ButterSwap/ButterSwap.js +0 -3
  20. package/dist/cjs/swappers/ButterSwap/endpoints.js +0 -3
  21. package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
  22. package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +0 -51
  23. package/dist/cjs/swappers/ButterSwap/types.d.ts +3 -14
  24. package/dist/cjs/swappers/ButterSwap/utils/constants.d.ts +2 -0
  25. package/dist/cjs/swappers/ButterSwap/utils/constants.js +4 -1
  26. package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
  27. package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
  28. package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +115 -73
  29. package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -4
  30. package/dist/cjs/swappers/ButterSwap/xhr.js +3 -3
  31. package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +3 -19
  32. package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
  33. package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.js +31 -12
  34. package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
  35. package/dist/cjs/swappers/NearIntentsSwapper/constants.js +3 -1
  36. package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
  37. package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +1 -1
  38. package/dist/cjs/swappers/RelaySwapper/constant.d.ts +1 -1
  39. package/dist/cjs/swappers/RelaySwapper/constant.js +3 -2
  40. package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
  41. package/dist/cjs/swappers/RelaySwapper/utils/getRelayAssetAddress.js +2 -1
  42. package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
  43. package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
  44. package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
  45. package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.js +139 -0
  46. package/dist/cjs/swappers/RelaySwapper/utils/helpers.js +1 -2
  47. package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +1 -1
  48. package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +1 -4
  49. package/dist/cjs/swappers/SunioSwapper/endpoints.js +3 -63
  50. package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
  51. package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
  52. package/dist/cjs/swappers/SunioSwapper/types.d.ts +0 -3
  53. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
  54. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -30
  55. package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +3 -3
  56. package/dist/cjs/swappers/SunioSwapper/utils/constants.js +5 -9
  57. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
  58. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +54 -20
  59. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
  60. package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.js +177 -0
  61. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +3 -2
  62. package/dist/cjs/swappers/SunioSwapper/utils/helpers.js +2 -1
  63. package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +3 -4
  64. package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
  65. package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
  66. package/dist/cjs/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
  67. package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
  68. package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
  69. package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
  70. package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
  71. package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +31 -0
  72. package/dist/cjs/types.d.ts +9 -8
  73. package/dist/cjs/utils/helpers.js +3 -0
  74. package/dist/cjs/utils/helpers.test.js +3 -0
  75. package/dist/cjs/utils/thorchain/getThorStepData.js +32 -49
  76. package/dist/cjs/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
  77. package/dist/cjs/utils/thorchain/getThorStepData.tron.test.js +93 -0
  78. package/dist/cjs/utils/thorchain/index.d.ts +0 -1
  79. package/dist/cjs/utils/thorchain/index.js +1 -14
  80. package/dist/cjs/utils/tron/constants.d.ts +1 -0
  81. package/dist/cjs/utils/tron/constants.js +5 -0
  82. package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
  83. package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +64 -0
  84. package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
  85. package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +157 -0
  86. package/dist/cjs/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
  87. package/dist/cjs/utils/tron/getUnsignedTronTransaction.js +14 -48
  88. package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
  89. package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.js +76 -0
  90. package/dist/cjs/utils/tron/index.d.ts +2 -0
  91. package/dist/cjs/utils/tron/index.js +2 -0
  92. package/dist/esm/.tsbuildinfo +1 -1
  93. package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
  94. package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
  95. package/dist/esm/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
  96. package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +11 -2
  97. package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +5 -36
  98. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
  99. package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
  100. package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +3 -3
  101. package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
  102. package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +8 -7
  103. package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
  104. package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +21 -25
  105. package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
  106. package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +115 -0
  107. package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
  108. package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
  109. package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +13 -30
  110. package/dist/esm/swappers/ButterSwap/ButterSwap.js +0 -3
  111. package/dist/esm/swappers/ButterSwap/endpoints.js +0 -3
  112. package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
  113. package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -49
  114. package/dist/esm/swappers/ButterSwap/types.d.ts +3 -14
  115. package/dist/esm/swappers/ButterSwap/utils/constants.d.ts +2 -0
  116. package/dist/esm/swappers/ButterSwap/utils/constants.js +3 -0
  117. package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
  118. package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
  119. package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +116 -74
  120. package/dist/esm/swappers/ButterSwap/utils/helpers.js +2 -5
  121. package/dist/esm/swappers/ButterSwap/xhr.js +3 -3
  122. package/dist/esm/swappers/ChainflipSwapper/endpoints.js +3 -19
  123. package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
  124. package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.js +32 -13
  125. package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
  126. package/dist/esm/swappers/NearIntentsSwapper/constants.js +2 -0
  127. package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
  128. package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
  129. package/dist/esm/swappers/RelaySwapper/constant.d.ts +1 -1
  130. package/dist/esm/swappers/RelaySwapper/constant.js +2 -1
  131. package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
  132. package/dist/esm/swappers/RelaySwapper/utils/getRelayAssetAddress.js +3 -2
  133. package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
  134. package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
  135. package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
  136. package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.js +137 -0
  137. package/dist/esm/swappers/RelaySwapper/utils/helpers.js +1 -2
  138. package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +3 -3
  139. package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +1 -4
  140. package/dist/esm/swappers/SunioSwapper/endpoints.js +5 -65
  141. package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
  142. package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
  143. package/dist/esm/swappers/SunioSwapper/types.d.ts +0 -3
  144. package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
  145. package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +31 -28
  146. package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +3 -3
  147. package/dist/esm/swappers/SunioSwapper/utils/constants.js +4 -8
  148. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
  149. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +52 -18
  150. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
  151. package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.js +175 -0
  152. package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +2 -1
  153. package/dist/esm/swappers/SunioSwapper/utils/helpers.js +3 -2
  154. package/dist/esm/swappers/ThorchainSwapper/endpoints.js +4 -5
  155. package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
  156. package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
  157. package/dist/esm/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
  158. package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
  159. package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
  160. package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
  161. package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
  162. package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +29 -1
  163. package/dist/esm/types.d.ts +9 -8
  164. package/dist/esm/utils/helpers.js +4 -1
  165. package/dist/esm/utils/helpers.test.js +3 -0
  166. package/dist/esm/utils/thorchain/getThorStepData.js +32 -49
  167. package/dist/esm/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
  168. package/dist/esm/utils/thorchain/getThorStepData.tron.test.js +91 -0
  169. package/dist/esm/utils/thorchain/index.d.ts +0 -1
  170. package/dist/esm/utils/thorchain/index.js +0 -1
  171. package/dist/esm/utils/tron/constants.d.ts +1 -0
  172. package/dist/esm/utils/tron/constants.js +2 -0
  173. package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
  174. package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +59 -0
  175. package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
  176. package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +155 -0
  177. package/dist/esm/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
  178. package/dist/esm/utils/tron/getUnsignedTronTransaction.js +14 -48
  179. package/dist/esm/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
  180. package/dist/esm/utils/tron/getUnsignedTronTransaction.test.js +74 -0
  181. package/dist/esm/utils/tron/index.d.ts +2 -0
  182. package/dist/esm/utils/tron/index.js +2 -0
  183. package/package.json +9 -9
  184. package/dist/cjs/swappers/ButterSwap/test-data/eth-btc.json +0 -461
  185. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
  186. package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -32
  187. package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
  188. package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -78
  189. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
  190. package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -36
  191. package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
  192. package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.js +0 -68
  193. package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
  194. package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -35
  195. package/dist/cjs/utils/thorchain/tron/index.d.ts +0 -2
  196. package/dist/cjs/utils/thorchain/tron/index.js +0 -18
  197. package/dist/esm/swappers/ButterSwap/test-data/eth-btc.json +0 -461
  198. package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
  199. package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -28
  200. package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
  201. package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -74
  202. package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
  203. package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -32
  204. package/dist/esm/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
  205. package/dist/esm/utils/thorchain/tron/getTronTransactionFees.js +0 -64
  206. package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
  207. package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -31
  208. package/dist/esm/utils/thorchain/tron/index.d.ts +0 -2
  209. package/dist/esm/utils/thorchain/tron/index.js +0 -2
  210. /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
  211. /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
  212. /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
  213. /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
@@ -13,13 +13,12 @@ export declare const fetchBebopQuote: ({ buyAsset, sellAsset, sellAmountIncludin
13
13
  affiliateBps?: string | undefined;
14
14
  apiKey: string;
15
15
  }) => Promise<Result<BebopQuoteResponse, SwapErrorRight>>;
16
- export declare const fetchBebopSolanaQuote: ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, affiliateBps, apiKey, }: {
16
+ export declare const fetchBebopSolanaQuote: ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, apiKey, }: {
17
17
  buyAsset: Asset;
18
18
  sellAsset: Asset;
19
19
  sellAmountIncludingProtocolFeesCryptoBaseUnit: string;
20
20
  takerAddress: string;
21
21
  receiverAddress: string;
22
22
  slippageTolerancePercentageDecimal: string;
23
- affiliateBps?: string | undefined;
24
23
  apiKey: string;
25
24
  }) => Promise<Result<BebopSolanaQuoteResponse, SwapErrorRight>>;
@@ -27,16 +27,15 @@ export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncluding
27
27
  approval_type: 'Standard',
28
28
  skip_validation: 'true',
29
29
  gasless: 'false',
30
+ // PMM fees are configured against our api key on Bebop's side, not sent per quote
30
31
  source: 'shapeshift',
31
32
  };
32
33
  const jamParams = new URLSearchParams(baseParams);
33
34
  const pmmParams = new URLSearchParams(baseParams);
35
+ // JAM settles the fee on-chain, so it still takes our bps and a recipient per quote
34
36
  if (affiliateBps && affiliateBps !== '0') {
35
- // JAM collects the fee on-chain and requires a recipient
36
37
  jamParams.set('fee', affiliateBps);
37
38
  jamParams.set('fee_recipient', getAddress(getTreasuryAddressFromChainId(buyAsset.chainId)));
38
- // PMM attributes the fee off-chain via source
39
- pmmParams.set('fee', affiliateBps);
40
39
  }
41
40
  const service = bebopServiceFactory({ apiKey });
42
41
  const [maybeJam, maybePmm] = await Promise.all([
@@ -77,7 +76,7 @@ export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncluding
77
76
  }));
78
77
  }
79
78
  };
80
- export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, affiliateBps, apiKey, }) => {
79
+ export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, apiKey, }) => {
81
80
  try {
82
81
  // Bebop's Solana routes don't wrap native SOL on the input side, so selling native SOL
83
82
  // always fails on-chain. Reject up front instead of returning an unexecutable quote.
@@ -101,11 +100,9 @@ export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountInc
101
100
  approval_type: 'Standard',
102
101
  skip_validation: 'false',
103
102
  gasless: 'true',
103
+ // Solana is PMM only, so its fees are configured against our api key on Bebop's side
104
104
  source: 'shapeshift',
105
105
  });
106
- if (affiliateBps && affiliateBps !== '0') {
107
- params.set('fee', affiliateBps);
108
- }
109
106
  const maybeResponse = await bebopServiceFactory({ apiKey }).get('https://api.bebop.xyz/pmm/solana/v3/quote', { params });
110
107
  if (maybeResponse.isErr()) {
111
108
  const err = maybeResponse.unwrapErr();
@@ -19,7 +19,6 @@ export const getBebopSolanaTradeContext = async ({ input, deps, takerAddress, re
19
19
  takerAddress,
20
20
  receiverAddress,
21
21
  slippageTolerancePercentageDecimal,
22
- affiliateBps,
23
22
  apiKey: deps.config.VITE_BEBOP_API_KEY,
24
23
  });
25
24
  if (maybeBebopQuoteResponse.isErr())
@@ -1,6 +1,15 @@
1
- import { executeEvmTransaction, executeTronTransaction } from '../../utils/index.js';
1
+ import { executeEvmTransaction, executeTronTransaction, getSwapMetadata } from '../../utils/index.js';
2
+ import { submitBobGatewayBtcDeposit } from './utils/helpers.js';
2
3
  export const bobGatewaySwapper = {
3
4
  executeEvmTransaction,
4
- executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => signAndBroadcastTransaction(txToSign),
5
+ executeUtxoTransaction: async (txToSign, { signTransaction }, context) => {
6
+ if (!signTransaction)
7
+ throw new Error('[BobGateway] signTransaction is required');
8
+ if (!context)
9
+ throw new Error('[BobGateway] execution context is required');
10
+ const { orderId } = getSwapMetadata(context.swapperMetadata, 'bob');
11
+ const bitcoinTxHex = await signTransaction(txToSign);
12
+ return submitBobGatewayBtcDeposit({ config: context.config, orderId, bitcoinTxHex });
13
+ },
5
14
  executeTronTransaction,
6
15
  };
@@ -1,13 +1,12 @@
1
1
  import { isGatewayError } from '@gobob/bob-sdk';
2
2
  import { TxStatus } from '@shapeshiftoss/unchained-client';
3
- import { getExecutableTradeStep, getSwapMetadata, isExecutableTradeQuote } from '../../utils/index.js';
3
+ import { getSwapMetadata } from '../../utils/index.js';
4
4
  import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/evm/index.js';
5
- import { getTronTransactionFees } from '../../utils/tron/index.js';
5
+ import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
6
6
  import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
7
7
  import { getBobGatewayTradeQuote } from './swapperApi/getTradeQuote.js';
8
8
  import { getBobGatewayTradeRate } from './swapperApi/getTradeRate.js';
9
- import { getBobGatewayClient, mapBobGatewayOrderStatusToTxStatus, registerBobGatewayTx, toTronBase58, } from './utils/helpers.js';
10
- const registeredSwapIds = new Set();
9
+ import { getBobGatewayClient, mapBobGatewayOrderStatusToTxStatus } from './utils/helpers.js';
11
10
  export const bobGatewayApi = {
12
11
  getTradeRate: (input, deps) => getBobGatewayTradeRate(input, deps),
13
12
  getTradeQuote: (input, deps) => getBobGatewayTradeQuote(input, deps),
@@ -15,42 +14,12 @@ export const bobGatewayApi = {
15
14
  getUtxoTransactionFees,
16
15
  getUnsignedEvmTransaction,
17
16
  getEvmTransactionFees,
18
- getUnsignedTronTransaction: ({ from, stepIndex, tradeQuote, assertGetTronChainAdapter }) => {
19
- if (!isExecutableTradeQuote(tradeQuote)) {
20
- throw new Error('[BobGateway] unable to execute a trade rate');
21
- }
22
- const step = getExecutableTradeStep(tradeQuote, stepIndex);
23
- const { accountNumber, sellAsset, transactionData } = step;
24
- if (transactionData?.type !== 'tron')
25
- throw new Error('[BobGateway] invalid tron transaction');
26
- const adapter = assertGetTronChainAdapter(sellAsset.chainId);
27
- const { to, data, value } = transactionData;
28
- return adapter.buildCustomApiTx({
29
- accountNumber,
30
- from,
31
- to: toTronBase58(to),
32
- value,
33
- data,
34
- });
35
- },
17
+ getUnsignedTronTransaction,
36
18
  getTronTransactionFees,
37
- checkTradeStatus: async ({ swap, config, txHash }) => {
19
+ checkTradeStatus: async ({ swap, config }) => {
38
20
  if (!swap)
39
21
  throw new Error('[BobGateway] swap is required for status check');
40
22
  const { orderId } = getSwapMetadata(swap.metadata.swapperMetadata, 'bob');
41
- if (txHash && !registeredSwapIds.has(swap.id)) {
42
- try {
43
- await registerBobGatewayTx({
44
- config,
45
- orderId,
46
- txHash,
47
- sellAsset: swap.sellAsset,
48
- buyAsset: swap.buyAsset,
49
- });
50
- registeredSwapIds.add(swap.id);
51
- }
52
- catch { }
53
- }
54
23
  let orderInfo;
55
24
  try {
56
25
  orderInfo = await getBobGatewayClient(config).getOrder(orderId);
@@ -1,4 +1,4 @@
1
- import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
1
+ import { btcChainId } from '@shapeshiftoss/caip';
2
2
  import { Err, Ok } from '@sniptt/monads';
3
3
  import { assertQuoteAddresses } from '../../../utils/index.js';
4
4
  import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
@@ -10,18 +10,15 @@ export const getBobGatewayTradeQuote = async (input, deps) => {
10
10
  if (maybeAddresses.isErr())
11
11
  return Err(maybeAddresses.unwrapErr());
12
12
  const { sendAddress, receiveAddress } = maybeAddresses.unwrap();
13
- const isEvmSell = isEvmChainId(sellAsset.chainId);
14
- // omit the sender for utxo sells so order creation does not enforce a per-address confirmed
15
- // funds check (deposits are matched via op_return, not the sending address)
16
- const sender = isEvmSell ? sendAddress : undefined;
17
- // utxo deposits are refunded on the sell chain, so refunds go to the sending address
18
- const refundAddress = isEvmSell ? undefined : sendAddress;
13
+ const isBtcSell = sellAsset.chainId === btcChainId;
14
+ // omit the sender for btc sells so the sdk doesn't build a psbt from a single address
15
+ const sender = isBtcSell ? undefined : sendAddress;
19
16
  const maybeContext = await getBobGatewayTradeContext({
20
17
  input,
21
18
  deps,
22
19
  sender,
23
20
  recipient: receiveAddress,
24
- refundAddress,
21
+ refundAddress: sendAddress,
25
22
  });
26
23
  if (maybeContext.isErr())
27
24
  return Err(maybeContext.unwrapErr());
@@ -8,8 +8,7 @@ export const getBobGatewayTradeRate = async (input, deps) => {
8
8
  const isBtcSell = sellAsset.chainId === btcChainId;
9
9
  const recipient = receiveAddress ?? dummyAddressForChainId(buyAsset.chainId);
10
10
  const sender = isBtcSell ? undefined : dummyAddressForChainId(sellAsset.chainId);
11
- // utxo deposits are refunded on the sell chain, so the refund address must be a btc address
12
- const refundAddress = isBtcSell ? dummyAddressForChainId(sellAsset.chainId) : undefined;
11
+ const refundAddress = dummyAddressForChainId(sellAsset.chainId);
13
12
  const maybeContext = await getBobGatewayTradeContext({
14
13
  input,
15
14
  deps,
@@ -1,7 +1,7 @@
1
- import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types.js';
1
+ import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types.js';
2
2
  export type BobGatewayMetadata = {
3
3
  name: 'bob';
4
4
  orderId: string;
5
5
  };
6
- export type BobGatewayTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput;
7
- export type BobGatewayTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput;
6
+ export type BobGatewayTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInput | GetTronTradeQuoteInput;
7
+ export type BobGatewayTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetTronTradeRateInput;
@@ -1,13 +1,14 @@
1
1
  import type { ChainId } from '@shapeshiftoss/caip';
2
2
  export declare const BOB_GATEWAY_BASE_URL = "https://gateway-api-mainnet.gobob.xyz";
3
3
  export declare const chainIdToBobGatewayChainName: {
4
- readonly [x: string]: "ethereum" | "polygon" | "arbitrum" | "base" | "avalanche" | "bsc" | "bob" | "plasma" | "bera" | "bitcoin" | "sei" | "sonic" | "unichain" | "hyperliquid";
4
+ readonly [x: string]: "ethereum" | "polygon" | "arbitrum" | "base" | "avalanche" | "bsc" | "robinhood" | "bob" | "plasma" | "tron" | "bera" | "bitcoin" | "sei" | "sonic" | "unichain" | "hyperevm";
5
5
  };
6
6
  export declare const bobGatewayChainNameToChainId: Record<BobGatewayChainName, ChainId>;
7
7
  export type BobGatewayChainName = (typeof chainIdToBobGatewayChainName)[keyof typeof chainIdToBobGatewayChainName];
8
8
  export declare const DUMMY_EVM_ADDRESS: `0x${string}`;
9
9
  export declare const DUMMY_BTC_ADDRESS = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
10
- export declare const DUMMY_TRON_ADDRESS = "TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N";
11
10
  export declare const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = "350000";
12
11
  export declare const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = "550000";
12
+ export declare const BOB_GATEWAY_TRON_DEFAULT_ENERGY = "420000";
13
+ export declare const BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES = 4000;
13
14
  export declare const decimalSlippageToBobBps: (slippageDecimal: string) => string;
@@ -1,9 +1,7 @@
1
- import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, btcChainId, ethChainId, hyperEvmChainId, plasmaChainId, polygonChainId, seiChainId, sonicChainId,
2
- // tronChainId,
3
- unichainChainId, } from '@shapeshiftoss/caip';
1
+ import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, btcChainId, ethChainId, hyperEvmChainId, plasmaChainId, polygonChainId, robinhoodChainId, seiChainId, sonicChainId, tronChainId, unichainChainId, } from '@shapeshiftoss/caip';
4
2
  export const BOB_GATEWAY_BASE_URL = 'https://gateway-api-mainnet.gobob.xyz';
5
3
  // Chain name strings expected by the BOB Gateway API
6
- // https://gateway-api-mainnet.gobob.xyz/v2/get-routes
4
+ // https://gateway-api-mainnet.gobob.xyz/v4/get-routes
7
5
  export const chainIdToBobGatewayChainName = {
8
6
  [arbitrumChainId]: 'arbitrum',
9
7
  [avalancheChainId]: 'avalanche',
@@ -18,15 +16,18 @@ export const chainIdToBobGatewayChainName = {
18
16
  [unichainChainId]: 'unichain',
19
17
  [plasmaChainId]: 'plasma',
20
18
  [polygonChainId]: 'polygon',
21
- [hyperEvmChainId]: 'hyperliquid',
22
- // [tronChainId]: 'tron',
19
+ [hyperEvmChainId]: 'hyperevm',
20
+ [robinhoodChainId]: 'robinhood',
21
+ [tronChainId]: 'tron',
23
22
  };
24
23
  export const bobGatewayChainNameToChainId = Object.fromEntries(Object.entries(chainIdToBobGatewayChainName).map(([chainId, chainName]) => [chainName, chainId]));
25
24
  export const DUMMY_EVM_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
26
25
  export const DUMMY_BTC_ADDRESS = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
27
- export const DUMMY_TRON_ADDRESS = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
28
26
  export const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = '350000'; // EVM→EVM
29
27
  export const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = '550000'; // EVM→BTC
28
+ // AllowanceHolder exec measured on mainnet: rates price it before an order exists, token quotes without their allowance fall back to it
29
+ export const BOB_GATEWAY_TRON_DEFAULT_ENERGY = '420000';
30
+ export const BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES = 4000;
30
31
  // https://docs.gobob.xyz/api-reference/v2/get-a-gateway-quote#parameter-slippage
31
32
  export const decimalSlippageToBobBps = (slippageDecimal) => {
32
33
  return String(Math.round(parseFloat(slippageDecimal) * 10_000));
@@ -1,8 +1,8 @@
1
- import type { GatewayQuoteV3 } from '@gobob/bob-sdk';
1
+ import type { GatewayQuoteV4 } from '@gobob/bob-sdk';
2
2
  import type { Result } from '@sniptt/monads';
3
3
  import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.js';
4
4
  type BaseArgs = {
5
- quote: GatewayQuoteV3;
5
+ quote: GatewayQuoteV4;
6
6
  sellAmountCryptoBaseUnit: string;
7
7
  spenderAddress: string;
8
8
  };
@@ -1,12 +1,12 @@
1
1
  import { CHAIN_NAMESPACE, fromChainId } from '@shapeshiftoss/caip';
2
- import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
3
2
  import { Err, Ok } from '@sniptt/monads';
4
3
  import { TradeQuoteError } from '../../../types.js';
5
4
  import { makeNetworkFeeEstimationFailedErr, makeSwapErrorRight, makeTradeStepBuildFailedErr, } from '../../../utils/index.js';
6
5
  import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
6
+ import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from '../../../utils/tron/index.js';
7
7
  import { getUtxoNetworkFeeCryptoBaseUnit, UTXO_PLACEHOLDER_ADDRESS } from '../../../utils/utxo/index.js';
8
- import { BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT, BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT, } from './constants.js';
9
- import { createBobGatewayOrder, toTronBase58 } from './helpers.js';
8
+ import { BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT, BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT, BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES, BOB_GATEWAY_TRON_DEFAULT_ENERGY, } from './constants.js';
9
+ import { createBobGatewayOrder } from './helpers.js';
10
10
  export async function getBobGatewayStepData(args) {
11
11
  const { input, quote, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, deps } = args;
12
12
  const { chainNamespace } = fromChainId(sellAsset.chainId);
@@ -139,19 +139,17 @@ export async function getBobGatewayStepData(args) {
139
139
  // Tron sells (offramp Tron → BTC, or tokenSwap TRON → EVM)
140
140
  case CHAIN_NAMESPACE.Tron: {
141
141
  const adapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
142
- const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
143
142
  if (resolved.type === 'rate') {
143
+ // The gateway call isn't built until an order exists, so rates price a measured default
144
144
  const networkFeeCryptoBaseUnit = await (async () => {
145
145
  try {
146
- if (!('offramp' in quote) && !('tokenSwap' in quote))
147
- return;
148
- const order = 'offramp' in quote ? quote.offramp : quote.tokenSwap;
149
- const { fast } = await adapter.getFeeData({
150
- to: toTronBase58(order.txTo),
151
- value: order.inputAmount.amount,
152
- chainSpecific: { contractAddress },
146
+ return await getTronContractCallFallbackFeeCryptoBaseUnit({
147
+ adapter,
148
+ energy: BOB_GATEWAY_TRON_DEFAULT_ENERGY,
149
+ bandwidthBytes: BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES,
150
+ contractAddress: spenderAddress,
151
+ fullEnergyOnShareLookupFailure: true,
153
152
  });
154
- return fast.txFee;
155
153
  }
156
154
  catch { }
157
155
  })();
@@ -165,22 +163,20 @@ export async function getBobGatewayStepData(args) {
165
163
  if (order.tx.type !== 'tron')
166
164
  return Err(makeTradeStepBuildFailedErr('getBobGatewayStepData'));
167
165
  const { tx, orderId } = order;
168
- const transactionData = {
169
- type: 'tron',
170
- to: tx.to,
171
- data: tx.data,
172
- value: tx.value,
173
- };
166
+ const call = { to: tx.to, data: tx.data, value: tx.value };
174
167
  try {
175
- const { fast } = await adapter.getFeeData({
176
- to: toTronBase58(tx.to),
177
- value: sellAmountCryptoBaseUnit,
178
- chainSpecific: { from, contractAddress },
179
- });
180
168
  const stepData = {
181
169
  orderId,
182
- transactionData,
183
- networkFeeCryptoBaseUnit: fast.txFee,
170
+ transactionData: { type: 'tron', ...call },
171
+ networkFeeCryptoBaseUnit: await getTronContractCallNetworkFeeCryptoBaseUnit({
172
+ adapter,
173
+ transactionData: call,
174
+ from,
175
+ sellAsset,
176
+ sellAmountCryptoBaseUnit,
177
+ spenderAddress,
178
+ fallbackEnergy: BOB_GATEWAY_TRON_DEFAULT_ENERGY,
179
+ }),
184
180
  };
185
181
  return Ok(stepData);
186
182
  }
@@ -0,0 +1,115 @@
1
+ import { tronChainId } from '@shapeshiftoss/caip';
2
+ import { Ok } from '@sniptt/monads';
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { ETH } from '../../../utils/test-data/assets.js';
5
+ import { getBobGatewayStepData } from './getBobGatewayStepData.js';
6
+ import { createBobGatewayOrder } from './helpers.js';
7
+ vi.mock('./helpers', () => ({ createBobGatewayOrder: vi.fn() }));
8
+ const USDT_TRON = {
9
+ ...ETH,
10
+ assetId: `${tronChainId}/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t`,
11
+ chainId: tronChainId,
12
+ };
13
+ const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
14
+ // BOB returns the AllowanceHolder as 0x-prefixed 41-hex (TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K)
15
+ const ALLOWANCE_HOLDER_HEX = '0x4107a39ae4c49dee86e892450b20881f32cd5d500d';
16
+ const tronTx = { type: 'tron', to: ALLOWANCE_HOLDER_HEX, data: '0x2213bc0b', value: '0' };
17
+ const tronAdapter = ({ txFee = '45600000', allowance = '0' } = {}) => ({
18
+ getFeeData: vi.fn().mockResolvedValue({ fast: { txFee } }),
19
+ httpProvider: {
20
+ getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
21
+ getTrc20Allowance: vi.fn().mockResolvedValue(allowance),
22
+ getTrc20Balance: vi.fn().mockResolvedValue('100000000'),
23
+ getContractEnergyShare: vi.fn().mockResolvedValue({
24
+ callerPercent: 100,
25
+ originEnergyLimit: 0,
26
+ originEnergyAvailable: 0,
27
+ }),
28
+ },
29
+ });
30
+ const makeDeps = (tron) => ({ config: {}, assertGetTronChainAdapter: () => tron });
31
+ const quote = {};
32
+ describe('getBobGatewayStepData', () => {
33
+ describe('tron', () => {
34
+ it('prices a rate from the measured default energy and bandwidth at the gateway share', async () => {
35
+ const adapter = tronAdapter();
36
+ const actual = await getBobGatewayStepData({
37
+ type: 'rate',
38
+ input: {},
39
+ deps: makeDeps(adapter),
40
+ quote,
41
+ sellAsset: USDT_TRON,
42
+ sellAmountCryptoBaseUnit: '100000000',
43
+ spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
44
+ });
45
+ // 420000 energy * 1.2 margin * 100 sun + 4000 bytes * 1000 sun
46
+ expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '54400000' });
47
+ expect(adapter.httpProvider.getContractEnergyShare).toHaveBeenCalledWith('TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K');
48
+ });
49
+ it('simulates the real gateway call for a quote', async () => {
50
+ vi.mocked(createBobGatewayOrder).mockResolvedValue(Ok({ offramp: { orderId: 'order-1', tx: tronTx } }));
51
+ const adapter = tronAdapter();
52
+ const actual = await getBobGatewayStepData({
53
+ type: 'quote',
54
+ input: {},
55
+ deps: makeDeps(adapter),
56
+ quote,
57
+ sellAsset: USDT_TRON,
58
+ sellAmountCryptoBaseUnit: '100000000',
59
+ spenderAddress: '',
60
+ from: FROM,
61
+ });
62
+ expect(adapter.getFeeData).toHaveBeenCalledWith({
63
+ to: ALLOWANCE_HOLDER_HEX,
64
+ value: '0',
65
+ chainSpecific: { from: FROM, data: '0x2213bc0b', requireEnergyShare: true },
66
+ });
67
+ expect(actual.unwrap()).toEqual({
68
+ orderId: 'order-1',
69
+ transactionData: { type: 'tron', to: ALLOWANCE_HOLDER_HEX, data: '0x2213bc0b', value: '0' },
70
+ networkFeeCryptoBaseUnit: '45600000',
71
+ });
72
+ });
73
+ it('prices the measured worst case when the allowance is not granted yet', async () => {
74
+ vi.mocked(createBobGatewayOrder).mockResolvedValue(Ok({ offramp: { orderId: 'order-1', tx: tronTx } }));
75
+ const adapter = tronAdapter({ allowance: '0' });
76
+ adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
77
+ const actual = await getBobGatewayStepData({
78
+ type: 'quote',
79
+ input: {},
80
+ deps: makeDeps(adapter),
81
+ quote,
82
+ sellAsset: USDT_TRON,
83
+ sellAmountCryptoBaseUnit: '100000000',
84
+ spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
85
+ from: FROM,
86
+ });
87
+ // 420000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
88
+ expect(actual.unwrap()).toMatchObject({
89
+ orderId: 'order-1',
90
+ networkFeeCryptoBaseUnit: '50683000',
91
+ });
92
+ expect(adapter.httpProvider.getTrc20Allowance).toHaveBeenCalledWith({
93
+ contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
94
+ owner: FROM,
95
+ spender: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
96
+ });
97
+ });
98
+ it('fails the quote when the simulation reverts with the allowance in place', async () => {
99
+ vi.mocked(createBobGatewayOrder).mockResolvedValue(Ok({ offramp: { orderId: 'order-1', tx: tronTx } }));
100
+ const adapter = tronAdapter({ allowance: '100000000' });
101
+ adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
102
+ const actual = await getBobGatewayStepData({
103
+ type: 'quote',
104
+ input: {},
105
+ deps: makeDeps(adapter),
106
+ quote,
107
+ sellAsset: USDT_TRON,
108
+ sellAmountCryptoBaseUnit: '100000000',
109
+ spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
110
+ from: FROM,
111
+ });
112
+ expect(actual.isErr()).toBe(true);
113
+ });
114
+ });
115
+ });
@@ -1,4 +1,3 @@
1
- import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
2
1
  import { Err, Ok } from '@sniptt/monads';
3
2
  import { v4 as uuid } from 'uuid';
4
3
  import { SwapperName } from '../../../types.js';
@@ -58,7 +57,7 @@ export const getBobGatewayTradeContext = async ({ input, deps, sender, recipient
58
57
  quote,
59
58
  sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
60
59
  sellAsset,
61
- spenderAddress: isEvmChainId(sellAsset.chainId) ? allowanceContract : '',
60
+ spenderAddress: allowanceContract,
62
61
  deps,
63
62
  },
64
63
  });
@@ -1,4 +1,4 @@
1
- import type { GatewayOrderStatusV3, GatewayQuoteV3, GetQuoteParams } from '@gobob/bob-sdk';
1
+ import type { GatewayOrderStatusV3, GatewayQuoteV4, GetQuoteParams } from '@gobob/bob-sdk';
2
2
  import { GatewaySDK } from '@gobob/bob-sdk';
3
3
  import type { AssetId, ChainId } from '@shapeshiftoss/caip';
4
4
  import type { Asset, AssetsByIdPartial } from '@shapeshiftoss/types';
@@ -8,7 +8,6 @@ import type { SwapErrorRight, SwapperConfig } from '../../../types.js';
8
8
  import type { BobGatewayChainName } from './constants.js';
9
9
  export declare const dummyAddressForChainId: (chainId: ChainId) => string;
10
10
  export declare const getBobGatewayClient: (config: SwapperConfig) => GatewaySDK;
11
- export declare const toTronBase58: (address: string) => string;
12
11
  export declare const assetIdToBobGatewayToken: (assetId: string) => string;
13
12
  export declare const getBobGatewayAffiliates: (affiliateBps: string) => GetQuoteParams['affiliates'];
14
13
  export declare const getBobGatewayQuote: ({ config, sellAsset, buyAsset, sellChainName, buyChainName, sender, recipient, refundAddress, amount, affiliateBps, slippageTolerancePercentageDecimal, }: {
@@ -23,23 +22,21 @@ export declare const getBobGatewayQuote: ({ config, sellAsset, buyAsset, sellCha
23
22
  amount: string;
24
23
  affiliateBps: string;
25
24
  slippageTolerancePercentageDecimal: string | undefined;
26
- }) => Promise<Result<GatewayQuoteV3, SwapErrorRight>>;
27
- export declare const createBobGatewayOrder: (config: SwapperConfig, quote: GatewayQuoteV3) => Promise<import("@sniptt/monads/build/result/result").ResOk<import("@gobob/bob-sdk").GatewayCreateOrderV3, never> | import("@sniptt/monads/build/result/result").ResErr<unknown, SwapErrorRight>>;
28
- export declare const registerBobGatewayTx: ({ config, orderId, txHash, sellAsset, buyAsset, }: {
25
+ }) => Promise<Result<GatewayQuoteV4, SwapErrorRight>>;
26
+ export declare const createBobGatewayOrder: (config: SwapperConfig, quote: GatewayQuoteV4) => Promise<import("@sniptt/monads/build/result/result").ResOk<import("@gobob/bob-sdk").GatewayCreateOrderV3, never> | import("@sniptt/monads/build/result/result").ResErr<unknown, SwapErrorRight>>;
27
+ export declare const submitBobGatewayBtcDeposit: ({ config, orderId, bitcoinTxHex, }: {
29
28
  config: SwapperConfig;
30
29
  orderId: string;
31
- txHash: string;
32
- sellAsset: Asset;
33
- buyAsset: Asset;
34
- }) => Promise<void>;
30
+ bitcoinTxHex: string;
31
+ }) => Promise<string>;
35
32
  export declare const mapBobGatewayOrderStatusToTxStatus: (status: GatewayOrderStatusV3) => TxStatus;
36
- export declare const parseBobGatewayQuote: (quote: GatewayQuoteV3, buyAsset: Asset, assetsById: AssetsByIdPartial) => {
33
+ export declare const parseBobGatewayQuote: (quote: GatewayQuoteV4, buyAsset: Asset, assetsById: AssetsByIdPartial) => {
37
34
  buyAmountBeforeFeesCryptoBaseUnit: string;
38
35
  buyAmountAfterFeesCryptoBaseUnit: string;
39
36
  protocolFees: Partial<Record<AssetId, import("../../../types.js").ProtocolFee>>;
40
37
  estimatedExecutionTimeMs: number | undefined;
41
38
  };
42
- export declare const getBobGatewayAllowanceContract: (quote: GatewayQuoteV3, sellAsset: Asset) => string;
39
+ export declare const getBobGatewayAllowanceContract: (quote: GatewayQuoteV4, sellAsset: Asset) => string;
43
40
  export declare const assertValidTrade: ({ sellAsset, buyAsset, }: {
44
41
  sellAsset: Asset;
45
42
  buyAsset: Asset;
@@ -1,33 +1,27 @@
1
1
  import { GatewayErrorCode, GatewaySDK, isGatewayError } from '@gobob/bob-sdk';
2
+ import * as bitcoin from '@shapeshiftoss/bitcoinjs-lib';
2
3
  import { ASSET_NAMESPACE, btcChainId, ethChainId, fromAssetId, toAssetId, tronChainId, } from '@shapeshiftoss/caip';
3
- import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
4
+ import { isEvmChainId, tron } from '@shapeshiftoss/chain-adapters';
4
5
  import { TxStatus } from '@shapeshiftoss/unchained-client';
5
6
  import { bnOrZero, chainIdToFeeAssetId, contractAddressOrUndefined, isToken, } from '@shapeshiftoss/utils';
6
7
  import { Err, Ok } from '@sniptt/monads';
7
- import { TronWeb } from 'tronweb';
8
8
  import { getAddress, zeroAddress } from 'viem';
9
9
  import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
10
10
  import { SwapperName, TradeQuoteError } from '../../../types.js';
11
11
  import { createTradeAmountTooSmallErr, makeSwapErrorRight } from '../../../utils/index.js';
12
12
  import { getTreasuryAddressFromChainId } from '../../../utils/helpers.js';
13
- import { BOB_GATEWAY_BASE_URL, bobGatewayChainNameToChainId, chainIdToBobGatewayChainName, decimalSlippageToBobBps, DUMMY_BTC_ADDRESS, DUMMY_EVM_ADDRESS, DUMMY_TRON_ADDRESS, } from './constants.js';
13
+ import { TRON_PLACEHOLDER_ADDRESS } from '../../../utils/tron/index.js';
14
+ import { BOB_GATEWAY_BASE_URL, bobGatewayChainNameToChainId, chainIdToBobGatewayChainName, decimalSlippageToBobBps, DUMMY_BTC_ADDRESS, DUMMY_EVM_ADDRESS, } from './constants.js';
14
15
  export const dummyAddressForChainId = (chainId) => {
15
16
  if (chainId === btcChainId)
16
17
  return DUMMY_BTC_ADDRESS;
17
18
  if (chainId === tronChainId)
18
- return DUMMY_TRON_ADDRESS;
19
+ return TRON_PLACEHOLDER_ADDRESS;
19
20
  return DUMMY_EVM_ADDRESS;
20
21
  };
21
22
  export const getBobGatewayClient = (config) => {
22
23
  return new GatewaySDK({ basePath: BOB_GATEWAY_BASE_URL, apiKey: config.VITE_BOB_GATEWAY_API_KEY });
23
24
  };
24
- export const toTronBase58 = (address) => {
25
- if (address.startsWith('T'))
26
- return address;
27
- if (address.startsWith('0x'))
28
- return TronWeb.address.fromHex(address.slice(2));
29
- return TronWeb.address.fromHex(address);
30
- };
31
25
  export const assetIdToBobGatewayToken = (assetId) => {
32
26
  // BOB Gateway uses the zero address as the token address for native assets
33
27
  if (!isToken(assetId))
@@ -54,7 +48,6 @@ export const getBobGatewayQuote = async ({ config, sellAsset, buyAsset, sellChai
54
48
  toUserAddress: recipient,
55
49
  amount,
56
50
  maxSlippage: Number(slippage),
57
- ownerAddress: sellChainName === 'bitcoin' ? recipient : sender,
58
51
  refundAddress,
59
52
  affiliates: getBobGatewayAffiliates(affiliateBps),
60
53
  });
@@ -99,7 +92,7 @@ export const getBobGatewayQuote = async ({ config, sellAsset, buyAsset, sellChai
99
92
  };
100
93
  export const createBobGatewayOrder = async (config, quote) => {
101
94
  try {
102
- const order = await getBobGatewayClient(config).api.createOrderV3({ gatewayQuoteV3: quote });
95
+ const order = await getBobGatewayClient(config).api.createOrderV4({ gatewayQuoteV4: quote });
103
96
  return Ok(order);
104
97
  }
105
98
  catch (err) {
@@ -117,21 +110,11 @@ export const createBobGatewayOrder = async (config, quote) => {
117
110
  }));
118
111
  }
119
112
  };
120
- export const registerBobGatewayTx = async ({ config, orderId, txHash, sellAsset, buyAsset, }) => {
121
- const registerTxV3 = (() => {
122
- const sellChainName = chainIdToBobGatewayChainName[sellAsset.chainId];
123
- // BTC→EVM
124
- if (sellChainName === 'bitcoin') {
125
- return { onramp: { orderId, bitcoinTxid: txHash } };
126
- }
127
- // EVM→BTC
128
- if (chainIdToBobGatewayChainName[buyAsset.chainId] === 'bitcoin') {
129
- return { offramp: { orderId, srcChain: sellChainName, srcTxHash: txHash } };
130
- }
131
- // EVM→EVM
132
- return { tokenSwap: { orderId, srcChain: sellChainName, srcTxHash: txHash } };
133
- })();
134
- await getBobGatewayClient(config).api.registerTxV3({ registerTxV3 });
113
+ export const submitBobGatewayBtcDeposit = async ({ config, orderId, bitcoinTxHex, }) => {
114
+ await getBobGatewayClient(config).api.registerTxV4({
115
+ registerTxV4: { onramp: { orderId, bitcoinTxHex } },
116
+ });
117
+ return bitcoin.Transaction.fromHex(bitcoinTxHex).getId();
135
118
  };
136
119
  export const mapBobGatewayOrderStatusToTxStatus = (status) => {
137
120
  if ('inProgress' in status)
@@ -154,7 +137,7 @@ const bobGatewayFeeToAssetId = (fee) => {
154
137
  return toAssetId({
155
138
  chainId,
156
139
  assetNamespace: ASSET_NAMESPACE.trc20,
157
- assetReference: toTronBase58(fee.address),
140
+ assetReference: tron.toTronBase58(fee.address),
158
141
  });
159
142
  }
160
143
  return toAssetId({
@@ -227,7 +210,7 @@ export const getBobGatewayAllowanceContract = (quote, sellAsset) => {
227
210
  if (!txTo)
228
211
  return '';
229
212
  if (isTron)
230
- return toTronBase58(txTo);
213
+ return tron.toTronBase58(txTo);
231
214
  return txTo;
232
215
  };
233
216
  export const assertValidTrade = ({ sellAsset, buyAsset, }) => {
@@ -3,7 +3,4 @@ export const butterSwap = {
3
3
  executeEvmTransaction,
4
4
  executeSolanaTransaction,
5
5
  executeTronTransaction,
6
- executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
7
- return signAndBroadcastTransaction(txToSign);
8
- },
9
6
  };