@lifi/sdk-provider-tron 4.1.6 → 4.1.8

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +9 -0
  3. package/dist/cjs/actions/getTronBalance.js +2 -1
  4. package/dist/cjs/actions/getTronBalance.js.map +1 -1
  5. package/dist/cjs/core/TronStepExecutor.js +4 -2
  6. package/dist/cjs/core/TronStepExecutor.js.map +1 -1
  7. package/dist/cjs/core/constants.d.ts +3 -0
  8. package/dist/cjs/core/constants.js +6 -0
  9. package/dist/cjs/core/constants.js.map +1 -1
  10. package/dist/cjs/core/tasks/TronCheckAllowanceTask.js +2 -1
  11. package/dist/cjs/core/tasks/TronCheckAllowanceTask.js.map +1 -1
  12. package/dist/cjs/core/tasks/TronSignAndExecuteTask.js +11 -1
  13. package/dist/cjs/core/tasks/TronSignAndExecuteTask.js.map +1 -1
  14. package/dist/cjs/core/tasks/TronWaitForTransactionTask.js +63 -15
  15. package/dist/cjs/core/tasks/TronWaitForTransactionTask.js.map +1 -1
  16. package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.d.ts +22 -0
  17. package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.js +88 -0
  18. package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.js.map +1 -0
  19. package/dist/cjs/rpc/broadcastTronTransaction.d.ts +31 -0
  20. package/dist/cjs/rpc/broadcastTronTransaction.js +68 -0
  21. package/dist/cjs/rpc/broadcastTronTransaction.js.map +1 -0
  22. package/dist/cjs/rpc/waitForTronTxConfirmation.d.ts +5 -3
  23. package/dist/cjs/rpc/waitForTronTxConfirmation.js +7 -5
  24. package/dist/cjs/rpc/waitForTronTxConfirmation.js.map +1 -1
  25. package/dist/cjs/utils/trc20Abi.d.ts +10 -0
  26. package/dist/cjs/utils/trc20Abi.js +39 -0
  27. package/dist/cjs/utils/trc20Abi.js.map +1 -0
  28. package/dist/cjs/utils/tronSignedTransaction.d.ts +19 -0
  29. package/dist/cjs/utils/tronSignedTransaction.js +40 -0
  30. package/dist/cjs/utils/tronSignedTransaction.js.map +1 -0
  31. package/dist/cjs/version.d.ts +1 -1
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/cjs/version.js.map +1 -1
  34. package/dist/esm/actions/getTronBalance.d.ts.map +1 -1
  35. package/dist/esm/actions/getTronBalance.js +2 -1
  36. package/dist/esm/actions/getTronBalance.js.map +1 -1
  37. package/dist/esm/core/TronStepExecutor.d.ts.map +1 -1
  38. package/dist/esm/core/TronStepExecutor.js +5 -3
  39. package/dist/esm/core/TronStepExecutor.js.map +1 -1
  40. package/dist/esm/core/constants.d.ts +3 -0
  41. package/dist/esm/core/constants.d.ts.map +1 -1
  42. package/dist/esm/core/constants.js +4 -1
  43. package/dist/esm/core/constants.js.map +1 -1
  44. package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts.map +1 -1
  45. package/dist/esm/core/tasks/TronCheckAllowanceTask.js +2 -1
  46. package/dist/esm/core/tasks/TronCheckAllowanceTask.js.map +1 -1
  47. package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts.map +1 -1
  48. package/dist/esm/core/tasks/TronSignAndExecuteTask.js +12 -2
  49. package/dist/esm/core/tasks/TronSignAndExecuteTask.js.map +1 -1
  50. package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts.map +1 -1
  51. package/dist/esm/core/tasks/TronWaitForTransactionTask.js +64 -16
  52. package/dist/esm/core/tasks/TronWaitForTransactionTask.js.map +1 -1
  53. package/dist/esm/core/tasks/helpers/isTronTransactionDropped.d.ts +22 -0
  54. package/dist/esm/core/tasks/helpers/isTronTransactionDropped.d.ts.map +1 -0
  55. package/dist/esm/core/tasks/helpers/isTronTransactionDropped.js +87 -0
  56. package/dist/esm/core/tasks/helpers/isTronTransactionDropped.js.map +1 -0
  57. package/dist/esm/rpc/broadcastTronTransaction.d.ts +31 -0
  58. package/dist/esm/rpc/broadcastTronTransaction.d.ts.map +1 -0
  59. package/dist/esm/rpc/broadcastTronTransaction.js +67 -0
  60. package/dist/esm/rpc/broadcastTronTransaction.js.map +1 -0
  61. package/dist/esm/rpc/waitForTronTxConfirmation.d.ts +5 -3
  62. package/dist/esm/rpc/waitForTronTxConfirmation.d.ts.map +1 -1
  63. package/dist/esm/rpc/waitForTronTxConfirmation.js +7 -5
  64. package/dist/esm/rpc/waitForTronTxConfirmation.js.map +1 -1
  65. package/dist/esm/utils/trc20Abi.d.ts +10 -0
  66. package/dist/esm/utils/trc20Abi.d.ts.map +1 -0
  67. package/dist/esm/utils/trc20Abi.js +38 -0
  68. package/dist/esm/utils/trc20Abi.js.map +1 -0
  69. package/dist/esm/utils/tronSignedTransaction.d.ts +19 -0
  70. package/dist/esm/utils/tronSignedTransaction.d.ts.map +1 -0
  71. package/dist/esm/utils/tronSignedTransaction.js +38 -0
  72. package/dist/esm/utils/tronSignedTransaction.js.map +1 -0
  73. package/dist/esm/version.d.ts +1 -1
  74. package/dist/esm/version.js +1 -1
  75. package/dist/esm/version.js.map +1 -1
  76. package/package.json +2 -2
  77. package/src/actions/getTronBalance.ts +2 -1
  78. package/src/core/TronStepExecutor.ts +14 -4
  79. package/src/core/constants.ts +12 -0
  80. package/src/core/tasks/TronCheckAllowanceTask.ts +2 -1
  81. package/src/core/tasks/TronSignAndExecuteTask.ts +32 -0
  82. package/src/core/tasks/TronWaitForTransactionTask.ts +153 -33
  83. package/src/core/tasks/helpers/isTronTransactionDropped.ts +159 -0
  84. package/src/rpc/broadcastTronTransaction.ts +92 -0
  85. package/src/rpc/waitForTronTxConfirmation.ts +13 -5
  86. package/src/utils/trc20Abi.ts +26 -0
  87. package/src/utils/tronSignedTransaction.ts +53 -0
  88. package/src/version.ts +1 -1
@@ -1,30 +1,78 @@
1
- import { callTronRpcsWithRetry } from "../../rpc/callTronRpcsWithRetry.js";
2
1
  import { waitForTronTxConfirmation } from "../../rpc/waitForTronTxConfirmation.js";
3
2
  import { getTronTxLink } from "../../utils/getTronTxLink.js";
4
3
  import { stripHexPrefix } from "../../utils/stripHexPrefix.js";
5
- import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
4
+ import { parseTronSignedTransaction } from "../../utils/tronSignedTransaction.js";
5
+ import { broadcastTronTransaction } from "../../rpc/broadcastTronTransaction.js";
6
+ import { isTronTransactionDropped } from "./helpers/isTronTransactionDropped.js";
7
+ import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, isFinalTransactionError } from "@lifi/sdk";
6
8
  //#region src/core/tasks/TronWaitForTransactionTask.ts
