@scallop-io/sui-scallop-sdk 1.3.5-alpha.1 → 1.3.5-alpha.3

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.mjs CHANGED
@@ -267,18 +267,6 @@ var spoolRewardCoins = {
267
267
  var suiBridgeCoins = {
268
268
  sbeth: "sbeth"
269
269
  };
270
- var borrowIncentiveRewardCoins = {
271
- usdc: ["ssui", "ssca"],
272
- sui: ["ssui", "ssca"],
273
- wusdc: ["ssui", "ssca"],
274
- wusdt: ["ssui", "ssca"],
275
- sca: ["ssui", "ssca"],
276
- afsui: ["ssui"],
277
- hasui: ["ssui"],
278
- vsui: ["ssui"],
279
- weth: ["ssui"],
280
- sbeth: ["ssui"]
281
- };
282
270
  var coinIds = {
283
271
  usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
284
272
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
@@ -2501,7 +2489,6 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2501
2489
  const borrowIncentivePools = {};
2502
2490
  marketPools = marketPools ?? await query.getMarketPools(void 0, false, { coinPrices });
2503
2491
  coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
2504
- console.log({ coinPrices });
2505
2492
  if (indexer) {
2506
2493
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
2507
2494
  const updateBorrowIncentivePool = (pool) => {
@@ -3709,8 +3696,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3709
3696
  const collateralAssetCoinNames = [
3710
3697
  ...SUPPORT_COLLATERALS
3711
3698
  ];
3712
- coinPrices = coinPrices ?? await query.utils.getCoinPrices();
3713
- market = market ?? await query.queryMarket(indexer, { coinPrices });
3699
+ market = market ?? await query.queryMarket(indexer);
3700
+ coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
3714
3701
  coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3715
3702
  const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3716
3703
  query.queryObligation(obligationId),
@@ -3851,44 +3838,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3851
3838
  const borrowIncentivePool = borrowIncentivePools[coinName];
3852
3839
  if (borrowIncentivePool) {
3853
3840
  const rewards = [];
3854
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
3855
- const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
3856
- const poolPoint = borrowIncentivePool.points[rewardCoinName];
3857
- if (accountPoint && poolPoint) {
3858
- let availableClaimAmount = BigNumber5(0);
3859
- let availableClaimCoin = BigNumber5(0);
3860
- const accountBorrowedAmount = BigNumber5(accountPoint.weightedAmount);
3861
- const baseIndexRate = 1e9;
3862
- const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
3863
- BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
3864
- 0
3865
- ) : 1;
3866
- availableClaimAmount = availableClaimAmount.plus(
3867
- accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
3868
- );
3869
- availableClaimCoin = availableClaimAmount.shiftedBy(
3870
- -1 * poolPoint.coinDecimal
3871
- );
3872
- const weightScale = BigNumber5(1e12);
3873
- const boostValue = BigNumber5(accountPoint.weightedAmount).div(
3874
- BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3875
- ).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
3876
- BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3877
- ).toNumber() : 1;
3878
- if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
3879
- rewards.push({
3880
- coinName: poolPoint.coinName,
3881
- coinType: poolPoint.coinType,
3882
- symbol: poolPoint.symbol,
3883
- coinDecimal: poolPoint.coinDecimal,
3884
- coinPrice: poolPoint.coinPrice,
3885
- availableClaimAmount: availableClaimAmount.toNumber(),
3886
- availableClaimCoin: availableClaimCoin.toNumber(),
3887
- boostValue
3888
- });
3841
+ Object.entries(borrowIncentiveAccount.pointList).forEach(
3842
+ ([key, accountPoint]) => {
3843
+ const poolPoint = borrowIncentivePool.points[key];
3844
+ if (accountPoint && poolPoint) {
3845
+ let availableClaimAmount = BigNumber5(0);
3846
+ let availableClaimCoin = BigNumber5(0);
3847
+ const accountBorrowedAmount = BigNumber5(
3848
+ accountPoint.weightedAmount
3849
+ );
3850
+ const baseIndexRate = 1e9;
3851
+ const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
3852
+ BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
3853
+ 0
3854
+ ) : 1;
3855
+ availableClaimAmount = availableClaimAmount.plus(
3856
+ accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
3857
+ );
3858
+ availableClaimCoin = availableClaimAmount.shiftedBy(
3859
+ -1 * poolPoint.coinDecimal
3860
+ );
3861
+ const weightScale = BigNumber5(1e12);
3862
+ const boostValue = BigNumber5(accountPoint.weightedAmount).div(
3863
+ BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3864
+ ).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
3865
+ BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3866
+ ).toNumber() : 1;
3867
+ if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
3868
+ rewards.push({
3869
+ coinName: poolPoint.coinName,
3870
+ coinType: poolPoint.coinType,
3871
+ symbol: poolPoint.symbol,
3872
+ coinDecimal: poolPoint.coinDecimal,
3873
+ coinPrice: poolPoint.coinPrice,
3874
+ availableClaimAmount: availableClaimAmount.toNumber(),
3875
+ availableClaimCoin: availableClaimCoin.toNumber(),
3876
+ boostValue
3877
+ });
3878
+ }
3889
3879
  }
3890
3880
  }
3891
- }
3881
+ );
3892
3882
  if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
