@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.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.
Files changed (58) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +12 -0
  2. package/dist/constants/common.d.ts +3 -1
  3. package/dist/constants/enum.d.ts +3 -2
  4. package/dist/index.js +753 -211
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +714 -175
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/models/scallopClient.d.ts +33 -2
  9. package/dist/models/scallopQuery.d.ts +31 -10
  10. package/dist/models/scallopUtils.d.ts +11 -4
  11. package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
  12. package/dist/queries/coreQuery.d.ts +8 -0
  13. package/dist/queries/index.d.ts +1 -0
  14. package/dist/queries/spoolQuery.d.ts +13 -5
  15. package/dist/types/address.d.ts +8 -0
  16. package/dist/types/builder/borrowIncentive.d.ts +31 -0
  17. package/dist/types/builder/index.d.ts +3 -1
  18. package/dist/types/constant/common.d.ts +5 -3
  19. package/dist/types/constant/enum.d.ts +6 -3
  20. package/dist/types/query/borrowIncentive.d.ts +118 -0
  21. package/dist/types/query/core.d.ts +1 -0
  22. package/dist/types/query/index.d.ts +1 -0
  23. package/dist/types/query/spool.d.ts +12 -13
  24. package/dist/utils/builder.d.ts +8 -0
  25. package/dist/utils/index.d.ts +1 -1
  26. package/dist/utils/query.d.ts +33 -10
  27. package/dist/utils/util.d.ts +13 -0
  28. package/package.json +1 -1
  29. package/src/builders/borrowIncentiveBuilder.ts +257 -0
  30. package/src/builders/coreBuilder.ts +1 -14
  31. package/src/builders/index.ts +9 -2
  32. package/src/builders/spoolBuilder.ts +3 -16
  33. package/src/constants/common.ts +4 -1
  34. package/src/constants/enum.ts +8 -2
  35. package/src/models/scallopAddress.ts +8 -0
  36. package/src/models/scallopClient.ts +104 -2
  37. package/src/models/scallopQuery.ts +48 -14
  38. package/src/models/scallopUtils.ts +21 -5
  39. package/src/queries/borrowIncentiveQuery.ts +166 -0
  40. package/src/queries/coreQuery.ts +57 -15
  41. package/src/queries/index.ts +1 -0
  42. package/src/queries/spoolQuery.ts +78 -62
  43. package/src/types/address.ts +8 -0
  44. package/src/types/builder/borrowIncentive.ts +67 -0
  45. package/src/types/builder/index.ts +5 -1
  46. package/src/types/builder/spool.ts +0 -1
  47. package/src/types/constant/common.ts +10 -3
  48. package/src/types/constant/enum.ts +9 -3
  49. package/src/types/query/borrowIncentive.ts +150 -0
  50. package/src/types/query/core.ts +1 -1
  51. package/src/types/query/index.ts +1 -0
  52. package/src/types/query/spool.ts +28 -18
  53. package/src/utils/builder.ts +15 -0
  54. package/src/utils/index.ts +1 -1
  55. package/src/utils/query.ts +277 -70
  56. package/src/utils/util.ts +36 -2
  57. package/dist/utils/oracle.d.ts +0 -14
  58. package/src/utils/oracle.ts +0 -36
