@ref-finance/ref-sdk 1.4.4-beta.0-development → 1.4.5

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.
@@ -24,29 +24,32 @@ import { TiWarning } from '@react-icons/all-files/ti/TiWarning';
24
24
  import { CgArrowsExchangeAltV } from '@react-icons/all-files/cg/CgArrowsExchangeAltV';
25
25
 
26
26
  var FEE_DIVISOR = 10000;
27
- var DEFAULT_SLIPPAGE_TOLERANCE = "0.5";
27
+ var DEFAULT_SLIPPAGE_TOLERANCE = '0.5';
28
28
  var STABLE_LP_TOKEN_DECIMALS = 18;
29
29
  var RATED_POOL_LP_TOKEN_DECIMALS = 24;
30
30
  var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
31
31
  //0.0125 NEAR
32
- var FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000";
32
+ var FT_MINIMUM_STORAGE_BALANCE_LARGE = '12500000000000000000000';
33
33
  var ONE_YOCTO_NEAR = '0.000000000000000000000001';
34
34
  var ENV = '';
35
35
  var INDEXER_URL = '';
36
- function getConfig(env, indexerUrl) {
36
+ function getConfig(env, indexerUrl, nodeUrl) {
37
37
  if (env === void 0) {
38
38
  env = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
39
39
  }
40
40
  if (indexerUrl === void 0) {
41
41
  indexerUrl = INDEXER_URL;
42
42
  }
43
+ if (nodeUrl === void 0) {
44
+ nodeUrl = '';
45
+ }
43
46
  ENV = env;
44
47
  INDEXER_URL = indexerUrl;
45
48
  switch (env) {
46
49
  case 'mainnet':
47
50
  return {
48
51
  networkId: 'mainnet',
49
- nodeUrl: 'https://rpc.mainnet.near.org',
52
+ nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
50
53
  walletUrl: 'https://wallet.near.org',
51
54
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
52
55
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
@@ -58,7 +61,7 @@ function getConfig(env, indexerUrl) {
58
61
  case 'testnet':
59
62
  return {
60
63
  networkId: 'testnet',
61
- nodeUrl: 'https://rpc.testnet.near.org',
64
+ nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
62
65
  walletUrl: 'https://wallet.testnet.near.org',
63
66
  indexerUrl: indexerUrl || 'https://testnet-indexer.ref-finance.com',
64
67
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
@@ -70,7 +73,7 @@ function getConfig(env, indexerUrl) {
70
73
  case 'dev':
71
74
  return {
72
75
  networkId: 'testnet',
73
- nodeUrl: 'https://rpc.testnet.near.org',
76
+ nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
74
77
  walletUrl: 'https://wallet.testnet.near.org',
75
78
  indexerUrl: indexerUrl || 'https://dev-indexer.ref-finance.com',
76
79
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
@@ -82,7 +85,7 @@ function getConfig(env, indexerUrl) {
82
85
  default:
83
86
  return {
84
87
  networkId: 'mainnet',
85
- nodeUrl: 'https://rpc.mainnet.near.org',
88
+ nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
86
89
  walletUrl: 'https://wallet.near.org',
87
90
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
88
91
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
@@ -625,7 +628,9 @@ var getSwappedAmount = function getSwappedAmount(tokenInId, tokenOutId, amountIn
625
628
  var out_token_idx = stablePool.token_account_ids.findIndex(function (id) {
626
629
  return id === tokenOutId;
627
630
  });
628
- var rates = stablePool.rates.map(function (r) {
631
+ var rates = stablePool != null && stablePool.degens ? stablePool.degens.map(function (r) {
632
+ return toReadableNumber(STABLE_LP_TOKEN_DECIMALS, r);
633
+ }) : stablePool.rates.map(function (r) {
629
634
  return toReadableNumber(STABLE_LP_TOKEN_DECIMALS, r);
630
635
  });
631
636
  var base_old_c_amounts = stablePool.c_amounts.map(function (amount) {
@@ -2954,7 +2959,7 @@ function _getHybridStableSmart() {
2954
2959
  var tmpPool1 = poolPair[0],
2955
2960
  tmpPool2 = poolPair[1];
2956
2961
  var tokenMidId = poolPair[0].tokenIds.find(function (t) {
2957
- return poolPair[1].tokenIds.includes(t);
2962
+ return poolPair[1].tokenIds.includes(t) && t !== tokenIn.id && t !== tokenOut.id;
2958
2963
  });
2959
2964
  var tokenMidMeta = tokensMedata[tokenMidId];
2960
2965
  var estimate1 = _extends({}, isStablePool(stablePoolsDetail, tmpPool1.id) ? getStablePoolEstimate({
@@ -3028,7 +3033,7 @@ function _getHybridStableSmart() {
3028
3033
  pool1 = BestPoolPair[0];
3029
3034
  pool2 = BestPoolPair[1];
3030
3035
  tokenMidId = BestPoolPair[0].tokenIds.find(function (t) {
3031
- return BestPoolPair[1].tokenIds.includes(t);
3036
+ return BestPoolPair[1].tokenIds.includes(t) && t !== tokenIn.id && t !== tokenOut.id;
3032
3037
  });
3033
3038
  _context3.t0 = allTokens[tokenMidId];
3034
3039
  if (_context3.t0) {
@@ -3244,7 +3249,7 @@ var isStablePool = function isStablePool(stablePools, poolId) {
3244
3249
  }).includes(poolId.toString());
3245
3250
  };
3246
3251
  var getStablePoolDecimal = function getStablePoolDecimal(stablePool) {
3247
- return stablePool.pool_kind === 'RATED_SWAP' ? RATED_POOL_LP_TOKEN_DECIMALS : STABLE_LP_TOKEN_DECIMALS;
3252
+ return stablePool.pool_kind === 'RATED_SWAP' || stablePool.pool_kind === 'DEGEN_SWAP' ? RATED_POOL_LP_TOKEN_DECIMALS : STABLE_LP_TOKEN_DECIMALS;
3248
3253
  };
3249
3254
  var round = function round(decimals, minAmountOut) {
3250
3255
  return Number.isInteger(Number(minAmountOut)) ? minAmountOut : Math.ceil(Math.round(Number(minAmountOut) * Math.pow(10, decimals)) / Math.pow(10, decimals)).toString();
@@ -3924,11 +3929,11 @@ var near = /*#__PURE__*/new Near( /*#__PURE__*/_extends({
3924
3929
  keyStore: /*#__PURE__*/getKeyStore(),
3925
3930
  headers: {}
3926
3931
  }, /*#__PURE__*/getConfig()));
3927
- var init_env = function init_env(env, indexerUrl) {
3932
+ var init_env = function init_env(env, indexerUrl, nodeUrl) {
3928
3933
  near = new Near(_extends({
3929
3934
  keyStore: getKeyStore(),
3930
3935
  headers: {}
3931
- }, getConfig(env, indexerUrl)));
3936
+ }, getConfig(env, indexerUrl, nodeUrl)));
3932
3937
  return switchEnv();
3933
3938
  };
3934
3939
  var refFiViewFunction = /*#__PURE__*/function () {
@@ -4518,7 +4523,7 @@ var instantSwap = /*#__PURE__*/function () {
4518
4523
  actions: actionsList
4519
4524
  })
4520
4525
  },
4521
- gas: '180000000000000',
4526
+ gas: '300000000000000',
4522
4527
  amount: ONE_YOCTO_NEAR
4523
4528
  }]
4524
4529
  });
@@ -4555,7 +4560,7 @@ var getRatedPoolDetail = /*#__PURE__*/function () {
4555
4560
  id: Number(id),
4556
4561
  pool_kind: 'RATED_SWAP'
4557
4562
  });
4558
- }));
4563
+ })["catch"](function () {}));
4559
4564
  case 2:
4560
4565
  case "end":
4561
4566
  return _context.stop();
@@ -4588,7 +4593,7 @@ var getUnRatedPoolDetail = /*#__PURE__*/function () {
4588
4593
  return toNonDivisibleNumber(STABLE_LP_TOKEN_DECIMALS, '1');
4589
4594
  })
4590
4595
  });
4591
- }));
4596
+ })["catch"](function () {}));
4592
4597
  case 2:
