@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.
@@ -7,7 +7,7 @@ import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
7
7
  import type { TransactionObjectArgument } from '@mysten/sui/transactions';
8
8
  import { ScallopCache } from './scallopCache';
9
9
  import type { SuiObjectArg } from '@scallop-io/sui-kit';
10
- import type { ScallopClientFnReturnType, ScallopClientParams, SupportPoolCoins, SupportCollateralCoins, SupportAssetCoins, SupportStakeCoins, SupportStakeMarketCoins, SupportBorrowIncentiveCoins, ScallopTxBlock, ScallopClientVeScaReturnType, ScallopClientInstanceParams } from '../types';
10
+ import type { ScallopClientFnReturnType, ScallopClientParams, SupportPoolCoins, SupportCollateralCoins, SupportAssetCoins, SupportStakeCoins, SupportStakeMarketCoins, ScallopTxBlock, ScallopClientVeScaReturnType, ScallopClientInstanceParams } from '../types';
11
11
  /**
12
12
  * @description
13
13
  * It provides contract interaction operations for general users.
@@ -284,16 +284,16 @@ export declare class ScallopClient {
284
284
  */
285
285
  unstakeObligation<S extends boolean>(obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
286
286
  /**
287
- * unstake market coin from the specific spool.
287
+ * Claim borrow incentive reward.
288
288
  *
289
- * @param marketCoinName - Types of mak coin.
289
+ * @param poolName
290
290
  * @param amount - The amount of coins would deposit.
291
291
  * @param sign - Decide to directly sign the transaction or return the transaction block.
292
292
  * @param accountId - The stake account object.
293
293
  * @param walletAddress - The wallet address of the owner.
294
294
  * @return Transaction block response or transaction block
295
295
  */
296
- claimBorrowIncentive<S extends boolean>(coinName: SupportBorrowIncentiveCoins, obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
296
+ claimBorrowIncentive<S extends boolean>(obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
297
297
  /**
298
298
  * Function to migrate all market coin in user wallet into sCoin
299
299
  * @returns Transaction response
@@ -1,7 +1,7 @@
1
1
  import { SuiKit } from '@scallop-io/sui-kit';
2
2
  import { ScallopAddress } from './scallopAddress';
3
3
  import { ScallopCache } from './scallopCache';
4
- import type { ScallopUtilsParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, SupportBorrowIncentiveCoins, CoinWrappedType, SupportSCoin, ScallopUtilsInstanceParams, SupportSuiBridgeCoins, SupportWormholeCoins, PoolAddressInfo } from '../types';
4
+ import type { ScallopUtilsParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, CoinWrappedType, SupportSCoin, ScallopUtilsInstanceParams, SupportSuiBridgeCoins, SupportWormholeCoins, PoolAddressInfo } from '../types';
5
5
  import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
6
6
  /**
7
7
  * @description
@@ -131,13 +131,6 @@ export declare class ScallopUtils {
131
131
  * @return Spool reward coin name.
132
132
  */
133
133
  getSpoolRewardCoinName: (stakeMarketCoinName: SupportStakeMarketCoins) => "sui";
134
- /**
135
- * Get reward type of borrow incentive pool.
136
- *
137
- * @param borrowIncentiveCoinName - Support borrow incentive coin.
138
- * @return Borrow incentive reward coin name.
139
- */
140
- getBorrowIncentiveRewardCoinName: (borrowIncentiveCoinName: SupportBorrowIncentiveCoins) => ("usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca")[];
141
134
  /**
142
135
  * Get coin decimal.
143
136
  *
@@ -1,7 +1,7 @@
1
1
  import type { SuiTxBlock as SuiKitTxBlock, SuiObjectArg } from '@scallop-io/sui-kit';
2
2
  import type { TransactionResult } from '@mysten/sui/transactions';
3
3
  import type { ScallopBuilder } from '../../models';
4
- import type { SupportBorrowIncentiveCoins, SupportBorrowIncentiveRewardCoins } from '../constant';
4
+ import type { SupportBorrowIncentiveRewardCoins } from '../constant';
5
5
  export type BorrowIncentiveIds = {
6
6
  borrowIncentivePkg: string;
7
7
  query: string;
@@ -14,14 +14,14 @@ export type BorrowIncentiveNormalMethods = {
14
14
  stakeObligation: (obligation: SuiObjectArg, obligationKey: SuiObjectArg) => void;
15
15
  stakeObligationWithVesca: (obligation: SuiObjectArg, obligationKey: SuiObjectArg, veScaKey: SuiObjectArg) => void;
16
16
  unstakeObligation: (obligation: SuiObjectArg, obligationKey: SuiObjectArg) => void;
17
- claimBorrowIncentive: (obligation: SuiObjectArg, obligationKey: SuiObjectArg, coinName: SupportBorrowIncentiveCoins, rewardType: SupportBorrowIncentiveRewardCoins) => TransactionResult;
17
+ claimBorrowIncentive: (obligation: SuiObjectArg, obligationKey: SuiObjectArg, rewardType: SupportBorrowIncentiveRewardCoins) => TransactionResult;
18
18
  deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
19
19
  };
20
20
  export type BorrowIncentiveQuickMethods = {
21
- stakeObligationQuick(obligation?: SuiObjectArg, obligationKey?: SuiObjectArg): Promise<void>;
22
- stakeObligationWithVeScaQuick(obligation?: SuiObjectArg, obligationKey?: SuiObjectArg, veScaKey?: SuiObjectArg): Promise<void>;
23
- unstakeObligationQuick(obligation?: SuiObjectArg, obligationKey?: SuiObjectArg): Promise<void>;
24
- claimBorrowIncentiveQuick(coinName: SupportBorrowIncentiveCoins, rewardType: SupportBorrowIncentiveRewardCoins, obligation?: SuiObjectArg, obligationKey?: SuiObjectArg): Promise<TransactionResult>;
21
+ stakeObligationQuick(obligation?: string, obligationKey?: string): Promise<void>;
22
+ stakeObligationWithVeScaQuick(obligation?: string, obligationKey?: string, veScaKey?: string): Promise<void>;
23
+ unstakeObligationQuick(obligation?: string, obligationKey?: string): Promise<void>;
24
+ claimBorrowIncentiveQuick(rewardType: SupportBorrowIncentiveRewardCoins, obligation?: string, obligationKey?: string): Promise<TransactionResult>;
25
25
  };
26
26
  export type SuiTxBlockWithBorrowIncentiveNormalMethods = SuiKitTxBlock & BorrowIncentiveNormalMethods;
27
27
  export type BorrowIncentiveTxBlock = SuiTxBlockWithBorrowIncentiveNormalMethods & BorrowIncentiveQuickMethods;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.3.5-alpha.2",
3
+ "version": "1.3.5-alpha.3",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -143,17 +143,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
143
143
  ]
144
144
  );
145
145
  },
146
- claimBorrowIncentive: (
147
- obligationId,
148
- obligationKey,
149
- coinName,
150
- rewardCoinName
151
- ) => {
152
- const rewardCoinNames =
153
- builder.utils.getBorrowIncentiveRewardCoinName(coinName);
154
- if (rewardCoinNames.includes(rewardCoinName) === false) {
155
- throw new Error(`Invalid reward coin name ${rewardCoinName}`);
156
- }
146
+ claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
157
147
  const rewardType = builder.utils.parseCoinType(rewardCoinName);
158
148
  return txBlock.moveCall(
159
149
  `${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
@@ -284,11 +274,11 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
284
274
  }
285
275
  },
286
276
  claimBorrowIncentiveQuick: async (
287
- coinName,
288
277
  rewardCoinName,
289
278
  obligation,
290
279
  obligationKey
291
280
  ) => {
281
+ // check for available reward coin names
292
282
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } =
293
283
  await requireObligationInfo(
294
284
  builder,
@@ -300,7 +290,6 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
300
290
  return txBlock.claimBorrowIncentive(
301
291
  obligationArg,
302
292
  obligationKeyArg,
303
- coinName,
304
293
  rewardCoinName
305
294
  );
306
295
  },
@@ -125,19 +125,6 @@ export const suiBridgeCoins: types.SuiBridgeCoins = {
125
125
  sbeth: 'sbeth',
126
126
  };
127
127
 
128
- export const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins = {
129
- usdc: ['ssui', 'ssca'],
130
- sui: ['ssui', 'ssca'],
131
- wusdc: ['ssui', 'ssca'],
132
- wusdt: ['ssui', 'ssca'],
133
- sca: ['ssui', 'ssca'],
134
- afsui: ['ssui'],
135
- hasui: ['ssui'],
136
- vsui: ['ssui'],
137
- weth: ['ssui'],
138
- sbeth: ['ssui'],
139
- };
140
-
141
128
  export const coinIds: types.AssetCoinIds = {
142
129
  usdc: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7',
143
130
  sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
@@ -4,7 +4,6 @@ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
4
4
  import {
5
5
  ADDRESSES_ID,
6
6
  SUPPORT_BORROW_INCENTIVE_POOLS,
7
- SUPPORT_BORROW_INCENTIVE_REWARDS,
8
7
  SUPPORT_SCOIN,
9
8
  SUPPORT_SPOOLS,
10
9
  } from '../constants';
@@ -28,7 +27,6 @@ import type {
28
27
  SupportAssetCoins,
29
28
  SupportStakeCoins,
30
29
  SupportStakeMarketCoins,
31
- SupportBorrowIncentiveCoins,
32
30
  ScallopTxBlock,
33
31
  SupportSCoin,
34
32
  ScallopClientVeScaReturnType,
@@ -945,9 +943,9 @@ export class ScallopClient {
945
943
  }
946
944
 
947
945
  /**
948
- * unstake market coin from the specific spool.
946
+ * Claim borrow incentive reward.
949
947
  *
950
- * @param marketCoinName - Types of mak coin.
948
+ * @param poolName
951
949
  * @param amount - The amount of coins would deposit.
952
950
  * @param sign - Decide to directly sign the transaction or return the transaction block.
953
951
  * @param accountId - The stake account object.
@@ -955,7 +953,6 @@ export class ScallopClient {
955
953
  * @return Transaction block response or transaction block
956
954
  */
957
955
  public async claimBorrowIncentive<S extends boolean>(
958
- coinName: SupportBorrowIncentiveCoins,
959
956
  obligationId: string,
960
957
  obligationKeyId: string,
961
958
  sign: S = true as S,
@@ -965,17 +962,37 @@ export class ScallopClient {
965
962
  const sender = walletAddress ?? this.walletAddress;
966
963
  txBlock.setSender(sender);
967
964
 
968
- const rewardCoins = [];
969
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
965
+ const rewardCoinsCollection: Record<string, TransactionResult[]> = {};
966
+ const obligationAccount =
967
+ await this.query.getObligationAccount(obligationId);
968
+ const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
969
+ .flatMap(({ rewards }) =>
970
+ rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
971
+ )
972
+ .flatMap(({ coinName }) => coinName);
973
+ for (const rewardCoinName of rewardCoinNames) {
970
974
  const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
971
- coinName,
972
975
  rewardCoinName,
973
976
  obligationId,
974
977
  obligationKeyId
975
978
  );
976
- rewardCoins.push(rewardCoin);
979
+ if (!rewardCoinsCollection[rewardCoinName]) {
980
+ rewardCoinsCollection[rewardCoinName] = [rewardCoin];
981
+ } else {
982
+ rewardCoinsCollection[rewardCoinName].push(rewardCoin);
983
+ }
977
984
  }
978
- txBlock.transferObjects(rewardCoins, sender);
985
+
986
+ txBlock.transferObjects(
987
+ Object.values(rewardCoinsCollection).map((rewardCoins) => {
988
+ const mergeDest = rewardCoins[0];
989
+ if (rewardCoins.length > 1) {
990
+ txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
991
+ }
992
+ return mergeDest;
993
+ }),
994
+ sender
995
+ );
979
996
 
980
997
  if (sign) {
981
998
  return (await this.suiKit.signAndSendTxn(
@@ -8,7 +8,6 @@ import {
8
8
  SUPPORT_POOLS,
9
9
  SUPPORT_COLLATERALS,
10
10
  spoolRewardCoins,
11
- borrowIncentiveRewardCoins,
12
11
  coinDecimals,
13
12
  wormholeCoinIds,
14
13
  voloCoinIds,
@@ -41,7 +40,6 @@ import type {
41
40
  SupportAssetCoins,
42
41
  SupportMarketCoins,
43
42
  SupportStakeMarketCoins,
44
- SupportBorrowIncentiveCoins,
45
43
  CoinPrices,
46
44
  CoinWrappedType,
47
45
  SupportSCoin,
@@ -159,6 +157,10 @@ export class ScallopUtils {
159
157
  * @return Coin type.
160
158
  */
161
159
  public parseCoinType(coinName: SupportCoins) {
160
+ // try parse scoin first
161
+ if (sCoinIds[coinName as SupportSCoin]) {
162
+ return sCoinIds[coinName as SupportSCoin];
163
+ }
162
164
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
163
165
  const coinPackageId =
164
166
  this.address.get(`core.coins.${coinName}.id`) ||
@@ -395,18 +397,6 @@ export class ScallopUtils {
395
397
  return spoolRewardCoins[stakeMarketCoinName];
396
398
  };
397
399
 
398
- /**
399
- * Get reward type of borrow incentive pool.
400
- *
401
- * @param borrowIncentiveCoinName - Support borrow incentive coin.
402
- * @return Borrow incentive reward coin name.
403
- */
404
- public getBorrowIncentiveRewardCoinName = (
405
- borrowIncentiveCoinName: SupportBorrowIncentiveCoins
406
- ) => {
407
- return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
408
- };
409
-
410
400
  /**
411
401
  * Get coin decimal.
412
402
  *
@@ -4,10 +4,7 @@ import type {
4
4
  } from '@scallop-io/sui-kit';
5
5
  import type { TransactionResult } from '@mysten/sui/transactions';
6
6
  import type { ScallopBuilder } from '../../models';
7
- import type {
8
- SupportBorrowIncentiveCoins,
9
- SupportBorrowIncentiveRewardCoins,
10
- } from '../constant';
7
+ import type { SupportBorrowIncentiveRewardCoins } from '../constant';
11
8
 
12
9
  export type BorrowIncentiveIds = {
13
10
  borrowIncentivePkg: string;
@@ -35,7 +32,6 @@ export type BorrowIncentiveNormalMethods = {
35
32
  claimBorrowIncentive: (
36
33
  obligation: SuiObjectArg,
37
34
  obligationKey: SuiObjectArg,
38
- coinName: SupportBorrowIncentiveCoins,
39
35
  rewardType: SupportBorrowIncentiveRewardCoins
40
36
  ) => TransactionResult;
41
37
  deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
@@ -43,23 +39,22 @@ export type BorrowIncentiveNormalMethods = {
43
39
 
44
40
  export type BorrowIncentiveQuickMethods = {
45
41
  stakeObligationQuick(
46
- obligation?: SuiObjectArg,
47
- obligationKey?: SuiObjectArg
42
+ obligation?: string,
43
+ obligationKey?: string
48
44
  ): Promise<void>;
49
45
  stakeObligationWithVeScaQuick(
50
- obligation?: SuiObjectArg,
51
- obligationKey?: SuiObjectArg,
52
- veScaKey?: SuiObjectArg
46
+ obligation?: string,
47
+ obligationKey?: string,
48
+ veScaKey?: string
53
49
  ): Promise<void>;
54
50
  unstakeObligationQuick(
55
- obligation?: SuiObjectArg,
56
- obligationKey?: SuiObjectArg
51
+ obligation?: string,
52
+ obligationKey?: string
57
53
  ): Promise<void>;
58
54
  claimBorrowIncentiveQuick(
59
- coinName: SupportBorrowIncentiveCoins,
60
55
  rewardType: SupportBorrowIncentiveRewardCoins,
61
- obligation?: SuiObjectArg,
62
- obligationKey?: SuiObjectArg
56
+ obligation?: string,
57
+ obligationKey?: string
63
58
  ): Promise<TransactionResult>;
64
59
  };
65
60