@ethereansos/interfaces-core 0.4.99 → 0.4.102

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs.js CHANGED
@@ -50367,14 +50367,15 @@ function fromDecimals(number, decimals, skipFormat) {
50367
50367
  return '0';
50368
50368
  }
50369
50369
 
50370
+ number = numberToString(number).split('.')[0];
50370
50371
  var symbol = toEthereumSymbol(decimals);
50371
50372
 
50372
50373
  if (symbol) {
50373
- var result = web3Utils__default["default"].fromWei(numberToString(number), symbol);
50374
+ var result = web3Utils__default["default"].fromWei(number, symbol);
50374
50375
  return skipFormat === true ? result : formatMoney(result);
50375
50376
  }
50376
50377
 
50377
- var nts = parseFloat(numberToString(number / (decimals < 2 ? 1 : Math.pow(10, decimals)))); // TODO verify if is expected that is rounded to 2 decimals
50378
+ var nts = parseFloat(numberToString(parseFloat(number) / (decimals < 2 ? 1 : Math.pow(10, decimals)))); // TODO verify if is expected that is rounded to 2 decimals
50378
50379
 
50379
50380
  return skipFormat === true ? numberToString(nts) : formatMoney(nts);
50380
50381
  }
@@ -64110,6 +64111,333 @@ function _getTokenPriceInDollarsOnUniswapV() {
64110
64111
  return _getTokenPriceInDollarsOnUniswapV.apply(this, arguments);
64111
64112
  }
64112
64113
 
