@ref-finance/ref-sdk 1.3.0 → 1.3.2
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 +60 -0
- package/dist/dcl-swap/swap.d.ts +6 -1
- package/dist/ref-sdk.cjs.development.js +49 -26
- 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 +49 -26
- package/dist/ref-sdk.esm.js.map +1 -1
- package/dist/ref-sdk.umd.development.js +49 -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/package.json +2 -2
package/README.md
CHANGED
|
@@ -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/dcl-swap/swap.d.ts
CHANGED
|
@@ -18,10 +18,15 @@ interface DCLSwapProps {
|
|
|
18
18
|
pool_id: string;
|
|
19
19
|
output_amount: string;
|
|
20
20
|
};
|
|
21
|
+
SwapByStopPoint?: {
|
|
22
|
+
pool_id: string;
|
|
23
|
+
stop_point: number;
|
|
24
|
+
skip_unwrap_near: boolean;
|
|
25
|
+
};
|
|
21
26
|
AccountId: string;
|
|
22
27
|
}
|
|
23
28
|
export declare const DCL_POOL_SPLITER = "|";
|
|
24
|
-
export declare const DCLSwap: ({ Swap, SwapByOutput, LimitOrderWithSwap, AccountId, swapInfo, }: DCLSwapProps) => Promise<Transaction[]>;
|
|
29
|
+
export declare const DCLSwap: ({ Swap, SwapByOutput, LimitOrderWithSwap, SwapByStopPoint, AccountId, swapInfo, }: DCLSwapProps) => Promise<Transaction[]>;
|
|
25
30
|
export declare const quote: ({ pool_ids, input_amount, input_token, output_token, tag, }: {
|
|
26
31
|
pool_ids: string[];
|
|
27
32
|
input_token: TokenMetadata;
|
|
@@ -3884,11 +3884,7 @@ var refFiViewFunction = /*#__PURE__*/function () {
|
|
|
3884
3884
|
return near.account(exports.REF_FI_CONTRACT_ID);
|
|
3885
3885
|
case 3:
|
|
3886
3886
|
nearConnection = _context.sent;
|
|
3887
|
-
return _context.abrupt("return", nearConnection.viewFunction(
|
|
3888
|
-
contractId: exports.REF_FI_CONTRACT_ID,
|
|
3889
|
-
methodName: methodName,
|
|
3890
|
-
args: args
|
|
3891
|
-
}));
|
|
3887
|
+
return _context.abrupt("return", nearConnection.viewFunction(exports.REF_FI_CONTRACT_ID, methodName, args));
|
|
3892
3888
|
case 5:
|
|
3893
3889
|
case "end":
|
|
3894
3890
|
return _context.stop();
|
|
@@ -3912,11 +3908,7 @@ var ftViewFunction = /*#__PURE__*/function () {
|
|
|
3912
3908
|
return near.account(exports.REF_FI_CONTRACT_ID);
|
|
3913
3909
|
case 3:
|
|
3914
3910
|
nearConnection = _context2.sent;
|
|
3915
|
-
return _context2.abrupt("return", nearConnection.viewFunction(
|
|
3916
|
-
contractId: tokenId,
|
|
3917
|
-
methodName: methodName,
|
|
3918
|
-
args: args
|
|
3919
|
-
}));
|
|
3911
|
+
return _context2.abrupt("return", nearConnection.viewFunction(tokenId, methodName, args));
|
|
3920
3912
|
case 5:
|
|
3921
3913
|
case "end":
|
|
3922
3914
|
return _context2.stop();
|
|
@@ -4208,11 +4200,7 @@ var refDCLSwapViewFunction = /*#__PURE__*/function () {
|
|
|
4208
4200
|
}
|
|
4209
4201
|
throw DCLInValid;
|
|
4210
4202
|
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
|
-
}));
|
|
4203
|
+
return _context10.abrupt("return", nearConnection.viewFunction(exports.config.REF_DCL_SWAP_CONTRACT_ID, methodName, args));
|
|
4216
4204
|
case 7:
|
|
4217
4205
|
case "end":
|
|
4218
4206
|
return _context10.stop();
|
|
@@ -7507,12 +7495,12 @@ function getDefaultTokenList() {
|
|
|
7507
7495
|
var DCL_POOL_SPLITER = '|';
|
|
7508
7496
|
var DCLSwap = /*#__PURE__*/function () {
|
|
7509
7497
|
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
7510
|
-
var Swap, SwapByOutput, LimitOrderWithSwap, 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, registered;
|
|
7498
|
+
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;
|
|
7511
7499
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7512
7500
|
while (1) {
|
|
7513
7501
|
switch (_context.prev = _context.next) {
|
|
7514
7502
|
case 0:
|
|
7515
|
-
Swap = _ref.Swap, SwapByOutput = _ref.SwapByOutput, LimitOrderWithSwap = _ref.LimitOrderWithSwap, AccountId = _ref.AccountId, swapInfo = _ref.swapInfo;
|
|
7503
|
+
Swap = _ref.Swap, SwapByOutput = _ref.SwapByOutput, LimitOrderWithSwap = _ref.LimitOrderWithSwap, SwapByStopPoint = _ref.SwapByStopPoint, AccountId = _ref.AccountId, swapInfo = _ref.swapInfo;
|
|
7516
7504
|
transactions = [];
|
|
7517
7505
|
tokenA = swapInfo.tokenA, tokenB = swapInfo.tokenB, amountA = swapInfo.amountA;
|
|
7518
7506
|
if (!Swap) {
|
|
@@ -7555,7 +7543,7 @@ var DCLSwap = /*#__PURE__*/function () {
|
|
|
7555
7543
|
amount: ONE_YOCTO_NEAR
|
|
7556
7544
|
}]
|
|
7557
7545
|
});
|
|
7558
|
-
_context.next =
|
|
7546
|
+
_context.next = 52;
|
|
7559
7547
|
break;
|
|
7560
7548
|
case 15:
|
|
7561
7549
|
if (!SwapByOutput) {
|
|
@@ -7598,11 +7586,11 @@ var DCLSwap = /*#__PURE__*/function () {
|
|
|
7598
7586
|
amount: ONE_YOCTO_NEAR
|
|
7599
7587
|
}]
|
|
7600
7588
|
});
|
|
7601
|
-
_context.next =
|
|
7589
|
+
_context.next = 52;
|
|
7602
7590
|
break;
|
|
7603
7591
|
case 27:
|
|
7604
7592
|
if (!LimitOrderWithSwap) {
|
|
7605
|
-
_context.next =
|
|
7593
|
+
_context.next = 45;
|
|
7606
7594
|
break;
|
|
7607
7595
|
}
|
|
7608
7596
|
pool_id = LimitOrderWithSwap.pool_id;
|
|
@@ -7669,14 +7657,49 @@ var DCLSwap = /*#__PURE__*/function () {
|
|
|
7669
7657
|
amount: ONE_YOCTO_NEAR
|
|
7670
7658
|
}]
|
|
7671
7659
|
});
|
|
7672
|
-
|
|
7660
|
+
_context.next = 52;
|
|
7661
|
+
break;
|
|
7662
|
+
case 45:
|
|
7663
|
+
if (!SwapByStopPoint) {
|
|
7664
|
+
_context.next = 52;
|
|
7665
|
+
break;
|
|
7666
|
+
}
|
|
7667
|
+
_context.next = 48;
|
|
7668
|
+
return ftGetStorageBalance(tokenB.id, AccountId)["catch"](function () {
|
|
7669
|
+
throw new Error(tokenB.id + " doesn't exist.");
|
|
7670
|
+
});
|
|
7671
|
+
case 48:
|
|
7672
|
+
_tokenRegistered3 = _context.sent;
|
|
7673
|
+
if (_tokenRegistered3 === null) {
|
|
7674
|
+
transactions.push({
|
|
7675
|
+
receiverId: tokenB.id,
|
|
7676
|
+
functionCalls: [registerAccountOnToken(AccountId)]
|
|
7677
|
+
});
|
|
7678
|
+
}
|
|
7679
|
+
_msg3 = JSON.stringify({
|
|
7680
|
+
SwapByStopPoint: SwapByStopPoint
|
|
7681
|
+
});
|
|
7682
|
+
transactions.push({
|
|
7683
|
+
receiverId: tokenA.id,
|
|
7684
|
+
functionCalls: [{
|
|
7685
|
+
methodName: 'ft_transfer_call',
|
|
7686
|
+
args: {
|
|
7687
|
+
receiver_id: exports.config.REF_DCL_SWAP_CONTRACT_ID,
|
|
7688
|
+
amount: toNonDivisibleNumber(tokenA.decimals, amountA),
|
|
7689
|
+
msg: _msg3
|
|
7690
|
+
},
|
|
7691
|
+
gas: '180000000000000',
|
|
7692
|
+
amount: ONE_YOCTO_NEAR
|
|
7693
|
+
}]
|
|
7694
|
+
});
|
|
7695
|
+
case 52:
|
|
7673
7696
|
if (!(tokenA.id === exports.WRAP_NEAR_CONTRACT_ID)) {
|
|
7674
|
-
_context.next =
|
|
7697
|
+
_context.next = 57;
|
|
7675
7698
|
break;
|
|
7676
7699
|
}
|
|
7677
|
-
_context.next =
|
|
7700
|
+
_context.next = 55;
|
|
7678
7701
|
return ftGetStorageBalance(exports.WRAP_NEAR_CONTRACT_ID, AccountId);
|
|
7679
|
-
case
|
|
7702
|
+
case 55:
|
|
7680
7703
|
registered = _context.sent;
|
|
7681
7704
|
if (registered === null) {
|
|
7682
7705
|
transactions.unshift({
|
|
@@ -7684,9 +7707,9 @@ var DCLSwap = /*#__PURE__*/function () {
|
|
|
7684
7707
|
functionCalls: [registerAccountOnToken(AccountId)]
|
|
7685
7708
|
});
|
|
7686
7709
|
}
|
|
7687
|
-
case
|
|
7710
|
+
case 57:
|
|
7688
7711
|
return _context.abrupt("return", transactions);
|
|
7689
|
-
case
|
|
7712
|
+
case 58:
|
|
7690
7713
|
case "end":
|
|
7691
7714
|
return _context.stop();
|
|
7692
7715
|
}
|