@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
package/src/utils/Utils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {Request, Response} from "express";
|
|
2
2
|
import {ServerParamEncoder} from "./paramcoders/server/ServerParamEncoder";
|
|
3
|
-
import * as BN from "bn.js";
|
|
4
3
|
|
|
5
4
|
export type DefinedRuntimeError = {
|
|
6
5
|
code: number;
|
|
@@ -68,10 +67,10 @@ export function getLogger(prefix: string) {
|
|
|
68
67
|
|
|
69
68
|
export const HEX_REGEX = /[0-9a-fA-F]+/;
|
|
70
69
|
|
|
71
|
-
export function serializeBN(bn:
|
|
70
|
+
export function serializeBN(bn: bigint | null): string | null {
|
|
72
71
|
return bn==null ? null : bn.toString(10);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
export function deserializeBN(str: string | null):
|
|
76
|
-
return str==null ? null :
|
|
74
|
+
export function deserializeBN(str: string | null): bigint | null {
|
|
75
|
+
return str==null ? null : BigInt(str);
|
|
77
76
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {FieldTypeEnum,
|
|
1
|
+
import {FieldTypeEnum, parseBigInt, RequestSchema, RequestSchemaResult, verifySchema} from "./SchemaVerifier";
|
|
2
2
|
import {IParamReader} from "./IParamReader";
|
|
3
3
|
|
|
4
4
|
|
|
@@ -155,8 +155,8 @@ export class ParamDecoder implements IParamReader {
|
|
|
155
155
|
if(typeof(val)!=="number") return null;
|
|
156
156
|
if(isNaN(val as number)) return null;
|
|
157
157
|
resultSchema[fieldName] = val;
|
|
158
|
-
} else if(type===FieldTypeEnum.
|
|
159
|
-
const result =
|
|
158
|
+
} else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
|
|
159
|
+
const result = parseBigInt(val);
|
|
160
160
|
if(result==null) return null;
|
|
161
161
|
resultSchema[fieldName] = result;
|
|
162
162
|
} else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
|
|
@@ -199,8 +199,8 @@ export class ParamDecoder implements IParamReader {
|
|
|
199
199
|
if(typeof(val)!=="number") return null;
|
|
200
200
|
if(isNaN(val as number)) return null;
|
|
201
201
|
resultSchema[fieldName] = val;
|
|
202
|
-
} else if(type===FieldTypeEnum.
|
|
203
|
-
const result =
|
|
202
|
+
} else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
|
|
203
|
+
const result = parseBigInt(val);
|
|
204
204
|
if(result==null) return null;
|
|
205
205
|
resultSchema[fieldName] = result;
|
|
206
206
|
} else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
|
|
3
|
-
export function
|
|
2
|
+
export function parseBigInt(str: string | number): bigint | null {
|
|
4
3
|
if(str==null) return null;
|
|
5
4
|
if(typeof(str)!=="string" && typeof(str)!=="number") return null;
|
|
6
5
|
try {
|
|
7
|
-
return
|
|
6
|
+
return BigInt(str);
|
|
8
7
|
} catch (e) {
|
|
9
8
|
return null;
|
|
10
9
|
}
|
|
@@ -14,32 +13,32 @@ export enum FieldTypeEnum {
|
|
|
14
13
|
String=0,
|
|
15
14
|
Boolean=1,
|
|
16
15
|
Number=2,
|
|
17
|
-
|
|
16
|
+
BigInt=3,
|
|
18
17
|
Any=4,
|
|
19
18
|
|
|
20
19
|
StringOptional=100,
|
|
21
20
|
BooleanOptional=101,
|
|
22
21
|
NumberOptional=102,
|
|
23
|
-
|
|
22
|
+
BigIntOptional=103,
|
|
24
23
|
AnyOptional=104,
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number |
|
|
26
|
+
export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number | bigint | any))> =
|
|
28
27
|
T extends FieldTypeEnum.String ? string :
|
|
29
28
|
T extends FieldTypeEnum.Boolean ? boolean :
|
|
30
29
|
T extends FieldTypeEnum.Number ? number :
|
|
31
|
-
T extends FieldTypeEnum.
|
|
30
|
+
T extends FieldTypeEnum.BigInt ? bigint :
|
|
32
31
|
T extends FieldTypeEnum.Any ? any :
|
|
33
32
|
T extends FieldTypeEnum.StringOptional ? string :
|
|
34
33
|
T extends FieldTypeEnum.BooleanOptional ? boolean :
|
|
35
34
|
T extends FieldTypeEnum.NumberOptional ? number :
|
|
36
|
-
T extends FieldTypeEnum.
|
|
35
|
+
T extends FieldTypeEnum.BigIntOptional ? bigint :
|
|
37
36
|
T extends FieldTypeEnum.AnyOptional ? any :
|
|
38
37
|
T extends RequestSchema ? RequestSchemaResult<T> :
|
|
39
38
|
T extends ((val: any) => string) ? string :
|
|
40
39
|
T extends ((val: any) => boolean) ? boolean :
|
|
41
40
|
T extends ((val: any) => number) ? number :
|
|
42
|
-
T extends ((val: any) =>
|
|
41
|
+
T extends ((val: any) => bigint) ? bigint :
|
|
43
42
|
T extends ((val: any) => any) ? any :
|
|
44
43
|
never;
|
|
45
44
|
|
|
@@ -79,8 +78,8 @@ export function verifySchema<T extends RequestSchema>(req: any, schema: T): Requ
|
|
|
79
78
|
if(typeof(val)!=="number") return null;
|
|
80
79
|
if(isNaN(val as number)) return null;
|
|
81
80
|
resultSchema[fieldName] = val;
|
|
82
|
-
} else if(type===FieldTypeEnum.
|
|
83
|
-
const result =
|
|
81
|
+
} else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
|
|
82
|
+
const result = parseBigInt(val);
|
|
84
83
|
if(result==null) return null;
|
|
85
84
|
resultSchema[fieldName] = result;
|
|
86
85
|
} else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
|
|
@@ -38,7 +38,7 @@ export const serverParamDecoder = (timeoutMillis: number) => (req: Request, res:
|
|
|
38
38
|
});
|
|
39
39
|
req.on("end", () => {
|
|
40
40
|
try {
|
|
41
|
-
const body = JSON.parse(Buffer.concat(dataBuffers).toString());
|
|
41
|
+
const body = dataBuffers.length===0 ? {} : JSON.parse(Buffer.concat(dataBuffers).toString());
|
|
42
42
|
const paramReader: IParamReader = {
|
|
43
43
|
getParams: <T extends RequestSchema>(schema: T) => {
|
|
44
44
|
return Promise.resolve(verifySchema(body, schema));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
|
-
import {Psbt, Transaction} from "bitcoinjs-lib";
|
|
3
1
|
import {BtcTx} from "@atomiqlabs/base";
|
|
4
2
|
import {Command} from "@atomiqlabs/server-base";
|
|
3
|
+
import {Transaction} from "@scure/btc-signer";
|
|
5
4
|
|
|
6
5
|
export type BitcoinUtxo = {
|
|
7
6
|
address: string,
|
|
@@ -14,7 +13,7 @@ export type BitcoinUtxo = {
|
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
export type SignPsbtResponse = {
|
|
17
|
-
psbt:
|
|
16
|
+
psbt: Transaction,
|
|
18
17
|
tx: Transaction,
|
|
19
18
|
raw: string,
|
|
20
19
|
txId: string,
|
|
@@ -53,9 +52,9 @@ export interface IBitcoinWallet {
|
|
|
53
52
|
getWalletTransaction(txId: string): Promise<BtcTx | null>;
|
|
54
53
|
subscribeToWalletTransactions(callback: (tx: BtcTx) => void, abortSignal?: AbortSignal): void;
|
|
55
54
|
|
|
56
|
-
signPsbt(psbt:
|
|
55
|
+
signPsbt(psbt: Transaction): Promise<SignPsbtResponse>;
|
|
57
56
|
sendRawTransaction(tx: string): Promise<void>;
|
|
58
|
-
getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?:
|
|
57
|
+
getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?: bigint, maxAllowedFeeRate?: number): Promise<SignPsbtResponse>;
|
|
59
58
|
estimateFee(destination: string, amount: number, feeRate?: number, feeRateMultiplier?: number): Promise<{satsPerVbyte: number, networkFee: number}>;
|
|
60
59
|
drainAll(destination: string | Buffer, inputs: Omit<BitcoinUtxo, "address">[], feeRate?: number): Promise<SignPsbtResponse>;
|
|
61
60
|
burnAll(inputs: Omit<BitcoinUtxo, "address">[]): Promise<SignPsbtResponse>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {Command} from "@atomiqlabs/server-base";
|
|
3
2
|
|
|
4
3
|
export type IncomingLightningNetworkPayment = {
|
|
@@ -10,7 +9,7 @@ export type IncomingLightningNetworkPayment = {
|
|
|
10
9
|
|
|
11
10
|
status: "held" | "canceled" | "confirmed"
|
|
12
11
|
|
|
13
|
-
mtokens:
|
|
12
|
+
mtokens: bigint
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export type LightningNetworkInvoice = {
|
|
@@ -19,7 +18,7 @@ export type LightningNetworkInvoice = {
|
|
|
19
18
|
secret?: string,
|
|
20
19
|
|
|
21
20
|
cltvDelta: number,
|
|
22
|
-
mtokens:
|
|
21
|
+
mtokens: bigint,
|
|
23
22
|
|
|
24
23
|
createdAt: number,
|
|
25
24
|
expiresAt: number,
|
|
@@ -36,25 +35,25 @@ export type OutgoingLightningNetworkPayment = {
|
|
|
36
35
|
failedReason?: "insufficient_balance" | "invalid_payment" | "pathfinding_timeout" | "route_not_found",
|
|
37
36
|
status: "confirmed" | "failed" | "pending",
|
|
38
37
|
secret?: string,
|
|
39
|
-
feeMtokens?:
|
|
38
|
+
feeMtokens?: bigint
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
export type LightningNetworkChannel = {
|
|
43
42
|
id: string,
|
|
44
|
-
capacity:
|
|
43
|
+
capacity: bigint,
|
|
45
44
|
isActive: boolean,
|
|
46
45
|
|
|
47
|
-
localBalance:
|
|
48
|
-
localReserve:
|
|
49
|
-
remoteBalance:
|
|
50
|
-
remoteReserve:
|
|
51
|
-
unsettledBalance:
|
|
46
|
+
localBalance: bigint,
|
|
47
|
+
localReserve: bigint,
|
|
48
|
+
remoteBalance: bigint,
|
|
49
|
+
remoteReserve: bigint,
|
|
50
|
+
unsettledBalance: bigint,
|
|
52
51
|
transactionId: string,
|
|
53
52
|
transactionVout: number
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export type InvoiceInit = {
|
|
57
|
-
mtokens:
|
|
56
|
+
mtokens: bigint,
|
|
58
57
|
descriptionHash?: string
|
|
59
58
|
description?: string,
|
|
60
59
|
cltvDelta?: number,
|
|
@@ -66,7 +65,7 @@ export type HodlInvoiceInit = {
|
|
|
66
65
|
cltvDelta: number,
|
|
67
66
|
expiresAt: number,
|
|
68
67
|
id: string,
|
|
69
|
-
mtokens:
|
|
68
|
+
mtokens: bigint,
|
|
70
69
|
descriptionHash?: string
|
|
71
70
|
};
|
|
72
71
|
|
|
@@ -75,12 +74,12 @@ export type LNRoutes = {
|
|
|
75
74
|
feeRate?: number,
|
|
76
75
|
cltvDelta?: number,
|
|
77
76
|
channel?: string,
|
|
78
|
-
baseFeeMtokens?:
|
|
77
|
+
baseFeeMtokens?: bigint
|
|
79
78
|
}[][];
|
|
80
79
|
|
|
81
80
|
export type ParsedPaymentRequest = {
|
|
82
81
|
id: string,
|
|
83
|
-
mtokens:
|
|
82
|
+
mtokens: bigint,
|
|
84
83
|
expiryEpochMillis: number,
|
|
85
84
|
destination: string,
|
|
86
85
|
cltvDelta: number,
|
|
@@ -90,26 +89,26 @@ export type ParsedPaymentRequest = {
|
|
|
90
89
|
|
|
91
90
|
export type LightningPaymentInit = {
|
|
92
91
|
request: string,
|
|
93
|
-
maxFeeMtokens?:
|
|
92
|
+
maxFeeMtokens?: bigint,
|
|
94
93
|
maxTimeoutHeight?: number
|
|
95
94
|
};
|
|
96
95
|
|
|
97
96
|
export type LightningBalanceResponse = {
|
|
98
|
-
localBalance:
|
|
99
|
-
remoteBalance:
|
|
100
|
-
unsettledBalance:
|
|
97
|
+
localBalance: bigint,
|
|
98
|
+
remoteBalance: bigint,
|
|
99
|
+
unsettledBalance: bigint
|
|
101
100
|
};
|
|
102
101
|
|
|
103
102
|
export type ProbeAndRouteInit = {
|
|
104
103
|
request: string,
|
|
105
|
-
amountMtokens:
|
|
106
|
-
maxFeeMtokens:
|
|
104
|
+
amountMtokens: bigint,
|
|
105
|
+
maxFeeMtokens: bigint,
|
|
107
106
|
maxTimeoutHeight: number
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
export type ProbeAndRouteResponse = {
|
|
111
110
|
confidence: number,
|
|
112
|
-
feeMtokens:
|
|
111
|
+
feeMtokens: bigint,
|
|
113
112
|
destination: string,
|
|
114
113
|
privateRoutes: LNRoutes
|
|
115
114
|
}
|
|
@@ -133,7 +132,7 @@ export function routesMatch(routesA: LNRoutes, routesB: LNRoutes) {
|
|
|
133
132
|
}
|
|
134
133
|
if(
|
|
135
134
|
routesA[i][e].publicKey!==routesB[i][e].publicKey ||
|
|
136
|
-
|
|
135
|
+
routesA[i][e].baseFeeMtokens!==routesB[i][e].baseFeeMtokens ||
|
|
137
136
|
routesA[i][e].channel!==routesB[i][e].channel ||
|
|
138
137
|
routesA[i][e].cltvDelta!==routesB[i][e].cltvDelta ||
|
|
139
138
|
routesA[i][e].feeRate!==routesB[i][e].feeRate
|