@atomiqlabs/chain-evm 2.1.11 → 2.1.14

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.
Files changed (151) hide show
  1. package/README.md +75 -0
  2. package/dist/chains/EVMOptions.d.ts +66 -0
  3. package/dist/chains/EVMOptions.js +2 -0
  4. package/dist/chains/alpen/AlpenInitializer.d.ts +3 -30
  5. package/dist/chains/alpen/AlpenInitializer.js +3 -3
  6. package/dist/chains/botanix/BotanixInitializer.d.ts +3 -30
  7. package/dist/chains/botanix/BotanixInitializer.js +3 -3
  8. package/dist/chains/citrea/CitreaBtcRelay.d.ts +5 -0
  9. package/dist/chains/citrea/CitreaBtcRelay.js +7 -2
  10. package/dist/chains/citrea/CitreaFees.d.ts +3 -5
  11. package/dist/chains/citrea/CitreaFees.js +3 -5
  12. package/dist/chains/citrea/CitreaInitializer.d.ts +3 -29
  13. package/dist/chains/citrea/CitreaInitializer.js +3 -3
  14. package/dist/chains/citrea/CitreaSpvVaultContract.d.ts +5 -0
  15. package/dist/chains/citrea/CitreaSpvVaultContract.js +7 -2
  16. package/dist/chains/citrea/CitreaSwapContract.d.ts +7 -2
  17. package/dist/chains/citrea/CitreaSwapContract.js +10 -5
  18. package/dist/chains/citrea/CitreaTokens.d.ts +5 -0
  19. package/dist/chains/citrea/CitreaTokens.js +5 -0
  20. package/dist/chains/goat/GoatInitializer.d.ts +3 -30
  21. package/dist/chains/goat/GoatInitializer.js +3 -3
  22. package/dist/evm/btcrelay/EVMBtcRelay.d.ts +41 -10
  23. package/dist/evm/btcrelay/EVMBtcRelay.js +50 -18
  24. package/dist/evm/btcrelay/headers/EVMBtcHeader.d.ts +53 -7
  25. package/dist/evm/btcrelay/headers/EVMBtcHeader.js +43 -5
  26. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.d.ts +53 -8
  27. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.js +41 -1
  28. package/dist/evm/chain/EVMChainInterface.d.ts +57 -2
  29. package/dist/evm/chain/EVMChainInterface.js +7 -7
  30. package/dist/evm/chain/EVMModule.d.ts +5 -0
  31. package/dist/evm/chain/EVMModule.js +6 -1
  32. package/dist/evm/chain/modules/EVMBlocks.d.ts +7 -0
  33. package/dist/evm/chain/modules/EVMBlocks.js +2 -0
  34. package/dist/evm/chain/modules/EVMEvents.js +19 -19
  35. package/dist/evm/chain/modules/EVMFees.d.ts +41 -5
  36. package/dist/evm/chain/modules/EVMFees.js +24 -5
  37. package/dist/evm/chain/modules/EVMTokens.d.ts +1 -1
  38. package/dist/evm/chain/modules/EVMTokens.js +1 -1
  39. package/dist/evm/chain/modules/EVMTransactions.d.ts +20 -2
  40. package/dist/evm/chain/modules/EVMTransactions.js +11 -8
  41. package/dist/evm/contract/EVMContractBase.d.ts +28 -10
  42. package/dist/evm/contract/EVMContractBase.js +9 -18
  43. package/dist/evm/contract/EVMContractModule.d.ts +5 -0
  44. package/dist/evm/contract/EVMContractModule.js +5 -0
  45. package/dist/evm/contract/modules/EVMContractEvents.d.ts +7 -1
  46. package/dist/evm/contract/modules/EVMContractEvents.js +23 -3
  47. package/dist/evm/events/EVMChainEvents.d.ts +8 -0
  48. package/dist/evm/events/EVMChainEvents.js +8 -0
  49. package/dist/evm/events/EVMChainEventsBrowser.d.ts +87 -19
  50. package/dist/evm/events/EVMChainEventsBrowser.js +53 -18
  51. package/dist/evm/providers/JsonRpcProviderWithRetries.d.ts +9 -0
  52. package/dist/evm/providers/JsonRpcProviderWithRetries.js +9 -0
  53. package/dist/evm/providers/ReconnectingWebSocketProvider.d.ts +5 -0
  54. package/dist/evm/providers/ReconnectingWebSocketProvider.js +5 -0
  55. package/dist/evm/providers/WebSocketProviderWithRetries.d.ts +9 -0
  56. package/dist/evm/providers/WebSocketProviderWithRetries.js +9 -0
  57. package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +46 -21
  58. package/dist/evm/spv_swap/EVMSpvVaultContract.js +62 -22
  59. package/dist/evm/spv_swap/EVMSpvVaultData.d.ts +57 -2
  60. package/dist/evm/spv_swap/EVMSpvVaultData.js +57 -2
  61. package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +12 -0
  62. package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +12 -0
  63. package/dist/evm/swaps/EVMSwapContract.d.ts +58 -13
  64. package/dist/evm/swaps/EVMSwapContract.js +81 -54
  65. package/dist/evm/swaps/EVMSwapData.d.ts +27 -6
  66. package/dist/evm/swaps/EVMSwapData.js +26 -0
  67. package/dist/evm/swaps/EVMSwapModule.d.ts +5 -0
  68. package/dist/evm/swaps/EVMSwapModule.js +5 -0
  69. package/dist/evm/swaps/handlers/IHandler.d.ts +5 -0
  70. package/dist/evm/swaps/handlers/claim/ClaimHandlers.d.ts +15 -0
  71. package/dist/evm/swaps/handlers/claim/ClaimHandlers.js +5 -0
  72. package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +5 -0
  73. package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +10 -0
  74. package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +5 -0
  75. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +15 -0
  76. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +7 -2
  77. package/dist/evm/swaps/modules/EVMLpVault.d.ts +5 -0
  78. package/dist/evm/swaps/modules/EVMLpVault.js +9 -4
  79. package/dist/evm/swaps/modules/EVMSwapClaim.d.ts +7 -2
  80. package/dist/evm/swaps/modules/EVMSwapClaim.js +11 -6
  81. package/dist/evm/swaps/modules/EVMSwapInit.d.ts +10 -0
  82. package/dist/evm/swaps/modules/EVMSwapInit.js +11 -6
  83. package/dist/evm/swaps/modules/EVMSwapRefund.d.ts +5 -0
  84. package/dist/evm/swaps/modules/EVMSwapRefund.js +9 -4
  85. package/dist/evm/wallet/EVMBrowserSigner.d.ts +22 -2
  86. package/dist/evm/wallet/EVMBrowserSigner.js +40 -2
  87. package/dist/evm/wallet/EVMPersistentSigner.d.ts +13 -2
  88. package/dist/evm/wallet/EVMPersistentSigner.js +13 -1
  89. package/dist/evm/wallet/EVMSigner.d.ts +30 -1
  90. package/dist/evm/wallet/EVMSigner.js +34 -1
  91. package/dist/index.d.ts +71 -0
  92. package/dist/index.js +70 -0
  93. package/dist/node/index.d.ts +10 -0
  94. package/dist/node/index.js +15 -0
  95. package/dist/utils/Utils.d.ts +50 -0
  96. package/dist/utils/Utils.js +45 -0
  97. package/node/index.d.ts +1 -0
  98. package/node/index.js +3 -0
  99. package/package.json +4 -3
  100. package/src/chains/EVMOptions.ts +70 -0
  101. package/src/chains/alpen/AlpenInitializer.ts +5 -27
  102. package/src/chains/botanix/BotanixChainType.ts +5 -5
  103. package/src/chains/botanix/BotanixInitializer.ts +5 -27
  104. package/src/chains/citrea/CitreaBtcRelay.ts +8 -3
  105. package/src/chains/citrea/CitreaFees.ts +3 -6
  106. package/src/chains/citrea/CitreaInitializer.ts +5 -27
  107. package/src/chains/citrea/CitreaSpvVaultContract.ts +7 -2
  108. package/src/chains/citrea/CitreaSwapContract.ts +11 -6
  109. package/src/chains/citrea/CitreaTokens.ts +6 -1
  110. package/src/chains/goat/GoatChainType.ts +5 -5
  111. package/src/chains/goat/GoatInitializer.ts +3 -25
  112. package/src/evm/btcrelay/EVMBtcRelay.ts +54 -22
  113. package/src/evm/btcrelay/headers/EVMBtcHeader.ts +60 -13
  114. package/src/evm/btcrelay/headers/EVMBtcStoredHeader.ts +55 -10
  115. package/src/evm/chain/EVMChainInterface.ts +66 -14
  116. package/src/evm/chain/EVMModule.ts +6 -1
  117. package/src/evm/chain/modules/EVMBlocks.ts +7 -0
  118. package/src/evm/chain/modules/EVMEvents.ts +19 -19
  119. package/src/evm/chain/modules/EVMFees.ts +41 -5
  120. package/src/evm/chain/modules/EVMTokens.ts +1 -1
  121. package/src/evm/chain/modules/EVMTransactions.ts +27 -8
  122. package/src/evm/contract/EVMContractBase.ts +29 -24
  123. package/src/evm/contract/EVMContractModule.ts +5 -0
  124. package/src/evm/contract/modules/EVMContractEvents.ts +27 -8
  125. package/src/evm/events/EVMChainEvents.ts +8 -0
  126. package/src/evm/events/EVMChainEventsBrowser.ts +103 -29
  127. package/src/evm/providers/JsonRpcProviderWithRetries.ts +10 -1
  128. package/src/evm/providers/ReconnectingWebSocketProvider.ts +6 -1
  129. package/src/evm/providers/WebSocketProviderWithRetries.ts +10 -1
  130. package/src/evm/spv_swap/EVMSpvVaultContract.ts +73 -31
  131. package/src/evm/spv_swap/EVMSpvVaultData.ts +57 -2
  132. package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +12 -0
  133. package/src/evm/swaps/EVMSwapContract.ts +108 -63
  134. package/src/evm/swaps/EVMSwapData.ts +27 -1
  135. package/src/evm/swaps/EVMSwapModule.ts +5 -0
  136. package/src/evm/swaps/handlers/IHandler.ts +5 -0
  137. package/src/evm/swaps/handlers/claim/ClaimHandlers.ts +15 -0
  138. package/src/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +5 -0
  139. package/src/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +10 -0
  140. package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +5 -0
  141. package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +17 -2
  142. package/src/evm/swaps/modules/EVMLpVault.ts +10 -5
  143. package/src/evm/swaps/modules/EVMSwapClaim.ts +12 -7
  144. package/src/evm/swaps/modules/EVMSwapInit.ts +17 -7
  145. package/src/evm/swaps/modules/EVMSwapRefund.ts +9 -4
  146. package/src/evm/wallet/EVMBrowserSigner.ts +44 -5
  147. package/src/evm/wallet/EVMPersistentSigner.ts +14 -2
  148. package/src/evm/wallet/EVMSigner.ts +37 -1
  149. package/src/index.ts +72 -0
  150. package/src/node/index.ts +10 -0
  151. package/src/utils/Utils.ts +50 -1
