@ref-finance/ref-sdk 1.4.8 → 1.5.0

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
@@ -6,11 +6,6 @@ Our SDK is provided by a third party, and we do not take any responsibility for
6
6
  This SDK is designed to assist developers when interacting with the main functions of the protocol. Main functions that can be defined as:
7
7
 
8
8
  - Trade: Swap tokens with our Automated Market Maker (AMM).
9
- - Pool: Add/Remove liquidity and earn revenue from swap fee (Coming soon)
10
- - Farm: Stale LP tokens into farms and earn liquidity incentives (Coming soon)
11
- - Boost Farm: Stake LOVE tokens to get boosted liquidity incentives (Coming soon)
12
- - Stake: Stake REF tokens to earn fees generated by the protocol (Coming soon)
13
- - Vote: Lock REF<>NEAR LP tokens to get veTokens and participate in the governance of the protocol and the allocation of liquidity incentives (Coming soon)
14
9
 
15
10
  ## Install
16
11
 
@@ -20,7 +15,7 @@ npm: `npm install @ref-finance/ref-sdk`
20
15
 
21
16
  ## Initialization
22
17
 
23
- Ref SDK identifies env variable NEAR_ENV or REACT_APP_REF_SDK_ENV to get global configuration.
18
+ Rhea SDK identifies env variable NEAR_ENV or REACT_APP_REF_SDK_ENV to get global configuration.
24
19
 
25
20
  ```plain
26
21
  export function getConfig(
@@ -90,7 +85,7 @@ init_env('mainnet', '', 'https://beta.rpc.mainnet.near.org');
90
85
 
91
86
 
92
87
 
93
- ## Ref V1 Swap
88
+ ## Rhea V1 Swap
94
89
 
95
90
  ### Tokens
96
91
 
@@ -750,11 +745,11 @@ Response
750
745
 
751
746
 
752
747
 
753
- ## Ref Swap Widget
748
+ ## Rhea Swap Widget
754
749
 
755
750
  ### Description
756
751
 
757
- The Ref Swap Widget is a useful tool, allowing any third party service to access Ref's liquidity. Users of ecosystem dapps have the ability to swap via the Widget, without the need to go to Ref app, thus improving the user experience.
752
+ The Rhea Swap Widget is a useful tool, allowing any third party service to access Rhea's liquidity. Users of ecosystem dapps have the ability to swap via the Widget, without the need to go to Rhea app, thus improving the user experience.
758
753
 
759
754
  Here are some use cases:
760
755
 
@@ -762,18 +757,18 @@ Here are some use cases:
762
757
  - Swapping tokens to lend, farm or stake
763
758
  - Swapping one token for a specific token, which can be used to buy a NFT in the associated marketplace
764
759
 
765
- Using the Ref Swap Widget, with a few customizations, developers can integrate the Swap funtion directly into their dapps. Both mobile and/or website version are available.
760
+ Using the Rhea Swap Widget, with a few customizations, developers can integrate the Swap funtion directly into their dapps. Both mobile and/or website version are available.
766
761
  ![图片](https://user-images.githubusercontent.com/50706666/199178215-f2b184dc-f683-4740-af9f-fd67efd41503.png)
767
762
 
768
763
  For the default theme, developers can chose between the light mode and dark mode.
769
764
 
770
765
  More themes can be selected: [Click here to check them on figma](https://www.figma.com/file/v069nTXfE8pXDJQcDcC5wl/Swap-Widget?node-id=0%3A1).
771
766
 
772
- To integrate the Ref Swap Widget, please follow this guide.
767
+ To integrate the Rhea Swap Widget, please follow this guide.
773
768
 
774
769
  ### Getting started
775
770
 
776
- A QuickStart of Ref Swap component.
771
+ A QuickStart of Rhea Swap component.
777
772
 
778
773
  #### Props
779
774
 
@@ -807,7 +802,7 @@ export interface SwapWidgetProps {
807
802
  ```
808
803
 
809
804
  - theme: widget theme for customization.
810
- - defaultTokenList: default tokens with ref whitelist into token list in the widget.
805
+ - defaultTokenList: default tokens with Rhea whitelist into token list in the widget.
811
806
  - onSwap: Swap button triggers this function.
