@ref-finance/ref-sdk 1.1.7 → 1.1.8
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 +52 -15
- package/dist/ref-sdk.cjs.development.js +29 -22
- package/dist/ref-sdk.cjs.development.js.map +1 -1
- package/dist/ref-sdk.cjs.production.min.js +1 -1
- package/dist/ref-sdk.cjs.production.min.js.map +1 -1
- package/dist/ref-sdk.esm.js +29 -22
- package/dist/ref-sdk.esm.js.map +1 -1
- package/dist/ref-sdk.umd.development.js +33 -26
- package/dist/ref-sdk.umd.development.js.map +1 -1
- package/dist/ref-sdk.umd.production.min.js +1 -1
- package/dist/ref-sdk.umd.production.min.js.map +1 -1
- package/dist/swap-widget/state.d.ts +1 -0
- package/dist/swap-widget/types.d.ts +1 -0
- package/dist/v1-swap/instantSwap.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -596,6 +596,7 @@ Parameters
|
|
|
596
596
|
slippageTolerance: number;
|
|
597
597
|
swapTodos: EstimateSwapView[];
|
|
598
598
|
AccountId: string;
|
|
599
|
+
referralId?: string;
|
|
599
600
|
}
|
|
600
601
|
```
|
|
601
602
|
|
|
@@ -608,7 +609,8 @@ const transactionsRef: Transaction[] = await instantSwap({
|
|
|
608
609
|
amountIn: '1',
|
|
609
610
|
swapTodos,
|
|
610
611
|
slippageTolerance = 0.01,
|
|
611
|
-
AccountId: 'your-account-id.testnet'
|
|
612
|
+
AccountId: 'your-account-id.testnet',
|
|
613
|
+
referralId: 'ref-fee.testnet'
|
|
612
614
|
});
|
|
613
615
|
```
|
|
614
616
|
|
|
@@ -623,7 +625,7 @@ Response
|
|
|
623
625
|
args: {
|
|
624
626
|
amount: '1000000000000000000',
|
|
625
627
|
msg:
|
|
626
|
-
'{"force":0,"actions":[{"pool_id":38,"token_in":"ref.fakes.testnet","token_out":"wrap.testnet","amount_in":"1000000000000000000","min_amount_out":"730191122546589600000000"}]}',
|
|
628
|
+
'{"force":0,"referral_id":"ref-fee.testnet" ,"actions":[{"pool_id":38,"token_in":"ref.fakes.testnet","token_out":"wrap.testnet","amount_in":"1000000000000000000","min_amount_out":"730191122546589600000000"}]}',
|
|
627
629
|
receiver_id: 'ref-finance-101.testnet',
|
|
628
630
|
},
|
|
629
631
|
gas: '180000000000000',
|
|
@@ -656,7 +658,7 @@ Parameters
|
|
|
656
658
|
Example
|
|
657
659
|
|
|
658
660
|
```plain
|
|
659
|
-
const signedTransactions:nearTransactions.SignedTransaction[] = getSignedTransactionsByMemoryKey({
|
|
661
|
+
const signedTransactions:nearTransactions.SignedTransaction[] = await getSignedTransactionsByMemoryKey({
|
|
660
662
|
transactionsRef;
|
|
661
663
|
AccountId: "your-account-id.testnet",
|
|
662
664
|
keyPath: "/.near-credentials/testnet/your-account-id.testnet.json"
|
|
@@ -781,6 +783,7 @@ export interface SwapWidgetProps {
|
|
|
781
783
|
};
|
|
782
784
|
defaultTokenIn?: string;
|
|
783
785
|
defaultTokenOut?: string;
|
|
786
|
+
referralId?:string;
|
|
784
787
|
transactionState?: {
|
|
785
788
|
state: 'success' | 'fail' | null;
|
|
786
789
|
tx?: string;
|
|
@@ -801,6 +804,7 @@ export interface SwapWidgetProps {
|
|
|
801
804
|
- connection: connection to wallets, input { AccountId:"", isSignedIn:false } if wallet not connected.
|
|
802
805
|
- defaultTokenIn: default token-in.
|
|
803
806
|
- defaultTokenOut: default token-out.
|
|
807
|
+
- 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 .
|
|
804
808
|
- transactionState: entry to input transaction states after you send transactions.
|
|
805
809
|
- state: denote if last transaction is failed or successfull.
|
|
806
810
|
- setState: used to change setState to interact with pop-up.
|
|
@@ -1166,11 +1170,16 @@ const fee = 10000
|
|
|
1166
1170
|
|
|
1167
1171
|
const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
|
|
1168
1172
|
|
|
1173
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1174
|
+
|
|
1175
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1176
|
+
|
|
1177
|
+
|
|
1169
1178
|
const res = await quote({
|
|
1170
1179
|
pool_ids,
|
|
1171
1180
|
input_amount,
|
|
1172
|
-
input_token:
|
|
1173
|
-
output_token:
|
|
1181
|
+
input_token: tokenAMetadata,
|
|
1182
|
+
output_token: tokenBMetadata,
|
|
1174
1183
|
});
|
|
1175
1184
|
```
|
|
1176
1185
|
|
|
@@ -1209,11 +1218,17 @@ const fee = 10000
|
|
|
1209
1218
|
|
|
1210
1219
|
const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
|
|
1211
1220
|
|
|
1221
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1222
|
+
|
|
1223
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1212
1227
|
const res = await quote_by_output({
|
|
1213
1228
|
pool_ids,
|
|
1214
1229
|
output_amount: "0.1",
|
|
1215
|
-
input_token:
|
|
1216
|
-
output_token:
|
|
1230
|
+
input_token: tokenAMetadata,
|
|
1231
|
+
output_token: tokenBMetadata,
|
|
1217
1232
|
});
|
|
1218
1233
|
```
|
|
1219
1234
|
|
|
@@ -1271,11 +1286,16 @@ const fee = 2000
|
|
|
1271
1286
|
|
|
1272
1287
|
const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
|
|
1273
1288
|
|
|
1289
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1290
|
+
|
|
1291
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1292
|
+
|
|
1293
|
+
|
|
1274
1294
|
const res = await DCLSwap({
|
|
1275
1295
|
swapInfo: {
|
|
1276
1296
|
amountA: input_amount,
|
|
1277
|
-
tokenA:
|
|
1278
|
-
tokenB:
|
|
1297
|
+
tokenA: tokenAMetadata,
|
|
1298
|
+
tokenB: tokenBMetadata,
|
|
1279
1299
|
},
|
|
1280
1300
|
Swap: {
|
|
1281
1301
|
min_output_amount: "0",
|
|
@@ -1317,13 +1337,19 @@ const tokenB = "wrap.testnet";
|
|
|
1317
1337
|
|
|
1318
1338
|
const fee = 2000
|
|
1319
1339
|
|
|
1340
|
+
|
|
1341
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1342
|
+
|
|
1343
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1344
|
+
|
|
1345
|
+
|
|
1320
1346
|
const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
|
|
1321
1347
|
|
|
1322
1348
|
const res = await DCLSwap({
|
|
1323
1349
|
swapInfo: {
|
|
1324
1350
|
amountA: input_amount,
|
|
1325
|
-
tokenA:
|
|
1326
|
-
tokenB:
|
|
1351
|
+
tokenA: tokenAMetadata,
|
|
1352
|
+
tokenB: tokenBMetadata,
|
|
1327
1353
|
},
|
|
1328
1354
|
SwapByOutput: {
|
|
1329
1355
|
pool_ids,
|
|
@@ -1367,11 +1393,17 @@ const fee = 2000
|
|
|
1367
1393
|
|
|
1368
1394
|
const pool_ids = [getDCLPoolId(tokenA, tokenB, fee)];
|
|
1369
1395
|
|
|
1396
|
+
|
|
1397
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1398
|
+
|
|
1399
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1400
|
+
|
|
1401
|
+
|
|
1370
1402
|
const res = await DCLSwap({
|
|
1371
1403
|
swapInfo: {
|
|
1372
1404
|
amountA: input_amount,
|
|
1373
|
-
tokenA:
|
|
1374
|
-
tokenB:
|
|
1405
|
+
tokenA: tokenAMetadata,
|
|
1406
|
+
tokenB: tokenBMetadata,
|
|
1375
1407
|
},
|
|
1376
1408
|
LimitOrderWithSwap: {
|
|
1377
1409
|
pool_id,
|
|
@@ -1430,9 +1462,14 @@ const tokenA = "usdt.fakes.testnet";
|
|
|
1430
1462
|
|
|
1431
1463
|
const tokenB = "wrap.testnet";
|
|
1432
1464
|
|
|
1465
|
+
const tokenAMetadata = await ftGetTokenMetadata(tokenA)
|
|
1466
|
+
|
|
1467
|
+
const tokenBMetadata = await ftGetTokenMetadata(tokenB)
|
|
1468
|
+
|
|
1469
|
+
|
|
1433
1470
|
const res = await DCLSwapByInputOnBestPool({
|
|
1434
|
-
tokenA,
|
|
1435
|
-
tokenB,
|
|
1471
|
+
tokenA:tokenAMetadata,
|
|
1472
|
+
tokenB:tokenBMetadata,
|
|
1436
1473
|
amountA: "1",
|
|
1437
1474
|
slippageTolerance: 0.1,
|
|
1438
1475
|
AccountId,
|
|
@@ -7,7 +7,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
7
7
|
var nearApiJs = require('near-api-js');
|
|
8
8
|
var BN = _interopDefault(require('bn.js'));
|
|
9
9
|
var fs = _interopDefault(require('fs'));
|
|
10
|
-
var os = _interopDefault(require('os'));
|
|
11
10
|
var _ = require('lodash');
|
|
12
11
|
var ___default = _interopDefault(_);
|
|
13
12
|
var math = require('mathjs');
|
|
@@ -52,7 +51,7 @@ function getConfig(env) {
|
|
|
52
51
|
REF_TOKEN_ID: 'token.v2.ref-finance.near',
|
|
53
52
|
indexerUrl: 'https://indexer.ref.finance',
|
|
54
53
|
explorerUrl: 'https://testnet.nearblocks.io',
|
|
55
|
-
REF_DCL_SWAP_CONTRACT_ID: ''
|
|
54
|
+
REF_DCL_SWAP_CONTRACT_ID: 'dcl.ref-labs.near'
|
|
56
55
|
};
|
|
57
56
|
case 'testnet':
|
|
58
57
|
return {
|
|
@@ -64,7 +63,7 @@ function getConfig(env) {
|
|
|
64
63
|
REF_FI_CONTRACT_ID: 'ref-finance-101.testnet',
|
|
65
64
|
REF_TOKEN_ID: 'ref.fakes.testnet',
|
|
66
65
|
explorerUrl: 'https://testnet.nearblocks.io',
|
|
67
|
-
REF_DCL_SWAP_CONTRACT_ID: '
|
|
66
|
+
REF_DCL_SWAP_CONTRACT_ID: 'dclv1.ref-dev.testnet'
|
|
68
67
|
};
|
|
69
68
|
default:
|
|
70
69
|
return {
|
|
@@ -76,7 +75,7 @@ function getConfig(env) {
|
|
|
76
75
|
REF_TOKEN_ID: 'token.v2.ref-finance.near',
|
|
77
76
|
indexerUrl: 'https://indexer.ref.finance',
|
|
78
77
|
explorerUrl: 'https://nearblocks.io',
|
|
79
|
-
REF_DCL_SWAP_CONTRACT_ID: ''
|
|
78
|
+
REF_DCL_SWAP_CONTRACT_ID: 'dcl.ref-labs.near'
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
}
|
|
@@ -3661,42 +3660,42 @@ var provider = /*#__PURE__*/new nearApiJs.providers.JsonRpcProvider({
|
|
|
3661
3660
|
});
|
|
3662
3661
|
var getMemorySigner = /*#__PURE__*/function () {
|
|
3663
3662
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
3664
|
-
var AccountId, keyPath,
|
|
3663
|
+
var AccountId, keyPath, credentials, credentialAccountId, myKeyStore, signer;
|
|
3665
3664
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3666
3665
|
while (1) {
|
|
3667
3666
|
switch (_context.prev = _context.next) {
|
|
3668
3667
|
case 0:
|
|
3669
3668
|
AccountId = _ref.AccountId, keyPath = _ref.keyPath;
|
|
3670
3669
|
_context.prev = 1;
|
|
3671
|
-
homedir = os.homedir();
|
|
3672
|
-
credentials = JSON.parse(fs.readFileSync(
|
|
3670
|
+
// const homedir = os.homedir();
|
|
3671
|
+
credentials = JSON.parse(fs.readFileSync(keyPath).toString());
|
|
3673
3672
|
credentialAccountId = credentials == null ? void 0 : credentials.account_id;
|
|
3674
3673
|
if (credentialAccountId) {
|
|
3675
|
-
_context.next =
|
|
3674
|
+
_context.next = 6;
|
|
3676
3675
|
break;
|
|
3677
3676
|
}
|
|
3678
3677
|
throw NoCredential;
|
|
3679
|
-
case
|
|
3678
|
+
case 6:
|
|
3680
3679
|
if (!(credentialAccountId !== AccountId)) {
|
|
3681
|
-
_context.next =
|
|
3680
|
+
_context.next = 8;
|
|
3682
3681
|
break;
|
|
3683
3682
|
}
|
|
3684
3683
|
throw AccountIdMisMatch;
|
|
3685
|
-
case
|
|
3684
|
+
case 8:
|
|
3686
3685
|
myKeyStore = new nearApiJs.keyStores.InMemoryKeyStore();
|
|
3687
3686
|
myKeyStore.setKey(getConfig().networkId, AccountId, nearApiJs.KeyPair.fromString(credentials.private_key));
|
|
3688
3687
|
signer = new nearApiJs.InMemorySigner(myKeyStore);
|
|
3689
3688
|
return _context.abrupt("return", signer);
|
|
3690
|
-
case
|
|
3691
|
-
_context.prev =
|
|
3689
|
+
case 14:
|
|
3690
|
+
_context.prev = 14;
|
|
3692
3691
|
_context.t0 = _context["catch"](1);
|
|
3693
3692
|
throw _context.t0;
|
|
3694
|
-
case
|
|
3693
|
+
case 17:
|
|
3695
3694
|
case "end":
|
|
3696
3695
|
return _context.stop();
|
|
3697
3696
|
}
|
|
3698
3697
|
}
|
|
3699
|
-
}, _callee, null, [[1,
|
|
3698
|
+
}, _callee, null, [[1, 14]]);
|
|
3700
3699
|
}));
|
|
3701
3700
|
return function getMemorySigner(_x) {
|
|
3702
3701
|
return _ref2.apply(this, arguments);
|
|
@@ -4295,12 +4294,12 @@ var OrderNoRemainedAmount = /*#__PURE__*/formatError('No remained amount on this
|
|
|
4295
4294
|
var instantSwap = /*#__PURE__*/function () {
|
|
4296
4295
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
4297
4296
|
var _swapTodos;
|
|
4298
|
-
var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, transactions, registerToken, registered, actionsList, allSwapsTokens, i, swapTokens;
|
|
4297
|
+
var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, referralId, transactions, registerToken, registered, actionsList, allSwapsTokens, i, swapTokens;
|
|
4299
4298
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4300
4299
|
while (1) {
|
|
4301
4300
|
switch (_context2.prev = _context2.next) {
|
|
4302
4301
|
case 0:
|
|
4303
|
-
tokenIn = _ref.tokenIn, tokenOut = _ref.tokenOut, amountIn = _ref.amountIn, slippageTolerance = _ref.slippageTolerance, swapTodos = _ref.swapTodos, AccountId = _ref.AccountId;
|
|
4302
|
+
tokenIn = _ref.tokenIn, tokenOut = _ref.tokenOut, amountIn = _ref.amountIn, slippageTolerance = _ref.slippageTolerance, swapTodos = _ref.swapTodos, AccountId = _ref.AccountId, referralId = _ref.referralId;
|
|
4304
4303
|
transactions = [];
|
|
4305
4304
|
if (!((swapTodos == null ? void 0 : (_swapTodos = swapTodos[(swapTodos == null ? void 0 : swapTodos.length) - 1]) == null ? void 0 : _swapTodos.outputToken) !== tokenOut.id)) {
|
|
4306
4305
|
_context2.next = 4;
|
|
@@ -4407,7 +4406,11 @@ var instantSwap = /*#__PURE__*/function () {
|
|
|
4407
4406
|
args: {
|
|
4408
4407
|
receiver_id: exports.REF_FI_CONTRACT_ID,
|
|
4409
4408
|
amount: toNonDivisibleNumber(tokenIn.decimals, amountIn),
|
|
4410
|
-
msg: JSON.stringify({
|
|
4409
|
+
msg: !!referralId ? JSON.stringify({
|
|
4410
|
+
force: 0,
|
|
4411
|
+
actions: actionsList,
|
|
4412
|
+
referral_id: referralId
|
|
4413
|
+
}) : JSON.stringify({
|
|
4411
4414
|
force: 0,
|
|
4412
4415
|
actions: actionsList
|
|
4413
4416
|
})
|
|
@@ -4657,7 +4660,7 @@ var fetchAllPools = /*#__PURE__*/function () {
|
|
|
4657
4660
|
};
|
|
4658
4661
|
}();
|
|
4659
4662
|
|
|
4660
|
-
var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState"];
|
|
4663
|
+
var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState", "referralId"];
|
|
4661
4664
|
var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
|
|
4662
4665
|
var ThemeContextProvider = function ThemeContextProvider(_ref) {
|
|
4663
4666
|
var customTheme = _ref.customTheme,
|
|
@@ -4835,6 +4838,7 @@ var useSwap = function useSwap(params) {
|
|
|
4835
4838
|
onSwap = params.onSwap,
|
|
4836
4839
|
AccountId = params.AccountId,
|
|
4837
4840
|
poolFetchingState = params.poolFetchingState,
|
|
4841
|
+
referralId = params.referralId,
|
|
4838
4842
|
swapParams = _objectWithoutPropertiesLoose(params, _excluded);
|
|
4839
4843
|
var tokenIn = params.tokenIn,
|
|
4840
4844
|
tokenOut = params.tokenOut,
|
|
@@ -4880,7 +4884,8 @@ var useSwap = function useSwap(params) {
|
|
|
4880
4884
|
amountIn: params.amountIn,
|
|
4881
4885
|
swapTodos: estimates,
|
|
4882
4886
|
slippageTolerance: slippageTolerance,
|
|
4883
|
-
AccountId: AccountId || ''
|
|
4887
|
+
AccountId: AccountId || '',
|
|
4888
|
+
referralId: referralId
|
|
4884
4889
|
});
|
|
4885
4890
|
case 4:
|
|
4886
4891
|
transactionsRef = _context3.sent;
|
|
@@ -6261,7 +6266,8 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6261
6266
|
defaultTokenIn = props.defaultTokenIn,
|
|
6262
6267
|
defaultTokenOut = props.defaultTokenOut,
|
|
6263
6268
|
onDisConnect = props.onDisConnect,
|
|
6264
|
-
darkMode = props.darkMode
|
|
6269
|
+
darkMode = props.darkMode,
|
|
6270
|
+
referralId = props.referralId;
|
|
6265
6271
|
var curTheme = theme || (darkMode ? defaultDarkModeTheme : defaultTheme);
|
|
6266
6272
|
var STORAGED_TOKEN_IN = localStorage.getItem(REF_WIDGET_SWAP_IN_KEY);
|
|
6267
6273
|
var STORAGED_TOKEN_OUT = localStorage.getItem(REF_WIDGET_SWAP_OUT_KEY);
|
|
@@ -6414,7 +6420,8 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6414
6420
|
onSwap: onSwap,
|
|
6415
6421
|
AccountId: AccountId,
|
|
6416
6422
|
refreshTrigger: refreshTrigger,
|
|
6417
|
-
poolFetchingState: poolFetchingState
|
|
6423
|
+
poolFetchingState: poolFetchingState,
|
|
6424
|
+
referralId: referralId
|
|
6418
6425
|
}),
|
|
6419
6426
|
amountOut = _useSwap.amountOut,
|
|
6420
6427
|
minAmountOut = _useSwap.minAmountOut,
|