64114
+ var tokenPrices = {};
64115
+ var tokenPricesPromises = {};
64116
+
64117
+ function elaboratePrices(_x, _x2, _x3) {
64118
+ return _elaboratePrices.apply(this, arguments);
64119
+ }
64120
+
64121
+ function _elaboratePrices() {
64122
+ _elaboratePrices = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref, res, tokens) {
64123
+ var context, web3Data, response, _iterator, _step, token;
64124
+
64125
+ return regeneratorRuntime.wrap(function _callee$(_context) {
64126
+ while (1) {
64127
+ switch (_context.prev = _context.next) {
64128
+ case 0:
64129
+ context = _ref.context, web3Data = _ref.web3Data;
64130
+ response = {
64131
+ data: {}
64132
+ };
64133
+ Object.entries(res.data).forEach(function (entry) {
64134
+ return response.data[entry[0]] = entry[1];
64135
+ });
64136
+ tokens = (!(tokens instanceof Array) ? tokens = tokens.split(',') : tokens).map(function (it) {
64137
+ return it.toLowerCase();
64138
+ }).filter(function (it) {
64139
+ return it && it !== VOID_ETHEREUM_ADDRESS && !response.data[it];
64140
+ });
64141
+ _iterator = _createForOfIteratorHelper(tokens);
64142
+ _context.prev = 5;
64143
+
64144
+ _iterator.s();
64145
+
64146
+ case 7:
64147
+ if ((_step = _iterator.n()).done) {
64148
+ _context.next = 36;
64149
+ break;
64150
+ }
64151
+
64152
+ token = _step.value;
64153
+ _context.prev = 9;
64154
+ _context.t0 = getTokenPriceInDollarsOnUniswapV3;
64155
+ _context.t1 = _objectSpread2({
64156
+ context: context
64157
+ }, web3Data);
64158
+ _context.t2 = token;
64159
+ _context.next = 15;
64160
+ return blockchainCall(web3Data.newContract(context.ERC20ABI, token).methods.decimals);
64161
+
64162
+ case 15:
64163
+ _context.t3 = _context.sent;
64164
+ _context.next = 18;
64165
+ return (0, _context.t0)(_context.t1, _context.t2, _context.t3);
64166
+
64167
+ case 18:
64168
+ _context.t4 = _context.sent;
64169
+ response.data[token] = {
64170
+ usd: _context.t4
64171
+ };
64172
+ _context.next = 34;
64173
+ break;
64174
+
64175
+ case 22:
64176
+ _context.prev = 22;
64177
+ _context.t5 = _context["catch"](9);
64178
+ _context.t6 = getTokenPriceInDollarsOnUniswap;
64179
+ _context.t7 = _objectSpread2({
64180
+ context: context
64181
+ }, web3Data);
64182
+ _context.t8 = token;
64183
+ _context.next = 29;
64184
+ return blockchainCall(web3Data.newContract(context.ERC20ABI, token).methods.decimals);
64185
+
64186
+ case 29:
64187
+ _context.t9 = _context.sent;
64188
+ _context.next = 32;
64189
+ return (0, _context.t6)(_context.t7, _context.t8, _context.t9);
64190
+
64191
+ case 32:
64192
+ _context.t10 = _context.sent;
64193
+ response.data[token] = {
64194
+ usd: _context.t10
64195
+ };
64196
+
64197
+ case 34:
64198
+ _context.next = 7;
64199
+ break;
64200
+
64201
+ case 36:
64202
+ _context.next = 41;
64203
+ break;
64204
+
64205
+ case 38:
64206
+ _context.prev = 38;
64207
+ _context.t11 = _context["catch"](5);
64208
+
64209
+ _iterator.e(_context.t11);
64210
+
64211
+ case 41:
64212
+ _context.prev = 41;
64213
+
64214
+ _iterator.f();
64215
+
64216
+ return _context.finish(41);
64217
+
64218
+ case 44:
64219
+ return _context.abrupt("return", response);
64220
+
64221
+ case 45:
64222
+ case "end":
64223
+ return _context.stop();
64224
+ }
64225
+ }
64226
+ }, _callee, null, [[5, 38, 41, 44], [9, 22]]);
64227
+ }));
64228
+ return _elaboratePrices.apply(this, arguments);
64229
+ }
64230
+
64231
+ function getTokenPricesInDollarsOnCoingecko(_x4, _x5) {
64232
+ return _getTokenPricesInDollarsOnCoingecko.apply(this, arguments);
64233
+ }
64234
+
64235
+ function _getTokenPricesInDollarsOnCoingecko() {
64236
+ _getTokenPricesInDollarsOnCoingecko = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(_ref2, t) {
64237
+ var context, web3Data, tokens, response, tkns, _iterator2, _step2, token, prom, _i, _tkns, _i2, _tkns2, _iterator3, _step3;
64238
+
64239
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
64240
+ while (1) {
64241
+ switch (_context3.prev = _context3.next) {
64242
+ case 0:
64243
+ context = _ref2.context, web3Data = _ref2.web3Data;
64244
+ tokens = (!(t instanceof Array) ? t = t.split(',') : t).map(function (it) {
64245
+ return it.toLowerCase();
64246
+ });
64247
+ response = {
64248
+ data: {}
64249
+ };
64250
+ tkns = [];
64251
+ _iterator2 = _createForOfIteratorHelper(tokens);
64252
+ _context3.prev = 5;
64253
+
64254
+ _iterator2.s();
64255
+
64256
+ case 7:
64257
+ if ((_step2 = _iterator2.n()).done) {
64258
+ _context3.next = 29;
64259
+ break;
64260
+ }
64261
+
64262
+ token = _step2.value;
64263
+
64264
+ if (!(!token || token === VOID_ETHEREUM_ADDRESS)) {
64265
+ _context3.next = 14;
64266
+ break;
64267
+ }
64268
+
64269
+ _context3.next = 12;
64270
+ return getEthereumPrice({
64271
+ context: context
64272
+ });
64273
+
64274
+ case 12:
64275
+ response.data[token] = _context3.sent;
64276
+ return _context3.abrupt("continue", 27);
64277
+
64278
+ case 14:
64279
+ if (!(tokenPrices[token] && tokenPrices[token].requestExpires > new Date().getTime() && tokenPrices[token].price !== 0)) {
64280
+ _context3.next = 18;
64281
+ break;
64282
+ }
64283
+
64284
+ response.data[token] = {
64285
+ usd: tokenPrices[token].price
64286
+ };
64287
+ _context3.next = 27;
64288
+ break;
64289
+
64290
+ case 18:
64291
+ if (!tokenPricesPromises[token]) {
64292
+ _context3.next = 26;
64293
+ break;
64294
+ }
64295
+
64296
+ _context3.next = 21;
64297
+ return tokenPricesPromises[token];
64298
+
64299
+ case 21:
64300
+ _context3.t0 = token;
64301
+ _context3.t1 = _context3.sent.data[_context3.t0].usd;
64302
+ response.data[token] = {
64303
+ usd: _context3.t1
64304
+ };
64305
+ _context3.next = 27;
64306
+ break;
64307
+
64308
+ case 26:
64309
+ tkns.push(token);
64310
+
64311
+ case 27:
64312
+ _context3.next = 7;
64313
+ break;
64314
+
64315
+ case 29:
64316
+ _context3.next = 34;
64317
+ break;
64318
+
64319
+ case 31:
64320
+ _context3.prev = 31;
64321
+ _context3.t2 = _context3["catch"](5);
64322
+
64323
+ _iterator2.e(_context3.t2);
64324
+
64325
+ case 34:
64326
+ _context3.prev = 34;
64327
+
64328
+ _iterator2.f();
64329
+
64330
+ return _context3.finish(34);
64331
+
64332
+ case 37:
64333
+ prom = /*#__PURE__*/function () {
64334
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(t1, t2) {
64335
+ var res;
64336
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
64337
+ while (1) {
64338
+ switch (_context2.prev = _context2.next) {
64339
+ case 0:
64340
+ res = {
64341
+ data: {}
64342
+ };
64343
+ _context2.prev = 1;
64344
+ _context2.t0 = t1.length > 0;
64345
+
64346
+ if (!_context2.t0) {
64347
+ _context2.next = 9;
64348
+ break;
64349
+ }
64350
+
64351
+ _context2.next = 6;
64352
+ return fetch(context.coingeckoCoinPriceURL + t1.join(','));
64353
+
64354
+ case 6:
64355
+ _context2.next = 8;
64356
+ return _context2.sent.json();
64357
+
64358
+ case 8:
64359
+ res.data = _context2.sent;
64360
+
64361
+ case 9:
64362
+ _context2.next = 13;
64363
+ break;
64364
+
64365
+ case 11:
64366
+ _context2.prev = 11;
64367
+ _context2.t1 = _context2["catch"](1);
64368
+
64369
+ case 13:
64370
+ _context2.next = 15;
64371
+ return elaboratePrices({
64372
+ context: context,
64373
+ web3Data: web3Data
64374
+ }, res, t2);
64375
+
64376
+ case 15:
64377
+ return _context2.abrupt("return", _context2.sent);
64378
+
64379
+ case 16:
64380
+ case "end":
64381
+ return _context2.stop();
64382
+ }
64383
+ }
64384
+ }, _callee2, null, [[1, 11]]);
64385
+ }));
64386
+
64387
+ return function prom(_x6, _x7) {
64388
+ return _ref3.apply(this, arguments);
64389
+ };
64390
+ }();
64391
+
64392
+ prom = prom(tkns, t);
64393
+
64394
+ for (_i = 0, _tkns = tkns; _i < _tkns.length; _i++) {
64395
+ token = _tkns[_i];
64396
+ tokenPricesPromises[token] = prom;
64397
+ }
64398
+
64399
+ _context3.next = 42;
64400
+ return prom;
64401
+
64402
+ case 42:
64403
+ prom = _context3.sent;
64404
+ Object.entries(prom.data).forEach(function (it) {
64405
+ return response.data[it[0]] = it[1];
64406
+ });
64407
+
64408
+ for (_i2 = 0, _tkns2 = tkns; _i2 < _tkns2.length; _i2++) {
64409
+ token = _tkns2[_i2];
64410
+ tokenPrices[token] = {
64411
+ requestExpires: new Date().getTime() + context.coingeckoEthereumPriceRequestInterval,
64412
+ price: response.data[token].usd
64413
+ };
64414
+ }
64415
+
64416
+ _iterator3 = _createForOfIteratorHelper(tokens);
64417
+
64418
+ try {
64419
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
64420
+ token = _step3.value;
64421
+ delete tokenPricesPromises[token];
64422
+ }
64423
+ } catch (err) {
64424
+ _iterator3.e(err);
64425
+ } finally {
64426
+ _iterator3.f();
64427
+ }
64428
+
64429
+ return _context3.abrupt("return", response);
64430
+
64431
+ case 48:
64432
+ case "end":
64433
+ return _context3.stop();
64434
+ }
64435
+ }
64436
+ }, _callee3, null, [[5, 31, 34, 37]]);
64437
+ }));
64438
+ return _getTokenPricesInDollarsOnCoingecko.apply(this, arguments);
64439
+ }
64440
+
64113
64441
  function op(a, operator, b) {
64114
64442
  var operations = {
64115
64443
  '+': 'add',
@@ -64656,6 +64984,7 @@ exports.getSolidityUtilities = SolidityUtilities;
64656
64984
  exports.getSupportedSolidityVersion = getSupportedSolidityVersion;
64657
64985
  exports.getTokenPriceInDollarsOnUniswap = getTokenPriceInDollarsOnUniswap;
64658
64986
  exports.getTokenPriceInDollarsOnUniswapV3 = getTokenPriceInDollarsOnUniswapV3;
64987
+ exports.getTokenPricesInDollarsOnCoingecko = getTokenPricesInDollarsOnCoingecko;
64659
64988
  exports.hasEthereumAddress = hasEthereumAddress;
64660
64989
  exports.isEthereumAddress = isEthereumAddress;
64661
64990
  exports.isSorted = isSorted;