812
807
  - width: width of widget component.
813
808
  - height: height of widget component.
@@ -817,7 +812,7 @@ export interface SwapWidgetProps {
817
812
  - connection: connection to wallets, input { AccountId:"", isSignedIn:false } if wallet not connected.
818
813
  - defaultTokenIn: default token-in.
819
814
  - defaultTokenOut: default token-out.
820
- - referralId: You can get referral fee from every swap routed by your app. But make sure that your referral_id is in Ref's referral list. For the details, please check https://gov.ref.finance/t/contract-upgrade-1-7-0-referral-fee/823 .
815
+ - referralId: You can get referral fee from every swap routed by your app. But make sure that your referral_id is in Ref's referral list. For the details, please check https://gov.ref.finance/t/contract-upgrade-1-7-0-referral-fee/823 .
821
816
  - transactionState: entry to input transaction states after you send transactions.
822
817
  - state: denote if last transaction is failed or successfull.
823
818
  - setState: used to change setState to interact with pop-up.
@@ -967,7 +962,7 @@ export const Widget = ()=>{
967
962
  }
968
963
  ```
969
964
 
970
- ### Integrating Ref Swap function using the SDK
965
+ ### Integrating Rhea Swap function using the SDK
971
966
 
972
967
  The SDK provides more flexibility/options.
973
968
 
@@ -983,11 +978,11 @@ SDK integration tips:
983
978
  - For a better user experience, before the execution of the swap, you can show more details about the swap (ex: fee, rate, route, etc.), allowing users to take better data-driven decisions.
984
979
  - You can redirect the user to the NEAR Explorer, once the transaction is confirmed.
985
980
 
986
- ## Ref V2(DCL) Swap
981
+ ## Rhea V2(DCL) Swap
987
982
 
988
- #### An overview of Ref V2
983
+ #### An overview of Rhea V2
989
984
 
990
- The launch of concentrated liquidity AMM is an achievement for Ref Finance. In collaboration with Izumi Finance and Arctic, Ref is glad to introduce discretized concentrated liquidity and limit order two new key features to the NEAR ecosystem. Using REF SDK, developers can dig more opportunities and implement various trading strategies.Before introducing SDK details, let's have an overview of V2 exciting features.
985
+ The launch of concentrated liquidity AMM is an achievement for Rhea Finance. In collaboration with Izumi Finance and Arctic, Rhea is glad to introduce discretized concentrated liquidity and limit order two new key features to the NEAR ecosystem. Using Rhea SDK, developers can dig more opportunities and implement various trading strategies.Before introducing SDK details, let's have an overview of V2 exciting features.
991
986
 
992
987
  #### Discretized concentrated liquidity
993
988
 
@@ -1291,6 +1286,7 @@ interface DCLSwapProps {
1291
1286
  skip_unwrap_near: boolean;
1292
1287
  };
1293
1288
  AccountId: string;
1289
+ referralId?: string;
1294
1290
  }
1295
1291
  ```
1296
1292
 
@@ -1321,6 +1317,7 @@ const res = await DCLSwap({
1321
1317
  pool_ids,
1322
1318
  },
1323
1319
  AccountId,
1320
+ referralId: 'ref-fee.testnet', // optional: referral ID to earn referral fees
1324
1321
  });
1325
1322
  ```
1326
1323
 
@@ -1375,6 +1372,7 @@ const res = await DCLSwap({
1375
1372
  output_amount: "4.89454792",
1376
1373
  },
1377
1374
  AccountId,
1375
+ referralId: 'ref-fee.testnet', // optional: referral ID to earn referral fees
1378
1376
  });
1379
1377
  ```
1380
1378
 
@@ -1426,9 +1424,10 @@ const res = await DCLSwap({
1426
1424
  },
1427
1425
  LimitOrderWithSwap: {
1428
1426
  pool_id,
1429
- output_amount: "3217.929",
1427
+ output_amount: "3217.929",
1430
1428
  },
1431
1429
  AccountId,
1430
+ referralId: 'ref-fee.testnet', // optional: referral ID to earn referral fees
1432
1431
  });
