@ref-finance/ref-sdk 1.1.7 → 1.1.9

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.
@@ -1,7 +1,6 @@
1
1
  import { utils, keyStores, providers, KeyPair, InMemorySigner, transactions, Near } from 'near-api-js';
2
2
  import BN from 'bn.js';
3
3
  import fs from 'fs';
4
- import os from 'os';
5
4
  import _, { sortBy } from 'lodash-es';
6
5
  import * as math from 'mathjs';
7
6
  import { divide as divide$1, evaluate, format, floor, bignumber, sum, round as round$1 } from 'mathjs';
@@ -45,7 +44,7 @@ function getConfig(env) {
45
44
  REF_TOKEN_ID: 'token.v2.ref-finance.near',
46
45
  indexerUrl: 'https://indexer.ref.finance',
47
46
  explorerUrl: 'https://testnet.nearblocks.io',
48
- REF_DCL_SWAP_CONTRACT_ID: ''
47
+ REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-labs.near'
49
48
  };
50
49
  case 'testnet':
51
50
  return {
@@ -57,7 +56,7 @@ function getConfig(env) {
57
56
  REF_FI_CONTRACT_ID: 'ref-finance-101.testnet',
58
57
  REF_TOKEN_ID: 'ref.fakes.testnet',
59
58
  explorerUrl: 'https://testnet.nearblocks.io',
60
- REF_DCL_SWAP_CONTRACT_ID: 'dcl.ref-dev.testnet'
59
+ REF_DCL_SWAP_CONTRACT_ID: 'dclv2-dev.ref-dev.testnet'
61
60
  };
62
61
  default:
63
62
  return {
@@ -69,7 +68,7 @@ function getConfig(env) {
69
68
  REF_TOKEN_ID: 'token.v2.ref-finance.near',
70
69
  indexerUrl: 'https://indexer.ref.finance',
71
70
  explorerUrl: 'https://nearblocks.io',
72
- REF_DCL_SWAP_CONTRACT_ID: ''
71
+ REF_DCL_SWAP_CONTRACT_ID: 'dcl.ref-labs.near'
73
72
  };
74
73
  }
75
74
  }
@@ -3655,42 +3654,42 @@ var provider = /*#__PURE__*/new providers.JsonRpcProvider({
3655
3654
  });
3656
3655
  var getMemorySigner = /*#__PURE__*/function () {
3657
3656
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3658
- var AccountId, keyPath, homedir, credentials, credentialAccountId, myKeyStore, signer;
3657
+ var AccountId, keyPath, credentials, credentialAccountId, myKeyStore, signer;
3659
3658
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3660
3659
  while (1) {
3661
3660
  switch (_context.prev = _context.next) {
3662
3661
  case 0:
3663
3662
  AccountId = _ref.AccountId, keyPath = _ref.keyPath;
3664
3663
  _context.prev = 1;
3665
- homedir = os.homedir();
3666
- credentials = JSON.parse(fs.readFileSync(homedir + keyPath).toString());
3664
+ // const homedir = os.homedir();
3665
+ credentials = JSON.parse(fs.readFileSync(keyPath).toString());
3667
3666
  credentialAccountId = credentials == null ? void 0 : credentials.account_id;
3668
3667
  if (credentialAccountId) {
3669
- _context.next = 7;
3668
+ _context.next = 6;
3670
3669
  break;
3671
3670
  }
3672
3671
  throw NoCredential;
3673
- case 7:
3672
+ case 6:
3674
3673
  if (!(credentialAccountId !== AccountId)) {
3675
- _context.next = 9;
3674
+ _context.next = 8;
3676
3675
  break;
3677
3676
  }
3678
3677
  throw AccountIdMisMatch;
3679
- case 9:
3678
+ case 8:
3680
3679
  myKeyStore = new keyStores.InMemoryKeyStore();
3681
3680
  myKeyStore.setKey(getConfig().networkId, AccountId, KeyPair.fromString(credentials.private_key));
3682
3681
  signer = new InMemorySigner(myKeyStore);
3683
3682
  return _context.abrupt("return", signer);
3684
- case 15:
3685
- _context.prev = 15;
3683
+ case 14:
3684
+ _context.prev = 14;
3686
3685
  _context.t0 = _context["catch"](1);
3687
3686
  throw _context.t0;
3688
- case 18:
3687
+ case 17:
3689
3688
  case "end":
3690
3689
  return _context.stop();
3691
3690
  }
3692
3691
  }
3693
- }, _callee, null, [[1, 15]]);
3692
+ }, _callee, null, [[1, 14]]);
3694
3693
  }));
