@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.
@@ -15,6 +15,6 @@ export declare const SUPPORT_SUI_BRIDGE: readonly ["sbeth"];
15
15
  export declare const SUPPORT_WORMHOLE: readonly ["wusdc", "wusdt", "weth", "wbtc", "wapt", "wsol"];
16
16
  export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
17
17
  export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "wusdc", "wusdt", "afsui", "hasui", "vsui", "weth", "sbeth", "sca", "usdc"];
18
- export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["sui", "sca"];
18
+ export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["usdc", "sbeth", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca", "fud", "deep", "susdc", "ssbeth", "ssui", "swusdc", "swusdt", "safsui", "shasui", "svsui", "sweth", "ssca", "scetus", "swsol", "swbtc", "sdeep", "sfud"];
19
19
  export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
20
20
  export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "protocolWhitelist", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];
@@ -6,9 +6,9 @@ export declare const sCoins: types.SCoins;
6
6
  export declare const stakeMarketCoins: types.StakeMarketCoins;
7
7
  export declare const spoolRewardCoins: types.StakeRewardCoins;
8
8
  export declare const suiBridgeCoins: types.SuiBridgeCoins;
9
- export declare const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins;
10
9
  export declare const coinIds: types.AssetCoinIds;
11
10
  export declare const wormholeCoinIds: types.WormholeCoinIds;
12
11
  export declare const voloCoinIds: types.VoloCoinIds;
13
12
  export declare const sCoinIds: types.SCoinIds;
14
13
  export declare const sCoinTypeToName: Record<string, "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep">;
14
+ export declare const sCoinRawNameToName: Record<string, "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep">;
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,
78
77
  coinDecimals: () => coinDecimals,
79
78
  coinIds: () => coinIds,
80
79
  marketCoins: () => marketCoins,
81
80
  queryKeys: () => queryKeys,
82
81
  sCoinIds: () => sCoinIds,
82
+ sCoinRawNameToName: () => sCoinRawNameToName,
83
83
  sCoinTypeToName: () => sCoinTypeToName,
84
84
  sCoins: () => sCoins,
85
85
  spoolRewardCoins: () => spoolRewardCoins,
@@ -218,7 +218,10 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
218
218
  "sca",
219
219
  "usdc"
220
220
  ];
221
- var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui", "sca"];
221
+ var SUPPORT_BORROW_INCENTIVE_REWARDS = [
222
+ ...SUPPORT_POOLS,
223
+ ...SUPPORT_SCOIN
224
+ ];
222
225
  var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
223
226
  var SUPPORT_PACKAGES = [
224
227
  "coinDecimalsRegistry",
@@ -348,18 +351,6 @@ var spoolRewardCoins = {
348
351
  var suiBridgeCoins = {
349
352
  sbeth: "sbeth"
350
353
  };
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
- };
363
354
  var coinIds = {
364
355
  usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
365
356
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
@@ -394,10 +385,10 @@ var sCoinIds = {
394
385
  susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
395
386
  ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
396
387
  ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
397
- scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
398
- ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
399
388
  swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
400
389
  swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
390
+ ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
391
+ scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
401
392
  sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
402
393
  safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
403
394
  shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
@@ -414,6 +405,13 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
414
405
  },
415
406
  {}
416
407
  );
408
+ var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
409
+ (acc, [coinName, coinType]) => {
410
+ acc[coinType.split("::")[2].toLowerCase()] = coinName;
411
+ return acc;
412
+ },
413
+ {}
414
+ );
417
415
 
418
416
  // src/constants/flashloan.ts