7
9
  var TronWaitForTransactionTask = class extends BaseStepExecutionTask {
8
10
  async run(context) {
9
11
  const { client, step, statusManager, fromChain, isBridgeExecution, signedTransaction } = context;
10
- if (!signedTransaction) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transaction is not found.");
11
12
  const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
12
13
  if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
13
- const broadcastResult = await callTronRpcsWithRetry(client, async (tronWeb) => {
14
- const result = await tronWeb.trx.sendRawTransaction(signedTransaction);
15
- if (!result.result && String(result.code) !== "DUP_TRANSACTION_ERROR") throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction broadcast failed: ${result.code || "Unknown error"}`);
16
- return result;
17
- });
18
- const txHash = stripHexPrefix(broadcastResult.transaction?.txID ?? signedTransaction.txID);
19
- statusManager.updateAction(step, action.type, "PENDING", {
20
- txHash,
21
- txLink: getTronTxLink(fromChain, txHash)
22
- });
23
- await waitForTronTxConfirmation(client, txHash);
24
- if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
25
- return { status: "COMPLETED" };
14
+ if (signedTransaction) {
15
+ const broadcast = await broadcastTronTransaction(client, signedTransaction);
16
+ if (broadcast.status !== "accepted") {
17
+ if (broadcast.status === "rejected") statusManager.updateAction(step, action.type, "PENDING", { txHex: void 0 });
18
+ throw broadcast.error;
19
+ }
20
+ statusManager.updateAction(step, action.type, "PENDING", {
21
+ txHash: broadcast.txHash,
22
+ txLink: getTronTxLink(fromChain, broadcast.txHash)
23
+ });
24
+ return confirm(context, action, broadcast.txHash, { expiration: signedTransaction.raw_data.expiration });
25
+ }
26
+ const storedTransaction = action.txHex ? parseTronSignedTransaction(action.txHex) : void 0;
27
+ if (action.txHex && !storedTransaction) {
28
+ statusManager.updateAction(step, action.type, "PENDING", { txHex: void 0 });
29
+ if (!action.txHash) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to resume transaction. The stored signed transaction is invalid.");
30
+ }
31
+ const storedTxId = storedTransaction ? stripHexPrefix(storedTransaction.txID) : void 0;
32
+ if (storedTxId && action.txHash && storedTxId.toLowerCase() !== stripHexPrefix(action.txHash).toLowerCase()) return confirm(context, action, action.txHash, { mayDrop: false });
33
+ const txHash = action.txHash ?? storedTxId;
34
+ if (!txHash) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transaction is not found.");
35
+ const expiration = storedTransaction?.raw_data.expiration;
36
+ if (await isTronTransactionDropped(client, step, txHash, expiration)) throw dropped(context, action);
37
+ if (storedTransaction) {
38
+ if ((await broadcastTronTransaction(client, storedTransaction)).status === "accepted" && !action.txHash) statusManager.updateAction(step, action.type, "PENDING", {
39
+ txHash,
40
+ txLink: getTronTxLink(fromChain, txHash)
41
+ });
42
+ }
43
+ return confirm(context, action, txHash, { expiration });
26
44
  }
27
45
  };
46
+ /**
47
+ * Waits for the inclusion of `txHash`. After a timeout, the dropped rule runs
48
+ * with `options.expiration`; with `{ mayDrop: false }` it never runs, and the
49
+ * outcome stays unknown.
50
+ */
51
+ async function confirm(context, action, txHash, options) {
52
+ const { client, step, statusManager, fromChain, isBridgeExecution } = context;
53
+ const included = {
54
+ txHash,
55
+ txLink: getTronTxLink(fromChain, txHash),
56
+ txHex: void 0
57
+ };
58
+ try {
59
+ await waitForTronTxConfirmation(client, txHash);
60
+ } catch (error) {
61
+ if (isFinalTransactionError(error)) {
62
+ statusManager.updateAction(step, action.type, "PENDING", included);
63
+ throw error;
64
+ }
65
+ if ("expiration" in options && await isTronTransactionDropped(client, step, txHash, options.expiration)) throw dropped(context, action);
66
+ throw error;
67
+ }
68
+ statusManager.updateAction(step, action.type, "PENDING", included);
69
+ if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
70
+ return { status: "COMPLETED" };
71
+ }
72
+ function dropped(context, action) {
73
+ context.statusManager.updateAction(context.step, action.type, "PENDING", { txHex: void 0 });
74
+ return new TransactionError(LiFiErrorCode.TransactionExpired, "Transaction expired before it was included in a block.", void 0, { final: true });
75
+ }
28
76
  //#endregion
29
77
  export { TronWaitForTransactionTask };
30
78
 
@@ -1 +1 @@
1
- {"version":3,"file":"TronWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/TronWaitForTransactionTask.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\nexport class TronWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransaction,\n } = context\n\n if (!signedTransaction) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transaction is not found.'\n )\n }\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\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 `Transaction 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(client, txHash)\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,6BAAb,cAAgD,sBAAsB;CACpE,MAAM,IAAI,SAAuD;EAC/D,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,sBACE;EAEJ,IAAI,CAAC,mBACH,MAAM,IAAI,iBACR,cAAc,uBACd,iEACF;EAGF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,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,iCAAiC,OAAO,QAAQ,iBAClD;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,0BAA0B,QAAQ,MAAM;EAE9C,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
1
+ {"version":3,"file":"TronWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/TronWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n isFinalTransactionError,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { broadcastTronTransaction } from '../../rpc/broadcastTronTransaction.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'\nimport { parseTronSignedTransaction } from '../../utils/tronSignedTransaction.js'\nimport { isTronTransactionDropped } from './helpers/isTronTransactionDropped.js'\n\nexport class TronWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransaction,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n if (signedTransaction) {\n const broadcast = await broadcastTronTransaction(\n client,\n signedTransaction\n )\n if (broadcast.status !== 'accepted') {\n if (broadcast.status === 'rejected') {\n // Every node refused the transaction before its pending pool (or\n // no node was tried), so no node holds it. Drop the stored bytes:\n // \"Try again\" signs a new one.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: undefined,\n })\n }\n // A network error or a code after the push may leave the transaction\n // on a node, so an unknown outcome keeps the bytes for the resume.\n throw broadcast.error\n }\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: broadcast.txHash,\n txLink: getTronTxLink(fromChain, broadcast.txHash),\n })\n\n return confirm(context, action, broadcast.txHash, {\n expiration: signedTransaction.raw_data.expiration,\n })\n }\n\n // Resuming: the signing task did not run in this session. Continue with\n // the bytes and the hash persisted on the action; never sign again.\n const storedTransaction = action.txHex\n ? parseTronSignedTransaction(action.txHex)\n : undefined\n\n if (action.txHex && !storedTransaction) {\n // Damaged stored bytes can never be sent or looked up.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: undefined,\n })\n if (!action.txHash) {\n // No node ever accepted these bytes, so \"Try again\" signs again.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to resume transaction. The stored signed transaction is invalid.'\n )\n }\n }\n\n const storedTxId = storedTransaction\n ? stripHexPrefix(storedTransaction.txID)\n : undefined\n\n if (\n storedTxId &&\n action.txHash &&\n storedTxId.toLowerCase() !== stripHexPrefix(action.txHash).toLowerCase()\n ) {\n // Stored bytes whose txID is not the stored txHash (damaged storage)\n // prove nothing about that transaction, and they may have been sent.\n // Then the SDK neither sends nor drops; it only waits by txHash, and\n // the outcome stays unknown.\n return confirm(context, action, action.txHash, { mayDrop: false })\n }\n\n const txHash = action.txHash ?? storedTxId\n\n if (!txHash) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transaction is not found.'\n )\n }\n\n const expiration = storedTransaction?.raw_data.expiration\n\n if (await isTronTransactionDropped(client, step, txHash, expiration)) {\n throw dropped(context, action)\n }\n\n if (storedTransaction) {\n // The transaction may already be included, so a refusal says nothing\n // about the outcome. The confirmation wait below decides it.\n const broadcast = await broadcastTronTransaction(\n client,\n storedTransaction\n )\n if (broadcast.status === 'accepted' && !action.txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash,\n txLink: getTronTxLink(fromChain, txHash),\n })\n }\n }\n\n return confirm(context, action, txHash, { expiration })\n }\n}\n\n/**\n * Waits for the inclusion of `txHash`. After a timeout, the dropped rule runs\n * with `options.expiration`; with `{ mayDrop: false }` it never runs, and the\n * outcome stays unknown.\n */\nasync function confirm(\n context: TronStepExecutorContext,\n action: ExecutionAction,\n txHash: string,\n options: { expiration: number | undefined } | { mayDrop: false }\n): Promise<TaskResult> {\n const { client, step, statusManager, fromChain, isBridgeExecution } = context\n // Included in a block: the stored bytes are no longer needed.\n const included = {\n txHash,\n txLink: getTronTxLink(fromChain, txHash),\n txHex: undefined,\n }\n\n try {\n await waitForTronTxConfirmation(client, txHash)\n } catch (error) {\n if (isFinalTransactionError(error)) {\n statusManager.updateAction(step, action.type, 'PENDING', included)\n throw error\n }\n // The wait ended without a result. Only an expired transaction that no\n // source knows is final; anything else stays unknown and keeps `txHex`.\n if (\n 'expiration' in options &&\n (await isTronTransactionDropped(client, step, txHash, options.expiration))\n ) {\n throw dropped(context, action)\n }\n throw error\n }\n\n statusManager.updateAction(step, action.type, 'PENDING', included)\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n}\n\nfunction dropped(\n context: TronStepExecutorContext,\n action: ExecutionAction\n): TransactionError {\n context.statusManager.updateAction(context.step, action.type, 'PENDING', {\n txHex: undefined,\n })\n return new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction expired before it was included in a block.',\n undefined,\n { final: true }\n )\n}\n"],"mappings":";;;;;;;;AAgBA,IAAa,6BAAb,cAAgD,sBAAsB;CACpE,MAAM,IAAI,SAAuD;EAC/D,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,IAAI,mBAAmB;GACrB,MAAM,YAAY,MAAM,yBACtB,QACA,iBACF;GACA,IAAI,UAAU,WAAW,YAAY;IACnC,IAAI,UAAU,WAAW,YAIvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAO,KAAA,EACT,CAAC;IAIH,MAAM,UAAU;GAClB;GAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ,UAAU;IAClB,QAAQ,cAAc,WAAW,UAAU,MAAM;GACnD,CAAC;GAED,OAAO,QAAQ,SAAS,QAAQ,UAAU,QAAQ,EAChD,YAAY,kBAAkB,SAAS,WACzC,CAAC;EACH;EAIA,MAAM,oBAAoB,OAAO,QAC7B,2BAA2B,OAAO,KAAK,IACvC,KAAA;EAEJ,IAAI,OAAO,SAAS,CAAC,mBAAmB;GAEtC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAO,KAAA,EACT,CAAC;GACD,IAAI,CAAC,OAAO,QAEV,MAAM,IAAI,iBACR,cAAc,uBACd,yEACF;EAEJ;EAEA,MAAM,aAAa,oBACf,eAAe,kBAAkB,IAAI,IACrC,KAAA;EAEJ,IACE,cACA,OAAO,UACP,WAAW,YAAY,MAAM,eAAe,OAAO,MAAM,CAAC,CAAC,YAAY,GAMvE,OAAO,QAAQ,SAAS,QAAQ,OAAO,QAAQ,EAAE,SAAS,MAAM,CAAC;EAGnE,MAAM,SAAS,OAAO,UAAU;EAEhC,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,iEACF;EAGF,MAAM,aAAa,mBAAmB,SAAS;EAE/C,IAAI,MAAM,yBAAyB,QAAQ,MAAM,QAAQ,UAAU,GACjE,MAAM,QAAQ,SAAS,MAAM;EAG/B,IAAI,mBAOE;QAAA,MAJoB,yBACtB,QACA,iBACF,EAAA,CACc,WAAW,cAAc,CAAC,OAAO,QAC7C,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD;IACA,QAAQ,cAAc,WAAW,MAAM;GACzC,CAAC;EAAA;EAIL,OAAO,QAAQ,SAAS,QAAQ,QAAQ,EAAE,WAAW,CAAC;CACxD;AACF;;;;;;AAOA,eAAe,QACb,SACA,QACA,QACA,SACqB;CACrB,MAAM,EAAE,QAAQ,MAAM,eAAe,WAAW,sBAAsB;CAEtE,MAAM,WAAW;EACf;EACA,QAAQ,cAAc,WAAW,MAAM;EACvC,OAAO,KAAA;CACT;CAEA,IAAI;EACF,MAAM,0BAA0B,QAAQ,MAAM;CAChD,SAAS,OAAO;EACd,IAAI,wBAAwB,KAAK,GAAG;GAClC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,QAAQ;GACjE,MAAM;EACR;EAGA,IACE,gBAAgB,WACf,MAAM,yBAAyB,QAAQ,MAAM,QAAQ,QAAQ,UAAU,GAExE,MAAM,QAAQ,SAAS,MAAM;EAE/B,MAAM;CACR;CAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,QAAQ;CAEjE,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;CAGtD,OAAO,EAAE,QAAQ,YAAY;AAC/B;AAEA,SAAS,QACP,SACA,QACkB;CAClB,QAAQ,cAAc,aAAa,QAAQ,MAAM,OAAO,MAAM,WAAW,EACvE,OAAO,KAAA,EACT,CAAC;CACD,OAAO,IAAI,iBACT,cAAc,oBACd,0DACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;AACF"}
@@ -0,0 +1,22 @@
1
+ import { LiFiStepExtended, SDKClient } from "@lifi/sdk";
2
+ //#region src/core/tasks/helpers/isTronTransactionDropped.d.ts
3
+ /**
4
+ * True only when the transaction can no longer land and no source knows it
5
+ * (see the resume rules in `transactionState.ts`):
6
+ * (a) it can no longer land: with a stored transaction, a node's head is past
7
+ * `raw_data.expiration` (block time, not `Date.now()`, so a wrong local
8
+ * clock cannot expire it); without one (routes stored before `txHex`),
9
+ * `isOldEnoughToDrop(signedAt)` on the local clock of the same device;
10
+ * (b) at least one covering node answers "not found" and no node returns the
11
+ * transaction. A node covers when its head is more than
12
+ * `TRON_HEAD_MARGIN_MS` past the latest landing time and less than
13
+ * `TRON_LOOKUP_WINDOW_MS` past the earliest one;
14
+ * (c) the LI.FI status API does not know the hash. It is a veto only: an
15
+ * unknown hash says nothing.
16
+ *
17
+ * Any lookup error leaves the outcome unknown and returns false. A `0x` prefix
18
+ * on `txHash` is removed first: a node does not find a prefixed txID.
19
+ */
20
+ export declare function isTronTransactionDropped(client: SDKClient, step: LiFiStepExtended, txHash: string, expiration: number | undefined): Promise<boolean>;
21
+ //#endregion
22
+ //# sourceMappingURL=isTronTransactionDropped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isTronTransactionDropped.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/isTronTransactionDropped.ts"],"mappings":";;;;;;;;;;;;;;;;;;;wBAwCsB,yBACpB,QAAQ,WACR,MAAM,kBACN,gBACA,iCACC"}
@@ -0,0 +1,87 @@
1
+ import { TRON_EXPIRATION_OFFSET_MS } from "../../constants.js";
2
+ import { callTronRpcsWithRetry } from "../../../rpc/callTronRpcsWithRetry.js";
3
+ import { stripHexPrefix } from "../../../utils/stripHexPrefix.js";
4
+ import { CLOCK_SKEW_MARGIN_MS, isKnownToStatusApi, isOldEnoughToDrop } from "@lifi/sdk";
5
+ //#region src/core/tasks/helpers/isTronTransactionDropped.ts
6
+ /**
7
+ * True only when the transaction can no longer land and no source knows it
8
+ * (see the resume rules in `transactionState.ts`):
9
+ * (a) it can no longer land: with a stored transaction, a node's head is past
10
+ * `raw_data.expiration` (block time, not `Date.now()`, so a wrong local
11
+ * clock cannot expire it); without one (routes stored before `txHex`),
12
+ * `isOldEnoughToDrop(signedAt)` on the local clock of the same device;
13
+ * (b) at least one covering node answers "not found" and no node returns the
14
+ * transaction. A node covers when its head is more than
15
+ * `TRON_HEAD_MARGIN_MS` past the latest landing time and less than
16
+ * `TRON_LOOKUP_WINDOW_MS` past the earliest one;
17
+ * (c) the LI.FI status API does not know the hash. It is a veto only: an
18
+ * unknown hash says nothing.
19
+ *
20
+ * Any lookup error leaves the outcome unknown and returns false. A `0x` prefix
21
+ * on `txHash` is removed first: a node does not find a prefixed txID.
22
+ */
23
+ async function isTronTransactionDropped(client, step, txHash, expiration) {
24
+ try {
25
+ const window = getLandingWindow(step, expiration);
26
+ if (!window) return false;
27
+ const txId = stripHexPrefix(txHash);
28
+ if (await lookUpOnTronNodes(client, txId, window) !== "not-found") return false;
29
+ return !await isKnownToStatusApi(client, step, txId);
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+ function getLandingWindow(step, expiration) {
35
+ if (expiration !== void 0) return {
36
+ earliest: expiration - TRON_EXPIRATION_OFFSET_MS,
37
+ latest: expiration
38
+ };
39
+ const signedAt = step.execution?.signedAt;
40
+ if (signedAt === void 0 || !isOldEnoughToDrop(signedAt)) return;
41
+ return {
42
+ earliest: signedAt - CLOCK_SKEW_MARGIN_MS,
43
+ latest: signedAt + CLOCK_SKEW_MARGIN_MS + TRON_EXPIRATION_OFFSET_MS
44
+ };
45
+ }
46
+ /**
47
+ * Asks every node. `found` as soon as one returns the transaction;
48
+ * `not-found` when none returns it and at least one covering node answered
49
+ * `{}`; `unknown` otherwise (errors, answers other than `{}` without `id`, or
50
+ * no node covers the window). A node without a head is still asked: its
51
+ * transaction vetoes, but its `{}` never counts.
52
+ */
53
+ async function lookUpOnTronNodes(client, txId, window) {
54
+ let coveringNotFound = 0;
55
+ try {
56
+ await callTronRpcsWithRetry(client, async (tronWeb) => {
57
+ const head = await getHeadTime(tronWeb);
58
+ const txInfo = await tronWeb.trx.getUnconfirmedTransactionInfo(txId);
59
+ if (hasId(txInfo)) return;
60
+ if (!isEmptyObject(txInfo)) throw new Error("The node answered neither the transaction nor {}.");
61
+ if (head !== void 0 && head > window.latest + 3e5 && head - window.earliest < 864e5) coveringNotFound++;
62
+ throw new Error("The node does not return the transaction.");
63
+ });
64
+ return "found";
65
+ } catch {
66
+ return coveringNotFound > 0 ? "not-found" : "unknown";
67
+ }
68
+ }
69
+ /** The node's latest block time, or `undefined` when the request fails. */
70
+ async function getHeadTime(tronWeb) {
71
+ try {
72
+ return (await tronWeb.trx.getCurrentBlock()).block_header.raw_data.timestamp;
73
+ } catch {
74
+ return;
75
+ }
76
+ }
77
+ function hasId(txInfo) {
78
+ return typeof txInfo === "object" && txInfo !== null && "id" in txInfo && Boolean(txInfo.id);
79
+ }
80
+ /** Only a plain object without keys: `null` and `[]` do not count. */
81
+ function isEmptyObject(txInfo) {
82
+ return typeof txInfo === "object" && txInfo !== null && !Array.isArray(txInfo) && Object.keys(txInfo).length === 0;
83
+ }
84
+ //#endregion
85
+ export { isTronTransactionDropped };
86
+
87
+ //# sourceMappingURL=isTronTransactionDropped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isTronTransactionDropped.js","names":[],"sources":["../../../../../src/core/tasks/helpers/isTronTransactionDropped.ts"],"sourcesContent":["import {\n CLOCK_SKEW_MARGIN_MS,\n isKnownToStatusApi,\n isOldEnoughToDrop,\n type LiFiStepExtended,\n type SDKClient,\n} from '@lifi/sdk'\nimport type { TronWeb } from 'tronweb'\nimport { callTronRpcsWithRetry } from '../../../rpc/callTronRpcsWithRetry.js'\nimport { stripHexPrefix } from '../../../utils/stripHexPrefix.js'\nimport {\n TRON_EXPIRATION_OFFSET_MS,\n TRON_HEAD_MARGIN_MS,\n TRON_LOOKUP_WINDOW_MS,\n} from '../../constants.js'\n\ninterface LandingWindow {\n /** The earliest time the transaction can land (chain time). */\n earliest: number\n /** The latest time the transaction can land (chain time). */\n latest: number\n}\n\n/**\n * True only when the transaction can no longer land and no source knows it\n * (see the resume rules in `transactionState.ts`):\n * (a) it can no longer land: with a stored transaction, a node's head is past\n * `raw_data.expiration` (block time, not `Date.now()`, so a wrong local\n * clock cannot expire it); without one (routes stored before `txHex`),\n * `isOldEnoughToDrop(signedAt)` on the local clock of the same device;\n * (b) at least one covering node answers \"not found\" and no node returns the\n * transaction. A node covers when its head is more than\n * `TRON_HEAD_MARGIN_MS` past the latest landing time and less than\n * `TRON_LOOKUP_WINDOW_MS` past the earliest one;\n * (c) the LI.FI status API does not know the hash. It is a veto only: an\n * unknown hash says nothing.\n *\n * Any lookup error leaves the outcome unknown and returns false. A `0x` prefix\n * on `txHash` is removed first: a node does not find a prefixed txID.\n */\nexport async function isTronTransactionDropped(\n client: SDKClient,\n step: LiFiStepExtended,\n txHash: string,\n expiration: number | undefined\n): Promise<boolean> {\n try {\n const window = getLandingWindow(step, expiration)\n if (!window) {\n return false\n }\n const txId = stripHexPrefix(txHash)\n if ((await lookUpOnTronNodes(client, txId, window)) !== 'not-found') {\n return false\n }\n return !(await isKnownToStatusApi(client, step, txId))\n } catch {\n return false\n }\n}\n\nfunction getLandingWindow(\n step: LiFiStepExtended,\n expiration: number | undefined\n): LandingWindow | undefined {\n if (expiration !== undefined) {\n // Chain times carried by the transaction itself. The head condition in\n // `lookUpOnTronNodes` is the expiry verdict (a).\n return {\n earliest: expiration - TRON_EXPIRATION_OFFSET_MS,\n latest: expiration,\n }\n }\n const signedAt = step.execution?.signedAt\n if (signedAt === undefined || !isOldEnoughToDrop(signedAt)) {\n return undefined\n }\n // Local signing time: the ref block was fetched just before signing, so the\n // expiration is at most the signing time + 60 s, give or take the clock skew.\n return {\n earliest: signedAt - CLOCK_SKEW_MARGIN_MS,\n latest: signedAt + CLOCK_SKEW_MARGIN_MS + TRON_EXPIRATION_OFFSET_MS,\n }\n}\n\n/**\n * Asks every node. `found` as soon as one returns the transaction;\n * `not-found` when none returns it and at least one covering node answered\n * `{}`; `unknown` otherwise (errors, answers other than `{}` without `id`, or\n * no node covers the window). A node without a head is still asked: its\n * transaction vetoes, but its `{}` never counts.\n */\nasync function lookUpOnTronNodes(\n client: SDKClient,\n txId: string,\n window: LandingWindow\n): Promise<'found' | 'not-found' | 'unknown'> {\n let coveringNotFound = 0\n try {\n await callTronRpcsWithRetry(client, async (tronWeb) => {\n // The head comes first, so the lookup below sees at least this head.\n const head = await getHeadTime(tronWeb)\n // The full node answers: unlike `getTransactionInfo`, this call does not\n // wait for the solidity node.\n const txInfo: unknown =\n await tronWeb.trx.getUnconfirmedTransactionInfo(txId)\n if (hasId(txInfo)) {\n return\n }\n // The full node answers `{}` for a transaction it has not included.\n // Any other answer (an `{ Error }` body, an empty response) proves\n // nothing and counts as a lookup error.\n if (!isEmptyObject(txInfo)) {\n throw new Error('The node answered neither the transaction nor {}.')\n }\n const covers =\n head !== undefined &&\n head > window.latest + TRON_HEAD_MARGIN_MS &&\n head - window.earliest < TRON_LOOKUP_WINDOW_MS\n if (covers) {\n coveringNotFound++\n }\n // Throw so that `callTronRpcsWithRetry` asks the next node as well.\n throw new Error('The node does not return the transaction.')\n })\n return 'found'\n } catch {\n return coveringNotFound > 0 ? 'not-found' : 'unknown'\n }\n}\n\n/** The node's latest block time, or `undefined` when the request fails. */\nasync function getHeadTime(tronWeb: TronWeb): Promise<number | undefined> {\n try {\n const block = await tronWeb.trx.getCurrentBlock()\n return block.block_header.raw_data.timestamp\n } catch {\n return undefined\n }\n}\n\nfunction hasId(txInfo: unknown): boolean {\n return (\n typeof txInfo === 'object' &&\n txInfo !== null &&\n 'id' in txInfo &&\n Boolean(txInfo.id)\n )\n}\n\n/** Only a plain object without keys: `null` and `[]` do not count. */\nfunction isEmptyObject(txInfo: unknown): boolean {\n return (\n typeof txInfo === 'object' &&\n txInfo !== null &&\n !Array.isArray(txInfo) &&\n Object.keys(txInfo).length === 0\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwCA,eAAsB,yBACpB,QACA,MACA,QACA,YACkB;CAClB,IAAI;EACF,MAAM,SAAS,iBAAiB,MAAM,UAAU;EAChD,IAAI,CAAC,QACH,OAAO;EAET,MAAM,OAAO,eAAe,MAAM;EAClC,IAAK,MAAM,kBAAkB,QAAQ,MAAM,MAAM,MAAO,aACtD,OAAO;EAET,OAAO,CAAE,MAAM,mBAAmB,QAAQ,MAAM,IAAI;CACtD,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,iBACP,MACA,YAC2B;CAC3B,IAAI,eAAe,KAAA,GAGjB,OAAO;EACL,UAAU,aAAa;EACvB,QAAQ;CACV;CAEF,MAAM,WAAW,KAAK,WAAW;CACjC,IAAI,aAAa,KAAA,KAAa,CAAC,kBAAkB,QAAQ,GACvD;CAIF,OAAO;EACL,UAAU,WAAW;EACrB,QAAQ,WAAW,uBAAuB;CAC5C;AACF;;;;;;;;AASA,eAAe,kBACb,QACA,MACA,QAC4C;CAC5C,IAAI,mBAAmB;CACvB,IAAI;EACF,MAAM,sBAAsB,QAAQ,OAAO,YAAY;GAErD,MAAM,OAAO,MAAM,YAAY,OAAO;GAGtC,MAAM,SACJ,MAAM,QAAQ,IAAI,8BAA8B,IAAI;GACtD,IAAI,MAAM,MAAM,GACd;GAKF,IAAI,CAAC,cAAc,MAAM,GACvB,MAAM,IAAI,MAAM,mDAAmD;GAMrE,IAHE,SAAS,KAAA,KACT,OAAO,OAAO,SAAA,OACd,OAAO,OAAO,WAAA,OAEd;GAGF,MAAM,IAAI,MAAM,2CAA2C;EAC7D,CAAC;EACD,OAAO;CACT,QAAQ;EACN,OAAO,mBAAmB,IAAI,cAAc;CAC9C;AACF;;AAGA,eAAe,YAAY,SAA+C;CACxE,IAAI;EAEF,QAAO,MADa,QAAQ,IAAI,gBAAgB,EAAA,CACnC,aAAa,SAAS;CACrC,QAAQ;EACN;CACF;AACF;AAEA,SAAS,MAAM,QAA0B;CACvC,OACE,OAAO,WAAW,YAClB,WAAW,QACX,QAAQ,UACR,QAAQ,OAAO,EAAE;AAErB;;AAGA,SAAS,cAAc,QAA0B;CAC/C,OACE,OAAO,WAAW,YAClB,WAAW,QACX,CAAC,MAAM,QAAQ,MAAM,KACrB,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW;AAEnC"}
@@ -0,0 +1,31 @@
1
+ import { SDKClient } from "@lifi/sdk";
2
+ import { SignedTransaction } from "@tronweb3/tronwallet-abstract-adapter";
3
+ //#region src/rpc/broadcastTronTransaction.d.ts
4
+ export type TronBroadcastResult = {
5
+ status: "accepted";
6
+ txHash: string;
7
+ } | {
8
+ status: "rejected";
9
+ error: unknown;
10
+ } | {
11
+ status: "unknown";
12
+ error: unknown;
13
+ };
14
+ /**
15
+ * Broadcasts a signed transaction through the Tron RPCs in turn.
16
+ *
17
+ * - `accepted`: a node took the transaction. `DUP_TRANSACTION_ERROR` counts as
18
+ * accepted: the node already has it.
19
+ * - `rejected`: every node refused it with a code of
20
+ * `PRE_PUSH_REJECTION_CODES`, or no node was tried. No node holds the
21
+ * transaction.
22
+ * - `unknown`: at least one attempt failed in another way: a network error, a
23
+ * different code (for example `NOT_ENOUGH_EFFECTIVE_CONNECTION`, which comes
24
+ * after the push) or an answer without a code (such as an `{ Error }` body).
25
+ * That node may hold the transaction.
26
+ *
27
+ * `error` is what `callTronRpcsWithRetry` threw, unchanged.
28
+ */
29
+ export declare function broadcastTronTransaction(client: SDKClient, signedTransaction: SignedTransaction): Promise<TronBroadcastResult>;
30
+ //#endregion
31
+ //# sourceMappingURL=broadcastTronTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcastTronTransaction.d.ts","names":[],"sources":["../../../src/rpc/broadcastTronTransaction.ts"],"mappings":";;;YAKY;EACN;EAAoB;;EACpB;EAAoB;;EACpB;EAAmB;;;;;;;;;;;;;;;;;wBAwCH,yBACpB,QAAQ,WACR,mBAAmB,oBAClB,QAAQ"}
@@ -0,0 +1,67 @@
1
+ import { callTronRpcsWithRetry } from "./callTronRpcsWithRetry.js";
2
+ import { stripHexPrefix } from "../utils/stripHexPrefix.js";
3
+ import { LiFiErrorCode, TransactionError } from "@lifi/sdk";
4
+ //#region src/rpc/broadcastTronTransaction.ts
5
+ /**
6
+ * The codes that java-tron's `Wallet.broadcastTransaction` returns before it
7
+ * puts the transaction into the node's pending pool: a node that answers one
8
+ * of them does not hold the transaction. Any other code proves nothing: for
9
+ * example, java-tron returns `NOT_ENOUGH_EFFECTIVE_CONNECTION` after the push,
10
+ * and `OTHER_ERROR` does not say at which step the broadcast failed.
11
+ */
12
+ const PRE_PUSH_REJECTION_CODES = /* @__PURE__ */ new Set([
13
+ "SIGERROR",
14
+ "BLOCK_UNSOLIDIFIED",
15
+ "NO_CONNECTION",
16
+ "SERVER_BUSY",
17
+ "CONTRACT_VALIDATE_ERROR",
18
+ "CONTRACT_EXE_ERROR",
19
+ "BANDWITH_ERROR",
20
+ "BANDWIDTH_ERROR",
21
+ "TAPOS_ERROR",
22
+ "TOO_BIG_TRANSACTION_ERROR",
23
+ "TRANSACTION_EXPIRATION_ERROR"
24
+ ]);
25
+ /**
26
+ * Broadcasts a signed transaction through the Tron RPCs in turn.
27
+ *
28
+ * - `accepted`: a node took the transaction. `DUP_TRANSACTION_ERROR` counts as
29
+ * accepted: the node already has it.
30
+ * - `rejected`: every node refused it with a code of
31
+ * `PRE_PUSH_REJECTION_CODES`, or no node was tried. No node holds the
32
+ * transaction.
33
+ * - `unknown`: at least one attempt failed in another way: a network error, a
34
+ * different code (for example `NOT_ENOUGH_EFFECTIVE_CONNECTION`, which comes
35
+ * after the push) or an answer without a code (such as an `{ Error }` body).
36
+ * That node may hold the transaction.
37
+ *
38
+ * `error` is what `callTronRpcsWithRetry` threw, unchanged.
39
+ */
40
+ async function broadcastTronTransaction(client, signedTransaction) {
41
+ let attempts = 0;
42
+ let rejections = 0;
43
+ try {
44
+ const broadcastResult = await callTronRpcsWithRetry(client, async (tronWeb) => {
45
+ attempts++;
46
+ const result = await tronWeb.trx.sendRawTransaction(signedTransaction);
47
+ if (!result.result && String(result.code) !== "DUP_TRANSACTION_ERROR") {
48
+ if (PRE_PUSH_REJECTION_CODES.has(String(result.code))) rejections++;
49
+ throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction broadcast failed: ${result.code || "Unknown error"}`);
50
+ }
51
+ return result;
52
+ });
53
+ return {
54
+ status: "accepted",
55
+ txHash: stripHexPrefix(broadcastResult.transaction?.txID ?? signedTransaction.txID)
56
+ };
57
+ } catch (error) {
58
+ return {
59
+ status: rejections === attempts ? "rejected" : "unknown",
60
+ error
61
+ };
62
+ }
63
+ }
64
+ //#endregion
65
+ export { broadcastTronTransaction };
66
+
67
+ //# sourceMappingURL=broadcastTronTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcastTronTransaction.js","names":[],"sources":["../../../src/rpc/broadcastTronTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport type { SignedTransaction } from '@tronweb3/tronwallet-abstract-adapter'\nimport { stripHexPrefix } from '../utils/stripHexPrefix.js'\nimport { callTronRpcsWithRetry } from './callTronRpcsWithRetry.js'\n\nexport type TronBroadcastResult =\n | { status: 'accepted'; txHash: string }\n | { status: 'rejected'; error: unknown }\n | { status: 'unknown'; error: unknown }\n\n/**\n * The codes that java-tron's `Wallet.broadcastTransaction` returns before it\n * puts the transaction into the node's pending pool: a node that answers one\n * of them does not hold the transaction. Any other code proves nothing: for\n * example, java-tron returns `NOT_ENOUGH_EFFECTIVE_CONNECTION` after the push,\n * and `OTHER_ERROR` does not say at which step the broadcast failed.\n */\nconst PRE_PUSH_REJECTION_CODES: ReadonlySet<string> = new Set([\n 'SIGERROR',\n 'BLOCK_UNSOLIDIFIED',\n 'NO_CONNECTION',\n 'SERVER_BUSY',\n 'CONTRACT_VALIDATE_ERROR',\n 'CONTRACT_EXE_ERROR',\n // java-tron's spelling (api.proto `BANDWITH_ERROR = 4`). The HTTP API sends\n // the enum name. `BANDWIDTH_ERROR` is a harmless alias.\n 'BANDWITH_ERROR',\n 'BANDWIDTH_ERROR',\n 'TAPOS_ERROR',\n 'TOO_BIG_TRANSACTION_ERROR',\n 'TRANSACTION_EXPIRATION_ERROR',\n])\n\n/**\n * Broadcasts a signed transaction through the Tron RPCs in turn.\n *\n * - `accepted`: a node took the transaction. `DUP_TRANSACTION_ERROR` counts as\n * accepted: the node already has it.\n * - `rejected`: every node refused it with a code of\n * `PRE_PUSH_REJECTION_CODES`, or no node was tried. No node holds the\n * transaction.\n * - `unknown`: at least one attempt failed in another way: a network error, a\n * different code (for example `NOT_ENOUGH_EFFECTIVE_CONNECTION`, which comes\n * after the push) or an answer without a code (such as an `{ Error }` body).\n * That node may hold the transaction.\n *\n * `error` is what `callTronRpcsWithRetry` threw, unchanged.\n */\nexport async function broadcastTronTransaction(\n client: SDKClient,\n signedTransaction: SignedTransaction\n): Promise<TronBroadcastResult> {\n let attempts = 0\n let rejections = 0\n try {\n const broadcastResult = await callTronRpcsWithRetry(\n client,\n async (tronWeb) => {\n attempts++\n const result = await tronWeb.trx.sendRawTransaction(signedTransaction)\n\n if (!result.result && String(result.code) !== 'DUP_TRANSACTION_ERROR') {\n // Only a pre-push code is a definite rejection. The message is\n // never read.\n if (PRE_PUSH_REJECTION_CODES.has(String(result.code))) {\n rejections++\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction 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 return {\n status: 'accepted',\n txHash: stripHexPrefix(\n broadcastResult.transaction?.txID ?? signedTransaction.txID\n ),\n }\n } catch (error) {\n return {\n status: rejections === attempts ? 'rejected' : 'unknown',\n error,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,2CAAgD,IAAI,IAAI;CAC5D;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;;;;;;AAiBD,eAAsB,yBACpB,QACA,mBAC8B;CAC9B,IAAI,WAAW;CACf,IAAI,aAAa;CACjB,IAAI;EACF,MAAM,kBAAkB,MAAM,sBAC5B,QACA,OAAO,YAAY;GACjB;GACA,MAAM,SAAS,MAAM,QAAQ,IAAI,mBAAmB,iBAAiB;GAErE,IAAI,CAAC,OAAO,UAAU,OAAO,OAAO,IAAI,MAAM,yBAAyB;IAGrE,IAAI,yBAAyB,IAAI,OAAO,OAAO,IAAI,CAAC,GAClD;IAEF,MAAM,IAAI,iBACR,cAAc,mBACd,iCAAiC,OAAO,QAAQ,iBAClD;GACF;GAEA,OAAO;EACT,CACF;EAIA,OAAO;GACL,QAAQ;GACR,QAAQ,eACN,gBAAgB,aAAa,QAAQ,kBAAkB,IACzD;EACF;CACF,SAAS,OAAO;EACd,OAAO;GACL,QAAQ,eAAe,WAAW,aAAa;GAC/C;EACF;CACF;AACF"}
@@ -6,9 +6,11 @@ import { SDKClient } from "@lifi/sdk";
6
6
  * Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
7
7
  * success) and puts the reason in `receipt.result`; both are checked. Throws
8
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.
9
+ * OUT_OF_ENERGY, `TransactionFailed` otherwise); these errors are marked
10
+ * `final`. Tolerates up to `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors
11
+ * and caps total polls at `TRON_POLL_MAX_POLLS`, since `waitForResult`'s
12
+ * maxRetries counts errors only. The poll timeout and RPC errors are not
13
+ * final: the transaction may still be included.
12
14
  */
13
15
  export declare function waitForTronTxConfirmation(client: SDKClient, txHash: string, onChainFailureMessage?: string): Promise<void>;
14
16
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"waitForTronTxConfirmation.d.ts","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"mappings":";;;;;;;;;;;;wBA6CsB,0BACpB,QAAQ,WACR,gBACA,iCACC"}
1
+ {"version":3,"file":"waitForTronTxConfirmation.d.ts","names":[],"sources":["../../../src/rpc/waitForTronTxConfirmation.ts"],"mappings":";;;;;;;;;;;;;;wBAqDsB,0BACpB,QAAQ,WACR,gBACA,iCACC"}
@@ -5,8 +5,8 @@ import { LiFiErrorCode, TransactionError, waitForResult } from "@lifi/sdk";
5
5
  const NON_FAILURE_CONTRACT_RESULTS = /* @__PURE__ */ new Set(["SUCCESS", "DEFAULT"]);
6
6
  function createOnChainFailureError(messageStem, reason) {
7
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}.`);
8
+ if (reason === "OUT_OF_ENERGY") return new TransactionError(LiFiErrorCode.InsufficientFunds, `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`, void 0, { final: true });
9
+ return new TransactionError(LiFiErrorCode.TransactionFailed, reason ? `${stem}: ${reason}.` : `${stem}.`, void 0, { final: true });
10
10
  }
11
11
  /**
12
12
  * Polls getTransactionInfo until the transaction is indexed, then resolves.
@@ -14,9 +14,11 @@ function createOnChainFailureError(messageStem, reason) {
14
14
  * Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
15
15
  * success) and puts the reason in `receipt.result`; both are checked. Throws
16
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.
17
+ * OUT_OF_ENERGY, `TransactionFailed` otherwise); these errors are marked
18
+ * `final`. Tolerates up to `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors
19
+ * and caps total polls at `TRON_POLL_MAX_POLLS`, since `waitForResult`'s
20
+ * maxRetries counts errors only. The poll timeout and RPC errors are not
21
+ * final: the transaction may still be included.
20
22
  */
21
23
  async function waitForTronTxConfirmation(client, txHash, onChainFailureMessage = "Transaction failed on-chain") {
22
24
  let polls = 0;
@@ -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// `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"}
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 // The transaction is in a block and failed there: the outcome is final, so\n // \"Try again\" may sign a new transaction.\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 undefined,\n { final: true }\n )\n }\n return new TransactionError(\n LiFiErrorCode.TransactionFailed,\n reason ? `${stem}: ${reason}.` : `${stem}.`,\n undefined,\n { final: true }\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); these errors are marked\n * `final`. Tolerates up to `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors\n * and caps total polls at `TRON_POLL_MAX_POLLS`, since `waitForResult`'s\n * maxRetries counts errors only. The poll timeout and RPC errors are not\n * final: the transaction may still be included.\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;CAG1C,IAAI,WAAW,iBACb,OAAO,IAAI,iBACT,cAAc,mBACd,GAAG,KAAK,IAAI,OAAO,2DACnB,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,OAAO,IAAI,iBACT,cAAc,mBACd,SAAS,GAAG,KAAK,IAAI,OAAO,KAAK,GAAG,KAAK,IACzC,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;AACF;;;;;;;;;;;;;AAcA,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"}
@@ -0,0 +1,10 @@
1
+ import { Types } from "tronweb";
2
+ //#region src/utils/trc20Abi.d.ts
3
+ /**
4
+ * The TRC-20 reads the SDK makes. With a static ABI, `tronWeb.contract(abi,
5
+ * address)` needs no `wallet/getcontract` request, and TronWeb does not keep
6
+ * the token's ABI and bytecode in `trx.cache.contracts`, which never shrinks.
7
+ */
8
+ export declare const TRC20_ABI: Types.ContractAbiInterface;
9
+ //#endregion
10
+ //# sourceMappingURL=trc20Abi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trc20Abi.d.ts","names":[],"sources":["../../../src/utils/trc20Abi.ts"],"mappings":";;;;;;;qBAOa,WAAW,MAAM"}
@@ -0,0 +1,38 @@
1
+ //#region src/utils/trc20Abi.ts
2
+ /**
3
+ * The TRC-20 reads the SDK makes. With a static ABI, `tronWeb.contract(abi,
4
+ * address)` needs no `wallet/getcontract` request, and TronWeb does not keep
5
+ * the token's ABI and bytecode in `trx.cache.contracts`, which never shrinks.
6
+ */
7
+ const TRC20_ABI = [{
8
+ inputs: [{
9
+ name: "owner",
10
+ type: "address"
11
+ }],
12
+ name: "balanceOf",
13
+ outputs: [{
14
+ name: "",
15
+ type: "uint256"
16
+ }],
17
+ stateMutability: "view",
18
+ type: "function"
19
+ }, {
20
+ inputs: [{
21
+ name: "owner",
22
+ type: "address"
23
+ }, {
24
+ name: "spender",
25
+ type: "address"
26
+ }],
27
+ name: "allowance",
28
+ outputs: [{
29
+ name: "",
30
+ type: "uint256"
31
+ }],
32
+ stateMutability: "view",
33
+ type: "function"
34
+ }];
35
+ //#endregion
36
+ export { TRC20_ABI };
37
+
38
+ //# sourceMappingURL=trc20Abi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trc20Abi.js","names":[],"sources":["../../../src/utils/trc20Abi.ts"],"sourcesContent":["import type { Types } from 'tronweb'\n\n/**\n * The TRC-20 reads the SDK makes. With a static ABI, `tronWeb.contract(abi,\n * address)` needs no `wallet/getcontract` request, and TronWeb does not keep\n * the token's ABI and bytecode in `trx.cache.contracts`, which never shrinks.\n */\nexport const TRC20_ABI: Types.ContractAbiInterface = [\n {\n inputs: [{ name: 'owner', type: 'address' }],\n name: 'balanceOf',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n ],\n name: 'allowance',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n]\n"],"mappings":";;;;;;AAOA,MAAa,YAAwC,CACnD;CACE,QAAQ,CAAC;EAAE,MAAM;EAAS,MAAM;CAAU,CAAC;CAC3C,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAI,MAAM;CAAU,CAAC;CACvC,iBAAiB;CACjB,MAAM;AACR,GACA;CACE,QAAQ,CACN;EAAE,MAAM;EAAS,MAAM;CAAU,GACjC;EAAE,MAAM;EAAW,MAAM;CAAU,CACrC;CACA,MAAM;CACN,SAAS,CAAC;EAAE,MAAM;EAAI,MAAM;CAAU,CAAC;CACvC,iBAAiB;CACjB,MAAM;AACR,CACF"}
@@ -0,0 +1,19 @@
1
+ import { SignedTransaction } from "@tronweb3/tronwallet-abstract-adapter";
2
+ //#region src/utils/tronSignedTransaction.d.ts
3
+ /**
4
+ * Reads a signed transaction back from `ExecutionAction.txHex`.
5
+ *
6
+ * Returns `undefined` unless the value carries everything a resume needs: the
7
+ * `txID` to look the transaction up, a signature to resend it and
8
+ * `raw_data.expiration` to tell when it can no longer land.
9
+ */
10
+ export declare function parseTronSignedTransaction(txHex: string): SignedTransaction | undefined;
11
+ /**
12
+ * Serializes a signed transaction for `ExecutionAction.txHex`.
13
+ *
14
+ * Returns `undefined` when the result would not read back with
15
+ * `parseTronSignedTransaction`, so a stored value is always usable on resume.
16
+ */
17
+ export declare function serializeTronSignedTransaction(signedTransaction: SignedTransaction): string | undefined;
18
+ //#endregion
19
+ //# sourceMappingURL=tronSignedTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tronSignedTransaction.d.ts","names":[],"sources":["../../../src/utils/tronSignedTransaction.ts"],"mappings":";;;;;;;;;wBAagB,2BACd,gBACC;;;;;;;wBAgCa,+BACd,mBAAmB"}
@@ -0,0 +1,38 @@
1
+ import { stripHexPrefix } from "./stripHexPrefix.js";
2
+ //#region src/utils/tronSignedTransaction.ts
3
+ const TX_ID_PATTERN = /^[0-9a-f]{64}$/i;
4
+ /**
5
+ * Reads a signed transaction back from `ExecutionAction.txHex`.
6
+ *
7
+ * Returns `undefined` unless the value carries everything a resume needs: the
8
+ * `txID` to look the transaction up, a signature to resend it and
9
+ * `raw_data.expiration` to tell when it can no longer land.
10
+ */
11
+ function parseTronSignedTransaction(txHex) {
12
+ let value;
13
+ try {
14
+ value = JSON.parse(txHex);
15
+ } catch {
16
+ return;
17
+ }
18
+ if (!value || typeof value !== "object") return;
19
+ const { txID, signature, raw_data } = value;
20
+ if (typeof txID !== "string" || !TX_ID_PATTERN.test(stripHexPrefix(txID))) return;
21
+ if (!Array.isArray(signature) || !signature.length) return;
22
+ if (typeof raw_data?.expiration !== "number" || !Number.isFinite(raw_data.expiration)) return;
23
+ return value;
24
+ }
25
+ /**
26
+ * Serializes a signed transaction for `ExecutionAction.txHex`.
27
+ *
28
+ * Returns `undefined` when the result would not read back with
29
+ * `parseTronSignedTransaction`, so a stored value is always usable on resume.
30
+ */
31
+ function serializeTronSignedTransaction(signedTransaction) {
32
+ const txHex = JSON.stringify(signedTransaction);
33
+ return txHex && parseTronSignedTransaction(txHex) ? txHex : void 0;
34
+ }
35
+ //#endregion
36
+ export { parseTronSignedTransaction, serializeTronSignedTransaction };
37
+
38
+ //# sourceMappingURL=tronSignedTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tronSignedTransaction.js","names":[],"sources":["../../../src/utils/tronSignedTransaction.ts"],"sourcesContent":["import type { SignedTransaction } from '@tronweb3/tronwallet-abstract-adapter'\nimport { stripHexPrefix } from './stripHexPrefix.js'\n\n// A txID is the SHA-256 of `raw_data_hex`: 32 bytes, 64 hex characters.\nconst TX_ID_PATTERN = /^[0-9a-f]{64}$/i\n\n/**\n * Reads a signed transaction back from `ExecutionAction.txHex`.\n *\n * Returns `undefined` unless the value carries everything a resume needs: the\n * `txID` to look the transaction up, a signature to resend it and\n * `raw_data.expiration` to tell when it can no longer land.\n */\nexport function parseTronSignedTransaction(\n txHex: string\n): SignedTransaction | undefined {\n let value: unknown\n try {\n value = JSON.parse(txHex)\n } catch {\n return undefined\n }\n if (!value || typeof value !== 'object') {\n return undefined\n }\n const { txID, signature, raw_data } = value as Partial<SignedTransaction>\n if (typeof txID !== 'string' || !TX_ID_PATTERN.test(stripHexPrefix(txID))) {\n return undefined\n }\n if (!Array.isArray(signature) || !signature.length) {\n return undefined\n }\n if (\n typeof raw_data?.expiration !== 'number' ||\n !Number.isFinite(raw_data.expiration)\n ) {\n return undefined\n }\n return value as SignedTransaction\n}\n\n/**\n * Serializes a signed transaction for `ExecutionAction.txHex`.\n *\n * Returns `undefined` when the result would not read back with\n * `parseTronSignedTransaction`, so a stored value is always usable on resume.\n */\nexport function serializeTronSignedTransaction(\n signedTransaction: SignedTransaction\n): string | undefined {\n const txHex = JSON.stringify(signedTransaction) as string | undefined\n return txHex && parseTronSignedTransaction(txHex) ? txHex : undefined\n}\n"],"mappings":";;AAIA,MAAM,gBAAgB;;;;;;;;AAStB,SAAgB,2BACd,OAC+B;CAC/B,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,KAAK;CAC1B,QAAQ;EACN;CACF;CACA,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B;CAEF,MAAM,EAAE,MAAM,WAAW,aAAa;CACtC,IAAI,OAAO,SAAS,YAAY,CAAC,cAAc,KAAK,eAAe,IAAI,CAAC,GACtE;CAEF,IAAI,CAAC,MAAM,QAAQ,SAAS,KAAK,CAAC,UAAU,QAC1C;CAEF,IACE,OAAO,UAAU,eAAe,YAChC,CAAC,OAAO,SAAS,SAAS,UAAU,GAEpC;CAEF,OAAO;AACT;;;;;;;AAQA,SAAgB,+BACd,mBACoB;CACpB,MAAM,QAAQ,KAAK,UAAU,iBAAiB;CAC9C,OAAO,SAAS,2BAA2B,KAAK,IAAI,QAAQ,KAAA;AAC9D"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk-provider-tron";
3
- export declare const version = "4.1.6";
3
+ export declare const version = "4.1.8";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-tron";
3
- const version = "4.1.6";
3
+ const version = "4.1.8";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -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.1.6'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-tron'\nexport const version = '4.1.8'\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.1.6",
3
+ "version": "4.1.8",
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.10.0",
31
+ "@lifi/sdk": "4.12.0",
32
32
  "@tronweb3/tronwallet-abstract-adapter": "^1.3.0",
33
33
  "tronweb": "^6.5.1"
34
34
  },