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

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