@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
@@ -1,16 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CoinGeckoSwapPrice = void 0;
13
- const BN = require("bn.js");
14
4
  const ISwapPrice_1 = require("../swaps/ISwapPrice");
15
5
  const CACHE_DURATION = 15000;
16
6
  class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
@@ -37,40 +27,38 @@ class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
37
27
  *
38
28
  * @param coin
39
29
  */
40
- getPrice(coin) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const coinId = coin.coinId;
43
- if (coinId.startsWith("$fixed-")) {
44
- const amt = parseFloat(coinId.substring(7));
45
- return new BN(Math.floor(amt * 1000));
46
- }
47
- const cachedValue = this.cache[coinId];
48
- if (cachedValue != null && cachedValue.expiry > Date.now()) {
49
- return cachedValue.price;
30
+ async getPrice(coin) {
31
+ const coinId = coin.coinId;
32
+ if (coinId.startsWith("$fixed-")) {
33
+ const amt = parseFloat(coinId.substring(7));
34
+ return BigInt(Math.floor(amt * 1000));
35
+ }
36
+ const cachedValue = this.cache[coinId];
37
+ if (cachedValue != null && cachedValue.expiry > Date.now()) {
38
+ return cachedValue.price;
39
+ }
40
+ const response = await fetch(this.url + "/simple/price?ids=" + coinId + "&vs_currencies=sats&precision=3", {
41
+ method: "GET",
42
+ headers: { 'Content-Type': 'application/json' }
43
+ });
44
+ if (response.status !== 200) {
45
+ let resp;
46
+ try {
47
+ resp = await response.text();
50
48
  }
51
- const response = yield fetch(this.url + "/simple/price?ids=" + coinId + "&vs_currencies=sats&precision=3", {
52
- method: "GET",
53
- headers: { 'Content-Type': 'application/json' }
54
- });
55
- if (response.status !== 200) {
56
- let resp;
57
- try {
58
- resp = yield response.text();
59
- }
60
- catch (e) {
61
- throw new Error(response.statusText);
62
- }
63
- throw new Error(resp);
49
+ catch (e) {
50
+ throw new Error(response.statusText);
64
51
  }
65
- let jsonBody = yield response.json();
66
- const amt = jsonBody[coinId].sats;
67
- const result = new BN(amt * 1000);
68
- this.cache[coinId] = {
69
- price: result,
70
- expiry: Date.now() + CACHE_DURATION
71
- };
72
- return result;
73
- });
52
+ throw new Error(resp);
53
+ }
54
+ let jsonBody = await response.json();
55
+ const amt = jsonBody[coinId].sats;
56
+ const result = BigInt(Math.floor(amt * 1000));
57
+ this.cache[coinId] = {
58
+ price: result,
59
+ expiry: Date.now() + CACHE_DURATION
60
+ };
61
+ return result;
74
62
  }
75
63
  }
76
64
  exports.CoinGeckoSwapPrice = CoinGeckoSwapPrice;
@@ -1,4 +1,3 @@
1
- import * as BN from "bn.js";
2
1
  import { ISwapPrice } from "../swaps/ISwapPrice";
3
2
  export type OKXPriceData = {
4
3
  [pair: string]: {
@@ -23,5 +22,5 @@ export declare class OKXSwapPrice extends ISwapPrice<{
23
22
  fetchPrice(pair: string): Promise<number>;
24
23
  getPrice(tokenData: {
25
24
  pair: string;
26
- }): Promise<BN>;
25
+ }): Promise<bigint>;
27
26
  }
@@ -1,16 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.OKXSwapPrice = void 0;
13
- const BN = require("bn.js");
14
4
  const ISwapPrice_1 = require("../swaps/ISwapPrice");
15
5
  const CACHE_DURATION = 15000;
