@lifi/sdk-provider-tron 4.0.8 → 4.0.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/CHANGELOG.md +13 -0
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js +1 -1
- package/dist/cjs/core/tasks/TronSetAllowanceTask.js.map +1 -1
- package/dist/cjs/rpc/waitForTronTxConfirmation.d.ts +6 -6
- package/dist/cjs/rpc/waitForTronTxConfirmation.js +18 -11
- package/dist/cjs/rpc/waitForTronTxConfirmation.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.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/rpc/waitForTronTxConfirmation.d.ts +6 -6
- 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/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/core/tasks/TronSetAllowanceTask.ts +1 -1
- package/src/rpc/waitForTronTxConfirmation.ts +41 -16
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lifi/sdk-provider-tron
|
|
2
2
|
|
|
3
|
+
## 4.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#469](https://github.com/lifinance/sdk/pull/469) [`5fd3b74`](https://github.com/lifinance/sdk/commit/5fd3b74f41f64da17c5869e8778b3bc4bd6e470c) Thanks [@chybisov](https://github.com/chybisov)! - Fix failed Tron transactions being reported as confirmed, which also left swap routes polling the status API forever. `waitForTronTxConfirmation` compared `receipt.result` to `FAILED`, a value Tron never emits there; it now checks the top-level `result` and the contract result, so a reverted or out-of-energy approval or swap throws `TransactionFailed` (or `InsufficientFunds` for `OUT_OF_ENERGY`) with the reason in the message.
|
|
8
|
+
|
|
9
|
+
## 4.0.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`954bc4b`](https://github.com/lifinance/sdk/commit/954bc4bda013b470102041810daf95cb4f9181a1)]:
|
|
14
|
+
- @lifi/sdk@4.6.1
|
|
15
|
+
|
|
3
16
|
## 4.0.8
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -51,7 +51,7 @@ var TronSetAllowanceTask = class extends _lifi_sdk.BaseStepExecutionTask {
|
|
|
51
51
|
txHash,
|
|
52
52
|
txLink: require_utils_getTronTxLink.getTronTxLink(fromChain, txHash)
|
|
53
53
|
});
|
|
54
|
-
await require_rpc_waitForTronTxConfirmation.waitForTronTxConfirmation(client, txHash, "Approval transaction failed on-chain
|
|
54
|
+
await require_rpc_waitForTronTxConfirmation.waitForTronTxConfirmation(client, txHash, "Approval transaction failed on-chain");
|
|
55
55
|
statusManager.updateAction(step, action.type, "DONE", {
|
|
56
56
|
txHash,
|
|
57
57
|
txLink: require_utils_getTronTxLink.getTronTxLink(fromChain, txHash)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TronSetAllowanceTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","callTronRpcsWithRetry","stripHexPrefix","getTronTxLink","waitForTronTxConfirmation"],"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":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","callTronRpcsWithRetry","stripHexPrefix","getTronTxLink","waitForTronTxConfirmation"],"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,cAA0CA,UAAAA,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,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,qEACF;EAGF,IAAI,CAAC,KAAK,SAAS,iBACjB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,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,MAAMC,kCAAAA,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,MAAMA,kCAAAA,sBAC5B,QACA,OAAO,YAAY;GACjB,MAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB,iBAAiB;GAErE,IAAI,CAAC,OAAO,UAAU,OAAO,OAAO,IAAI,MAAM,yBAC5C,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,mBACd,8BAA8B,OAAO,QAAQ,iBAC/C;GAGF,OAAO;EACT,CACF;EAIA,MAAM,SAASE,6BAAAA,eACb,gBAAgB,aAAa,QAAQ,kBAAkB,IACzD;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD;GACA,QAAQC,4BAAAA,cAAc,WAAW,MAAM;EACzC,CAAC;EAED,MAAMC,sCAAAA,0BACJ,QACA,QACA,sCACF;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,QAAQ;GACpD;GACA,QAAQD,4BAAAA,cAAc,WAAW,MAAM;EACzC,CAAC;EAED,OAAO;GACL,QAAQ;GACR,SAAS,EAAE,wBAAwB,KAAK;EAC1C;CACF;AACF"}
|
|
@@ -3,12 +3,12 @@ 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
13
|
declare function waitForTronTxConfirmation(client: SDKClient, txHash: string, onChainFailureMessage?: string): Promise<void>;
|
|
14
14
|
//#endregion
|
|
@@ -3,25 +3,32 @@ const require_core_constants = require("../core/constants.js");
|
|
|
3
3
|
const require_rpc_callTronRpcsWithRetry = require("./callTronRpcsWithRetry.js");
|
|
4
4
|
let _lifi_sdk = require("@lifi/sdk");
|
|
5
5
|
//#region src/rpc/waitForTronTxConfirmation.ts
|
|
6
|
+
const NON_FAILURE_CONTRACT_RESULTS = /* @__PURE__ */ new Set(["SUCCESS", "DEFAULT"]);
|
|
7
|
+
function createOnChainFailureError(messageStem, reason) {
|
|
8
|
+
const stem = messageStem.replace(/\.$/, "");
|
|
9
|
+
if (reason === "OUT_OF_ENERGY") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.InsufficientFunds, `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`);
|
|
10
|
+
return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, reason ? `${stem}: ${reason}.` : `${stem}.`);
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* Polls getTransactionInfo until the transaction is indexed, then resolves.
|
|
8
14
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
* `
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
+
* Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
|
|
16
|
+
* success) and puts the reason in `receipt.result`; both are checked. Throws
|
|
17
|
+
* `TransactionError` without retry on failure (`InsufficientFunds` for
|
|
18
|
+
* OUT_OF_ENERGY, `TransactionFailed` otherwise). Tolerates up to
|
|
19
|
+
* `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors and caps total polls at
|
|
20
|
+
* `TRON_POLL_MAX_POLLS`, since `waitForResult`'s maxRetries counts errors only.
|
|
15
21
|
*/
|
|
16
|
-
async function waitForTronTxConfirmation(client, txHash, onChainFailureMessage = "Transaction failed on-chain
|
|
22
|
+
async function waitForTronTxConfirmation(client, txHash, onChainFailureMessage = "Transaction failed on-chain") {
|
|
17
23
|
let polls = 0;
|
|
18
24
|
await (0, _lifi_sdk.waitForResult)(async () => {
|
|
19
25
|
if (++polls > 40) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, "Transaction confirmation timeout.");
|
|
20
26
|
const txInfo = await require_rpc_callTronRpcsWithRetry.callTronRpcsWithRetry(client, (tronWeb) => tronWeb.trx.getTransactionInfo(txHash));
|
|
21
|
-
if (txInfo?.id)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
if (!txInfo?.id) return;
|
|
28
|
+
const contractResult = txInfo.receipt?.result;
|
|
29
|
+
const isContractFailure = !!contractResult && !NON_FAILURE_CONTRACT_RESULTS.has(contractResult);
|
|
30
|
+
if (txInfo.result === "FAILED" || isContractFailure) throw createOnChainFailureError(onChainFailureMessage, isContractFailure ? contractResult : void 0);
|
|
31
|
+
return txInfo;
|
|
25
32
|
}, require_core_constants.TRON_POLL_INTERVAL_MS, 5, (_count, error) => !(error instanceof _lifi_sdk.TransactionError));
|
|
26
33
|
}
|
|
27
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForTronTxConfirmation.js","names":["
|
|
1
|
+
{"version":3,"file":"waitForTronTxConfirmation.js","names":["TransactionError","LiFiErrorCode","waitForResult","callTronRpcsWithRetry","TRON_POLL_INTERVAL_MS"],"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,IAAIA,UAAAA,iBACTC,UAAAA,cAAc,mBACd,GAAG,KAAK,IAAI,OAAO,yDACrB;CAEF,OAAO,IAAID,UAAAA,iBACTC,UAAAA,cAAc,mBACd,SAAS,GAAG,KAAK,IAAI,OAAO,KAAK,GAAG,KAAK,EAC3C;AACF;;;;;;;;;;;AAYA,eAAsB,0BACpB,QACA,QACA,wBAAwB,+BACT;CACf,IAAI,QAAQ;CACZ,OAAA,GAAMC,UAAAA,cAAAA,CACJ,YAAY;EACV,IAAI,EAAE,QAAA,IACJ,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,mBACd,mCACF;EAEF,MAAM,SAAS,MAAME,kCAAAA,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,GACAC,uBAAAA,uBAAAA,IAEC,QAAQ,UAAU,EAAE,iBAAiBJ,UAAAA,iBACxC;AACF"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/cjs/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.0.10'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -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"}
|
|
@@ -3,12 +3,12 @@ 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
13
|
declare function waitForTronTxConfirmation(client: SDKClient, txHash: string, onChainFailureMessage?: string): Promise<void>;
|
|
14
14
|
//#endregion
|
|
@@ -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":";;;;;;;;;;;;iBA6CsB,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/version.d.ts
CHANGED
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.0.10'\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.0.10",
|
|
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,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.6.
|
|
31
|
+
"@lifi/sdk": "4.6.1",
|
|
32
32
|
"@tronweb3/tronwallet-abstract-adapter": "^1.2.0",
|
|
33
33
|
"tronweb": "^6.5.0"
|
|
34
34
|
},
|
|
@@ -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.0.10'
|