@lifi/sdk-provider-tron 4.0.9 → 4.1.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/CHANGELOG.md +21 -0
- package/dist/cjs/TronProvider.d.ts +1 -2
- package/dist/cjs/TronProvider.js +3 -1
- package/dist/cjs/TronProvider.js.map +1 -1
- package/dist/cjs/actions/getMulticallAddress.d.ts +1 -2
- package/dist/cjs/actions/getTronBalance.d.ts +1 -2
- package/dist/cjs/actions/resolveTronAddress.d.ts +1 -2
- package/dist/cjs/core/TronStepExecutor.d.ts +1 -2
- package/dist/cjs/core/constants.d.ts +4 -5
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.d.ts +1 -2
- package/dist/cjs/core/tasks/TronSetAllowanceTask.d.ts +1 -2
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js +1 -1
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.d.ts +1 -2
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.d.ts +1 -2
- package/dist/cjs/errors/parseTronErrors.d.ts +1 -2
- package/dist/cjs/rpc/callTronRpcsWithRetry.d.ts +2 -3
- package/dist/cjs/rpc/waitForTronTxConfirmation.d.ts +7 -8
- package/dist/cjs/rpc/waitForTronTxConfirmation.js +18 -11
- package/dist/cjs/rpc/waitForTronTxConfirmation.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -7
- package/dist/cjs/utils/address.d.ts +2 -3
- package/dist/cjs/utils/getTronTxLink.d.ts +1 -2
- package/dist/cjs/utils/isZeroAddress.d.ts +3 -4
- package/dist/cjs/utils/multicall3Abi.d.ts +1 -2
- package/dist/cjs/utils/stripHexPrefix.d.ts +1 -2
- package/dist/cjs/version.d.ts +2 -3
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/TronProvider.d.ts +1 -2
- package/dist/esm/TronProvider.d.ts.map +1 -1
- package/dist/esm/TronProvider.js +3 -1
- package/dist/esm/TronProvider.js.map +1 -1
- package/dist/esm/actions/getMulticallAddress.d.ts +1 -2
- package/dist/esm/actions/getMulticallAddress.d.ts.map +1 -1
- package/dist/esm/actions/getTronBalance.d.ts +1 -2
- package/dist/esm/actions/getTronBalance.d.ts.map +1 -1
- package/dist/esm/actions/resolveTronAddress.d.ts +1 -2
- package/dist/esm/actions/resolveTronAddress.d.ts.map +1 -1
- package/dist/esm/core/TronStepExecutor.d.ts +1 -2
- package/dist/esm/core/TronStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/constants.d.ts +4 -5
- package/dist/esm/core/constants.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts +1 -2
- package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronSetAllowanceTask.d.ts +1 -2
- package/dist/esm/core/tasks/TronSetAllowanceTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronSetAllowanceTask.js +1 -1
- package/dist/esm/core/tasks/TronSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts +1 -2
- package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts +1 -2
- package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/errors/parseTronErrors.d.ts +1 -2
- package/dist/esm/errors/parseTronErrors.d.ts.map +1 -1
- package/dist/esm/rpc/callTronRpcsWithRetry.d.ts +2 -3
- package/dist/esm/rpc/callTronRpcsWithRetry.d.ts.map +1 -1
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts +7 -8
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts.map +1 -1
- package/dist/esm/rpc/waitForTronTxConfirmation.js +18 -11
- package/dist/esm/rpc/waitForTronTxConfirmation.js.map +1 -1
- package/dist/esm/types.d.ts +6 -7
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utils/address.d.ts +2 -3
- package/dist/esm/utils/address.d.ts.map +1 -1
- package/dist/esm/utils/getTronTxLink.d.ts +1 -2
- package/dist/esm/utils/getTronTxLink.d.ts.map +1 -1
- package/dist/esm/utils/isZeroAddress.d.ts +3 -4
- package/dist/esm/utils/isZeroAddress.d.ts.map +1 -1
- package/dist/esm/utils/multicall3Abi.d.ts +1 -2
- package/dist/esm/utils/multicall3Abi.d.ts.map +1 -1
- package/dist/esm/utils/stripHexPrefix.d.ts +1 -2
- package/dist/esm/utils/stripHexPrefix.d.ts.map +1 -1
- package/dist/esm/version.d.ts +2 -3
- package/dist/esm/version.d.ts.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/TronProvider.ts +4 -1
- package/src/core/tasks/TronSetAllowanceTask.ts +1 -1
- package/src/rpc/waitForTronTxConfirmation.ts +41 -16
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronSetAllowanceTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronSetAllowanceTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TronSetAllowanceTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronSetAllowanceTask.ts"],"mappings":";;;qBAea,6BAA6B;WACzB,UAAU,SAAS,0BAA0B;EAI5D,IAAU,SAAS,0BAA0B,QAAQ"}
|
|
@@ -50,7 +50,7 @@ var TronSetAllowanceTask = class extends BaseStepExecutionTask {
|
|
|
50
50
|
txHash,
|
|
51
51
|
txLink: getTronTxLink(fromChain, txHash)
|
|
52
52
|
});
|
|
53
|
-
await waitForTronTxConfirmation(client, txHash, "Approval transaction failed on-chain
|
|
53
|
+
await waitForTronTxConfirmation(client, txHash, "Approval transaction failed on-chain");
|
|
54
54
|
statusManager.updateAction(step, action.type, "DONE", {
|
|
55
55
|
txHash,
|
|
56
56
|
txLink: getTronTxLink(fromChain, txHash)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronSetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/TronSetAllowanceTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { callTronRpcsWithRetry } from '../../rpc/callTronRpcsWithRetry.js'\nimport { waitForTronTxConfirmation } from '../../rpc/waitForTronTxConfirmation.js'\nimport type { TronStepExecutorContext } from '../../types.js'\nimport { getTronTxLink } from '../../utils/getTronTxLink.js'\nimport { stripHexPrefix } from '../../utils/stripHexPrefix.js'\n\n// 100 TRX in sun (1 TRX = 1_000_000 sun) — generous default for TRC-20 approve calls.\nconst DEFAULT_APPROVE_FEE_LIMIT = 100_000_000\n\nexport class TronSetAllowanceTask extends BaseStepExecutionTask {\n override async shouldRun(context: TronStepExecutorContext): Promise<boolean> {\n return !context.hasSufficientAllowance\n }\n\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n const { step, client, wallet, statusManager, fromChain } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'SET_ALLOWANCE',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!wallet.address) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'Wallet address is not available. Wallet may have been disconnected.'\n )\n }\n\n if (!step.estimate.approvalAddress) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Approval address is not available.'\n )\n }\n\n const tokenAddress = step.action.fromToken.address\n const spenderAddress = step.estimate.approvalAddress\n const ownerAddress = wallet.address\n const approveAmount = BigInt(step.action.fromAmount).toString()\n\n const approveGasCost = step.estimate.gasCosts?.find(\n (gc) => gc.type === 'APPROVE'\n )\n const parsedLimit = approveGasCost?.limit ? Number(approveGasCost.limit) : 0\n if (\n approveGasCost?.limit &&\n (!Number.isFinite(parsedLimit) || parsedLimit <= 0)\n ) {\n console.warn(\n '[TronSetAllowanceTask] Invalid fee limit estimate, using default:',\n approveGasCost.limit\n )\n }\n const feeLimit = parsedLimit > 0 ? parsedLimit : DEFAULT_APPROVE_FEE_LIMIT\n\n const transaction = await callTronRpcsWithRetry(client, async (tronWeb) => {\n const { transaction } =\n await tronWeb.transactionBuilder.triggerSmartContract(\n tokenAddress,\n 'approve(address,uint256)',\n { feeLimit },\n [\n { type: 'address', value: spenderAddress },\n { type: 'uint256', value: approveAmount },\n ],\n ownerAddress\n )\n return transaction\n })\n\n const signedTransaction = await wallet.signTransaction(transaction)\n\n statusManager.updateAction(step, action.type, 'PENDING')\n\n const broadcastResult = await callTronRpcsWithRetry(\n client,\n async (tronWeb) => {\n const result = await tronWeb.trx.sendRawTransaction(signedTransaction)\n\n if (!result.result && String(result.code) !== 'DUP_TRANSACTION_ERROR') {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Approval broadcast failed: ${result.code || 'Unknown error'}`\n )\n }\n\n return result\n }\n )\n\n // DUP_TRANSACTION_ERROR responses omit the `transaction` field — fall back\n // to the txID computed locally from the signed transaction in that case.\n const txHash = stripHexPrefix(\n broadcastResult.transaction?.txID ?? signedTransaction.txID\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash,\n txLink: getTronTxLink(fromChain, txHash),\n })\n\n await waitForTronTxConfirmation(\n client,\n txHash,\n 'Approval transaction failed on-chain
|
|
1
|
+
{"version":3,"file":"TronSetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/TronSetAllowanceTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { callTronRpcsWithRetry } from '../../rpc/callTronRpcsWithRetry.js'\nimport { waitForTronTxConfirmation } from '../../rpc/waitForTronTxConfirmation.js'\nimport type { TronStepExecutorContext } from '../../types.js'\nimport { getTronTxLink } from '../../utils/getTronTxLink.js'\nimport { stripHexPrefix } from '../../utils/stripHexPrefix.js'\n\n// 100 TRX in sun (1 TRX = 1_000_000 sun) — generous default for TRC-20 approve calls.\nconst DEFAULT_APPROVE_FEE_LIMIT = 100_000_000\n\nexport class TronSetAllowanceTask extends BaseStepExecutionTask {\n override async shouldRun(context: TronStepExecutorContext): Promise<boolean> {\n return !context.hasSufficientAllowance\n }\n\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n const { step, client, wallet, statusManager, fromChain } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'SET_ALLOWANCE',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!wallet.address) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'Wallet address is not available. Wallet may have been disconnected.'\n )\n }\n\n if (!step.estimate.approvalAddress) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Approval address is not available.'\n )\n }\n\n const tokenAddress = step.action.fromToken.address\n const spenderAddress = step.estimate.approvalAddress\n const ownerAddress = wallet.address\n const approveAmount = BigInt(step.action.fromAmount).toString()\n\n const approveGasCost = step.estimate.gasCosts?.find(\n (gc) => gc.type === 'APPROVE'\n )\n const parsedLimit = approveGasCost?.limit ? Number(approveGasCost.limit) : 0\n if (\n approveGasCost?.limit &&\n (!Number.isFinite(parsedLimit) || parsedLimit <= 0)\n ) {\n console.warn(\n '[TronSetAllowanceTask] Invalid fee limit estimate, using default:',\n approveGasCost.limit\n )\n }\n const feeLimit = parsedLimit > 0 ? parsedLimit : DEFAULT_APPROVE_FEE_LIMIT\n\n const transaction = await callTronRpcsWithRetry(client, async (tronWeb) => {\n const { transaction } =\n await tronWeb.transactionBuilder.triggerSmartContract(\n tokenAddress,\n 'approve(address,uint256)',\n { feeLimit },\n [\n { type: 'address', value: spenderAddress },\n { type: 'uint256', value: approveAmount },\n ],\n ownerAddress\n )\n return transaction\n })\n\n const signedTransaction = await wallet.signTransaction(transaction)\n\n statusManager.updateAction(step, action.type, 'PENDING')\n\n const broadcastResult = await callTronRpcsWithRetry(\n client,\n async (tronWeb) => {\n const result = await tronWeb.trx.sendRawTransaction(signedTransaction)\n\n if (!result.result && String(result.code) !== 'DUP_TRANSACTION_ERROR') {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Approval broadcast failed: ${result.code || 'Unknown error'}`\n )\n }\n\n return result\n }\n )\n\n // DUP_TRANSACTION_ERROR responses omit the `transaction` field — fall back\n // to the txID computed locally from the signed transaction in that case.\n const txHash = stripHexPrefix(\n broadcastResult.transaction?.txID ?? signedTransaction.txID\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash,\n txLink: getTronTxLink(fromChain, txHash),\n })\n\n await waitForTronTxConfirmation(\n client,\n txHash,\n 'Approval transaction failed on-chain'\n )\n\n statusManager.updateAction(step, action.type, 'DONE', {\n txHash,\n txLink: getTronTxLink(fromChain, txHash),\n })\n\n return {\n status: 'COMPLETED',\n context: { hasSufficientAllowance: true },\n }\n }\n}\n"],"mappings":";;;;;;AAaA,MAAM,4BAA4B;AAElC,IAAa,uBAAb,cAA0C,sBAAsB;CAC9D,MAAe,UAAU,SAAoD;EAC3E,OAAO,CAAC,QAAQ;CAClB;CAEA,MAAM,IAAI,SAAuD;EAC/D,MAAM,EAAE,MAAM,QAAQ,QAAQ,eAAe,cAAc;EAE3D,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;EAE/D,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,iBACR,cAAc,8BACd,qEACF;EAGF,IAAI,CAAC,KAAK,SAAS,iBACjB,MAAM,IAAI,iBACR,cAAc,uBACd,oCACF;EAGF,MAAM,eAAe,KAAK,OAAO,UAAU;EAC3C,MAAM,iBAAiB,KAAK,SAAS;EACrC,MAAM,eAAe,OAAO;EAC5B,MAAM,gBAAgB,OAAO,KAAK,OAAO,UAAU,CAAC,CAAC,SAAS;EAE9D,MAAM,iBAAiB,KAAK,SAAS,UAAU,MAC5C,OAAO,GAAG,SAAS,SACtB;EACA,MAAM,cAAc,gBAAgB,QAAQ,OAAO,eAAe,KAAK,IAAI;EAC3E,IACE,gBAAgB,UACf,CAAC,OAAO,SAAS,WAAW,KAAK,eAAe,IAEjD,QAAQ,KACN,qEACA,eAAe,KACjB;EAEF,MAAM,WAAW,cAAc,IAAI,cAAc;EAEjD,MAAM,cAAc,MAAM,sBAAsB,QAAQ,OAAO,YAAY;GACzE,MAAM,EAAE,gBACN,MAAM,QAAQ,mBAAmB,qBAC/B,cACA,4BACA,EAAE,SAAS,GACX,CACE;IAAE,MAAM;IAAW,OAAO;GAAe,GACzC;IAAE,MAAM;IAAW,OAAO;GAAc,CAC1C,GACA,YACF;GACF,OAAO;EACT,CAAC;EAED,MAAM,oBAAoB,MAAM,OAAO,gBAAgB,WAAW;EAElE,cAAc,aAAa,MAAM,OAAO,MAAM,SAAS;EAEvD,MAAM,kBAAkB,MAAM,sBAC5B,QACA,OAAO,YAAY;GACjB,MAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB,iBAAiB;GAErE,IAAI,CAAC,OAAO,UAAU,OAAO,OAAO,IAAI,MAAM,yBAC5C,MAAM,IAAI,iBACR,cAAc,mBACd,8BAA8B,OAAO,QAAQ,iBAC/C;GAGF,OAAO;EACT,CACF;EAIA,MAAM,SAAS,eACb,gBAAgB,aAAa,QAAQ,kBAAkB,IACzD;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD;GACA,QAAQ,cAAc,WAAW,MAAM;EACzC,CAAC;EAED,MAAM,0BACJ,QACA,QACA,sCACF;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,QAAQ;GACpD;GACA,QAAQ,cAAc,WAAW,MAAM;EACzC,CAAC;EAED,OAAO;GACL,QAAQ;GACR,SAAS,EAAE,wBAAwB,KAAK;EAC1C;CACF;AACF"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TronStepExecutorContext } from "../../types.js";
|
|
2
2
|
import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
|
|
3
3
|
//#region src/core/tasks/TronSignAndExecuteTask.d.ts
|
|
4
|
-
declare class TronSignAndExecuteTask extends BaseStepExecutionTask {
|
|
4
|
+
export declare class TronSignAndExecuteTask extends BaseStepExecutionTask {
|
|
5
5
|
run(context: TronStepExecutorContext): Promise<TaskResult>;
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
|
-
export { TronSignAndExecuteTask };
|
|
9
8
|
//# sourceMappingURL=TronSignAndExecuteTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronSignAndExecuteTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TronSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronSignAndExecuteTask.ts"],"mappings":";;;qBAYa,+BAA+B;EAC1C,IAAU,SAAS,0BAA0B,QAAQ"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TronStepExecutorContext } from "../../types.js";
|
|
2
2
|
import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
|
|
3
3
|
//#region src/core/tasks/TronWaitForTransactionTask.d.ts
|
|
4
|
-
declare class TronWaitForTransactionTask extends BaseStepExecutionTask {
|
|
4
|
+
export declare class TronWaitForTransactionTask extends BaseStepExecutionTask {
|
|
5
5
|
run(context: TronStepExecutorContext): Promise<TaskResult>;
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
|
-
export { TronWaitForTransactionTask };
|
|
9
8
|
//# sourceMappingURL=TronWaitForTransactionTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TronWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronWaitForTransactionTask.ts"],"mappings":";;;qBAYa,mCAAmC;EAC9C,IAAU,SAAS,0BAA0B,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ExecutionAction, LiFiStep, SDKError } from "@lifi/sdk";
|
|
2
2
|
//#region src/errors/parseTronErrors.d.ts
|
|
3
|
-
declare const parseTronErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
|
|
3
|
+
export declare const parseTronErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { parseTronErrors };
|
|
6
5
|
//# sourceMappingURL=parseTronErrors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTronErrors.d.ts","names":[],"sources":["../../../src/errors/parseTronErrors.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"parseTronErrors.d.ts","names":[],"sources":["../../../src/errors/parseTronErrors.ts"],"mappings":";;qBAwBa,kBACX,GAAG,OACH,OAAO,UACP,SAAS,oBACR,QAAQ"}
|
|
@@ -2,8 +2,7 @@ import { LruMap, SDKClient } from "@lifi/sdk";
|
|
|
2
2
|
import { TronWeb } from "tronweb";
|
|
3
3
|
//#region src/rpc/callTronRpcsWithRetry.d.ts
|
|
4
4
|
/** @internal Exposed so unit tests can clear between cases (e.g. `tronWebCache.clear()`). */
|
|
5
|
-
declare const tronWebCache: LruMap<TronWeb>;
|
|
6
|
-
declare function callTronRpcsWithRetry<R>(client: SDKClient, fn: (tronWeb: TronWeb) => Promise<R>): Promise<R>;
|
|
5
|
+
export declare const tronWebCache: LruMap<TronWeb>;
|
|
6
|
+
export declare function callTronRpcsWithRetry<R>(client: SDKClient, fn: (tronWeb: TronWeb) => Promise<R>): Promise<R>;
|
|
7
7
|
//#endregion
|
|
8
|
-
export { callTronRpcsWithRetry, tronWebCache };
|
|
9
8
|
//# sourceMappingURL=callTronRpcsWithRetry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callTronRpcsWithRetry.d.ts","names":[],"sources":["../../../src/rpc/callTronRpcsWithRetry.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"callTronRpcsWithRetry.d.ts","names":[],"sources":["../../../src/rpc/callTronRpcsWithRetry.ts"],"mappings":";;;;qBAIa,cAAc,OAAO;wBAEZ,sBAAsB,GAC1C,QAAQ,WACR,KAAK,SAAS,YAAY,QAAQ,KACjC,QAAQ"}
|
|
@@ -3,14 +3,13 @@ import { SDKClient } from "@lifi/sdk";
|
|
|
3
3
|
/**
|
|
4
4
|
* Polls getTransactionInfo until the transaction is indexed, then resolves.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
* `
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
6
|
+
* Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
|
|
7
|
+
* success) and puts the reason in `receipt.result`; both are checked. Throws
|
|
8
|
+
* `TransactionError` without retry on failure (`InsufficientFunds` for
|
|
9
|
+
* OUT_OF_ENERGY, `TransactionFailed` otherwise). Tolerates up to
|
|
10
|
+
* `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors and caps total polls at
|
|
11
|
+
* `TRON_POLL_MAX_POLLS`, since `waitForResult`'s maxRetries counts errors only.
|
|
12
12
|
*/
|
|
13
|
-
declare function waitForTronTxConfirmation(client: SDKClient, txHash: string, onChainFailureMessage?: string): Promise<void>;
|
|
13
|
+
export declare function waitForTronTxConfirmation(client: SDKClient, txHash: string, onChainFailureMessage?: string): Promise<void>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { waitForTronTxConfirmation };
|
|
16
15
|
//# sourceMappingURL=waitForTronTxConfirmation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForTronTxConfirmation.d.ts","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"waitForTronTxConfirmation.d.ts","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"mappings":";;;;;;;;;;;;wBA6CsB,0BACpB,QAAQ,WACR,gBACA,iCACC"}
|
|
@@ -2,25 +2,32 @@ import { TRON_POLL_INTERVAL_MS } from "../core/constants.js";
|
|
|
2
2
|
import { callTronRpcsWithRetry } from "./callTronRpcsWithRetry.js";
|
|
3
3
|
import { LiFiErrorCode, TransactionError, waitForResult } from "@lifi/sdk";
|
|
4
4
|
//#region src/rpc/waitForTronTxConfirmation.ts
|
|
5
|
+
const NON_FAILURE_CONTRACT_RESULTS = /* @__PURE__ */ new Set(["SUCCESS", "DEFAULT"]);
|
|
6
|
+
function createOnChainFailureError(messageStem, reason) {
|
|
7
|
+
const stem = messageStem.replace(/\.$/, "");
|
|
8
|
+
if (reason === "OUT_OF_ENERGY") return new TransactionError(LiFiErrorCode.InsufficientFunds, `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`);
|
|
9
|
+
return new TransactionError(LiFiErrorCode.TransactionFailed, reason ? `${stem}: ${reason}.` : `${stem}.`);
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
12
|
* Polls getTransactionInfo until the transaction is indexed, then resolves.
|
|
7
13
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
11
|
-
* `
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
14
|
+
* Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
|
|
15
|
+
* success) and puts the reason in `receipt.result`; both are checked. Throws
|
|
16
|
+
* `TransactionError` without retry on failure (`InsufficientFunds` for
|
|
17
|
+
* OUT_OF_ENERGY, `TransactionFailed` otherwise). Tolerates up to
|
|
18
|
+
* `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors and caps total polls at
|
|
19
|
+
* `TRON_POLL_MAX_POLLS`, since `waitForResult`'s maxRetries counts errors only.
|
|
14
20
|
*/
|
|
15
|
-
async function waitForTronTxConfirmation(client, txHash, onChainFailureMessage = "Transaction failed on-chain
|
|
21
|
+
async function waitForTronTxConfirmation(client, txHash, onChainFailureMessage = "Transaction failed on-chain") {
|
|
16
22
|
let polls = 0;
|
|
17
23
|
await waitForResult(async () => {
|
|
18
24
|
if (++polls > 40) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction confirmation timeout.");
|
|
19
25
|
const txInfo = await callTronRpcsWithRetry(client, (tronWeb) => tronWeb.trx.getTransactionInfo(txHash));
|
|
20
|
-
if (txInfo?.id)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
if (!txInfo?.id) return;
|
|
27
|
+
const contractResult = txInfo.receipt?.result;
|
|
28
|
+
const isContractFailure = !!contractResult && !NON_FAILURE_CONTRACT_RESULTS.has(contractResult);
|
|
29
|
+
if (txInfo.result === "FAILED" || isContractFailure) throw createOnChainFailureError(onChainFailureMessage, isContractFailure ? contractResult : void 0);
|
|
30
|
+
return txInfo;
|
|
24
31
|
}, TRON_POLL_INTERVAL_MS, 5, (_count, error) => !(error instanceof TransactionError));
|
|
25
32
|
}
|
|
26
33
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForTronTxConfirmation.js","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"sourcesContent":["import {\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport {\n TRON_POLL_INTERVAL_MS,\n TRON_POLL_MAX_ERROR_RETRIES,\n TRON_POLL_MAX_POLLS,\n} from '../core/constants.js'\nimport { callTronRpcsWithRetry } from './callTronRpcsWithRetry.js'\n\n/**\n * Polls getTransactionInfo until the transaction is indexed, then resolves.\n *\n *
|
|
1
|
+
{"version":3,"file":"waitForTronTxConfirmation.js","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"sourcesContent":["import {\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport {\n TRON_POLL_INTERVAL_MS,\n TRON_POLL_MAX_ERROR_RETRIES,\n TRON_POLL_MAX_POLLS,\n} from '../core/constants.js'\nimport { callTronRpcsWithRetry } from './callTronRpcsWithRetry.js'\n\n// `receipt.result` is java-tron's `Transaction.Result.contractResult` enum. It has\n// no FAILED member: SUCCESS and DEFAULT (enum 0) mean success, anything else is\n// an execution failure (REVERT, OUT_OF_ENERGY, OUT_OF_TIME, …).\nconst NON_FAILURE_CONTRACT_RESULTS = new Set(['SUCCESS', 'DEFAULT'])\n\nfunction createOnChainFailureError(\n messageStem: string,\n reason?: string\n): TransactionError {\n const stem = messageStem.replace(/\\.$/, '')\n if (reason === 'OUT_OF_ENERGY') {\n return new TransactionError(\n LiFiErrorCode.InsufficientFunds,\n `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`\n )\n }\n return new TransactionError(\n LiFiErrorCode.TransactionFailed,\n reason ? `${stem}: ${reason}.` : `${stem}.`\n )\n}\n\n/**\n * Polls getTransactionInfo until the transaction is indexed, then resolves.\n *\n * Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on\n * success) and puts the reason in `receipt.result`; both are checked. Throws\n * `TransactionError` without retry on failure (`InsufficientFunds` for\n * OUT_OF_ENERGY, `TransactionFailed` otherwise). Tolerates up to\n * `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors and caps total polls at\n * `TRON_POLL_MAX_POLLS`, since `waitForResult`'s maxRetries counts errors only.\n */\nexport async function waitForTronTxConfirmation(\n client: SDKClient,\n txHash: string,\n onChainFailureMessage = 'Transaction failed on-chain'\n): Promise<void> {\n let polls = 0\n await waitForResult(\n async () => {\n if (++polls > TRON_POLL_MAX_POLLS) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction confirmation timeout.'\n )\n }\n const txInfo = await callTronRpcsWithRetry(client, (tronWeb) =>\n tronWeb.trx.getTransactionInfo(txHash)\n )\n if (!txInfo?.id) {\n return undefined\n }\n const contractResult = txInfo.receipt?.result\n const isContractFailure =\n !!contractResult && !NON_FAILURE_CONTRACT_RESULTS.has(contractResult)\n if (txInfo.result === 'FAILED' || isContractFailure) {\n throw createOnChainFailureError(\n onChainFailureMessage,\n isContractFailure ? contractResult : undefined\n )\n }\n return txInfo\n },\n TRON_POLL_INTERVAL_MS,\n TRON_POLL_MAX_ERROR_RETRIES,\n (_count, error) => !(error instanceof TransactionError)\n )\n}\n"],"mappings":";;;;AAgBA,MAAM,+CAA+B,IAAI,IAAI,CAAC,WAAW,SAAS,CAAC;AAEnE,SAAS,0BACP,aACA,QACkB;CAClB,MAAM,OAAO,YAAY,QAAQ,OAAO,EAAE;CAC1C,IAAI,WAAW,iBACb,OAAO,IAAI,iBACT,cAAc,mBACd,GAAG,KAAK,IAAI,OAAO,yDACrB;CAEF,OAAO,IAAI,iBACT,cAAc,mBACd,SAAS,GAAG,KAAK,IAAI,OAAO,KAAK,GAAG,KAAK,EAC3C;AACF;;;;;;;;;;;AAYA,eAAsB,0BACpB,QACA,QACA,wBAAwB,+BACT;CACf,IAAI,QAAQ;CACZ,MAAM,cACJ,YAAY;EACV,IAAI,EAAE,QAAA,IACJ,MAAM,IAAI,iBACR,cAAc,mBACd,mCACF;EAEF,MAAM,SAAS,MAAM,sBAAsB,SAAS,YAClD,QAAQ,IAAI,mBAAmB,MAAM,CACvC;EACA,IAAI,CAAC,QAAQ,IACX;EAEF,MAAM,iBAAiB,OAAO,SAAS;EACvC,MAAM,oBACJ,CAAC,CAAC,kBAAkB,CAAC,6BAA6B,IAAI,cAAc;EACtE,IAAI,OAAO,WAAW,YAAY,mBAChC,MAAM,0BACJ,uBACA,oBAAoB,iBAAiB,KAAA,CACvC;EAEF,OAAO;CACT,GACA,uBAAA,IAEC,QAAQ,UAAU,EAAE,iBAAiB,iBACxC;AACF"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { LiFiStepExtended, SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
2
2
|
import { Adapter, SignedTransaction } from "@tronweb3/tronwallet-abstract-adapter";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
interface TronProviderOptions {
|
|
4
|
+
export interface TronProviderOptions {
|
|
5
5
|
getWallet?: () => Promise<Adapter>;
|
|
6
6
|
multicallBatchSize?: number;
|
|
7
7
|
}
|
|
8
|
-
interface TronTaskContext {
|
|
8
|
+
export interface TronTaskContext {
|
|
9
9
|
signedTransaction?: SignedTransaction;
|
|
10
10
|
hasSufficientAllowance?: boolean;
|
|
11
11
|
}
|
|
12
|
-
interface TronStepExecutorContext extends StepExecutorContext, TronTaskContext {
|
|
12
|
+
export interface TronStepExecutorContext extends StepExecutorContext, TronTaskContext {
|
|
13
13
|
wallet: Adapter;
|
|
14
14
|
checkWallet: (step: LiFiStepExtended) => void;
|
|
15
15
|
}
|
|
16
|
-
interface TronSDKProvider extends SDKProvider {
|
|
16
|
+
export interface TronSDKProvider extends SDKProvider {
|
|
17
17
|
setOptions(options: TronProviderOptions): void;
|
|
18
18
|
}
|
|
19
|
-
declare function isTronProvider(provider: SDKProvider): provider is TronSDKProvider;
|
|
20
|
-
interface TronStepExecutorOptions extends StepExecutorOptions {
|
|
19
|
+
export declare function isTronProvider(provider: SDKProvider): provider is TronSDKProvider;
|
|
20
|
+
export interface TronStepExecutorOptions extends StepExecutorOptions {
|
|
21
21
|
wallet: Adapter;
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
|
-
export { TronProviderOptions, TronSDKProvider, TronStepExecutorContext, TronStepExecutorOptions, TronTaskContext, isTronProvider };
|
|
25
24
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;iBAYiB;EACf,kBAAkB,QAAQ;EAC1B;;iBAGe;EACf,oBAAoB;EACpB;;iBAGe,gCACP,qBACN;EACF,QAAQ;EACR,cAAc,MAAM;;iBAGL,wBAAwB;EACvC,WAAW,SAAS;;wBAGN,eACd,UAAU,cACT,YAAY;iBAIE,gCAAgC;EAC/C,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
//#region src/utils/address.d.ts
|
|
2
|
-
declare function toEvmHex(tronAddress: string): string;
|
|
3
|
-
declare function encodeAddressCalldata(selector: string, address: string): string;
|
|
2
|
+
export declare function toEvmHex(tronAddress: string): string;
|
|
3
|
+
export declare function encodeAddressCalldata(selector: string, address: string): string;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { encodeAddressCalldata, toEvmHex };
|
|
6
5
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","names":[],"sources":["../../../src/utils/address.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"address.d.ts","names":[],"sources":["../../../src/utils/address.ts"],"mappings":";wBAIgB,SAAS;wBAQT,sBACd,kBACA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ExtendedChain } from "@lifi/sdk";
|
|
2
2
|
//#region src/utils/getTronTxLink.d.ts
|
|
3
|
-
declare const getTronTxLink: (chain: ExtendedChain, txHash: string) => string | undefined;
|
|
3
|
+
export declare const getTronTxLink: (chain: ExtendedChain, txHash: string) => string | undefined;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { getTronTxLink };
|
|
6
5
|
//# sourceMappingURL=getTronTxLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTronTxLink.d.ts","names":[],"sources":["../../../src/utils/getTronTxLink.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getTronTxLink.d.ts","names":[],"sources":["../../../src/utils/getTronTxLink.ts"],"mappings":";;qBAEa,gBACX,OAAO,eACP"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//#region src/utils/isZeroAddress.d.ts
|
|
2
|
-
declare const AddressZero = "0x0000000000000000000000000000000000000000";
|
|
3
|
-
declare const TronAddressZero = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
4
|
-
declare const isZeroAddress: (address: string) => boolean;
|
|
2
|
+
export declare const AddressZero = "0x0000000000000000000000000000000000000000";
|
|
3
|
+
export declare const TronAddressZero = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
4
|
+
export declare const isZeroAddress: (address: string) => boolean;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { AddressZero, TronAddressZero, isZeroAddress };
|
|
7
6
|
//# sourceMappingURL=isZeroAddress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isZeroAddress.d.ts","names":[],"sources":["../../../src/utils/isZeroAddress.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"isZeroAddress.d.ts","names":[],"sources":["../../../src/utils/isZeroAddress.ts"],"mappings":";qBAAa;qBAGA;qBAEA,gBAAiB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Types } from "tronweb";
|
|
2
2
|
//#region src/utils/multicall3Abi.d.ts
|
|
3
|
-
declare const multicall3Abi: Types.ContractAbiInterface;
|
|
3
|
+
export declare const multicall3Abi: Types.ContractAbiInterface;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { multicall3Abi };
|
|
6
5
|
//# sourceMappingURL=multicall3Abi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multicall3Abi.d.ts","names":[],"sources":["../../../src/utils/multicall3Abi.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"multicall3Abi.d.ts","names":[],"sources":["../../../src/utils/multicall3Abi.ts"],"mappings":";;qBAEa,eAAe,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripHexPrefix.d.ts","names":[],"sources":["../../../src/utils/stripHexPrefix.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"stripHexPrefix.d.ts","names":[],"sources":["../../../src/utils/stripHexPrefix.ts"],"mappings":";qBAAa,iBAAkB"}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
//#region src/version.d.ts
|
|
2
|
-
declare const name = "@lifi/sdk-provider-tron";
|
|
3
|
-
declare const version = "4.0
|
|
2
|
+
export declare const name = "@lifi/sdk-provider-tron";
|
|
3
|
+
export declare const version = "4.1.0";
|
|
4
4
|
//#endregion
|
|
5
|
-
export { name, version };
|
|
6
5
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","names":[],"sources":["../../src/version.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"version.d.ts","names":[],"sources":["../../src/version.ts"],"mappings":";qBAAa;qBACA"}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-tron'\nexport const version = '4.0
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-tron'\nexport const version = '4.1.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-tron",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "LI.FI Tron SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
32
|
-
"@tronweb3/tronwallet-abstract-adapter": "^1.
|
|
31
|
+
"@lifi/sdk": "4.7.0",
|
|
32
|
+
"@tronweb3/tronwallet-abstract-adapter": "^1.3.0",
|
|
33
33
|
"tronweb": "^6.5.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
package/src/TronProvider.ts
CHANGED
|
@@ -10,13 +10,16 @@ import { resolveTronAddress } from './actions/resolveTronAddress.js'
|
|
|
10
10
|
import { TronStepExecutor } from './core/TronStepExecutor.js'
|
|
11
11
|
import type { TronProviderOptions, TronSDKProvider } from './types.js'
|
|
12
12
|
|
|
13
|
+
const isTronAddress = (address: string): boolean => TronWeb.isAddress(address)
|
|
14
|
+
|
|
13
15
|
export function TronProvider(options?: TronProviderOptions): TronSDKProvider {
|
|
14
16
|
const _options: TronProviderOptions = options ?? {}
|
|
15
17
|
return {
|
|
16
18
|
get type() {
|
|
17
19
|
return ChainType.TVM
|
|
18
20
|
},
|
|
19
|
-
isAddress:
|
|
21
|
+
isAddress: isTronAddress,
|
|
22
|
+
isTokenAddress: isTronAddress,
|
|
20
23
|
resolveAddress: resolveTronAddress,
|
|
21
24
|
getBalance: (client, walletAddress, tokens) =>
|
|
22
25
|
getTronBalance(
|
|
@@ -113,7 +113,7 @@ export class TronSetAllowanceTask extends BaseStepExecutionTask {
|
|
|
113
113
|
await waitForTronTxConfirmation(
|
|
114
114
|
client,
|
|
115
115
|
txHash,
|
|
116
|
-
'Approval transaction failed on-chain
|
|
116
|
+
'Approval transaction failed on-chain'
|
|
117
117
|
)
|
|
118
118
|
|
|
119
119
|
statusManager.updateAction(step, action.type, 'DONE', {
|
|
@@ -11,20 +11,42 @@ import {
|
|
|
11
11
|
} from '../core/constants.js'
|
|
12
12
|
import { callTronRpcsWithRetry } from './callTronRpcsWithRetry.js'
|
|
13
13
|
|
|
14
|
+
// `receipt.result` is java-tron's `Transaction.Result.contractResult` enum. It has
|
|
15
|
+
// no FAILED member: SUCCESS and DEFAULT (enum 0) mean success, anything else is
|
|
16
|
+
// an execution failure (REVERT, OUT_OF_ENERGY, OUT_OF_TIME, …).
|
|
17
|
+
const NON_FAILURE_CONTRACT_RESULTS = new Set(['SUCCESS', 'DEFAULT'])
|
|
18
|
+
|
|
19
|
+
function createOnChainFailureError(
|
|
20
|
+
messageStem: string,
|
|
21
|
+
reason?: string
|
|
22
|
+
): TransactionError {
|
|
23
|
+
const stem = messageStem.replace(/\.$/, '')
|
|
24
|
+
if (reason === 'OUT_OF_ENERGY') {
|
|
25
|
+
return new TransactionError(
|
|
26
|
+
LiFiErrorCode.InsufficientFunds,
|
|
27
|
+
`${stem}: ${reason}. The account may need more TRX to cover the energy fee.`
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
return new TransactionError(
|
|
31
|
+
LiFiErrorCode.TransactionFailed,
|
|
32
|
+
reason ? `${stem}: ${reason}.` : `${stem}.`
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
/**
|
|
15
37
|
* Polls getTransactionInfo until the transaction is indexed, then resolves.
|
|
16
38
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* `
|
|
20
|
-
* `
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
39
|
+
* Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
|
|
40
|
+
* success) and puts the reason in `receipt.result`; both are checked. Throws
|
|
41
|
+
* `TransactionError` without retry on failure (`InsufficientFunds` for
|
|
42
|
+
* OUT_OF_ENERGY, `TransactionFailed` otherwise). Tolerates up to
|
|
43
|
+
* `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors and caps total polls at
|
|
44
|
+
* `TRON_POLL_MAX_POLLS`, since `waitForResult`'s maxRetries counts errors only.
|
|
23
45
|
*/
|
|
24
46
|
export async function waitForTronTxConfirmation(
|
|
25
47
|
client: SDKClient,
|
|
26
48
|
txHash: string,
|
|
27
|
-
onChainFailureMessage = 'Transaction failed on-chain
|
|
49
|
+
onChainFailureMessage = 'Transaction failed on-chain'
|
|
28
50
|
): Promise<void> {
|
|
29
51
|
let polls = 0
|
|
30
52
|
await waitForResult(
|
|
@@ -38,16 +60,19 @@ export async function waitForTronTxConfirmation(
|
|
|
38
60
|
const txInfo = await callTronRpcsWithRetry(client, (tronWeb) =>
|
|
39
61
|
tronWeb.trx.getTransactionInfo(txHash)
|
|
40
62
|
)
|
|
41
|
-
if (txInfo?.id) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
if (!txInfo?.id) {
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
66
|
+
const contractResult = txInfo.receipt?.result
|
|
67
|
+
const isContractFailure =
|
|
68
|
+
!!contractResult && !NON_FAILURE_CONTRACT_RESULTS.has(contractResult)
|
|
69
|
+
if (txInfo.result === 'FAILED' || isContractFailure) {
|
|
70
|
+
throw createOnChainFailureError(
|
|
71
|
+
onChainFailureMessage,
|
|
72
|
+
isContractFailure ? contractResult : undefined
|
|
73
|
+
)
|
|
49
74
|
}
|
|
50
|
-
return
|
|
75
|
+
return txInfo
|
|
51
76
|
},
|
|
52
77
|
TRON_POLL_INTERVAL_MS,
|
|
53
78
|
TRON_POLL_MAX_ERROR_RETRIES,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-tron'
|
|
2
|
-
export const version = '4.0
|
|
2
|
+
export const version = '4.1.0'
|