@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.
Files changed (100) hide show
  1. package/dist/info/InfoHandler.js +3 -12
  2. package/dist/plugins/IPlugin.d.ts +34 -35
  3. package/dist/plugins/IPlugin.js +7 -8
  4. package/dist/plugins/PluginManager.d.ts +29 -30
  5. package/dist/plugins/PluginManager.js +160 -188
  6. package/dist/prices/BinanceSwapPrice.d.ts +1 -2
  7. package/dist/prices/BinanceSwapPrice.js +56 -70
  8. package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
  9. package/dist/prices/CoinGeckoSwapPrice.js +30 -42
  10. package/dist/prices/OKXSwapPrice.d.ts +1 -2
  11. package/dist/prices/OKXSwapPrice.js +56 -70
  12. package/dist/storage/IIntermediaryStorage.d.ts +8 -5
  13. package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
  14. package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
  15. package/dist/storagemanager/StorageManager.js +42 -59
  16. package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
  17. package/dist/swaps/FromBtcBaseSwap.js +2 -3
  18. package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
  19. package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
  20. package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
  21. package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
  22. package/dist/swaps/ISwapPrice.d.ts +4 -5
  23. package/dist/swaps/ISwapPrice.js +8 -30
  24. package/dist/swaps/SwapHandler.d.ts +26 -15
  25. package/dist/swaps/SwapHandler.js +107 -66
  26. package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
  27. package/dist/swaps/SwapHandlerSwap.js +32 -8
  28. package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
  29. package/dist/swaps/ToBtcBaseSwap.js +4 -4
  30. package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
  31. package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
  32. package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
  33. package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
  34. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
  35. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
  36. package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
  37. package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
  38. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
  39. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
  40. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
  41. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
  42. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
  43. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
  44. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
  45. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
  46. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
  47. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
  48. package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
  49. package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
  50. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
  51. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
  52. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
  53. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +398 -453
  54. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
  55. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
  56. package/dist/utils/Utils.d.ts +2 -3
  57. package/dist/utils/Utils.js +4 -14
  58. package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
  59. package/dist/utils/paramcoders/ParamDecoder.js +53 -65
  60. package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
  61. package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
  62. package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
  63. package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
  64. package/dist/wallets/IBitcoinWallet.d.ts +4 -5
  65. package/dist/wallets/ILightningWallet.d.ts +20 -21
  66. package/dist/wallets/ILightningWallet.js +1 -1
  67. package/package.json +4 -6
  68. package/src/plugins/IPlugin.ts +28 -29
  69. package/src/plugins/PluginManager.ts +21 -22
  70. package/src/prices/BinanceSwapPrice.ts +3 -4
  71. package/src/prices/CoinGeckoSwapPrice.ts +4 -5
  72. package/src/prices/OKXSwapPrice.ts +3 -4
  73. package/src/storage/IIntermediaryStorage.ts +4 -5
  74. package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
  75. package/src/swaps/FromBtcBaseSwap.ts +9 -10
  76. package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
  77. package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
  78. package/src/swaps/ISwapPrice.ts +10 -20
  79. package/src/swaps/SwapHandler.ts +101 -35
  80. package/src/swaps/SwapHandlerSwap.ts +42 -17
  81. package/src/swaps/ToBtcBaseSwap.ts +20 -18
  82. package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
  83. package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
  84. package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
  85. package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
  86. package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
  87. package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
  88. package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
  89. package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
  90. package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
  91. package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
  92. package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
  93. package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +106 -118
  94. package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
  95. package/src/utils/Utils.ts +3 -4
  96. package/src/utils/paramcoders/ParamDecoder.ts +5 -5
  97. package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
  98. package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
  99. package/src/wallets/IBitcoinWallet.ts +4 -5
  100. package/src/wallets/ILightningWallet.ts +21 -22
@@ -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?: BN,
29
- feePPM?: BN
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 || BN.isBN(obj.baseFee)) &&
35
- (obj.feePPM==null || BN.isBN(obj.feePPM));
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: BN, max: BN }
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" && BN.isBN(obj.data.min) && BN.isBN(obj.data.max);
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: BN, max: BN }
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" && BN.isBN(obj.data.min) && BN.isBN(obj.data.max);
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: BN},
59
- swapFee: { inInputTokens: BN, inOutputTokens: BN }
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" && BN.isBN(obj.amount.amount) &&
65
- typeof(obj.swapFee)==="object" && BN.isBN(obj.swapFee.inInputTokens) && BN.isBN(obj.swapFee.inOutputTokens);
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: BN, inOutputTokens: BN }
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" && BN.isBN(obj.networkFee.inInputTokens) && BN.isBN(obj.networkFee.inOutputTokens) &&
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: BN},
115
+ requestedAmount: {input: boolean, amount: bigint},
117
116
  chainIdentifier: string,
118
117
  token: string,
119
- constraints: {minInBtc: BN, maxInBtc: BN},
120
- fees: {baseFeeInBtc: BN, feePPM: BN}
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: BN},
123
+ requestedAmount: {input: boolean, amount: bigint},
125
124
  chainIdentifier: string,
126
125
  token: string,
