@scallop-io/sui-scallop-sdk 0.44.6 → 0.44.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 +8 -1
- package/dist/constants/common.d.ts +2 -1
- package/dist/index.js +488 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +486 -92
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.ts +1 -0
- package/dist/models/scallop.d.ts +9 -1
- package/dist/models/scallopAddress.d.ts +1 -1
- package/dist/models/scallopBuilder.d.ts +1 -1
- package/dist/models/scallopClient.d.ts +1 -1
- package/dist/models/scallopIndexer.d.ts +81 -0
- package/dist/models/scallopQuery.d.ts +31 -15
- package/dist/queries/borrowIncentiveQuery.d.ts +4 -1
- package/dist/queries/coreQuery.d.ts +10 -6
- package/dist/queries/portfolioQuery.d.ts +10 -5
- package/dist/queries/spoolQuery.d.ts +6 -3
- package/dist/types/query/portfolio.d.ts +2 -0
- package/dist/utils/query.d.ts +8 -0
- package/package.json +1 -1
- package/src/constants/common.ts +2 -1
- package/src/constants/enum.ts +1 -0
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +14 -1
- package/src/models/scallopAddress.ts +1 -1
- package/src/models/scallopBuilder.ts +1 -1
- package/src/models/scallopClient.ts +36 -1
- package/src/models/scallopIndexer.ts +269 -0
- package/src/models/scallopQuery.ts +71 -28
- package/src/queries/borrowIncentiveQuery.ts +27 -6
- package/src/queries/coreQuery.ts +104 -18
- package/src/queries/portfolioQuery.ts +111 -52
- package/src/queries/spoolQuery.ts +67 -9
- package/src/types/query/portfolio.ts +2 -0
- package/src/utils/query.ts +26 -0
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
API_BASE_URL: () => API_BASE_URL,
|
|
35
35
|
BORROW_FEE_PROTOCOL_ID: () => BORROW_FEE_PROTOCOL_ID,
|
|
36
36
|
PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
|
|
37
|
+
SDK_API_BASE_URL: () => SDK_API_BASE_URL,
|
|
37
38
|
SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
38
39
|
SUPPORT_BORROW_INCENTIVE_REWARDS: () => SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
39
40
|
SUPPORT_COLLATERALS: () => SUPPORT_COLLATERALS,
|
|
@@ -46,6 +47,7 @@ __export(src_exports, {
|
|
|
46
47
|
ScallopAddress: () => ScallopAddress,
|
|
47
48
|
ScallopBuilder: () => ScallopBuilder,
|
|
48
49
|
ScallopClient: () => ScallopClient,
|
|
50
|
+
ScallopIndexer: () => ScallopIndexer,
|
|
49
51
|
ScallopQuery: () => ScallopQuery,
|
|
50
52
|
ScallopUtils: () => ScallopUtils,
|
|
51
53
|
assetCoins: () => assetCoins,
|
|
@@ -62,6 +64,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
62
64
|
|
|
63
65
|
// src/constants/common.ts
|
|
64
66
|
var API_BASE_URL = "https://sui.api.scallop.io";
|
|
67
|
+
var SDK_API_BASE_URL = "https://sui-scallop-sdk-api.vercel.app";
|
|
65
68
|
var ADDRESSES_ID = "6462a088a7ace142bb6d7e9b";
|
|
66
69
|
var PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
67
70
|
var BORROW_FEE_PROTOCOL_ID = "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
@@ -93,7 +96,7 @@ var SUPPORT_COLLATERALS = [
|
|
|
93
96
|
];
|
|
94
97
|
var SUPPORT_SPOOLS = ["ssui", "susdc", "susdt"];
|
|
95
98
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
96
|
-
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc"];
|
|
99
|
+
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc", "usdt"];
|
|
97
100
|
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
98
101
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
99
102
|
var SUPPORT_PACKAGES = [
|
|
@@ -174,7 +177,8 @@ var spoolRewardCoins = {
|
|
|
174
177
|
};
|
|
175
178
|
var borrowIncentiveRewardCoins = {
|
|
176
179
|
sui: "sui",
|
|
177
|
-
usdc: "sui"
|
|
180
|
+
usdc: "sui",
|
|
181
|
+
usdt: "sui"
|
|
178
182
|
};
|
|
179
183
|
var coinIds = {
|
|
180
184
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -1115,6 +1119,16 @@ var minBigNumber = (...args) => {
|
|
|
1115
1119
|
)
|
|
1116
1120
|
);
|
|
1117
1121
|
};
|
|
1122
|
+
var estimatedFactor = (amount, scaleStep, type) => {
|
|
1123
|
+
const amountOfDigits = Math.max(
|
|
1124
|
+
1,
|
|
1125
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
1126
|
+
);
|
|
1127
|
+
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
1128
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
1129
|
+
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
1130
|
+
return adjustFactor;
|
|
1131
|
+
};
|
|
1118
1132
|
|
|
1119
1133
|
// src/utils/util.ts
|
|
1120
1134
|
var isMarketCoin = (coinName) => {
|
|
@@ -1159,7 +1173,7 @@ var parseDataFromPythPriceFeed = (feed, address) => {
|
|
|
1159
1173
|
};
|
|
1160
1174
|
|
|
1161
1175
|
// src/queries/coreQuery.ts
|
|
1162
|
-
var queryMarket = async (query) => {
|
|
1176
|
+
var queryMarket = async (query, indexer = false) => {
|
|
1163
1177
|
const packageId = query.address.get("core.packages.query.id");
|
|
1164
1178
|
const marketId = query.address.get("core.market");
|
|
1165
1179
|
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
@@ -1167,12 +1181,30 @@ var queryMarket = async (query) => {
|
|
|
1167
1181
|
txBlock.moveCall(queryTarget, [marketId]);
|
|
1168
1182
|
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
1169
1183
|
const marketData = queryResult.events[0].parsedJson;
|
|
1184
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
1170
1185
|
const pools = {};
|
|
1171
1186
|
const collaterals = {};
|
|
1187
|
+
if (indexer) {
|
|
1188
|
+
const marketIndexer = await query.indexer.getMarket();
|
|
1189
|
+
for (const pool of Object.values(marketIndexer.pools)) {
|
|
1190
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
1191
|
+
pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
|
|
1192
|
+
}
|
|
1193
|
+
for (const collateral of Object.values(marketIndexer.collaterals)) {
|
|
1194
|
+
collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
|
|
1195
|
+
collateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
1196
|
+
collateral.coinName
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
return {
|
|
1200
|
+
pools: marketIndexer.pools,
|
|
1201
|
+
collaterals: marketIndexer.collaterals
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1172
1204
|
for (const pool of marketData.pools) {
|
|
1173
1205
|
const coinType = (0, import_utils2.normalizeStructTag)(pool.type.name);
|
|
1174
1206
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1175
|
-
const coinPrice =
|
|
1207
|
+
const coinPrice = coinPrices[poolCoinName] ?? 0;
|
|
1176
1208
|
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
1177
1209
|
continue;
|
|
1178
1210
|
}
|
|
@@ -1222,7 +1254,7 @@ var queryMarket = async (query) => {
|
|
|
1222
1254
|
for (const collateral of marketData.collaterals) {
|
|
1223
1255
|
const coinType = (0, import_utils2.normalizeStructTag)(collateral.type.name);
|
|
1224
1256
|
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1225
|
-
const coinPrice =
|
|
1257
|
+
const coinPrice = coinPrices[collateralCoinName] ?? 0;
|
|
1226
1258
|
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
1227
1259
|
continue;
|
|
1228
1260
|
}
|
|
@@ -1262,7 +1294,7 @@ var queryMarket = async (query) => {
|
|
|
1262
1294
|
data: marketData
|
|
1263
1295
|
};
|
|
1264
1296
|
};
|
|
1265
|
-
var getMarketPools = async (query, poolCoinNames) => {
|
|
1297
|
+
var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
1266
1298
|
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
1267
1299
|
const marketId = query.address.get("core.market");
|
|
1268
1300
|
const marketObjectResponse = await query.suiKit.client().getObject({
|
|
@@ -1273,10 +1305,24 @@ var getMarketPools = async (query, poolCoinNames) => {
|
|
|
1273
1305
|
});
|
|
1274
1306
|
const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
|
|
1275
1307
|
const marketPools = {};
|
|
1308
|
+
if (indexer) {
|
|
1309
|
+
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
1310
|
+
for (const marketPool of Object.values(marketPoolsIndexer)) {
|
|
1311
|
+
if (!poolCoinNames.includes(marketPool.coinName))
|
|
1312
|
+
continue;
|
|
1313
|
+
marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
|
|
1314
|
+
marketPool.coinWrappedType = query.utils.getCoinWrappedType(
|
|
1315
|
+
marketPool.coinName
|
|
1316
|
+
);
|
|
1317
|
+
marketPools[marketPool.coinName] = marketPool;
|
|
1318
|
+
}
|
|
1319
|
+
return marketPools;
|
|
1320
|
+
}
|
|
1276
1321
|
for (const poolCoinName of poolCoinNames) {
|
|
1277
1322
|
const marketPool = await getMarketPool(
|
|
1278
1323
|
query,
|
|
1279
1324
|
poolCoinName,
|
|
1325
|
+
indexer,
|
|
1280
1326
|
marketObjectResponse.data,
|
|
1281
1327
|
coinPrices?.[poolCoinName]
|
|
1282
1328
|
);
|
|
@@ -1286,7 +1332,7 @@ var getMarketPools = async (query, poolCoinNames) => {
|
|
|
1286
1332
|
}
|
|
1287
1333
|
return marketPools;
|
|
1288
1334
|
};
|
|
1289
|
-
var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
|
|
1335
|
+
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1290
1336
|
const marketId = query.address.get("core.market");
|
|
1291
1337
|
marketObject = marketObject || (await query.suiKit.client().getObject({
|
|
1292
1338
|
id: marketId,
|
|
@@ -1294,11 +1340,20 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
|
|
|
1294
1340
|
showContent: true
|
|
1295
1341
|
}
|
|
1296
1342
|
})).data;
|
|
1343
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
1297
1344
|
let marketPool;
|
|
1298
1345
|
let balanceSheet;
|
|
1299
1346
|
let borrowIndex;
|
|
1300
1347
|
let interestModel;
|
|
1301
1348
|
let borrowFeeRate;
|
|
1349
|
+
if (indexer) {
|
|
1350
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
1351
|
+
marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
|
|
1352
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
1353
|
+
marketPoolIndexer.coinName
|
|
1354
|
+
);
|
|
1355
|
+
return marketPoolIndexer;
|
|
1356
|
+
}
|
|
1302
1357
|
if (marketObject) {
|
|
1303
1358
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
1304
1359
|
const fields = marketObject.content.fields;
|
|
@@ -1392,7 +1447,6 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
|
|
|
1392
1447
|
query.utils,
|
|
1393
1448
|
parsedMarketPoolData
|
|
1394
1449
|
);
|
|
1395
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
1396
1450
|
marketPool = {
|
|
1397
1451
|
coinName: poolCoinName,
|
|
1398
1452
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -1413,7 +1467,7 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
|
|
|
1413
1467
|
}
|
|
1414
1468
|
return marketPool;
|
|
1415
1469
|
};
|
|
1416
|
-
var getMarketCollaterals = async (query, collateralCoinNames) => {
|
|
1470
|
+
var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
|
|
1417
1471
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
1418
1472
|
const marketId = query.address.get("core.market");
|
|
1419
1473
|
const marketObjectResponse = await query.suiKit.client().getObject({
|
|
@@ -1424,10 +1478,24 @@ var getMarketCollaterals = async (query, collateralCoinNames) => {
|
|
|
1424
1478
|
});
|
|
1425
1479
|
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
|
|
1426
1480
|
const marketCollaterals = {};
|
|
1481
|
+
if (indexer) {
|
|
1482
|
+
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
1483
|
+
for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
|
|
1484
|
+
if (!collateralCoinNames.includes(marketCollateral.coinName))
|
|
1485
|
+
continue;
|
|
1486
|
+
marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
|
|
1487
|
+
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
1488
|
+
marketCollateral.coinName
|
|
1489
|
+
);
|
|
1490
|
+
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
1491
|
+
}
|
|
1492
|
+
return marketCollaterals;
|
|
1493
|
+
}
|
|
1427
1494
|
for (const collateralCoinName of collateralCoinNames) {
|
|
1428
1495
|
const marketCollateral = await getMarketCollateral(
|
|
1429
1496
|
query,
|
|
1430
1497
|
collateralCoinName,
|
|
1498
|
+
indexer,
|
|
1431
1499
|
marketObjectResponse.data,
|
|
1432
1500
|
coinPrices?.[collateralCoinName]
|
|
1433
1501
|
);
|
|
@@ -1437,7 +1505,7 @@ var getMarketCollaterals = async (query, collateralCoinNames) => {
|
|
|
1437
1505
|
}
|
|
1438
1506
|
return marketCollaterals;
|
|
1439
1507
|
};
|
|
1440
|
-
var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPrice) => {
|
|
1508
|
+
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1441
1509
|
const marketId = query.address.get("core.market");
|
|
1442
1510
|
marketObject = marketObject || (await query.suiKit.client().getObject({
|
|
1443
1511
|
id: marketId,
|
|
@@ -1445,9 +1513,18 @@ var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPr
|
|
|
1445
1513
|
showContent: true
|
|
1446
1514
|
}
|
|
1447
1515
|
})).data;
|
|
1516
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
1448
1517
|
let marketCollateral;
|
|
1449
1518
|
let riskModel;
|
|
1450
1519
|
let collateralStat;
|
|
1520
|
+
if (indexer) {
|
|
1521
|
+
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
1522
|
+
marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
|
|
1523
|
+
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
1524
|
+
marketCollateralIndexer.coinName
|
|
1525
|
+
);
|
|
1526
|
+
return marketCollateralIndexer;
|
|
1527
|
+
}
|
|
1451
1528
|
if (marketObject) {
|
|
1452
1529
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
1453
1530
|
const fields = marketObject.content.fields;
|
|
@@ -1499,7 +1576,6 @@ var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPr
|
|
|
1499
1576
|
query.utils,
|
|
1500
1577
|
parsedMarketCollateralData
|
|
1501
1578
|
);
|
|
1502
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
1503
1579
|
marketCollateral = {
|
|
1504
1580
|
coinName: collateralCoinName,
|
|
1505
1581
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -1742,19 +1818,47 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1742
1818
|
|
|
1743
1819
|
// src/queries/spoolQuery.ts
|
|
1744
1820
|
var import_utils4 = require("@mysten/sui.js/utils");
|
|
1745
|
-
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1821
|
+
var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
|
|
1746
1822
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1747
1823
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
1748
1824
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
1749
1825
|
);
|
|
1750
|
-
const
|
|
1826
|
+
const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
|
|
1827
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
|
|
1828
|
+
return rewardCoinName;
|
|
1829
|
+
});
|
|
1830
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
1831
|
+
[.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])]
|
|
1832
|
+
);
|
|
1833
|
+
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
1751
1834
|
const spools = {};
|
|
1835
|
+
if (indexer) {
|
|
1836
|
+
const spoolsIndexer = await query.indexer.getSpools();
|
|
1837
|
+
for (const spool of Object.values(spoolsIndexer)) {
|
|
1838
|
+
if (!stakeMarketCoinNames.includes(spool.marketCoinName))
|
|
1839
|
+
continue;
|
|
1840
|
+
const coinName = query.utils.parseCoinName(
|
|
1841
|
+
spool.marketCoinName
|
|
1842
|
+
);
|
|
1843
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
1844
|
+
spool.marketCoinName
|
|
1845
|
+
);
|
|
1846
|
+
const marketPool = marketPools[coinName];
|
|
1847
|
+
spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
|
|
1848
|
+
spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
|
|
1849
|
+
spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
|
|
1850
|
+
spools[spool.marketCoinName] = spool;
|
|
1851
|
+
}
|
|
1852
|
+
return spools;
|
|
1853
|
+
}
|
|
1752
1854
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
1753
1855
|
const stakeCoinName = query.utils.parseCoinName(stakeMarketCoinName);
|
|
1754
1856
|
const spool = await getSpool(
|
|
1755
1857
|
query,
|
|
1756
1858
|
stakeMarketCoinName,
|
|
1757
|
-
|
|
1859
|
+
indexer,
|
|
1860
|
+
marketPools[stakeCoinName],
|
|
1861
|
+
coinPrices
|
|
1758
1862
|
);
|
|
1759
1863
|
if (spool) {
|
|
1760
1864
|
spools[stakeMarketCoinName] = spool;
|
|
@@ -1762,15 +1866,24 @@ var getSpools = async (query, stakeMarketCoinNames) => {
|
|
|
1762
1866
|
}
|
|
1763
1867
|
return spools;
|
|
1764
1868
|
};
|
|
1765
|
-
var getSpool = async (query, marketCoinName, marketPool) => {
|
|
1869
|
+
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
1766
1870
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1767
|
-
marketPool = marketPool || await query.getMarketPool(coinName);
|
|
1871
|
+
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
1768
1872
|
const spoolPkgId = query.address.get(`spool.id`);
|
|
1769
1873
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1770
1874
|
const rewardPoolId = query.address.get(
|
|
1771
1875
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
1772
1876
|
);
|
|
1773
1877
|
let spool = void 0;
|
|
1878
|
+
if (indexer) {
|
|
1879
|
+
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
1880
|
+
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
1881
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1882
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName2] || spoolIndexer.coinPrice;
|
|
1883
|
+
spoolIndexer.marketCoinPrice = (coinPrices?.[coinName2] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spoolIndexer.marketCoinPrice;
|
|
1884
|
+
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName] || spoolIndexer.rewardCoinPrice;
|
|
1885
|
+
return spoolIndexer;
|
|
1886
|
+
}
|
|
1774
1887
|
const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
|
|
1775
1888
|
ids: [poolId, rewardPoolId],
|
|
1776
1889
|
options: {
|
|
@@ -1786,10 +1899,7 @@ var getSpool = async (query, marketCoinName, marketPool) => {
|
|
|
1786
1899
|
});
|
|
1787
1900
|
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1788
1901
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1789
|
-
|
|
1790
|
-
coinName,
|
|
1791
|
-
rewardCoinName
|
|
1792
|
-
]);
|
|
1902
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
1793
1903
|
const spoolObject = spoolObjectResponse[0].data;
|
|
1794
1904
|
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1795
1905
|
const rewardFeeObject = spoolRewardFeeDynamicFieldsResponse.data;
|
|
@@ -2047,7 +2157,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2047
2157
|
// src/queries/borrowIncentiveQuery.ts
|
|
2048
2158
|
var import_utils6 = require("@mysten/sui.js/utils");
|
|
2049
2159
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
2050
|
-
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
2160
|
+
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
|
|
2051
2161
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2052
2162
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2053
2163
|
];
|
|
@@ -2062,18 +2172,31 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
|
2062
2172
|
borrowIncentivePoolsQueryData.reward_pool
|
|
2063
2173
|
);
|
|
2064
2174
|
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
2175
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2176
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
2177
|
+
[.../* @__PURE__ */ new Set([...borrowIncentiveCoinNames, rewardCoinName])]
|
|
2178
|
+
);
|
|
2065
2179
|
const borrowIncentivePools = {};
|
|
2180
|
+
if (indexer) {
|
|
2181
|
+
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2182
|
+
for (const borrowIncentivePool of Object.values(
|
|
2183
|
+
borrowIncentivePoolsIndexer
|
|
2184
|
+
)) {
|
|
2185
|
+
if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
|
|
2186
|
+
continue;
|
|
2187
|
+
borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
|
|
2188
|
+
borrowIncentivePool.rewardCoinPrice = coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
|
|
2189
|
+
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
2190
|
+
}
|
|
2191
|
+
return borrowIncentivePools;
|
|
2192
|
+
}
|
|
2066
2193
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2067
2194
|
const coinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
|
|
2068
2195
|
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
2069
|
-
const
|
|
2196
|
+
const rewardCoinName2 = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
2070
2197
|
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
2071
2198
|
continue;
|
|
2072
2199
|
}
|
|
2073
|
-
const coinPrices = await query.utils.getCoinPrices([
|
|
2074
|
-
coinName,
|
|
2075
|
-
rewardCoinName
|
|
2076
|
-
]);
|
|
2077
2200
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2078
2201
|
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
2079
2202
|
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
@@ -2082,8 +2205,8 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
|
2082
2205
|
coinPrice,
|
|
2083
2206
|
coinDecimal
|
|
2084
2207
|
);
|
|
2085
|
-
const rewardCoinPrice = coinPrices?.[
|
|
2086
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(
|
|
2208
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName2] ?? 0;
|
|
2209
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName2);
|
|
2087
2210
|
const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
|
|
2088
2211
|
parsedBorrowIncentivePoolData,
|
|
2089
2212
|
parsedBorrowIncentiveRewardPoolData,
|
|
@@ -2179,7 +2302,7 @@ var getPythPrice = async (query, assetCoinName) => {
|
|
|
2179
2302
|
|
|
2180
2303
|
// src/queries/portfolioQuery.ts
|
|
2181
2304
|
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
2182
|
-
var getLendings = async (query, poolCoinNames, ownerAddress) => {
|
|
2305
|
+
var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) => {
|
|
2183
2306
|
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
2184
2307
|
const marketCoinNames = poolCoinNames.map(
|
|
2185
2308
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
@@ -2187,8 +2310,8 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
|
|
|
2187
2310
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
2188
2311
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
2189
2312
|
);
|
|
2190
|
-
const marketPools = await query.getMarketPools(poolCoinNames);
|
|
2191
|
-
const spools = await query.getSpools(stakeMarketCoinNames);
|
|
2313
|
+
const marketPools = await query.getMarketPools(poolCoinNames, indexer);
|
|
2314
|
+
const spools = await query.getSpools(stakeMarketCoinNames, indexer);
|
|
2192
2315
|
const coinAmounts = await query.getCoinAmounts(poolCoinNames, ownerAddress);
|
|
2193
2316
|
const marketCoinAmounts = await query.getMarketCoinAmounts(
|
|
2194
2317
|
marketCoinNames,
|
|
@@ -2206,6 +2329,7 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
|
|
|
2206
2329
|
query,
|
|
2207
2330
|
poolCoinName,
|
|
2208
2331
|
ownerAddress,
|
|
2332
|
+
indexer,
|
|
2209
2333
|
marketPools?.[poolCoinName],
|
|
2210
2334
|
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
2211
2335
|
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
|
|
@@ -2216,10 +2340,10 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
|
|
|
2216
2340
|
}
|
|
2217
2341
|
return lendings;
|
|
2218
2342
|
};
|
|
2219
|
-
var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
2343
|
+
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
2220
2344
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
2221
|
-
marketPool = marketPool || await query.getMarketPool(poolCoinName);
|
|
2222
|
-
spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName) : void 0;
|
|
2345
|
+
marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
|
|
2346
|
+
spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
|
|
2223
2347
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
2224
2348
|
marketCoinName,
|
|
2225
2349
|
ownerAddress
|
|
@@ -2266,7 +2390,7 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
|
|
|
2266
2390
|
-1 * spool.coinDecimal
|
|
2267
2391
|
);
|
|
2268
2392
|
const baseIndexRate = 1e9;
|
|
2269
|
-
const increasedPointRate = spool
|
|
2393
|
+
const increasedPointRate = spool.currentPointIndex ? (0, import_bignumber3.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
2270
2394
|
baseIndexRate
|
|
2271
2395
|
) : 1;
|
|
2272
2396
|
availableClaimAmount = availableClaimAmount.plus(
|
|
@@ -2330,8 +2454,8 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
|
|
|
2330
2454
|
};
|
|
2331
2455
|
return lending;
|
|
2332
2456
|
};
|
|
2333
|
-
var getObligationAccounts = async (query, ownerAddress) => {
|
|
2334
|
-
const market = await query.queryMarket();
|
|
2457
|
+
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
2458
|
+
const market = await query.queryMarket(indexer);
|
|
2335
2459
|
const coinPrices = await query.utils.getCoinPrices();
|
|
2336
2460
|
const coinAmounts = await query.getCoinAmounts(void 0, ownerAddress);
|
|
2337
2461
|
const obligations = await query.getObligations(ownerAddress);
|
|
@@ -2341,6 +2465,7 @@ var getObligationAccounts = async (query, ownerAddress) => {
|
|
|
2341
2465
|
query,
|
|
2342
2466
|
obligation.id,
|
|
2343
2467
|
ownerAddress,
|
|
2468
|
+
indexer,
|
|
2344
2469
|
market,
|
|
2345
2470
|
coinPrices,
|
|
2346
2471
|
coinAmounts
|
|
@@ -2348,8 +2473,8 @@ var getObligationAccounts = async (query, ownerAddress) => {
|
|
|
2348
2473
|
}
|
|
2349
2474
|
return obligationAccounts;
|
|
2350
2475
|
};
|
|
2351
|
-
var getObligationAccount = async (query, obligationId, ownerAddress, market, coinPrices, coinAmounts) => {
|
|
2352
|
-
market = market || await query.queryMarket();
|
|
2476
|
+
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
2477
|
+
market = market || await query.queryMarket(indexer);
|
|
2353
2478
|
const assetCoinNames = [
|
|
2354
2479
|
.../* @__PURE__ */ new Set([
|
|
2355
2480
|
...Object.values(market.pools).map((pool) => pool.coinName),
|
|
@@ -2359,7 +2484,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2359
2484
|
])
|
|
2360
2485
|
];
|
|
2361
2486
|
const obligationQuery = await query.queryObligation(obligationId);
|
|
2362
|
-
const borrowIncentivePools = await query.getBorrowIncentivePools(
|
|
2487
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools(
|
|
2488
|
+
void 0,
|
|
2489
|
+
indexer
|
|
2490
|
+
);
|
|
2363
2491
|
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
2364
2492
|
coinPrices = coinPrices || await query.utils.getCoinPrices(assetCoinNames);
|
|
2365
2493
|
coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
|
|
@@ -2380,8 +2508,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2380
2508
|
);
|
|
2381
2509
|
return assetCoinName === collateralCoinName;
|
|
2382
2510
|
});
|
|
2383
|
-
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2384
2511
|
const marketCollateral = market.collaterals[assetCoinName];
|
|
2512
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2385
2513
|
const coinPrice = coinPrices?.[assetCoinName];
|
|
2386
2514
|
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
2387
2515
|
if (marketCollateral && coinPrice) {
|
|
@@ -2431,20 +2559,23 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2431
2559
|
);
|
|
2432
2560
|
return assetCoinName === poolCoinName;
|
|
2433
2561
|
});
|
|
2434
|
-
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2435
2562
|
const marketPool = market.pools[assetCoinName];
|
|
2563
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2436
2564
|
const coinPrice = coinPrices?.[assetCoinName];
|
|
2565
|
+
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
2437
2566
|
if (marketPool && coinPrice) {
|
|
2438
2567
|
const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
|
|
2439
2568
|
const borrowedAmount = (0, import_bignumber3.default)(debt?.amount ?? 0);
|
|
2440
2569
|
const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
|
|
2441
|
-
const
|
|
2570
|
+
const requiredRepayAmount = borrowedAmount.multipliedBy(
|
|
2442
2571
|
increasedRate + 1
|
|
2443
2572
|
);
|
|
2573
|
+
const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
|
|
2574
|
+
const availableRepayAmount = (0, import_bignumber3.default)(coinAmount);
|
|
2444
2575
|
const availableRepayCoin = availableRepayAmount.shiftedBy(
|
|
2445
2576
|
-1 * coinDecimal
|
|
2446
2577
|
);
|
|
2447
|
-
const borrowedValue =
|
|
2578
|
+
const borrowedValue = requiredRepayCoin.multipliedBy(coinPrice);
|
|
2448
2579
|
const borrowedValueWithWeight = borrowedValue.multipliedBy(
|
|
2449
2580
|
marketPool.borrowWeight
|
|
2450
2581
|
);
|
|
@@ -2466,6 +2597,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2466
2597
|
borrowedValue: borrowedValue.toNumber(),
|
|
2467
2598
|
borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
|
|
2468
2599
|
borrowIndex: Number(debt?.borrowIndex ?? 0),
|
|
2600
|
+
requiredRepayAmount: requiredRepayAmount.toNumber(),
|
|
2601
|
+
requiredRepayCoin: requiredRepayCoin.toNumber(),
|
|
2469
2602
|
availableBorrowAmount: 0,
|
|
2470
2603
|
availableBorrowCoin: 0,
|
|
2471
2604
|
availableRepayAmount: availableRepayAmount.toNumber(),
|
|
@@ -2508,8 +2641,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2508
2641
|
}
|
|
2509
2642
|
}
|
|
2510
2643
|
}
|
|
2511
|
-
let riskLevel = totalRequiredCollateralValue.isZero()
|
|
2512
|
-
riskLevel = riskLevel.
|
|
2644
|
+
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
2645
|
+
riskLevel = riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber3.default)(1);
|
|
2513
2646
|
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber3.default)(0);
|
|
2514
2647
|
const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0, import_bignumber3.default)(0);
|
|
2515
2648
|
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber3.default)(0);
|
|
@@ -2544,13 +2677,25 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2544
2677
|
)) {
|
|
2545
2678
|
const marketCollateral = market.collaterals[collateralCoinName];
|
|
2546
2679
|
if (marketCollateral) {
|
|
2547
|
-
|
|
2548
|
-
|
|
2680
|
+
let estimatedAvailableWithdrawAmount = (0, import_bignumber3.default)(
|
|
2681
|
+
obligationAccount.totalAvailableCollateralValue
|
|
2682
|
+
).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).shiftedBy(marketCollateral.coinDecimal);
|
|
2683
|
+
estimatedAvailableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? (
|
|
2684
|
+
// Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
|
|
2685
|
+
(0, import_bignumber3.default)(obligationCollateral.depositedAmount)
|
|
2686
|
+
) : minBigNumber(
|
|
2687
|
+
estimatedAvailableWithdrawAmount.multipliedBy(
|
|
2688
|
+
estimatedFactor(
|
|
2689
|
+
(0, import_bignumber3.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).toNumber(),
|
|
2690
|
+
3,
|
|
2691
|
+
"increase"
|
|
2692
|
+
)
|
|
2693
|
+
).toNumber(),
|
|
2549
2694
|
obligationCollateral.depositedAmount,
|
|
2550
2695
|
marketCollateral.depositAmount
|
|
2551
2696
|
);
|
|
2552
|
-
obligationCollateral.availableWithdrawAmount =
|
|
2553
|
-
obligationCollateral.availableWithdrawCoin =
|
|
2697
|
+
obligationCollateral.availableWithdrawAmount = estimatedAvailableWithdrawAmount.toNumber();
|
|
2698
|
+
obligationCollateral.availableWithdrawCoin = estimatedAvailableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
2554
2699
|
}
|
|
2555
2700
|
}
|
|
2556
2701
|
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
@@ -2558,29 +2703,44 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2558
2703
|
)) {
|
|
2559
2704
|
const marketPool = market.pools[poolCoinName];
|
|
2560
2705
|
if (marketPool) {
|
|
2561
|
-
const
|
|
2562
|
-
obligationDebt.
|
|
2563
|
-
).multipliedBy(
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2706
|
+
const estimatedRequiredRepayAmount = (0, import_bignumber3.default)(
|
|
2707
|
+
obligationDebt.requiredRepayAmount
|
|
2708
|
+
).multipliedBy(
|
|
2709
|
+
estimatedFactor(obligationDebt.borrowedValue, 3, "decrease")
|
|
2710
|
+
);
|
|
2711
|
+
let estimatedAvailableBorrowAmount = (0, import_bignumber3.default)(
|
|
2712
|
+
obligationAccount.totalAvailableCollateralValue
|
|
2713
|
+
).dividedBy(marketPool.borrowWeight).shiftedBy(marketPool.coinDecimal).dividedBy(marketPool.coinPrice);
|
|
2714
|
+
estimatedAvailableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
|
|
2715
|
+
estimatedAvailableBorrowAmount.multipliedBy(
|
|
2716
|
+
estimatedFactor(
|
|
2717
|
+
estimatedAvailableBorrowAmount.shiftedBy(-1 * marketPool.coinDecimal).multipliedBy(marketPool.coinPrice).toNumber(),
|
|
2718
|
+
3,
|
|
2719
|
+
"increase"
|
|
2568
2720
|
)
|
|
2569
|
-
).
|
|
2721
|
+
).toNumber(),
|
|
2570
2722
|
marketPool.supplyAmount
|
|
2571
2723
|
) : (0, import_bignumber3.default)(0);
|
|
2572
|
-
obligationDebt.availableBorrowAmount =
|
|
2573
|
-
obligationDebt.availableBorrowCoin =
|
|
2574
|
-
obligationDebt.
|
|
2575
|
-
obligationDebt.
|
|
2724
|
+
obligationDebt.availableBorrowAmount = estimatedAvailableBorrowAmount.toNumber();
|
|
2725
|
+
obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
2726
|
+
obligationDebt.requiredRepayAmount = estimatedRequiredRepayAmount.toNumber();
|
|
2727
|
+
obligationDebt.requiredRepayCoin = estimatedRequiredRepayAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
2576
2728
|
}
|
|
2577
2729
|
}
|
|
2578
2730
|
return obligationAccount;
|
|
2579
2731
|
};
|
|
2580
|
-
var getTotalValueLocked = async (query) => {
|
|
2581
|
-
const market = await query.queryMarket();
|
|
2732
|
+
var getTotalValueLocked = async (query, indexer = false) => {
|
|
2733
|
+
const market = await query.queryMarket(indexer);
|
|
2582
2734
|
let supplyValue = (0, import_bignumber3.default)(0);
|
|
2583
2735
|
let borrowValue = (0, import_bignumber3.default)(0);
|
|
2736
|
+
if (indexer) {
|
|
2737
|
+
const tvl2 = await query.indexer.getTotalValueLocked();
|
|
2738
|
+
return {
|
|
2739
|
+
supplyValue: tvl2.supplyValue,
|
|
2740
|
+
borrowValue: tvl2.borrowValue,
|
|
2741
|
+
totalValue: tvl2.totalValue
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2584
2744
|
for (const pool of Object.values(market.pools)) {
|
|
2585
2745
|
supplyValue = supplyValue.plus(
|
|
2586
2746
|
(0, import_bignumber3.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
|
|
@@ -2602,6 +2762,183 @@ var getTotalValueLocked = async (query) => {
|
|
|
2602
2762
|
return tvl;
|
|
2603
2763
|
};
|
|
2604
2764
|
|
|
2765
|
+
// src/models/scallopIndexer.ts
|
|
2766
|
+
var import_axios2 = __toESM(require("axios"));
|
|
2767
|
+
var ScallopIndexer = class {
|
|
2768
|
+
constructor() {
|
|
2769
|
+
this._requestClient = import_axios2.default.create({
|
|
2770
|
+
baseURL: SDK_API_BASE_URL,
|
|
2771
|
+
headers: {
|
|
2772
|
+
"Content-Type": "application/json",
|
|
2773
|
+
Accept: "application/json"
|
|
2774
|
+
},
|
|
2775
|
+
timeout: 3e4
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Get market index data.
|
|
2780
|
+
*
|
|
2781
|
+
* @return Market data.
|
|
2782
|
+
*/
|
|
2783
|
+
async getMarket() {
|
|
2784
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market`);
|
|
2785
|
+
if (response.status === 200) {
|
|
2786
|
+
return {
|
|
2787
|
+
pools: response.data.pools.reduce((marketPools, marketPool) => {
|
|
2788
|
+
marketPools[marketPool.coinName] = marketPool;
|
|
2789
|
+
return marketPools;
|
|
2790
|
+
}, {}),
|
|
2791
|
+
collaterals: response.data.collaterals.reduce(
|
|
2792
|
+
(marketCollaterals, marketCollateral) => {
|
|
2793
|
+
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
2794
|
+
return marketCollaterals;
|
|
2795
|
+
},
|
|
2796
|
+
{}
|
|
2797
|
+
)
|
|
2798
|
+
};
|
|
2799
|
+
} else {
|
|
2800
|
+
throw Error("Failed to getMarket.");
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* Get market pools index data.
|
|
2805
|
+
*
|
|
2806
|
+
* @return Market pools data.
|
|
2807
|
+
*/
|
|
2808
|
+
async getMarketPools() {
|
|
2809
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pools`);
|
|
2810
|
+
if (response.status === 200) {
|
|
2811
|
+
return response.data.pools.reduce((marketPools, marketPool) => {
|
|
2812
|
+
marketPools[marketPool.coinName] = marketPool;
|
|
2813
|
+
return marketPools;
|
|
2814
|
+
}, {});
|
|
2815
|
+
} else {
|
|
2816
|
+
throw Error("Failed to getMarketPools.");
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* Get market pool index data.
|
|
2821
|
+
*
|
|
2822
|
+
* @return Market pool data.
|
|
2823
|
+
*/
|
|
2824
|
+
async getMarketPool(poolCoinName) {
|
|
2825
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pool/${poolCoinName}`);
|
|
2826
|
+
if (response.status === 200) {
|
|
2827
|
+
return response.data.pool;
|
|
2828
|
+
} else {
|
|
2829
|
+
throw Error("Failed to getMarketPool.");
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Get market collaterals index data.
|
|
2834
|
+
*
|
|
2835
|
+
* @return Market collaterals data.
|
|
2836
|
+
*/
|
|
2837
|
+
async getMarketCollaterals() {
|
|
2838
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collaterals`);
|
|
2839
|
+
if (response.status === 200) {
|
|
2840
|
+
return response.data.collaterals.reduce(
|
|
2841
|
+
(marketCollaterals, marketCollateral) => {
|
|
2842
|
+
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
2843
|
+
return marketCollaterals;
|
|
2844
|
+
},
|
|
2845
|
+
{}
|
|
2846
|
+
);
|
|
2847
|
+
} else {
|
|
2848
|
+
throw Error("Failed to getMarketCollaterals.");
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Get market collateral index data.
|
|
2853
|
+
*
|
|
2854
|
+
* @return Market collateral data.
|
|
2855
|
+
*/
|
|
2856
|
+
async getMarketCollateral(collateralCoinName) {
|
|
2857
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collateral/${collateralCoinName}`);
|
|
2858
|
+
if (response.status === 200) {
|
|
2859
|
+
return response.data.collateral;
|
|
2860
|
+
} else {
|
|
2861
|
+
throw Error("Failed to getMarketCollateral.");
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* Get spools index data.
|
|
2866
|
+
*
|
|
2867
|
+
* @return Spools data.
|
|
2868
|
+
*/
|
|
2869
|
+
async getSpools() {
|
|
2870
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spools`);
|
|
2871
|
+
if (response.status === 200) {
|
|
2872
|
+
return response.data.spools.reduce((spools, spool) => {
|
|
2873
|
+
spools[spool.marketCoinName] = spool;
|
|
2874
|
+
return spools;
|
|
2875
|
+
}, {});
|
|
2876
|
+
} else {
|
|
2877
|
+
throw Error("Failed to getSpools.");
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Get spool index data.
|
|
2882
|
+
*
|
|
2883
|
+
* @return Spool data.
|
|
2884
|
+
*/
|
|
2885
|
+
async getSpool(marketCoinName) {
|
|
2886
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spool/${marketCoinName}`);
|
|
2887
|
+
if (response.status === 200) {
|
|
2888
|
+
return response.data.spool;
|
|
2889
|
+
} else {
|
|
2890
|
+
throw Error("Failed to getSpool.");
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Get borrow incentive pools index data.
|
|
2895
|
+
*
|
|
2896
|
+
* @return Borrow incentive pools data.
|
|
2897
|
+
*/
|
|
2898
|
+
async getBorrowIncentivePools() {
|
|
2899
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/borrowIncentivePools`);
|
|
2900
|
+
if (response.status === 200) {
|
|
2901
|
+
return response.data.borrowIncentivePools.reduce(
|
|
2902
|
+
(borrowIncentivePools, borrowIncentivePool) => {
|
|
2903
|
+
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
2904
|
+
return borrowIncentivePools;
|
|
2905
|
+
},
|
|
2906
|
+
{}
|
|
2907
|
+
);
|
|
2908
|
+
} else {
|
|
2909
|
+
throw Error("Failed to getBorrowIncentivePools.");
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Get borrow incentive pool index data.
|
|
2914
|
+
*
|
|
2915
|
+
* @return Borrow incentive pool data.
|
|
2916
|
+
*/
|
|
2917
|
+
async getBorrowIncentivePool(borrowIncentiveCoinName) {
|
|
2918
|
+
const response = await this._requestClient.get(
|
|
2919
|
+
`${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
|
|
2920
|
+
);
|
|
2921
|
+
if (response.status === 200) {
|
|
2922
|
+
return response.data.borrowIncentivePool;
|
|
2923
|
+
} else {
|
|
2924
|
+
throw Error("Failed to getSpool.");
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* Get total value locked index data.
|
|
2929
|
+
*
|
|
2930
|
+
* @return Total value locked.
|
|
2931
|
+
*/
|
|
2932
|
+
async getTotalValueLocked() {
|
|
2933
|
+
const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/tvl`);
|
|
2934
|
+
if (response.status === 200) {
|
|
2935
|
+
return response.data;
|
|
2936
|
+
} else {
|
|
2937
|
+
throw Error("Failed to getTotalValueLocked.");
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
|
|
2605
2942
|
// src/models/scallopQuery.ts
|
|
2606
2943
|
var ScallopQuery = class {
|
|
2607
2944
|
constructor(params, instance) {
|
|
@@ -2616,6 +2953,7 @@ var ScallopQuery = class {
|
|
|
2616
2953
|
address: this.address,
|
|
2617
2954
|
query: this
|
|
2618
2955
|
});
|
|
2956
|
+
this.indexer = new ScallopIndexer();
|
|
2619
2957
|
}
|
|
2620
2958
|
/**
|
|
2621
2959
|
* Request the scallop API to initialize data.
|
|
@@ -2631,11 +2969,11 @@ var ScallopQuery = class {
|
|
|
2631
2969
|
/* ==================== Core Query Methods ==================== */
|
|
2632
2970
|
/**
|
|
2633
2971
|
* Query market data.
|
|
2634
|
-
*
|
|
2972
|
+
* @param indexer - Whether to use indexer.
|
|
2635
2973
|
* @return Market data.
|
|
2636
2974
|
*/
|
|
2637
|
-
async queryMarket() {
|
|
2638
|
-
return await queryMarket(this);
|
|
2975
|
+
async queryMarket(indexer = false) {
|
|
2976
|
+
return await queryMarket(this, indexer);
|
|
2639
2977
|
}
|
|
2640
2978
|
/**
|
|
2641
2979
|
* Get market pools.
|
|
@@ -2645,19 +2983,21 @@ var ScallopQuery = class {
|
|
|
2645
2983
|
* the `queryMarket` method to reduce time consumption.
|
|
2646
2984
|
*
|
|
2647
2985
|
* @param poolCoinNames - Specific an array of support pool coin name.
|
|
2986
|
+
* @param indexer - Whether to use indexer.
|
|
2648
2987
|
* @return Market pools data.
|
|
2649
2988
|
*/
|
|
2650
|
-
async getMarketPools(poolCoinNames) {
|
|
2651
|
-
return await getMarketPools(this, poolCoinNames);
|
|
2989
|
+
async getMarketPools(poolCoinNames, indexer = false) {
|
|
2990
|
+
return await getMarketPools(this, poolCoinNames, indexer);
|
|
2652
2991
|
}
|
|
2653
2992
|
/**
|
|
2654
2993
|
* Get market pool
|
|
2655
2994
|
*
|
|
2656
2995
|
* @param poolCoinName - Specific support pool coin name.
|
|
2996
|
+
* @param indexer - Whether to use indexer.
|
|
2657
2997
|
* @return Market pool data.
|
|
2658
2998
|
*/
|
|
2659
|
-
async getMarketPool(poolCoinName) {
|
|
2660
|
-
return await getMarketPool(this, poolCoinName);
|
|
2999
|
+
async getMarketPool(poolCoinName, indexer = false) {
|
|
3000
|
+
return await getMarketPool(this, poolCoinName, indexer);
|
|
2661
3001
|
}
|
|
2662
3002
|
/**
|
|
2663
3003
|
* Get market collaterals.
|
|
@@ -2667,19 +3007,21 @@ var ScallopQuery = class {
|
|
|
2667
3007
|
* the `queryMarket` method to reduce time consumption.
|
|
2668
3008
|
*
|
|
2669
3009
|
* @param collateralCoinNames - Specific an array of support collateral coin name.
|
|
3010
|
+
* @param indexer - Whether to use indexer.
|
|
2670
3011
|
* @return Market collaterals data.
|
|
2671
3012
|
*/
|
|
2672
|
-
async getMarketCollaterals(collateralCoinNames) {
|
|
2673
|
-
return await getMarketCollaterals(this, collateralCoinNames);
|
|
3013
|
+
async getMarketCollaterals(collateralCoinNames, indexer = false) {
|
|
3014
|
+
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
2674
3015
|
}
|
|
2675
3016
|
/**
|
|
2676
3017
|
* Get market collateral
|
|
2677
3018
|
*
|
|
2678
3019
|
* @param collateralCoinName - Specific support collateral coin name.
|
|
3020
|
+
* @param indexer - Whether to use indexer.
|
|
2679
3021
|
* @return Market collateral data.
|
|
2680
3022
|
*/
|
|
2681
|
-
async getMarketCollateral(collateralCoinName) {
|
|
2682
|
-
return await getMarketCollateral(this, collateralCoinName);
|
|
3023
|
+
async getMarketCollateral(collateralCoinName, indexer = false) {
|
|
3024
|
+
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
2683
3025
|
}
|
|
2684
3026
|
/**
|
|
2685
3027
|
* Get obligations data.
|
|
@@ -2753,19 +3095,21 @@ var ScallopQuery = class {
|
|
|
2753
3095
|
* Get spools data.
|
|
2754
3096
|
*
|
|
2755
3097
|
* @param stakeMarketCoinNames - Specific an array of support stake market coin name.
|
|
3098
|
+
* @param indexer - Whether to use indexer.
|
|
2756
3099
|
* @return Spools data.
|
|
2757
3100
|
*/
|
|
2758
|
-
async getSpools(stakeMarketCoinNames) {
|
|
2759
|
-
return await getSpools(this, stakeMarketCoinNames);
|
|
3101
|
+
async getSpools(stakeMarketCoinNames, indexer = false) {
|
|
3102
|
+
return await getSpools(this, stakeMarketCoinNames, indexer);
|
|
2760
3103
|
}
|
|
2761
3104
|
/**
|
|
2762
3105
|
* Get spool data.
|
|
2763
3106
|
*
|
|
2764
3107
|
* @param stakeMarketCoinName - Specific support stake market coin name.
|
|
3108
|
+
* @param indexer - Whether to use indexer.
|
|
2765
3109
|
* @return Spool data.
|
|
2766
3110
|
*/
|
|
2767
|
-
async getSpool(stakeMarketCoinName) {
|
|
2768
|
-
return await getSpool(this, stakeMarketCoinName);
|
|
3111
|
+
async getSpool(stakeMarketCoinName, indexer = false) {
|
|
3112
|
+
return await getSpool(this, stakeMarketCoinName, indexer);
|
|
2769
3113
|
}
|
|
2770
3114
|
/**
|
|
2771
3115
|
* Get stake accounts data for all stake pools (spools).
|
|
@@ -2862,10 +3206,11 @@ var ScallopQuery = class {
|
|
|
2862
3206
|
* Get borrow incentive pools data.
|
|
2863
3207
|
*
|
|
2864
3208
|
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
3209
|
+
* @param indexer - Whether to use indexer.
|
|
2865
3210
|
* @return Borrow incentive pools data.
|
|
2866
3211
|
*/
|
|
2867
|
-
async getBorrowIncentivePools(coinNames) {
|
|
2868
|
-
return await queryBorrowIncentivePools(this, coinNames);
|
|
3212
|
+
async getBorrowIncentivePools(coinNames, indexer = false) {
|
|
3213
|
+
return await queryBorrowIncentivePools(this, coinNames, indexer);
|
|
2869
3214
|
}
|
|
2870
3215
|
/**
|
|
2871
3216
|
* Get borrow incentive accounts data.
|
|
@@ -2882,20 +3227,22 @@ var ScallopQuery = class {
|
|
|
2882
3227
|
*
|
|
2883
3228
|
* @param poolCoinNames - Specific an array of support pool coin name.
|
|
2884
3229
|
* @param ownerAddress - The owner address.
|
|
3230
|
+
* @param indexer - Whether to use indexer.
|
|
2885
3231
|
* @return All lending and spool infomation.
|
|
2886
3232
|
*/
|
|
2887
|
-
async getLendings(poolCoinNames, ownerAddress) {
|
|
2888
|
-
return await getLendings(this, poolCoinNames, ownerAddress);
|
|
3233
|
+
async getLendings(poolCoinNames, ownerAddress, indexer = false) {
|
|
3234
|
+
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
2889
3235
|
}
|
|
2890
3236
|
/**
|
|
2891
3237
|
* Get user lending and spool information for specific pool.
|
|
2892
3238
|
*
|
|
2893
3239
|
* @param poolCoinName - Specific support pool coin name.
|
|
2894
3240
|
* @param ownerAddress - The owner address.
|
|
3241
|
+
* @param indexer - Whether to use indexer.
|
|
2895
3242
|
* @return Lending pool data.
|
|
2896
3243
|
*/
|
|
2897
|
-
async getLending(poolCoinName, ownerAddress) {
|
|
2898
|
-
return await getLending(this, poolCoinName, ownerAddress);
|
|
3244
|
+
async getLending(poolCoinName, ownerAddress, indexer = false) {
|
|
3245
|
+
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
2899
3246
|
}
|
|
2900
3247
|
/**
|
|
2901
3248
|
* Get user all obligation accounts information.
|
|
@@ -2904,10 +3251,11 @@ var ScallopQuery = class {
|
|
|
2904
3251
|
* All collateral and borrowing information in all obligation accounts owned by the user.
|
|
2905
3252
|
*
|
|
2906
3253
|
* @param ownerAddress - The owner address.
|
|
3254
|
+
* @param indexer - Whether to use indexer.
|
|
2907
3255
|
* @return All obligation accounts information.
|
|
2908
3256
|
*/
|
|
2909
|
-
async getObligationAccounts(ownerAddress) {
|
|
2910
|
-
return await getObligationAccounts(this, ownerAddress);
|
|
3257
|
+
async getObligationAccounts(ownerAddress, indexer = false) {
|
|
3258
|
+
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
2911
3259
|
}
|
|
2912
3260
|
/**
|
|
2913
3261
|
* Get obligation account information for specific id.
|
|
@@ -2917,21 +3265,28 @@ var ScallopQuery = class {
|
|
|
2917
3265
|
*
|
|
2918
3266
|
* @param obligationId - The obligation id.
|
|
2919
3267
|
* @param ownerAddress - The owner address.
|
|
3268
|
+
* @param indexer - Whether to use indexer.
|
|
2920
3269
|
* @return Borrowing and collateral information.
|
|
2921
3270
|
*/
|
|
2922
|
-
async getObligationAccount(obligationId, ownerAddress) {
|
|
2923
|
-
return await getObligationAccount(
|
|
3271
|
+
async getObligationAccount(obligationId, ownerAddress, indexer = false) {
|
|
3272
|
+
return await getObligationAccount(
|
|
3273
|
+
this,
|
|
3274
|
+
obligationId,
|
|
3275
|
+
ownerAddress,
|
|
3276
|
+
indexer
|
|
3277
|
+
);
|
|
2924
3278
|
}
|
|
2925
3279
|
/**
|
|
2926
3280
|
* Get total value locked.
|
|
2927
3281
|
*
|
|
3282
|
+
* @param indexer - Whether to use indexer.
|
|
2928
3283
|
* @description
|
|
2929
3284
|
* Include total supplied value and total borrowed value.
|
|
2930
3285
|
*
|
|
2931
3286
|
* @return Total value locked.
|
|
2932
3287
|
*/
|
|
2933
|
-
async getTvl() {
|
|
2934
|
-
return await getTotalValueLocked(this);
|
|
3288
|
+
async getTvl(indexer = false) {
|
|
3289
|
+
return await getTotalValueLocked(this, indexer);
|
|
2935
3290
|
}
|
|
2936
3291
|
};
|
|
2937
3292
|
|
|
@@ -4414,6 +4769,14 @@ var ScallopClient = class {
|
|
|
4414
4769
|
const txBlock = this.builder.createTxBlock();
|
|
4415
4770
|
const sender = walletAddress || this.walletAddress;
|
|
4416
4771
|
txBlock.setSender(sender);
|
|
4772
|
+
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
4773
|
+
if (sign && availableStake) {
|
|
4774
|
+
await txBlock.unstakeObligationQuick(
|
|
4775
|
+
poolCoinName,
|
|
4776
|
+
obligationId,
|
|
4777
|
+
obligationKey
|
|
4778
|
+
);
|
|
4779
|
+
}
|
|
4417
4780
|
const coin = await txBlock.borrowQuick(
|
|
4418
4781
|
amount,
|
|
4419
4782
|
poolCoinName,
|
|
@@ -4421,6 +4784,13 @@ var ScallopClient = class {
|
|
|
4421
4784
|
obligationKey
|
|
4422
4785
|
);
|
|
4423
4786
|
txBlock.transferObjects([coin], sender);
|
|
4787
|
+
if (sign && availableStake) {
|
|
4788
|
+
await txBlock.stakeObligationQuick(
|
|
4789
|
+
poolCoinName,
|
|
4790
|
+
obligationId,
|
|
4791
|
+
obligationKey
|
|
4792
|
+
);
|
|
4793
|
+
}
|
|
4424
4794
|
if (sign) {
|
|
4425
4795
|
return await this.suiKit.signAndSendTxn(
|
|
4426
4796
|
txBlock
|
|
@@ -4439,11 +4809,26 @@ var ScallopClient = class {
|
|
|
4439
4809
|
* @param walletAddress - The wallet address of the owner.
|
|
4440
4810
|
* @return Transaction block response or transaction block.
|
|
4441
4811
|
*/
|
|
4442
|
-
async repay(poolCoinName, amount, sign = true, obligationId, walletAddress) {
|
|
4812
|
+
async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
4443
4813
|
const txBlock = this.builder.createTxBlock();
|
|
4444
4814
|
const sender = walletAddress || this.walletAddress;
|
|
4445
4815
|
txBlock.setSender(sender);
|
|
4816
|
+
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
4817
|
+
if (sign && availableStake) {
|
|
4818
|
+
await txBlock.unstakeObligationQuick(
|
|
4819
|
+
poolCoinName,
|
|
4820
|
+
obligationId,
|
|
4821
|
+
obligationKey
|
|
4822
|
+
);
|
|
4823
|
+
}
|
|
4446
4824
|
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
4825
|
+
if (sign && availableStake) {
|
|
4826
|
+
await txBlock.stakeObligationQuick(
|
|
4827
|
+
poolCoinName,
|
|
4828
|
+
obligationId,
|
|
4829
|
+
obligationKey
|
|
4830
|
+
);
|
|
4831
|
+
}
|
|
4447
4832
|
if (sign) {
|
|
4448
4833
|
return await this.suiKit.signAndSendTxn(
|
|
4449
4834
|
txBlock
|
|
@@ -4718,6 +5103,15 @@ var Scallop = class {
|
|
|
4718
5103
|
});
|
|
4719
5104
|
return scallopQuery;
|
|
4720
5105
|
}
|
|
5106
|
+
/**
|
|
5107
|
+
* Create a scallop indexer instance.
|
|
5108
|
+
*
|
|
5109
|
+
* @return Scallop Indexer.
|
|
5110
|
+
*/
|
|
5111
|
+
async createScallopIndexer() {
|
|
5112
|
+
const scallopIndexer = new ScallopIndexer();
|
|
5113
|
+
return scallopIndexer;
|
|
5114
|
+
}
|
|
4721
5115
|
/**
|
|
4722
5116
|
* Create a scallop utils instance.
|
|
4723
5117
|
*
|
|
@@ -4739,6 +5133,7 @@ var Scallop = class {
|
|
|
4739
5133
|
API_BASE_URL,
|
|
4740
5134
|
BORROW_FEE_PROTOCOL_ID,
|
|
4741
5135
|
PROTOCOL_OBJECT_ID,
|
|
5136
|
+
SDK_API_BASE_URL,
|
|
4742
5137
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4743
5138
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4744
5139
|
SUPPORT_COLLATERALS,
|
|
@@ -4751,6 +5146,7 @@ var Scallop = class {
|
|
|
4751
5146
|
ScallopAddress,
|
|
4752
5147
|
ScallopBuilder,
|
|
4753
5148
|
ScallopClient,
|
|
5149
|
+
ScallopIndexer,
|
|
4754
5150
|
ScallopQuery,
|
|
4755
5151
|
ScallopUtils,
|
|
4756
5152
|
assetCoins,
|