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