16
6
  class OKXSwapPrice extends ISwapPrice_1.ISwapPrice {
@@ -32,75 +22,71 @@ class OKXSwapPrice extends ISwapPrice_1.ISwapPrice {
32
22
  this.cache = {};
33
23
  this.url = url || "https://www.okx.com/api/v5";
34
24
  }
35
- fetchPrice(pair) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const response = yield fetch(this.url + "/market/index-tickers?instId=" + pair, {
38
- method: "GET"
39
- });
40
- if (response.status !== 200) {
41
- let resp;
42
- try {
43
- resp = yield response.text();
44
- }
45
- catch (e) {
46
- throw new Error(response.statusText);
47
- }
48
- throw new Error(resp);
49
- }
50
- let jsonBody = yield response.json();
51
- return parseFloat(jsonBody.data[0].idxPx);
25
+ async fetchPrice(pair) {
26
+ const response = await fetch(this.url + "/market/index-tickers?instId=" + pair, {
27
+ method: "GET"
52
28
  });
53
- }
54
- getPrice(tokenData) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const pair = tokenData.pair;
57
- if (pair.startsWith("$fixed-")) {
58
- const amt = parseFloat(pair.substring(7));
59
- return new BN(Math.floor(amt * 1000000));
29
+ if (response.status !== 200) {
30
+ let resp;
31
+ try {
32
+ resp = await response.text();
60
33
  }
61
- const arr = pair.split(";");
62
- const promises = [];
63
- const cachedValue = this.cache[pair];
64
- if (cachedValue == null || cachedValue.expiry < Date.now()) {
65
- let resultPrice = 1;
66
- for (let pair of arr) {
67
- let invert = false;
68
- if (pair.startsWith("!")) {
69
- invert = true;
70
- pair = pair.substring(1);
71
- }
72
- const cachedValue = this.cache[pair];
73
- if (cachedValue == null || cachedValue.expiry < Date.now()) {
74
- promises.push(this.fetchPrice(pair).then(price => {
75
- this.cache[pair] = {
76
- price,
77
- expiry: Date.now() + CACHE_DURATION
78
- };
79
- if (invert) {
80
- resultPrice /= price;
81
- }
82
- else {
83
- resultPrice *= price;
84
- }
85
- }));
86
- }
87
- else {
34
+ catch (e) {
35
+ throw new Error(response.statusText);
36
+ }
37
+ throw new Error(resp);
38
+ }
39
+ let jsonBody = await response.json();
40
+ return parseFloat(jsonBody.data[0].idxPx);
41
+ }
42
+ async getPrice(tokenData) {
43
+ const pair = tokenData.pair;
44
+ if (pair.startsWith("$fixed-")) {
45
+ const amt = parseFloat(pair.substring(7));
46
+ return BigInt(Math.floor(amt * 1000000));
47
+ }
48
+ const arr = pair.split(";");
49
+ const promises = [];
50
+ const cachedValue = this.cache[pair];
51
+ if (cachedValue == null || cachedValue.expiry < Date.now()) {
52
+ let resultPrice = 1;
53
+ for (let pair of arr) {
54
+ let invert = false;
55
+ if (pair.startsWith("!")) {
56
+ invert = true;
57
+ pair = pair.substring(1);
58
+ }
59
+ const cachedValue = this.cache[pair];
60
+ if (cachedValue == null || cachedValue.expiry < Date.now()) {
61
+ promises.push(this.fetchPrice(pair).then(price => {
62
+ this.cache[pair] = {
63
+ price,
64
+ expiry: Date.now() + CACHE_DURATION
65
+ };
88
66
  if (invert) {
89
- resultPrice /= cachedValue.price;
67
+ resultPrice /= price;
90
68
  }
91
69
  else {
92
- resultPrice *= cachedValue.price;
70
+ resultPrice *= price;
93
71
  }
72
+ }));
73
+ }
74
+ else {
75
+ if (invert) {
76
+ resultPrice /= cachedValue.price;
77
+ }
78
+ else {
79
+ resultPrice *= cachedValue.price;
94
80
  }
95
81
  }
96
- yield Promise.all(promises);
97
- this.cache[pair] = {
98
- price: resultPrice,
99
- expiry: Date.now() + CACHE_DURATION
100
- };
101
82
  }
102
- return new BN(Math.floor(this.cache[pair].price * 100000000000000));
103
- });
83
+ await Promise.all(promises);
84
+ this.cache[pair] = {
85
+ price: resultPrice,
86
+ expiry: Date.now() + CACHE_DURATION
87
+ };
88
+ }
89
+ return BigInt(Math.floor(this.cache[pair].price * 100000000000000));
104
90
  }
105
91
  }
106
92
  exports.OKXSwapPrice = OKXSwapPrice;
@@ -1,5 +1,4 @@
1
1
  import { StorageObject } from "@atomiqlabs/base";
2
- import * as BN from "bn.js";
3
2
  export type StorageQueryParam = {
4
3
  key: string;
5
4
  value?: any;
@@ -7,9 +6,13 @@ export type StorageQueryParam = {
7
6
  };
8
7
  export interface IIntermediaryStorage<T extends StorageObject> {
9
8
  init(): Promise<void>;
10
- query(params: StorageQueryParam[]): Promise<T[]>;
11
- getData(hash: string, sequence: BN | null): Promise<T>;
12
- saveData(hash: string, sequence: BN | null, object: T): Promise<void>;
13
- removeData(hash: string, sequence: BN | null): Promise<void>;
9
+ query(params: StorageQueryParam[]): Promise<{
10
+ hash: string;
11
+ sequence: bigint;
12
+ obj: T;
13
+ }[]>;
14
+ getData(hash: string, sequence: bigint | null): Promise<T>;
15
+ saveData(hash: string, sequence: bigint | null, object: T): Promise<void>;
16
+ removeData(hash: string, sequence: bigint | null): Promise<void>;
14
17
  loadData(type: new (data: any) => T): Promise<void>;
15
18
  }
@@ -1,15 +1,18 @@
1
1
  import { StorageObject } from "@atomiqlabs/base";
2
2
  import { IIntermediaryStorage, StorageQueryParam } from "../storage/IIntermediaryStorage";
3
- import * as BN from "bn.js";
4
3
  export declare class IntermediaryStorageManager<T extends StorageObject> implements IIntermediaryStorage<T> {
5
4
  private readonly directory;
6
5
  private type;
7
6
  private data;
8
7
  constructor(directory: string);
9
8
  init(): Promise<void>;
10
- query(params: StorageQueryParam[]): Promise<T[]>;
11
- getData(paymentHash: string, sequence: BN | null): Promise<T>;
12
- saveData(hash: string, sequence: BN | null, object: T): Promise<void>;
13
- removeData(hash: string, sequence: BN | null): Promise<void>;
9
+ query(params: StorageQueryParam[]): Promise<{
10
+ hash: string;
11
+ sequence: bigint;
12
+ obj: T;
13
+ }[]>;
14
+ getData(paymentHash: string, sequence: bigint | null): Promise<T>;
15
+ saveData(hash: string, sequence: bigint | null, object: T): Promise<void>;
16
+ removeData(hash: string, sequence: bigint | null): Promise<void>;
14
17
  loadData(type: new (data: any) => T): Promise<void>;
15
18
  }
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.IntermediaryStorageManager = void 0;
13
4
  const fs = require("fs/promises");
14
- const BN = require("bn.js");
15
5
  class IntermediaryStorageManager {
16
6
  constructor(directory) {
17
7
  this.data = {};
18
8
  this.directory = directory;
19
9
  }
20
- init() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- try {
23
- yield fs.mkdir(this.directory);
24
- }
25
- catch (e) { }
26
- });
10
+ async init() {
11
+ try {
12
+ await fs.mkdir(this.directory);
13
+ }
14
+ catch (e) { }
27
15
  }
28
16
  query(params) {
29
- return Promise.resolve(Object.keys(this.data).map((val) => this.data[val]).filter((val) => {
17
+ return Promise.resolve(Object.keys(this.data).filter((key) => {
18
+ const val = this.data[key];
30
19
  for (let param of params) {
31
20
  if (param.value != null) {
32
21
  if (typeof param.value === "object") {
@@ -59,55 +48,57 @@ class IntermediaryStorageManager {
59
48
  }
60
49
  }
61
50
  return true;
51
+ }).map(key => {
52
+ const [hash, sequenceStr] = key.split("_");
53
+ const sequence = BigInt("0x" + sequenceStr);
54
+ return {
55
+ obj: this.data[key],
56
+ hash,
57
+ sequence
58
+ };
62
59
  }));
63
60
  }
64
61
  getData(paymentHash, sequence) {
65
- return Promise.resolve(this.data[paymentHash + "_" + (sequence || new BN(0)).toString("hex", 8)]);
62
+ return Promise.resolve(this.data[paymentHash + "_" + (sequence || 0n).toString(16).padStart(16, "0")]);
66
63
  }
67
- saveData(hash, sequence, object) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- const _sequence = (sequence || new BN(0)).toString("hex", 8);
70
- try {
71
- yield fs.mkdir(this.directory);
72
- }
73
- catch (e) { }
74
- this.data[hash + "_" + _sequence] = object;
75
- const cpy = object.serialize();
76
- yield fs.writeFile(this.directory + "/" + hash + "_" + _sequence + ".json", JSON.stringify(cpy));
77
- });
64
+ async saveData(hash, sequence, object) {
65
+ const _sequence = (sequence || 0n).toString(16).padStart(16, "0");
66
+ try {
67
+ await fs.mkdir(this.directory);
68
+ }
69
+ catch (e) { }
70
+ this.data[hash + "_" + _sequence] = object;
71
+ const cpy = object.serialize();
72
+ await fs.writeFile(this.directory + "/" + hash + "_" + _sequence + ".json", JSON.stringify(cpy));
78
73
  }
79
- removeData(hash, sequence) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const identifier = hash + "_" + (sequence || new BN(0)).toString("hex", 8);
82
- try {
83
- if (this.data[identifier] != null)
84
- delete this.data[identifier];
85
- yield fs.rm(this.directory + "/" + identifier + ".json");
86
- }
87
- catch (e) {
88
- console.error(e);
89
- }
90
- });
74
+ async removeData(hash, sequence) {
75
+ const identifier = hash + "_" + (sequence || 0n).toString(16).padStart(16, "0");
76
+ try {
77
+ if (this.data[identifier] != null)
78
+ delete this.data[identifier];
79
+ await fs.rm(this.directory + "/" + identifier + ".json");
80
+ }
81
+ catch (e) {
82
+ console.error(e);
83
+ }
91
84
  }
92
- loadData(type) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- this.type = type;
95
- let files;
96
- try {
97
- files = yield fs.readdir(this.directory);
98
- }
99
- catch (e) {
100
- console.error(e);
101
- return;
102
- }
103
- for (let file of files) {
104
- const indentifier = file.split(".")[0];
105
- const result = yield fs.readFile(this.directory + "/" + file);
106
- const obj = JSON.parse(result.toString());
107
- const parsed = new type(obj);
108
- this.data[indentifier] = parsed;
109
- }
110
- });
85
+ async loadData(type) {
86
+ this.type = type;
87
+ let files;
88
+ try {
89
+ files = await fs.readdir(this.directory);
90
+ }
91
+ catch (e) {
92
+ console.error(e);
93
+ return;
94
+ }
95
+ for (let file of files) {
96
+ const indentifier = file.split(".")[0];
97
+ const result = await fs.readFile(this.directory + "/" + file);
98
+ const obj = JSON.parse(result.toString());
99
+ const parsed = new type(obj);
100
+ this.data[indentifier] = parsed;
101
+ }
111
102
  }
