@ethereansos/interfaces-core 0.4.104 → 0.4.107

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs.js CHANGED
@@ -50111,7 +50111,21 @@ function toDecimals(number, decimals) {
50111
50111
  var symbol = toEthereumSymbol(decimals);
50112
50112
 
50113
50113
  if (symbol) {
50114
- return web3Utils__default["default"].toWei(numberToString(number), symbol);
50114
+ number = numberToString(number);
50115
+
50116
+ while (true) {
50117
+ try {
50118
+ return web3Utils__default["default"].toWei(number, symbol);
50119
+ } catch (e) {
50120
+ var message = (e.message || e).toLowerCase();
50121
+
50122
+ if (message.indexOf('too many') !== -1) {
50123
+ number = number.substring(0, number.length - 1);
50124
+ } else {
50125
+ throw e;
50126
+ }
50127
+ }
50128
+ }
50115
50129
  }
50116
50130
 
50117
50131
  return numberToString(number * (decimals < 2 ? 1 : Math.pow(10, decimals)));
@@ -64052,107 +64066,165 @@ function _getTokenPriceInDollarsOnUniswap() {
64052
64066
  return _getTokenPriceInDollarsOnUniswap.apply(this, arguments);
64053
64067
  }
64054
64068
 
64055
- function getTokenPriceInDollarsOnUniswapV3(_x5, _x6, _x7) {
64069
+ function getTokenPriceInDollarsOnSushiSwap(_x5, _x6, _x7, _x8) {
64070
+ return _getTokenPriceInDollarsOnSushiSwap.apply(this, arguments);
64071
+ }
64072
+
64073
+ function _getTokenPriceInDollarsOnSushiSwap() {
64074
+ _getTokenPriceInDollarsOnSushiSwap = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref2, tokenAddress, decimals, amountPlain) {
64075
+ var context, newContract, uniswapV2Router, wethAddress, ethereumPrice, path, amount, ethereumValue;
64076
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
64077
+ while (1) {
64078
+ switch (_context2.prev = _context2.next) {
64079
+ case 0:
64080
+ context = _ref2.context, newContract = _ref2.newContract;
64081
+ uniswapV2Router = newContract(context.uniswapV2RouterABI, context.sushiSwapRouterAddress);
64082
+ _context2.t0 = web3Utils__default["default"];
64083
+ _context2.next = 5;
64084
+ return blockchainCall(uniswapV2Router.methods.WETH);
64085
+
64086
+ case 5:
64087
+ _context2.t1 = _context2.sent;
64088
+ wethAddress = _context2.t0.toChecksumAddress.call(_context2.t0, _context2.t1);
64089
+ _context2.next = 9;
64090
+ return getEthereumPrice({
64091
+ context: context
64092
+ });
64093
+
64094
+ case 9:
64095
+ ethereumPrice = _context2.sent;
64096
+ path = [tokenAddress, wethAddress];
64097
+ amount = toDecimals(numberToString(!isNaN(amountPlain) ? amountPlain : 1), decimals);
64098
+ ethereumValue = '0';
64099
+ _context2.prev = 13;
64100
+ _context2.next = 16;
64101
+ return blockchainCall(uniswapV2Router.methods.getAmountsOut, amount, path);
64102
+
64103
+ case 16:
64104
+ ethereumValue = _context2.sent[1];
64105
+ _context2.next = 21;
64106
+ break;
64107
+
64108
+ case 19:
64109
+ _context2.prev = 19;
64110
+ _context2.t2 = _context2["catch"](13);
64111
+
64112
+ case 21:
64113
+ ethereumValue = parseFloat(fromDecimals(ethereumValue, 18, true));
64114
+ ethereumValue *= ethereumPrice;
64115
+ return _context2.abrupt("return", ethereumValue);
64116
+
64117
+ case 24:
64118
+ case "end":
64119
+ return _context2.stop();
64120
+ }
64121
+ }
64122
+ }, _callee2, null, [[13, 19]]);
64123
+ }));
64124
+ return _getTokenPriceInDollarsOnSushiSwap.apply(this, arguments);
64125
+ }
64126
+
64127
+ function getTokenPriceInDollarsOnUniswapV3(_x9, _x10, _x11) {
64056
64128
  return _getTokenPriceInDollarsOnUniswapV.apply(this, arguments);
64057
64129
  }
