@scallop-io/sui-scallop-sdk 1.3.5-rc.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/common.d.ts +1 -1
- package/dist/constants/enum.d.ts +1 -1
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +299 -340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -339
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +35 -57
- package/dist/models/scallopUtils.d.ts +10 -10
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +2 -36
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +6 -2
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +13 -2
- package/src/constants/common.ts +2 -4
- package/src/constants/enum.ts +16 -11
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopClient.ts +10 -27
- package/src/models/scallopQuery.ts +38 -44
- package/src/models/scallopUtils.ts +18 -23
- package/src/queries/borrowIncentiveQuery.ts +12 -29
- package/src/queries/coreQuery.ts +191 -191
- package/src/queries/portfolioQuery.ts +78 -80
- package/src/queries/priceQuery.ts +2 -36
- package/src/queries/sCoinQuery.ts +3 -3
- package/src/queries/spoolQuery.ts +6 -4
- package/src/types/builder/borrowIncentive.ts +15 -10
- package/src/types/constant/common.ts +2 -1
- package/src/types/utils.ts +10 -2
- package/src/utils/indexer.ts +9 -3
- package/src/utils/query.ts +87 -0
- package/src/utils/tokenBucket.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -126,10 +126,7 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
126
126
|
"sca",
|
|
127
127
|
"usdc"
|
|
128
128
|
];
|
|
129
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
130
|
-
...SUPPORT_POOLS,
|
|
131
|
-
...SUPPORT_SCOIN
|
|
132
|
-
];
|
|
129
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui", "sca"];
|
|
133
130
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
134
131
|
var SUPPORT_PACKAGES = [
|
|
135
132
|
"coinDecimalsRegistry",
|
|
@@ -259,6 +256,18 @@ var spoolRewardCoins = {
|
|
|
259
256
|
var suiBridgeCoins = {
|
|
260
257
|
sbeth: "sbeth"
|
|
261
258
|
};
|
|
259
|
+
var borrowIncentiveRewardCoins = {
|
|
260
|
+
usdc: ["sui", "sca"],
|
|
261
|
+
sui: ["sui", "sca"],
|
|
262
|
+
wusdc: ["sui", "sca"],
|
|
263
|
+
wusdt: ["sui", "sca"],
|
|
264
|
+
sca: ["sui", "sca"],
|
|
265
|
+
afsui: ["sui"],
|
|
266
|
+
hasui: ["sui"],
|
|
267
|
+
vsui: ["sui"],
|
|
268
|
+
weth: ["sui"],
|
|
269
|
+
sbeth: ["sui"]
|
|
270
|
+
};
|
|
262
271
|
var coinIds = {
|
|
263
272
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
264
273
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -293,10 +302,10 @@ var sCoinIds = {
|
|
|
293
302
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
294
303
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
295
304
|
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
305
|
+
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
306
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
296
307
|
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
297
308
|
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
298
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
299
|
-
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
300
309
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
301
310
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
302
311
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
@@ -313,13 +322,6 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
313
322
|
},
|
|
314
323
|
{}
|
|
315
324
|
);
|
|
316
|
-
var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
317
|
-
(acc, [coinName, coinType]) => {
|
|
318
|
-
acc[coinType.split("::")[2].toLowerCase()] = coinName;
|
|
319
|
-
return acc;
|
|
320
|
-
},
|
|
321
|
-
{}
|
|
322
|
-
);
|
|
323
325
|
|
|
324
326
|
// src/constants/flashloan.ts
|
|
325
327
|
var FlashLoanFeeObjectMap = {
|
|
@@ -950,7 +952,7 @@ var TEST_ADDRESSES = {
|
|
|
950
952
|
|
|
951
953
|
// src/constants/tokenBucket.ts
|
|
952
954
|
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
953
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
955
|
+
var DEFAULT_INTERVAL_IN_MS = 100;
|
|
954
956
|
|
|
955
957
|
// src/constants/vesca.ts
|
|
956
958
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1554,7 +1556,7 @@ var TokenBucket = class {
|
|
|
1554
1556
|
return false;
|
|
1555
1557
|
}
|
|
1556
1558
|
};
|
|
1557
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1559
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
|
|
1558
1560
|
let retries = 0;
|
|
1559
1561
|
const tryRequest = async () => {
|
|
1560
1562
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1590,13 +1592,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1590
1592
|
|
|
1591
1593
|
// src/utils/indexer.ts
|
|
1592
1594
|
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1593
|
-
const
|
|
1594
|
-
if (indexer) {
|
|
1595
|
+
const lastArgs = args[args.length - 1];
|
|
1596
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1595
1597
|
try {
|
|
1596
1598
|
return await method.apply(context, args);
|
|
1597
1599
|
} catch (e) {
|
|
1598
1600
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1599
|
-
return await method.apply(context, [
|
|
1601
|
+
return await method.apply(context, [
|
|
1602
|
+
...args.slice(0, -1),
|
|
1603
|
+
{
|
|
1604
|
+
...lastArgs,
|
|
1605
|
+
indexer: false
|
|
1606
|
+
}
|
|
1607
|
+
]);
|
|
1600
1608
|
}
|
|
1601
1609
|
}
|
|
1602
1610
|
return await method.apply(context, args);
|
|
@@ -2464,21 +2472,15 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
2464
2472
|
};
|
|
2465
2473
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2466
2474
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2467
|
-
], indexer = false,
|
|
2475
|
+
], indexer = false, coinPrices) => {
|
|
2468
2476
|
const borrowIncentivePools = {};
|
|
2469
|
-
|
|
2470
|
-
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2477
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2471
2478
|
if (indexer) {
|
|
2472
2479
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2473
2480
|
const updateBorrowIncentivePool = (pool) => {
|
|
2474
2481
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2475
2482
|
return;
|
|
2476
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
2477
|
-
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2478
|
-
if (pool.points[sCoinName]) {
|
|
2479
|
-
pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2483
|
+
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
2482
2484
|
borrowIncentivePools[pool.coinName] = pool;
|
|
2483
2485
|
};
|
|
2484
2486
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -2504,15 +2506,12 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2504
2506
|
for (const [coinName, poolPoint] of Object.entries(
|
|
2505
2507
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2506
2508
|
)) {
|
|
2507
|
-
const rewardCoinType = poolPoint.pointType;
|
|
2508
|
-
|
|
2509
|
+
const rewardCoinType = normalizeStructTag3(poolPoint.pointType);
|
|
2510
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2509
2511
|
rewardCoinType
|
|
2510
2512
|
);
|
|
2511
|
-
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2512
|
-
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2513
|
-
}
|
|
2514
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2515
2513
|
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2514
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2516
2515
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2517
2516
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2518
2517
|
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
@@ -2945,7 +2944,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2945
2944
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
2946
2945
|
showContent: true
|
|
2947
2946
|
});
|
|
2948
|
-
coinPrices =
|
|
2947
|
+
coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
|
|
2949
2948
|
const marketPools = {};
|
|
2950
2949
|
if (indexer) {
|
|
2951
2950
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
@@ -2978,154 +2977,150 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2978
2977
|
return marketPools;
|
|
2979
2978
|
};
|
|
2980
2979
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2980
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2981
|
+
if (indexer) {
|
|
2982
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
2983
|
+
if (!marketPoolIndexer) {
|
|
2984
|
+
return void 0;
|
|
2985
|
+
}
|
|
2986
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2987
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2988
|
+
marketPoolIndexer.coinName
|
|
2989
|
+
);
|
|
2990
|
+
return marketPoolIndexer;
|
|
2991
|
+
}
|
|
2992
|
+
const marketId = query.address.get("core.market");
|
|
2993
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2994
|
+
showContent: true
|
|
2995
|
+
}))?.data;
|
|
2996
|
+
if (!(marketObject && marketObject.content?.dataType === "moveObject"))
|
|
2997
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
2998
|
+
const fields = marketObject.content.fields;
|
|
2999
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
3000
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
3001
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3002
|
+
parentId: balanceSheetParentId,
|
|
3003
|
+
name: {
|
|
3004
|
+
type: "0x1::type_name::TypeName",
|
|
3005
|
+
value: {
|
|
3006
|
+
name: coinType.substring(2)
|
|
2987
3007
|
}
|
|
2988
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2989
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2990
|
-
marketPoolIndexer.coinName
|
|
2991
|
-
);
|
|
2992
|
-
return marketPoolIndexer;
|
|
2993
3008
|
}
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
name: coinType.substring(2)
|
|
3009
|
-
}
|
|
3009
|
+
});
|
|
3010
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
|
|
3011
|
+
if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
|
|
3012
|
+
throw new Error(
|
|
3013
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
3014
|
+
);
|
|
3015
|
+
const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
|
|
3016
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
3017
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3018
|
+
parentId: borrowIndexParentId,
|
|
3019
|
+
name: {
|
|
3020
|
+
type: "0x1::type_name::TypeName",
|
|
3021
|
+
value: {
|
|
3022
|
+
name: coinType.substring(2)
|
|
3010
3023
|
}
|
|
3011
|
-
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
|
|
3027
|
+
if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
|
|
3028
|
+
throw new Error(
|
|
3029
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
3030
|
+
);
|
|
3031
|
+
const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
|
|
3032
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
3033
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3034
|
+
parentId: interestModelParentId,
|
|
3035
|
+
name: {
|
|
3036
|
+
type: "0x1::type_name::TypeName",
|
|
3037
|
+
value: {
|
|
3038
|
+
name: coinType.substring(2)
|
|
3026
3039
|
}
|
|
3027
|
-
}
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3040
|
+
}
|
|
3041
|
+
});
|
|
3042
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3043
|
+
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3044
|
+
throw new Error(
|
|
3045
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3046
|
+
);
|
|
3047
|
+
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3048
|
+
const getBorrowFee = async () => {
|
|
3049
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3050
|
+
parentId: marketId,
|
|
3037
3051
|
name: {
|
|
3038
|
-
type:
|
|
3052
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3039
3053
|
value: {
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
}
|
|
3043
|
-
});
|
|
3044
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3045
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3046
|
-
throw new Error(
|
|
3047
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3048
|
-
);
|
|
3049
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3050
|
-
const getBorrowFee = async () => {
|
|
3051
|
-
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3052
|
-
parentId: marketId,
|
|
3053
|
-
name: {
|
|
3054
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3055
|
-
value: {
|
|
3056
|
-
type: {
|
|
3057
|
-
name: coinType.substring(2)
|
|
3058
|
-
}
|
|
3054
|
+
type: {
|
|
3055
|
+
name: coinType.substring(2)
|
|
3059
3056
|
}
|
|
3060
3057
|
}
|
|
3061
|
-
}
|
|
3062
|
-
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3063
|
-
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3064
|
-
return { value: "0" };
|
|
3065
|
-
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3066
|
-
};
|
|
3067
|
-
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3068
|
-
type: interestModel.type.fields,
|
|
3069
|
-
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3070
|
-
interestRate: borrowIndex.interest_rate.fields,
|
|
3071
|
-
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3072
|
-
borrowIndex: borrowIndex.borrow_index,
|
|
3073
|
-
lastUpdated: borrowIndex.last_updated,
|
|
3074
|
-
cash: balanceSheet.cash,
|
|
3075
|
-
debt: balanceSheet.debt,
|
|
3076
|
-
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3077
|
-
reserve: balanceSheet.revenue,
|
|
3078
|
-
reserveFactor: interestModel.revenue_factor.fields,
|
|
3079
|
-
borrowWeight: interestModel.borrow_weight.fields,
|
|
3080
|
-
borrowFeeRate: await getBorrowFee(),
|
|
3081
|
-
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3082
|
-
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3083
|
-
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3084
|
-
highKink: interestModel.high_kink.fields,
|
|
3085
|
-
midKink: interestModel.mid_kink.fields,
|
|
3086
|
-
minBorrowAmount: interestModel.min_borrow_amount
|
|
3058
|
+
}
|
|
3087
3059
|
});
|
|
3088
|
-
const
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3060
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3061
|
+
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3062
|
+
return { value: "0" };
|
|
3063
|
+
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3064
|
+
};
|
|
3065
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3066
|
+
type: interestModel.type.fields,
|
|
3067
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3068
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
3069
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3070
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
3071
|
+
lastUpdated: borrowIndex.last_updated,
|
|
3072
|
+
cash: balanceSheet.cash,
|
|
3073
|
+
debt: balanceSheet.debt,
|
|
3074
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3075
|
+
reserve: balanceSheet.revenue,
|
|
3076
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
3077
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
3078
|
+
borrowFeeRate: await getBorrowFee(),
|
|
3079
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3080
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3081
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3082
|
+
highKink: interestModel.high_kink.fields,
|
|
3083
|
+
midKink: interestModel.mid_kink.fields,
|
|
3084
|
+
minBorrowAmount: interestModel.min_borrow_amount
|
|
3085
|
+
});
|
|
3086
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
3087
|
+
query.utils,
|
|
3088
|
+
parsedMarketPoolData
|
|
3089
|
+
);
|
|
3090
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3091
|
+
const maxSupplyCoin = BigNumber3(
|
|
3092
|
+
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
3093
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3094
|
+
const maxBorrowCoin = BigNumber3(
|
|
3095
|
+
await getBorrowLimit(query.utils, poolCoinName) ?? "0"
|
|
3096
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3097
|
+
return {
|
|
3098
|
+
coinName: poolCoinName,
|
|
3099
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3100
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3101
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3102
|
+
sCoinType: query.utils.parseSCoinType(
|
|
3103
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
3104
|
+
),
|
|
3105
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
3106
|
+
coinDecimal,
|
|
3107
|
+
coinPrice: coinPrice ?? 0,
|
|
3108
|
+
highKink: parsedMarketPoolData.highKink,
|
|
3109
|
+
midKink: parsedMarketPoolData.midKink,
|
|
3110
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
3111
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
3112
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
3113
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
3114
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
3115
|
+
maxSupplyCoin,
|
|
3116
|
+
maxBorrowCoin,
|
|
3117
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
3118
|
+
...calculatedMarketPoolData
|
|
3119
|
+
};
|
|
3125
3120
|
};
|
|
3126
3121
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3127
3122
|
const marketId = query.address.get("core.market");
|
|
3128
|
-
const coinPrices = await query.utils.getCoinPrices() ?? {};
|
|
3123
|
+
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
|
|
3129
3124
|
const marketCollaterals = {};
|
|
3130
3125
|
if (indexer) {
|
|
3131
3126
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -3161,7 +3156,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
3161
3156
|
return marketCollaterals;
|
|
3162
3157
|
};
|
|
3163
3158
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3164
|
-
coinPrice = coinPrice
|
|
3159
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
3165
3160
|
if (indexer) {
|
|
3166
3161
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
3167
3162
|
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
@@ -3477,11 +3472,13 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3477
3472
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3478
3473
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3479
3474
|
);
|
|
3480
|
-
const coinPrices = await query.utils.getCoinPrices();
|
|
3481
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
3475
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3476
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3477
|
+
indexer,
|
|
3482
3478
|
coinPrices
|
|
3483
3479
|
});
|
|
3484
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
3480
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
3481
|
+
indexer,
|
|
3485
3482
|
marketPools,
|
|
3486
3483
|
coinPrices
|
|
3487
3484
|
});
|
|
@@ -3515,22 +3512,20 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3515
3512
|
};
|
|
3516
3513
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3517
3514
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3518
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
3519
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName,
|
|
3515
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3516
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3517
|
+
indexer,
|
|
3520
3518
|
coinPrice
|
|
3521
3519
|
});
|
|
3522
3520
|
if (!marketPool)
|
|
3523
3521
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3524
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3525
|
-
marketCoinName,
|
|
3522
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
|
|
3526
3523
|
indexer,
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
[poolCoinName]: coinPrice
|
|
3531
|
-
}
|
|
3524
|
+
marketPool,
|
|
3525
|
+
coinPrices: {
|
|
3526
|
+
[poolCoinName]: coinPrice
|
|
3532
3527
|
}
|
|
3533
|
-
) : void 0;
|
|
3528
|
+
}) : void 0;
|
|
3534
3529
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3535
3530
|
marketCoinName,
|
|
3536
3531
|
ownerAddress
|
|
@@ -3650,7 +3645,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3650
3645
|
};
|
|
3651
3646
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3652
3647
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3653
|
-
const market = await query.queryMarket(indexer,
|
|
3648
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
3654
3649
|
const [coinAmounts, obligations] = await Promise.all([
|
|
3655
3650
|
query.getCoinAmounts(void 0, ownerAddress),
|
|
3656
3651
|
query.getObligations(ownerAddress)
|
|
@@ -3675,13 +3670,14 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3675
3670
|
const collateralAssetCoinNames = [
|
|
3676
3671
|
...SUPPORT_COLLATERALS
|
|
3677
3672
|
];
|
|
3678
|
-
|
|
3679
|
-
|
|
3673
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3674
|
+
market = market ?? await query.queryMarket({ indexer, coinPrices });
|
|
3680
3675
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3681
3676
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3682
3677
|
query.queryObligation(obligationId),
|
|
3683
|
-
query.getBorrowIncentivePools(void 0,
|
|
3684
|
-
coinPrices
|
|
3678
|
+
query.getBorrowIncentivePools(void 0, {
|
|
3679
|
+
coinPrices,
|
|
3680
|
+
indexer
|
|
3685
3681
|
}),
|
|
3686
3682
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3687
3683
|
]);
|
|
@@ -3817,47 +3813,44 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3817
3813
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3818
3814
|
if (borrowIncentivePool) {
|
|
3819
3815
|
const rewards = [];
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
)
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
boostValue
|
|
3856
|
-
});
|
|
3857
|
-
}
|
|
3816
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
3817
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
3818
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
3819
|
+
if (accountPoint && poolPoint) {
|
|
3820
|
+
let availableClaimAmount = BigNumber5(0);
|
|
3821
|
+
let availableClaimCoin = BigNumber5(0);
|
|
3822
|
+
const accountBorrowedAmount = BigNumber5(accountPoint.weightedAmount);
|
|
3823
|
+
const baseIndexRate = 1e9;
|
|
3824
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3825
|
+
BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3826
|
+
0
|
|
3827
|
+
) : 1;
|
|
3828
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3829
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3830
|
+
);
|
|
3831
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3832
|
+
-1 * poolPoint.coinDecimal
|
|
3833
|
+
);
|
|
3834
|
+
const weightScale = BigNumber5(1e12);
|
|
3835
|
+
const boostValue = BigNumber5(accountPoint.weightedAmount).div(
|
|
3836
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3837
|
+
).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
|
|
3838
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3839
|
+
).toNumber() : 1;
|
|
3840
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3841
|
+
rewards.push({
|
|
3842
|
+
coinName: poolPoint.coinName,
|
|
3843
|
+
coinType: poolPoint.coinType,
|
|
3844
|
+
symbol: poolPoint.symbol,
|
|
3845
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3846
|
+
coinPrice: poolPoint.coinPrice,
|
|
3847
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3848
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3849
|
+
boostValue
|
|
3850
|
+
});
|
|
3858
3851
|
}
|
|
3859
3852
|
}
|
|
3860
|
-
|
|
3853
|
+
}
|
|
3861
3854
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3862
3855
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3863
3856
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -3964,7 +3957,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3964
3957
|
return obligationAccount;
|
|
3965
3958
|
};
|
|
3966
3959
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
3967
|
-
const market = await query.queryMarket(indexer);
|
|
3960
|
+
const market = await query.queryMarket({ indexer });
|
|
3968
3961
|
let supplyValue = BigNumber5(0);
|
|
3969
3962
|
let borrowValue = BigNumber5(0);
|
|
3970
3963
|
if (indexer) {
|
|
@@ -4001,7 +3994,6 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4001
3994
|
};
|
|
4002
3995
|
|
|
4003
3996
|
// src/queries/priceQuery.ts
|
|
4004
|
-
import BigNumber6 from "bignumber.js";
|
|
4005
3997
|
var getPythPrice = async ({
|
|
4006
3998
|
address
|
|
4007
3999
|
}, assetCoinName, priceFeedObject) => {
|
|
@@ -4083,22 +4075,6 @@ var getPythPrices = async ({
|
|
|
4083
4075
|
{}
|
|
4084
4076
|
);
|
|
4085
4077
|
};
|
|
4086
|
-
var getAllCoinPrices = async (query, marketPools, coinPrices) => {
|
|
4087
|
-
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4088
|
-
marketPools = marketPools ?? await query.getMarketPools(void 0, void 0, { coinPrices });
|
|
4089
|
-
if (!marketPools) {
|
|
4090
|
-
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
4091
|
-
}
|
|
4092
|
-
const sCoinPrices = {};
|
|
4093
|
-
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
4094
|
-
const coinName = query.utils.parseCoinName(sCoinName);
|
|
4095
|
-
sCoinPrices[sCoinName] = BigNumber6(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
|
|
4096
|
-
});
|
|
4097
|
-
return {
|
|
4098
|
-
...coinPrices,
|
|
4099
|
-
...sCoinPrices
|
|
4100
|
-
};
|
|
4101
|
-
};
|
|
4102
4078
|
|
|
4103
4079
|
// src/queries/referralQuery.ts
|
|
4104
4080
|
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
@@ -4119,7 +4095,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4119
4095
|
// src/queries/sCoinQuery.ts
|
|
4120
4096
|
import { bcs } from "@mysten/sui/bcs";
|
|
4121
4097
|
import assert from "assert";
|
|
4122
|
-
import
|
|
4098
|
+
import BigNumber6 from "bignumber.js";
|
|
4123
4099
|
var getSCoinTotalSupply = async ({
|
|
4124
4100
|
utils
|
|
4125
4101
|
}, sCoinName) => {
|
|
@@ -4140,7 +4116,7 @@ var getSCoinTotalSupply = async ({
|
|
|
4140
4116
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4141
4117
|
const type = results[0].returnValues[0][1];
|
|
4142
4118
|
assert(type === "u64", "Result type is not u64");
|
|
4143
|
-
return
|
|
4119
|
+
return BigNumber6(bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4144
4120
|
}
|
|
4145
4121
|
return 0;
|
|
4146
4122
|
};
|
|
@@ -4166,7 +4142,7 @@ var getSCoinAmount = async ({
|
|
|
4166
4142
|
owner,
|
|
4167
4143
|
coinType: sCoinType
|
|
4168
4144
|
});
|
|
4169
|
-
return
|
|
4145
|
+
return BigNumber6(amount).toNumber();
|
|
4170
4146
|
};
|
|
4171
4147
|
var isSupportStakeCoins = (value) => {
|
|
4172
4148
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4185,8 +4161,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4185
4161
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4186
4162
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4187
4163
|
const marketPools = await Promise.all([
|
|
4188
|
-
query.getMarketPool(fromCoinName
|
|
4189
|
-
query.getMarketPool(toCoinName
|
|
4164
|
+
query.getMarketPool(fromCoinName),
|
|
4165
|
+
query.getMarketPool(toCoinName)
|
|
4190
4166
|
]);
|
|
4191
4167
|
if (marketPools.some((pool) => !pool))
|
|
4192
4168
|
throw new Error("Failed to fetch the lendings data");
|
|
@@ -4196,7 +4172,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4196
4172
|
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4197
4173
|
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4198
4174
|
const calcAtoBRate = async () => {
|
|
4199
|
-
const prices = await query.utils.getCoinPrices();
|
|
4175
|
+
const prices = await query.utils.getCoinPrices([fromCoinName, toCoinName]);
|
|
4200
4176
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4201
4177
|
throw new Error("Failed to fetch the coin prices");
|
|
4202
4178
|
}
|
|
@@ -4206,7 +4182,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4206
4182
|
return prices[fromCoinName] / prices[toCoinName];
|
|
4207
4183
|
};
|
|
4208
4184
|
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4209
|
-
return
|
|
4185
|
+
return BigNumber6(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4210
4186
|
};
|
|
4211
4187
|
|
|
4212
4188
|
// src/queries/spoolQuery.ts
|
|
@@ -4216,7 +4192,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4216
4192
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4217
4193
|
);
|
|
4218
4194
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4219
|
-
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4195
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
|
|
4220
4196
|
if (!marketPools)
|
|
4221
4197
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4222
4198
|
const spools = {};
|
|
@@ -4257,7 +4233,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4257
4233
|
};
|
|
4258
4234
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4259
4235
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4260
|
-
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4236
|
+
marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
|
|
4261
4237
|
if (!marketPool) {
|
|
4262
4238
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4263
4239
|
}
|
|
@@ -4266,7 +4242,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4266
4242
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4267
4243
|
);
|
|
4268
4244
|
let spool = void 0;
|
|
4269
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4245
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
|
|
4270
4246
|
if (indexer) {
|
|
4271
4247
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4272
4248
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
@@ -4286,7 +4262,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4286
4262
|
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4287
4263
|
}
|
|
4288
4264
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4289
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4265
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
4290
4266
|
const spoolObject = spoolObjectResponse[0];
|
|
4291
4267
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
4292
4268
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
@@ -4530,7 +4506,7 @@ var getStakeRewardPool = async ({
|
|
|
4530
4506
|
};
|
|
4531
4507
|
|
|
4532
4508
|
// src/queries/vescaQuery.ts
|
|
4533
|
-
import
|
|
4509
|
+
import BigNumber7 from "bignumber.js";
|
|
4534
4510
|
import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
|
|
4535
4511
|
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
4536
4512
|
import { z as zod5 } from "zod";
|
|
@@ -4612,7 +4588,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4612
4588
|
0
|
|
4613
4589
|
);
|
|
4614
4590
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4615
|
-
const lockedScaCoin =
|
|
4591
|
+
const lockedScaCoin = BigNumber7(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4616
4592
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4617
4593
|
vesca = {
|
|
4618
4594
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4622,7 +4598,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4622
4598
|
lockedScaAmount,
|
|
4623
4599
|
lockedScaCoin,
|
|
4624
4600
|
currentVeScaBalance,
|
|
4625
|
-
unlockAt:
|
|
4601
|
+
unlockAt: BigNumber7(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4626
4602
|
};
|
|
4627
4603
|
}
|
|
4628
4604
|
return vesca;
|
|
@@ -4684,10 +4660,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4684
4660
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4685
4661
|
return null;
|
|
4686
4662
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4687
|
-
const totalLockedSca =
|
|
4663
|
+
const totalLockedSca = BigNumber7(
|
|
4688
4664
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4689
4665
|
).shiftedBy(-9).toNumber();
|
|
4690
|
-
const totalVeSca =
|
|
4666
|
+
const totalVeSca = BigNumber7(
|
|
4691
4667
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4692
4668
|
).shiftedBy(-9).toNumber();
|
|
4693
4669
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4723,6 +4699,15 @@ var ScallopUtils = class {
|
|
|
4723
4699
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4724
4700
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4725
4701
|
};
|
|
4702
|
+
/**
|
|
4703
|
+
* Get reward type of borrow incentive pool.
|
|
4704
|
+
*
|
|
4705
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4706
|
+
* @return Borrow incentive reward coin name.
|
|
4707
|
+
*/
|
|
4708
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4709
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4710
|
+
};
|
|
4726
4711
|
this.params = {
|
|
4727
4712
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4728
4713
|
...params
|
|
@@ -4792,10 +4777,7 @@ var ScallopUtils = class {
|
|
|
4792
4777
|
* @param coinName - Specific support coin name.
|
|
4793
4778
|
* @return Coin type.
|
|
4794
4779
|
*/
|
|
4795
|
-
parseCoinType(coinName
|
|
4796
|
-
if (sCoinIds[coinName] && !useOldMarketCoin) {
|
|
4797
|
-
return sCoinIds[coinName];
|
|
4798
|
-
}
|
|
4780
|
+
parseCoinType(coinName) {
|
|
4799
4781
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4800
4782
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4801
4783
|
if (!coinPackageId) {
|
|
@@ -4850,15 +4832,6 @@ var ScallopUtils = class {
|
|
|
4850
4832
|
return void 0;
|
|
4851
4833
|
}
|
|
4852
4834
|
}
|
|
4853
|
-
/**
|
|
4854
|
-
* Convert sCoin name to coin name.
|
|
4855
|
-
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4856
|
-
* e.g: `scallop_sui -> ssui
|
|
4857
|
-
* @return sCoin name
|
|
4858
|
-
*/
|
|
4859
|
-
parseCoinNameFromSCoinName(coinName) {
|
|
4860
|
-
return sCoinRawNameToName[coinName];
|
|
4861
|
-
}
|
|
4862
4835
|
/**
|
|
4863
4836
|
* Convert sCoin name into sCoin type
|
|
4864
4837
|
* @param sCoinName
|
|
@@ -4901,7 +4874,7 @@ var ScallopUtils = class {
|
|
|
4901
4874
|
*/
|
|
4902
4875
|
parseMarketCoinType(coinName) {
|
|
4903
4876
|
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4904
|
-
const coinType = this.parseCoinType(coinName
|
|
4877
|
+
const coinType = this.parseCoinType(coinName);
|
|
4905
4878
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4906
4879
|
}
|
|
4907
4880
|
parseCoinNameFromType(coinType) {
|
|
@@ -4910,7 +4883,7 @@ var ScallopUtils = class {
|
|
|
4910
4883
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4911
4884
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4912
4885
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4913
|
-
const
|
|
4886
|
+
const wormHoleCoinTypeMap = {
|
|
4914
4887
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4915
4888
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
4916
4889
|
[`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
|
|
@@ -4930,7 +4903,7 @@ var ScallopUtils = class {
|
|
|
4930
4903
|
},
|
|
4931
4904
|
{}
|
|
4932
4905
|
);
|
|
4933
|
-
const assetCoinName =
|
|
4906
|
+
const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
4934
4907
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
4935
4908
|
}
|
|
4936
4909
|
/**
|
|
@@ -6044,7 +6017,11 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6044
6017
|
]
|
|
6045
6018
|
);
|
|
6046
6019
|
},
|
|
6047
|
-
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6020
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
6021
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6022
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6023
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6024
|
+
}
|
|
6048
6025
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6049
6026
|
return txBlock.moveCall(
|
|
6050
6027
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6137,7 +6114,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6137
6114
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6138
6115
|
}
|
|
6139
6116
|
},
|
|
6140
|
-
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6117
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
6141
6118
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6142
6119
|
builder,
|
|
6143
6120
|
txBlock,
|
|
@@ -6147,6 +6124,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6147
6124
|
return txBlock.claimBorrowIncentive(
|
|
6148
6125
|
obligationArg,
|
|
6149
6126
|
obligationKeyArg,
|
|
6127
|
+
coinName,
|
|
6150
6128
|
rewardCoinName
|
|
6151
6129
|
);
|
|
6152
6130
|
}
|
|
@@ -7050,8 +7028,8 @@ var ScallopQuery = class {
|
|
|
7050
7028
|
* @param indexer - Whether to use indexer.
|
|
7051
7029
|
* @return Market data.
|
|
7052
7030
|
*/
|
|
7053
|
-
async queryMarket(
|
|
7054
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7031
|
+
async queryMarket(args) {
|
|
7032
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
7055
7033
|
}
|
|
7056
7034
|
/**
|
|
7057
7035
|
* Get market pools.
|
|
@@ -7064,8 +7042,13 @@ var ScallopQuery = class {
|
|
|
7064
7042
|
* @param indexer - Whether to use indexer.
|
|
7065
7043
|
* @return Market pools data.
|
|
7066
7044
|
*/
|
|
7067
|
-
async getMarketPools(poolCoinNames,
|
|
7068
|
-
return await getMarketPools(
|
|
7045
|
+
async getMarketPools(poolCoinNames, args) {
|
|
7046
|
+
return await getMarketPools(
|
|
7047
|
+
this,
|
|
7048
|
+
poolCoinNames,
|
|
7049
|
+
args?.indexer,
|
|
7050
|
+
args?.coinPrices
|
|
7051
|
+
);
|
|
7069
7052
|
}
|
|
7070
7053
|
/**
|
|
7071
7054
|
* Get market pool
|
|
@@ -7074,11 +7057,11 @@ var ScallopQuery = class {
|
|
|
7074
7057
|
* @param indexer - Whether to use indexer.
|
|
7075
7058
|
* @return Market pool data.
|
|
7076
7059
|
*/
|
|
7077
|
-
async getMarketPool(poolCoinName,
|
|
7060
|
+
async getMarketPool(poolCoinName, args) {
|
|
7078
7061
|
return await getMarketPool(
|
|
7079
7062
|
this,
|
|
7080
7063
|
poolCoinName,
|
|
7081
|
-
indexer,
|
|
7064
|
+
args?.indexer,
|
|
7082
7065
|
args?.marketObject,
|
|
7083
7066
|
args?.coinPrice
|
|
7084
7067
|
);
|
|
@@ -7094,8 +7077,8 @@ var ScallopQuery = class {
|
|
|
7094
7077
|
* @param indexer - Whether to use indexer.
|
|
7095
7078
|
* @return Market collaterals data.
|
|
7096
7079
|
*/
|
|
7097
|
-
async getMarketCollaterals(collateralCoinNames,
|
|
7098
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
7080
|
+
async getMarketCollaterals(collateralCoinNames, args) {
|
|
7081
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
7099
7082
|
}
|
|
7100
7083
|
/**
|
|
7101
7084
|
* Get market collateral
|
|
@@ -7104,8 +7087,8 @@ var ScallopQuery = class {
|
|
|
7104
7087
|
* @param indexer - Whether to use indexer.
|
|
7105
7088
|
* @return Market collateral data.
|
|
7106
7089
|
*/
|
|
7107
|
-
async getMarketCollateral(collateralCoinName,
|
|
7108
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
7090
|
+
async getMarketCollateral(collateralCoinName, args) {
|
|
7091
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
7109
7092
|
}
|
|
7110
7093
|
/**
|
|
7111
7094
|
* Get obligations data.
|
|
@@ -7191,11 +7174,11 @@ var ScallopQuery = class {
|
|
|
7191
7174
|
* @param indexer - Whether to use indexer.
|
|
7192
7175
|
* @return Spools data.
|
|
7193
7176
|
*/
|
|
7194
|
-
async getSpools(stakeMarketCoinNames,
|
|
7177
|
+
async getSpools(stakeMarketCoinNames, args) {
|
|
7195
7178
|
return await getSpools(
|
|
7196
7179
|
this,
|
|
7197
7180
|
stakeMarketCoinNames,
|
|
7198
|
-
indexer,
|
|
7181
|
+
args?.indexer,
|
|
7199
7182
|
args?.marketPools,
|
|
7200
7183
|
args?.coinPrices
|
|
7201
7184
|
);
|
|
@@ -7207,11 +7190,11 @@ var ScallopQuery = class {
|
|
|
7207
7190
|
* @param indexer - Whether to use indexer.
|
|
7208
7191
|
* @return Spool data.
|
|
7209
7192
|
*/
|
|
7210
|
-
async getSpool(stakeMarketCoinName,
|
|
7193
|
+
async getSpool(stakeMarketCoinName, args) {
|
|
7211
7194
|
return await getSpool(
|
|
7212
7195
|
this,
|
|
7213
7196
|
stakeMarketCoinName,
|
|
7214
|
-
indexer,
|
|
7197
|
+
args?.indexer,
|
|
7215
7198
|
args?.marketPool,
|
|
7216
7199
|
args?.coinPrices
|
|
7217
7200
|
);
|
|
@@ -7314,12 +7297,11 @@ var ScallopQuery = class {
|
|
|
7314
7297
|
* @param indexer - Whether to use indexer.
|
|
7315
7298
|
* @return Borrow incentive pools data.
|
|
7316
7299
|
*/
|
|
7317
|
-
async getBorrowIncentivePools(coinNames,
|
|
7300
|
+
async getBorrowIncentivePools(coinNames, args) {
|
|
7318
7301
|
return await getBorrowIncentivePools(
|
|
7319
7302
|
this,
|
|
7320
7303
|
coinNames,
|
|
7321
|
-
indexer,
|
|
7322
|
-
args?.marketPools,
|
|
7304
|
+
args?.indexer,
|
|
7323
7305
|
args?.coinPrices
|
|
7324
7306
|
);
|
|
7325
7307
|
}
|
|
@@ -7341,8 +7323,8 @@ var ScallopQuery = class {
|
|
|
7341
7323
|
* @param indexer - Whether to use indexer.
|
|
7342
7324
|
* @return All lending and spool infomation.
|
|
7343
7325
|
*/
|
|
7344
|
-
async getLendings(poolCoinNames, ownerAddress = this.walletAddress,
|
|
7345
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
7326
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
7327
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
7346
7328
|
}
|
|
7347
7329
|
/**
|
|
7348
7330
|
* Get user lending and spool information for specific pool.
|
|
@@ -7352,8 +7334,8 @@ var ScallopQuery = class {
|
|
|
7352
7334
|
* @param indexer - Whether to use indexer.
|
|
7353
7335
|
* @return Lending pool data.
|
|
7354
7336
|
*/
|
|
7355
|
-
async getLending(poolCoinName, ownerAddress = this.walletAddress,
|
|
7356
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
7337
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
|
|
7338
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
7357
7339
|
}
|
|
7358
7340
|
/**
|
|
7359
7341
|
* Get user all obligation accounts information.
|
|
@@ -7365,8 +7347,8 @@ var ScallopQuery = class {
|
|
|
7365
7347
|
* @param indexer - Whether to use indexer.
|
|
7366
7348
|
* @return All obligation accounts information.
|
|
7367
7349
|
*/
|
|
7368
|
-
async getObligationAccounts(ownerAddress = this.walletAddress,
|
|
7369
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
7350
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
7351
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
7370
7352
|
}
|
|
7371
7353
|
/**
|
|
7372
7354
|
* Get obligation account information for specific id.
|
|
@@ -7379,12 +7361,12 @@ var ScallopQuery = class {
|
|
|
7379
7361
|
* @param indexer - Whether to use indexer.
|
|
7380
7362
|
* @return Borrowing and collateral information.
|
|
7381
7363
|
*/
|
|
7382
|
-
async getObligationAccount(obligationId, ownerAddress = this.walletAddress,
|
|
7364
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
|
|
7383
7365
|
return await getObligationAccount(
|
|
7384
7366
|
this,
|
|
7385
7367
|
obligationId,
|
|
7386
7368
|
ownerAddress,
|
|
7387
|
-
indexer
|
|
7369
|
+
args?.indexer
|
|
7388
7370
|
);
|
|
7389
7371
|
}
|
|
7390
7372
|
/**
|
|
@@ -7396,8 +7378,8 @@ var ScallopQuery = class {
|
|
|
7396
7378
|
*
|
|
7397
7379
|
* @return Total value locked.
|
|
7398
7380
|
*/
|
|
7399
|
-
async getTvl(
|
|
7400
|
-
return await getTotalValueLocked(this, indexer);
|
|
7381
|
+
async getTvl(args) {
|
|
7382
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
7401
7383
|
}
|
|
7402
7384
|
/**
|
|
7403
7385
|
* Get veSca data.
|
|
@@ -7535,13 +7517,6 @@ var ScallopQuery = class {
|
|
|
7535
7517
|
async getCoinPriceByIndexer(poolName) {
|
|
7536
7518
|
return this.indexer.getCoinPrice(poolName);
|
|
7537
7519
|
}
|
|
7538
|
-
/**
|
|
7539
|
-
* Get all coin prices, including sCoin
|
|
7540
|
-
* @returns prices data
|
|
7541
|
-
*/
|
|
7542
|
-
async getAllCoinPrices(args) {
|
|
7543
|
-
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
7544
|
-
}
|
|
7545
7520
|
};
|
|
7546
7521
|
|
|
7547
7522
|
// src/models/scallopBuilder.ts
|
|
@@ -8191,46 +8166,30 @@ var ScallopClient = class {
|
|
|
8191
8166
|
}
|
|
8192
8167
|
}
|
|
8193
8168
|
/**
|
|
8194
|
-
*
|
|
8169
|
+
* unstake market coin from the specific spool.
|
|
8195
8170
|
*
|
|
8196
|
-
* @param
|
|
8171
|
+
* @param marketCoinName - Types of mak coin.
|
|
8197
8172
|
* @param amount - The amount of coins would deposit.
|
|
8198
8173
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8199
8174
|
* @param accountId - The stake account object.
|
|
8200
8175
|
* @param walletAddress - The wallet address of the owner.
|
|
8201
8176
|
* @return Transaction block response or transaction block
|
|
8202
8177
|
*/
|
|
8203
|
-
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8178
|
+
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8204
8179
|
const txBlock = this.builder.createTxBlock();
|
|
8205
8180
|
const sender = walletAddress ?? this.walletAddress;
|
|
8206
8181
|
txBlock.setSender(sender);
|
|
8207
|
-
const
|
|
8208
|
-
const
|
|
8209
|
-
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8210
|
-
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8211
|
-
).flatMap(({ coinName }) => coinName);
|
|
8212
|
-
for (const rewardCoinName of rewardCoinNames) {
|
|
8182
|
+
const rewardCoins = [];
|
|
8183
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
8213
8184
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8185
|
+
coinName,
|
|
8214
8186
|
rewardCoinName,
|
|
8215
8187
|
obligationId,
|
|
8216
8188
|
obligationKeyId
|
|
8217
8189
|
);
|
|
8218
|
-
|
|
8219
|
-
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8220
|
-
} else {
|
|
8221
|
-
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8222
|
-
}
|
|
8190
|
+
rewardCoins.push(rewardCoin);
|
|
8223
8191
|
}
|
|
8224
|
-
txBlock.transferObjects(
|
|
8225
|
-
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8226
|
-
const mergeDest = rewardCoins[0];
|
|
8227
|
-
if (rewardCoins.length > 1) {
|
|
8228
|
-
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8229
|
-
}
|
|
8230
|
-
return mergeDest;
|
|
8231
|
-
}),
|
|
8232
|
-
sender
|
|
8233
|
-
);
|
|
8192
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
8234
8193
|
if (sign) {
|
|
8235
8194
|
return await this.suiKit.signAndSendTxn(
|
|
8236
8195
|
txBlock
|
|
@@ -8539,12 +8498,12 @@ export {
|
|
|
8539
8498
|
UNLOCK_ROUND_DURATION,
|
|
8540
8499
|
USE_TEST_ADDRESS,
|
|
8541
8500
|
assetCoins,
|
|
8501
|
+
borrowIncentiveRewardCoins,
|
|
8542
8502
|
coinDecimals,
|
|
8543
8503
|
coinIds,
|
|
8544
8504
|
marketCoins,
|
|
8545
8505
|
queryKeys,
|
|
8546
8506
|
sCoinIds,
|
|
8547
|
-
sCoinRawNameToName,
|
|
8548
8507
|
sCoinTypeToName,
|
|
8549
8508
|
sCoins,
|
|
8550
8509
|
spoolRewardCoins,
|