112
103
  }
113
104
  exports.IntermediaryStorageManager = IntermediaryStorageManager;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.StorageManager = void 0;
13
4
  const fs = require("fs/promises");
@@ -16,59 +7,51 @@ class StorageManager {
16
7
  this.data = {};
17
8
  this.directory = directory;
18
9
  }
19
- init() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- try {
22
- yield fs.mkdir(this.directory);
23
- }
24
- catch (e) { }
25
- });
10
+ async init() {
11
+ try {
12
+ await fs.mkdir(this.directory);
13
+ }
14
+ catch (e) { }
26
15
  }
27
- saveData(hash, object) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- try {
30
- yield fs.mkdir(this.directory);
31
- }
32
- catch (e) { }
33
- this.data[hash] = object;
34
- const cpy = object.serialize();
35
- yield fs.writeFile(this.directory + "/" + hash + ".json", JSON.stringify(cpy));
36
- });
16
+ async saveData(hash, object) {
17
+ try {
18
+ await fs.mkdir(this.directory);
19
+ }
20
+ catch (e) { }
21
+ this.data[hash] = object;
22
+ const cpy = object.serialize();
23
+ await fs.writeFile(this.directory + "/" + hash + ".json", JSON.stringify(cpy));
37
24
  }
38
- removeData(hash) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const paymentHash = hash;
41
- try {
42
- if (this.data[paymentHash] != null)
43
- delete this.data[paymentHash];
44
- yield fs.rm(this.directory + "/" + paymentHash + ".json");
45
- }
46
- catch (e) {
47
- console.error(e);
48
- }
49
- });
25
+ async removeData(hash) {
26
+ const paymentHash = hash;
27
+ try {
28
+ if (this.data[paymentHash] != null)
29
+ delete this.data[paymentHash];
30
+ await fs.rm(this.directory + "/" + paymentHash + ".json");
31
+ }
32
+ catch (e) {
33
+ console.error(e);
34
+ }
50
35
  }
