@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,91 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { SwapperName } from '../../types.js';
|
|
4
|
+
import { ETH } from '../test-data/assets.js';
|
|
5
|
+
import { getThorStepData } from './getThorStepData.js';
|
|
6
|
+
import { TradeType } from './types.js';
|
|
7
|
+
vi.mock('./getThorTxData', () => ({
|
|
8
|
+
getThorTxData: vi.fn().mockResolvedValue({ vault: 'TVault' }),
|
|
9
|
+
getThorRouterAndVault: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
12
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
13
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
14
|
+
const tronAdapter = (txFee = '9000000') => ({
|
|
15
|
+
getFeeData: vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
16
|
+
});
|
|
17
|
+
const makeDeps = (tron) => ({ config: {}, assertGetTronChainAdapter: () => tron });
|
|
18
|
+
const baseArgs = {
|
|
19
|
+
swapperName: SwapperName.Thorchain,
|
|
20
|
+
tradeType: TradeType.L1ToL1,
|
|
21
|
+
sellAsset: USDT_TRON,
|
|
22
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
23
|
+
expiry: 0,
|
|
24
|
+
rawMemo: '=:ETH.ETH:0xabc:1',
|
|
25
|
+
};
|
|
26
|
+
describe('getThorStepData tron', () => {
|
|
27
|
+
it('carries the vault transfer as transactionData and estimates it for a quote', async () => {
|
|
28
|
+
const adapter = tronAdapter();
|
|
29
|
+
const actual = await getThorStepData({
|
|
30
|
+
...baseArgs,
|
|
31
|
+
type: 'quote',
|
|
32
|
+
input: {},
|
|
33
|
+
deps: makeDeps(adapter),
|
|
34
|
+
from: FROM,
|
|
35
|
+
memo: '=:ETH.ETH:0xabc:1/1/0:ss:55',
|
|
36
|
+
});
|
|
37
|
+
expect(actual.unwrap()).toEqual({
|
|
38
|
+
transactionData: {
|
|
39
|
+
type: 'tron',
|
|
40
|
+
to: 'TVault',
|
|
41
|
+
value: '100000000',
|
|
42
|
+
memo: '=:ETH.ETH:0xabc:1/1/0:ss:55',
|
|
43
|
+
},
|
|
44
|
+
networkFeeCryptoBaseUnit: '9000000',
|
|
45
|
+
});
|
|
46
|
+
expect(adapter.getFeeData).toHaveBeenCalledWith({
|
|
47
|
+
to: 'TVault',
|
|
48
|
+
value: '100000000',
|
|
49
|
+
chainSpecific: {
|
|
50
|
+
from: FROM,
|
|
51
|
+
contractAddress: USDT,
|
|
52
|
+
memo: '=:ETH.ETH:0xabc:1/1/0:ss:55',
|
|
53
|
+
requireEnergyShare: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('fails the quote when estimation fails', async () => {
|
|
58
|
+
const adapter = tronAdapter();
|
|
59
|
+
adapter.getFeeData.mockRejectedValue(new Error('rpc down'));
|
|
60
|
+
const actual = await getThorStepData({
|
|
61
|
+
...baseArgs,
|
|
62
|
+
type: 'quote',
|
|
63
|
+
input: {},
|
|
64
|
+
deps: makeDeps(adapter),
|
|
65
|
+
from: FROM,
|
|
66
|
+
memo: '=:ETH.ETH:0xabc:1/1/0:ss:55',
|
|
67
|
+
});
|
|
68
|
+
expect(actual.isErr()).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it('sizes a rate with the raw memo and no sender', async () => {
|
|
71
|
+
const adapter = tronAdapter();
|
|
72
|
+
const actual = await getThorStepData({
|
|
73
|
+
...baseArgs,
|
|
74
|
+
type: 'rate',
|
|
75
|
+
input: {},
|
|
76
|
+
deps: makeDeps(adapter),
|
|
77
|
+
memo: '',
|
|
78
|
+
});
|
|
79
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '9000000' });
|
|
80
|
+
expect(adapter.getFeeData).toHaveBeenCalledWith({
|
|
81
|
+
to: 'TVault',
|
|
82
|
+
value: '100000000',
|
|
83
|
+
chainSpecific: {
|
|
84
|
+
from: undefined,
|
|
85
|
+
contractAddress: USDT,
|
|
86
|
+
memo: '=:ETH.ETH:0xabc:1',
|
|
87
|
+
requireEnergyShare: false,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -15,7 +15,6 @@ export * from './getThorL1TradeContexts.js';
|
|
|
15
15
|
export * from './getThorL1TradeQuote.js';
|
|
16
16
|
export * from './getThorL1TradeRate.js';
|
|
17
17
|
export * from './getPoolDetails.js';
|
|
18
|
-
export * as tron from './tron/index.js';
|
|
19
18
|
export declare const getChainIdBySwapper: (swapperName: SwapperName) => import("@shapeshiftoss/caip").ChainId;
|
|
20
19
|
export declare const isThorTradeRate: (quote: TradeRate | undefined) => quote is ThorTradeRate;
|
|
21
20
|
export declare const isThorTradeQuote: (quote: TradeQuote | undefined) => quote is ThorTradeQuote;
|
|
@@ -15,7 +15,6 @@ export * from './getThorL1TradeContexts.js';
|
|
|
15
15
|
export * from './getThorL1TradeQuote.js';
|
|
16
16
|
export * from './getThorL1TradeRate.js';
|
|
17
17
|
export * from './getPoolDetails.js';
|
|
18
|
-
export * as tron from './tron/index.js';
|
|
19
18
|
export const getChainIdBySwapper = (swapperName) => {
|
|
20
19
|
switch (swapperName) {
|
|
21
20
|
case SwapperName.Thorchain:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TRON_PLACEHOLDER_ADDRESS = "TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
+
import type { TxBuildData } from '../../types.js';
|
|
4
|
+
export type TronContractCall = Omit<Extract<TxBuildData, {
|
|
5
|
+
type: 'tron';
|
|
6
|
+
}>, 'type' | 'data' | 'memo'> & {
|
|
7
|
+
data: string;
|
|
8
|
+
};
|
|
9
|
+
type GetTronContractCallFallbackFeeArgs = {
|
|
10
|
+
adapter: tron.ChainAdapter;
|
|
11
|
+
energy: string;
|
|
12
|
+
bandwidthBytes: number;
|
|
13
|
+
contractAddress?: string;
|
|
14
|
+
fullEnergyOnShareLookupFailure?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const getTronContractCallFallbackFeeCryptoBaseUnit: ({ adapter, energy, bandwidthBytes, contractAddress, fullEnergyOnShareLookupFailure, }: GetTronContractCallFallbackFeeArgs) => Promise<string>;
|
|
17
|
+
type GetTronContractCallNetworkFeeArgs = {
|
|
18
|
+
adapter: tron.ChainAdapter;
|
|
19
|
+
transactionData: TronContractCall;
|
|
20
|
+
from: string;
|
|
21
|
+
sellAsset: Asset;
|
|
22
|
+
sellAmountCryptoBaseUnit: string;
|
|
23
|
+
spenderAddress: string;
|
|
24
|
+
fallbackEnergy: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const getTronContractCallNetworkFeeCryptoBaseUnit: ({ adapter, transactionData, from, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, fallbackEnergy, }: GetTronContractCallNetworkFeeArgs) => Promise<string>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { tron as unchainedTron } from '@shapeshiftoss/unchained-client';
|
|
4
|
+
import { bn, isToken } from '@shapeshiftoss/utils';
|
|
5
|
+
// A measured worst-case energy under the adapter's margin, at live prices
|
|
6
|
+
export const getTronContractCallFallbackFeeCryptoBaseUnit = async ({ adapter, energy, bandwidthBytes, contractAddress, fullEnergyOnShareLookupFailure = false, }) => {
|
|
7
|
+
const { httpProvider } = adapter;
|
|
8
|
+
const [{ energyPrice, bandwidthPrice }, share] = await Promise.all([
|
|
9
|
+
httpProvider.getChainPrices(),
|
|
10
|
+
contractAddress
|
|
11
|
+
? httpProvider.getContractEnergyShare(tron.toTronBase58(contractAddress)).catch(error => {
|
|
12
|
+
if (!fullEnergyOnShareLookupFailure)
|
|
13
|
+
throw error;
|
|
14
|
+
return undefined;
|
|
15
|
+
})
|
|
16
|
+
: undefined,
|
|
17
|
+
]);
|
|
18
|
+
const callerEnergy = share ? unchainedTron.getCallerEnergy(Number(energy), share) : energy;
|
|
19
|
+
return bn(callerEnergy)
|
|
20
|
+
.times(tron.TRON_ENERGY_SAFETY_MARGIN)
|
|
21
|
+
.times(energyPrice)
|
|
22
|
+
.plus(bn(bandwidthBytes).times(bandwidthPrice))
|
|
23
|
+
.toFixed(0);
|
|
24
|
+
};
|
|
25
|
+
// Quote arm: a funded token sell that reverts for want of its allowance prices the measured worst case, anything else throws
|
|
26
|
+
export const getTronContractCallNetworkFeeCryptoBaseUnit = async ({ adapter, transactionData, from, sellAsset, sellAmountCryptoBaseUnit, spenderAddress, fallbackEnergy, }) => {
|
|
27
|
+
const { to, value, data } = transactionData;
|
|
28
|
+
try {
|
|
29
|
+
const { fast } = await adapter.getFeeData({
|
|
30
|
+
to,
|
|
31
|
+
value,
|
|
32
|
+
chainSpecific: { from, data, requireEnergyShare: true },
|
|
33
|
+
});
|
|
34
|
+
return fast.txFee;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (!isToken(sellAsset.assetId))
|
|
38
|
+
throw error;
|
|
39
|
+
const contractAddress = fromAssetId(sellAsset.assetId).assetReference;
|
|
40
|
+
const { httpProvider } = adapter;
|
|
41
|
+
const [allowance, balance] = await Promise.all([
|
|
42
|
+
httpProvider.getTrc20Allowance({
|
|
43
|
+
contractAddress,
|
|
44
|
+
owner: from,
|
|
45
|
+
spender: tron.toTronBase58(spenderAddress),
|
|
46
|
+
}),
|
|
47
|
+
httpProvider.getTrc20Balance({ contractAddress, address: from }),
|
|
48
|
+
]);
|
|
49
|
+
const sellAmount = BigInt(sellAmountCryptoBaseUnit);
|
|
50
|
+
if (BigInt(allowance) >= sellAmount || BigInt(balance) < sellAmount)
|
|
51
|
+
throw error;
|
|
52
|
+
return getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
53
|
+
adapter,
|
|
54
|
+
energy: fallbackEnergy,
|
|
55
|
+
bandwidthBytes: tron.getTronContractCallBandwidthBytes(data),
|
|
56
|
+
contractAddress: to,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { ETH } from '../test-data/assets.js';
|
|
4
|
+
import { getTronContractCallFallbackFeeCryptoBaseUnit, getTronContractCallNetworkFeeCryptoBaseUnit, } from './getTronNetworkFeeCryptoBaseUnit.js';
|
|
5
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
6
|
+
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
7
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
8
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
9
|
+
const SPENDER_HEX = '4107a39ae4c49dee86e892450b20881f32cd5d500d';
|
|
10
|
+
const SPENDER = 'TAfbit1ENsRmtZbPQfYU3srURpfYuWYS7K';
|
|
11
|
+
const transactionData = { to: SPENDER, data: '0x2213bc0b', value: '0' };
|
|
12
|
+
const makeAdapter = ({ allowance = '0', balance = '100000000', simulation = 'ok', } = {}) => {
|
|
13
|
+
const getFeeData = simulation === 'ok'
|
|
14
|
+
? vi.fn().mockResolvedValue({ fast: { txFee: '9000000' } })
|
|
15
|
+
: vi.fn().mockRejectedValue(new Error('REVERT opcode executed'));
|
|
16
|
+
const getTrc20Allowance = vi.fn().mockResolvedValue(allowance);
|
|
17
|
+
const getTrc20Balance = vi.fn().mockResolvedValue(balance);
|
|
18
|
+
const getContractEnergyShare = vi.fn().mockResolvedValue({
|
|
19
|
+
callerPercent: 100,
|
|
20
|
+
originEnergyLimit: 0,
|
|
21
|
+
originEnergyAvailable: 0,
|
|
22
|
+
});
|
|
23
|
+
const adapter = {
|
|
24
|
+
getFeeData,
|
|
25
|
+
httpProvider: {
|
|
26
|
+
getTrc20Allowance,
|
|
27
|
+
getTrc20Balance,
|
|
28
|
+
getContractEnergyShare,
|
|
29
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
adapter: adapter,
|
|
34
|
+
getFeeData,
|
|
35
|
+
getTrc20Allowance,
|
|
36
|
+
getTrc20Balance,
|
|
37
|
+
getContractEnergyShare,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const baseArgs = {
|
|
41
|
+
transactionData,
|
|
42
|
+
from: FROM,
|
|
43
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
44
|
+
spenderAddress: SPENDER_HEX,
|
|
45
|
+
fallbackEnergy: '400000',
|
|
46
|
+
};
|
|
47
|
+
// 400000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
48
|
+
const FALLBACK_FEE = '48283000';
|
|
49
|
+
describe('getTronContractCallFallbackFeeCryptoBaseUnit', () => {
|
|
50
|
+
it('prices the energy under the adapter margin at live prices plus the bandwidth', async () => {
|
|
51
|
+
const { adapter, getContractEnergyShare } = makeAdapter();
|
|
52
|
+
expect(await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
53
|
+
adapter,
|
|
54
|
+
energy: '400000',
|
|
55
|
+
bandwidthBytes: 283,
|
|
56
|
+
})).toBe(FALLBACK_FEE);
|
|
57
|
+
expect(getContractEnergyShare).not.toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
it('bills the caller only their share of a contract whose deployer covers the rest', async () => {
|
|
60
|
+
const { adapter, getContractEnergyShare } = makeAdapter();
|
|
61
|
+
getContractEnergyShare.mockResolvedValue({
|
|
62
|
+
callerPercent: 5,
|
|
63
|
+
originEnergyLimit: 10_000_000,
|
|
64
|
+
originEnergyAvailable: 5_000_000,
|
|
65
|
+
});
|
|
66
|
+
// 20000 caller energy * 1.2 margin * 100 sun + 283 bytes * 1000 sun
|
|
67
|
+
expect(await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
68
|
+
adapter,
|
|
69
|
+
energy: '400000',
|
|
70
|
+
bandwidthBytes: 283,
|
|
71
|
+
contractAddress: SPENDER,
|
|
72
|
+
})).toBe('2683000');
|
|
73
|
+
expect(getContractEnergyShare).toHaveBeenCalledWith(SPENDER);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('getTronContractCallFallbackFeeCryptoBaseUnit share lookup failure', () => {
|
|
77
|
+
it('rejects by default', async () => {
|
|
78
|
+
const { adapter, getContractEnergyShare } = makeAdapter();
|
|
79
|
+
getContractEnergyShare.mockRejectedValue(new Error('429'));
|
|
80
|
+
await expect(getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
81
|
+
adapter,
|
|
82
|
+
energy: '400000',
|
|
83
|
+
bandwidthBytes: 283,
|
|
84
|
+
contractAddress: SPENDER,
|
|
85
|
+
})).rejects.toThrow('429');
|
|
86
|
+
});
|
|
87
|
+
it('prices the caller in full when the caller opts in', async () => {
|
|
88
|
+
const { adapter, getContractEnergyShare } = makeAdapter();
|
|
89
|
+
getContractEnergyShare.mockRejectedValue(new Error('429'));
|
|
90
|
+
expect(await getTronContractCallFallbackFeeCryptoBaseUnit({
|
|
91
|
+
adapter,
|
|
92
|
+
energy: '400000',
|
|
93
|
+
bandwidthBytes: 283,
|
|
94
|
+
contractAddress: SPENDER,
|
|
95
|
+
fullEnergyOnShareLookupFailure: true,
|
|
96
|
+
})).toBe(FALLBACK_FEE);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('getTronContractCallNetworkFeeCryptoBaseUnit', () => {
|
|
100
|
+
it('prices a successful simulation without reading the allowance', async () => {
|
|
101
|
+
const { adapter, getFeeData, getTrc20Allowance } = makeAdapter();
|
|
102
|
+
const actual = await getTronContractCallNetworkFeeCryptoBaseUnit({
|
|
103
|
+
...baseArgs,
|
|
104
|
+
adapter,
|
|
105
|
+
sellAsset: USDT_TRON,
|
|
106
|
+
});
|
|
107
|
+
expect(actual).toBe('9000000');
|
|
108
|
+
expect(getFeeData).toHaveBeenCalledWith({
|
|
109
|
+
to: SPENDER,
|
|
110
|
+
value: '0',
|
|
111
|
+
chainSpecific: { from: FROM, data: '0x2213bc0b', requireEnergyShare: true },
|
|
112
|
+
});
|
|
113
|
+
expect(getTrc20Allowance).not.toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
it('prices the measured worst case when a funded token sell reverts without its allowance', async () => {
|
|
116
|
+
const { adapter, getTrc20Allowance, getTrc20Balance, getContractEnergyShare } = makeAdapter({
|
|
117
|
+
simulation: 'revert',
|
|
118
|
+
allowance: '0',
|
|
119
|
+
});
|
|
120
|
+
const actual = await getTronContractCallNetworkFeeCryptoBaseUnit({
|
|
121
|
+
...baseArgs,
|
|
122
|
+
adapter,
|
|
123
|
+
sellAsset: USDT_TRON,
|
|
124
|
+
});
|
|
125
|
+
expect(actual).toBe(FALLBACK_FEE);
|
|
126
|
+
expect(getTrc20Allowance).toHaveBeenCalledWith({
|
|
127
|
+
contractAddress: USDT,
|
|
128
|
+
owner: FROM,
|
|
129
|
+
spender: SPENDER,
|
|
130
|
+
});
|
|
131
|
+
expect(getTrc20Balance).toHaveBeenCalledWith({ contractAddress: USDT, address: FROM });
|
|
132
|
+
expect(getContractEnergyShare).toHaveBeenCalledWith(SPENDER);
|
|
133
|
+
});
|
|
134
|
+
it('fails the quote rather than guessing when the share lookup fails', async () => {
|
|
135
|
+
const { adapter, getContractEnergyShare } = makeAdapter({
|
|
136
|
+
simulation: 'revert',
|
|
137
|
+
allowance: '0',
|
|
138
|
+
});
|
|
139
|
+
getContractEnergyShare.mockRejectedValue(new Error('429'));
|
|
140
|
+
await expect(getTronContractCallNetworkFeeCryptoBaseUnit({ ...baseArgs, adapter, sellAsset: USDT_TRON })).rejects.toThrow('429');
|
|
141
|
+
});
|
|
142
|
+
it('throws when a token sell reverts with a sufficient allowance', async () => {
|
|
143
|
+
const { adapter } = makeAdapter({ simulation: 'revert', allowance: '100000000' });
|
|
144
|
+
await expect(getTronContractCallNetworkFeeCryptoBaseUnit({ ...baseArgs, adapter, sellAsset: USDT_TRON })).rejects.toThrow('REVERT opcode executed');
|
|
145
|
+
});
|
|
146
|
+
it('throws when the token balance cannot cover the sell', async () => {
|
|
147
|
+
const { adapter } = makeAdapter({ simulation: 'revert', allowance: '0', balance: '1' });
|
|
148
|
+
await expect(getTronContractCallNetworkFeeCryptoBaseUnit({ ...baseArgs, adapter, sellAsset: USDT_TRON })).rejects.toThrow('REVERT opcode executed');
|
|
149
|
+
});
|
|
150
|
+
it('throws when a native sell reverts', async () => {
|
|
151
|
+
const { adapter, getTrc20Allowance } = makeAdapter({ simulation: 'revert' });
|
|
152
|
+
await expect(getTronContractCallNetworkFeeCryptoBaseUnit({ ...baseArgs, adapter, sellAsset: TRX })).rejects.toThrow('REVERT opcode executed');
|
|
153
|
+
expect(getTrc20Allowance).not.toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
1
2
|
import type { GetUnsignedTronTransactionArgs } from '../../types.js';
|
|
2
|
-
export declare const getUnsignedTronTransaction: ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }: GetUnsignedTronTransactionArgs) => Promise<
|
|
3
|
+
export declare const getUnsignedTronTransaction: ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }: GetUnsignedTronTransactionArgs) => Promise<tron.TronSignTx>;
|
|
@@ -1,61 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
2
|
import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
3
|
-
import { TronWeb } from 'tronweb';
|
|
4
3
|
import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils/index.js';
|
|
5
4
|
export const getUnsignedTronTransaction = ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }) => {
|
|
6
5
|
if (!isExecutableTradeQuote(tradeQuote))
|
|
7
|
-
throw new Error('Unable to execute a trade rate
|
|
6
|
+
throw new Error('Unable to execute a trade rate');
|
|
8
7
|
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
9
|
-
const { accountNumber, sellAsset,
|
|
8
|
+
const { accountNumber, sellAsset, transactionData, feeData } = step;
|
|
9
|
+
if (transactionData?.type !== 'tron')
|
|
10
|
+
throw new Error('Missing tron transactionData');
|
|
10
11
|
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!data)
|
|
16
|
-
throw new Error('Missing Butter swap transaction data');
|
|
17
|
-
// Use Butter's value field which includes swap fees for same-chain swaps
|
|
18
|
-
// For native TRX sells, also include the sell amount
|
|
19
|
-
const isNativeTron = sellAsset.assetId === tronAssetId;
|
|
20
|
-
const value = isNativeTron ? step.sellAmountIncludingProtocolFeesCryptoBaseUnit : butterValue;
|
|
21
|
-
return adapter.buildCustomApiTx({
|
|
22
|
-
from,
|
|
23
|
-
to,
|
|
24
|
-
accountNumber,
|
|
25
|
-
data,
|
|
26
|
-
value,
|
|
27
|
-
method,
|
|
28
|
-
args,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (relayTransactionMetadata?.data) {
|
|
32
|
-
if (!relayTransactionMetadata.to) {
|
|
33
|
-
throw new Error('Missing Relay transaction destination address');
|
|
34
|
-
}
|
|
35
|
-
const to = TronWeb.address.fromHex(relayTransactionMetadata.to);
|
|
36
|
-
const isNativeTron = sellAsset.assetId === tronAssetId;
|
|
37
|
-
const value = isNativeTron ? step.sellAmountIncludingProtocolFeesCryptoBaseUnit : '0';
|
|
38
|
-
return adapter.buildCustomApiTx({
|
|
39
|
-
from,
|
|
40
|
-
to,
|
|
41
|
-
accountNumber,
|
|
42
|
-
data: relayTransactionMetadata.data,
|
|
43
|
-
value,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const nearIntentsDepositAddress = step.swapperMetadata?.name === 'nearIntents' ? step.swapperMetadata.depositAddress : undefined;
|
|
47
|
-
const to = relayTransactionMetadata?.to ?? nearIntentsDepositAddress;
|
|
48
|
-
if (!to)
|
|
49
|
-
throw new Error('Missing transaction destination address');
|
|
50
|
-
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
51
|
-
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
12
|
+
const { to, value, data, memo } = transactionData;
|
|
13
|
+
const feeLimit = tron.getTronFeeLimit(feeData.networkFeeCryptoBaseUnit);
|
|
14
|
+
if (data)
|
|
15
|
+
return adapter.buildCustomApiTx({ from, to, accountNumber, data, value, feeLimit });
|
|
52
16
|
return adapter.buildSendApiTransaction({
|
|
53
|
-
to,
|
|
54
17
|
from,
|
|
55
|
-
|
|
18
|
+
to,
|
|
56
19
|
accountNumber,
|
|
20
|
+
value,
|
|
57
21
|
chainSpecific: {
|
|
58
|
-
contractAddress,
|
|
22
|
+
contractAddress: contractAddressOrUndefined(sellAsset.assetId),
|
|
23
|
+
memo,
|
|
24
|
+
feeLimit,
|
|
59
25
|
},
|
|
60
26
|
});
|
|
61
27
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { ETH } from '../test-data/assets.js';
|
|
4
|
+
import { getUnsignedTronTransaction } from './getUnsignedTronTransaction.js';
|
|
5
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
6
|
+
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
7
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
8
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
9
|
+
const TO = 'TCFNp179Lg46D16zKoumd4Poa2WFFdtqYj';
|
|
10
|
+
const makeArgs = (sellAsset, transactionData, feeData = {
|
|
11
|
+
networkFeeCryptoBaseUnit: '9000000',
|
|
12
|
+
}) => {
|
|
13
|
+
const adapter = {
|
|
14
|
+
buildCustomApiTx: vi.fn().mockResolvedValue('custom'),
|
|
15
|
+
buildSendApiTransaction: vi.fn().mockResolvedValue('send'),
|
|
16
|
+
};
|
|
17
|
+
const tradeQuote = {
|
|
18
|
+
quoteOrRate: 'quote',
|
|
19
|
+
steps: [{ accountNumber: 0, sellAsset, transactionData, feeData }],
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
adapter,
|
|
23
|
+
args: {
|
|
24
|
+
tradeQuote,
|
|
25
|
+
stepIndex: 0,
|
|
26
|
+
from: FROM,
|
|
27
|
+
assertGetTronChainAdapter: () => adapter,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
describe('getUnsignedTronTransaction', () => {
|
|
32
|
+
it('builds a contract call when data is present', async () => {
|
|
33
|
+
const { adapter, args } = makeArgs(TRX, {
|
|
34
|
+
type: 'tron',
|
|
35
|
+
to: TO,
|
|
36
|
+
data: '0xdeadbeef',
|
|
37
|
+
value: '1',
|
|
38
|
+
});
|
|
39
|
+
expect(await getUnsignedTronTransaction(args)).toBe('custom');
|
|
40
|
+
expect(adapter.buildCustomApiTx).toHaveBeenCalledWith({
|
|
41
|
+
from: FROM,
|
|
42
|
+
to: TO,
|
|
43
|
+
accountNumber: 0,
|
|
44
|
+
data: '0xdeadbeef',
|
|
45
|
+
value: '1',
|
|
46
|
+
feeLimit: 27_000_000,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('uses the standard fee limit when the step carries no estimate', async () => {
|
|
50
|
+
const { adapter, args } = makeArgs(TRX, { type: 'tron', to: TO, data: '0xdeadbeef', value: '1' }, { networkFeeCryptoBaseUnit: undefined });
|
|
51
|
+
await getUnsignedTronTransaction(args);
|
|
52
|
+
expect(adapter.buildCustomApiTx).toHaveBeenCalledWith(expect.objectContaining({ feeLimit: 100_000_000 }));
|
|
53
|
+
});
|
|
54
|
+
it('builds a send of the sell asset when data is absent', async () => {
|
|
55
|
+
const { adapter, args } = makeArgs(USDT_TRON, {
|
|
56
|
+
type: 'tron',
|
|
57
|
+
to: TO,
|
|
58
|
+
value: '1',
|
|
59
|
+
memo: '=:ETH.ETH:0xabc',
|
|
60
|
+
});
|
|
61
|
+
expect(await getUnsignedTronTransaction(args)).toBe('send');
|
|
62
|
+
expect(adapter.buildSendApiTransaction).toHaveBeenCalledWith({
|
|
63
|
+
from: FROM,
|
|
64
|
+
to: TO,
|
|
65
|
+
accountNumber: 0,
|
|
66
|
+
value: '1',
|
|
67
|
+
chainSpecific: { contractAddress: USDT, memo: '=:ETH.ETH:0xabc', feeLimit: 27_000_000 },
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('throws without tron transactionData', () => {
|
|
71
|
+
const { args } = makeArgs(TRX, undefined);
|
|
72
|
+
expect(() => getUnsignedTronTransaction(args)).toThrow('Missing tron transactionData');
|
|
73
|
+
});
|
|
74
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.3.0",
|
|
4
4
|
"repository": "https://github.com/shapeshift/web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@coral-xyz/anchor": "0.29.0",
|
|
29
29
|
"@cowprotocol/app-data": "^2.3.0",
|
|
30
30
|
"@defuse-protocol/one-click-sdk-typescript": "^0.1.1-0.2",
|
|
31
|
-
"@gobob/bob-sdk": "
|
|
31
|
+
"@gobob/bob-sdk": "6.0.1",
|
|
32
32
|
"@mysten/sui": "^1.45.2",
|
|
33
33
|
"@shapeshiftoss/bitcoinjs-lib": "7.0.0-shapeshift.0",
|
|
34
34
|
"@sniptt/monads": "^0.5.10",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"retry-axios": "^2.6.0",
|
|
51
51
|
"uuid": "^9.0.0",
|
|
52
52
|
"viem": "2.55.11",
|
|
53
|
-
"@shapeshiftoss/caip": "^8.17.
|
|
54
|
-
"@shapeshiftoss/chain-adapters": "^11.
|
|
55
|
-
"@shapeshiftoss/contracts": "^1.0.7",
|
|
53
|
+
"@shapeshiftoss/caip": "^8.17.1",
|
|
54
|
+
"@shapeshiftoss/chain-adapters": "^11.6.0",
|
|
56
55
|
"@shapeshiftoss/hdwallet-core": "^1.62.41",
|
|
57
|
-
"@shapeshiftoss/
|
|
58
|
-
"@shapeshiftoss/
|
|
59
|
-
"@shapeshiftoss/utils": "^1.3.
|
|
56
|
+
"@shapeshiftoss/contracts": "^1.1.0",
|
|
57
|
+
"@shapeshiftoss/types": "^9.1.0",
|
|
58
|
+
"@shapeshiftoss/utils": "^1.3.1",
|
|
59
|
+
"@shapeshiftoss/unchained-client": "^10.15.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/lodash": "^4.14.178",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types';
|
|
2
|
-
export type SwapRouteParameters = {
|
|
3
|
-
path: string[];
|
|
4
|
-
poolVersion: string[];
|
|
5
|
-
versionLen: number[];
|
|
6
|
-
fees: number[];
|
|
7
|
-
swapData: {
|
|
8
|
-
amountIn: string;
|
|
9
|
-
amountOutMin: string;
|
|
10
|
-
recipient: string;
|
|
11
|
-
deadline: number;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare const buildSwapRouteParameters: (route: SunioRoute, sellAmountCryptoBaseUnit: string, minBuyAmountCryptoBaseUnit: string, recipient: string, slippageTolerancePercentageDecimal: string) => SwapRouteParameters;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSwapRouteParameters = void 0;
|
|
4
|
-
const utils_1 = require("@shapeshiftoss/utils");
|
|
5
|
-
const buildSwapRouteParameters = (route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal) => {
|
|
6
|
-
const path = route.tokens;
|
|
7
|
-
const poolVersion = route.poolVersions;
|
|
8
|
-
// The SmartExchangeRouter expects sum(versionLen) === path.length: the first
|
|
9
|
-
// pool segment consumes 2 tokens (input + output) and each subsequent pool
|
|
10
|
-
// reuses the previous output, consuming 1 new token. This relies on the Sun.io
|
|
11
|
-
// API returning poolVersions per-hop (poolVersions.length === tokens.length - 1),
|
|
12
|
-
// which it does — the router also accepts this un-collapsed form for same-version hops.
|
|
13
|
-
const versionLen = poolVersion.map((_, index) => (index === 0 ? 2 : 1));
|
|
14
|
-
const fees = route.poolFees.map(fee => Number(fee));
|
|
15
|
-
const amountOutWithSlippage = (0, utils_1.bn)(minBuyAmountCryptoBaseUnit)
|
|
16
|
-
.times((0, utils_1.bn)(1).minus(slippageTolerancePercentageDecimal))
|
|
17
|
-
.toFixed(0);
|
|
18
|
-
const swapData = {
|
|
19
|
-
amountIn: sellAmountCryptoBaseUnit,
|
|
20
|
-
amountOutMin: amountOutWithSlippage,
|
|
21
|
-
recipient,
|
|
22
|
-
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
path,
|
|
26
|
-
poolVersion,
|
|
27
|
-
versionLen,
|
|
28
|
-
fees,
|
|
29
|
-
swapData,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.buildSwapRouteParameters = buildSwapRouteParameters;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { SunioRoute } from '../types';
|
|
2
|
-
type EstimateSunioNetworkFeeArgs = {
|
|
3
|
-
rpcUrl: string;
|
|
4
|
-
apiKey: string;
|
|
5
|
-
route: SunioRoute;
|
|
6
|
-
sellAmountCryptoBaseUnit: string;
|
|
7
|
-
isSellingNativeTrx: boolean;
|
|
8
|
-
address: string | undefined;
|
|
9
|
-
slippageTolerancePercentageDecimal: string | undefined;
|
|
10
|
-
};
|
|
11
|
-
export declare const estimateSunioNetworkFeeCryptoBaseUnit: ({ rpcUrl, apiKey, route, sellAmountCryptoBaseUnit, isSellingNativeTrx, address, slippageTolerancePercentageDecimal, }: EstimateSunioNetworkFeeArgs) => Promise<string>;
|
|
12
|
-
export {};
|