@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.
- package/dist/BSAggregator.js +4 -15
- package/dist/features/bridge/Neo3NeoXBridgeOrchestrator.js +245 -241
- package/dist/features/swap/SimpleSwapApi.js +114 -144
- package/dist/features/swap/SimpleSwapOrchestrator.js +273 -295
- package/dist/features/swap/SimpleSwapService.js +20 -31
- package/dist/features/wallet-connect/WalletKitHelper.js +19 -32
- package/package.json +15 -18
|
@@ -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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
|
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
|
|
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
|
|
223
|
-
let hash =
|
|
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
|
|
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();
|