51
- loadData(type) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- let files;
54
- try {
55
- files = yield fs.readdir(this.directory);
56
- }
57
- catch (e) {
58
- console.error(e);
59
- return [];
60
- }
61
- const arr = [];
62
- for (let file of files) {
63
- const paymentHash = file.split(".")[0];
64
- const result = yield fs.readFile(this.directory + "/" + file);
65
- const obj = JSON.parse(result.toString());
66
- const parsed = new type(obj);
67
- arr.push(parsed);
68
- this.data[paymentHash] = parsed;
69
- }
70
- return arr;
71
- });
36
+ async loadData(type) {
37
+ let files;
38
+ try {
39
+ files = await fs.readdir(this.directory);
40
+ }
41
+ catch (e) {
42
+ console.error(e);
43
+ return [];
44
+ }
45
+ const arr = [];
46
+ for (let file of files) {
47
+ const paymentHash = file.split(".")[0];
48
+ const result = await fs.readFile(this.directory + "/" + file);
49
+ const obj = JSON.parse(result.toString());
50
+ const parsed = new type(obj);
51
+ arr.push(parsed);
52
+ this.data[paymentHash] = parsed;
53
+ }
54
+ return arr;
72
55
  }
73
56
  }
74
57
  exports.StorageManager = StorageManager;
