@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.js
CHANGED
|
@@ -74,12 +74,12 @@ __export(src_exports, {
|
|
|
74
74
|
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
75
75
|
USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
|
|
76
76
|
assetCoins: () => assetCoins,
|
|
77
|
+
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
77
78
|
coinDecimals: () => coinDecimals,
|
|
78
79
|
coinIds: () => coinIds,
|
|
79
80
|
marketCoins: () => marketCoins,
|
|
80
81
|
queryKeys: () => queryKeys,
|
|
81
82
|
sCoinIds: () => sCoinIds,
|
|
82
|
-
sCoinRawNameToName: () => sCoinRawNameToName,
|
|
83
83
|
sCoinTypeToName: () => sCoinTypeToName,
|
|
84
84
|
sCoins: () => sCoins,
|
|
85
85
|
spoolRewardCoins: () => spoolRewardCoins,
|
|
@@ -218,10 +218,7 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
218
218
|
"sca",
|
|
219
219
|
"usdc"
|
|
220
220
|
];
|
|
221
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
222
|
-
...SUPPORT_POOLS,
|
|
223
|
-
...SUPPORT_SCOIN
|
|
224
|
-
];
|
|
221
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui", "sca"];
|
|
225
222
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
226
223
|
var SUPPORT_PACKAGES = [
|
|
227
224
|
"coinDecimalsRegistry",
|
|
@@ -351,6 +348,18 @@ var spoolRewardCoins = {
|
|
|
351
348
|
var suiBridgeCoins = {
|
|
352
349
|
sbeth: "sbeth"
|
|
353
350
|
};
|
|
351
|
+
var borrowIncentiveRewardCoins = {
|
|
352
|
+
usdc: ["sui", "sca"],
|
|
353
|
+
sui: ["sui", "sca"],
|
|
354
|
+
wusdc: ["sui", "sca"],
|
|
355
|
+
wusdt: ["sui", "sca"],
|
|
356
|
+
sca: ["sui", "sca"],
|
|
357
|
+
afsui: ["sui"],
|
|
358
|
+
hasui: ["sui"],
|
|
359
|
+
vsui: ["sui"],
|
|
360
|
+
weth: ["sui"],
|
|
361
|
+
sbeth: ["sui"]
|
|
362
|
+
};
|
|
354
363
|
var coinIds = {
|
|
355
364
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
356
365
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -385,10 +394,10 @@ var sCoinIds = {
|
|
|
385
394
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
386
395
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
387
396
|
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
397
|
+
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
398
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
388
399
|
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
389
400
|
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
390
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
391
|
-
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
392
401
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
393
402
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
394
403
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
@@ -405,13 +414,6 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
405
414
|
},
|
|
406
415
|
{}
|
|
407
416
|
);
|
|
408
|
-
var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
409
|
-
(acc, [coinName, coinType]) => {
|
|
410
|
-
acc[coinType.split("::")[2].toLowerCase()] = coinName;
|
|
411
|
-
return acc;
|
|
412
|
-
},
|
|
413
|
-
{}
|
|
414
|
-
);
|
|
415
417
|
|
|
416
418
|
// src/constants/flashloan.ts
|
|
417
419
|
var FlashLoanFeeObjectMap = {
|
|
@@ -1042,7 +1044,7 @@ var TEST_ADDRESSES = {
|
|
|
1042
1044
|
|
|
1043
1045
|
// src/constants/tokenBucket.ts
|
|
1044
1046
|
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
1045
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
1047
|
+
var DEFAULT_INTERVAL_IN_MS = 100;
|
|
1046
1048
|
|
|
1047
1049
|
// src/constants/vesca.ts
|
|
1048
1050
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1643,7 +1645,7 @@ var TokenBucket = class {
|
|
|
1643
1645
|
return false;
|
|
1644
1646
|
}
|
|
1645
1647
|
};
|
|
1646
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1648
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
|
|
1647
1649
|
let retries = 0;
|
|
1648
1650
|
const tryRequest = async () => {
|
|
1649
1651
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1679,13 +1681,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1679
1681
|
|
|
1680
1682
|
// src/utils/indexer.ts
|
|
1681
1683
|
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1682
|
-
const
|
|
1683
|
-
if (indexer) {
|
|
1684
|
+
const lastArgs = args[args.length - 1];
|
|
1685
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1684
1686
|
try {
|
|
1685
1687
|
return await method.apply(context, args);
|
|
1686
1688
|
} catch (e) {
|
|
1687
1689
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1688
|
-
return await method.apply(context, [
|
|
1690
|
+
return await method.apply(context, [
|
|
1691
|
+
...args.slice(0, -1),
|
|
1692
|
+
{
|
|
1693
|
+
...lastArgs,
|
|
1694
|
+
indexer: false
|
|
1695
|
+
}
|
|
1696
|
+
]);
|
|
1689
1697
|
}
|
|
1690
1698
|
}
|
|
1691
1699
|
return await method.apply(context, args);
|
|
@@ -2553,21 +2561,15 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
2553
2561
|
};
|
|
2554
2562
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2555
2563
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2556
|
-
], indexer = false,
|
|
2564
|
+
], indexer = false, coinPrices) => {
|
|
2557
2565
|
const borrowIncentivePools = {};
|
|
2558
|
-
|
|
2559
|
-
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2566
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2560
2567
|
if (indexer) {
|
|
2561
2568
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2562
2569
|
const updateBorrowIncentivePool = (pool) => {
|
|
2563
2570
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2564
2571
|
return;
|
|
2565
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
2566
|
-
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2567
|
-
if (pool.points[sCoinName]) {
|
|
2568
|
-
pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2572
|
+
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
2571
2573
|
borrowIncentivePools[pool.coinName] = pool;
|
|
2572
2574
|
};
|
|
2573
2575
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -2593,15 +2595,12 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2593
2595
|
for (const [coinName, poolPoint] of Object.entries(
|
|
2594
2596
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2595
2597
|
)) {
|
|
2596
|
-
const rewardCoinType = poolPoint.pointType;
|
|
2597
|
-
|
|
2598
|
+
const rewardCoinType = (0, import_utils3.normalizeStructTag)(poolPoint.pointType);
|
|
2599
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2598
2600
|
rewardCoinType
|
|
2599
2601
|
);
|
|
2600
|
-
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2601
|
-
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2602
|
-
}
|
|
2603
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2604
2602
|
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2603
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2605
2604
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2606
2605
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2607
2606
|
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
@@ -3034,7 +3033,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
3034
3033
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
3035
3034
|
showContent: true
|
|
3036
3035
|
});
|
|
3037
|
-
coinPrices =
|
|
3036
|
+
coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
|
|
3038
3037
|
const marketPools = {};
|
|
3039
3038
|
if (indexer) {
|
|
3040
3039
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
@@ -3067,154 +3066,150 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
3067
3066
|
return marketPools;
|
|
3068
3067
|
};
|
|
3069
3068
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3069
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
3070
|
+
if (indexer) {
|
|
3071
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
3072
|
+
if (!marketPoolIndexer) {
|
|
3073
|
+
return void 0;
|
|
3074
|
+
}
|
|
3075
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
3076
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
3077
|
+
marketPoolIndexer.coinName
|
|
3078
|
+
);
|
|
3079
|
+
return marketPoolIndexer;
|
|
3080
|
+
}
|
|
3081
|
+
const marketId = query.address.get("core.market");
|
|
3082
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
3083
|
+
showContent: true
|
|
3084
|
+
}))?.data;
|
|
3085
|
+
if (!(marketObject && marketObject.content?.dataType === "moveObject"))
|
|
3086
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
3087
|
+
const fields = marketObject.content.fields;
|
|
3088
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
3089
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
3090
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3091
|
+
parentId: balanceSheetParentId,
|
|
3092
|
+
name: {
|
|
3093
|
+
type: "0x1::type_name::TypeName",
|
|
3094
|
+
value: {
|
|
3095
|
+
name: coinType.substring(2)
|
|
3076
3096
|
}
|
|
3077
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
3078
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
3079
|
-
marketPoolIndexer.coinName
|
|
3080
|
-
);
|
|
3081
|
-
return marketPoolIndexer;
|
|
3082
3097
|
}
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
name: coinType.substring(2)
|
|
3098
|
-
}
|
|
3098
|
+
});
|
|
3099
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
|
|
3100
|
+
if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
|
|
3101
|
+
throw new Error(
|
|
3102
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
3103
|
+
);
|
|
3104
|
+
const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
|
|
3105
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
3106
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3107
|
+
parentId: borrowIndexParentId,
|
|
3108
|
+
name: {
|
|
3109
|
+
type: "0x1::type_name::TypeName",
|
|
3110
|
+
value: {
|
|
3111
|
+
name: coinType.substring(2)
|
|
3099
3112
|
}
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3113
|
+
}
|
|
3114
|
+
});
|
|
3115
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
|
|
3116
|
+
if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
|
|
3117
|
+
throw new Error(
|
|
3118
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
3119
|
+
);
|
|
3120
|
+
const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
|
|
3121
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
3122
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3123
|
+
parentId: interestModelParentId,
|
|
3124
|
+
name: {
|
|
3125
|
+
type: "0x1::type_name::TypeName",
|
|
3126
|
+
value: {
|
|
3127
|
+
name: coinType.substring(2)
|
|
3115
3128
|
}
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3129
|
+
}
|
|
3130
|
+
});
|
|
3131
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3132
|
+
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3133
|
+
throw new Error(
|
|
3134
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3135
|
+
);
|
|
3136
|
+
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3137
|
+
const getBorrowFee = async () => {
|
|
3138
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3139
|
+
parentId: marketId,
|
|
3126
3140
|
name: {
|
|
3127
|
-
type:
|
|
3141
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3128
3142
|
value: {
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
}
|
|
3132
|
-
});
|
|
3133
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3134
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3135
|
-
throw new Error(
|
|
3136
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3137
|
-
);
|
|
3138
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3139
|
-
const getBorrowFee = async () => {
|
|
3140
|
-
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3141
|
-
parentId: marketId,
|
|
3142
|
-
name: {
|
|
3143
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3144
|
-
value: {
|
|
3145
|
-
type: {
|
|
3146
|
-
name: coinType.substring(2)
|
|
3147
|
-
}
|
|
3143
|
+
type: {
|
|
3144
|
+
name: coinType.substring(2)
|
|
3148
3145
|
}
|
|
3149
3146
|
}
|
|
3150
|
-
}
|
|
3151
|
-
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3152
|
-
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3153
|
-
return { value: "0" };
|
|
3154
|
-
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3155
|
-
};
|
|
3156
|
-
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3157
|
-
type: interestModel.type.fields,
|
|
3158
|
-
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3159
|
-
interestRate: borrowIndex.interest_rate.fields,
|
|
3160
|
-
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3161
|
-
borrowIndex: borrowIndex.borrow_index,
|
|
3162
|
-
lastUpdated: borrowIndex.last_updated,
|
|
3163
|
-
cash: balanceSheet.cash,
|
|
3164
|
-
debt: balanceSheet.debt,
|
|
3165
|
-
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3166
|
-
reserve: balanceSheet.revenue,
|
|
3167
|
-
reserveFactor: interestModel.revenue_factor.fields,
|
|
3168
|
-
borrowWeight: interestModel.borrow_weight.fields,
|
|
3169
|
-
borrowFeeRate: await getBorrowFee(),
|
|
3170
|
-
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3171
|
-
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3172
|
-
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3173
|
-
highKink: interestModel.high_kink.fields,
|
|
3174
|
-
midKink: interestModel.mid_kink.fields,
|
|
3175
|
-
minBorrowAmount: interestModel.min_borrow_amount
|
|
3147
|
+
}
|
|
3176
3148
|
});
|
|
3177
|
-
const
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3149
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3150
|
+
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3151
|
+
return { value: "0" };
|
|
3152
|
+
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3153
|
+
};
|
|
3154
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3155
|
+
type: interestModel.type.fields,
|
|
3156
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3157
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
3158
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3159
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
3160
|
+
lastUpdated: borrowIndex.last_updated,
|
|
3161
|
+
cash: balanceSheet.cash,
|
|
3162
|
+
debt: balanceSheet.debt,
|
|
3163
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3164
|
+
reserve: balanceSheet.revenue,
|
|
3165
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
3166
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
3167
|
+
borrowFeeRate: await getBorrowFee(),
|
|
3168
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3169
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3170
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3171
|
+
highKink: interestModel.high_kink.fields,
|
|
3172
|
+
midKink: interestModel.mid_kink.fields,
|
|
3173
|
+
minBorrowAmount: interestModel.min_borrow_amount
|
|
3174
|
+
});
|
|
3175
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
3176
|
+
query.utils,
|
|
3177
|
+
parsedMarketPoolData
|
|
3178
|
+
);
|
|
3179
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3180
|
+
const maxSupplyCoin = (0, import_bignumber3.default)(
|
|
3181
|
+
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
3182
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3183
|
+
const maxBorrowCoin = (0, import_bignumber3.default)(
|
|
3184
|
+
await getBorrowLimit(query.utils, poolCoinName) ?? "0"
|
|
3185
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3186
|
+
return {
|
|
3187
|
+
coinName: poolCoinName,
|
|
3188
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3189
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3190
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3191
|
+
sCoinType: query.utils.parseSCoinType(
|
|
3192
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
3193
|
+
),
|
|
3194
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
3195
|
+
coinDecimal,
|
|
3196
|
+
coinPrice: coinPrice ?? 0,
|
|
3197
|
+
highKink: parsedMarketPoolData.highKink,
|
|
3198
|
+
midKink: parsedMarketPoolData.midKink,
|
|
3199
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
3200
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
3201
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
3202
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
3203
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
3204
|
+
maxSupplyCoin,
|
|
3205
|
+
maxBorrowCoin,
|
|
3206
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
3207
|
+
...calculatedMarketPoolData
|
|
3208
|
+
};
|
|
3214
3209
|
};
|
|
3215
3210
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3216
3211
|
const marketId = query.address.get("core.market");
|
|
3217
|
-
const coinPrices = await query.utils.getCoinPrices() ?? {};
|
|
3212
|
+
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
|
|
3218
3213
|
const marketCollaterals = {};
|
|
3219
3214
|
if (indexer) {
|
|
3220
3215
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -3250,7 +3245,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
3250
3245
|
return marketCollaterals;
|
|
3251
3246
|
};
|
|
3252
3247
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3253
|
-
coinPrice = coinPrice
|
|
3248
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
3254
3249
|
if (indexer) {
|
|
3255
3250
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
3256
3251
|
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
@@ -3566,11 +3561,13 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3566
3561
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3567
3562
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3568
3563
|
);
|
|
3569
|
-
const coinPrices = await query.utils.getCoinPrices();
|
|
3570
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
3564
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3565
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3566
|
+
indexer,
|
|
3571
3567
|
coinPrices
|
|
3572
3568
|
});
|
|
3573
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
3569
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
3570
|
+
indexer,
|
|
3574
3571
|
marketPools,
|
|
3575
3572
|
coinPrices
|
|
3576
3573
|
});
|
|
@@ -3604,22 +3601,20 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3604
3601
|
};
|
|
3605
3602
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3606
3603
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3607
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
3608
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName,
|
|
3604
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3605
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3606
|
+
indexer,
|
|
3609
3607
|
coinPrice
|
|
3610
3608
|
});
|
|
3611
3609
|
if (!marketPool)
|
|
3612
3610
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3613
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3614
|
-
marketCoinName,
|
|
3611
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
|
|
3615
3612
|
indexer,
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
[poolCoinName]: coinPrice
|
|
3620
|
-
}
|
|
3613
|
+
marketPool,
|
|
3614
|
+
coinPrices: {
|
|
3615
|
+
[poolCoinName]: coinPrice
|
|
3621
3616
|
}
|
|
3622
|
-
) : void 0;
|
|
3617
|
+
}) : void 0;
|
|
3623
3618
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3624
3619
|
marketCoinName,
|
|
3625
3620
|
ownerAddress
|
|
@@ -3739,7 +3734,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3739
3734
|
};
|
|
3740
3735
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3741
3736
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3742
|
-
const market = await query.queryMarket(indexer,
|
|
3737
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
3743
3738
|
const [coinAmounts, obligations] = await Promise.all([
|
|
3744
3739
|
query.getCoinAmounts(void 0, ownerAddress),
|
|
3745
3740
|
query.getObligations(ownerAddress)
|
|
@@ -3764,13 +3759,14 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3764
3759
|
const collateralAssetCoinNames = [
|
|
3765
3760
|
...SUPPORT_COLLATERALS
|
|
3766
3761
|
];
|
|
3767
|
-
|
|
3768
|
-
|
|
3762
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3763
|
+
market = market ?? await query.queryMarket({ indexer, coinPrices });
|
|
3769
3764
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3770
3765
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3771
3766
|
query.queryObligation(obligationId),
|
|
3772
|
-
query.getBorrowIncentivePools(void 0,
|
|
3773
|
-
coinPrices
|
|
3767
|
+
query.getBorrowIncentivePools(void 0, {
|
|
3768
|
+
coinPrices,
|
|
3769
|
+
indexer
|
|
3774
3770
|
}),
|
|
3775
3771
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3776
3772
|
]);
|
|
@@ -3906,47 +3902,44 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3906
3902
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3907
3903
|
if (borrowIncentivePool) {
|
|
3908
3904
|
const rewards = [];
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
)
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
boostValue
|
|
3945
|
-
});
|
|
3946
|
-
}
|
|
3905
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
3906
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
3907
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
3908
|
+
if (accountPoint && poolPoint) {
|
|
3909
|
+
let availableClaimAmount = (0, import_bignumber5.default)(0);
|
|
3910
|
+
let availableClaimCoin = (0, import_bignumber5.default)(0);
|
|
3911
|
+
const accountBorrowedAmount = (0, import_bignumber5.default)(accountPoint.weightedAmount);
|
|
3912
|
+
const baseIndexRate = 1e9;
|
|
3913
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3914
|
+
(0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3915
|
+
0
|
|
3916
|
+
) : 1;
|
|
3917
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3918
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3919
|
+
);
|
|
3920
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3921
|
+
-1 * poolPoint.coinDecimal
|
|
3922
|
+
);
|
|
3923
|
+
const weightScale = (0, import_bignumber5.default)(1e12);
|
|
3924
|
+
const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3925
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3926
|
+
).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3927
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3928
|
+
).toNumber() : 1;
|
|
3929
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3930
|
+
rewards.push({
|
|
3931
|
+
coinName: poolPoint.coinName,
|
|
3932
|
+
coinType: poolPoint.coinType,
|
|
3933
|
+
symbol: poolPoint.symbol,
|
|
3934
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3935
|
+
coinPrice: poolPoint.coinPrice,
|
|
3936
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3937
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3938
|
+
boostValue
|
|
3939
|
+
});
|
|
3947
3940
|
}
|
|
3948
3941
|
}
|
|
3949
|
-
|
|
3942
|
+
}
|
|
3950
3943
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3951
3944
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3952
3945
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -4053,7 +4046,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
4053
4046
|
return obligationAccount;
|
|
4054
4047
|
};
|
|
4055
4048
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
4056
|
-
const market = await query.queryMarket(indexer);
|
|
4049
|
+
const market = await query.queryMarket({ indexer });
|
|
4057
4050
|
let supplyValue = (0, import_bignumber5.default)(0);
|
|
4058
4051
|
let borrowValue = (0, import_bignumber5.default)(0);
|
|
4059
4052
|
if (indexer) {
|
|
@@ -4090,7 +4083,6 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4090
4083
|
};
|
|
4091
4084
|
|
|
4092
4085
|
// src/queries/priceQuery.ts
|
|
4093
|
-
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4094
4086
|
var getPythPrice = async ({
|
|
4095
4087
|
address
|
|
4096
4088
|
}, assetCoinName, priceFeedObject) => {
|
|
@@ -4172,22 +4164,6 @@ var getPythPrices = async ({
|
|
|
4172
4164
|
{}
|
|
4173
4165
|
);
|
|
4174
4166
|
};
|
|
4175
|
-
var getAllCoinPrices = async (query, marketPools, coinPrices) => {
|
|
4176
|
-
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4177
|
-
marketPools = marketPools ?? await query.getMarketPools(void 0, void 0, { coinPrices });
|
|
4178
|
-
if (!marketPools) {
|
|
4179
|
-
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
4180
|
-
}
|
|
4181
|
-
const sCoinPrices = {};
|
|
4182
|
-
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
4183
|
-
const coinName = query.utils.parseCoinName(sCoinName);
|
|
4184
|
-
sCoinPrices[sCoinName] = (0, import_bignumber6.default)(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
|
|
4185
|
-
});
|
|
4186
|
-
return {
|
|
4187
|
-
...coinPrices,
|
|
4188
|
-
...sCoinPrices
|
|
4189
|
-
};
|
|
4190
|
-
};
|
|
4191
4167
|
|
|
4192
4168
|
// src/queries/referralQuery.ts
|
|
4193
4169
|
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
@@ -4208,7 +4184,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4208
4184
|
// src/queries/sCoinQuery.ts
|
|
4209
4185
|
var import_bcs = require("@mysten/sui/bcs");
|
|
4210
4186
|
var import_assert = __toESM(require("assert"));
|
|
4211
|
-
var
|
|
4187
|
+
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4212
4188
|
var getSCoinTotalSupply = async ({
|
|
4213
4189
|
utils
|
|
4214
4190
|
}, sCoinName) => {
|
|
@@ -4229,7 +4205,7 @@ var getSCoinTotalSupply = async ({
|
|
|
4229
4205
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4230
4206
|
const type = results[0].returnValues[0][1];
|
|
4231
4207
|
(0, import_assert.default)(type === "u64", "Result type is not u64");
|
|
4232
|
-
return (0,
|
|
4208
|
+
return (0, import_bignumber6.default)(import_bcs.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4233
4209
|
}
|
|
4234
4210
|
return 0;
|
|
4235
4211
|
};
|
|
@@ -4255,7 +4231,7 @@ var getSCoinAmount = async ({
|
|
|
4255
4231
|
owner,
|
|
4256
4232
|
coinType: sCoinType
|
|
4257
4233
|
});
|
|
4258
|
-
return (0,
|
|
4234
|
+
return (0, import_bignumber6.default)(amount).toNumber();
|
|
4259
4235
|
};
|
|
4260
4236
|
var isSupportStakeCoins = (value) => {
|
|
4261
4237
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4274,8 +4250,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4274
4250
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4275
4251
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4276
4252
|
const marketPools = await Promise.all([
|
|
4277
|
-
query.getMarketPool(fromCoinName
|
|
4278
|
-
query.getMarketPool(toCoinName
|
|
4253
|
+
query.getMarketPool(fromCoinName),
|
|
4254
|
+
query.getMarketPool(toCoinName)
|
|
4279
4255
|
]);
|
|
4280
4256
|
if (marketPools.some((pool) => !pool))
|
|
4281
4257
|
throw new Error("Failed to fetch the lendings data");
|
|
@@ -4285,7 +4261,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4285
4261
|
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4286
4262
|
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4287
4263
|
const calcAtoBRate = async () => {
|
|
4288
|
-
const prices = await query.utils.getCoinPrices();
|
|
4264
|
+
const prices = await query.utils.getCoinPrices([fromCoinName, toCoinName]);
|
|
4289
4265
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4290
4266
|
throw new Error("Failed to fetch the coin prices");
|
|
4291
4267
|
}
|
|
@@ -4295,7 +4271,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4295
4271
|
return prices[fromCoinName] / prices[toCoinName];
|
|
4296
4272
|
};
|
|
4297
4273
|
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4298
|
-
return (0,
|
|
4274
|
+
return (0, import_bignumber6.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4299
4275
|
};
|
|
4300
4276
|
|
|
4301
4277
|
// src/queries/spoolQuery.ts
|
|
@@ -4305,7 +4281,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4305
4281
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4306
4282
|
);
|
|
4307
4283
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4308
|
-
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4284
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
|
|
4309
4285
|
if (!marketPools)
|
|
4310
4286
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4311
4287
|
const spools = {};
|
|
@@ -4346,7 +4322,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4346
4322
|
};
|
|
4347
4323
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4348
4324
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4349
|
-
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4325
|
+
marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
|
|
4350
4326
|
if (!marketPool) {
|
|
4351
4327
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4352
4328
|
}
|
|
@@ -4355,7 +4331,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4355
4331
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4356
4332
|
);
|
|
4357
4333
|
let spool = void 0;
|
|
4358
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4334
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
|
|
4359
4335
|
if (indexer) {
|
|
4360
4336
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4361
4337
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
@@ -4375,7 +4351,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4375
4351
|
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4376
4352
|
}
|
|
4377
4353
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4378
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4354
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
4379
4355
|
const spoolObject = spoolObjectResponse[0];
|
|
4380
4356
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
4381
4357
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
@@ -4619,7 +4595,7 @@ var getStakeRewardPool = async ({
|
|
|
4619
4595
|
};
|
|
4620
4596
|
|
|
4621
4597
|
// src/queries/vescaQuery.ts
|
|
4622
|
-
var
|
|
4598
|
+
var import_bignumber7 = __toESM(require("bignumber.js"));
|
|
4623
4599
|
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4624
4600
|
var import_bcs2 = require("@mysten/sui/bcs");
|
|
4625
4601
|
var import_zod5 = require("zod");
|
|
@@ -4701,7 +4677,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4701
4677
|
0
|
|
4702
4678
|
);
|
|
4703
4679
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4704
|
-
const lockedScaCoin = (0,
|
|
4680
|
+
const lockedScaCoin = (0, import_bignumber7.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4705
4681
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4706
4682
|
vesca = {
|
|
4707
4683
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4711,7 +4687,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4711
4687
|
lockedScaAmount,
|
|
4712
4688
|
lockedScaCoin,
|
|
4713
4689
|
currentVeScaBalance,
|
|
4714
|
-
unlockAt: (0,
|
|
4690
|
+
unlockAt: (0, import_bignumber7.default)(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4715
4691
|
};
|
|
4716
4692
|
}
|
|
4717
4693
|
return vesca;
|
|
@@ -4773,10 +4749,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4773
4749
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4774
4750
|
return null;
|
|
4775
4751
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4776
|
-
const totalLockedSca = (0,
|
|
4752
|
+
const totalLockedSca = (0, import_bignumber7.default)(
|
|
4777
4753
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4778
4754
|
).shiftedBy(-9).toNumber();
|
|
4779
|
-
const totalVeSca = (0,
|
|
4755
|
+
const totalVeSca = (0, import_bignumber7.default)(
|
|
4780
4756
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4781
4757
|
).shiftedBy(-9).toNumber();
|
|
4782
4758
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4812,6 +4788,15 @@ var ScallopUtils = class {
|
|
|
4812
4788
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4813
4789
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4814
4790
|
};
|
|
4791
|
+
/**
|
|
4792
|
+
* Get reward type of borrow incentive pool.
|
|
4793
|
+
*
|
|
4794
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4795
|
+
* @return Borrow incentive reward coin name.
|
|
4796
|
+
*/
|
|
4797
|
+
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4798
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4799
|
+
};
|
|
4815
4800
|
this.params = {
|
|
4816
4801
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4817
4802
|
...params
|
|
@@ -4881,10 +4866,7 @@ var ScallopUtils = class {
|
|
|
4881
4866
|
* @param coinName - Specific support coin name.
|
|
4882
4867
|
* @return Coin type.
|
|
4883
4868
|
*/
|
|
4884
|
-
parseCoinType(coinName
|
|
4885
|
-
if (sCoinIds[coinName] && !useOldMarketCoin) {
|
|
4886
|
-
return sCoinIds[coinName];
|
|
4887
|
-
}
|
|
4869
|
+
parseCoinType(coinName) {
|
|
4888
4870
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4889
4871
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4890
4872
|
if (!coinPackageId) {
|
|
@@ -4939,15 +4921,6 @@ var ScallopUtils = class {
|
|
|
4939
4921
|
return void 0;
|
|
4940
4922
|
}
|
|
4941
4923
|
}
|
|
4942
|
-
/**
|
|
4943
|
-
* Convert sCoin name to coin name.
|
|
4944
|
-
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4945
|
-
* e.g: `scallop_sui -> ssui
|
|
4946
|
-
* @return sCoin name
|
|
4947
|
-
*/
|
|
4948
|
-
parseCoinNameFromSCoinName(coinName) {
|
|
4949
|
-
return sCoinRawNameToName[coinName];
|
|
4950
|
-
}
|
|
4951
4924
|
/**
|
|
4952
4925
|
* Convert sCoin name into sCoin type
|
|
4953
4926
|
* @param sCoinName
|
|
@@ -4990,7 +4963,7 @@ var ScallopUtils = class {
|
|
|
4990
4963
|
*/
|
|
4991
4964
|
parseMarketCoinType(coinName) {
|
|
4992
4965
|
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4993
|
-
const coinType = this.parseCoinType(coinName
|
|
4966
|
+
const coinType = this.parseCoinType(coinName);
|
|
4994
4967
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4995
4968
|
}
|
|
4996
4969
|
parseCoinNameFromType(coinType) {
|
|
@@ -4999,7 +4972,7 @@ var ScallopUtils = class {
|
|
|
4999
4972
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
5000
4973
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
5001
4974
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
5002
|
-
const
|
|
4975
|
+
const wormHoleCoinTypeMap = {
|
|
5003
4976
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
5004
4977
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
5005
4978
|
[`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
|
|
@@ -5019,7 +4992,7 @@ var ScallopUtils = class {
|
|
|
5019
4992
|
},
|
|
5020
4993
|
{}
|
|
5021
4994
|
);
|
|
5022
|
-
const assetCoinName =
|
|
4995
|
+
const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
5023
4996
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
5024
4997
|
}
|
|
5025
4998
|
/**
|
|
@@ -6130,7 +6103,11 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6130
6103
|
]
|
|
6131
6104
|
);
|
|
6132
6105
|
},
|
|
6133
|
-
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6106
|
+
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
6107
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6108
|
+
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6109
|
+
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6110
|
+
}
|
|
6134
6111
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6135
6112
|
return txBlock.moveCall(
|
|
6136
6113
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6223,7 +6200,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6223
6200
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6224
6201
|
}
|
|
6225
6202
|
},
|
|
6226
|
-
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6203
|
+
claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
|
|
6227
6204
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6228
6205
|
builder,
|
|
6229
6206
|
txBlock,
|
|
@@ -6233,6 +6210,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6233
6210
|
return txBlock.claimBorrowIncentive(
|
|
6234
6211
|
obligationArg,
|
|
6235
6212
|
obligationKeyArg,
|
|
6213
|
+
coinName,
|
|
6236
6214
|
rewardCoinName
|
|
6237
6215
|
);
|
|
6238
6216
|
}
|
|
@@ -7128,8 +7106,8 @@ var ScallopQuery = class {
|
|
|
7128
7106
|
* @param indexer - Whether to use indexer.
|
|
7129
7107
|
* @return Market data.
|
|
7130
7108
|
*/
|
|
7131
|
-
async queryMarket(
|
|
7132
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7109
|
+
async queryMarket(args) {
|
|
7110
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
7133
7111
|
}
|
|
7134
7112
|
/**
|
|
7135
7113
|
* Get market pools.
|
|
@@ -7142,8 +7120,13 @@ var ScallopQuery = class {
|
|
|
7142
7120
|
* @param indexer - Whether to use indexer.
|
|
7143
7121
|
* @return Market pools data.
|
|
7144
7122
|
*/
|
|
7145
|
-
async getMarketPools(poolCoinNames,
|
|
7146
|
-
return await getMarketPools(
|
|
7123
|
+
async getMarketPools(poolCoinNames, args) {
|
|
7124
|
+
return await getMarketPools(
|
|
7125
|
+
this,
|
|
7126
|
+
poolCoinNames,
|
|
7127
|
+
args?.indexer,
|
|
7128
|
+
args?.coinPrices
|
|
7129
|
+
);
|
|
7147
7130
|
}
|
|
7148
7131
|
/**
|
|
7149
7132
|
* Get market pool
|
|
@@ -7152,11 +7135,11 @@ var ScallopQuery = class {
|
|
|
7152
7135
|
* @param indexer - Whether to use indexer.
|
|
7153
7136
|
* @return Market pool data.
|
|
7154
7137
|
*/
|
|
7155
|
-
async getMarketPool(poolCoinName,
|
|
7138
|
+
async getMarketPool(poolCoinName, args) {
|
|
7156
7139
|
return await getMarketPool(
|
|
7157
7140
|
this,
|
|
7158
7141
|
poolCoinName,
|
|
7159
|
-
indexer,
|
|
7142
|
+
args?.indexer,
|
|
7160
7143
|
args?.marketObject,
|
|
7161
7144
|
args?.coinPrice
|
|
7162
7145
|
);
|
|
@@ -7172,8 +7155,8 @@ var ScallopQuery = class {
|
|
|
7172
7155
|
* @param indexer - Whether to use indexer.
|
|
7173
7156
|
* @return Market collaterals data.
|
|
7174
7157
|
*/
|
|
7175
|
-
async getMarketCollaterals(collateralCoinNames,
|
|
7176
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
7158
|
+
async getMarketCollaterals(collateralCoinNames, args) {
|
|
7159
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
7177
7160
|
}
|
|
7178
7161
|
/**
|
|
7179
7162
|
* Get market collateral
|
|
@@ -7182,8 +7165,8 @@ var ScallopQuery = class {
|
|
|
7182
7165
|
* @param indexer - Whether to use indexer.
|
|
7183
7166
|
* @return Market collateral data.
|
|
7184
7167
|
*/
|
|
7185
|
-
async getMarketCollateral(collateralCoinName,
|
|
7186
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
7168
|
+
async getMarketCollateral(collateralCoinName, args) {
|
|
7169
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
7187
7170
|
}
|
|
7188
7171
|
/**
|
|
7189
7172
|
* Get obligations data.
|
|
@@ -7269,11 +7252,11 @@ var ScallopQuery = class {
|
|
|
7269
7252
|
* @param indexer - Whether to use indexer.
|
|
7270
7253
|
* @return Spools data.
|
|
7271
7254
|
*/
|
|
7272
|
-
async getSpools(stakeMarketCoinNames,
|
|
7255
|
+
async getSpools(stakeMarketCoinNames, args) {
|
|
7273
7256
|
return await getSpools(
|
|
7274
7257
|
this,
|
|
7275
7258
|
stakeMarketCoinNames,
|
|
7276
|
-
indexer,
|
|
7259
|
+
args?.indexer,
|
|
7277
7260
|
args?.marketPools,
|
|
7278
7261
|
args?.coinPrices
|
|
7279
7262
|
);
|
|
@@ -7285,11 +7268,11 @@ var ScallopQuery = class {
|
|
|
7285
7268
|
* @param indexer - Whether to use indexer.
|
|
7286
7269
|
* @return Spool data.
|
|
7287
7270
|
*/
|
|
7288
|
-
async getSpool(stakeMarketCoinName,
|
|
7271
|
+
async getSpool(stakeMarketCoinName, args) {
|
|
7289
7272
|
return await getSpool(
|
|
7290
7273
|
this,
|
|
7291
7274
|
stakeMarketCoinName,
|
|
7292
|
-
indexer,
|
|
7275
|
+
args?.indexer,
|
|
7293
7276
|
args?.marketPool,
|
|
7294
7277
|
args?.coinPrices
|
|
7295
7278
|
);
|
|
@@ -7392,12 +7375,11 @@ var ScallopQuery = class {
|
|
|
7392
7375
|
* @param indexer - Whether to use indexer.
|
|
7393
7376
|
* @return Borrow incentive pools data.
|
|
7394
7377
|
*/
|
|
7395
|
-
async getBorrowIncentivePools(coinNames,
|
|
7378
|
+
async getBorrowIncentivePools(coinNames, args) {
|
|
7396
7379
|
return await getBorrowIncentivePools(
|
|
7397
7380
|
this,
|
|
7398
7381
|
coinNames,
|
|
7399
|
-
indexer,
|
|
7400
|
-
args?.marketPools,
|
|
7382
|
+
args?.indexer,
|
|
7401
7383
|
args?.coinPrices
|
|
7402
7384
|
);
|
|
7403
7385
|
}
|
|
@@ -7419,8 +7401,8 @@ var ScallopQuery = class {
|
|
|
7419
7401
|
* @param indexer - Whether to use indexer.
|
|
7420
7402
|
* @return All lending and spool infomation.
|
|
7421
7403
|
*/
|
|
7422
|
-
async getLendings(poolCoinNames, ownerAddress = this.walletAddress,
|
|
7423
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
7404
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
7405
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
7424
7406
|
}
|
|
7425
7407
|
/**
|
|
7426
7408
|
* Get user lending and spool information for specific pool.
|
|
@@ -7430,8 +7412,8 @@ var ScallopQuery = class {
|
|
|
7430
7412
|
* @param indexer - Whether to use indexer.
|
|
7431
7413
|
* @return Lending pool data.
|
|
7432
7414
|
*/
|
|
7433
|
-
async getLending(poolCoinName, ownerAddress = this.walletAddress,
|
|
7434
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
7415
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
|
|
7416
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
7435
7417
|
}
|
|
7436
7418
|
/**
|
|
7437
7419
|
* Get user all obligation accounts information.
|
|
@@ -7443,8 +7425,8 @@ var ScallopQuery = class {
|
|
|
7443
7425
|
* @param indexer - Whether to use indexer.
|
|
7444
7426
|
* @return All obligation accounts information.
|
|
7445
7427
|
*/
|
|
7446
|
-
async getObligationAccounts(ownerAddress = this.walletAddress,
|
|
7447
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
7428
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
7429
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
7448
7430
|
}
|
|
7449
7431
|
/**
|
|
7450
7432
|
* Get obligation account information for specific id.
|
|
@@ -7457,12 +7439,12 @@ var ScallopQuery = class {
|
|
|
7457
7439
|
* @param indexer - Whether to use indexer.
|
|
7458
7440
|
* @return Borrowing and collateral information.
|
|
7459
7441
|
*/
|
|
7460
|
-
async getObligationAccount(obligationId, ownerAddress = this.walletAddress,
|
|
7442
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
|
|
7461
7443
|
return await getObligationAccount(
|
|
7462
7444
|
this,
|
|
7463
7445
|
obligationId,
|
|
7464
7446
|
ownerAddress,
|
|
7465
|
-
indexer
|
|
7447
|
+
args?.indexer
|
|
7466
7448
|
);
|
|
7467
7449
|
}
|
|
7468
7450
|
/**
|
|
@@ -7474,8 +7456,8 @@ var ScallopQuery = class {
|
|
|
7474
7456
|
*
|
|
7475
7457
|
* @return Total value locked.
|
|
7476
7458
|
*/
|
|
7477
|
-
async getTvl(
|
|
7478
|
-
return await getTotalValueLocked(this, indexer);
|
|
7459
|
+
async getTvl(args) {
|
|
7460
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
7479
7461
|
}
|
|
7480
7462
|
/**
|
|
7481
7463
|
* Get veSca data.
|
|
@@ -7613,13 +7595,6 @@ var ScallopQuery = class {
|
|
|
7613
7595
|
async getCoinPriceByIndexer(poolName) {
|
|
7614
7596
|
return this.indexer.getCoinPrice(poolName);
|
|
7615
7597
|
}
|
|
7616
|
-
/**
|
|
7617
|
-
* Get all coin prices, including sCoin
|
|
7618
|
-
* @returns prices data
|
|
7619
|
-
*/
|
|
7620
|
-
async getAllCoinPrices(args) {
|
|
7621
|
-
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
7622
|
-
}
|
|
7623
7598
|
};
|
|
7624
7599
|
|
|
7625
7600
|
// src/models/scallopBuilder.ts
|
|
@@ -8269,46 +8244,30 @@ var ScallopClient = class {
|
|
|
8269
8244
|
}
|
|
8270
8245
|
}
|
|
8271
8246
|
/**
|
|
8272
|
-
*
|
|
8247
|
+
* unstake market coin from the specific spool.
|
|
8273
8248
|
*
|
|
8274
|
-
* @param
|
|
8249
|
+
* @param marketCoinName - Types of mak coin.
|
|
8275
8250
|
* @param amount - The amount of coins would deposit.
|
|
8276
8251
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8277
8252
|
* @param accountId - The stake account object.
|
|
8278
8253
|
* @param walletAddress - The wallet address of the owner.
|
|
8279
8254
|
* @return Transaction block response or transaction block
|
|
8280
8255
|
*/
|
|
8281
|
-
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8256
|
+
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8282
8257
|
const txBlock = this.builder.createTxBlock();
|
|
8283
8258
|
const sender = walletAddress ?? this.walletAddress;
|
|
8284
8259
|
txBlock.setSender(sender);
|
|
8285
|
-
const
|
|
8286
|
-
const
|
|
8287
|
-
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8288
|
-
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8289
|
-
).flatMap(({ coinName }) => coinName);
|
|
8290
|
-
for (const rewardCoinName of rewardCoinNames) {
|
|
8260
|
+
const rewardCoins = [];
|
|
8261
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
8291
8262
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8263
|
+
coinName,
|
|
8292
8264
|
rewardCoinName,
|
|
8293
8265
|
obligationId,
|
|
8294
8266
|
obligationKeyId
|
|
8295
8267
|
);
|
|
8296
|
-
|
|
8297
|
-
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8298
|
-
} else {
|
|
8299
|
-
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8300
|
-
}
|
|
8268
|
+
rewardCoins.push(rewardCoin);
|
|
8301
8269
|
}
|
|
8302
|
-
txBlock.transferObjects(
|
|
8303
|
-
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8304
|
-
const mergeDest = rewardCoins[0];
|
|
8305
|
-
if (rewardCoins.length > 1) {
|
|
8306
|
-
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8307
|
-
}
|
|
8308
|
-
return mergeDest;
|
|
8309
|
-
}),
|
|
8310
|
-
sender
|
|
8311
|
-
);
|
|
8270
|
+
txBlock.transferObjects(rewardCoins, sender);
|
|
8312
8271
|
if (sign) {
|
|
8313
8272
|
return await this.suiKit.signAndSendTxn(
|
|
8314
8273
|
txBlock
|
|
@@ -8618,12 +8577,12 @@ var Scallop = class {
|
|
|
8618
8577
|
UNLOCK_ROUND_DURATION,
|
|
8619
8578
|
USE_TEST_ADDRESS,
|
|
8620
8579
|
assetCoins,
|
|
8580
|
+
borrowIncentiveRewardCoins,
|
|
8621
8581
|
coinDecimals,
|
|
8622
8582
|
coinIds,
|
|
8623
8583
|
marketCoins,
|
|
8624
8584
|
queryKeys,
|
|
8625
8585
|
sCoinIds,
|
|
8626
|
-
sCoinRawNameToName,
|
|
8627
8586
|
sCoinTypeToName,
|
|
8628
8587
|
sCoins,
|
|
8629
8588
|
spoolRewardCoins,
|