@atomiqlabs/base 7.2.1 → 8.0.0-beta.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.
- package/dist/btc/BitcoinNetwork.d.ts +4 -0
- package/dist/btc/BitcoinNetwork.js +8 -0
- package/dist/btcrelay/BtcRelay.d.ts +4 -3
- package/dist/btcrelay/rpc/BitcoinRpc.d.ts +2 -0
- package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +1 -1
- package/dist/btcrelay/types/BtcBlock.d.ts +1 -0
- package/dist/btcrelay/types/BtcHeader.d.ts +1 -0
- package/dist/btcrelay/types/BtcStoredHeader.d.ts +1 -0
- package/dist/btcrelay/utils/StatePredictorUtils.d.ts +2 -0
- package/dist/btcrelay/utils/StatePredictorUtils.js +10 -3
- package/dist/chains/ChainData.d.ts +29 -0
- package/dist/chains/ChainData.js +2 -0
- package/dist/chains/ChainType.d.ts +15 -0
- package/dist/chains/ChainType.js +2 -0
- package/dist/events/types/ClaimEvent.d.ts +2 -3
- package/dist/events/types/ClaimEvent.js +3 -3
- package/dist/events/types/InitializeEvent.d.ts +1 -3
- package/dist/events/types/InitializeEvent.js +2 -3
- package/dist/events/types/RefundEvent.d.ts +0 -2
- package/dist/events/types/RefundEvent.js +0 -3
- package/dist/events/types/SwapEvent.d.ts +2 -4
- package/dist/events/types/SwapEvent.js +2 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -26
- package/dist/swaps/SwapContract.d.ts +60 -70
- package/dist/swaps/SwapData.d.ts +15 -13
- package/dist/swaps/SwapData.js +0 -5
- package/dist/utils/BigIntBufferUtils.d.ts +6 -0
- package/dist/utils/BigIntBufferUtils.js +31 -0
- package/package.json +2 -3
- package/src/btc/BitcoinNetwork.ts +5 -0
- package/src/btcrelay/BtcRelay.ts +4 -3
- package/src/btcrelay/rpc/BitcoinRpc.ts +2 -0
- package/src/btcrelay/synchronizer/RelaySynchronizer.ts +1 -1
- package/src/btcrelay/types/BtcBlock.ts +1 -0
- package/src/btcrelay/types/BtcHeader.ts +1 -1
- package/src/btcrelay/types/BtcStoredHeader.ts +1 -0
- package/src/btcrelay/utils/StatePredictorUtils.ts +10 -2
- package/src/chains/ChainData.ts +38 -0
- package/src/{ChainType.ts → chains/ChainType.ts} +4 -4
- package/src/events/types/ClaimEvent.ts +4 -5
- package/src/events/types/InitializeEvent.ts +2 -5
- package/src/events/types/RefundEvent.ts +1 -8
- package/src/events/types/SwapEvent.ts +3 -7
- package/src/index.ts +5 -26
- package/src/swaps/SwapContract.ts +90 -81
- package/src/swaps/SwapData.ts +17 -18
- package/src/utils/BigIntBufferUtils.ts +31 -0
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import {SwapEvent} from "./SwapEvent";
|
|
2
2
|
import {SwapData} from "../../swaps/SwapData";
|
|
3
|
-
import * as BN from "bn.js";
|
|
4
3
|
import {ChainSwapType} from "../../swaps/ChainSwapType";
|
|
5
4
|
|
|
6
5
|
export class InitializeEvent<T extends SwapData> extends SwapEvent<T> {
|
|
7
6
|
|
|
8
|
-
txoHash: string;
|
|
9
7
|
swapType: ChainSwapType;
|
|
10
8
|
swapData: () => Promise<T>;
|
|
11
9
|
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
14
|
-
this.txoHash = txoHash;
|
|
10
|
+
constructor(escrowHash: string, swapType: ChainSwapType, swapData: () => Promise<T>) {
|
|
11
|
+
super(escrowHash);
|
|
15
12
|
this.swapType = swapType;
|
|
16
13
|
this.swapData = swapData;
|
|
17
14
|
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import {SwapEvent} from "./SwapEvent";
|
|
2
2
|
import {SwapData} from "../../swaps/SwapData";
|
|
3
|
-
import * as BN from "bn.js";
|
|
4
3
|
|
|
5
|
-
export class RefundEvent<T extends SwapData> extends SwapEvent<T> {
|
|
6
|
-
|
|
7
|
-
constructor(paymentHash: string, sequence: BN) {
|
|
8
|
-
super(paymentHash, sequence);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
export class RefundEvent<T extends SwapData> extends SwapEvent<T> {}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import {SwapData} from "../../swaps/SwapData";
|
|
2
|
-
import * as BN from "bn.js";
|
|
3
|
-
|
|
4
2
|
|
|
5
3
|
export class SwapEvent<T extends SwapData> {
|
|
6
4
|
|
|
@@ -8,12 +6,10 @@ export class SwapEvent<T extends SwapData> {
|
|
|
8
6
|
blockTime: number,
|
|
9
7
|
txId: string
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
sequence: BN;
|
|
9
|
+
escrowHash: string;
|
|
13
10
|
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
16
|
-
this.sequence = sequence;
|
|
11
|
+
constructor(escrowHash: string) {
|
|
12
|
+
this.escrowHash = escrowHash;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,30 +22,9 @@ export * from "./errors/SignatureVerificationError";
|
|
|
22
22
|
export * from "./errors/CannotInitializeATAError"
|
|
23
23
|
export * from "./errors/SwapDataVerificationError";
|
|
24
24
|
|
|
25
|
-
export * from "./ChainType";
|
|
25
|
+
export * from "./chains/ChainType";
|
|
26
|
+
export * from "./chains/ChainData";
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// BtcBlock,
|
|
31
|
-
// BtcHeader,
|
|
32
|
-
// BtcStoredHeader,
|
|
33
|
-
// StatePredictorUtils,
|
|
34
|
-
// BtcRelay,
|
|
35
|
-
//
|
|
36
|
-
// ClaimEvent,
|
|
37
|
-
// InitializeEvent,
|
|
38
|
-
// RefundEvent,
|
|
39
|
-
// SwapEvent,
|
|
40
|
-
// ChainEvents,
|
|
41
|
-
//
|
|
42
|
-
// Lockable,
|
|
43
|
-
//
|
|
44
|
-
// StorageObject,
|
|
45
|
-
//
|
|
46
|
-
// ISwapNonce,
|
|
47
|
-
// SwapContract,
|
|
48
|
-
// SwapData,
|
|
49
|
-
// SwapType,
|
|
50
|
-
// TokenAddress,
|
|
51
|
-
// }
|
|
28
|
+
export * from "./utils/BigIntBufferUtils";
|
|
29
|
+
|
|
30
|
+
export * from "./btc/BitcoinNetwork";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {SwapData} from "./SwapData";
|
|
2
|
-
import * as BN from "bn.js";
|
|
3
2
|
import {BtcStoredHeader} from "../btcrelay/types/BtcStoredHeader";
|
|
4
3
|
import {SwapCommitStatus} from "./SwapCommitStatus";
|
|
5
4
|
import {ChainSwapType} from "./ChainSwapType";
|
|
6
5
|
import {RelaySynchronizer} from "../btcrelay/synchronizer/RelaySynchronizer";
|
|
6
|
+
import {Buffer} from "buffer";
|
|
7
7
|
|
|
8
8
|
export type IntermediaryReputationType = {
|
|
9
9
|
[key in ChainSwapType]: {
|
|
10
|
-
successVolume:
|
|
11
|
-
successCount:
|
|
12
|
-
failVolume:
|
|
13
|
-
failCount:
|
|
14
|
-
coopCloseVolume:
|
|
15
|
-
coopCloseCount:
|
|
10
|
+
successVolume: bigint,
|
|
11
|
+
successCount: bigint,
|
|
12
|
+
failVolume: bigint,
|
|
13
|
+
failCount: bigint,
|
|
14
|
+
coopCloseVolume: bigint,
|
|
15
|
+
coopCloseCount: bigint
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -26,7 +26,8 @@ export type BitcoinTransactionData = {
|
|
|
26
26
|
blockhash: string,
|
|
27
27
|
confirmations: number,
|
|
28
28
|
txid: string,
|
|
29
|
-
hex: string
|
|
29
|
+
hex: string,
|
|
30
|
+
height: number
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
export type TransactionConfirmationOptions = {
|
|
@@ -58,49 +59,26 @@ export interface SwapContract<
|
|
|
58
59
|
*/
|
|
59
60
|
start(): Promise<void>;
|
|
60
61
|
|
|
61
|
-
/**
|
|
62
|
-
* Signs & sends transactions for initializing a payIn swap (SC -> BTC)
|
|
63
|
-
*
|
|
64
|
-
* @param signer Signer to use for the transaction (must match offerer in swap data)
|
|
65
|
-
* @param swapData Swap to init
|
|
66
|
-
* @param signature Signature data from the claimer
|
|
67
|
-
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
68
|
-
* @param txOptions Transaction options
|
|
69
|
-
*/
|
|
70
|
-
initPayIn(signer: Signer, swapData: T, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the unsigned transactions required for initializing a payIn swap (SC -> BTC)
|
|
74
|
-
*
|
|
75
|
-
* @param swapData Swap to init
|
|
76
|
-
* @param signature Signature data from the claimer
|
|
77
|
-
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
78
|
-
* @param feeRate Fee rate to use for the transaction
|
|
79
|
-
*/
|
|
80
|
-
txsInitPayIn(swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
81
|
-
|
|
82
62
|
/**
|
|
83
63
|
* Signs & sends transactions for initializing a non-payIn swap (BTC -> SC)
|
|
84
64
|
*
|
|
85
65
|
* @param signer Signer to use for the transaction (must match claimer in swap data)
|
|
86
66
|
* @param swapData Swap to init
|
|
87
67
|
* @param signature Signature data from the offerer
|
|
88
|
-
* @param txoHash Tx output hash to use for BTC -> SC (on-chain) swaps to allow watchtowers to claim swaps
|
|
89
68
|
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
90
69
|
* @param txOptions Transaction options
|
|
91
70
|
*/
|
|
92
|
-
init(signer: Signer, swapData: T, signature: SignatureData,
|
|
71
|
+
init(signer: Signer, swapData: T, signature: SignatureData, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
93
72
|
|
|
94
73
|
/**
|
|
95
74
|
* Returns the unsigned transactions required for initializing a non-payIn swap (BTC -> SC)
|
|
96
75
|
*
|
|
97
76
|
* @param swapData Swap to init
|
|
98
77
|
* @param signature Signature data from the offerer
|
|
99
|
-
* @param txoHash Tx output hash to use for BTC -> SC (on-chain) swaps to allow watchtowers to claim swaps
|
|
100
78
|
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
101
79
|
* @param feeRate Fee rate to use for the transaction
|
|
102
80
|
*/
|
|
103
|
-
txsInit(swapData: T, signature: SignatureData,
|
|
81
|
+
txsInit(swapData: T, signature: SignatureData, skipChecks?: boolean, feeRate?: string): Promise<TX[]>;
|
|
104
82
|
|
|
105
83
|
/**
|
|
106
84
|
* Signs & sends transactions required for claiming an HTLC swap
|
|
@@ -132,30 +110,50 @@ export interface SwapContract<
|
|
|
132
110
|
*
|
|
133
111
|
* @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
|
|
134
112
|
* @param swapData Swap to claim
|
|
135
|
-
* @param blockheight Blockheight of the bitcoin block which includes the transaction
|
|
136
113
|
* @param tx Bitcoin transaction containing the required output
|
|
114
|
+
* @param requiredConfirmations Required confirmations for the escrow to be claimed
|
|
137
115
|
* @param vout Bitcoin tx's output index of the required output
|
|
138
116
|
* @param storedHeader Optional already retrieved stored header to use for proving
|
|
139
117
|
* @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
|
|
140
118
|
* @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
|
|
141
119
|
* @param txOptions Transaction options
|
|
142
120
|
*/
|
|
143
|
-
claimWithTxData(
|
|
121
|
+
claimWithTxData(
|
|
122
|
+
signer: Signer,
|
|
123
|
+
swapData: T,
|
|
124
|
+
tx: BitcoinTransactionData,
|
|
125
|
+
requiredConfirmations: number,
|
|
126
|
+
vout: number,
|
|
127
|
+
storedHeader?: BtcStoredHeader<any>,
|
|
128
|
+
synchronizer?: RelaySynchronizer<any, TX, any>,
|
|
129
|
+
initAta?: boolean,
|
|
130
|
+
txOptions?: TransactionConfirmationOptions
|
|
131
|
+
): Promise<string>;
|
|
144
132
|
|
|
145
133
|
/**
|
|
146
134
|
* Returns the unsigned transactions required for claiming an on-chain PTLC (proof-time locked contract) swap
|
|
147
135
|
*
|
|
148
136
|
* @param signer Signer for which the transaction should be created (doesn't need to match the claimer)
|
|
149
137
|
* @param swapData Swap to claim
|
|
150
|
-
* @param blockheight Blockheight of the bitcoin block which includes the transaction
|
|
151
138
|
* @param tx Bitcoin transaction containing the required output
|
|
139
|
+
* @param requiredConfirmations Required confirmations for the escrow to be claimed
|
|
152
140
|
* @param vout Bitcoin tx's output index of the required output
|
|
153
141
|
* @param storedHeader Optional already retrieved stored header to use for proving
|
|
154
142
|
* @param synchronizer Optiona synchronizer to be used if BTC relay contract is not synced up to the required blockheight
|
|
155
143
|
* @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
|
|
156
144
|
* @param feeRate Fee rate to use for the transactions
|
|
157
145
|
*/
|
|
158
|
-
txsClaimWithTxData(
|
|
146
|
+
txsClaimWithTxData(
|
|
147
|
+
signer: string | Signer,
|
|
148
|
+
swapData: T,
|
|
149
|
+
tx: BitcoinTransactionData,
|
|
150
|
+
requiredConfirmations: number,
|
|
151
|
+
vout: number,
|
|
152
|
+
storedHeader?: BtcStoredHeader<any>,
|
|
153
|
+
synchronizer?: RelaySynchronizer<any, TX, any>,
|
|
154
|
+
initAta?: boolean,
|
|
155
|
+
feeRate?: string
|
|
156
|
+
): Promise<TX[]>;
|
|
159
157
|
|
|
160
158
|
/**
|
|
161
159
|
* Signs & sends transactions for refunding a timed out swap
|
|
@@ -171,12 +169,13 @@ export interface SwapContract<
|
|
|
171
169
|
/**
|
|
172
170
|
* Returns the transactions for refunding a timed out swap
|
|
173
171
|
*
|
|
172
|
+
* @param signer Signer of the refund transaction
|
|
174
173
|
* @param swapData Swap to refund
|
|
175
174
|
* @param check Whether to check if the swap contract still exists on-chain
|
|
176
175
|
* @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
|
|
177
176
|
* @param feeRate Fee rate to use for the transactions
|
|
178
177
|
*/
|
|
179
|
-
txsRefund(swapData: T, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
|
|
178
|
+
txsRefund(signer: string, swapData: T, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
|
|
180
179
|
|
|
181
180
|
/**
|
|
182
181
|
* Signs & sends transactions for refunding a swap with a valid refund signature from the claimer
|
|
@@ -193,13 +192,14 @@ export interface SwapContract<
|
|
|
193
192
|
/**
|
|
194
193
|
* Returns the transactions for refunding a swap with a valid refund signature from the claimer
|
|
195
194
|
*
|
|
195
|
+
* @param signer Signer of the refund transaction
|
|
196
196
|
* @param swapData Swap to refund
|
|
197
197
|
* @param signature Refund signature received from the claimer
|
|
198
198
|
* @param check Whether to check if the swap contract still exists on-chain
|
|
199
199
|
* @param initAta Whether to initialize a token account if it doesn't exist (applies to e.g. Solana, with token specific ATAs)
|
|
200
200
|
* @param feeRate Fee rate to use for the transactions
|
|
201
201
|
*/
|
|
202
|
-
txsRefundWithAuthorization(swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
|
|
202
|
+
txsRefundWithAuthorization(signer: string, swapData: T, signature: SignatureData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<TX[]>;
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* Signs & sends transactions for initializing and instantly (upon init confirmation) claiming the HTLC, used for BTC-LN -> SC swaps
|
|
@@ -211,7 +211,7 @@ export interface SwapContract<
|
|
|
211
211
|
* @param skipChecks Whether to skip verification of the signature & checking if the swap is already committed
|
|
212
212
|
* @param txOptions Transaction options
|
|
213
213
|
*/
|
|
214
|
-
initAndClaimWithSecret(signer: Signer, swapData: T, signature: SignatureData, secret: string, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string[]>;
|
|
214
|
+
initAndClaimWithSecret?(signer: Signer, swapData: T, signature: SignatureData, secret: string, skipChecks?: boolean, txOptions?: TransactionConfirmationOptions): Promise<string[]>;
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
217
|
* Checks whether a swap is already expired, swap expires a bit sooner for the claimer & a bit later for offerer, this
|
|
@@ -220,7 +220,7 @@ export interface SwapContract<
|
|
|
220
220
|
* @param signer Signer to use for checking the expiry
|
|
221
221
|
* @param swapData Swap to check
|
|
222
222
|
*/
|
|
223
|
-
isExpired(signer: string, swapData: T): boolean
|
|
223
|
+
isExpired(signer: string, swapData: T): Promise<boolean>;
|
|
224
224
|
|
|
225
225
|
/**
|
|
226
226
|
* Checks whether a swap is claimable for the signer, i.e. it is not expired yet and is committed on-chain
|
|
@@ -245,21 +245,6 @@ export interface SwapContract<
|
|
|
245
245
|
*/
|
|
246
246
|
getCommitStatus(signer: string, swapData: T): Promise<SwapCommitStatus>;
|
|
247
247
|
|
|
248
|
-
/**
|
|
249
|
-
* Returns the full status of the swap as identified by its payment hash
|
|
250
|
-
*
|
|
251
|
-
* @param paymentHash
|
|
252
|
-
*/
|
|
253
|
-
getPaymentHashStatus(paymentHash: string): Promise<SwapCommitStatus>;
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Returns the on-chain committed data for the swap as identifier by its payment hash, NOTE: this might be slow & expensive
|
|
257
|
-
* for EVM chains due to the need to go through all the events
|
|
258
|
-
*
|
|
259
|
-
* @param paymentHash
|
|
260
|
-
*/
|
|
261
|
-
getCommitedData(paymentHash: string): Promise<T>;
|
|
262
|
-
|
|
263
248
|
/**
|
|
264
249
|
* Checks whether a given swap is refundable by us, i.e. it is already expired, we are offerer & swap is committed on-chain
|
|
265
250
|
*
|
|
@@ -359,7 +344,7 @@ export interface SwapContract<
|
|
|
359
344
|
* @param token Token
|
|
360
345
|
* @param inContract Whether we are checking the liquidity deposited into the LP vault or just on-chain balance
|
|
361
346
|
*/
|
|
362
|
-
getBalance(signer: string, token: string, inContract: boolean): Promise<
|
|
347
|
+
getBalance(signer: string, token: string, inContract: boolean): Promise<bigint>;
|
|
363
348
|
|
|
364
349
|
/**
|
|
365
350
|
* Create a swap data for this given chain
|
|
@@ -372,29 +357,27 @@ export interface SwapContract<
|
|
|
372
357
|
* @param paymentHash Payment hash identifying the swap
|
|
373
358
|
* @param sequence Swap sequence uniquelly defining this swap
|
|
374
359
|
* @param expiry Expiration of the swap
|
|
375
|
-
* @param escrowNonce Nonce to be used for replay protection of BTC transactions
|
|
376
|
-
* @param confirmations Required transaction on-chain confirmation for BTC on-chain swaps
|
|
377
360
|
* @param payIn Whether the swap is payIn (offerer paying to the contract, or not payIn offerer using funds in his LP vault)
|
|
378
361
|
* @param payOut Whether the swap is payOut (claimer getting the funds to his on-chain address, or no payOut claimer
|
|
379
362
|
* getting his funds into his LP vault)
|
|
380
363
|
* @param securityDeposit Security deposit for the swap paid by the claimer (options premium)
|
|
381
364
|
* @param claimerBounty Bounty for the claimer of the swap (used for watchtowers)
|
|
365
|
+
* @param depositToken Token to be used for security deposit and claimer bounty
|
|
382
366
|
*/
|
|
383
367
|
createSwapData(
|
|
384
368
|
type: ChainSwapType,
|
|
385
369
|
offerer: string,
|
|
386
370
|
claimer: string,
|
|
387
371
|
token: string,
|
|
388
|
-
amount:
|
|
372
|
+
amount: bigint,
|
|
389
373
|
paymentHash: string,
|
|
390
|
-
sequence:
|
|
391
|
-
expiry:
|
|
392
|
-
escrowNonce: BN,
|
|
393
|
-
confirmations: number,
|
|
374
|
+
sequence: bigint,
|
|
375
|
+
expiry: bigint,
|
|
394
376
|
payIn: boolean,
|
|
395
377
|
payOut: boolean,
|
|
396
|
-
securityDeposit:
|
|
397
|
-
claimerBounty:
|
|
378
|
+
securityDeposit: bigint,
|
|
379
|
+
claimerBounty: bigint,
|
|
380
|
+
depositToken?: string
|
|
398
381
|
): Promise<T>;
|
|
399
382
|
|
|
400
383
|
/**
|
|
@@ -435,7 +418,15 @@ export interface SwapContract<
|
|
|
435
418
|
* @param swapData Swap to initiate
|
|
436
419
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
437
420
|
*/
|
|
438
|
-
getCommitFee(swapData: T, feeRate?: string): Promise<
|
|
421
|
+
getCommitFee(swapData: T, feeRate?: string): Promise<bigint>;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Returns raw fee (not including any account deposits we might need) for initiating the swap
|
|
425
|
+
*
|
|
426
|
+
* @param swapData Swap to initiate
|
|
427
|
+
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
428
|
+
*/
|
|
429
|
+
getRawCommitFee?(swapData: T, feeRate?: string): Promise<bigint>;
|
|
439
430
|
|
|
440
431
|
/**
|
|
441
432
|
* Returns the fee in native token base units to claim the swap
|
|
@@ -444,7 +435,7 @@ export interface SwapContract<
|
|
|
444
435
|
* @param swapData Swap to claim
|
|
445
436
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
446
437
|
*/
|
|
447
|
-
getClaimFee(signer: string, swapData: T, feeRate?: string): Promise<
|
|
438
|
+
getClaimFee(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
|
|
448
439
|
|
|
449
440
|
/**
|
|
450
441
|
* Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
|
|
@@ -453,7 +444,7 @@ export interface SwapContract<
|
|
|
453
444
|
* @param swapData Swap to claim
|
|
454
445
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
455
446
|
*/
|
|
456
|
-
getRawClaimFee?(signer: string, swapData: T, feeRate?: string): Promise<
|
|
447
|
+
getRawClaimFee?(signer: string, swapData: T, feeRate?: string): Promise<bigint>;
|
|
457
448
|
|
|
458
449
|
/**
|
|
459
450
|
* Returns the fee in native token base units to refund the swap
|
|
@@ -461,7 +452,7 @@ export interface SwapContract<
|
|
|
461
452
|
* @param swapData Swap to refund
|
|
462
453
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
463
454
|
*/
|
|
464
|
-
getRefundFee(swapData: T, feeRate?: string): Promise<
|
|
455
|
+
getRefundFee(swapData: T, feeRate?: string): Promise<bigint>;
|
|
465
456
|
|
|
466
457
|
/**
|
|
467
458
|
* Returns raw fee (not including any refunds we might get that would make the getRefundFee negative) for claiming the swap
|
|
@@ -469,7 +460,7 @@ export interface SwapContract<
|
|
|
469
460
|
* @param swapData Swap to claim
|
|
470
461
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
471
462
|
*/
|
|
472
|
-
getRawRefundFee?(swapData: T, feeRate?: string): Promise<
|
|
463
|
+
getRawRefundFee?(swapData: T, feeRate?: string): Promise<bigint>;
|
|
473
464
|
|
|
474
465
|
/**
|
|
475
466
|
* Returns the fee rate for committing (initializing) a payIn swap
|
|
@@ -506,14 +497,32 @@ export interface SwapContract<
|
|
|
506
497
|
*/
|
|
507
498
|
getClaimFeeRate(signer: string, swapData: T): Promise<string>;
|
|
508
499
|
|
|
500
|
+
getExtraData(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
|
|
501
|
+
|
|
509
502
|
/**
|
|
510
|
-
* Compute the
|
|
503
|
+
* Compute the claim hash for a given transaction output, either nonced or just output locked
|
|
511
504
|
*
|
|
512
505
|
* @param outputScript Bitcoin output locking script
|
|
513
506
|
* @param amount Amount of sats in the output
|
|
507
|
+
* @param confirmations Required number of confirmations for the swap to be claimable
|
|
514
508
|
* @param nonce Nonce to be used as replay protection
|
|
515
509
|
*/
|
|
516
|
-
getHashForOnchain(outputScript: Buffer, amount:
|
|
510
|
+
getHashForOnchain(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Compute the claim hash for a given transaction id
|
|
514
|
+
*
|
|
515
|
+
* @param txId Bitcoin transaction ID
|
|
516
|
+
* @param confirmations Required number of confirmations for the swap to be claimable
|
|
517
|
+
*/
|
|
518
|
+
getHashForTxId(txId: string, confirmations: number): Buffer;
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Compute the claim hash for an HTLC swap with a given swap hash
|
|
522
|
+
*
|
|
523
|
+
* @param swapHash
|
|
524
|
+
*/
|
|
525
|
+
getHashForHtlc(swapHash: Buffer): Buffer;
|
|
517
526
|
|
|
518
527
|
/**
|
|
519
528
|
* Returns the token address of the native currency of the chain
|
|
@@ -528,7 +537,7 @@ export interface SwapContract<
|
|
|
528
537
|
* @param amount Amount of the token to withdraw
|
|
529
538
|
* @param txOptions Transaction options
|
|
530
539
|
*/
|
|
531
|
-
withdraw(signer: Signer, token: string, amount:
|
|
540
|
+
withdraw(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
532
541
|
|
|
533
542
|
/**
|
|
534
543
|
* Returns transactions required for signer to withdraw funds from the trading LP vault
|
|
@@ -538,7 +547,7 @@ export interface SwapContract<
|
|
|
538
547
|
* @param amount Amount of the token to withdraw
|
|
539
548
|
* @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
|
|
540
549
|
*/
|
|
541
|
-
txsWithdraw(signer: string, token: string, amount:
|
|
550
|
+
txsWithdraw(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
|
|
542
551
|
|
|
543
552
|
/**
|
|
544
553
|
* Deposits funds to the trading LP vault
|
|
@@ -548,7 +557,7 @@ export interface SwapContract<
|
|
|
548
557
|
* @param amount Amount of the token to deposit
|
|
549
558
|
* @param txOptions Transaction options
|
|
550
559
|
*/
|
|
551
|
-
deposit(signer: Signer, token: string, amount:
|
|
560
|
+
deposit(signer: Signer, token: string, amount: bigint, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
552
561
|
|
|
553
562
|
/**
|
|
554
563
|
* Returns transactions required for signer to deposit funds to the trading LP vault
|
|
@@ -558,7 +567,7 @@ export interface SwapContract<
|
|
|
558
567
|
* @param amount Amount of the token to deposit
|
|
559
568
|
* @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
|
|
560
569
|
*/
|
|
561
|
-
txsDeposit(signer: string, token: string, amount:
|
|
570
|
+
txsDeposit(signer: string, token: string, amount: bigint, feeRate?: string): Promise<TX[]>;
|
|
562
571
|
|
|
563
572
|
/**
|
|
564
573
|
* Transfers the specific token to a given recipient
|
|
@@ -569,7 +578,7 @@ export interface SwapContract<
|
|
|
569
578
|
* @param dstAddress Destination address of the transfer
|
|
570
579
|
* @param txOptions Transaction options
|
|
571
580
|
*/
|
|
572
|
-
transfer(signer: Signer, token: string, amount:
|
|
581
|
+
transfer(signer: Signer, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
|
|
573
582
|
|
|
574
583
|
/**
|
|
575
584
|
* Returns transactions for transferring a specific token to a given recipient
|
|
@@ -580,7 +589,7 @@ export interface SwapContract<
|
|
|
580
589
|
* @param dstAddress Destination address of the transfer
|
|
581
590
|
* @param feeRate Optional fee rate to use for the transaction (fetched on-demand if not provided)
|
|
582
591
|
*/
|
|
583
|
-
txsTransfer(signer: string, token: string, amount:
|
|
592
|
+
txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<TX[]>;
|
|
584
593
|
|
|
585
594
|
/**
|
|
586
595
|
* Serializes a given transaction to a string
|
|
@@ -643,7 +652,7 @@ export interface SwapContract<
|
|
|
643
652
|
*
|
|
644
653
|
* @param signer Signer to check the claimable deposits for
|
|
645
654
|
*/
|
|
646
|
-
getClaimableDeposits?(signer: string): Promise<{count: number, totalValue:
|
|
655
|
+
getClaimableDeposits?(signer: string): Promise<{count: number, totalValue: bigint}>;
|
|
647
656
|
|
|
648
657
|
/**
|
|
649
658
|
* Claims the funds from claimable deposits
|
|
@@ -651,6 +660,6 @@ export interface SwapContract<
|
|
|
651
660
|
* @param signer Owner of the deposits, transaction signer
|
|
652
661
|
* @param txOptions Transaction options
|
|
653
662
|
*/
|
|
654
|
-
claimDeposits?(signer: Signer): Promise<{txIds: string[], count: number, totalValue:
|
|
663
|
+
claimDeposits?(signer: Signer): Promise<{txIds: string[], count: number, totalValue: bigint}>;
|
|
655
664
|
|
|
656
665
|
}
|
package/src/swaps/SwapData.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {ChainSwapType} from "./ChainSwapType";
|
|
2
|
-
import BN from "bn.js";
|
|
3
2
|
import {StorageObject} from "../storage/StorageObject";
|
|
4
3
|
|
|
5
4
|
export abstract class SwapData implements StorageObject {
|
|
@@ -26,38 +25,38 @@ export abstract class SwapData implements StorageObject {
|
|
|
26
25
|
|
|
27
26
|
abstract getType(): ChainSwapType;
|
|
28
27
|
|
|
29
|
-
abstract getAmount():
|
|
28
|
+
abstract getAmount(): bigint;
|
|
30
29
|
|
|
31
30
|
abstract getToken(): string;
|
|
32
31
|
|
|
33
32
|
abstract isToken(token: string): boolean;
|
|
34
33
|
|
|
35
|
-
abstract getExpiry():
|
|
36
|
-
|
|
37
|
-
abstract getConfirmations(): number;
|
|
38
|
-
|
|
39
|
-
abstract getEscrowNonce(): BN;
|
|
34
|
+
abstract getExpiry(): bigint;
|
|
40
35
|
|
|
41
36
|
abstract isPayOut(): boolean;
|
|
42
37
|
|
|
43
38
|
abstract isPayIn(): boolean;
|
|
44
39
|
|
|
45
|
-
abstract
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
40
|
+
abstract getClaimHash(): string;
|
|
41
|
+
|
|
42
|
+
abstract getEscrowHash(): string;
|
|
43
|
+
|
|
44
|
+
abstract getSequence?(): bigint;
|
|
51
45
|
|
|
52
|
-
abstract
|
|
46
|
+
abstract getExtraData(): string;
|
|
47
|
+
abstract getConfirmationsHint(): number;
|
|
48
|
+
abstract getNonceHint(): bigint;
|
|
49
|
+
abstract getTxoHashHint(): string;
|
|
50
|
+
abstract setExtraData(extraData: string): void;
|
|
53
51
|
|
|
54
|
-
abstract
|
|
52
|
+
abstract getSecurityDeposit(): bigint;
|
|
55
53
|
|
|
56
|
-
abstract
|
|
54
|
+
abstract getClaimerBounty(): bigint;
|
|
57
55
|
|
|
58
|
-
abstract
|
|
56
|
+
abstract getTotalDeposit(): bigint;
|
|
59
57
|
|
|
60
|
-
abstract
|
|
58
|
+
abstract getDepositToken(): string;
|
|
59
|
+
abstract isDepositToken(token: string): boolean;
|
|
61
60
|
|
|
62
61
|
abstract equals(other: SwapData): boolean;
|
|
63
62
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Buffer} from "buffer";
|
|
2
|
+
|
|
3
|
+
export const BigIntBufferUtils: {
|
|
4
|
+
toBuffer: (value: bigint, endianness?: "be" | "le", length?: number) => Buffer
|
|
5
|
+
fromBuffer: (value: Buffer, endianness?: "be" | "le") => bigint
|
|
6
|
+
} = {
|
|
7
|
+
toBuffer: (value: bigint, endianness: "be" | "le" = "be", length: number) => {
|
|
8
|
+
let values: number[] = Array(length);
|
|
9
|
+
for(let i=0;i<length;i++) {
|
|
10
|
+
values[i] = Number(value & 0xffn);
|
|
11
|
+
value >>= 8n;
|
|
12
|
+
}
|
|
13
|
+
const buff = Buffer.from(values);
|
|
14
|
+
if(endianness==="be") buff.reverse();
|
|
15
|
+
return buff;
|
|
16
|
+
},
|
|
17
|
+
fromBuffer: (value: Buffer, endianness: "be" | "le" = "be") => {
|
|
18
|
+
if(endianness==="le") {
|
|
19
|
+
const dst = Buffer.alloc(value.length);
|
|
20
|
+
value.copy(dst);
|
|
21
|
+
dst.reverse();
|
|
22
|
+
value = dst;
|
|
23
|
+
}
|
|
24
|
+
let accumulator = 0n;
|
|
25
|
+
for(let byte of value) {
|
|
26
|
+
accumulator <<= 8n;
|
|
27
|
+
accumulator |= BigInt(byte);
|
|
28
|
+
}
|
|
29
|
+
return accumulator;
|
|
30
|
+
}
|
|
31
|
+
};
|