@cityofzion/bs-multichain 3.0.4 → 3.0.5

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.
@@ -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
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -39,148 +30,130 @@ class SimpleSwapApi {
39
30
  _SimpleSwapApi_apiInstance.set(this, void 0);
40
31
  _SimpleSwapApi_allCurrenciesMap.set(this, new Map());
41
32
  }
42
- getCurrencies(options) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- var _a;
45
- try {
46
- if (__classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").size) {
47
- return Array.from(__classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").values());
48
- }
49
- const response = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/currencies');
50
- const tokens = [];
51
- response.data.result.forEach(currency => {
52
- const token = __classPrivateFieldGet(this, _SimpleSwapApi_instances, "m", _SimpleSwapApi_getTokenFromCurrency).call(this, currency, options);
53
- if (!token)
54
- return;
55
- __classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").set(`${token.ticker}:${token.network}`, token);
56
- if (!token.blockchain)
57
- return;
58
- tokens.push(token);
59
- });
60
- return tokens;
61
- }
62
- catch (error) {
63
- if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message)) {
64
- throw new Error(error.response.data.message);
65
- }
66
- throw error;
33
+ async getCurrencies(options) {
34
+ try {
35
+ if (__classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").size) {
36
+ return Array.from(__classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").values());
67
37
  }
68
- });
69
- }
70
- getPairs(ticker, network) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- var _a, _b;
73
- try {
74
- const response = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get(`/pairs/${ticker}/${network}`);
75
- const pairs = (_a = response.data.result[`${ticker}:${network}`]) !== null && _a !== void 0 ? _a : [];
76
- const tokens = [];
77
- pairs.forEach(pair => {
78
- const token = __classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").get(pair);
79
- if (token)
80
- tokens.push(token);
81
- });
82
- return tokens;
83
- }
84
- catch (error) {
85
- if (axios_1.default.isAxiosError(error) && ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data.message)) {
86
- throw new Error(error.response.data.message);
87
- }
88
- throw error;
38
+ const response = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/currencies');
39
+ const tokens = [];
40
+ response.data.result.forEach(currency => {
41
+ const token = __classPrivateFieldGet(this, _SimpleSwapApi_instances, "m", _SimpleSwapApi_getTokenFromCurrency).call(this, currency, options);
42
+ if (!token)
43
+ return;
44
+ __classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").set(`${token.ticker}:${token.network}`, token);
45
+ if (!token.blockchain)
46
+ return;
47
+ tokens.push(token);
48
+ });
49
+ return tokens;
50
+ }
51
+ catch (error) {
52
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
53
+ throw new Error(error.response.data.message);
89
54
  }
90
- });
55
+ throw error;
56
+ }
91
57
  }
92
- getRange(currencyFrom, currencyTo) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- var _a;
95
- try {
96
- const response = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/ranges', {
97
- params: {
98
- tickerFrom: currencyFrom.ticker,
99
- tickerTo: currencyTo.ticker,
100
- networkFrom: currencyFrom.network,
101
- networkTo: currencyTo.network,
102
- },
103
- });
104
- return response.data.result;
105
- }
106
- catch (error) {
107
- if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message)) {
108
- throw new Error(error.response.data.message);
109
- }
110
- throw error;
58
+ async getPairs(ticker, network) {
59
+ try {
60
+ const response = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get(`/pairs/${ticker}/${network}`);
61
+ const pairs = response.data.result[`${ticker}:${network}`] ?? [];
62
+ const tokens = [];
63
+ pairs.forEach(pair => {
64
+ const token = __classPrivateFieldGet(this, _SimpleSwapApi_allCurrenciesMap, "f").get(pair);
65
+ if (token)
66
+ tokens.push(token);
67
+ });
68
+ return tokens;
69
+ }
70
+ catch (error) {
71
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
72
+ throw new Error(error.response.data.message);
111
73
  }
112
- });
74
+ throw error;
75
+ }
113
76
  }
