@scallop-io/sui-scallop-sdk 1.3.5-alpha.2 → 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",
@@ -4846,15 +4833,6 @@ var ScallopUtils = class {
4846
4833
  this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
4847
4834
  return spoolRewardCoins[stakeMarketCoinName];
4848
4835
  };
4849
- /**
4850
- * Get reward type of borrow incentive pool.
4851
- *
4852
- * @param borrowIncentiveCoinName - Support borrow incentive coin.
4853
- * @return Borrow incentive reward coin name.
4854
- */
4855
- this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
4856
- return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
4857
- };
4858
4836
  this.params = {
4859
4837
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4860
4838
  ...params
@@ -4925,6 +4903,9 @@ var ScallopUtils = class {
4925
4903
  * @return Coin type.
4926
4904
  */
4927
4905
  parseCoinType(coinName) {
4906
+ if (sCoinIds[coinName]) {
4907
+ return sCoinIds[coinName];
4908
+ }
4928
4909
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
4929
4910
  const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
4930
4911
  if (!coinPackageId) {
@@ -6170,11 +6151,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
6170
6151
  ]
6171
6152
  );
6172
6153
  },
6173
- claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
6174
- const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
6175
- if (rewardCoinNames.includes(rewardCoinName) === false) {
6176
- throw new Error(`Invalid reward coin name ${rewardCoinName}`);
6177
- }
6154
+ claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
6178
6155
  const rewardType = builder.utils.parseCoinType(rewardCoinName);
6179
6156
  return txBlock.moveCall(
6180
6157
  `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
@@ -6267,7 +6244,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6267
6244
  txBlock.unstakeObligation(obligationArg, obligationKeyArg);
6268
6245
  }
6269
6246
  },
6270
- claimBorrowIncentiveQuick: async (coinName, rewardCoinName, obligation, obligationKey) => {
6247
+ claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
6271
6248
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
6272
6249
  builder,
6273
6250
  txBlock,
@@ -6277,7 +6254,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
6277
6254
  return txBlock.claimBorrowIncentive(
6278
6255
  obligationArg,
6279
6256
  obligationKeyArg,
6280
- coinName,
6281
6257
  rewardCoinName
6282
6258
  );
6283
6259
  }
@@ -8314,30 +8290,46 @@ var ScallopClient = class {
8314
8290
  }
8315
8291
  }
8316
8292
  /**
8317
- * unstake market coin from the specific spool.
8293
+ * Claim borrow incentive reward.
8318
8294
  *
8319
- * @param marketCoinName - Types of mak coin.
8295
+ * @param poolName
8320
8296
  * @param amount - The amount of coins would deposit.
8321
8297
  * @param sign - Decide to directly sign the transaction or return the transaction block.
8322
8298
  * @param accountId - The stake account object.
8323
8299
  * @param walletAddress - The wallet address of the owner.
8324
8300
  * @return Transaction block response or transaction block
8325
8301
  */
8326
- async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
8302
+ async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
8327
8303
  const txBlock = this.builder.createTxBlock();
8328
8304
  const sender = walletAddress ?? this.walletAddress;
8329
8305
  txBlock.setSender(sender);
8330
- const rewardCoins = [];
8331
- 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) {
8332
8312
  const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
8333
- coinName,
8334
8313
  rewardCoinName,
8335
8314
  obligationId,
8336
8315
  obligationKeyId
8337
8316
  );
8338
- rewardCoins.push(rewardCoin);
8317
+ if (!rewardCoinsCollection[rewardCoinName]) {
8318
+ rewardCoinsCollection[rewardCoinName] = [rewardCoin];
8319
+ } else {
8320
+ rewardCoinsCollection[rewardCoinName].push(rewardCoin);
8321
+ }
8339
8322
  }
8340
- 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
+ );
8341
8333
  if (sign) {
8342
8334
  return await this.suiKit.signAndSendTxn(
8343
8335
  txBlock
@@ -8647,7 +8639,6 @@ var Scallop = class {
8647
8639
  UNLOCK_ROUND_DURATION,
8648
8640
  USE_TEST_ADDRESS,
8649
8641
  assetCoins,
8650
- borrowIncentiveRewardCoins,
8651
8642
  coinDecimals,
8652
8643
  coinIds,
8653
8644
  marketCoins,