@atomiqlabs/chain-evm 1.0.0-dev.37 → 1.0.0-dev.39

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 (167) hide show
  1. package/LICENSE +201 -201
  2. package/dist/chains/botanix/BotanixChainType.d.ts +13 -0
  3. package/dist/chains/botanix/BotanixChainType.js +2 -0
  4. package/dist/chains/botanix/BotanixInitializer.d.ts +30 -0
  5. package/dist/chains/botanix/BotanixInitializer.js +117 -0
  6. package/dist/chains/citrea/CitreaBtcRelay.d.ts +21 -21
  7. package/dist/chains/citrea/CitreaBtcRelay.js +43 -43
  8. package/dist/chains/citrea/CitreaChainType.d.ts +13 -13
  9. package/dist/chains/citrea/CitreaChainType.js +2 -2
  10. package/dist/chains/citrea/CitreaFees.d.ts +29 -29
  11. package/dist/chains/citrea/CitreaFees.js +67 -67
  12. package/dist/chains/citrea/CitreaInitializer.d.ts +30 -30
  13. package/dist/chains/citrea/CitreaInitializer.js +127 -127
  14. package/dist/chains/citrea/CitreaSpvVaultContract.d.ts +15 -15
  15. package/dist/chains/citrea/CitreaSpvVaultContract.js +74 -74
  16. package/dist/chains/citrea/CitreaSwapContract.d.ts +22 -22
  17. package/dist/chains/citrea/CitreaSwapContract.js +96 -96
  18. package/dist/chains/citrea/CitreaTokens.d.ts +9 -9
  19. package/dist/chains/citrea/CitreaTokens.js +20 -20
  20. package/dist/evm/btcrelay/BtcRelayAbi.d.ts +198 -198
  21. package/dist/evm/btcrelay/BtcRelayAbi.js +261 -261
  22. package/dist/evm/btcrelay/BtcRelayTypechain.d.ts +172 -172
  23. package/dist/evm/btcrelay/BtcRelayTypechain.js +2 -2
  24. package/dist/evm/btcrelay/EVMBtcRelay.d.ts +195 -195
  25. package/dist/evm/btcrelay/EVMBtcRelay.js +423 -423
  26. package/dist/evm/btcrelay/headers/EVMBtcHeader.d.ts +33 -33
  27. package/dist/evm/btcrelay/headers/EVMBtcHeader.js +84 -84
  28. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.d.ts +56 -56
  29. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.js +123 -123
  30. package/dist/evm/chain/EVMChainInterface.d.ts +51 -51
  31. package/dist/evm/chain/EVMChainInterface.js +89 -89
  32. package/dist/evm/chain/EVMModule.d.ts +9 -9
  33. package/dist/evm/chain/EVMModule.js +13 -13
  34. package/dist/evm/chain/modules/ERC20Abi.d.ts +168 -168
  35. package/dist/evm/chain/modules/ERC20Abi.js +225 -225
  36. package/dist/evm/chain/modules/EVMAddresses.d.ts +10 -10
  37. package/dist/evm/chain/modules/EVMAddresses.js +30 -30
  38. package/dist/evm/chain/modules/EVMBlocks.d.ts +20 -20
  39. package/dist/evm/chain/modules/EVMBlocks.js +64 -64
  40. package/dist/evm/chain/modules/EVMEvents.d.ts +36 -36
  41. package/dist/evm/chain/modules/EVMEvents.js +122 -122
  42. package/dist/evm/chain/modules/EVMFees.d.ts +36 -36
  43. package/dist/evm/chain/modules/EVMFees.js +73 -73
  44. package/dist/evm/chain/modules/EVMSignatures.d.ts +29 -29
  45. package/dist/evm/chain/modules/EVMSignatures.js +68 -68
  46. package/dist/evm/chain/modules/EVMTokens.d.ts +70 -70
  47. package/dist/evm/chain/modules/EVMTokens.js +142 -142
  48. package/dist/evm/chain/modules/EVMTransactions.d.ts +89 -89
  49. package/dist/evm/chain/modules/EVMTransactions.js +230 -230
  50. package/dist/evm/contract/EVMContractBase.d.ts +22 -22
  51. package/dist/evm/contract/EVMContractBase.js +34 -34
  52. package/dist/evm/contract/EVMContractModule.d.ts +8 -8
  53. package/dist/evm/contract/EVMContractModule.js +11 -11
  54. package/dist/evm/contract/modules/EVMContractEvents.d.ts +42 -42
  55. package/dist/evm/contract/modules/EVMContractEvents.js +75 -75
  56. package/dist/evm/events/EVMChainEvents.d.ts +22 -22
  57. package/dist/evm/events/EVMChainEvents.js +67 -67
  58. package/dist/evm/events/EVMChainEventsBrowser.d.ts +86 -86
  59. package/dist/evm/events/EVMChainEventsBrowser.js +294 -294
  60. package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +78 -78
  61. package/dist/evm/spv_swap/EVMSpvVaultContract.js +478 -478
  62. package/dist/evm/spv_swap/EVMSpvVaultData.d.ts +39 -39
  63. package/dist/evm/spv_swap/EVMSpvVaultData.js +180 -180
  64. package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +19 -19
  65. package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +55 -55
  66. package/dist/evm/spv_swap/SpvVaultContractAbi.d.ts +91 -91
  67. package/dist/evm/spv_swap/SpvVaultContractAbi.js +849 -849
  68. package/dist/evm/spv_swap/SpvVaultContractTypechain.d.ts +450 -450
  69. package/dist/evm/spv_swap/SpvVaultContractTypechain.js +2 -2
  70. package/dist/evm/swaps/EVMSwapContract.d.ts +193 -193
  71. package/dist/evm/swaps/EVMSwapContract.js +378 -374
  72. package/dist/evm/swaps/EVMSwapData.d.ts +66 -66
  73. package/dist/evm/swaps/EVMSwapData.js +260 -260
  74. package/dist/evm/swaps/EVMSwapModule.d.ts +9 -9
  75. package/dist/evm/swaps/EVMSwapModule.js +11 -11
  76. package/dist/evm/swaps/EscrowManagerAbi.d.ts +120 -120
  77. package/dist/evm/swaps/EscrowManagerAbi.js +985 -985
  78. package/dist/evm/swaps/EscrowManagerTypechain.d.ts +475 -475
  79. package/dist/evm/swaps/EscrowManagerTypechain.js +2 -2
  80. package/dist/evm/swaps/handlers/IHandler.d.ts +13 -13
  81. package/dist/evm/swaps/handlers/IHandler.js +2 -2
  82. package/dist/evm/swaps/handlers/claim/ClaimHandlers.d.ts +10 -10
  83. package/dist/evm/swaps/handlers/claim/ClaimHandlers.js +13 -13
  84. package/dist/evm/swaps/handlers/claim/HashlockClaimHandler.d.ts +20 -20
  85. package/dist/evm/swaps/handlers/claim/HashlockClaimHandler.js +39 -39
  86. package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +24 -24
  87. package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.js +59 -59
  88. package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +25 -25
  89. package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.js +51 -51
  90. package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +21 -21
  91. package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.js +28 -28
  92. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +48 -48
  93. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +63 -63
  94. package/dist/evm/swaps/handlers/refund/TimelockRefundHandler.d.ts +17 -17
  95. package/dist/evm/swaps/handlers/refund/TimelockRefundHandler.js +28 -28
  96. package/dist/evm/swaps/modules/EVMLpVault.d.ts +69 -69
  97. package/dist/evm/swaps/modules/EVMLpVault.js +134 -134
  98. package/dist/evm/swaps/modules/EVMSwapClaim.d.ts +54 -54
  99. package/dist/evm/swaps/modules/EVMSwapClaim.js +137 -137
  100. package/dist/evm/swaps/modules/EVMSwapInit.d.ts +88 -88
  101. package/dist/evm/swaps/modules/EVMSwapInit.js +274 -274
  102. package/dist/evm/swaps/modules/EVMSwapRefund.d.ts +62 -62
  103. package/dist/evm/swaps/modules/EVMSwapRefund.js +167 -167
  104. package/dist/evm/typechain/common.d.ts +50 -50
  105. package/dist/evm/typechain/common.js +2 -2
  106. package/dist/evm/wallet/EVMSigner.d.ts +10 -10
  107. package/dist/evm/wallet/EVMSigner.js +17 -17
  108. package/dist/index.d.ts +40 -38
  109. package/dist/index.js +56 -54
  110. package/dist/utils/Utils.d.ts +15 -15
  111. package/dist/utils/Utils.js +71 -71
  112. package/package.json +37 -37
  113. package/src/chains/botanix/BotanixChainType.ts +28 -0
  114. package/src/chains/botanix/BotanixInitializer.ts +164 -0
  115. package/src/chains/citrea/CitreaBtcRelay.ts +57 -57
  116. package/src/chains/citrea/CitreaChainType.ts +28 -28
  117. package/src/chains/citrea/CitreaFees.ts +77 -77
  118. package/src/chains/citrea/CitreaInitializer.ts +178 -178
  119. package/src/chains/citrea/CitreaSpvVaultContract.ts +75 -75
  120. package/src/chains/citrea/CitreaSwapContract.ts +102 -102
  121. package/src/chains/citrea/CitreaTokens.ts +21 -21
  122. package/src/evm/btcrelay/BtcRelayAbi.ts +258 -258
  123. package/src/evm/btcrelay/BtcRelayTypechain.ts +371 -371
  124. package/src/evm/btcrelay/EVMBtcRelay.ts +522 -522
  125. package/src/evm/btcrelay/headers/EVMBtcHeader.ts +109 -109
  126. package/src/evm/btcrelay/headers/EVMBtcStoredHeader.ts +152 -152
  127. package/src/evm/chain/EVMChainInterface.ts +155 -155
  128. package/src/evm/chain/EVMModule.ts +21 -21
  129. package/src/evm/chain/modules/ERC20Abi.ts +222 -222
  130. package/src/evm/chain/modules/EVMAddresses.ts +28 -28
  131. package/src/evm/chain/modules/EVMBlocks.ts +75 -75
  132. package/src/evm/chain/modules/EVMEvents.ts +139 -139
  133. package/src/evm/chain/modules/EVMFees.ts +104 -104
  134. package/src/evm/chain/modules/EVMSignatures.ts +76 -76
  135. package/src/evm/chain/modules/EVMTokens.ts +155 -155
  136. package/src/evm/chain/modules/EVMTransactions.ts +257 -257
  137. package/src/evm/contract/EVMContractBase.ts +63 -63
  138. package/src/evm/contract/EVMContractModule.ts +16 -16
  139. package/src/evm/contract/modules/EVMContractEvents.ts +102 -102
  140. package/src/evm/events/EVMChainEvents.ts +81 -81
  141. package/src/evm/events/EVMChainEventsBrowser.ts +390 -390
  142. package/src/evm/spv_swap/EVMSpvVaultContract.ts +608 -608
  143. package/src/evm/spv_swap/EVMSpvVaultData.ts +224 -224
  144. package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +70 -70
  145. package/src/evm/spv_swap/SpvVaultContractAbi.ts +846 -846
  146. package/src/evm/spv_swap/SpvVaultContractTypechain.ts +685 -685
  147. package/src/evm/swaps/EVMSwapContract.ts +600 -592
  148. package/src/evm/swaps/EVMSwapData.ts +378 -378
  149. package/src/evm/swaps/EVMSwapModule.ts +16 -16
  150. package/src/evm/swaps/EscrowManagerAbi.ts +982 -982
  151. package/src/evm/swaps/EscrowManagerTypechain.ts +723 -723
  152. package/src/evm/swaps/handlers/IHandler.ts +17 -17
  153. package/src/evm/swaps/handlers/claim/ClaimHandlers.ts +20 -20
  154. package/src/evm/swaps/handlers/claim/HashlockClaimHandler.ts +46 -46
  155. package/src/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +82 -82
  156. package/src/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +76 -76
  157. package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +46 -46
  158. package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +115 -115
  159. package/src/evm/swaps/handlers/refund/TimelockRefundHandler.ts +37 -37
  160. package/src/evm/swaps/modules/EVMLpVault.ts +154 -154
  161. package/src/evm/swaps/modules/EVMSwapClaim.ts +172 -172
  162. package/src/evm/swaps/modules/EVMSwapInit.ts +328 -328
  163. package/src/evm/swaps/modules/EVMSwapRefund.ts +229 -229
  164. package/src/evm/typechain/common.ts +131 -131
  165. package/src/evm/wallet/EVMSigner.ts +25 -25
  166. package/src/index.ts +48 -45
  167. package/src/utils/Utils.ts +81 -81