64058
64130
 
64059
64131
  function _getTokenPriceInDollarsOnUniswapV() {
64060
- _getTokenPriceInDollarsOnUniswapV = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(_ref2, tokenAddress, decimals) {
64132
+ _getTokenPriceInDollarsOnUniswapV = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref3, tokenAddress, decimals) {
64061
64133
  var context, newContract, chainId, uniswapV2Router, wethAddress, ethereumPrice, ethereumValue, univ3Factory, uniToken, uniTokenWeth, proms;
64062
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
64134
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
64063
64135
  while (1) {
64064
- switch (_context3.prev = _context3.next) {
64136
+ switch (_context4.prev = _context4.next) {
64065
64137
  case 0:
64066
- context = _ref2.context, newContract = _ref2.newContract, chainId = _ref2.chainId;
64138
+ context = _ref3.context, newContract = _ref3.newContract, chainId = _ref3.chainId;
64067
64139
  uniswapV2Router = newContract(context.uniswapV2RouterABI, context.uniswapV2RouterAddress);
64068
- _context3.t0 = web3Utils__default["default"];
64069
- _context3.next = 5;
64140
+ _context4.t0 = web3Utils__default["default"];
64141
+ _context4.next = 5;
64070
64142
  return blockchainCall(uniswapV2Router.methods.WETH);
64071
64143
 
64072
64144
  case 5:
64073
- _context3.t1 = _context3.sent;
64074
- wethAddress = _context3.t0.toChecksumAddress.call(_context3.t0, _context3.t1);
64075
- _context3.next = 9;
64145
+ _context4.t1 = _context4.sent;
64146
+ wethAddress = _context4.t0.toChecksumAddress.call(_context4.t0, _context4.t1);
64147
+ _context4.next = 9;
64076
64148
  return getEthereumPrice({
64077
64149
  context: context
64078
64150
  });
64079
64151
 
64080
64152
  case 9:
64081
- ethereumPrice = _context3.sent;
64153
+ ethereumPrice = _context4.sent;
64082
64154
  ethereumValue = '0';
64083
64155
  univ3Factory = newContract(context.UniswapV3FactoryABI, context.uniswapV3FactoryAddress);
64084
64156
  uniToken = new Token(chainId, tokenAddress, parseInt(decimals), 'TOK', 'Token');
64085
64157
  uniTokenWeth = new Token(chainId, wethAddress, 18, 'ETH', 'Ethereum');
64086
- _context3.prev = 14;
64087
- _context3.next = 17;
64158
+ _context4.prev = 14;
64159
+ _context4.next = 17;
64088
64160
  return Promise.all(Object.keys(conversionEncode).map( /*#__PURE__*/function () {
64089
- var _ref3 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(fee) {
64161
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(fee) {
64090
64162
  var pool, slot0, price;
64091
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
64163
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
64092
64164
  while (1) {
64093
- switch (_context2.prev = _context2.next) {
64165
+ switch (_context3.prev = _context3.next) {
64094
64166
  case 0:
64095
- _context2.prev = 0;
64096
- _context2.t0 = newContract;
64097
- _context2.t1 = context.UniswapV3PoolABI;
64098
- _context2.next = 5;
64167
+ _context3.prev = 0;
64168
+ _context3.t0 = newContract;
64169
+ _context3.t1 = context.UniswapV3PoolABI;
64170
+ _context3.next = 5;
64099
64171
  return blockchainCall(univ3Factory.methods.getPool, wethAddress, tokenAddress, fee);
64100
64172
 
64101
64173
  case 5:
64102
- _context2.t2 = _context2.sent;
64103
- pool = (0, _context2.t0)(_context2.t1, _context2.t2);
64104
- _context2.next = 9;
64174
+ _context3.t2 = _context3.sent;
64175
+ pool = (0, _context3.t0)(_context3.t1, _context3.t2);
64176
+ _context3.next = 9;
64105
64177
  return blockchainCall(pool.methods.slot0);
64106
64178
 
64107
64179
  case 9:
64108
- slot0 = _context2.sent;
64180
+ slot0 = _context3.sent;
64109
64181
  price = tickToPrice(uniToken, uniTokenWeth, parseInt(slot0.tick)).toSignificant(15);
64110
- return _context2.abrupt("return", toDecimals(price, 18));
64182
+ return _context3.abrupt("return", toDecimals(price, 18));
64111
64183
 
64112
64184
  case 14:
64113
- _context2.prev = 14;
64114
- _context2.t3 = _context2["catch"](0);
64115
- return _context2.abrupt("return", '0');
64185
+ _context3.prev = 14;
64186
+ _context3.t3 = _context3["catch"](0);
64187
+ return _context3.abrupt("return", '0');
64116
64188
 
64117
64189
  case 17:
64118
64190
  case "end":
64119
- return _context2.stop();
64191
+ return _context3.stop();
64120
64192
  }
64121
64193
  }
64122
- }, _callee2, null, [[0, 14]]);
64194
+ }, _callee3, null, [[0, 14]]);
64123
64195
  }));
64124
64196
 
64125
- return function (_x8) {
64126
- return _ref3.apply(this, arguments);
64197
+ return function (_x12) {
64198
+ return _ref4.apply(this, arguments);
64127
64199
  };
64128
64200
  }()));
64129
64201
 
64130
64202
  case 17:
64131
- proms = _context3.sent.filter(function (it) {
64203
+ proms = _context4.sent.filter(function (it) {
64132
64204
  return it && it !== '0';
64133
64205
  });
64134
64206
  ethereumValue = proms.reduce(function (a, b) {
64135
64207
  return a.ethereansosAdd(b);
64136
64208
  });
64137
64209
  ethereumValue = ethereumValue.ethereansosDiv(proms.length);
64138
- _context3.next = 24;
64210
+ _context4.next = 24;
64139
64211
  break;
64140
64212
 
64141
64213
  case 22:
64142
- _context3.prev = 22;
64143
- _context3.t2 = _context3["catch"](14);
64214
+ _context4.prev = 22;
64215
+ _context4.t2 = _context4["catch"](14);
64144
64216
 
64145
64217
  case 24:
64146
64218
  ethereumValue = parseFloat(fromDecimals(ethereumValue, 18, true));
64147
64219
  ethereumValue *= ethereumPrice;
64148
- return _context3.abrupt("return", ethereumValue);
64220
+ return _context4.abrupt("return", ethereumValue);
64149
64221
 
64150
64222
  case 27:
64151
64223
  case "end":
64152
- return _context3.stop();
64224
+ return _context4.stop();
64153
64225
  }
64154
64226
  }
64155
- }, _callee3, null, [[14, 22]]);
64227
+ }, _callee4, null, [[14, 22]]);
64156
64228
  }));
