@lifi/sdk-provider-tron 4.0.0-alpha.24 → 4.0.0-beta.10
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/TronProvider.d.ts +7 -2
- package/dist/cjs/TronProvider.js +30 -34
- package/dist/cjs/TronProvider.js.map +1 -1
- package/dist/cjs/actions/getMulticallAddress.d.ts +7 -2
- package/dist/cjs/actions/getMulticallAddress.js +6 -6
- package/dist/cjs/actions/getMulticallAddress.js.map +1 -1
- package/dist/cjs/actions/getTronBalance.d.ts +7 -2
- package/dist/cjs/actions/getTronBalance.js +86 -100
- package/dist/cjs/actions/getTronBalance.js.map +1 -1
- package/dist/cjs/actions/resolveTronAddress.d.ts +5 -1
- package/dist/cjs/actions/resolveTronAddress.js +6 -4
- package/dist/cjs/actions/resolveTronAddress.js.map +1 -1
- package/dist/cjs/core/TronStepExecutor.d.ts +14 -9
- package/dist/cjs/core/TronStepExecutor.js +50 -62
- package/dist/cjs/core/TronStepExecutor.js.map +1 -1
- package/dist/cjs/core/constants.d.ts +8 -2
- package/dist/cjs/core/constants.js +12 -5
- package/dist/cjs/core/constants.js.map +1 -1
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.d.ts +10 -5
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.js +35 -43
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronSetAllowanceTask.d.ts +10 -5
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js +65 -76
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.d.ts +9 -4
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.js +37 -42
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.d.ts +9 -4
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.js +29 -56
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/errors/parseTronErrors.d.ts +7 -2
- package/dist/cjs/errors/parseTronErrors.js +26 -46
- package/dist/cjs/errors/parseTronErrors.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +5 -8
- package/dist/cjs/rpc/callTronRpcsWithRetry.d.ts +10 -3
- package/dist/cjs/rpc/callTronRpcsWithRetry.js +24 -19
- package/dist/cjs/rpc/callTronRpcsWithRetry.js.map +1 -1
- package/dist/cjs/rpc/waitForTronTxConfirmation.d.ts +17 -0
- package/dist/cjs/rpc/waitForTronTxConfirmation.js +30 -0
- package/dist/cjs/rpc/waitForTronTxConfirmation.js.map +1 -0
- package/dist/cjs/types.d.ts +21 -16
- package/dist/cjs/types.js +7 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/address.d.ts +6 -2
- package/dist/cjs/utils/address.js +11 -8
- package/dist/cjs/utils/address.js.map +1 -1
- package/dist/cjs/utils/getTronTxLink.d.ts +7 -0
- package/dist/cjs/utils/getTronTxLink.js +11 -0
- package/dist/cjs/utils/getTronTxLink.js.map +1 -0
- package/dist/cjs/utils/isZeroAddress.d.ts +7 -3
- package/dist/cjs/utils/isZeroAddress.js +9 -6
- package/dist/cjs/utils/isZeroAddress.js.map +1 -1
- package/dist/cjs/utils/multicall3Abi.d.ts +7 -2
- package/dist/cjs/utils/multicall3Abi.js +60 -40
- package/dist/cjs/utils/multicall3Abi.js.map +1 -1
- package/dist/cjs/utils/stripHexPrefix.d.ts +5 -1
- package/dist/cjs/utils/stripHexPrefix.js +5 -4
- package/dist/cjs/utils/stripHexPrefix.js.map +1 -1
- package/dist/cjs/version.d.ts +6 -2
- package/dist/cjs/version.js +8 -5
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/TronProvider.d.ts +7 -2
- package/dist/esm/TronProvider.d.ts.map +1 -0
- package/dist/esm/TronProvider.js +30 -32
- package/dist/esm/TronProvider.js.map +1 -1
- package/dist/esm/actions/getMulticallAddress.d.ts +7 -2
- package/dist/esm/actions/getMulticallAddress.d.ts.map +1 -0
- package/dist/esm/actions/getMulticallAddress.js +7 -4
- package/dist/esm/actions/getMulticallAddress.js.map +1 -1
- package/dist/esm/actions/getTronBalance.d.ts +7 -2
- package/dist/esm/actions/getTronBalance.d.ts.map +1 -0
- package/dist/esm/actions/getTronBalance.js +85 -99
- package/dist/esm/actions/getTronBalance.js.map +1 -1
- package/dist/esm/actions/resolveTronAddress.d.ts +5 -1
- package/dist/esm/actions/resolveTronAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveTronAddress.js +6 -3
- package/dist/esm/actions/resolveTronAddress.js.map +1 -1
- package/dist/esm/core/TronStepExecutor.d.ts +14 -9
- package/dist/esm/core/TronStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/TronStepExecutor.js +50 -59
- package/dist/esm/core/TronStepExecutor.js.map +1 -1
- package/dist/esm/core/constants.d.ts +8 -2
- package/dist/esm/core/constants.d.ts.map +1 -0
- package/dist/esm/core/constants.js +8 -2
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts +10 -5
- package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/TronCheckAllowanceTask.js +35 -40
- package/dist/esm/core/tasks/TronCheckAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/TronSetAllowanceTask.d.ts +10 -5
- package/dist/esm/core/tasks/TronSetAllowanceTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/TronSetAllowanceTask.js +65 -74
- package/dist/esm/core/tasks/TronSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts +9 -4
- package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/TronSignAndExecuteTask.js +37 -39
- package/dist/esm/core/tasks/TronSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts +9 -4
- package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/TronWaitForTransactionTask.js +29 -54
- package/dist/esm/core/tasks/TronWaitForTransactionTask.js.map +1 -1
- package/dist/esm/errors/parseTronErrors.d.ts +7 -2
- package/dist/esm/errors/parseTronErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseTronErrors.js +26 -45
- package/dist/esm/errors/parseTronErrors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/package.json +1 -1
- package/dist/esm/rpc/callTronRpcsWithRetry.d.ts +10 -3
- package/dist/esm/rpc/callTronRpcsWithRetry.d.ts.map +1 -0
- package/dist/esm/rpc/callTronRpcsWithRetry.js +23 -17
- package/dist/esm/rpc/callTronRpcsWithRetry.js.map +1 -1
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts +17 -0
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts.map +1 -0
- package/dist/esm/rpc/waitForTronTxConfirmation.js +29 -0
- package/dist/esm/rpc/waitForTronTxConfirmation.js.map +1 -0
- package/dist/esm/types.d.ts +21 -16
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +7 -3
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/address.d.ts +6 -2
- package/dist/esm/utils/address.d.ts.map +1 -0
- package/dist/esm/utils/address.js +11 -7
- package/dist/esm/utils/address.js.map +1 -1
- package/dist/esm/utils/getTronTxLink.d.ts +7 -0
- package/dist/esm/utils/getTronTxLink.d.ts.map +1 -0
- package/dist/esm/utils/getTronTxLink.js +10 -0
- package/dist/esm/utils/getTronTxLink.js.map +1 -0
- package/dist/esm/utils/isZeroAddress.d.ts +7 -3
- package/dist/esm/utils/isZeroAddress.d.ts.map +1 -0
- package/dist/esm/utils/isZeroAddress.js +7 -3
- package/dist/esm/utils/isZeroAddress.js.map +1 -1
- package/dist/esm/utils/multicall3Abi.d.ts +7 -2
- package/dist/esm/utils/multicall3Abi.d.ts.map +1 -0
- package/dist/esm/utils/multicall3Abi.js +59 -37
- package/dist/esm/utils/multicall3Abi.js.map +1 -1
- package/dist/esm/utils/stripHexPrefix.d.ts +5 -1
- package/dist/esm/utils/stripHexPrefix.d.ts.map +1 -0
- package/dist/esm/utils/stripHexPrefix.js +5 -1
- package/dist/esm/utils/stripHexPrefix.js.map +1 -1
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +8 -12
- package/src/TronProvider.ts +1 -3
- package/src/actions/getTronBalance.ts +16 -6
- package/src/core/constants.ts +8 -1
- package/src/core/tasks/TronSetAllowanceTask.ts +25 -27
- package/src/core/tasks/TronSignAndExecuteTask.ts +35 -20
- package/src/core/tasks/TronWaitForTransactionTask.ts +6 -41
- package/src/errors/parseTronErrors.ts +26 -15
- package/src/rpc/callTronRpcsWithRetry.ts +10 -2
- package/src/rpc/waitForTronTxConfirmation.ts +56 -0
- package/src/utils/address.ts +7 -1
- package/src/utils/getTronTxLink.ts +15 -0
- package/src/utils/isZeroAddress.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/types/TronProvider.d.ts +0 -3
- package/dist/types/TronProvider.d.ts.map +0 -1
- package/dist/types/actions/getMulticallAddress.d.ts +0 -3
- package/dist/types/actions/getMulticallAddress.d.ts.map +0 -1
- package/dist/types/actions/getTronBalance.d.ts +0 -3
- package/dist/types/actions/getTronBalance.d.ts.map +0 -1
- package/dist/types/actions/resolveTronAddress.d.ts +0 -2
- package/dist/types/actions/resolveTronAddress.d.ts.map +0 -1
- package/dist/types/core/TronStepExecutor.d.ts +0 -11
- package/dist/types/core/TronStepExecutor.d.ts.map +0 -1
- package/dist/types/core/constants.d.ts +0 -3
- package/dist/types/core/constants.d.ts.map +0 -1
- package/dist/types/core/tasks/TronCheckAllowanceTask.d.ts +0 -7
- package/dist/types/core/tasks/TronCheckAllowanceTask.d.ts.map +0 -1
- package/dist/types/core/tasks/TronSetAllowanceTask.d.ts +0 -7
- package/dist/types/core/tasks/TronSetAllowanceTask.d.ts.map +0 -1
- package/dist/types/core/tasks/TronSignAndExecuteTask.d.ts +0 -6
- package/dist/types/core/tasks/TronSignAndExecuteTask.d.ts.map +0 -1
- package/dist/types/core/tasks/TronWaitForTransactionTask.d.ts +0 -6
- package/dist/types/core/tasks/TronWaitForTransactionTask.d.ts.map +0 -1
- package/dist/types/errors/parseTronErrors.d.ts +0 -3
- package/dist/types/errors/parseTronErrors.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/rpc/callTronRpcsWithRetry.d.ts +0 -4
- package/dist/types/rpc/callTronRpcsWithRetry.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -22
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils/address.d.ts +0 -3
- package/dist/types/utils/address.d.ts.map +0 -1
- package/dist/types/utils/isZeroAddress.d.ts +0 -4
- package/dist/types/utils/isZeroAddress.d.ts.map +0 -1
- package/dist/types/utils/multicall3Abi.d.ts +0 -3
- package/dist/types/utils/multicall3Abi.d.ts.map +0 -1
- package/dist/types/utils/stripHexPrefix.d.ts +0 -2
- package/dist/types/utils/stripHexPrefix.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -3
- package/dist/types/version.d.ts.map +0 -1
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { TronProviderOptions, TronSDKProvider } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/TronProvider.d.ts
|
|
4
|
+
declare function TronProvider(options?: TronProviderOptions): TronSDKProvider;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { TronProvider };
|
|
7
|
+
//# sourceMappingURL=TronProvider.d.ts.map
|
package/dist/cjs/TronProvider.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const TronStepExecutor_js_1 = require("./core/TronStepExecutor.js");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_actions_getTronBalance = require("./actions/getTronBalance.js");
|
|
3
|
+
const require_actions_resolveTronAddress = require("./actions/resolveTronAddress.js");
|
|
4
|
+
const require_core_TronStepExecutor = require("./core/TronStepExecutor.js");
|
|
5
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
6
|
+
let tronweb = require("tronweb");
|
|
7
|
+
//#region src/TronProvider.ts
|
|
9
8
|
function TronProvider(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return executor;
|
|
31
|
-
},
|
|
32
|
-
setOptions(options) {
|
|
33
|
-
Object.assign(_options, options);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
9
|
+
const _options = options ?? {};
|
|
10
|
+
return {
|
|
11
|
+
get type() {
|
|
12
|
+
return _lifi_sdk.ChainType.TVM;
|
|
13
|
+
},
|
|
14
|
+
isAddress: (address) => tronweb.TronWeb.isAddress(address),
|
|
15
|
+
resolveAddress: require_actions_resolveTronAddress.resolveTronAddress,
|
|
16
|
+
getBalance: (client, walletAddress, tokens) => require_actions_getTronBalance.getTronBalance(client, walletAddress, tokens, _options.multicallBatchSize),
|
|
17
|
+
async getStepExecutor(options) {
|
|
18
|
+
if (!_options.getWallet) throw new _lifi_sdk.ProviderError(_lifi_sdk.LiFiErrorCode.ProviderUnavailable, "TronProvider requires a getWallet function.");
|
|
19
|
+
return new require_core_TronStepExecutor.TronStepExecutor({
|
|
20
|
+
wallet: await _options.getWallet(),
|
|
21
|
+
routeId: options.routeId,
|
|
22
|
+
executionOptions: options.executionOptions
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
setOptions(options) {
|
|
26
|
+
Object.assign(_options, options);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
36
29
|
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.TronProvider = TronProvider;
|
|
32
|
+
|
|
37
33
|
//# sourceMappingURL=TronProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronProvider.js","
|
|
1
|
+
{"version":3,"file":"TronProvider.js","names":["ChainType","TronWeb","resolveTronAddress","getTronBalance","ProviderError","LiFiErrorCode","TronStepExecutor"],"sources":["../../src/TronProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport { TronWeb } from 'tronweb'\nimport { getTronBalance } from './actions/getTronBalance.js'\nimport { resolveTronAddress } from './actions/resolveTronAddress.js'\nimport { TronStepExecutor } from './core/TronStepExecutor.js'\nimport type { TronProviderOptions, TronSDKProvider } from './types.js'\n\nexport function TronProvider(options?: TronProviderOptions): TronSDKProvider {\n const _options: TronProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.TVM\n },\n isAddress: (address: string) => TronWeb.isAddress(address),\n resolveAddress: resolveTronAddress,\n getBalance: (client, walletAddress, tokens) =>\n getTronBalance(\n client,\n walletAddress,\n tokens,\n _options.multicallBatchSize\n ),\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<TronStepExecutor> {\n if (!_options.getWallet) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'TronProvider requires a getWallet function.'\n )\n }\n\n const wallet = await _options.getWallet()\n\n const executor = new TronStepExecutor({\n wallet,\n routeId: options.routeId,\n executionOptions: options.executionOptions,\n })\n\n return executor\n },\n setOptions(options: TronProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,aAAa,SAAgD;CAC3E,MAAM,WAAgC,WAAW,EAAE;CACnD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;;EAEnB,YAAY,YAAoBC,QAAAA,QAAQ,UAAU,QAAQ;EAC1D,gBAAgBC,mCAAAA;EAChB,aAAa,QAAQ,eAAe,WAClCC,+BAAAA,eACE,QACA,eACA,QACA,SAAS,mBACV;EACH,MAAM,gBACJ,SAC2B;GAC3B,IAAI,CAAC,SAAS,WACZ,MAAM,IAAIC,UAAAA,cACRC,UAAAA,cAAc,qBACd,8CACD;GAWH,OAAO,IANcC,8BAAAA,iBAAiB;IACpC,QAAA,MAHmB,SAAS,WAAW;IAIvC,SAAS,QAAQ;IACjB,kBAAkB,QAAQ;IAC3B,CAEc;;EAEjB,WAAW,SAA8B;GACvC,OAAO,OAAO,UAAU,QAAQ;;EAEnC"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ChainId, SDKClient } from "@lifi/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getMulticallAddress.d.ts
|
|
4
|
+
declare const getMulticallAddress: (client: SDKClient, chainId: ChainId) => Promise<string | undefined>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getMulticallAddress };
|
|
7
|
+
//# sourceMappingURL=getMulticallAddress.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
3
|
+
//#region src/actions/getMulticallAddress.ts
|
|
5
4
|
const getMulticallAddress = async (client, chainId) => {
|
|
6
|
-
|
|
7
|
-
return chains?.find((chain) => chain.id === chainId && chain.chainType === sdk_1.ChainType.TVM)?.multicallAddress;
|
|
5
|
+
return (await client.getChains())?.find((chain) => chain.id === chainId && chain.chainType === _lifi_sdk.ChainType.TVM)?.multicallAddress;
|
|
8
6
|
};
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.getMulticallAddress = getMulticallAddress;
|
|
9
|
+
|
|
10
10
|
//# sourceMappingURL=getMulticallAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMulticallAddress.js","
|
|
1
|
+
{"version":3,"file":"getMulticallAddress.js","names":["ChainType"],"sources":["../../../src/actions/getMulticallAddress.ts"],"sourcesContent":["import { type ChainId, ChainType, type SDKClient } from '@lifi/sdk'\n\nexport const getMulticallAddress = async (\n client: SDKClient,\n chainId: ChainId\n): Promise<string | undefined> => {\n const chains = await client.getChains()\n return chains?.find(\n (chain) => chain.id === chainId && chain.chainType === ChainType.TVM\n )?.multicallAddress\n}\n"],"mappings":";;;AAEA,MAAa,sBAAsB,OACjC,QACA,YACgC;CAEhC,QAAO,MADc,OAAO,WAAW,GACxB,MACZ,UAAU,MAAM,OAAO,WAAW,MAAM,cAAcA,UAAAA,UAAU,IAClE,EAAE"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { SDKClient, Token, TokenAmount } from "@lifi/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getTronBalance.d.ts
|
|
4
|
+
declare const getTronBalance: (client: SDKClient, walletAddress: string, tokens: Token[], multicallBatchSize?: number) => Promise<TokenAmount[]>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getTronBalance };
|
|
7
|
+
//# sourceMappingURL=getTronBalance.d.ts.map
|
|
@@ -1,106 +1,92 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const BALANCE_OF_SELECTOR =
|
|
12
|
-
const GET_ETH_BALANCE_SELECTOR =
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (token.chainId !== chainId) {
|
|
21
|
-
console.warn('Requested tokens have to be on the same chain.');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const multicallAddress = await (0, getMulticallAddress_js_1.getMulticallAddress)(client, chainId);
|
|
25
|
-
if (multicallAddress && tokens.length > 1) {
|
|
26
|
-
return getTronBalanceMulticall(client, tokens, walletAddress, multicallAddress, multicallBatchSize);
|
|
27
|
-
}
|
|
28
|
-
return getTronBalanceDefault(client, tokens, walletAddress);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../core/constants.js");
|
|
3
|
+
const require_rpc_callTronRpcsWithRetry = require("../rpc/callTronRpcsWithRetry.js");
|
|
4
|
+
const require_utils_address = require("../utils/address.js");
|
|
5
|
+
const require_utils_isZeroAddress = require("../utils/isZeroAddress.js");
|
|
6
|
+
const require_utils_multicall3Abi = require("../utils/multicall3Abi.js");
|
|
7
|
+
const require_actions_getMulticallAddress = require("./getMulticallAddress.js");
|
|
8
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
9
|
+
let tronweb = require("tronweb");
|
|
10
|
+
//#region src/actions/getTronBalance.ts
|
|
11
|
+
const BALANCE_OF_SELECTOR = tronweb.TronWeb.sha3("balanceOf(address)").slice(2, 10);
|
|
12
|
+
const GET_ETH_BALANCE_SELECTOR = tronweb.TronWeb.sha3("getEthBalance(address)").slice(2, 10);
|
|
13
|
+
const getTronBalance = async (client, walletAddress, tokens, multicallBatchSize = 50) => {
|
|
14
|
+
if (tokens.length === 0) return [];
|
|
15
|
+
const { chainId } = tokens[0];
|
|
16
|
+
for (const token of tokens) if (token.chainId !== chainId) console.warn("Requested tokens have to be on the same chain.");
|
|
17
|
+
const multicallAddress = await require_actions_getMulticallAddress.getMulticallAddress(client, chainId);
|
|
18
|
+
if (multicallAddress && tokens.length > 1) return getTronBalanceMulticall(client, tokens, walletAddress, multicallAddress, multicallBatchSize);
|
|
19
|
+
return getTronBalanceDefault(client, tokens, walletAddress);
|
|
29
20
|
};
|
|
30
|
-
exports.getTronBalance = getTronBalance;
|
|
31
21
|
const getTronBalanceMulticall = async (client, tokens, walletAddress, multicallAddress, batchSize) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
22
|
+
const walletHex = require_utils_address.toEvmHex(walletAddress);
|
|
23
|
+
const multicallHex = require_utils_address.toEvmHex(multicallAddress);
|
|
24
|
+
const [blockNumber, results] = await require_rpc_callTronRpcsWithRetry.callTronRpcsWithRetry(client, async (tronWeb) => {
|
|
25
|
+
const contract = tronWeb.contract(require_utils_multicall3Abi.multicall3Abi, multicallAddress);
|
|
26
|
+
const allCalls = tokens.map((token) => {
|
|
27
|
+
const isNative = require_utils_isZeroAddress.isZeroAddress(token.address);
|
|
28
|
+
return [
|
|
29
|
+
isNative ? multicallHex : require_utils_address.toEvmHex(token.address),
|
|
30
|
+
true,
|
|
31
|
+
require_utils_address.encodeAddressCalldata(isNative ? GET_ETH_BALANCE_SELECTOR : BALANCE_OF_SELECTOR, walletHex)
|
|
32
|
+
];
|
|
33
|
+
});
|
|
34
|
+
const batches = [];
|
|
35
|
+
for (let i = 0; i < allCalls.length; i += batchSize) batches.push(allCalls.slice(i, i + batchSize));
|
|
36
|
+
const [block, ...batchResults] = await Promise.all([tronWeb.trx.getCurrentBlock(), ...batches.map((batch, idx) => contract.aggregate3(batch).call({ from: walletAddress }).then((r) => r[0]).catch((error) => {
|
|
37
|
+
console.warn(`[getTronBalance] batch ${idx + 1}/${batches.length} failed:`, error.message);
|
|
38
|
+
return batch.map(() => [false, "0x"]);
|
|
39
|
+
}))]);
|
|
40
|
+
const blockNumber = block.block_header?.raw_data?.number;
|
|
41
|
+
return [blockNumber !== void 0 ? BigInt(blockNumber) : void 0, batchResults.flat()];
|
|
42
|
+
});
|
|
43
|
+
return tokens.map((token, i) => {
|
|
44
|
+
const entry = results[i];
|
|
45
|
+
if (!entry) return {
|
|
46
|
+
...token,
|
|
47
|
+
blockNumber
|
|
48
|
+
};
|
|
49
|
+
const [success, returnData] = entry;
|
|
50
|
+
if (!success) return {
|
|
51
|
+
...token,
|
|
52
|
+
blockNumber
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
...token,
|
|
56
|
+
amount: BigInt(returnData),
|
|
57
|
+
blockNumber
|
|
58
|
+
};
|
|
59
|
+
});
|
|
71
60
|
};
|
|
72
61
|
const getTronBalanceDefault = async (client, tokens, walletAddress) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (result.status === 'rejected') {
|
|
100
|
-
return { ...token, blockNumber };
|
|
101
|
-
}
|
|
102
|
-
return { ...token, amount: result.value, blockNumber };
|
|
103
|
-
});
|
|
104
|
-
return tokenAmounts;
|
|
62
|
+
const [blockNumber, results] = await require_rpc_callTronRpcsWithRetry.callTronRpcsWithRetry(client, async (tronWeb) => {
|
|
63
|
+
const host = tronWeb.fullNode.host;
|
|
64
|
+
const queue = tokens.map((token) => {
|
|
65
|
+
if (require_utils_isZeroAddress.isZeroAddress(token.address)) return (0, _lifi_sdk.withDedupe)(async () => BigInt(await tronWeb.trx.getBalance(walletAddress)), { id: `${getTronBalanceDefault.name}.getBalance.${host}` });
|
|
66
|
+
return (0, _lifi_sdk.withDedupe)(async () => {
|
|
67
|
+
const balance = await (await tronWeb.contract().at(token.address)).balanceOf(walletAddress).call({ from: walletAddress });
|
|
68
|
+
return BigInt(balance.toString());
|
|
69
|
+
}, { id: `${getTronBalanceDefault.name}.balanceOf.${token.address}.${host}` });
|
|
70
|
+
});
|
|
71
|
+
return Promise.all([(0, _lifi_sdk.withDedupe)(async () => {
|
|
72
|
+
const n = (await tronWeb.trx.getCurrentBlock()).block_header?.raw_data?.number;
|
|
73
|
+
return n !== void 0 ? BigInt(n) : void 0;
|
|
74
|
+
}, { id: `${getTronBalanceDefault.name}.getCurrentBlock.${host}` }), Promise.allSettled(queue)]);
|
|
75
|
+
});
|
|
76
|
+
return tokens.map((token, index) => {
|
|
77
|
+
const result = results[index];
|
|
78
|
+
if (result.status === "rejected") return {
|
|
79
|
+
...token,
|
|
80
|
+
blockNumber
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
...token,
|
|
84
|
+
amount: result.value,
|
|
85
|
+
blockNumber
|
|
86
|
+
};
|
|
87
|
+
});
|
|
105
88
|
};
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.getTronBalance = getTronBalance;
|
|
91
|
+
|
|
106
92
|
//# sourceMappingURL=getTronBalance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTronBalance.js","
|
|
1
|
+
{"version":3,"file":"getTronBalance.js","names":["TronWeb","getMulticallAddress","toEvmHex","callTronRpcsWithRetry","multicall3Abi","isZeroAddress","encodeAddressCalldata"],"sources":["../../../src/actions/getTronBalance.ts"],"sourcesContent":["import type { SDKClient, Token, TokenAmount } from '@lifi/sdk'\nimport { withDedupe } from '@lifi/sdk'\nimport { TronWeb } from 'tronweb'\nimport { DEFAULT_MULTICALL_BATCH_SIZE } from '../core/constants.js'\nimport { callTronRpcsWithRetry } from '../rpc/callTronRpcsWithRetry.js'\nimport { encodeAddressCalldata, toEvmHex } from '../utils/address.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { multicall3Abi } from '../utils/multicall3Abi.js'\nimport { getMulticallAddress } from './getMulticallAddress.js'\n\nconst BALANCE_OF_SELECTOR = TronWeb.sha3('balanceOf(address)').slice(2, 10)\nconst GET_ETH_BALANCE_SELECTOR = TronWeb.sha3('getEthBalance(address)').slice(\n 2,\n 10\n)\n\nexport const getTronBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[],\n multicallBatchSize: number = DEFAULT_MULTICALL_BATCH_SIZE\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n\n const multicallAddress = await getMulticallAddress(client, chainId)\n\n if (multicallAddress && tokens.length > 1) {\n return getTronBalanceMulticall(\n client,\n tokens,\n walletAddress,\n multicallAddress,\n multicallBatchSize\n )\n }\n\n return getTronBalanceDefault(client, tokens, walletAddress)\n}\n\nconst getTronBalanceMulticall = async (\n client: SDKClient,\n tokens: Token[],\n walletAddress: string,\n multicallAddress: string,\n batchSize: number\n): Promise<TokenAmount[]> => {\n const walletHex = toEvmHex(walletAddress)\n const multicallHex = toEvmHex(multicallAddress)\n\n const [blockNumber, results] = await callTronRpcsWithRetry(\n client,\n async (tronWeb) => {\n const contract = tronWeb.contract(multicall3Abi, multicallAddress)\n\n // TronWeb encodes tuples positionally: [target, allowFailure, callData]\n const allCalls = tokens.map((token) => {\n const isNative = isZeroAddress(token.address)\n return [\n isNative ? multicallHex : toEvmHex(token.address),\n true,\n encodeAddressCalldata(\n isNative ? GET_ETH_BALANCE_SELECTOR : BALANCE_OF_SELECTOR,\n walletHex\n ),\n ]\n })\n\n // Chunk calls to avoid CPU timeout on Tron nodes\n const batches: (typeof allCalls)[] = []\n for (let i = 0; i < allCalls.length; i += batchSize) {\n batches.push(allCalls.slice(i, i + batchSize))\n }\n\n const [block, ...batchResults] = await Promise.all([\n tronWeb.trx.getCurrentBlock(),\n ...batches.map((batch, idx) =>\n contract\n .aggregate3(batch)\n .call({ from: walletAddress })\n // TronWeb wraps the single return value in an extra array\n .then((r: unknown[]) => r[0] as Array<[boolean, string]>)\n .catch((error: Error) => {\n console.warn(\n `[getTronBalance] batch ${idx + 1}/${batches.length} failed:`,\n error.message\n )\n return batch.map(() => [false, '0x'] as [boolean, string])\n })\n ),\n ])\n\n const blockNumber = block.block_header?.raw_data?.number\n return [\n blockNumber !== undefined ? BigInt(blockNumber) : undefined,\n batchResults.flat(),\n ]\n }\n )\n\n return tokens.map((token, i) => {\n // Guard against an unexpected length mismatch between tokens and flattened batch results.\n const entry = results[i] as [boolean, string] | undefined\n if (!entry) {\n return { ...token, blockNumber }\n }\n const [success, returnData] = entry\n if (!success) {\n // RPC failure: amount is omitted (undefined)\n // Consumers must treat a missing amount as \"balance unavailable\", not zero.\n return { ...token, blockNumber }\n }\n return { ...token, amount: BigInt(returnData), blockNumber }\n })\n}\n\nconst getTronBalanceDefault = async (\n client: SDKClient,\n tokens: Token[],\n walletAddress: string\n): Promise<TokenAmount[]> => {\n const [blockNumber, results] = await callTronRpcsWithRetry(\n client,\n async (tronWeb) => {\n const host = tronWeb.fullNode.host\n const queue: Promise<bigint>[] = tokens.map((token) => {\n if (isZeroAddress(token.address)) {\n return withDedupe(\n async () => BigInt(await tronWeb.trx.getBalance(walletAddress)),\n { id: `${getTronBalanceDefault.name}.getBalance.${host}` }\n )\n }\n return withDedupe(\n async () => {\n const contract = await tronWeb.contract().at(token.address)\n const balance = await contract\n .balanceOf(walletAddress)\n .call({ from: walletAddress })\n return BigInt(balance.toString())\n },\n {\n id: `${getTronBalanceDefault.name}.balanceOf.${token.address}.${host}`,\n }\n )\n })\n\n return Promise.all([\n withDedupe(\n async (): Promise<bigint | undefined> => {\n const block = await tronWeb.trx.getCurrentBlock()\n const n = block.block_header?.raw_data?.number\n return n !== undefined ? BigInt(n) : undefined\n },\n { id: `${getTronBalanceDefault.name}.getCurrentBlock.${host}` }\n ),\n Promise.allSettled(queue),\n ])\n }\n )\n\n const tokenAmounts: TokenAmount[] = tokens.map((token, index) => {\n const result = results[index]\n if (result.status === 'rejected') {\n // RPC failure: amount is omitted (undefined), matching getSolanaBalance's contract.\n // Consumers must treat a missing amount as \"balance unavailable\", not zero.\n return { ...token, blockNumber }\n }\n return { ...token, amount: result.value, blockNumber }\n })\n\n return tokenAmounts\n}\n"],"mappings":"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"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/actions/resolveTronAddress.d.ts
|
|
2
|
+
declare function resolveTronAddress(name: string): Promise<string>;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { resolveTronAddress };
|
|
5
|
+
//# sourceMappingURL=resolveTronAddress.d.ts.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
exports.resolveTronAddress = resolveTronAddress;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/actions/resolveTronAddress.ts
|
|
4
3
|
async function resolveTronAddress(name) {
|
|
5
|
-
|
|
4
|
+
return name;
|
|
6
5
|
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.resolveTronAddress = resolveTronAddress;
|
|
8
|
+
|
|
7
9
|
//# sourceMappingURL=resolveTronAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTronAddress.js","
|
|
1
|
+
{"version":3,"file":"resolveTronAddress.js","names":[],"sources":["../../../src/actions/resolveTronAddress.ts"],"sourcesContent":["export async function resolveTronAddress(name: string): Promise<string> {\n // Tron does not have a name service, return the address as-is\n return name\n}\n"],"mappings":";;AAAA,eAAsB,mBAAmB,MAA+B;CAEtE,OAAO"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { TronStepExecutorContext, TronStepExecutorOptions } from "../types.js";
|
|
2
|
+
import { BaseStepExecutor, ExecutionAction, LiFiStepExtended, SDKError, StepExecutorBaseContext, TaskPipeline } from "@lifi/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/core/TronStepExecutor.d.ts
|
|
5
|
+
declare class TronStepExecutor extends BaseStepExecutor {
|
|
6
|
+
private wallet;
|
|
7
|
+
constructor(options: TronStepExecutorOptions);
|
|
8
|
+
checkWallet: (step: LiFiStepExtended) => void;
|
|
9
|
+
override parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
|
|
10
|
+
override createContext: (baseContext: StepExecutorBaseContext) => Promise<TronStepExecutorContext>;
|
|
11
|
+
override createPipeline: (context: TronStepExecutorContext) => TaskPipeline;
|
|
10
12
|
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TronStepExecutor };
|
|
15
|
+
//# sourceMappingURL=TronStepExecutor.d.ts.map
|
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
taskName = TronCheckAllowanceTask_js_1.TronCheckAllowanceTask.name;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
taskName =
|
|
54
|
-
swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'
|
|
55
|
-
? sdk_1.WaitForTransactionStatusTask.name
|
|
56
|
-
: sdk_1.CheckBalanceTask.name;
|
|
57
|
-
}
|
|
58
|
-
const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
|
|
59
|
-
const tasksToRun = tasks.slice(firstTaskIndex);
|
|
60
|
-
return new sdk_1.TaskPipeline(tasksToRun);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_isZeroAddress = require("../utils/isZeroAddress.js");
|
|
3
|
+
const require_errors_parseTronErrors = require("../errors/parseTronErrors.js");
|
|
4
|
+
const require_core_tasks_TronCheckAllowanceTask = require("./tasks/TronCheckAllowanceTask.js");
|
|
5
|
+
const require_core_tasks_TronSetAllowanceTask = require("./tasks/TronSetAllowanceTask.js");
|
|
6
|
+
const require_core_tasks_TronSignAndExecuteTask = require("./tasks/TronSignAndExecuteTask.js");
|
|
7
|
+
const require_core_tasks_TronWaitForTransactionTask = require("./tasks/TronWaitForTransactionTask.js");
|
|
8
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
9
|
+
//#region src/core/TronStepExecutor.ts
|
|
10
|
+
var TronStepExecutor = class extends _lifi_sdk.BaseStepExecutor {
|
|
11
|
+
wallet;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this.wallet = options.wallet;
|
|
15
|
+
}
|
|
16
|
+
checkWallet = (step) => {
|
|
17
|
+
const address = this.wallet.address;
|
|
18
|
+
if (address && address !== step.action.fromAddress) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.WalletChangedDuringExecution, "The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.");
|
|
19
|
+
};
|
|
20
|
+
parseErrors = (error, step, action) => require_errors_parseTronErrors.parseTronErrors(error, step, action);
|
|
21
|
+
createContext = async (baseContext) => {
|
|
22
|
+
return {
|
|
23
|
+
...baseContext,
|
|
24
|
+
wallet: this.wallet,
|
|
25
|
+
checkWallet: this.checkWallet
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
createPipeline = (context) => {
|
|
29
|
+
const { step, isBridgeExecution } = context;
|
|
30
|
+
const isFromNativeToken = require_utils_isZeroAddress.isZeroAddress(step.action.fromToken.address);
|
|
31
|
+
const tasks = [
|
|
32
|
+
new require_core_tasks_TronCheckAllowanceTask.TronCheckAllowanceTask(),
|
|
33
|
+
new require_core_tasks_TronSetAllowanceTask.TronSetAllowanceTask(),
|
|
34
|
+
new _lifi_sdk.CheckBalanceTask(),
|
|
35
|
+
new _lifi_sdk.PrepareTransactionTask(),
|
|
36
|
+
new require_core_tasks_TronSignAndExecuteTask.TronSignAndExecuteTask(),
|
|
37
|
+
new require_core_tasks_TronWaitForTransactionTask.TronWaitForTransactionTask(),
|
|
38
|
+
new _lifi_sdk.WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
|
|
39
|
+
];
|
|
40
|
+
const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
41
|
+
const doCheckAllowance = !swapOrBridgeAction?.txHash && !isFromNativeToken && !!step.estimate.approvalAddress && !step.estimate.skipApproval;
|
|
42
|
+
let taskName;
|
|
43
|
+
if (doCheckAllowance) taskName = require_core_tasks_TronCheckAllowanceTask.TronCheckAllowanceTask.name;
|
|
44
|
+
else taskName = swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === "DONE" ? _lifi_sdk.WaitForTransactionStatusTask.name : _lifi_sdk.CheckBalanceTask.name;
|
|
45
|
+
const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
|
|
46
|
+
return new _lifi_sdk.TaskPipeline(tasks.slice(firstTaskIndex));
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
63
50
|
exports.TronStepExecutor = TronStepExecutor;
|
|
51
|
+
|
|
64
52
|
//# sourceMappingURL=TronStepExecutor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronStepExecutor.js","
|
|
1
|
+
{"version":3,"file":"TronStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","parseTronErrors","isZeroAddress","TronCheckAllowanceTask","TronSetAllowanceTask","CheckBalanceTask","PrepareTransactionTask","TronSignAndExecuteTask","TronWaitForTransactionTask","WaitForTransactionStatusTask","TaskPipeline"],"sources":["../../../src/core/TronStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Adapter } from '@tronweb3/tronwallet-abstract-adapter'\nimport { parseTronErrors } from '../errors/parseTronErrors.js'\nimport type {\n TronStepExecutorContext,\n TronStepExecutorOptions,\n} from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'\nimport { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'\nimport { TronWaitForTransactionTask } from './tasks/TronWaitForTransactionTask.js'\n\nexport class TronStepExecutor extends BaseStepExecutor {\n private wallet: Adapter\n\n constructor(options: TronStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n const address = this.wallet.address\n if (address && address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseTronErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<TronStepExecutorContext> => {\n return {\n ...baseContext,\n wallet: this.wallet,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: TronStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const isFromNativeToken = isZeroAddress(step.action.fromToken.address)\n\n const tasks = [\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new TronSignAndExecuteTask(),\n new TronWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const doCheckAllowance =\n !swapOrBridgeAction?.txHash &&\n !isFromNativeToken &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n\n let taskName: string\n if (doCheckAllowance) {\n taskName = TronCheckAllowanceTask.name\n } else {\n taskName =\n swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : CheckBalanceTask.name\n }\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,IAAa,mBAAb,cAAsCA,UAAAA,iBAAiB;CACrD;CAEA,YAAY,SAAkC;EAC5C,MAAM,QAAQ;EACd,KAAK,SAAS,QAAQ;;CAGxB,eAAe,SAAiC;EAC9C,MAAM,UAAU,KAAK,OAAO;EAC5B,IAAI,WAAW,YAAY,KAAK,OAAO,aACrC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,oHACD;;CAIL,eACE,OACA,MACA,WACsBC,+BAAAA,gBAAgB,OAAO,MAAM,OAAO;CAE5D,gBAAyB,OACvB,gBACqC;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,aAAa,KAAK;GACnB;;CAGH,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,oBAAoBC,4BAAAA,cAAc,KAAK,OAAO,UAAU,QAAQ;EAEtE,MAAM,QAAQ;GACZ,IAAIC,0CAAAA,wBAAwB;GAC5B,IAAIC,wCAAAA,sBAAsB;GAC1B,IAAIC,UAAAA,kBAAkB;GACtB,IAAIC,UAAAA,wBAAwB;GAC5B,IAAIC,0CAAAA,wBAAwB;GAC5B,IAAIC,8CAAAA,4BAA4B;GAChC,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,OACzC;GACF;EAED,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,mBACJ,CAAC,oBAAoB,UACrB,CAAC,qBACD,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;EAEjB,IAAI;EACJ,IAAI,kBACF,WAAWN,0CAAAA,uBAAuB;OAElC,WACE,oBAAoB,UAAU,oBAAoB,WAAW,SACzDM,UAAAA,6BAA6B,OAC7BJ,UAAAA,iBAAiB;EAGzB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,SACrC;EAID,OAAO,IAAIK,UAAAA,aAFQ,MAAM,MAAM,eAEG,CAAC"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/core/constants.d.ts
|
|
2
|
+
declare const TRON_POLL_INTERVAL_MS = 3e3;
|
|
3
|
+
declare const TRON_POLL_MAX_POLLS = 40;
|
|
4
|
+
declare const TRON_POLL_MAX_ERROR_RETRIES = 5;
|
|
5
|
+
declare const DEFAULT_MULTICALL_BATCH_SIZE = 50;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { DEFAULT_MULTICALL_BATCH_SIZE, TRON_POLL_INTERVAL_MS, TRON_POLL_MAX_ERROR_RETRIES, TRON_POLL_MAX_POLLS };
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|