@atomiqlabs/base 10.0.0-dev.2 → 10.0.0-dev.21

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 (131) hide show
  1. package/LICENSE +201 -201
  2. package/dist/btc/BitcoinNetwork.d.ts +6 -6
  3. package/dist/btc/BitcoinNetwork.js +10 -10
  4. package/dist/btc/rpc/BitcoinRpc.d.ts +68 -68
  5. package/dist/btc/rpc/BitcoinRpc.js +2 -2
  6. package/dist/btcrelay/BtcRelay.d.ts +61 -61
  7. package/dist/btcrelay/BtcRelay.js +2 -2
  8. package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +18 -18
  9. package/dist/btcrelay/synchronizer/RelaySynchronizer.js +2 -2
  10. package/dist/btcrelay/types/BtcBlock.d.ts +13 -13
  11. package/dist/btcrelay/types/BtcBlock.js +2 -2
  12. package/dist/btcrelay/types/BtcHeader.d.ts +10 -10
  13. package/dist/btcrelay/types/BtcHeader.js +2 -2
  14. package/dist/btcrelay/types/BtcStoredHeader.d.ts +11 -11
  15. package/dist/btcrelay/types/BtcStoredHeader.js +2 -2
  16. package/dist/btcrelay/utils/StatePredictorUtils.d.ts +11 -11
  17. package/dist/btcrelay/utils/StatePredictorUtils.js +80 -80
  18. package/dist/chains/ChainData.d.ts +31 -31
  19. package/dist/chains/ChainData.js +2 -2
  20. package/dist/chains/ChainInterface.d.ts +133 -110
  21. package/dist/chains/ChainInterface.js +7 -2
  22. package/dist/chains/ChainType.d.ts +24 -23
  23. package/dist/chains/ChainType.js +2 -2
  24. package/dist/errors/CannotInitializeATAError.d.ts +3 -3
  25. package/dist/errors/CannotInitializeATAError.js +11 -11
  26. package/dist/errors/SignatureVerificationError.d.ts +3 -3
  27. package/dist/errors/SignatureVerificationError.js +11 -11
  28. package/dist/errors/SwapDataVerificationError.d.ts +3 -3
  29. package/dist/errors/SwapDataVerificationError.js +11 -11
  30. package/dist/errors/TransactionRevertedError.d.ts +3 -0
  31. package/dist/errors/TransactionRevertedError.js +11 -0
  32. package/dist/events/ChainEvents.d.ts +9 -9
  33. package/dist/events/ChainEvents.js +2 -2
  34. package/dist/events/types/ChainEvent.d.ts +7 -7
  35. package/dist/events/types/ChainEvent.js +6 -6
  36. package/dist/events/types/spv_vault/SpvVaultClaimEvent.d.ts +12 -12
  37. package/dist/events/types/spv_vault/SpvVaultClaimEvent.js +18 -18
  38. package/dist/events/types/spv_vault/SpvVaultCloseEvent.d.ts +7 -7
  39. package/dist/events/types/spv_vault/SpvVaultCloseEvent.js +13 -13
  40. package/dist/events/types/spv_vault/SpvVaultDepositEvent.d.ts +7 -7
  41. package/dist/events/types/spv_vault/SpvVaultDepositEvent.js +13 -13
  42. package/dist/events/types/spv_vault/SpvVaultEvent.d.ts +15 -15
  43. package/dist/events/types/spv_vault/SpvVaultEvent.js +20 -20
  44. package/dist/events/types/spv_vault/SpvVaultFrontEvent.d.ts +10 -10
  45. package/dist/events/types/spv_vault/SpvVaultFrontEvent.js +16 -16
  46. package/dist/events/types/spv_vault/SpvVaultOpenEvent.d.ts +7 -7
  47. package/dist/events/types/spv_vault/SpvVaultOpenEvent.js +13 -13
  48. package/dist/events/types/swap/ClaimEvent.d.ts +7 -7
  49. package/dist/events/types/swap/ClaimEvent.js +11 -11
  50. package/dist/events/types/swap/InitializeEvent.d.ts +9 -9
  51. package/dist/events/types/swap/InitializeEvent.js +12 -12
  52. package/dist/events/types/swap/RefundEvent.d.ts +5 -5
  53. package/dist/events/types/swap/RefundEvent.js +7 -7
  54. package/dist/events/types/swap/SwapEvent.d.ts +12 -12
  55. package/dist/events/types/swap/SwapEvent.js +17 -17
  56. package/dist/index.d.ts +42 -38
  57. package/dist/index.js +58 -54
  58. package/dist/lockable/Lockable.d.ts +6 -6
  59. package/dist/lockable/Lockable.js +28 -28
  60. package/dist/messaging/Messenger.d.ts +8 -0
  61. package/dist/messaging/Messenger.js +2 -0
  62. package/dist/messaging/messages/Message.d.ts +11 -0
  63. package/dist/messaging/messages/Message.js +22 -0
  64. package/dist/messaging/messages/SwapClaimWitnessMessage.d.ts +10 -0
  65. package/dist/messaging/messages/SwapClaimWitnessMessage.js +28 -0
  66. package/dist/spv_swap/SpvVaultContract.d.ts +258 -199
  67. package/dist/spv_swap/SpvVaultContract.js +2 -2
  68. package/dist/spv_swap/SpvVaultData.d.ts +35 -35
  69. package/dist/spv_swap/SpvVaultData.js +37 -37
  70. package/dist/spv_swap/SpvWithdrawalState.d.ts +31 -31
  71. package/dist/spv_swap/SpvWithdrawalState.js +10 -10
  72. package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +43 -43
  73. package/dist/spv_swap/SpvWithdrawalTransactionData.js +143 -143
  74. package/dist/storage/IStorageManager.d.ts +15 -15
  75. package/dist/storage/IStorageManager.js +2 -2
  76. package/dist/storage/StorageObject.d.ts +3 -3
  77. package/dist/storage/StorageObject.js +2 -2
  78. package/dist/swaps/ChainSwapType.d.ts +6 -6
  79. package/dist/swaps/ChainSwapType.js +10 -10
  80. package/dist/swaps/SwapCommitState.d.ts +39 -38
  81. package/dist/swaps/SwapCommitState.js +11 -11
  82. package/dist/swaps/SwapContract.d.ts +479 -467
  83. package/dist/swaps/SwapContract.js +2 -2
  84. package/dist/swaps/SwapData.d.ts +37 -36
  85. package/dist/swaps/SwapData.js +17 -14
  86. package/dist/utils/BigIntBufferUtils.d.ts +6 -6
  87. package/dist/utils/BigIntBufferUtils.js +31 -31
  88. package/package.json +31 -31
  89. package/src/btc/BitcoinNetwork.ts +6 -6
  90. package/src/btc/rpc/BitcoinRpc.ts +77 -77
  91. package/src/btcrelay/BtcRelay.ts +70 -70
  92. package/src/btcrelay/synchronizer/RelaySynchronizer.ts +17 -17
  93. package/src/btcrelay/types/BtcBlock.ts +15 -15
  94. package/src/btcrelay/types/BtcHeader.ts +11 -11
  95. package/src/btcrelay/types/BtcStoredHeader.ts +12 -12
  96. package/src/btcrelay/utils/StatePredictorUtils.ts +108 -108
  97. package/src/chains/ChainData.ts +40 -40
  98. package/src/chains/ChainInterface.ts +159 -132
  99. package/src/chains/ChainType.ts +40 -38
  100. package/src/errors/CannotInitializeATAError.ts +11 -11
  101. package/src/errors/SignatureVerificationError.ts +11 -11
  102. package/src/errors/SwapDataVerificationError.ts +11 -11
  103. package/src/errors/TransactionRevertedError.ts +11 -0
  104. package/src/events/ChainEvents.ts +13 -13
  105. package/src/events/types/ChainEvent.ts +10 -10
  106. package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +31 -31
  107. package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +17 -17
  108. package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +17 -17
  109. package/src/events/types/spv_vault/SpvVaultEvent.ts +25 -25
  110. package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +27 -27
  111. package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +16 -16
  112. package/src/events/types/swap/ClaimEvent.ts +15 -15
  113. package/src/events/types/swap/InitializeEvent.ts +18 -18
  114. package/src/events/types/swap/RefundEvent.ts +6 -6
  115. package/src/events/types/swap/SwapEvent.ts +21 -21
  116. package/src/index.ts +51 -46
  117. package/src/lockable/Lockable.ts +30 -30
  118. package/src/messaging/Messenger.ts +11 -0
  119. package/src/messaging/messages/Message.ts +25 -0
  120. package/src/messaging/messages/SwapClaimWitnessMessage.ts +34 -0
  121. package/src/spv_swap/SpvVaultContract.ts +269 -230
  122. package/src/spv_swap/SpvVaultData.ts +70 -70
  123. package/src/spv_swap/SpvWithdrawalState.ts +40 -40
  124. package/src/spv_swap/SpvWithdrawalTransactionData.ts +169 -169
  125. package/src/storage/IStorageManager.ts +16 -16
  126. package/src/storage/StorageObject.ts +6 -6
  127. package/src/swaps/ChainSwapType.ts +6 -6
  128. package/src/swaps/SwapCommitState.ts +40 -39
  129. package/src/swaps/SwapContract.ts +564 -556
  130. package/src/swaps/SwapData.ts +69 -65
  131. package/src/utils/BigIntBufferUtils.ts +31 -31