419
417
  var FlashLoanFeeObjectMap = {
@@ -2561,15 +2559,21 @@ var queryBorrowIncentivePools = async (address) => {
2561
2559
  };
2562
2560
  var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2563
2561
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2564
- ], indexer = false, coinPrices) => {
2562
+ ], indexer = false, marketPools, coinPrices) => {
2565
2563
  const borrowIncentivePools = {};
2566
- coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
2564
+ marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices, indexer });
2565
+ coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
2567
2566
  if (indexer) {
2568
2567
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
2569
2568
  const updateBorrowIncentivePool = (pool) => {
2570
2569
  if (!borrowIncentiveCoinNames.includes(pool.coinName))
2571
2570
  return;
2572
- pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
2571
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2572
+ for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
2573
+ if (pool.points[sCoinName]) {
2574
+ pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
2575
+ }
2576
+ }
2573
2577
  borrowIncentivePools[pool.coinName] = pool;
2574
2578
  };
2575
2579
  Object.values(borrowIncentivePoolsIndexer).forEach(
@@ -2595,12 +2599,15 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2595
2599
  for (const [coinName, poolPoint] of Object.entries(
2596
2600
  parsedBorrowIncentivePoolData.poolPoints
2597
2601
  )) {
2598
- const rewardCoinType = (0, import_utils3.normalizeStructTag)(poolPoint.pointType);
2599
- const rewardCoinName = query.utils.parseCoinNameFromType(
2602
+ const rewardCoinType = poolPoint.pointType;
2603
+ let rewardCoinName = query.utils.parseCoinNameFromType(
2600
2604
  rewardCoinType
2601
2605
  );
2602
- const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2606
+ if (sCoinRawNameToName[rewardCoinName]) {
2607
+ rewardCoinName = sCoinRawNameToName[rewardCoinName];
2608
+ }
2603
2609
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2610
+ const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2604
2611
  const symbol = query.utils.parseSymbol(rewardCoinName);
2605
2612
  const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2606
2613
  const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
@@ -3033,7 +3040,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
3033
3040
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
3034
3041
  showContent: true
3035
3042
  });
3036
- coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
3043
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices();
3037
3044
  const marketPools = {};
3038
3045
  if (indexer) {
3039
3046
  const marketPoolsIndexer = await query.indexer.getMarketPools();
@@ -3066,7 +3073,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
3066
3073
  return marketPools;
3067
3074
  };
3068
3075
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
3069
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3076
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName];
3070
3077
  if (indexer) {
3071
3078
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
3072
3079
  if (!marketPoolIndexer) {
@@ -3209,7 +3216,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
3209
3216
  };
3210
3217
  var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
3211
3218
  const marketId = query.address.get("core.market");
3212
- const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
3219
+ const coinPrices = await query.utils.getCoinPrices() ?? {};
3213
3220
  const marketCollaterals = {};
3214
3221
  if (indexer) {
3215
3222
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
@@ -3245,7 +3252,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
3245
3252
  return marketCollaterals;
3246
3253
  };
3247
3254
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
3248
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
3255
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
3249
3256
  if (indexer) {
3250
3257
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
3251
3258
  marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
@@ -3561,7 +3568,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3561
3568
  const stakeMarketCoinNames = marketCoinNames.filter(
3562
3569
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3563
3570
  );
3564
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3571
+ const coinPrices = await query.utils.getCoinPrices();
3565
3572
  const marketPools = await query.getMarketPools(poolCoinNames, {
3566
3573
  indexer,
3567
3574
  coinPrices
@@ -3601,7 +3608,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3601
3608
  };
3602
3609
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
3603
3610
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3604
- coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
3611
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
3605
3612
  marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
3606
3613
  indexer,
3607
3614
  coinPrice
@@ -3759,8 +3766,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3759
3766
  const collateralAssetCoinNames = [
3760
3767
  ...SUPPORT_COLLATERALS
3761
3768
  ];
3762
- coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
3763
- market = market ?? await query.queryMarket({ indexer, coinPrices });
3769
+ market = market ?? await query.queryMarket({ indexer });
3770
+ coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
3764
3771
  coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3765
3772
  const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3766
3773
  query.queryObligation(obligationId),
@@ -3902,44 +3909,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3902
3909
  const borrowIncentivePool = borrowIncentivePools[coinName];
3903
3910
  if (borrowIncentivePool) {
3904
3911
  const rewards = [];
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
- });
3912
+ Object.entries(borrowIncentiveAccount.pointList).forEach(
3913
+ ([key, accountPoint]) => {
3914
+ const poolPoint = borrowIncentivePool.points[key];
3915
+ if (accountPoint && poolPoint) {
3916
+ let availableClaimAmount = (0, import_bignumber5.default)(0);
3917
+ let availableClaimCoin = (0, import_bignumber5.default)(0);
3918
+ const accountBorrowedAmount = (0, import_bignumber5.default)(
3919
+ accountPoint.weightedAmount
3920
+ );
3921
+ const baseIndexRate = 1e9;
3922
+ const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
3923
+ (0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
3924
+ 0
3925
+ ) : 1;
3926
+ availableClaimAmount = availableClaimAmount.plus(
3927
+ accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
3928
+ );
3929
+ availableClaimCoin = availableClaimAmount.shiftedBy(
3930
+ -1 * poolPoint.coinDecimal
3931
+ );
3932
+ const weightScale = (0, import_bignumber5.default)(1e12);
3933
+ const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3934
+ (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3935
+ ).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3936
+ (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3937
+ ).toNumber() : 1;
3938
+ if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
3939
+ rewards.push({
3940
+ coinName: poolPoint.coinName,
3941
+ coinType: poolPoint.coinType,
3942
+ symbol: poolPoint.symbol,
3943
+ coinDecimal: poolPoint.coinDecimal,
3944
+ coinPrice: poolPoint.coinPrice,
3945
+ availableClaimAmount: availableClaimAmount.toNumber(),
3946
+ availableClaimCoin: availableClaimCoin.toNumber(),
3947
+ boostValue
3948
+ });
3949
+ }
3940
3950
  }
3941
3951
  }
3942
- }
3952
+ );
3943
3953
  if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