@@ -8,7 +8,8 @@ import {
8
8
  PROTOCOL_OBJECT_ID,
9
9
  SUPPORT_POOLS,
10
10
  SUPPORT_COLLATERALS,
11
- rewardCoins,
11
+ spoolRewardCoins,
12
+ borrowIncentiveRewardCoins,
12
13
  coinDecimals,
13
14
  wormholeCoinIds,
14
15
  voloCoinIds,
@@ -27,6 +28,7 @@ import type {
27
28
  SupportAssetCoins,
28
29
  SupportMarketCoins,
29
30
  SupportStakeMarketCoins,
31
+ SupportBorrowIncentiveCoins,
30
32
  CoinPrices,
31
33
  PriceMap,
32
34
  CoinWrappedType,
@@ -246,13 +248,27 @@ export class ScallopUtils {
246
248
  }
247
249
 
248
250
  /**
249
- * Get reward type of stake pool.
251
+ * Get reward type of spool.
250
252
  *
251
253
  * @param stakeMarketCoinName - Support stake market coin.
252
- * @return Reward coin name.
254
+ * @return Spool reward coin name.
253
255
  */
254
- public getRewardCoinName = (stakeMarketCoinName: SupportStakeMarketCoins) => {
255
- return rewardCoins[stakeMarketCoinName];
256
+ public getSpoolRewardCoinName = (
257
+ stakeMarketCoinName: SupportStakeMarketCoins
258
+ ) => {
259
+ return spoolRewardCoins[stakeMarketCoinName];
260
+ };
261
+
262
+ /**
263
+ * Get reward type of borrow incentive pool.
264
+ *
265
+ * @param borrowIncentiveCoinName - Support borrow incentive coin.
266
+ * @return Borrow incentive reward coin name.
267
+ */
268
+ public getBorrowIncentiveRewardCoinName = (
269
+ borrowIncentiveCoinName: SupportBorrowIncentiveCoins
270
+ ) => {
271
+ return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
256
272
  };
257
273
 
258
274
  /**
@@ -0,0 +1,166 @@
1
+ import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
+ import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
3
+ import {
4
+ parseOriginBorrowIncentivePoolData,
5
+ calculateBorrowIncentivePoolData,
6
+ parseOriginBorrowIncentiveRewardPoolData,
7
+ calculateBorrowIncentiveRewardPoolData,
8
+ parseOriginBorrowIncentiveAccountData,
9
+ } from '../utils';
10
+ import type { ScallopQuery } from '../models';
11
+ import type {
12
+ BorrowIncentivePoolsQueryInterface,
13
+ BorrowIncentivePools,
14
+ BorrowIncentiveAccountsQueryInterface,
15
+ BorrowIncentiveAccounts,
16
+ SupportBorrowIncentiveCoins,
17
+ SupportAssetCoins,
18
+ } from '../types';
19
+
20
+ /**
21
+ * Query borrow incentive pools data.
22
+ *
23
+ * @param query - The Scallop query instance.
24
+ * @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
25
+ * @return Borrow incentive pools data.
26
+ */
27
+ export const queryBorrowIncentivePools = async (
28
+ query: ScallopQuery,
29
+ borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]
30
+ ) => {
31
+ borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
32
+ ...SUPPORT_BORROW_INCENTIVE_POOLS,
33
+ ];
34
+ const queryPkgId = query.address.get('borrowIncentive.query');
35
+ const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
36
+ const txBlock = new SuiKitTxBlock();
37
+ const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
38
+ // The reward coin type currently only support sui, so bring it in directly here.
39
+ txBlock.moveCall(queryTarget, [incentivePoolsId], ['0x2::sui::SUI']);
40
+ const queryResult = await query.suiKit.inspectTxn(txBlock);
41
+ const borrowIncentivePoolsQueryData = queryResult.events[0]
42
+ .parsedJson as BorrowIncentivePoolsQueryInterface;
43
+
44
+ const parsedBorrowIncentiveRewardPoolData =
45
+ parseOriginBorrowIncentiveRewardPoolData(
46
+ borrowIncentivePoolsQueryData.reward_pool
47
+ );
48
+ const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
49
+
50
+ const borrowIncentivePools: BorrowIncentivePools = {};
51
+ for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
52
+ const coinType = '0x' + pool.pool_type.name;
53
+ const coinName =
54
+ query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(coinType);
55
+ const rewardCoinName =
56
+ query.utils.parseCoinNameFromType<SupportAssetCoins>(rewardCoinType);
57
+
58
+ // Filter pools not yet supported by the SDK.
59
+ if (!borrowIncentiveCoinNames.includes(coinName)) {
60
+ continue;
61
+ }
62
+
63
+ const coinPrices = await query.utils.getCoinPrices([
64
+ coinName,
65
+ rewardCoinName,
66
+ ]);
67
+
68
+ const parsedBorrowIncentivePoolData =
69
+ parseOriginBorrowIncentivePoolData(pool);
70
+
71
+ const coinPrice = coinPrices?.[coinName] ?? 0;
72
+ const coinDecimal = query.utils.getCoinDecimal(coinName);
73
+ const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
74
+ parsedBorrowIncentivePoolData,
75
+ coinPrice,
76
+ coinDecimal
77
+ );
78
+
79
+ const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
80
+ const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
81
+ const calculatedBorrowIncentiveRewardPoolData =
82
+ calculateBorrowIncentiveRewardPoolData(
83
+ parsedBorrowIncentivePoolData,
84
+ parsedBorrowIncentiveRewardPoolData,
85
+ calculatedBorrowIncentivePoolData,
86
+ rewardCoinPrice,
87
+ rewardCoinDecimal
88
+ );
89
+
90
+ borrowIncentivePools[coinName] = {
91
+ coinName: coinName,
92
+ symbol: query.utils.parseSymbol(coinName),
93
+ coinType: coinType,
94
+ rewardCoinType: rewardCoinType,
95
+ coinDecimal: coinDecimal,
96
+ rewardCoinDecimal: rewardCoinDecimal,
97
+ coinPrice: coinPrice,
98
+ rewardCoinPrice: rewardCoinPrice,
99
+ maxPoint: parsedBorrowIncentivePoolData.maxPoint,
100
+ distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
101
+ maxStake: parsedBorrowIncentivePoolData.maxStake,
102
+ ...calculatedBorrowIncentivePoolData,
103
+ exchangeRateNumerator:
104
+ parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
105
+ exchangeRateDenominator:
106
+ parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
107
+ ...calculatedBorrowIncentiveRewardPoolData,
108
+ };
109
+ }
110
+
111
+ return borrowIncentivePools;
112
+ };
113
+
114
+ /**
115
+ * Query borrow incentive accounts data.
116
+ *
117
+ * @param query - The Scallop query instance.
118
+ * @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
119
+ * @return Borrow incentive accounts data.
120
+ */
121
+ export const queryBorrowIncentiveAccounts = async (
122
+ query: ScallopQuery,
123
+ obligationId: string,
124
+ borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]
125
+ ) => {
126
+ borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
127
+ ...SUPPORT_BORROW_INCENTIVE_POOLS,
128
+ ];
129
+ const queryPkgId = query.address.get('borrowIncentive.query');
130
+ const incentiveAccountsId = query.address.get(
131
+ 'borrowIncentive.incentiveAccounts'
132
+ );
133
+ const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
134
+ const txBlock = new SuiKitTxBlock();
135
+ txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
136
+ const queryResult = await query.suiKit.inspectTxn(txBlock);
137
+ const borrowIncentiveAccountsQueryData = queryResult.events[0]
138
+ .parsedJson as BorrowIncentiveAccountsQueryInterface;
139
+
140
+ const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
141
+ borrowIncentiveAccountsQueryData.incentive_states
142
+ ).reduce((accounts, accountData) => {
143
+ const parsedBorrowIncentiveAccount =
144
+ parseOriginBorrowIncentiveAccountData(accountData);
145
+ const poolType = parsedBorrowIncentiveAccount.poolType;
146
+ const coinName =
147
+ query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(poolType);
148
+
149
+ if (
150
+ borrowIncentiveCoinNames &&
151
+ borrowIncentiveCoinNames.includes(coinName)
152
+ ) {
153
+ accounts[coinName] = {
154
+ poolType: poolType,
155
+ amount: parsedBorrowIncentiveAccount.amount,
156
+ points: parsedBorrowIncentiveAccount.points,
157
+ totalPoints: parsedBorrowIncentiveAccount.totalPoints,
158
+ index: parsedBorrowIncentiveAccount.index,
159
+ };
160
+ }
161
+
162
+ return accounts;
163
+ }, {} as BorrowIncentiveAccounts);
164
+
165
+ return borrowIncentiveAccounts;
166
+ };
@@ -59,6 +59,17 @@ export const queryMarket = async (query: ScallopQuery) => {
59
59
  const collaterals: MarketCollaterals = {};
60
60
 
61
61
  for (const pool of marketData.pools) {
62
+ const coinType = '0x' + pool.type.name;
63
+ const poolCoinName =
64
+ query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
65
+ const coinPrice =
66
+ (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
67
+
68
+ // Filter pools not yet supported by the SDK.
69
+ if (!SUPPORT_POOLS.includes(poolCoinName)) {
70
+ continue;
71
+ }
72
+
62
73
  const parsedMarketPoolData = parseOriginMarketPoolData({
63
74
  type: pool.type,
64
75
  maxBorrowRate: pool.maxBorrowRate,
@@ -85,12 +96,6 @@ export const queryMarket = async (query: ScallopQuery) => {
85
96
  parsedMarketPoolData
86
97
  );
87
98
 
88
- const coinType = '0x' + pool.type.name;
89
- const poolCoinName =
90
- query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
91
- const coinPrice =
92
- (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
93
-
94
99
  pools[poolCoinName] = {
95
100
  coinName: poolCoinName,
96
101
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -110,6 +115,19 @@ export const queryMarket = async (query: ScallopQuery) => {
110
115
  }
111
116
 
112
117
  for (const collateral of marketData.collaterals) {
118
+ const coinType = '0x' + collateral.type.name;
119
+ const collateralCoinName =
120
+ query.utils.parseCoinNameFromType<SupportCollateralCoins>(coinType);
121
+ const coinPrice =
122
+ (await query.utils.getCoinPrices([collateralCoinName]))?.[
123
+ collateralCoinName
124
+ ] ?? 0;
125
+
126
+ // Filter collaterals not yet supported by the SDK.
127
+ if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
128
+ continue;
129
+ }
130
+
113
131
  const parsedMarketCollateralData = parseOriginMarketCollateralData({
114
132
  type: collateral.type,
115
133
  collateralFactor: collateral.collateralFactor,
@@ -126,14 +144,6 @@ export const queryMarket = async (query: ScallopQuery) => {
126
144
  parsedMarketCollateralData
127
145
  );
128
146
 
129
- const coinType = '0x' + collateral.type.name;
130
- const collateralCoinName =
131
- query.utils.parseCoinNameFromType<SupportCollateralCoins>(coinType);
132
- const coinPrice =
133
- (await query.utils.getCoinPrices([collateralCoinName]))?.[
134
- collateralCoinName
135
- ] ?? 0;
136
-
137
147
  collaterals[collateralCoinName] = {
138
148
  coinName: collateralCoinName,
139
149
  symbol: query.utils.parseSymbol(collateralCoinName),
@@ -586,12 +596,44 @@ export const getObligations = async (
586
596
  if (keyObject.content && 'fields' in keyObject.content) {
587
597
  const fields = keyObject.content.fields as any;
588
598
  const obligationId = String(fields.ownership.fields.of);
589
- obligations.push({ id: obligationId, keyId });
599
+ const locked = await getObligationLocked(query, obligationId);
600
+ obligations.push({ id: obligationId, keyId, locked });
590
601
  }
591
602
  }
592
603
  return obligations;
593
604
  };
594
605
 
606
+ /**
607
+ * Query obligation locked status.
608
+ *
609
+ * @param query - The Scallop query instance.
610
+ * @param obligationId - The obligation id.
611
+ * @return Obligation locked status.
612
+ */
613
+ export const getObligationLocked = async (
614
+ query: ScallopQuery,
615
+ obligationId: string
616
+ ) => {
617
+ const obligationObjectResponse = await query.suiKit.client().getObject({
618
+ id: obligationId,
619
+ options: {
620
+ showContent: true,
621
+ },
622
+ });
623
+ let obligationLocked = false;
624
+ if (
625
+ obligationObjectResponse.data &&
626
+ obligationObjectResponse?.data?.content?.dataType === 'moveObject' &&
627
+ 'lock_key' in obligationObjectResponse.data.content.fields
628
+ ) {
629
+ obligationLocked = Boolean(
630
+ obligationObjectResponse.data.content.fields.lock_key
631
+ );
632
+ }
633
+
634
+ return obligationLocked;
635
+ };
636
+
595
637
  /**
596
638
  * Query obligation data.
597
639
  *
@@ -1,4 +1,5 @@
1
1
  export * from './coreQuery';
2
2
  export * from './spoolQuery';
3
+ export * from './borrowIncentiveQuery';
3
4
  export * from './priceQuery';
4
5
  export * from './portfolioQuery';
@@ -1,10 +1,10 @@
1
1
  import { normalizeStructTag } from '@mysten/sui.js/utils';
2
2
  import { SUPPORT_SPOOLS } from '../constants';
3
3
  import {
4
- parseOriginStakePoolData,
5
- calculateStakePoolData,
6
- parseOriginRewardPoolData,
7
- calculateRewardPoolData,
4
+ parseOriginSpoolData,
5
+ calculateSpoolData,
6
+ parseOriginSpoolRewardPoolData,
7
+ calculateSpoolRewardPoolData,
8
8
  isMarketCoin,
9
9
  } from '../utils';
10
10
  import type { SuiObjectResponse } from '@mysten/sui.js/client';
@@ -14,7 +14,7 @@ import type {
14
14
  Spools,
15
15
  Spool,
16
16
  StakePool,
17
- RewardPool,
17
+ StakeRewardPool,
18
18
  StakeAccounts,
19
19
  SupportStakeMarketCoins,
20
20
  SupportStakeCoins,
@@ -64,18 +64,17 @@ export const getSpools = async (
64
64
  */
65
65
  export const getSpool = async (
66
66
  query: ScallopQuery,
67
- stakeMarketCoinName: SupportStakeMarketCoins,
67
+ marketCoinName: SupportStakeMarketCoins,
68
68
  marketPool?: MarketPool
69
69
  ) => {
70
- const stakeCoinName =
71
- query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
72
- marketPool = marketPool || (await query.getMarketPool(stakeCoinName));
73
- const poolId = query.address.get(`spool.pools.${stakeMarketCoinName}.id`);
70
+ const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
71
+ marketPool = marketPool || (await query.getMarketPool(coinName));
72
+ const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
74
73
  const rewardPoolId = query.address.get(
75
- `spool.pools.${stakeMarketCoinName}.rewardPoolId`
74
+ `spool.pools.${marketCoinName}.rewardPoolId`
76
75
  );
77
76
  let spool: Spool | undefined = undefined;
78
- const stakePoolObjectResponse = await query.suiKit.client().multiGetObjects({
77
+ const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
79
78
  ids: [poolId, rewardPoolId],
80
79
  options: {
81
80
  showContent: true,
@@ -84,20 +83,20 @@ export const getSpool = async (
84
83
 
85
84
  if (
86
85
  marketPool &&
87
- stakePoolObjectResponse[0].data &&
88
- stakePoolObjectResponse[1].data
86
+ spoolObjectResponse[0].data &&
87
+ spoolObjectResponse[1].data
89
88
  ) {
90
- const rewardCoin = query.utils.getRewardCoinName(stakeMarketCoinName);
89
+ const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
91
90
  const coinPrices = await query.utils.getCoinPrices([
92
- stakeCoinName,
93
- rewardCoin,
91
+ coinName,
92
+ rewardCoinName,
94
93
  ]);
95
94
 
96
- const stakePoolObject = stakePoolObjectResponse[0].data;
97
- const rewardPoolObject = stakePoolObjectResponse[1].data;
98
- if (stakePoolObject.content && 'fields' in stakePoolObject.content) {
99
- const fields = stakePoolObject.content.fields as any;
100
- const parsedStakePoolData = parseOriginStakePoolData({
95
+ const spoolObject = spoolObjectResponse[0].data;
96
+ const rewardPoolObject = spoolObjectResponse[1].data;
97
+ if (spoolObject.content && 'fields' in spoolObject.content) {
98
+ const fields = spoolObject.content.fields as any;
99
+ const parsedSpoolData = parseOriginSpoolData({
101
100
  stakeType: fields.stake_type,
102
101
  maxDistributedPoint: fields.max_distributed_point,
103
102
  distributedPoint: fields.distributed_point,
@@ -110,19 +109,18 @@ export const getSpool = async (
110
109
  lastUpdate: fields.last_update,
111
110
  });
112
111
 
113
- const stakeMarketCoinPrice =
114
- (coinPrices?.[stakeCoinName] ?? 0) * marketPool.conversionRate;
115
- const stakeMarketCoinDecimal =
116
- query.utils.getCoinDecimal(stakeMarketCoinName);
117
- const calculatedStakePoolData = calculateStakePoolData(
118
- parsedStakePoolData,
119
- stakeMarketCoinPrice,
120
- stakeMarketCoinDecimal
112
+ const marketCoinPrice =
113
+ (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
114
+ const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
115
+ const calculatedSpoolData = calculateSpoolData(
116
+ parsedSpoolData,
117
+ marketCoinPrice,
118
+ marketCoinDecimal
121
119
  );
122
120
 
123
121
  if (rewardPoolObject.content && 'fields' in rewardPoolObject.content) {
124
122
  const fields = rewardPoolObject.content.fields as any;
125
- const parsedRewardPoolData = parseOriginRewardPoolData({
123
+ const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
126
124
  claimed_rewards: fields.claimed_rewards,
127
125
  exchange_rate_numerator: fields.exchange_rate_numerator,
128
126
  exchange_rate_denominator: fields.exchange_rate_denominator,
@@ -130,31 +128,38 @@ export const getSpool = async (
130
128
  spool_id: fields.spool_id,
131
129
  });
132
130
 
133
- const rewardCoinPrice = coinPrices?.[rewardCoin] ?? 0;
134
- const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoin);
131
+ const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
132
+ const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
135
133
 
136
- const calculatedRewardPoolData = calculateRewardPoolData(
137
- parsedStakePoolData,
138
- parsedRewardPoolData,
139
- calculatedStakePoolData,
134
+ const calculatedRewardPoolData = calculateSpoolRewardPoolData(
135
+ parsedSpoolData,
136
+ parsedSpoolRewardPoolData,
137
+ calculatedSpoolData,
140
138
  rewardCoinPrice,
141
139
  rewardCoinDecimal
142
140
  );
143
141
 
144
142
  spool = {
145
- marketCoinName: stakeMarketCoinName,
146
- symbol: query.utils.parseSymbol(stakeMarketCoinName),
147
- coinType: query.utils.parseCoinType(stakeCoinName),
148
- marketCoinType: query.utils.parseMarketCoinType(stakeCoinName),
149
- rewardCoinType: isMarketCoin(rewardCoin)
150
- ? query.utils.parseMarketCoinType(rewardCoin)
151
- : query.utils.parseCoinType(rewardCoin),
152
- coinDecimal: query.utils.getCoinDecimal(stakeCoinName),
153
- rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoin),
154
- coinPrice: coinPrices?.[stakeCoinName] ?? 0,
155
- marketCoinPrice: stakeMarketCoinPrice,
143
+ marketCoinName: marketCoinName,
144
+ symbol: query.utils.parseSymbol(marketCoinName),
145
+ coinType: query.utils.parseCoinType(coinName),
146
+ marketCoinType: query.utils.parseMarketCoinType(coinName),
147
+ rewardCoinType: isMarketCoin(rewardCoinName)
148
+ ? query.utils.parseMarketCoinType(rewardCoinName)
149
+ : query.utils.parseCoinType(rewardCoinName),
150
+ coinDecimal: query.utils.getCoinDecimal(coinName),
151
+ rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
152
+ coinPrice: coinPrices?.[coinName] ?? 0,
153
+ marketCoinPrice: marketCoinPrice,
156
154
  rewardCoinPrice: rewardCoinPrice,
157
- ...calculatedStakePoolData,
155
+ maxPoint: parsedSpoolData.maxPoint,
156
+ distributedPoint: parsedSpoolData.distributedPoint,
157
+ maxStake: parsedSpoolData.maxStake,
158
+ ...calculatedSpoolData,
159
+ exchangeRateNumerator:
160
+ parsedSpoolRewardPoolData.exchangeRateNumerator,
161
+ exchangeRateDenominator:
162
+ parsedSpoolRewardPoolData.exchangeRateDenominator,
158
163
  ...calculatedRewardPoolData,
159
164
  };
160
165
  }
@@ -281,6 +286,10 @@ export const getStakeAccounts = async (
281
286
  /**
282
287
  * Get stake pool data.
283
288
  *
289
+ * @description
290
+ * For backward compatible, it is recommended to use `getSpool` method
291
+ * to get stake pool info in spool data.
292
+ *
284
293
  * @param query - The Scallop query instance.
285
294
  * @param marketCoinName - Specific support stake market coin name.
286
295
  * @return Stake pool data.
@@ -334,39 +343,46 @@ export const getStakePool = async (
334
343
  };
335
344
 
336
345
  /**
337
- * Get reward pool of the owner.
346
+ * Get stake reward pool of the owner.
347
+ *
348
+ * @description
349
+ * For backward compatible, it is recommended to use `getSpool` method
350
+ * to get reward info in spool data.
338
351
  *
339
352
  * @param query - The Scallop query instance.
340
353
  * @param marketCoinName - Specific support stake market coin name.
341
- * @return Reward pool.
354
+ * @return Stake reward pool.
342
355
  */
343
- export const getRewardPool = async (
356
+ export const getStakeRewardPool = async (
344
357
  query: ScallopQuery,
345
358
  marketCoinName: SupportStakeMarketCoins
346
359
  ) => {
347
360
  const poolId = query.address.get(
348
361
  `spool.pools.${marketCoinName}.rewardPoolId`
349
362
  );
350
- let rewardPool: RewardPool | undefined = undefined;
351
- const rewardPoolObjectResponse = await query.suiKit.client().getObject({
363
+ let stakeRewardPool: StakeRewardPool | undefined = undefined;
364
+ const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
352
365
  id: poolId,
353
366
  options: {
354
367
  showContent: true,
355
368
  showType: true,
356
369
  },
357
370
  });
358
- if (rewardPoolObjectResponse.data) {
359
- const rewardPoolObject = rewardPoolObjectResponse.data;
360
- const id = rewardPoolObject.objectId;
361
- const type = rewardPoolObject.type!;
362
- if (rewardPoolObject.content && 'fields' in rewardPoolObject.content) {
363
- const fields = rewardPoolObject.content.fields as any;
371
+ if (stakeRewardPoolObjectResponse.data) {
372
+ const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
373
+ const id = stakeRewardPoolObject.objectId;
374
+ const type = stakeRewardPoolObject.type!;
375
+ if (
376
+ stakeRewardPoolObject.content &&
377
+ 'fields' in stakeRewardPoolObject.content
378
+ ) {
379
+ const fields = stakeRewardPoolObject.content.fields as any;
364
380
  const stakePoolId = String(fields.spool_id);
365
381
  const ratioNumerator = Number(fields.exchange_rate_numerator);
366
382
  const ratioDenominator = Number(fields.exchange_rate_denominator);
367
383
  const rewards = Number(fields.rewards);
368
384
  const claimedRewards = Number(fields.claimed_rewards);
369
- rewardPool = {
385
+ stakeRewardPool = {
370
386
  id,
371
387
  type,
372
388
  stakePoolId,
@@ -377,5 +393,5 @@ export const getRewardPool = async (
377
393
  };
378
394
  }
379
395
  }
380
- return rewardPool;
396
+ return stakeRewardPool;
381
397
  };
@@ -13,6 +13,7 @@ export interface AddressesInterface {
13
13
  market: string;
14
14
  adminCap: string;
15
15
  coinDecimalsRegistry: string;
16
+ obligationAccessStore: string;
16
17
  coins: Partial<
17
18
  Record<
18
19
  SupportAssetCoins,
@@ -80,6 +81,13 @@ export interface AddressesInterface {
80
81
  >
81
82
  >;
82
83
  };
84
+ borrowIncentive: {
85
+ id: string;
86
+ adminCap: string;
87
+ query: string;
88
+ incentivePools: string;
89
+ incentiveAccounts: string;
90
+ };
83
91
  }
84
92
 
85
93
  type AddressPathsProps<T> = T extends string
@@ -0,0 +1,67 @@
1
+ import type {
2
+ SuiTxBlock as SuiKitTxBlock,
3
+ SuiAddressArg,
4
+ } from '@scallop-io/sui-kit';
5
+ import type { TransactionResult } from '@mysten/sui.js/transactions';
6
+ import type { ScallopBuilder } from '../../models';
7
+ import type { SupportBorrowIncentiveCoins } from '../constant';
8
+
9
+ export type BorrowIncentiveIds = {
10
+ borrowIncentivePkg: string;
11
+ query: string;
12
+ incentivePools: string;
13
+ incentiveAccounts: string;
14
+ obligationAccessStore: string;
15
+ };
16
+
17
+ export type BorrowIncentiveNormalMethods = {
18
+ stakeObligation: (
19
+ obligation: SuiAddressArg,
20
+ obligaionKey: SuiAddressArg,
21
+ coinName: SupportBorrowIncentiveCoins
22
+ ) => void;
23
+ unstakeObligation: (
24
+ obligation: SuiAddressArg,
25
+ obligaionKey: SuiAddressArg,
26
+ coinName: SupportBorrowIncentiveCoins
27
+ ) => void;
28
+ claimBorrowIncentive: (
29
+ obligation: SuiAddressArg,
30
+ obligaionKey: SuiAddressArg,
31
+ coinName: SupportBorrowIncentiveCoins
32
+ ) => TransactionResult;
33
+ };
34
+
35
+ export type BorrowIncentiveQuickMethods = {
36
+ stakeObligationQuick(
37
+ coinName: SupportBorrowIncentiveCoins,
38
+ obligation?: SuiAddressArg,
39
+ obligationKey?: SuiAddressArg
40
+ ): Promise<void>;
41
+ unstakeObligationQuick(
42
+ coinName: SupportBorrowIncentiveCoins,
43
+ obligation?: SuiAddressArg,
44
+ obligationKey?: SuiAddressArg
45
+ ): Promise<void>;
46
+ claimBorrowIncentiveQuick(
47
+ coinName: SupportBorrowIncentiveCoins,
48
+ obligation?: SuiAddressArg,
49
+ obligationKey?: SuiAddressArg
50
+ ): Promise<TransactionResult>;
51
+ };
52
+
53
+ export type SuiTxBlockWithBorrowIncentiveNormalMethods = SuiKitTxBlock &
54
+ BorrowIncentiveNormalMethods;
55
+
56
+ export type BorrowIncentiveTxBlock =
57
+ SuiTxBlockWithBorrowIncentiveNormalMethods & BorrowIncentiveQuickMethods;
58
+
59
+ export type GenerateBorrowIncentiveNormalMethod = (params: {
60
+ builder: ScallopBuilder;
61
+ txBlock: SuiKitTxBlock;
62
+ }) => BorrowIncentiveNormalMethods;
63
+
64
+ export type GenerateBorrowIncentiveQuickMethod = (params: {
65
+ builder: ScallopBuilder;
66
+ txBlock: SuiTxBlockWithBorrowIncentiveNormalMethods;
67
+ }) => BorrowIncentiveQuickMethods;
@@ -1,7 +1,11 @@
1
1
  import type { CoreTxBlock } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
+ import type { BorrowIncentiveTxBlock } from './borrowIncentive';
3
4
 
4
5
  export type * from './core';
5
6
  export type * from './spool';
7
+ export type * from './borrowIncentive';
6
8
 
7
- export type ScallopTxBlock = CoreTxBlock & SpoolTxBlock;
9
+ export type ScallopTxBlock = CoreTxBlock &
10
+ SpoolTxBlock &
11
+ BorrowIncentiveTxBlock;
@@ -38,7 +38,6 @@ export type SpoolQuickMethods = {
38
38
  stakeMarketCoinName: SupportStakeMarketCoins,
39
39
  stakeAccountId?: SuiAddressArg
40
40
  ): Promise<void>;
41
-
42
41
  unstakeQuick(
43
42
  amount: number,
44
43
  stakeMarketCoinName: SupportStakeMarketCoins,