@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/plugins/IPlugin.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
ToBtcRequestType
|
|
9
9
|
} from "..";
|
|
10
10
|
import {SwapHandlerSwap} from "../swaps/SwapHandlerSwap";
|
|
11
|
-
import * as BN from "bn.js";
|
|
12
11
|
import {Command} from "@atomiqlabs/server-base";
|
|
13
12
|
import {FromBtcLnTrustedRequestType} from "../swaps/frombtcln_trusted/FromBtcLnTrusted";
|
|
14
13
|
import {IBitcoinWallet} from "../wallets/IBitcoinWallet";
|
|
@@ -25,52 +24,52 @@ export function isQuoteThrow(obj: any): obj is QuoteThrow {
|
|
|
25
24
|
|
|
26
25
|
export type QuoteSetFees = {
|
|
27
26
|
type: "fees"
|
|
28
|
-
baseFee?:
|
|
29
|
-
feePPM?:
|
|
27
|
+
baseFee?: bigint,
|
|
28
|
+
feePPM?: bigint
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
export function isQuoteSetFees(obj: any): obj is QuoteSetFees {
|
|
33
32
|
return obj.type==="fees" &&
|
|
34
|
-
(obj.baseFee==null ||
|
|
35
|
-
(obj.feePPM==null ||
|
|
33
|
+
(obj.baseFee==null || typeof(obj.baseFee) === "bigint") &&
|
|
34
|
+
(obj.feePPM==null || typeof(obj.feePPM) === "bigint");
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
export type QuoteAmountTooLow = {
|
|
39
38
|
type: "low",
|
|
40
|
-
data: { min:
|
|
39
|
+
data: { min: bigint, max: bigint }
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
export function isQuoteAmountTooLow(obj: any): obj is QuoteAmountTooLow {
|
|
44
|
-
return obj.type==="low" && typeof(obj.data)==="object" &&
|
|
43
|
+
return obj.type==="low" && typeof(obj.data)==="object" && typeof(obj.data.min)==="bigint" && typeof(obj.data.max)==="bigint";
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export type QuoteAmountTooHigh = {
|
|
48
47
|
type: "high",
|
|
49
|
-
data: { min:
|
|
48
|
+
data: { min: bigint, max: bigint }
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
export function isQuoteAmountTooHigh(obj: any): obj is QuoteAmountTooHigh {
|
|
53
|
-
return obj.type==="high" && typeof(obj.data)==="object" &&
|
|
52
|
+
return obj.type==="high" && typeof(obj.data)==="object" && typeof(obj.data.min)==="bigint" && typeof(obj.data.max)==="bigint";
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
export type PluginQuote = {
|
|
57
56
|
type: "success",
|
|
58
|
-
amount: {input: boolean, amount:
|
|
59
|
-
swapFee: { inInputTokens:
|
|
57
|
+
amount: {input: boolean, amount: bigint},
|
|
58
|
+
swapFee: { inInputTokens: bigint, inOutputTokens: bigint }
|
|
60
59
|
};
|
|
61
60
|
|
|
62
61
|
export function isPluginQuote(obj: any): obj is PluginQuote {
|
|
63
62
|
return obj.type==="success" &&
|
|
64
|
-
typeof(obj.amount)==="object" && typeof(obj.amount.input)==="boolean" &&
|
|
65
|
-
typeof(obj.swapFee)==="object" &&
|
|
63
|
+
typeof(obj.amount)==="object" && typeof(obj.amount.input)==="boolean" && typeof(obj.amount.amount)==="bigint" &&
|
|
64
|
+
typeof(obj.swapFee)==="object" && typeof(obj.swapFee.inInputTokens)==="bigint" && typeof(obj.swapFee.inOutputTokens)==="bigint";
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
export type ToBtcPluginQuote = PluginQuote & {
|
|
69
|
-
networkFee: { inInputTokens:
|
|
68
|
+
networkFee: { inInputTokens: bigint, inOutputTokens: bigint }
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
export function isToBtcPluginQuote(obj: any): obj is ToBtcPluginQuote {
|
|
73
|
-
return typeof(obj.networkFee)==="object" &&
|
|
72
|
+
return typeof(obj.networkFee)==="object" && typeof(obj.networkFee.inInputTokens)==="bigint" && typeof(obj.networkFee.inOutputTokens)==="bigint" &&
|
|
74
73
|
isPluginQuote(obj);
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -113,38 +112,38 @@ export interface IPlugin {
|
|
|
113
112
|
|
|
114
113
|
onHandlePreFromBtcQuote?(
|
|
115
114
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>,
|
|
116
|
-
requestedAmount: {input: boolean, amount:
|
|
115
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
117
116
|
chainIdentifier: string,
|
|
118
117
|
token: string,
|
|
119
|
-
constraints: {minInBtc:
|
|
120
|
-
fees: {baseFeeInBtc:
|
|
118
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
119
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint}
|
|
121
120
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
122
121
|
onHandlePostFromBtcQuote?(
|
|
123
122
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>,
|
|
124
|
-
requestedAmount: {input: boolean, amount:
|
|
123
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
125
124
|
chainIdentifier: string,
|
|
126
125
|
token: string,
|
|
127
|
-
constraints: {minInBtc:
|
|
128
|
-
fees: {baseFeeInBtc:
|
|
129
|
-
pricePrefetchPromise?: Promise<
|
|
126
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
127
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint},
|
|
128
|
+
pricePrefetchPromise?: Promise<bigint> | null
|
|
130
129
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | PluginQuote>;
|
|
131
130
|
|
|
132
131
|
onHandlePreToBtcQuote?(
|
|
133
132
|
request: RequestData<ToBtcLnRequestType | ToBtcRequestType>,
|
|
134
|
-
requestedAmount: {input: boolean, amount:
|
|
133
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
135
134
|
chainIdentifier: string,
|
|
136
135
|
token: string,
|
|
137
|
-
constraints: {minInBtc:
|
|
138
|
-
fees: {baseFeeInBtc:
|
|
136
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
137
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint}
|
|
139
138
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
140
139
|
onHandlePostToBtcQuote?(
|
|
141
140
|
request: RequestData<ToBtcLnRequestType | ToBtcRequestType>,
|
|
142
|
-
requestedAmount: {input: boolean, amount:
|
|
141
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
143
142
|
chainIdentifier: string,
|
|
144
143
|
token: string,
|
|
145
|
-
constraints: {minInBtc:
|
|
146
|
-
fees: {baseFeeInBtc:
|
|
147
|
-
pricePrefetchPromise?: Promise<
|
|
144
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
145
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint, networkFeeGetter: (amount: bigint) => Promise<bigint>},
|
|
146
|
+
pricePrefetchPromise?: Promise<bigint> | null
|
|
148
147
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | ToBtcPluginQuote>;
|
|
149
148
|
|
|
150
149
|
/**
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
ToBtcRequestType
|
|
17
17
|
} from "..";
|
|
18
18
|
import {SwapHandlerSwap} from "../swaps/SwapHandlerSwap";
|
|
19
|
-
import * as BN from "bn.js";
|
|
20
19
|
import * as fs from "fs";
|
|
21
20
|
import {getLogger} from "../utils/Utils";
|
|
22
21
|
import {FromBtcLnTrustedRequestType} from "../swaps/frombtcln_trusted/FromBtcLnTrusted";
|
|
@@ -31,15 +30,15 @@ export type FailSwapResponse = {
|
|
|
31
30
|
|
|
32
31
|
export type FeeSwapResponse = {
|
|
33
32
|
type: "fee",
|
|
34
|
-
baseFee:
|
|
35
|
-
feePPM:
|
|
33
|
+
baseFee: bigint,
|
|
34
|
+
feePPM: bigint
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
export type AmountAndFeeSwapResponse = {
|
|
39
38
|
type: "amountAndFee",
|
|
40
|
-
baseFee?:
|
|
41
|
-
feePPM?:
|
|
42
|
-
amount:
|
|
39
|
+
baseFee?: bigint,
|
|
40
|
+
feePPM?: bigint,
|
|
41
|
+
amount: bigint
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
export type SwapResponse = FailSwapResponse | FeeSwapResponse | AmountAndFeeSwapResponse;
|
|
@@ -168,12 +167,12 @@ export class PluginManager {
|
|
|
168
167
|
|
|
169
168
|
static async onHandlePostFromBtcQuote(
|
|
170
169
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>,
|
|
171
|
-
requestedAmount: {input: boolean, amount:
|
|
170
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
172
171
|
chainIdentifier: string,
|
|
173
172
|
token: string,
|
|
174
|
-
constraints: {minInBtc:
|
|
175
|
-
fees: {baseFeeInBtc:
|
|
176
|
-
pricePrefetchPromise?: Promise<
|
|
173
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
174
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint},
|
|
175
|
+
pricePrefetchPromise?: Promise<bigint> | null
|
|
177
176
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | PluginQuote> {
|
|
178
177
|
for(let plugin of PluginManager.plugins.values()) {
|
|
179
178
|
try {
|
|
@@ -199,11 +198,11 @@ export class PluginManager {
|
|
|
199
198
|
|
|
200
199
|
static async onHandlePreFromBtcQuote(
|
|
201
200
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>,
|
|
202
|
-
requestedAmount: {input: boolean, amount:
|
|
201
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
203
202
|
chainIdentifier: string,
|
|
204
203
|
token: string,
|
|
205
|
-
constraints: {minInBtc:
|
|
206
|
-
fees: {baseFeeInBtc:
|
|
204
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
205
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint}
|
|
207
206
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh> {
|
|
208
207
|
for(let plugin of PluginManager.plugins.values()) {
|
|
209
208
|
try {
|
|
@@ -223,14 +222,14 @@ export class PluginManager {
|
|
|
223
222
|
return null;
|
|
224
223
|
}
|
|
225
224
|
|
|
226
|
-
static async onHandlePostToBtcQuote<T extends {networkFee:
|
|
225
|
+
static async onHandlePostToBtcQuote<T extends {networkFee: bigint}>(
|
|
227
226
|
request: RequestData<ToBtcLnRequestType | ToBtcRequestType>,
|
|
228
|
-
requestedAmount: {input: boolean, amount:
|
|
227
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
229
228
|
chainIdentifier: string,
|
|
230
229
|
token: string,
|
|
231
|
-
constraints: {minInBtc:
|
|
232
|
-
fees: {baseFeeInBtc:
|
|
233
|
-
pricePrefetchPromise?: Promise<
|
|
230
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
231
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint, networkFeeGetter: (amount: bigint) => Promise<T>},
|
|
232
|
+
pricePrefetchPromise?: Promise<bigint> | null
|
|
234
233
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | (ToBtcPluginQuote & {networkFeeData: T})> {
|
|
235
234
|
for(let plugin of PluginManager.plugins.values()) {
|
|
236
235
|
try {
|
|
@@ -239,7 +238,7 @@ export class PluginManager {
|
|
|
239
238
|
const result = await plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, {
|
|
240
239
|
baseFeeInBtc: fees.baseFeeInBtc,
|
|
241
240
|
feePPM: fees.feePPM,
|
|
242
|
-
networkFeeGetter: async (amount:
|
|
241
|
+
networkFeeGetter: async (amount: bigint) => {
|
|
243
242
|
networkFeeData = await fees.networkFeeGetter(amount);
|
|
244
243
|
return networkFeeData.networkFee;
|
|
245
244
|
}
|
|
@@ -267,11 +266,11 @@ export class PluginManager {
|
|
|
267
266
|
|
|
268
267
|
static async onHandlePreToBtcQuote(
|
|
269
268
|
request: RequestData<ToBtcLnRequestType | ToBtcRequestType>,
|
|
270
|
-
requestedAmount: {input: boolean, amount:
|
|
269
|
+
requestedAmount: {input: boolean, amount: bigint},
|
|
271
270
|
chainIdentifier: string,
|
|
272
271
|
token: string,
|
|
273
|
-
constraints: {minInBtc:
|
|
274
|
-
fees: {baseFeeInBtc:
|
|
272
|
+
constraints: {minInBtc: bigint, maxInBtc: bigint},
|
|
273
|
+
fees: {baseFeeInBtc: bigint, feePPM: bigint}
|
|
275
274
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh> {
|
|
276
275
|
for(let plugin of PluginManager.plugins.values()) {
|
|
277
276
|
try {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {ISwapPrice} from "../swaps/ISwapPrice";
|
|
3
2
|
|
|
4
3
|
const CACHE_DURATION = 15000;
|
|
@@ -59,11 +58,11 @@ export class BinanceSwapPrice extends ISwapPrice<{ pair: string, decimals: numbe
|
|
|
59
58
|
return parseFloat(jsonBody.price);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
async getPrice(tokenData: {pair: string}): Promise<
|
|
61
|
+
async getPrice(tokenData: {pair: string}): Promise<bigint> {
|
|
63
62
|
const pair = tokenData.pair;
|
|
64
63
|
if(pair.startsWith("$fixed-")) {
|
|
65
64
|
const amt: number = parseFloat(pair.substring(7));
|
|
66
|
-
return
|
|
65
|
+
return BigInt(Math.floor(amt*1000000));
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
const arr = pair.split(";");
|
|
@@ -109,6 +108,6 @@ export class BinanceSwapPrice extends ISwapPrice<{ pair: string, decimals: numbe
|
|
|
109
108
|
};
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
return
|
|
111
|
+
return BigInt(Math.floor(this.cache[pair].price*100000000000000));
|
|
113
112
|
}
|
|
114
113
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {ISwapPrice} from "../swaps/ISwapPrice";
|
|
3
2
|
|
|
4
3
|
const CACHE_DURATION = 15000;
|
|
@@ -17,7 +16,7 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
17
16
|
url: string;
|
|
18
17
|
cache: {
|
|
19
18
|
[coinId: string]: {
|
|
20
|
-
price:
|
|
19
|
+
price: bigint,
|
|
21
20
|
expiry: number
|
|
22
21
|
}
|
|
23
22
|
} = {};
|
|
@@ -44,11 +43,11 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
44
43
|
*
|
|
45
44
|
* @param coin
|
|
46
45
|
*/
|
|
47
|
-
async getPrice(coin: {coinId: string}): Promise<
|
|
46
|
+
async getPrice(coin: {coinId: string}): Promise<bigint> {
|
|
48
47
|
const coinId = coin.coinId;
|
|
49
48
|
if(coinId.startsWith("$fixed-")) {
|
|
50
49
|
const amt: number = parseFloat(coinId.substring(7));
|
|
51
|
-
return
|
|
50
|
+
return BigInt(Math.floor(amt*1000));
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
const cachedValue = this.cache[coinId];
|
|
@@ -75,7 +74,7 @@ export class CoinGeckoSwapPrice extends ISwapPrice<{coinId: string, decimals: nu
|
|
|
75
74
|
|
|
76
75
|
const amt: number = jsonBody[coinId].sats;
|
|
77
76
|
|
|
78
|
-
const result =
|
|
77
|
+
const result = BigInt(Math.floor(amt*1000));
|
|
79
78
|
|
|
80
79
|
this.cache[coinId] = {
|
|
81
80
|
price: result,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import {ISwapPrice} from "../swaps/ISwapPrice";
|
|
3
2
|
|
|
4
3
|
const CACHE_DURATION = 15000;
|
|
@@ -59,11 +58,11 @@ export class OKXSwapPrice extends ISwapPrice<{ pair: string, decimals: number }>
|
|
|
59
58
|
return parseFloat(jsonBody.data[0].idxPx);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
async getPrice(tokenData: {pair: string}): Promise<
|
|
61
|
+
async getPrice(tokenData: {pair: string}): Promise<bigint> {
|
|
63
62
|
const pair = tokenData.pair;
|
|
64
63
|
if(pair.startsWith("$fixed-")) {
|
|
65
64
|
const amt: number = parseFloat(pair.substring(7));
|
|
66
|
-
return
|
|
65
|
+
return BigInt(Math.floor(amt*1000000));
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
const arr = pair.split(";");
|
|
@@ -109,6 +108,6 @@ export class OKXSwapPrice extends ISwapPrice<{ pair: string, decimals: number }>
|
|
|
109
108
|
};
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
return
|
|
111
|
+
return BigInt(Math.floor(this.cache[pair].price*100000000000000));
|
|
113
112
|
}
|
|
114
113
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {StorageObject} from "@atomiqlabs/base";
|
|
2
|
-
import * as BN from "bn.js";
|
|
3
2
|
|
|
4
3
|
export type StorageQueryParam = {
|
|
5
4
|
key: string,
|
|
@@ -11,11 +10,11 @@ export interface IIntermediaryStorage<T extends StorageObject> {
|
|
|
11
10
|
|
|
12
11
|
init(): Promise<void>;
|
|
13
12
|
|
|
14
|
-
query(params: StorageQueryParam[]): Promise<T[]>;
|
|
13
|
+
query(params: StorageQueryParam[]): Promise<{hash: string, sequence: bigint, obj: T}[]>;
|
|
15
14
|
|
|
16
|
-
getData(hash: string, sequence:
|
|
17
|
-
saveData(hash: string, sequence:
|
|
18
|
-
removeData(hash: string, sequence:
|
|
15
|
+
getData(hash: string, sequence: bigint | null): Promise<T>;
|
|
16
|
+
saveData(hash: string, sequence: bigint | null, object: T): Promise<void>;
|
|
17
|
+
removeData(hash: string, sequence: bigint | null): Promise<void>;
|
|
19
18
|
loadData(type: new(data: any) => T): Promise<void>;
|
|
20
19
|
|
|
21
20
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {StorageObject} from "@atomiqlabs/base";
|
|
2
2
|
import * as fs from "fs/promises";
|
|
3
3
|
import {IIntermediaryStorage, StorageQueryParam} from "../storage/IIntermediaryStorage";
|
|
4
|
-
import * as BN from "bn.js";
|
|
5
4
|
|
|
6
5
|
export class IntermediaryStorageManager<T extends StorageObject> implements IIntermediaryStorage<T> {
|
|
7
6
|
|
|
@@ -21,8 +20,9 @@ export class IntermediaryStorageManager<T extends StorageObject> implements IInt
|
|
|
21
20
|
} catch (e) {}
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
query(params: StorageQueryParam[]): Promise<T[]> {
|
|
25
|
-
return Promise.resolve(Object.keys(this.data).
|
|
23
|
+
query(params: StorageQueryParam[]): Promise<{hash: string, sequence: bigint, obj: T}[]> {
|
|
24
|
+
return Promise.resolve(Object.keys(this.data).filter((key) => {
|
|
25
|
+
const val = this.data[key];
|
|
26
26
|
for(let param of params) {
|
|
27
27
|
if(param.value!=null) {
|
|
28
28
|
if(typeof param.value === "object") {
|
|
@@ -45,16 +45,24 @@ export class IntermediaryStorageManager<T extends StorageObject> implements IInt
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return true;
|
|
48
|
+
}).map(key => {
|
|
49
|
+
const [hash, sequenceStr] = key.split("_");
|
|
50
|
+
const sequence = BigInt("0x"+sequenceStr);
|
|
51
|
+
return {
|
|
52
|
+
obj: this.data[key],
|
|
53
|
+
hash,
|
|
54
|
+
sequence
|
|
55
|
+
}
|
|
48
56
|
}));
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
getData(paymentHash: string, sequence:
|
|
52
|
-
return Promise.resolve(this.data[paymentHash+"_"+(sequence ||
|
|
59
|
+
getData(paymentHash: string, sequence: bigint | null): Promise<T> {
|
|
60
|
+
return Promise.resolve(this.data[paymentHash+"_"+(sequence || 0n).toString(16).padStart(16, "0")]);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
async saveData(hash: string, sequence:
|
|
63
|
+
async saveData(hash: string, sequence: bigint | null, object: T): Promise<void> {
|
|
56
64
|
|
|
57
|
-
const _sequence = (sequence ||
|
|
65
|
+
const _sequence = (sequence || 0n).toString(16).padStart(16, "0");
|
|
58
66
|
|
|
59
67
|
try {
|
|
60
68
|
await fs.mkdir(this.directory)
|
|
@@ -68,8 +76,8 @@ export class IntermediaryStorageManager<T extends StorageObject> implements IInt
|
|
|
68
76
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
|
-
async removeData(hash: string, sequence:
|
|
72
|
-
const identifier = hash+"_"+(sequence ||
|
|
79
|
+
async removeData(hash: string, sequence: bigint | null): Promise<void> {
|
|
80
|
+
const identifier = hash+"_"+(sequence || 0n).toString(16).padStart(16, "0");
|
|
73
81
|
try {
|
|
74
82
|
if(this.data[identifier]!=null) delete this.data[identifier];
|
|
75
83
|
await fs.rm(this.directory+"/"+identifier+".json");
|
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
import {SwapData} from "@atomiqlabs/base";
|
|
2
2
|
import {SwapHandlerSwap} from "./SwapHandlerSwap";
|
|
3
|
-
import * as BN from "bn.js";
|
|
4
3
|
import {deserializeBN, serializeBN} from "../utils/Utils";
|
|
5
4
|
|
|
6
5
|
export abstract class FromBtcBaseSwap<T extends SwapData, S = any> extends SwapHandlerSwap<T, S> {
|
|
7
6
|
|
|
8
|
-
amount:
|
|
7
|
+
amount: bigint;
|
|
9
8
|
|
|
10
|
-
protected constructor(chainIdentifier: string, amount:
|
|
9
|
+
protected constructor(chainIdentifier: string, amount: bigint, swapFee: bigint, swapFeeInToken: bigint);
|
|
11
10
|
protected constructor(obj: any);
|
|
12
11
|
|
|
13
|
-
protected constructor(obj?: any | string, amount?:
|
|
12
|
+
protected constructor(obj?: any | string, amount?: bigint, swapFee?: bigint, swapFeeInToken?: bigint) {
|
|
14
13
|
super(obj, swapFee, swapFeeInToken);
|
|
15
|
-
if (typeof (obj) === "string" &&
|
|
14
|
+
if (typeof (obj) === "string" && typeof(amount)==="bigint" && typeof(swapFee)==="bigint" && typeof(swapFeeInToken)==="bigint") {
|
|
16
15
|
this.amount = amount;
|
|
17
16
|
} else {
|
|
18
17
|
this.amount = deserializeBN(obj.amount);
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
getInputAmount():
|
|
23
|
-
return this.getTotalInputAmount()
|
|
21
|
+
getInputAmount(): bigint {
|
|
22
|
+
return this.getTotalInputAmount() - this.getSwapFee().inInputToken;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
getTotalInputAmount():
|
|
25
|
+
getTotalInputAmount(): bigint {
|
|
27
26
|
return this.amount;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
getOutputAmount():
|
|
29
|
+
getOutputAmount(): bigint {
|
|
31
30
|
return this.data.getAmount();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
getSwapFee(): { inInputToken:
|
|
33
|
+
getSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
35
34
|
return {inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken};
|
|
36
35
|
}
|
|
37
36
|
|