@ref-finance/ref-sdk 1.1.3 → 1.1.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.
@@ -33,11 +33,16 @@ var CgArrowsExchangeAltV = require('@react-icons/all-files/cg/CgArrowsExchangeAl
33
33
  var FEE_DIVISOR = 10000;
34
34
  var STABLE_LP_TOKEN_DECIMALS = 18;
35
35
  var RATED_POOL_LP_TOKEN_DECIMALS = 24;
36
+ var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
37
+ var ONE_YOCTO_NEAR = '0.000000000000000000000001';
38
+ var ENV = '';
36
39
  function getConfig(env) {
37
40
  if (env === void 0) {
38
- env = process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
41
+ env = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
39
42
  }
40
43
 
44
+ ENV = env;
45
+
41
46
  switch (env) {
42
47
  case 'mainnet':
43
48
  return {
@@ -55,7 +60,7 @@ function getConfig(env) {
55
60
  case 'testnet':
56
61
  return {
57
62
  networkId: 'testnet',
58
- nodeUrl: 'https://near-testnet.infura.io/v3/388c72223585424086eea3872bb0ba2c',
63
+ nodeUrl: 'https://rpc.testnet.near.org',
59
64
  walletUrl: 'https://wallet.testnet.near.org',
60
65
  indexerUrl: 'https://testnet-indexer.ref-finance.com',
61
66
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
@@ -79,23 +84,21 @@ function getConfig(env) {
79
84
  };
80
85
  }
81
86
  }
82
- var config = /*#__PURE__*/getConfig();
83
- var REF_FI_CONTRACT_ID = config.REF_FI_CONTRACT_ID;
84
- var WRAP_NEAR_CONTRACT_ID = config.WRAP_NEAR_CONTRACT_ID;
85
- var REF_TOKEN_ID = config.REF_TOKEN_ID;
86
- var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
87
- var ONE_YOCTO_NEAR = '0.000000000000000000000001';
88
- var WNEAR_META_DATA = {
89
- id: WRAP_NEAR_CONTRACT_ID,
87
+ exports.config = /*#__PURE__*/getConfig();
88
+ exports.REF_FI_CONTRACT_ID = exports.config.REF_FI_CONTRACT_ID;
89
+ exports.WRAP_NEAR_CONTRACT_ID = exports.config.WRAP_NEAR_CONTRACT_ID;
90
+ exports.REF_TOKEN_ID = exports.config.REF_TOKEN_ID;
91
+ exports.WNEAR_META_DATA = {
92
+ id: exports.WRAP_NEAR_CONTRACT_ID,
90
93
  name: 'wNEAR',
91
94
  symbol: 'wNEAR',
92
95
  decimals: 24,
93
96
  icon: 'https://assets.ref.finance/images/w-NEAR-no-border.png'
94
97
  };
95
- var REF_META_DATA = {
98
+ exports.REF_META_DATA = {
96
99
  decimals: 18,
97
100
  icon: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='16 24 248 248' style='background: %23000'%3E%3Cpath d='M164,164v52h52Zm-45-45,20.4,20.4,20.6-20.6V81H119Zm0,18.39V216h41V137.19l-20.6,20.6ZM166.5,81H164v33.81l26.16-26.17A40.29,40.29,0,0,0,166.5,81ZM72,153.19V216h43V133.4l-11.6-11.61Zm0-18.38,31.4-31.4L115,115V81H72ZM207,121.5h0a40.29,40.29,0,0,0-7.64-23.66L164,133.19V162h2.5A40.5,40.5,0,0,0,207,121.5Z' fill='%23fff'/%3E%3Cpath d='M189 72l27 27V72h-27z' fill='%2300c08b'/%3E%3C/svg%3E%0A",
98
- id: REF_TOKEN_ID,
101
+ id: exports.REF_TOKEN_ID,
99
102
  name: 'Ref Finance Token',
100
103
  symbol: 'REF'
101
104
  };
@@ -152,6 +155,34 @@ var TokenLinks = {
152
155
  var CONSTANT_D = 1.0001;
153
156
  var POINTLEFTRANGE = -800000;
154
157
  var POINTRIGHTRANGE = 800000;
158
+ var switchEnv = function switchEnv() {
159
+ exports.config = getConfig();
160
+ exports.REF_FI_CONTRACT_ID = exports.config.REF_FI_CONTRACT_ID;
161
+ exports.WRAP_NEAR_CONTRACT_ID = exports.config.WRAP_NEAR_CONTRACT_ID;
162
+ exports.REF_TOKEN_ID = exports.config.REF_TOKEN_ID;
163
+ exports.REF_META_DATA = {
164
+ decimals: 18,
165
+ icon: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='16 24 248 248' style='background: %23000'%3E%3Cpath d='M164,164v52h52Zm-45-45,20.4,20.4,20.6-20.6V81H119Zm0,18.39V216h41V137.19l-20.6,20.6ZM166.5,81H164v33.81l26.16-26.17A40.29,40.29,0,0,0,166.5,81ZM72,153.19V216h43V133.4l-11.6-11.61Zm0-18.38,31.4-31.4L115,115V81H72ZM207,121.5h0a40.29,40.29,0,0,0-7.64-23.66L164,133.19V162h2.5A40.5,40.5,0,0,0,207,121.5Z' fill='%23fff'/%3E%3Cpath d='M189 72l27 27V72h-27z' fill='%2300c08b'/%3E%3C/svg%3E%0A",
166
+ id: exports.REF_TOKEN_ID,
167
+ name: 'Ref Finance Token',
168
+ symbol: 'REF'
169
+ };
170
+ exports.WNEAR_META_DATA = {
171
+ id: exports.WRAP_NEAR_CONTRACT_ID,
172
+ name: 'wNEAR',
173
+ symbol: 'wNEAR',
174
+ decimals: 24,
175
+ icon: 'https://assets.ref.finance/images/w-NEAR-no-border.png'
176
+ };
177
+ return {
178
+ config: exports.config,
179
+ REF_FI_CONTRACT_ID: exports.REF_FI_CONTRACT_ID,
180
+ WRAP_NEAR_CONTRACT_ID: exports.WRAP_NEAR_CONTRACT_ID,
181
+ REF_TOKEN_ID: exports.REF_TOKEN_ID,
182
+ REF_META_DATA: exports.REF_META_DATA,
183
+ WNEAR_META_DATA: exports.WNEAR_META_DATA
184
+ };
185
+ };
155
186
 
156
187
  function _regeneratorRuntime() {
157
188
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -642,7 +673,7 @@ var calc_y = function calc_y(amp, x_c_amount, current_c_amounts, index_x, index_
642
673
  var c = d * d / x_c_amount;
643
674
 
644
675
  for (var i = 0; i < token_num; i++) {
645
- if (i != index_x && i != index_y) {
676
+ if (i !== index_x && i !== index_y) {
646
677
  s += current_c_amounts[i];
647
678
  c = c * d / current_c_amounts[i];
648
679
  }
@@ -708,7 +739,6 @@ var REF_WIDGET_SWAP_OUT_KEY = 'REF_WIDGET_SWAP_OUT_VALUE';
708
739
  var REF_WIDGET_SWAP_DETAIL_KEY = 'REF_WIDGET_SWAP_DETAIL_VALUE';
709
740
  var DEFAULT_START_TOKEN_LIST_TESTNET = ['wrap.testnet', 'usdtt.fakes.testnet', 'usdt.fakes.testnet', 'ref.fakes.testnet', 'usdn.testnet', 'eth.fakes.testnet'];
710
741
  var DEFAULT_START_TOKEN_LIST_MAINNET = ['wrap.near', 'usdt.tether-token.near', 'dac17f958d2ee523a2206206994597c13d831ec7.factory.bridge.near', 'token.v2.ref-finance.near', 'usn', 'aurora', 'token.sweat'];
711
- var DEFAULT_START_TOKEN_LIST = /*#__PURE__*/getConfig().networkId === 'testnet' ? DEFAULT_START_TOKEN_LIST_TESTNET : DEFAULT_START_TOKEN_LIST_MAINNET;
712
742
  var defaultTheme = {
713
743
  container: '#FFFFFF',
714
744
  buttonBg: '#00C6A2',
@@ -778,7 +808,7 @@ var getTokenPriceList = /*#__PURE__*/function () {
778
808
  switch (_context.prev = _context.next) {
779
809
  case 0:
780
810
  _context.next = 2;
781
- return fetch(config.indexerUrl + '/list-token-price', {
811
+ return fetch(exports.config.indexerUrl + '/list-token-price', {
782
812
  method: 'GET',
783
813
  headers: {
784
814
  'Content-type': 'application/json; charset=UTF-8'
@@ -824,7 +854,7 @@ var getTokens = /*#__PURE__*/function () {
824
854
 
825
855
  case 5:
826
856
  _context2.next = 7;
827
- return fetch(config.indexerUrl + '/list-token', {
857
+ return fetch(exports.config.indexerUrl + '/list-token', {
828
858
  method: 'GET',
829
859
  headers: {
830
860
  'Content-type': 'application/json; charset=UTF-8'
@@ -872,7 +902,7 @@ var getWhiteListTokensIndexer = /*#__PURE__*/function () {
872
902
  switch (_context3.prev = _context3.next) {
873
903
  case 0:
874
904
  _context3.next = 2;
875
- return fetch(config.indexerUrl + '/list-token', {
905
+ return fetch(exports.config.indexerUrl + '/list-token', {
876
906
  method: 'GET',
877
907
  headers: {
878
908
  'Content-type': 'application/json; charset=UTF-8'
@@ -3013,7 +3043,7 @@ var singlePoolSwap = function singlePoolSwap(_ref3) {
3013
3043
  var parsedAmountIn = toNonDivisibleNumber(tokenIn.decimals, amountIn); // const pools = simplePools.concat(stablePools);
3014
3044
 
3015
3045
  var simplePoolsThisPair = simplePools.filter(function (p) {
3016
- return p.tokenIds.includes(tokenIn.id) && p.tokenIds.includes(tokenOut.id);
3046
+ return p.tokenIds.includes(tokenIn.id) && p.tokenIds.includes(tokenOut.id) && (!stablePools || !isStablePool(stablePools, p.id));
3017
3047
  });
3018
3048
  var estimatesSimplePool = simplePoolsThisPair.map(function (pool) {
3019
3049
  return getSimplePoolEstimate({
@@ -4100,7 +4130,7 @@ function divide(numerator, denominator) {
4100
4130
  });
4101
4131
  }
4102
4132
  var getMax = function getMax(id, amount) {
4103
- return id !== WRAP_NEAR_CONTRACT_ID ? amount : Number(amount) <= 0.5 ? '0' : String(Number(amount) - 0.5);
4133
+ return id !== exports.WRAP_NEAR_CONTRACT_ID ? amount : Number(amount) <= 0.5 ? '0' : String(Number(amount) - 0.5);
4104
4134
  };
4105
4135
  function getPointByPrice(pointDelta, price, decimalRate, noNeedSlot) {
4106
4136
  var point = Math.log(+price * decimalRate) / Math.log(CONSTANT_D);
@@ -4426,7 +4456,14 @@ var REPLACE_TOKENS = [BANANA_ID, CHEDDAR_ID, CUCUMBER_ID, HAPI_ID, WOO_ID];
4426
4456
  var near = /*#__PURE__*/new nearApiJs.Near( /*#__PURE__*/_extends({
4427
4457
  keyStore: /*#__PURE__*/getKeyStore(),
4428
4458
  headers: {}
4429
- }, config));
4459
+ }, /*#__PURE__*/getConfig()));
4460
+ var init_env = function init_env(env) {
4461
+ near = new nearApiJs.Near(_extends({
4462
+ keyStore: getKeyStore(),
4463
+ headers: {}
4464
+ }, getConfig(env)));
4465
+ return switchEnv();
4466
+ };
4430
4467
  var refFiViewFunction = /*#__PURE__*/function () {
4431
4468
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
4432
4469
  var methodName, args, nearConnection;
@@ -4436,11 +4473,11 @@ var refFiViewFunction = /*#__PURE__*/function () {
4436
4473
  case 0:
4437
4474
  methodName = _ref.methodName, args = _ref.args;
4438
4475
  _context.next = 3;
4439
- return near.account(REF_FI_CONTRACT_ID);
4476
+ return near.account(exports.REF_FI_CONTRACT_ID);
4440
4477
 
4441
4478
  case 3:
4442
4479
  nearConnection = _context.sent;
4443
- return _context.abrupt("return", nearConnection.viewFunction(REF_FI_CONTRACT_ID, methodName, args));
4480
+ return _context.abrupt("return", nearConnection.viewFunction(exports.REF_FI_CONTRACT_ID, methodName, args));
4444
4481
 
4445
4482
  case 5:
4446
4483
  case "end":
@@ -4463,7 +4500,7 @@ var ftViewFunction = /*#__PURE__*/function () {
4463
4500
  case 0:
4464
4501
  methodName = _ref3.methodName, args = _ref3.args;
4465
4502
  _context2.next = 3;
4466
- return near.account(REF_FI_CONTRACT_ID);
4503
+ return near.account(exports.REF_FI_CONTRACT_ID);
4467
4504
 
4468
4505
  case 3:
4469
4506
  nearConnection = _context2.sent;
@@ -4566,12 +4603,12 @@ var ftGetTokenMetadata = /*#__PURE__*/function () {
4566
4603
  while (1) {
4567
4604
  switch (_context5.prev = _context5.next) {
4568
4605
  case 0:
4569
- if (!(id === REF_TOKEN_ID)) {
4606
+ if (!(id === exports.REF_TOKEN_ID)) {
4570
4607
  _context5.next = 2;
4571
4608
  break;
4572
4609
  }
4573
4610
 
4574
- return _context5.abrupt("return", REF_META_DATA);
4611
+ return _context5.abrupt("return", exports.REF_META_DATA);
4575
4612
 
4576
4613
  case 2:
4577
4614
  _context5.next = 4;
@@ -4584,7 +4621,7 @@ var ftGetTokenMetadata = /*#__PURE__*/function () {
4584
4621
  case 4:
4585
4622
  metadata = _context5.sent;
4586
4623
 
4587
- if (!(!metadata.icon || id === BANANA_ID || id === CHEDDAR_ID || id === CUCUMBER_ID || id === HAPI_ID || id === WOO_ID || id === WRAP_NEAR_CONTRACT_ID)) {
4624
+ if (!(!metadata.icon || id === BANANA_ID || id === CHEDDAR_ID || id === CUCUMBER_ID || id === HAPI_ID || id === WOO_ID || id === exports.WRAP_NEAR_CONTRACT_ID)) {
4588
4625
  _context5.next = 7;
4589
4626
  break;
4590
4627
  }
@@ -4736,7 +4773,7 @@ var getAccountNearBalance = /*#__PURE__*/function () {
4736
4773
  }();
4737
4774
  var nearDepositTransaction = function nearDepositTransaction(amount) {
4738
4775
  var transaction = {
4739
- receiverId: WRAP_NEAR_CONTRACT_ID,
4776
+ receiverId: exports.WRAP_NEAR_CONTRACT_ID,
4740
4777
  functionCalls: [{
4741
4778
  methodName: 'near_deposit',
4742
4779
  args: {},
@@ -4748,7 +4785,7 @@ var nearDepositTransaction = function nearDepositTransaction(amount) {
4748
4785
  };
4749
4786
  var nearWithdrawTransaction = function nearWithdrawTransaction(amount) {
4750
4787
  var transaction = {
4751
- receiverId: WRAP_NEAR_CONTRACT_ID,
4788
+ receiverId: exports.WRAP_NEAR_CONTRACT_ID,
4752
4789
  functionCalls: [{
4753
4790
  methodName: 'near_withdraw',
4754
4791
  args: {
@@ -4768,12 +4805,12 @@ var refDCLSwapViewFunction = /*#__PURE__*/function () {
4768
4805
  case 0:
4769
4806
  methodName = _ref12.methodName, args = _ref12.args;
4770
4807
  _context10.next = 3;
4771
- return near.account(REF_FI_CONTRACT_ID);
4808
+ return near.account(exports.REF_FI_CONTRACT_ID);
4772
4809
 
4773
4810
  case 3:
4774
4811
  nearConnection = _context10.sent;
4775
4812
 
4776
- if (config.REF_DCL_SWAP_CONTRACT_ID) {
4813
+ if (exports.config.REF_DCL_SWAP_CONTRACT_ID) {
4777
4814
  _context10.next = 6;
4778
4815
  break;
4779
4816
  }
@@ -4781,7 +4818,7 @@ var refDCLSwapViewFunction = /*#__PURE__*/function () {
4781
4818
  throw DCLInValid;
4782
4819
 
4783
4820
  case 6:
4784
- return _context10.abrupt("return", nearConnection.viewFunction(config.REF_DCL_SWAP_CONTRACT_ID, methodName, args));
4821
+ return _context10.abrupt("return", nearConnection.viewFunction(exports.config.REF_DCL_SWAP_CONTRACT_ID, methodName, args));
4785
4822
 
4786
4823
  case 7:
4787
4824
  case "end":
@@ -4865,7 +4902,7 @@ var NoAccountIdFound = /*#__PURE__*/formatError('No account id found');
4865
4902
  var NoFeeToPool = function NoFeeToPool(fee) {
4866
4903
  return formatError("InValid fee " + fee + " to DCL pool, the valid fee should be one of " + DCL_POOL_FEE_LIST);
4867
4904
  };
4868
- var DCLInValid = /*#__PURE__*/formatError("DCL contract currently in Valid on " + config.networkId);
4905
+ var DCLInValid = /*#__PURE__*/formatError("DCL contract currently in Valid on " + exports.config.networkId);
4869
4906
  var NoPoolOnThisPair = function NoPoolOnThisPair(tokenA, tokenB) {
4870
4907
  return formatError("No pools on pair " + tokenA + " <> " + tokenB);
4871
4908
  };
@@ -4938,13 +4975,13 @@ var instantSwap = /*#__PURE__*/function () {
4938
4975
  };
4939
4976
  }();
4940
4977
 
4941
- if (!(tokenIn.id === config.WRAP_NEAR_CONTRACT_ID)) {
4978
+ if (!(tokenIn.id === exports.config.WRAP_NEAR_CONTRACT_ID)) {
4942
4979
  _context2.next = 12;
4943
4980
  break;
4944
4981
  }
4945
4982
 
4946
4983
  _context2.next = 8;
4947
- return ftGetStorageBalance(config.WRAP_NEAR_CONTRACT_ID, AccountId);
4984
+ return ftGetStorageBalance(exports.config.WRAP_NEAR_CONTRACT_ID, AccountId);
4948
4985
 
4949
4986
  case 8:
4950
4987
  registered = _context2.sent;
@@ -5006,7 +5043,7 @@ var instantSwap = /*#__PURE__*/function () {
5006
5043
  functionCalls: [{
5007
5044
  methodName: 'ft_transfer_call',
5008
5045
  args: {
5009
- receiver_id: REF_FI_CONTRACT_ID,
5046
+ receiver_id: exports.REF_FI_CONTRACT_ID,
5010
5047
  amount: toNonDivisibleNumber(tokenIn.decimals, amountIn),
5011
5048
  msg: JSON.stringify({
5012
5049
  force: 0,
@@ -5201,24 +5238,28 @@ var getRefPools = /*#__PURE__*/function () {
5201
5238
  };
5202
5239
  }();
5203
5240
  var fetchAllPools = /*#__PURE__*/function () {
5204
- var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
5241
+ var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(perPage) {
5205
5242
  var totalPools, pages, pools;
5206
5243
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5207
5244
  while (1) {
5208
5245
  switch (_context6.prev = _context6.next) {
5209
5246
  case 0:
5210
- _context6.next = 2;
5247
+ if (perPage) {
5248
+ DEFAULT_PAGE_LIMIT = Math.min(perPage, 500);
5249
+ }
5250
+
5251
+ _context6.next = 3;
5211
5252
  return getTotalPools();
5212
5253
 
5213
- case 2:
5254
+ case 3:
5214
5255
  totalPools = _context6.sent;
5215
5256
  pages = Math.ceil(totalPools / DEFAULT_PAGE_LIMIT);
5216
- _context6.next = 6;
5257
+ _context6.next = 7;
5217
5258
  return Promise.all([].concat(Array(pages)).fill(0).map(function (_, i) {
5218
5259
  return getRefPools(i + 1);
5219
5260
  }));
5220
5261
 
5221
- case 6:
5262
+ case 7:
5222
5263
  pools = _context6.sent.flat();
5223
5264
  return _context6.abrupt("return", {
5224
5265
  simplePools: pools.filter(function (p) {
@@ -5232,7 +5273,7 @@ var fetchAllPools = /*#__PURE__*/function () {
5232
5273
  })
5233
5274
  });
5234
5275
 
5235
- case 8:
5276
+ case 9:
5236
5277
  case "end":
5237
5278
  return _context6.stop();
5238
5279
  }
@@ -5240,7 +5281,7 @@ var fetchAllPools = /*#__PURE__*/function () {
5240
5281
  }, _callee6);
5241
5282
  }));
5242
5283
 
5243
- return function fetchAllPools() {
5284
+ return function fetchAllPools(_x7) {
5244
5285
  return _ref8.apply(this, arguments);
5245
5286
  };
5246
5287
  }();
@@ -5360,7 +5401,7 @@ var useTokensIndexer = function useTokensIndexer(_ref4) {
5360
5401
  return !!token;
5361
5402
  });
5362
5403
  parsedTokens = globalWhiteListTokens.map(function (t) {
5363
- return t.id === WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5404
+ return t.id === exports.WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5364
5405
  id: t.id
5365
5406
  }) : t;
5366
5407
  });
@@ -5370,7 +5411,7 @@ var useTokensIndexer = function useTokensIndexer(_ref4) {
5370
5411
  setTokenLoading(false);
5371
5412
  } else {
5372
5413
  newList = defaultTokenList.map(function (t) {
5373
- return t.id === WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5414
+ return t.id === exports.WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5374
5415
  id: t.id
5375
5416
  }) : t;
5376
5417
  }).filter(function (t) {
@@ -5512,11 +5553,11 @@ var useSwap = function useSwap(params) {
5512
5553
  case 4:
5513
5554
  transactionsRef = _context3.sent;
5514
5555
 
5515
- if (tokenIn && tokenIn.id === WRAP_NEAR_CONTRACT_ID) {
5556
+ if (tokenIn && tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID) {
5516
5557
  transactionsRef.splice(-1, 0, nearDepositTransaction(amountIn));
5517
5558
  }
5518
5559
 
5519
- if (tokenOut && tokenOut.id === WRAP_NEAR_CONTRACT_ID) {
5560
+ if (tokenOut && tokenOut.id === exports.WRAP_NEAR_CONTRACT_ID) {
5520
5561
  outEstimate = new Big(0);
5521
5562
  routes = separateRoutes(estimates, tokenOut.id);
5522
5563
  bigEstimate = routes.reduce(function (acc, cur) {
@@ -5639,7 +5680,7 @@ var useTokenBalnces = function useTokenBalnces(tokens, AccountId) {
5639
5680
  return token.id;
5640
5681
  });
5641
5682
  Promise.all(ids.map(function (id) {
5642
- return ftGetBalance(id === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : id, AccountId);
5683
+ return ftGetBalance(id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : id, AccountId);
5643
5684
  })).then(function (balances) {
5644
5685
  var balancesMap = validTokens.reduce(function (acc, token, index) {
5645
5686
  var _extends2;
@@ -5674,8 +5715,8 @@ var SmartRouteV2 = function SmartRouteV2(_ref) {
5674
5715
  pools = _ref.pools;
5675
5716
  var theme = React.useContext(ThemeContext);
5676
5717
  var tokens = tokensRaw.map(function (t) {
5677
- return t.id === WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5678
- id: WRAP_NEAR_CONTRACT_ID
5718
+ return t.id === exports.WRAP_NEAR_CONTRACT_ID ? _extends({}, NEAR_META_DATA, {
5719
+ id: exports.WRAP_NEAR_CONTRACT_ID
5679
5720
  }) : t;
5680
5721
  });
5681
5722
 
@@ -6012,7 +6053,7 @@ var TokenAmount = function TokenAmount(props) {
6012
6053
  };
6013
6054
 
6014
6055
  React.useEffect(function () {
6015
- if (ref.current && onChangeAmount && token && balance && token.id === WRAP_NEAR_CONTRACT_ID && Number(balance) - Number(ref.current.value) < 0.5) {
6056
+ if (ref.current && onChangeAmount && token && balance && token.id === exports.WRAP_NEAR_CONTRACT_ID && Number(balance) - Number(ref.current.value) < 0.5) {
6016
6057
  ref.current.setCustomValidity('Must have 0.5N or more left in wallet for gas fee.');
6017
6058
  } else {
6018
6059
  var _ref$current;
@@ -6574,6 +6615,7 @@ var TokenSelector = function TokenSelector(_ref13) {
6574
6615
  };
6575
6616
 
6576
6617
  var storagedStartList = localStorage.getItem(REF_WIDGET_STAR_TOKEN_LIST_KEY) ? JSON.parse(localStorage.getItem(REF_WIDGET_STAR_TOKEN_LIST_KEY) || '[]') : null;
6618
+ var DEFAULT_START_TOKEN_LIST = getConfig().networkId === 'testnet' ? DEFAULT_START_TOKEN_LIST_TESTNET : DEFAULT_START_TOKEN_LIST_MAINNET;
6577
6619
 
6578
6620
  var _useState14 = React.useState(storagedStartList || DEFAULT_START_TOKEN_LIST),
6579
6621
  starList = _useState14[0],
@@ -6879,7 +6921,7 @@ var Notification = function Notification(_ref15) {
6879
6921
  }
6880
6922
  }, (state === null || state === undefined) && React__default.createElement("p", null, "Waiting for confirmation"), state === 'fail' && !!tx && React__default.createElement("a", {
6881
6923
  className: "text-primary font-semibold",
6882
- href: config.explorerUrl + "/txns/" + tx,
6924
+ href: exports.config.explorerUrl + "/txns/" + tx,
6883
6925
  target: "_blank",
6884
6926
  style: {
6885
6927
  textDecoration: 'underline',
@@ -7062,36 +7104,46 @@ var SwapWidget = function SwapWidget(props) {
7062
7104
  poolFetchingState = _useRefPools.poolFetchingState;
7063
7105
 
7064
7106
  React.useEffect(function () {
7065
- var defaultIn = STORAGED_TOKEN_IN || defaultTokenIn || WRAP_NEAR_CONTRACT_ID;
7066
- var defaultOut = STORAGED_TOKEN_OUT || defaultTokenOut || REF_TOKEN_ID;
7107
+ var defaultIn = STORAGED_TOKEN_IN || defaultTokenIn || exports.WRAP_NEAR_CONTRACT_ID;
7108
+ var defaultOut = STORAGED_TOKEN_OUT || defaultTokenOut || exports.REF_TOKEN_ID;
7067
7109
 
7068
7110
  if (tokens.length > 0 && defaultIn && tokens.findIndex(function (t) {
7069
7111
  return t.id === defaultIn;
7070
7112
  }) !== -1) {
7071
- if (defaultIn === WRAP_NEAR_CONTRACT_ID || defaultIn === 'NEAR') {
7113
+ if (defaultIn === exports.WRAP_NEAR_CONTRACT_ID || defaultIn === 'NEAR') {
7072
7114
  handleSetTokenIn(_extends({}, NEAR_META_DATA, {
7073
- id: WRAP_NEAR_CONTRACT_ID
7115
+ id: exports.WRAP_NEAR_CONTRACT_ID
7074
7116
  }));
7075
7117
  } else {
7076
7118
  ftGetTokenMetadata(defaultIn).then(handleSetTokenIn);
7077
7119
  }
7120
+ } else if (tokens.length > 0 && defaultIn && tokens.findIndex(function (t) {
7121
+ return t.id === defaultIn;
7122
+ }) === -1) {
7123
+ handleSetTokenIn(_extends({}, NEAR_META_DATA, {
7124
+ id: exports.WRAP_NEAR_CONTRACT_ID
7125
+ }));
7078
7126
  }
7079
7127
 
7080
7128
  if (tokens.length > 0 && defaultOut && tokens.findIndex(function (t) {
7081
7129
  return t.id === defaultOut;
7082
7130
  }) !== -1) {
7083
- if (defaultOut === WRAP_NEAR_CONTRACT_ID || defaultOut === 'NEAR') {
7131
+ if (defaultOut === exports.WRAP_NEAR_CONTRACT_ID || defaultOut === 'NEAR') {
7084
7132
  handleSetTokenOut(_extends({}, NEAR_META_DATA, {
7085
- id: WRAP_NEAR_CONTRACT_ID
7133
+ id: exports.WRAP_NEAR_CONTRACT_ID
7086
7134
  }));
7087
7135
  } else {
7088
7136
  ftGetTokenMetadata(defaultOut).then(handleSetTokenOut);
7089
7137
  }
7138
+ } else if (tokens.length > 0 && defaultOut && tokens.findIndex(function (t) {
7139
+ return t.id === defaultOut;
7140
+ }) === -1) {
7141
+ handleSetTokenOut(exports.REF_META_DATA);
7090
7142
  }
7091
7143
  }, [tokens, tokenLoading]);
7092
7144
  React.useEffect(function () {
7093
7145
  if (!tokenIn) return;
7094
- var wrapedId = tokenIn.id === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenIn.id;
7146
+ var wrapedId = tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenIn.id;
7095
7147
 
7096
7148
  if (balances[wrapedId]) {
7097
7149
  setTokenInBalance(balances[wrapedId]);
@@ -7104,7 +7156,7 @@ var SwapWidget = function SwapWidget(props) {
7104
7156
  }, [tokenIn, AccountId, balances]);
7105
7157
  React.useEffect(function () {
7106
7158
  if (!tokenOut) return;
7107
- var wrapedId = tokenOut.id === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenOut.id;
7159
+ var wrapedId = tokenOut.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenOut.id;
7108
7160
 
7109
7161
  if (balances[wrapedId]) {
7110
7162
  setTokenOutBalance(balances[wrapedId]);
@@ -7120,11 +7172,17 @@ var SwapWidget = function SwapWidget(props) {
7120
7172
  tokenIn: tokenIn,
7121
7173
  tokenOut: tokenOut,
7122
7174
  amountIn: amountIn,
7123
- simplePools: allPools.simplePools,
7175
+ simplePools: allPools.simplePools.filter(function (p) {
7176
+ return Number(p.shareSupply) > 0;
7177
+ }),
7124
7178
  options: {
7125
7179
  enableSmartRouting: enableSmartRouting,
7126
- stablePools: allPools.ratedPools.concat(allPools.unRatedPools),
7127
- stablePoolsDetail: allStablePools
7180
+ stablePools: allPools.ratedPools.concat(allPools.unRatedPools).filter(function (p) {
7181
+ return Number(p.shareSupply) > 0;
7182
+ }),
7183
+ stablePoolsDetail: allStablePools.filter(function (p) {
7184
+ return Number(p.shares_total_supply) > 0;
7185
+ })
7128
7186
  },
7129
7187
  slippageTolerance: slippageTolerance,
7130
7188
  onSwap: onSwap,
@@ -8186,10 +8244,8 @@ var DefaultMainnetTokenList = [{
8186
8244
  decimals: 6,
8187
8245
  id: 'usdt.tether-token.near'
8188
8246
  }];
8189
- function getDefaultTokenList(env) {
8190
- if (env === void 0) {
8191
- env = process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
8192
- }
8247
+ function getDefaultTokenList() {
8248
+ var env = getConfig().networkId;
8193
8249
 
8194
8250
  switch (env) {
8195
8251
  case 'mainnet':
@@ -8251,7 +8307,7 @@ var DCLSwap = /*#__PURE__*/function () {
8251
8307
  functionCalls: [{
8252
8308
  methodName: 'ft_transfer_call',
8253
8309
  args: {
8254
- receiver_id: config.REF_DCL_SWAP_CONTRACT_ID,
8310
+ receiver_id: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8255
8311
  amount: toNonDivisibleNumber(tokenA.decimals, amountA),
8256
8312
  msg: msg
8257
8313
  },
@@ -8298,7 +8354,7 @@ var DCLSwap = /*#__PURE__*/function () {
8298
8354
  functionCalls: [{
8299
8355
  methodName: 'ft_transfer_call',
8300
8356
  args: {
8301
- receiver_id: config.REF_DCL_SWAP_CONTRACT_ID,
8357
+ receiver_id: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8302
8358
  amount: toNonDivisibleNumber(tokenA.decimals, amountA),
8303
8359
  msg: _msg
8304
8360
  },
@@ -8350,7 +8406,7 @@ var DCLSwap = /*#__PURE__*/function () {
8350
8406
 
8351
8407
  if (DCLRegistered === null) {
8352
8408
  transactions.push({
8353
- receiverId: config.REF_DCL_SWAP_CONTRACT_ID,
8409
+ receiverId: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8354
8410
  functionCalls: [{
8355
8411
  methodName: 'storage_deposit',
8356
8412
  args: {
@@ -8376,7 +8432,7 @@ var DCLSwap = /*#__PURE__*/function () {
8376
8432
  functionCalls: [{
8377
8433
  methodName: 'ft_transfer_call',
8378
8434
  args: {
8379
- receiver_id: config.REF_DCL_SWAP_CONTRACT_ID,
8435
+ receiver_id: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8380
8436
  amount: toNonDivisibleNumber(tokenA.decimals, amountA),
8381
8437
  msg: _msg2
8382
8438
  },
@@ -8386,20 +8442,20 @@ var DCLSwap = /*#__PURE__*/function () {
8386
8442
  });
8387
8443
 
8388
8444
  case 43:
8389
- if (!(tokenA.id === WRAP_NEAR_CONTRACT_ID)) {
8445
+ if (!(tokenA.id === exports.WRAP_NEAR_CONTRACT_ID)) {
8390
8446
  _context.next = 48;
8391
8447
  break;
8392
8448
  }
8393
8449
 
8394
8450
  _context.next = 46;
8395
- return ftGetStorageBalance(WRAP_NEAR_CONTRACT_ID, AccountId);
8451
+ return ftGetStorageBalance(exports.WRAP_NEAR_CONTRACT_ID, AccountId);
8396
8452
 
8397
8453
  case 46:
8398
8454
  registered = _context.sent;
8399
8455
 
8400
8456
  if (registered === null) {
8401
8457
  transactions.unshift({
8402
- receiverId: WRAP_NEAR_CONTRACT_ID,
8458
+ receiverId: exports.WRAP_NEAR_CONTRACT_ID,
8403
8459
  functionCalls: [registerAccountOnToken(AccountId)]
8404
8460
  });
8405
8461
  }
@@ -8690,7 +8746,7 @@ var cancel_order = /*#__PURE__*/function () {
8690
8746
 
8691
8747
  case 5:
8692
8748
  transactions = [{
8693
- receiverId: config.REF_DCL_SWAP_CONTRACT_ID,
8749
+ receiverId: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8694
8750
  functionCalls: [{
8695
8751
  methodName: 'cancel_order',
8696
8752
  args: {
@@ -8716,7 +8772,7 @@ var cancel_order = /*#__PURE__*/function () {
8716
8772
  }();
8717
8773
  var claim_order = function claim_order(order_id) {
8718
8774
  var transactions = [{
8719
- receiverId: config.REF_DCL_SWAP_CONTRACT_ID,
8775
+ receiverId: exports.config.REF_DCL_SWAP_CONTRACT_ID,
8720
8776
  functionCalls: [{
8721
8777
  methodName: 'cancel_order',
8722
8778
  args: {
@@ -8750,7 +8806,6 @@ exports.DCLSwapByInputOnBestPool = DCLSwapByInputOnBestPool;
8750
8806
  exports.DCLSwapGetStorageBalance = DCLSwapGetStorageBalance;
8751
8807
  exports.DCL_POOL_FEE_LIST = DCL_POOL_FEE_LIST;
8752
8808
  exports.DCL_POOL_SPLITER = DCL_POOL_SPLITER;
8753
- exports.DEFAULT_PAGE_LIMIT = DEFAULT_PAGE_LIMIT;
8754
8809
  exports.DefaultMainnetTokenList = DefaultMainnetTokenList;
8755
8810
  exports.DefaultTestnetTokenList = DefaultTestnetTokenList;
8756
8811
  exports.FEE_DIVISOR = FEE_DIVISOR;
@@ -8771,9 +8826,6 @@ exports.OrderNoRemainedAmount = OrderNoRemainedAmount;
8771
8826
  exports.POINTLEFTRANGE = POINTLEFTRANGE;
8772
8827
  exports.POINTRIGHTRANGE = POINTRIGHTRANGE;
8773
8828
  exports.RATED_POOL_LP_TOKEN_DECIMALS = RATED_POOL_LP_TOKEN_DECIMALS;
8774
- exports.REF_FI_CONTRACT_ID = REF_FI_CONTRACT_ID;
8775
- exports.REF_META_DATA = REF_META_DATA;
8776
- exports.REF_TOKEN_ID = REF_TOKEN_ID;
8777
8829
  exports.REPLACE_TOKENS = REPLACE_TOKENS;
8778
8830
  exports.STABLE_LP_TOKEN_DECIMALS = STABLE_LP_TOKEN_DECIMALS;
8779
8831
  exports.STORAGE_TO_REGISTER_WITH_MFT = STORAGE_TO_REGISTER_WITH_MFT;
@@ -8783,8 +8835,6 @@ exports.SwapRouteError = SwapRouteError;
8783
8835
  exports.SwapWidget = SwapWidget;
8784
8836
  exports.TokenLinks = TokenLinks;
8785
8837
  exports.TokenNotExistError = TokenNotExistError;
8786
- exports.WNEAR_META_DATA = WNEAR_META_DATA;
8787
- exports.WRAP_NEAR_CONTRACT_ID = WRAP_NEAR_CONTRACT_ID;
8788
8838
  exports.WalletSelectorTransactions = WalletSelectorTransactions;
8789
8839
  exports.ZeroInputError = ZeroInputError;
8790
8840
  exports.calcStableSwapPriceImpact = calcStableSwapPriceImpact;
@@ -8801,7 +8851,6 @@ exports.calculateSmartRoutesV2PriceImpact = calculateSmartRoutesV2PriceImpact;
8801
8851
  exports.calculateSmartRoutingPriceImpact = calculateSmartRoutingPriceImpact;
8802
8852
  exports.cancel_order = cancel_order;
8803
8853
  exports.claim_order = claim_order;
8804
- exports.config = config;
8805
8854
  exports.convertToPercentDecimal = convertToPercentDecimal;
8806
8855
  exports.divide = divide;
8807
8856
  exports.estimateSwap = estimateSwap;
@@ -8850,6 +8899,7 @@ exports.getUnRatedPoolDetail = getUnRatedPoolDetail;
8850
8899
  exports.getUserRegisteredTokens = getUserRegisteredTokens;
8851
8900
  exports.get_order = get_order;
8852
8901
  exports.get_pointorder_range = get_pointorder_range;
8902
+ exports.init_env = init_env;
8853
8903
  exports.instantSwap = instantSwap;
8854
8904
  exports.isMobile = isMobile;
8855
8905
  exports.isStablePool = isStablePool;
@@ -8859,7 +8909,6 @@ exports.list_active_orders = list_active_orders;
8859
8909
  exports.list_history_orders = list_history_orders;
8860
8910
  exports.list_user_assets = list_user_assets;
8861
8911
  exports.multiply = multiply;
8862
- exports.near = near;
8863
8912
  exports.nearDepositTransaction = nearDepositTransaction;
8864
8913
  exports.nearWithdrawTransaction = nearWithdrawTransaction;
8865
8914
  exports.parsePool = parsePool;
@@ -8882,6 +8931,7 @@ exports.sendTransactionsByMemoryKey = sendTransactionsByMemoryKey;
8882
8931
  exports.separateRoutes = separateRoutes;
8883
8932
  exports.singlePoolSwap = singlePoolSwap;
8884
8933
  exports.subtraction = subtraction;
8934
+ exports.switchEnv = switchEnv;
8885
8935
  exports.symbolsArr = symbolsArr;
8886
8936
  exports.toInternationalCurrencySystemLongString = toInternationalCurrencySystemLongString;
8887
8937
  exports.toNonDivisibleNumber = toNonDivisibleNumber;