@@ -1,374 +1,378 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EVMSwapContract = void 0;
4
- const base_1 = require("@atomiqlabs/base");
5
- const buffer_1 = require("buffer");
6
- const TimelockRefundHandler_1 = require("./handlers/refund/TimelockRefundHandler");
7
- const ClaimHandlers_1 = require("./handlers/claim/ClaimHandlers");
8
- const sha2_1 = require("@noble/hashes/sha2");
9
- const EVMContractBase_1 = require("../contract/EVMContractBase");
10
- const EVMSwapData_1 = require("./EVMSwapData");
11
- const EscrowManagerAbi_1 = require("./EscrowManagerAbi");
12
- const ethers_1 = require("ethers");
13
- const EVMLpVault_1 = require("./modules/EVMLpVault");
14
- const EVMSwapInit_1 = require("./modules/EVMSwapInit");
15
- const EVMSwapRefund_1 = require("./modules/EVMSwapRefund");
16
- const EVMSwapClaim_1 = require("./modules/EVMSwapClaim");
17
- const ESCROW_STATE_COMMITTED = 1;
18
- const ESCROW_STATE_CLAIMED = 2;
19
- const ESCROW_STATE_REFUNDED = 3;
20
- class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
21
- constructor(chainInterface, btcRelay, contractAddress, handlerAddresses) {
22
- super(chainInterface, contractAddress, EscrowManagerAbi_1.EscrowManagerAbi);
23
- this.supportsInitWithoutClaimer = true;
24
- ////////////////////////
25
- //// Timeouts
26
- this.claimWithSecretTimeout = 180;
27
- this.claimWithTxDataTimeout = 180;
28
- this.refundTimeout = 180;
29
- this.claimGracePeriod = 10 * 60;
30
- this.refundGracePeriod = 10 * 60;
31
- this.authGracePeriod = 30;
32
- ////////////////////////
33
- //// Handlers
34
- this.claimHandlersByAddress = {};
35
- this.claimHandlersBySwapType = {};
36
- this.refundHandlersByAddress = {};
37
- this.chainId = chainInterface.chainId;
38
- this.Init = new EVMSwapInit_1.EVMSwapInit(chainInterface, this);
39
- this.Refund = new EVMSwapRefund_1.EVMSwapRefund(chainInterface, this);
40
- this.Claim = new EVMSwapClaim_1.EVMSwapClaim(chainInterface, this);
41
- this.LpVault = new EVMLpVault_1.EVMLpVault(chainInterface, this);
42
- this.btcRelay = btcRelay;
43
- ClaimHandlers_1.claimHandlersList.forEach(handlerCtor => {
44
- const handler = new handlerCtor(handlerAddresses.claim[handlerCtor.type]);
45
- this.claimHandlersByAddress[handler.address.toLowerCase()] = handler;
46
- this.claimHandlersBySwapType[handlerCtor.type] = handler;
47
- });
48
- this.timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
49
- this.refundHandlersByAddress[this.timelockRefundHandler.address.toLowerCase()] = this.timelockRefundHandler;
50
- }
51
- async start() {
52
- }
53
- ////////////////////////////////////////////
54
- //// Signatures
55
- preFetchForInitSignatureVerification() {
56
- return this.Init.preFetchForInitSignatureVerification();
57
- }
58
- getInitSignature(signer, swapData, authorizationTimeout, preFetchedBlockData, feeRate) {
59
- return this.Init.signSwapInitialization(signer, swapData, authorizationTimeout);
60
- }
61
- isValidInitAuthorization(sender, swapData, { timeout, prefix, signature }, feeRate, preFetchedData) {
62
- return this.Init.isSignatureValid(sender, swapData, timeout, prefix, signature, preFetchedData);
63
- }
64
- getInitAuthorizationExpiry(swapData, { timeout, prefix, signature }, preFetchedData) {
65
- return this.Init.getSignatureExpiry(timeout);
66
- }
67
- isInitAuthorizationExpired(swapData, { timeout, prefix, signature }) {
68
- return this.Init.isSignatureExpired(timeout);
69
- }
70
- getRefundSignature(signer, swapData, authorizationTimeout) {
71
- return this.Refund.signSwapRefund(signer, swapData, authorizationTimeout);
72
- }
73
- isValidRefundAuthorization(swapData, { timeout, prefix, signature }) {
74
- return this.Refund.isSignatureValid(swapData, timeout, prefix, signature);
75
- }
76
- getDataSignature(signer, data) {
77
- return this.Chain.Signatures.getDataSignature(signer, data);
78
- }
79
- isValidDataSignature(data, signature, publicKey) {
80
- return this.Chain.Signatures.isValidDataSignature(data, signature, publicKey);
81
- }
82
- ////////////////////////////////////////////
83
- //// Swap data utils
84
- /**
85
- * Checks whether the claim is claimable by us, that means not expired, we are claimer & the swap is commited
86
- *
87
- * @param signer
88
- * @param data
89
- */
90
- async isClaimable(signer, data) {
91
- if (!data.isClaimer(signer))
92
- return false;
93
- if (await this.isExpired(signer, data))
94
- return false;
95
- return await this.isCommited(data);
96
- }
97
- /**
98
- * Checks whether a swap is commited, i.e. the swap still exists on-chain and was not claimed nor refunded
99
- *
100
- * @param swapData
101
- */
102
- async isCommited(swapData) {
103
- const data = await this.contract.getHashState("0x" + swapData.getEscrowHash());
104
- return Number(data.state) === ESCROW_STATE_COMMITTED;
105
- }
106
- /**
107
- * Checks whether the swap is expired, takes into consideration possible on-chain time skew, therefore for claimer
108
- * the swap expires a bit sooner than it should've & for the offerer it expires a bit later
109
- *
110
- * @param signer
111
- * @param data
112
- */
113
- isExpired(signer, data) {
114
- let currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
115
- if (data.isClaimer(signer))
116
- currentTimestamp = currentTimestamp + BigInt(this.claimGracePeriod);
117
- if (data.isOfferer(signer))
118
- currentTimestamp = currentTimestamp - BigInt(this.refundGracePeriod);
119
- return Promise.resolve(data.getExpiry() < currentTimestamp);
120
- }
121
- /**
122
- * Checks if the swap is refundable by us, checks if we are offerer, if the swap is already expired & if the swap
123
- * is still commited
124
- *
125
- * @param signer
126
- * @param data
127
- */
128
- async isRequestRefundable(signer, data) {
129
- //Swap can only be refunded by the offerer
130
- if (!data.isOfferer(signer))
131
- return false;
132
- if (!(await this.isExpired(signer, data)))
133
- return false;
134
- return await this.isCommited(data);
135
- }
136
- getHashForTxId(txId, confirmations) {
137
- return buffer_1.Buffer.from(this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_TXID].getCommitment({
138
- txId,
139
- confirmations,
140
- btcRelay: this.btcRelay
141
- }).slice(2), "hex");
142
- }
143
- /**
144
- * Get the swap payment hash to be used for an on-chain swap, uses poseidon hash of the value
145
- *
146
- * @param outputScript output script required to claim the swap
147
- * @param amount sats sent required to claim the swap
148
- * @param confirmations
149
- * @param nonce swap nonce uniquely identifying the transaction to prevent replay attacks
150
- */
151
- getHashForOnchain(outputScript, amount, confirmations, nonce) {
152
- let result;
153
- if (nonce == null || nonce === 0n) {
154
- result = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN].getCommitment({
155
- output: outputScript,
156
- amount,
157
- confirmations,
158
- btcRelay: this.btcRelay
159
- });
160
- }
161
- else {
162
- result = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_NONCED].getCommitment({
163
- output: outputScript,
164
- amount,
165
- nonce,
166
- confirmations,
167
- btcRelay: this.btcRelay
168
- });
169
- }
170
- return buffer_1.Buffer.from(result.slice(2), "hex");
171
- }
172
- /**
173
- * Get the swap payment hash to be used for a lightning htlc swap, uses poseidon hash of the sha256 hash of the preimage
174
- *
175
- * @param paymentHash payment hash of the HTLC
176
- */
177
- getHashForHtlc(paymentHash) {
178
- return buffer_1.Buffer.from(this.claimHandlersBySwapType[base_1.ChainSwapType.HTLC].getCommitment(paymentHash).slice(2), "hex");
179
- }
180
- getExtraData(outputScript, amount, confirmations, nonce) {
181
- if (nonce == null)
182
- nonce = 0n;
183
- const txoHash = buffer_1.Buffer.from((0, sha2_1.sha256)(buffer_1.Buffer.concat([
184
- base_1.BigIntBufferUtils.toBuffer(amount, "le", 8),
185
- outputScript
186
- ])));
187
- return buffer_1.Buffer.concat([
188
- txoHash,
189
- base_1.BigIntBufferUtils.toBuffer(nonce, "be", 8),
190
- base_1.BigIntBufferUtils.toBuffer(BigInt(confirmations), "be", 2)
191
- ]);
192
- }
193
- ////////////////////////////////////////////
194
- //// Swap data getters
195
- /**
196
- * Gets the status of the specific swap, this also checks if we are offerer/claimer & checks for expiry (to see
197
- * if swap is refundable)
198
- *
199
- * @param signer
200
- * @param data
201
- */
202
- async getCommitStatus(signer, data) {
203
- const escrowHash = data.getEscrowHash();
204
- const stateData = await this.contract.getHashState("0x" + escrowHash);
205
- const state = Number(stateData.state);
206
- const blockHeight = Number(stateData.finishBlockheight);
207
- switch (state) {
208
- case ESCROW_STATE_COMMITTED:
209
- if (data.isOfferer(signer) && await this.isExpired(signer, data))
210
- return { type: base_1.SwapCommitStateType.REFUNDABLE };
211
- return { type: base_1.SwapCommitStateType.COMMITED };
212
- case ESCROW_STATE_CLAIMED:
213
- return {
214
- type: base_1.SwapCommitStateType.PAID,
215
- getTxBlock: async () => {
216
- return {
217
- blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
218
- blockHeight: blockHeight
219
- };
220
- },
221
- getClaimTxId: async () => {
222
- const events = await this.Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
223
- return events.length === 0 ? null : events[0].transactionHash;
224
- }
225
- };
226
- default:
227
- return {
228
- type: await this.isExpired(signer, data) ? base_1.SwapCommitStateType.EXPIRED : base_1.SwapCommitStateType.NOT_COMMITED,
229
- getTxBlock: async () => {
230
- return {
231
- blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
232
- blockHeight: blockHeight
233
- };
234
- },
235
- getRefundTxId: async () => {
236
- const events = await this.Events.getContractBlockEvents(["Refund"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
237
- return events.length === 0 ? null : events[0].transactionHash;
238
- }
239
- };
240
- }
241
- }
242
- /**
243
- * Returns the data committed for a specific payment hash, or null if no data is currently commited for
244
- * the specific swap
245
- *
246
- * @param paymentHashHex
247
- */
248
- async getCommitedData(paymentHashHex) {
249
- //TODO: Noop
250
- return null;
251
- }
252
- ////////////////////////////////////////////
253
- //// Swap data initializer
254
- createSwapData(type, offerer, claimer, token, amount, paymentHash, sequence, expiry, payIn, payOut, securityDeposit, claimerBounty, depositToken = this.Chain.Tokens.getNativeCurrencyAddress()) {
255
- return Promise.resolve(new EVMSwapData_1.EVMSwapData(offerer, claimer, token, this.timelockRefundHandler.address, this.claimHandlersBySwapType?.[type]?.address, payOut, payIn, payIn, //For now track reputation for all payIn swaps
256
- sequence, "0x" + paymentHash, (0, ethers_1.hexlify)(base_1.BigIntBufferUtils.toBuffer(expiry, "be", 32)), amount, depositToken, securityDeposit, claimerBounty, type, null));
257
- }
258
- ////////////////////////////////////////////
259
- //// Utils
260
- async getBalance(signer, tokenAddress, inContract) {
261
- if (inContract)
262
- return await this.getIntermediaryBalance(signer, tokenAddress);
263
- return await this.Chain.getBalance(signer, tokenAddress);
264
- }
265
- getIntermediaryData(address, token) {
266
- return this.LpVault.getIntermediaryData(address, token);
267
- }
268
- getIntermediaryReputation(address, token) {
269
- return this.LpVault.getIntermediaryReputation(address, token);
270
- }
271
- getIntermediaryBalance(address, token) {
272
- return this.LpVault.getIntermediaryBalance(address, token);
273
- }
274
- ////////////////////////////////////////////
275
- //// Transaction initializers
276
- async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
277
- return this.Claim.txsClaimWithSecret(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, secret, checkExpiry, feeRate);
278
- }
279
- async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, feeRate) {
280
- return this.Claim.txsClaimWithTxData(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate);
281
- }
282
- txsRefund(signer, swapData, check, initAta, feeRate) {
283
- return this.Refund.txsRefund(signer, swapData, check, feeRate);
284
- }
285
- txsRefundWithAuthorization(signer, swapData, { timeout, prefix, signature }, check, initAta, feeRate) {
286
- return this.Refund.txsRefundWithAuthorization(signer, swapData, timeout, prefix, signature, check, feeRate);
287
- }
288
- txsInit(signer, swapData, { timeout, prefix, signature }, skipChecks, feeRate) {
289
- return this.Init.txsInit(signer, swapData, timeout, prefix, signature, skipChecks, feeRate);
290
- }
291
- txsWithdraw(signer, token, amount, feeRate) {
292
- return this.LpVault.txsWithdraw(signer, token, amount, feeRate);
293
- }
294
- txsDeposit(signer, token, amount, feeRate) {
295
- return this.LpVault.txsDeposit(signer, token, amount, feeRate);
296
- }
297
- ////////////////////////////////////////////
298
- //// Executors
299
- async claimWithSecret(signer, swapData, secret, checkExpiry, initAta, txOptions) {
300
- const result = await this.Claim.txsClaimWithSecret(signer.getAddress(), swapData, secret, checkExpiry, txOptions?.feeRate);
301
- const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
302
- return signature;
303
- }
304
- async claimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, txOptions) {
305
- const txs = await this.Claim.txsClaimWithTxData(signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, txOptions?.feeRate);
306
- if (txs === null)
307
- throw new Error("Btc relay not synchronized to required blockheight!");
308
- const txHashes = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
309
- return txHashes[txHashes.length - 1];
310
- }
311
- async refund(signer, swapData, check, initAta, txOptions) {
312
- let result = await this.txsRefund(signer.getAddress(), swapData, check, initAta, txOptions?.feeRate);
313
- const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
314
- return signature;
315
- }
316
- async refundWithAuthorization(signer, swapData, signature, check, initAta, txOptions) {
317
- let result = await this.txsRefundWithAuthorization(signer.getAddress(), swapData, signature, check, initAta, txOptions?.feeRate);
318
- const [txSignature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
319
- return txSignature;
320
- }
321
- async init(signer, swapData, signature, skipChecks, txOptions) {
322
- if (swapData.isPayIn()) {
323
- if (!swapData.isOfferer(signer.getAddress()) && !swapData.isOfferer(signer.getAddress()))
324
- throw new Error("Invalid signer provided!");
325
- }
326
- else {
327
- if (!swapData.isClaimer(signer.getAddress()) && !swapData.isOfferer(signer.getAddress()))
328
- throw new Error("Invalid signer provided!");
329
- }
330
- let result = await this.txsInit(signer.getAddress(), swapData, signature, skipChecks, txOptions?.feeRate);
331
- const txHashes = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
332
- return txHashes[txHashes.length - 1];
333
- }
334
- async withdraw(signer, token, amount, txOptions) {
335
- const txs = await this.LpVault.txsWithdraw(signer.getAddress(), token, amount, txOptions?.feeRate);
336
- const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
337
- return txId;
338
- }
339
- async deposit(signer, token, amount, txOptions) {
340
- const txs = await this.LpVault.txsDeposit(signer.getAddress(), token, amount, txOptions?.feeRate);
341
- const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
342
- return txId;
343
- }
344
- ////////////////////////////////////////////
345
- //// Fees
346
- getInitPayInFeeRate(offerer, claimer, token, paymentHash) {
347
- return this.Chain.Fees.getFeeRate();
348
- }
349
- getInitFeeRate(offerer, claimer, token, paymentHash) {
350
- return this.Chain.Fees.getFeeRate();
351
- }
352
- getRefundFeeRate(swapData) {
353
- return this.Chain.Fees.getFeeRate();
354
- }
355
- getClaimFeeRate(signer, swapData) {
356
- return this.Chain.Fees.getFeeRate();
357
- }
358
- getClaimFee(signer, swapData, feeRate) {
359
- return this.Claim.getClaimFee(swapData, feeRate);
360
- }
361
- /**
362
- * Get the estimated fee of the commit transaction
363
- */
364
- getCommitFee(signer, swapData, feeRate) {
365
- return this.Init.getInitFee(swapData, feeRate);
366
- }
367
- /**
368
- * Get the estimated transaction fee of the refund transaction
369
- */
370
- getRefundFee(signer, swapData, feeRate) {
371
- return this.Refund.getRefundFee(swapData, feeRate);
372
- }
373
- }
374
- exports.EVMSwapContract = EVMSwapContract;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVMSwapContract = void 0;
4
+ const base_1 = require("@atomiqlabs/base");
5
+ const buffer_1 = require("buffer");
6
+ const TimelockRefundHandler_1 = require("./handlers/refund/TimelockRefundHandler");
7
+ const ClaimHandlers_1 = require("./handlers/claim/ClaimHandlers");
8
+ const sha2_1 = require("@noble/hashes/sha2");
9
+ const EVMContractBase_1 = require("../contract/EVMContractBase");
10
+ const EVMSwapData_1 = require("./EVMSwapData");
11
+ const EscrowManagerAbi_1 = require("./EscrowManagerAbi");
12
+ const ethers_1 = require("ethers");
13
+ const EVMLpVault_1 = require("./modules/EVMLpVault");
14
+ const EVMSwapInit_1 = require("./modules/EVMSwapInit");
15
+ const EVMSwapRefund_1 = require("./modules/EVMSwapRefund");
16
+ const EVMSwapClaim_1 = require("./modules/EVMSwapClaim");
17
+ const ESCROW_STATE_COMMITTED = 1;
18
+ const ESCROW_STATE_CLAIMED = 2;
19
+ const ESCROW_STATE_REFUNDED = 3;
20
+ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
21
+ constructor(chainInterface, btcRelay, contractAddress, handlerAddresses) {
22
+ super(chainInterface, contractAddress, EscrowManagerAbi_1.EscrowManagerAbi);
23
+ this.supportsInitWithoutClaimer = true;
24
+ ////////////////////////
25
+ //// Timeouts
26
+ this.claimWithSecretTimeout = 180;
27
+ this.claimWithTxDataTimeout = 180;
28
+ this.refundTimeout = 180;
29
+ this.claimGracePeriod = 10 * 60;
30
+ this.refundGracePeriod = 10 * 60;
31
+ this.authGracePeriod = 30;
32
+ ////////////////////////
33
+ //// Handlers
34
+ this.claimHandlersByAddress = {};
35
+ this.claimHandlersBySwapType = {};
36
+ this.refundHandlersByAddress = {};
37
+ this.chainId = chainInterface.chainId;
38
+ this.Init = new EVMSwapInit_1.EVMSwapInit(chainInterface, this);
39
+ this.Refund = new EVMSwapRefund_1.EVMSwapRefund(chainInterface, this);
40
+ this.Claim = new EVMSwapClaim_1.EVMSwapClaim(chainInterface, this);
41
+ this.LpVault = new EVMLpVault_1.EVMLpVault(chainInterface, this);
42
+ this.btcRelay = btcRelay;
43
+ ClaimHandlers_1.claimHandlersList.forEach(handlerCtor => {
44
+ const handler = new handlerCtor(handlerAddresses.claim[handlerCtor.type]);
45
+ this.claimHandlersByAddress[handler.address.toLowerCase()] = handler;
46
+ this.claimHandlersBySwapType[handlerCtor.type] = handler;
47
+ });
48
+ this.timelockRefundHandler = new TimelockRefundHandler_1.TimelockRefundHandler(handlerAddresses.refund.timelock);
49
+ this.refundHandlersByAddress[this.timelockRefundHandler.address.toLowerCase()] = this.timelockRefundHandler;
50
+ }
51
+ async start() {
52
+ }
53
+ ////////////////////////////////////////////
54
+ //// Signatures
55
+ preFetchForInitSignatureVerification() {
56
+ return this.Init.preFetchForInitSignatureVerification();
57
+ }
58
+ getInitSignature(signer, swapData, authorizationTimeout, preFetchedBlockData, feeRate) {
59
+ return this.Init.signSwapInitialization(signer, swapData, authorizationTimeout);
60
+ }
61
+ isValidInitAuthorization(sender, swapData, { timeout, prefix, signature }, feeRate, preFetchedData) {
62
+ return this.Init.isSignatureValid(sender, swapData, timeout, prefix, signature, preFetchedData);
63
+ }
64
+ getInitAuthorizationExpiry(swapData, { timeout, prefix, signature }, preFetchedData) {
65
+ return this.Init.getSignatureExpiry(timeout);
66
+ }
67
+ isInitAuthorizationExpired(swapData, { timeout, prefix, signature }) {
68
+ return this.Init.isSignatureExpired(timeout);
69
+ }
70
+ getRefundSignature(signer, swapData, authorizationTimeout) {
71
+ return this.Refund.signSwapRefund(signer, swapData, authorizationTimeout);
72
+ }
73
+ isValidRefundAuthorization(swapData, { timeout, prefix, signature }) {
74
+ return this.Refund.isSignatureValid(swapData, timeout, prefix, signature);
75
+ }
76
+ getDataSignature(signer, data) {
77
+ return this.Chain.Signatures.getDataSignature(signer, data);
78
+ }
79
+ isValidDataSignature(data, signature, publicKey) {
80
+ return this.Chain.Signatures.isValidDataSignature(data, signature, publicKey);
81
+ }
82
+ ////////////////////////////////////////////
83
+ //// Swap data utils
84
+ /**
85
+ * Checks whether the claim is claimable by us, that means not expired, we are claimer & the swap is commited
86
+ *
87
+ * @param signer
88
+ * @param data
89
+ */
90
+ async isClaimable(signer, data) {
91
+ if (!data.isClaimer(signer))
92
+ return false;
93
+ if (await this.isExpired(signer, data))
94
+ return false;
95
+ return await this.isCommited(data);
96
+ }
97
+ /**
98
+ * Checks whether a swap is commited, i.e. the swap still exists on-chain and was not claimed nor refunded
99
+ *
100
+ * @param swapData
101
+ */
102
+ async isCommited(swapData) {
103
+ const data = await this.contract.getHashState("0x" + swapData.getEscrowHash());
104
+ return Number(data.state) === ESCROW_STATE_COMMITTED;
105
+ }
106
+ /**
107
+ * Checks whether the swap is expired, takes into consideration possible on-chain time skew, therefore for claimer
108
+ * the swap expires a bit sooner than it should've & for the offerer it expires a bit later
109
+ *
110
+ * @param signer
111
+ * @param data
112
+ */
113
+ isExpired(signer, data) {
114
+ let currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
115
+ if (data.isClaimer(signer))
116
+ currentTimestamp = currentTimestamp + BigInt(this.claimGracePeriod);
117
+ if (data.isOfferer(signer))
118
+ currentTimestamp = currentTimestamp - BigInt(this.refundGracePeriod);
119
+ return Promise.resolve(data.getExpiry() < currentTimestamp);
120
+ }
121
+ /**
122
+ * Checks if the swap is refundable by us, checks if we are offerer, if the swap is already expired & if the swap
123
+ * is still commited
124
+ *
125
+ * @param signer
126
+ * @param data
127
+ */
128
+ async isRequestRefundable(signer, data) {
129
+ //Swap can only be refunded by the offerer
130
+ if (!data.isOfferer(signer))
131
+ return false;
132
+ if (!(await this.isExpired(signer, data)))
133
+ return false;
134
+ return await this.isCommited(data);
135
+ }
136
+ getHashForTxId(txId, confirmations) {
137
+ return buffer_1.Buffer.from(this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_TXID].getCommitment({
138
+ txId,
139
+ confirmations,
140
+ btcRelay: this.btcRelay
141
+ }).slice(2), "hex");
142
+ }
143
+ /**
144
+ * Get the swap payment hash to be used for an on-chain swap, uses poseidon hash of the value
145
+ *
146
+ * @param outputScript output script required to claim the swap
147
+ * @param amount sats sent required to claim the swap
148
+ * @param confirmations
149
+ * @param nonce swap nonce uniquely identifying the transaction to prevent replay attacks
150
+ */
151
+ getHashForOnchain(outputScript, amount, confirmations, nonce) {
152
+ let result;
153
+ if (nonce == null || nonce === 0n) {
154
+ result = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN].getCommitment({
155
+ output: outputScript,
156
+ amount,
157
+ confirmations,
158
+ btcRelay: this.btcRelay
159
+ });
160
+ }
161
+ else {
162
+ result = this.claimHandlersBySwapType[base_1.ChainSwapType.CHAIN_NONCED].getCommitment({
163
+ output: outputScript,
164
+ amount,
165
+ nonce,
166
+ confirmations,
167
+ btcRelay: this.btcRelay
168
+ });
169
+ }
170
+ return buffer_1.Buffer.from(result.slice(2), "hex");
171
+ }
172
+ /**
173
+ * Get the swap payment hash to be used for a lightning htlc swap, uses poseidon hash of the sha256 hash of the preimage
174
+ *
175
+ * @param paymentHash payment hash of the HTLC
176
+ */
177
+ getHashForHtlc(paymentHash) {
178
+ return buffer_1.Buffer.from(this.claimHandlersBySwapType[base_1.ChainSwapType.HTLC].getCommitment(paymentHash).slice(2), "hex");
179
+ }
180
+ getExtraData(outputScript, amount, confirmations, nonce) {
181
+ if (nonce == null)
182
+ nonce = 0n;
183
+ const txoHash = buffer_1.Buffer.from((0, sha2_1.sha256)(buffer_1.Buffer.concat([
184
+ base_1.BigIntBufferUtils.toBuffer(amount, "le", 8),
185
+ outputScript
186
+ ])));
187
+ return buffer_1.Buffer.concat([
188
+ txoHash,
189
+ base_1.BigIntBufferUtils.toBuffer(nonce, "be", 8),
190
+ base_1.BigIntBufferUtils.toBuffer(BigInt(confirmations), "be", 2)
191
+ ]);
192
+ }
193
+ ////////////////////////////////////////////
194
+ //// Swap data getters
195
+ /**
196
+ * Gets the status of the specific swap, this also checks if we are offerer/claimer & checks for expiry (to see
197
+ * if swap is refundable)
198
+ *
199
+ * @param signer
200
+ * @param data
201
+ */
202
+ async getCommitStatus(signer, data) {
203
+ const escrowHash = data.getEscrowHash();
204
+ const stateData = await this.contract.getHashState("0x" + escrowHash);
205
+ const state = Number(stateData.state);
206
+ const blockHeight = Number(stateData.finishBlockheight);
207
+ switch (state) {
208
+ case ESCROW_STATE_COMMITTED:
209
+ if (data.isOfferer(signer) && await this.isExpired(signer, data))
210
+ return { type: base_1.SwapCommitStateType.REFUNDABLE };
211
+ return { type: base_1.SwapCommitStateType.COMMITED };
212
+ case ESCROW_STATE_CLAIMED:
213
+ return {
214
+ type: base_1.SwapCommitStateType.PAID,
215
+ getTxBlock: async () => {
216
+ return {
217
+ blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
218
+ blockHeight: blockHeight
219
+ };
220
+ },
221
+ getClaimResult: async () => {
222
+ const events = await this.Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
223
+ return events.length === 0 ? null : events[0].args.witnessResult;
224
+ },
225
+ getClaimTxId: async () => {
226
+ const events = await this.Events.getContractBlockEvents(["Claim"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
227
+ return events.length === 0 ? null : events[0].transactionHash;
228
+ }
229
+ };
230
+ default:
231
+ return {
232
+ type: await this.isExpired(signer, data) ? base_1.SwapCommitStateType.EXPIRED : base_1.SwapCommitStateType.NOT_COMMITED,
233
+ getTxBlock: async () => {
234
+ return {
235
+ blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
236
+ blockHeight: blockHeight
237
+ };
238
+ },
239
+ getRefundTxId: async () => {
240
+ const events = await this.Events.getContractBlockEvents(["Refund"], [null, null, "0x" + escrowHash], blockHeight, blockHeight);
241
+ return events.length === 0 ? null : events[0].transactionHash;
242
+ }
243
+ };
244
+ }
245
+ }
246
+ /**
247
+ * Returns the data committed for a specific payment hash, or null if no data is currently commited for
248
+ * the specific swap
249
+ *
250
+ * @param paymentHashHex
251
+ */
252
+ async getCommitedData(paymentHashHex) {
253
+ //TODO: Noop
254
+ return null;
255
+ }
256
+ ////////////////////////////////////////////
257
+ //// Swap data initializer
258
+ createSwapData(type, offerer, claimer, token, amount, paymentHash, sequence, expiry, payIn, payOut, securityDeposit, claimerBounty, depositToken = this.Chain.Tokens.getNativeCurrencyAddress()) {
259
+ return Promise.resolve(new EVMSwapData_1.EVMSwapData(offerer, claimer, token, this.timelockRefundHandler.address, this.claimHandlersBySwapType?.[type]?.address, payOut, payIn, payIn, //For now track reputation for all payIn swaps
260
+ sequence, "0x" + paymentHash, (0, ethers_1.hexlify)(base_1.BigIntBufferUtils.toBuffer(expiry, "be", 32)), amount, depositToken, securityDeposit, claimerBounty, type, null));
261
+ }
262
+ ////////////////////////////////////////////
263
+ //// Utils
264
+ async getBalance(signer, tokenAddress, inContract) {
265
+ if (inContract)
266
+ return await this.getIntermediaryBalance(signer, tokenAddress);
267
+ return await this.Chain.getBalance(signer, tokenAddress);
268
+ }
269
+ getIntermediaryData(address, token) {
270
+ return this.LpVault.getIntermediaryData(address, token);
271
+ }
272
+ getIntermediaryReputation(address, token) {
273
+ return this.LpVault.getIntermediaryReputation(address, token);
274
+ }
275
+ getIntermediaryBalance(address, token) {
276
+ return this.LpVault.getIntermediaryBalance(address, token);
277
+ }
278
+ ////////////////////////////////////////////
279
+ //// Transaction initializers
280
+ async txsClaimWithSecret(signer, swapData, secret, checkExpiry, initAta, feeRate, skipAtaCheck) {
281
+ return this.Claim.txsClaimWithSecret(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, secret, checkExpiry, feeRate);
282
+ }
283
+ async txsClaimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, feeRate) {
284
+ return this.Claim.txsClaimWithTxData(typeof (signer) === "string" ? signer : signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, feeRate);
285
+ }
286
+ txsRefund(signer, swapData, check, initAta, feeRate) {
287
+ return this.Refund.txsRefund(signer, swapData, check, feeRate);
288
+ }
289
+ txsRefundWithAuthorization(signer, swapData, { timeout, prefix, signature }, check, initAta, feeRate) {
290
+ return this.Refund.txsRefundWithAuthorization(signer, swapData, timeout, prefix, signature, check, feeRate);
291
+ }
292
+ txsInit(signer, swapData, { timeout, prefix, signature }, skipChecks, feeRate) {
293
+ return this.Init.txsInit(signer, swapData, timeout, prefix, signature, skipChecks, feeRate);
294
+ }
295
+ txsWithdraw(signer, token, amount, feeRate) {
296
+ return this.LpVault.txsWithdraw(signer, token, amount, feeRate);
297
+ }
298
+ txsDeposit(signer, token, amount, feeRate) {
299
+ return this.LpVault.txsDeposit(signer, token, amount, feeRate);
300
+ }
301
+ ////////////////////////////////////////////
302
+ //// Executors
303
+ async claimWithSecret(signer, swapData, secret, checkExpiry, initAta, txOptions) {
304
+ const result = await this.Claim.txsClaimWithSecret(signer.getAddress(), swapData, secret, checkExpiry, txOptions?.feeRate);
305
+ const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
306
+ return signature;
307
+ }
308
+ async claimWithTxData(signer, swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, initAta, txOptions) {
309
+ const txs = await this.Claim.txsClaimWithTxData(signer.getAddress(), swapData, tx, requiredConfirmations, vout, commitedHeader, synchronizer, txOptions?.feeRate);
310
+ if (txs === null)
311
+ throw new Error("Btc relay not synchronized to required blockheight!");
312
+ const txHashes = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
313
+ return txHashes[txHashes.length - 1];
314
+ }
315
+ async refund(signer, swapData, check, initAta, txOptions) {
316
+ let result = await this.txsRefund(signer.getAddress(), swapData, check, initAta, txOptions?.feeRate);
317
+ const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
318
+ return signature;
319
+ }
320
+ async refundWithAuthorization(signer, swapData, signature, check, initAta, txOptions) {
321
+ let result = await this.txsRefundWithAuthorization(signer.getAddress(), swapData, signature, check, initAta, txOptions?.feeRate);
322
+ const [txSignature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
323
+ return txSignature;
324
+ }
325
+ async init(signer, swapData, signature, skipChecks, txOptions) {
326
+ if (swapData.isPayIn()) {
327
+ if (!swapData.isOfferer(signer.getAddress()) && !swapData.isOfferer(signer.getAddress()))
328
+ throw new Error("Invalid signer provided!");
329
+ }
330
+ else {
331
+ if (!swapData.isClaimer(signer.getAddress()) && !swapData.isOfferer(signer.getAddress()))
332
+ throw new Error("Invalid signer provided!");
333
+ }
334
+ let result = await this.txsInit(signer.getAddress(), swapData, signature, skipChecks, txOptions?.feeRate);
335
+ const txHashes = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
336
+ return txHashes[txHashes.length - 1];
337
+ }
338
+ async withdraw(signer, token, amount, txOptions) {
339
+ const txs = await this.LpVault.txsWithdraw(signer.getAddress(), token, amount, txOptions?.feeRate);
340
+ const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
341
+ return txId;
342
+ }
343
+ async deposit(signer, token, amount, txOptions) {
344
+ const txs = await this.LpVault.txsDeposit(signer.getAddress(), token, amount, txOptions?.feeRate);
345
+ const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
346
+ return txId;
347
+ }
348
+ ////////////////////////////////////////////
349
+ //// Fees
350
+ getInitPayInFeeRate(offerer, claimer, token, paymentHash) {
351
+ return this.Chain.Fees.getFeeRate();
352
+ }
353
+ getInitFeeRate(offerer, claimer, token, paymentHash) {
354
+ return this.Chain.Fees.getFeeRate();
355
+ }
356
+ getRefundFeeRate(swapData) {
357
+ return this.Chain.Fees.getFeeRate();
358
+ }
359
+ getClaimFeeRate(signer, swapData) {
360
+ return this.Chain.Fees.getFeeRate();
361
+ }
362
+ getClaimFee(signer, swapData, feeRate) {
363
+ return this.Claim.getClaimFee(swapData, feeRate);
364
+ }
365
+ /**
366
+ * Get the estimated fee of the commit transaction
367
+ */
368
+ getCommitFee(signer, swapData, feeRate) {
369
+ return this.Init.getInitFee(swapData, feeRate);
370
+ }
371
+ /**
372
+ * Get the estimated transaction fee of the refund transaction
373
+ */
374
+ getRefundFee(signer, swapData, feeRate) {
375
+ return this.Refund.getRefundFee(swapData, feeRate);
376
+ }
377
+ }
378
+ exports.EVMSwapContract = EVMSwapContract;