@@ -17,6 +17,9 @@ import { EVMPreFetchVerification, EVMSwapInit } from "./modules/EVMSwapInit";
17
17
  import { EVMSwapRefund } from "./modules/EVMSwapRefund";
18
18
  import { EVMSwapClaim } from "./modules/EVMSwapClaim";
19
19
  /**
20
+ * EVM swap contract (escrow manager) representation handling PrTLC (on-chain) and HTLC (lightning)
21
+ * based swaps.
22
+ *
20
23
  * @category Swaps
21
24
  */
22
25
  export declare class EVMSwapContract<ChainId extends string = string> extends EVMContractBase<EscrowManager> implements SwapContract<EVMSwapData, EVMTx, never, EVMPreFetchVerification, EVMSigner, ChainId> {
@@ -25,24 +28,54 @@ export declare class EVMSwapContract<ChainId extends string = string> extends EV
25
28
  readonly claimWithSecretTimeout: number;
26
29
  readonly claimWithTxDataTimeout: number;
27
30
  readonly refundTimeout: number;
28
- readonly claimGracePeriod: number;
29
- readonly refundGracePeriod: number;
30
- readonly authGracePeriod: number;
31
- readonly Init: EVMSwapInit;
32
- readonly Refund: EVMSwapRefund;
33
- readonly Claim: EVMSwapClaim;
34
- readonly LpVault: EVMLpVault;
35
- readonly claimHandlersByAddress: {
31
+ private readonly claimGracePeriod;
32
+ private readonly refundGracePeriod;
33
+ /**
34
+ * @internal
35
+ */
36
+ readonly _authGracePeriod: number;
37
+ /**
38
+ * @internal
39
+ */
40
+ readonly _Init: EVMSwapInit;
41
+ /**
42
+ * @internal
43
+ */
44
+ readonly _Refund: EVMSwapRefund;
45
+ /**
46
+ * @internal
47
+ */
48
+ readonly _Claim: EVMSwapClaim;
49
+ /**
50
+ * @internal
51
+ */
52
+ readonly _LpVault: EVMLpVault;
53
+ /**
54
+ * @internal
55
+ */
56
+ readonly _claimHandlersByAddress: {
36
57
  [address: string]: IClaimHandler<any, any>;
37
58
  };
38
- readonly claimHandlersBySwapType: {
59
+ /**
60
+ * @internal
61
+ */
62
+ readonly _claimHandlersBySwapType: {
39
63
  [type in ChainSwapType]?: IClaimHandler<any, any>;
40
64
  };
41
- readonly refundHandlersByAddress: {
65
+ /**
66
+ * @internal
67
+ */
68
+ readonly _refundHandlersByAddress: {
42
69
  [address: string]: IHandler<any, any>;
43
70
  };
44
- readonly timelockRefundHandler: IHandler<any, any>;
45
- readonly btcRelay: EVMBtcRelay<any>;
71
+ /**
72
+ * @internal
73
+ */
74
+ readonly _timelockRefundHandler: IHandler<any, any>;
75
+ /**
76
+ * @internal
77
+ */
78
+ readonly _btcRelay: EVMBtcRelay<any>;
46
79
  constructor(chainInterface: EVMChainInterface<ChainId>, btcRelay: EVMBtcRelay<any>, contractAddress: string, handlerAddresses: {
47
80
  refund: {
48
81
  timelock: string;
@@ -136,6 +169,9 @@ export declare class EVMSwapContract<ChainId extends string = string> extends EV
136
169
  }[]): Promise<{
137
170
  [p: string]: SwapCommitState;
138
171
  }>;
172
+ /**
173
+ * @inheritDoc
174
+ */
139
175
  getHistoricalSwaps(signer: string, startBlockheight?: number): Promise<{
140
176
  swaps: {
141
177
  [escrowHash: string]: {
@@ -156,6 +192,15 @@ export declare class EVMSwapContract<ChainId extends string = string> extends EV
156
192
  * @inheritDoc
157
193
  */
158
194
  createSwapData(type: ChainSwapType, offerer: string, claimer: string, token: string, amount: bigint, paymentHash: string, sequence: bigint, expiry: bigint, payIn: boolean, payOut: boolean, securityDeposit: bigint, claimerBounty: bigint, depositToken?: string): Promise<EVMSwapData>;
195
+ /**
196
+ * Recursively scans call traces and extracts swap data from `initialize(...)` calldata
197
+ * for the specified escrow hash.
198
+ *
199
+ * @param call Trace call node to inspect
200
+ * @param escrowHash Escrow hash to match
201
+ * @param claimHandler Claim handler used to deserialize claim-specific fields
202
+ * @private
203
+ */
159
204
  findInitSwapData(call: EVMTxTrace, escrowHash: string, claimHandler: IClaimHandler<any, any>): EVMSwapData | null;
160
205
  /**
161
206
  * @inheritDoc
@@ -172,7 +217,7 @@ export declare class EVMSwapContract<ChainId extends string = string> extends EV
172
217
  * @inheritDoc
173
218
  */
174
219
  getIntermediaryReputation(address: string, token: string): Promise<IntermediaryReputationType>;
175
- getIntermediaryBalance(address: string, token: string): Promise<bigint>;
220
+ private getIntermediaryBalance;
176
221
  /**
177
222
  * @inheritDoc
178
223
  */
@@ -20,6 +20,9 @@ const ESCROW_STATE_CLAIMED = 2;
20
20
  const ESCROW_STATE_REFUNDED = 3;
21
21
  const logger = (0, Utils_1.getLogger)("EVMSwapContract: ");
22
22
  /**
23
+ * EVM swap contract (escrow manager) representation handling PrTLC (on-chain) and HTLC (lightning)
24
+ * based swaps.
25
+ *
23
26
  * @category Swaps
24
27
  */
25
28
  class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
@@ -33,25 +36,37 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
33
36
  this.refundTimeout = 180;
34
37
  this.claimGracePeriod = 10 * 60;
35
38
  this.refundGracePeriod = 10 * 60;
36
- this.authGracePeriod = 30;
39
+ /**
40
+ * @internal
41
+ */
42
+ this._authGracePeriod = 30;
37
43
  ////////////////////////
38
44
  //// Handlers
39
- this.claimHandlersByAddress = {};
40
- this.claimHandlersBySwapType = {};
41
- this.refundHandlersByAddress = {};
45
+ /**
46
+ * @internal
47
+ */
48
+ this._claimHandlersByAddress = {};
49
+ /**
50
+ * @internal
51
+ */
52
+ this._claimHandlersBySwapType = {};
53
+ /**
54
+ * @internal
55
+ */
56
+ this._refundHandlersByAddress = {};
42
57
  this.chainId = chainInterface.chainId;
43
- this.Init = new EVMSwapInit_1.EVMSwapInit(chainInterface, this);
44
- this.Refund = new EVMSwapRefund_1.EVMSwapRefund(chainInterface, this);
45
- this.Claim = new EVMSwapClaim_1.EVMSwapClaim(chainInterface, this);
46
- this.LpVault = new EVMLpVault_1.EVMLpVault(chainInterface, this);
47
- this.btcRelay = btcRelay;
58
+ this._Init = new EVMSwapInit_1.EVMSwapInit(chainInterface, this);
59
+ this._Refund = new EVMSwapRefund_1.EVMSwapRefund(chainInterface, this);
60
+ this._Claim = new EVMSwapClaim_1.EVMSwapClaim(chainInterface, this);
61
+ this._LpVault = new EVMLpVault_1.EVMLpVault(chainInterface, this);
62
+ this._btcRelay = btcRelay;
48
63
  ClaimHandlers_1.claimHandlersList.forEach(handlerCtor => {
49
64
  const handler = new handlerCtor(handlerAddresses.claim[handlerCtor.type]);
50
- this.claimHandlersByAddress[handler.address.toLowerCase()] = handler;
51
- this.claimHandlersBySwapType[handlerCtor.type] = handler;
65
+ this._claimHandlersByAddress[handler.address.toLowerCase()] = handler;
66
+ this._claimHandlersBySwapType[handlerCtor.type] = handler;
52
67
  });
53
- this.timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
54
- this.refundHandlersByAddress[this.timelockRefundHandler.address.toLowerCase()] = this.timelockRefundHandler;
68
+ this._timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
69
+ this._refundHandlersByAddress[this._timelockRefundHandler.address.toLowerCase()] = this._timelockRefundHandler;
55
70
  }
56
71
  /**
57
72
  * @inheritDoc
@@ -64,43 +79,43 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
64
79
  * @inheritDoc
65
80
  */
66
81
  preFetchForInitSignatureVerification() {
67
- return this.Init.preFetchForInitSignatureVerification();
82
+ return this._Init.preFetchForInitSignatureVerification();
68
83
  }
69
84
  /**
70
85
  * @inheritDoc
71
86
  */
72
87
  getInitSignature(signer, swapData, authorizationTimeout, preFetchedBlockData, feeRate) {
73
- return this.Init.signSwapInitialization(signer, swapData, authorizationTimeout);
88
+ return this._Init.signSwapInitialization(signer, swapData, authorizationTimeout);
74
89
  }
75
90
  /**
76
91
  * @inheritDoc
77
92
  */
78
93
  isValidInitAuthorization(sender, swapData, signature, feeRate, preFetchedData) {
79
- return this.Init.isSignatureValid(sender, swapData, signature.timeout, signature.prefix, signature.signature, preFetchedData);
94
+ return this._Init.isSignatureValid(sender, swapData, signature.timeout, signature.prefix, signature.signature, preFetchedData);
80
95
  }
81
96
  /**
82
97
  * @inheritDoc
83
98
  */
84
99
  getInitAuthorizationExpiry(swapData, signature, preFetchedData) {
85
- return this.Init.getSignatureExpiry(signature.timeout);
100
+ return this._Init.getSignatureExpiry(signature.timeout);
86
101
  }
87
102
  /**
88
103
  * @inheritDoc
89
104
  */
90
105
  isInitAuthorizationExpired(swapData, signature) {
91
- return this.Init.isSignatureExpired(signature.timeout);
106
+ return this._Init.isSignatureExpired(signature.timeout);
92
107
  }
93
108
  /**
94
109
  * @inheritDoc
95
110
  */
96
111
  getRefundSignature(signer, swapData, authorizationTimeout) {
97
- return this.Refund.signSwapRefund(signer, swapData, authorizationTimeout);
112
+ return this._Refund.signSwapRefund(signer, swapData, authorizationTimeout);
98
113
  }
99
114
  /**
100
115
  * @inheritDoc
101
116
  */
102
117
  isValidRefundAuthorization(swapData, signature) {
103
- return this.Refund.isSignatureValid(swapData, signature.timeout, signature.prefix, signature.signature);
118
+ return this._Refund.isSignatureValid(swapData, signature.timeout, signature.prefix, signature.signature);
104
119
  }
105
120
  /**
106
121
  * @inheritDoc
@@ -159,13 +174,13 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
159
174
  * @inheritDoc
160
175
  */
161
176
  getHashForTxId(txId, confirmations) {
162
- const chainTxIdHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_TXID];
177
+ const chainTxIdHandler = this._claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_TXID];
163
178
  if (chainTxIdHandler == null)
164
179
  throw new Error("Claim handler for CHAIN_TXID not found!");
165
180
  return buffer_1.Buffer.from(chainTxIdHandler.getCommitment({
166
181
  txId,
167
182
  confirmations,
168
- btcRelay: this.btcRelay
183
+ btcRelay: this._btcRelay
169
184
  }).slice(2), "hex");
170
185
  }
171
186
  /**
@@ -174,18 +189,18 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
174
189
  getHashForOnchain(outputScript, amount, confirmations, nonce) {
175
190
  let result;
176
191
  if (nonce == null || nonce === 0n) {
177
- const chainHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN];
192
+ const chainHandler = this._claimHandlersBySwapType[base_1.ChainSwapType.CHAIN];
178
193
  if (chainHandler == null)
179
194
  throw new Error("Claim handler for CHAIN not found!");
180
195
  result = chainHandler.getCommitment({
181
196
  output: outputScript,
182
197
  amount,
183
198
  confirmations,
184
- btcRelay: this.btcRelay
199
+ btcRelay: this._btcRelay
185
200
  });
186
201
  }
187
202
  else {
188
- const chainNoncedHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_NONCED];
203
+ const chainNoncedHandler = this._claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_NONCED];
189
204
  if (chainNoncedHandler == null)
190
205
  throw new Error("Claim handler for CHAIN_NONCED not found!");
191
206
  result = chainNoncedHandler.getCommitment({
@@ -193,7 +208,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
193
208
  amount,
194
209
  nonce,
195
210
  confirmations,
196
- btcRelay: this.btcRelay
211
+ btcRelay: this._btcRelay
197
212
  });
198
213
  }
199
214
  return buffer_1.Buffer.from(result.slice(2), "hex");
@@ -202,7 +217,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
202
217
  * @inheritDoc
203
218
  */
204
219
  getHashForHtlc(paymentHash) {
205
- const htlcHandler = this.claimHandlersBySwapType[base_1.ChainSwapType.HTLC];
220
+ const htlcHandler = this._claimHandlersBySwapType[base_1.ChainSwapType.HTLC];
206
221
  if (htlcHandler == null)
207
222
  throw new Error("Claim handler for HTLC not found!");
208
223
  return buffer_1.Buffer.from(htlcHandler.getCommitment(paymentHash).slice(2), "hex");
@@ -248,13 +263,13 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
248
263
  };
249
264
  },
250
265
  getClaimResult: async () => {
251
- const events = await this.Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
266
+ const events = await this._Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
252
267
  if (events.length === 0)
253
268
  throw new Error("Claim event not found!");
254
269
  return events[0].args.witnessResult;
255
270
  },
256
271
  getClaimTxId: async () => {
257
- const events = await this.Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
272
+ const events = await this._Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
258
273
  if (events.length === 0)
259
274
  throw new Error("Claim event not found!");
260
275
  return events[0].transactionHash;
@@ -270,7 +285,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
270
285
  };
271
286
  },
272
287
  getRefundTxId: async () => {
273
- const events = await this.Events.getContractBlockEvents(["Refund"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
288
+ const events = await this._Events.getContractBlockEvents(["Refund"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
274
289
  if (events.length === 0)
275
290
  throw new Error("Refund event not found!");
276
291
  return events[0].transactionHash;
@@ -293,7 +308,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
293
308
  promises.push(this.getCommitStatus(signer, swapData).then(val => {
294
309
  result[swapData.getEscrowHash()] = val;
295
310
  }));
296
- if (promises.length >= this.Chain.config.maxParallelCalls) {
311
+ if (promises.length >= this.Chain._config.maxParallelCalls) {
297
312
  await Promise.all(promises);
298
313
  promises = [];
299
314
  }
@@ -301,6 +316,9 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
301
316
  await Promise.all(promises);
302
317
  return result;
303
318
  }
319
+ /**
320
+ * @inheritDoc
321
+ */
304
322
  async getHistoricalSwaps(signer, startBlockheight) {
305
323
  const { height: latestBlockheight } = await this.Chain.getFinalizedBlock();
306
324
  const swapsOpened = {};
@@ -310,7 +328,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
310
328
  if (_event.eventName === "Initialize") {
311
329
  const event = _event;
312
330
  const claimHandlerHex = event.args.claimHandler;
313
- const claimHandler = this.claimHandlersByAddress[claimHandlerHex.toLowerCase()];
331
+ const claimHandler = this._claimHandlersByAddress[claimHandlerHex.toLowerCase()];
314
332
  if (claimHandler == null) {
315
333
  logger.warn(`getHistoricalSwaps(): Unknown claim handler in tx ${event.transactionHash} with claim handler: ` + claimHandlerHex);
316
334
  return null;
@@ -372,8 +390,8 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
372
390
  }
373
391
  };
374
392
  //We have to fetch separately the different directions
375
- await this.Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [signer, null], processor, startBlockheight);
376
- await this.Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [null, signer], processor, startBlockheight);
393
+ await this._Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [signer, null], processor, startBlockheight);
394
+ await this._Events.findInContractEventsForward(["Initialize", "Claim", "Refund"], [null, signer], processor, startBlockheight);
377
395
  logger.debug(`getHistoricalSwaps(): Found ${Object.keys(resultingSwaps).length} settled swaps!`);
378
396
  logger.debug(`getHistoricalSwaps(): Found ${Object.keys(swapsOpened).length} unsettled swaps!`);
379
397
  for (let escrowHash in swapsOpened) {
@@ -396,14 +414,23 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
396
414
  * @inheritDoc
397
415
  */
398
416
  createSwapData(type, offerer, claimer, token, amount, paymentHash, sequence, expiry, payIn, payOut, securityDeposit, claimerBounty, depositToken = this.Chain.Tokens.getNativeCurrencyAddress()) {
399
- const claimHandler = this.claimHandlersBySwapType?.[type];
417
+ const claimHandler = this._claimHandlersBySwapType?.[type];
400
418
  if (claimHandler == null)
401
419
  throw new Error(`Claim handler unknown for swap type: ${base_1.ChainSwapType[type]}!`);
402
- return Promise.resolve(new EVMSwapData_1.EVMSwapData(offerer, claimer, token, this.timelockRefundHandler.address, claimHandler.address, payOut, payIn, payIn, //For now track reputation for all payIn swaps
420
+ return Promise.resolve(new EVMSwapData_1.EVMSwapData(offerer, claimer, token, this._timelockRefundHandler.address, claimHandler.address, payOut, payIn, payIn, //For now track reputation for all payIn swaps
403
421
  sequence, "0x" + paymentHash, (0, ethers_1.hexlify)(base_1.BigIntBufferUtils.toBuffer(expiry, "be", 32)), amount, depositToken, securityDeposit, claimerBounty, type));
404
422
  }
423
+ /**
424
+ * Recursively scans call traces and extracts swap data from `initialize(...)` calldata
425
+ * for the specified escrow hash.
426
+ *
427
+ * @param call Trace call node to inspect
428
+ * @param escrowHash Escrow hash to match
429
+ * @param claimHandler Claim handler used to deserialize claim-specific fields
430
+ * @private
431
+ */
405
432
  findInitSwapData(call, escrowHash, claimHandler) {
406
- if (call.to.toLowerCase() === this.contractAddress.toLowerCase()) {
433
+ if (call.to.toLowerCase() === this._contractAddress.toLowerCase()) {
407
434
  const _result = this.parseCalldata(call.input);
408
435
  if (_result != null && _result.name === "initialize") {
409
436
  const result = _result;
@@ -440,16 +467,16 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
440
467
  * @inheritDoc
441
468
  */
442
469
  getIntermediaryData(address, token) {
443
- return this.LpVault.getIntermediaryData(address, token);
470
+ return this._LpVault.getIntermediaryData(address, token);
444
471
  }
445
472
  /**
446
473
  * @inheritDoc
447
474
  */
448
475
  getIntermediaryReputation(address, token) {
449
- return this.LpVault.getIntermediaryReputation(address, token);
476
+ return this._LpVault.getIntermediaryReputation(address, token);
450
477
  }
451
478
  getIntermediaryBalance(address, token) {
452
- return this.LpVault.getIntermediaryBalance(address, token);
479
+ return this._LpVault.getIntermediaryBalance(address, token);
453
480
  }
454
481
  ////////////////////////////////////////////
455
482
  //// Transaction initializers
@@ -457,43 +484,43 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
457
484
  * @inheritDoc
458
485
  */
459
486
  async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
460
- return this.Claim.txsClaimWithSecret(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, secret, checkExpiry, feeRate);
487
+ return this._Claim.txsClaimWithSecret(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, secret, checkExpiry, feeRate);
461
488
  }
462
489
  /**
463
490
  * @inheritDoc
464
491
  */
465
492
  async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, feeRate) {
466
- return this.Claim.txsClaimWithTxData(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate);
493
+ return this._Claim.txsClaimWithTxData(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate);
467
494
  }
468
495
  /**
469
496
  * @inheritDoc
470
497
  */
471
498
  txsRefund(signer, swapData, check, initAta, feeRate) {
472
- return this.Refund.txsRefund(signer, swapData, check, feeRate);
499
+ return this._Refund.txsRefund(signer, swapData, check, feeRate);
473
500
  }
474
501
  /**
475
502
  * @inheritDoc
476
503
  */
477
504
  txsRefundWithAuthorization(signer, swapData, signature, check, initAta, feeRate) {
478
- return this.Refund.txsRefundWithAuthorization(signer, swapData, signature.timeout, signature.prefix, signature.signature, check, feeRate);
505
+ return this._Refund.txsRefundWithAuthorization(signer, swapData, signature.timeout, signature.prefix, signature.signature, check, feeRate);
479
506
  }
480
507
  /**
481
508
  * @inheritDoc
482
509
  */
483
510
  txsInit(signer, swapData, signature, skipChecks, feeRate) {
484
- return this.Init.txsInit(signer, swapData, signature.timeout, signature.prefix, signature.signature, skipChecks, feeRate);
511
+ return this._Init.txsInit(signer, swapData, signature.timeout, signature.prefix, signature.signature, skipChecks, feeRate);
485
512
  }
486
513
  /**
487
514
  * @inheritDoc
488
515
  */
489
516
  txsWithdraw(signer, token, amount, feeRate) {
490
- return this.LpVault.txsWithdraw(signer, token, amount, feeRate);
517
+ return this._LpVault.txsWithdraw(signer, token, amount, feeRate);
491
518
  }
492
519
  /**
493
520
  * @inheritDoc
494
521
  */
495
522
  txsDeposit(signer, token, amount, feeRate) {
496
- return this.LpVault.txsDeposit(signer, token, amount, feeRate);
523
+ return this._LpVault.txsDeposit(signer, token, amount, feeRate);
497
524
  }
498
525
  ////////////////////////////////////////////
499
526
  //// Executors
@@ -501,7 +528,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
501
528
  * @inheritDoc
502
529
  */
503
530
  async claimWithSecret(signer, swapData, secret, checkExpiry, initAta, txOptions) {
504
- const result = await this.Claim.txsClaimWithSecret(signer.getAddress(), swapData, secret, checkExpiry, txOptions?.feeRate);
531
+ const result = await this._Claim.txsClaimWithSecret(signer.getAddress(), swapData, secret, checkExpiry, txOptions?.feeRate);
505
532
  const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
506
533
  return signature;
507
534
  }
@@ -509,7 +536,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
509
536
  * @inheritDoc
510
537
  */
511
538
  async claimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, txOptions) {
512
- const txs = await this.Claim.txsClaimWithTxData(signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, txOptions?.feeRate);
539
+ const txs = await this._Claim.txsClaimWithTxData(signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, txOptions?.feeRate);
513
540
  if (txs === null)
514
541
  throw new Error("Btc relay not synchronized to required blockheight!");
515
542
  const txHashes = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
@@ -551,7 +578,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
551
578
  * @inheritDoc
552
579
  */
553
580
  async withdraw(signer, token, amount, txOptions) {
554
- const txs = await this.LpVault.txsWithdraw(signer.getAddress(), token, amount, txOptions?.feeRate);
581
+ const txs = await this._LpVault.txsWithdraw(signer.getAddress(), token, amount, txOptions?.feeRate);
555
582
  const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
556
583
  return txId;
557
584
  }
@@ -559,7 +586,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
559
586
  * @inheritDoc
560
587
  */
561
588
  async deposit(signer, token, amount, txOptions) {
562
- const txs = await this.LpVault.txsDeposit(signer.getAddress(), token, amount, txOptions?.feeRate);
589
+ const txs = await this._LpVault.txsDeposit(signer.getAddress(), token, amount, txOptions?.feeRate);
563
590
  const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
564
591
  return txId;
565
592
  }
@@ -593,19 +620,19 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
593
620
  * @inheritDoc
594
621
  */
595
622
  getClaimFee(signer, swapData, feeRate) {
596
- return this.Claim.getClaimFee(swapData, feeRate);
623
+ return this._Claim.getClaimFee(swapData, feeRate);
597
624
  }
598
625
  /**
599
626
  * @inheritDoc
600
627
  */
601
628
  getCommitFee(signer, swapData, feeRate) {
602
- return this.Init.getInitFee(swapData, feeRate);
629
+ return this._Init.getInitFee(swapData, feeRate);
603
630
  }
604
631
  /**
605
632
  * @inheritDoc
606
633
  */
607
634
  getRefundFee(signer, swapData, feeRate) {
608
- return this.Refund.getRefundFee(swapData, feeRate);
635
+ return this._Refund.getRefundFee(swapData, feeRate);
609
636
  }
610
637
  }
611
638
  exports.EVMSwapContract = EVMSwapContract;
@@ -2,15 +2,12 @@ import { SwapData, ChainSwapType } from "@atomiqlabs/base";
2
2
  import { EscrowDataStruct } from "./EscrowManagerTypechain";
3
3
  import { IClaimHandler } from "./handlers/claim/ClaimHandlers";
4
4
  /**
5
+ * Represents swap data for executing PrTLC (on-chain) or HTLC (lightning) based swaps.
6
+ *
5
7
  * @category Swaps
6
8
  */
7
9
  export declare class EVMSwapData extends SwapData {
8
- static toFlags(val: bigint): {
9
- payOut: boolean;
10
- payIn: boolean;
11
- reputation: boolean;
12
- sequence: bigint;
13
- };
10
+ private static toFlags;
14
11
  private getFlags;
15
12
  offerer: string;
16
13
  claimer: string;
@@ -144,17 +141,41 @@ export declare class EVMSwapData extends SwapData {
144
141
  * @inheritDoc
145
142
  */
146
143
  isOfferer(address: string): boolean;
144
+ /**
145
+ * Checks whether the passed address is specified as the refund handler for the swap.
146
+ *
147
+ * @param address
148
+ */
147
149
  isRefundHandler(address: string): boolean;
150
+ /**
151
+ * Checks whether the passed address is specified as the claim handler for the swap.
152
+ *
153
+ * @param address
154
+ */
148
155
  isClaimHandler(address: string): boolean;
156
+ /**
157
+ * Checks if the passed data matches the swap's claim data.
158
+ *
159
+ * @param data
160
+ */
149
161
  isClaimData(data: string): boolean;
150
162
  /**
151
163
  * @inheritDoc
152
164
  */
153
165
  equals(other: EVMSwapData): boolean;
166
+ /**
167
+ * Serializes the swap data into the EVM escrow-manager struct representation.
168
+ */
154
169
  toEscrowStruct(): EscrowDataStruct;
155
170
  /**
156
171
  * @inheritDoc
157
172
  */
158
173
  hasSuccessAction(): boolean;
174
+ /**
175
+ * Deserializes swap data from an on-chain escrow struct.
176
+ *
177
+ * @param struct Escrow struct as returned by the contract
178
+ * @param claimHandlerImpl Claim handler implementation used to resolve swap type
179
+ */
159
180
  static deserializeFromStruct(struct: EscrowDataStruct, claimHandlerImpl: IClaimHandler<any, any>): EVMSwapData;
160
181
  }
@@ -8,6 +8,8 @@ const FLAG_PAY_OUT = 0x01n;
8
8
  const FLAG_PAY_IN = 0x02n;
9
9
  const FLAG_REPUTATION = 0x04n;
10
10
  /**
11
+ * Represents swap data for executing PrTLC (on-chain) or HTLC (lightning) based swaps.
12
+ *
11
13
  * @category Swaps
12
14
  */
13
15
  class EVMSwapData extends base_1.SwapData {
@@ -325,16 +327,31 @@ class EVMSwapData extends base_1.SwapData {
325
327
  address = "0x" + address;
326
328
  return this.offerer.toLowerCase() === address.toLowerCase();
327
329
  }
330
+ /**
331
+ * Checks whether the passed address is specified as the refund handler for the swap.
332
+ *
333
+ * @param address
334
+ */
328
335
  isRefundHandler(address) {
329
336
  if (!address.startsWith("0x"))
330
337
  address = "0x" + address;
331
338
  return this.refundHandler.toLowerCase() === address.toLowerCase();
332
339
  }
340
+ /**
341
+ * Checks whether the passed address is specified as the claim handler for the swap.
342
+ *
343
+ * @param address
344
+ */
333
345
  isClaimHandler(address) {
334
346
  if (!address.startsWith("0x"))
335
347
  address = "0x" + address;
336
348
  return this.claimHandler.toLowerCase() === address.toLowerCase();
337
349
  }
350
+ /**
351
+ * Checks if the passed data matches the swap's claim data.
352
+ *
353
+ * @param data
354
+ */
338
355
  isClaimData(data) {
339
356
  if (!data.startsWith("0x"))
340
357
  data = "0x" + data;
@@ -360,6 +377,9 @@ class EVMSwapData extends base_1.SwapData {
360
377
  other.claimerBounty === this.claimerBounty &&
361
378
  other.successActionCommitment.toLowerCase() === this.successActionCommitment.toLowerCase();
362
379
  }
380
+ /**
381
+ * Serializes the swap data into the EVM escrow-manager struct representation.
382
+ */
363
383
  toEscrowStruct() {
364
384
  return {
365
385
  offerer: this.offerer,
@@ -383,6 +403,12 @@ class EVMSwapData extends base_1.SwapData {
383
403
  hasSuccessAction() {
384
404
  return this.successActionCommitment !== ethers_1.ZeroHash;
385
405
  }
406
+ /**
407
+ * Deserializes swap data from an on-chain escrow struct.
408
+ *
409
+ * @param struct Escrow struct as returned by the contract
410
+ * @param claimHandlerImpl Claim handler implementation used to resolve swap type
411
+ */
386
412
  static deserializeFromStruct(struct, claimHandlerImpl) {
387
413
  const { payOut, payIn, reputation, sequence } = EVMSwapData.toFlags(BigInt(struct.flags));
388
414
  return new EVMSwapData(struct.offerer, struct.claimer, struct.token, struct.refundHandler, struct.claimHandler, payOut, payIn, reputation, sequence, (0, ethers_1.hexlify)(struct.claimData), (0, ethers_1.hexlify)(struct.refundData), BigInt(struct.amount), struct.depositToken, BigInt(struct.securityDeposit), BigInt(struct.claimerBounty), claimHandlerImpl.getType(), undefined, struct.successActionCommitment);
@@ -2,6 +2,11 @@ import { EscrowManager } from "./EscrowManagerTypechain";
2
2
  import { EVMContractModule } from "../contract/EVMContractModule";
3
3
  import { EVMSwapContract } from "./EVMSwapContract";
4
4
  import { EVMChainInterface } from "../chain/EVMChainInterface";
5
+ /**
6
+ * Base class for EVM swap submodules operating on the escrow manager contract.
7
+ *
8
+ * @category Internal/Swaps
9
+ */
5
10
  export declare class EVMSwapModule extends EVMContractModule<EscrowManager, EVMSwapContract> {
6
11
  readonly swapContract: EscrowManager;
7
12
  constructor(chainInterface: EVMChainInterface, contract: EVMSwapContract);
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMSwapModule = void 0;
4
4
  const EVMContractModule_1 = require("../contract/EVMContractModule");
5
+ /**
6
+ * Base class for EVM swap submodules operating on the escrow manager contract.
7
+ *
8
+ * @category Internal/Swaps
9
+ */
5
10
  class EVMSwapModule extends EVMContractModule_1.EVMContractModule {
6
11
  constructor(chainInterface, contract) {
7
12
  super(chainInterface, contract);
@@ -2,6 +2,11 @@
2
2
  /// <reference types="node" />
3
3
  import { EVMSwapData } from "../EVMSwapData";
4
4
  import { EVMTx } from "../../chain/modules/EVMTransactions";
5
+ /**
6
+ * Generic swap handler interface for commitment and witness generation.
7
+ *
8
+ * @category Internal/Handlers
9
+ */
5
10
  export interface IHandler<TCommitmentData, TWitnessData> {
6
11
  readonly address: string;
7
12
  getCommitment(data: TCommitmentData): string;