@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.
@@ -51,44 +51,71 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
51
51
  this.timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
52
52
  this.refundHandlersByAddress[this.timelockRefundHandler.address.toLowerCase()] = this.timelockRefundHandler;
53
53
  }
54
+ /**
55
+ * @inheritDoc
56
+ */
54
57
  async start() {
55
58
  }
56
59
  ////////////////////////////////////////////
57
60
  //// Signatures
61
+ /**
62
+ * @inheritDoc
63
+ */
58
64
  preFetchForInitSignatureVerification() {
59
65
  return this.Init.preFetchForInitSignatureVerification();
60
66
  }
67
+ /**
68
+ * @inheritDoc
69
+ */
61
70
  getInitSignature(signer, swapData, authorizationTimeout, preFetchedBlockData, feeRate) {
62
71
  return this.Init.signSwapInitialization(signer, swapData, authorizationTimeout);
63
72
  }
73
+ /**
74
+ * @inheritDoc
75
+ */
64
76
  isValidInitAuthorization(sender, swapData, signature, feeRate, preFetchedData) {
65
77
  return this.Init.isSignatureValid(sender, swapData, signature.timeout, signature.prefix, signature.signature, preFetchedData);
66
78
  }
79
+ /**
80
+ * @inheritDoc
81
+ */
67
82
  getInitAuthorizationExpiry(swapData, signature, preFetchedData) {
68
83
  return this.Init.getSignatureExpiry(signature.timeout);
69
84
  }
85
+ /**
86
+ * @inheritDoc
87
+ */
70
88
  isInitAuthorizationExpired(swapData, signature) {
71
89
  return this.Init.isSignatureExpired(signature.timeout);
72
90
  }
91
+ /**
92
+ * @inheritDoc
93
+ */
73
94
  getRefundSignature(signer, swapData, authorizationTimeout) {
74
95
  return this.Refund.signSwapRefund(signer, swapData, authorizationTimeout);
75
96
  }
97
+ /**
98
+ * @inheritDoc
99
+ */
76
100
  isValidRefundAuthorization(swapData, signature) {
77
101
  return this.Refund.isSignatureValid(swapData, signature.timeout, signature.prefix, signature.signature);
78
102
  }
103
+ /**
104
+ * @inheritDoc
105
+ */
79
106
  getDataSignature(signer, data) {
80
107
  return this.Chain.Signatures.getDataSignature(signer, data);
81
108
  }
109
+ /**
110
+ * @inheritDoc
111
+ */
82
112
  isValidDataSignature(data, signature, publicKey) {
83
113
  return this.Chain.Signatures.isValidDataSignature(data, signature, publicKey);
84
114
  }
85
115
  ////////////////////////////////////////////
86
116
  //// Swap data utils
87
117
  /**
88
- * Checks whether the claim is claimable by us, that means not expired, we are claimer & the swap is commited
89
- *
90
- * @param signer
91
- * @param data
118
+ * @inheritDoc
92
119
  */
93
120
  async isClaimable(signer, data) {
94
121
  if (!data.isClaimer(signer))
@@ -98,20 +125,14 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
98
125
  return await this.isCommited(data);
99
126
  }
100
127
  /**
101
- * Checks whether a swap is commited, i.e. the swap still exists on-chain and was not claimed nor refunded
102
- *
103
- * @param swapData
128
+ * @inheritDoc
104
129
  */
105
130
  async isCommited(swapData) {
106
131
  const data = await this.contract.getHashState("0x" + swapData.getEscrowHash());
107
132
  return Number(data.state) === ESCROW_STATE_COMMITTED;
108
133
  }
109
134
  /**
110
- * Checks whether the swap is expired, takes into consideration possible on-chain time skew, therefore for claimer
111
- * the swap expires a bit sooner than it should've & for the offerer it expires a bit later
112
- *
113
- * @param signer
114
- * @param data
135
+ * @inheritDoc
115
136
  */
116
137
  isExpired(signer, data) {
117
138
  let currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
@@ -122,11 +143,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
122
143
  return Promise.resolve(data.getExpiry() < currentTimestamp);
123
144
  }
124
145
  /**
125
- * Checks if the swap is refundable by us, checks if we are offerer, if the swap is already expired & if the swap
126
- * is still commited
127
- *
128
- * @param signer
129
- * @param data
146
+ * @inheritDoc
130
147
  */
131
148
  async isRequestRefundable(signer, data) {
132
149
  //Swap can only be refunded by the offerer
@@ -136,6 +153,9 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
136
153
  return false;
137
154
  return await this.isCommited(data);
138
155
  }
156
+ /**
157
+ * @inheritDoc
158
+ */
139
159
  getHashForTxId(txId, confirmations) {
140
160
  const chainTxIdHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_TXID];
