@shapeshiftoss/swapper 17.7.2 → 17.8.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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.js +35 -26
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +8 -17
- package/dist/cjs/swappers/AcrossSwapper/utils/acrossService.d.ts +3 -3
- package/dist/cjs/swappers/AcrossSwapper/utils/getTrade.js +2 -1
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/endpoints.d.ts +3 -3
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.js +2 -2
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.test.js +12 -4
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/getTradeRate/getTradeRate.js +2 -1
- package/dist/cjs/swappers/ArbitrumBridgeSwapper/utils/fetchArbitrumBridgeSwap.d.ts +2 -2
- package/dist/cjs/swappers/AvnuSwapper/endpoints.js +2 -2
- package/dist/cjs/swappers/AvnuSwapper/utils/constants.d.ts +1 -1
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeQuote/getBebopSolanaTradeQuote.js +2 -1
- package/dist/cjs/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +11 -6
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +4 -11
- package/dist/cjs/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +12 -15
- package/dist/cjs/swappers/BebopSwapper/types.d.ts +65 -79
- package/dist/cjs/swappers/BebopSwapper/utils/bebopService.d.ts +1 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +2 -18
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +49 -82
- package/dist/cjs/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.d.ts +2 -0
- package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +8 -0
- package/dist/cjs/swappers/BobGatewaySwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +143 -0
- package/dist/cjs/swappers/BobGatewaySwapper/index.d.ts +3 -0
- package/dist/cjs/swappers/BobGatewaySwapper/index.js +22 -0
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +90 -0
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +73 -0
- package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +20 -0
- package/dist/cjs/swappers/BobGatewaySwapper/types.js +2 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +13 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +31 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +49 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +314 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/checkTradeStatus.test.js +9 -19
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +1 -1
- package/dist/cjs/swappers/ButterSwap/test-data/routeQuote.js +4 -4
- package/dist/cjs/swappers/ButterSwap/utils/butterSwapHistoryService.d.ts +3 -3
- package/dist/cjs/swappers/ButterSwap/utils/butterSwapService.d.ts +3 -3
- package/dist/cjs/swappers/ButterSwap/xhr.js +4 -4
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/ChainflipSwapper.js +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/constants.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/constants.js +3 -0
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +20 -0
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasQuoteBoostQuote.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasQuoteEstimatedDurationsSeconds.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasQuoteQuote.js +5 -5
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasQuoteQuoteFee.js +5 -5
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasStatusChunkInfo.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasStatusDca.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasStatusEgress.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasStatusSwap.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/models/ChainflipBaasSwapDepositAddress.js +5 -4
- package/dist/cjs/swappers/ChainflipSwapper/types.d.ts +2 -1
- package/dist/cjs/swappers/ChainflipSwapper/types.js +1 -0
- package/dist/cjs/swappers/ChainflipSwapper/utils/chainflipService.d.ts +3 -3
- package/dist/cjs/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +25 -5
- package/dist/cjs/swappers/ChainflipSwapper/utils/getUtxoTxFees.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.d.ts +2 -3
- package/dist/cjs/swappers/ChainflipSwapper/utils/helpers.js +2 -1
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +3 -2
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +8 -8
- package/dist/cjs/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +3 -2
- package/dist/cjs/swappers/CowSwapper/utils/cowService.d.ts +3 -3
- package/dist/cjs/swappers/CowSwapper/utils/helpers/helpers.test.js +3 -3
- package/dist/cjs/swappers/DebridgeSwapper/utils/debridgeService.d.ts +3 -3
- package/dist/cjs/swappers/DebridgeSwapper/utils/getTrade.js +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +2 -1
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +5 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.d.ts +2 -2
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +5 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeQuote/getPortalsTradeQuote.js +2 -1
- package/dist/cjs/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +4 -3
- package/dist/cjs/swappers/PortalsSwapper/utils/helpers.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.d.ts +1 -39
- package/dist/cjs/swappers/RelaySwapper/constant.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/fetchRelayTrade.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayPsbtRelayer.js +7 -17
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +2 -1
- package/dist/cjs/swappers/RelaySwapper/utils/relayService.d.ts +3 -3
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +19 -36
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +6 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -0
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +6 -6
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +7 -1
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +12 -0
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +78 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getQuoteOrRate.js +18 -75
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +2 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +36 -0
- package/dist/cjs/swappers/SunioSwapper/utils/helpers/helpers.d.ts +1 -2
- package/dist/cjs/swappers/SunioSwapper/utils/sunioService.d.ts +3 -3
- package/dist/cjs/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +10 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +8 -18
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +8 -18
- package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailQuote.js +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/getLongtailRate.js +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/longTailHelpers.js +2 -2
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.js +2 -1
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.test.js +7 -17
- package/dist/cjs/swappers/ZrxSwapper/getZrxTradeRate/getZrxTradeRate.js +2 -1
- package/dist/cjs/swappers/ZrxSwapper/utils/fetchFromZrx.js +2 -2
- package/dist/cjs/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +3 -2
- package/dist/cjs/swappers/ZrxSwapper/utils/zrxService.d.ts +1 -1
- package/dist/cjs/swappers/utils/helpers/helpers.js +1 -0
- package/dist/cjs/swappers/utils/test-data/cryptoMarketDataById.d.ts +1 -35
- package/dist/cjs/thorchain-utils/checkTradeStatus.js +8 -1
- package/dist/cjs/thorchain-utils/cosmossdk/getThorTxData.d.ts +12 -0
- package/dist/cjs/thorchain-utils/cosmossdk/getThorTxData.js +19 -0
- package/dist/cjs/thorchain-utils/cosmossdk/index.d.ts +1 -0
- package/dist/cjs/thorchain-utils/cosmossdk/index.js +1 -0
- package/dist/cjs/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +51 -33
- package/dist/cjs/thorchain-utils/getQuote.js +27 -29
- package/dist/cjs/thorchain-utils/index.d.ts +1 -0
- package/dist/cjs/thorchain-utils/index.js +19 -18
- package/dist/cjs/thorchain-utils/parseBuyTxHash.d.ts +1 -1
- package/dist/cjs/thorchain-utils/service.d.ts +3 -3
- package/dist/cjs/thorchain-utils/tron/getTronTransactionFees.js +8 -5
- package/dist/cjs/thorchain-utils/types.d.ts +1 -1
- package/dist/cjs/tron-utils/getTronTransactionFees.d.ts +1 -1
- package/dist/cjs/types.d.ts +16 -3
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/utils/tenderly/storageSlots.js +20 -20
- package/dist/cjs/utils.d.ts +4 -4
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +9 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/swappers/AcrossSwapper/utils/acrossService.d.ts +3 -3
- package/dist/esm/swappers/ArbitrumBridgeSwapper/endpoints.d.ts +3 -3
- package/dist/esm/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote.test.js +12 -4
- package/dist/esm/swappers/ArbitrumBridgeSwapper/utils/fetchArbitrumBridgeSwap.d.ts +2 -2
- package/dist/esm/swappers/AvnuSwapper/endpoints.js +2 -2
- package/dist/esm/swappers/AvnuSwapper/utils/constants.d.ts +1 -1
- package/dist/esm/swappers/BebopSwapper/getBebopSolanaTradeRate/getBebopSolanaTradeRate.js +10 -6
- package/dist/esm/swappers/BebopSwapper/getBebopTradeQuote/getBebopTradeQuote.js +2 -10
- package/dist/esm/swappers/BebopSwapper/getBebopTradeRate/getBebopTradeRate.js +11 -15
- package/dist/esm/swappers/BebopSwapper/types.d.ts +65 -79
- package/dist/esm/swappers/BebopSwapper/utils/bebopService.d.ts +1 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +2 -18
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +45 -76
- package/dist/esm/swappers/BebopSwapper/utils/helpers/helpers.d.ts +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.d.ts +2 -0
- package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +5 -0
- package/dist/esm/swappers/BobGatewaySwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +140 -0
- package/dist/esm/swappers/BobGatewaySwapper/index.d.ts +3 -0
- package/dist/esm/swappers/BobGatewaySwapper/index.js +3 -0
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +86 -0
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +69 -0
- package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +20 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +13 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +27 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +49 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +299 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/checkTradeStatus.test.js +2 -2
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +1 -1
- package/dist/esm/swappers/ButterSwap/test-data/routeQuote.js +4 -4
- package/dist/esm/swappers/ButterSwap/utils/butterSwapHistoryService.d.ts +3 -3
- package/dist/esm/swappers/ButterSwap/utils/butterSwapService.d.ts +3 -3
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/ChainflipSwapper.js +2 -1
- package/dist/esm/swappers/ChainflipSwapper/constants.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/constants.js +4 -1
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +20 -0
- package/dist/esm/swappers/ChainflipSwapper/types.d.ts +2 -1
- package/dist/esm/swappers/ChainflipSwapper/types.js +1 -0
- package/dist/esm/swappers/ChainflipSwapper/utils/chainflipService.d.ts +3 -3
- package/dist/esm/swappers/ChainflipSwapper/utils/getQuoteOrRate.js +26 -6
- package/dist/esm/swappers/ChainflipSwapper/utils/getUtxoTxFees.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/helpers.d.ts +2 -3
- package/dist/esm/swappers/ChainflipSwapper/utils/helpers.js +2 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.js +1 -1
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeQuote/getCowSwapTradeQuote.test.js +8 -8
- package/dist/esm/swappers/CowSwapper/getCowSwapTradeRate/getCowSwapTradeRate.js +1 -1
- package/dist/esm/swappers/CowSwapper/utils/cowService.d.ts +3 -3
- package/dist/esm/swappers/CowSwapper/utils/helpers/helpers.test.js +3 -3
- package/dist/esm/swappers/DebridgeSwapper/utils/debridgeService.d.ts +3 -3
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +7 -4
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.d.ts +2 -2
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +5 -1
- package/dist/esm/swappers/PortalsSwapper/getPortalsTradeRate/getPortalsTradeRate.js +2 -2
- package/dist/esm/swappers/PortalsSwapper/utils/helpers.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/constant.d.ts +1 -39
- package/dist/esm/swappers/RelaySwapper/constant.js +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/fetchRelayTrade.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/relayService.d.ts +3 -3
- package/dist/esm/swappers/SunioSwapper/endpoints.js +19 -36
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +29 -0
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +6 -6
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +6 -0
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +12 -0
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +74 -0
- package/dist/esm/swappers/SunioSwapper/utils/getQuoteOrRate.js +16 -74
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +2 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +32 -0
- package/dist/esm/swappers/SunioSwapper/utils/helpers/helpers.d.ts +1 -2
- package/dist/esm/swappers/SunioSwapper/utils/sunioService.d.ts +3 -3
- package/dist/esm/swappers/ThorchainSwapper/getTradeQuote/getTradeQuote.test.js +10 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailQuote.js +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getLongtailRate.js +1 -1
- package/dist/esm/swappers/ZrxSwapper/utils/fetchFromZrx.js +2 -2
- package/dist/esm/swappers/ZrxSwapper/utils/helpers/helpers.d.ts +3 -2
- package/dist/esm/swappers/ZrxSwapper/utils/zrxService.d.ts +1 -1
- package/dist/esm/swappers/utils/helpers/helpers.js +2 -1
- package/dist/esm/swappers/utils/test-data/cryptoMarketDataById.d.ts +1 -35
- package/dist/esm/thorchain-utils/checkTradeStatus.js +8 -1
- package/dist/esm/thorchain-utils/cosmossdk/getThorTxData.d.ts +12 -0
- package/dist/esm/thorchain-utils/cosmossdk/getThorTxData.js +15 -0
- package/dist/esm/thorchain-utils/cosmossdk/index.d.ts +1 -0
- package/dist/esm/thorchain-utils/cosmossdk/index.js +1 -0
- package/dist/esm/thorchain-utils/getCallDataFromQuote.d.ts +1 -1
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +44 -16
- package/dist/esm/thorchain-utils/getQuote.js +27 -29
- package/dist/esm/thorchain-utils/index.d.ts +1 -0
- package/dist/esm/thorchain-utils/index.js +11 -1
- package/dist/esm/thorchain-utils/parseBuyTxHash.d.ts +1 -1
- package/dist/esm/thorchain-utils/service.d.ts +3 -3
- package/dist/esm/thorchain-utils/tron/getTronTransactionFees.js +8 -5
- package/dist/esm/thorchain-utils/types.d.ts +1 -1
- package/dist/esm/tron-utils/getTronTransactionFees.d.ts +1 -1
- package/dist/esm/types.d.ts +16 -3
- package/dist/esm/types.js +5 -0
- package/dist/esm/utils/tenderly/storageSlots.js +20 -20
- package/dist/esm/utils.d.ts +4 -4
- package/package.json +8 -7
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +0 -11
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapTransaction.js +0 -57
- package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +0 -11
- package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +0 -40
- package/dist/cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +0 -94
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.d.ts +0 -11
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapTransaction.js +0 -53
- package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.d.ts +0 -11
- package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.js +0 -34
- package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.d.ts +0 -1
- package/dist/esm/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.js +0 -92
- /package/dist/{cjs/thorchain-utils/getThresholdedAffiliateBps/getThresholdedAffiliateBps.test.d.ts → esm/swappers/BobGatewaySwapper/types.js} +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { solAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { bn, bnOrZero } from '@shapeshiftoss/utils';
|
|
2
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
4
|
import { getAddress } from 'viem';
|
|
4
5
|
import { TradeQuoteError } from '../../../types.js';
|
|
5
6
|
import { makeSwapErrorRight } from '../../../utils.js';
|
|
6
|
-
import {
|
|
7
|
+
import { getTreasuryAddressFromChainId } from '../../utils/helpers/helpers.js';
|
|
8
|
+
import { chainIdToBebopChain } from '../types.js';
|
|
7
9
|
import { bebopServiceFactory } from './bebopService.js';
|
|
8
10
|
import { assetIdToBebopSolanaToken, assetIdToBebopToken } from './helpers/helpers.js';
|
|
9
11
|
export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, affiliateBps, apiKey, }) => {
|
|
@@ -14,14 +16,8 @@ export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncluding
|
|
|
14
16
|
const checksummedReceiverAddress = getAddress(receiverAddress);
|
|
15
17
|
const chainName = chainIdToBebopChain[sellAsset.chainId];
|
|
16
18
|
const sellAmountFormatted = bn(sellAmountIncludingProtocolFeesCryptoBaseUnit).toFixed(0);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// See: https://api.bebop.xyz/pmm/ethereum/docs#/v3/quote_v3_quote_get
|
|
20
|
-
const slippagePercentage = bn(slippageTolerancePercentageDecimal ?? 0.003)
|
|
21
|
-
.times(100)
|
|
22
|
-
.toNumber();
|
|
23
|
-
const url = `https://api.bebop.xyz/router/${chainName}/v1/quote`;
|
|
24
|
-
const params = new URLSearchParams({
|
|
19
|
+
const slippagePercentage = bn(slippageTolerancePercentageDecimal).times(100).toNumber();
|
|
20
|
+
const baseParams = {
|
|
25
21
|
sell_tokens: sellToken,
|
|
26
22
|
buy_tokens: buyToken,
|
|
27
23
|
sell_amounts: sellAmountFormatted,
|
|
@@ -32,38 +28,46 @@ export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncluding
|
|
|
32
28
|
skip_validation: 'true',
|
|
33
29
|
gasless: 'false',
|
|
34
30
|
source: 'shapeshift',
|
|
35
|
-
}
|
|
31
|
+
};
|
|
32
|
+
const jamParams = new URLSearchParams(baseParams);
|
|
33
|
+
const pmmParams = new URLSearchParams(baseParams);
|
|
36
34
|
if (affiliateBps && affiliateBps !== '0') {
|
|
37
|
-
|
|
35
|
+
// JAM collects the fee on-chain and requires a recipient
|
|
36
|
+
jamParams.set('fee', affiliateBps);
|
|
37
|
+
jamParams.set('fee_recipient', getAddress(getTreasuryAddressFromChainId(buyAsset.chainId)));
|
|
38
|
+
// PMM attributes the fee off-chain via source
|
|
39
|
+
pmmParams.set('fee', affiliateBps);
|
|
38
40
|
}
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
41
|
+
const service = bebopServiceFactory({ apiKey });
|
|
42
|
+
const [maybeJam, maybePmm] = await Promise.all([
|
|
43
|
+
service.get(`https://api.bebop.xyz/jam/${chainName}/v2/quote`, {
|
|
44
|
+
params: jamParams,
|
|
45
|
+
}),
|
|
46
|
+
service.get(`https://api.bebop.xyz/pmm/${chainName}/v3/quote`, {
|
|
47
|
+
params: pmmParams,
|
|
48
|
+
}),
|
|
49
|
+
]);
|
|
50
|
+
const maybeResponses = [maybeJam, maybePmm];
|
|
51
|
+
if (maybeResponses.every(maybeResponse => maybeResponse.isErr())) {
|
|
42
52
|
return Err(makeSwapErrorRight({
|
|
43
53
|
message: 'Failed to fetch quote from Bebop',
|
|
44
|
-
cause:
|
|
54
|
+
cause: maybeResponses[0].unwrapErr().cause,
|
|
45
55
|
code: TradeQuoteError.QueryFailed,
|
|
46
56
|
}));
|
|
47
57
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Validate response has routes - only fail if there are NO valid routes
|
|
54
|
-
if (!response.data.routes || response.data.routes.length === 0) {
|
|
58
|
+
const quotes = maybeResponses
|
|
59
|
+
.filter(maybeResponse => maybeResponse.isOk())
|
|
60
|
+
.map(maybeResponse => maybeResponse.unwrap().data)
|
|
61
|
+
.filter(quote => Boolean(quote.tx?.data));
|
|
62
|
+
if (!quotes.length) {
|
|
55
63
|
return Err(makeSwapErrorRight({
|
|
56
|
-
message: 'No
|
|
64
|
+
message: 'No route available',
|
|
57
65
|
code: TradeQuoteError.NoRouteFound,
|
|
58
66
|
}));
|
|
59
67
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
code: TradeQuoteError.InvalidResponse,
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
return Ok(response.data);
|
|
68
|
+
const getBuyAmount = (quote) => bnOrZero(Object.values(quote.buyTokens)[0]?.amount);
|
|
69
|
+
const bestQuote = quotes.reduce((best, quote) => getBuyAmount(quote).gt(getBuyAmount(best)) ? quote : best);
|
|
70
|
+
return Ok(bestQuote);
|
|
67
71
|
}
|
|
68
72
|
catch (error) {
|
|
69
73
|
return Err(makeSwapErrorRight({
|
|
@@ -73,28 +77,20 @@ export const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncluding
|
|
|
73
77
|
}));
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
|
-
export const fetchBebopPrice = ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, affiliateBps, apiKey, }) => {
|
|
77
|
-
const address = receiveAddress || BEBOP_DUMMY_ADDRESS;
|
|
78
|
-
return fetchBebopQuote({
|
|
79
|
-
buyAsset,
|
|
80
|
-
sellAsset,
|
|
81
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
82
|
-
takerAddress: address,
|
|
83
|
-
receiverAddress: address,
|
|
84
|
-
slippageTolerancePercentageDecimal: '0.01',
|
|
85
|
-
affiliateBps,
|
|
86
|
-
apiKey,
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
80
|
export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, affiliateBps, apiKey, }) => {
|
|
90
81
|
try {
|
|
82
|
+
// Bebop's Solana routes don't wrap native SOL on the input side, so selling native SOL
|
|
83
|
+
// always fails on-chain. Reject up front instead of returning an unexecutable quote.
|
|
84
|
+
if (sellAsset.assetId === solAssetId) {
|
|
85
|
+
return Err(makeSwapErrorRight({
|
|
86
|
+
message: 'Bebop Solana cannot sell native SOL',
|
|
87
|
+
code: TradeQuoteError.NoRouteFound,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
91
90
|
const sellToken = assetIdToBebopSolanaToken(sellAsset.assetId);
|
|
92
91
|
const buyToken = assetIdToBebopSolanaToken(buyAsset.assetId);
|
|
93
92
|
const sellAmountFormatted = bn(sellAmountIncludingProtocolFeesCryptoBaseUnit).toFixed(0);
|
|
94
|
-
const slippagePercentage = bn(slippageTolerancePercentageDecimal
|
|
95
|
-
.times(100)
|
|
96
|
-
.toNumber();
|
|
97
|
-
const url = 'https://api.bebop.xyz/pmm/solana/v3/quote';
|
|
93
|
+
const slippagePercentage = bn(slippageTolerancePercentageDecimal).times(100).toNumber();
|
|
98
94
|
const params = new URLSearchParams({
|
|
99
95
|
sell_tokens: sellToken,
|
|
100
96
|
buy_tokens: buyToken,
|
|
@@ -110,8 +106,7 @@ export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountInc
|
|
|
110
106
|
if (affiliateBps && affiliateBps !== '0') {
|
|
111
107
|
params.set('fee', affiliateBps);
|
|
112
108
|
}
|
|
113
|
-
const
|
|
114
|
-
const maybeResponse = await bebopService.get(`${url}?${params}`);
|
|
109
|
+
const maybeResponse = await bebopServiceFactory({ apiKey }).get('https://api.bebop.xyz/pmm/solana/v3/quote', { params });
|
|
115
110
|
if (maybeResponse.isErr()) {
|
|
116
111
|
const err = maybeResponse.unwrapErr();
|
|
117
112
|
return Err(makeSwapErrorRight({
|
|
@@ -133,19 +128,6 @@ export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountInc
|
|
|
133
128
|
code: TradeQuoteError.InvalidResponse,
|
|
134
129
|
}));
|
|
135
130
|
}
|
|
136
|
-
// Reject routes containing ANY AMM/CLMM makers - these produce malformed txs
|
|
137
|
-
// (wrong signature count in wire format) and require pre-existing ATAs that
|
|
138
|
-
// Bebop's gasless co-signed flow can't create. This includes mixed routes
|
|
139
|
-
// like ["raydium clmm-rfqm", "🦊"] where Bebop serializes the tx with fewer
|
|
140
|
-
// signature slots than the message header requires.
|
|
141
|
-
// When rejected, other swappers like Jupiter will handle these pairs instead.
|
|
142
|
-
const hasAmmRoute = response.data.makers.some(maker => maker.toLowerCase().includes('clmm') || maker.toLowerCase().includes('amm'));
|
|
143
|
-
if (hasAmmRoute) {
|
|
144
|
-
return Err(makeSwapErrorRight({
|
|
145
|
-
message: `Bebop Solana quote contains AMM routing (${response.data.makers.join(', ')}), which produces malformed txs`,
|
|
146
|
-
code: TradeQuoteError.NoRouteFound,
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
131
|
return Ok(response.data);
|
|
150
132
|
}
|
|
151
133
|
catch (error) {
|
|
@@ -156,16 +138,3 @@ export const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountInc
|
|
|
156
138
|
}));
|
|
157
139
|
}
|
|
158
140
|
};
|
|
159
|
-
export const fetchBebopSolanaPrice = ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, affiliateBps, apiKey, }) => {
|
|
160
|
-
const address = receiveAddress || BEBOP_SOLANA_DUMMY_ADDRESS;
|
|
161
|
-
return fetchBebopSolanaQuote({
|
|
162
|
-
buyAsset,
|
|
163
|
-
sellAsset,
|
|
164
|
-
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
165
|
-
takerAddress: address,
|
|
166
|
-
receiverAddress: address,
|
|
167
|
-
slippageTolerancePercentageDecimal: '0.01',
|
|
168
|
-
affiliateBps,
|
|
169
|
-
apiKey,
|
|
170
|
-
});
|
|
171
|
-
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { AssetId, ChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
-
import type { BebopSupportedChainId } from '../../types.js';
|
|
4
3
|
export declare const isSolanaChainId: (chainId: ChainId) => boolean;
|
|
5
4
|
export declare const assetIdToBebopToken: (assetId: AssetId) => string;
|
|
6
5
|
export declare const assetIdToBebopSolanaToken: (assetId: AssetId) => string;
|
|
7
|
-
export declare const isSupportedChainId: (chainId: ChainId) => chainId is
|
|
6
|
+
export declare const isSupportedChainId: (chainId: ChainId) => chainId is import("@shapeshiftoss/types").KnownChainIds.EthereumMainnet | import("@shapeshiftoss/types").KnownChainIds.AvalancheMainnet | import("@shapeshiftoss/types").KnownChainIds.OptimismMainnet | import("@shapeshiftoss/types").KnownChainIds.BnbSmartChainMainnet | import("@shapeshiftoss/types").KnownChainIds.PolygonMainnet | import("@shapeshiftoss/types").KnownChainIds.ArbitrumMainnet | import("@shapeshiftoss/types").KnownChainIds.BaseMainnet | import("@shapeshiftoss/types").KnownChainIds.SolanaMainnet;
|
|
8
7
|
export declare const assertValidTrade: ({ buyAsset, sellAsset, }: {
|
|
9
8
|
buyAsset: Asset;
|
|
10
9
|
sellAsset: Asset;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { isGatewayError } from '@gobob/bob-sdk';
|
|
2
|
+
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
4
|
+
import { bnOrZero } from '@shapeshiftoss/utils';
|
|
5
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils.js';
|
|
6
|
+
import { getBobGatewayTradeQuote } from './swapperApi/getTradeQuote.js';
|
|
7
|
+
import { getBobGatewayTradeRate } from './swapperApi/getTradeRate.js';
|
|
8
|
+
import { getBobGatewayClient, mapBobGatewayOrderStatusToTxStatus, registerBobGatewayTx, } from './utils/helpers.js';
|
|
9
|
+
const registeredSwapIds = new Set();
|
|
10
|
+
export const bobGatewayApi = {
|
|
11
|
+
getTradeRate: async (input, deps) => {
|
|
12
|
+
return (await getBobGatewayTradeRate(input, deps)).map(tradeRate => [tradeRate]);
|
|
13
|
+
},
|
|
14
|
+
getTradeQuote: async (input, deps) => {
|
|
15
|
+
return (await getBobGatewayTradeQuote(input, deps)).map(tradeQuote => [tradeQuote]);
|
|
16
|
+
},
|
|
17
|
+
getUnsignedUtxoTransaction: ({ stepIndex, tradeQuote, xpub, accountType, assertGetUtxoChainAdapter, }) => {
|
|
18
|
+
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
19
|
+
throw new Error('[BobGateway] unable to execute a trade rate');
|
|
20
|
+
}
|
|
21
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
22
|
+
const { bobSpecific, sellAsset } = step;
|
|
23
|
+
const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
24
|
+
if (!bobSpecific?.utxoTx)
|
|
25
|
+
throw new Error('[BobGateway] invalid utxo transaction');
|
|
26
|
+
const { depositAddress, opReturnData } = bobSpecific.utxoTx;
|
|
27
|
+
return adapter.buildSendApiTransaction({
|
|
28
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
29
|
+
xpub,
|
|
30
|
+
to: depositAddress,
|
|
31
|
+
accountNumber: step.accountNumber,
|
|
32
|
+
skipToAddressValidation: true,
|
|
33
|
+
chainSpecific: {
|
|
34
|
+
accountType,
|
|
35
|
+
opReturnData,
|
|
36
|
+
satoshiPerByte: step.feeData.chainSpecific.satsPerByte,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
getUtxoTransactionFees: async ({ stepIndex, tradeQuote, xpub, assertGetUtxoChainAdapter }) => {
|
|
41
|
+
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
42
|
+
throw new Error('[BobGateway] unable to execute a trade rate');
|
|
43
|
+
}
|
|
44
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
45
|
+
const { bobSpecific, sellAsset } = step;
|
|
46
|
+
const adapter = assertGetUtxoChainAdapter(sellAsset.chainId);
|
|
47
|
+
if (!bobSpecific?.utxoTx)
|
|
48
|
+
throw new Error('[BobGateway] invalid utxo transaction');
|
|
49
|
+
const { depositAddress, opReturnData } = bobSpecific.utxoTx;
|
|
50
|
+
const { fast } = await adapter.getFeeData({
|
|
51
|
+
to: depositAddress,
|
|
52
|
+
value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
53
|
+
chainSpecific: { pubkey: xpub, opReturnData },
|
|
54
|
+
sendMax: false,
|
|
55
|
+
});
|
|
56
|
+
return fast.txFee;
|
|
57
|
+
},
|
|
58
|
+
getUnsignedEvmTransaction: async ({ from, stepIndex, tradeQuote, assertGetEvmChainAdapter, supportsEIP1559, }) => {
|
|
59
|
+
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
60
|
+
throw new Error('[BobGateway] unable to execute a trade rate');
|
|
61
|
+
}
|
|
62
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
63
|
+
const { accountNumber, bobSpecific, sellAsset } = step;
|
|
64
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
65
|
+
if (!bobSpecific?.evmTx)
|
|
66
|
+
throw new Error('[BobGateway] invalid evm transaction');
|
|
67
|
+
const { to, data, value } = bobSpecific.evmTx;
|
|
68
|
+
const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
|
|
69
|
+
// Pad the gas limit of the tx we actually broadcast to reduce the risk of out-of-gas reverts.
|
|
70
|
+
const gasLimit = bnOrZero(feeData.gasLimit).times(1.2).toFixed(0);
|
|
71
|
+
return adapter.buildCustomApiTx({
|
|
72
|
+
accountNumber,
|
|
73
|
+
from,
|
|
74
|
+
to,
|
|
75
|
+
value,
|
|
76
|
+
data,
|
|
77
|
+
...feeData,
|
|
78
|
+
gasLimit,
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
getEvmTransactionFees: async ({ from, stepIndex, tradeQuote, supportsEIP1559, assertGetEvmChainAdapter, }) => {
|
|
82
|
+
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
83
|
+
throw new Error('[BobGateway] unable to execute a trade rate');
|
|
84
|
+
}
|
|
85
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
86
|
+
const { bobSpecific, sellAsset } = step;
|
|
87
|
+
const adapter = assertGetEvmChainAdapter(sellAsset.chainId);
|
|
88
|
+
if (!bobSpecific?.evmTx)
|
|
89
|
+
throw new Error('[BobGateway] invalid evm transaction');
|
|
90
|
+
const { to, data, value } = bobSpecific.evmTx;
|
|
91
|
+
const feeData = await evm.getFees({ adapter, data, to, value, from, supportsEIP1559 });
|
|
92
|
+
return feeData.networkFeeCryptoBaseUnit;
|
|
93
|
+
},
|
|
94
|
+
checkTradeStatus: async ({ swap, config, txHash }) => {
|
|
95
|
+
if (!swap)
|
|
96
|
+
throw new Error('[BobGateway] swap is required for status check');
|
|
97
|
+
const orderId = swap.metadata.bobSpecific?.orderId;
|
|
98
|
+
if (!orderId)
|
|
99
|
+
throw new Error('[BobGateway] orderId is required for status check');
|
|
100
|
+
if (txHash && !registeredSwapIds.has(swap.id)) {
|
|
101
|
+
try {
|
|
102
|
+
await registerBobGatewayTx({
|
|
103
|
+
config,
|
|
104
|
+
orderId,
|
|
105
|
+
txHash,
|
|
106
|
+
sellAsset: swap.sellAsset,
|
|
107
|
+
buyAsset: swap.buyAsset,
|
|
108
|
+
});
|
|
109
|
+
registeredSwapIds.add(swap.id);
|
|
110
|
+
}
|
|
111
|
+
catch { }
|
|
112
|
+
}
|
|
113
|
+
let orderInfo;
|
|
114
|
+
try {
|
|
115
|
+
orderInfo = await getBobGatewayClient(config).getOrder(orderId);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
if (isGatewayError(err)) {
|
|
119
|
+
if (err.code === 'ORDER_NOT_FOUND') {
|
|
120
|
+
return {
|
|
121
|
+
buyTxHash: undefined,
|
|
122
|
+
status: TxStatus.Unknown,
|
|
123
|
+
message: 'Waiting for deposit...',
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
const status = mapBobGatewayOrderStatusToTxStatus(orderInfo.status);
|
|
130
|
+
const buyTxHash = 'success' in orderInfo.status ? orderInfo.status.success.receivedTokens[0]?.txHash : undefined;
|
|
131
|
+
const refundTxHash = 'refunded' in orderInfo.status
|
|
132
|
+
? orderInfo.status.refunded.refundedTokens[0]?.txHash
|
|
133
|
+
: undefined;
|
|
134
|
+
return {
|
|
135
|
+
status,
|
|
136
|
+
buyTxHash,
|
|
137
|
+
message: refundTxHash ? 'Trade refunded' : undefined,
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { CommonTradeQuoteInput, SwapErrorRight, SwapperDeps, TradeQuote } from '../../../types.js';
|
|
3
|
+
export declare const getBobGatewayTradeQuote: (input: CommonTradeQuoteInput, deps: SwapperDeps) => Promise<Result<TradeQuote, SwapErrorRight>>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
3
|
+
import { v4 as uuid } from 'uuid';
|
|
4
|
+
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
5
|
+
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
6
|
+
import { assertValidTrade, createBobGatewayOrderMetadata, getBobGatewayAllowanceContract, getBobGatewayQuote, getBobGatewayQuoteFeeData, parseBobGatewayQuote, } from '../utils/helpers.js';
|
|
7
|
+
export const getBobGatewayTradeQuote = async (input, deps) => {
|
|
8
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, sendAddress, receiveAddress, accountNumber, affiliateBps, slippageTolerancePercentageDecimal, } = input;
|
|
9
|
+
const { config } = deps;
|
|
10
|
+
if (!sendAddress) {
|
|
11
|
+
return Err(makeSwapErrorRight({
|
|
12
|
+
message: '[BobGateway] sendAddress is required for quote',
|
|
13
|
+
code: TradeQuoteError.UnknownError,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
if (!receiveAddress) {
|
|
17
|
+
return Err(makeSwapErrorRight({
|
|
18
|
+
message: '[BobGateway] receiveAddress is required for quote',
|
|
19
|
+
code: TradeQuoteError.UnknownError,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
const assertion = assertValidTrade({ sellAsset, buyAsset });
|
|
23
|
+
if (assertion.isErr())
|
|
24
|
+
return Err(assertion.unwrapErr());
|
|
25
|
+
const { sellChainName, buyChainName } = assertion.unwrap();
|
|
26
|
+
// omit the sender for utxo sells so order creation does not enforce a per-address confirmed
|
|
27
|
+
// funds check (deposits are matched via op_return, not the sending address)
|
|
28
|
+
const sender = isEvmChainId(sellAsset.chainId) ? sendAddress : undefined;
|
|
29
|
+
const maybeQuote = await getBobGatewayQuote({
|
|
30
|
+
config,
|
|
31
|
+
sellAsset,
|
|
32
|
+
buyAsset,
|
|
33
|
+
sellChainName,
|
|
34
|
+
buyChainName,
|
|
35
|
+
sender,
|
|
36
|
+
recipient: receiveAddress,
|
|
37
|
+
amount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
38
|
+
affiliateBps,
|
|
39
|
+
slippageTolerancePercentageDecimal,
|
|
40
|
+
});
|
|
41
|
+
if (maybeQuote.isErr())
|
|
42
|
+
return Err(maybeQuote.unwrapErr());
|
|
43
|
+
const quote = maybeQuote.unwrap();
|
|
44
|
+
const maybeOrderMetadata = await createBobGatewayOrderMetadata(config, quote);
|
|
45
|
+
if (maybeOrderMetadata.isErr())
|
|
46
|
+
return Err(maybeOrderMetadata.unwrapErr());
|
|
47
|
+
const orderMetadata = maybeOrderMetadata.unwrap();
|
|
48
|
+
const maybeFeeData = await getBobGatewayQuoteFeeData(input, deps, orderMetadata);
|
|
49
|
+
if (maybeFeeData.isErr())
|
|
50
|
+
return Err(maybeFeeData.unwrapErr());
|
|
51
|
+
const feeData = maybeFeeData.unwrap();
|
|
52
|
+
const { buyAmountBeforeFeesCryptoBaseUnit, buyAmountAfterFeesCryptoBaseUnit, protocolFees, estimatedExecutionTimeMs, } = parseBobGatewayQuote(quote, buyAsset, deps.assetsById);
|
|
53
|
+
const rate = getInputOutputRate({
|
|
54
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
55
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
56
|
+
sellAsset,
|
|
57
|
+
buyAsset,
|
|
58
|
+
});
|
|
59
|
+
const allowanceContract = getBobGatewayAllowanceContract(quote, sellAsset);
|
|
60
|
+
const tradeQuote = {
|
|
61
|
+
id: uuid(),
|
|
62
|
+
quoteOrRate: 'quote',
|
|
63
|
+
rate,
|
|
64
|
+
receiveAddress,
|
|
65
|
+
affiliateBps,
|
|
66
|
+
slippageTolerancePercentageDecimal,
|
|
67
|
+
swapperName: SwapperName.BobGateway,
|
|
68
|
+
steps: [
|
|
69
|
+
{
|
|
70
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
71
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
72
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
73
|
+
feeData: { ...feeData, protocolFees },
|
|
74
|
+
rate,
|
|
75
|
+
source: SwapperName.BobGateway,
|
|
76
|
+
buyAsset,
|
|
77
|
+
sellAsset,
|
|
78
|
+
accountNumber,
|
|
79
|
+
allowanceContract,
|
|
80
|
+
estimatedExecutionTimeMs,
|
|
81
|
+
bobSpecific: orderMetadata,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
return Ok(tradeQuote);
|
|
86
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result } from '@sniptt/monads';
|
|
2
|
+
import type { GetTradeRateInput, SwapErrorRight, SwapperDeps, TradeRate } from '../../../types.js';
|
|
3
|
+
export declare const getBobGatewayTradeRate: (input: GetTradeRateInput, deps: SwapperDeps) => Promise<Result<TradeRate, SwapErrorRight>>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { btcChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { Err, Ok } from '@sniptt/monads';
|
|
3
|
+
import { v4 as uuid } from 'uuid';
|
|
4
|
+
import { SwapperName } from '../../../types.js';
|
|
5
|
+
import { getInputOutputRate } from '../../../utils.js';
|
|
6
|
+
import { DUMMY_BTC_ADDRESS, DUMMY_EVM_ADDRESS } from '../utils/constants.js';
|
|
7
|
+
import { assertValidTrade, getBobGatewayAllowanceContract, getBobGatewayQuote, getBobGatewayRateNetworkFeeCryptoBaseUnit, parseBobGatewayQuote, } from '../utils/helpers.js';
|
|
8
|
+
export const getBobGatewayTradeRate = async (input, deps) => {
|
|
9
|
+
const { sellAsset, buyAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, receiveAddress, accountNumber, affiliateBps, slippageTolerancePercentageDecimal, } = input;
|
|
10
|
+
const { config } = deps;
|
|
11
|
+
const assertion = assertValidTrade({ sellAsset, buyAsset });
|
|
12
|
+
if (assertion.isErr())
|
|
13
|
+
return Err(assertion.unwrapErr());
|
|
14
|
+
const { sellChainName, buyChainName } = assertion.unwrap();
|
|
15
|
+
const recipient = receiveAddress ?? (buyAsset.chainId === btcChainId ? DUMMY_BTC_ADDRESS : DUMMY_EVM_ADDRESS);
|
|
16
|
+
const sender = sellAsset.chainId === btcChainId ? undefined : DUMMY_EVM_ADDRESS;
|
|
17
|
+
const maybeQuote = await getBobGatewayQuote({
|
|
18
|
+
config,
|
|
19
|
+
sellAsset,
|
|
20
|
+
buyAsset,
|
|
21
|
+
sellChainName,
|
|
22
|
+
buyChainName,
|
|
23
|
+
sender,
|
|
24
|
+
recipient,
|
|
25
|
+
amount: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
26
|
+
affiliateBps,
|
|
27
|
+
slippageTolerancePercentageDecimal,
|
|
28
|
+
});
|
|
29
|
+
if (maybeQuote.isErr())
|
|
30
|
+
return Err(maybeQuote.unwrapErr());
|
|
31
|
+
const quote = maybeQuote.unwrap();
|
|
32
|
+
const { buyAmountBeforeFeesCryptoBaseUnit, buyAmountAfterFeesCryptoBaseUnit, protocolFees, estimatedExecutionTimeMs, } = parseBobGatewayQuote(quote, buyAsset, deps.assetsById);
|
|
33
|
+
const rate = getInputOutputRate({
|
|
34
|
+
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
35
|
+
buyAmountCryptoBaseUnit: buyAmountAfterFeesCryptoBaseUnit,
|
|
36
|
+
sellAsset,
|
|
37
|
+
buyAsset,
|
|
38
|
+
});
|
|
39
|
+
const allowanceContract = getBobGatewayAllowanceContract(quote, sellAsset);
|
|
40
|
+
const networkFeeCryptoBaseUnit = await getBobGatewayRateNetworkFeeCryptoBaseUnit(quote, sellAsset, deps);
|
|
41
|
+
const tradeRate = {
|
|
42
|
+
id: uuid(),
|
|
43
|
+
quoteOrRate: 'rate',
|
|
44
|
+
rate,
|
|
45
|
+
receiveAddress,
|
|
46
|
+
affiliateBps,
|
|
47
|
+
slippageTolerancePercentageDecimal,
|
|
48
|
+
swapperName: SwapperName.BobGateway,
|
|
49
|
+
steps: [
|
|
50
|
+
{
|
|
51
|
+
buyAmountBeforeFeesCryptoBaseUnit,
|
|
52
|
+
buyAmountAfterFeesCryptoBaseUnit,
|
|
53
|
+
sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
54
|
+
feeData: {
|
|
55
|
+
networkFeeCryptoBaseUnit,
|
|
56
|
+
protocolFees,
|
|
57
|
+
},
|
|
58
|
+
rate,
|
|
59
|
+
source: SwapperName.BobGateway,
|
|
60
|
+
buyAsset,
|
|
61
|
+
sellAsset,
|
|
62
|
+
accountNumber,
|
|
63
|
+
allowanceContract,
|
|
64
|
+
estimatedExecutionTimeMs,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
return Ok(tradeRate);
|
|
69
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type BobGatewayEvmTxMetadata = {
|
|
2
|
+
to: string;
|
|
3
|
+
data: string;
|
|
4
|
+
value: string;
|
|
5
|
+
chain: string;
|
|
6
|
+
};
|
|
7
|
+
type BobGatewayUtxoTxMetadata = {
|
|
8
|
+
depositAddress: string;
|
|
9
|
+
opReturnData?: string;
|
|
10
|
+
};
|
|
11
|
+
export type BobGatewayMetadata = {
|
|
12
|
+
orderId: string;
|
|
13
|
+
} & ({
|
|
14
|
+
evmTx: BobGatewayEvmTxMetadata;
|
|
15
|
+
utxoTx?: never;
|
|
16
|
+
} | {
|
|
17
|
+
utxoTx: BobGatewayUtxoTxMetadata;
|
|
18
|
+
evmTx?: never;
|
|
19
|
+
});
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
export declare const BOB_GATEWAY_BASE_URL = "https://gateway-api-mainnet.gobob.xyz";
|
|
3
|
+
export declare const chainIdToBobGatewayChainName: {
|
|
4
|
+
readonly [x: string]: "arbitrum" | "avalanche" | "base" | "bera" | "bitcoin" | "bob" | "bsc" | "ethereum" | "sei" | "sonic" | "unichain";
|
|
5
|
+
};
|
|
6
|
+
export declare const bobGatewayChainNameToChainId: Record<BobGatewayChainName, ChainId>;
|
|
7
|
+
export type BobGatewayChainName = (typeof chainIdToBobGatewayChainName)[keyof typeof chainIdToBobGatewayChainName];
|
|
8
|
+
export declare const DUMMY_EVM_ADDRESS: `0x${string}`;
|
|
9
|
+
export declare const DUMMY_BTC_ADDRESS = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
|
|
10
|
+
export declare const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = "350000";
|
|
11
|
+
export declare const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = "550000";
|
|
12
|
+
export declare const BOB_GATEWAY_ONRAMP_DEFAULT_TX_VSIZE = "200";
|
|
13
|
+
export declare const decimalSlippageToBobBps: (slippageDecimal: string) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { arbitrumChainId, avalancheChainId, baseChainId, berachainChainId, bobChainId, bscChainId, btcChainId, ethChainId, seiChainId, sonicChainId, unichainChainId, } from '@shapeshiftoss/caip';
|
|
2
|
+
export const BOB_GATEWAY_BASE_URL = 'https://gateway-api-mainnet.gobob.xyz';
|
|
3
|
+
// Chain name strings expected by the BOB Gateway API
|
|
4
|
+
// https://gateway-api-mainnet.gobob.xyz/v2/get-routes
|
|
5
|
+
export const chainIdToBobGatewayChainName = {
|
|
6
|
+
[arbitrumChainId]: 'arbitrum',
|
|
7
|
+
[avalancheChainId]: 'avalanche',
|
|
8
|
+
[baseChainId]: 'base',
|
|
9
|
+
[berachainChainId]: 'bera',
|
|
10
|
+
[btcChainId]: 'bitcoin',
|
|
11
|
+
[bobChainId]: 'bob',
|
|
12
|
+
[bscChainId]: 'bsc',
|
|
13
|
+
[ethChainId]: 'ethereum',
|
|
14
|
+
[seiChainId]: 'sei',
|
|
15
|
+
[sonicChainId]: 'sonic',
|
|
16
|
+
[unichainChainId]: 'unichain',
|
|
17
|
+
};
|
|
18
|
+
export const bobGatewayChainNameToChainId = Object.fromEntries(Object.entries(chainIdToBobGatewayChainName).map(([chainId, chainName]) => [chainName, chainId]));
|
|
19
|
+
export const DUMMY_EVM_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
|
20
|
+
export const DUMMY_BTC_ADDRESS = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
|
|
21
|
+
export const BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = '350000'; // EVM→EVM
|
|
22
|
+
export const BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = '550000'; // EVM→BTC
|
|
23
|
+
export const BOB_GATEWAY_ONRAMP_DEFAULT_TX_VSIZE = '200'; // BTC→EVM
|
|
24
|
+
// https://docs.gobob.xyz/api-reference/v2/get-a-gateway-quote#parameter-slippage
|
|
25
|
+
export const decimalSlippageToBobBps = (slippageDecimal) => {
|
|
26
|
+
return String(Math.round(parseFloat(slippageDecimal) * 10_000));
|
|
27
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GatewayOrderStatusV2, GatewayQuoteV2, GetQuoteParams } from '@gobob/bob-sdk';
|
|
2
|
+
import { GatewaySDK } from '@gobob/bob-sdk';
|
|
3
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
4
|
+
import type { Asset, AssetsByIdPartial } from '@shapeshiftoss/types';
|
|
5
|
+
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
6
|
+
import type { Result } from '@sniptt/monads';
|
|
7
|
+
import type { GetTradeQuoteInput, QuoteFeeData, SwapErrorRight, SwapperConfig, SwapperDeps } from '../../../types.js';
|
|
8
|
+
import type { BobGatewayMetadata } from '../types.js';
|
|
9
|
+
import type { BobGatewayChainName } from './constants.js';
|
|
10
|
+
export declare const getBobGatewayClient: (config: SwapperConfig) => GatewaySDK;
|
|
11
|
+
export declare const assetIdToBobGatewayToken: (assetId: string) => string;
|
|
12
|
+
export declare const getBobGatewayAffiliates: (affiliateBps: string) => GetQuoteParams['affiliates'];
|
|
13
|
+
export declare const getBobGatewayQuote: ({ config, sellAsset, buyAsset, sellChainName, buyChainName, sender, recipient, amount, affiliateBps, slippageTolerancePercentageDecimal, }: {
|
|
14
|
+
config: SwapperConfig;
|
|
15
|
+
sellAsset: Asset;
|
|
16
|
+
buyAsset: Asset;
|
|
17
|
+
sellChainName: BobGatewayChainName;
|
|
18
|
+
buyChainName: BobGatewayChainName;
|
|
19
|
+
sender: string | undefined;
|
|
20
|
+
recipient: string;
|
|
21
|
+
amount: string;
|
|
22
|
+
affiliateBps: string;
|
|
23
|
+
slippageTolerancePercentageDecimal: string | undefined;
|
|
24
|
+
}) => Promise<Result<GatewayQuoteV2, SwapErrorRight>>;
|
|
25
|
+
export declare const createBobGatewayOrderMetadata: (config: SwapperConfig, gatewayQuote: GatewayQuoteV2) => Promise<Result<BobGatewayMetadata, SwapErrorRight>>;
|
|
26
|
+
export declare const registerBobGatewayTx: ({ config, orderId, txHash, sellAsset, buyAsset, }: {
|
|
27
|
+
config: SwapperConfig;
|
|
28
|
+
orderId: string;
|
|
29
|
+
txHash: string;
|
|
30
|
+
sellAsset: Asset;
|
|
31
|
+
buyAsset: Asset;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
export declare const getBobGatewayQuoteFeeData: (input: GetTradeQuoteInput, { assertGetUtxoChainAdapter, assertGetEvmChainAdapter }: SwapperDeps, orderMetadata: BobGatewayMetadata) => Promise<Result<Omit<QuoteFeeData, 'protocolFees'>, SwapErrorRight>>;
|
|
34
|
+
export declare const getBobGatewayRateNetworkFeeCryptoBaseUnit: (quote: GatewayQuoteV2, sellAsset: Asset, { assertGetEvmChainAdapter, assertGetUtxoChainAdapter }: SwapperDeps) => Promise<string | undefined>;
|
|
35
|
+
export declare const mapBobGatewayOrderStatusToTxStatus: (status: GatewayOrderStatusV2) => TxStatus;
|
|
36
|
+
export declare const parseBobGatewayQuote: (quote: GatewayQuoteV2, buyAsset: Asset, assetsById: AssetsByIdPartial) => {
|
|
37
|
+
buyAmountBeforeFeesCryptoBaseUnit: string;
|
|
38
|
+
buyAmountAfterFeesCryptoBaseUnit: string;
|
|
39
|
+
protocolFees: Partial<Record<AssetId, import("../../../types.js").ProtocolFee>>;
|
|
40
|
+
estimatedExecutionTimeMs: number | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare const getBobGatewayAllowanceContract: (quote: GatewayQuoteV2, sellAsset: Asset) => string;
|
|
43
|
+
export declare const assertValidTrade: ({ sellAsset, buyAsset, }: {
|
|
44
|
+
sellAsset: Asset;
|
|
45
|
+
buyAsset: Asset;
|
|
46
|
+
}) => Result<{
|
|
47
|
+
sellChainName: BobGatewayChainName;
|
|
48
|
+
buyChainName: BobGatewayChainName;
|
|
49
|
+
}, SwapErrorRight>;
|