@ref-finance/ref-sdk 1.3.1 → 1.3.3

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)
@@ -1273,6 +1273,11 @@ interface DCLSwapProps {
1273
1273
  pool_id: string;
1274
1274
  output_amount: string;
1275
1275
  };
1276
+ SwapByStopPoint?: {
1277
+ pool_id: string;
1278
+ stop_point: number;
1279
+ skip_unwrap_near: boolean;
1280
+ };
1276
1281
  AccountId: string;
1277
1282
  }
1278
1283
  ```
@@ -1439,6 +1444,61 @@ Response (LimitOrderWithSwap)
1439
1444
 
1440
1445
  ```
1441
1446
 
1447
+ Example (SwapByStopPoint)
1448
+
1449
+ ```plain
1450
+ const tokenA = "usdt.fakes.testnet";
1451
+
1452
+ const tokenB = "wrap.testnet";
1453
+
1454
+ const fee = 2000
1455
+
1456
+ const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
1457
+
1458
+
1459
+ const tokenAMetadata = await ftGetTokenMetadata(tokenA)
1460
+
1461
+ const tokenBMetadata = await ftGetTokenMetadata(tokenB)
1462
+
1463
+
1464
+ const res = await DCLSwap({
1465
+ swapInfo: {
1466
+ amountA: input_amount,
1467
+ tokenA: tokenAMetadata,
1468
+ tokenB: tokenBMetadata,
1469
+ },
1470
+ SwapByStopPoint: {
1471
+ pool_id: pool_id,
1472
+ stop_point: 405920,
1473
+ },
1474
+ AccountId,
1475
+ });
1476
+ ```
1477
+
1478
+ Response (SwapByStopPoint)
1479
+
1480
+ ```
1481
+
1482
+ [
1483
+ {
1484
+ receiverId: "usdt.fakes.testnet",
1485
+ functionCalls: [
1486
+ {
1487
+ methodName: "ft_transfer_call",
1488
+ args: {
1489
+ receiver_id: "dcl.ref-dev.testnet",
1490
+ amount: "1000000",
1491
+ msg: '{"SwapByStopPoint":{"pool_id":"usdt.fakes.testnet|wrap.testnet|2000","stop_point":495240}}',
1492
+ },
1493
+ gas: "180000000000000",
1494
+ amount: "0.000000000000000000000001",
1495
+ },
1496
+ ],
1497
+ },
1498
+ ];
1499
+
1500
+ ```
1501
+
1442
1502
  ---
1443
1503
 
1444
1504
  #### DCLSwapByInputOnBestPool
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[]>;
@@ -644,6 +644,7 @@ var getSwappedAmount = function getSwappedAmount(tokenInId, tokenOutId, amountIn
644
644
 
645
645
  var REF_WIDGET_STAR_TOKEN_LIST_KEY = 'REF_WIDGET_STAR_TOKEN_LIST_VALUE';
646
646
  var REF_WIDGET_ALL_TOKENS_LIST_KEY = 'REF_WIDGET_ALL_TOKENS_LIST_VALUE';
647
+ var REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY = 'REF_WIDGET_ALL_LIGHT_TOKENS_LIST_VALUE';
647
648
  var REF_WIDGET_SWAP_IN_KEY = 'REF_WIDGET_SWAP_IN_VALUE';
648
649
  var REF_WIDGET_SWAP_OUT_KEY = 'REF_WIDGET_SWAP_OUT_VALUE';
649
650
  var REF_WIDGET_SWAP_DETAIL_KEY = 'REF_WIDGET_SWAP_DETAIL_VALUE';
@@ -794,13 +795,65 @@ var getTokens = /*#__PURE__*/function () {
794
795
  return _ref2.apply(this, arguments);
795
796
  };
796
797
  }();