141
161
  if (chainTxIdHandler == null)
@@ -147,12 +167,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
147
167
  }).slice(2), "hex");
148
168
  }
149
169
  /**
150
- * Get the swap payment hash to be used for an on-chain swap, uses poseidon hash of the value
151
- *
152
- * @param outputScript output script required to claim the swap
153
- * @param amount sats sent required to claim the swap
154
- * @param confirmations
155
- * @param nonce swap nonce uniquely identifying the transaction to prevent replay attacks
170
+ * @inheritDoc
156
171
  */
157
172
  getHashForOnchain(outputScript, amount, confirmations, nonce) {
158
173
  let result;
@@ -182,9 +197,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
182
197
  return buffer_1.Buffer.from(result.slice(2), "hex");
183
198
  }
184
199
  /**
185
- * Get the swap payment hash to be used for a lightning htlc swap, uses poseidon hash of the sha256 hash of the preimage
186
- *
187
- * @param paymentHash payment hash of the HTLC
200
+ * @inheritDoc
188
201
  */
189
202
  getHashForHtlc(paymentHash) {
190
203
  const htlcHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.HTLC];
@@ -192,6 +205,9 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
192
205
  throw new Error("Claim handler for HTLC not found!");
193
206
  return buffer_1.Buffer.from(htlcHandler.getCommitment(paymentHash).slice(2), "hex");
194
207
  }
208
+ /**
209
+ * @inheritDoc
210
+ */
195
211
  getExtraData(outputScript, amount, confirmations, nonce) {
196
212
  if (nonce == null)
197
213
  nonce = 0n;
@@ -208,11 +224,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
208
224
  ////////////////////////////////////////////
209
225
  //// Swap data getters
210
226
  /**
211
- * Gets the status of the specific swap, this also checks if we are offerer/claimer & checks for expiry (to see
212
- * if swap is refundable)
213
- *
214
- * @param signer
215
- * @param data
227
+ * @inheritDoc
216
228
  */
217
229
  async getCommitStatus(signer, data) {
218
230
  const escrowHash = data.getEscrowHash();
@@ -268,6 +280,9 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
268
280
  };
269
281
  }
270
282
  }
283
+ /**
284
+ * @inheritDoc
285
+ */
271
286
  async getCommitStatuses(request) {
272
287
  const result = {};
273
288
  let promises = [];
@@ -286,6 +301,9 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
286
301
  }
287
302
  ////////////////////////////////////////////
288
303
  //// Swap data initializer
304
+ /**
305
+ * @inheritDoc
306
+ */
289
307
  createSwapData(type, offerer, claimer, token, amount, paymentHash, sequence, expiry, payIn, payOut, securityDeposit, claimerBounty, depositToken = this.Chain.Tokens.getNativeCurrencyAddress()) {
290
308
  const claimHandler = this.claimHandlersBySwapType?.[type];
291
309
  if (claimHandler == null)
@@ -295,14 +313,23 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
295
313
  }
296
314
  ////////////////////////////////////////////
297
315
  //// Utils
316
+ /**
317
+ * @inheritDoc
318
+ */
298
319
  async getBalance(signer, tokenAddress, inContract) {
299
320
  if (inContract)
300
321
  return await this.getIntermediaryBalance(signer, tokenAddress);
301
322
  return await this.Chain.getBalance(signer, tokenAddress);
302
323
  }
324
+ /**
325
+ * @inheritDoc
326
+ */
303
327
  getIntermediaryData(address, token) {
304
328
  return this.LpVault.getIntermediaryData(address, token);
305
329
  }
330
+ /**
331
+ * @inheritDoc
332
+ */
306
333
  getIntermediaryReputation(address, token) {
307
334
  return this.LpVault.getIntermediaryReputation(address, token);
308
335
  }
@@ -311,34 +338,61 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
311
338
  }
312
339
  ////////////////////////////////////////////
313
340
  //// Transaction initializers
341
+ /**
342
+ * @inheritDoc
343
+ */
314
344
  async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
315
345
  return this.Claim.txsClaimWithSecret(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, secret, checkExpiry, feeRate);
316
346
  }
347
+ /**
348
+ * @inheritDoc
349
+ */
317
350
  async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, feeRate) {
318
351
  return this.Claim.txsClaimWithTxData(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate);
319
352
  }
353
+ /**
354
+ * @inheritDoc
355
+ */
320
356
  txsRefund(signer, swapData, check, initAta, feeRate) {
321
357
  return this.Refund.txsRefund(signer, swapData, check, feeRate);
322
358
  }
359
+ /**
360
+ * @inheritDoc
361
+ */
323
362
  txsRefundWithAuthorization(signer, swapData, signature, check, initAta, feeRate) {
324
363
  return this.Refund.txsRefundWithAuthorization(signer, swapData, signature.timeout, signature.prefix, signature.signature, check, feeRate);
325
364
  }