127
- constraints: {minInBtc: BN, maxInBtc: BN},
128
- fees: {baseFeeInBtc: BN, feePPM: BN},
129
- pricePrefetchPromise?: Promise<BN> | null
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: BN},
133
+ requestedAmount: {input: boolean, amount: bigint},
135
134
  chainIdentifier: string,
136
135
  token: string,
137
- constraints: {minInBtc: BN, maxInBtc: BN},
138
- fees: {baseFeeInBtc: BN, feePPM: BN}
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: BN},
141
+ requestedAmount: {input: boolean, amount: bigint},
143
142
  chainIdentifier: string,
144
143
  token: string,
145
- constraints: {minInBtc: BN, maxInBtc: BN},
146
- fees: {baseFeeInBtc: BN, feePPM: BN, networkFeeGetter: (amount: BN) => Promise<BN>},
147
- pricePrefetchPromise?: Promise<BN> | null
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: BN,
35
- feePPM: BN
33
+ baseFee: bigint,
34
+ feePPM: bigint
36
35
  };
37
36
 
38
37
  export type AmountAndFeeSwapResponse = {
39
38
  type: "amountAndFee",
40
- baseFee?: BN,
41
- feePPM?: BN,
42
- amount: BN
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: BN},
170
+ requestedAmount: {input: boolean, amount: bigint},
172
171
  chainIdentifier: string,
173
172
  token: string,
174
- constraints: {minInBtc: BN, maxInBtc: BN},
175
- fees: {baseFeeInBtc: BN, feePPM: BN},
176
- pricePrefetchPromise?: Promise<BN> | null
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: BN},
201
+ requestedAmount: {input: boolean, amount: bigint},
203
202
  chainIdentifier: string,
204
203
  token: string,
205
- constraints: {minInBtc: BN, maxInBtc: BN},
206
- fees: {baseFeeInBtc: BN, feePPM: BN}
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: BN}>(
225
+ static async onHandlePostToBtcQuote<T extends {networkFee: bigint}>(
227
226
  request: RequestData<ToBtcLnRequestType | ToBtcRequestType>,
228
- requestedAmount: {input: boolean, amount: BN},
227
+ requestedAmount: {input: boolean, amount: bigint},
229
228
  chainIdentifier: string,
230
229
  token: string,
231
- constraints: {minInBtc: BN, maxInBtc: BN},
232
- fees: {baseFeeInBtc: BN, feePPM: BN, networkFeeGetter: (amount: BN) => Promise<T>},
233
- pricePrefetchPromise?: Promise<BN> | null
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: BN) => {
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: BN},
269
+ requestedAmount: {input: boolean, amount: bigint},
271
270
  chainIdentifier: string,
272
271
  token: string,
273
- constraints: {minInBtc: BN, maxInBtc: BN},
274
- fees: {baseFeeInBtc: BN, feePPM: BN}
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<BN> {
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 new BN(Math.floor(amt*1000000));
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 new BN(Math.floor(this.cache[pair].price*100000000000000));
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: BN,
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<BN> {
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 new BN(Math.floor(amt*1000));
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 = new BN(amt*1000);
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<BN> {
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 new BN(Math.floor(amt*1000000));
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 new BN(Math.floor(this.cache[pair].price*100000000000000));
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: BN | null): Promise<T>;
17
- saveData(hash: string, sequence: BN | null, object: T): Promise<void>;
18
- removeData(hash: string, sequence: BN | null): Promise<void>;
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).map((val) => this.data[val]).filter((val) => {
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: BN | null): Promise<T> {
52
- return Promise.resolve(this.data[paymentHash+"_"+(sequence || new BN(0)).toString("hex", 8)]);
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: BN | null, object: T): Promise<void> {
63
+ async saveData(hash: string, sequence: bigint | null, object: T): Promise<void> {
56
64
 
57
- const _sequence = (sequence || new BN(0)).toString("hex", 8);
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: BN | null): Promise<void> {
72
- const identifier = hash+"_"+(sequence || new BN(0)).toString("hex", 8);
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: BN;
7
+ amount: bigint;
9
8
 
10
- protected constructor(chainIdentifier: string, amount: BN, swapFee: BN, swapFeeInToken: BN);
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?: BN, swapFee?: BN, swapFeeInToken?: BN) {
12
+ protected constructor(obj?: any | string, amount?: bigint, swapFee?: bigint, swapFeeInToken?: bigint) {
14
13
  super(obj, swapFee, swapFeeInToken);
15
- if (typeof (obj) === "string" && BN.isBN(amount) && BN.isBN(swapFee) && BN.isBN(swapFeeInToken)) {
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(): BN {
23
- return this.getTotalInputAmount().sub(this.getSwapFee().inInputToken);
21
+ getInputAmount(): bigint {
22
+ return this.getTotalInputAmount() - this.getSwapFee().inInputToken;
24
23
  }
25
24
 
26
- getTotalInputAmount(): BN {
25
+ getTotalInputAmount(): bigint {
27
26
  return this.amount;
28
27
  }
29
28
 
30
- getOutputAmount(): BN {
29
+ getOutputAmount(): bigint {
31
30
  return this.data.getAmount();
32
31
  }
33
32
 
34
- getSwapFee(): { inInputToken: BN; inOutputToken: BN } {
33
+ getSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
35
34
  return {inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken};
36
35
  }
37
36