@ref-finance/ref-sdk 1.3.2 → 1.3.4

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  This SDK is designed to assist developers when interacting with the main functions of the protocol. Main functions that can be defined as:
4
4
 
5
- - Trade: Swap tokens with our Automated Market Maker (AMM)
5
+ - Trade: Swap tokens with our Automated Market Maker (AMM).
6
6
  - Pool: Add/Remove liquidity and earn revenue from swap fee (Coming soon)
7
7
  - Farm: Stale LP tokens into farms and earn liquidity incentives (Coming soon)
8
8
  - Boost Farm: Stake LOVE tokens to get boosted liquidity incentives (Coming soon)
@@ -4,7 +4,7 @@ export declare const STABLE_LP_TOKEN_DECIMALS = 18;
4
4
  export declare const RATED_POOL_LP_TOKEN_DECIMALS = 24;
5
5
  export declare const STORAGE_TO_REGISTER_WITH_MFT = "0.1";
6
6
  export declare const ONE_YOCTO_NEAR = "0.000000000000000000000001";
7
- export declare function getConfig(env?: string | undefined): {
7
+ export declare function getConfig(env?: string | undefined, indexerUrl?: string | undefined): {
8
8
  networkId: string;
9
9
  nodeUrl: string;
10
10
  walletUrl: string;
package/dist/indexer.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare const getTokenPriceList: () => Promise<any>;
2
2
  export declare const getTokens: (reload?: boolean | undefined) => Promise<any>;
3
+ export declare const getTokensTiny: (reload?: boolean | undefined) => Promise<any>;
3
4
  export declare const getWhiteListTokensIndexer: (whiteListIds: string[]) => Promise<unknown[]>;
@@ -35,11 +35,16 @@ var RATED_POOL_LP_TOKEN_DECIMALS = 24;
35
35
  var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
36
36
  var ONE_YOCTO_NEAR = '0.000000000000000000000001';
37
37
  var ENV = '';
38
- function getConfig(env) {
38
+ var INDEXER_URL = '';
39
+ function getConfig(env, indexerUrl) {
39
40
  if (env === void 0) {
40
41
  env = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV;
41
42
  }
43
+ if (indexerUrl === void 0) {
44
+ indexerUrl = INDEXER_URL;
45
+ }
42
46
  ENV = env;
47
+ INDEXER_URL = indexerUrl;
43
48
  switch (env) {
44
49
  case 'mainnet':
45
50
  return {
@@ -49,7 +54,7 @@ function getConfig(env) {
49
54
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
50
55
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
51
56
  REF_TOKEN_ID: 'token.v2.ref-finance.near',
52
- indexerUrl: 'https://indexer.ref.finance',
57
+ indexerUrl: indexerUrl || 'https://mainnet-indexer.ref-finance.com',
53
58
  explorerUrl: 'https://testnet.nearblocks.io',
54
59
  REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-labs.near'
55
60
  };
@@ -58,7 +63,7 @@ function getConfig(env) {
58
63
  networkId: 'testnet',
59
64
  nodeUrl: 'https://rpc.testnet.near.org',
60
65
  walletUrl: 'https://wallet.testnet.near.org',
61
- indexerUrl: 'https://testnet-indexer.ref-finance.com',
66
+ indexerUrl: indexerUrl || 'https://testnet-indexer.ref-finance.com',
62
67
  WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
63
68
  REF_FI_CONTRACT_ID: 'ref-finance-101.testnet',
64
69
  REF_TOKEN_ID: 'ref.fakes.testnet',
@@ -73,7 +78,7 @@ function getConfig(env) {
73
78
  REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
74
79
  WRAP_NEAR_CONTRACT_ID: 'wrap.near',
75
80
  REF_TOKEN_ID: 'token.v2.ref-finance.near',
76
- indexerUrl: 'https://indexer.ref.finance',
81
+ indexerUrl: indexerUrl || 'https://mainnet-indexer.ref-finance.com',
77
82
  explorerUrl: 'https://nearblocks.io',
78
83
  REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-labs.near'
79
84
  };
@@ -644,6 +649,7 @@ var getSwappedAmount = function getSwappedAmount(tokenInId, tokenOutId, amountIn
644
649
 
645
650
  var REF_WIDGET_STAR_TOKEN_LIST_KEY = 'REF_WIDGET_STAR_TOKEN_LIST_VALUE';
646
651
  var REF_WIDGET_ALL_TOKENS_LIST_KEY = 'REF_WIDGET_ALL_TOKENS_LIST_VALUE';
652
+ var REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY = 'REF_WIDGET_ALL_LIGHT_TOKENS_LIST_VALUE';
647
653
  var REF_WIDGET_SWAP_IN_KEY = 'REF_WIDGET_SWAP_IN_VALUE';
648
654
  var REF_WIDGET_SWAP_OUT_KEY = 'REF_WIDGET_SWAP_OUT_VALUE';
649
655
  var REF_WIDGET_SWAP_DETAIL_KEY = 'REF_WIDGET_SWAP_DETAIL_VALUE';
@@ -794,13 +800,65 @@ var getTokens = /*#__PURE__*/function () {
794
800
  return _ref2.apply(this, arguments);
795
801
  };
796
802
  }();
797
- var getWhiteListTokensIndexer = /*#__PURE__*/function () {
798
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(whiteListIds) {
803
+ var getTokensTiny = /*#__PURE__*/function () {
804
+ var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(reload) {
805
+ var storagedTokens;
799
806
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
800
807
  while (1) {
801
808
  switch (_context3.prev = _context3.next) {
802
809
  case 0:
803
- _context3.next = 2;
810
+ storagedTokens = typeof window !== 'undefined' && !reload ? localStorage.getItem(REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY) : null;
811
+ if (!storagedTokens) {
812
+ _context3.next = 5;
813
+ break;
814
+ }
815
+ _context3.t0 = JSON.parse(storagedTokens);
816
+ _context3.next = 8;
817
+ break;
818
+ case 5:
819
+ _context3.next = 7;
820
+ return fetch(exports.config.indexerUrl + '/list-token-v2', {
821
+ method: 'GET',
822
+ headers: {
823
+ 'Content-type': 'application/json; charset=UTF-8'
824
+ }
825
+ }).then(function (res) {
826
+ return res.json();
827
+ }).then(function (tokens) {
828
+ var newTokens = Object.values(tokens).reduce(function (acc, cur, i) {
829
+ var _extends3;
830
+ var id = Object.keys(tokens)[i];
831
+ return _extends({}, acc, (_extends3 = {}, _extends3[id] = _extends({}, cur, {
832
+ id: id
833
+ }), _extends3));
834
+ }, {});
835
+ return newTokens;
836
+ }).then(function (res) {
837
+ typeof window !== 'undefined' && !reload && localStorage.setItem(REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY, JSON.stringify(res));
838
+ return res;
839
+ });
840
+ case 7:
841
+ _context3.t0 = _context3.sent;
842
+ case 8:
843
+ return _context3.abrupt("return", _context3.t0);
844
+ case 9:
845
+ case "end":
846
+ return _context3.stop();
847
+ }
848
+ }
849
+ }, _callee3);
850
+ }));
851
+ return function getTokensTiny(_x2) {
852
+ return _ref3.apply(this, arguments);
853
+ };
854
+ }();
855
+ var getWhiteListTokensIndexer = /*#__PURE__*/function () {
856
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(whiteListIds) {
857
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
858
+ while (1) {
859
+ switch (_context4.prev = _context4.next) {
860
+ case 0:
861
+ _context4.next = 2;
804
862
  return fetch(exports.config.indexerUrl + '/list-token', {
805
863
  method: 'GET',
806
864
  headers: {
@@ -810,26 +868,26 @@ var getWhiteListTokensIndexer = /*#__PURE__*/function () {
810
868
  return res.json();
811
869
  }).then(function (res) {
812
870
  return whiteListIds.reduce(function (acc, cur, i) {
813
- var _extends3;
871
+ var _extends4;
814
872
  if (!res[cur] || !Object.values(res[cur]) || Object.values(res[cur]).length === 0) return acc;
815
- return _extends({}, acc, (_extends3 = {}, _extends3[cur] = _extends({}, res[cur], {
873
+ return _extends({}, acc, (_extends4 = {}, _extends4[cur] = _extends({}, res[cur], {
816
874
  id: cur
817
- }), _extends3));
875
+ }), _extends4));
818
876
  }, {});
819
877
  }).then(function (res) {
820
878
  return Object.values(res);
821
879
  });
822
880
  case 2:
823
- return _context3.abrupt("return", _context3.sent);
881
+ return _context4.abrupt("return", _context4.sent);
824
882
  case 3:
825
883
  case "end":
826
- return _context3.stop();
884
+ return _context4.stop();
827
885
  }
828
886
  }
829
- }, _callee3);
887
+ }, _callee4);
830
888
  }));
831
- return function getWhiteListTokensIndexer(_x2) {
832
- return _ref3.apply(this, arguments);
889
+ return function getWhiteListTokensIndexer(_x3) {
890
+ return _ref4.apply(this, arguments);
833
891
  };
834
892
  }();
835
893
 
@@ -3100,7 +3158,7 @@ var estimateSwap = /*#__PURE__*/function () {
3100
3158
  return poolFormatter(p);
3101
3159
  });
3102
3160
  _context2.next = 22;
3103
- return getTokens();
3161
+ return getTokensTiny();
3104
3162
  case 22:
3105
3163
  allTokens = _context2.sent;
3106
3164
  _context2.next = 25;
@@ -3865,11 +3923,11 @@ var near = /*#__PURE__*/new nearApiJs.Near( /*#__PURE__*/_extends({
3865
3923
  keyStore: /*#__PURE__*/getKeyStore(),
3866
3924
  headers: {}
3867
3925
  }, /*#__PURE__*/getConfig()));
3868
- var init_env = function init_env(env) {
3926
+ var init_env = function init_env(env, indexerUrl) {
3869
3927
  near = new nearApiJs.Near(_extends({
3870
3928
  keyStore: getKeyStore(),
3871
3929
  headers: {}
3872
- }, getConfig(env)));
3930
+ }, getConfig(env, indexerUrl)));
3873
3931
  return switchEnv();
3874
3932
  };
3875
3933
  var refFiViewFunction = /*#__PURE__*/function () {