365
+ /**
366
+ * @inheritDoc
367
+ */
326
368
  txsInit(signer, swapData, signature, skipChecks, feeRate) {
327
369
  return this.Init.txsInit(signer, swapData, signature.timeout, signature.prefix, signature.signature, skipChecks, feeRate);
328
370
  }
371
+ /**
372
+ * @inheritDoc
373
+ */
329
374
  txsWithdraw(signer, token, amount, feeRate) {
330
375
  return this.LpVault.txsWithdraw(signer, token, amount, feeRate);
331
376
  }
377
+ /**
378
+ * @inheritDoc
379
+ */
332
380
  txsDeposit(signer, token, amount, feeRate) {
333
381
  return this.LpVault.txsDeposit(signer, token, amount, feeRate);
334
382
  }
335
383
  ////////////////////////////////////////////
336
384
  //// Executors
385
+ /**
386
+ * @inheritDoc
387
+ */
337
388
  async claimWithSecret(signer, swapData, secret, checkExpiry, initAta, txOptions) {
338
389
  const result = await this.Claim.txsClaimWithSecret(signer.getAddress(), swapData, secret, checkExpiry, txOptions?.feeRate);
339
390
  const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
340
391
  return signature;
341
392
  }
393
+ /**
394
+ * @inheritDoc
395
+ */
342
396
  async claimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, txOptions) {
343
397
  const txs = await this.Claim.txsClaimWithTxData(signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, txOptions?.feeRate);
344
398
  if (txs === null)
@@ -346,16 +400,25 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
346
400
  const txHashes = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
347
401
  return txHashes[txHashes.length - 1];
348
402
  }
403
+ /**
404
+ * @inheritDoc
405
+ */
349
406
  async refund(signer, swapData, check, initAta, txOptions) {
350
407
  let result = await this.txsRefund(signer.getAddress(), swapData, check, initAta, txOptions?.feeRate);
351
408
  const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
352
409
  return signature;
353
410
  }