114
- getEstimate(currencyFrom, currencyTo, amount) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- var _a;
117
- try {
118
- const response = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/estimates', {
119
- params: {
120
- tickerFrom: currencyFrom.ticker,
121
- tickerTo: currencyTo.ticker,
122
- networkFrom: currencyFrom.network,
123
- networkTo: currencyTo.network,
124
- amount,
125
- },
126
- });
127
- return response.data.result.estimatedAmount;
128
- }
129
- catch (error) {
130
- if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message)) {
131
- throw new Error(error.response.data.message);
132
- }
133
- throw error;
77
+ async getRange(currencyFrom, currencyTo) {
78
+ try {
79
+ const response = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/ranges', {
80
+ params: {
81
+ tickerFrom: currencyFrom.ticker,
82
+ tickerTo: currencyTo.ticker,
83
+ networkFrom: currencyFrom.network,
84
+ networkTo: currencyTo.network,
85
+ },
86
+ });
87
+ return response.data.result;
88
+ }
89
+ catch (error) {
90
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
91
+ throw new Error(error.response.data.message);
134
92
  }
135
- });
93
+ throw error;
94
+ }
136
95
  }
137
- createExchange(_a) {
138
- return __awaiter(this, arguments, void 0, function* ({ currencyFrom, currencyTo, amount, refundAddress, address, extraIdToReceive, }) {
139
- var _b, _c;
140
- try {
141
- const { data: { result }, } = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).post('/exchanges', {
96
+ async getEstimate(currencyFrom, currencyTo, amount) {
97
+ try {
98
+ const response = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get('/estimates', {
99
+ params: {
142
100
  tickerFrom: currencyFrom.ticker,
143
- networkFrom: currencyFrom.network,
144
101
  tickerTo: currencyTo.ticker,
102
+ networkFrom: currencyFrom.network,
145
103
  networkTo: currencyTo.network,
146
104
  amount,
147
- userRefundAddress: refundAddress,
148
- addressTo: address,
149
- extraIdTo: (_b = extraIdToReceive === null || extraIdToReceive === void 0 ? void 0 : extraIdToReceive.trim()) !== null && _b !== void 0 ? _b : null,
150
- });
151
- return {
152
- id: result.id,
153
- depositAddress: result.addressFrom,
154
- log: JSON.stringify(result),
155
- };
156
- }
157
- catch (error) {
158
- if (axios_1.default.isAxiosError(error) && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data.message)) {
159
- throw new Error(error.response.data.message);
160
- }
161
- throw error;
105
+ },
106
+ });
107
+ return response.data.result.estimatedAmount;
108
+ }
109
+ catch (error) {
110
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
111
+ throw new Error(error.response.data.message);
162
112
  }
163
- });
113
+ throw error;
114
+ }
164
115
  }
165
- getExchange(id) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- var _a;
168
- try {
169
- const { data: { result }, } = yield __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get(`/exchanges/${id}`);
170
- return {
171
- status: result.status,
172
- txFrom: result.txFrom,
173
- txTo: result.txTo,
174
- log: JSON.stringify(result),
175
- };
116
+ async createExchange({ currencyFrom, currencyTo, amount, refundAddress, address, extraIdToReceive, }) {
117
+ try {
118
+ const { data: { result }, } = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).post('/exchanges', {
119
+ tickerFrom: currencyFrom.ticker,
120
+ networkFrom: currencyFrom.network,
121
+ tickerTo: currencyTo.ticker,
122
+ networkTo: currencyTo.network,
123
+ amount,
124
+ userRefundAddress: refundAddress,
125
+ addressTo: address,
126
+ extraIdTo: extraIdToReceive?.trim() ?? null,
127
+ });
128
+ return {
129
+ id: result.id,
130
+ depositAddress: result.addressFrom,
131
+ log: JSON.stringify(result),
132
+ };
133
+ }
134
+ catch (error) {
135
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
136
+ throw new Error(error.response.data.message);
176
137
  }
177
- catch (error) {
178
- if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data.message)) {
179
- throw new Error(error.response.data.message);
180
- }
181
- throw error;
138
+ throw error;
139
+ }
140
+ }
141
+ async getExchange(id) {
142
+ try {
143
+ const { data: { result }, } = await __classPrivateFieldGet(this, _SimpleSwapApi_instances, "a", _SimpleSwapApi_api_get).get(`/exchanges/${id}`);
144
+ return {
145
+ status: result.status,
146
+ txFrom: result.txFrom,
147
+ txTo: result.txTo,
148
+ log: JSON.stringify(result),
149
+ };
150
+ }
151
+ catch (error) {
152
+ if (axios_1.default.isAxiosError(error) && error.response?.data.message) {
153
+ throw new Error(error.response.data.message);
182
154
  }
183
- });
155
+ throw error;
156
+ }
184
157
  }
