@pioneer-platform/helpers 4.0.3 → 4.0.4
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/__tests__/test-module.js +14 -6
- package/lib/modules/assetValue.js +10 -13
- package/package.json +1 -1
- package/src/modules/assetValue.ts +12 -57
package/__tests__/test-module.js
CHANGED
@@ -16,12 +16,20 @@ let run_test = async function(){
|
|
16
16
|
|
17
17
|
await helpers.AssetValue.loadStaticAssets();
|
18
18
|
|
19
|
-
let assetValue = helpers.AssetValue.fromChainOrSignature(
|
20
|
-
|
21
|
-
|
22
|
-
);
|
23
|
-
console.log("assetValue: ",assetValue)
|
24
|
-
console.log("assetValue: ",assetValue.getValue('string'))
|
19
|
+
// let assetValue = helpers.AssetValue.fromChainOrSignature(
|
20
|
+
// 'BASE',
|
21
|
+
// 0,
|
22
|
+
// );
|
23
|
+
// console.log("assetValue: ",assetValue)
|
24
|
+
// console.log("assetValue: ",assetValue.getValue('string'))
|
25
|
+
|
26
|
+
//formatBigIntToSafeValue
|
27
|
+
let value = helpers.formatBigIntToSafeValue({
|
28
|
+
value: 45354402190799130n,
|
29
|
+
decimal: 18,
|
30
|
+
})
|
31
|
+
console.log("value: ",value)
|
32
|
+
|
25
33
|
|
26
34
|
}catch(e){
|
27
35
|
console.error(e)
|
@@ -144,7 +144,7 @@ var AssetValue = /** @class */ (function (_super) {
|
|
144
144
|
function AssetValue(params) {
|
145
145
|
var _this = this;
|
146
146
|
var identifier = 'identifier' in params ? params.identifier : "".concat(params.chain, ".").concat(params.symbol);
|
147
|
-
console.log('identifier: ', identifier);
|
147
|
+
// console.log('identifier: ', identifier);
|
148
148
|
var value;
|
149
149
|
if (params.value instanceof bigIntArithmetics_1.BigIntArithmetics) {
|
150
150
|
value = params.value;
|
@@ -152,7 +152,7 @@ var AssetValue = /** @class */ (function (_super) {
|
|
152
152
|
else {
|
153
153
|
value = { decimal: params.decimal, value: params.value };
|
154
154
|
}
|
155
|
-
console.log('value: ', value);
|
155
|
+
// console.log('value: ', value);
|
156
156
|
_this = _super.call(this, value) || this;
|
157
157
|
_this.isGasAsset = false;
|
158
158
|
_this.isSynthetic = false;
|
@@ -162,7 +162,7 @@ var AssetValue = /** @class */ (function (_super) {
|
|
162
162
|
// : { decimal: params.decimal, value: params.value },
|
163
163
|
// );
|
164
164
|
var assetInfo = getAssetInfo(identifier);
|
165
|
-
console.log('assetInfo: ', assetInfo);
|
165
|
+
// console.log('assetInfo: ', assetInfo);
|
166
166
|
_this.type = (0, asset_1.getAssetType)(assetInfo);
|
167
167
|
_this.chain = assetInfo.chain;
|
168
168
|
_this.ticker = assetInfo.ticker;
|
@@ -245,13 +245,13 @@ var AssetValue = /** @class */ (function (_super) {
|
|
245
245
|
AssetValue.fromStringSync = function (assetString, value) {
|
246
246
|
if (value === void 0) { value = 0; }
|
247
247
|
var _a = getAssetInfo(assetString), isSynthetic = _a.isSynthetic, symbol = _a.symbol, chain = _a.chain, isGasAsset = _a.isGasAsset, ticker = _a.ticker, address = _a.address;
|
248
|
-
console.log('getAssetInfo: ', { isSynthetic
|
248
|
+
//console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
|
249
249
|
var _b = getStaticToken(assetString), tax = _b.tax, decimal = _b.decimal, tokenIdentifier = _b.identifier;
|
250
|
-
console.log('getStaticToken: ', { tax
|
251
|
-
console.log('value: ', value);
|
252
|
-
console.log('decimal: ', decimal);
|
250
|
+
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
|
251
|
+
// console.log('value: ', value);
|
252
|
+
// console.log('decimal: ', decimal);
|
253
253
|
var parsedValue = safeValue(value, decimal);
|
254
|
-
console.log('parsedValue: ', parsedValue);
|
254
|
+
// console.log('parsedValue: ', parsedValue);
|
255
255
|
var asset;
|
256
256
|
if (tokenIdentifier) {
|
257
257
|
console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context
|
@@ -309,21 +309,18 @@ var AssetValue = /** @class */ (function (_super) {
|
|
309
309
|
switch (_b.label) {
|
310
310
|
case 0:
|
311
311
|
_b.trys.push([0, 2, , 3]);
|
312
|
-
console.log("Starting to load static assets...");
|
313
312
|
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('@coinmasters/tokens')); })];
|
314
313
|
case 1:
|
315
314
|
_a = _b.sent(), _ThorchainList = _a.ThorchainList, NativeList = _a.NativeList, tokensPackage = __rest(_a, ["ThorchainList", "NativeList"]);
|
316
|
-
console.log("Successfully imported @coinmasters/tokens package.");
|
317
315
|
tokensMap = __spreadArray([NativeList], Object.values(tokensPackage), true).reduce(
|
318
316
|
//@ts-ignore
|
319
317
|
function (acc, _a) {
|
320
|
-
var _b;
|
321
318
|
var tokens = _a.tokens;
|
322
319
|
if (!tokens) {
|
323
320
|
console.warn("No tokens found in the current package, skipping.");
|
324
321
|
return acc;
|
325
322
|
}
|
326
|
-
console.log(
|
323
|
+
// console.log(`Processing tokens for chain ${tokens[0]?.chain || 'unknown'}`);
|
327
324
|
tokens.forEach(function (_a) {
|
328
325
|
var identifier = _a.identifier, chain = _a.chain, rest = __rest(_a, ["identifier", "chain"]);
|
329
326
|
//@ts-ignore
|
@@ -332,7 +329,7 @@ var AssetValue = /** @class */ (function (_super) {
|
|
332
329
|
});
|
333
330
|
return acc;
|
334
331
|
}, new Map());
|
335
|
-
console.log("Tokens map successfully created:", tokensMap);
|
332
|
+
// console.log("Tokens map successfully created:", tokensMap);
|
336
333
|
staticTokensMap = tokensMap;
|
337
334
|
resolve({ ok: true });
|
338
335
|
return [3 /*break*/, 3];
|
package/package.json
CHANGED
@@ -102,7 +102,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
102
102
|
constructor(params: AssetValueParams) {
|
103
103
|
const identifier =
|
104
104
|
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
|
105
|
-
console.log('identifier: ', identifier);
|
105
|
+
// console.log('identifier: ', identifier);
|
106
106
|
|
107
107
|
let value;
|
108
108
|
if (params.value instanceof BigIntArithmetics) {
|
@@ -110,7 +110,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
110
110
|
} else {
|
111
111
|
value = { decimal: params.decimal, value: params.value };
|
112
112
|
}
|
113
|
-
console.log('value: ', value);
|
113
|
+
// console.log('value: ', value);
|
114
114
|
super(value);
|
115
115
|
|
116
116
|
// super(
|
@@ -120,7 +120,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
120
120
|
// );
|
121
121
|
|
122
122
|
const assetInfo = getAssetInfo(identifier);
|
123
|
-
console.log('assetInfo: ', assetInfo);
|
123
|
+
// console.log('assetInfo: ', assetInfo);
|
124
124
|
this.type = getAssetType(assetInfo);
|
125
125
|
this.chain = assetInfo.chain;
|
126
126
|
this.ticker = assetInfo.ticker;
|
@@ -202,17 +202,17 @@ export class AssetValue extends BigIntArithmetics {
|
|
202
202
|
|
203
203
|
static fromStringSync(assetString: string, value: NumberPrimitives = 0) {
|
204
204
|
const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString);
|
205
|
-
console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
|
205
|
+
//console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
|
206
206
|
const {
|
207
207
|
tax,
|
208
208
|
decimal,
|
209
209
|
identifier: tokenIdentifier,
|
210
210
|
} = getStaticToken(assetString as unknown as TokenNames);
|
211
|
-
console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
|
212
|
-
console.log('value: ', value);
|
213
|
-
console.log('decimal: ', decimal);
|
211
|
+
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
|
212
|
+
// console.log('value: ', value);
|
213
|
+
// console.log('decimal: ', decimal);
|
214
214
|
const parsedValue = safeValue(value, decimal);
|
215
|
-
console.log('parsedValue: ', parsedValue);
|
215
|
+
// console.log('parsedValue: ', parsedValue);
|
216
216
|
let asset: AssetValue | undefined;
|
217
217
|
|
218
218
|
if (tokenIdentifier) {
|
@@ -265,7 +265,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
265
265
|
return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
|
266
266
|
async (resolve, reject) => {
|
267
267
|
try {
|
268
|
-
console.log("Starting to load static assets...");
|
268
|
+
// console.log("Starting to load static assets...");
|
269
269
|
|
270
270
|
// @ts-ignore
|
271
271
|
const {
|
@@ -277,7 +277,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
277
277
|
//@ts-ignore
|
278
278
|
} = await import('@coinmasters/tokens');
|
279
279
|
|
280
|
-
console.log("Successfully imported @coinmasters/tokens package.");
|
280
|
+
// console.log("Successfully imported @coinmasters/tokens package.");
|
281
281
|
|
282
282
|
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
|
283
283
|
//@ts-ignore
|
@@ -286,7 +286,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
286
286
|
console.warn("No tokens found in the current package, skipping.");
|
287
287
|
return acc;
|
288
288
|
}
|
289
|
-
console.log(`Processing tokens for chain ${tokens[0]?.chain || 'unknown'}`);
|
289
|
+
// console.log(`Processing tokens for chain ${tokens[0]?.chain || 'unknown'}`);
|
290
290
|
|
291
291
|
tokens.forEach(({ identifier, chain, ...rest }:any) => {
|
292
292
|
//@ts-ignore
|
@@ -300,7 +300,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
300
300
|
new Map<TokenNames, { decimal: number; identifier: string }>(),
|
301
301
|
);
|
302
302
|
|
303
|
-
console.log("Tokens map successfully created:", tokensMap);
|
303
|
+
// console.log("Tokens map successfully created:", tokensMap);
|
304
304
|
|
305
305
|
staticTokensMap = tokensMap;
|
306
306
|
|
@@ -316,51 +316,6 @@ export class AssetValue extends BigIntArithmetics {
|
|
316
316
|
},
|
317
317
|
);
|
318
318
|
}
|
319
|
-
|
320
|
-
// static async loadStaticAssets() {
|
321
|
-
// return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
|
322
|
-
// async (resolve, reject) => {
|
323
|
-
// try {
|
324
|
-
// // @ts-ignore
|
325
|
-
// const {
|
326
|
-
// // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
327
|
-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
328
|
-
// ThorchainList: _ThorchainList,
|
329
|
-
// NativeList,
|
330
|
-
// ...tokensPackage
|
331
|
-
// //@ts-ignore
|
332
|
-
// } = await import('@coinmasters/tokens');
|
333
|
-
// const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
|
334
|
-
// //@ts-ignore
|
335
|
-
// (acc, { tokens }) => {
|
336
|
-
// // @ts-ignore
|
337
|
-
// tokens.forEach(({ identifier, chain, ...rest }) => {
|
338
|
-
// //@ts-ignore
|
339
|
-
// const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
|
340
|
-
//
|
341
|
-
// acc.set(identifier as TokenNames, { identifier, decimal });
|
342
|
-
// });
|
343
|
-
//
|
344
|
-
// return acc;
|
345
|
-
// },
|
346
|
-
// new Map<TokenNames, { decimal: number; identifier: string }>(),
|
347
|
-
// );
|
348
|
-
//
|
349
|
-
// staticTokensMap = tokensMap;
|
350
|
-
//
|
351
|
-
// resolve({ ok: true });
|
352
|
-
// } catch (error) {
|
353
|
-
// console.error(error);
|
354
|
-
// reject({
|
355
|
-
// ok: false,
|
356
|
-
// error,
|
357
|
-
// message:
|
358
|
-
// "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
359
|
-
// });
|
360
|
-
// }
|
361
|
-
// },
|
362
|
-
// );
|
363
|
-
// }
|
364
319
|
}
|
365
320
|
|
366
321
|
export const getMinAmountByChain = (chain: Chain) => {
|