@lifi/sdk-provider-tron 4.1.5 → 4.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +16 -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 +8 -5
  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 +9 -6
  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 +29 -8
  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
@@ -21,15 +21,21 @@ function createOnChainFailureError(
21
21
  reason?: string
22
22
  ): TransactionError {
23
23
  const stem = messageStem.replace(/\.$/, '')
24
+ // The transaction is in a block and failed there: the outcome is final, so
25
+ // "Try again" may sign a new transaction.
24
26
  if (reason === 'OUT_OF_ENERGY') {
25
27
  return new TransactionError(
26
28
  LiFiErrorCode.InsufficientFunds,
27
- `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`
29
+ `${stem}: ${reason}. The account may need more TRX to cover the energy fee.`,
30
+ undefined,
31
+ { final: true }
28
32
  )
29
33
  }
30
34
  return new TransactionError(
31
35
  LiFiErrorCode.TransactionFailed,
32
- reason ? `${stem}: ${reason}.` : `${stem}.`
36
+ reason ? `${stem}: ${reason}.` : `${stem}.`,
37
+ undefined,
38
+ { final: true }
33
39
  )
34
40
  }
35
41
 
@@ -39,9 +45,11 @@ function createOnChainFailureError(
39
45
  * Tron marks a failed execution with a top-level `result: 'FAILED'` (omitted on
40
46
  * success) and puts the reason in `receipt.result`; both are checked. Throws
41
47
  * `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.
48
+ * OUT_OF_ENERGY, `TransactionFailed` otherwise); these errors are marked
49
+ * `final`. Tolerates up to `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors
50
+ * and caps total polls at `TRON_POLL_MAX_POLLS`, since `waitForResult`'s
51
+ * maxRetries counts errors only. The poll timeout and RPC errors are not
52
+ * final: the transaction may still be included.
45
53
  */
46
54
  export async function waitForTronTxConfirmation(
47
55
  client: SDKClient,
@@ -0,0 +1,26 @@
1
+ import type { Types } from 'tronweb'
2
+
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 const TRC20_ABI: Types.ContractAbiInterface = [
9
+ {
10
+ inputs: [{ name: 'owner', type: 'address' }],
11
+ name: 'balanceOf',
12
+ outputs: [{ name: '', type: 'uint256' }],
13
+ stateMutability: 'view',
14
+ type: 'function',
15
+ },
16
+ {
17
+ inputs: [
18
+ { name: 'owner', type: 'address' },
19
+ { name: 'spender', type: 'address' },
20
+ ],
21
+ name: 'allowance',
22
+ outputs: [{ name: '', type: 'uint256' }],
23
+ stateMutability: 'view',
24
+ type: 'function',
25
+ },
26
+ ]
@@ -0,0 +1,53 @@
1
+ import type { SignedTransaction } from '@tronweb3/tronwallet-abstract-adapter'
2
+ import { stripHexPrefix } from './stripHexPrefix.js'
3
+
4
+ // A txID is the SHA-256 of `raw_data_hex`: 32 bytes, 64 hex characters.
5
+ const TX_ID_PATTERN = /^[0-9a-f]{64}$/i
6
+
7
+ /**
8
+ * Reads a signed transaction back from `ExecutionAction.txHex`.
9
+ *
10
+ * Returns `undefined` unless the value carries everything a resume needs: the
11
+ * `txID` to look the transaction up, a signature to resend it and
12
+ * `raw_data.expiration` to tell when it can no longer land.
13
+ */
14
+ export function parseTronSignedTransaction(
15
+ txHex: string
16
+ ): SignedTransaction | undefined {
17
+ let value: unknown
18
+ try {
19
+ value = JSON.parse(txHex)
20
+ } catch {
21
+ return undefined
22
+ }
23
+ if (!value || typeof value !== 'object') {
24
+ return undefined
25
+ }
26
+ const { txID, signature, raw_data } = value as Partial<SignedTransaction>
27
+ if (typeof txID !== 'string' || !TX_ID_PATTERN.test(stripHexPrefix(txID))) {
28
+ return undefined
29
+ }
30
+ if (!Array.isArray(signature) || !signature.length) {
31
+ return undefined
32
+ }
33
+ if (
34
+ typeof raw_data?.expiration !== 'number' ||
35
+ !Number.isFinite(raw_data.expiration)
36
+ ) {
37
+ return undefined
38
+ }
39
+ return value as SignedTransaction
40
+ }
41
+
42
+ /**
43
+ * Serializes a signed transaction for `ExecutionAction.txHex`.
44
+ *
45
+ * Returns `undefined` when the result would not read back with
46
+ * `parseTronSignedTransaction`, so a stored value is always usable on resume.
47
+ */
48
+ export function serializeTronSignedTransaction(
49
+ signedTransaction: SignedTransaction
50
+ ): string | undefined {
51
+ const txHex = JSON.stringify(signedTransaction) as string | undefined
52
+ return txHex && parseTronSignedTransaction(txHex) ? txHex : undefined
53
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-tron'
2
- export const version = '4.1.5'
2
+ export const version = '4.1.7'