@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.
package/README.md CHANGED
@@ -72,6 +72,8 @@ export function getConfig(
72
72
 
73
73
  Also, the SDK provides `init_env` to switch application environment. there is an optional parameter indexerUrl that you can use to replace the one in the SDK with your own deployed indexer service. We'd better call it at the entrance of the application, then the entire application environment switch takes effect. If you're not sure where to call, you can call in more than one place.
74
74
 
75
+ An optional property nodeUrl has been added as the third parameter, allowing developers to pass their own nodeUrl to replace the default nodeUrl in the SDK.
76
+
75
77
  Example
76
78
 
77
79
  ```
@@ -79,6 +81,8 @@ init_env('testnet');
79
81
  init_env('mainnet');
80
82
  init_env('testnet', 'https://xx-xx.xx-xxx.com');
81
83
  init_env('mainnet', 'https://xx-xx.xx-xxx.com');
84
+ init_env('mainnet', 'https://xx-xx.xx-xxx.com', 'https://beta.rpc.mainnet.near.org');
85
+ init_env('mainnet', '', 'https://beta.rpc.mainnet.near.org');
82
86
  ```
83
87
 
84
88
 
@@ -6,7 +6,7 @@ export declare const RATED_POOL_LP_TOKEN_DECIMALS = 24;
6
6
  export declare const STORAGE_TO_REGISTER_WITH_MFT = "0.1";
7
7
  export declare const FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000";
8
8
  export declare const ONE_YOCTO_NEAR = "0.000000000000000000000001";
9
- export declare function getConfig(env?: string | undefined, indexerUrl?: string | undefined): {
9
+ export declare function getConfig(env?: string | undefined, indexerUrl?: string | undefined, nodeUrl?: string | undefined): {
10
10
  networkId: string;
11
11
  nodeUrl: string;
12
12
  walletUrl: string;
@@ -31,29 +31,32 @@ var TiWarning = require('@react-icons/all-files/ti/TiWarning');
31
31
  var CgArrowsExchangeAltV = require('@react-icons/all-files/cg/CgArrowsExchangeAltV');
32
32
 
33
33
  var FEE_DIVISOR = 10000;
34
- var DEFAULT_SLIPPAGE_TOLERANCE = "0.5";
34
+ var DEFAULT_SLIPPAGE_TOLERANCE = '0.5';
35
35
  var STABLE_LP_TOKEN_DECIMALS = 18;
36
36
  var RATED_POOL_LP_TOKEN_DECIMALS = 24;
37
37
  var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
38
38
  //0.0125 NEAR
39
- var FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000";
39
+ var FT_MINIMUM_STORAGE_BALANCE_LARGE = '12500000000000000000000';
40
40
  var ONE_YOCTO_NEAR = '0.000000000000000000000001';
41
41
  var ENV = '';
42
42
  var INDEXER_URL = '';
43
- function getConfig(env, indexerUrl) {
43
+ function getConfig(env, indexerUrl, nodeUrl) {
44
44
  if (env === void 0) {
45
45
  env = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
46
46
  }
47
47
  if (indexerUrl === void 0) {
48
48
  indexerUrl = INDEXER_URL;
49
49
  }
50
+ if (nodeUrl === void 0) {
51
+ nodeUrl = '';
52
+ }
50
53
  ENV = env;
51
54
  INDEXER_URL = indexerUrl;
52
55
  switch (env) {
53
56
  case 'mainnet':
54
57
  return {
55
58
  networkId: 'mainnet',
56
- nodeUrl: 'https://rpc.mainnet.near.org',
59
+ nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
57
60
  walletUrl: 'https://wallet.near.org',
58
61
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
59
62
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
@@ -65,7 +68,7 @@ function getConfig(env, indexerUrl) {
65
68
  case 'testnet':
66
69
  return {
67
70
  networkId: 'testnet',
68
- nodeUrl: 'https://rpc.testnet.near.org',
71
+ nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
69
72
  walletUrl: 'https://wallet.testnet.near.org',
70
73
  indexerUrl: indexerUrl || 'https://testnet-indexer.ref-finance.com',
71
74
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
@@ -77,7 +80,7 @@ function getConfig(env, indexerUrl) {
77
80
  case 'dev':
78
81
  return {
79
82
  networkId: 'testnet',
80
- nodeUrl: 'https://rpc.testnet.near.org',
83
+ nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
81
84
  walletUrl: 'https://wallet.testnet.near.org',
82
85
  indexerUrl: indexerUrl || 'https://dev-indexer.ref-finance.com',
83
86
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
@@ -89,7 +92,7 @@ function getConfig(env, indexerUrl) {
89
92
  default:
90
93
  return {
91
94
  networkId: 'mainnet',
92
- nodeUrl: 'https://rpc.mainnet.near.org',
95
+ nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
93
96
  walletUrl: 'https://wallet.near.org',
94
97
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
95
98
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
@@ -632,7 +635,9 @@ var getSwappedAmount = function getSwappedAmount(tokenInId, tokenOutId, amountIn
632
635
  var out_token_idx = stablePool.token_account_ids.findIndex(function (id) {
633
636
  return id === tokenOutId;
634
637
  });
635
- var rates = stablePool.rates.map(function (r) {
638
+ var rates = stablePool != null && stablePool.degens ? stablePool.degens.map(function (r) {
639
+ return toReadableNumber(STABLE_LP_TOKEN_DECIMALS, r);
640
+ }) : stablePool.rates.map(function (r) {
636
641
  return toReadableNumber(STABLE_LP_TOKEN_DECIMALS, r);
637
642
  });
638
643
  var base_old_c_amounts = stablePool.c_amounts.map(function (amount) {
@@ -2960,7 +2965,7 @@ function _getHybridStableSmart() {
2960
2965
  var tmpPool1 = poolPair[0],
2961
2966
  tmpPool2 = poolPair[1];
2962
2967
  var tokenMidId = poolPair[0].tokenIds.find(function (t) {
2963
- return poolPair[1].tokenIds.includes(t);
2968
+ return poolPair[1].tokenIds.includes(t) && t !== tokenIn.id && t !== tokenOut.id;
2964
2969
  });
2965
2970
  var tokenMidMeta = tokensMedata[tokenMidId];
2966
2971
  var estimate1 = _extends({}, isStablePool(stablePoolsDetail, tmpPool1.id) ? getStablePoolEstimate({
@@ -3034,7 +3039,7 @@ function _getHybridStableSmart() {
3034
3039
  pool1 = BestPoolPair[0];
3035
3040
  pool2 = BestPoolPair[1];
3036
3041
  tokenMidId = BestPoolPair[0].tokenIds.find(function (t) {
3037
- return BestPoolPair[1].tokenIds.includes(t);
3042
+ return BestPoolPair[1].tokenIds.includes(t) && t !== tokenIn.id && t !== tokenOut.id;
3038
3043
  });
3039
3044
  _context3.t0 = allTokens[tokenMidId];
3040
3045
  if (_context3.t0) {
@@ -3250,7 +3255,7 @@ var isStablePool = function isStablePool(stablePools, poolId) {
3250
3255
  }).includes(poolId.toString());
3251
3256
  };
3252
3257
  var getStablePoolDecimal = function getStablePoolDecimal(stablePool) {
3253
- return stablePool.pool_kind === 'RATED_SWAP' ? RATED_POOL_LP_TOKEN_DECIMALS : STABLE_LP_TOKEN_DECIMALS;
3258
+ return stablePool.pool_kind === 'RATED_SWAP' || stablePool.pool_kind === 'DEGEN_SWAP' ? RATED_POOL_LP_TOKEN_DECIMALS : STABLE_LP_TOKEN_DECIMALS;
3254
3259
  };
3255
3260
  var round = function round(decimals, minAmountOut) {
3256
3261
  return Number.isInteger(Number(minAmountOut)) ? minAmountOut : Math.ceil(Math.round(Number(minAmountOut) * Math.pow(10, decimals)) / Math.pow(10, decimals)).toString();
@@ -3930,11 +3935,11 @@ var near = /*#__PURE__*/new nearApiJs.Near( /*#__PURE__*/_extends({
3930
3935
  keyStore: /*#__PURE__*/getKeyStore(),
3931
3936
  headers: {}
3932
3937
  }, /*#__PURE__*/getConfig()));
3933
- var init_env = function init_env(env, indexerUrl) {
3938
+ var init_env = function init_env(env, indexerUrl, nodeUrl) {
3934
3939
  near = new nearApiJs.Near(_extends({
3935
3940
  keyStore: getKeyStore(),
3936
3941
  headers: {}
3937
- }, getConfig(env, indexerUrl)));
3942
+ }, getConfig(env, indexerUrl, nodeUrl)));
3938
3943
  return switchEnv();
3939
3944
  };
3940
3945
  var refFiViewFunction = /*#__PURE__*/function () {
@@ -4524,7 +4529,7 @@ var instantSwap = /*#__PURE__*/function () {
4524
4529
  actions: actionsList
4525
4530
  })
4526
4531
  },
4527
- gas: '180000000000000',
4532
+ gas: '300000000000000',
4528
4533
  amount: ONE_YOCTO_NEAR
4529
4534
  }]
4530
4535
  });
@@ -4561,7 +4566,7 @@ var getRatedPoolDetail = /*#__PURE__*/function () {
4561
4566
  id: Number(id),
4562
4567
  pool_kind: 'RATED_SWAP'
4563
4568
  });
4564
- }));
4569
+ })["catch"](function () {}));
4565
4570
  case 2:
4566
4571
  case "end":
4567
4572
  return _context.stop();
@@ -4594,7 +4599,7 @@ var getUnRatedPoolDetail = /*#__PURE__*/function () {
4594
4599
  return toNonDivisibleNumber(STABLE_LP_TOKEN_DECIMALS, '1');
4595
4600
  })
4596
4601
  });
4597
- }));
4602
+ })["catch"](function () {}));
4598
4603
  case 2:
