@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
|
@@ -14,7 +14,7 @@ type ChainflipRateStepData = {
|
|
|
14
14
|
networkFeeCryptoBaseUnit: string | undefined;
|
|
15
15
|
};
|
|
16
16
|
type ChainflipQuoteStepData = {
|
|
17
|
-
transactionData
|
|
17
|
+
transactionData: TxBuildData;
|
|
18
18
|
networkFeeCryptoBaseUnit: string | undefined;
|
|
19
19
|
};
|
|
20
20
|
export declare function getChainflipStepData(args: Extract<GetChainflipStepDataArgs, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CHAIN_NAMESPACE, fromAssetId, fromChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { evm } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { evm, tron } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { bn, contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
5
|
import { TradeQuoteError } from '../../../types.js';
|
|
@@ -150,23 +150,42 @@ export async function getChainflipStepData(args) {
|
|
|
150
150
|
return Err(makeNetworkFeeEstimationFailedErr('getChainflipStepData', error));
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
// Un-migrated - exec builds its tx from chainflipSpecific.depositAddress, so no transactionData is carried
|
|
154
153
|
case CHAIN_NAMESPACE.Tron: {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
const adapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
155
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
156
|
+
if (args.type === 'rate') {
|
|
157
|
+
// No deposit channel yet, but every channel is a fresh address, so a fresh recipient prices the transfer
|
|
158
|
+
const networkFeeCryptoBaseUnit = await (async () => {
|
|
159
|
+
if (!from)
|
|
160
|
+
return;
|
|
161
|
+
try {
|
|
162
|
+
const { fast } = await adapter.getFeeData({
|
|
163
|
+
to: tron.generateFreshTronAddress(),
|
|
164
|
+
value: sellAmountCryptoBaseUnit,
|
|
165
|
+
chainSpecific: { from, contractAddress },
|
|
166
|
+
});
|
|
167
|
+
return fast.txFee;
|
|
168
|
+
}
|
|
169
|
+
catch { }
|
|
170
|
+
})();
|
|
171
|
+
const stepData = { networkFeeCryptoBaseUnit };
|
|
158
172
|
return Ok(stepData);
|
|
159
173
|
}
|
|
174
|
+
const transactionData = {
|
|
175
|
+
type: 'tron',
|
|
176
|
+
to: args.depositAddress,
|
|
177
|
+
value: sellAmountCryptoBaseUnit,
|
|
178
|
+
};
|
|
160
179
|
try {
|
|
161
|
-
const { fast } = await
|
|
162
|
-
to,
|
|
163
|
-
value:
|
|
164
|
-
chainSpecific: {
|
|
165
|
-
from,
|
|
166
|
-
contractAddress: contractAddressOrUndefined(sellAsset.assetId),
|
|
167
|
-
},
|
|
180
|
+
const { fast } = await adapter.getFeeData({
|
|
181
|
+
to: transactionData.to,
|
|
182
|
+
value: transactionData.value,
|
|
183
|
+
chainSpecific: { from, contractAddress, requireEnergyShare: true },
|
|
168
184
|
});
|
|
169
|
-
const stepData = {
|
|
185
|
+
const stepData = {
|
|
186
|
+
transactionData,
|
|
187
|
+
networkFeeCryptoBaseUnit: fast.txFee,
|
|
188
|
+
};
|
|
170
189
|
return Ok(stepData);
|
|
171
190
|
}
|
|
172
191
|
catch (error) {
|
|
@@ -2,3 +2,4 @@ export declare const ONE_CLICK_BASE_URL = "https://1click.chaindefuser.com";
|
|
|
2
2
|
export declare const DEFAULT_SLIPPAGE_BPS = 50;
|
|
3
3
|
export declare const DEFAULT_QUOTE_DEADLINE_MS: number;
|
|
4
4
|
export declare const UTXO_QUOTE_DEADLINE_MS: number;
|
|
5
|
+
export declare const APP_FEE_SPLIT_MULTIPLIER = 2;
|
|
@@ -3,3 +3,5 @@ export const DEFAULT_SLIPPAGE_BPS = 50;
|
|
|
3
3
|
// 1Click refunds a deposit it cannot settle by the requested deadline, and prices a quote the same at any length
|
|
4
4
|
export const DEFAULT_QUOTE_DEADLINE_MS = 60 * 60 * 1000;
|
|
5
5
|
export const UTXO_QUOTE_DEADLINE_MS = 4 * 60 * 60 * 1000;
|
|
6
|
+
// 1Click pays half of the requested appFee to its own account, so request double to receive affiliateBps
|
|
7
|
+
export const APP_FEE_SPLIT_MULTIPLIER = 2;
|
|
@@ -142,12 +142,17 @@ export async function getNearIntentsStepData(args) {
|
|
|
142
142
|
const { fast } = await deps.assertGetTronChainAdapter(sellAsset.chainId).getFeeData({
|
|
143
143
|
to: depositAddress,
|
|
144
144
|
value: sellAmountCryptoBaseUnit,
|
|
145
|
-
chainSpecific: {
|
|
146
|
-
from,
|
|
147
|
-
contractAddress: contractAddressOrUndefined(sellAsset.assetId),
|
|
148
|
-
},
|
|
145
|
+
chainSpecific: { from, contractAddress, requireEnergyShare: type === 'quote' },
|
|
149
146
|
});
|
|
150
|
-
const
|
|
147
|
+
const networkFeeCryptoBaseUnit = fast.txFee;
|
|
148
|
+
if (type === 'rate') {
|
|
149
|
+
const stepData = { networkFeeCryptoBaseUnit };
|
|
150
|
+
return Ok(stepData);
|
|
151
|
+
}
|
|
152
|
+
const stepData = {
|
|
153
|
+
transactionData: { type: 'tron', to: depositAddress, value: sellAmountCryptoBaseUnit },
|
|
154
|
+
networkFeeCryptoBaseUnit,
|
|
155
|
+
};
|
|
151
156
|
return Ok(stepData);
|
|
152
157
|
}
|
|
153
158
|
case CHAIN_NAMESPACE.Sui: {
|
|
@@ -5,7 +5,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
5
5
|
import { zeroAddress } from 'viem';
|
|
6
6
|
import { TradeQuoteError } from '../../../types.js';
|
|
7
7
|
import { createTradeAmountTooSmallErr, makeSwapErrorRight } from '../../../utils/index.js';
|
|
8
|
-
import { DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS, UTXO_QUOTE_DEADLINE_MS, } from '../constants.js';
|
|
8
|
+
import { APP_FEE_SPLIT_MULTIPLIER, DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS, UTXO_QUOTE_DEADLINE_MS, } from '../constants.js';
|
|
9
9
|
import { chainIdToNearIntentsChain, QuoteRequest } from '../types.js';
|
|
10
10
|
import { ApiError, OneClickService } from './oneClickService.js';
|
|
11
11
|
const getTokensWithRetry = async () => {
|
|
@@ -149,7 +149,7 @@ export const buildNearIntentsQuoteRequest = ({ originAsset, destinationAsset, am
|
|
|
149
149
|
appFees: [
|
|
150
150
|
{
|
|
151
151
|
recipient: DAO_TREASURY_NEAR,
|
|
152
|
-
fee: Number(affiliateBps),
|
|
152
|
+
fee: Number(affiliateBps) * APP_FEE_SPLIT_MULTIPLIER,
|
|
153
153
|
},
|
|
154
154
|
],
|
|
155
155
|
};
|
|
@@ -14,8 +14,8 @@ export declare const relayChainIdToChainId: import("lodash").Dictionary<string>;
|
|
|
14
14
|
export declare const DEFAULT_RELAY_EVM_TOKEN_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
15
15
|
export declare const RELAY_BTC_TOKEN_ADDRESS = "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8";
|
|
16
16
|
export declare const RELAY_SOLANA_TOKEN_ADDRESS = "11111111111111111111111111111111";
|
|
17
|
-
export declare const RELAY_TRON_TOKEN_ADDRESS = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
18
17
|
export declare const DEFAULT_RELAY_EVM_USER_ADDRESS = "0x000000000000000000000000000000000000dead";
|
|
18
|
+
export declare const RELAY_TRON_FALLBACK_DEPOSIT_ENERGY = "100000";
|
|
19
19
|
export declare const DEFAULT_RELAY_BTC_USER_ADDRESS = "bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa";
|
|
20
20
|
export declare const DEFAULT_RELAY_SOLANA_USER_ADDRESS = "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr";
|
|
21
21
|
export declare const DEFAULT_RELAY_TRON_USER_ADDRESS = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy";
|
|
@@ -58,8 +58,9 @@ export const relayChainIdToChainId = invert(chainIdToRelayChainId);
|
|
|
58
58
|
export const DEFAULT_RELAY_EVM_TOKEN_ADDRESS = zeroAddress;
|
|
59
59
|
export const RELAY_BTC_TOKEN_ADDRESS = 'bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8';
|
|
60
60
|
export const RELAY_SOLANA_TOKEN_ADDRESS = '11111111111111111111111111111111';
|
|
61
|
-
export const RELAY_TRON_TOKEN_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
62
61
|
export const DEFAULT_RELAY_EVM_USER_ADDRESS = '0x000000000000000000000000000000000000dead';
|
|
62
|
+
// depositor energy for a TRC20 deposit measured on mainnet, for token quotes without their allowance
|
|
63
|
+
export const RELAY_TRON_FALLBACK_DEPOSIT_ENERGY = '100000';
|
|
63
64
|
export const DEFAULT_RELAY_BTC_USER_ADDRESS = 'bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa';
|
|
64
65
|
export const DEFAULT_RELAY_SOLANA_USER_ADDRESS = 'CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr';
|
|
65
66
|
export const DEFAULT_RELAY_TRON_USER_ADDRESS = 'TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy';
|
|
@@ -21,12 +21,11 @@ const getQuote = async (input, deps, relayChainMap) => {
|
|
|
21
21
|
type: 'quote',
|
|
22
22
|
input,
|
|
23
23
|
});
|
|
24
|
-
return maybeStepData.map(({ transactionData,
|
|
24
|
+
return maybeStepData.map(({ transactionData, networkFeeCryptoBaseUnit }) => ({
|
|
25
25
|
...stepCommon,
|
|
26
26
|
accountNumber,
|
|
27
27
|
allowanceContract,
|
|
28
28
|
transactionData,
|
|
29
|
-
relayTransactionMetadata,
|
|
30
29
|
swapperMetadata: {
|
|
31
30
|
name: 'relay',
|
|
32
31
|
relayId,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { btcAssetId, fromAssetId, isAssetReference, solAssetId, tronAssetId, } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import { isNativeEvmAsset } from '../../../utils/helpers.js';
|
|
3
|
-
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS,
|
|
4
|
+
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, } from '../constant.js';
|
|
4
5
|
export const getRelayAssetAddress = (asset) => {
|
|
5
6
|
if (asset.assetId === btcAssetId)
|
|
6
7
|
return RELAY_BTC_TOKEN_ADDRESS;
|
|
7
8
|
if (asset.assetId === solAssetId)
|
|
8
9
|
return RELAY_SOLANA_TOKEN_ADDRESS;
|
|
9
10
|
if (asset.assetId === tronAssetId)
|
|
10
|
-
return
|
|
11
|
+
return tron.TRON_ZERO_ADDRESS;
|
|
11
12
|
if (isNativeEvmAsset(asset.assetId))
|
|
12
13
|
return DEFAULT_RELAY_EVM_TOKEN_ADDRESS;
|
|
13
14
|
const { assetReference } = fromAssetId(asset.assetId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
2
|
import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.js';
|
|
3
3
|
import type { SolanaComputeBudgetOptions } from '../../../utils/solana/index.js';
|
|
4
|
-
import type { RelayQuoteItem
|
|
4
|
+
import type { RelayQuoteItem } from './types.js';
|
|
5
5
|
export declare const RELAY_SOLANA_COMPUTE_BUDGET: SolanaComputeBudgetOptions;
|
|
6
6
|
type BaseArgs = {
|
|
7
7
|
data: RelayQuoteItem['data'];
|
|
@@ -15,8 +15,7 @@ type RelayRateStepData = {
|
|
|
15
15
|
networkFeeCryptoBaseUnit: string;
|
|
16
16
|
};
|
|
17
17
|
type RelayQuoteStepData = {
|
|
18
|
-
transactionData
|
|
19
|
-
relayTransactionMetadata?: RelayTransactionMetadata;
|
|
18
|
+
transactionData: TxBuildData;
|
|
20
19
|
networkFeeCryptoBaseUnit: string;
|
|
21
20
|
};
|
|
22
21
|
export type GetRelayStepDataArgs = StepDataArgs<BaseArgs, {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { fromChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import { bnOrZero, contractAddressOrUndefined, isToken } from '@shapeshiftoss/utils';
|
|
3
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
5
|
import { makeNetworkFeeEstimationFailedErr, makeTradeStepBuildFailedErr } from '../../../utils/index.js';
|
|
5
6
|
import { getEvmNetworkFeeCryptoBaseUnit } from '../../../utils/evm/index.js';
|
|
6
7
|
import { getSolanaNetworkFeeCryptoBaseUnit, omitComputeBudgetInstructions, withComputeUnitLimit, } from '../../../utils/solana/index.js';
|
|
8
|
+
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from '../../../utils/tron/index.js';
|
|
7
9
|
import { getUtxoNetworkFeeCryptoBaseUnit } from '../../../utils/utxo/index.js';
|
|
10
|
+
import { RELAY_TRON_FALLBACK_DEPOSIT_ENERGY } from '../constant.js';
|
|
8
11
|
import { getRelayPsbtRelayer } from './getRelayPsbtRelayer.js';
|
|
9
12
|
import { convertRelaySolanaInstruction } from './helpers.js';
|
|
10
13
|
import { isRelayQuoteEvmItemData, isRelayQuoteSolanaItemData, isRelayQuoteTronItemData, isRelayQuoteUtxoItemData, } from './types.js';
|
|
@@ -169,25 +172,55 @@ export async function getRelayStepData({ data, sellAsset, sellAmountCryptoBaseUn
|
|
|
169
172
|
return Err(makeNetworkFeeEstimationFailedErr('getRelayStepData', error));
|
|
170
173
|
}
|
|
171
174
|
}
|
|
175
|
+
// Native and token sells alike are a call into relay's depositor contract
|
|
172
176
|
if (isRelayQuoteTronItemData(data)) {
|
|
173
|
-
const contractAddress = data.parameter
|
|
174
|
-
const tronCallData = data.parameter?.data;
|
|
175
|
-
const isTronToken = isToken(sellAsset.assetId);
|
|
176
|
-
if (isTronToken && !contractAddress)
|
|
177
|
-
return Err(makeTradeStepBuildFailedErr('getRelayStepData'));
|
|
178
|
-
if (isTronToken && !tronCallData)
|
|
179
|
-
return Err(makeTradeStepBuildFailedErr('getRelayStepData'));
|
|
177
|
+
const { contract_address: contractAddress, data: callData, call_value: callValue, } = data.parameter ?? {};
|
|
180
178
|
if (type === 'rate') {
|
|
179
|
+
// Relay's gas figure runs ~35% under the deposit's measured energy, so rates price the measured call
|
|
180
|
+
const networkFeeCryptoBaseUnit = await (async () => {
|
|
181
|
+
if (!contractAddress || !callData)
|
|
182
|
+
return fallbackNetworkFeeCryptoBaseUnit;
|
|
183
|
+
try {
|
|
184
|
+
return await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
185
|
+
adapter: deps.assertGetTronChainAdapter(sellAsset.chainId),
|
|
186
|
+
energy: RELAY_TRON_FALLBACK_DEPOSIT_ENERGY,
|
|
187
|
+
bandwidthBytes: tron.getTronContractCallBandwidthBytes(callData),
|
|
188
|
+
contractAddress,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return fallbackNetworkFeeCryptoBaseUnit;
|
|
193
|
+
}
|
|
194
|
+
})();
|
|
195
|
+
const stepData = { networkFeeCryptoBaseUnit };
|
|
196
|
+
return Ok(stepData);
|
|
197
|
+
}
|
|
198
|
+
if (!contractAddress || !callData)
|
|
199
|
+
return Err(makeTradeStepBuildFailedErr('getRelayStepData'));
|
|
200
|
+
const isNativeSell = !isToken(sellAsset.assetId);
|
|
201
|
+
const call = {
|
|
202
|
+
to: contractAddress,
|
|
203
|
+
data: callData,
|
|
204
|
+
value: String(callValue ?? (isNativeSell ? sellAmountCryptoBaseUnit : 0)),
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
181
207
|
const stepData = {
|
|
182
|
-
|
|
208
|
+
transactionData: { type: 'tron', ...call },
|
|
209
|
+
networkFeeCryptoBaseUnit: await getTronContractCallNetworkFeeCryptoBaseUnit({
|
|
210
|
+
adapter: deps.assertGetTronChainAdapter(sellAsset.chainId),
|
|
211
|
+
transactionData: call,
|
|
212
|
+
from,
|
|
213
|
+
sellAsset,
|
|
214
|
+
sellAmountCryptoBaseUnit,
|
|
215
|
+
spenderAddress: contractAddress,
|
|
216
|
+
fallbackEnergy: RELAY_TRON_FALLBACK_DEPOSIT_ENERGY,
|
|
217
|
+
}),
|
|
183
218
|
};
|
|
184
219
|
return Ok(stepData);
|
|
185
220
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
190
|
-
return Ok(stepData);
|
|
221
|
+
catch (error) {
|
|
222
|
+
return Err(makeNetworkFeeEstimationFailedErr('getRelayStepData', error));
|
|
223
|
+
}
|
|
191
224
|
}
|
|
192
225
|
return Err(makeTradeStepBuildFailedErr('getRelayStepData'));
|
|
193
226
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { ETH } from '../../../utils/test-data/assets.js';
|
|
4
|
+
import { getRelayStepData } from './getRelayStepData.js';
|
|
5
|
+
import { getRelayAllowanceContract } from './helpers.js';
|
|
6
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
7
|
+
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
8
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
9
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
10
|
+
const DEPOSITOR_HEX = '41f0623e1012177482912fb057e44e1a9769b1f588';
|
|
11
|
+
const DEPOSITOR = 'TXtEs6t2oUWQsNos7m68gbHdE9Q5n6x2oN';
|
|
12
|
+
const tronItem = {
|
|
13
|
+
type: 'TriggerSmartContract',
|
|
14
|
+
parameter: { contract_address: DEPOSITOR_HEX, data: '49290c1c', call_value: 50000000 },
|
|
15
|
+
};
|
|
16
|
+
const tronAdapter = ({ txFee = '9000000', allowance = '0' } = {}) => ({
|
|
17
|
+
getFeeData: vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
18
|
+
httpProvider: {
|
|
19
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
20
|
+
getTrc20Allowance: vi.fn().mockResolvedValue(allowance),
|
|
21
|
+
getTrc20Balance: vi.fn().mockResolvedValue('100000000'),
|
|
22
|
+
getContractEnergyShare: vi.fn().mockResolvedValue({
|
|
23
|
+
callerPercent: 100,
|
|
24
|
+
originEnergyLimit: 0,
|
|
25
|
+
originEnergyAvailable: 0,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const makeDeps = (tron) => ({ assertGetTronChainAdapter: () => tron });
|
|
30
|
+
const baseArgs = {
|
|
31
|
+
data: tronItem,
|
|
32
|
+
sellAsset: TRX,
|
|
33
|
+
sellAmountCryptoBaseUnit: '50000000',
|
|
34
|
+
spenderAddress: '',
|
|
35
|
+
orderId: undefined,
|
|
36
|
+
xpub: undefined,
|
|
37
|
+
fallbackNetworkFeeCryptoBaseUnit: '6100715',
|
|
38
|
+
};
|
|
39
|
+
describe('getRelayAllowanceContract', () => {
|
|
40
|
+
it('returns the tron depositor as relay gives it', () => {
|
|
41
|
+
expect(getRelayAllowanceContract(tronItem)).toBe(DEPOSITOR_HEX);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('getRelayStepData', () => {
|
|
45
|
+
describe('tron', () => {
|
|
46
|
+
it('carries the depositor call as transactionData and simulates it', async () => {
|
|
47
|
+
const adapter = tronAdapter();
|
|
48
|
+
const actual = await getRelayStepData({
|
|
49
|
+
...baseArgs,
|
|
50
|
+
type: 'quote',
|
|
51
|
+
input: {},
|
|
52
|
+
from: FROM,
|
|
53
|
+
deps: makeDeps(adapter),
|
|
54
|
+
});
|
|
55
|
+
const transactionData = {
|
|
56
|
+
type: 'tron',
|
|
57
|
+
to: DEPOSITOR_HEX,
|
|
58
|
+
data: '49290c1c',
|
|
59
|
+
value: '50000000',
|
|
60
|
+
};
|
|
61
|
+
expect(actual.unwrap()).toEqual({ transactionData, networkFeeCryptoBaseUnit: '9000000' });
|
|
62
|
+
expect(adapter.getFeeData).toHaveBeenCalledWith({
|
|
63
|
+
to: DEPOSITOR_HEX,
|
|
64
|
+
value: '50000000',
|
|
65
|
+
chainSpecific: { from: FROM, data: '49290c1c', requireEnergyShare: true },
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('fails a native quote when the simulation fails', async () => {
|
|
69
|
+
const adapter = tronAdapter();
|
|
70
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
71
|
+
const actual = await getRelayStepData({
|
|
72
|
+
...baseArgs,
|
|
73
|
+
type: 'quote',
|
|
74
|
+
input: {},
|
|
75
|
+
from: FROM,
|
|
76
|
+
deps: makeDeps(adapter),
|
|
77
|
+
});
|
|
78
|
+
expect(actual.isErr()).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
it('prices the measured worst case when a token allowance is not granted yet', async () => {
|
|
81
|
+
const adapter = tronAdapter({ allowance: '0' });
|
|
82
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
83
|
+
const actual = await getRelayStepData({
|
|
84
|
+
...baseArgs,
|
|
85
|
+
data: { type: 'TriggerSmartContract', parameter: { ...tronItem.parameter, call_value: 0 } },
|
|
86
|
+
sellAsset: USDT_TRON,
|
|
87
|
+
type: 'quote',
|
|
88
|
+
input: {},
|
|
89
|
+
from: FROM,
|
|
90
|
+
deps: makeDeps(adapter),
|
|
91
|
+
});
|
|
92
|
+
// 100000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
93
|
+
expect(actual.unwrap().networkFeeCryptoBaseUnit).toBe('12283000');
|
|
94
|
+
expect(adapter.httpProvider.getTrc20Allowance).toHaveBeenCalledWith({
|
|
95
|
+
contractAddress: USDT,
|
|
96
|
+
owner: FROM,
|
|
97
|
+
spender: DEPOSITOR,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it('prices a rate from the measured deposit', async () => {
|
|
101
|
+
const adapter = tronAdapter();
|
|
102
|
+
const actual = await getRelayStepData({
|
|
103
|
+
...baseArgs,
|
|
104
|
+
type: 'rate',
|
|
105
|
+
input: {},
|
|
106
|
+
from: FROM,
|
|
107
|
+
deps: makeDeps(adapter),
|
|
108
|
+
});
|
|
109
|
+
// 100000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
110
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '12283000' });
|
|
111
|
+
expect(adapter.httpProvider.getContractEnergyShare).toHaveBeenCalledWith(DEPOSITOR);
|
|
112
|
+
});
|
|
113
|
+
it('falls back to the relay fee when the measured deposit cannot be priced', async () => {
|
|
114
|
+
const adapter = tronAdapter();
|
|
115
|
+
adapter.httpProvider.getChainPrices = () => Promise.reject(new Error('429'));
|
|
116
|
+
const actual = await getRelayStepData({
|
|
117
|
+
...baseArgs,
|
|
118
|
+
type: 'rate',
|
|
119
|
+
input: {},
|
|
120
|
+
from: FROM,
|
|
121
|
+
deps: makeDeps(adapter),
|
|
122
|
+
});
|
|
123
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '6100715' });
|
|
124
|
+
});
|
|
125
|
+
it('fails to build without the depositor call', async () => {
|
|
126
|
+
const actual = await getRelayStepData({
|
|
127
|
+
...baseArgs,
|
|
128
|
+
data: { type: 'TriggerSmartContract', parameter: {} },
|
|
129
|
+
type: 'quote',
|
|
130
|
+
input: {},
|
|
131
|
+
from: FROM,
|
|
132
|
+
deps: makeDeps(tronAdapter()),
|
|
133
|
+
});
|
|
134
|
+
expect(actual.isErr()).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -51,8 +51,7 @@ export const resolveRelayAddresses = ({ input, sellChainId, buyChainId, }) => {
|
|
|
51
51
|
const refundTo = input.sendAddress ?? getRelayDefaultUserAddress(sellChainId);
|
|
52
52
|
return { sendAddress, recipient, refundTo };
|
|
53
53
|
};
|
|
54
|
-
// The spender to approve
|
|
55
|
-
// UTXO/Solana need no allowance. Derived from the provider route, not the built transactionData.
|
|
54
|
+
// The spender to approve is the call target: EVM data.to, tron the depositor; UTXO/Solana need none
|
|
56
55
|
export const getRelayAllowanceContract = (data) => {
|
|
57
56
|
if (!data)
|
|
58
57
|
return '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASSET_NAMESPACE, ASSET_REFERENCE, btcChainId, CHAIN_REFERENCE, fromChainId, solanaChainId, toAssetId, tronChainId, } from '@shapeshiftoss/caip';
|
|
2
|
-
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS,
|
|
2
|
+
import { isEvmChainId, tron } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, relayChainIdToChainId, } from '../constant.js';
|
|
4
4
|
export const relayTokenToAssetId = (relayToken) => {
|
|
5
5
|
const chainId = relayChainIdToChainId[relayToken.chainId];
|
|
6
6
|
const { chainReference } = fromChainId(chainId);
|
|
@@ -15,7 +15,7 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
15
15
|
return relayToken.address === RELAY_SOLANA_TOKEN_ADDRESS;
|
|
16
16
|
}
|
|
17
17
|
if (chainId === tronChainId) {
|
|
18
|
-
return relayToken.address ===
|
|
18
|
+
return relayToken.address === tron.TRON_ZERO_ADDRESS;
|
|
19
19
|
}
|
|
20
20
|
return false;
|
|
21
21
|
})();
|
|
@@ -3,10 +3,6 @@ export type RelayTradeQuoteInput = GetEvmTradeQuoteInput | GetUtxoTradeQuoteInpu
|
|
|
3
3
|
export type RelayTradeRateInput = GetEvmTradeRateInput | GetUtxoTradeRateInput | GetSolanaTradeRateInput | GetTronTradeRateInput;
|
|
4
4
|
export type RelayExactOutputTradeQuoteInput = WithExactBuyAmount<RelayTradeQuoteInput>;
|
|
5
5
|
export type RelayExactOutputTradeRateInput = WithExactBuyAmount<RelayTradeRateInput>;
|
|
6
|
-
export type RelayTransactionMetadata = {
|
|
7
|
-
to?: string;
|
|
8
|
-
data?: string;
|
|
9
|
-
};
|
|
10
6
|
export type RelayMetadata = {
|
|
11
7
|
name: 'relay';
|
|
12
8
|
relayId: string;
|
|
@@ -114,6 +110,7 @@ export type RelayQuoteTronItemData = {
|
|
|
114
110
|
owner_address?: string;
|
|
115
111
|
contract_address?: string;
|
|
116
112
|
data?: string;
|
|
113
|
+
call_value?: number;
|
|
117
114
|
};
|
|
118
115
|
};
|
|
119
116
|
export type RelayQuoteItem = {
|
|
@@ -1,75 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { toAddressNList } from '@shapeshiftoss/chain-adapters';
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
3
2
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { createDefaultStatusResponse } from '../../utils/index.js';
|
|
4
|
+
import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
|
|
6
5
|
import { getSunioTradeQuote } from './getSunioTradeQuote/getSunioTradeQuote.js';
|
|
7
6
|
import { getSunioTradeRate } from './getSunioTradeRate/getSunioTradeRate.js';
|
|
8
|
-
import { buildSwapExactInputParameters, SUNIO_SWAP_EXACT_INPUT_SELECTOR, } from './utils/buildSwapContractCall.js';
|
|
9
|
-
import { buildSwapRouteParameters } from './utils/buildSwapRouteParameters.js';
|
|
10
|
-
import { SUNIO_SMART_ROUTER_CONTRACT } from './utils/constants.js';
|
|
11
|
-
import { getSunioTransactionFees } from './utils/getSunioTransactionFees.js';
|
|
12
7
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
13
8
|
export const sunioApi = {
|
|
14
9
|
getTradeQuote: (input, deps) => getSunioTradeQuote(input, deps),
|
|
15
10
|
getTradeRate: (input, deps) => getSunioTradeRate(input, deps),
|
|
16
|
-
getUnsignedTronTransaction
|
|
17
|
-
|
|
18
|
-
if (!isExecutableTradeQuote(tradeQuote)) {
|
|
19
|
-
throw new Error('Unable to execute a trade rate quote');
|
|
20
|
-
}
|
|
21
|
-
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
22
|
-
const adapter = assertGetTronChainAdapter(tronChainId);
|
|
23
|
-
const sunioTransactionData = step.sunioTransactionData;
|
|
24
|
-
if (!sunioTransactionData)
|
|
25
|
-
throw new Error('[Sun.io] Missing transaction data in quote');
|
|
26
|
-
const rpcUrl = adapter.httpProvider.getRpcUrl();
|
|
27
|
-
const tronWeb = new TronWeb({
|
|
28
|
-
fullHost: rpcUrl,
|
|
29
|
-
headers: config.VITE_TRON_GRID_API_KEY
|
|
30
|
-
? { 'TRON-PRO-API-KEY': config.VITE_TRON_GRID_API_KEY }
|
|
31
|
-
: {},
|
|
32
|
-
});
|
|
33
|
-
const routeParams = buildSwapRouteParameters(sunioTransactionData.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit, tradeQuote.receiveAddress, slippageTolerancePercentageDecimal);
|
|
34
|
-
const parameters = buildSwapExactInputParameters(routeParams);
|
|
35
|
-
const isSellingNativeTrx = step.sellAsset.assetId === tronAssetId;
|
|
36
|
-
const callValue = isSellingNativeTrx
|
|
37
|
-
? Number(step.sellAmountIncludingProtocolFeesCryptoBaseUnit)
|
|
38
|
-
: 0;
|
|
39
|
-
const options = {
|
|
40
|
-
feeLimit: 100_000_000,
|
|
41
|
-
callValue,
|
|
42
|
-
};
|
|
43
|
-
const txData = await tronWeb.transactionBuilder.triggerSmartContract(SUNIO_SMART_ROUTER_CONTRACT, SUNIO_SWAP_EXACT_INPUT_SELECTOR, options, parameters, from);
|
|
44
|
-
if (!txData.result || !txData.result.result) {
|
|
45
|
-
throw new Error('[Sun.io] Failed to build swap transaction');
|
|
46
|
-
}
|
|
47
|
-
const transaction = txData.transaction;
|
|
48
|
-
const rawDataHex = typeof transaction.raw_data_hex === 'string'
|
|
49
|
-
? transaction.raw_data_hex
|
|
50
|
-
: Buffer.isBuffer(transaction.raw_data_hex)
|
|
51
|
-
? transaction.raw_data_hex.toString('hex')
|
|
52
|
-
: Array.isArray(transaction.raw_data_hex)
|
|
53
|
-
? Buffer.from(transaction.raw_data_hex).toString('hex')
|
|
54
|
-
: (() => {
|
|
55
|
-
throw new Error(`Unexpected raw_data_hex type: ${typeof transaction.raw_data_hex}`);
|
|
56
|
-
})();
|
|
57
|
-
if (!/^[0-9a-fA-F]+$/.test(rawDataHex)) {
|
|
58
|
-
throw new Error(`Invalid raw_data_hex format: ${rawDataHex.slice(0, 100)}`);
|
|
59
|
-
}
|
|
60
|
-
const accountNumber = step.accountNumber;
|
|
61
|
-
if (accountNumber === undefined) {
|
|
62
|
-
throw new Error('[Sun.io] accountNumber is required for execution');
|
|
63
|
-
}
|
|
64
|
-
const bip44Params = adapter.getBip44Params({ accountNumber });
|
|
65
|
-
const addressNList = toAddressNList(bip44Params);
|
|
66
|
-
return {
|
|
67
|
-
addressNList,
|
|
68
|
-
rawDataHex,
|
|
69
|
-
transaction,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
getTronTransactionFees: getSunioTransactionFees,
|
|
11
|
+
getUnsignedTronTransaction,
|
|
12
|
+
getTronTransactionFees,
|
|
73
13
|
checkTradeStatus: async ({ txHash, assertGetTronChainAdapter }) => {
|
|
74
14
|
try {
|
|
75
15
|
// Wait for TronGrid indexing to avoid false "REVERT"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
2
2
|
import { assertQuoteAddresses } from '../../../utils/index.js';
|
|
3
|
-
import { FALLBACK_QUOTE_DEADLINE_MS } from '../../../utils/helpers.js';
|
|
4
3
|
import { getSunioStepData } from '../utils/getSunioStepData.js';
|
|
5
4
|
import { getSunioTradeContext } from '../utils/getSunioTradeContext.js';
|
|
6
5
|
export const getSunioTradeQuote = async (input, deps) => {
|
|
@@ -21,17 +20,17 @@ export const getSunioTradeQuote = async (input, deps) => {
|
|
|
21
20
|
});
|
|
22
21
|
if (maybeStepData.isErr())
|
|
23
22
|
return Err(maybeStepData.unwrapErr());
|
|
24
|
-
const { networkFeeCryptoBaseUnit,
|
|
23
|
+
const { networkFeeCryptoBaseUnit, transactionData, deadline } = maybeStepData.unwrap();
|
|
25
24
|
const tradeQuote = {
|
|
26
25
|
...tradeCommon,
|
|
27
26
|
quoteOrRate: 'quote',
|
|
28
|
-
deadline
|
|
27
|
+
deadline,
|
|
29
28
|
receiveAddress,
|
|
30
29
|
steps: [
|
|
31
30
|
{
|
|
32
31
|
...stepCommon,
|
|
33
32
|
accountNumber,
|
|
34
|
-
|
|
33
|
+
transactionData,
|
|
35
34
|
feeData: { networkFeeCryptoBaseUnit, protocolFees },
|
|
36
35
|
},
|
|
37
36
|
],
|
|
@@ -7,7 +7,13 @@ export const getSunioTradeRate = async (input, deps) => {
|
|
|
7
7
|
if (maybeContext.isErr())
|
|
8
8
|
return Err(maybeContext.unwrapErr());
|
|
9
9
|
const { tradeCommon, stepCommon, protocolFees, stepDataArgs } = maybeContext.unwrap();
|
|
10
|
-
|
|
10
|
+
// Sun.io is tron-only, so the receive address is also the seller's account to simulate from
|
|
11
|
+
const maybeStepData = await getSunioStepData({
|
|
12
|
+
...stepDataArgs,
|
|
13
|
+
type: 'rate',
|
|
14
|
+
input,
|
|
15
|
+
from: input.sendAddress ?? receiveAddress,
|
|
16
|
+
});
|
|
11
17
|
if (maybeStepData.isErr())
|
|
12
18
|
return Err(maybeStepData.unwrapErr());
|
|
13
19
|
const { networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { SunioRoute } from '../types.js';
|
|
2
|
+
type BuildSunioSwapCalldataArgs = {
|
|
3
|
+
route: SunioRoute;
|
|
4
|
+
sellAmountCryptoBaseUnit: string;
|
|
5
|
+
minBuyAmountCryptoBaseUnit: string;
|
|
6
|
+
recipient: string;
|
|
7
|
+
slippageTolerancePercentageDecimal: string;
|
|
8
|
+
deadline: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const buildSunioSwapCalldata: ({ route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal, deadline, }: BuildSunioSwapCalldataArgs) => string;
|
|
11
|
+
export {};
|