@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
|
@@ -106,22 +106,37 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
106
106
|
this.successActionCommitment = offererOrData.successActionCommitment ?? ethers_1.ZeroHash;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* @inheritDoc
|
|
111
|
+
*/
|
|
109
112
|
getOfferer() {
|
|
110
113
|
return this.offerer;
|
|
111
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* @inheritDoc
|
|
117
|
+
*/
|
|
112
118
|
setOfferer(newOfferer) {
|
|
113
119
|
this.offerer = newOfferer;
|
|
114
120
|
this.payIn = true;
|
|
115
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* @inheritDoc
|
|
124
|
+
*/
|
|
116
125
|
getClaimer() {
|
|
117
126
|
return this.claimer;
|
|
118
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
119
131
|
setClaimer(newClaimer) {
|
|
120
132
|
this.claimer = newClaimer;
|
|
121
133
|
this.payIn = false;
|
|
122
134
|
this.payOut = true;
|
|
123
135
|
this.reputation = false;
|
|
124
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* @inheritDoc
|
|
139
|
+
*/
|
|
125
140
|
serialize() {
|
|
126
141
|
return {
|
|
127
142
|
type: "evm",
|
|
@@ -145,30 +160,57 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
145
160
|
successActionCommitment: this.successActionCommitment
|
|
146
161
|
};
|
|
147
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* @inheritDoc
|
|
165
|
+
*/
|
|
148
166
|
getAmount() {
|
|
149
167
|
return this.amount;
|
|
150
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* @inheritDoc
|
|
171
|
+
*/
|
|
151
172
|
getToken() {
|
|
152
173
|
return this.token;
|
|
153
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* @inheritDoc
|
|
177
|
+
*/
|
|
154
178
|
isToken(token) {
|
|
155
179
|
return this.token.toLowerCase() === token.toLowerCase();
|
|
156
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* @inheritDoc
|
|
183
|
+
*/
|
|
157
184
|
getType() {
|
|
158
185
|
return this.kind;
|
|
159
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* @inheritDoc
|
|
189
|
+
*/
|
|
160
190
|
getExpiry() {
|
|
161
191
|
return TimelockRefundHandler_1.TimelockRefundHandler.getExpiry(this);
|
|
162
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* @inheritDoc
|
|
195
|
+
*/
|
|
163
196
|
isPayIn() {
|
|
164
197
|
return this.payIn;
|
|
165
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* @inheritDoc
|
|
201
|
+
*/
|
|
166
202
|
isPayOut() {
|
|
167
203
|
return this.payOut;
|
|
168
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* @inheritDoc
|
|
207
|
+
*/
|
|
169
208
|
isTrackingReputation() {
|
|
170
209
|
return this.reputation;
|
|
171
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* @inheritDoc
|
|
213
|
+
*/
|
|
172
214
|
getEscrowHash() {
|
|
173
215
|
const encoded = ethers_1.AbiCoder.defaultAbiCoder().encode(["address", "address", "uint256", "address", "uint256", "address", "bytes32", "address", "bytes32", "uint256", "uint256", "address", "bytes32"], [
|
|
174
216
|
this.offerer, this.claimer, this.amount, this.token, this.getFlags(),
|
|
@@ -178,15 +220,24 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
178
220
|
let escrowHash = (0, ethers_1.keccak256)(encoded);
|
|
179
221
|
return escrowHash.slice(2); //Strip `0x`
|
|
180
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* @inheritDoc
|
|
225
|
+
*/
|
|
181
226
|
getClaimHash() {
|
|
182
227
|
let hash = this.claimData;
|
|
183
228
|
if (hash.startsWith("0x"))
|
|
184
229
|
hash = hash.slice(2);
|
|
185
230
|
return hash;
|
|
186
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* @inheritDoc
|
|
234
|
+
*/
|
|
187
235
|
getSequence() {
|
|
188
236
|
return this.sequence;
|
|
189
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* @inheritDoc
|
|
240
|
+
*/
|
|
190
241
|
getConfirmationsHint() {
|
|
191
242
|
if (this.extraData == null)
|
|
192
243
|
return null;
|
|
@@ -194,6 +245,9 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
194
245
|
return null;
|
|
195
246
|
return parseInt(this.extraData.slice(80), 16);
|
|
196
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* @inheritDoc
|
|
250
|
+
*/
|
|
197
251
|
getNonceHint() {
|
|
198
252
|
if (this.extraData == null)
|
|
199
253
|
return null;
|
|
@@ -201,6 +255,9 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
201
255
|
return null;
|
|
202
256
|
return BigInt("0x" + this.extraData.slice(64, 80));
|
|
203
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* @inheritDoc
|
|
260
|
+
*/
|
|
204
261
|
getTxoHashHint() {
|
|
205
262
|
if (this.extraData == null)
|
|
206
263
|
return null;
|
|
@@ -208,34 +265,61 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
208
265
|
return null;
|
|
209
266
|
return this.extraData.slice(0, 64);
|
|
210
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* @inheritDoc
|
|
270
|
+
*/
|
|
211
271
|
getExtraData() {
|
|
212
272
|
return this.extraData ?? null;
|
|
213
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* @inheritDoc
|
|
276
|
+
*/
|
|
214
277
|
setExtraData(extraData) {
|
|
215
278
|
this.extraData = extraData;
|
|
216
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* @inheritDoc
|
|
282
|
+
*/
|
|
217
283
|
getSecurityDeposit() {
|
|
218
284
|
return this.securityDeposit;
|
|
219
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* @inheritDoc
|
|
288
|
+
*/
|
|
220
289
|
getClaimerBounty() {
|
|
221
290
|
return this.claimerBounty;
|
|
222
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* @inheritDoc
|
|
294
|
+
*/
|
|
223
295
|
getTotalDeposit() {
|
|
224
296
|
return this.claimerBounty < this.securityDeposit ? this.securityDeposit : this.claimerBounty;
|
|
225
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* @inheritDoc
|
|
300
|
+
*/
|
|
226
301
|
getDepositToken() {
|
|
227
302
|
return this.depositToken;
|
|
228
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* @inheritDoc
|
|
306
|
+
*/
|
|
229
307
|
isDepositToken(token) {
|
|
230
308
|
if (!token.startsWith("0x"))
|
|
231
309
|
token = "0x" + token;
|
|
232
310
|
return this.depositToken.toLowerCase() === token.toLowerCase();
|
|
233
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* @inheritDoc
|
|
314
|
+
*/
|
|
234
315
|
isClaimer(address) {
|
|
235
316
|
if (!address.startsWith("0x"))
|
|
236
317
|
address = "0x" + address;
|
|
237
318
|
return this.claimer.toLowerCase() === address.toLowerCase();
|
|
238
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* @inheritDoc
|
|
322
|
+
*/
|
|
239
323
|
isOfferer(address) {
|
|
240
324
|
if (!address.startsWith("0x"))
|
|
241
325
|
address = "0x" + address;
|
|
@@ -256,6 +340,9 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
256
340
|
data = "0x" + data;
|
|
257
341
|
return (this.claimData.startsWith("0x") ? this.claimData : "0x" + this.claimData) === data;
|
|
258
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* @inheritDoc
|
|
345
|
+
*/
|
|
259
346
|
equals(other) {
|
|
260
347
|
return other.offerer.toLowerCase() === this.offerer.toLowerCase() &&
|
|
261
348
|
other.claimer.toLowerCase() === this.claimer.toLowerCase() &&
|
|
@@ -290,6 +377,9 @@ class EVMSwapData extends base_1.SwapData {
|
|
|
290
377
|
successActionCommitment: this.successActionCommitment
|
|
291
378
|
};
|
|
292
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* @inheritDoc
|
|
382
|
+
*/
|
|
293
383
|
hasSuccessAction() {
|
|
294
384
|
return this.successActionCommitment !== ethers_1.ZeroHash;
|
|
295
385
|
}
|
|
@@ -10,6 +10,9 @@ export declare class EVMSigner implements AbstractSigner {
|
|
|
10
10
|
readonly address: string;
|
|
11
11
|
readonly isManagingNoncesInternally: boolean;
|
|
12
12
|
constructor(account: Signer, address: string, isManagingNoncesInternally?: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
13
16
|
getAddress(): string;
|
|
14
17
|
signTransaction?(transaction: TransactionRequest): Promise<string>;
|
|
15
18
|
sendTransaction(transaction: TransactionRequest, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<TransactionResponse>;
|
package/package.json
CHANGED
|
@@ -226,7 +226,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/**
|
|
229
|
-
*
|
|
229
|
+
* @inheritDoc
|
|
230
230
|
*/
|
|
231
231
|
public async getTipData(): Promise<{ commitHash: string; blockhash: string, chainWork: Buffer, blockheight: number } | null> {
|
|
232
232
|
const commitHash = await this.contract.getTipCommitHash();
|
|
@@ -246,11 +246,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
/**
|
|
249
|
-
*
|
|
250
|
-
* btc relay contract is not synced up to the desired blockheight
|
|
251
|
-
*
|
|
252
|
-
* @param blockData
|
|
253
|
-
* @param requiredBlockheight
|
|
249
|
+
* @inheritDoc
|
|
254
250
|
*/
|
|
255
251
|
public async retrieveLogAndBlockheight(blockData: {blockhash: string}, requiredBlockheight?: number): Promise<{
|
|
256
252
|
header: EVMBtcStoredHeader,
|
|
@@ -277,10 +273,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
277
273
|
}
|
|
278
274
|
|
|
279
275
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* @param commitmentHashStr
|
|
283
|
-
* @param blockData
|
|
276
|
+
* @inheritDoc
|
|
284
277
|
*/
|
|
285
278
|
public async retrieveLogByCommitHash(commitmentHashStr: string, blockData: {blockhash: string}): Promise<EVMBtcStoredHeader | null> {
|
|
286
279
|
const result = await this.getBlock(commitmentHashStr, Buffer.from(blockData.blockhash, "hex"));
|
|
@@ -299,7 +292,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
299
292
|
}
|
|
300
293
|
|
|
301
294
|
/**
|
|
302
|
-
*
|
|
295
|
+
* @inheritDoc
|
|
303
296
|
*/
|
|
304
297
|
public async retrieveLatestKnownBlockLog(): Promise<{
|
|
305
298
|
resultStoredHeader: EVMBtcStoredHeader,
|
|
@@ -340,12 +333,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
340
333
|
}
|
|
341
334
|
|
|
342
335
|
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* @param signer
|
|
346
|
-
* @param mainHeaders
|
|
347
|
-
* @param storedHeader
|
|
348
|
-
* @param feeRate
|
|
336
|
+
* @inheritDoc
|
|
349
337
|
*/
|
|
350
338
|
public async saveMainHeaders(signer: string, mainHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, feeRate?: string) {
|
|
351
339
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
@@ -354,13 +342,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
354
342
|
}
|
|
355
343
|
|
|
356
344
|
/**
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* @param signer
|
|
360
|
-
* @param forkHeaders
|
|
361
|
-
* @param storedHeader
|
|
362
|
-
* @param tipWork
|
|
363
|
-
* @param feeRate
|
|
345
|
+
* @inheritDoc
|
|
364
346
|
*/
|
|
365
347
|
public async saveNewForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, tipWork: Buffer, feeRate?: string) {
|
|
366
348
|
let forkId: number = Math.floor(Math.random() * 0xFFFFFFFFFFFF);
|
|
@@ -378,14 +360,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
378
360
|
}
|
|
379
361
|
|
|
380
362
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* @param signer
|
|
384
|
-
* @param forkHeaders
|
|
385
|
-
* @param storedHeader
|
|
386
|
-
* @param forkId
|
|
387
|
-
* @param tipWork
|
|
388
|
-
* @param feeRate
|
|
363
|
+
* @inheritDoc
|
|
389
364
|
*/
|
|
390
365
|
public async saveForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, forkId: number, tipWork: Buffer, feeRate?: string) {
|
|
391
366
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
@@ -402,13 +377,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
402
377
|
}
|
|
403
378
|
|
|
404
379
|
/**
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
* @param signer
|
|
408
|
-
* @param forkHeaders
|
|
409
|
-
* @param storedHeader
|
|
410
|
-
* @param tipWork
|
|
411
|
-
* @param feeRate
|
|
380
|
+
* @inheritDoc
|
|
412
381
|
*/
|
|
413
382
|
public async saveShortForkHeaders(signer: string, forkHeaders: BtcBlock[], storedHeader: EVMBtcStoredHeader, tipWork: Buffer, feeRate?: string) {
|
|
414
383
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
@@ -425,10 +394,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
425
394
|
}
|
|
426
395
|
|
|
427
396
|
/**
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* @param requiredBlockheight
|
|
431
|
-
* @param feeRate
|
|
397
|
+
* @inheritDoc
|
|
432
398
|
*/
|
|
433
399
|
public async estimateSynchronizeFee(requiredBlockheight: number, feeRate?: string): Promise<bigint> {
|
|
434
400
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
@@ -450,9 +416,7 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
450
416
|
}
|
|
451
417
|
|
|
452
418
|
/**
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* @param feeRate
|
|
419
|
+
* @inheritDoc
|
|
456
420
|
*/
|
|
457
421
|
public async getFeePerBlock(feeRate?: string): Promise<bigint> {
|
|
458
422
|
feeRate ??= await this.Chain.Fees.getFeeRate();
|
|
@@ -460,19 +424,22 @@ export class EVMBtcRelay<B extends BtcBlock>
|
|
|
460
424
|
}
|
|
461
425
|
|
|
462
426
|
/**
|
|
463
|
-
*
|
|
427
|
+
* @inheritDoc
|
|
464
428
|
*/
|
|
465
429
|
public getMainFeeRate(signer: string | null): Promise<string> {
|
|
466
430
|
return this.Chain.Fees.getFeeRate();
|
|
467
431
|
}
|
|
468
432
|
|
|
469
433
|
/**
|
|
470
|
-
*
|
|
434
|
+
* @inheritDoc
|
|
471
435
|
*/
|
|
472
436
|
public getForkFeeRate(signer: string, forkId: number): Promise<string> {
|
|
473
437
|
return this.Chain.Fees.getFeeRate();
|
|
474
438
|
}
|
|
475
439
|
|
|
440
|
+
/**
|
|
441
|
+
* @inheritDoc
|
|
442
|
+
*/
|
|
476
443
|
saveInitialHeader(signer: string, header: B, epochStart: number, pastBlocksTimestamps: number[], feeRate?: string): Promise<EVMTx> {
|
|
477
444
|
throw new Error("Not supported, EVM contract is initialized with constructor!");
|
|
478
445
|
}
|
|
@@ -104,46 +104,79 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @inheritDoc
|
|
109
|
+
*/
|
|
107
110
|
async getBalance(signer: string, tokenAddress: string): Promise<bigint> {
|
|
108
111
|
//TODO: For native token we should discount the cost of transactions
|
|
109
112
|
return await this.Tokens.getTokenBalance(signer, tokenAddress);
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/**
|
|
116
|
+
* @inheritDoc
|
|
117
|
+
*/
|
|
112
118
|
getNativeCurrencyAddress(): string {
|
|
113
119
|
return this.Tokens.getNativeCurrencyAddress();
|
|
114
120
|
}
|
|
115
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @inheritDoc
|
|
124
|
+
*/
|
|
116
125
|
isValidToken(tokenIdentifier: string): boolean {
|
|
117
126
|
return this.Tokens.isValidToken(tokenIdentifier);
|
|
118
127
|
}
|
|
119
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @inheritDoc
|
|
131
|
+
*/
|
|
120
132
|
isValidAddress(address: string): boolean {
|
|
121
133
|
return EVMAddresses.isValidAddress(address);
|
|
122
134
|
}
|
|
123
135
|
|
|
136
|
+
/**
|
|
137
|
+
* @inheritDoc
|
|
138
|
+
*/
|
|
124
139
|
normalizeAddress(address: string): string {
|
|
125
140
|
return getAddress(address);
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
///////////////////////////////////
|
|
129
144
|
//// Callbacks & handlers
|
|
145
|
+
/**
|
|
146
|
+
* @inheritDoc
|
|
147
|
+
*/
|
|
130
148
|
offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean {
|
|
131
149
|
return true;
|
|
132
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* @inheritDoc
|
|
153
|
+
*/
|
|
133
154
|
onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void {}
|
|
134
155
|
|
|
156
|
+
/**
|
|
157
|
+
* @inheritDoc
|
|
158
|
+
*/
|
|
135
159
|
onBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): void {
|
|
136
160
|
this.Transactions.onBeforeTxSigned(callback);
|
|
137
161
|
}
|
|
138
162
|
|
|
163
|
+
/**
|
|
164
|
+
* @inheritDoc
|
|
165
|
+
*/
|
|
139
166
|
offBeforeTxSigned(callback: (tx: TransactionRequest) => Promise<void>): boolean {
|
|
140
167
|
return this.Transactions.offBeforeTxSigned(callback);
|
|
141
168
|
}
|
|
142
169
|
|
|
170
|
+
/**
|
|
171
|
+
* @inheritDoc
|
|
172
|
+
*/
|
|
143
173
|
randomAddress(): string {
|
|
144
174
|
return EVMAddresses.randomAddress();
|
|
145
175
|
}
|
|
146
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @inheritDoc
|
|
179
|
+
*/
|
|
147
180
|
randomSigner(): EVMSigner {
|
|
148
181
|
const wallet = Wallet.createRandom();
|
|
149
182
|
return new EVMSigner(wallet, wallet.address);
|
|
@@ -151,6 +184,9 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
151
184
|
|
|
152
185
|
////////////////////////////////////////////
|
|
153
186
|
//// Transactions
|
|
187
|
+
/**
|
|
188
|
+
* @inheritDoc
|
|
189
|
+
*/
|
|
154
190
|
sendAndConfirm(
|
|
155
191
|
signer: EVMSigner,
|
|
156
192
|
txs: TransactionRequest[],
|
|
@@ -163,6 +199,9 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
163
199
|
return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish, useAccessLists);
|
|
164
200
|
}
|
|
165
201
|
|
|
202
|
+
/**
|
|
203
|
+
* @inheritDoc
|
|
204
|
+
*/
|
|
166
205
|
sendSignedAndConfirm(
|
|
167
206
|
signedTxs: Transaction[],
|
|
168
207
|
waitForConfirmation?: boolean,
|
|
@@ -173,30 +212,51 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
173
212
|
return this.Transactions.sendSignedAndConfirm(signedTxs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
|
|
174
213
|
}
|
|
175
214
|
|
|
215
|
+
/**
|
|
216
|
+
* @inheritDoc
|
|
217
|
+
*/
|
|
176
218
|
serializeTx(tx: TransactionRequest): Promise<string> {
|
|
177
219
|
return this.Transactions.serializeUnsignedTx(tx);
|
|
178
220
|
}
|
|
179
221
|
|
|
222
|
+
/**
|
|
223
|
+
* @inheritDoc
|
|
224
|
+
*/
|
|
180
225
|
deserializeTx(txData: string): Promise<TransactionRequest> {
|
|
181
226
|
return Promise.resolve(this.Transactions.deserializeUnsignedTx(txData));
|
|
182
227
|
}
|
|
183
228
|
|
|
229
|
+
/**
|
|
230
|
+
* @inheritDoc
|
|
231
|
+
*/
|
|
184
232
|
serializeSignedTx(tx: Transaction): Promise<string> {
|
|
185
233
|
return Promise.resolve(this.Transactions.serializeSignedTx(tx));
|
|
186
234
|
}
|
|
187
235
|
|
|
236
|
+
/**
|
|
237
|
+
* @inheritDoc
|
|
238
|
+
*/
|
|
188
239
|
deserializeSignedTx(txData: string): Promise<Transaction> {
|
|
189
240
|
return Promise.resolve(this.Transactions.deserializeSignedTx(txData));
|
|
190
241
|
}
|
|
191
242
|
|
|
243
|
+
/**
|
|
244
|
+
* @inheritDoc
|
|
245
|
+
*/
|
|
192
246
|
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
|
|
193
247
|
return this.Transactions.getTxIdStatus(txId);
|
|
194
248
|
}
|
|
195
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @inheritDoc
|
|
252
|
+
*/
|
|
196
253
|
getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
|
|
197
254
|
return this.Transactions.getTxStatus(tx);
|
|
198
255
|
}
|
|
199
256
|
|
|
257
|
+
/**
|
|
258
|
+
* @inheritDoc
|
|
259
|
+
*/
|
|
200
260
|
async getFinalizedBlock(): Promise<{ height: number; blockHash: string }> {
|
|
201
261
|
const block = await this.Blocks.getBlock(this.config.finalizedBlockTag);
|
|
202
262
|
return {
|
|
@@ -205,10 +265,16 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
205
265
|
};
|
|
206
266
|
}
|
|
207
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @inheritDoc
|
|
270
|
+
*/
|
|
208
271
|
async txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<TransactionRequest[]> {
|
|
209
272
|
return [await this.Tokens.Transfer(signer, token, amount, dstAddress, feeRate)];
|
|
210
273
|
}
|
|
211
274
|
|
|
275
|
+
/**
|
|
276
|
+
* @inheritDoc
|
|
277
|
+
*/
|
|
212
278
|
async transfer(
|
|
213
279
|
signer: EVMSigner,
|
|
214
280
|
token: string,
|
|
@@ -221,6 +287,9 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
221
287
|
return txId;
|
|
222
288
|
}
|
|
223
289
|
|
|
290
|
+
/**
|
|
291
|
+
* @inheritDoc
|
|
292
|
+
*/
|
|
224
293
|
async wrapSigner(signer: Signer): Promise<EVMSigner> {
|
|
225
294
|
const address = await signer.getAddress();
|
|
226
295
|
if(signer instanceof JsonRpcSigner || signer.provider instanceof BrowserProvider) {
|
|
@@ -253,7 +253,11 @@ export class EVMTransactions extends EVMModule<any> {
|
|
|
253
253
|
for(let i=0;i<txs.length;i++) {
|
|
254
254
|
let tx: TransactionResponse | Transaction;
|
|
255
255
|
if(signer.signTransaction==null) {
|
|
256
|
-
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
256
|
+
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
257
|
+
.catch(e => {
|
|
258
|
+
if(e?.message?.includes("User rejected")) e.message = "User refused to sign the transaction";
|
|
259
|
+
throw e;
|
|
260
|
+
});
|
|
257
261
|
} else {
|
|
258
262
|
const signedTx = signedTxs[i];
|
|
259
263
|
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
@@ -281,7 +285,11 @@ export class EVMTransactions extends EVMModule<any> {
|
|
|
281
285
|
for(let i=0;i<txs.length;i++) {
|
|
282
286
|
let tx: TransactionResponse | Transaction;
|
|
283
287
|
if(signer.signTransaction==null) {
|
|
284
|
-
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
288
|
+
tx = await signer.sendTransaction(txs[i], onBeforePublish)
|
|
289
|
+
.catch(e => {
|
|
290
|
+
if(e?.message?.includes("User rejected")) e.message = "User refused to sign the transaction";
|
|
291
|
+
throw e;
|
|
292
|
+
});
|
|
285
293
|
} else {
|
|
286
294
|
const signedTx = signedTxs[i];
|
|
287
295
|
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
@@ -409,6 +409,9 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
409
409
|
return {lastEvent, lastBlockNumber};
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
/**
|
|
413
|
+
* @inheritDoc
|
|
414
|
+
*/
|
|
412
415
|
async poll(lastState?: EVMEventListenerState[]): Promise<EVMEventListenerState[]> {
|
|
413
416
|
lastState ??= [];
|
|
414
417
|
|
|
@@ -560,6 +563,9 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
560
563
|
});
|
|
561
564
|
}
|
|
562
565
|
|
|
566
|
+
/**
|
|
567
|
+
* @inheritDoc
|
|
568
|
+
*/
|
|
563
569
|
async init(noAutomaticPoll?: boolean): Promise<void> {
|
|
564
570
|
if(noAutomaticPoll) return Promise.resolve();
|
|
565
571
|
if((this.provider as any).websocket!=null) {
|
|
@@ -571,6 +577,9 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
571
577
|
return Promise.resolve();
|
|
572
578
|
}
|
|
573
579
|
|
|
580
|
+
/**
|
|
581
|
+
* @inheritDoc
|
|
582
|
+
*/
|
|
574
583
|
async stop(): Promise<void> {
|
|
575
584
|
this.stopped = true;
|
|
576
585
|
if(this.timeout!=null) clearTimeout(this.timeout);
|
|
@@ -583,10 +592,16 @@ export class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventL
|
|
|
583
592
|
}
|
|
584
593
|
}
|
|
585
594
|
|
|
595
|
+
/**
|
|
596
|
+
* @inheritDoc
|
|
597
|
+
*/
|
|
586
598
|
registerListener(cbk: EventListener<EVMSwapData>): void {
|
|
587
599
|
this.listeners.push(cbk);
|
|
588
600
|
}
|
|
589
601
|
|
|
602
|
+
/**
|
|
603
|
+
* @inheritDoc
|
|
604
|
+
*/
|
|
590
605
|
unregisterListener(cbk: EventListener<EVMSwapData>): boolean {
|
|
591
606
|
const index = this.listeners.indexOf(cbk);
|
|
592
607
|
if(index>=0) {
|