@pioneer-platform/helpers 4.0.12 → 4.1.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/CHANGELOG.md +12 -0
- package/lib/helpers/asset.d.ts +1 -1
- package/lib/helpers/asset.js +83 -145
- package/lib/helpers/liquidity.js +52 -73
- package/lib/helpers/memo.js +19 -22
- package/lib/helpers/others.js +6 -7
- package/lib/helpers/request.d.ts +1 -1
- package/lib/helpers/request.js +30 -68
- package/lib/helpers/validators.js +7 -8
- package/lib/modules/assetValue.js +171 -258
- package/lib/modules/bigIntArithmetics.js +180 -225
- package/lib/modules/swapKitError.js +6 -25
- package/lib/modules/swapKitNumber.js +10 -30
- package/package.json +18 -15
- package/src/helpers/asset.ts +0 -5
- package/tsconfig.json +1 -1
- package/lib/modules/__tests__/assetValue.test.d.ts +0 -1
- package/lib/modules/__tests__/assetValue.test.js +0 -399
- package/lib/modules/__tests__/swapKitNumber.test.d.ts +0 -1
- package/lib/modules/__tests__/swapKitNumber.test.js +0 -425
@@ -1,19 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
3
|
-
var extendStatics = function (d, b) {
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
-
return extendStatics(d, b);
|
8
|
-
};
|
9
|
-
return function (d, b) {
|
10
|
-
if (typeof b !== "function" && b !== null)
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
-
extendStatics(d, b);
|
13
|
-
function __() { this.constructor = d; }
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
-
};
|
16
|
-
})();
|
17
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
18
3
|
if (k2 === undefined) k2 = k;
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
@@ -30,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
30
15
|
}) : function(o, v) {
|
31
16
|
o["default"] = v;
|
32
17
|
});
|
33
|
-
var __importStar = (this && this.__importStar) || function (
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
40
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
41
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
42
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -46,33 +41,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
46
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
47
42
|
});
|
48
43
|
};
|
49
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
51
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
53
|
-
function step(op) {
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
55
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
56
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
58
|
-
switch (op[0]) {
|
59
|
-
case 0: case 1: t = op; break;
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
63
|
-
default:
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
68
|
-
if (t[2]) _.ops.pop();
|
69
|
-
_.trys.pop(); continue;
|
70
|
-
}
|
71
|
-
op = body.call(thisArg, _);
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
74
|
-
}
|
75
|
-
};
|
76
44
|
var __rest = (this && this.__rest) || function (s, e) {
|
77
45
|
var t = {};
|
78
46
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
@@ -84,24 +52,16 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
84
52
|
}
|
85
53
|
return t;
|
86
54
|
};
|
87
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
88
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
89
|
-
if (ar || !(i in from)) {
|
90
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
91
|
-
ar[i] = from[i];
|
92
|
-
}
|
93
|
-
}
|
94
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
95
|
-
};
|
96
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
97
|
-
exports.getMinAmountByChain = exports.AssetValue =
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
56
|
+
exports.getMinAmountByChain = exports.AssetValue = void 0;
|
57
|
+
exports.safeValue = safeValue;
|
58
|
+
const types_1 = require("@coinmasters/types");
|
59
|
+
const asset_1 = require("../helpers/asset");
|
60
|
+
const validators_1 = require("../helpers/validators");
|
61
|
+
const bigIntArithmetics_1 = require("./bigIntArithmetics");
|
62
|
+
const TAG = " | assetValue | ";
|
103
63
|
function safeValue(value, decimal) {
|
104
|
-
|
64
|
+
let tag = TAG + " | safeValue | ";
|
105
65
|
try {
|
106
66
|
if (typeof value === 'bigint') {
|
107
67
|
return value;
|
@@ -119,58 +79,44 @@ function safeValue(value, decimal) {
|
|
119
79
|
return BigInt(0);
|
120
80
|
}
|
121
81
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
var tag = TAG + " | getStaticToken | ";
|
82
|
+
let staticTokensMap;
|
83
|
+
const getStaticToken = (identifier) => {
|
84
|
+
let tag = TAG + " | getStaticToken | ";
|
126
85
|
try {
|
127
86
|
if (!staticTokensMap) {
|
128
87
|
throw new Error('Static assets not loaded, call await AssetValue.loadStaticAssets() first');
|
129
88
|
}
|
130
|
-
|
89
|
+
const tokenInfo = staticTokensMap.get(identifier.toUpperCase());
|
131
90
|
return tokenInfo || { decimal: types_1.BaseDecimal.THOR, identifier: '' };
|
132
91
|
}
|
133
92
|
catch (error) {
|
134
93
|
console.error(tag + 'Error in getStaticToken:', error);
|
135
94
|
}
|
136
95
|
};
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
return [2 /*return*/, new AssetValue({ decimal: decimal, value: parsedValue, identifier: assetString })];
|
156
|
-
case 3:
|
157
|
-
error_1 = _a.sent();
|
158
|
-
console.error(tag + 'Error in createAssetValue:', error_1);
|
159
|
-
return [3 /*break*/, 4];
|
160
|
-
case 4: return [2 /*return*/];
|
161
|
-
}
|
162
|
-
});
|
163
|
-
});
|
164
|
-
};
|
165
|
-
var AssetValue = /** @class */ (function (_super) {
|
166
|
-
__extends(AssetValue, _super);
|
96
|
+
const createAssetValue = (assetString_1, ...args_1) => __awaiter(void 0, [assetString_1, ...args_1], void 0, function* (assetString, value = 0) {
|
97
|
+
let tag = TAG + " | createAssetValue | ";
|
98
|
+
try {
|
99
|
+
(0, validators_1.validateIdentifier)(assetString);
|
100
|
+
//console.log(tag + 'assetString', assetString);
|
101
|
+
//@ts-ignore
|
102
|
+
const decimal = yield (0, asset_1.getDecimal)(getAssetInfo(assetString));
|
103
|
+
//console.log(tag + 'decimal', decimal);
|
104
|
+
const parsedValue = safeValue(value, decimal);
|
105
|
+
//console.log(tag + 'parsedValue', parsedValue);
|
106
|
+
// @ts-ignore
|
107
|
+
return new AssetValue({ decimal, value: parsedValue, identifier: assetString });
|
108
|
+
}
|
109
|
+
catch (error) {
|
110
|
+
console.error(tag + 'Error in createAssetValue:', error);
|
111
|
+
}
|
112
|
+
});
|
113
|
+
class AssetValue extends bigIntArithmetics_1.BigIntArithmetics {
|
167
114
|
//@ts-ignore
|
168
|
-
|
169
|
-
|
170
|
-
var tag = TAG + " | constructor | ";
|
115
|
+
constructor(params) {
|
116
|
+
let tag = TAG + " | constructor | ";
|
171
117
|
try {
|
172
|
-
|
173
|
-
|
118
|
+
const identifier = 'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
|
119
|
+
let value;
|
174
120
|
if (params.value instanceof bigIntArithmetics_1.BigIntArithmetics) {
|
175
121
|
value = params.value;
|
176
122
|
}
|
@@ -178,87 +124,78 @@ var AssetValue = /** @class */ (function (_super) {
|
|
178
124
|
value = { decimal: params.decimal, value: safeValue(params.value, params.decimal) };
|
179
125
|
}
|
180
126
|
// @ts-ignore
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
127
|
+
super(value);
|
128
|
+
this.isGasAsset = false;
|
129
|
+
this.isSynthetic = false;
|
130
|
+
const assetInfo = getAssetInfo(identifier);
|
131
|
+
this.type = (0, asset_1.getAssetType)(assetInfo);
|
132
|
+
this.identifier = identifier;
|
133
|
+
this.chain = assetInfo.chain;
|
134
|
+
this.ticker = assetInfo.ticker;
|
135
|
+
this.symbol = assetInfo.symbol;
|
136
|
+
this.address = assetInfo.address;
|
137
|
+
this.isSynthetic = assetInfo.isSynthetic;
|
192
138
|
// @ts-ignore
|
193
|
-
|
194
|
-
|
139
|
+
this.isGasAsset = assetInfo.isGasAsset;
|
140
|
+
this.tax = params.tax;
|
195
141
|
}
|
196
142
|
catch (error) {
|
197
143
|
console.error(tag + 'Error in constructor:', error);
|
198
144
|
}
|
199
|
-
return _this;
|
200
145
|
}
|
201
|
-
|
202
|
-
|
203
|
-
var tag = TAG + " | toString | ";
|
146
|
+
toString(short = false) {
|
147
|
+
let tag = TAG + " | toString | ";
|
204
148
|
try {
|
205
|
-
|
149
|
+
const shortFormat = this.isSynthetic ? this.symbol : this.ticker;
|
206
150
|
return short
|
207
151
|
? shortFormat
|
208
|
-
:
|
152
|
+
: `${this.chain}.${this.symbol}`;
|
209
153
|
}
|
210
154
|
catch (error) {
|
211
155
|
console.error(tag + 'Error in toString:', error);
|
212
156
|
}
|
213
|
-
}
|
214
|
-
|
215
|
-
|
157
|
+
}
|
158
|
+
toUrl() {
|
159
|
+
let tag = TAG + " | toUrl | ";
|
216
160
|
try {
|
217
|
-
return this.isSynthetic ?
|
161
|
+
return this.isSynthetic ? `${this.chain}.${this.symbol.replace('/', '.')}` : this.toString();
|
218
162
|
}
|
219
163
|
catch (error) {
|
220
164
|
console.error(tag + 'Error in toUrl:', error);
|
221
165
|
}
|
222
|
-
}
|
223
|
-
|
224
|
-
|
225
|
-
var tag = TAG + " | eq | ";
|
166
|
+
}
|
167
|
+
eq({ chain, symbol }) {
|
168
|
+
let tag = TAG + " | eq | ";
|
226
169
|
try {
|
227
170
|
return this.chain === chain && this.symbol === symbol;
|
228
171
|
}
|
229
172
|
catch (error) {
|
230
173
|
console.error(tag + 'Error in eq:', error);
|
231
174
|
}
|
232
|
-
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
catch (error) {
|
243
|
-
console.error(tag + 'Error in fromString:', error);
|
244
|
-
}
|
245
|
-
return [2 /*return*/];
|
246
|
-
});
|
175
|
+
}
|
176
|
+
static fromString(assetString_1) {
|
177
|
+
return __awaiter(this, arguments, void 0, function* (assetString, value = 0) {
|
178
|
+
let tag = TAG + " | fromString | ";
|
179
|
+
try {
|
180
|
+
return createAssetValue(assetString, value);
|
181
|
+
}
|
182
|
+
catch (error) {
|
183
|
+
console.error(tag + 'Error in fromString:', error);
|
184
|
+
}
|
247
185
|
});
|
248
|
-
}
|
249
|
-
|
250
|
-
|
251
|
-
var tag = TAG + " | fromStringSync | ";
|
186
|
+
}
|
187
|
+
static fromStringSync(assetString, value = 0) {
|
188
|
+
let tag = TAG + " | fromStringSync | ";
|
252
189
|
try {
|
253
190
|
//@ts-ignore
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
191
|
+
const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString);
|
192
|
+
const { tax, decimal, identifier: tokenIdentifier, } = getStaticToken(assetString);
|
193
|
+
const parsedValue = safeValue(value, decimal);
|
194
|
+
let asset;
|
258
195
|
if (tokenIdentifier) {
|
259
196
|
asset = new AssetValue({
|
260
|
-
tax
|
261
|
-
decimal
|
197
|
+
tax,
|
198
|
+
decimal,
|
262
199
|
identifier: tokenIdentifier,
|
263
200
|
// @ts-ignore
|
264
201
|
value: parsedValue,
|
@@ -266,7 +203,7 @@ var AssetValue = /** @class */ (function (_super) {
|
|
266
203
|
}
|
267
204
|
else if (isSynthetic) {
|
268
205
|
asset = new AssetValue({
|
269
|
-
tax
|
206
|
+
tax,
|
270
207
|
decimal: 8, // Synthetic assets use a fixed decimal value
|
271
208
|
identifier: assetString,
|
272
209
|
// @ts-ignore
|
@@ -281,116 +218,92 @@ var AssetValue = /** @class */ (function (_super) {
|
|
281
218
|
catch (error) {
|
282
219
|
console.error(tag + 'Error in fromStringSync:', error);
|
283
220
|
}
|
284
|
-
}
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
catch (error) {
|
295
|
-
console.error(tag + 'Error in fromIdentifier:', error);
|
296
|
-
}
|
297
|
-
return [2 /*return*/];
|
298
|
-
});
|
221
|
+
}
|
222
|
+
static fromIdentifier(assetString_1) {
|
223
|
+
return __awaiter(this, arguments, void 0, function* (assetString, value = 0) {
|
224
|
+
let tag = TAG + " | fromIdentifier | ";
|
225
|
+
try {
|
226
|
+
return createAssetValue(assetString, value);
|
227
|
+
}
|
228
|
+
catch (error) {
|
229
|
+
console.error(tag + 'Error in fromIdentifier:', error);
|
230
|
+
}
|
299
231
|
});
|
300
|
-
}
|
301
|
-
|
302
|
-
|
303
|
-
var tag = TAG + " | fromIdentifierSync | ";
|
232
|
+
}
|
233
|
+
static fromIdentifierSync(identifier, value = 0) {
|
234
|
+
let tag = TAG + " | fromIdentifierSync | ";
|
304
235
|
try {
|
305
236
|
//@ts-ignore
|
306
|
-
|
307
|
-
|
237
|
+
const { decimal, identifier: tokenIdentifier } = getStaticToken(identifier);
|
238
|
+
const parsedValue = safeValue(value, decimal);
|
308
239
|
// @ts-ignore
|
309
|
-
return new AssetValue({ decimal
|
240
|
+
return new AssetValue({ decimal, identifier: tokenIdentifier, value: parsedValue });
|
310
241
|
}
|
311
242
|
catch (error) {
|
312
243
|
console.error(tag + 'Error in fromIdentifierSync:', error);
|
313
244
|
}
|
314
|
-
}
|
315
|
-
|
316
|
-
|
317
|
-
var tag = TAG + " | fromChainOrSignature | ";
|
245
|
+
}
|
246
|
+
static fromChainOrSignature(assetString, value = 0) {
|
247
|
+
let tag = TAG + " | fromChainOrSignature | ";
|
318
248
|
try {
|
319
|
-
|
249
|
+
const { decimal, identifier } = (0, asset_1.getCommonAssetInfo)(assetString);
|
320
250
|
if (!decimal || !identifier)
|
321
251
|
throw Error('unknown coin! ' + assetString);
|
322
|
-
|
252
|
+
const parsedValue = safeValue(value, decimal);
|
323
253
|
//console.log(tag + "parsedValue: ", parsedValue);
|
324
254
|
//console.log(tag + "decimal: ", decimal);
|
325
255
|
//console.log(tag + "identifier: ", identifier);
|
326
256
|
// @ts-ignore
|
327
|
-
return new AssetValue({ value: parsedValue, decimal
|
257
|
+
return new AssetValue({ value: parsedValue, decimal, identifier });
|
328
258
|
}
|
329
259
|
catch (error) {
|
330
260
|
console.error(tag + 'Error in fromChainOrSignature:', error);
|
331
261
|
}
|
332
|
-
}
|
333
|
-
|
334
|
-
return __awaiter(this, void 0, void 0, function () {
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
var tokens = _a.tokens;
|
351
|
-
if (!tokens) {
|
352
|
-
console.warn(tag + "No tokens found in the current package, skipping.");
|
353
|
-
return acc;
|
354
|
-
}
|
355
|
-
// @ts-ignore
|
356
|
-
tokens.forEach(function (_a) {
|
357
|
-
var identifier = _a.identifier, chain = _a.chain, rest = __rest(_a, ["identifier", "chain"]);
|
358
|
-
var decimal = 'decimals' in rest ? rest.decimals : types_1.BaseDecimal[chain];
|
359
|
-
acc.set(identifier, { identifier: identifier, decimal: decimal });
|
360
|
-
});
|
361
|
-
return acc;
|
362
|
-
}, new Map());
|
363
|
-
staticTokensMap = tokensMap;
|
364
|
-
resolve({ ok: true });
|
365
|
-
return [3 /*break*/, 3];
|
366
|
-
case 2:
|
367
|
-
error_2 = _b.sent();
|
368
|
-
console.error(tag + "Error loading static assets:", error_2);
|
369
|
-
reject({
|
370
|
-
ok: false,
|
371
|
-
error: error_2,
|
372
|
-
message: "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
373
|
-
});
|
374
|
-
return [3 /*break*/, 3];
|
375
|
-
case 3: return [2 /*return*/];
|
376
|
-
}
|
262
|
+
}
|
263
|
+
static loadStaticAssets() {
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
265
|
+
let tag = TAG + " | loadStaticAssets | ";
|
266
|
+
try {
|
267
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
268
|
+
try {
|
269
|
+
const _a = yield Promise.resolve().then(() => __importStar(require('@coinmasters/tokens'))), { ThorchainList: _ThorchainList, NativeList } = _a, tokensPackage = __rest(_a, ["ThorchainList", "NativeList"]);
|
270
|
+
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce((acc, { tokens }) => {
|
271
|
+
if (!tokens) {
|
272
|
+
console.warn(tag + "No tokens found in the current package, skipping.");
|
273
|
+
return acc;
|
274
|
+
}
|
275
|
+
// @ts-ignore
|
276
|
+
tokens.forEach((_a) => {
|
277
|
+
var { identifier, chain } = _a, rest = __rest(_a, ["identifier", "chain"]);
|
278
|
+
const decimal = 'decimals' in rest ? rest.decimals : types_1.BaseDecimal[chain];
|
279
|
+
acc.set(identifier, { identifier, decimal });
|
377
280
|
});
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
281
|
+
return acc;
|
282
|
+
}, new Map());
|
283
|
+
staticTokensMap = tokensMap;
|
284
|
+
resolve({ ok: true });
|
285
|
+
}
|
286
|
+
catch (error) {
|
287
|
+
console.error(tag + "Error loading static assets:", error);
|
288
|
+
reject({
|
289
|
+
ok: false,
|
290
|
+
error,
|
291
|
+
message: "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
292
|
+
});
|
293
|
+
}
|
294
|
+
}));
|
295
|
+
}
|
296
|
+
catch (error) {
|
297
|
+
console.error(tag + 'Error in loadStaticAssets:', error);
|
298
|
+
}
|
385
299
|
});
|
386
|
-
}
|
387
|
-
|
388
|
-
}(bigIntArithmetics_1.BigIntArithmetics));
|
300
|
+
}
|
301
|
+
}
|
389
302
|
exports.AssetValue = AssetValue;
|
390
|
-
|
391
|
-
|
303
|
+
const getMinAmountByChain = (chain) => {
|
304
|
+
let tag = TAG + " | getMinAmountByChain | ";
|
392
305
|
try {
|
393
|
-
|
306
|
+
const asset = AssetValue.fromChainOrSignature(chain);
|
394
307
|
switch (chain) {
|
395
308
|
case types_1.Chain.Bitcoin:
|
396
309
|
case types_1.Chain.Litecoin:
|
@@ -417,23 +330,23 @@ var getMinAmountByChain = function (chain) {
|
|
417
330
|
}
|
418
331
|
};
|
419
332
|
exports.getMinAmountByChain = getMinAmountByChain;
|
420
|
-
|
333
|
+
const getAssetInfo = (identifier) => {
|
421
334
|
var _a;
|
422
|
-
|
335
|
+
let tag = TAG + " | getAssetInfo | ";
|
423
336
|
try {
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
337
|
+
const isSynthetic = identifier.slice(0, 14).includes('/');
|
338
|
+
const [synthChain, synthSymbol] = identifier.split('.').pop().split('/');
|
339
|
+
const adjustedIdentifier = identifier.includes('.') && !isSynthetic ? identifier : `${types_1.Chain.THORChain}.${synthSymbol}`;
|
340
|
+
const [chain, symbol] = adjustedIdentifier.split('.');
|
341
|
+
const [ticker, address] = (isSynthetic ? synthSymbol : symbol).split('-');
|
429
342
|
return {
|
430
343
|
address: address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
431
|
-
chain
|
432
|
-
isGasAsset: (0, asset_1.isGasAsset)({ chain
|
433
|
-
isSynthetic
|
434
|
-
symbol: (isSynthetic ?
|
435
|
-
(address ?
|
436
|
-
ticker
|
344
|
+
chain,
|
345
|
+
isGasAsset: (0, asset_1.isGasAsset)({ chain, symbol }),
|
346
|
+
isSynthetic,
|
347
|
+
symbol: (isSynthetic ? `${synthChain}/` : '') +
|
348
|
+
(address ? `${ticker}-${(_a = address === null || address === void 0 ? void 0 : address.toLowerCase()) !== null && _a !== void 0 ? _a : ''}` : symbol),
|
349
|
+
ticker,
|
437
350
|
};
|
438
351
|
}
|
439
352
|
catch (error) {
|