@scallop-io/sui-scallop-sdk 0.46.3 → 0.46.32
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/index.js +104 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -88
- package/dist/index.mjs.map +1 -1
- package/dist/types/query/borrowIncentive.d.ts +3 -4
- package/dist/utils/query.d.ts +1 -1
- package/package.json +3 -2
- package/src/builders/vescaBuilder.ts +0 -5
- package/src/models/scallopIndexer.ts +16 -0
- package/src/queries/borrowIncentiveQuery.ts +33 -27
- package/src/queries/portfolioQuery.ts +13 -11
- package/src/types/query/borrowIncentive.ts +3 -4
- package/src/utils/query.ts +1 -9
package/dist/index.js
CHANGED
|
@@ -1474,7 +1474,7 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
|
1474
1474
|
)
|
|
1475
1475
|
};
|
|
1476
1476
|
};
|
|
1477
|
-
var calculateBorrowIncentivePoolPointData = (
|
|
1477
|
+
var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolData, parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
1478
1478
|
const baseIndexRate = 1e9;
|
|
1479
1479
|
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
1480
1480
|
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
@@ -1496,9 +1496,6 @@ var calculateBorrowIncentivePoolPointData = (pasredBorrowIncentinvePoolData, par
|
|
|
1496
1496
|
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1497
1497
|
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
1498
1498
|
).plus(accumulatedPoints);
|
|
1499
|
-
const stakedAmount = (0, import_bignumber.default)(pasredBorrowIncentinvePoolData.staked);
|
|
1500
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
1501
|
-
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
1502
1499
|
const baseWeight = (0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
1503
1500
|
const weightedStakedAmount = (0, import_bignumber.default)(
|
|
1504
1501
|
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
@@ -1527,9 +1524,6 @@ var calculateBorrowIncentivePoolPointData = (pasredBorrowIncentinvePoolData, par
|
|
|
1527
1524
|
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1528
1525
|
currentPointIndex: currentPointIndex.toNumber(),
|
|
1529
1526
|
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1530
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
1531
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
1532
|
-
stakedValue: stakedValue.toNumber(),
|
|
1533
1527
|
baseWeight: baseWeight.toNumber(),
|
|
1534
1528
|
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
1535
1529
|
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
@@ -2544,6 +2538,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2544
2538
|
|
|
2545
2539
|
// src/queries/borrowIncentiveQuery.ts
|
|
2546
2540
|
var import_utils6 = require("@mysten/sui.js/utils");
|
|
2541
|
+
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
2547
2542
|
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
|
|
2548
2543
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2549
2544
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
@@ -2555,19 +2550,29 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2555
2550
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2556
2551
|
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2557
2552
|
const borrowIncentivePools = {};
|
|
2553
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
2554
|
+
[
|
|
2555
|
+
.../* @__PURE__ */ new Set([
|
|
2556
|
+
...borrowIncentiveCoinNames,
|
|
2557
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
2558
|
+
])
|
|
2559
|
+
]
|
|
2560
|
+
);
|
|
2558
2561
|
if (indexer) {
|
|
2562
|
+
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2563
|
+
for (const borrowIncentivePool of Object.values(
|
|
2564
|
+
borrowIncentivePoolsIndexer
|
|
2565
|
+
)) {
|
|
2566
|
+
if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
|
|
2567
|
+
continue;
|
|
2568
|
+
borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
|
|
2569
|
+
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
2570
|
+
}
|
|
2571
|
+
return borrowIncentivePools;
|
|
2559
2572
|
}
|
|
2560
2573
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2561
2574
|
const borrowIncentivePoolPoints = {};
|
|
2562
2575
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2563
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
2564
|
-
[
|
|
2565
|
-
.../* @__PURE__ */ new Set([
|
|
2566
|
-
...borrowIncentiveCoinNames,
|
|
2567
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
2568
|
-
])
|
|
2569
|
-
]
|
|
2570
|
-
);
|
|
2571
2576
|
const poolCoinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
|
|
2572
2577
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2573
2578
|
poolCoinType
|
|
@@ -2608,14 +2613,19 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2608
2613
|
...calculatedPoolPoint
|
|
2609
2614
|
};
|
|
2610
2615
|
}
|
|
2616
|
+
const stakedAmount = (0, import_bignumber3.default)(parsedBorrowIncentivePoolData.staked);
|
|
2617
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
2618
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
2611
2619
|
borrowIncentivePools[poolCoinName] = {
|
|
2612
2620
|
coinName: poolCoinName,
|
|
2613
2621
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
2614
2622
|
coinType: poolCoinType,
|
|
2615
2623
|
coinDecimal: poolCoinDecimal,
|
|
2616
2624
|
coinPrice: poolCoinPrice,
|
|
2617
|
-
|
|
2618
|
-
|
|
2625
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
2626
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
2627
|
+
stakedValue: stakedValue.toNumber(),
|
|
2628
|
+
points: borrowIncentivePoolPoints
|
|
2619
2629
|
};
|
|
2620
2630
|
}
|
|
2621
2631
|
return borrowIncentivePools;
|
|
@@ -2762,7 +2772,7 @@ var getPythPrices = async (query, assetCoinNames) => {
|
|
|
2762
2772
|
};
|
|
2763
2773
|
|
|
2764
2774
|
// src/queries/portfolioQuery.ts
|
|
2765
|
-
var
|
|
2775
|
+
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
2766
2776
|
var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) => {
|
|
2767
2777
|
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
2768
2778
|
const marketCoinNames = poolCoinNames.map(
|
|
@@ -2813,18 +2823,18 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
2813
2823
|
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
2814
2824
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2815
2825
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2816
|
-
let stakedMarketAmount = (0,
|
|
2817
|
-
let stakedMarketCoin = (0,
|
|
2818
|
-
let stakedAmount = (0,
|
|
2819
|
-
let stakedCoin = (0,
|
|
2820
|
-
let stakedValue = (0,
|
|
2821
|
-
let availableUnstakeAmount = (0,
|
|
2822
|
-
let availableUnstakeCoin = (0,
|
|
2823
|
-
let availableClaimAmount = (0,
|
|
2824
|
-
let availableClaimCoin = (0,
|
|
2826
|
+
let stakedMarketAmount = (0, import_bignumber4.default)(0);
|
|
2827
|
+
let stakedMarketCoin = (0, import_bignumber4.default)(0);
|
|
2828
|
+
let stakedAmount = (0, import_bignumber4.default)(0);
|
|
2829
|
+
let stakedCoin = (0, import_bignumber4.default)(0);
|
|
2830
|
+
let stakedValue = (0, import_bignumber4.default)(0);
|
|
2831
|
+
let availableUnstakeAmount = (0, import_bignumber4.default)(0);
|
|
2832
|
+
let availableUnstakeCoin = (0, import_bignumber4.default)(0);
|
|
2833
|
+
let availableClaimAmount = (0, import_bignumber4.default)(0);
|
|
2834
|
+
let availableClaimCoin = (0, import_bignumber4.default)(0);
|
|
2825
2835
|
if (spool) {
|
|
2826
2836
|
for (const stakeAccount of stakeAccounts) {
|
|
2827
|
-
const accountStakedMarketCoinAmount = (0,
|
|
2837
|
+
const accountStakedMarketCoinAmount = (0, import_bignumber4.default)(stakeAccount.staked);
|
|
2828
2838
|
const accountStakedMarketCoin = accountStakedMarketCoinAmount.shiftedBy(
|
|
2829
2839
|
-1 * spool.coinDecimal
|
|
2830
2840
|
);
|
|
@@ -2851,7 +2861,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
2851
2861
|
-1 * spool.coinDecimal
|
|
2852
2862
|
);
|
|
2853
2863
|
const baseIndexRate = 1e9;
|
|
2854
|
-
const increasedPointRate = spool.currentPointIndex ? (0,
|
|
2864
|
+
const increasedPointRate = spool.currentPointIndex ? (0, import_bignumber4.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
2855
2865
|
baseIndexRate
|
|
2856
2866
|
) : 1;
|
|
2857
2867
|
availableClaimAmount = availableClaimAmount.plus(
|
|
@@ -2862,17 +2872,17 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
2862
2872
|
);
|
|
2863
2873
|
}
|
|
2864
2874
|
}
|
|
2865
|
-
const suppliedAmount = (0,
|
|
2875
|
+
const suppliedAmount = (0, import_bignumber4.default)(marketCoinAmount).multipliedBy(
|
|
2866
2876
|
marketPool?.conversionRate ?? 1
|
|
2867
2877
|
);
|
|
2868
2878
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
2869
2879
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
2870
|
-
const marketCoinPrice = (0,
|
|
2880
|
+
const marketCoinPrice = (0, import_bignumber4.default)(coinPrice ?? 0).multipliedBy(
|
|
2871
2881
|
marketPool?.conversionRate ?? 1
|
|
2872
2882
|
);
|
|
2873
|
-
const unstakedMarketAmount = (0,
|
|
2883
|
+
const unstakedMarketAmount = (0, import_bignumber4.default)(marketCoinAmount);
|
|
2874
2884
|
const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
|
|
2875
|
-
const availableSupplyAmount = (0,
|
|
2885
|
+
const availableSupplyAmount = (0, import_bignumber4.default)(coinAmount);
|
|
2876
2886
|
const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
|
|
2877
2887
|
const availableWithdrawAmount = minBigNumber(
|
|
2878
2888
|
suppliedAmount,
|
|
@@ -2926,17 +2936,19 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
2926
2936
|
const coinAmounts = await query.getCoinAmounts(void 0, ownerAddress);
|
|
2927
2937
|
const obligations = await query.getObligations(ownerAddress);
|
|
2928
2938
|
const obligationAccounts = {};
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2939
|
+
await Promise.allSettled(
|
|
2940
|
+
obligations.map(async (obligation) => {
|
|
2941
|
+
obligationAccounts[obligation.keyId] = await getObligationAccount(
|
|
2942
|
+
query,
|
|
2943
|
+
obligation.id,
|
|
2944
|
+
ownerAddress,
|
|
2945
|
+
indexer,
|
|
2946
|
+
market,
|
|
2947
|
+
coinPrices,
|
|
2948
|
+
coinAmounts
|
|
2949
|
+
);
|
|
2950
|
+
})
|
|
2951
|
+
);
|
|
2940
2952
|
return obligationAccounts;
|
|
2941
2953
|
};
|
|
2942
2954
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
@@ -2960,12 +2972,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2960
2972
|
const debts = {};
|
|
2961
2973
|
const borrowIncentives = {};
|
|
2962
2974
|
let totalDepositedPools = 0;
|
|
2963
|
-
let totalDepositedValue = (0,
|
|
2964
|
-
let totalBorrowCapacityValue = (0,
|
|
2965
|
-
let totalRequiredCollateralValue = (0,
|
|
2975
|
+
let totalDepositedValue = (0, import_bignumber4.default)(0);
|
|
2976
|
+
let totalBorrowCapacityValue = (0, import_bignumber4.default)(0);
|
|
2977
|
+
let totalRequiredCollateralValue = (0, import_bignumber4.default)(0);
|
|
2966
2978
|
let totalBorrowedPools = 0;
|
|
2967
|
-
let totalBorrowedValue = (0,
|
|
2968
|
-
let totalBorrowedValueWithWeight = (0,
|
|
2979
|
+
let totalBorrowedValue = (0, import_bignumber4.default)(0);
|
|
2980
|
+
let totalBorrowedValueWithWeight = (0, import_bignumber4.default)(0);
|
|
2969
2981
|
for (const assetCoinName of collateralAssetCoinNames) {
|
|
2970
2982
|
const collateral = obligationQuery.collaterals.find((collateral2) => {
|
|
2971
2983
|
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
@@ -2978,7 +2990,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2978
2990
|
const coinPrice = coinPrices?.[assetCoinName];
|
|
2979
2991
|
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
2980
2992
|
if (marketCollateral && coinPrice) {
|
|
2981
|
-
const depositedAmount = (0,
|
|
2993
|
+
const depositedAmount = (0, import_bignumber4.default)(collateral?.amount ?? 0);
|
|
2982
2994
|
const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
|
|
2983
2995
|
const depositedValue = depositedCoin.multipliedBy(coinPrice);
|
|
2984
2996
|
const borrowCapacityValue = depositedValue.multipliedBy(
|
|
@@ -2987,11 +2999,11 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
2987
2999
|
const requiredCollateralValue2 = depositedValue.multipliedBy(
|
|
2988
3000
|
marketCollateral.liquidationFactor
|
|
2989
3001
|
);
|
|
2990
|
-
const poolSizeAmount = (0,
|
|
3002
|
+
const poolSizeAmount = (0, import_bignumber4.default)(marketCollateral.maxDepositAmount).minus(
|
|
2991
3003
|
marketCollateral.depositAmount
|
|
2992
3004
|
);
|
|
2993
3005
|
const availableDepositAmount = minBigNumber(
|
|
2994
|
-
(0,
|
|
3006
|
+
(0, import_bignumber4.default)(coinAmount),
|
|
2995
3007
|
poolSizeAmount
|
|
2996
3008
|
);
|
|
2997
3009
|
const availableDepositCoin = availableDepositAmount.shiftedBy(
|
|
@@ -3039,13 +3051,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3039
3051
|
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
3040
3052
|
if (marketPool && coinPrice) {
|
|
3041
3053
|
const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
|
|
3042
|
-
const borrowedAmount = (0,
|
|
3054
|
+
const borrowedAmount = (0, import_bignumber4.default)(debt?.amount ?? 0);
|
|
3043
3055
|
const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
|
|
3044
3056
|
const requiredRepayAmount = borrowedAmount.multipliedBy(
|
|
3045
3057
|
increasedRate + 1
|
|
3046
3058
|
);
|
|
3047
3059
|
const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
|
|
3048
|
-
const availableRepayAmount = (0,
|
|
3060
|
+
const availableRepayAmount = (0, import_bignumber4.default)(coinAmount);
|
|
3049
3061
|
const availableRepayCoin = availableRepayAmount.shiftedBy(
|
|
3050
3062
|
-1 * coinDecimal
|
|
3051
3063
|
);
|
|
@@ -3091,11 +3103,11 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3091
3103
|
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
3092
3104
|
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
3093
3105
|
if (accountPoint && poolPoint) {
|
|
3094
|
-
let availableClaimAmount = (0,
|
|
3095
|
-
let availableClaimCoin = (0,
|
|
3096
|
-
const accountBorrowedAmount = (0,
|
|
3106
|
+
let availableClaimAmount = (0, import_bignumber4.default)(0);
|
|
3107
|
+
let availableClaimCoin = (0, import_bignumber4.default)(0);
|
|
3108
|
+
const accountBorrowedAmount = (0, import_bignumber4.default)(accountPoint.weightedAmount);
|
|
3097
3109
|
const baseIndexRate = 1e9;
|
|
3098
|
-
const increasedPointRate = poolPoint.currentPointIndex ? (0,
|
|
3110
|
+
const increasedPointRate = poolPoint.currentPointIndex ? (0, import_bignumber4.default)(
|
|
3099
3111
|
poolPoint.currentPointIndex - accountPoint.index
|
|
3100
3112
|
).dividedBy(baseIndexRate) : 1;
|
|
3101
3113
|
availableClaimAmount = availableClaimAmount.plus(
|
|
@@ -3104,11 +3116,11 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3104
3116
|
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3105
3117
|
-1 * poolPoint.coinDecimal
|
|
3106
3118
|
);
|
|
3107
|
-
const weightScale = (0,
|
|
3108
|
-
const boostValue = (0,
|
|
3109
|
-
(0,
|
|
3110
|
-
).isFinite() ? (0,
|
|
3111
|
-
(0,
|
|
3119
|
+
const weightScale = (0, import_bignumber4.default)(1e12);
|
|
3120
|
+
const boostValue = (0, import_bignumber4.default)(accountPoint.weightedAmount).div(
|
|
3121
|
+
(0, import_bignumber4.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3122
|
+
).isFinite() ? (0, import_bignumber4.default)(accountPoint.weightedAmount).div(
|
|
3123
|
+
(0, import_bignumber4.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3112
3124
|
).toNumber() : 1;
|
|
3113
3125
|
if (availableClaimAmount.isGreaterThan(0)) {
|
|
3114
3126
|
rewards.push({
|
|
@@ -3134,12 +3146,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3134
3146
|
};
|
|
3135
3147
|
}
|
|
3136
3148
|
}
|
|
3137
|
-
let riskLevel = totalRequiredCollateralValue.isZero() ? (0,
|
|
3138
|
-
riskLevel = riskLevel.isLessThan(1) ? riskLevel : (0,
|
|
3139
|
-
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0,
|
|
3140
|
-
const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0,
|
|
3141
|
-
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0,
|
|
3142
|
-
const unhealthyCollateralValue = totalBorrowedValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalBorrowedValueWithWeight.minus(requiredCollateralValue) : (0,
|
|
3149
|
+
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber4.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
3150
|
+
riskLevel = riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber4.default)(1);
|
|
3151
|
+
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber4.default)(0);
|
|
3152
|
+
const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0, import_bignumber4.default)(0);
|
|
3153
|
+
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber4.default)(0);
|
|
3154
|
+
const unhealthyCollateralValue = totalBorrowedValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalBorrowedValueWithWeight.minus(requiredCollateralValue) : (0, import_bignumber4.default)(0);
|
|
3143
3155
|
const obligationAccount = {
|
|
3144
3156
|
obligationId,
|
|
3145
3157
|
// Deposited collateral value (collateral balance)
|
|
@@ -3170,16 +3182,16 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3170
3182
|
)) {
|
|
3171
3183
|
const marketCollateral = market.collaterals[collateralCoinName];
|
|
3172
3184
|
if (marketCollateral) {
|
|
3173
|
-
let estimatedAvailableWithdrawAmount = (0,
|
|
3185
|
+
let estimatedAvailableWithdrawAmount = (0, import_bignumber4.default)(
|
|
3174
3186
|
obligationAccount.totalAvailableCollateralValue
|
|
3175
3187
|
).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).shiftedBy(marketCollateral.coinDecimal);
|
|
3176
3188
|
estimatedAvailableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? (
|
|
3177
3189
|
// Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
|
|
3178
|
-
(0,
|
|
3190
|
+
(0, import_bignumber4.default)(obligationCollateral.depositedAmount)
|
|
3179
3191
|
) : minBigNumber(
|
|
3180
3192
|
estimatedAvailableWithdrawAmount.multipliedBy(
|
|
3181
3193
|
estimatedFactor(
|
|
3182
|
-
(0,
|
|
3194
|
+
(0, import_bignumber4.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).toNumber(),
|
|
3183
3195
|
3,
|
|
3184
3196
|
"increase"
|
|
3185
3197
|
)
|
|
@@ -3196,12 +3208,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3196
3208
|
)) {
|
|
3197
3209
|
const marketPool = market.pools[poolCoinName];
|
|
3198
3210
|
if (marketPool) {
|
|
3199
|
-
const estimatedRequiredRepayAmount = (0,
|
|
3211
|
+
const estimatedRequiredRepayAmount = (0, import_bignumber4.default)(
|
|
3200
3212
|
obligationDebt.requiredRepayAmount
|
|
3201
3213
|
).multipliedBy(
|
|
3202
3214
|
estimatedFactor(obligationDebt.borrowedValue, 3, "decrease")
|
|
3203
3215
|
);
|
|
3204
|
-
let estimatedAvailableBorrowAmount = (0,
|
|
3216
|
+
let estimatedAvailableBorrowAmount = (0, import_bignumber4.default)(
|
|
3205
3217
|
obligationAccount.totalAvailableCollateralValue
|
|
3206
3218
|
).dividedBy(marketPool.borrowWeight).shiftedBy(marketPool.coinDecimal).dividedBy(marketPool.coinPrice);
|
|
3207
3219
|
estimatedAvailableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
|
|
@@ -3213,7 +3225,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3213
3225
|
)
|
|
3214
3226
|
).toNumber(),
|
|
3215
3227
|
marketPool.supplyAmount
|
|
3216
|
-
) : (0,
|
|
3228
|
+
) : (0, import_bignumber4.default)(0);
|
|
3217
3229
|
obligationDebt.availableBorrowAmount = estimatedAvailableBorrowAmount.toNumber();
|
|
3218
3230
|
obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
3219
3231
|
obligationDebt.requiredRepayAmount = estimatedRequiredRepayAmount.toNumber();
|
|
@@ -3224,8 +3236,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3224
3236
|
};
|
|
3225
3237
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
3226
3238
|
const market = await query.queryMarket(indexer);
|
|
3227
|
-
let supplyValue = (0,
|
|
3228
|
-
let borrowValue = (0,
|
|
3239
|
+
let supplyValue = (0, import_bignumber4.default)(0);
|
|
3240
|
+
let borrowValue = (0, import_bignumber4.default)(0);
|
|
3229
3241
|
if (indexer) {
|
|
3230
3242
|
const tvlIndexer = await query.indexer.getTotalValueLocked();
|
|
3231
3243
|
const tvl2 = {
|
|
@@ -3240,15 +3252,15 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
3240
3252
|
}
|
|
3241
3253
|
for (const pool of Object.values(market.pools)) {
|
|
3242
3254
|
supplyValue = supplyValue.plus(
|
|
3243
|
-
(0,
|
|
3255
|
+
(0, import_bignumber4.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
|
|
3244
3256
|
);
|
|
3245
3257
|
borrowValue = borrowValue.plus(
|
|
3246
|
-
(0,
|
|
3258
|
+
(0, import_bignumber4.default)(pool.borrowCoin).multipliedBy(pool.coinPrice)
|
|
3247
3259
|
);
|
|
3248
3260
|
}
|
|
3249
3261
|
for (const collateral of Object.values(market.collaterals)) {
|
|
3250
3262
|
supplyValue = supplyValue.plus(
|
|
3251
|
-
(0,
|
|
3263
|
+
(0, import_bignumber4.default)(collateral.depositCoin).multipliedBy(collateral.coinPrice)
|
|
3252
3264
|
);
|
|
3253
3265
|
}
|
|
3254
3266
|
const tvl = {
|
|
@@ -3260,7 +3272,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
3260
3272
|
};
|
|
3261
3273
|
|
|
3262
3274
|
// src/queries/vescaQuery.ts
|
|
3263
|
-
var
|
|
3275
|
+
var import_bignumber5 = __toESM(require("bignumber.js"));
|
|
3264
3276
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
3265
3277
|
var import_bcs = require("@mysten/sui.js/bcs");
|
|
3266
3278
|
var getVescaKeys = async (query, ownerAddress) => {
|
|
@@ -3321,7 +3333,7 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3321
3333
|
0
|
|
3322
3334
|
);
|
|
3323
3335
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
3324
|
-
const lockedScaCoin = (0,
|
|
3336
|
+
const lockedScaCoin = (0, import_bignumber5.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
3325
3337
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
3326
3338
|
vesca = {
|
|
3327
3339
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -3329,7 +3341,7 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3329
3341
|
lockedScaAmount,
|
|
3330
3342
|
lockedScaCoin,
|
|
3331
3343
|
currentVeScaBalance,
|
|
3332
|
-
unlockAt: (0,
|
|
3344
|
+
unlockAt: (0, import_bignumber5.default)(dynamicFields.unlock_at * 1e3).toNumber()
|
|
3333
3345
|
};
|
|
3334
3346
|
}
|
|
3335
3347
|
return vesca;
|
|
@@ -3523,6 +3535,15 @@ var ScallopIndexer = class {
|
|
|
3523
3535
|
if (response.status === 200) {
|
|
3524
3536
|
return response.data.borrowIncentivePools.reduce(
|
|
3525
3537
|
(borrowIncentivePools, borrowIncentivePool) => {
|
|
3538
|
+
if (Array.isArray(borrowIncentivePool.points)) {
|
|
3539
|
+
borrowIncentivePool.points = borrowIncentivePool.points.reduce(
|
|
3540
|
+
(prev, curr) => {
|
|
3541
|
+
prev[curr.coinName] = curr;
|
|
3542
|
+
return prev;
|
|
3543
|
+
},
|
|
3544
|
+
{}
|
|
3545
|
+
);
|
|
3546
|
+
}
|
|
3526
3547
|
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
3527
3548
|
return borrowIncentivePools;
|
|
3528
3549
|
},
|
|
@@ -5180,11 +5201,6 @@ var generateQuickVeScaMethod = ({
|
|
|
5180
5201
|
newUnlockAt,
|
|
5181
5202
|
veSca?.unlockAt
|
|
5182
5203
|
);
|
|
5183
|
-
console.log(
|
|
5184
|
-
new Date(newUnlockAt * 1e3).toLocaleString("en-CA", {
|
|
5185
|
-
hour12: true
|
|
5186
|
-
})
|
|
5187
|
-
);
|
|
5188
5204
|
const isInitialLock = !veSca?.unlockAt;
|
|
5189
5205
|
const isLockExpired = !isInitialLock && veSca.unlockAt * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
5190
5206
|
if (isInitialLock || isLockExpired) {
|