@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.
package/README.md CHANGED
@@ -243,6 +243,75 @@ Response
243
243
  ]
244
244
  ```
245
245
 
246
+ ---
247
+
248
+ #### getPoolByIds
249
+
250
+ Input pool id array to get according pools detail
251
+
252
+ Parameters
253
+
254
+ ```
255
+ ids: number[]
256
+ ```
257
+
258
+ Example
259
+
260
+ ```
261
+ const pools = await getPoolByIds([1, 2, 20])
262
+ ```
263
+
264
+ Response
265
+
266
+ ```
267
+ [
268
+ {
269
+ "id": 1,
270
+ "tokenIds": [
271
+ "nusdt.ft-fin.testnet",
272
+ "nusdc.ft-fin.testnet"
273
+ ],
274
+ "supplies": {
275
+ "nusdt.ft-fin.testnet": "194177",
276
+ "nusdc.ft-fin.testnet": "54127"
277
+ },
278
+ "fee": 20,
279
+ "shareSupply": "1004672374319452764166320",
280
+ "pool_kind": "SIMPLE_POOL"
281
+ },
282
+ {
283
+ "id": 2,
284
+ "tokenIds": [
285
+ "wrap.testnet",
286
+ "rft.tokenfactory.testnet"
287
+ ],
288
+ "supplies": {
289
+ "wrap.testnet": "511569006838329327251856820",
290
+ "rft.tokenfactory.testnet": "860281941972"
291
+ },
292
+ "fee": 20,
293
+ "shareSupply": "935312501418615016412773941",
294
+ "pool_kind": "SIMPLE_POOL"
295
+ },
296
+ {
297
+ "id": 20,
298
+ "tokenIds": [
299
+ "usdc.fakes.testnet",
300
+ "nusdc.ft-fin.testnet"
301
+ ],
302
+ "supplies": {
303
+ "usdc.fakes.testnet": "129199395436",
304
+ "nusdc.ft-fin.testnet": "26747"
305
+ },
306
+ "fee": 20,
307
+ "shareSupply": "7084500646929369809446253",
308
+ "pool_kind": "SIMPLE_POOL"
309
+ }
310
+ ]
311
+ ```
312
+
313
+
314
+
246
315
  ---
247
316
 
248
317
  ### Swap
package/dist/error.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const ZeroInputError: Error;
5
5
  export declare const NoPoolError: Error;
6
6
  export declare const NotLoginError: Error;
7
7
  export declare const SwapRouteError: Error;
8
- export declare const TokenNotExistError: Error;
8
+ export declare const TokenNotExistError: (id: string) => Error;
9
9
  export declare const NoPuiblicKeyError: Error;
10
10
  export declare const NoLocalSignerError: Error;
11
11
  export declare const InValidAccessKeyError: Error;
@@ -4008,7 +4008,7 @@ var ftGetTokenMetadata = /*#__PURE__*/function () {
4008
4008
  return ftViewFunction(id, {
4009
4009
  methodName: 'ft_metadata'
4010
4010
  })["catch"](function () {
4011
- throw TokenNotExistError;
4011
+ throw TokenNotExistError(id);
4012
4012
  });
4013
4013
  case 4:
4014
4014
  metadata = _context5.sent;
@@ -4037,22 +4037,35 @@ var ftGetTokenMetadata = /*#__PURE__*/function () {
4037
4037
  }();
4038
4038
  var ftGetTokensMetadata = /*#__PURE__*/function () {
4039
4039
  var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(tokenIds, allTokens) {
4040
- var tokensMetadata;
4040
+ var ids, tokensMetadata;
4041
4041
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4042
4042
  while (1) {
4043
4043
  switch (_context6.prev = _context6.next) {
4044
4044
  case 0:
4045
- _context6.next = 2;
4046
- return Promise.all(tokenIds.map(function (id) {
4047
- return allTokens[id] || ftGetTokenMetadata(id);
4045
+ _context6.t0 = tokenIds;
4046
+ if (_context6.t0) {
4047
+ _context6.next = 5;
4048
+ break;
4049
+ }
4050
+ _context6.next = 4;
4051
+ return getGlobalWhitelist();
4052
+ case 4:
4053
+ _context6.t0 = _context6.sent;
4054
+ case 5:
4055
+ ids = _context6.t0;
4056
+ _context6.next = 8;
4057
+ return Promise.all(ids.map(function (id) {
4058
+ return (allTokens == null ? void 0 : allTokens[id]) || ftGetTokenMetadata(id)["catch"](function () {
4059
+ return null;
4060
+ });
4048
4061
  }));
4049
- case 2:
4062
+ case 8:
4050
4063
  tokensMetadata = _context6.sent;
4051
4064
  return _context6.abrupt("return", tokensMetadata.reduce(function (pre, cur, i) {
4052
4065
  var _extends2;
4053
- return _extends({}, pre, (_extends2 = {}, _extends2[tokenIds[i]] = cur, _extends2));
4066
+ return _extends({}, pre, (_extends2 = {}, _extends2[ids[i]] = cur, _extends2));
4054
4067
  }, {}));
4055
- case 4:
4068
+ case 10:
4056
4069
  case "end":
4057
4070
  return _context6.stop();
4058
4071
  }
@@ -4257,7 +4270,9 @@ var ZeroInputError = /*#__PURE__*/formatError('Input amount should be greater th
4257
4270
  var NoPoolError = /*#__PURE__*/formatError('No pool found for the input tokens');
4258
4271
  var NotLoginError = /*#__PURE__*/formatError('Please login in first');
4259
4272
  var SwapRouteError = /*#__PURE__*/formatError("Something wrong happened, we don't get correct routes corrreponding to current input");
4260
- var TokenNotExistError = /*#__PURE__*/formatError("This token doesn't exist in " + /*#__PURE__*/getConfig().networkId);
4273
+ var TokenNotExistError = function TokenNotExistError(id) {
4274
+ return formatError(id + " doesn't exist in " + getConfig().networkId);
4275
+ };
4261
4276
  var NoPuiblicKeyError = /*#__PURE__*/formatError('No public key found');
4262
4277
  var NoLocalSignerError = /*#__PURE__*/formatError('No local signer found');
4263
4278
  var InValidAccessKeyError = /*#__PURE__*/formatError('Invalid access key');
@@ -4530,12 +4545,42 @@ var getPool = /*#__PURE__*/function () {
4530
4545
  return _ref6.apply(this, arguments);
4531
4546
  };
4532
4547
  }();
4533
- var getRefPools = /*#__PURE__*/function () {
4534
- var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(page, perPage) {
4535
- var index, poolData;
4548
+ var getPoolByIds = /*#__PURE__*/function () {
4549
+ var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(ids) {
4536
4550
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4537
4551
  while (1) {
4538
4552
  switch (_context5.prev = _context5.next) {
4553
+ case 0:
4554
+ _context5.next = 2;
4555
+ return refFiViewFunction({
4556
+ methodName: 'get_pool_by_ids',
4557
+ args: {
4558
+ pool_ids: ids
4559
+ }
4560
+ }).then(function (pools) {
4561
+ return pools.map(function (p, i) {
4562
+ return parsePool(p, ids[i]);
4563
+ });
4564
+ });
4565
+ case 2:
4566
+ return _context5.abrupt("return", _context5.sent);
4567
+ case 3:
4568
+ case "end":
4569
+ return _context5.stop();
4570
+ }
4571
+ }
4572
+ }, _callee5);
4573
+ }));
4574
+ return function getPoolByIds(_x5) {
4575
+ return _ref7.apply(this, arguments);
4576
+ };
4577
+ }();
4578
+ var getRefPools = /*#__PURE__*/function () {
4579
+ var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(page, perPage) {
4580
+ var index, poolData;
4581
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4582
+ while (1) {
4583
+ switch (_context6.prev = _context6.next) {
4539
4584
  case 0:
4540
4585
  if (page === void 0) {
4541
4586
  page = 1;
@@ -4544,7 +4589,7 @@ var getRefPools = /*#__PURE__*/function () {
4544
4589
  perPage = DEFAULT_PAGE_LIMIT;
4545
4590
  }
4546
4591
  index = (page - 1) * perPage;
4547
- _context5.next = 5;
4592
+ _context6.next = 5;
4548
4593
  return refFiViewFunction({
4549
4594
  methodName: 'get_pools',
4550
4595
  args: {
@@ -4553,43 +4598,43 @@ var getRefPools = /*#__PURE__*/function () {
4553
4598
  }
4554
4599
  });
4555
4600
  case 5:
4556
- poolData = _context5.sent;
4557
- return _context5.abrupt("return", poolData.map(function (rawPool, i) {
4601
+ poolData = _context6.sent;
4602
+ return _context6.abrupt("return", poolData.map(function (rawPool, i) {
4558
4603
  return parsePool(rawPool, i + index);
4559
4604
  }));
4560
4605
  case 7:
4561
4606
  case "end":
4562
- return _context5.stop();
4607
+ return _context6.stop();
4563
4608
  }
4564
4609
  }
4565
- }, _callee5);
4610
+ }, _callee6);
4566
4611
  }));
4567
- return function getRefPools(_x5, _x6) {
4568
- return _ref7.apply(this, arguments);
4612
+ return function getRefPools(_x6, _x7) {
4613
+ return _ref8.apply(this, arguments);
4569
4614
  };
4570
4615
  }();
4571
4616
  var fetchAllPools = /*#__PURE__*/function () {
4572
- var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(perPage) {
4617
+ var _ref9 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(perPage) {
4573
4618
  var totalPools, pages, pools;
4574
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4619
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4575
4620
  while (1) {
4576
- switch (_context6.prev = _context6.next) {
4621
+ switch (_context7.prev = _context7.next) {
4577
4622
  case 0:
4578
4623
  if (perPage) {
4579
4624
  DEFAULT_PAGE_LIMIT = Math.min(perPage, 500);
4580
4625
  }
4581
- _context6.next = 3;
4626
+ _context7.next = 3;
4582
4627
  return getTotalPools();
4583
4628
  case 3:
4584
- totalPools = _context6.sent;
4629
+ totalPools = _context7.sent;
4585
4630
  pages = Math.ceil(totalPools / DEFAULT_PAGE_LIMIT);
4586
- _context6.next = 7;
4631
+ _context7.next = 7;
4587
4632
  return Promise.all([].concat(Array(pages)).fill(0).map(function (_, i) {
4588
4633
  return getRefPools(i + 1);
4589
4634
  }));
4590
4635
  case 7:
4591
- pools = _context6.sent.flat();
4592
- return _context6.abrupt("return", {
4636
+ pools = _context7.sent.flat();
4637
+ return _context7.abrupt("return", {
4593
4638
  simplePools: pools.filter(function (p) {
4594
4639
  return p.pool_kind && p.pool_kind === 'SIMPLE_POOL';
4595
4640
  }),
@@ -4602,13 +4647,13 @@ var fetchAllPools = /*#__PURE__*/function () {
4602
4647
  });
4603
4648
  case 9:
4604
4649
  case "end":
4605
- return _context6.stop();
4650
+ return _context7.stop();
4606
4651
  }
4607
4652
  }
4608
- }, _callee6);
4653
+ }, _callee7);
4609
4654
  }));
4610
- return function fetchAllPools(_x7) {
4611
- return _ref8.apply(this, arguments);
4655
+ return function fetchAllPools(_x8) {
4656
+ return _ref9.apply(this, arguments);
4612
4657
  };
4613
4658
  }();
4614
4659
 
@@ -8003,6 +8048,7 @@ exports.getMemorySigner = getMemorySigner;
8003
8048
  exports.getPointByPrice = getPointByPrice;
8004
8049
  exports.getPool = getPool;
8005
8050
  exports.getPoolAllocationPercents = getPoolAllocationPercents;
8051
+ exports.getPoolByIds = getPoolByIds;
8006
8052
  exports.getPoolEstimate = getPoolEstimate;
8007
8053
  exports.getPoolsByTokens = getPoolsByTokens;
8008
8054
  exports.getPriceImpact = getPriceImpact;