@@ -1,16 +1,15 @@
1
1
  import { SwapData } from "@atomiqlabs/base";
2
2
  import { SwapHandlerSwap } from "./SwapHandlerSwap";
3
- import * as BN from "bn.js";
4
3
  export declare abstract class FromBtcBaseSwap<T extends SwapData, S = any> extends SwapHandlerSwap<T, S> {
5
- amount: BN;
6
- protected constructor(chainIdentifier: string, amount: BN, swapFee: BN, swapFeeInToken: BN);
4
+ amount: bigint;
5
+ protected constructor(chainIdentifier: string, amount: bigint, swapFee: bigint, swapFeeInToken: bigint);
7
6
  protected constructor(obj: any);
8
- getInputAmount(): BN;
9
- getTotalInputAmount(): BN;
10
- getOutputAmount(): BN;
7
+ getInputAmount(): bigint;
8
+ getTotalInputAmount(): bigint;
9
+ getOutputAmount(): bigint;
11
10
  getSwapFee(): {
12
- inInputToken: BN;
13
- inOutputToken: BN;
11
+ inInputToken: bigint;
12
+ inOutputToken: bigint;
14
13
  };
15
14
  serialize(): any;
16
15
  }
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FromBtcBaseSwap = void 0;
4
4
  const SwapHandlerSwap_1 = require("./SwapHandlerSwap");
5
- const BN = require("bn.js");
6
5
  const Utils_1 = require("../utils/Utils");
7
6
  class FromBtcBaseSwap extends SwapHandlerSwap_1.SwapHandlerSwap {
8
7
  constructor(obj, amount, swapFee, swapFeeInToken) {
9
8
  super(obj, swapFee, swapFeeInToken);
10
- if (typeof (obj) === "string" && BN.isBN(amount) && BN.isBN(swapFee) && BN.isBN(swapFeeInToken)) {
9
+ if (typeof (obj) === "string" && typeof (amount) === "bigint" && typeof (swapFee) === "bigint" && typeof (swapFeeInToken) === "bigint") {
11
10
  this.amount = amount;
12
11
  }
13
12
  else {
@@ -16,7 +15,7 @@ class FromBtcBaseSwap extends SwapHandlerSwap_1.SwapHandlerSwap {
16
15
  }
17
16
  ;
18
17
  getInputAmount() {
19
- return this.getTotalInputAmount().sub(this.getSwapFee().inInputToken);
18
+ return this.getTotalInputAmount() - this.getSwapFee().inInputToken;
20
19
  }
21
20
  getTotalInputAmount() {
22
21
  return this.amount;