@scallop-io/sui-scallop-sdk 1.4.0 → 1.4.1
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/index.js +156 -107
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -106
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +42 -0
- package/dist/models/scallopUtils.d.ts +10 -10
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +36 -2
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/common.ts +4 -2
- package/src/constants/enum.ts +11 -16
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +18 -1
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/coreQuery.ts +4 -10
- package/src/queries/portfolioQuery.ts +65 -62
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +2 -4
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/query.ts +0 -87
package/dist/index.mjs
CHANGED
|
@@ -126,7 +126,10 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
126
126
|
"sca",
|
|
127
127
|
"usdc"
|
|
128
128
|
];
|
|
129
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
129
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
130
|
+
...SUPPORT_POOLS,
|
|
131
|
+
...SUPPORT_SCOIN
|
|
132
|
+
];
|
|
130
133
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
131
134
|
var SUPPORT_PACKAGES = [
|
|
132
135
|
"coinDecimalsRegistry",
|
|
@@ -256,18 +259,6 @@ var spoolRewardCoins = {
|
|
|
256
259
|
var suiBridgeCoins = {
|
|
257
260
|
sbeth: "sbeth"
|
|
258
261
|
};
|
|
259
|
-
var borrowIncentiveRewardCoins = {
|
|
260
|
-
usdc: ["sui", "sca"],
|
|
261
|
-
sui: ["sui", "sca"],
|
|
262
|
-
wusdc: ["sui", "sca"],
|
|
263
|
-
wusdt: ["sui", "sca"],
|
|
264
|
-
sca: ["sui", "sca"],
|
|
265
|
-
afsui: ["sui"],
|
|
266
|
-
hasui: ["sui"],
|
|
267
|
-
vsui: ["sui"],
|
|
268
|
-
weth: ["sui"],
|
|
269
|
-
sbeth: ["sui"]
|
|
270
|
-
};
|
|
271
262
|
var coinIds = {
|
|
272
263
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
273
264
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -302,10 +293,10 @@ var sCoinIds = {
|
|
|
302
293
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
303
294
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
304
295
|
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
305
|
-
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
306
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
307
296
|
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
308
297
|
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
298
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
299
|
+
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
309
300
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
310
301
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
311
302
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
@@ -322,6 +313,13 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
322
313
|
},
|
|
323
314
|
{}
|
|
324
315
|
);
|
|
316
|
+
var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
317
|
+
(acc, [coinName, coinType]) => {
|
|
318
|
+
acc[coinType.split("::")[2].toLowerCase()] = coinName;
|
|
319
|
+
return acc;
|
|
320
|
+
},
|
|
321
|
+
{}
|
|
322
|
+
);
|
|
325
323
|
|
|
326
324
|
// src/constants/flashloan.ts
|
|
327
325
|
var FlashLoanFeeObjectMap = {
|
|
@@ -2472,15 +2470,21 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
2472
2470
|
};
|
|
2473
2471
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2474
2472
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2475
|
-
], indexer = false, coinPrices) => {
|
|
2473
|
+
], indexer = false, marketPools, coinPrices) => {
|
|
2476
2474
|
const borrowIncentivePools = {};
|
|
2477
|
-
|
|
2475
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices, indexer });
|
|
2476
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2478
2477
|
if (indexer) {
|
|
2479
2478
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2480
2479
|
const updateBorrowIncentivePool = (pool) => {
|
|
2481
2480
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2482
2481
|
return;
|
|
2483
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
2482
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
2483
|
+
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2484
|
+
if (pool.points[sCoinName]) {
|
|
2485
|
+
pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2484
2488
|
borrowIncentivePools[pool.coinName] = pool;
|
|
2485
2489
|
};
|
|
2486
2490
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -2506,12 +2510,15 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2506
2510
|
for (const [coinName, poolPoint] of Object.entries(
|
|
2507
2511
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2508
2512
|
)) {
|
|
2509
|
-
const rewardCoinType =
|
|
2510
|
-
|
|
2513
|
+
const rewardCoinType = poolPoint.pointType;
|
|
2514
|
+
let rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2511
2515
|
rewardCoinType
|
|
2512
2516
|
);
|
|
2513
|
-
|
|
2517
|
+
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2518
|
+
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2519
|
+
}
|
|
2514
2520
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2521
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2515
2522
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2516
2523
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2517
2524
|
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
@@ -2944,7 +2951,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2944
2951
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
2945
2952
|
showContent: true
|
|
2946
2953
|
});
|
|
2947
|
-
coinPrices = await query.utils.getCoinPrices(
|
|
2954
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
2948
2955
|
const marketPools = {};
|
|
2949
2956
|
if (indexer) {
|
|
2950
2957
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
@@ -2977,7 +2984,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2977
2984
|
return marketPools;
|
|
2978
2985
|
};
|
|
2979
2986
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2980
|
-
coinPrice = coinPrice
|
|
2987
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName];
|
|
2981
2988
|
if (indexer) {
|
|
2982
2989
|
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
2983
2990
|
if (!marketPoolIndexer) {
|
|
@@ -3120,7 +3127,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
3120
3127
|
};
|
|
3121
3128
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3122
3129
|
const marketId = query.address.get("core.market");
|
|
3123
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3130
|
+
const coinPrices = await query.utils.getCoinPrices() ?? {};
|
|
3124
3131
|
const marketCollaterals = {};
|
|
3125
3132
|
if (indexer) {
|
|
3126
3133
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -3156,7 +3163,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
3156
3163
|
return marketCollaterals;
|
|
3157
3164
|
};
|
|
3158
3165
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3159
|
-
coinPrice = coinPrice
|
|
3166
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
|
|
3160
3167
|
if (indexer) {
|
|
3161
3168
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
3162
3169
|
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
@@ -3472,7 +3479,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3472
3479
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3473
3480
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3474
3481
|
);
|
|
3475
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3482
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
3476
3483
|
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3477
3484
|
indexer,
|
|
3478
3485
|
coinPrices
|
|
@@ -3512,7 +3519,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3512
3519
|
};
|
|
3513
3520
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3514
3521
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3515
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices(
|
|
3522
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
3516
3523
|
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3517
3524
|
indexer,
|
|
3518
3525
|
coinPrice
|
|
@@ -3670,8 +3677,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3670
3677
|
const collateralAssetCoinNames = [
|
|
3671
3678
|
...SUPPORT_COLLATERALS
|
|
3672
3679
|
];
|
|
3673
|
-
|
|
3674
|
-
|
|
3680
|
+
market = market ?? await query.queryMarket({ indexer });
|
|
3681
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3675
3682
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3676
3683
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3677
3684
|
query.queryObligation(obligationId),
|
|
@@ -3813,44 +3820,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3813
3820
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3814
3821
|
if (borrowIncentivePool) {
|
|
3815
3822
|
const rewards = [];
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
BigNumber5(
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3823
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
3824
|
+
([key, accountPoint]) => {
|
|
3825
|
+
const poolPoint = borrowIncentivePool.points[key];
|
|
3826
|
+
if (accountPoint && poolPoint) {
|
|
3827
|
+
let availableClaimAmount = BigNumber5(0);
|
|
3828
|
+
let availableClaimCoin = BigNumber5(0);
|
|
3829
|
+
const accountBorrowedAmount = BigNumber5(
|
|
3830
|
+
accountPoint.weightedAmount
|
|
3831
|
+
);
|
|
3832
|
+
const baseIndexRate = 1e9;
|
|
3833
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3834
|
+
BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3835
|
+
0
|
|
3836
|
+
) : 1;
|
|
3837
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3838
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3839
|
+
);
|
|
3840
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3841
|
+
-1 * poolPoint.coinDecimal
|
|
3842
|
+
);
|
|
3843
|
+
const weightScale = BigNumber5(1e12);
|
|
3844
|
+
const boostValue = BigNumber5(accountPoint.weightedAmount).div(
|
|
3845
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3846
|
+
).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
|
|
3847
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3848
|
+
).toNumber() : 1;
|
|
3849
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3850
|
+
rewards.push({
|
|
3851
|
+
coinName: poolPoint.coinName,
|
|
3852
|
+
coinType: poolPoint.coinType,
|
|
3853
|
+
symbol: poolPoint.symbol,
|
|
3854
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3855
|
+
coinPrice: poolPoint.coinPrice,
|
|
3856
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3857
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3858
|
+
boostValue
|
|
3859
|
+
});
|
|
3860
|
+
}
|
|
3851
3861
|
}
|
|
3852
3862
|
}
|
|
3853
|
-
|
|
3863
|
+
);
|
|
3854
3864
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3855
3865
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3856
3866
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -3994,6 +4004,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
3994
4004
|
};
|
|
3995
4005
|
|
|
3996
4006
|
// src/queries/priceQuery.ts
|
|
4007
|
+
import BigNumber6 from "bignumber.js";
|
|
3997
4008
|
var getPythPrice = async ({
|
|
3998
4009
|
address
|
|
3999
4010
|
}, assetCoinName, priceFeedObject) => {
|
|
@@ -4075,6 +4086,22 @@ var getPythPrices = async ({
|
|
|
4075
4086
|
{}
|
|
4076
4087
|
);
|
|
4077
4088
|
};
|
|
4089
|
+
var getAllCoinPrices = async (query, marketPools, coinPrices) => {
|
|
4090
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4091
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices });
|
|
4092
|
+
if (!marketPools) {
|
|
4093
|
+
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
4094
|
+
}
|
|
4095
|
+
const sCoinPrices = {};
|
|
4096
|
+
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
4097
|
+
const coinName = query.utils.parseCoinName(sCoinName);
|
|
4098
|
+
sCoinPrices[sCoinName] = BigNumber6(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
|
|
4099
|
+
});
|
|
4100
|
+
return {
|
|
4101
|
+
...coinPrices,
|
|
4102
|
+
...sCoinPrices
|
|
4103
|
+
};
|
|
4104
|
+
};
|
|
4078
4105
|
|
|
4079
4106
|
// src/queries/referralQuery.ts
|
|
4080
4107
|
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
@@ -4095,7 +4122,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4095
4122
|
// src/queries/sCoinQuery.ts
|
|
4096
4123
|
import { bcs } from "@mysten/sui/bcs";
|
|
4097
4124
|
import assert from "assert";
|
|
4098
|
-
import
|
|
4125
|
+
import BigNumber7 from "bignumber.js";
|
|
4099
4126
|
var getSCoinTotalSupply = async ({
|
|
4100
4127
|
utils
|
|
4101
4128
|
}, sCoinName) => {
|
|
@@ -4116,7 +4143,7 @@ var getSCoinTotalSupply = async ({
|
|
|
4116
4143
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4117
4144
|
const type = results[0].returnValues[0][1];
|
|
4118
4145
|
assert(type === "u64", "Result type is not u64");
|
|
4119
|
-
return
|
|
4146
|
+
return BigNumber7(bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4120
4147
|
}
|
|
4121
4148
|
return 0;
|
|
4122
4149
|
};
|
|
@@ -4142,7 +4169,7 @@ var getSCoinAmount = async ({
|
|
|
4142
4169
|
owner,
|
|
4143
4170
|
coinType: sCoinType
|
|
4144
4171
|
});
|
|
4145
|
-
return
|
|
4172
|
+
return BigNumber7(amount).toNumber();
|
|
4146
4173
|
};
|
|
4147
4174
|
var isSupportStakeCoins = (value) => {
|
|
4148
4175
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4172,7 +4199,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4172
4199
|
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4173
4200
|
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4174
4201
|
const calcAtoBRate = async () => {
|
|
4175
|
-
const prices = await query.utils.getCoinPrices(
|
|
4202
|
+
const prices = await query.utils.getCoinPrices();
|
|
4176
4203
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4177
4204
|
throw new Error("Failed to fetch the coin prices");
|
|
4178
4205
|
}
|
|
@@ -4182,7 +4209,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4182
4209
|
return prices[fromCoinName] / prices[toCoinName];
|
|
4183
4210
|
};
|
|
4184
4211
|
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4185
|
-
return
|
|
4212
|
+
return BigNumber7(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4186
4213
|
};
|
|
4187
4214
|
|
|
4188
4215
|
// src/queries/spoolQuery.ts
|
|
@@ -4242,7 +4269,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4242
4269
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4243
4270
|
);
|
|
4244
4271
|
let spool = void 0;
|
|
4245
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4272
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4246
4273
|
if (indexer) {
|
|
4247
4274
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4248
4275
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
@@ -4262,7 +4289,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4262
4289
|
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4263
4290
|
}
|
|
4264
4291
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4265
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4292
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4266
4293
|
const spoolObject = spoolObjectResponse[0];
|
|
4267
4294
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
4268
4295
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
@@ -4506,7 +4533,7 @@ var getStakeRewardPool = async ({
|
|
|
4506
4533
|
};
|
|
4507
4534
|
|
|
4508
4535
|
// src/queries/vescaQuery.ts
|
|
4509
|
-
import
|
|
4536
|
+
import BigNumber8 from "bignumber.js";
|
|
4510
4537
|
import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
|
|
4511
4538
|
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
4512
4539
|
import { z as zod5 } from "zod";
|
|
@@ -4588,7 +4615,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4588
4615
|
0
|
|
4589
4616
|
);
|
|
4590
4617
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4591
|
-
const lockedScaCoin =
|
|
4618
|
+
const lockedScaCoin = BigNumber8(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4592
4619
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4593
4620
|
vesca = {
|
|
4594
4621
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4598,7 +4625,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4598
4625
|
lockedScaAmount,
|
|
4599
4626
|
lockedScaCoin,
|
|
4600
4627
|
currentVeScaBalance,
|
|
4601
|
-
unlockAt:
|
|
4628
|
+
unlockAt: BigNumber8(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4602
4629
|
};
|
|
4603
4630
|
}
|
|
4604
4631
|
return vesca;
|
|
@@ -4660,10 +4687,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4660
4687
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4661
4688
|
return null;
|
|
4662
4689
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4663
|
-
const totalLockedSca =
|
|
4690
|
+
const totalLockedSca = BigNumber8(
|
|
4664
4691
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4665
4692
|
).shiftedBy(-9).toNumber();
|
|
4666
|
-
const totalVeSca =
|
|
4693
|
+
const totalVeSca = BigNumber8(
|
|
4667
4694
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4668
4695
|
).shiftedBy(-9).toNumber();
|
|
4669
4696
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4699,15 +4726,6 @@ var ScallopUtils = class {
|
|
|
4699
4726
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4700
4727
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4701
4728
|
};
|
|
4702
|
-
/**
|
|
4703
|
-
* Get reward type of borrow incentive pool.
|
|
4704
|
-
*
|
|
4705
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4706
|
-
* @return Borrow incentive reward coin name.
|
|
4707
|
-
*/
|
|
4708
|
-
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4709
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4710
|
-
};
|
|
4711
4729
|
this.params = {
|
|
4712
4730
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4713
4731
|
...params
|
|
@@ -4777,7 +4795,10 @@ var ScallopUtils = class {
|
|
|
4777
4795
|
* @param coinName - Specific support coin name.
|
|
4778
4796
|
* @return Coin type.
|
|
4779
4797
|
*/
|
|
4780
|
-
parseCoinType(coinName) {
|
|
4798
|
+
parseCoinType(coinName, useOldMarketCoin = false) {
|
|
4799
|
+
if (sCoinIds[coinName] && !useOldMarketCoin) {
|
|
4800
|
+
return sCoinIds[coinName];
|
|
4801
|
+
}
|
|
4781
4802
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4782
4803
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4783
4804
|
if (!coinPackageId) {
|
|
@@ -4832,6 +4853,15 @@ var ScallopUtils = class {
|
|
|
4832
4853
|
return void 0;
|
|
4833
4854
|
}
|
|
4834
4855
|
}
|
|
4856
|
+
/**
|
|
4857
|
+
* Convert sCoin name to coin name.
|
|
4858
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4859
|
+
* e.g: `scallop_sui -> ssui
|
|
4860
|
+
* @return sCoin name
|
|
4861
|
+
*/
|
|
4862
|
+
parseCoinNameFromSCoinName(coinName) {
|
|
4863
|
+
return sCoinRawNameToName[coinName];
|
|
4864
|
+
}
|
|
4835
4865
|
/**
|
|
4836
4866
|
* Convert sCoin name into sCoin type
|
|
4837
4867
|
* @param sCoinName
|
|
@@ -4874,7 +4904,7 @@ var ScallopUtils = class {
|
|
|
4874
4904
|
*/
|
|
4875
4905
|
parseMarketCoinType(coinName) {
|
|
4876
4906
|
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4877
|
-
const coinType = this.parseCoinType(coinName);
|
|
4907
|
+
const coinType = this.parseCoinType(coinName, true);
|
|
4878
4908
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4879
4909
|
}
|
|
4880
4910
|
parseCoinNameFromType(coinType) {
|
|
@@ -4883,7 +4913,7 @@ var ScallopUtils = class {
|
|
|
4883
4913
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4884
4914
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4885
4915
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4886
|
-
const
|
|
4916
|
+
const wormholeCoinTypeMap = {
|
|
4887
4917
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4888
4918
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
4889
4919
|
[`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
|
|
@@ -4903,7 +4933,7 @@ var ScallopUtils = class {
|
|
|
4903
4933
|
},
|
|
4904
4934
|
{}
|
|
4905
4935
|
);
|
|
4906
|
-
const assetCoinName =
|
|
4936
|
+
const assetCoinName = wormholeCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
4907
4937
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
4908
4938
|
}
|
|
4909
4939
|
/**
|
|
@@ -6017,11 +6047,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6017
6047
|
]
|
|
6018
6048
|
);
|
|
6019
6049
|
},
|
|
6020
|
-
claimBorrowIncentive: (obligationId, obligationKey,
|
|
6021
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6022
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6023
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6024
|
-
}
|
|
6050
|
+
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6025
6051
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6026
6052
|
return txBlock.moveCall(
|
|
6027
6053
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6114,7 +6140,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6114
6140
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6115
6141
|
}
|
|
6116
6142
|
},
|
|
6117
|
-
claimBorrowIncentiveQuick: async (
|
|
6143
|
+
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6118
6144
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6119
6145
|
builder,
|
|
6120
6146
|
txBlock,
|
|
@@ -6124,7 +6150,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6124
6150
|
return txBlock.claimBorrowIncentive(
|
|
6125
6151
|
obligationArg,
|
|
6126
6152
|
obligationKeyArg,
|
|
6127
|
-
coinName,
|
|
6128
6153
|
rewardCoinName
|
|
6129
6154
|
);
|
|
6130
6155
|
}
|
|
@@ -7302,6 +7327,7 @@ var ScallopQuery = class {
|
|
|
7302
7327
|
this,
|
|
7303
7328
|
coinNames,
|
|
7304
7329
|
args?.indexer,
|
|
7330
|
+
args?.marketPools,
|
|
7305
7331
|
args?.coinPrices
|
|
7306
7332
|
);
|
|
7307
7333
|
}
|
|
@@ -7517,6 +7543,13 @@ var ScallopQuery = class {
|
|
|
7517
7543
|
async getCoinPriceByIndexer(poolName) {
|
|
7518
7544
|
return this.indexer.getCoinPrice(poolName);
|
|
7519
7545
|
}
|
|
7546
|
+
/**
|
|
7547
|
+
* Get all coin prices, including sCoin
|
|
7548
|
+
* @returns prices data
|
|
7549
|
+
*/
|
|
7550
|
+
async getAllCoinPrices(args) {
|
|
7551
|
+
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
7552
|
+
}
|
|
7520
7553
|
};
|
|
7521
7554
|
|
|
7522
7555
|
// src/models/scallopBuilder.ts
|
|
@@ -8166,30 +8199,46 @@ var ScallopClient = class {
|
|
|
8166
8199
|
}
|
|
8167
8200
|
}
|
|
8168
8201
|
/**
|
|
8169
|
-
*
|
|
8202
|
+
* Claim borrow incentive reward.
|
|
8170
8203
|
*
|
|
8171
|
-
* @param
|
|
8204
|
+
* @param poolName
|
|
8172
8205
|
* @param amount - The amount of coins would deposit.
|
|
8173
8206
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8174
8207
|
* @param accountId - The stake account object.
|
|
8175
8208
|
* @param walletAddress - The wallet address of the owner.
|
|
8176
8209
|
* @return Transaction block response or transaction block
|
|
8177
8210
|
*/
|
|
8178
|
-
async claimBorrowIncentive(
|
|
8211
|
+
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8179
8212
|
const txBlock = this.builder.createTxBlock();
|
|
8180
8213
|
const sender = walletAddress ?? this.walletAddress;
|
|
8181
8214
|
txBlock.setSender(sender);
|
|
8182
|
-
const
|
|
8183
|
-
|
|
8215
|
+
const rewardCoinsCollection = {};
|
|
8216
|
+
const obligationAccount = await this.query.getObligationAccount(obligationId);
|
|
8217
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8218
|
+
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8219
|
+
).flatMap(({ coinName }) => coinName);
|
|
8220
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
8184
8221
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8185
|
-
coinName,
|
|
8186
8222
|
rewardCoinName,
|
|
8187
8223
|
obligationId,
|
|
8188
8224
|
obligationKeyId
|
|
8189
8225
|
);
|
|
8190
|
-
|
|
8226
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
8227
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8228
|
+
} else {
|
|
8229
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8230
|
+
}
|
|
8191
8231
|
}
|
|
8192
|
-
txBlock.transferObjects(
|
|
8232
|
+
txBlock.transferObjects(
|
|
8233
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8234
|
+
const mergeDest = rewardCoins[0];
|
|
8235
|
+
if (rewardCoins.length > 1) {
|
|
8236
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8237
|
+
}
|
|
8238
|
+
return mergeDest;
|
|
8239
|
+
}),
|
|
8240
|
+
sender
|
|
8241
|
+
);
|
|
8193
8242
|
if (sign) {
|
|
8194
8243
|
return await this.suiKit.signAndSendTxn(
|
|
8195
8244
|
txBlock
|
|
@@ -8498,12 +8547,12 @@ export {
|
|
|
8498
8547
|
UNLOCK_ROUND_DURATION,
|
|
8499
8548
|
USE_TEST_ADDRESS,
|
|
8500
8549
|
assetCoins,
|
|
8501
|
-
borrowIncentiveRewardCoins,
|
|
8502
8550
|
coinDecimals,
|
|
8503
8551
|
coinIds,
|
|
8504
8552
|
marketCoins,
|
|
8505
8553
|
queryKeys,
|
|
8506
8554
|
sCoinIds,
|
|
8555
|
+
sCoinRawNameToName,
|
|
8507
8556
|
sCoinTypeToName,
|
|
8508
8557
|
sCoins,
|
|
8509
8558
|
spoolRewardCoins,
|