@atomiqlabs/lp-lib 11.0.5 → 12.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/info/InfoHandler.js +3 -12
- package/dist/plugins/IPlugin.d.ts +34 -35
- package/dist/plugins/IPlugin.js +7 -8
- package/dist/plugins/PluginManager.d.ts +29 -30
- package/dist/plugins/PluginManager.js +160 -188
- package/dist/prices/BinanceSwapPrice.d.ts +1 -2
- package/dist/prices/BinanceSwapPrice.js +56 -70
- package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
- package/dist/prices/CoinGeckoSwapPrice.js +30 -42
- package/dist/prices/OKXSwapPrice.d.ts +1 -2
- package/dist/prices/OKXSwapPrice.js +56 -70
- package/dist/storage/IIntermediaryStorage.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
- package/dist/storagemanager/StorageManager.js +42 -59
- package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
- package/dist/swaps/FromBtcBaseSwap.js +2 -3
- package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
- package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
- package/dist/swaps/ISwapPrice.d.ts +4 -5
- package/dist/swaps/ISwapPrice.js +8 -30
- package/dist/swaps/SwapHandler.d.ts +26 -15
- package/dist/swaps/SwapHandler.js +107 -66
- package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
- package/dist/swaps/SwapHandlerSwap.js +32 -8
- package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
- package/dist/swaps/ToBtcBaseSwap.js +4 -4
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
- package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
- package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
- package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
- package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
- package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +398 -453
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
- package/dist/utils/Utils.d.ts +2 -3
- package/dist/utils/Utils.js +4 -14
- package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
- package/dist/utils/paramcoders/ParamDecoder.js +53 -65
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
- package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
- package/dist/wallets/IBitcoinWallet.d.ts +4 -5
- package/dist/wallets/ILightningWallet.d.ts +20 -21
- package/dist/wallets/ILightningWallet.js +1 -1
- package/package.json +4 -6
- package/src/plugins/IPlugin.ts +28 -29
- package/src/plugins/PluginManager.ts +21 -22
- package/src/prices/BinanceSwapPrice.ts +3 -4
- package/src/prices/CoinGeckoSwapPrice.ts +4 -5
- package/src/prices/OKXSwapPrice.ts +3 -4
- package/src/storage/IIntermediaryStorage.ts +4 -5
- package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
- package/src/swaps/FromBtcBaseSwap.ts +9 -10
- package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
- package/src/swaps/ISwapPrice.ts +10 -20
- package/src/swaps/SwapHandler.ts +101 -35
- package/src/swaps/SwapHandlerSwap.ts +42 -17
- package/src/swaps/ToBtcBaseSwap.ts +20 -18
- package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
- package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
- package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
- package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
- package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
- package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
- package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
- package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
- package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
- package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
- package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
- package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +106 -118
- package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
- package/src/utils/Utils.ts +3 -4
- package/src/utils/paramcoders/ParamDecoder.ts +5 -5
- package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
- package/src/wallets/IBitcoinWallet.ts +4 -5
- package/src/wallets/ILightningWallet.ts +21 -22
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {Express, Request, Response} from "express";
|
|
3
2
|
import {createHash, randomBytes} from "crypto";
|
|
4
3
|
import {
|
|
@@ -18,7 +17,6 @@ import {ServerParamEncoder} from "../../utils/paramcoders/server/ServerParamEnco
|
|
|
18
17
|
import {FieldTypeEnum, verifySchema} from "../../utils/paramcoders/SchemaVerifier";
|
|
19
18
|
import {PluginManager} from "../../plugins/PluginManager";
|
|
20
19
|
import {FromBtcLnBaseSwapHandler} from "../FromBtcLnBaseSwapHandler";
|
|
21
|
-
import {serverParamDecoder} from "../../utils/paramcoders/server/ServerParamDecoder";
|
|
22
20
|
import {
|
|
23
21
|
HodlInvoiceInit,
|
|
24
22
|
ILightningWallet,
|
|
@@ -27,15 +25,16 @@ import {
|
|
|
27
25
|
} from "../../wallets/ILightningWallet";
|
|
28
26
|
|
|
29
27
|
export type SwapForGasServerConfig = FromBtcBaseConfig & {
|
|
30
|
-
minCltv:
|
|
28
|
+
minCltv: bigint,
|
|
31
29
|
|
|
32
30
|
invoiceTimeoutSeconds?: number
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export type FromBtcLnTrustedRequestType = {
|
|
36
34
|
address: string,
|
|
37
|
-
amount:
|
|
38
|
-
|
|
35
|
+
amount: bigint,
|
|
36
|
+
exactIn?: boolean,
|
|
37
|
+
token?: string
|
|
39
38
|
};
|
|
40
39
|
|
|
41
40
|
/**
|
|
@@ -43,6 +42,7 @@ export type FromBtcLnTrustedRequestType = {
|
|
|
43
42
|
*/
|
|
44
43
|
export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedSwap, FromBtcLnTrustedSwapState> {
|
|
45
44
|
readonly type: SwapHandlerType = SwapHandlerType.FROM_BTCLN_TRUSTED;
|
|
45
|
+
readonly swapType = null;
|
|
46
46
|
|
|
47
47
|
activeSubscriptions: Map<string, AbortController> = new Map<string, AbortController>();
|
|
48
48
|
processedTxIds: Map<string, string> = new Map<string, string>();
|
|
@@ -60,9 +60,6 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
60
60
|
super(storageDirectory, path, chains, lightning, swapPricing);
|
|
61
61
|
this.config = config;
|
|
62
62
|
this.config.invoiceTimeoutSeconds = this.config.invoiceTimeoutSeconds || 90;
|
|
63
|
-
for(let chainId in chains.chains) {
|
|
64
|
-
this.allowedTokens[chainId] = new Set<string>([chains.chains[chainId].swapContract.getNativeCurrencyAddress()]);
|
|
65
|
-
}
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
/**
|
|
@@ -85,7 +82,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
85
82
|
* @param invoiceData
|
|
86
83
|
*/
|
|
87
84
|
private subscribeToInvoice(invoiceData: FromBtcLnTrustedSwap) {
|
|
88
|
-
const hash = invoiceData.
|
|
85
|
+
const hash = invoiceData.getIdentifierHash();
|
|
89
86
|
|
|
90
87
|
//Already subscribed
|
|
91
88
|
if(this.activeSubscriptions.has(hash)) return;
|
|
@@ -140,7 +137,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
140
137
|
for(let swap of swaps) {
|
|
141
138
|
//Cancel invoices
|
|
142
139
|
try {
|
|
143
|
-
const paymentHash = swap.
|
|
140
|
+
const paymentHash = swap.getIdentifierHash();
|
|
144
141
|
await this.lightning.cancelHodlInvoice(paymentHash);
|
|
145
142
|
this.unsubscribeInvoice(paymentHash);
|
|
146
143
|
this.swapLogger.info(swap, "cancelInvoices(): invoice cancelled!");
|
|
@@ -171,7 +168,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
171
168
|
}
|
|
172
169
|
]);
|
|
173
170
|
|
|
174
|
-
for(let swap of queriedData) {
|
|
171
|
+
for(let {obj: swap} of queriedData) {
|
|
175
172
|
if(await this.processPastSwap(swap)) cancelInvoices.push(swap);
|
|
176
173
|
}
|
|
177
174
|
|
|
@@ -181,7 +178,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
181
178
|
private async cancelSwapAndInvoice(swap: FromBtcLnTrustedSwap): Promise<void> {
|
|
182
179
|
if(swap.state!==FromBtcLnTrustedSwapState.RECEIVED) return;
|
|
183
180
|
await swap.setState(FromBtcLnTrustedSwapState.CANCELED);
|
|
184
|
-
const paymentHash = swap.
|
|
181
|
+
const paymentHash = swap.getIdentifierHash();
|
|
185
182
|
await this.lightning.cancelHodlInvoice(paymentHash);
|
|
186
183
|
this.unsubscribeInvoice(paymentHash);
|
|
187
184
|
await this.removeSwapData(swap);
|
|
@@ -206,7 +203,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
206
203
|
}
|
|
207
204
|
|
|
208
205
|
if(invoiceData.state===FromBtcLnTrustedSwapState.RECEIVED) {
|
|
209
|
-
const balance: Promise<
|
|
206
|
+
const balance: Promise<bigint> = swapContract.getBalance(signer.getAddress(), invoiceData.token, false);
|
|
210
207
|
try {
|
|
211
208
|
await this.checkBalance(invoiceData.output, balance, null);
|
|
212
209
|
if(invoiceData.metadata!=null) invoiceData.metadata.times.htlcBalanceChecked = Date.now();
|
|
@@ -217,7 +214,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
217
214
|
|
|
218
215
|
if(invoiceData.state!==FromBtcLnTrustedSwapState.RECEIVED) return;
|
|
219
216
|
|
|
220
|
-
const txns = await swapContract.txsTransfer(signer.getAddress(),
|
|
217
|
+
const txns = await swapContract.txsTransfer(signer.getAddress(), invoiceData.token, invoiceData.output, invoiceData.dstAddress);
|
|
221
218
|
|
|
222
219
|
let unlock = invoiceData.lock(Infinity);
|
|
223
220
|
if(unlock==null) return;
|
|
@@ -289,7 +286,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
289
286
|
|
|
290
287
|
if(invoiceData.metadata!=null) invoiceData.metadata.times.htlcSettled = Date.now();
|
|
291
288
|
|
|
292
|
-
const paymentHash = invoiceData.
|
|
289
|
+
const paymentHash = invoiceData.getIdentifierHash();
|
|
293
290
|
this.processedTxIds.set(paymentHash, invoiceData.txIds.init);
|
|
294
291
|
await invoiceData.setState(FromBtcLnTrustedSwapState.SETTLED);
|
|
295
292
|
|
|
@@ -382,12 +379,18 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
382
379
|
* amount: string amount (in lamports/smart chain base units) of the invoice
|
|
383
380
|
*/
|
|
384
381
|
|
|
385
|
-
|
|
382
|
+
req.query.token ??= swapContract.getNativeCurrencyAddress();
|
|
383
|
+
|
|
384
|
+
const parsedBody: FromBtcLnTrustedRequestType = verifySchema(req.query,{
|
|
386
385
|
address: (val: string) => val!=null &&
|
|
387
386
|
typeof(val)==="string" &&
|
|
388
387
|
swapContract.isValidAddress(val) ? val : null,
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
token: (val: string) => val!=null &&
|
|
389
|
+
typeof(val)==="string" &&
|
|
390
|
+
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
391
|
+
amount: FieldTypeEnum.BigInt,
|
|
392
|
+
exactIn: (val: string) => val==="true" ? true :
|
|
393
|
+
(val==="false" || val===undefined) ? false : null
|
|
391
394
|
});
|
|
392
395
|
if(parsedBody==null) throw {
|
|
393
396
|
code: 20100,
|
|
@@ -395,14 +398,14 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
395
398
|
};
|
|
396
399
|
metadata.request = parsedBody;
|
|
397
400
|
|
|
398
|
-
const requestedAmount = {input:
|
|
401
|
+
const requestedAmount = {input: parsedBody.exactIn, amount: parsedBody.amount};
|
|
399
402
|
const request = {
|
|
400
403
|
chainIdentifier,
|
|
401
404
|
raw: req,
|
|
402
405
|
parsed: parsedBody,
|
|
403
406
|
metadata
|
|
404
407
|
};
|
|
405
|
-
const useToken =
|
|
408
|
+
const useToken = parsedBody.token;
|
|
406
409
|
|
|
407
410
|
//Check request params
|
|
408
411
|
const fees = await this.preCheckAmounts(request, requestedAmount, useToken);
|
|
@@ -413,7 +416,7 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
413
416
|
const abortController = this.getAbortController(responseStream);
|
|
414
417
|
|
|
415
418
|
//Pre-fetch data
|
|
416
|
-
const {pricePrefetchPromise} = this.getFromBtcPricePrefetches(chainIdentifier, useToken, abortController);
|
|
419
|
+
const {pricePrefetchPromise} = this.getFromBtcPricePrefetches(chainIdentifier, useToken, useToken, abortController);
|
|
417
420
|
const balancePrefetch = swapContract.getBalance(signer.getAddress(), useToken, false).catch(e => {
|
|
418
421
|
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
419
422
|
abortController.abort(e);
|
|
@@ -440,10 +443,10 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
440
443
|
|
|
441
444
|
const hodlInvoiceObj: HodlInvoiceInit = {
|
|
442
445
|
description: chainIdentifier+"-GAS-"+parsedBody.address,
|
|
443
|
-
cltvDelta: this.config.minCltv
|
|
446
|
+
cltvDelta: Number(this.config.minCltv) + 5,
|
|
444
447
|
expiresAt: Date.now()+(this.config.invoiceTimeoutSeconds*1000),
|
|
445
448
|
id: hash.toString("hex"),
|
|
446
|
-
mtokens: amountBD
|
|
449
|
+
mtokens: amountBD * 1000n
|
|
447
450
|
};
|
|
448
451
|
metadata.invoiceRequest = hodlInvoiceObj;
|
|
449
452
|
|
|
@@ -462,7 +465,8 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
462
465
|
swapFeeInToken,
|
|
463
466
|
totalInToken,
|
|
464
467
|
secret.toString("hex"),
|
|
465
|
-
parsedBody.address
|
|
468
|
+
parsedBody.address,
|
|
469
|
+
useToken
|
|
466
470
|
);
|
|
467
471
|
metadata.times.swapCreated = Date.now();
|
|
468
472
|
createdSwap.metadata = metadata;
|
|
@@ -473,21 +477,21 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
473
477
|
|
|
474
478
|
this.swapLogger.info(createdSwap, "REST: /createInvoice: Created swap invoice: "+hodlInvoice.request+" amount: "+amountBD.toString(10));
|
|
475
479
|
|
|
476
|
-
|
|
480
|
+
res.status(200).json({
|
|
477
481
|
msg: "Success",
|
|
478
482
|
code: 10000,
|
|
479
483
|
data: {
|
|
480
484
|
pr: hodlInvoice.request,
|
|
485
|
+
amountSats: amountBD.toString(10),
|
|
486
|
+
swapFeeSats: swapFee.toString(10),
|
|
481
487
|
swapFee: swapFeeInToken.toString(10),
|
|
482
488
|
total: totalInToken.toString(10),
|
|
483
489
|
intermediaryKey: signer.getAddress()
|
|
484
490
|
}
|
|
485
491
|
});
|
|
486
|
-
|
|
487
492
|
});
|
|
488
493
|
|
|
489
|
-
restServer.
|
|
490
|
-
restServer.post(this.path+"/createInvoice", createInvoice);
|
|
494
|
+
restServer.get(this.path+"/createInvoice", createInvoice);
|
|
491
495
|
|
|
492
496
|
const getInvoiceStatus = expressHandlerWrapper(async (req, res) => {
|
|
493
497
|
/**
|
|
@@ -557,7 +561,6 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
557
561
|
}
|
|
558
562
|
};
|
|
559
563
|
});
|
|
560
|
-
restServer.post(this.path+"/getInvoiceStatus", getInvoiceStatus);
|
|
561
564
|
restServer.get(this.path+"/getInvoiceStatus", getInvoiceStatus);
|
|
562
565
|
|
|
563
566
|
this.logger.info("started at path: ", this.path);
|
|
@@ -566,10 +569,10 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
566
569
|
async init() {
|
|
567
570
|
await this.storageManager.loadData(FromBtcLnTrustedSwap);
|
|
568
571
|
//Check if all swaps contain a valid amount
|
|
569
|
-
for(let swap of await this.storageManager.query([])) {
|
|
572
|
+
for(let {obj: swap} of await this.storageManager.query([])) {
|
|
570
573
|
if(swap.amount==null) {
|
|
571
574
|
const parsedPR = await this.lightning.parsePaymentRequest(swap.pr);
|
|
572
|
-
swap.amount = parsedPR.mtokens
|
|
575
|
+
swap.amount = (parsedPR.mtokens + 999n) / 1000n;
|
|
573
576
|
}
|
|
574
577
|
}
|
|
575
578
|
await PluginManager.serviceInitialize(this);
|
|
@@ -577,19 +580,19 @@ export class FromBtcLnTrusted extends FromBtcLnBaseSwapHandler<FromBtcLnTrustedS
|
|
|
577
580
|
|
|
578
581
|
getInfoData(): any {
|
|
579
582
|
return {
|
|
580
|
-
minCltv: this.config.minCltv
|
|
581
|
-
}
|
|
583
|
+
minCltv: Number(this.config.minCltv)
|
|
584
|
+
};
|
|
582
585
|
}
|
|
583
586
|
|
|
584
|
-
protected processClaimEvent(chainIdentifier: string, event: ClaimEvent<SwapData>): Promise<void> {
|
|
587
|
+
protected processClaimEvent(chainIdentifier: string, swap: FromBtcLnTrustedSwap, event: ClaimEvent<SwapData>): Promise<void> {
|
|
585
588
|
return Promise.resolve();
|
|
586
589
|
}
|
|
587
590
|
|
|
588
|
-
protected processInitializeEvent(chainIdentifier: string, event: InitializeEvent<SwapData>): Promise<void> {
|
|
591
|
+
protected processInitializeEvent(chainIdentifier: string, swap: FromBtcLnTrustedSwap, event: InitializeEvent<SwapData>): Promise<void> {
|
|
589
592
|
return Promise.resolve();
|
|
590
593
|
}
|
|
591
594
|
|
|
592
|
-
protected processRefundEvent(chainIdentifier: string, event: RefundEvent<SwapData>): Promise<void> {
|
|
595
|
+
protected processRefundEvent(chainIdentifier: string, swap: FromBtcLnTrustedSwap, event: RefundEvent<SwapData>): Promise<void> {
|
|
593
596
|
return Promise.resolve();
|
|
594
597
|
}
|
|
595
598
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {SwapData} from "@atomiqlabs/base";
|
|
3
2
|
import {createHash} from "crypto";
|
|
4
3
|
import {FromBtcBaseSwap} from "../FromBtcBaseSwap";
|
|
@@ -17,49 +16,63 @@ export enum FromBtcLnTrustedSwapState {
|
|
|
17
16
|
export class FromBtcLnTrustedSwap<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnTrustedSwapState> {
|
|
18
17
|
|
|
19
18
|
readonly pr: string;
|
|
20
|
-
readonly output:
|
|
19
|
+
readonly output: bigint;
|
|
21
20
|
readonly dstAddress: string;
|
|
22
21
|
readonly secret: string;
|
|
22
|
+
readonly token: string;
|
|
23
23
|
|
|
24
24
|
scRawTx: string;
|
|
25
25
|
|
|
26
26
|
constructor(
|
|
27
27
|
chainIdentifier: string,
|
|
28
28
|
pr: string,
|
|
29
|
-
inputMtokens:
|
|
30
|
-
swapFee:
|
|
31
|
-
swapFeeInToken:
|
|
32
|
-
output:
|
|
29
|
+
inputMtokens: bigint,
|
|
30
|
+
swapFee: bigint,
|
|
31
|
+
swapFeeInToken: bigint,
|
|
32
|
+
output: bigint,
|
|
33
33
|
secret: string,
|
|
34
|
-
dstAddress: string
|
|
34
|
+
dstAddress: string,
|
|
35
|
+
token: string
|
|
35
36
|
);
|
|
36
37
|
constructor(obj: any);
|
|
37
38
|
|
|
38
|
-
constructor(
|
|
39
|
+
constructor(
|
|
40
|
+
chainIdOrObj: string | any,
|
|
41
|
+
pr?: string,
|
|
42
|
+
inputMtokens?: bigint,
|
|
43
|
+
swapFee?: bigint,
|
|
44
|
+
swapFeeInToken?: bigint,
|
|
45
|
+
output?: bigint,
|
|
46
|
+
secret?: string,
|
|
47
|
+
dstAddress?: string,
|
|
48
|
+
token?: string
|
|
49
|
+
) {
|
|
39
50
|
if(typeof(chainIdOrObj)==="string") {
|
|
40
|
-
super(chainIdOrObj, inputMtokens
|
|
51
|
+
super(chainIdOrObj, (inputMtokens + 999n) / 1000n, swapFee, swapFeeInToken);
|
|
41
52
|
this.state = FromBtcLnTrustedSwapState.CREATED;
|
|
42
53
|
this.pr = pr;
|
|
43
54
|
this.output = output;
|
|
44
55
|
this.secret = secret;
|
|
45
56
|
this.dstAddress = dstAddress;
|
|
57
|
+
this.token = token;
|
|
46
58
|
} else {
|
|
47
59
|
super(chainIdOrObj);
|
|
48
60
|
this.pr = chainIdOrObj.pr;
|
|
49
61
|
this.output = deserializeBN(chainIdOrObj.output);
|
|
50
62
|
this.secret = chainIdOrObj.secret;
|
|
51
63
|
this.dstAddress = chainIdOrObj.dstAddress;
|
|
64
|
+
this.token = chainIdOrObj.token;
|
|
52
65
|
this.scRawTx = chainIdOrObj.scRawTx;
|
|
53
66
|
}
|
|
54
67
|
this.type = null;
|
|
55
68
|
}
|
|
56
69
|
|
|
57
|
-
|
|
70
|
+
getClaimHash(): string {
|
|
58
71
|
return createHash("sha256").update(Buffer.from(this.secret, "hex")).digest().toString("hex");
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
getSequence():
|
|
62
|
-
return
|
|
74
|
+
getSequence(): bigint {
|
|
75
|
+
return 0n;
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
serialize(): any {
|
|
@@ -68,6 +81,7 @@ export class FromBtcLnTrustedSwap<T extends SwapData = SwapData> extends FromBtc
|
|
|
68
81
|
partialSerialized.output = serializeBN(this.output);
|
|
69
82
|
partialSerialized.secret = this.secret;
|
|
70
83
|
partialSerialized.dstAddress = this.dstAddress;
|
|
84
|
+
partialSerialized.token = this.token;
|
|
71
85
|
partialSerialized.scRawTx = this.scRawTx;
|
|
72
86
|
return partialSerialized;
|
|
73
87
|
}
|