@ref-finance/ref-sdk 1.1.6 → 1.1.7

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.
@@ -3989,7 +3989,7 @@
3989
3989
  return ftViewFunction(id, {
3990
3990
  methodName: 'ft_metadata'
3991
3991
  })["catch"](function () {
3992
- throw TokenNotExistError;
3992
+ throw TokenNotExistError(id);
3993
3993
  });
3994
3994
  case 4:
3995
3995
  metadata = _context5.sent;
@@ -4018,22 +4018,35 @@
4018
4018
  }();
4019
4019
  var ftGetTokensMetadata = /*#__PURE__*/function () {
4020
4020
  var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(tokenIds, allTokens) {
4021
- var tokensMetadata;
4021
+ var ids, tokensMetadata;
4022
4022
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4023
4023
  while (1) {
4024
4024
  switch (_context6.prev = _context6.next) {
4025
4025
  case 0:
4026
- _context6.next = 2;
4027
- return Promise.all(tokenIds.map(function (id) {
4028
- return allTokens[id] || ftGetTokenMetadata(id);
4026
+ _context6.t0 = tokenIds;
4027
+ if (_context6.t0) {
4028
+ _context6.next = 5;
4029
+ break;
4030
+ }
4031
+ _context6.next = 4;
4032
+ return getGlobalWhitelist();
4033
+ case 4:
4034
+ _context6.t0 = _context6.sent;
4035
+ case 5:
4036
+ ids = _context6.t0;
4037
+ _context6.next = 8;
4038
+ return Promise.all(ids.map(function (id) {
4039
+ return (allTokens == null ? void 0 : allTokens[id]) || ftGetTokenMetadata(id)["catch"](function () {
4040
+ return null;
4041
+ });
4029
4042
  }));
4030
- case 2:
4043
+ case 8:
4031
4044
  tokensMetadata = _context6.sent;
4032
4045
  return _context6.abrupt("return", tokensMetadata.reduce(function (pre, cur, i) {
4033
4046
  var _extends2;
4034
- return _extends({}, pre, (_extends2 = {}, _extends2[tokenIds[i]] = cur, _extends2));
4047
+ return _extends({}, pre, (_extends2 = {}, _extends2[ids[i]] = cur, _extends2));
4035
4048
  }, {}));
4036
- case 4:
4049
+ case 10:
4037
4050
  case "end":
4038
4051
  return _context6.stop();
4039
4052
  }
@@ -4238,7 +4251,9 @@
4238
4251
  var NoPoolError = /*#__PURE__*/formatError('No pool found for the input tokens');
4239
4252
  var NotLoginError = /*#__PURE__*/formatError('Please login in first');
4240
4253
  var SwapRouteError = /*#__PURE__*/formatError("Something wrong happened, we don't get correct routes corrreponding to current input");
4241
- var TokenNotExistError = /*#__PURE__*/formatError("This token doesn't exist in " + /*#__PURE__*/getConfig().networkId);
4254
+ var TokenNotExistError = function TokenNotExistError(id) {
4255
+ return formatError(id + " doesn't exist in " + getConfig().networkId);
4256
+ };
4242
4257
  var NoPuiblicKeyError = /*#__PURE__*/formatError('No public key found');
4243
4258
  var NoLocalSignerError = /*#__PURE__*/formatError('No local signer found');
4244
4259
  var InValidAccessKeyError = /*#__PURE__*/formatError('Invalid access key');
@@ -4511,12 +4526,42 @@
4511
4526
  return _ref6.apply(this, arguments);
4512
4527
  };
4513
4528
  }();
4514
- var getRefPools = /*#__PURE__*/function () {
4515
- var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(page, perPage) {
4516
- var index, poolData;
4529
+ var getPoolByIds = /*#__PURE__*/function () {
4530
+ var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(ids) {
4517
4531
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4518
4532
  while (1) {
4519
4533
  switch (_context5.prev = _context5.next) {
4534
+ case 0:
4535
+ _context5.next = 2;
4536
+ return refFiViewFunction({
4537
+ methodName: 'get_pool_by_ids',
4538
+ args: {
4539
+ pool_ids: ids
4540
+ }
4541
+ }).then(function (pools) {
4542
+ return pools.map(function (p, i) {
4543
+ return parsePool(p, ids[i]);
4544
+ });
4545
+ });
4546
+ case 2:
4547
+ return _context5.abrupt("return", _context5.sent);
4548
+ case 3:
4549
+ case "end":
4550
+ return _context5.stop();
4551
+ }
4552
+ }
4553
+ }, _callee5);
4554
+ }));
4555
+ return function getPoolByIds(_x5) {
4556
+ return _ref7.apply(this, arguments);
4557
+ };
4558
+ }();
4559
+ var getRefPools = /*#__PURE__*/function () {
4560
+ var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(page, perPage) {
4561
+ var index, poolData;
4562
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4563
+ while (1) {
4564
+ switch (_context6.prev = _context6.next) {
4520
4565
  case 0:
4521
4566
  if (page === void 0) {
4522
4567
  page = 1;
@@ -4525,7 +4570,7 @@
4525
4570
  perPage = DEFAULT_PAGE_LIMIT;
4526
4571
  }
4527
4572
  index = (page - 1) * perPage;
4528
- _context5.next = 5;
4573
+ _context6.next = 5;
4529
4574
  return refFiViewFunction({
4530
4575
  methodName: 'get_pools',
4531
4576
  args: {
@@ -4534,43 +4579,43 @@
4534
4579
  }
4535
4580
  });
4536
4581
  case 5:
4537
- poolData = _context5.sent;
4538
- return _context5.abrupt("return", poolData.map(function (rawPool, i) {
4582
+ poolData = _context6.sent;
4583
+ return _context6.abrupt("return", poolData.map(function (rawPool, i) {
4539
4584
  return parsePool(rawPool, i + index);
4540
4585
  }));
4541
4586
  case 7:
4542
4587
  case "end":
4543
- return _context5.stop();
4588
+ return _context6.stop();
4544
4589
  }
4545
4590
  }
4546
- }, _callee5);
4591
+ }, _callee6);
4547
4592
  }));