1433
1432
  ```
1434
1433
 
@@ -1484,6 +1483,7 @@ const res = await DCLSwap({
1484
1483
  stop_point: 405920,
1485
1484
  },
1486
1485
  AccountId,
1486
+ referralId: 'ref-fee.testnet', // optional: referral ID to earn referral fees
1487
1487
  });
1488
1488
  ```
1489
1489
 
@@ -1526,6 +1526,7 @@ Parameters
1526
1526
  amountA: string;
1527
1527
  slippageTolerance: number;
1528
1528
  AccountId: string;
1529
+ referralId?: string;
1529
1530
  }
1530
1531
  ```
1531
1532
 
@@ -1547,6 +1548,7 @@ const res = await DCLSwapByInputOnBestPool({
1547
1548
  amountA: "1",
1548
1549
  slippageTolerance: 0.1,
1549
1550
  AccountId,
1551
+ referralId: 'ref-fee.testnet', // optional: referral ID to earn referral fees
1550
1552
  });
1551
1553
  ```
1552
1554
 
@@ -24,9 +24,10 @@ interface DCLSwapProps {
24
24
  skip_unwrap_near: boolean;
25
25
  };
26
26
  AccountId: string;
27
+ referralId?: string;
27
28
  }
28
29
  export declare const DCL_POOL_SPLITER = "|";
