@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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +10 -1
- package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +2 -33
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +8 -5
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +30 -34
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +117 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +36 -31
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/cjs/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +0 -51
- package/dist/cjs/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/cjs/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/constants.js +4 -1
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +115 -73
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -4
- package/dist/cjs/swappers/ButterSwap/xhr.js +3 -3
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.js +31 -12
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayAssetAddress.js +2 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.js +139 -0
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +3 -63
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -30
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +5 -9
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +54 -20
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.js +177 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +3 -2
- package/dist/cjs/swappers/SunioSwapper/utils/helpers.js +2 -1
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +3 -4
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +31 -0
- package/dist/cjs/types.d.ts +9 -8
- package/dist/cjs/utils/helpers.js +3 -0
- package/dist/cjs/utils/helpers.test.js +3 -0
- package/dist/cjs/utils/thorchain/getThorStepData.js +32 -49
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.js +93 -0
- package/dist/cjs/utils/thorchain/index.d.ts +0 -1
- package/dist/cjs/utils/thorchain/index.js +1 -14
- package/dist/cjs/utils/tron/constants.d.ts +1 -0
- package/dist/cjs/utils/tron/constants.js +5 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +64 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +157 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.js +76 -0
- package/dist/cjs/utils/tron/index.d.ts +2 -0
- package/dist/cjs/utils/tron/index.js +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/esm/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +11 -2
- package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +5 -36
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +8 -7
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +21 -25
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +115 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +13 -30
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/esm/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -49
- package/dist/esm/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/esm/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/esm/swappers/ButterSwap/utils/constants.js +3 -0
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +116 -74
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +2 -5
- package/dist/esm/swappers/ButterSwap/xhr.js +3 -3
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.js +32 -13
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
- package/dist/esm/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayAssetAddress.js +3 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.js +137 -0
- package/dist/esm/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +3 -3
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/esm/swappers/SunioSwapper/endpoints.js +5 -65
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/esm/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +31 -28
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +4 -8
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +52 -18
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.js +175 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +2 -1
- package/dist/esm/swappers/SunioSwapper/utils/helpers.js +3 -2
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +4 -5
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +29 -1
- package/dist/esm/types.d.ts +9 -8
- package/dist/esm/utils/helpers.js +4 -1
- package/dist/esm/utils/helpers.test.js +3 -0
- package/dist/esm/utils/thorchain/getThorStepData.js +32 -49
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.js +91 -0
- package/dist/esm/utils/thorchain/index.d.ts +0 -1
- package/dist/esm/utils/thorchain/index.js +0 -1
- package/dist/esm/utils/tron/constants.d.ts +1 -0
- package/dist/esm/utils/tron/constants.js +2 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +59 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +155 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/esm/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.js +74 -0
- package/dist/esm/utils/tron/index.d.ts +2 -0
- package/dist/esm/utils/tron/index.js +2 -0
- package/package.json +9 -9
- package/dist/cjs/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -32
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -78
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -36
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.js +0 -68
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -35
- package/dist/cjs/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/index.js +0 -18
- package/dist/esm/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -28
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -74
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -32
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.js +0 -64
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -31
- package/dist/esm/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/index.js +0 -2
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
- /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /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,
|
|
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>>;
|
|
@@ -30,16 +30,15 @@ const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtoco
|
|
|
30
30
|
approval_type: 'Standard',
|
|
31
31
|
skip_validation: 'true',
|
|
32
32
|
gasless: 'false',
|
|
33
|
+
// PMM fees are configured against our api key on Bebop's side, not sent per quote
|
|
33
34
|
source: 'shapeshift',
|
|
34
35
|
};
|
|
35
36
|
const jamParams = new URLSearchParams(baseParams);
|
|
36
37
|
const pmmParams = new URLSearchParams(baseParams);
|
|
38
|
+
// JAM settles the fee on-chain, so it still takes our bps and a recipient per quote
|
|
37
39
|
if (affiliateBps && affiliateBps !== '0') {
|
|
38
|
-
// JAM collects the fee on-chain and requires a recipient
|
|
39
40
|
jamParams.set('fee', affiliateBps);
|
|
40
41
|
jamParams.set('fee_recipient', (0, viem_1.getAddress)((0, helpers_1.getTreasuryAddressFromChainId)(buyAsset.chainId)));
|
|
41
|
-
// PMM attributes the fee off-chain via source
|
|
42
|
-
pmmParams.set('fee', affiliateBps);
|
|
43
42
|
}
|
|
44
43
|
const service = (0, bebopService_1.bebopServiceFactory)({ apiKey });
|
|
45
44
|
const [maybeJam, maybePmm] = await Promise.all([
|
|
@@ -81,7 +80,7 @@ const fetchBebopQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtoco
|
|
|
81
80
|
}
|
|
82
81
|
};
|
|
83
82
|
exports.fetchBebopQuote = fetchBebopQuote;
|
|
84
|
-
const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal,
|
|
83
|
+
const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingProtocolFeesCryptoBaseUnit, takerAddress, receiverAddress, slippageTolerancePercentageDecimal, apiKey, }) => {
|
|
85
84
|
try {
|
|
86
85
|
// Bebop's Solana routes don't wrap native SOL on the input side, so selling native SOL
|
|
87
86
|
// always fails on-chain. Reject up front instead of returning an unexecutable quote.
|
|
@@ -105,11 +104,9 @@ const fetchBebopSolanaQuote = async ({ buyAsset, sellAsset, sellAmountIncludingP
|
|
|
105
104
|
approval_type: 'Standard',
|
|
106
105
|
skip_validation: 'false',
|
|
107
106
|
gasless: 'true',
|
|
107
|
+
// Solana is PMM only, so its fees are configured against our api key on Bebop's side
|
|
108
108
|
source: 'shapeshift',
|
|
109
109
|
});
|
|
110
|
-
if (affiliateBps && affiliateBps !== '0') {
|
|
111
|
-
params.set('fee', affiliateBps);
|
|
112
|
-
}
|
|
113
110
|
const maybeResponse = await (0, bebopService_1.bebopServiceFactory)({ apiKey }).get('https://api.bebop.xyz/pmm/solana/v3/quote', { params });
|
|
114
111
|
if (maybeResponse.isErr()) {
|
|
115
112
|
const err = maybeResponse.unwrapErr();
|
|
@@ -22,7 +22,6 @@ const getBebopSolanaTradeContext = async ({ input, deps, takerAddress, receiverA
|
|
|
22
22
|
takerAddress,
|
|
23
23
|
receiverAddress,
|
|
24
24
|
slippageTolerancePercentageDecimal,
|
|
25
|
-
affiliateBps,
|
|
26
25
|
apiKey: deps.config.VITE_BEBOP_API_KEY,
|
|
27
26
|
});
|
|
28
27
|
if (maybeBebopQuoteResponse.isErr())
|
|
@@ -2,8 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bobGatewaySwapper = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
+
const helpers_1 = require("./utils/helpers");
|
|
5
6
|
exports.bobGatewaySwapper = {
|
|
6
7
|
executeEvmTransaction: utils_1.executeEvmTransaction,
|
|
7
|
-
executeUtxoTransaction: (txToSign, {
|
|
8
|
+
executeUtxoTransaction: async (txToSign, { signTransaction }, context) => {
|
|
9
|
+
if (!signTransaction)
|
|
10
|
+
throw new Error('[BobGateway] signTransaction is required');
|
|
11
|
+
if (!context)
|
|
12
|
+
throw new Error('[BobGateway] execution context is required');
|
|
13
|
+
const { orderId } = (0, utils_1.getSwapMetadata)(context.swapperMetadata, 'bob');
|
|
14
|
+
const bitcoinTxHex = await signTransaction(txToSign);
|
|
15
|
+
return (0, helpers_1.submitBobGatewayBtcDeposit)({ config: context.config, orderId, bitcoinTxHex });
|
|
16
|
+
},
|
|
8
17
|
executeTronTransaction: utils_1.executeTronTransaction,
|
|
9
18
|
};
|
|
@@ -10,7 +10,6 @@ const utxo_1 = require("../../utils/utxo");
|
|
|
10
10
|
const getTradeQuote_1 = require("./swapperApi/getTradeQuote");
|
|
11
11
|
const getTradeRate_1 = require("./swapperApi/getTradeRate");
|
|
12
12
|
const helpers_1 = require("./utils/helpers");
|
|
13
|
-
const registeredSwapIds = new Set();
|
|
14
13
|
exports.bobGatewayApi = {
|
|
15
14
|
getTradeRate: (input, deps) => (0, getTradeRate_1.getBobGatewayTradeRate)(input, deps),
|
|
16
15
|
getTradeQuote: (input, deps) => (0, getTradeQuote_1.getBobGatewayTradeQuote)(input, deps),
|
|
@@ -18,42 +17,12 @@ exports.bobGatewayApi = {
|
|
|
18
17
|
getUtxoTransactionFees: utxo_1.getUtxoTransactionFees,
|
|
19
18
|
getUnsignedEvmTransaction: evm_1.getUnsignedEvmTransaction,
|
|
20
19
|
getEvmTransactionFees: evm_1.getEvmTransactionFees,
|
|
21
|
-
getUnsignedTronTransaction:
|
|
22
|
-
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote)) {
|
|
23
|
-
throw new Error('[BobGateway] unable to execute a trade rate');
|
|
24
|
-
}
|
|
25
|
-
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
26
|
-
const { accountNumber, sellAsset, transactionData } = step;
|
|
27
|
-
if (transactionData?.type !== 'tron')
|
|
28
|
-
throw new Error('[BobGateway] invalid tron transaction');
|
|
29
|
-
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
30
|
-
const { to, data, value } = transactionData;
|
|
31
|
-
return adapter.buildCustomApiTx({
|
|
32
|
-
accountNumber,
|
|
33
|
-
from,
|
|
34
|
-
to: (0, helpers_1.toTronBase58)(to),
|
|
35
|
-
value,
|
|
36
|
-
data,
|
|
37
|
-
});
|
|
38
|
-
},
|
|
20
|
+
getUnsignedTronTransaction: tron_1.getUnsignedTronTransaction,
|
|
39
21
|
getTronTransactionFees: tron_1.getTronTransactionFees,
|
|
40
|
-
checkTradeStatus: async ({ swap, config
|
|
22
|
+
checkTradeStatus: async ({ swap, config }) => {
|
|
41
23
|
if (!swap)
|
|
42
24
|
throw new Error('[BobGateway] swap is required for status check');
|
|
43
25
|
const { orderId } = (0, utils_1.getSwapMetadata)(swap.metadata.swapperMetadata, 'bob');
|
|
44
|
-
if (txHash && !registeredSwapIds.has(swap.id)) {
|
|
45
|
-
try {
|
|
46
|
-
await (0, helpers_1.registerBobGatewayTx)({
|
|
47
|
-
config,
|
|
48
|
-
orderId,
|
|
49
|
-
txHash,
|
|
50
|
-
sellAsset: swap.sellAsset,
|
|
51
|
-
buyAsset: swap.buyAsset,
|
|
52
|
-
});
|
|
53
|
-
registeredSwapIds.add(swap.id);
|
|
54
|
-
}
|
|
55
|
-
catch { }
|
|
56
|
-
}
|
|
57
26
|
let orderInfo;
|
|
58
27
|
try {
|
|
59
28
|
orderInfo = await (0, helpers_1.getBobGatewayClient)(config).getOrder(orderId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBobGatewayTradeQuote = void 0;
|
|
4
|
-
const
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const monads_1 = require("@sniptt/monads");
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const helpers_1 = require("../../../utils/helpers");
|
|
@@ -13,18 +13,15 @@ const getBobGatewayTradeQuote = async (input, deps) => {
|
|
|
13
13
|
if (maybeAddresses.isErr())
|
|
14
14
|
return (0, monads_1.Err)(maybeAddresses.unwrapErr());
|
|
15
15
|
const { sendAddress, receiveAddress } = maybeAddresses.unwrap();
|
|
16
|
-
const
|
|
17
|
-
// omit the sender for
|
|
18
|
-
|
|
19
|
-
const sender = isEvmSell ? sendAddress : undefined;
|
|
20
|
-
// utxo deposits are refunded on the sell chain, so refunds go to the sending address
|
|
21
|
-
const refundAddress = isEvmSell ? undefined : sendAddress;
|
|
16
|
+
const isBtcSell = sellAsset.chainId === caip_1.btcChainId;
|
|
17
|
+
// omit the sender for btc sells so the sdk doesn't build a psbt from a single address
|
|
18
|
+
const sender = isBtcSell ? undefined : sendAddress;
|
|
22
19
|
const maybeContext = await (0, getBobGatewayTradeContext_1.getBobGatewayTradeContext)({
|
|
23
20
|
input,
|
|
24
21
|
deps,
|
|
25
22
|
sender,
|
|
26
23
|
recipient: receiveAddress,
|
|
27
|
-
refundAddress,
|
|
24
|
+
refundAddress: sendAddress,
|
|
28
25
|
});
|
|
29
26
|
if (maybeContext.isErr())
|
|
30
27
|
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
@@ -11,8 +11,7 @@ const getBobGatewayTradeRate = async (input, deps) => {
|
|
|
11
11
|
const isBtcSell = sellAsset.chainId === caip_1.btcChainId;
|
|
12
12
|
const recipient = receiveAddress ?? (0, helpers_1.dummyAddressForChainId)(buyAsset.chainId);
|
|
13
13
|
const sender = isBtcSell ? undefined : (0, helpers_1.dummyAddressForChainId)(sellAsset.chainId);
|
|
14
|
-
|
|
15
|
-
const refundAddress = isBtcSell ? (0, helpers_1.dummyAddressForChainId)(sellAsset.chainId) : undefined;
|
|
14
|
+
const refundAddress = (0, helpers_1.dummyAddressForChainId)(sellAsset.chainId);
|
|
16
15
|
const maybeContext = await (0, getBobGatewayTradeContext_1.getBobGatewayTradeContext)({
|
|
17
16
|
input,
|
|
18
17
|
deps,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types';
|
|
1
|
+
import type { GetEvmTradeQuoteInput, GetEvmTradeRateInput, GetTronTradeQuoteInput, GetTronTradeRateInput, GetUtxoTradeQuoteInput, GetUtxoTradeRateInput } from '../../types';
|
|
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" | "
|
|
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,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decimalSlippageToBobBps = exports.
|
|
3
|
+
exports.decimalSlippageToBobBps = exports.BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES = exports.BOB_GATEWAY_TRON_DEFAULT_ENERGY = exports.BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = exports.BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = exports.DUMMY_BTC_ADDRESS = exports.DUMMY_EVM_ADDRESS = exports.bobGatewayChainNameToChainId = exports.chainIdToBobGatewayChainName = exports.BOB_GATEWAY_BASE_URL = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
exports.BOB_GATEWAY_BASE_URL = 'https://gateway-api-mainnet.gobob.xyz';
|
|
6
6
|
// Chain name strings expected by the BOB Gateway API
|
|
7
|
-
// https://gateway-api-mainnet.gobob.xyz/
|
|
7
|
+
// https://gateway-api-mainnet.gobob.xyz/v4/get-routes
|
|
8
8
|
exports.chainIdToBobGatewayChainName = {
|
|
9
9
|
[caip_1.arbitrumChainId]: 'arbitrum',
|
|
10
10
|
[caip_1.avalancheChainId]: 'avalanche',
|
|
@@ -19,15 +19,18 @@ exports.chainIdToBobGatewayChainName = {
|
|
|
19
19
|
[caip_1.unichainChainId]: 'unichain',
|
|
20
20
|
[caip_1.plasmaChainId]: 'plasma',
|
|
21
21
|
[caip_1.polygonChainId]: 'polygon',
|
|
22
|
-
[caip_1.hyperEvmChainId]: '
|
|
23
|
-
|
|
22
|
+
[caip_1.hyperEvmChainId]: 'hyperevm',
|
|
23
|
+
[caip_1.robinhoodChainId]: 'robinhood',
|
|
24
|
+
[caip_1.tronChainId]: 'tron',
|
|
24
25
|
};
|
|
25
26
|
exports.bobGatewayChainNameToChainId = Object.fromEntries(Object.entries(exports.chainIdToBobGatewayChainName).map(([chainId, chainName]) => [chainName, chainId]));
|
|
26
27
|
exports.DUMMY_EVM_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
|
27
28
|
exports.DUMMY_BTC_ADDRESS = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
|
|
28
|
-
exports.DUMMY_TRON_ADDRESS = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
29
29
|
exports.BOB_GATEWAY_TOKENSWAP_DEFAULT_GAS_LIMIT = '350000'; // EVM→EVM
|
|
30
30
|
exports.BOB_GATEWAY_OFFRAMP_DEFAULT_GAS_LIMIT = '550000'; // EVM→BTC
|
|
31
|
+
// AllowanceHolder exec measured on mainnet: rates price it before an order exists, token quotes without their allowance fall back to it
|
|
32
|
+
exports.BOB_GATEWAY_TRON_DEFAULT_ENERGY = '420000';
|
|
33
|
+
exports.BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES = 4000;
|
|
31
34
|
// https://docs.gobob.xyz/api-reference/v2/get-a-gateway-quote#parameter-slippage
|
|
32
35
|
const decimalSlippageToBobBps = (slippageDecimal) => {
|
|
33
36
|
return String(Math.round(parseFloat(slippageDecimal) * 10_000));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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';
|
|
4
4
|
type BaseArgs = {
|
|
5
|
-
quote:
|
|
5
|
+
quote: GatewayQuoteV4;
|
|
6
6
|
sellAmountCryptoBaseUnit: string;
|
|
7
7
|
spenderAddress: string;
|
|
8
8
|
};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBobGatewayStepData = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
-
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
5
|
const monads_1 = require("@sniptt/monads");
|
|
7
6
|
const types_1 = require("../../../types");
|
|
8
|
-
const
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
9
8
|
const evm_1 = require("../../../utils/evm");
|
|
9
|
+
const tron_1 = require("../../../utils/tron");
|
|
10
10
|
const utxo_1 = require("../../../utils/utxo");
|
|
11
11
|
const constants_1 = require("./constants");
|
|
12
12
|
const helpers_1 = require("./helpers");
|
|
@@ -52,7 +52,7 @@ async function getBobGatewayStepData(args) {
|
|
|
52
52
|
}
|
|
53
53
|
const { orderResponse } = resolved;
|
|
54
54
|
if (!('onramp' in orderResponse))
|
|
55
|
-
return (0, monads_1.Err)((0,
|
|
55
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
56
56
|
const transactionData = {
|
|
57
57
|
type: 'utxo',
|
|
58
58
|
to: orderResponse.onramp.address,
|
|
@@ -75,7 +75,7 @@ async function getBobGatewayStepData(args) {
|
|
|
75
75
|
return (0, monads_1.Ok)(stepData);
|
|
76
76
|
}
|
|
77
77
|
catch (err) {
|
|
78
|
-
return (0, monads_1.Err)((0,
|
|
78
|
+
return (0, monads_1.Err)((0, utils_1.makeNetworkFeeEstimationFailedErr)('getBobGatewayStepData', err));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
// EVM sells (offramp EVM → BTC, or tokenSwap EVM → Tron)
|
|
@@ -102,13 +102,13 @@ async function getBobGatewayStepData(args) {
|
|
|
102
102
|
}
|
|
103
103
|
const { orderResponse, from } = resolved;
|
|
104
104
|
if (!('offramp' in orderResponse) && !('tokenSwap' in orderResponse))
|
|
105
|
-
return (0, monads_1.Err)((0,
|
|
105
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
106
106
|
const order = 'offramp' in orderResponse ? orderResponse.offramp : orderResponse.tokenSwap;
|
|
107
107
|
if (order.tx.type !== 'evm')
|
|
108
|
-
return (0, monads_1.Err)((0,
|
|
108
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
109
109
|
const { tx, orderId } = order;
|
|
110
110
|
if (!('supportsEIP1559' in input))
|
|
111
|
-
return (0, monads_1.Err)((0,
|
|
111
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
112
112
|
const transactionData = {
|
|
113
113
|
type: 'evm',
|
|
114
114
|
chainId: Number((0, caip_1.fromChainId)(sellAsset.chainId).chainReference),
|
|
@@ -136,25 +136,23 @@ async function getBobGatewayStepData(args) {
|
|
|
136
136
|
return (0, monads_1.Ok)(stepData);
|
|
137
137
|
}
|
|
138
138
|
catch (err) {
|
|
139
|
-
return (0, monads_1.Err)((0,
|
|
139
|
+
return (0, monads_1.Err)((0, utils_1.makeNetworkFeeEstimationFailedErr)('getBobGatewayStepData', err));
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
// Tron sells (offramp Tron → BTC, or tokenSwap TRON → EVM)
|
|
143
143
|
case caip_1.CHAIN_NAMESPACE.Tron: {
|
|
144
144
|
const adapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
145
|
-
const contractAddress = (0, utils_1.contractAddressOrUndefined)(sellAsset.assetId);
|
|
146
145
|
if (resolved.type === 'rate') {
|
|
146
|
+
// The gateway call isn't built until an order exists, so rates price a measured default
|
|
147
147
|
const networkFeeCryptoBaseUnit = await (async () => {
|
|
148
148
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
chainSpecific: { contractAddress },
|
|
149
|
+
return await (0, tron_1.getTronContractCallFallbackFeeCryptoBaseUnit)({
|
|
150
|
+
adapter,
|
|
151
|
+
energy: constants_1.BOB_GATEWAY_TRON_DEFAULT_ENERGY,
|
|
152
|
+
bandwidthBytes: constants_1.BOB_GATEWAY_TRON_DEFAULT_BANDWIDTH_BYTES,
|
|
153
|
+
contractAddress: spenderAddress,
|
|
154
|
+
fullEnergyOnShareLookupFailure: true,
|
|
156
155
|
});
|
|
157
|
-
return fast.txFee;
|
|
158
156
|
}
|
|
159
157
|
catch { }
|
|
160
158
|
})();
|
|
@@ -163,36 +161,34 @@ async function getBobGatewayStepData(args) {
|
|
|
163
161
|
}
|
|
164
162
|
const { orderResponse, from } = resolved;
|
|
165
163
|
if (!('offramp' in orderResponse) && !('tokenSwap' in orderResponse))
|
|
166
|
-
return (0, monads_1.Err)((0,
|
|
164
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
167
165
|
const order = 'offramp' in orderResponse ? orderResponse.offramp : orderResponse.tokenSwap;
|
|
168
166
|
if (order.tx.type !== 'tron')
|
|
169
|
-
return (0, monads_1.Err)((0,
|
|
167
|
+
return (0, monads_1.Err)((0, utils_1.makeTradeStepBuildFailedErr)('getBobGatewayStepData'));
|
|
170
168
|
const { tx, orderId } = order;
|
|
171
|
-
const
|
|
172
|
-
type: 'tron',
|
|
173
|
-
to: tx.to,
|
|
174
|
-
data: tx.data,
|
|
175
|
-
value: tx.value,
|
|
176
|
-
};
|
|
169
|
+
const call = { to: tx.to, data: tx.data, value: tx.value };
|
|
177
170
|
try {
|
|
178
|
-
const { fast } = await adapter.getFeeData({
|
|
179
|
-
to: (0, helpers_1.toTronBase58)(tx.to),
|
|
180
|
-
value: sellAmountCryptoBaseUnit,
|
|
181
|
-
chainSpecific: { from, contractAddress },
|
|
182
|
-
});
|
|
183
171
|
const stepData = {
|
|
184
172
|
orderId,
|
|
185
|
-
transactionData,
|
|
186
|
-
networkFeeCryptoBaseUnit:
|
|
173
|
+
transactionData: { type: 'tron', ...call },
|
|
174
|
+
networkFeeCryptoBaseUnit: await (0, tron_1.getTronContractCallNetworkFeeCryptoBaseUnit)({
|
|
175
|
+
adapter,
|
|
176
|
+
transactionData: call,
|
|
177
|
+
from,
|
|
178
|
+
sellAsset,
|
|
179
|
+
sellAmountCryptoBaseUnit,
|
|
180
|
+
spenderAddress,
|
|
181
|
+
fallbackEnergy: constants_1.BOB_GATEWAY_TRON_DEFAULT_ENERGY,
|
|
182
|
+
}),
|
|
187
183
|
};
|
|
188
184
|
return (0, monads_1.Ok)(stepData);
|
|
189
185
|
}
|
|
190
186
|
catch (err) {
|
|
191
|
-
return (0, monads_1.Err)((0,
|
|
187
|
+
return (0, monads_1.Err)((0, utils_1.makeNetworkFeeEstimationFailedErr)('getBobGatewayStepData', err));
|
|
192
188
|
}
|
|
193
189
|
}
|
|
194
190
|
default:
|
|
195
|
-
return (0, monads_1.Err)((0,
|
|
191
|
+
return (0, monads_1.Err)((0, utils_1.makeSwapErrorRight)({
|
|
196
192
|
message: `[BobGateway] unsupported chain namespace: ${chainNamespace}`,
|
|
197
193
|
code: types_1.TradeQuoteError.UnsupportedChain,
|
|
198
194
|
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
4
|
+
const monads_1 = require("@sniptt/monads");
|
|
5
|
+
const vitest_1 = require("vitest");
|
|
6
|
+
const assets_1 = require("../../../utils/test-data/assets");
|
|
7
|
+
const getBobGatewayStepData_1 = require("./getBobGatewayStepData");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
vitest_1.vi.mock('./helpers', () => ({ createBobGatewayOrder: vitest_1.vi.fn() }));
|
|
10
|
+
const USDT_TRON = {
|
|
11
|
+
...assets_1.ETH,
|
|
12
|
+
assetId: `${caip_1.tronChainId}/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t`,
|
|
13
|
+
chainId: caip_1.tronChainId,
|
|
14
|
+
};
|
|
15
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
16
|
+
// BOB returns the AllowanceHolder as 0x-prefixed 41-hex (TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K)
|
|
17
|
+
const ALLOWANCE_HOLDER_HEX = '0x4107a39ae4c49dee86e892450b20881f32cd5d500d';
|
|
18
|
+
const tronTx = { type: 'tron', to: ALLOWANCE_HOLDER_HEX, data: '0x2213bc0b', value: '0' };
|
|
19
|
+
const tronAdapter = ({ txFee = '45600000', allowance = '0' } = {}) => ({
|
|
20
|
+
getFeeData: vitest_1.vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
21
|
+
httpProvider: {
|
|
22
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
23
|
+
getTrc20Allowance: vitest_1.vi.fn().mockResolvedValue(allowance),
|
|
24
|
+
getTrc20Balance: vitest_1.vi.fn().mockResolvedValue('100000000'),
|
|
25
|
+
getContractEnergyShare: vitest_1.vi.fn().mockResolvedValue({
|
|
26
|
+
callerPercent: 100,
|
|
27
|
+
originEnergyLimit: 0,
|
|
28
|
+
originEnergyAvailable: 0,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const makeDeps = (tron) => ({ config: {}, assertGetTronChainAdapter: () => tron });
|
|
33
|
+
const quote = {};
|
|
34
|
+
(0, vitest_1.describe)('getBobGatewayStepData', () => {
|
|
35
|
+
(0, vitest_1.describe)('tron', () => {
|
|
36
|
+
(0, vitest_1.it)('prices a rate from the measured default energy and bandwidth at the gateway share', async () => {
|
|
37
|
+
const adapter = tronAdapter();
|
|
38
|
+
const actual = await (0, getBobGatewayStepData_1.getBobGatewayStepData)({
|
|
39
|
+
type: 'rate',
|
|
40
|
+
input: {},
|
|
41
|
+
deps: makeDeps(adapter),
|
|
42
|
+
quote,
|
|
43
|
+
sellAsset: USDT_TRON,
|
|
44
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
45
|
+
spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
|
|
46
|
+
});
|
|
47
|
+
// 420000 energy * 1.2 margin * 100 sun + 4000 bytes * 1000 sun
|
|
48
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '54400000' });
|
|
49
|
+
(0, vitest_1.expect)(adapter.httpProvider.getContractEnergyShare).toHaveBeenCalledWith('TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K');
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.it)('simulates the real gateway call for a quote', async () => {
|
|
52
|
+
vitest_1.vi.mocked(helpers_1.createBobGatewayOrder).mockResolvedValue((0, monads_1.Ok)({ offramp: { orderId: 'order-1', tx: tronTx } }));
|
|
53
|
+
const adapter = tronAdapter();
|
|
54
|
+
const actual = await (0, getBobGatewayStepData_1.getBobGatewayStepData)({
|
|
55
|
+
type: 'quote',
|
|
56
|
+
input: {},
|
|
57
|
+
deps: makeDeps(adapter),
|
|
58
|
+
quote,
|
|
59
|
+
sellAsset: USDT_TRON,
|
|
60
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
61
|
+
spenderAddress: '',
|
|
62
|
+
from: FROM,
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.expect)(adapter.getFeeData).toHaveBeenCalledWith({
|
|
65
|
+
to: ALLOWANCE_HOLDER_HEX,
|
|
66
|
+
value: '0',
|
|
67
|
+
chainSpecific: { from: FROM, data: '0x2213bc0b', requireEnergyShare: true },
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({
|
|
70
|
+
orderId: 'order-1',
|
|
71
|
+
transactionData: { type: 'tron', to: ALLOWANCE_HOLDER_HEX, data: '0x2213bc0b', value: '0' },
|
|
72
|
+
networkFeeCryptoBaseUnit: '45600000',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.it)('prices the measured worst case when the allowance is not granted yet', async () => {
|
|
76
|
+
vitest_1.vi.mocked(helpers_1.createBobGatewayOrder).mockResolvedValue((0, monads_1.Ok)({ offramp: { orderId: 'order-1', tx: tronTx } }));
|
|
77
|
+
const adapter = tronAdapter({ allowance: '0' });
|
|
78
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
79
|
+
const actual = await (0, getBobGatewayStepData_1.getBobGatewayStepData)({
|
|
80
|
+
type: 'quote',
|
|
81
|
+
input: {},
|
|
82
|
+
deps: makeDeps(adapter),
|
|
83
|
+
quote,
|
|
84
|
+
sellAsset: USDT_TRON,
|
|
85
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
86
|
+
spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
|
|
87
|
+
from: FROM,
|
|
88
|
+
});
|
|
89
|
+
// 420000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
90
|
+
(0, vitest_1.expect)(actual.unwrap()).toMatchObject({
|
|
91
|
+
orderId: 'order-1',
|
|
92
|
+
networkFeeCryptoBaseUnit: '50683000',
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.expect)(adapter.httpProvider.getTrc20Allowance).toHaveBeenCalledWith({
|
|
95
|
+
contractAddress: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
|
|
96
|
+
owner: FROM,
|
|
97
|
+
spender: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
(0, vitest_1.it)('fails the quote when the simulation reverts with the allowance in place', async () => {
|
|
101
|
+
vitest_1.vi.mocked(helpers_1.createBobGatewayOrder).mockResolvedValue((0, monads_1.Ok)({ offramp: { orderId: 'order-1', tx: tronTx } }));
|
|
102
|
+
const adapter = tronAdapter({ allowance: '100000000' });
|
|
103
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
104
|
+
const actual = await (0, getBobGatewayStepData_1.getBobGatewayStepData)({
|
|
105
|
+
type: 'quote',
|
|
106
|
+
input: {},
|
|
107
|
+
deps: makeDeps(adapter),
|
|
108
|
+
quote,
|
|
109
|
+
sellAsset: USDT_TRON,
|
|
110
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
111
|
+
spenderAddress: 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K',
|
|
112
|
+
from: FROM,
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.expect)(actual.isErr()).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBobGatewayTradeContext = void 0;
|
|
4
|
-
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
5
4
|
const monads_1 = require("@sniptt/monads");
|
|
6
5
|
const uuid_1 = require("uuid");
|
|
7
6
|
const types_1 = require("../../../types");
|
|
@@ -61,7 +60,7 @@ const getBobGatewayTradeContext = async ({ input, deps, sender, recipient, refun
|
|
|
61
60
|
quote,
|
|
62
61
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
63
62
|
sellAsset,
|
|
64
|
-
spenderAddress:
|
|
63
|
+
spenderAddress: allowanceContract,
|
|
65
64
|
deps,
|
|
66
65
|
},
|
|
67
66
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GatewayOrderStatusV3,
|
|
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';
|
|
|
8
8
|
import type { BobGatewayChainName } from './constants';
|
|
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<
|
|
27
|
-
export declare const createBobGatewayOrder: (config: SwapperConfig, quote:
|
|
28
|
-
export declare const
|
|
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
|
-
|
|
32
|
-
|
|
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:
|
|
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").ProtocolFee>>;
|
|
40
37
|
estimatedExecutionTimeMs: number | undefined;
|
|
41
38
|
};
|
|
42
|
-
export declare const getBobGatewayAllowanceContract: (quote:
|
|
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;
|