4548
- return function getRefPools(_x5, _x6) {
4549
- return _ref7.apply(this, arguments);
4593
+ return function getRefPools(_x6, _x7) {
4594
+ return _ref8.apply(this, arguments);
4550
4595
  };
4551
4596
  }();
4552
4597
  var fetchAllPools = /*#__PURE__*/function () {
4553
- var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(perPage) {
4598
+ var _ref9 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(perPage) {
4554
4599
  var totalPools, pages, pools;
4555
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4600
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4556
4601
  while (1) {
4557
- switch (_context6.prev = _context6.next) {
4602
+ switch (_context7.prev = _context7.next) {
4558
4603
  case 0:
4559
4604
  if (perPage) {
4560
4605
  DEFAULT_PAGE_LIMIT = Math.min(perPage, 500);
4561
4606
  }
4562
- _context6.next = 3;
4607
+ _context7.next = 3;
4563
4608
  return getTotalPools();
4564
4609
  case 3:
4565
- totalPools = _context6.sent;
4610
+ totalPools = _context7.sent;
4566
4611
  pages = Math.ceil(totalPools / DEFAULT_PAGE_LIMIT);
4567
- _context6.next = 7;
4612
+ _context7.next = 7;
4568
4613
  return Promise.all([].concat(Array(pages)).fill(0).map(function (_, i) {
4569
4614
  return getRefPools(i + 1);
4570
4615
  }));
4571
4616
  case 7:
4572
- pools = _context6.sent.flat();
4573
- return _context6.abrupt("return", {
4617
+ pools = _context7.sent.flat();
4618
+ return _context7.abrupt("return", {
4574
4619
  simplePools: pools.filter(function (p) {
4575
4620
  return p.pool_kind && p.pool_kind === 'SIMPLE_POOL';
4576
4621
  }),
@@ -4583,13 +4628,13 @@
4583
4628
  });
4584
4629
  case 9:
4585
4630
  case "end":
4586
- return _context6.stop();
4631
+ return _context7.stop();
4587
4632
  }
4588
4633
  }
4589
- }, _callee6);
4634
+ }, _callee7);
4590
4635
  }));
4591
- return function fetchAllPools(_x7) {
4592
- return _ref8.apply(this, arguments);
4636
+ return function fetchAllPools(_x8) {
4637
+ return _ref9.apply(this, arguments);
4593
4638
  };
4594
4639
  }();
4595
4640
 
@@ -8014,6 +8059,7 @@
8014
8059
  exports.getPointByPrice = getPointByPrice;
8015
8060
  exports.getPool = getPool;
8016
8061
  exports.getPoolAllocationPercents = getPoolAllocationPercents;
8062
+ exports.getPoolByIds = getPoolByIds;
8017
8063
  exports.getPoolEstimate = getPoolEstimate;
8018
8064
  exports.getPoolsByTokens = getPoolsByTokens;
8019
8065
  exports.getPriceImpact = getPriceImpact;