@scallop-io/sui-scallop-sdk 0.44.6 → 0.44.7
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/index.js +90 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -25
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +1 -1
- package/dist/models/scallopQuery.d.ts +2 -0
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -0
- package/dist/types/query/portfolio.d.ts +2 -0
- package/dist/utils/query.d.ts +8 -0
- package/package.json +1 -1
- package/src/constants/common.ts +1 -1
- package/src/constants/enum.ts +1 -0
- package/src/models/scallopClient.ts +36 -1
- package/src/queries/portfolioQuery.ts +73 -40
- package/src/types/query/portfolio.ts +2 -0
- package/src/utils/query.ts +26 -0
|
@@ -6,7 +6,7 @@ export declare const SUPPORT_POOLS: readonly ["eth", "btc", "usdc", "usdt", "sui
|
|
|
6
6
|
export declare const SUPPORT_COLLATERALS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus", "afsui", "hasui", "vsui"];
|
|
7
7
|
export declare const SUPPORT_SPOOLS: readonly ["ssui", "susdc", "susdt"];
|
|
8
8
|
export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
|
|
9
|
-
export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "usdc"];
|
|
9
|
+
export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "usdc", "usdt"];
|
|
10
10
|
export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["sui"];
|
|
11
11
|
export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
|
|
12
12
|
export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "protocolWhitelist", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];
|
package/dist/index.js
CHANGED
|
@@ -93,7 +93,7 @@ var SUPPORT_COLLATERALS = [
|
|
|
93
93
|
];
|
|
94
94
|
var SUPPORT_SPOOLS = ["ssui", "susdc", "susdt"];
|
|
95
95
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
96
|
-
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc"];
|
|
96
|
+
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc", "usdt"];
|
|
97
97
|
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
98
98
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
99
99
|
var SUPPORT_PACKAGES = [
|
|
@@ -174,7 +174,8 @@ var spoolRewardCoins = {
|
|
|
174
174
|
};
|
|
175
175
|
var borrowIncentiveRewardCoins = {
|
|
176
176
|
sui: "sui",
|
|
177
|
-
usdc: "sui"
|
|
177
|
+
usdc: "sui",
|
|
178
|
+
usdt: "sui"
|
|
178
179
|
};
|
|
179
180
|
var coinIds = {
|
|
180
181
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -1115,6 +1116,16 @@ var minBigNumber = (...args) => {
|
|
|
1115
1116
|
)
|
|
1116
1117
|
);
|
|
1117
1118
|
};
|
|
1119
|
+
var estimatedFactor = (amount, scaleStep, type) => {
|
|
1120
|
+
const amountOfDigits = Math.max(
|
|
1121
|
+
1,
|
|
1122
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
1123
|
+
);
|
|
1124
|
+
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
1125
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
1126
|
+
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
1127
|
+
return adjustFactor;
|
|
1128
|
+
};
|
|
1118
1129
|
|
|
1119
1130
|
// src/utils/util.ts
|
|
1120
1131
|
var isMarketCoin = (coinName) => {
|
|
@@ -2380,8 +2391,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2380
2391
|
);
|
|
2381
2392
|
return assetCoinName === collateralCoinName;
|
|
2382
2393
|
});
|
|
2383
|
-
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2384
2394
|
const marketCollateral = market.collaterals[assetCoinName];
|
|
2395
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2385
2396
|
const coinPrice = coinPrices?.[assetCoinName];
|
|
2386
2397
|
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
2387
2398
|
if (marketCollateral && coinPrice) {
|
|
@@ -2431,20 +2442,23 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2431
2442
|
);
|
|
2432
2443
|
return assetCoinName === poolCoinName;
|
|
2433
2444
|
});
|
|
2434
|
-
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2435
2445
|
const marketPool = market.pools[assetCoinName];
|
|
2446
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
2436
2447
|
const coinPrice = coinPrices?.[assetCoinName];
|
|
2448
|
+
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
2437
2449
|
if (marketPool && coinPrice) {
|
|
2438
2450
|
const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
|
|
2439
2451
|
const borrowedAmount = (0, import_bignumber3.default)(debt?.amount ?? 0);
|
|
2440
2452
|
const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
|
|
2441
|
-
const
|
|
2453
|
+
const requiredRepayAmount = borrowedAmount.multipliedBy(
|
|
2442
2454
|
increasedRate + 1
|
|
2443
2455
|
);
|
|
2456
|
+
const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
|
|
2457
|
+
const availableRepayAmount = (0, import_bignumber3.default)(coinAmount);
|
|
2444
2458
|
const availableRepayCoin = availableRepayAmount.shiftedBy(
|
|
2445
2459
|
-1 * coinDecimal
|
|
2446
2460
|
);
|
|
2447
|
-
const borrowedValue =
|
|
2461
|
+
const borrowedValue = requiredRepayCoin.multipliedBy(coinPrice);
|
|
2448
2462
|
const borrowedValueWithWeight = borrowedValue.multipliedBy(
|
|
2449
2463
|
marketPool.borrowWeight
|
|
2450
2464
|
);
|
|
@@ -2466,6 +2480,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2466
2480
|
borrowedValue: borrowedValue.toNumber(),
|
|
2467
2481
|
borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
|
|
2468
2482
|
borrowIndex: Number(debt?.borrowIndex ?? 0),
|
|
2483
|
+
requiredRepayAmount: requiredRepayAmount.toNumber(),
|
|
2484
|
+
requiredRepayCoin: requiredRepayCoin.toNumber(),
|
|
2469
2485
|
availableBorrowAmount: 0,
|
|
2470
2486
|
availableBorrowCoin: 0,
|
|
2471
2487
|
availableRepayAmount: availableRepayAmount.toNumber(),
|
|
@@ -2508,8 +2524,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2508
2524
|
}
|
|
2509
2525
|
}
|
|
2510
2526
|
}
|
|
2511
|
-
let riskLevel = totalRequiredCollateralValue.isZero()
|
|
2512
|
-
riskLevel = riskLevel.
|
|
2527
|
+
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
2528
|
+
riskLevel = riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber3.default)(1);
|
|
2513
2529
|
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber3.default)(0);
|
|
2514
2530
|
const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0, import_bignumber3.default)(0);
|
|
2515
2531
|
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber3.default)(0);
|
|
@@ -2544,13 +2560,25 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2544
2560
|
)) {
|
|
2545
2561
|
const marketCollateral = market.collaterals[collateralCoinName];
|
|
2546
2562
|
if (marketCollateral) {
|
|
2547
|
-
|
|
2548
|
-
|
|
2563
|
+
let estimatedAvailableWithdrawAmount = (0, import_bignumber3.default)(
|
|
2564
|
+
obligationAccount.totalAvailableCollateralValue
|
|
2565
|
+
).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).shiftedBy(marketCollateral.coinDecimal);
|
|
2566
|
+
estimatedAvailableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? (
|
|
2567
|
+
// Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
|
|
2568
|
+
(0, import_bignumber3.default)(obligationCollateral.depositedAmount)
|
|
2569
|
+
) : minBigNumber(
|
|
2570
|
+
estimatedAvailableWithdrawAmount.multipliedBy(
|
|
2571
|
+
estimatedFactor(
|
|
2572
|
+
(0, import_bignumber3.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).toNumber(),
|
|
2573
|
+
3,
|
|
2574
|
+
"increase"
|
|
2575
|
+
)
|
|
2576
|
+
).toNumber(),
|
|
2549
2577
|
obligationCollateral.depositedAmount,
|
|
2550
2578
|
marketCollateral.depositAmount
|
|
2551
2579
|
);
|
|
2552
|
-
obligationCollateral.availableWithdrawAmount =
|
|
2553
|
-
obligationCollateral.availableWithdrawCoin =
|
|
2580
|
+
obligationCollateral.availableWithdrawAmount = estimatedAvailableWithdrawAmount.toNumber();
|
|
2581
|
+
obligationCollateral.availableWithdrawCoin = estimatedAvailableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
2554
2582
|
}
|
|
2555
2583
|
}
|
|
2556
2584
|
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
@@ -2558,21 +2586,28 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2558
2586
|
)) {
|
|
2559
2587
|
const marketPool = market.pools[poolCoinName];
|
|
2560
2588
|
if (marketPool) {
|
|
2561
|
-
const
|
|
2562
|
-
obligationDebt.
|
|
2563
|
-
).multipliedBy(
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2589
|
+
const estimatedRequiredRepayAmount = (0, import_bignumber3.default)(
|
|
2590
|
+
obligationDebt.requiredRepayAmount
|
|
2591
|
+
).multipliedBy(
|
|
2592
|
+
estimatedFactor(obligationDebt.borrowedValue, 3, "decrease")
|
|
2593
|
+
);
|
|
2594
|
+
let estimatedAvailableBorrowAmount = (0, import_bignumber3.default)(
|
|
2595
|
+
obligationAccount.totalAvailableCollateralValue
|
|
2596
|
+
).dividedBy(marketPool.borrowWeight).shiftedBy(marketPool.coinDecimal).dividedBy(marketPool.coinPrice);
|
|
2597
|
+
estimatedAvailableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
|
|
2598
|
+
estimatedAvailableBorrowAmount.multipliedBy(
|
|
2599
|
+
estimatedFactor(
|
|
2600
|
+
estimatedAvailableBorrowAmount.shiftedBy(-1 * marketPool.coinDecimal).multipliedBy(marketPool.coinPrice).toNumber(),
|
|
2601
|
+
3,
|
|
2602
|
+
"increase"
|
|
2568
2603
|
)
|
|
2569
|
-
).
|
|
2604
|
+
).toNumber(),
|
|
2570
2605
|
marketPool.supplyAmount
|
|
2571
2606
|
) : (0, import_bignumber3.default)(0);
|
|
2572
|
-
obligationDebt.availableBorrowAmount =
|
|
2573
|
-
obligationDebt.availableBorrowCoin =
|
|
2574
|
-
obligationDebt.
|
|
2575
|
-
obligationDebt.
|
|
2607
|
+
obligationDebt.availableBorrowAmount = estimatedAvailableBorrowAmount.toNumber();
|
|
2608
|
+
obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
2609
|
+
obligationDebt.requiredRepayAmount = estimatedRequiredRepayAmount.toNumber();
|
|
2610
|
+
obligationDebt.requiredRepayCoin = estimatedRequiredRepayAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
2576
2611
|
}
|
|
2577
2612
|
}
|
|
2578
2613
|
return obligationAccount;
|
|
@@ -4414,6 +4449,14 @@ var ScallopClient = class {
|
|
|
4414
4449
|
const txBlock = this.builder.createTxBlock();
|
|
4415
4450
|
const sender = walletAddress || this.walletAddress;
|
|
4416
4451
|
txBlock.setSender(sender);
|
|
4452
|
+
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
4453
|
+
if (sign && availableStake) {
|
|
4454
|
+
await txBlock.unstakeObligationQuick(
|
|
4455
|
+
poolCoinName,
|
|
4456
|
+
obligationId,
|
|
4457
|
+
obligationKey
|
|
4458
|
+
);
|
|
4459
|
+
}
|
|
4417
4460
|
const coin = await txBlock.borrowQuick(
|
|
4418
4461
|
amount,
|
|
4419
4462
|
poolCoinName,
|
|
@@ -4421,6 +4464,13 @@ var ScallopClient = class {
|
|
|
4421
4464
|
obligationKey
|
|
4422
4465
|
);
|
|
4423
4466
|
txBlock.transferObjects([coin], sender);
|
|
4467
|
+
if (sign && availableStake) {
|
|
4468
|
+
await txBlock.stakeObligationQuick(
|
|
4469
|
+
poolCoinName,
|
|
4470
|
+
obligationId,
|
|
4471
|
+
obligationKey
|
|
4472
|
+
);
|
|
4473
|
+
}
|
|
4424
4474
|
if (sign) {
|
|
4425
4475
|
return await this.suiKit.signAndSendTxn(
|
|
4426
4476
|
txBlock
|
|
@@ -4439,11 +4489,26 @@ var ScallopClient = class {
|
|
|
4439
4489
|
* @param walletAddress - The wallet address of the owner.
|
|
4440
4490
|
* @return Transaction block response or transaction block.
|
|
4441
4491
|
*/
|
|
4442
|
-
async repay(poolCoinName, amount, sign = true, obligationId, walletAddress) {
|
|
4492
|
+
async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
4443
4493
|
const txBlock = this.builder.createTxBlock();
|
|
4444
4494
|
const sender = walletAddress || this.walletAddress;
|
|
4445
4495
|
txBlock.setSender(sender);
|
|
4496
|
+
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
4497
|
+
if (sign && availableStake) {
|
|
4498
|
+
await txBlock.unstakeObligationQuick(
|
|
4499
|
+
poolCoinName,
|
|
4500
|
+
obligationId,
|
|
4501
|
+
obligationKey
|
|
4502
|
+
);
|
|
4503
|
+
}
|
|
4446
4504
|
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
4505
|
+
if (sign && availableStake) {
|
|
4506
|
+
await txBlock.stakeObligationQuick(
|
|
4507
|
+
poolCoinName,
|
|
4508
|
+
obligationId,
|
|
4509
|
+
obligationKey
|
|
4510
|
+
);
|
|
4511
|
+
}
|
|
4447
4512
|
if (sign) {
|
|
4448
4513
|
return await this.suiKit.signAndSendTxn(
|
|
4449
4514
|
txBlock
|