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