185
158
  }
186
159
  exports.SimpleSwapApi = SimpleSwapApi;
@@ -197,19 +170,16 @@ _SimpleSwapApi_tickersBySimpleSwapBlockchain = new WeakMap(), _SimpleSwapApi_api
197
170
  }
198
171
  return __classPrivateFieldGet(this, _SimpleSwapApi_apiInstance, "f");
199
172
  }, _SimpleSwapApi_createAddressTemplateUrl = function _SimpleSwapApi_createAddressTemplateUrl(blockchainService, explorer) {
200
- var _a;
201
173
  explorer = !explorer ? undefined : explorer.replace('{}', '{address}');
202
174
  if (blockchainService && (0, blockchain_service_1.hasExplorerService)(blockchainService))
203
- return (_a = blockchainService.explorerService.getAddressTemplateUrl()) !== null && _a !== void 0 ? _a : explorer;
175
+ return blockchainService.explorerService.getAddressTemplateUrl() ?? explorer;
204
176
  return explorer;
205
177
  }, _SimpleSwapApi_createTxTemplateUrl = function _SimpleSwapApi_createTxTemplateUrl(blockchainService, explorer) {
206
- var _a;
207
178
  explorer = !explorer ? undefined : explorer.replace('{}', '{txId}');
208
179
  if (blockchainService && (0, blockchain_service_1.hasExplorerService)(blockchainService))
209
- return (_a = blockchainService.explorerService.getTxTemplateUrl()) !== null && _a !== void 0 ? _a : explorer;
180
+ return blockchainService.explorerService.getTxTemplateUrl() ?? explorer;
210
181
  return explorer;
211
182
  }, _SimpleSwapApi_getTokenFromCurrency = function _SimpleSwapApi_getTokenFromCurrency(currency, options) {
212
- var _a;
213
183
  const { network: simpleSwapBlockchain, ticker, precision } = currency;
214
184
  let { name } = currency;
215
185
  let symbol = ticker;
@@ -219,15 +189,15 @@ _SimpleSwapApi_tickersBySimpleSwapBlockchain = new WeakMap(), _SimpleSwapApi_api
219
189
  const chainsByServiceNameEntry = chainsByServiceNameEntries.find(([_serviceName, chains]) => chains.includes(simpleSwapBlockchain));
220
190
  let blockchain;
221
191
  let blockchainService;
222
- let decimals = precision !== null && precision !== void 0 ? precision : undefined;
223
- let hash = (_a = currency.contractAddress) !== null && _a !== void 0 ? _a : undefined;
192
+ let decimals = precision ?? undefined;
193
+ let hash = currency.contractAddress ?? undefined;
224
194
  const lowerCaseSymbol = symbol.toLowerCase();
225
195
  const tickers = __classPrivateFieldGet(this, _SimpleSwapApi_tickersBySimpleSwapBlockchain, "f")[simpleSwapBlockchain];
226
196
  if (chainsByServiceNameEntry) {
227
197
  blockchain = chainsByServiceNameEntry[0];
228
198
  blockchainService = options.blockchainServicesByName[blockchain];
229
199
  const normalizedHash = hash && blockchainService ? blockchainService.tokenService.normalizeHash(hash) : '';
230
- const token = blockchainService === null || blockchainService === void 0 ? void 0 : blockchainService.tokens.find(item => {
200
+ const token = blockchainService?.tokens.find(item => {
231
201
  if (normalizedHash && blockchainService && blockchainService.tokenService.predicateByHash(item, normalizedHash))
232
202
  return true;
233
203
  const currentLowerCaseSymbol = item.symbol.toLowerCase();