@atomiqlabs/chain-evm 2.0.7 → 2.0.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.
- package/dist/evm/btcrelay/EVMBtcRelay.d.ts +15 -48
- package/dist/evm/btcrelay/EVMBtcRelay.js +15 -48
- package/dist/evm/chain/EVMChainInterface.d.ts +69 -0
- package/dist/evm/chain/EVMChainInterface.js +69 -0
- package/dist/evm/chain/modules/EVMTransactions.js +12 -2
- package/dist/evm/events/EVMChainEventsBrowser.d.ts +15 -0
- package/dist/evm/events/EVMChainEventsBrowser.js +15 -0
- package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +72 -0
- package/dist/evm/spv_swap/EVMSpvVaultContract.js +72 -0
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +12 -0
- package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +12 -0
- package/dist/evm/swaps/EVMSwapContract.d.ts +117 -33
- package/dist/evm/swaps/EVMSwapContract.js +117 -33
- package/dist/evm/swaps/EVMSwapData.d.ts +90 -0
- package/dist/evm/swaps/EVMSwapData.js +90 -0
- package/dist/evm/wallet/EVMSigner.d.ts +3 -0
- package/dist/evm/wallet/EVMSigner.js +3 -0
- package/package.json +1 -1
- package/src/evm/btcrelay/EVMBtcRelay.ts +15 -48
- package/src/evm/chain/EVMChainInterface.ts +69 -0
- package/src/evm/chain/modules/EVMTransactions.ts +10 -2
- package/src/evm/events/EVMChainEventsBrowser.ts +15 -0
- package/src/evm/spv_swap/EVMSpvVaultContract.ts +72 -0
- package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +12 -0
- package/src/evm/swaps/EVMSwapContract.ts +117 -33
- package/src/evm/swaps/EVMSwapData.ts +90 -0
- package/src/evm/wallet/EVMSigner.ts +3 -0
|
@@ -54,7 +54,7 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
54
54
|
private getBlock;
|
|
55
55
|
private getBlockHeight;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* @inheritDoc
|
|
58
58
|
*/
|
|
59
59
|
getTipData(): Promise<{
|
|
60
60
|
commitHash: string;
|
|
@@ -63,11 +63,7 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
63
63
|
blockheight: number;
|
|
64
64
|
} | null>;
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
* btc relay contract is not synced up to the desired blockheight
|
|
68
|
-
*
|
|
69
|
-
* @param blockData
|
|
70
|
-
* @param requiredBlockheight
|
|
66
|
+
* @inheritDoc
|
|
71
67
|
*/
|
|
72
68
|
retrieveLogAndBlockheight(blockData: {
|
|
73
69
|
blockhash: string;
|
|
@@ -76,28 +72,20 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
76
72
|
height: number;
|
|
77
73
|
} | null>;
|
|
78
74
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @param commitmentHashStr
|
|
82
|
-
* @param blockData
|
|
75
|
+
* @inheritDoc
|
|
83
76
|
*/
|
|
84
77
|
retrieveLogByCommitHash(commitmentHashStr: string, blockData: {
|
|
85
78
|
blockhash: string;
|
|
86
79
|
}): Promise<EVMBtcStoredHeader | null>;
|
|
87
80
|
/**
|
|
88
|
-
*
|
|
81
|
+
* @inheritDoc
|
|
89
82
|
*/
|
|
90
83
|
retrieveLatestKnownBlockLog(): Promise<{
|
|
91
84
|
resultStoredHeader: EVMBtcStoredHeader;
|
|
92
85
|
resultBitcoinHeader: B;
|
|
93
86
|
} | null>;
|
|
94
87
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param signer
|
|
98
|
-
* @param mainHeaders
|
|
99
|
-
* @param storedHeader
|
|
100
|
-
* @param feeRate
|
|
88
|
+
* @inheritDoc
|
|
101
89
|
*/
|
|
102
90
|
saveMainHeaders(signer: string, mainHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, feeRate?: string): Promise<{
|
|
103
91
|
forkId: number;
|
|
@@ -106,13 +94,7 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
106
94
|
computedCommitedHeaders: EVMBtcStoredHeader[];
|
|
107
95
|
}>;
|
|
108
96
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @param signer
|
|
112
|
-
* @param forkHeaders
|
|
113
|
-
* @param storedHeader
|
|
114
|
-
* @param tipWork
|
|
115
|
-
* @param feeRate
|
|
97
|
+
* @inheritDoc
|
|
116
98
|
*/
|
|
117
99
|
saveNewForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, tipWork: Buffer, feeRate?: string): Promise<{
|
|
118
100
|
forkId: number;
|
|
@@ -121,14 +103,7 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
121
103
|
computedCommitedHeaders: EVMBtcStoredHeader[];
|
|
122
104
|
}>;
|
|
123
105
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param signer
|
|
127
|
-
* @param forkHeaders
|
|
128
|
-
* @param storedHeader
|
|
129
|
-
* @param forkId
|
|
130
|
-
* @param tipWork
|
|
131
|
-
* @param feeRate
|
|
106
|
+
* @inheritDoc
|
|
132
107
|
*/
|
|
133
108
|
saveForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, forkId: number, tipWork: Buffer, feeRate?: string): Promise<{
|
|
134
109
|
forkId: number;
|
|
@@ -137,13 +112,7 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
137
112
|
computedCommitedHeaders: EVMBtcStoredHeader[];
|
|
138
113
|
}>;
|
|
139
114
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @param signer
|
|
143
|
-
* @param forkHeaders
|
|
144
|
-
* @param storedHeader
|
|
145
|
-
* @param tipWork
|
|
146
|
-
* @param feeRate
|
|
115
|
+
* @inheritDoc
|
|
147
116
|
*/
|
|
148
117
|
saveShortForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, tipWork: Buffer, feeRate?: string): Promise<{
|
|
149
118
|
forkId: number;
|
|
@@ -152,26 +121,24 @@ export declare class EVMBtcRelay<B extends BtcBlock> extends EVMContractBase<Btc
|
|
|
152
121
|
computedCommitedHeaders: EVMBtcStoredHeader[];
|
|
153
122
|
}>;
|
|
154
123
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @param requiredBlockheight
|
|
158
|
-
* @param feeRate
|
|
124
|
+
* @inheritDoc
|
|
159
125
|
*/
|
|
160
126
|
estimateSynchronizeFee(requiredBlockheight: number, feeRate?: string): Promise<bigint>;
|
|
161
127
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @param feeRate
|
|
128
|
+
* @inheritDoc
|
|
165
129
|
*/
|
|
166
130
|
getFeePerBlock(feeRate?: string): Promise<bigint>;
|
|
167
131
|
/**
|
|
168
|
-
*
|
|
132
|
+
* @inheritDoc
|
|
169
133
|
*/
|
|
170
134
|
getMainFeeRate(signer: string | null): Promise<string>;
|
|
171
135
|
/**
|
|
172
|
-
*
|
|
136
|
+
* @inheritDoc
|
|
173
137
|
*/
|
|
174
138
|
getForkFeeRate(signer: string, forkId: number): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* @inheritDoc
|
|
141
|
+
*/
|
|
175
142
|
saveInitialHeader(signer: string, header: B, epochStart: number, pastBlocksTimestamps: number[], feeRate?: string): Promise<EVMTx>;
|
|
176
143
|
/**
|
|
177
144
|
* Gets committed header, identified by blockhash & blockheight, determines required BTC relay blockheight based on
|
|
@@ -175,7 +175,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
175
175
|
return Number(await this.contract.getBlockheight());
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
178
|
+
* @inheritDoc
|
|
179
179
|
*/
|
|
180
180
|
async getTipData() {
|
|
181
181
|
const commitHash = await this.contract.getTipCommitHash();
|
|
@@ -193,11 +193,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
|
-
*
|
|
197
|
-
* btc relay contract is not synced up to the desired blockheight
|
|
198
|
-
*
|
|
199
|
-
* @param blockData
|
|
200
|
-
* @param requiredBlockheight
|
|
196
|
+
* @inheritDoc
|
|
201
197
|
*/
|
|
202
198
|
async retrieveLogAndBlockheight(blockData, requiredBlockheight) {
|
|
203
199
|
//TODO: we can fetch the blockheight and events in parallel
|
|
@@ -218,10 +214,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
218
214
|
return { header: storedBlockHeader, height: blockHeight };
|
|
219
215
|
}
|
|
220
216
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @param commitmentHashStr
|
|
224
|
-
* @param blockData
|
|
217
|
+
* @inheritDoc
|
|
225
218
|
*/
|
|
226
219
|
async retrieveLogByCommitHash(commitmentHashStr, blockData) {
|
|
227
220
|
const result = await this.getBlock(commitmentHashStr, Buffer.from(blockData.blockhash, "hex"));
|
|
@@ -237,7 +230,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
237
230
|
return storedBlockHeader;
|
|
238
231
|
}
|
|
239
232
|
/**
|
|
240
|
-
*
|
|
233
|
+
* @inheritDoc
|
|
241
234
|
*/
|
|
242
235
|
async retrieveLatestKnownBlockLog() {
|
|
243
236
|
const data = await this.Events.findInContractEvents(["StoreHeader", "StoreForkHeader"], null, async (event) => {
|
|
@@ -268,12 +261,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
268
261
|
return data;
|
|
269
262
|
}
|
|
270
263
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* @param signer
|
|
274
|
-
* @param mainHeaders
|
|
275
|
-
* @param storedHeader
|
|
276
|
-
* @param feeRate
|
|
264
|
+
* @inheritDoc
|
|
277
265
|
*/
|
|
278
266
|
async saveMainHeaders(signer, mainHeaders, storedHeader, feeRate) {
|
|
279
267
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
@@ -281,13 +269,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
281
269
|
return this._saveHeaders(signer, mainHeaders, storedHeader, 0, feeRate, 0);
|
|
282
270
|
}
|
|
283
271
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* @param signer
|
|
287
|
-
* @param forkHeaders
|
|
288
|
-
* @param storedHeader
|
|
289
|
-
* @param tipWork
|
|
290
|
-
* @param feeRate
|
|
272
|
+
* @inheritDoc
|
|
291
273
|
*/
|
|
292
274
|
async saveNewForkHeaders(signer, forkHeaders, storedHeader, tipWork, feeRate) {
|
|
293
275
|
let forkId = Math.floor(Math.random() * 0xFFFFFFFFFFFF);
|
|
@@ -302,14 +284,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
302
284
|
return result;
|
|
303
285
|
}
|
|
304
286
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* @param signer
|
|
308
|
-
* @param forkHeaders
|
|
309
|
-
* @param storedHeader
|
|
310
|
-
* @param forkId
|
|
311
|
-
* @param tipWork
|
|
312
|
-
* @param feeRate
|
|
287
|
+
* @inheritDoc
|
|
313
288
|
*/
|
|
314
289
|
async saveForkHeaders(signer, forkHeaders, storedHeader, forkId, tipWork, feeRate) {
|
|
315
290
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
@@ -323,13 +298,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
323
298
|
return result;
|
|
324
299
|
}
|
|
325
300
|
/**
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* @param signer
|
|
329
|
-
* @param forkHeaders
|
|
330
|
-
* @param storedHeader
|
|
331
|
-
* @param tipWork
|
|
332
|
-
* @param feeRate
|
|
301
|
+
* @inheritDoc
|
|
333
302
|
*/
|
|
334
303
|
async saveShortForkHeaders(signer, forkHeaders, storedHeader, tipWork, feeRate) {
|
|
335
304
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
@@ -343,10 +312,7 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
343
312
|
return result;
|
|
344
313
|
}
|
|
345
314
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* @param requiredBlockheight
|
|
349
|
-
* @param feeRate
|
|
315
|
+
* @inheritDoc
|
|
350
316
|
*/
|
|
351
317
|
async estimateSynchronizeFee(requiredBlockheight, feeRate) {
|
|
352
318
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
@@ -364,26 +330,27 @@ class EVMBtcRelay extends EVMContractBase_1.EVMContractBase {
|
|
|
364
330
|
return synchronizationFee;
|
|
365
331
|
}
|
|
366
332
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* @param feeRate
|
|
333
|
+
* @inheritDoc
|
|
370
334
|
*/
|
|
371
335
|
async getFeePerBlock(feeRate) {
|
|
372
336
|
feeRate ?? (feeRate = await this.Chain.Fees.getFeeRate());
|
|
373
337
|
return EVMFees_1.EVMFees.getGasFee(EVMBtcRelay.GasCosts.GAS_PER_BLOCKHEADER, feeRate);
|
|
374
338
|
}
|
|
375
339
|
/**
|
|
376
|
-
*
|
|
340
|
+
* @inheritDoc
|
|
377
341
|
*/
|
|
378
342
|
getMainFeeRate(signer) {
|
|
379
343
|
return this.Chain.Fees.getFeeRate();
|
|
380
344
|
}
|
|
381
345
|
/**
|
|
382
|
-
*
|
|
346
|
+
* @inheritDoc
|
|
383
347
|
*/
|
|
384
348
|
getForkFeeRate(signer, forkId) {
|
|
385
349
|
return this.Chain.Fees.getFeeRate();
|
|
386
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* @inheritDoc
|
|
353
|
+
*/
|
|
387
354
|
saveInitialHeader(signer, header, epochStart, pastBlocksTimestamps, feeRate) {
|
|
388
355
|
throw new Error("Not supported, EVM contract is initialized with constructor!");
|
|
389
356
|
}
|
|
@@ -53,30 +53,99 @@ export declare class EVMChainInterface<ChainId extends string = string> implemen
|
|
|
53
53
|
Blocks: EVMBlocks;
|
|
54
54
|
protected logger: LoggerType;
|
|
55
55
|
constructor(chainId: ChainId, evmChainId: number, provider: JsonRpcApiProvider, config: EVMConfiguration, retryPolicy?: EVMRetryPolicy, evmFeeEstimator?: EVMFees);
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
56
59
|
getBalance(signer: string, tokenAddress: string): Promise<bigint>;
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
57
63
|
getNativeCurrencyAddress(): string;
|
|
64
|
+
/**
|
|
65
|
+
* @inheritDoc
|
|
66
|
+
*/
|
|
58
67
|
isValidToken(tokenIdentifier: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* @inheritDoc
|
|
70
|
+
*/
|
|
59
71
|
isValidAddress(address: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* @inheritDoc
|
|
74
|
+
*/
|
|
60
75
|
normalizeAddress(address: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* @inheritDoc
|
|
78
|
+
*/
|
|
61
79
|
offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* @inheritDoc
|
|
82
|
+
*/
|
|
62
83
|
onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
|
|
84
|
+
/**
|
|
85
|
+
* @inheritDoc
|
|
86
|
+
*/
|
|
63
87
|
onBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): void;
|
|
88
|
+
/**
|
|
89
|
+
* @inheritDoc
|
|
90
|
+
*/
|
|
64
91
|
offBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* @inheritDoc
|
|
94
|
+
*/
|
|
65
95
|
randomAddress(): string;
|
|
96
|
+
/**
|
|
97
|
+
* @inheritDoc
|
|
98
|
+
*/
|
|
66
99
|
randomSigner(): EVMSigner;
|
|
100
|
+
/**
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/
|
|
67
103
|
sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>, useAccessLists?: boolean): Promise<string[]>;
|
|
104
|
+
/**
|
|
105
|
+
* @inheritDoc
|
|
106
|
+
*/
|
|
68
107
|
sendSignedAndConfirm(signedTxs: Transaction[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
108
|
+
/**
|
|
109
|
+
* @inheritDoc
|
|
110
|
+
*/
|
|
69
111
|
serializeTx(tx: TransactionRequest): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* @inheritDoc
|
|
114
|
+
*/
|
|
70
115
|
deserializeTx(txData: string): Promise<TransactionRequest>;
|
|
116
|
+
/**
|
|
117
|
+
* @inheritDoc
|
|
118
|
+
*/
|
|
71
119
|
serializeSignedTx(tx: Transaction): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* @inheritDoc
|
|
122
|
+
*/
|
|
72
123
|
deserializeSignedTx(txData: string): Promise<Transaction>;
|
|
124
|
+
/**
|
|
125
|
+
* @inheritDoc
|
|
126
|
+
*/
|
|
73
127
|
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
74
131
|
getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
132
|
+
/**
|
|
133
|
+
* @inheritDoc
|
|
134
|
+
*/
|
|
75
135
|
getFinalizedBlock(): Promise<{
|
|
76
136
|
height: number;
|
|
77
137
|
blockHash: string;
|
|
78
138
|
}>;
|
|
139
|
+
/**
|
|
140
|
+
* @inheritDoc
|
|
141
|
+
*/
|
|
79
142
|
txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<TransactionRequest[]>;
|
|
143
|
+
/**
|
|
144
|
+
* @inheritDoc
|
|
145
|
+
*/
|
|
80
146
|
transfer(signer: EVMSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
147
|
+
/**
|
|
148
|
+
* @inheritDoc
|
|
149
|
+
*/
|
|
81
150
|
wrapSigner(signer: Signer): Promise<EVMSigner>;
|
|
82
151
|
}
|
|
@@ -36,67 +36,127 @@ class EVMChainInterface {
|
|
|
36
36
|
this.Events = new EVMEvents_1.EVMEvents(this);
|
|
37
37
|
this.Blocks = new EVMBlocks_1.EVMBlocks(this);
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
39
42
|
async getBalance(signer, tokenAddress) {
|
|
40
43
|
//TODO: For native token we should discount the cost of transactions
|
|
41
44
|
return await this.Tokens.getTokenBalance(signer, tokenAddress);
|
|
42
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
43
49
|
getNativeCurrencyAddress() {
|
|
44
50
|
return this.Tokens.getNativeCurrencyAddress();
|
|
45
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
46
55
|
isValidToken(tokenIdentifier) {
|
|
47
56
|
return this.Tokens.isValidToken(tokenIdentifier);
|
|
48
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
49
61
|
isValidAddress(address) {
|
|
50
62
|
return EVMAddresses_1.EVMAddresses.isValidAddress(address);
|
|
51
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @inheritDoc
|
|
66
|
+
*/
|
|
52
67
|
normalizeAddress(address) {
|
|
53
68
|
return (0, ethers_1.getAddress)(address);
|
|
54
69
|
}
|
|
55
70
|
///////////////////////////////////
|
|
56
71
|
//// Callbacks & handlers
|
|
72
|
+
/**
|
|
73
|
+
* @inheritDoc
|
|
74
|
+
*/
|
|
57
75
|
offBeforeTxReplace(callback) {
|
|
58
76
|
return true;
|
|
59
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* @inheritDoc
|
|
80
|
+
*/
|
|
60
81
|
onBeforeTxReplace(callback) { }
|
|
82
|
+
/**
|
|
83
|
+
* @inheritDoc
|
|
84
|
+
*/
|
|
61
85
|
onBeforeTxSigned(callback) {
|
|
62
86
|
this.Transactions.onBeforeTxSigned(callback);
|
|
63
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* @inheritDoc
|
|
90
|
+
*/
|
|
64
91
|
offBeforeTxSigned(callback) {
|
|
65
92
|
return this.Transactions.offBeforeTxSigned(callback);
|
|
66
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* @inheritDoc
|
|
96
|
+
*/
|
|
67
97
|
randomAddress() {
|
|
68
98
|
return EVMAddresses_1.EVMAddresses.randomAddress();
|
|
69
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/
|
|
70
103
|
randomSigner() {
|
|
71
104
|
const wallet = ethers_1.Wallet.createRandom();
|
|
72
105
|
return new EVMSigner_1.EVMSigner(wallet, wallet.address);
|
|
73
106
|
}
|
|
74
107
|
////////////////////////////////////////////
|
|
75
108
|
//// Transactions
|
|
109
|
+
/**
|
|
110
|
+
* @inheritDoc
|
|
111
|
+
*/
|
|
76
112
|
sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish, useAccessLists) {
|
|
77
113
|
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish, useAccessLists);
|
|
78
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* @inheritDoc
|
|
117
|
+
*/
|
|
79
118
|
sendSignedAndConfirm(signedTxs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
80
119
|
return this.Transactions.sendSignedAndConfirm(signedTxs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
81
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* @inheritDoc
|
|
123
|
+
*/
|
|
82
124
|
serializeTx(tx) {
|
|
83
125
|
return this.Transactions.serializeUnsignedTx(tx);
|
|
84
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* @inheritDoc
|
|
129
|
+
*/
|
|
85
130
|
deserializeTx(txData) {
|
|
86
131
|
return Promise.resolve(this.Transactions.deserializeUnsignedTx(txData));
|
|
87
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* @inheritDoc
|
|
135
|
+
*/
|
|
88
136
|
serializeSignedTx(tx) {
|
|
89
137
|
return Promise.resolve(this.Transactions.serializeSignedTx(tx));
|
|
90
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* @inheritDoc
|
|
141
|
+
*/
|
|
91
142
|
deserializeSignedTx(txData) {
|
|
92
143
|
return Promise.resolve(this.Transactions.deserializeSignedTx(txData));
|
|
93
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* @inheritDoc
|
|
147
|
+
*/
|
|
94
148
|
getTxIdStatus(txId) {
|
|
95
149
|
return this.Transactions.getTxIdStatus(txId);
|
|
96
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* @inheritDoc
|
|
153
|
+
*/
|
|
97
154
|
getTxStatus(tx) {
|
|
98
155
|
return this.Transactions.getTxStatus(tx);
|
|
99
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* @inheritDoc
|
|
159
|
+
*/
|
|
100
160
|
async getFinalizedBlock() {
|
|
101
161
|
const block = await this.Blocks.getBlock(this.config.finalizedBlockTag);
|
|
102
162
|
return {
|
|
@@ -104,14 +164,23 @@ class EVMChainInterface {
|
|
|
104
164
|
blockHash: block.hash
|
|
105
165
|
};
|
|
106
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* @inheritDoc
|
|
169
|
+
*/
|
|
107
170
|
async txsTransfer(signer, token, amount, dstAddress, feeRate) {
|
|
108
171
|
return [await this.Tokens.Transfer(signer, token, amount, dstAddress, feeRate)];
|
|
109
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* @inheritDoc
|
|
175
|
+
*/
|
|
110
176
|
async transfer(signer, token, amount, dstAddress, txOptions) {
|
|
111
177
|
const tx = await this.Tokens.Transfer(signer.getAddress(), token, amount, dstAddress, txOptions?.feeRate);
|
|
112
178
|
const [txId] = await this.Transactions.sendAndConfirm(signer, [tx], txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
|
|
113
179
|
return txId;
|
|
114
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* @inheritDoc
|
|
183
|
+
*/
|
|
115
184
|
async wrapSigner(signer) {
|
|
116
185
|
const address = await signer.getAddress();
|
|
117
186
|
if (signer instanceof ethers_1.JsonRpcSigner || signer.provider instanceof ethers_1.BrowserProvider) {
|
|
@@ -211,7 +211,12 @@ class EVMTransactions extends EVMModule_1.EVMModule {
|
|
|
211
211
|
for (let i = 0; i < txs.length; i++) {
|
|
212
212
|
let tx;
|
|
213
213
|
if (signer.signTransaction == null) {
|
|
214
|
-
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
214
|
+
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
215
|
+
.catch(e => {
|
|
216
|
+
if (e?.message?.includes("User rejected"))
|
|
217
|
+
e.message = "User refused to sign the transaction";
|
|
218
|
+
throw e;
|
|
219
|
+
});
|
|
215
220
|
}
|
|
216
221
|
else {
|
|
217
222
|
const signedTx = signedTxs[i];
|
|
@@ -241,7 +246,12 @@ class EVMTransactions extends EVMModule_1.EVMModule {
|
|
|
241
246
|
for (let i = 0; i < txs.length; i++) {
|
|
242
247
|
let tx;
|
|
243
248
|
if (signer.signTransaction == null) {
|
|
244
|
-
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
249
|
+
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
250
|
+
.catch(e => {
|
|
251
|
+
if (e?.message?.includes("User rejected"))
|
|
252
|
+
e.message = "User refused to sign the transaction";
|
|
253
|
+
throw e;
|
|
254
|
+
});
|
|
245
255
|
}
|
|
246
256
|
else {
|
|
247
257
|
const signedTx = signedTxs[i];
|
|
@@ -79,6 +79,9 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
|
|
|
79
79
|
blockHash: string;
|
|
80
80
|
logIndex: number;
|
|
81
81
|
}, lastBlockNumber?: number): Promise<EVMEventListenerState>;
|
|
82
|
+
/**
|
|
83
|
+
* @inheritDoc
|
|
84
|
+
*/
|
|
82
85
|
poll(lastState?: EVMEventListenerState[]): Promise<EVMEventListenerState[]>;
|
|
83
86
|
/**
|
|
84
87
|
* Sets up event handlers listening for swap events over websocket
|
|
@@ -96,9 +99,21 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
|
|
|
96
99
|
protected addOrRemoveBlockListener(): Promise<void>;
|
|
97
100
|
protected startFinalityCheckTimer(): Promise<void>;
|
|
98
101
|
protected setupWebsocket(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* @inheritDoc
|
|
104
|
+
*/
|
|
99
105
|
init(noAutomaticPoll?: boolean): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* @inheritDoc
|
|
108
|
+
*/
|
|
100
109
|
stop(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* @inheritDoc
|
|
112
|
+
*/
|
|
101
113
|
registerListener(cbk: EventListener<EVMSwapData>): void;
|
|
114
|
+
/**
|
|
115
|
+
* @inheritDoc
|
|
116
|
+
*/
|
|
102
117
|
unregisterListener(cbk: EventListener<EVMSwapData>): boolean;
|
|
103
118
|
}
|
|
104
119
|
export {};
|
|
@@ -291,6 +291,9 @@ class EVMChainEventsBrowser {
|
|
|
291
291
|
}
|
|
292
292
|
return { lastEvent, lastBlockNumber };
|
|
293
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* @inheritDoc
|
|
296
|
+
*/
|
|
294
297
|
async poll(lastState) {
|
|
295
298
|
lastState ?? (lastState = []);
|
|
296
299
|
const currentBlock = await this.provider.getBlock(this.chainInterface.config.safeBlockTag, false);
|
|
@@ -431,6 +434,9 @@ class EVMChainEventsBrowser {
|
|
|
431
434
|
this.handleWsEvent(event);
|
|
432
435
|
});
|
|
433
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* @inheritDoc
|
|
439
|
+
*/
|
|
434
440
|
async init(noAutomaticPoll) {
|
|
435
441
|
if (noAutomaticPoll)
|
|
436
442
|
return Promise.resolve();
|
|
@@ -443,6 +449,9 @@ class EVMChainEventsBrowser {
|
|
|
443
449
|
this.stopped = false;
|
|
444
450
|
return Promise.resolve();
|
|
445
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* @inheritDoc
|
|
454
|
+
*/
|
|
446
455
|
async stop() {
|
|
447
456
|
this.stopped = true;
|
|
448
457
|
if (this.timeout != null)
|
|
@@ -455,9 +464,15 @@ class EVMChainEventsBrowser {
|
|
|
455
464
|
clearTimeout(this.finalityCheckTimer);
|
|
456
465
|
}
|
|
457
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* @inheritDoc
|
|
469
|
+
*/
|
|
458
470
|
registerListener(cbk) {
|
|
459
471
|
this.listeners.push(cbk);
|
|
460
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* @inheritDoc
|
|
475
|
+
*/
|
|
461
476
|
unregisterListener(cbk) {
|
|
462
477
|
const index = this.listeners.indexOf(cbk);
|
|
463
478
|
if (index >= 0) {
|