4599
4604
  case "end":
4600
4605
  return _context2.stop();
@@ -4627,7 +4632,7 @@ var getDegenPoolDetail = /*#__PURE__*/function () {
4627
4632
  return toNonDivisibleNumber(STABLE_LP_TOKEN_DECIMALS, '1');
4628
4633
  })
4629
4634
  });
4630
- }));
4635
+ })["catch"](function () {}));
4631
4636
  case 2:
4632
4637
  case "end":
4633
4638
  return _context3.stop();
@@ -4641,11 +4646,13 @@ var getDegenPoolDetail = /*#__PURE__*/function () {
4641
4646
  }();
4642
4647
  var getStablePools = /*#__PURE__*/function () {
4643
4648
  var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(stablePools) {
4649
+ var res;
4644
4650
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4645
4651
  while (1) {
4646
4652
  switch (_context4.prev = _context4.next) {
4647
4653
  case 0:
4648
- return _context4.abrupt("return", Promise.all(stablePools.map(function (pool) {
4654
+ _context4.next = 2;
4655
+ return Promise.allSettled(stablePools.map(function (pool) {
4649
4656
  return pool.pool_kind === 'RATED_SWAP' ? getRatedPoolDetail({
4650
4657
  id: pool.id
4651
4658
  }) : pool.pool_kind === 'DEGEN_SWAP' ? getDegenPoolDetail({
@@ -4653,8 +4660,16 @@ var getStablePools = /*#__PURE__*/function () {
4653
4660
  }) : pool.pool_kind === 'STABLE_SWAP' ? getUnRatedPoolDetail({
4654
4661
  id: pool.id
4655
4662
  }) : getPool(pool.id);
4656
- })));
4657
- case 1:
4663
+ }));
4664
+ case 2:
4665
+ res = _context4.sent;
4666
+ return _context4.abrupt("return", res.reduce(function (acc, cur) {
4667
+ if (cur.status === 'fulfilled' && cur.value) {
4668
+ return [].concat(acc || [], [cur.value]);
4669
+ }
4670
+ return acc;
4671
+ }, []));
4672
+ case 4:
4658
4673
  case "end":
4659
4674
  return _context4.stop();
4660
4675
  }
@@ -4679,7 +4694,7 @@ var getPool = /*#__PURE__*/function () {
4679
4694
  }
4680
4695
  }).then(function (pool) {
4681
4696
  return parsePool(pool, id);
4682
- });
4697
+ })["catch"]();
4683
4698
  case 2:
4684
4699
  return _context5.abrupt("return", _context5.sent);
4685
4700
  case 3: