@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.
@@ -6,7 +6,6 @@ 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;
package/dist/index.js CHANGED
@@ -74,7 +74,6 @@ __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,
@@ -360,18 +359,6 @@ var spoolRewardCoins = {
360
359
  var suiBridgeCoins = {
361
360
  sbeth: "sbeth"
362
361
  };
363
- var borrowIncentiveRewardCoins = {
364
- usdc: ["ssui", "ssca"],
365
- sui: ["ssui", "ssca"],
366
- wusdc: ["ssui", "ssca"],
367
- wusdt: ["ssui", "ssca"],
368
- sca: ["ssui", "ssca"],
369
- afsui: ["ssui"],
370
- hasui: ["ssui"],
371
- vsui: ["ssui"],
372
- weth: ["ssui"],
373
- sbeth: ["ssui"]
374
- };
375
362
  var coinIds = {
376
363
  usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
377
364
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
@@ -2591,7 +2578,6 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2591
2578
  const borrowIncentivePools = {};
2592
2579
  marketPools = marketPools ?? await query.getMarketPools(void 0, false, { coinPrices });
2593
2580
  coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
2594
- console.log({ coinPrices });
2595
2581
  if (indexer) {
2596
2582
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
2597
2583
  const updateBorrowIncentivePool = (pool) => {
@@ -3799,8 +3785,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3799
3785
  const collateralAssetCoinNames = [
3800
3786
  ...SUPPORT_COLLATERALS
3801
3787
  ];
3802
- coinPrices = coinPrices ?? await query.utils.getCoinPrices();
3803
- market = market ?? await query.queryMarket(indexer, { coinPrices });
3788
+ market = market ?? await query.queryMarket(indexer);
3789
+ coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
3804
3790
  coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3805
3791
  const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3806
3792
  query.queryObligation(obligationId),
@@ -3941,44 +3927,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3941
3927
  const borrowIncentivePool = borrowIncentivePools[coinName];
3942
3928
  if (borrowIncentivePool) {
3943
3929
  const rewards = [];
3944
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
3945
- const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
3946
- const poolPoint = borrowIncentivePool.points[rewardCoinName];
3947
- if (accountPoint && poolPoint) {
3948
- let availableClaimAmount = (0, import_bignumber5.default)(0);
3949
- let availableClaimCoin = (0, import_bignumber5.default)(0);
3950
- const accountBorrowedAmount = (0, import_bignumber5.default)(accountPoint.weightedAmount);
3951
- const baseIndexRate = 1e9;
3952
- const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
3953
- (0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
3954
- 0
3955
- ) : 1;
3956
- availableClaimAmount = availableClaimAmount.plus(
3957
- accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
3958
- );
3959
- availableClaimCoin = availableClaimAmount.shiftedBy(
3960
- -1 * poolPoint.coinDecimal
3961
- );
3962
- const weightScale = (0, import_bignumber5.default)(1e12);
3963
- const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3964
- (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3965
- ).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3966
- (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3967
- ).toNumber() : 1;
3968
- if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
3969
- rewards.push({
3970
- coinName: poolPoint.coinName,
3971
- coinType: poolPoint.coinType,
3972
- symbol: poolPoint.symbol,
3973
- coinDecimal: poolPoint.coinDecimal,
3974
- coinPrice: poolPoint.coinPrice,
3975
- availableClaimAmount: availableClaimAmount.toNumber(),
3976
- availableClaimCoin: availableClaimCoin.toNumber(),
3977
- boostValue
3978
- });
3930
+ Object.entries(borrowIncentiveAccount.pointList).forEach(
3931
+ ([key, accountPoint]) => {
3932
+ const poolPoint = borrowIncentivePool.points[key];
3933
+ if (accountPoint && poolPoint) {
3934
+ let availableClaimAmount = (0, import_bignumber5.default)(0);
3935
+ let availableClaimCoin = (0, import_bignumber5.default)(0);
3936
+ const accountBorrowedAmount = (0, import_bignumber5.default)(
3937
+ accountPoint.weightedAmount
3938
+ );
3939
+ const baseIndexRate = 1e9;
3940
+ const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
3941
+ (0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
3942
+ 0
3943
+ ) : 1;
3944
+ availableClaimAmount = availableClaimAmount.plus(
3945
+ accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
3946
+ );
3947
+ availableClaimCoin = availableClaimAmount.shiftedBy(
3948
+ -1 * poolPoint.coinDecimal
3949
+ );
3950
+ const weightScale = (0, import_bignumber5.default)(1e12);
3951
+ const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3952
+ (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3953
+ ).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
3954
+ (0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
3955
+ ).toNumber() : 1;
3956
+ if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
3957
+ rewards.push({
3958
+ coinName: poolPoint.coinName,
3959
+ coinType: poolPoint.coinType,
3960
+ symbol: poolPoint.symbol,
3961
+ coinDecimal: poolPoint.coinDecimal,
3962
+ coinPrice: poolPoint.coinPrice,
3963
+ availableClaimAmount: availableClaimAmount.toNumber(),
3964
+ availableClaimCoin: availableClaimCoin.toNumber(),
3965
+ boostValue
3966
+ });
3967
+ }
3979
3968
  }
3980
3969
  }
3981
- }
3970
+ );
3982
3971
  if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
3983
3972
  const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
3984
3973
  return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
@@ -4844,15 +4833,6 @@ var ScallopUtils = class {
4844
4833
  this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
4845
4834
  return spoolRewardCoins[stakeMarketCoinName];
4846
4835
  };
4847
- /**
4848
- * Get reward type of borrow incentive pool.
4849
- *
4850
- * @param borrowIncentiveCoinName - Support borrow incentive coin.
4851
- * @return Borrow incentive reward coin name.
4852
- */
4853
- this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
4854
- return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
4855
- };
4856
4836
  this.params = {
4857
4837
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4858
4838
  ...params
@@ -4923,6 +4903,9 @@ var ScallopUtils = class {
4923
4903
  * @return Coin type.
4924
4904
  */
4925
4905
  parseCoinType(coinName) {
4906
+ if (sCoinIds[coinName]) {
4907
+ return sCoinIds[coinName];
4908
+ }
4926
4909
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
4927
4910
  const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
4928
4911
  if (!coinPackageId) {
@@ -6168,11 +6151,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
6168
6151
  ]
6169
6152
  );
6170
6153
  },
6171
- claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
6172
- const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
6173
- if (rewardCoinNames.includes(rewardCoinName) === false) {
6174
- throw new Error(`Invalid reward coin name ${rewardCoinName}`);
6175
- }
6154
+ claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
6176
6155
  const rewardType = builder.utils.parseCoinType(rewardCoinName);
6177
6156
  return txBlock.moveCall(
6178
6157
  `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
@@ -6265,7 +6244,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6265
6244
  txBlock.unstakeObligation(obligationArg, obligationKeyArg);
6266
6245
  }
6267
6246
  },
6268
- claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
6247
+ claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
6269
6248
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
6270
6249
  builder,
6271
6250
  txBlock,
@@ -6275,7 +6254,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6275
6254
  return txBlock.claimBorrowIncentive(
6276
6255
  obligationArg,
6277
6256
  obligationKeyArg,
6278
- coinName,
6279
6257
  rewardCoinName
6280
6258
  );
6281
6259
  }
@@ -8312,30 +8290,46 @@ var ScallopClient = class {
8312
8290
  }
8313
8291
  }
8314
8292
  /**
8315
- * unstake market coin from the specific spool.
8293
+ * Claim borrow incentive reward.
8316
8294
  *
8317
- * @param marketCoinName - Types of mak coin.
8295
+ * @param poolName
8318
8296
  * @param amount - The amount of coins would deposit.
8319
8297
  * @param sign - Decide to directly sign the transaction or return the transaction block.
8320
8298
  * @param accountId - The stake account object.
8321
8299
  * @param walletAddress - The wallet address of the owner.
8322
8300
  * @return Transaction block response or transaction block
8323
8301
  */
8324
- async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
8302
+ async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
8325
8303
  const txBlock = this.builder.createTxBlock();
8326
8304
  const sender = walletAddress ?? this.walletAddress;
8327
8305
  txBlock.setSender(sender);
8328
- const rewardCoins = [];
8329
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
8306
+ const rewardCoinsCollection = {};
8307
+ const obligationAccount = await this.query.getObligationAccount(obligationId);
8308
+ const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
8309
+ ({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
8310
+ ).flatMap(({ coinName }) => coinName);
8311
+ for (const rewardCoinName of rewardCoinNames) {
8330
8312
  const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
8331
- coinName,
8332
8313
  rewardCoinName,
8333
8314
  obligationId,
8334
8315
  obligationKeyId
8335
8316
  );
8336
- rewardCoins.push(rewardCoin);
8317
+ if (!rewardCoinsCollection[rewardCoinName]) {
8318
+ rewardCoinsCollection[rewardCoinName] = [rewardCoin];
8319
+ } else {
8320
+ rewardCoinsCollection[rewardCoinName].push(rewardCoin);
8321
+ }
8337
8322
  }
8338
- txBlock.transferObjects(rewardCoins, sender);
8323
+ txBlock.transferObjects(
8324
+ Object.values(rewardCoinsCollection).map((rewardCoins) => {
8325
+ const mergeDest = rewardCoins[0];
8326
+ if (rewardCoins.length > 1) {
8327
+ txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
8328
+ }
8329
+ return mergeDest;
8330
+ }),
8331
+ sender
8332
+ );
8339
8333
  if (sign) {
8340
8334
  return await this.suiKit.signAndSendTxn(
8341
8335
  txBlock
@@ -8645,7 +8639,6 @@ var Scallop = class {
8645
8639
  UNLOCK_ROUND_DURATION,
8646
8640
  USE_TEST_ADDRESS,
8647
8641
  assetCoins,
8648
- borrowIncentiveRewardCoins,
8649
8642
  coinDecimals,
8650
8643
  coinIds,
8651
8644
  marketCoins,