797
- var getWhiteListTokensIndexer = /*#__PURE__*/function () {
798
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(whiteListIds) {
798
+ var getTokensTiny = /*#__PURE__*/function () {
799
+ var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(reload) {
800
+ var storagedTokens;
799
801
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
800
802
  while (1) {
801
803
  switch (_context3.prev = _context3.next) {
802
804
  case 0:
803
- _context3.next = 2;
805
+ storagedTokens = typeof window !== 'undefined' && !reload ? localStorage.getItem(REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY) : null;
806
+ if (!storagedTokens) {
807
+ _context3.next = 5;
808
+ break;
809
+ }
810
+ _context3.t0 = JSON.parse(storagedTokens);
811
+ _context3.next = 8;
812
+ break;
813
+ case 5:
814
+ _context3.next = 7;
815
+ return fetch(exports.config.indexerUrl + '/list-token-v2', {
816
+ method: 'GET',
817
+ headers: {
818
+ 'Content-type': 'application/json; charset=UTF-8'
819
+ }
820
+ }).then(function (res) {
821
+ return res.json();
822
+ }).then(function (tokens) {
823
+ var newTokens = Object.values(tokens).reduce(function (acc, cur, i) {
824
+ var _extends3;
825
+ var id = Object.keys(tokens)[i];
826
+ return _extends({}, acc, (_extends3 = {}, _extends3[id] = _extends({}, cur, {
827
+ id: id
828
+ }), _extends3));
829
+ }, {});
830
+ return newTokens;
831
+ }).then(function (res) {
832
+ typeof window !== 'undefined' && !reload && localStorage.setItem(REF_WIDGET_ALL_LIGHT_TOKENS_LIST_KEY, JSON.stringify(res));
833
+ return res;
834
+ });
835
+ case 7:
836
+ _context3.t0 = _context3.sent;
837
+ case 8:
838
+ return _context3.abrupt("return", _context3.t0);
839
+ case 9:
840
+ case "end":
841
+ return _context3.stop();
842
+ }
843
+ }
844
+ }, _callee3);
845
+ }));
846
+ return function getTokensTiny(_x2) {
847
+ return _ref3.apply(this, arguments);
848
+ };
849
+ }();
850
+ var getWhiteListTokensIndexer = /*#__PURE__*/function () {
851
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(whiteListIds) {
852
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
853
+ while (1) {
854
+ switch (_context4.prev = _context4.next) {
855
+ case 0:
856
+ _context4.next = 2;
804
857
  return fetch(exports.config.indexerUrl + '/list-token', {
805
858
  method: 'GET',
806
859
  headers: {
@@ -810,26 +863,26 @@ var getWhiteListTokensIndexer = /*#__PURE__*/function () {
810
863
  return res.json();
811
864
  }).then(function (res) {
812
865
  return whiteListIds.reduce(function (acc, cur, i) {
813
- var _extends3;
866
+ var _extends4;
814
867
  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], {
868
+ return _extends({}, acc, (_extends4 = {}, _extends4[cur] = _extends({}, res[cur], {
816
869
  id: cur
817
- }), _extends3));
870
+ }), _extends4));
818
871
  }, {});
819
872
  }).then(function (res) {
820
873
  return Object.values(res);
821
874
  });
822
875
  case 2:
823
- return _context3.abrupt("return", _context3.sent);
876
+ return _context4.abrupt("return", _context4.sent);
824
877
  case 3:
825
878
  case "end":
826
- return _context3.stop();
879
+ return _context4.stop();
827
880
  }
828
881
  }
829
- }, _callee3);
882
+ }, _callee4);
830
883
  }));
831
- return function getWhiteListTokensIndexer(_x2) {
832
- return _ref3.apply(this, arguments);
884
+ return function getWhiteListTokensIndexer(_x3) {
885
+ return _ref4.apply(this, arguments);
833
886
  };
834
887
  }();
835
888
 
@@ -3100,7 +3153,7 @@ var estimateSwap = /*#__PURE__*/function () {
3100
3153
  return poolFormatter(p);
3101
3154
  });
3102
3155
  _context2.next = 22;
3103
- return getTokens();
3156
+ return getTokensTiny();
3104
3157
  case 22:
3105
3158
  allTokens = _context2.sent;
3106
3159
  _context2.next = 25;
@@ -3884,11 +3937,7 @@ var refFiViewFunction = /*#__PURE__*/function () {
3884
3937
  return near.account(exports.REF_FI_CONTRACT_ID);
3885
3938
  case 3:
3886
3939
  nearConnection = _context.sent;
3887
- return _context.abrupt("return", nearConnection.viewFunction({
3888
- contractId: exports.REF_FI_CONTRACT_ID,
3889
- methodName: methodName,
3890
- args: args
3891
- }));
3940
+ return _context.abrupt("return", nearConnection.viewFunction(exports.REF_FI_CONTRACT_ID, methodName, args));
3892
3941
  case 5:
3893
3942
  case "end":
3894
3943
  return _context.stop();
@@ -3912,11 +3961,7 @@ var ftViewFunction = /*#__PURE__*/function () {
3912
3961
  return near.account(exports.REF_FI_CONTRACT_ID);
3913
3962
  case 3:
3914
3963
  nearConnection = _context2.sent;
3915
- return _context2.abrupt("return", nearConnection.viewFunction({
3916
- contractId: tokenId,
3917
- methodName: methodName,
3918
- args: args
3919
- }));
3964
+ return _context2.abrupt("return", nearConnection.viewFunction(tokenId, methodName, args));
3920
3965
  case 5:
3921
3966
  case "end":
3922
3967
  return _context2.stop();
@@ -4208,11 +4253,7 @@ var refDCLSwapViewFunction = /*#__PURE__*/function () {
4208
4253
  }
4209
4254
  throw DCLInValid;
4210
4255
  case 6:
4211
- return _context10.abrupt("return", nearConnection.viewFunction({
4212
- contractId: exports.config.REF_DCL_SWAP_CONTRACT_ID,
4213
- methodName: methodName,
4214
- args: args
4215
- }));
4256
+ return _context10.abrupt("return", nearConnection.viewFunction(exports.config.REF_DCL_SWAP_CONTRACT_ID, methodName, args));
4216
4257
  case 7:
4217
4258
  case "end":
4218
4259
  return _context10.stop();