@@ -1,556 +1,564 @@
1
- import {SwapData} from "./SwapData";
2
- import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
3
- import {ChainSwapType} from "./ChainSwapType";
4
- import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
5
- import {Buffer} from "buffer";
6
- import {AbstractSigner, TransactionConfirmationOptions} from "../chains/ChainInterface";
7
- import {SwapCommitState} from "./SwapCommitState";
8
-
9
- export type IntermediaryReputationType = {
10
- [key in ChainSwapType]: {
11
- successVolume: bigint,
12
- successCount: bigint,
13
- failVolume: bigint,
14
- failCount: bigint,
15
- coopCloseVolume: bigint,
16
- coopCloseCount: bigint
17
- }
18
- };
19
-
20
- export type SignatureData = {
21
- prefix: string,
22
- timeout: string,
23
- signature: string
24
- };
25
-
26
- export type BitcoinTransactionData = {
27
- blockhash: string,
28
- confirmations: number,
29
- txid: string,
30
- hex: string,
31
- height: number
32
- };
33
-
34
- export interface SwapContract<
35
- T extends SwapData = SwapData,
36
- TX = any,
37
- PreFetchData = any,
38
- PreFetchVerification = any,
39
- Signer extends AbstractSigner = AbstractSigner,
40
- ChainId extends string = string
41
- > {
42
-
43
- readonly chainId: ChainId;
44
- readonly claimWithSecretTimeout: number;
45
- readonly claimWithTxDataTimeout: number;
46
- readonly refundTimeout: number;
47
-
48
- /**
49
- * Initializes the swap contract
50
- */
51
- start(): Promise<void>;
52
-
53
- /**
54
- * Signs & sends transactions for initializing a non-payIn swap (BTC -> SC)
55
- *
56
- * @param signer Signer to use for the transaction (must match claimer in swap data)
57
- * @param swapData Swap to init
58
- * @param signature Signature data from the offerer
59
- * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
60
- * @param txOptions Transaction options
61
- */
62
- init(signer: Signer, swapData: T, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
63
-
64
- /**
65
- * Returns the unsigned transactions required for initializing a non-payIn swap (BTC -> SC)
66
- *
67
- * @param sender Transaction sender address, must be either offerer or claimer
68
- * @param swapData Swap to init
69
- * @param signature Signature data from the offerer
70
- * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
71
- * @param feeRate Fee rate to use for the transaction
72
- */
73
- txsInit(sender: string, swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
74
-
75
- /**
76
- * Signs & sends transactions required for claiming an HTLC swap
77
- *
78
- * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
79
- * @param swapData Swap to claim
80
- * @param secret Secret pre-image that hashes to the swap hash
81
- * @param checkExpiry Whether to check expiration of the swap before executing transactions
82
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
83
- * @param txOptions Transaction options
84
- */
85
- claimWithSecret(signer: Signer, swapData: T, secret: string, checkExpiry?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
86
-
87
- /**
88
- * Returns the unsigned transactions required for claiming an HTLC swap
89
- *
90
- * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
91
- * @param swapData Swap to claim
92
- * @param secret Secret pre-image that hashes to the swap hash
93
- * @param checkExpiry Whether to check expiration of the swap before returning the transactions
94
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
95
- * @param feeRate Fee rate to use for the transactions
96
- * @param skipAtaCheck Whether to skip checking if token account exists
97
- */
98
- txsClaimWithSecret(signer: string | Signer, swapData: T, secret: string, checkExpiry?: boolean, initAta?: boolean, feeRate?: string, skipAtaCheck?: boolean): Promise<TX[]>;
99
-
100
- /**
101
- * Signs & sends transactions required for claiming an on-chain PTLC (proof-time locked contract) swap
102
- *
103
- * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
104
- * @param swapData Swap to claim
105
- * @param tx Bitcoin transaction containing the required output
106
- * @param requiredConfirmations Required confirmations for the escrow to be claimed
107
- * @param vout Bitcoin tx's output index of the required output
108
- * @param storedHeader Optional already retrieved stored header to use for proving
109
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
110
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
111
- * @param txOptions Transaction options
112
- */
113
- claimWithTxData(
114
- signer: Signer,
115
- swapData: T,
116
- tx: BitcoinTransactionData,
117
- requiredConfirmations: number,
118
- vout: number,
119
- storedHeader?: BtcStoredHeader<any>,
120
- synchronizer?: RelaySynchronizer<any, TX, any>,
121
- initAta?: boolean,
122
- txOptions?: TransactionConfirmationOptions
123
- ): Promise<string>;
124
-
125
- /**
126
- * Returns the unsigned transactions required for claiming an on-chain PTLC (proof-time locked contract) swap
127
- *
128
- * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
129
- * @param swapData Swap to claim
130
- * @param tx Bitcoin transaction containing the required output
131
- * @param requiredConfirmations Required confirmations for the escrow to be claimed
132
- * @param vout Bitcoin tx's output index of the required output
133
- * @param storedHeader Optional already retrieved stored header to use for proving
134
- * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
135
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
136
- * @param feeRate Fee rate to use for the transactions
137
- */
138
- txsClaimWithTxData(
139
- signer: string | Signer,
140
- swapData: T,
141
- tx: BitcoinTransactionData,
142
- requiredConfirmations: number,
143
- vout: number,
144
- storedHeader?: BtcStoredHeader<any>,
145
- synchronizer?: RelaySynchronizer<any, TX, any>,
146
- initAta?: boolean,
147
- feeRate?: string
148
- ): Promise<TX[]>;
149
-
150
- /**
151
- * Signs & sends transactions for refunding a timed out swap
152
- *
153
- * @param signer Signer to use for the transaction (must match offerer in swap data)
154
- * @param swapData Swap to refund
155
- * @param check Whether to check if the swap contract still exists on-chain
156
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
157
- * @param txOptions Transaction options
158
- */
159
- refund(signer: Signer, swapData: T, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
160
-
161
- /**
162
- * Returns the transactions for refunding a timed out swap
163
- *
164
- * @param signer Signer of the refund transaction
165
- * @param swapData Swap to refund
166
- * @param check Whether to check if the swap contract still exists on-chain
167
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
168
- * @param feeRate Fee rate to use for the transactions
169
- */
170
- txsRefund(signer: string, swapData: T, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
171
-
172
- /**
173
- * Signs & sends transactions for refunding a swap with a valid refund signature from the claimer
174
- *
175
- * @param signer Signer to use for the transaction (must match offerer in swap data)
176
- * @param swapData Swap to refund
177
- * @param signature Refund signature received from the claimer
178
- * @param check Whether to check if the swap contract still exists on-chain
179
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
180
- * @param txOptions Transaction options
181
- */
182
- refundWithAuthorization(signer: Signer, swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
183
-
184
- /**
185
- * Returns the transactions for refunding a swap with a valid refund signature from the claimer
186
- *
187
- * @param signer Signer of the refund transaction
188
- * @param swapData Swap to refund
189
- * @param signature Refund signature received from the claimer
190
- * @param check Whether to check if the swap contract still exists on-chain
191
- * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
192
- * @param feeRate Fee rate to use for the transactions
193
- */
194
- txsRefundWithAuthorization(signer: string, swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
195
-
196
- /**
197
- * Signs & sends transactions for initializing and instantly (upon init confirmation) claiming the HTLC, used for BTC-LN -> SC swaps
198
- *
199
- * @param signer Signer to use for the transaction (must match claimer in swap data)
200
- * @param swapData Swap to process
201
- * @param signature Signature data from the offerer
202
- * @param secret Secret pre-image that hashes to the swap hash
203
- * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
204
- * @param txOptions Transaction options
205
- */
206
- initAndClaimWithSecret?(signer: Signer, swapData: T, signature: SignatureData, secret: string, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string[]>;
207
-
208
- /**
209
- * Checks whether a swap is already expired, swap expires a bit sooner for the claimer & a bit later for offerer, this
210
- * is used to account for possible on-chain time skew
211
- *
212
- * @param signer Signer to use for checking the expiry
213
- * @param swapData Swap to check
214
- */
215
- isExpired(signer: string, swapData: T): Promise<boolean>;
216
-
217
- /**
218
- * Checks whether a swap is claimable for the signer, i.e. it is not expired yet and is committed on-chain
219
- *
220
- * @param signer
221
- * @param swapData
222
- */
223
- isClaimable(signer: string, swapData: T): Promise<boolean>;
224
-
225
- /**
226
- * Checks whether a given swap is committed on chain (initialized)
227
- *
228
- * @param swapData
229
- */
230
- isCommited(swapData: T): Promise<boolean>;
231
-
232
- /**
233
- * Returns the full status of the swap, expiry is handled by the isExpired function so also requires a signer/sender
234
- *
235
- * @param signer
236
- * @param swapData
237
- */
238
- getCommitStatus(signer: string, swapData: T): Promise<SwapCommitState>;
239
-
240
- /**
241
- * Checks whether a given swap is refundable by us, i.e. it is already expired, we are offerer & swap is committed on-chain
242
- *
243
- * @param signer
244
- * @param swapData
245
- */
246
- isRequestRefundable(signer: string, swapData: T): Promise<boolean>;
247
-
248
- /**
249
- * Pre-fetches data required for creating init signature
250
- */
251
- preFetchBlockDataForSignatures?(): Promise<PreFetchData>;
252
-
253
- /**
254
- * Pre-fetches data required for init signature verification
255
- * @param data
256
- */
257
- preFetchForInitSignatureVerification?(data: PreFetchData): Promise<PreFetchVerification>;
258
-
259
- /**
260
- * Generates the initialization signature
261
- *
262
- * @param signer Signer to use for signing the message
263
- * @param swapData Swap to sign
264
- * @param authorizationTimeout Timeout of the authorization
265
- * @param preFetchedBlockData Optional pre-fetched data required for creating the signature
266
- * @param feeRate Optional fee rate to use for the authorization
267
- */
268
- getInitSignature(signer: Signer, swapData: T, authorizationTimeout: number, preFetchedBlockData?: PreFetchData, feeRate?: string): Promise<SignatureData>;
269
-
270
- /**
271
- * Checks whether a signature is a valid initialization signature for a given swap
272
- *
273
- * @param sender Address of the sender of the transaction (must be either offerer or claimer)
274
- * @param swapData Swap to initialize
275
- * @param signature Signature data
276
- * @param feeRate Fee rate used for the authorization
277
- * @param preFetchedVerificationData Optional pre-fetched data required for signature validation
278
- * @returns {Buffer | null} The message being signed if valid or null if invalid signature
279
- */
280
- isValidInitAuthorization(sender: string, swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
281
-
282
- /**
283
- * Returns the expiry timestamp (UNIX milliseconds) of the authorization
284
- *
285
- * @param swapData Swap
286
- * @param signature Signature data
287
- * @param preFetchedVerificationData Optional pre-fetched data required for signature validation
288
- */
289
- getInitAuthorizationExpiry(swapData: T, signature: SignatureData, preFetchedVerificationData?: PreFetchVerification): Promise<number>;
290
-
291
- /**
292
- * Checks whether a given init signature is already expired
293
- *
294
- * @param swapData Swap
295
- * @param signature Signature data
296
- */
297
- isInitAuthorizationExpired(swapData: T, signature: SignatureData): Promise<boolean>;
298
-
299
- /**
300
- * Generates the refund signature for a given swap allowing the offerer to refund before expiration
301
- *
302
- * @param signer Signer to use for signing the message (must be the same as offerer in swap data)
303
- * @param swapData Swap to refund
304
- * @param authorizationTimeout Timeout of the provided refund authorization
305
- */
306
- getRefundSignature(signer: Signer, swapData: T, authorizationTimeout: number): Promise<SignatureData>;
307
-
308
- /**
309
- * Checks whether a given refund signature is valid
310
- *
311
- * @param swapData Swap to refund
312
- * @param signature Signature received from the claimer
313
- */
314
- isValidRefundAuthorization(swapData: T, signature: SignatureData): Promise<Buffer | null>;
315
-
316
- /**
317
- * Signs the given data with the provided signer
318
- *
319
- * @param signer Signer to sign the message
320
- * @param data Data to sign
321
- */
322
- getDataSignature(signer: Signer, data: Buffer): Promise<string>;
323
-
324
- /**
325
- * Checks whether a provided data is signature is valid
326
- *
327
- * @param data Data to sign
328
- * @param signature Signature
329
- * @param publicKey Public key of the signer
330
- */
331
- isValidDataSignature(data: Buffer, signature: string, publicKey: string): Promise<boolean>;
332
-
333
- /**
334
- * Returns the token balance of a given signer's address
335
- *
336
- * @param signer Address to check the balance of
337
- * @param token Token
338
- * @param inContract Whether we are checking the liquidity deposited into the LP vault or just on-chain balance
339
- */
340
- getBalance(signer: string, token: string, inContract: boolean): Promise<bigint>;
341
-
342
- /**
343
- * Create a swap data for this given chain
344
- *
345
- * @param type Type of the swap
346
- * @param offerer Offerer address
347
- * @param claimer Claimer addres
348
- * @param token Token to use for the swap
349
- * @param amount Amount of tokens for the swap
350
- * @param paymentHash Payment hash identifying the swap
351
- * @param sequence Swap sequence uniquelly defining this swap
352
- * @param expiry Expiration of the swap
353
- * @param payIn Whether the swap is payIn (offerer paying to the contract, or not payIn offerer using funds in his LP vault)
354
- * @param payOut Whether the swap is payOut (claimer getting the funds to his on-chain address, or no payOut claimer
355
- * getting his funds into his LP vault)
356
- * @param securityDeposit Security deposit for the swap paid by the claimer (options premium)
357
- * @param claimerBounty Bounty for the claimer of the swap (used for watchtowers)
358
- * @param depositToken Token to be used for security deposit and claimer bounty
359
- */
360
- createSwapData(
361
- type: ChainSwapType,
362
- offerer: string,
363
- claimer: string,
364
- token: string,
365
- amount: bigint,
366
- paymentHash: string,
367
- sequence: bigint,
368
- expiry: bigint,
369
- payIn: boolean,
370
- payOut: boolean,
371
- securityDeposit: bigint,
372
- claimerBounty: bigint,
373
- depositToken?: string
374
- ): Promise<T>;
375
-
376
- /**
377
- * Returns intermediary's reputation for a given token swaps
378
- *
379
- * @param address
380
- * @param token
381
- */
382
- getIntermediaryReputation(address: string, token: string): Promise<IntermediaryReputationType>;
383
-
384
- /**
385
- * Returns the fee in native token base units to commit (initiate) the swap
386
- *
387
- * @param signer
388
- * @param swapData Swap to initiate
389
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
390
- */
391
- getCommitFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
392
-
393
- /**
394
- * Returns raw fee (not including any account deposits we might need) for initiating the swap
395
- *
396
- * @param signer
397
- * @param swapData Swap to initiate
398
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
399
- */
400
- getRawCommitFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
401
-
402
- /**
403
- * Returns the fee in native token base units to claim the swap
404
- *
405
- * @param signer Signer claiming the swap
406
- * @param swapData Swap to claim
407
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
408
- */
409
- getClaimFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
410
-
411
- /**
412
- * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
413
- *
414
- * @param signer Signer claiming the swap
415
- * @param swapData Swap to claim
416
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
417
- */
418
- getRawClaimFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
419
-
420
- /**
421
- * Returns the fee in native token base units to refund the swap
422
- *
423
- * @param signer
424
- * @param swapData Swap to refund
425
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
426
- */
427
- getRefundFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
428
-
429
- /**
430
- * Returns raw fee (not including any refunds we might get that would make the getRefundFee negative) for claiming the swap
431
- *
432
- * @param signer
433
- * @param swapData Swap to claim
434
- * @param feeRate Optional fee rate (fetched on-demand if not provided)
435
- */
436
- getRawRefundFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
437
-
438
- /**
439
- * Returns the fee rate for committing (initializing) a payIn swap
440
- *
441
- * @param offerer Offerer of the swap
442
- * @param claimer Claimer of the swap
443
- * @param token Token to be swapped
444
- * @param paymentHash Optional payment hash
445
- */
446
- getInitPayInFeeRate(offerer: string, claimer: string, token: string, paymentHash?: string): Promise<string>;
447
-
448
- /**
449
- * Returns the fee rate for committing (initializing) a non-payIn swap
450
- *
451
- * @param offerer Offerer of the swap
452
- * @param claimer Claimer of the swap
453
- * @param token Token to be swapped
454
- * @param paymentHash Optional payment hash
455
- */
456
- getInitFeeRate(offerer: string, claimer: string, token: string, paymentHash?: string): Promise<string>;
457
-
458
- /**
459
- * Returns the fee rate for refunding a swap
460
- *
461
- * @param swapData Swap to refund
462
- */
463
- getRefundFeeRate(swapData: T): Promise<string>;
464
-
465
- /**
466
- * Returns the fee rate for claiming a swap as a specific signer
467
- *
468
- * @param signer Signer claiming the swap
469
- * @param swapData Swap to claim
470
- */
471
- getClaimFeeRate(signer: string, swapData: T): Promise<string>;
472
-
473
- getExtraData(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
474
-
475
- /**
476
- * Compute the claim hash for a given transaction output, either nonced or just output locked
477
- *
478
- * @param outputScript Bitcoin output locking script
479
- * @param amount Amount of sats in the output
480
- * @param confirmations Required number of confirmations for the swap to be claimable
481
- * @param nonce Nonce to be used as replay protection
482
- */
483
- getHashForOnchain(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
484
-
485
- /**
486
- * Compute the claim hash for a given transaction id
487
- *
488
- * @param txId Bitcoin transaction ID
489
- * @param confirmations Required number of confirmations for the swap to be claimable
490
- */
491
- getHashForTxId(txId: string, confirmations: number): Buffer;
492
-
493
- /**
494
- * Compute the claim hash for an HTLC swap with a given swap hash
495
- *
496
- * @param swapHash
497
- */
498
- getHashForHtlc(swapHash: Buffer): Buffer;
499
-
500
- /**
501
- * Withdraws funds from the trading LP vault
502
- *
503
- * @param signer Signer to sign the withdrawal with
504
- * @param token Token to withdraw
505
- * @param amount Amount of the token to withdraw
506
- * @param txOptions Transaction options
507
- */
508
- withdraw(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
509
-
510
- /**
511
- * Returns transactions required for signer to withdraw funds from the trading LP vault
512
- *
513
- * @param signer Owner of the funds
514
- * @param token Token to withdraw
515
- * @param amount Amount of the token to withdraw
516
- * @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
517
- */
518
- txsWithdraw(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
519
-
520
- /**
521
- * Deposits funds to the trading LP vault
522
- *
523
- * @param signer Signer to sign the deposit with
524
- * @param token Token to deposit
525
- * @param amount Amount of the token to deposit
526
- * @param txOptions Transaction options
527
- */
528
- deposit(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
529
-
530
- /**
531
- * Returns transactions required for signer to deposit funds to the trading LP vault
532
- *
533
- * @param signer Owner of the funds
534
- * @param token Token to deposit
535
- * @param amount Amount of the token to deposit
536
- * @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
537
- */
538
- txsDeposit(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
539
-
540
- /**
541
- * Returns the amount of deposits (in native token) that we can claim back (this is useful for SVM chains with the PDAs
542
- * requiring you to put some deposit in order to store data)
543
- *
544
- * @param signer Signer to check the claimable deposits for
545
- */
546
- getClaimableDeposits?(signer: string): Promise<{count: number, totalValue: bigint}>;
547
-
548
- /**
549
- * Claims the funds from claimable deposits
550
- *
551
- * @param signer Owner of the deposits, transaction signer
552
- * @param txOptions Transaction options
553
- */
554
- claimDeposits?(signer: Signer, txOptions: TransactionConfirmationOptions): Promise<{txIds: string[], count: number, totalValue: bigint}>;
555
-
556
- }
1
+ import {SwapData} from "./SwapData";
2
+ import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
3
+ import {ChainSwapType} from "./ChainSwapType";
4
+ import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
5
+ import {Buffer} from "buffer";
6
+ import {AbstractSigner, TransactionConfirmationOptions} from "../chains/ChainInterface";
7
+ import {SwapCommitState} from "./SwapCommitState";
8
+
9
+ export type IntermediaryReputationType = {
10
+ [key in ChainSwapType]: {
11
+ successVolume: bigint,
12
+ successCount: bigint,
13
+ failVolume: bigint,
14
+ failCount: bigint,
15
+ coopCloseVolume: bigint,
16
+ coopCloseCount: bigint
17
+ }
18
+ };
19
+
20
+ export type SignatureData = {
21
+ prefix: string,
22
+ timeout: string,
23
+ signature: string
24
+ };
25
+
26
+ export type BitcoinTransactionData = {
27
+ blockhash: string,
28
+ confirmations: number,
29
+ txid: string,
30
+ hex: string,
31
+ height: number
32
+ };
33
+
34
+ export interface SwapContract<
35
+ T extends SwapData = SwapData,
36
+ TX = any,
37
+ PreFetchData = any,
38
+ PreFetchVerification = any,
39
+ Signer extends AbstractSigner = AbstractSigner,
40
+ ChainId extends string = string
41
+ > {
42
+
43
+ readonly chainId: ChainId;
44
+ readonly claimWithSecretTimeout: number;
45
+ readonly claimWithTxDataTimeout: number;
46
+ readonly refundTimeout: number;
47
+ readonly supportsInitWithoutClaimer?: boolean;
48
+
49
+ /**
50
+ * Initializes the swap contract
51
+ */
52
+ start(): Promise<void>;
53
+
54
+ /**
55
+ * Signs & sends transactions for initializing a non-payIn swap (BTC -> SC)
56
+ *
57
+ * @param signer Signer to use for the transaction (must match claimer in swap data)
58
+ * @param swapData Swap to init
59
+ * @param signature Signature data from the offerer
60
+ * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
61
+ * @param txOptions Transaction options
62
+ */
63
+ init(signer: Signer, swapData: T, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
64
+
65
+ /**
66
+ * Returns the unsigned transactions required for initializing a non-payIn swap (BTC -> SC)
67
+ *
68
+ * @param sender Transaction sender address, must be either offerer or claimer
69
+ * @param swapData Swap to init
70
+ * @param signature Signature data from the offerer
71
+ * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
72
+ * @param feeRate Fee rate to use for the transaction
73
+ */
74
+ txsInit(sender: string, swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
75
+
76
+ /**
77
+ * Signs & sends transactions required for claiming an HTLC swap
78
+ *
79
+ * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
80
+ * @param swapData Swap to claim
81
+ * @param secret Secret pre-image that hashes to the swap hash
82
+ * @param checkExpiry Whether to check expiration of the swap before executing transactions
83
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
84
+ * @param txOptions Transaction options
85
+ */
86
+ claimWithSecret(signer: Signer, swapData: T, secret: string, checkExpiry?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
87
+
88
+ /**
89
+ * Returns the unsigned transactions required for claiming an HTLC swap
90
+ *
91
+ * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
92
+ * @param swapData Swap to claim
93
+ * @param secret Secret pre-image that hashes to the swap hash
94
+ * @param checkExpiry Whether to check expiration of the swap before returning the transactions
95
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
96
+ * @param feeRate Fee rate to use for the transactions
97
+ * @param skipAtaCheck Whether to skip checking if token account exists
98
+ */
99
+ txsClaimWithSecret(signer: string | Signer, swapData: T, secret: string, checkExpiry?: boolean, initAta?: boolean, feeRate?: string, skipAtaCheck?: boolean): Promise<TX[]>;
100
+
101
+ /**
102
+ * Signs & sends transactions required for claiming an on-chain PTLC (proof-time locked contract) swap
103
+ *
104
+ * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
105
+ * @param swapData Swap to claim
106
+ * @param tx Bitcoin transaction containing the required output
107
+ * @param requiredConfirmations Required confirmations for the escrow to be claimed
108
+ * @param vout Bitcoin tx's output index of the required output
109
+ * @param storedHeader Optional already retrieved stored header to use for proving
110
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
111
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
112
+ * @param txOptions Transaction options
113
+ */
114
+ claimWithTxData(
115
+ signer: Signer,
116
+ swapData: T,
117
+ tx: BitcoinTransactionData,
118
+ requiredConfirmations: number,
119
+ vout: number,
120
+ storedHeader?: BtcStoredHeader<any>,
121
+ synchronizer?: RelaySynchronizer<any, TX, any>,
122
+ initAta?: boolean,
123
+ txOptions?: TransactionConfirmationOptions
124
+ ): Promise<string>;
125
+
126
+ /**
127
+ * Returns the unsigned transactions required for claiming an on-chain PTLC (proof-time locked contract) swap
128
+ *
129
+ * @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
130
+ * @param swapData Swap to claim
131
+ * @param tx Bitcoin transaction containing the required output
132
+ * @param requiredConfirmations Required confirmations for the escrow to be claimed
133
+ * @param vout Bitcoin tx's output index of the required output
134
+ * @param storedHeader Optional already retrieved stored header to use for proving
135
+ * @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
136
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
137
+ * @param feeRate Fee rate to use for the transactions
138
+ */
139
+ txsClaimWithTxData(
140
+ signer: string | Signer,
141
+ swapData: T,
142
+ tx: BitcoinTransactionData,
143
+ requiredConfirmations: number,
144
+ vout: number,
145
+ storedHeader?: BtcStoredHeader<any>,
146
+ synchronizer?: RelaySynchronizer<any, TX, any>,
147
+ initAta?: boolean,
148
+ feeRate?: string
149
+ ): Promise<TX[]>;
150
+
151
+ /**
152
+ * Signs & sends transactions for refunding a timed out swap
153
+ *
154
+ * @param signer Signer to use for the transaction (must match offerer in swap data)
155
+ * @param swapData Swap to refund
156
+ * @param check Whether to check if the swap contract still exists on-chain
157
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
158
+ * @param txOptions Transaction options
159
+ */
160
+ refund(signer: Signer, swapData: T, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
161
+
162
+ /**
163
+ * Returns the transactions for refunding a timed out swap
164
+ *
165
+ * @param signer Signer of the refund transaction
166
+ * @param swapData Swap to refund
167
+ * @param check Whether to check if the swap contract still exists on-chain
168
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
169
+ * @param feeRate Fee rate to use for the transactions
170
+ */
171
+ txsRefund(signer: string, swapData: T, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
172
+
173
+ /**
174
+ * Signs & sends transactions for refunding a swap with a valid refund signature from the claimer
175
+ *
176
+ * @param signer Signer to use for the transaction (must match offerer in swap data)
177
+ * @param swapData Swap to refund
178
+ * @param signature Refund signature received from the claimer
179
+ * @param check Whether to check if the swap contract still exists on-chain
180
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
181
+ * @param txOptions Transaction options
182
+ */
183
+ refundWithAuthorization(signer: Signer, swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
184
+
185
+ /**
186
+ * Returns the transactions for refunding a swap with a valid refund signature from the claimer
187
+ *
188
+ * @param signer Signer of the refund transaction
189
+ * @param swapData Swap to refund
190
+ * @param signature Refund signature received from the claimer
191
+ * @param check Whether to check if the swap contract still exists on-chain
192
+ * @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
193
+ * @param feeRate Fee rate to use for the transactions
194
+ */
195
+ txsRefundWithAuthorization(signer: string, swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
196
+
197
+ /**
198
+ * Signs & sends transactions for initializing and instantly (upon init confirmation) claiming the HTLC, used for BTC-LN -> SC swaps
199
+ *
200
+ * @param signer Signer to use for the transaction (must match claimer in swap data)
201
+ * @param swapData Swap to process
202
+ * @param signature Signature data from the offerer
203
+ * @param secret Secret pre-image that hashes to the swap hash
204
+ * @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
205
+ * @param txOptions Transaction options
206
+ */
207
+ initAndClaimWithSecret?(signer: Signer, swapData: T, signature: SignatureData, secret: string, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string[]>;
208
+
209
+ /**
210
+ * Checks whether a swap is already expired, swap expires a bit sooner for the claimer & a bit later for offerer, this
211
+ * is used to account for possible on-chain time skew
212
+ *
213
+ * @param signer Signer to use for checking the expiry
214
+ * @param swapData Swap to check
215
+ */
216
+ isExpired(signer: string, swapData: T): Promise<boolean>;
217
+
218
+ /**
219
+ * Checks whether a swap is claimable for the signer, i.e. it is not expired yet and is committed on-chain
220
+ *
221
+ * @param signer
222
+ * @param swapData
223
+ */
224
+ isClaimable(signer: string, swapData: T): Promise<boolean>;
225
+
226
+ /**
227
+ * Checks whether a given swap is committed on chain (initialized)
228
+ *
229
+ * @param swapData
230
+ */
231
+ isCommited(swapData: T): Promise<boolean>;
232
+
233
+ /**
234
+ * Returns the full status of the swap, expiry is handled by the isExpired function so also requires a signer/sender
235
+ *
236
+ * @param signer
237
+ * @param swapData
238
+ */
239
+ getCommitStatus(signer: string, swapData: T): Promise<SwapCommitState>;
240
+
241
+ /**
242
+ * Returns the full status of the passed swaps, expiry is handled by the isExpired function so also requires a signer/sender
243
+ *
244
+ * @param request
245
+ */
246
+ getCommitStatuses(request: {signer: string, swapData: T}[]): Promise<{[escrowHash: string]: SwapCommitState}>;
247
+
248
+ /**
249
+ * Checks whether a given swap is refundable by us, i.e. it is already expired, we are offerer & swap is committed on-chain
250
+ *
251
+ * @param signer
252
+ * @param swapData
253
+ */
254
+ isRequestRefundable(signer: string, swapData: T): Promise<boolean>;
255
+
256
+ /**
257
+ * Pre-fetches data required for creating init signature
258
+ */
259
+ preFetchBlockDataForSignatures?(): Promise<PreFetchData>;
260
+
261
+ /**
262
+ * Pre-fetches data required for init signature verification
263
+ * @param data
264
+ */
265
+ preFetchForInitSignatureVerification?(data: PreFetchData): Promise<PreFetchVerification>;
266
+
267
+ /**
268
+ * Generates the initialization signature
269
+ *
270
+ * @param signer Signer to use for signing the message
271
+ * @param swapData Swap to sign
272
+ * @param authorizationTimeout Timeout of the authorization
273
+ * @param preFetchedBlockData Optional pre-fetched data required for creating the signature
274
+ * @param feeRate Optional fee rate to use for the authorization
275
+ */
276
+ getInitSignature(signer: Signer, swapData: T, authorizationTimeout: number, preFetchedBlockData?: PreFetchData, feeRate?: string): Promise<SignatureData>;
277
+
278
+ /**
279
+ * Checks whether a signature is a valid initialization signature for a given swap
280
+ *
281
+ * @param sender Address of the sender of the transaction (must be either offerer or claimer)
282
+ * @param swapData Swap to initialize
283
+ * @param signature Signature data
284
+ * @param feeRate Fee rate used for the authorization
285
+ * @param preFetchedVerificationData Optional pre-fetched data required for signature validation
286
+ * @returns {Buffer | null} The message being signed if valid or null if invalid signature
287
+ */
288
+ isValidInitAuthorization(sender: string, swapData: T, signature: SignatureData, feeRate?: string, preFetchedVerificationData?: PreFetchVerification): Promise<Buffer | null>;
289
+
290
+ /**
291
+ * Returns the expiry timestamp (UNIX milliseconds) of the authorization
292
+ *
293
+ * @param swapData Swap
294
+ * @param signature Signature data
295
+ * @param preFetchedVerificationData Optional pre-fetched data required for signature validation
296
+ */
297
+ getInitAuthorizationExpiry(swapData: T, signature: SignatureData, preFetchedVerificationData?: PreFetchVerification): Promise<number>;
298
+
299
+ /**
300
+ * Checks whether a given init signature is already expired
301
+ *
302
+ * @param swapData Swap
303
+ * @param signature Signature data
304
+ */
305
+ isInitAuthorizationExpired(swapData: T, signature: SignatureData): Promise<boolean>;
306
+
307
+ /**
308
+ * Generates the refund signature for a given swap allowing the offerer to refund before expiration
309
+ *
310
+ * @param signer Signer to use for signing the message (must be the same as offerer in swap data)
311
+ * @param swapData Swap to refund
312
+ * @param authorizationTimeout Timeout of the provided refund authorization
313
+ */
314
+ getRefundSignature(signer: Signer, swapData: T, authorizationTimeout: number): Promise<SignatureData>;
315
+
316
+ /**
317
+ * Checks whether a given refund signature is valid
318
+ *
319
+ * @param swapData Swap to refund
320
+ * @param signature Signature received from the claimer
321
+ */
322
+ isValidRefundAuthorization(swapData: T, signature: SignatureData): Promise<Buffer | null>;
323
+
324
+ /**
325
+ * Signs the given data with the provided signer
326
+ *
327
+ * @param signer Signer to sign the message
328
+ * @param data Data to sign
329
+ */
330
+ getDataSignature(signer: Signer, data: Buffer): Promise<string>;
331
+
332
+ /**
333
+ * Checks whether a provided data is signature is valid
334
+ *
335
+ * @param data Data to sign
336
+ * @param signature Signature
337
+ * @param publicKey Public key of the signer
338
+ */
339
+ isValidDataSignature(data: Buffer, signature: string, publicKey: string): Promise<boolean>;
340
+
341
+ /**
342
+ * Returns the token balance of a given signer's address
343
+ *
344
+ * @param signer Address to check the balance of
345
+ * @param token Token
346
+ * @param inContract Whether we are checking the liquidity deposited into the LP vault or just on-chain balance
347
+ */
348
+ getBalance(signer: string, token: string, inContract: boolean): Promise<bigint>;
349
+
350
+ /**
351
+ * Create a swap data for this given chain
352
+ *
353
+ * @param type Type of the swap
354
+ * @param offerer Offerer address
355
+ * @param claimer Claimer addres
356
+ * @param token Token to use for the swap
357
+ * @param amount Amount of tokens for the swap
358
+ * @param paymentHash Payment hash identifying the swap
359
+ * @param sequence Swap sequence uniquelly defining this swap
360
+ * @param expiry Expiration of the swap
361
+ * @param payIn Whether the swap is payIn (offerer paying to the contract, or not payIn offerer using funds in his LP vault)
362
+ * @param payOut Whether the swap is payOut (claimer getting the funds to his on-chain address, or no payOut claimer
363
+ * getting his funds into his LP vault)
364
+ * @param securityDeposit Security deposit for the swap paid by the claimer (options premium)
365
+ * @param claimerBounty Bounty for the claimer of the swap (used for watchtowers)
366
+ * @param depositToken Token to be used for security deposit and claimer bounty
367
+ */
368
+ createSwapData(
369
+ type: ChainSwapType,
370
+ offerer: string,
371
+ claimer: string,
372
+ token: string,
373
+ amount: bigint,
374
+ paymentHash: string,
375
+ sequence: bigint,
376
+ expiry: bigint,
377
+ payIn: boolean,
378
+ payOut: boolean,
379
+ securityDeposit: bigint,
380
+ claimerBounty: bigint,
381
+ depositToken?: string
382
+ ): Promise<T>;
383
+
384
+ /**
385
+ * Returns intermediary's reputation for a given token swaps
386
+ *
387
+ * @param address
388
+ * @param token
389
+ */
390
+ getIntermediaryReputation(address: string, token: string): Promise<IntermediaryReputationType>;
391
+
392
+ /**
393
+ * Returns the fee in native token base units to commit (initiate) the swap
394
+ *
395
+ * @param signer
396
+ * @param swapData Swap to initiate
397
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
398
+ */
399
+ getCommitFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
400
+
401
+ /**
402
+ * Returns raw fee (not including any account deposits we might need) for initiating the swap
403
+ *
404
+ * @param signer
405
+ * @param swapData Swap to initiate
406
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
407
+ */
408
+ getRawCommitFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
409
+
410
+ /**
411
+ * Returns the fee in native token base units to claim the swap
412
+ *
413
+ * @param signer Signer claiming the swap
414
+ * @param swapData Swap to claim
415
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
416
+ */
417
+ getClaimFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
418
+
419
+ /**
420
+ * Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
421
+ *
422
+ * @param signer Signer claiming the swap
423
+ * @param swapData Swap to claim
424
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
425
+ */
426
+ getRawClaimFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
427
+
428
+ /**
429
+ * Returns the fee in native token base units to refund the swap
430
+ *
431
+ * @param signer
432
+ * @param swapData Swap to refund
433
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
434
+ */
435
+ getRefundFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
436
+
437
+ /**
438
+ * Returns raw fee (not including any refunds we might get that would make the getRefundFee negative) for claiming the swap
439
+ *
440
+ * @param signer
441
+ * @param swapData Swap to claim
442
+ * @param feeRate Optional fee rate (fetched on-demand if not provided)
443
+ */
444
+ getRawRefundFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
445
+
446
+ /**
447
+ * Returns the fee rate for committing (initializing) a payIn swap
448
+ *
449
+ * @param offerer Offerer of the swap
450
+ * @param claimer Claimer of the swap
451
+ * @param token Token to be swapped
452
+ * @param paymentHash Optional payment hash
453
+ */
454
+ getInitPayInFeeRate(offerer: string, claimer: string, token: string, paymentHash?: string): Promise<string>;
455
+
456
+ /**
457
+ * Returns the fee rate for committing (initializing) a non-payIn swap
458
+ *
459
+ * @param offerer Offerer of the swap
460
+ * @param claimer Claimer of the swap
461
+ * @param token Token to be swapped
462
+ * @param paymentHash Optional payment hash
463
+ */
464
+ getInitFeeRate(offerer: string, claimer: string, token: string, paymentHash?: string): Promise<string>;
465
+
466
+ /**
467
+ * Returns the fee rate for refunding a swap
468
+ *
469
+ * @param swapData Swap to refund
470
+ */
471
+ getRefundFeeRate(swapData: T): Promise<string>;
472
+
473
+ /**
474
+ * Returns the fee rate for claiming a swap as a specific signer
475
+ *
476
+ * @param signer Signer claiming the swap
477
+ * @param swapData Swap to claim
478
+ */
479
+ getClaimFeeRate(signer: string, swapData: T): Promise<string>;
480
+
481
+ getExtraData(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
482
+
483
+ /**
484
+ * Compute the claim hash for a given transaction output, either nonced or just output locked
485
+ *
486
+ * @param outputScript Bitcoin output locking script
487
+ * @param amount Amount of sats in the output
488
+ * @param confirmations Required number of confirmations for the swap to be claimable
489
+ * @param nonce Nonce to be used as replay protection
490
+ */
491
+ getHashForOnchain(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
492
+
493
+ /**
494
+ * Compute the claim hash for a given transaction id
495
+ *
496
+ * @param txId Bitcoin transaction ID
497
+ * @param confirmations Required number of confirmations for the swap to be claimable
498
+ */
499
+ getHashForTxId(txId: string, confirmations: number): Buffer;
500
+
501
+ /**
502
+ * Compute the claim hash for an HTLC swap with a given swap hash
503
+ *
504
+ * @param swapHash
505
+ */
506
+ getHashForHtlc(swapHash: Buffer): Buffer;
507
+
508
+ /**
509
+ * Withdraws funds from the trading LP vault
510
+ *
511
+ * @param signer Signer to sign the withdrawal with
512
+ * @param token Token to withdraw
513
+ * @param amount Amount of the token to withdraw
514
+ * @param txOptions Transaction options
515
+ */
516
+ withdraw(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
517
+
518
+ /**
519
+ * Returns transactions required for signer to withdraw funds from the trading LP vault
520
+ *
521
+ * @param signer Owner of the funds
522
+ * @param token Token to withdraw
523
+ * @param amount Amount of the token to withdraw
524
+ * @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
525
+ */
526
+ txsWithdraw(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
527
+
528
+ /**
529
+ * Deposits funds to the trading LP vault
530
+ *
531
+ * @param signer Signer to sign the deposit with
532
+ * @param token Token to deposit
533
+ * @param amount Amount of the token to deposit
534
+ * @param txOptions Transaction options
535
+ */
536
+ deposit(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
537
+
538
+ /**
539
+ * Returns transactions required for signer to deposit funds to the trading LP vault
540
+ *
541
+ * @param signer Owner of the funds
542
+ * @param token Token to deposit
543
+ * @param amount Amount of the token to deposit
544
+ * @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
545
+ */
546
+ txsDeposit(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
547
+
548
+ /**
549
+ * Returns the amount of deposits (in native token) that we can claim back (this is useful for SVM chains with the PDAs
550
+ * requiring you to put some deposit in order to store data)
551
+ *
552
+ * @param signer Signer to check the claimable deposits for
553
+ */
554
+ getClaimableDeposits?(signer: string): Promise<{count: number, totalValue: bigint}>;
555
+
556
+ /**
557
+ * Claims the funds from claimable deposits
558
+ *
559
+ * @param signer Owner of the deposits, transaction signer
560
+ * @param txOptions Transaction options
561
+ */
562
+ claimDeposits?(signer: Signer, txOptions: TransactionConfirmationOptions): Promise<{txIds: string[], count: number, totalValue: bigint}>;
563
+
564
+ }