@ethereansos/interfaces-core 0.4.104 → 0.4.105

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