@atomiqlabs/base 9.0.0-beta.3 → 9.0.0

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