29
- export declare const DCLSwap: ({ Swap, SwapByOutput, LimitOrderWithSwap, SwapByStopPoint, AccountId, swapInfo, }: DCLSwapProps) => Promise<Transaction[]>;
30
+ export declare const DCLSwap: ({ Swap, SwapByOutput, LimitOrderWithSwap, SwapByStopPoint, AccountId, swapInfo, referralId, }: DCLSwapProps) => Promise<Transaction[]>;
30
31
  export declare const quote: ({ pool_ids, input_amount, input_token, output_token, tag, }: {
31
32
  pool_ids: string[];
32
33
  input_token: TokenMetadata;
@@ -35,12 +36,13 @@ export declare const quote: ({ pool_ids, input_amount, input_token, output_token
35
36
  tag?: string | undefined;
36
37
  }) => Promise<any>;
37
38
  export declare const list_user_assets: (AccountId: string) => Promise<any>;
38
- export declare const DCLSwapByInputOnBestPool: ({ tokenA, tokenB, amountA, slippageTolerance, AccountId, }: {
39
+ export declare const DCLSwapByInputOnBestPool: ({ tokenA, tokenB, amountA, slippageTolerance, AccountId, referralId, }: {
39
40
  tokenA: TokenMetadata;
40
41
  tokenB: TokenMetadata;
41
42
  amountA: string;
42
43
  slippageTolerance: number;
43
44
  AccountId: string;
45
+ referralId?: string | undefined;
44
46
  }) => Promise<Transaction[]>;
45
47
  export declare const quote_by_output: ({ pool_ids, output_amount, input_token, output_token, }: {
46
48
  pool_ids: string[];
@@ -4201,22 +4201,18 @@ var getUserRegisteredTokens = /*#__PURE__*/function () {
4201
4201
  }();
4202
4202
  var getAccountNearBalance = /*#__PURE__*/function () {
4203
4203
  var _ref11 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(accountId) {
4204
- var provider;
4205
4204
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
4206
4205
  while (1) {
4207
4206
  switch (_context9.prev = _context9.next) {
4208
4207
  case 0:
4209
- provider = new nearApiJs.providers.JsonRpcProvider({
4210
- url: getConfig().nodeUrl
4211
- });
4212
- return _context9.abrupt("return", provider.query({
4208
+ return _context9.abrupt("return", near.connection.provider.query({
4213
4209
  request_type: 'view_account',
4214
4210
  finality: 'final',
4215
4211
  account_id: accountId
4216
4212
  }).then(function (data) {
4217
4213
  return data.amount;
4218
4214
  }));
4219
- case 2:
4215
+ case 1:
4220
4216
  case "end":
4221
4217
  return _context9.stop();
4222
4218
  }
@@ -4292,44 +4288,41 @@ var DCLSwapGetStorageBalance = function DCLSwapGetStorageBalance(tokenId, Accoun
4292
4288
  };
4293
4289
  var getMinStorageBalance = /*#__PURE__*/function () {
4294
4290
  var _ref14 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(nep141Address) {
4295
- var provider, result, balance;
4291
+ var result, balance;
4296
4292
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
4297
4293
  while (1) {
4298
4294
  switch (_context11.prev = _context11.next) {
4299
4295
  case 0:
4300
4296
  _context11.prev = 0;
4301
- provider = new nearApiJs.providers.JsonRpcProvider({
4302
- url: getConfig().nodeUrl
4303
- });
4304
- _context11.next = 4;
4305
- return provider.query({
4297
+ _context11.next = 3;
4298
+ return near.connection.provider.query({
4306
4299
  request_type: 'call_function',
4307
4300
  account_id: nep141Address,
4308
4301
  method_name: 'storage_balance_bounds',
4309
4302
  args_base64: '',
4310
4303
  finality: 'optimistic'
4311
4304
  });
4312
- case 4:
4305
+ case 3:
4313
4306
  result = _context11.sent;
4314
4307
  balance = JSON.parse(Buffer.from(result.result).toString());
4315
4308
  if (!(!balance || !balance.min)) {
4316
- _context11.next = 8;
4309
+ _context11.next = 7;
4317
4310
  break;
4318
4311
  }
4319
4312
  return _context11.abrupt("return", FT_MINIMUM_STORAGE_BALANCE_LARGE);
4320
- case 8:
4313
+ case 7:
4321
4314
  return _context11.abrupt("return", balance.min);
4322
- case 11:
4323
- _context11.prev = 11;
4315
+ case 10:
4316
+ _context11.prev = 10;
4324
4317
  _context11.t0 = _context11["catch"](0);
4325
4318
  console.error(_context11.t0, nep141Address);
4326
4319
  return _context11.abrupt("return", FT_MINIMUM_STORAGE_BALANCE_LARGE);
4327
- case 15:
4320
+ case 14:
4328
4321
  case "end":
4329
4322
  return _context11.stop();
4330
4323
  }
4331
4324
  }
4332
- }, _callee11, null, [[0, 11]]);
4325
+ }, _callee11, null, [[0, 10]]);
4333
4326
  }));
4334
4327
  return function getMinStorageBalance(_x13) {
4335
4328
  return _ref14.apply(this, arguments);
@@ -7802,12 +7795,12 @@ function getDefaultTokenList() {
7802
7795
  var DCL_POOL_SPLITER = '|';
7803
7796
  var DCLSwap = /*#__PURE__*/function () {
7804
7797
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
7805
- var Swap, SwapByOutput, LimitOrderWithSwap, SwapByStopPoint, AccountId, swapInfo, transactions, tokenA, tokenB, amountA, pool_ids, tokenRegistered, output_token, min_output_amount, msg, _pool_ids, _output_token, output_amount, _msg, _tokenRegistered, pool_id, fee, buy_token, point, _tokenRegistered2, DCLRegistered, new_point, _msg2, _tokenRegistered3, _msg3, registered;
7798
+ var Swap, SwapByOutput, LimitOrderWithSwap, SwapByStopPoint, AccountId, swapInfo, referralId, transactions, tokenA, tokenB, amountA, pool_ids, tokenRegistered, output_token, min_output_amount, msg, _pool_ids, _output_token, output_amount, _msg, _tokenRegistered, pool_id, fee, buy_token, point, _tokenRegistered2, DCLRegistered, new_point, _msg2, _tokenRegistered3, _msg3, registered;
7806
7799
  return _regeneratorRuntime().wrap(function _callee$(_context) {
7807
7800
  while (1) {
7808
7801
  switch (_context.prev = _context.next) {
7809
7802
  case 0:
7810
- Swap = _ref.Swap, SwapByOutput = _ref.SwapByOutput, LimitOrderWithSwap = _ref.LimitOrderWithSwap, SwapByStopPoint = _ref.SwapByStopPoint, AccountId = _ref.AccountId, swapInfo = _ref.swapInfo;
7803
+ Swap = _ref.Swap, SwapByOutput = _ref.SwapByOutput, LimitOrderWithSwap = _ref.LimitOrderWithSwap, SwapByStopPoint = _ref.SwapByStopPoint, AccountId = _ref.AccountId, swapInfo = _ref.swapInfo, referralId = _ref.referralId;
7811
7804
  transactions = [];
7812
7805
  tokenA = swapInfo.tokenA, tokenB = swapInfo.tokenB, amountA = swapInfo.amountA;
7813
7806
  if (!Swap) {
@@ -7834,6 +7827,7 @@ var DCLSwap = /*#__PURE__*/function () {
7834
7827
  pool_ids: pool_ids,
7835
7828
  output_token: output_token,
7836
7829
  min_output_amount: min_output_amount,
7830
+ referral_id: referralId || '',
7837
7831
  client_id: ''
7838
7832
  }
7839
7833
  });
@@ -7865,6 +7859,7 @@ var DCLSwap = /*#__PURE__*/function () {
7865
7859
  pool_ids: _pool_ids,
7866
7860
  output_token: _output_token,
7867
7861
  output_amount: output_amount,
7862
+ referral_id: referralId || '',
7868
7863
  client_id: ''
7869
7864
  }
7870
7865
  });
@@ -7948,7 +7943,8 @@ var DCLSwap = /*#__PURE__*/function () {
7948
7943
  pool_id: pool_id,
7949
7944
  buy_token: buy_token,
7950
7945
  point: new_point,
7951
- client_id: ''
7946
+ client_id: '',
7947
+ referral_id: referralId || ''
7952
7948
  }
7953
7949
  });
7954
7950
  transactions.push({
@@ -7984,7 +7980,9 @@ var DCLSwap = /*#__PURE__*/function () {
7984
7980
  });
7985
7981
  }
7986
7982
  _msg3 = JSON.stringify({
7987
- SwapByStopPoint: SwapByStopPoint
7983
+ SwapByStopPoint: _extends({}, SwapByStopPoint, {
7984
+ referral_id: referralId || ''
7985
+ })
7988
7986
  });
7989
7987
  transactions.push({
7990
7988
  receiverId: tokenA.id,
@@ -8088,12 +8086,12 @@ var list_user_assets = /*#__PURE__*/function () {
8088
8086
  var DCLSwapByInputOnBestPool = /*#__PURE__*/function () {
8089
8087
  var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
8090
8088
  var _bestEstimate$tag, _bestEstimate$tag$spl, _bestEstimate$tag2, _bestEstimate$tag2$sp;
8091
- var tokenA, tokenB, amountA, slippageTolerance, AccountId, estimates, bestEstimate, bestFee;
8089
+ var tokenA, tokenB, amountA, slippageTolerance, AccountId, referralId, estimates, bestEstimate, bestFee;
8092
8090
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
8093
8091
  while (1) {
8094
8092
  switch (_context5.prev = _context5.next) {
8095
8093
  case 0:
8096
- tokenA = _ref6.tokenA, tokenB = _ref6.tokenB, amountA = _ref6.amountA, slippageTolerance = _ref6.slippageTolerance, AccountId = _ref6.AccountId;
8094
+ tokenA = _ref6.tokenA, tokenB = _ref6.tokenB, amountA = _ref6.amountA, slippageTolerance = _ref6.slippageTolerance, AccountId = _ref6.AccountId, referralId = _ref6.referralId;
8097
8095
  if (!(slippageTolerance <= 0 || slippageTolerance >= 100)) {
8098
8096
  _context5.next = 3;
8099
8097
  break;
@@ -8155,7 +8153,8 @@ var DCLSwapByInputOnBestPool = /*#__PURE__*/function () {
8155
8153
  pool_ids: [getDCLPoolId(tokenA.id, tokenB.id, bestFee)],
8156
8154
  min_output_amount: percentLess(slippageTolerance, bestEstimate.amount)
8157
8155
  },
8158
- AccountId: AccountId
8156
+ AccountId: AccountId,
8157
+ referralId: referralId
8159
8158
  }));
8160
8159
  case 11:
8161
8160
  case "end":