3944
3954
  const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
3945
3955
  return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
@@ -4083,6 +4093,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
4083
4093
  };
4084
4094
 
4085
4095
  // src/queries/priceQuery.ts
4096
+ var import_bignumber6 = __toESM(require("bignumber.js"));
4086
4097
  var getPythPrice = async ({
4087
4098
  address
4088
4099
  }, assetCoinName, priceFeedObject) => {
@@ -4164,6 +4175,22 @@ var getPythPrices = async ({
4164
4175
  {}
4165
4176
  );
4166
4177
  };
4178
+ var getAllCoinPrices = async (query, marketPools, coinPrices) => {
4179
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices();
4180
+ marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices });
4181
+ if (!marketPools) {
4182
+ throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
4183
+ }
4184
+ const sCoinPrices = {};
4185
+ SUPPORT_SCOIN.forEach((sCoinName) => {
4186
+ const coinName = query.utils.parseCoinName(sCoinName);
4187
+ sCoinPrices[sCoinName] = (0, import_bignumber6.default)(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
4188
+ });
4189
+ return {
4190
+ ...coinPrices,
4191
+ ...sCoinPrices
4192
+ };
4193
+ };
4167
4194
 
4168
4195
  // src/queries/referralQuery.ts
4169
4196
  var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
@@ -4184,7 +4211,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
4184
4211
  // src/queries/sCoinQuery.ts
4185
4212
  var import_bcs = require("@mysten/sui/bcs");
4186
4213
  var import_assert = __toESM(require("assert"));