3695
3694
  return function getMemorySigner(_x) {
3696
3695
  return _ref2.apply(this, arguments);
@@ -4289,12 +4288,12 @@ var OrderNoRemainedAmount = /*#__PURE__*/formatError('No remained amount on this
4289
4288
  var instantSwap = /*#__PURE__*/function () {
4290
4289
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
4291
4290
  var _swapTodos;
4292
- var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, transactions, registerToken, registered, actionsList, allSwapsTokens, i, swapTokens;
4291
+ var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, referralId, transactions, registerToken, registered, actionsList, allSwapsTokens, i, swapTokens;
4293
4292
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4294
4293
  while (1) {
4295
4294
  switch (_context2.prev = _context2.next) {
4296
4295
  case 0:
4297
- tokenIn = _ref.tokenIn, tokenOut = _ref.tokenOut, amountIn = _ref.amountIn, slippageTolerance = _ref.slippageTolerance, swapTodos = _ref.swapTodos, AccountId = _ref.AccountId;
4296
+ tokenIn = _ref.tokenIn, tokenOut = _ref.tokenOut, amountIn = _ref.amountIn, slippageTolerance = _ref.slippageTolerance, swapTodos = _ref.swapTodos, AccountId = _ref.AccountId, referralId = _ref.referralId;
4298
4297
  transactions = [];
4299
4298
  if (!((swapTodos == null ? void 0 : (_swapTodos = swapTodos[(swapTodos == null ? void 0 : swapTodos.length) - 1]) == null ? void 0 : _swapTodos.outputToken) !== tokenOut.id)) {
4300
4299
  _context2.next = 4;
@@ -4401,7 +4400,11 @@ var instantSwap = /*#__PURE__*/function () {
4401
4400
  args: {
4402
4401
  receiver_id: REF_FI_CONTRACT_ID,
4403
4402
  amount: toNonDivisibleNumber(tokenIn.decimals, amountIn),
4404
- msg: JSON.stringify({
4403
+ msg: !!referralId ? JSON.stringify({
4404
+ force: 0,
4405
+ actions: actionsList,
4406
+ referral_id: referralId
4407
+ }) : JSON.stringify({
4405
4408
  force: 0,
4406
4409
  actions: actionsList
4407
4410
  })
@@ -4651,7 +4654,7 @@ var fetchAllPools = /*#__PURE__*/function () {
4651
4654
  };
4652
4655
  }();
4653
4656
 
4654
- var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState"];
4657
+ var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState", "referralId"];
4655
4658
  var ThemeContext = /*#__PURE__*/createContext(defaultTheme);
4656
4659
  var ThemeContextProvider = function ThemeContextProvider(_ref) {
4657
4660
  var customTheme = _ref.customTheme,
@@ -4829,6 +4832,7 @@ var useSwap = function useSwap(params) {
4829
4832
  onSwap = params.onSwap,
4830
4833
  AccountId = params.AccountId,
4831
4834
  poolFetchingState = params.poolFetchingState,
4835
+ referralId = params.referralId,
4832
4836
  swapParams = _objectWithoutPropertiesLoose(params, _excluded);
4833
4837
  var tokenIn = params.tokenIn,
4834
4838
  tokenOut = params.tokenOut,
@@ -4874,7 +4878,8 @@ var useSwap = function useSwap(params) {
4874
4878
  amountIn: params.amountIn,
4875
4879
  swapTodos: estimates,
4876
4880
  slippageTolerance: slippageTolerance,
4877
- AccountId: AccountId || ''
4881
+ AccountId: AccountId || '',
4882
+ referralId: referralId
4878
4883
  });
4879
4884
  case 4:
4880
4885
  transactionsRef = _context3.sent;
@@ -6285,7 +6290,8 @@ var SwapWidget = function SwapWidget(props) {
6285
6290
  defaultTokenIn = props.defaultTokenIn,
6286
6291
  defaultTokenOut = props.defaultTokenOut,
6287
6292
  onDisConnect = props.onDisConnect,
6288
- darkMode = props.darkMode;
6293
+ darkMode = props.darkMode,
6294
+ referralId = props.referralId;
6289
6295
  var curTheme = theme || (darkMode ? defaultDarkModeTheme : defaultTheme);
6290
6296
  var STORAGED_TOKEN_IN = localStorage.getItem(REF_WIDGET_SWAP_IN_KEY);
6291
6297
  var STORAGED_TOKEN_OUT = localStorage.getItem(REF_WIDGET_SWAP_OUT_KEY);
@@ -6438,7 +6444,8 @@ var SwapWidget = function SwapWidget(props) {
6438
6444
  onSwap: onSwap,
6439
6445
  AccountId: AccountId,
6440
6446
  refreshTrigger: refreshTrigger,
6441
- poolFetchingState: poolFetchingState
6447
+ poolFetchingState: poolFetchingState,
6448
+ referralId: referralId
6442
6449
  }),
6443
6450
  amountOut = _useSwap.amountOut,
6444
6451
  minAmountOut = _useSwap.minAmountOut,