@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.
- package/CHANGELOG.md +16 -0
- package/README.md +9 -0
- package/dist/cjs/actions/getTronBalance.js +2 -1
- package/dist/cjs/actions/getTronBalance.js.map +1 -1
- package/dist/cjs/core/TronStepExecutor.js +8 -5
- package/dist/cjs/core/TronStepExecutor.js.map +1 -1
- package/dist/cjs/core/constants.d.ts +3 -0
- package/dist/cjs/core/constants.js +6 -0
- package/dist/cjs/core/constants.js.map +1 -1
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.js +2 -1
- package/dist/cjs/core/tasks/TronCheckAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.js +11 -1
- package/dist/cjs/core/tasks/TronSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.js +63 -15
- package/dist/cjs/core/tasks/TronWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.d.ts +22 -0
- package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.js +88 -0
- package/dist/cjs/core/tasks/helpers/isTronTransactionDropped.js.map +1 -0
- package/dist/cjs/rpc/broadcastTronTransaction.d.ts +31 -0
- package/dist/cjs/rpc/broadcastTronTransaction.js +68 -0
- package/dist/cjs/rpc/broadcastTronTransaction.js.map +1 -0
- package/dist/cjs/rpc/waitForTronTxConfirmation.d.ts +5 -3
- package/dist/cjs/rpc/waitForTronTxConfirmation.js +7 -5
- package/dist/cjs/rpc/waitForTronTxConfirmation.js.map +1 -1
- package/dist/cjs/utils/trc20Abi.d.ts +10 -0
- package/dist/cjs/utils/trc20Abi.js +39 -0
- package/dist/cjs/utils/trc20Abi.js.map +1 -0
- package/dist/cjs/utils/tronSignedTransaction.d.ts +19 -0
- package/dist/cjs/utils/tronSignedTransaction.js +40 -0
- package/dist/cjs/utils/tronSignedTransaction.js.map +1 -0
- 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/actions/getTronBalance.d.ts.map +1 -1
- package/dist/esm/actions/getTronBalance.js +2 -1
- package/dist/esm/actions/getTronBalance.js.map +1 -1
- package/dist/esm/core/TronStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/TronStepExecutor.js +9 -6
- package/dist/esm/core/TronStepExecutor.js.map +1 -1
- package/dist/esm/core/constants.d.ts +3 -0
- package/dist/esm/core/constants.d.ts.map +1 -1
- package/dist/esm/core/constants.js +4 -1
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/tasks/TronCheckAllowanceTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronCheckAllowanceTask.js +2 -1
- package/dist/esm/core/tasks/TronCheckAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronSignAndExecuteTask.js +12 -2
- package/dist/esm/core/tasks/TronSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/TronWaitForTransactionTask.js +64 -16
- package/dist/esm/core/tasks/TronWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/isTronTransactionDropped.d.ts +22 -0
- package/dist/esm/core/tasks/helpers/isTronTransactionDropped.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/isTronTransactionDropped.js +87 -0
- package/dist/esm/core/tasks/helpers/isTronTransactionDropped.js.map +1 -0
- package/dist/esm/rpc/broadcastTronTransaction.d.ts +31 -0
- package/dist/esm/rpc/broadcastTronTransaction.d.ts.map +1 -0
- package/dist/esm/rpc/broadcastTronTransaction.js +67 -0
- package/dist/esm/rpc/broadcastTronTransaction.js.map +1 -0
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts +5 -3
- package/dist/esm/rpc/waitForTronTxConfirmation.d.ts.map +1 -1
- package/dist/esm/rpc/waitForTronTxConfirmation.js +7 -5
- package/dist/esm/rpc/waitForTronTxConfirmation.js.map +1 -1
- package/dist/esm/utils/trc20Abi.d.ts +10 -0
- package/dist/esm/utils/trc20Abi.d.ts.map +1 -0
- package/dist/esm/utils/trc20Abi.js +38 -0
- package/dist/esm/utils/trc20Abi.js.map +1 -0
- package/dist/esm/utils/tronSignedTransaction.d.ts +19 -0
- package/dist/esm/utils/tronSignedTransaction.d.ts.map +1 -0
- package/dist/esm/utils/tronSignedTransaction.js +38 -0
- package/dist/esm/utils/tronSignedTransaction.js.map +1 -0
- 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/actions/getTronBalance.ts +2 -1
- package/src/core/TronStepExecutor.ts +29 -8
- package/src/core/constants.ts +12 -0
- package/src/core/tasks/TronCheckAllowanceTask.ts +2 -1
- package/src/core/tasks/TronSignAndExecuteTask.ts +32 -0
- package/src/core/tasks/TronWaitForTransactionTask.ts +153 -33
- package/src/core/tasks/helpers/isTronTransactionDropped.ts +159 -0
- package/src/rpc/broadcastTronTransaction.ts +92 -0
- package/src/rpc/waitForTronTxConfirmation.ts +13 -5
- package/src/utils/trc20Abi.ts +26 -0
- package/src/utils/tronSignedTransaction.ts +53 -0
- 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)
|
|
43
|
-
* `TRON_POLL_MAX_ERROR_RETRIES` transient RPC errors
|
|
44
|
-
* `TRON_POLL_MAX_POLLS`, since `waitForResult`'s
|
|
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.
|
|
2
|
+
export const version = '4.1.7'
|