@shapeshiftoss/swapper 20.2.0 → 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/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/swapperApi/getTradeQuote.js +2 -3
- package/dist/cjs/swappers/ButterSwap/types.d.ts +0 -11
- 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 -14
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +120 -17
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -2
- 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/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/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/swapperApi/getTradeQuote.js +2 -3
- package/dist/esm/swappers/ButterSwap/types.d.ts +0 -11
- 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 -14
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +120 -17
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +1 -2
- 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/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 +8 -8
- 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/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
|
@@ -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 {};
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import { bn } from '@shapeshiftoss/utils';
|
|
3
|
+
import { encodeFunctionData, parseAbiItem } from 'viem';
|
|
4
|
+
const SUNIO_SWAP_EXACT_INPUT_ABI = parseAbiItem('function swapExactInput(address[], string[], uint256[], uint24[], (uint256,uint256,address,uint256))');
|
|
5
|
+
// SmartExchangeRouter swapExactInput calldata - the TVM ABI is EVM-compatible, addresses as 20-byte bodies
|
|
6
|
+
export const buildSunioSwapCalldata = ({ route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal, deadline, }) => {
|
|
7
|
+
const amountOutMin = bn(minBuyAmountCryptoBaseUnit)
|
|
8
|
+
.times(bn(1).minus(slippageTolerancePercentageDecimal))
|
|
9
|
+
.toFixed(0);
|
|
10
|
+
// The SmartExchangeRouter expects sum(versionLen) === path.length: the first pool segment consumes
|
|
11
|
+
// 2 tokens (input + output) and each subsequent pool reuses the previous output, consuming 1 new
|
|
12
|
+
// token. Relies on the Sun.io API returning poolVersions per-hop (poolVersions.length ===
|
|
13
|
+
// tokens.length - 1), which it does.
|
|
14
|
+
const versionLen = route.poolVersions.map((_, index) => (index === 0 ? 2n : 1n));
|
|
15
|
+
const swapData = [
|
|
16
|
+
BigInt(sellAmountCryptoBaseUnit),
|
|
17
|
+
BigInt(amountOutMin),
|
|
18
|
+
tron.toTronHex(recipient),
|
|
19
|
+
BigInt(Math.floor(deadline / 1000)),
|
|
20
|
+
];
|
|
21
|
+
return encodeFunctionData({
|
|
22
|
+
abi: [SUNIO_SWAP_EXACT_INPUT_ABI],
|
|
23
|
+
functionName: 'swapExactInput',
|
|
24
|
+
args: [
|
|
25
|
+
route.tokens.map(tron.toTronHex),
|
|
26
|
+
route.poolVersions,
|
|
27
|
+
versionLen,
|
|
28
|
+
route.poolFees.map(Number),
|
|
29
|
+
swapData,
|
|
30
|
+
],
|
|
31
|
+
});
|
|
12
32
|
};
|
|
13
|
-
// Parameter list for the SmartExchangeRouter swapExactInput call, shared between fee
|
|
14
|
-
// estimation and execution so both encode the call identically.
|
|
15
|
-
export const buildSwapExactInputParameters = (routeParams) => [
|
|
16
|
-
{ type: 'address[]', value: routeParams.path },
|
|
17
|
-
{ type: 'string[]', value: routeParams.poolVersion },
|
|
18
|
-
{ type: 'uint256[]', value: routeParams.versionLen },
|
|
19
|
-
{ type: 'uint24[]', value: routeParams.fees },
|
|
20
|
-
{
|
|
21
|
-
type: 'tuple(uint256,uint256,address,uint256)',
|
|
22
|
-
value: convertAddressesToEvmFormat([
|
|
23
|
-
routeParams.swapData.amountIn,
|
|
24
|
-
routeParams.swapData.amountOutMin,
|
|
25
|
-
routeParams.swapData.recipient,
|
|
26
|
-
routeParams.swapData.deadline,
|
|
27
|
-
]),
|
|
28
|
-
},
|
|
29
|
-
];
|
|
@@ -2,7 +2,7 @@ export declare const SUNIO_SUPPORTED_CHAIN_IDS: readonly [import("@shapeshiftoss
|
|
|
2
2
|
export declare const SUNIO_API_BASE_URL = "https://rot.endjgfsv.link";
|
|
3
3
|
export declare const SUNIO_SMART_ROUTER_CONTRACT: "TCFNp179Lg46D16zKoumd4Poa2WFFdtqYj";
|
|
4
4
|
export declare const DEFAULT_SLIPPAGE_PERCENTAGE = "0.005";
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
5
|
+
export declare const SUNIO_SWAP_DEADLINE_MS: number;
|
|
6
|
+
export declare const SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = "250000";
|
|
7
|
+
export declare const SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = "480000";
|
|
7
8
|
export declare const SUNIO_DEX_TYPES: "PSM,CURVE,CURVE_COMBINATION,WTRX,SUNSWAP_V1,SUNSWAP_V2,SUNSWAP_V3";
|
|
8
|
-
export declare const SUNIO_TRON_NATIVE_ADDRESS: "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
@@ -8,12 +8,8 @@ export const SUNIO_API_BASE_URL = 'https://rot.endjgfsv.link';
|
|
|
8
8
|
// This is the current mainnet router that sun.io's frontend uses
|
|
9
9
|
export const SUNIO_SMART_ROUTER_CONTRACT = 'TCFNp179Lg46D16zKoumd4Poa2WFFdtqYj';
|
|
10
10
|
export const DEFAULT_SLIPPAGE_PERCENTAGE = '0.005';
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = 215_000;
|
|
16
|
-
export const SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = 375_000;
|
|
11
|
+
export const SUNIO_SWAP_DEADLINE_MS = 20 * 60 * 1000;
|
|
12
|
+
// p90 router energy on mainnet, for rates that can't simulate and token quotes without their allowance
|
|
13
|
+
export const SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = '250000';
|
|
14
|
+
export const SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = '480000';
|
|
17
15
|
export const SUNIO_DEX_TYPES = 'PSM,CURVE,CURVE_COMBINATION,WTRX,SUNSWAP_V1,SUNSWAP_V2,SUNSWAP_V3';
|
|
18
|
-
// Native TRX token address (used when assetId is not a TRC-20 token)
|
|
19
|
-
export const SUNIO_TRON_NATIVE_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
|
-
import type { StepDataArgs, SwapErrorRight } from '../../../types.js';
|
|
3
|
-
import type { SunioRoute
|
|
2
|
+
import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types.js';
|
|
3
|
+
import type { SunioRoute } from '../types.js';
|
|
4
4
|
type BaseArgs = {
|
|
5
5
|
route: SunioRoute;
|
|
6
6
|
sellAmountCryptoBaseUnit: string;
|
|
7
|
+
buyAmountCryptoBaseUnit: string;
|
|
7
8
|
};
|
|
8
9
|
export type GetSunioStepDataArgs = StepDataArgs<BaseArgs>;
|
|
10
|
+
type TronTxBuildData = Extract<TxBuildData, {
|
|
11
|
+
type: 'tron';
|
|
12
|
+
}>;
|
|
9
13
|
type SunioRateStepData = {
|
|
10
14
|
networkFeeCryptoBaseUnit: string | undefined;
|
|
11
15
|
};
|
|
12
16
|
type SunioQuoteStepData = {
|
|
17
|
+
transactionData: TronTxBuildData;
|
|
13
18
|
networkFeeCryptoBaseUnit: string;
|
|
14
|
-
|
|
19
|
+
deadline: number;
|
|
15
20
|
};
|
|
16
21
|
export declare function getSunioStepData(args: Extract<GetSunioStepDataArgs, {
|
|
17
22
|
type: 'rate';
|
|
@@ -1,35 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tronAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
4
|
import { makeNetworkFeeEstimationFailedErr } from '../../../utils/index.js';
|
|
4
|
-
import {
|
|
5
|
+
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, TRON_PLACEHOLDER_ADDRESS, } from '../../../utils/tron/index.js';
|
|
6
|
+
import { buildSunioSwapCalldata } from './buildSwapContractCall.js';
|
|
7
|
+
import { DEFAULT_SLIPPAGE_PERCENTAGE, SUNIO_FALLBACK_SWAP_ENERGY_NATIVE, SUNIO_FALLBACK_SWAP_ENERGY_TRC20, SUNIO_SMART_ROUTER_CONTRACT, SUNIO_SWAP_DEADLINE_MS, } from './constants.js';
|
|
5
8
|
export async function getSunioStepData(args) {
|
|
6
|
-
const { type, route, sellAsset, sellAmountCryptoBaseUnit, from, input
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const { type, route, sellAsset, sellAmountCryptoBaseUnit, buyAmountCryptoBaseUnit, from, input } = args;
|
|
10
|
+
const adapter = args.deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
11
|
+
const isNativeSell = sellAsset.assetId === tronAssetId;
|
|
12
|
+
const fallbackEnergy = isNativeSell
|
|
13
|
+
? SUNIO_FALLBACK_SWAP_ENERGY_NATIVE
|
|
14
|
+
: SUNIO_FALLBACK_SWAP_ENERGY_TRC20;
|
|
15
|
+
// The router reverts past this, so the quote expires with it
|
|
16
|
+
const deadline = Date.now() + SUNIO_SWAP_DEADLINE_MS;
|
|
17
|
+
const buildCall = (recipient) => ({
|
|
18
|
+
to: SUNIO_SMART_ROUTER_CONTRACT,
|
|
19
|
+
value: isNativeSell ? sellAmountCryptoBaseUnit : '0',
|
|
20
|
+
data: buildSunioSwapCalldata({
|
|
21
|
+
route,
|
|
22
|
+
sellAmountCryptoBaseUnit,
|
|
23
|
+
minBuyAmountCryptoBaseUnit: buyAmountCryptoBaseUnit,
|
|
24
|
+
recipient,
|
|
25
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal ?? DEFAULT_SLIPPAGE_PERCENTAGE,
|
|
26
|
+
deadline,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
16
29
|
if (type === 'rate') {
|
|
17
30
|
const networkFeeCryptoBaseUnit = await (async () => {
|
|
18
31
|
try {
|
|
19
|
-
|
|
32
|
+
if (from) {
|
|
33
|
+
const { to, value, data } = buildCall(from);
|
|
34
|
+
const { fast } = await adapter.getFeeData({ to, value, chainSpecific: { from, data } });
|
|
35
|
+
return fast.txFee;
|
|
36
|
+
}
|
|
20
37
|
}
|
|
21
|
-
catch {
|
|
22
|
-
|
|
38
|
+
catch { }
|
|
39
|
+
try {
|
|
40
|
+
return await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
41
|
+
adapter,
|
|
42
|
+
energy: fallbackEnergy,
|
|
43
|
+
bandwidthBytes: tron.getTronContractCallBandwidthBytes(buildCall(from ?? TRON_PLACEHOLDER_ADDRESS).data),
|
|
44
|
+
contractAddress: SUNIO_SMART_ROUTER_CONTRACT,
|
|
45
|
+
fullEnergyOnShareLookupFailure: true,
|
|
46
|
+
});
|
|
23
47
|
}
|
|
48
|
+
catch { }
|
|
24
49
|
})();
|
|
25
50
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
26
51
|
return Ok(stepData);
|
|
27
52
|
}
|
|
53
|
+
const call = buildCall(input.receiveAddress);
|
|
28
54
|
try {
|
|
29
|
-
const networkFeeCryptoBaseUnit = await estimateSunioNetworkFeeCryptoBaseUnit(estimateArgs);
|
|
30
55
|
const stepData = {
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
transactionData: { type: 'tron', ...call },
|
|
57
|
+
networkFeeCryptoBaseUnit: await getTronContractCallNetworkFeeCryptoBaseUnit({
|
|
58
|
+
adapter,
|
|
59
|
+
transactionData: call,
|
|
60
|
+
from,
|
|
61
|
+
sellAsset,
|
|
62
|
+
sellAmountCryptoBaseUnit,
|
|
63
|
+
spenderAddress: SUNIO_SMART_ROUTER_CONTRACT,
|
|
64
|
+
fallbackEnergy,
|
|
65
|
+
}),
|
|
66
|
+
deadline,
|
|
33
67
|
};
|
|
34
68
|
return Ok(stepData);
|
|
35
69
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|