@lifi/sdk 3.3.0-alpha.3 → 3.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -7
- package/src/_cjs/config.js +1 -0
- package/src/_cjs/config.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +15 -3
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +5 -1
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/switchChain.js +5 -1
- package/src/_cjs/core/EVM/switchChain.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +10 -2
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/StatusManager.js +2 -1
- package/src/_cjs/core/StatusManager.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js +39 -17
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_cjs/core/UTXO/getUTXOPublicClient.js +1 -0
- package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
- package/src/_cjs/core/UTXO/parseUTXOErrors.js +4 -0
- package/src/_cjs/core/UTXO/parseUTXOErrors.js.map +1 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js +31 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js +27 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +18 -9
- package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +1 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js +185 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js +45 -0
- package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js +3 -0
- package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js +51 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js +50 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js +48 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js.map +1 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js +28 -0
- package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js.map +1 -0
- package/src/_cjs/errors/constants.js +1 -0
- package/src/_cjs/errors/constants.js.map +1 -1
- package/src/_cjs/services/api.js +1 -1
- package/src/_cjs/services/balance.js +9 -2
- package/src/_cjs/services/balance.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/config.js +1 -0
- package/src/_esm/config.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +15 -3
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +5 -1
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/switchChain.js +5 -1
- package/src/_esm/core/EVM/switchChain.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +10 -2
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/StatusManager.js +11 -4
- package/src/_esm/core/StatusManager.js.map +1 -1
- package/src/_esm/core/UTXO/UTXOStepExecutor.js +41 -35
- package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_esm/core/UTXO/getUTXOPublicClient.js +1 -0
- package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
- package/src/_esm/core/UTXO/parseUTXOErrors.js +5 -0
- package/src/_esm/core/UTXO/parseUTXOErrors.js.map +1 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js +28 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js +24 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +18 -10
- package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +1 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js +230 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js +58 -0
- package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js +2 -0
- package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js +55 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js +53 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/observe.js +51 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/observe.js.map +1 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/poll.js +28 -0
- package/src/_esm/core/UTXO/utxo-stack/utils/poll.js.map +1 -0
- package/src/_esm/errors/constants.js +1 -0
- package/src/_esm/errors/constants.js.map +1 -1
- package/src/_esm/services/api.js +1 -1
- package/src/_esm/services/balance.js +9 -2
- package/src/_esm/services/balance.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/config.d.ts.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/StatusManager.d.ts +18 -8
- package/src/_types/core/StatusManager.d.ts.map +1 -1
- package/src/_types/core/UTXO/UTXOStepExecutor.d.ts.map +1 -1
- package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts +13 -0
- package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts +15 -0
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts +2 -2
- package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts.map +1 -1
- package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts +1 -1
- package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts.map +1 -1
- package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts +76 -0
- package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts +26 -0
- package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts +16 -0
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts.map +1 -1
- package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts +35 -0
- package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts +3 -0
- package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts +3 -0
- package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts +19 -0
- package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts.map +1 -0
- package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts +13 -0
- package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts.map +1 -0
- package/src/_types/errors/constants.d.ts +2 -1
- package/src/_types/errors/constants.d.ts.map +1 -1
- package/src/_types/services/balance.d.ts.map +1 -1
- package/src/_types/types/internal.d.ts +1 -0
- package/src/_types/types/internal.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/config.ts +1 -0
- package/src/core/EVM/EVMStepExecutor.ts +12 -10
- package/src/core/EVM/checkAllowance.ts +4 -3
- package/src/core/EVM/switchChain.ts +4 -4
- package/src/core/Solana/SolanaStepExecutor.ts +8 -7
- package/src/core/StatusManager.ts +24 -22
- package/src/core/UTXO/UTXOStepExecutor.ts +56 -53
- package/src/core/UTXO/getUTXOPublicClient.ts +1 -0
- package/src/core/UTXO/parseUTXOErrors.ts +11 -0
- package/src/core/UTXO/utxo-stack/actions/getBlock.ts +58 -0
- package/src/core/UTXO/utxo-stack/actions/getBlockStats.ts +55 -0
- package/src/core/UTXO/utxo-stack/actions/getUTXOTransaction.ts +24 -11
- package/src/core/UTXO/utxo-stack/actions/sendUTXOTransaction.ts +1 -1
- package/src/core/UTXO/utxo-stack/actions/waitForTransaction.ts +387 -0
- package/src/core/UTXO/utxo-stack/actions/watchBlockNumber.ts +105 -0
- package/src/core/UTXO/utxo-stack/transports/utxo/types.ts +16 -0
- package/src/core/UTXO/utxo-stack/types/blockStats.ts +35 -0
- package/src/core/UTXO/utxo-stack/utils/cancelTransaction.ts +75 -0
- package/src/core/UTXO/utxo-stack/utils/modifyFee.ts +78 -0
- package/src/core/UTXO/utxo-stack/utils/observe.ts +81 -0
- package/src/core/UTXO/utxo-stack/utils/poll.ts +46 -0
- package/src/errors/constants.ts +1 -0
- package/src/services/api.ts +1 -1
- package/src/services/balance.ts +11 -2
- package/src/types/internal.ts +1 -0
- package/src/version.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ChainId,
|
|
2
3
|
Execution,
|
|
3
4
|
ExecutionStatus,
|
|
4
5
|
LiFiStep,
|
|
@@ -10,19 +11,12 @@ import { executionState } from './executionState.js'
|
|
|
10
11
|
import { getProcessMessage } from './processMessages.js'
|
|
11
12
|
import type { LiFiStepExtended } from './types.js'
|
|
12
13
|
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
| 'txLink'
|
|
20
|
-
| 'error'
|
|
21
|
-
| 'substatus'
|
|
22
|
-
| 'substatusMessage'
|
|
23
|
-
| 'multisigTxHash'
|
|
24
|
-
>
|
|
25
|
-
>
|
|
14
|
+
export type FindOrCreateProcessProps = {
|
|
15
|
+
step: LiFiStepExtended
|
|
16
|
+
type: ProcessType
|
|
17
|
+
chainId?: ChainId
|
|
18
|
+
status?: ProcessStatus
|
|
19
|
+
}
|
|
26
20
|
|
|
27
21
|
/**
|
|
28
22
|
* Manages status updates of a route and provides various functions for tracking processes
|
|
@@ -88,16 +82,23 @@ export class StatusManager {
|
|
|
88
82
|
|
|
89
83
|
/**
|
|
90
84
|
* Create and push a new process into the execution.
|
|
91
|
-
* @param step The step that should contain the new process.
|
|
92
|
-
* @param type Type of the process. Used to identify already existing processes.
|
|
93
|
-
* @param
|
|
85
|
+
* @param step.step The step that should contain the new process.
|
|
86
|
+
* @param step.type Type of the process. Used to identify already existing processes.
|
|
87
|
+
* @param step.chainId Chain Id of the process.
|
|
88
|
+
* @param step.status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
89
|
+
* @param root0
|
|
90
|
+
* @param root0.step
|
|
91
|
+
* @param root0.type
|
|
92
|
+
* @param root0.chainId
|
|
93
|
+
* @param root0.status
|
|
94
94
|
* @returns Returns process.
|
|
95
95
|
*/
|
|
96
|
-
findOrCreateProcess = (
|
|
97
|
-
step
|
|
98
|
-
type
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
findOrCreateProcess = ({
|
|
97
|
+
step,
|
|
98
|
+
type,
|
|
99
|
+
chainId,
|
|
100
|
+
status,
|
|
101
|
+
}: FindOrCreateProcessProps): Process => {
|
|
101
102
|
if (!step.execution?.process) {
|
|
102
103
|
throw new Error("Execution hasn't been initialized.")
|
|
103
104
|
}
|
|
@@ -117,6 +118,7 @@ export class StatusManager {
|
|
|
117
118
|
startedAt: Date.now(),
|
|
118
119
|
message: getProcessMessage(type, status ?? 'STARTED'),
|
|
119
120
|
status: status ?? 'STARTED',
|
|
121
|
+
chainId: chainId,
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
step.execution.process.push(newProcess)
|
|
@@ -136,7 +138,7 @@ export class StatusManager {
|
|
|
136
138
|
step: LiFiStepExtended,
|
|
137
139
|
type: ProcessType,
|
|
138
140
|
status: ProcessStatus,
|
|
139
|
-
params?:
|
|
141
|
+
params?: Partial<Process>
|
|
140
142
|
): Process => {
|
|
141
143
|
if (!step.execution) {
|
|
142
144
|
throw new Error("Can't update an empty step execution.")
|
|
@@ -4,15 +4,12 @@ import {
|
|
|
4
4
|
type FullStatusData,
|
|
5
5
|
} from '@lifi/types'
|
|
6
6
|
import { address, networks, Psbt } from 'bitcoinjs-lib'
|
|
7
|
-
import {
|
|
7
|
+
import { withTimeout, type Client } from 'viem'
|
|
8
8
|
import { config } from '../../config.js'
|
|
9
9
|
import { LiFiErrorCode } from '../../errors/constants.js'
|
|
10
10
|
import { TransactionError } from '../../errors/errors.js'
|
|
11
11
|
import { getStepTransaction } from '../../services/api.js'
|
|
12
|
-
import {
|
|
13
|
-
getTransactionFailedMessage,
|
|
14
|
-
waitForResult,
|
|
15
|
-
} from '../../utils/index.js'
|
|
12
|
+
import { getTransactionFailedMessage } from '../../utils/index.js'
|
|
16
13
|
import { BaseStepExecutor } from '../BaseStepExecutor.js'
|
|
17
14
|
import { checkBalance } from '../checkBalance.js'
|
|
18
15
|
import { getSubstatusMessage } from '../processMessages.js'
|
|
@@ -26,6 +23,10 @@ import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js'
|
|
|
26
23
|
import { getUTXOPublicClient } from './getUTXOPublicClient.js'
|
|
27
24
|
import { parseUTXOErrors } from './parseUTXOErrors.js'
|
|
28
25
|
import { signPsbt } from './utxo-stack/actions/signPsbt.js'
|
|
26
|
+
import {
|
|
27
|
+
waitForTransaction,
|
|
28
|
+
type ReplacementReason,
|
|
29
|
+
} from './utxo-stack/actions/waitForTransaction.js'
|
|
29
30
|
|
|
30
31
|
export interface UTXOStepExecutorOptions extends StepExecutorOptions {
|
|
31
32
|
client: Client
|
|
@@ -60,22 +61,25 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
60
61
|
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
61
62
|
|
|
62
63
|
// STEP 2: Get transaction
|
|
63
|
-
let process = this.statusManager.findOrCreateProcess(
|
|
64
|
+
let process = this.statusManager.findOrCreateProcess({
|
|
64
65
|
step,
|
|
65
|
-
currentProcessType
|
|
66
|
-
|
|
66
|
+
type: currentProcessType,
|
|
67
|
+
chainId: fromChain.id,
|
|
68
|
+
})
|
|
67
69
|
|
|
68
70
|
const publicClient = await getUTXOPublicClient(ChainId.BTC)
|
|
69
71
|
|
|
70
72
|
if (process.status !== 'DONE') {
|
|
71
73
|
try {
|
|
72
74
|
let txHash: string
|
|
75
|
+
let txHex: string
|
|
73
76
|
if (process.txHash) {
|
|
74
77
|
// Make sure that the chain is still correct
|
|
75
78
|
this.checkClient(step)
|
|
76
79
|
|
|
77
80
|
// Wait for exiting transaction
|
|
78
81
|
txHash = process.txHash
|
|
82
|
+
txHex = process.txHex
|
|
79
83
|
} else {
|
|
80
84
|
process = this.statusManager.updateProcess(
|
|
81
85
|
step,
|
|
@@ -146,24 +150,7 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
146
150
|
|
|
147
151
|
this.checkClient(step)
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// const apiClient = blockchairApi({ chain: Chain.Bitcoin })
|
|
152
|
-
// const txFeeRate = await apiClient.getSuggestedTxFee()
|
|
153
|
-
|
|
154
|
-
// const tx = await toolbox.buildTx({
|
|
155
|
-
// assetValue: {
|
|
156
|
-
// bigIntValue: step.transactionRequest.value,
|
|
157
|
-
// },
|
|
158
|
-
// recipient: step.transactionRequest.to,
|
|
159
|
-
// memo: step.transactionRequest.data,
|
|
160
|
-
// sender: this.client.account?.address,
|
|
161
|
-
// chain: 'BTC',
|
|
162
|
-
// apiClient: blockchairApi({ chain: Chain.Bitcoin }),
|
|
163
|
-
// feeRate: txFeeRate,
|
|
164
|
-
// })
|
|
165
|
-
|
|
166
|
-
let psbtHex = transactionRequest.data // tx.psbt.toHex()
|
|
153
|
+
const psbtHex = transactionRequest.data
|
|
167
154
|
|
|
168
155
|
const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })
|
|
169
156
|
|
|
@@ -190,8 +177,6 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
190
177
|
.values()
|
|
191
178
|
)
|
|
192
179
|
|
|
193
|
-
psbtHex = psbt.toHex()
|
|
194
|
-
|
|
195
180
|
// We give users 10 minutes to sign the transaction or it should be considered expired
|
|
196
181
|
const signedPsbtHex = await withTimeout(
|
|
197
182
|
() =>
|
|
@@ -211,10 +196,10 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
211
196
|
|
|
212
197
|
const signedPsbt = Psbt.fromHex(signedPsbtHex).finalizeAllInputs()
|
|
213
198
|
|
|
214
|
-
|
|
199
|
+
txHex = signedPsbt.extractTransaction().toHex()
|
|
215
200
|
|
|
216
201
|
txHash = await publicClient.sendUTXOTransaction({
|
|
217
|
-
hex:
|
|
202
|
+
hex: txHex,
|
|
218
203
|
})
|
|
219
204
|
|
|
220
205
|
process = this.statusManager.updateProcess(
|
|
@@ -224,31 +209,48 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
224
209
|
{
|
|
225
210
|
txHash: txHash,
|
|
226
211
|
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
|
|
212
|
+
txHex,
|
|
227
213
|
}
|
|
228
214
|
)
|
|
229
215
|
}
|
|
230
216
|
|
|
231
|
-
|
|
232
|
-
await
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
return tx
|
|
244
|
-
},
|
|
217
|
+
let replacementReason: ReplacementReason | undefined
|
|
218
|
+
const transaction = await waitForTransaction(publicClient, {
|
|
219
|
+
txId: txHash,
|
|
220
|
+
txHex,
|
|
221
|
+
senderAddress: this.client.account?.address,
|
|
222
|
+
onReplaced: (response) => {
|
|
223
|
+
replacementReason = response.reason
|
|
224
|
+
process = this.statusManager.updateProcess(
|
|
225
|
+
step,
|
|
226
|
+
process.type,
|
|
227
|
+
'PENDING',
|
|
245
228
|
{
|
|
246
|
-
|
|
247
|
-
|
|
229
|
+
txHash: response.transaction.txid,
|
|
230
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,
|
|
248
231
|
}
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
)
|
|
232
|
+
)
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
if (replacementReason === 'cancelled') {
|
|
237
|
+
throw new TransactionError(
|
|
238
|
+
LiFiErrorCode.TransactionCanceled,
|
|
239
|
+
'User canceled transaction.'
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (transaction.txid !== txHash) {
|
|
244
|
+
process = this.statusManager.updateProcess(
|
|
245
|
+
step,
|
|
246
|
+
process.type,
|
|
247
|
+
'PENDING',
|
|
248
|
+
{
|
|
249
|
+
txHash: transaction.txid,
|
|
250
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
}
|
|
252
254
|
|
|
253
255
|
if (isBridgeExecution) {
|
|
254
256
|
process = this.statusManager.updateProcess(step, process.type, 'DONE')
|
|
@@ -274,11 +276,12 @@ export class UTXOStepExecutor extends BaseStepExecutor {
|
|
|
274
276
|
// STEP 5: Wait for the receiving chain
|
|
275
277
|
const processTxHash = process.txHash
|
|
276
278
|
if (isBridgeExecution) {
|
|
277
|
-
process = this.statusManager.findOrCreateProcess(
|
|
279
|
+
process = this.statusManager.findOrCreateProcess({
|
|
278
280
|
step,
|
|
279
|
-
'RECEIVING_CHAIN',
|
|
280
|
-
'PENDING'
|
|
281
|
-
|
|
281
|
+
type: 'RECEIVING_CHAIN',
|
|
282
|
+
status: 'PENDING',
|
|
283
|
+
chainId: toChain.id,
|
|
284
|
+
})
|
|
282
285
|
}
|
|
283
286
|
let statusResponse: FullStatusData
|
|
284
287
|
try {
|
|
@@ -21,6 +21,17 @@ export const parseUTXOErrors = async (
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const handleSpecificErrors = (e: any) => {
|
|
24
|
+
// txn-mempool-conflict
|
|
25
|
+
if (
|
|
26
|
+
e.details?.includes?.('conflict') ||
|
|
27
|
+
e.cause?.message?.includes?.('conflict')
|
|
28
|
+
) {
|
|
29
|
+
return new TransactionError(
|
|
30
|
+
LiFiErrorCode.TransactionConflict,
|
|
31
|
+
'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',
|
|
32
|
+
e
|
|
33
|
+
)
|
|
34
|
+
}
|
|
24
35
|
if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {
|
|
25
36
|
return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)
|
|
26
37
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Block } from 'bitcoinjs-lib'
|
|
2
|
+
import {
|
|
3
|
+
BlockNotFoundError,
|
|
4
|
+
type Account,
|
|
5
|
+
type Chain,
|
|
6
|
+
type Client,
|
|
7
|
+
type Transport,
|
|
8
|
+
} from 'viem'
|
|
9
|
+
import type { UTXOSchema } from '../transports/utxo/types.js'
|
|
10
|
+
|
|
11
|
+
export type GetBlockParameters =
|
|
12
|
+
| {
|
|
13
|
+
blockHash: string
|
|
14
|
+
blockNumber?: never
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
blockHash?: never
|
|
18
|
+
blockNumber: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type GetBlockReturnType = Block
|
|
22
|
+
|
|
23
|
+
export async function getBlock<
|
|
24
|
+
C extends Chain | undefined,
|
|
25
|
+
A extends Account | undefined = Account | undefined,
|
|
26
|
+
>(
|
|
27
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
28
|
+
{ blockHash, blockNumber }: GetBlockParameters
|
|
29
|
+
): Promise<GetBlockReturnType> {
|
|
30
|
+
let blockHex: string | undefined
|
|
31
|
+
try {
|
|
32
|
+
let _blockHash = blockHash
|
|
33
|
+
if (!_blockHash && blockNumber) {
|
|
34
|
+
_blockHash = await client.request(
|
|
35
|
+
{
|
|
36
|
+
method: 'getblockhash',
|
|
37
|
+
params: [blockNumber],
|
|
38
|
+
},
|
|
39
|
+
{ dedupe: true }
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
if (_blockHash) {
|
|
43
|
+
blockHex = await client.request(
|
|
44
|
+
{
|
|
45
|
+
method: 'getblock',
|
|
46
|
+
params: [_blockHash, 0],
|
|
47
|
+
},
|
|
48
|
+
{ dedupe: true }
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
53
|
+
}
|
|
54
|
+
if (!blockHex) {
|
|
55
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
56
|
+
}
|
|
57
|
+
return Block.fromHex(blockHex)
|
|
58
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BlockNotFoundError,
|
|
3
|
+
type Account,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import type { UTXOSchema } from '../transports/utxo/types.js'
|
|
9
|
+
import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'
|
|
10
|
+
|
|
11
|
+
export type GetBlockStatsParameters = (
|
|
12
|
+
| {
|
|
13
|
+
blockHash: string
|
|
14
|
+
blockNumber?: never
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
blockHash?: never
|
|
18
|
+
blockNumber: number
|
|
19
|
+
}
|
|
20
|
+
) & {
|
|
21
|
+
stats?: Array<BlockStatsKeys>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type GetBlockStatsReturnType = BlockStats
|
|
25
|
+
|
|
26
|
+
export async function getBlockStats<
|
|
27
|
+
C extends Chain | undefined,
|
|
28
|
+
A extends Account | undefined = Account | undefined,
|
|
29
|
+
>(
|
|
30
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
31
|
+
{ blockHash, blockNumber, stats }: GetBlockStatsParameters
|
|
32
|
+
): Promise<GetBlockStatsReturnType> {
|
|
33
|
+
const blockHashOrNumber = blockHash || blockNumber
|
|
34
|
+
if (!blockHashOrNumber) {
|
|
35
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const params: [string | number, Array<BlockStatsKeys>?] = [
|
|
39
|
+
blockHashOrNumber,
|
|
40
|
+
]
|
|
41
|
+
if (stats) {
|
|
42
|
+
params.push(stats)
|
|
43
|
+
}
|
|
44
|
+
const data = await client.request(
|
|
45
|
+
{
|
|
46
|
+
method: 'getblockstats',
|
|
47
|
+
params: params,
|
|
48
|
+
},
|
|
49
|
+
{ dedupe: true }
|
|
50
|
+
)
|
|
51
|
+
return data
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TransactionNotFoundError,
|
|
3
|
+
type Account,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
2
8
|
import type { UTXOSchema } from '../transports/utxo/types.js'
|
|
3
9
|
import type { UTXOTransaction } from '../types/transaction.js'
|
|
4
10
|
|
|
@@ -6,7 +12,7 @@ export type GetUTXOTransactionParameters = {
|
|
|
6
12
|
/** The Id of the transaction */
|
|
7
13
|
txId: string
|
|
8
14
|
/** The block in which to look for the transaction */
|
|
9
|
-
|
|
15
|
+
blockHash?: string
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
export type GetUTXOTransactionReturnType = UTXOTransaction
|
|
@@ -16,15 +22,22 @@ export async function getUTXOTransaction<
|
|
|
16
22
|
A extends Account | undefined = Account | undefined,
|
|
17
23
|
>(
|
|
18
24
|
client: Client<Transport, C, A, UTXOSchema>,
|
|
19
|
-
{ txId,
|
|
25
|
+
{ txId, blockHash }: GetUTXOTransactionParameters
|
|
20
26
|
): Promise<GetUTXOTransactionReturnType> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
try {
|
|
28
|
+
const params: [string, boolean, string?] = [txId, true]
|
|
29
|
+
if (blockHash) {
|
|
30
|
+
params.push(blockHash)
|
|
31
|
+
}
|
|
32
|
+
const data = await client.request({
|
|
33
|
+
method: 'getrawtransaction',
|
|
34
|
+
params: params,
|
|
35
|
+
})
|
|
36
|
+
return data
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new TransactionNotFoundError({
|
|
39
|
+
blockHash: blockHash as never,
|
|
40
|
+
hash: txId as never,
|
|
41
|
+
})
|
|
24
42
|
}
|
|
25
|
-
const data = await client.request({
|
|
26
|
-
method: 'getrawtransaction',
|
|
27
|
-
params: params,
|
|
28
|
-
})
|
|
29
|
-
return data
|
|
30
43
|
}
|
|
@@ -2,7 +2,7 @@ import { type Account, type Chain, type Client, type Transport } from 'viem'
|
|
|
2
2
|
import type { UTXOSchema } from '../transports/utxo/types.js'
|
|
3
3
|
|
|
4
4
|
export type SendUTXOTransactionParameters = {
|
|
5
|
-
/** The hex string of the raw transaction */
|
|
5
|
+
/** The hex string of the raw transaction. */
|
|
6
6
|
hex: string
|
|
7
7
|
/** Rejects transactions whose fee rate is higher than the specified value, expressed in BTC/kB. Set to 0 to accept any fee rate. Default = 0.10 */
|
|
8
8
|
maxFeeRate?: number
|