64157
64229
  return _getTokenPriceInDollarsOnUniswapV.apply(this, arguments);
64158
64230
  }
@@ -64191,7 +64263,7 @@ function _elaboratePrices() {
64191
64263
 
64192
64264
  case 7:
64193
64265
  if ((_step = _iterator.n()).done) {
64194
- _context.next = 36;
64266
+ _context.next = 57;
64195
64267
  break;
64196
64268
  }
64197
64269
 
@@ -64215,61 +64287,103 @@ function _elaboratePrices() {
64215
64287
  response.data[token] = {
64216
64288
  usd: _context.t4
64217
64289
  };
64218
- _context.next = 34;
64290
+ _context.next = 55;
64219
64291
  break;
64220
64292
 
64221
64293
  case 22:
64222
64294
  _context.prev = 22;
64223
64295
  _context.t5 = _context["catch"](9);
64296
+ _context.prev = 24;
64224
64297
  _context.t6 = getTokenPriceInDollarsOnUniswap;
64225
64298
  _context.t7 = _objectSpread2({
64226
64299
  context: context
64227
64300
  }, web3Data);
64228
64301
  _context.t8 = token;
64229
- _context.next = 29;
64302
+ _context.next = 30;
64230
64303
  return blockchainCall(web3Data.newContract(context.ERC20ABI, token).methods.decimals);
64231
64304
 
64232
- case 29:
64305
+ case 30:
64233
64306
  _context.t9 = _context.sent;
64234
- _context.next = 32;
64307
+ _context.next = 33;
64235
64308
  return (0, _context.t6)(_context.t7, _context.t8, _context.t9);
64236
64309
 
64237
- case 32:
64310
+ case 33:
64238
64311
  _context.t10 = _context.sent;
64239
64312
  response.data[token] = {
64240
64313
  usd: _context.t10
64241
64314
  };
64315
+ _context.next = 39;
64316
+ break;
64242
64317
 
64243
- case 34:
64318
+ case 37:
64319
+ _context.prev = 37;
64320
+ _context.t11 = _context["catch"](24);
64321
+
64322
+ case 39:
64323
+ _context.prev = 39;
64324
+
64325
+ if (!(!response.data[token].usd || parseFloat(response.data[token].usd) === 0)) {
64326
+ _context.next = 51;
64327
+ break;
64328
+ }
64329
+
64330
+ _context.t12 = getTokenPriceInDollarsOnSushiSwap;
64331
+ _context.t13 = _objectSpread2({
64332
+ context: context
64333
+ }, web3Data);
64334
+ _context.t14 = token;
64335
+ _context.next = 46;
64336
+ return blockchainCall(web3Data.newContract(context.ERC20ABI, token).methods.decimals);
64337
+
64338
+ case 46:
64339
+ _context.t15 = _context.sent;
64340
+ _context.next = 49;
64341
+ return (0, _context.t12)(_context.t13, _context.t14, _context.t15);
64342
+
64343
+ case 49:
64344
+ _context.t16 = _context.sent;
64345
+ response.data[token] = {
64346
+ usd: _context.t16
64347
+ };
64348
+
64349
+ case 51:
64350
+ _context.next = 55;
64351
+ break;
64352
+
64353
+ case 53:
64354
+ _context.prev = 53;
64355
+ _context.t17 = _context["catch"](39);
64356
+
64357
+ case 55:
64244
64358
  _context.next = 7;
64245
64359
  break;
64246
64360
 
64247
- case 36:
64248
- _context.next = 41;
64361
+ case 57:
64362
+ _context.next = 62;
64249
64363
  break;
64250
64364
 
64251
- case 38:
64252
- _context.prev = 38;
64253
- _context.t11 = _context["catch"](5);
64365
+ case 59:
64366
+ _context.prev = 59;
64367
+ _context.t18 = _context["catch"](5);
64254
64368
 
64255
- _iterator.e(_context.t11);
64369
+ _iterator.e(_context.t18);
64256
64370
 
64257
- case 41:
64258
- _context.prev = 41;
64371
+ case 62:
64372
+ _context.prev = 62;
64259
64373
 
64260
64374
  _iterator.f();
64261
64375
 
64262
- return _context.finish(41);
64376
+ return _context.finish(62);
64263
64377
 
64264
- case 44:
64378
+ case 65:
64265
64379
  return _context.abrupt("return", response);
64266
64380
 
64267
- case 45:
64381
+ case 66:
64268
64382
  case "end":
64269
64383
  return _context.stop();
64270
64384
  }
64271
64385
  }
64272
- }, _callee, null, [[5, 38, 41, 44], [9, 22]]);
64386
+ }, _callee, null, [[5, 59, 62, 65], [9, 22], [24, 37], [39, 53]]);
64273
64387
  }));
64274
64388
  return _elaboratePrices.apply(this, arguments);
64275
64389
  }
@@ -65028,6 +65142,7 @@ exports.getRandomArrayElement = getRandomArrayElement;
65028
65142
  exports.getRandomArrayIndex = getRandomArrayIndex;
65029
65143
  exports.getSolidityUtilities = SolidityUtilities;
65030
65144
  exports.getSupportedSolidityVersion = getSupportedSolidityVersion;
65145
+ exports.getTokenPriceInDollarsOnSushiSwap = getTokenPriceInDollarsOnSushiSwap;
65031
65146
  exports.getTokenPriceInDollarsOnUniswap = getTokenPriceInDollarsOnUniswap;
65032
65147
  exports.getTokenPriceInDollarsOnUniswapV3 = getTokenPriceInDollarsOnUniswapV3;
65033
65148
  exports.getTokenPricesInDollarsOnCoingecko = getTokenPricesInDollarsOnCoingecko;