4187
- var import_bignumber6 = __toESM(require("bignumber.js"));
4214
+ var import_bignumber7 = __toESM(require("bignumber.js"));
4188
4215
  var getSCoinTotalSupply = async ({
4189
4216
  utils
4190
4217
  }, sCoinName) => {
@@ -4205,7 +4232,7 @@ var getSCoinTotalSupply = async ({
4205
4232
  const value = Uint8Array.from(results[0].returnValues[0][0]);
4206
4233
  const type = results[0].returnValues[0][1];
4207
4234
  (0, import_assert.default)(type === "u64", "Result type is not u64");
4208
- return (0, import_bignumber6.default)(import_bcs.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
4235
+ return (0, import_bignumber7.default)(import_bcs.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
4209
4236
  }
4210
4237
  return 0;
4211
4238
  };
@@ -4231,7 +4258,7 @@ var getSCoinAmount = async ({
4231
4258
  owner,
4232
4259
  coinType: sCoinType
4233
4260
  });
4234
- return (0, import_bignumber6.default)(amount).toNumber();
4261
+ return (0, import_bignumber7.default)(amount).toNumber();
4235
4262
  };
4236
4263
  var isSupportStakeCoins = (value) => {
4237
4264
  return SUPPORT_SCOIN.includes(value);
@@ -4261,7 +4288,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
4261
4288
  const ScoinAToARate = marketPools[0].conversionRate;
4262
4289
  const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
4263
4290
  const calcAtoBRate = async () => {
4264
- const prices = await query.utils.getCoinPrices([fromCoinName, toCoinName]);
4291
+ const prices = await query.utils.getCoinPrices();
4265
4292
  if (!prices[fromCoinName] || !prices[toCoinName]) {
4266
4293
  throw new Error("Failed to fetch the coin prices");
4267
4294
  }
@@ -4271,7 +4298,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
4271
4298
  return prices[fromCoinName] / prices[toCoinName];
4272
4299
  };
4273
4300
  const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
4274
- return (0, import_bignumber6.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
4301
+ return (0, import_bignumber7.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
4275
4302
  };
4276
4303
 
4277
4304
  // src/queries/spoolQuery.ts
@@ -4331,7 +4358,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
4331
4358
  `spool.pools.${marketCoinName}.rewardPoolId`
4332
4359
  );
4333
4360
  let spool = void 0;
4334
- coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
4361
+ coinPrices = coinPrices || await query.utils.getCoinPrices();
4335
4362
  if (indexer) {
4336
4363
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
4337
4364
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -4351,7 +4378,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
4351
4378
  throw new Error("Fail to fetch spoolObjectResponse!");
4352
4379
  }
4353
4380
  const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
4354
- coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
4381
+ coinPrices = coinPrices || await query.utils.getCoinPrices();
4355
4382
  const spoolObject = spoolObjectResponse[0];
4356
4383
  const rewardPoolObject = spoolObjectResponse[1];
4357
4384
  if (spoolObject.content && "fields" in spoolObject.content) {
@@ -4595,7 +4622,7 @@ var getStakeRewardPool = async ({
4595
4622
  };
4596
4623
 
4597
4624
  // src/queries/vescaQuery.ts
4598
- var import_bignumber7 = __toESM(require("bignumber.js"));
4625
+ var import_bignumber8 = __toESM(require("bignumber.js"));
4599
4626
  var import_sui_kit3 = require("@scallop-io/sui-kit");
4600
4627
  var import_bcs2 = require("@mysten/sui/bcs");
4601
4628
  var import_zod5 = require("zod");
@@ -4677,7 +4704,7 @@ var getVeSca = async (utils, veScaKey) => {
4677
4704
  0
4678
4705
  );
4679
4706
  const lockedScaAmount = String(dynamicFields.locked_sca_amount);
4680
- const lockedScaCoin = (0, import_bignumber7.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
4707
+ const lockedScaCoin = (0, import_bignumber8.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
4681
4708
  const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
4682
4709
  vesca = {
4683
4710
  id: veScaDynamicFieldObject.objectId,
@@ -4687,7 +4714,7 @@ var getVeSca = async (utils, veScaKey) => {
4687
4714
  lockedScaAmount,
4688
4715
  lockedScaCoin,
4689
4716
  currentVeScaBalance,
4690
- unlockAt: (0, import_bignumber7.default)(dynamicFields.unlock_at * 1e3).toNumber()
4717
+ unlockAt: (0, import_bignumber8.default)(dynamicFields.unlock_at * 1e3).toNumber()
4691
4718
  };
4692
4719
  }
4693
4720
  return vesca;
@@ -4749,10 +4776,10 @@ var getVeScaTreasuryInfo = async (utils) => {
4749
4776
  if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
4750
4777
  return null;
4751
4778
  const treasuryFields = veScaTreasury.data.content.fields;
4752
- const totalLockedSca = (0, import_bignumber7.default)(
4779
+ const totalLockedSca = (0, import_bignumber8.default)(
4753
4780
  treasuryFields.unlock_schedule.fields.locked_sca_amount
4754
4781
  ).shiftedBy(-9).toNumber();
4755
- const totalVeSca = (0, import_bignumber7.default)(
4782
+ const totalVeSca = (0, import_bignumber8.default)(
4756
4783
  await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
4757
4784
  ).shiftedBy(-9).toNumber();
4758
4785
  const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
@@ -4788,15 +4815,6 @@ var ScallopUtils = class {
4788
4815
  this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
4789
4816
  return spoolRewardCoins[stakeMarketCoinName];
4790
4817
  };
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
- };
4800
4818
  this.params = {
4801
4819
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4802
4820
  ...params
@@ -4866,7 +4884,10 @@ var ScallopUtils = class {
4866
4884
  * @param coinName - Specific support coin name.
4867
4885
  * @return Coin type.
4868
4886
  */
4869
- parseCoinType(coinName) {
4887
+ parseCoinType(coinName, useOldMarketCoin = false) {
4888
+ if (sCoinIds[coinName] && !useOldMarketCoin) {
4889
+ return sCoinIds[coinName];
4890
+ }
4870
4891
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
4871
4892
  const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
4872
4893
  if (!coinPackageId) {
@@ -4921,6 +4942,15 @@ var ScallopUtils = class {
4921
4942
  return void 0;
4922
4943
  }
4923
4944
  }
4945
+ /**
4946
+ * Convert sCoin name to coin name.
4947
+ * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
4948
+ * e.g: `scallop_sui -> ssui
4949
+ * @return sCoin name
4950
+ */
4951
+ parseCoinNameFromSCoinName(coinName) {
4952
+ return sCoinRawNameToName[coinName];
4953
+ }
4924
4954
  /**
4925
4955
  * Convert sCoin name into sCoin type
4926
4956
  * @param sCoinName
@@ -4963,7 +4993,7 @@ var ScallopUtils = class {
4963
4993
  */
4964
4994
  parseMarketCoinType(coinName) {
4965
4995
  const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
4966
- const coinType = this.parseCoinType(coinName);
4996
+ const coinType = this.parseCoinType(coinName, true);
4967
4997
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
4968
4998
  }
4969
4999
  parseCoinNameFromType(coinType) {
@@ -4972,7 +5002,7 @@ var ScallopUtils = class {
4972
5002
  const coinTypeMatch = coinType.match(coinTypeRegex);
4973
5003
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");
4974
5004
  coinType = coinTypeMatch?.[1] ?? coinType;
4975
- const wormHoleCoinTypeMap = {
5005
+ const wormholeCoinTypeMap = {
4976
5006
  [`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
4977
5007
  [`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
4978
5008
  [`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
@@ -4992,7 +5022,7 @@ var ScallopUtils = class {
4992
5022
  },
4993
5023
  {}
4994
5024
  );
4995
- const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
5025
+ const assetCoinName = wormholeCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
4996
5026
  return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
4997
5027
  }
4998
5028
  /**
@@ -6103,11 +6133,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
6103
6133
  ]
6104
6134
  );
6105
6135
  },
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
- }
6136
+ claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
6111
6137
  const rewardType = builder.utils.parseCoinType(rewardCoinName);
6112
6138
  return txBlock.moveCall(
6113
6139
  `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
@@ -6200,7 +6226,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6200
6226
  txBlock.unstakeObligation(obligationArg, obligationKeyArg);
6201
6227
  }
6202
6228
  },
6203
- claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
6229
+ claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
6204
6230
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
6205
6231
  builder,
6206
6232
  txBlock,
@@ -6210,7 +6236,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6210
6236
  return txBlock.claimBorrowIncentive(
6211
6237
  obligationArg,
6212
6238
  obligationKeyArg,
6213
- coinName,
6214
6239
  rewardCoinName
6215
6240
  );
6216
6241
  }
@@ -7380,6 +7405,7 @@ var ScallopQuery = class {
7380
7405
  this,
7381
7406
  coinNames,
7382
7407
  args?.indexer,
7408
+ args?.marketPools,
7383
7409
  args?.coinPrices
7384
7410
  );
7385
7411
  }
@@ -7595,6 +7621,13 @@ var ScallopQuery = class {
7595
7621
  async getCoinPriceByIndexer(poolName) {
7596
7622
  return this.indexer.getCoinPrice(poolName);
7597
7623
  }
7624
+ /**
7625
+ * Get all coin prices, including sCoin
7626
+ * @returns prices data
7627
+ */
7628
+ async getAllCoinPrices(args) {
7629
+ return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
7630
+ }
7598
7631
  };
7599
7632
 
7600
7633
  // src/models/scallopBuilder.ts
@@ -8244,30 +8277,46 @@ var ScallopClient = class {
8244
8277
  }
8245
8278
  }
8246
8279
  /**
8247
- * unstake market coin from the specific spool.
8280
+ * Claim borrow incentive reward.
8248
8281
  *
8249
- * @param marketCoinName - Types of mak coin.
8282
+ * @param poolName
8250
8283
  * @param amount - The amount of coins would deposit.
8251
8284
  * @param sign - Decide to directly sign the transaction or return the transaction block.
8252
8285
  * @param accountId - The stake account object.
8253
8286
  * @param walletAddress - The wallet address of the owner.
8254
8287
  * @return Transaction block response or transaction block
8255
8288
  */
8256
- async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
8289
+ async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
8257
8290
  const txBlock = this.builder.createTxBlock();
8258
8291
  const sender = walletAddress ?? this.walletAddress;
8259
8292
  txBlock.setSender(sender);
8260
- const rewardCoins = [];
8261
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
8293
+ const rewardCoinsCollection = {};
8294
+ const obligationAccount = await this.query.getObligationAccount(obligationId);
8295
+ const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
8296
+ ({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
8297
+ ).flatMap(({ coinName }) => coinName);
8298
+ for (const rewardCoinName of rewardCoinNames) {
8262
8299
  const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
8263
- coinName,
8264
8300
  rewardCoinName,
8265
8301
  obligationId,
8266
8302
  obligationKeyId
8267
8303
  );
8268
- rewardCoins.push(rewardCoin);
8304
+ if (!rewardCoinsCollection[rewardCoinName]) {
8305
+ rewardCoinsCollection[rewardCoinName] = [rewardCoin];
8306
+ } else {
8307
+ rewardCoinsCollection[rewardCoinName].push(rewardCoin);
8308
+ }
8269
8309
  }
8270
- txBlock.transferObjects(rewardCoins, sender);
8310
+ txBlock.transferObjects(
8311
+ Object.values(rewardCoinsCollection).map((rewardCoins) => {
8312
+ const mergeDest = rewardCoins[0];
8313
+ if (rewardCoins.length > 1) {
8314
+ txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
8315
+ }
8316
+ return mergeDest;
8317
+ }),
8318
+ sender
8319
+ );
8271
8320
  if (sign) {
8272
8321
  return await this.suiKit.signAndSendTxn(
8273
8322
  txBlock
@@ -8577,12 +8626,12 @@ var Scallop = class {
8577
8626
  UNLOCK_ROUND_DURATION,
8578
8627
  USE_TEST_ADDRESS,
8579
8628
  assetCoins,
8580
- borrowIncentiveRewardCoins,
8581
8629
  coinDecimals,
8582
8630
  coinIds,
8583
8631
  marketCoins,
8584
8632
  queryKeys,
8585
8633
  sCoinIds,
8634
+ sCoinRawNameToName,
8586
8635
  sCoinTypeToName,
8587
8636
  sCoins,
8588
8637
  spoolRewardCoins,