@shapeshiftoss/swapper 20.1.1 → 20.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/cjs/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/cjs/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/cjs/swappers/BobGatewaySwapper/BobGatewaySwapper.js +10 -1
- package/dist/cjs/swappers/BobGatewaySwapper/endpoints.js +2 -33
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/cjs/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/constants.js +8 -5
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +30 -34
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +117 -0
- package/dist/cjs/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/cjs/swappers/BobGatewaySwapper/utils/helpers.js +36 -31
- package/dist/cjs/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/cjs/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +0 -51
- package/dist/cjs/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/cjs/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/cjs/swappers/ButterSwap/utils/constants.js +4 -1
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/cjs/swappers/ButterSwap/utils/getButterSwapStepData.test.js +115 -73
- package/dist/cjs/swappers/ButterSwap/utils/helpers.js +1 -4
- package/dist/cjs/swappers/ButterSwap/xhr.js +3 -3
- package/dist/cjs/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/cjs/swappers/ChainflipSwapper/utils/getChainflipStepData.js +31 -12
- package/dist/cjs/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/cjs/swappers/NearIntentsSwapper/constants.js +3 -1
- package/dist/cjs/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/constant.js +3 -2
- package/dist/cjs/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayAssetAddress.js +2 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayStepData.test.js +139 -0
- package/dist/cjs/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/cjs/swappers/SunioSwapper/endpoints.js +3 -63
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/cjs/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/cjs/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapContractCall.js +33 -30
- package/dist/cjs/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/cjs/swappers/SunioSwapper/utils/constants.js +5 -9
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.js +54 -20
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioStepData.test.js +177 -0
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTradeContext.js +3 -2
- package/dist/cjs/swappers/SunioSwapper/utils/helpers.js +2 -1
- package/dist/cjs/swappers/ThorchainSwapper/endpoints.js +3 -4
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/cjs/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +31 -0
- package/dist/cjs/types.d.ts +9 -8
- package/dist/cjs/utils/helpers.js +3 -0
- package/dist/cjs/utils/helpers.test.js +3 -0
- package/dist/cjs/utils/thorchain/getThorStepData.js +32 -49
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/cjs/utils/thorchain/getThorStepData.tron.test.js +93 -0
- package/dist/cjs/utils/thorchain/index.d.ts +0 -1
- package/dist/cjs/utils/thorchain/index.js +1 -14
- package/dist/cjs/utils/tron/constants.d.ts +1 -0
- package/dist/cjs/utils/tron/constants.js +5 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +64 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +157 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/cjs/utils/tron/getUnsignedTronTransaction.test.js +76 -0
- package/dist/cjs/utils/tron/index.d.ts +2 -0
- package/dist/cjs/utils/tron/index.js +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.d.ts +1 -2
- package/dist/esm/swappers/BebopSwapper/utils/fetchFromBebop.js +4 -7
- package/dist/esm/swappers/BebopSwapper/utils/getBebopSolanaTradeContext.js +0 -1
- package/dist/esm/swappers/BobGatewaySwapper/BobGatewaySwapper.js +11 -2
- package/dist/esm/swappers/BobGatewaySwapper/endpoints.js +5 -36
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeQuote.js +5 -8
- package/dist/esm/swappers/BobGatewaySwapper/swapperApi/getTradeRate.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/types.d.ts +3 -3
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.d.ts +3 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/constants.js +8 -7
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.d.ts +2 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.js +21 -25
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayStepData.test.js +115 -0
- package/dist/esm/swappers/BobGatewaySwapper/utils/getBobGatewayTradeContext.js +1 -2
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.d.ts +8 -11
- package/dist/esm/swappers/BobGatewaySwapper/utils/helpers.js +13 -30
- package/dist/esm/swappers/ButterSwap/ButterSwap.js +0 -3
- package/dist/esm/swappers/ButterSwap/endpoints.js +0 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.js +2 -3
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +1 -49
- package/dist/esm/swappers/ButterSwap/types.d.ts +3 -14
- package/dist/esm/swappers/ButterSwap/utils/constants.d.ts +2 -0
- package/dist/esm/swappers/ButterSwap/utils/constants.js +3 -0
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.d.ts +2 -3
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.js +42 -65
- package/dist/esm/swappers/ButterSwap/utils/getButterSwapStepData.test.js +116 -74
- package/dist/esm/swappers/ButterSwap/utils/helpers.js +2 -5
- package/dist/esm/swappers/ButterSwap/xhr.js +3 -3
- package/dist/esm/swappers/ChainflipSwapper/endpoints.js +3 -19
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.d.ts +1 -1
- package/dist/esm/swappers/ChainflipSwapper/utils/getChainflipStepData.js +32 -13
- package/dist/esm/swappers/NearIntentsSwapper/constants.d.ts +1 -0
- package/dist/esm/swappers/NearIntentsSwapper/constants.js +2 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/getNearIntentsStepData.js +10 -5
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers.js +2 -2
- package/dist/esm/swappers/RelaySwapper/constant.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/constant.js +2 -1
- package/dist/esm/swappers/RelaySwapper/getTradeQuote/getTradeQuote.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayAssetAddress.js +3 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.d.ts +2 -3
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.js +46 -13
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.d.ts +1 -0
- package/dist/esm/swappers/RelaySwapper/utils/getRelayStepData.test.js +137 -0
- package/dist/esm/swappers/RelaySwapper/utils/helpers.js +1 -2
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +3 -3
- package/dist/esm/swappers/RelaySwapper/utils/types.d.ts +1 -4
- package/dist/esm/swappers/SunioSwapper/endpoints.js +5 -65
- package/dist/esm/swappers/SunioSwapper/getSunioTradeQuote/getSunioTradeQuote.js +3 -4
- package/dist/esm/swappers/SunioSwapper/getSunioTradeRate/getSunioTradeRate.js +7 -1
- package/dist/esm/swappers/SunioSwapper/types.d.ts +0 -3
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.d.ts +11 -6
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapContractCall.js +31 -28
- package/dist/esm/swappers/SunioSwapper/utils/constants.d.ts +3 -3
- package/dist/esm/swappers/SunioSwapper/utils/constants.js +4 -8
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.d.ts +8 -3
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.js +52 -18
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.d.ts +1 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioStepData.test.js +175 -0
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTradeContext.js +2 -1
- package/dist/esm/swappers/SunioSwapper/utils/helpers.js +3 -2
- package/dist/esm/swappers/ThorchainSwapper/endpoints.js +4 -5
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.js +6 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/addL1ToLongtailPartsToMemo/addL1ToLongtailPartsToMemo.test.js +15 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/assertValidLongtailTrade.js +7 -0
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailQuote.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getL1ToLongtailRate.js +0 -2
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.d.ts +1 -1
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.js +17 -20
- package/dist/esm/swappers/ThorchainSwapper/utils/getUniqueAddressSubstring/getUniqueAddressSubstring.test.js +29 -1
- package/dist/esm/types.d.ts +9 -8
- package/dist/esm/utils/helpers.js +4 -1
- package/dist/esm/utils/helpers.test.js +3 -0
- package/dist/esm/utils/thorchain/getThorStepData.js +32 -49
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.d.ts +1 -0
- package/dist/esm/utils/thorchain/getThorStepData.tron.test.js +91 -0
- package/dist/esm/utils/thorchain/index.d.ts +0 -1
- package/dist/esm/utils/thorchain/index.js +0 -1
- package/dist/esm/utils/tron/constants.d.ts +1 -0
- package/dist/esm/utils/tron/constants.js +2 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.d.ts +27 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.js +59 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.d.ts +1 -0
- package/dist/esm/utils/tron/getTronNetworkFeeCryptoBaseUnit.test.js +155 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.d.ts +2 -1
- package/dist/esm/utils/tron/getUnsignedTronTransaction.js +14 -48
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.d.ts +1 -0
- package/dist/esm/utils/tron/getUnsignedTronTransaction.test.js +74 -0
- package/dist/esm/utils/tron/index.d.ts +2 -0
- package/dist/esm/utils/tron/index.js +2 -0
- package/package.json +9 -9
- package/dist/cjs/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/cjs/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -32
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/cjs/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -78
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/cjs/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -36
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/getTronTransactionFees.js +0 -68
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/cjs/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -35
- package/dist/cjs/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/cjs/utils/thorchain/tron/index.js +0 -18
- package/dist/esm/swappers/ButterSwap/test-data/eth-btc.json +0 -461
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.d.ts +0 -14
- package/dist/esm/swappers/SunioSwapper/utils/buildSwapRouteParameters.js +0 -28
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.d.ts +0 -12
- package/dist/esm/swappers/SunioSwapper/utils/estimateSunioNetworkFee.js +0 -74
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.d.ts +0 -2
- package/dist/esm/swappers/SunioSwapper/utils/getSunioTransactionFees.js +0 -32
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/getTronTransactionFees.js +0 -64
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.d.ts +0 -3
- package/dist/esm/utils/thorchain/tron/getUnsignedTronTransaction.js +0 -31
- package/dist/esm/utils/thorchain/tron/index.d.ts +0 -2
- package/dist/esm/utils/thorchain/tron/index.js +0 -2
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /package/dist/cjs/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
- /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.d.ts → fetchSunioQuote.d.ts} +0 -0
- /package/dist/esm/swappers/SunioSwapper/utils/{fetchFromSunio.js → fetchSunioQuote.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const assets_1 = require("../../../utils/test-data/assets");
|
|
6
|
+
const getRelayStepData_1 = require("./getRelayStepData");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
|
|
9
|
+
const TRX = { ...assets_1.ETH, assetId: `${caip_1.tronChainId}/slip44:195`, chainId: caip_1.tronChainId };
|
|
10
|
+
const USDT_TRON = { ...assets_1.ETH, assetId: `${caip_1.tronChainId}/trc20:${USDT}`, chainId: caip_1.tronChainId };
|
|
11
|
+
const FROM = 'TT2T17KZhoDu47i2E4FWxfG79zdkEWkU9N';
|
|
12
|
+
const DEPOSITOR_HEX = '41f0623e1012177482912fb057e44e1a9769b1f588';
|
|
13
|
+
const DEPOSITOR = 'TXtEs6t2oUWQsNos7m68gbHdE9Q5n6x2oN';
|
|
14
|
+
const tronItem = {
|
|
15
|
+
type: 'TriggerSmartContract',
|
|
16
|
+
parameter: { contract_address: DEPOSITOR_HEX, data: '49290c1c', call_value: 50000000 },
|
|
17
|
+
};
|
|
18
|
+
const tronAdapter = ({ txFee = '9000000', allowance = '0' } = {}) => ({
|
|
19
|
+
getFeeData: vitest_1.vi.fn().mockResolvedValue({ fast: { txFee } }),
|
|
20
|
+
httpProvider: {
|
|
21
|
+
getChainPrices: () => Promise.resolve({ energyPrice: 100, bandwidthPrice: 1000 }),
|
|
22
|
+
getTrc20Allowance: vitest_1.vi.fn().mockResolvedValue(allowance),
|
|
23
|
+
getTrc20Balance: vitest_1.vi.fn().mockResolvedValue('100000000'),
|
|
24
|
+
getContractEnergyShare: vitest_1.vi.fn().mockResolvedValue({
|
|
25
|
+
callerPercent: 100,
|
|
26
|
+
originEnergyLimit: 0,
|
|
27
|
+
originEnergyAvailable: 0,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const makeDeps = (tron) => ({ assertGetTronChainAdapter: () => tron });
|
|
32
|
+
const baseArgs = {
|
|
33
|
+
data: tronItem,
|
|
34
|
+
sellAsset: TRX,
|
|
35
|
+
sellAmountCryptoBaseUnit: '50000000',
|
|
36
|
+
spenderAddress: '',
|
|
37
|
+
orderId: undefined,
|
|
38
|
+
xpub: undefined,
|
|
39
|
+
fallbackNetworkFeeCryptoBaseUnit: '6100715',
|
|
40
|
+
};
|
|
41
|
+
(0, vitest_1.describe)('getRelayAllowanceContract', () => {
|
|
42
|
+
(0, vitest_1.it)('returns the tron depositor as relay gives it', () => {
|
|
43
|
+
(0, vitest_1.expect)((0, helpers_1.getRelayAllowanceContract)(tronItem)).toBe(DEPOSITOR_HEX);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.describe)('getRelayStepData', () => {
|
|
47
|
+
(0, vitest_1.describe)('tron', () => {
|
|
48
|
+
(0, vitest_1.it)('carries the depositor call as transactionData and simulates it', async () => {
|
|
49
|
+
const adapter = tronAdapter();
|
|
50
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
51
|
+
...baseArgs,
|
|
52
|
+
type: 'quote',
|
|
53
|
+
input: {},
|
|
54
|
+
from: FROM,
|
|
55
|
+
deps: makeDeps(adapter),
|
|
56
|
+
});
|
|
57
|
+
const transactionData = {
|
|
58
|
+
type: 'tron',
|
|
59
|
+
to: DEPOSITOR_HEX,
|
|
60
|
+
data: '49290c1c',
|
|
61
|
+
value: '50000000',
|
|
62
|
+
};
|
|
63
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ transactionData, networkFeeCryptoBaseUnit: '9000000' });
|
|
64
|
+
(0, vitest_1.expect)(adapter.getFeeData).toHaveBeenCalledWith({
|
|
65
|
+
to: DEPOSITOR_HEX,
|
|
66
|
+
value: '50000000',
|
|
67
|
+
chainSpecific: { from: FROM, data: '49290c1c', requireEnergyShare: true },
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.it)('fails a native quote when the simulation fails', async () => {
|
|
71
|
+
const adapter = tronAdapter();
|
|
72
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
73
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
74
|
+
...baseArgs,
|
|
75
|
+
type: 'quote',
|
|
76
|
+
input: {},
|
|
77
|
+
from: FROM,
|
|
78
|
+
deps: makeDeps(adapter),
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.expect)(actual.isErr()).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
(0, vitest_1.it)('prices the measured worst case when a token allowance is not granted yet', async () => {
|
|
83
|
+
const adapter = tronAdapter({ allowance: '0' });
|
|
84
|
+
adapter.getFeeData.mockRejectedValue(new Error('REVERT opcode executed'));
|
|
85
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
86
|
+
...baseArgs,
|
|
87
|
+
data: { type: 'TriggerSmartContract', parameter: { ...tronItem.parameter, call_value: 0 } },
|
|
88
|
+
sellAsset: USDT_TRON,
|
|
89
|
+
type: 'quote',
|
|
90
|
+
input: {},
|
|
91
|
+
from: FROM,
|
|
92
|
+
deps: makeDeps(adapter),
|
|
93
|
+
});
|
|
94
|
+
// 100000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
95
|
+
(0, vitest_1.expect)(actual.unwrap().networkFeeCryptoBaseUnit).toBe('12283000');
|
|
96
|
+
(0, vitest_1.expect)(adapter.httpProvider.getTrc20Allowance).toHaveBeenCalledWith({
|
|
97
|
+
contractAddress: USDT,
|
|
98
|
+
owner: FROM,
|
|
99
|
+
spender: DEPOSITOR,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)('prices a rate from the measured deposit', async () => {
|
|
103
|
+
const adapter = tronAdapter();
|
|
104
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
105
|
+
...baseArgs,
|
|
106
|
+
type: 'rate',
|
|
107
|
+
input: {},
|
|
108
|
+
from: FROM,
|
|
109
|
+
deps: makeDeps(adapter),
|
|
110
|
+
});
|
|
111
|
+
// 100000 energy * 1.2 margin * 100 sun + (4 calldata + 279 envelope) bytes * 1000 sun
|
|
112
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '12283000' });
|
|
113
|
+
(0, vitest_1.expect)(adapter.httpProvider.getContractEnergyShare).toHaveBeenCalledWith(DEPOSITOR);
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.it)('falls back to the relay fee when the measured deposit cannot be priced', async () => {
|
|
116
|
+
const adapter = tronAdapter();
|
|
117
|
+
adapter.httpProvider.getChainPrices = () => Promise.reject(new Error('429'));
|
|
118
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
119
|
+
...baseArgs,
|
|
120
|
+
type: 'rate',
|
|
121
|
+
input: {},
|
|
122
|
+
from: FROM,
|
|
123
|
+
deps: makeDeps(adapter),
|
|
124
|
+
});
|
|
125
|
+
(0, vitest_1.expect)(actual.unwrap()).toEqual({ networkFeeCryptoBaseUnit: '6100715' });
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.it)('fails to build without the depositor call', async () => {
|
|
128
|
+
const actual = await (0, getRelayStepData_1.getRelayStepData)({
|
|
129
|
+
...baseArgs,
|
|
130
|
+
data: { type: 'TriggerSmartContract', parameter: {} },
|
|
131
|
+
type: 'quote',
|
|
132
|
+
input: {},
|
|
133
|
+
from: FROM,
|
|
134
|
+
deps: makeDeps(tronAdapter()),
|
|
135
|
+
});
|
|
136
|
+
(0, vitest_1.expect)(actual.isErr()).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -56,8 +56,7 @@ const resolveRelayAddresses = ({ input, sellChainId, buyChainId, }) => {
|
|
|
56
56
|
return { sendAddress, recipient, refundTo };
|
|
57
57
|
};
|
|
58
58
|
exports.resolveRelayAddresses = resolveRelayAddresses;
|
|
59
|
-
// The spender to approve
|
|
60
|
-
// UTXO/Solana need no allowance. Derived from the provider route, not the built transactionData.
|
|
59
|
+
// The spender to approve is the call target: EVM data.to, tron the depositor; UTXO/Solana need none
|
|
61
60
|
const getRelayAllowanceContract = (data) => {
|
|
62
61
|
if (!data)
|
|
63
62
|
return '';
|
|
@@ -18,7 +18,7 @@ const relayTokenToAssetId = (relayToken) => {
|
|
|
18
18
|
return relayToken.address === constant_1.RELAY_SOLANA_TOKEN_ADDRESS;
|
|
19
19
|
}
|
|
20
20
|
if (chainId === caip_1.tronChainId) {
|
|
21
|
-
return relayToken.address ===
|
|
21
|
+
return relayToken.address === chain_adapters_1.tron.TRON_ZERO_ADDRESS;
|
|
22
22
|
}
|
|
23
23
|
return false;
|
|
24
24
|
})();
|
|
@@ -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 = {
|
|
@@ -2,77 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sunioApi = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
-
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
5
|
const unchained_client_1 = require("@shapeshiftoss/unchained-client");
|
|
7
|
-
const tronweb_1 = require("tronweb");
|
|
8
6
|
const utils_1 = require("../../utils");
|
|
7
|
+
const tron_1 = require("../../utils/tron");
|
|
9
8
|
const getSunioTradeQuote_1 = require("./getSunioTradeQuote/getSunioTradeQuote");
|
|
10
9
|
const getSunioTradeRate_1 = require("./getSunioTradeRate/getSunioTradeRate");
|
|
11
|
-
const buildSwapContractCall_1 = require("./utils/buildSwapContractCall");
|
|
12
|
-
const buildSwapRouteParameters_1 = require("./utils/buildSwapRouteParameters");
|
|
13
|
-
const constants_1 = require("./utils/constants");
|
|
14
|
-
const getSunioTransactionFees_1 = require("./utils/getSunioTransactionFees");
|
|
15
10
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
16
11
|
exports.sunioApi = {
|
|
17
12
|
getTradeQuote: (input, deps) => (0, getSunioTradeQuote_1.getSunioTradeQuote)(input, deps),
|
|
18
13
|
getTradeRate: (input, deps) => (0, getSunioTradeRate_1.getSunioTradeRate)(input, deps),
|
|
19
|
-
getUnsignedTronTransaction:
|
|
20
|
-
|
|
21
|
-
if (!(0, utils_1.isExecutableTradeQuote)(tradeQuote)) {
|
|
22
|
-
throw new Error('Unable to execute a trade rate quote');
|
|
23
|
-
}
|
|
24
|
-
const step = (0, utils_1.getExecutableTradeStep)(tradeQuote, stepIndex);
|
|
25
|
-
const adapter = assertGetTronChainAdapter(caip_1.tronChainId);
|
|
26
|
-
const sunioTransactionData = step.sunioTransactionData;
|
|
27
|
-
if (!sunioTransactionData)
|
|
28
|
-
throw new Error('[Sun.io] Missing transaction data in quote');
|
|
29
|
-
const rpcUrl = adapter.httpProvider.getRpcUrl();
|
|
30
|
-
const tronWeb = new tronweb_1.TronWeb({
|
|
31
|
-
fullHost: rpcUrl,
|
|
32
|
-
headers: config.VITE_TRON_GRID_API_KEY
|
|
33
|
-
? { 'TRON-PRO-API-KEY': config.VITE_TRON_GRID_API_KEY }
|
|
34
|
-
: {},
|
|
35
|
-
});
|
|
36
|
-
const routeParams = (0, buildSwapRouteParameters_1.buildSwapRouteParameters)(sunioTransactionData.route, step.sellAmountIncludingProtocolFeesCryptoBaseUnit, step.buyAmountAfterFeesCryptoBaseUnit, tradeQuote.receiveAddress, slippageTolerancePercentageDecimal);
|
|
37
|
-
const parameters = (0, buildSwapContractCall_1.buildSwapExactInputParameters)(routeParams);
|
|
38
|
-
const isSellingNativeTrx = step.sellAsset.assetId === caip_1.tronAssetId;
|
|
39
|
-
const callValue = isSellingNativeTrx
|
|
40
|
-
? Number(step.sellAmountIncludingProtocolFeesCryptoBaseUnit)
|
|
41
|
-
: 0;
|
|
42
|
-
const options = {
|
|
43
|
-
feeLimit: 100_000_000,
|
|
44
|
-
callValue,
|
|
45
|
-
};
|
|
46
|
-
const txData = await tronWeb.transactionBuilder.triggerSmartContract(constants_1.SUNIO_SMART_ROUTER_CONTRACT, buildSwapContractCall_1.SUNIO_SWAP_EXACT_INPUT_SELECTOR, options, parameters, from);
|
|
47
|
-
if (!txData.result || !txData.result.result) {
|
|
48
|
-
throw new Error('[Sun.io] Failed to build swap transaction');
|
|
49
|
-
}
|
|
50
|
-
const transaction = txData.transaction;
|
|
51
|
-
const rawDataHex = typeof transaction.raw_data_hex === 'string'
|
|
52
|
-
? transaction.raw_data_hex
|
|
53
|
-
: Buffer.isBuffer(transaction.raw_data_hex)
|
|
54
|
-
? transaction.raw_data_hex.toString('hex')
|
|
55
|
-
: Array.isArray(transaction.raw_data_hex)
|
|
56
|
-
? Buffer.from(transaction.raw_data_hex).toString('hex')
|
|
57
|
-
: (() => {
|
|
58
|
-
throw new Error(`Unexpected raw_data_hex type: ${typeof transaction.raw_data_hex}`);
|
|
59
|
-
})();
|
|
60
|
-
if (!/^[0-9a-fA-F]+$/.test(rawDataHex)) {
|
|
61
|
-
throw new Error(`Invalid raw_data_hex format: ${rawDataHex.slice(0, 100)}`);
|
|
62
|
-
}
|
|
63
|
-
const accountNumber = step.accountNumber;
|
|
64
|
-
if (accountNumber === undefined) {
|
|
65
|
-
throw new Error('[Sun.io] accountNumber is required for execution');
|
|
66
|
-
}
|
|
67
|
-
const bip44Params = adapter.getBip44Params({ accountNumber });
|
|
68
|
-
const addressNList = (0, chain_adapters_1.toAddressNList)(bip44Params);
|
|
69
|
-
return {
|
|
70
|
-
addressNList,
|
|
71
|
-
rawDataHex,
|
|
72
|
-
transaction,
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
getTronTransactionFees: getSunioTransactionFees_1.getSunioTransactionFees,
|
|
14
|
+
getUnsignedTronTransaction: tron_1.getUnsignedTronTransaction,
|
|
15
|
+
getTronTransactionFees: tron_1.getTronTransactionFees,
|
|
76
16
|
checkTradeStatus: async ({ txHash, assertGetTronChainAdapter }) => {
|
|
77
17
|
try {
|
|
78
18
|
// Wait for TronGrid indexing to avoid false "REVERT"
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSunioTradeQuote = void 0;
|
|
4
4
|
const monads_1 = require("@sniptt/monads");
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
|
-
const helpers_1 = require("../../../utils/helpers");
|
|
7
6
|
const getSunioStepData_1 = require("../utils/getSunioStepData");
|
|
8
7
|
const getSunioTradeContext_1 = require("../utils/getSunioTradeContext");
|
|
9
8
|
const getSunioTradeQuote = async (input, deps) => {
|
|
@@ -24,17 +23,17 @@ const getSunioTradeQuote = async (input, deps) => {
|
|
|
24
23
|
});
|
|
25
24
|
if (maybeStepData.isErr())
|
|
26
25
|
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
27
|
-
const { networkFeeCryptoBaseUnit,
|
|
26
|
+
const { networkFeeCryptoBaseUnit, transactionData, deadline } = maybeStepData.unwrap();
|
|
28
27
|
const tradeQuote = {
|
|
29
28
|
...tradeCommon,
|
|
30
29
|
quoteOrRate: 'quote',
|
|
31
|
-
deadline
|
|
30
|
+
deadline,
|
|
32
31
|
receiveAddress,
|
|
33
32
|
steps: [
|
|
34
33
|
{
|
|
35
34
|
...stepCommon,
|
|
36
35
|
accountNumber,
|
|
37
|
-
|
|
36
|
+
transactionData,
|
|
38
37
|
feeData: { networkFeeCryptoBaseUnit, protocolFees },
|
|
39
38
|
},
|
|
40
39
|
],
|
|
@@ -10,7 +10,13 @@ const getSunioTradeRate = async (input, deps) => {
|
|
|
10
10
|
if (maybeContext.isErr())
|
|
11
11
|
return (0, monads_1.Err)(maybeContext.unwrapErr());
|
|
12
12
|
const { tradeCommon, stepCommon, protocolFees, stepDataArgs } = maybeContext.unwrap();
|
|
13
|
-
|
|
13
|
+
// Sun.io is tron-only, so the receive address is also the seller's account to simulate from
|
|
14
|
+
const maybeStepData = await (0, getSunioStepData_1.getSunioStepData)({
|
|
15
|
+
...stepDataArgs,
|
|
16
|
+
type: 'rate',
|
|
17
|
+
input,
|
|
18
|
+
from: input.sendAddress ?? receiveAddress,
|
|
19
|
+
});
|
|
14
20
|
if (maybeStepData.isErr())
|
|
15
21
|
return (0, monads_1.Err)(maybeStepData.unwrapErr());
|
|
16
22
|
const { networkFeeCryptoBaseUnit } = maybeStepData.unwrap();
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { SunioRoute } from '../types';
|
|
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,33 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
exports.buildSunioSwapCalldata = void 0;
|
|
4
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
5
|
+
const utils_1 = require("@shapeshiftoss/utils");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const SUNIO_SWAP_EXACT_INPUT_ABI = (0, viem_1.parseAbiItem)('function swapExactInput(address[], string[], uint256[], uint24[], (uint256,uint256,address,uint256))');
|
|
8
|
+
// SmartExchangeRouter swapExactInput calldata - the TVM ABI is EVM-compatible, addresses as 20-byte bodies
|
|
9
|
+
const buildSunioSwapCalldata = ({ route, sellAmountCryptoBaseUnit, minBuyAmountCryptoBaseUnit, recipient, slippageTolerancePercentageDecimal, deadline, }) => {
|
|
10
|
+
const amountOutMin = (0, utils_1.bn)(minBuyAmountCryptoBaseUnit)
|
|
11
|
+
.times((0, utils_1.bn)(1).minus(slippageTolerancePercentageDecimal))
|
|
12
|
+
.toFixed(0);
|
|
13
|
+
// The SmartExchangeRouter expects sum(versionLen) === path.length: the first pool segment consumes
|
|
14
|
+
// 2 tokens (input + output) and each subsequent pool reuses the previous output, consuming 1 new
|
|
15
|
+
// token. Relies on the Sun.io API returning poolVersions per-hop (poolVersions.length ===
|
|
16
|
+
// tokens.length - 1), which it does.
|
|
17
|
+
const versionLen = route.poolVersions.map((_, index) => (index === 0 ? 2n : 1n));
|
|
18
|
+
const swapData = [
|
|
19
|
+
BigInt(sellAmountCryptoBaseUnit),
|
|
20
|
+
BigInt(amountOutMin),
|
|
21
|
+
chain_adapters_1.tron.toTronHex(recipient),
|
|
22
|
+
BigInt(Math.floor(deadline / 1000)),
|
|
23
|
+
];
|
|
24
|
+
return (0, viem_1.encodeFunctionData)({
|
|
25
|
+
abi: [SUNIO_SWAP_EXACT_INPUT_ABI],
|
|
26
|
+
functionName: 'swapExactInput',
|
|
27
|
+
args: [
|
|
28
|
+
route.tokens.map(chain_adapters_1.tron.toTronHex),
|
|
29
|
+
route.poolVersions,
|
|
30
|
+
versionLen,
|
|
31
|
+
route.poolFees.map(Number),
|
|
32
|
+
swapData,
|
|
33
|
+
],
|
|
34
|
+
});
|
|
15
35
|
};
|
|
16
|
-
|
|
17
|
-
// estimation and execution so both encode the call identically.
|
|
18
|
-
const buildSwapExactInputParameters = (routeParams) => [
|
|
19
|
-
{ type: 'address[]', value: routeParams.path },
|
|
20
|
-
{ type: 'string[]', value: routeParams.poolVersion },
|
|
21
|
-
{ type: 'uint256[]', value: routeParams.versionLen },
|
|
22
|
-
{ type: 'uint24[]', value: routeParams.fees },
|
|
23
|
-
{
|
|
24
|
-
type: 'tuple(uint256,uint256,address,uint256)',
|
|
25
|
-
value: convertAddressesToEvmFormat([
|
|
26
|
-
routeParams.swapData.amountIn,
|
|
27
|
-
routeParams.swapData.amountOutMin,
|
|
28
|
-
routeParams.swapData.recipient,
|
|
29
|
-
routeParams.swapData.deadline,
|
|
30
|
-
]),
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
exports.buildSwapExactInputParameters = buildSwapExactInputParameters;
|
|
36
|
+
exports.buildSunioSwapCalldata = buildSunioSwapCalldata;
|
|
@@ -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";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SUNIO_DEX_TYPES = exports.SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = exports.SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = exports.SUNIO_SWAP_DEADLINE_MS = exports.DEFAULT_SLIPPAGE_PERCENTAGE = exports.SUNIO_SMART_ROUTER_CONTRACT = exports.SUNIO_API_BASE_URL = exports.SUNIO_SUPPORTED_CHAIN_IDS = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
exports.SUNIO_SUPPORTED_CHAIN_IDS = [caip_1.tronChainId];
|
|
6
6
|
// NOTE: This domain looks suspicious, but it's the official Sun.io backend API
|
|
@@ -11,12 +11,8 @@ exports.SUNIO_API_BASE_URL = 'https://rot.endjgfsv.link';
|
|
|
11
11
|
// This is the current mainnet router that sun.io's frontend uses
|
|
12
12
|
exports.SUNIO_SMART_ROUTER_CONTRACT = 'TCFNp179Lg46D16zKoumd4Poa2WFFdtqYj';
|
|
13
13
|
exports.DEFAULT_SLIPPAGE_PERCENTAGE = '0.005';
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
exports.SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = 215_000;
|
|
19
|
-
exports.SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = 375_000;
|
|
14
|
+
exports.SUNIO_SWAP_DEADLINE_MS = 20 * 60 * 1000;
|
|
15
|
+
// p90 router energy on mainnet, for rates that can't simulate and token quotes without their allowance
|
|
16
|
+
exports.SUNIO_FALLBACK_SWAP_ENERGY_NATIVE = '250000';
|
|
17
|
+
exports.SUNIO_FALLBACK_SWAP_ENERGY_TRC20 = '480000';
|
|
20
18
|
exports.SUNIO_DEX_TYPES = 'PSM,CURVE,CURVE_COMBINATION,WTRX,SUNSWAP_V1,SUNSWAP_V2,SUNSWAP_V3';
|
|
21
|
-
// Native TRX token address (used when assetId is not a TRC-20 token)
|
|
22
|
-
exports.SUNIO_TRON_NATIVE_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { Result } from '@sniptt/monads';
|
|
2
|
-
import type { StepDataArgs, SwapErrorRight } from '../../../types';
|
|
3
|
-
import type { SunioRoute
|
|
2
|
+
import type { StepDataArgs, SwapErrorRight, TxBuildData } from '../../../types';
|
|
3
|
+
import type { SunioRoute } from '../types';
|
|
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,43 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSunioStepData = void 0;
|
|
4
|
-
const
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
5
6
|
const monads_1 = require("@sniptt/monads");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
8
|
+
const tron_1 = require("../../../utils/tron");
|
|
9
|
+
const buildSwapContractCall_1 = require("./buildSwapContractCall");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
8
11
|
async function getSunioStepData(args) {
|
|
9
|
-
const { type, route, sellAsset, sellAmountCryptoBaseUnit, from, input
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const { type, route, sellAsset, sellAmountCryptoBaseUnit, buyAmountCryptoBaseUnit, from, input } = args;
|
|
13
|
+
const adapter = args.deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
14
|
+
const isNativeSell = sellAsset.assetId === caip_1.tronAssetId;
|
|
15
|
+
const fallbackEnergy = isNativeSell
|
|
16
|
+
? constants_1.SUNIO_FALLBACK_SWAP_ENERGY_NATIVE
|
|
17
|
+
: constants_1.SUNIO_FALLBACK_SWAP_ENERGY_TRC20;
|
|
18
|
+
// The router reverts past this, so the quote expires with it
|
|
19
|
+
const deadline = Date.now() + constants_1.SUNIO_SWAP_DEADLINE_MS;
|
|
20
|
+
const buildCall = (recipient) => ({
|
|
21
|
+
to: constants_1.SUNIO_SMART_ROUTER_CONTRACT,
|
|
22
|
+
value: isNativeSell ? sellAmountCryptoBaseUnit : '0',
|
|
23
|
+
data: (0, buildSwapContractCall_1.buildSunioSwapCalldata)({
|
|
24
|
+
route,
|
|
25
|
+
sellAmountCryptoBaseUnit,
|
|
26
|
+
minBuyAmountCryptoBaseUnit: buyAmountCryptoBaseUnit,
|
|
27
|
+
recipient,
|
|
28
|
+
slippageTolerancePercentageDecimal: input.slippageTolerancePercentageDecimal ?? constants_1.DEFAULT_SLIPPAGE_PERCENTAGE,
|
|
29
|
+
deadline,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
19
32
|
if (type === 'rate') {
|
|
20
33
|
const networkFeeCryptoBaseUnit = await (async () => {
|
|
21
34
|
try {
|
|
22
|
-
|
|
35
|
+
if (from) {
|
|
36
|
+
const { to, value, data } = buildCall(from);
|
|
37
|
+
const { fast } = await adapter.getFeeData({ to, value, chainSpecific: { from, data } });
|
|
38
|
+
return fast.txFee;
|
|
39
|
+
}
|
|
23
40
|
}
|
|
24
|
-
catch {
|
|
25
|
-
|
|
41
|
+
catch { }
|
|
42
|
+
try {
|
|
43
|
+
return await (0, tron_1.getTronContractCallFallbackFeeCryptoBaseUnit)({
|
|
44
|
+
adapter,
|
|
45
|
+
energy: fallbackEnergy,
|
|
46
|
+
bandwidthBytes: chain_adapters_1.tron.getTronContractCallBandwidthBytes(buildCall(from ?? tron_1.TRON_PLACEHOLDER_ADDRESS).data),
|
|
47
|
+
contractAddress: constants_1.SUNIO_SMART_ROUTER_CONTRACT,
|
|
48
|
+
fullEnergyOnShareLookupFailure: true,
|
|
49
|
+
});
|
|
26
50
|
}
|
|
51
|
+
catch { }
|
|
27
52
|
})();
|
|
28
53
|
const stepData = { networkFeeCryptoBaseUnit };
|
|
29
54
|
return (0, monads_1.Ok)(stepData);
|
|
30
55
|
}
|
|
56
|
+
const call = buildCall(input.receiveAddress);
|
|
31
57
|
try {
|
|
32
|
-
const networkFeeCryptoBaseUnit = await (0, estimateSunioNetworkFee_1.estimateSunioNetworkFeeCryptoBaseUnit)(estimateArgs);
|
|
33
58
|
const stepData = {
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
transactionData: { type: 'tron', ...call },
|
|
60
|
+
networkFeeCryptoBaseUnit: await (0, tron_1.getTronContractCallNetworkFeeCryptoBaseUnit)({
|
|
61
|
+
adapter,
|
|
62
|
+
transactionData: call,
|
|
63
|
+
from,
|
|
64
|
+
sellAsset,
|
|
65
|
+
sellAmountCryptoBaseUnit,
|
|
66
|
+
spenderAddress: constants_1.SUNIO_SMART_ROUTER_CONTRACT,
|
|
67
|
+
fallbackEnergy,
|
|
68
|
+
}),
|
|
69
|
+
deadline,
|
|
36
70
|
};
|
|
37
71
|
return (0, monads_1.Ok)(stepData);
|
|
38
72
|
}
|
|
39
73
|
catch (error) {
|
|
40
|
-
return (0, monads_1.Err)((0,
|
|
74
|
+
return (0, monads_1.Err)((0, utils_1.makeNetworkFeeEstimationFailedErr)('getSunioStepData', error));
|
|
41
75
|
}
|
|
42
76
|
}
|
|
43
77
|
exports.getSunioStepData = getSunioStepData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|