@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,175 @@
|
|
|
1
|
+
import { tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { ETH } from '../../../utils/test-data/assets.js';
|
|
5
|
+
import { buildSunioSwapCalldata } from './buildSwapContractCall.js';
|
|
6
|
+
import { SUNIO_FALLBACK_SWAP_ENERGY_NATIVE, SUNIO_FALLBACK_SWAP_ENERGY_TRC20, SUNIO_SMART_ROUTER_CONTRACT, } from './constants.js';
|
|
7
|
+
import { getSunioStepData } from './getSunioStepData.js';
|
|
8
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
9
|
+
const TRX = { ...ETH, assetId: `${tronChainId}/slip44:195`, chainId: tronChainId };
|
|
10
|
+
const USDT_TRON = { ...ETH, assetId: `${tronChainId}/trc20:${USDT}`, chainId: tronChainId };
|
|
11
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
12
|
+
const route = {
|
|
13
|
+
tokens: ['T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb', USDT],
|
|
14
|
+
poolVersions: ['v2'],
|
|
15
|
+
poolFees: ['0'],
|
|
16
|
+
};
|
|
17
|
+
const tronAdapter = ({ txFee = '9000000', allowance = '0' } = {}) => ({
|
|
18
|
+
getFeeData: vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
19
|
+
httpProvider: {
|
|
20
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
21
|
+
getTrc20Allowance: vi.fn().mockResolvedValue(allowance),
|
|
22
|
+
getTrc20Balance: vi.fn().mockResolvedValue('100000000'),
|
|
23
|
+
getContractEnergyShare: vi.fn().mockResolvedValue({
|
|
24
|
+
callerPercent: 100,
|
|
25
|
+
originEnergyLimit: 0,
|
|
26
|
+
originEnergyAvailable: 0,
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const makeDeps = (tron) => ({ assertGetTronChainAdapter: () => tron });
|
|
31
|
+
const baseArgs = {
|
|
32
|
+
route,
|
|
33
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
34
|
+
buyAmountCryptoBaseUnit: '30000000',
|
|
35
|
+
};
|
|
36
|
+
// The calldata is fixed-width ABI, so its size doesn't depend on the recipient or deadline
|
|
37
|
+
const calldataBandwidthBytes = tron.getTronContractCallBandwidthBytes(buildSunioSwapCalldata({
|
|
38
|
+
route,
|
|
39
|
+
sellAmountCryptoBaseUnit: '100000000',
|
|
40
|
+
minBuyAmountCryptoBaseUnit: '30000000',
|
|
41
|
+
recipient: FROM,
|
|
42
|
+
slippageTolerancePercentageDecimal: '0.005',
|
|
43
|
+
deadline: 0,
|
|
44
|
+
}));
|
|
45
|
+
const fallbackFee = (energy) => String(Number(energy) * 1.2 * 100 + calldataBandwidthBytes * 1000);
|
|
46
|
+
describe('getSunioStepData', () => {
|
|
47
|
+
describe('quote', () => {
|
|
48
|
+
it('carries the router call as transactionData and simulates it', async () => {
|
|
49
|
+
const adapter = tronAdapter();
|
|
50
|
+
const actual = await getSunioStepData({
|
|
51
|
+
...baseArgs,
|
|
52
|
+
type: 'quote',
|
|
53
|
+
input: {
|
|
54
|
+
receiveAddress: FROM,
|
|
55
|
+
slippageTolerancePercentageDecimal: '0.01',
|
|
56
|
+
},
|
|
57
|
+
deps: makeDeps(adapter),
|
|
58
|
+
sellAsset: TRX,
|
|
59
|
+
from: FROM,
|
|
60
|
+
});
|
|
61
|
+
const { transactionData, networkFeeCryptoBaseUnit, deadline } = actual.unwrap();
|
|
62
|
+
expect(transactionData).toMatchObject({
|
|
63
|
+
type: 'tron',
|
|
64
|
+
to: SUNIO_SMART_ROUTER_CONTRACT,
|
|
65
|
+
value: '100000000',
|
|
66
|
+
});
|
|
67
|
+
// swapExactInput selector
|
|
68
|
+
expect(transactionData.data).toMatch(/^0x[0-9a-f]{8}/);
|
|
69
|
+
expect(networkFeeCryptoBaseUnit).toBe('9000000');
|
|
70
|
+
expect(deadline).toBeGreaterThan(Date.now());
|
|
71
|
+
expect(adapter.getFeeData).toHaveBeenCalledWith({
|
|
72
|
+
to: SUNIO_SMART_ROUTER_CONTRACT,
|
|
73
|
+
value: '100000000',
|
|
74
|
+
chainSpecific: { from: FROM, data: transactionData.data, requireEnergyShare: true },
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('sends no value for a token sell', async () => {
|
|
78
|
+
const actual = await getSunioStepData({
|
|
79
|
+
...baseArgs,
|
|
80
|
+
type: 'quote',
|
|
81
|
+
input: { receiveAddress: FROM },
|
|
82
|
+
deps: makeDeps(tronAdapter()),
|
|
83
|
+
sellAsset: USDT_TRON,
|
|
84
|
+
from: FROM,
|
|
85
|
+
});
|
|
86
|
+
expect(actual.unwrap().transactionData.value).toBe('0');
|
|
87
|
+
});
|
|
88
|
+
it('fails a native quote when the simulation fails', async () => {
|
|
89
|
+
const adapter = tronAdapter();
|
|
90
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
91
|
+
const actual = await getSunioStepData({
|
|
92
|
+
...baseArgs,
|
|
93
|
+
type: 'quote',
|
|
94
|
+
input: { receiveAddress: FROM },
|
|
95
|
+
deps: makeDeps(adapter),
|
|
96
|
+
sellAsset: TRX,
|
|
97
|
+
from: FROM,
|
|
98
|
+
});
|
|
99
|
+
expect(actual.isErr()).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
it('prices the token worst case when the allowance is not granted yet', async () => {
|
|
102
|
+
const adapter = tronAdapter({ allowance: '0' });
|
|
103
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
104
|
+
const actual = await getSunioStepData({
|
|
105
|
+
...baseArgs,
|
|
106
|
+
type: 'quote',
|
|
107
|
+
input: { receiveAddress: FROM },
|
|
108
|
+
deps: makeDeps(adapter),
|
|
109
|
+
sellAsset: USDT_TRON,
|
|
110
|
+
from: FROM,
|
|
111
|
+
});
|
|
112
|
+
const { transactionData, networkFeeCryptoBaseUnit } = actual.unwrap();
|
|
113
|
+
expect(transactionData.to).toBe(SUNIO_SMART_ROUTER_CONTRACT);
|
|
114
|
+
expect(networkFeeCryptoBaseUnit).toBe(fallbackFee(SUNIO_FALLBACK_SWAP_ENERGY_TRC20));
|
|
115
|
+
expect(adapter.httpProvider.getTrc20Allowance).toHaveBeenCalledWith({
|
|
116
|
+
contractAddress: USDT,
|
|
117
|
+
owner: FROM,
|
|
118
|
+
spender: SUNIO_SMART_ROUTER_CONTRACT,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it('fails a token quote that reverts with its allowance in place', async () => {
|
|
122
|
+
const adapter = tronAdapter({ allowance: '100000000' });
|
|
123
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
124
|
+
const actual = await getSunioStepData({
|
|
125
|
+
...baseArgs,
|
|
126
|
+
type: 'quote',
|
|
127
|
+
input: { receiveAddress: FROM },
|
|
128
|
+
deps: makeDeps(adapter),
|
|
129
|
+
sellAsset: USDT_TRON,
|
|
130
|
+
from: FROM,
|
|
131
|
+
});
|
|
132
|
+
expect(actual.isErr()).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('rate', () => {
|
|
136
|
+
it('simulates from the receive address when present', async () => {
|
|
137
|
+
const actual = await getSunioStepData({
|
|
138
|
+
...baseArgs,
|
|
139
|
+
type: 'rate',
|
|
140
|
+
input: { receiveAddress: FROM },
|
|
141
|
+
deps: makeDeps(tronAdapter()),
|
|
142
|
+
sellAsset: TRX,
|
|
143
|
+
from: FROM,
|
|
144
|
+
});
|
|
145
|
+
expect(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '9000000' });
|
|
146
|
+
});
|
|
147
|
+
it('prices the measured worst case without an address to simulate from', async () => {
|
|
148
|
+
const actual = await getSunioStepData({
|
|
149
|
+
...baseArgs,
|
|
150
|
+
type: 'rate',
|
|
151
|
+
input: {},
|
|
152
|
+
deps: makeDeps(tronAdapter()),
|
|
153
|
+
sellAsset: TRX,
|
|
154
|
+
});
|
|
155
|
+
expect(actual.unwrap()).toEqual({
|
|
156
|
+
networkFeeCryptoBaseUnit: fallbackFee(SUNIO_FALLBACK_SWAP_ENERGY_NATIVE),
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('prices the token worst case when a pre-approval simulation reverts', async () => {
|
|
160
|
+
const adapter = tronAdapter();
|
|
161
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
162
|
+
const actual = await getSunioStepData({
|
|
163
|
+
...baseArgs,
|
|
164
|
+
type: 'rate',
|
|
165
|
+
input: { receiveAddress: FROM },
|
|
166
|
+
deps: makeDeps(adapter),
|
|
167
|
+
sellAsset: USDT_TRON,
|
|
168
|
+
from: FROM,
|
|
169
|
+
});
|
|
170
|
+
expect(actual.unwrap()).toEqual({
|
|
171
|
+
networkFeeCryptoBaseUnit: fallbackFee(SUNIO_FALLBACK_SWAP_ENERGY_TRC20),
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -4,7 +4,7 @@ import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
|
4
4
|
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils/index.js';
|
|
5
5
|
import { buildAffiliateFee } from '../../../utils/affiliateFee.js';
|
|
6
6
|
import { DEFAULT_SLIPPAGE_PERCENTAGE, SUNIO_SMART_ROUTER_CONTRACT } from './constants.js';
|
|
7
|
-
import { fetchSunioQuote } from './
|
|
7
|
+
import { fetchSunioQuote } from './fetchSunioQuote.js';
|
|
8
8
|
import { assertValidTrade } from './helpers.js';
|
|
9
9
|
import { sunioServiceFactory } from './sunioService.js';
|
|
10
10
|
export const getSunioTradeContext = async ({ input, deps, }) => {
|
|
@@ -84,6 +84,7 @@ export const getSunioTradeContext = async ({ input, deps, }) => {
|
|
|
84
84
|
deps,
|
|
85
85
|
sellAsset,
|
|
86
86
|
sellAmountCryptoBaseUnit: sellAmountIncludingProtocolFeesCryptoBaseUnit,
|
|
87
|
+
buyAmountCryptoBaseUnit,
|
|
87
88
|
route: bestRoute,
|
|
88
89
|
},
|
|
89
90
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { fromAssetId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { tron } from '@shapeshiftoss/chain-adapters';
|
|
2
3
|
import { isToken } from '@shapeshiftoss/utils';
|
|
3
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
5
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
5
6
|
import { makeSwapErrorRight } from '../../../utils/index.js';
|
|
6
|
-
import { SUNIO_SUPPORTED_CHAIN_IDS
|
|
7
|
+
import { SUNIO_SUPPORTED_CHAIN_IDS } from './constants.js';
|
|
7
8
|
export const isSupportedChainId = (chainId) => {
|
|
8
9
|
return SUNIO_SUPPORTED_CHAIN_IDS.includes(chainId);
|
|
9
10
|
};
|
|
@@ -12,7 +13,7 @@ export const assetIdToTronToken = (assetId) => {
|
|
|
12
13
|
const { assetReference } = fromAssetId(assetId);
|
|
13
14
|
return assetReference;
|
|
14
15
|
}
|
|
15
|
-
return
|
|
16
|
+
return tron.TRON_ZERO_ADDRESS;
|
|
16
17
|
};
|
|
17
18
|
export const assertValidTrade = ({ sellAsset, buyAsset, }) => {
|
|
18
19
|
if (!isSupportedChainId(sellAsset.chainId)) {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { SwapperName } from '../../types.js';
|
|
2
1
|
import { getCosmosSdkTransactionFees, getUnsignedCosmosSdkTransaction } from '../../utils/cosmossdk/index.js';
|
|
3
2
|
import { getEvmTransactionFees, getUnsignedEvmTransaction } from '../../utils/evm/index.js';
|
|
4
3
|
import { getSolanaTransactionFees, getUnsignedSolanaTransaction } from '../../utils/solana/index.js';
|
|
5
|
-
import { checkTradeStatus
|
|
4
|
+
import { checkTradeStatus } from '../../utils/thorchain/index.js';
|
|
5
|
+
import { getTronTransactionFees, getUnsignedTronTransaction } from '../../utils/tron/index.js';
|
|
6
6
|
import { getUnsignedUtxoTransaction, getUtxoTransactionFees } from '../../utils/utxo/index.js';
|
|
7
7
|
import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
8
8
|
import { getTradeRate } from './getTradeRate/getTradeRate.js';
|
|
9
|
-
const swapperName = SwapperName.Thorchain;
|
|
10
9
|
export const thorchainApi = {
|
|
11
10
|
getTradeRate: (input, deps) => getTradeRate(input, deps),
|
|
12
11
|
getTradeQuote: (input, deps) => getTradeQuote(input, deps),
|
|
@@ -18,8 +17,8 @@ export const thorchainApi = {
|
|
|
18
17
|
getCosmosSdkTransactionFees,
|
|
19
18
|
getUnsignedSolanaTransaction,
|
|
20
19
|
getSolanaTransactionFees,
|
|
21
|
-
getUnsignedTronTransaction
|
|
22
|
-
getTronTransactionFees
|
|
20
|
+
getUnsignedTronTransaction,
|
|
21
|
+
getTronTransactionFees,
|
|
23
22
|
checkTradeStatus: input => {
|
|
24
23
|
const { config } = input;
|
|
25
24
|
const nodeUrl = `${config.VITE_THORCHAIN_NODE_URL}/thorchain`;
|
|
@@ -34,7 +34,12 @@ export const addL1ToLongtailPartsToMemo = ({ sellAssetChainId, quotedMemo, aggre
|
|
|
34
34
|
finalAssetAddress: finalAssetContractAddressShortened,
|
|
35
35
|
});
|
|
36
36
|
const [prefix, nativeAssetName, address, nativeAssetLimitWithManualSlippage, affiliate, affiliateBps, aggregatorLastTwoChars, finalAssetContract,] = quotedMemoWithAggregatorAndFinalAssetContract.split(MEMO_PART_DELIMITER);
|
|
37
|
-
|
|
37
|
+
// THORNode quote memos may already use the shortened native asset name
|
|
38
|
+
const shortenedNativeAssetNames = Object.values(shortenedNativeAssetNameByNativeAssetName);
|
|
39
|
+
const isAlreadyShortened = shortenedNativeAssetNames.includes(nativeAssetName);
|
|
40
|
+
const shortenedNativeAssetName = isAlreadyShortened
|
|
41
|
+
? nativeAssetName
|
|
42
|
+
: shortenedNativeAssetNameByNativeAssetName[nativeAssetName];
|
|
38
43
|
assert(shortenedNativeAssetName, 'cannot find shortened native asset name');
|
|
39
44
|
const memoWithoutFinalAssetLimit = [
|
|
40
45
|
prefix,
|
|
@@ -35,6 +35,21 @@ describe('addL1ToLongtailPartsToMemo', () => {
|
|
|
35
35
|
// The aggregator will turn the finalAssetAmountOut from 94136714201 to 9413671420 using the last 2 bytes as exponents
|
|
36
36
|
`=:e:0x32DBc9Cf9E8FbCebE1e0a2ecF05Ed86Ca3096Cb6:42:ss:100:d2:a6df4741:94136714201`);
|
|
37
37
|
});
|
|
38
|
+
it('should accept a quoted memo with an already shortened native asset name', () => {
|
|
39
|
+
const finalAssetAmountOut = '9508759019';
|
|
40
|
+
const quotedMemo = `=:e:0x32DBc9Cf9E8FbCebE1e0a2ecF05Ed86Ca3096Cb6:42:ss:100`;
|
|
41
|
+
const modifiedMemo = addL1ToLongtailPartsToMemo({
|
|
42
|
+
sellAssetChainId: ethChainId,
|
|
43
|
+
quotedMemo,
|
|
44
|
+
aggregator: AGGREGATOR_ADDRESS,
|
|
45
|
+
finalAssetAssetId: FINAL_ASSET_ASSETID,
|
|
46
|
+
finalAssetAmountOut,
|
|
47
|
+
slippageBps,
|
|
48
|
+
longtailTokens: THORCHAIN_ASSETIDS_ONE_COLLISION,
|
|
49
|
+
affiliate: THORCHAIN_AFFILIATE_NAME,
|
|
50
|
+
});
|
|
51
|
+
expect(modifiedMemo).toBe(`=:e:0x32DBc9Cf9E8FbCebE1e0a2ecF05Ed86Ca3096Cb6:42:ss:100:d2:a6df4741:94136714201`);
|
|
52
|
+
});
|
|
38
53
|
it('should throw if chainId is BCH and initial memo length is > 220', () => {
|
|
39
54
|
const finalAssetAmountOut = '2083854765519275828179229';
|
|
40
55
|
const memoOver220Bytes = `=:ETH.ETH:${REALLY_BIG_ADDRESS}:42:ss:100`;
|
|
@@ -67,5 +67,12 @@ export const assertValidL1ToLongtailTrade = async ({ sellAsset, buyAsset, deps,
|
|
|
67
67
|
details: { sellAssetChainId: sellAsset.chainId },
|
|
68
68
|
}));
|
|
69
69
|
}
|
|
70
|
+
if (sellAsset.assetId === buyAssetFeeAsset.assetId) {
|
|
71
|
+
return Err(makeSwapErrorRight({
|
|
72
|
+
message: `[getThorTradeQuote] - Cannot swap ${sellAsset.assetId} to itself before the aggregator.`,
|
|
73
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
74
|
+
details: { buyAsset, sellAsset },
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
70
77
|
return Ok({ buyAssetFeeAsset, longtailTokens });
|
|
71
78
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET } from '@shapeshiftoss/contracts';
|
|
2
1
|
import { convertDecimalPercentageToBasisPoints } from '@shapeshiftoss/utils';
|
|
3
2
|
import { Err, Ok } from '@sniptt/monads';
|
|
4
3
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
@@ -82,7 +81,6 @@ export const getL1ToLongtailQuote = async (input, deps, streamingInterval, swapp
|
|
|
82
81
|
buyAmountAfterFeesCryptoBaseUnit: quotedAmountOut.toString(),
|
|
83
82
|
// This is wrong, we should get the get the value before fees or display ETH value received after the thorchain bridge
|
|
84
83
|
buyAmountBeforeFeesCryptoBaseUnit: quotedAmountOut.toString(),
|
|
85
|
-
allowanceContract: TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET,
|
|
86
84
|
transactionData,
|
|
87
85
|
feeData: { ...s.feeData, networkFeeCryptoBaseUnit },
|
|
88
86
|
})),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET } from '@shapeshiftoss/contracts';
|
|
2
1
|
import { Err, Ok } from '@sniptt/monads';
|
|
3
2
|
import { getSuccessfulTrades, getThorL1TradeRate, TradeType } from '../../../utils/thorchain/index.js';
|
|
4
3
|
import { assertValidL1ToLongtailTrade } from './assertValidLongtailTrade.js';
|
|
@@ -35,7 +34,6 @@ export const getL1ToLongtailRate = async (input, deps, streamingInterval, swappe
|
|
|
35
34
|
buyAmountAfterFeesCryptoBaseUnit: quotedAmountOut.toString(),
|
|
36
35
|
// This is wrong, we should get the get the value before fees or display ETH value received after the thorchain bridge
|
|
37
36
|
buyAmountBeforeFeesCryptoBaseUnit: quotedAmountOut.toString(),
|
|
38
|
-
allowanceContract: TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET,
|
|
39
37
|
})),
|
|
40
38
|
isLongtail: true,
|
|
41
39
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
export declare const getUniqueAddressSubstring: (destinationAssetId: AssetId, longTailAssetIds: AssetId[]) =>
|
|
2
|
+
export declare const getUniqueAddressSubstring: (destinationAssetId: AssetId, longTailAssetIds: AssetId[]) => string;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
+
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
const MINIMUM_UNIQUE_SUBSTRING = 2;
|
|
3
|
+
// Mirrors THORNode's externalAssetMatch: a case-insensitive suffix match against the target chain's token list only
|
|
1
4
|
export const getUniqueAddressSubstring = (destinationAssetId, longTailAssetIds) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const { chainId, assetReference } = fromAssetId(destinationAssetId);
|
|
6
|
+
const address = assetReference.toLowerCase();
|
|
7
|
+
const sameChainAddresses = longTailAssetIds
|
|
8
|
+
.map(assetId => fromAssetId(assetId))
|
|
9
|
+
.filter(asset => asset.chainId === chainId)
|
|
10
|
+
.map(asset => asset.assetReference.toLowerCase());
|
|
11
|
+
if (!sameChainAddresses.includes(address))
|
|
12
|
+
return address;
|
|
13
|
+
for (let length = MINIMUM_UNIQUE_SUBSTRING; length < address.length; length++) {
|
|
14
|
+
const suffix = address.slice(-length);
|
|
15
|
+
const matchCount = sameChainAddresses.filter(sameChainAddress => sameChainAddress.endsWith(suffix)).length;
|
|
16
|
+
if (matchCount === 1)
|
|
17
|
+
return suffix;
|
|
8
18
|
}
|
|
9
|
-
|
|
10
|
-
Object.keys(substringsCount).forEach(substring => {
|
|
11
|
-
if (assetId.includes(substring)) {
|
|
12
|
-
substringsCount[substring] += 1;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
for (const [substring, count] of Object.entries(substringsCount)) {
|
|
17
|
-
if (count === 1) {
|
|
18
|
-
maybeShortenedDestinationAddress = substring;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return maybeShortenedDestinationAddress;
|
|
19
|
+
return address;
|
|
23
20
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ethChainId, toAssetId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { bscChainId, ethChainId, toAssetId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import longtailTokens from '../../generated/generatedThorLongtailTokens.json';
|
|
3
4
|
import { getUniqueAddressSubstring } from './getUniqueAddressSubstring.js';
|
|
4
5
|
const FINAL_ASSET_ASSETID = toAssetId({
|
|
5
6
|
chainId: ethChainId,
|
|
@@ -16,6 +17,16 @@ const BIGGER_COLLIDING_FINAL_ASSETID = toAssetId({
|
|
|
16
17
|
assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb032a6dF4741',
|
|
17
18
|
assetNamespace: 'erc20',
|
|
18
19
|
});
|
|
20
|
+
const SAME_ADDRESS_OTHER_CHAIN_ASSETID = toAssetId({
|
|
21
|
+
chainId: bscChainId,
|
|
22
|
+
assetReference: '0x8a65ac0E23F31979db06Ec62Af62b432a6dF4741',
|
|
23
|
+
assetNamespace: 'erc20',
|
|
24
|
+
});
|
|
25
|
+
const ONE_INCH_ASSETID = toAssetId({
|
|
26
|
+
chainId: ethChainId,
|
|
27
|
+
assetReference: '0x111111111117dc0aa78b770fa6a738034120c302',
|
|
28
|
+
assetNamespace: 'erc20',
|
|
29
|
+
});
|
|
19
30
|
const SHORTENED_FINAL_ASSET_ADDRESS = 'a6df4741';
|
|
20
31
|
const BIGGER_SHORTENED_FINAL_ASSET_ADDRESS = '432a6df4741';
|
|
21
32
|
const THORCHAIN_ASSETIDS_ONE_COLLISION = [FINAL_ASSET_ASSETID, COLLIDING_FINAL_ASSETID];
|
|
@@ -33,4 +44,21 @@ describe('getUniqueAddressSubstring', () => {
|
|
|
33
44
|
const substring = getUniqueAddressSubstring(FINAL_ASSET_ASSETID, THORCHAIN_ASSETIDS_TWO_COLLISION);
|
|
34
45
|
expect(substring).toBe(BIGGER_SHORTENED_FINAL_ASSET_ADDRESS);
|
|
35
46
|
});
|
|
47
|
+
it('should ignore the same address on other chains', () => {
|
|
48
|
+
const substring = getUniqueAddressSubstring(FINAL_ASSET_ASSETID, [
|
|
49
|
+
...THORCHAIN_ASSETIDS_ONE_COLLISION,
|
|
50
|
+
SAME_ADDRESS_OTHER_CHAIN_ASSETID,
|
|
51
|
+
]);
|
|
52
|
+
expect(substring).toBe(SHORTENED_FINAL_ASSET_ADDRESS);
|
|
53
|
+
});
|
|
54
|
+
it('should return the full address when the asset is not in the list', () => {
|
|
55
|
+
const substring = getUniqueAddressSubstring(FINAL_ASSET_ASSETID, [COLLIDING_FINAL_ASSETID]);
|
|
56
|
+
expect(substring).toBe('0x8a65ac0e23f31979db06ec62af62b432a6df4741');
|
|
57
|
+
});
|
|
58
|
+
it('should return a hex suffix for an address listed on multiple chains', () => {
|
|
59
|
+
expect(longtailTokens).toContain(ONE_INCH_ASSETID);
|
|
60
|
+
const substring = getUniqueAddressSubstring(ONE_INCH_ASSETID, longtailTokens);
|
|
61
|
+
expect(substring).toMatch(/^[0-9a-f]+$/);
|
|
62
|
+
expect('0x111111111117dc0aa78b770fa6a738034120c302'.endsWith(substring)).toBe(true);
|
|
63
|
+
});
|
|
36
64
|
});
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -12,14 +12,12 @@ import type { InterpolationOptions } from 'node-polyglot';
|
|
|
12
12
|
import type { AvnuMetadata } from './swappers/AvnuSwapper/types.js';
|
|
13
13
|
import type { BebopMetadata } from './swappers/BebopSwapper/types.js';
|
|
14
14
|
import type { BobGatewayMetadata } from './swappers/BobGatewaySwapper/types.js';
|
|
15
|
-
import type { ButterSwapTransactionMetadata } from './swappers/ButterSwap/types.js';
|
|
16
15
|
import type { ChainflipMetadata } from './swappers/ChainflipSwapper/types.js';
|
|
17
16
|
import type { CowMessageToSign } from './swappers/CowSwapper/types.js';
|
|
18
17
|
import type { DebridgeMetadata } from './swappers/DebridgeSwapper/utils/types.js';
|
|
19
18
|
import type { NearIntentsMetadata } from './swappers/NearIntentsSwapper/types.js';
|
|
20
|
-
import type { RelayMetadata
|
|
19
|
+
import type { RelayMetadata } from './swappers/RelaySwapper/utils/types.js';
|
|
21
20
|
import type { StonfiMetadata, StonfiTransactionData } from './swappers/StonfiSwapper/types.js';
|
|
22
|
-
import type { SunioTransactionData } from './swappers/SunioSwapper/types.js';
|
|
23
21
|
import type { makeSwapperAxiosServiceMonadic } from './utils/index.js';
|
|
24
22
|
import type { MayachainMetadata, ThorchainMetadata } from './utils/thorchain/types.js';
|
|
25
23
|
export type SwapperConfig = {
|
|
@@ -323,8 +321,9 @@ export type TxBuildData = {
|
|
|
323
321
|
} | {
|
|
324
322
|
type: 'tron';
|
|
325
323
|
to: string;
|
|
326
|
-
data: string;
|
|
327
324
|
value: string;
|
|
325
|
+
data?: string;
|
|
326
|
+
memo?: string;
|
|
328
327
|
} | {
|
|
329
328
|
type: 'cowswap';
|
|
330
329
|
chainId: ChainId;
|
|
@@ -344,9 +343,6 @@ export type TradeStepCommon = {
|
|
|
344
343
|
estimatedExecutionTimeMs: number | undefined;
|
|
345
344
|
swapperMetadata?: SwapperMetadata;
|
|
346
345
|
stonfiTransactionData?: StonfiTransactionData;
|
|
347
|
-
sunioTransactionData?: SunioTransactionData;
|
|
348
|
-
relayTransactionMetadata?: RelayTransactionMetadata;
|
|
349
|
-
butterSwapTransactionMetadata?: ButterSwapTransactionMetadata;
|
|
350
346
|
chainflipSpecific?: {
|
|
351
347
|
depositAddress?: string;
|
|
352
348
|
};
|
|
@@ -477,6 +473,11 @@ export type EvmMessageExecutionProps = {
|
|
|
477
473
|
};
|
|
478
474
|
export type UtxoTransactionExecutionProps = {
|
|
479
475
|
signAndBroadcastTransaction: (txToSign: SignTx<UtxoChainId>) => Promise<string>;
|
|
476
|
+
signTransaction?: (txToSign: SignTx<UtxoChainId>) => Promise<string>;
|
|
477
|
+
};
|
|
478
|
+
export type UtxoTransactionExecutionContext = {
|
|
479
|
+
config: SwapperConfig;
|
|
480
|
+
swapperMetadata: SwapperMetadata | undefined;
|
|
480
481
|
};
|
|
481
482
|
export type CosmosSdkTransactionExecutionProps = {
|
|
482
483
|
signAndBroadcastTransaction: (txToSign: SignTx<CosmosSdkChainId>) => Promise<string>;
|
|
@@ -587,7 +588,7 @@ export type Swapper = {
|
|
|
587
588
|
supportsExternalPayment?: boolean;
|
|
588
589
|
executeEvmTransaction?: (txToSign: SignTx<EvmChainId>, callbacks: EvmTransactionExecutionProps) => Promise<string>;
|
|
589
590
|
executeEvmMessage?: (txMetaToSign: EvmMessageToSign, callbacks: EvmMessageExecutionProps, config: SwapperConfig) => Promise<string>;
|
|
590
|
-
executeUtxoTransaction?: (txToSign: SignTx<UtxoChainId>, callbacks: UtxoTransactionExecutionProps) => Promise<string>;
|
|
591
|
+
executeUtxoTransaction?: (txToSign: SignTx<UtxoChainId>, callbacks: UtxoTransactionExecutionProps, context?: UtxoTransactionExecutionContext) => Promise<string>;
|
|
591
592
|
executeCosmosSdkTransaction?: (txToSign: SignTx<CosmosSdkChainId>, callbacks: CosmosSdkTransactionExecutionProps) => Promise<string>;
|
|
592
593
|
executeSolanaTransaction?: (txToSign: SolanaSignTx, callbacks: SolanaTransactionExecutionProps) => Promise<string>;
|
|
593
594
|
executeSolanaMessage?: (messageData: SolanaMessageToSign, callbacks: SolanaMessageExecutionProps, config: SwapperConfig) => Promise<string>;
|
|
@@ -2,7 +2,6 @@ import { CHAIN_NAMESPACE, cosmosAssetId, fromAssetId, fromChainId, mayachainAsse
|
|
|
2
2
|
import { THOR_ROUTER_CONTRACT_MAINNET, TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET, } from '@shapeshiftoss/contracts';
|
|
3
3
|
import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
5
|
-
import { TronWeb } from 'tronweb';
|
|
6
5
|
import { getAddress, zeroAddress } from 'viem';
|
|
7
6
|
import { TradeQuoteError } from '../../types.js';
|
|
8
7
|
import { makeNetworkFeeEstimationFailedErr, makeSwapErrorRight } from '../../utils/index.js';
|
|
@@ -269,58 +268,42 @@ export async function getThorStepData({ type, input, from, deps, swapperName, tr
|
|
|
269
268
|
}
|
|
270
269
|
case CHAIN_NAMESPACE.Tron: {
|
|
271
270
|
const { vault } = await getThorTxData({ sellAsset, config, swapperName });
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const bandwidthPrice = params.find(p => p.key === 'getTransactionFee')?.value ?? 1000;
|
|
288
|
-
const energyPrice = params.find(p => p.key === 'getEnergyFee')?.value ?? 100;
|
|
289
|
-
if (contractAddress) {
|
|
290
|
-
// TRC20: Estimate energy with actual recipient
|
|
291
|
-
try {
|
|
292
|
-
const result = await tronWeb.transactionBuilder.triggerConstantContract(contractAddress, 'transfer(address,uint256)', {}, [
|
|
293
|
-
{ type: 'address', value: vault },
|
|
294
|
-
{ type: 'uint256', value: sellAmountCryptoBaseUnit },
|
|
295
|
-
], input.receiveAddress);
|
|
296
|
-
const energyUsed = result.energy_used ?? 65000;
|
|
297
|
-
const energyFee = energyUsed * energyPrice * 1.5; // 1.5x safety margin
|
|
298
|
-
const bandwidthFee = 276 * bandwidthPrice; // TRC20 bandwidth
|
|
299
|
-
return String(Math.ceil(energyFee + bandwidthFee));
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
// Fallback: Conservative estimate
|
|
303
|
-
return String(13_000_000); // 13 TRX worst case
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// TRX transfer bandwidth: Base tx + memo bytes
|
|
307
|
-
const baseBytes = 198;
|
|
308
|
-
const memoBytes = rawMemo ? Buffer.from(rawMemo, 'utf8').length : 0;
|
|
309
|
-
const totalBandwidth = baseBytes + memoBytes;
|
|
310
|
-
return String(totalBandwidth * bandwidthPrice);
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
// Leave as undefined if estimation fails
|
|
314
|
-
return undefined;
|
|
315
|
-
}
|
|
316
|
-
})();
|
|
271
|
+
const adapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
272
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
273
|
+
const estimate = async (txMemo) => {
|
|
274
|
+
const { fast } = await adapter.getFeeData({
|
|
275
|
+
to: vault,
|
|
276
|
+
value: sellAmountCryptoBaseUnit,
|
|
277
|
+
chainSpecific: {
|
|
278
|
+
from,
|
|
279
|
+
contractAddress,
|
|
280
|
+
memo: txMemo,
|
|
281
|
+
requireEnergyShare: type === 'quote',
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
return fast.txFee;
|
|
285
|
+
};
|
|
317
286
|
if (type === 'rate') {
|
|
287
|
+
// Rates size the memo with the raw thornode memo (processed memo is '' for rates)
|
|
288
|
+
const networkFeeCryptoBaseUnit = await (async () => {
|
|
289
|
+
try {
|
|
290
|
+
return await estimate(rawMemo);
|
|
291
|
+
}
|
|
292
|
+
catch { }
|
|
293
|
+
})();
|
|
318
294
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
319
295
|
return Ok(stepData);
|
|
320
296
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
297
|
+
try {
|
|
298
|
+
const stepData = {
|
|
299
|
+
transactionData: { type: 'tron', to: vault, value: sellAmountCryptoBaseUnit, memo },
|
|
300
|
+
networkFeeCryptoBaseUnit: await estimate(memo),
|
|
301
|
+
};
|
|
302
|
+
return Ok(stepData);
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
return Err(makeNetworkFeeEstimationFailedErr('getThorStepData', error));
|
|
306
|
+
}
|
|
324
307
|
}
|
|
325
308
|
default:
|
|
326
309
|
return Err(makeSwapErrorRight({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|