411
+ /**
412
+ * @inheritDoc
413
+ */
354
414
  async refundWithAuthorization(signer, swapData, signature, check, initAta, txOptions) {
355
415
  let result = await this.txsRefundWithAuthorization(signer.getAddress(), swapData, signature, check, initAta, txOptions?.feeRate);
356
416
  const [txSignature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
357
417
  return txSignature;
358
418
  }
419
+ /**
420
+ * @inheritDoc
421
+ */
359
422
  async init(signer, swapData, signature, skipChecks, txOptions) {
360
423
  if (swapData.isPayIn()) {
361
424
  if (!swapData.isOfferer(signer.getAddress()) && !swapData.isOfferer(signer.getAddress()))
@@ -369,11 +432,17 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
369
432
  const txHashes = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
370
433
  return txHashes[txHashes.length - 1];
371
434
  }
435
+ /**
436
+ * @inheritDoc
437
+ */
372
438
  async withdraw(signer, token, amount, txOptions) {
373
439
  const txs = await this.LpVault.txsWithdraw(signer.getAddress(), token, amount, txOptions?.feeRate);
374
440
  const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
375
441
  return txId;
376
442
  }
443
+ /**
444
+ * @inheritDoc
445
+ */
377
446
  async deposit(signer, token, amount, txOptions) {
378
447
  const txs = await this.LpVault.txsDeposit(signer.getAddress(), token, amount, txOptions?.feeRate);
379
448
  const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
@@ -381,29 +450,44 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
381
450
  }
382
451
  ////////////////////////////////////////////
383
452
  //// Fees
453
+ /**
454
+ * @inheritDoc
455
+ */
384
456
  getInitPayInFeeRate(offerer, claimer, token, paymentHash) {
385
457
  return this.Chain.Fees.getFeeRate();
386
458
  }
459
+ /**
460
+ * @inheritDoc
461
+ */
387
462
  getInitFeeRate(offerer, claimer, token, paymentHash) {
388
463
  return this.Chain.Fees.getFeeRate();
389
464
  }
465
+ /**
466
+ * @inheritDoc
467
+ */
390
468
  getRefundFeeRate(swapData) {
391
469
  return this.Chain.Fees.getFeeRate();
392
470
  }
471
+ /**
472
+ * @inheritDoc
473
+ */
393
474
  getClaimFeeRate(signer, swapData) {
394
475
  return this.Chain.Fees.getFeeRate();
395
476
  }
477
+ /**
478
+ * @inheritDoc
479
+ */
396
480
  getClaimFee(signer, swapData, feeRate) {
397
481
  return this.Claim.getClaimFee(swapData, feeRate);
398
482
  }
399
483
  /**
400
- * Get the estimated fee of the commit transaction
484
+ * @inheritDoc
401
485
  */
402
486
  getCommitFee(signer, swapData, feeRate) {
403
487
  return this.Init.getInitFee(swapData, feeRate);
404
488
  }
405
489
  /**
406
- * Get the estimated transaction fee of the refund transaction
490
+ * @inheritDoc
407
491
  */
408
492
  getRefundFee(signer, swapData, feeRate) {
409
493
  return this.Refund.getRefundFee(swapData, feeRate);
@@ -32,39 +32,129 @@ export declare class EVMSwapData extends SwapData {
32
32
  kind: ChainSwapType;
33
33
  constructor(offerer: string, claimer: string, token: string, refundHandler: string, claimHandler: string, payOut: boolean, payIn: boolean, reputation: boolean, sequence: bigint, claimData: string, refundData: string, amount: bigint, depositToken: string, securityDeposit: bigint, claimerBounty: bigint, kind: ChainSwapType, extraData?: string, successActionCommitment?: string);
34
34
  constructor(data: any);
35
+ /**
36
+ * @inheritDoc
37
+ */
35
38
  getOfferer(): string;
39
+ /**
40
+ * @inheritDoc
41
+ */
36
42
  setOfferer(newOfferer: string): void;
43
+ /**
44
+ * @inheritDoc
45
+ */
37
46
  getClaimer(): string;
47
+ /**
48
+ * @inheritDoc
49
+ */
38
50
  setClaimer(newClaimer: string): void;
51
+ /**
52
+ * @inheritDoc
53
+ */
39
54
  serialize(): any;
55
+ /**
56
+ * @inheritDoc
57
+ */
40
58
  getAmount(): bigint;
59
+ /**
60
+ * @inheritDoc
61
+ */
41
62
  getToken(): string;
63
+ /**
64
+ * @inheritDoc
65
+ */
42
66
  isToken(token: string): boolean;
67
+ /**
68
+ * @inheritDoc
69
+ */
43
70
  getType(): ChainSwapType;
71
+ /**
72
+ * @inheritDoc
73
+ */
44
74
  getExpiry(): bigint;
75
+ /**
76
+ * @inheritDoc
77
+ */
45
78
  isPayIn(): boolean;
79
+ /**
80
+ * @inheritDoc
81
+ */
46
82
  isPayOut(): boolean;
83
+ /**
84
+ * @inheritDoc
85
+ */
47
86
  isTrackingReputation(): boolean;
87
+ /**
88
+ * @inheritDoc
89
+ */
48
90
  getEscrowHash(): string;
91
+ /**
92
+ * @inheritDoc
93
+ */
49
94
  getClaimHash(): string;
95
+ /**
96
+ * @inheritDoc
97
+ */
50
98
  getSequence(): bigint;
99
+ /**
100
+ * @inheritDoc
101
+ */
51
102
  getConfirmationsHint(): number | null;
103
+ /**
104
+ * @inheritDoc
105
+ */
52
106
  getNonceHint(): bigint | null;
107
+ /**
108
+ * @inheritDoc
109
+ */
53
110
  getTxoHashHint(): string | null;
111
+ /**
112
+ * @inheritDoc
113
+ */
54
114
  getExtraData(): string | null;
115
+ /**
116
+ * @inheritDoc
117
+ */
55
118
  setExtraData(extraData: string): void;
119
+ /**
120
+ * @inheritDoc
121
+ */
56
122
  getSecurityDeposit(): bigint;
123
+ /**
124
+ * @inheritDoc
125
+ */
57
126
  getClaimerBounty(): bigint;
127
+ /**
128
+ * @inheritDoc
129
+ */
58
130
  getTotalDeposit(): bigint;
131
+ /**
132
+ * @inheritDoc
133
+ */
59
134
  getDepositToken(): string;
135
+ /**
136
+ * @inheritDoc
137
+ */
60
138
  isDepositToken(token: string): boolean;
139
+ /**
140
+ * @inheritDoc
141
+ */
61
142
  isClaimer(address: string): boolean;
143
+ /**
144
+ * @inheritDoc
145
+ */
62
146
  isOfferer(address: string): boolean;
63
147
  isRefundHandler(address: string): boolean;
64
148
  isClaimHandler(address: string): boolean;
65
149
  isClaimData(data: string): boolean;
150
+ /**
151
+ * @inheritDoc
152
+ */
66
153
  equals(other: EVMSwapData): boolean;
67
154
  toEscrowStruct(): EscrowDataStruct;
155
+ /**
156
+ * @inheritDoc
157
+ */
68
158
  hasSuccessAction(): boolean;
69
159
  static deserializeFromStruct(struct: EscrowDataStruct, claimHandlerImpl: IClaimHandler<any, any>): EVMSwapData;
70
160
  }