3893
3883
  const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
3894
3884
  return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
@@ -4754,15 +4744,6 @@ var ScallopUtils = class {
4754
4744
  this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
4755
4745
  return spoolRewardCoins[stakeMarketCoinName];
4756
4746
  };
4757
- /**
4758
- * Get reward type of borrow incentive pool.
4759
- *
4760
- * @param borrowIncentiveCoinName - Support borrow incentive coin.
4761
- * @return Borrow incentive reward coin name.
4762
- */
4763
- this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
4764
- return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
4765
- };
4766
4747
  this.params = {
4767
4748
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4768
4749
  ...params
@@ -4833,6 +4814,9 @@ var ScallopUtils = class {
4833
4814
  * @return Coin type.
4834
4815
  */
4835
4816
  parseCoinType(coinName) {
4817
+ if (sCoinIds[coinName]) {
4818
+ return sCoinIds[coinName];
4819
+ }
4836
4820
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
4837
4821
  const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
4838
4822
  if (!coinPackageId) {
@@ -6081,11 +6065,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
6081
6065
  ]
6082
6066
  );
6083
6067
  },
6084
- claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
6085
- const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
6086
- if (rewardCoinNames.includes(rewardCoinName) === false) {
6087
- throw new Error(`Invalid reward coin name ${rewardCoinName}`);
6088
- }
6068
+ claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
6089
6069
  const rewardType = builder.utils.parseCoinType(rewardCoinName);
6090
6070
  return txBlock.moveCall(
6091
6071
  `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
@@ -6178,7 +6158,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6178
6158
  txBlock.unstakeObligation(obligationArg, obligationKeyArg);
6179
6159
  }
6180
6160
  },
6181
- claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
6161
+ claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
6182
6162
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
6183
6163
  builder,
6184
6164
  txBlock,
@@ -6188,7 +6168,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6188
6168
  return txBlock.claimBorrowIncentive(
6189
6169
  obligationArg,
6190
6170
  obligationKeyArg,
6191
- coinName,
6192
6171
  rewardCoinName
6193
6172
  );
6194
6173
  }
@@ -8233,30 +8212,46 @@ var ScallopClient = class {
8233
8212
  }
8234
8213
  }
8235
8214
  /**
8236
- * unstake market coin from the specific spool.
8215
+ * Claim borrow incentive reward.
8237
8216
  *
8238
- * @param marketCoinName - Types of mak coin.
8217
+ * @param poolName
8239
8218
  * @param amount - The amount of coins would deposit.
8240
8219
  * @param sign - Decide to directly sign the transaction or return the transaction block.
8241
8220
  * @param accountId - The stake account object.
8242
8221
  * @param walletAddress - The wallet address of the owner.
8243
8222
  * @return Transaction block response or transaction block
8244
8223
  */
8245
- async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
8224
+ async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
8246
8225
  const txBlock = this.builder.createTxBlock();
8247
8226
  const sender = walletAddress ?? this.walletAddress;
8248
8227
  txBlock.setSender(sender);
8249
- const rewardCoins = [];
8250
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
8228
+ const rewardCoinsCollection = {};
8229
+ const obligationAccount = await this.query.getObligationAccount(obligationId);
8230
+ const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
8231
+ ({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
8232
+ ).flatMap(({ coinName }) => coinName);
8233
+ for (const rewardCoinName of rewardCoinNames) {
8251
8234
  const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
8252
- coinName,
8253
8235
  rewardCoinName,
8254
8236
  obligationId,
8255
8237
  obligationKeyId
8256
8238
  );
8257
- rewardCoins.push(rewardCoin);
8239
+ if (!rewardCoinsCollection[rewardCoinName]) {
8240
+ rewardCoinsCollection[rewardCoinName] = [rewardCoin];
8241
+ } else {
8242
+ rewardCoinsCollection[rewardCoinName].push(rewardCoin);
8243
+ }
8258
8244
  }
8259
- txBlock.transferObjects(rewardCoins, sender);
8245
+ txBlock.transferObjects(
8246
+ Object.values(rewardCoinsCollection).map((rewardCoins) => {
8247
+ const mergeDest = rewardCoins[0];
8248
+ if (rewardCoins.length > 1) {
8249
+ txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
8250
+ }
8251
+ return mergeDest;
8252
+ }),
8253
+ sender
8254
+ );
8260
8255
  if (sign) {
8261
8256
  return await this.suiKit.signAndSendTxn(
8262
8257
  txBlock
@@ -8565,7 +8560,6 @@ export {
8565
8560
  UNLOCK_ROUND_DURATION,
8566
8561
  USE_TEST_ADDRESS,
8567
8562
  assetCoins,
8568
- borrowIncentiveRewardCoins,
8569
8563
  coinDecimals,
8570
8564
  coinIds,
8571
8565
  marketCoins,