4593
4598
  case "end":
4594
4599
  return _context2.stop();
@@ -4621,7 +4626,7 @@ var getDegenPoolDetail = /*#__PURE__*/function () {
4621
4626
  return toNonDivisibleNumber(STABLE_LP_TOKEN_DECIMALS, '1');
4622
4627
  })
4623
4628
  });
4624
- }));
4629
+ })["catch"](function () {}));
4625
4630
  case 2:
4626
4631
  case "end":
4627
4632
  return _context3.stop();
@@ -4635,11 +4640,13 @@ var getDegenPoolDetail = /*#__PURE__*/function () {
4635
4640
  }();
4636
4641
  var getStablePools = /*#__PURE__*/function () {
4637
4642
  var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(stablePools) {
4643
+ var res;
4638
4644
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4639
4645
  while (1) {
4640
4646
  switch (_context4.prev = _context4.next) {
4641
4647
  case 0:
4642
- return _context4.abrupt("return", Promise.all(stablePools.map(function (pool) {
4648
+ _context4.next = 2;
4649
+ return Promise.allSettled(stablePools.map(function (pool) {
4643
4650
  return pool.pool_kind === 'RATED_SWAP' ? getRatedPoolDetail({
4644
4651
  id: pool.id
4645
4652
  }) : pool.pool_kind === 'DEGEN_SWAP' ? getDegenPoolDetail({
@@ -4647,8 +4654,16 @@ var getStablePools = /*#__PURE__*/function () {
4647
4654
  }) : pool.pool_kind === 'STABLE_SWAP' ? getUnRatedPoolDetail({
4648
4655
  id: pool.id
4649
4656
  }) : getPool(pool.id);
4650
- })));
4651
- case 1:
4657
+ }));
4658
+ case 2:
4659
+ res = _context4.sent;
4660
+ return _context4.abrupt("return", res.reduce(function (acc, cur) {
4661
+ if (cur.status === 'fulfilled' && cur.value) {
4662
+ return [].concat(acc || [], [cur.value]);
4663
+ }
4664
+ return acc;
4665
+ }, []));
4666
+ case 4:
4652
4667
  case "end":
4653
4668
  return _context4.stop();
4654
4669
  }
@@ -4673,7 +4688,7 @@ var getPool = /*#__PURE__*/function () {
4673
4688
  }
4674
4689
  }).then(function (pool) {
4675
4690
  return parsePool(pool, id);
4676
- });
4691
+ })["catch"]();
4677
4692
  case 2:
4678
4693
  return _context5.abrupt("return", _context5.sent);
4679
4694
  case 3: