@shapeshiftoss/swapper 17.6.6-alpha.1 → 17.6.7
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/constants.js +27 -18
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/cjs/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/cjs/swappers/CetusSwapper/CetusSwapper.d.ts +2 -0
- package/dist/cjs/swappers/CetusSwapper/CetusSwapper.js +7 -0
- package/dist/cjs/swappers/CetusSwapper/endpoints.d.ts +2 -0
- package/dist/cjs/swappers/CetusSwapper/endpoints.js +87 -0
- package/dist/cjs/swappers/CetusSwapper/index.d.ts +1 -0
- package/dist/cjs/swappers/CetusSwapper/index.js +17 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeQuote.js +122 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/cjs/swappers/CetusSwapper/swapperApi/getTradeRate.js +110 -0
- package/dist/cjs/swappers/CetusSwapper/utils/constants.d.ts +3 -0
- package/dist/cjs/swappers/CetusSwapper/utils/constants.js +9 -0
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.d.ts +13 -0
- package/dist/cjs/swappers/CetusSwapper/utils/helpers.js +118 -0
- package/dist/cjs/swappers/NearIntentsSwapper/NearIntentsSwapper.js +2 -0
- package/dist/cjs/swappers/NearIntentsSwapper/endpoints.js +43 -0
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +50 -10
- package/dist/cjs/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +65 -9
- package/dist/cjs/swappers/NearIntentsSwapper/types.d.ts +2 -2
- package/dist/cjs/swappers/NearIntentsSwapper/types.js +4 -0
- package/dist/cjs/swappers/NearIntentsSwapper/utils/helpers/helpers.js +12 -7
- package/dist/cjs/swappers/RelaySwapper/RelaySwapper.js +1 -0
- package/dist/cjs/swappers/RelaySwapper/constant.d.ts +2 -2
- package/dist/cjs/swappers/RelaySwapper/constant.js +27 -36
- package/dist/cjs/swappers/RelaySwapper/endpoints.js +4 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayAssetAddress.js +2 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.js +2 -0
- package/dist/cjs/swappers/RelaySwapper/utils/getRelayPsbtRelayer.js +1 -1
- package/dist/cjs/swappers/RelaySwapper/utils/getTrade.js +7 -2
- package/dist/cjs/swappers/RelaySwapper/utils/relayTokenToAssetId.js +15 -0
- package/dist/cjs/thorchain-utils/getL1RateOrQuote.js +12 -0
- package/dist/cjs/tron-utils/getTronTransactionFees.d.ts +2 -0
- package/dist/cjs/tron-utils/getTronTransactionFees.js +14 -0
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.d.ts +2 -0
- package/dist/cjs/tron-utils/getUnsignedTronTransaction.js +28 -0
- package/dist/cjs/types.d.ts +56 -11
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/utils.d.ts +11 -3
- package/dist/cjs/utils.js +34 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.js +9 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeQuote.test.js +2 -0
- package/dist/esm/swappers/ButterSwap/swapperApi/getTradeRate.test.js +4 -0
- package/dist/esm/swappers/CetusSwapper/CetusSwapper.d.ts +2 -0
- package/dist/esm/swappers/CetusSwapper/CetusSwapper.js +4 -0
- package/dist/esm/swappers/CetusSwapper/endpoints.d.ts +2 -0
- package/dist/esm/swappers/CetusSwapper/endpoints.js +84 -0
- package/dist/esm/swappers/CetusSwapper/index.d.ts +1 -0
- package/dist/esm/swappers/CetusSwapper/index.js +1 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.d.ts +3 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeQuote.js +118 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.d.ts +3 -0
- package/dist/esm/swappers/CetusSwapper/swapperApi/getTradeRate.js +106 -0
- package/dist/esm/swappers/CetusSwapper/utils/constants.d.ts +3 -0
- package/dist/esm/swappers/CetusSwapper/utils/constants.js +5 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.d.ts +13 -0
- package/dist/esm/swappers/CetusSwapper/utils/helpers.js +86 -0
- package/dist/esm/swappers/NearIntentsSwapper/NearIntentsSwapper.js +3 -1
- package/dist/esm/swappers/NearIntentsSwapper/endpoints.js +43 -0
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeQuote.js +51 -11
- package/dist/esm/swappers/NearIntentsSwapper/swapperApi/getTradeRate.js +66 -10
- package/dist/esm/swappers/NearIntentsSwapper/types.d.ts +2 -2
- package/dist/esm/swappers/NearIntentsSwapper/types.js +4 -0
- package/dist/esm/swappers/NearIntentsSwapper/utils/helpers/helpers.js +13 -8
- package/dist/esm/swappers/RelaySwapper/RelaySwapper.js +2 -1
- package/dist/esm/swappers/RelaySwapper/constant.d.ts +2 -2
- package/dist/esm/swappers/RelaySwapper/constant.js +6 -15
- package/dist/esm/swappers/RelaySwapper/endpoints.js +4 -0
- package/dist/esm/swappers/RelaySwapper/utils/getRelayAssetAddress.js +4 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.d.ts +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getRelayDefaultUserAddress.js +4 -2
- package/dist/esm/swappers/RelaySwapper/utils/getRelayPsbtRelayer.js +1 -1
- package/dist/esm/swappers/RelaySwapper/utils/getTrade.js +8 -3
- package/dist/esm/swappers/RelaySwapper/utils/relayTokenToAssetId.js +17 -2
- package/dist/esm/thorchain-utils/getL1RateOrQuote.js +12 -0
- package/dist/esm/tron-utils/getTronTransactionFees.d.ts +2 -0
- package/dist/esm/tron-utils/getTronTransactionFees.js +10 -0
- package/dist/esm/tron-utils/getUnsignedTronTransaction.d.ts +2 -0
- package/dist/esm/tron-utils/getUnsignedTronTransaction.js +24 -0
- package/dist/esm/types.d.ts +56 -11
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +11 -3
- package/dist/esm/utils.js +31 -1
- package/package.json +17 -10
|
@@ -5,7 +5,7 @@ import { Err, Ok } from '@sniptt/monads';
|
|
|
5
5
|
import { v4 as uuid } from 'uuid';
|
|
6
6
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
7
7
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
8
|
-
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
8
|
+
import { createTradeAmountTooSmallErr, getInputOutputRate, makeSwapErrorRight, } from '../../../utils.js';
|
|
9
9
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
10
10
|
import { DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS } from '../constants.js';
|
|
11
11
|
import { QuoteRequest } from '../types.js';
|
|
@@ -36,11 +36,16 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
36
36
|
initializeOneClickService(deps.config.VITE_NEAR_INTENTS_API_KEY);
|
|
37
37
|
const originAsset = await assetToNearIntentsAsset(sellAsset);
|
|
38
38
|
const destinationAsset = await assetToNearIntentsAsset(buyAsset);
|
|
39
|
-
|
|
40
|
-
if (!(originAsset && destinationAsset)) {
|
|
39
|
+
if (!originAsset) {
|
|
41
40
|
return Err(makeSwapErrorRight({
|
|
42
41
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
43
|
-
message:
|
|
42
|
+
message: `Asset ${sellAsset.symbol} on ${sellAsset.networkName || sellAsset.chainId} is not supported by NEAR Intents`,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
if (!destinationAsset) {
|
|
46
|
+
return Err(makeSwapErrorRight({
|
|
47
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
48
|
+
message: `Asset ${buyAsset.symbol} on ${buyAsset.networkName || buyAsset.chainId} is not supported by NEAR Intents`,
|
|
44
49
|
}));
|
|
45
50
|
}
|
|
46
51
|
const quoteRequest = {
|
|
@@ -138,6 +143,30 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
138
143
|
const totalFee = bn(txFee).plus(ataCreationCost).toString();
|
|
139
144
|
return { networkFeeCryptoBaseUnit: totalFee };
|
|
140
145
|
}
|
|
146
|
+
case CHAIN_NAMESPACE.Tron: {
|
|
147
|
+
const sellAdapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
148
|
+
const feeData = await sellAdapter.getFeeData({
|
|
149
|
+
to: depositAddress,
|
|
150
|
+
value: sellAmount,
|
|
151
|
+
});
|
|
152
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
153
|
+
}
|
|
154
|
+
case CHAIN_NAMESPACE.Sui: {
|
|
155
|
+
const sellAdapter = deps.assertGetSuiChainAdapter(sellAsset.chainId);
|
|
156
|
+
const tokenId = isToken(sellAsset.assetId)
|
|
157
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
158
|
+
: undefined;
|
|
159
|
+
const feeData = await sellAdapter.getFeeData({
|
|
160
|
+
to: depositAddress,
|
|
161
|
+
value: sellAmount,
|
|
162
|
+
chainSpecific: {
|
|
163
|
+
from,
|
|
164
|
+
tokenId,
|
|
165
|
+
},
|
|
166
|
+
sendMax: false,
|
|
167
|
+
});
|
|
168
|
+
return { networkFeeCryptoBaseUnit: feeData.fast.txFee };
|
|
169
|
+
}
|
|
141
170
|
default:
|
|
142
171
|
throw new Error(`Unsupported chain namespace: ${chainNamespace}`);
|
|
143
172
|
}
|
|
@@ -188,13 +217,24 @@ export const getTradeQuote = async (input, deps) => {
|
|
|
188
217
|
}
|
|
189
218
|
catch (error) {
|
|
190
219
|
console.error('[NEAR Intents] getTradeQuote error:', error);
|
|
191
|
-
if (error instanceof ApiError
|
|
192
|
-
(error.body?.message === 'tokenIn is not valid' ||
|
|
193
|
-
error.body?.message === 'tokenOut is not valid')
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
220
|
+
if (error instanceof ApiError) {
|
|
221
|
+
if (error.body?.message === 'tokenIn is not valid' ||
|
|
222
|
+
error.body?.message === 'tokenOut is not valid') {
|
|
223
|
+
return Err(makeSwapErrorRight({
|
|
224
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
225
|
+
message: 'Unsupported asset',
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
if (error.body?.message?.includes('Amount is too low')) {
|
|
229
|
+
const match = error.body.message.match(/try at least (\d+)/);
|
|
230
|
+
if (match) {
|
|
231
|
+
const minAmountCryptoBaseUnit = match[1];
|
|
232
|
+
return Err(createTradeAmountTooSmallErr({
|
|
233
|
+
minAmountCryptoBaseUnit,
|
|
234
|
+
assetId: sellAsset.assetId,
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
198
238
|
}
|
|
199
239
|
return Err(makeSwapErrorRight({
|
|
200
240
|
message: error instanceof Error ? error.message : 'Unknown error getting NEAR Intents quote',
|
|
@@ -6,7 +6,7 @@ import { v4 as uuid } from 'uuid';
|
|
|
6
6
|
import { getAddress } from 'viem';
|
|
7
7
|
import { getDefaultSlippageDecimalPercentageForSwapper } from '../../../constants.js';
|
|
8
8
|
import { SwapperName, TradeQuoteError } from '../../../types.js';
|
|
9
|
-
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils.js';
|
|
9
|
+
import { createTradeAmountTooSmallErr, getInputOutputRate, makeSwapErrorRight, } from '../../../utils.js';
|
|
10
10
|
import { simulateWithStateOverrides } from '../../../utils/tenderly/index.js';
|
|
11
11
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
12
12
|
import { DEFAULT_QUOTE_DEADLINE_MS, DEFAULT_SLIPPAGE_BPS } from '../constants.js';
|
|
@@ -19,10 +19,18 @@ export const getTradeRate = async (input, deps) => {
|
|
|
19
19
|
initializeOneClickService(deps.config.VITE_NEAR_INTENTS_API_KEY);
|
|
20
20
|
const originAsset = await assetToNearIntentsAsset(sellAsset);
|
|
21
21
|
const destinationAsset = await assetToNearIntentsAsset(buyAsset);
|
|
22
|
-
if (!
|
|
22
|
+
if (!originAsset) {
|
|
23
|
+
console.log('[NEAR] Returning error - originAsset not supported');
|
|
23
24
|
return Err(makeSwapErrorRight({
|
|
24
25
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
25
|
-
message:
|
|
26
|
+
message: `Asset ${sellAsset.symbol} on ${sellAsset.networkName || sellAsset.chainId} is not supported by NEAR Intents`,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
if (!destinationAsset) {
|
|
30
|
+
console.log('[NEAR] Returning error - destinationAsset not supported');
|
|
31
|
+
return Err(makeSwapErrorRight({
|
|
32
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
33
|
+
message: `Asset ${buyAsset.symbol} on ${buyAsset.networkName || buyAsset.chainId} is not supported by NEAR Intents`,
|
|
26
34
|
}));
|
|
27
35
|
}
|
|
28
36
|
// Wallet connected: use actual addresses
|
|
@@ -145,6 +153,43 @@ export const getTradeRate = async (input, deps) => {
|
|
|
145
153
|
return '0';
|
|
146
154
|
}
|
|
147
155
|
}
|
|
156
|
+
case CHAIN_NAMESPACE.Tron: {
|
|
157
|
+
try {
|
|
158
|
+
const sellAdapter = deps.assertGetTronChainAdapter(sellAsset.chainId);
|
|
159
|
+
const feeData = await sellAdapter.getFeeData({
|
|
160
|
+
to: depositAddress,
|
|
161
|
+
value: sellAmount,
|
|
162
|
+
});
|
|
163
|
+
return feeData.fast.txFee;
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return '0';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
case CHAIN_NAMESPACE.Sui: {
|
|
170
|
+
try {
|
|
171
|
+
const sellAdapter = deps.assertGetSuiChainAdapter(sellAsset.chainId);
|
|
172
|
+
const tokenId = isToken(sellAsset.assetId)
|
|
173
|
+
? fromAssetId(sellAsset.assetId).assetReference
|
|
174
|
+
: undefined;
|
|
175
|
+
if (!sendAddress) {
|
|
176
|
+
return '0';
|
|
177
|
+
}
|
|
178
|
+
const feeData = await sellAdapter.getFeeData({
|
|
179
|
+
to: depositAddress,
|
|
180
|
+
value: sellAmount,
|
|
181
|
+
chainSpecific: {
|
|
182
|
+
from: sendAddress,
|
|
183
|
+
tokenId,
|
|
184
|
+
},
|
|
185
|
+
sendMax: false,
|
|
186
|
+
});
|
|
187
|
+
return feeData.fast.txFee;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return '0';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
148
193
|
default:
|
|
149
194
|
return undefined;
|
|
150
195
|
}
|
|
@@ -187,13 +232,24 @@ export const getTradeRate = async (input, deps) => {
|
|
|
187
232
|
return Ok([tradeRate]);
|
|
188
233
|
}
|
|
189
234
|
catch (error) {
|
|
190
|
-
if (error instanceof ApiError
|
|
191
|
-
(error.body?.message === 'tokenIn is not valid' ||
|
|
192
|
-
error.body?.message === 'tokenOut is not valid')
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
235
|
+
if (error instanceof ApiError) {
|
|
236
|
+
if (error.body?.message === 'tokenIn is not valid' ||
|
|
237
|
+
error.body?.message === 'tokenOut is not valid') {
|
|
238
|
+
return Err(makeSwapErrorRight({
|
|
239
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
240
|
+
message: 'Unsupported asset',
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
if (error.body?.message?.includes('Amount is too low')) {
|
|
244
|
+
const match = error.body.message.match(/try at least (\d+)/);
|
|
245
|
+
if (match) {
|
|
246
|
+
const minAmountCryptoBaseUnit = match[1];
|
|
247
|
+
return Err(createTradeAmountTooSmallErr({
|
|
248
|
+
minAmountCryptoBaseUnit,
|
|
249
|
+
assetId: sellAsset.assetId,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
197
253
|
}
|
|
198
254
|
return Err(makeSwapErrorRight({
|
|
199
255
|
message: error instanceof Error ? error.message : 'Unknown error getting NEAR Intents rate',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
2
|
export { QuoteRequest } from '@defuse-protocol/one-click-sdk-typescript';
|
|
3
|
-
export type {
|
|
4
|
-
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.SolanaMainnet];
|
|
3
|
+
export type { GetExecutionStatusResponse, QuoteResponse, TokenResponse, } from '@defuse-protocol/one-click-sdk-typescript';
|
|
4
|
+
export declare const nearIntentsSupportedChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BitcoinMainnet, KnownChainIds.DogecoinMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.TronMainnet, KnownChainIds.SuiMainnet];
|
|
5
5
|
export type NearIntentsSupportedChainId = (typeof nearIntentsSupportedChainIds)[number];
|
|
6
6
|
export declare const chainIdToNearIntentsChain: Record<NearIntentsSupportedChainId, string>;
|
|
@@ -12,6 +12,8 @@ export const nearIntentsSupportedChainIds = [
|
|
|
12
12
|
KnownChainIds.BitcoinMainnet,
|
|
13
13
|
KnownChainIds.DogecoinMainnet,
|
|
14
14
|
KnownChainIds.SolanaMainnet,
|
|
15
|
+
KnownChainIds.TronMainnet,
|
|
16
|
+
KnownChainIds.SuiMainnet,
|
|
15
17
|
];
|
|
16
18
|
export const chainIdToNearIntentsChain = {
|
|
17
19
|
[KnownChainIds.EthereumMainnet]: 'eth',
|
|
@@ -25,4 +27,6 @@ export const chainIdToNearIntentsChain = {
|
|
|
25
27
|
[KnownChainIds.BitcoinMainnet]: 'btc',
|
|
26
28
|
[KnownChainIds.DogecoinMainnet]: 'doge',
|
|
27
29
|
[KnownChainIds.SolanaMainnet]: 'sol',
|
|
30
|
+
[KnownChainIds.TronMainnet]: 'tron',
|
|
31
|
+
[KnownChainIds.SuiMainnet]: 'sui',
|
|
28
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASSOCIATED_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/utils/token';
|
|
2
|
-
import { fromAssetId, solanaChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { fromAssetId, solanaChainId, suiChainId } from '@shapeshiftoss/caip';
|
|
3
3
|
import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
4
4
|
import { bnOrZero, isToken } from '@shapeshiftoss/utils';
|
|
5
5
|
import { zeroAddress } from 'viem';
|
|
@@ -23,19 +23,23 @@ export const getNearIntentsAsset = ({ nearNetwork, contractAddress, }) => {
|
|
|
23
23
|
// ERC20 tokens: "nep141:eth-0x{address}.omft.near"
|
|
24
24
|
return `nep141:${nearNetwork}-${contractAddress.toLowerCase()}.omft.near`;
|
|
25
25
|
};
|
|
26
|
-
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op'];
|
|
26
|
+
const NEP245_CHAINS = ['bsc', 'pol', 'avax', 'op', 'tron'];
|
|
27
|
+
const TOKEN_LOOKUP_CHAINS = ['sui'];
|
|
27
28
|
export const assetToNearIntentsAsset = async (asset) => {
|
|
28
29
|
const nearNetwork = chainIdToNearIntentsChain[asset.chainId];
|
|
29
30
|
if (!nearNetwork)
|
|
30
31
|
return null;
|
|
31
|
-
// NEP-245 chains (BSC, Polygon, Avalanche, Optimism) and Solana require token lookup
|
|
32
|
+
// NEP-245 chains (BSC, Polygon, Avalanche, Optimism, TRON, SUI) and Solana require token lookup
|
|
32
33
|
// Asset IDs use hashed format that can't be generated from contract addresses
|
|
33
|
-
const requiresLookup = NEP245_CHAINS.includes(nearNetwork) ||
|
|
34
|
+
const requiresLookup = NEP245_CHAINS.includes(nearNetwork) ||
|
|
35
|
+
TOKEN_LOOKUP_CHAINS.includes(nearNetwork) ||
|
|
36
|
+
asset.chainId === solanaChainId ||
|
|
37
|
+
asset.chainId === suiChainId;
|
|
34
38
|
if (requiresLookup) {
|
|
35
39
|
const tokens = await OneClickService.getTokens();
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const { assetNamespace, assetReference } = fromAssetId(asset.assetId);
|
|
41
|
+
const isNativeAsset = assetNamespace === 'slip44';
|
|
42
|
+
const contractAddress = !isNativeAsset ? assetReference.toLowerCase() : null;
|
|
39
43
|
const match = tokens.find((t) => {
|
|
40
44
|
if (t.blockchain !== nearNetwork)
|
|
41
45
|
return false;
|
|
@@ -43,8 +47,9 @@ export const assetToNearIntentsAsset = async (asset) => {
|
|
|
43
47
|
? t.contractAddress?.toLowerCase() === contractAddress
|
|
44
48
|
: !t.contractAddress;
|
|
45
49
|
});
|
|
46
|
-
if (!match)
|
|
50
|
+
if (!match) {
|
|
47
51
|
return null;
|
|
52
|
+
}
|
|
48
53
|
return match.assetId;
|
|
49
54
|
}
|
|
50
55
|
// NEP-141 chains (ETH, ARB, BASE, GNOSIS, BTC, DOGE): use predictable format
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { executeEvmTransaction, executeSolanaTransaction } from '../../utils.js';
|
|
1
|
+
import { executeEvmTransaction, executeSolanaTransaction, executeTronTransaction, } from '../../utils.js';
|
|
2
2
|
export const relaySwapper = {
|
|
3
3
|
executeEvmTransaction,
|
|
4
4
|
executeSolanaTransaction,
|
|
5
|
+
executeTronTransaction,
|
|
5
6
|
executeUtxoTransaction: (txToSign, { signAndBroadcastTransaction }) => {
|
|
6
7
|
return signAndBroadcastTransaction(txToSign);
|
|
7
8
|
},
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
1
|
import { TradeQuoteError } from '../../types.js';
|
|
3
2
|
import { RelayErrorCode } from './utils/types.js';
|
|
4
|
-
export declare const relaySupportedChainIds: KnownChainIds[];
|
|
5
3
|
export declare const chainIdToRelayChainId: {
|
|
6
4
|
[x: string]: number;
|
|
7
5
|
};
|
|
@@ -16,8 +14,10 @@ export declare const relayChainIdToChainId: import("lodash").Dictionary<string>;
|
|
|
16
14
|
export declare const DEFAULT_RELAY_EVM_TOKEN_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
17
15
|
export declare const RELAY_BTC_TOKEN_ADDRESS = "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8";
|
|
18
16
|
export declare const RELAY_SOLANA_TOKEN_ADDRESS = "11111111111111111111111111111111";
|
|
17
|
+
export declare const RELAY_TRON_TOKEN_ADDRESS = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
19
18
|
export declare const DEFAULT_RELAY_EVM_USER_ADDRESS = "0x000000000000000000000000000000000000dead";
|
|
20
19
|
export declare const DEFAULT_RELAY_BTC_USER_ADDRESS = "bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa";
|
|
21
20
|
export declare const DEFAULT_RELAY_SOLANA_USER_ADDRESS = "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr";
|
|
21
|
+
export declare const DEFAULT_RELAY_TRON_USER_ADDRESS = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy";
|
|
22
22
|
export declare const MAXIMUM_SUPPORTED_RELAY_STEPS = 2;
|
|
23
23
|
export declare const relayErrorCodeToTradeQuoteError: Record<RelayErrorCode, TradeQuoteError>;
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { arbitrumChainId, avalancheChainId, baseChainId, bscChainId, btcChainId, ethChainId, gnosisChainId, optimismChainId, polygonChainId, solanaChainId, } from '@shapeshiftoss/caip';
|
|
2
|
-
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
1
|
+
import { arbitrumChainId, avalancheChainId, baseChainId, bscChainId, btcChainId, ethChainId, gnosisChainId, monadChainId, optimismChainId, polygonChainId, solanaChainId, tronChainId, } from '@shapeshiftoss/caip';
|
|
3
2
|
import invert from 'lodash/invert';
|
|
4
3
|
import { zeroAddress } from 'viem';
|
|
5
|
-
import { arbitrum, avalanche, base, bsc, gnosis, mainnet as ethereum, optimism, polygon, } from 'viem/chains';
|
|
4
|
+
import { arbitrum, avalanche, base, bsc, gnosis, mainnet as ethereum, monad, optimism, polygon, } from 'viem/chains';
|
|
6
5
|
import { TradeQuoteError } from '../../types.js';
|
|
7
6
|
import { RelayErrorCode } from './utils/types.js';
|
|
8
|
-
export const relaySupportedChainIds = [
|
|
9
|
-
KnownChainIds.EthereumMainnet,
|
|
10
|
-
KnownChainIds.ArbitrumMainnet,
|
|
11
|
-
KnownChainIds.BaseMainnet,
|
|
12
|
-
KnownChainIds.OptimismMainnet,
|
|
13
|
-
KnownChainIds.PolygonMainnet,
|
|
14
|
-
KnownChainIds.GnosisMainnet,
|
|
15
|
-
KnownChainIds.AvalancheMainnet,
|
|
16
|
-
KnownChainIds.BitcoinMainnet,
|
|
17
|
-
KnownChainIds.SolanaMainnet,
|
|
18
|
-
KnownChainIds.BnbSmartChainMainnet,
|
|
19
|
-
];
|
|
20
7
|
export const chainIdToRelayChainId = {
|
|
21
8
|
// https://docs.relay.link/resources/supported-chains
|
|
22
9
|
[btcChainId]: 8253038,
|
|
@@ -30,6 +17,8 @@ export const chainIdToRelayChainId = {
|
|
|
30
17
|
[gnosisChainId]: gnosis.id,
|
|
31
18
|
[avalancheChainId]: avalanche.id,
|
|
32
19
|
[bscChainId]: bsc.id,
|
|
20
|
+
[tronChainId]: 728126428,
|
|
21
|
+
[monadChainId]: monad.id,
|
|
33
22
|
};
|
|
34
23
|
export var RelayStatusMessage;
|
|
35
24
|
(function (RelayStatusMessage) {
|
|
@@ -43,9 +32,11 @@ export const relayChainIdToChainId = invert(chainIdToRelayChainId);
|
|
|
43
32
|
export const DEFAULT_RELAY_EVM_TOKEN_ADDRESS = zeroAddress;
|
|
44
33
|
export const RELAY_BTC_TOKEN_ADDRESS = 'bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8';
|
|
45
34
|
export const RELAY_SOLANA_TOKEN_ADDRESS = '11111111111111111111111111111111';
|
|
35
|
+
export const RELAY_TRON_TOKEN_ADDRESS = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb';
|
|
46
36
|
export const DEFAULT_RELAY_EVM_USER_ADDRESS = '0x000000000000000000000000000000000000dead';
|
|
47
37
|
export const DEFAULT_RELAY_BTC_USER_ADDRESS = 'bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa';
|
|
48
38
|
export const DEFAULT_RELAY_SOLANA_USER_ADDRESS = 'CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr';
|
|
39
|
+
export const DEFAULT_RELAY_TRON_USER_ADDRESS = 'TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy';
|
|
49
40
|
export const MAXIMUM_SUPPORTED_RELAY_STEPS = 2;
|
|
50
41
|
export const relayErrorCodeToTradeQuoteError = {
|
|
51
42
|
[RelayErrorCode.AmountTooLow]: TradeQuoteError.SellAmountBelowMinimum,
|
|
@@ -3,6 +3,8 @@ import { TxStatus } from '@shapeshiftoss/unchained-client';
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { getSolanaTransactionFees } from '../../solana-utils/getSolanaTransactionFees.js';
|
|
5
5
|
import { getUnsignedSolanaTransaction } from '../../solana-utils/getUnsignedSolanaTransaction.js';
|
|
6
|
+
import { getTronTransactionFees } from '../../tron-utils/getTronTransactionFees.js';
|
|
7
|
+
import { getUnsignedTronTransaction } from '../../tron-utils/getUnsignedTronTransaction.js';
|
|
6
8
|
import { checkSafeTransactionStatus, getExecutableTradeStep, isExecutableTradeQuote, } from '../../utils.js';
|
|
7
9
|
import { chainIdToRelayChainId } from './constant.js';
|
|
8
10
|
import { getTradeQuote } from './getTradeQuote/getTradeQuote.js';
|
|
@@ -119,6 +121,8 @@ export const relayApi = {
|
|
|
119
121
|
},
|
|
120
122
|
getSolanaTransactionFees,
|
|
121
123
|
getUnsignedSolanaTransaction,
|
|
124
|
+
getTronTransactionFees,
|
|
125
|
+
getUnsignedTronTransaction,
|
|
122
126
|
checkTradeStatus: async ({ swap, txHash, chainId, address, config, fetchIsSmartContractAddressQuery, assertGetEvmChainAdapter, }) => {
|
|
123
127
|
const maybeSafeTransactionStatus = await checkSafeTransactionStatus({
|
|
124
128
|
txHash,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { btcAssetId, fromAssetId, isAssetReference, solAssetId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { btcAssetId, fromAssetId, isAssetReference, solAssetId, tronAssetId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import { isNativeEvmAsset } from '../../utils/helpers/helpers.js';
|
|
3
|
-
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, } from '../constant.js';
|
|
3
|
+
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, RELAY_TRON_TOKEN_ADDRESS, } from '../constant.js';
|
|
4
4
|
export const getRelayAssetAddress = (asset) => {
|
|
5
5
|
if (asset.assetId === btcAssetId)
|
|
6
6
|
return RELAY_BTC_TOKEN_ADDRESS;
|
|
7
7
|
if (asset.assetId === solAssetId)
|
|
8
8
|
return RELAY_SOLANA_TOKEN_ADDRESS;
|
|
9
|
+
if (asset.assetId === tronAssetId)
|
|
10
|
+
return RELAY_TRON_TOKEN_ADDRESS;
|
|
9
11
|
if (isNativeEvmAsset(asset.assetId))
|
|
10
12
|
return DEFAULT_RELAY_EVM_TOKEN_ADDRESS;
|
|
11
13
|
const { assetReference } = fromAssetId(asset.assetId);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
export declare const getRelayDefaultUserAddress: (chainId: ChainId) => "0x000000000000000000000000000000000000dead" | "bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa" | "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr";
|
|
2
|
+
export declare const getRelayDefaultUserAddress: (chainId: ChainId) => "0x000000000000000000000000000000000000dead" | "bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa" | "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr" | "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { btcChainId, solanaChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { DEFAULT_RELAY_BTC_USER_ADDRESS, DEFAULT_RELAY_EVM_USER_ADDRESS, DEFAULT_RELAY_SOLANA_USER_ADDRESS, } from '../constant.js';
|
|
1
|
+
import { btcChainId, solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { DEFAULT_RELAY_BTC_USER_ADDRESS, DEFAULT_RELAY_EVM_USER_ADDRESS, DEFAULT_RELAY_SOLANA_USER_ADDRESS, DEFAULT_RELAY_TRON_USER_ADDRESS, } from '../constant.js';
|
|
3
3
|
export const getRelayDefaultUserAddress = (chainId) => {
|
|
4
4
|
switch (chainId) {
|
|
5
5
|
case btcChainId:
|
|
6
6
|
return DEFAULT_RELAY_BTC_USER_ADDRESS;
|
|
7
7
|
case solanaChainId:
|
|
8
8
|
return DEFAULT_RELAY_SOLANA_USER_ADDRESS;
|
|
9
|
+
case tronChainId:
|
|
10
|
+
return DEFAULT_RELAY_TRON_USER_ADDRESS;
|
|
9
11
|
default:
|
|
10
12
|
return DEFAULT_RELAY_EVM_USER_ADDRESS;
|
|
11
13
|
}
|
|
@@ -9,7 +9,7 @@ export const getRelayPsbtRelayer = (psbtHex, sellAmountCryptoBaseUnit) => {
|
|
|
9
9
|
try {
|
|
10
10
|
const address = bitcoin.address.fromOutputScript(script);
|
|
11
11
|
// Assuming the destination address is the one with the exact amount of sellAmountCryptoBaseUnit
|
|
12
|
-
if (output.value ===
|
|
12
|
+
if (output.value === BigInt(sellAmountCryptoBaseUnit)) {
|
|
13
13
|
return address;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { btcChainId, fromChainId, solanaChainId } from '@shapeshiftoss/caip';
|
|
1
|
+
import { btcChainId, fromChainId, solanaChainId, tronChainId } from '@shapeshiftoss/caip';
|
|
2
2
|
import { evm, isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
3
|
import { bnOrZero, convertBasisPointsToPercentage, convertDecimalPercentageToBasisPoints, convertPrecision, DAO_TREASURY_BASE, } from '@shapeshiftoss/utils';
|
|
4
4
|
import { Err, Ok } from '@sniptt/monads';
|
|
@@ -26,7 +26,8 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
26
26
|
const buyRelayChainId = relayChainMap[buyAsset.chainId];
|
|
27
27
|
if (!isEvmChainId(sellAsset.chainId) &&
|
|
28
28
|
sellAsset.chainId !== btcChainId &&
|
|
29
|
-
sellAsset.chainId !== solanaChainId
|
|
29
|
+
sellAsset.chainId !== solanaChainId &&
|
|
30
|
+
sellAsset.chainId !== tronChainId) {
|
|
30
31
|
return Err(makeSwapErrorRight({
|
|
31
32
|
message: `asset '${sellAsset.name}' on chainId '${sellAsset.chainId}' not supported`,
|
|
32
33
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
@@ -34,7 +35,8 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
34
35
|
}
|
|
35
36
|
if (!isEvmChainId(buyAsset.chainId) &&
|
|
36
37
|
buyAsset.chainId !== btcChainId &&
|
|
37
|
-
buyAsset.chainId !== solanaChainId
|
|
38
|
+
buyAsset.chainId !== solanaChainId &&
|
|
39
|
+
buyAsset.chainId !== tronChainId) {
|
|
38
40
|
return Err(makeSwapErrorRight({
|
|
39
41
|
message: `asset '${buyAsset.name}' on chainId '${buyAsset.chainId}' not supported`,
|
|
40
42
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
@@ -211,6 +213,9 @@ export async function getTrade({ input, deps, relayChainMap, }) {
|
|
|
211
213
|
if (sellAsset.chainId === solanaChainId) {
|
|
212
214
|
return sellAsset.assetId === appFeesAsset.assetId;
|
|
213
215
|
}
|
|
216
|
+
if (sellAsset.chainId === tronChainId) {
|
|
217
|
+
return sellAsset.assetId === appFeesAsset.assetId;
|
|
218
|
+
}
|
|
214
219
|
return false;
|
|
215
220
|
})();
|
|
216
221
|
const appFeesBaseUnit = (() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ASSET_NAMESPACE, ASSET_REFERENCE, btcChainId, CHAIN_REFERENCE, fromChainId, solanaChainId, toAssetId, } from '@shapeshiftoss/caip';
|
|
1
|
+
import { ASSET_NAMESPACE, ASSET_REFERENCE, btcChainId, CHAIN_REFERENCE, fromChainId, solanaChainId, toAssetId, tronChainId, } from '@shapeshiftoss/caip';
|
|
2
2
|
import { isEvmChainId } from '@shapeshiftoss/chain-adapters';
|
|
3
|
-
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, relayChainIdToChainId, } from '../constant.js';
|
|
3
|
+
import { DEFAULT_RELAY_EVM_TOKEN_ADDRESS, RELAY_BTC_TOKEN_ADDRESS, RELAY_SOLANA_TOKEN_ADDRESS, RELAY_TRON_TOKEN_ADDRESS, relayChainIdToChainId, } from '../constant.js';
|
|
4
4
|
export const relayTokenToAssetId = (relayToken) => {
|
|
5
5
|
const chainId = relayChainIdToChainId[relayToken.chainId];
|
|
6
6
|
const { chainReference } = fromChainId(chainId);
|
|
@@ -14,6 +14,9 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
14
14
|
if (chainId === solanaChainId) {
|
|
15
15
|
return relayToken.address === RELAY_SOLANA_TOKEN_ADDRESS;
|
|
16
16
|
}
|
|
17
|
+
if (chainId === tronChainId) {
|
|
18
|
+
return relayToken.address === RELAY_TRON_TOKEN_ADDRESS;
|
|
19
|
+
}
|
|
17
20
|
return false;
|
|
18
21
|
})();
|
|
19
22
|
const { assetReference, assetNamespace } = (() => {
|
|
@@ -24,6 +27,8 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
24
27
|
return ASSET_NAMESPACE.erc20;
|
|
25
28
|
case CHAIN_REFERENCE.SolanaMainnet === chainReference:
|
|
26
29
|
return ASSET_NAMESPACE.splToken;
|
|
30
|
+
case CHAIN_REFERENCE.TronMainnet === chainReference:
|
|
31
|
+
return ASSET_NAMESPACE.trc20;
|
|
27
32
|
default:
|
|
28
33
|
throw Error(`chainReference '${chainReference}' not supported`);
|
|
29
34
|
}
|
|
@@ -79,6 +84,16 @@ export const relayTokenToAssetId = (relayToken) => {
|
|
|
79
84
|
assetReference: ASSET_REFERENCE.Solana,
|
|
80
85
|
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
81
86
|
};
|
|
87
|
+
case CHAIN_REFERENCE.TronMainnet:
|
|
88
|
+
return {
|
|
89
|
+
assetReference: ASSET_REFERENCE.Tron,
|
|
90
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
91
|
+
};
|
|
92
|
+
case CHAIN_REFERENCE.MonadMainnet:
|
|
93
|
+
return {
|
|
94
|
+
assetReference: ASSET_REFERENCE.Monad,
|
|
95
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
96
|
+
};
|
|
82
97
|
default:
|
|
83
98
|
throw Error(`chainId '${relayToken.chainId}' not supported`);
|
|
84
99
|
}
|
|
@@ -272,6 +272,18 @@ export const getL1RateOrQuote = async (input, deps, streamingInterval, tradeType
|
|
|
272
272
|
code: TradeQuoteError.UnsupportedTradePair,
|
|
273
273
|
}));
|
|
274
274
|
}
|
|
275
|
+
case CHAIN_NAMESPACE.Tron: {
|
|
276
|
+
return Err(makeSwapErrorRight({
|
|
277
|
+
message: 'Tron is not supported',
|
|
278
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
case CHAIN_NAMESPACE.Sui: {
|
|
282
|
+
return Err(makeSwapErrorRight({
|
|
283
|
+
message: 'SUI is not supported',
|
|
284
|
+
code: TradeQuoteError.UnsupportedTradePair,
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
275
287
|
default:
|
|
276
288
|
return assertUnreachable(chainNamespace);
|
|
277
289
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../utils.js';
|
|
2
|
+
export const getTronTransactionFees = ({ tradeQuote, stepIndex, }) => {
|
|
3
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
4
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
5
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
6
|
+
if (!step.feeData.networkFeeCryptoBaseUnit) {
|
|
7
|
+
throw new Error('Missing network fee in quote');
|
|
8
|
+
}
|
|
9
|
+
return Promise.resolve(step.feeData.networkFeeCryptoBaseUnit);
|
|
10
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { GetUnsignedTronTransactionArgs } from '../types.js';
|
|
2
|
+
export declare const getUnsignedTronTransaction: ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }: GetUnsignedTronTransactionArgs) => Promise<import("packages/chain-adapters/src/tron").TronSignTx>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { contractAddressOrUndefined } from '@shapeshiftoss/utils';
|
|
2
|
+
import { getExecutableTradeStep, isExecutableTradeQuote } from '../utils.js';
|
|
3
|
+
export const getUnsignedTronTransaction = ({ stepIndex, tradeQuote, from, assertGetTronChainAdapter, }) => {
|
|
4
|
+
if (!isExecutableTradeQuote(tradeQuote))
|
|
5
|
+
throw new Error('Unable to execute a trade rate quote');
|
|
6
|
+
const step = getExecutableTradeStep(tradeQuote, stepIndex);
|
|
7
|
+
const { accountNumber, sellAsset, relayTransactionMetadata, nearIntentsSpecific } = step;
|
|
8
|
+
const adapter = assertGetTronChainAdapter(sellAsset.chainId);
|
|
9
|
+
const to = relayTransactionMetadata?.to ?? nearIntentsSpecific?.depositAddress;
|
|
10
|
+
if (!to)
|
|
11
|
+
throw new Error('Missing transaction destination address');
|
|
12
|
+
const value = step.sellAmountIncludingProtocolFeesCryptoBaseUnit;
|
|
13
|
+
// Extract contract address for TRC20 tokens
|
|
14
|
+
const contractAddress = contractAddressOrUndefined(sellAsset.assetId);
|
|
15
|
+
return adapter.buildSendApiTransaction({
|
|
16
|
+
to,
|
|
17
|
+
from,
|
|
18
|
+
value,
|
|
19
|
+
accountNumber,
|
|
20
|
+
chainSpecific: {
|
|
21
|
+
contractAddress,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
};
|