@scallop-io/sui-scallop-sdk 0.44.18 → 0.44.19

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 (56) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +7 -0
  2. package/dist/builders/vescaBuilder.d.ts +24 -0
  3. package/dist/constants/common.d.ts +7 -4
  4. package/dist/constants/index.d.ts +1 -0
  5. package/dist/constants/vesca.d.ts +5 -0
  6. package/dist/index.js +874 -254
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +863 -247
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/models/scallopClient.d.ts +7 -7
  11. package/dist/models/scallopUtils.d.ts +16 -14
  12. package/dist/queries/index.d.ts +1 -0
  13. package/dist/queries/vescaQuery.d.ts +28 -0
  14. package/dist/types/address.d.ts +9 -0
  15. package/dist/types/builder/borrowIncentive.d.ts +9 -6
  16. package/dist/types/builder/index.d.ts +3 -1
  17. package/dist/types/builder/vesca.d.ts +33 -0
  18. package/dist/types/constant/enum.d.ts +1 -1
  19. package/dist/types/query/borrowIncentive.d.ts +65 -60
  20. package/dist/types/query/index.d.ts +1 -0
  21. package/dist/types/query/portfolio.d.ts +12 -6
  22. package/dist/types/query/vesca.d.ts +7 -0
  23. package/dist/types/utils.d.ts +1 -2
  24. package/dist/utils/builder.d.ts +6 -0
  25. package/dist/utils/query.d.ts +4 -10
  26. package/dist/utils/util.d.ts +7 -0
  27. package/package.json +1 -1
  28. package/src/builders/borrowIncentiveBuilder.ts +174 -25
  29. package/src/builders/index.ts +6 -2
  30. package/src/builders/vescaBuilder.ts +392 -0
  31. package/src/constants/common.ts +19 -6
  32. package/src/constants/enum.ts +9 -3
  33. package/src/constants/index.ts +1 -0
  34. package/src/constants/vesca.ts +7 -0
  35. package/src/models/scallopAddress.ts +9 -1
  36. package/src/models/scallopClient.ts +29 -20
  37. package/src/models/scallopUtils.ts +45 -0
  38. package/src/queries/borrowIncentiveQuery.ts +93 -83
  39. package/src/queries/coreQuery.ts +19 -20
  40. package/src/queries/index.ts +1 -0
  41. package/src/queries/portfolioQuery.ts +79 -41
  42. package/src/queries/spoolQuery.ts +1 -1
  43. package/src/queries/vescaQuery.ts +124 -0
  44. package/src/types/address.ts +9 -0
  45. package/src/types/builder/borrowIncentive.ts +22 -5
  46. package/src/types/builder/index.ts +4 -1
  47. package/src/types/builder/vesca.ts +73 -0
  48. package/src/types/constant/enum.ts +1 -1
  49. package/src/types/query/borrowIncentive.ts +195 -74
  50. package/src/types/query/index.ts +1 -0
  51. package/src/types/query/portfolio.ts +17 -6
  52. package/src/types/query/vesca.ts +7 -0
  53. package/src/types/utils.ts +1 -1
  54. package/src/utils/builder.ts +141 -0
  55. package/src/utils/query.ts +221 -130
  56. package/src/utils/util.ts +28 -0
@@ -1,14 +1,27 @@
1
1
  export const API_BASE_URL = 'https://sui.api.scallop.io';
2
2
  export const SDK_API_BASE_URL = 'https://sdk.api.scallop.io';
3
3
 
4
- export const ADDRESSES_ID = '6462a088a7ace142bb6d7e9b';
4
+ export const IS_VE_SCA_TEST = false;
5
5
 
6
- export const PROTOCOL_OBJECT_ID =
7
- '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf';
6
+ export const ADDRESSES_ID = IS_VE_SCA_TEST
7
+ ? ('65fb07c39c845425d71d7b18' as const)
8
+ : ('6601955b8b0024600a917079' as const);
9
+ // : ('6462a088a7ace142bb6d7e9b' as const);
8
10
 
9
- export const BORROW_FEE_PROTOCOL_ID =
10
- '0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da';
11
+ export const PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST
12
+ ? ('0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778' as const)
13
+ : ('0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf' as const);
11
14
 
15
+ export const BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST
16
+ ? ('0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778' as const)
17
+ : ('0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da' as const); // test environment
18
+
19
+ export const SCA_COIN_TYPE = IS_VE_SCA_TEST
20
+ ? (`0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` as const)
21
+ : ('0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA' as const);
22
+
23
+ export const OLD_BORROW_INCENTIVE_PROTOCOL_ID =
24
+ '0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410' as const;
12
25
  export const SUPPORT_POOLS = [
13
26
  'eth',
14
27
  'btc',
@@ -52,7 +65,7 @@ export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
52
65
 
53
66
  export const SUPPORT_BORROW_INCENTIVE_POOLS = ['sui', 'usdc', 'usdt'] as const;
54
67
 
55
- export const SUPPORT_BORROW_INCENTIVE_REWARDS = ['sui'] as const;
68
+ export const SUPPORT_BORROW_INCENTIVE_REWARDS = ['sui', 'sca'] as const;
56
69
  export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
57
70
 
58
71
  export const SUPPORT_PACKAGES = [
@@ -9,6 +9,7 @@ import type {
9
9
  WormholeCoinIds,
10
10
  VoloCoinIds,
11
11
  } from '../types';
12
+ import { IS_VE_SCA_TEST } from './common';
12
13
 
13
14
  export const coinDecimals: SupportCoinDecimals = {
14
15
  eth: 8,
@@ -33,6 +34,7 @@ export const coinDecimals: SupportCoinDecimals = {
33
34
  safsui: 9,
34
35
  shasui: 9,
35
36
  svsui: 9,
37
+ sca: 9,
36
38
  };
37
39
 
38
40
  export const assetCoins: AssetCoins = {
@@ -47,6 +49,7 @@ export const assetCoins: AssetCoins = {
47
49
  afsui: 'afsui',
48
50
  hasui: 'hasui',
49
51
  vsui: 'vsui',
52
+ sca: 'sca',
50
53
  };
51
54
 
52
55
  export const marketCoins: MarketCoins = {
@@ -86,9 +89,9 @@ export const spoolRewardCoins: StakeRewardCoins = {
86
89
  };
87
90
 
88
91
  export const borrowIncentiveRewardCoins: BorrowIncentiveRewardCoins = {
89
- sui: 'sui',
90
- usdc: 'sui',
91
- usdt: 'sui',
92
+ sui: ['sui', 'sca'],
93
+ usdc: ['sui', 'sca'],
94
+ usdt: ['sui', 'sca'],
92
95
  };
93
96
 
94
97
  export const coinIds: AssetCoinIds = {
@@ -103,6 +106,9 @@ export const coinIds: AssetCoinIds = {
103
106
  afsui: '0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc',
104
107
  hasui: '0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d',
105
108
  vsui: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55',
109
+ sca: IS_VE_SCA_TEST
110
+ ? '0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524'
111
+ : '0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6',
106
112
  };
107
113
 
108
114
  export const wormholeCoinIds: WormholeCoinIds = {
@@ -1,2 +1,3 @@
1
1
  export * from './common';
2
2
  export * from './enum';
3
+ export * from './vesca';
@@ -0,0 +1,7 @@
1
+ export const UNLOCK_ROUND_DURATION = 60 * 60 * 24; // 1 days in seconds
2
+ export const MAX_LOCK_ROUNDS: number = 1460; // 4 years in days
3
+ export const MAX_LOCK_DURATION: number =
4
+ MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION; // 4 years in seconds
5
+
6
+ export const MIN_INITIAL_LOCK_AMOUNT: number = 10_000_000_000 as const;
7
+ export const MIN_TOP_UP_AMOUNT: number = 1_000_000_000 as const;
@@ -230,9 +230,18 @@ const EMPTY_ADDRESSES: AddressesInterface = {
230
230
  adminCap: '',
231
231
  object: '',
232
232
  query: '',
233
+ config: '',
233
234
  incentivePools: '',
234
235
  incentiveAccounts: '',
235
236
  },
237
+ vesca: {
238
+ id: '',
239
+ adminCap: '',
240
+ tableId: '',
241
+ table: '',
242
+ treasury: '',
243
+ config: '',
244
+ },
236
245
  };
237
246
 
238
247
  /**
@@ -452,7 +461,6 @@ export class ScallopAddress {
452
461
  */
453
462
  public async read(id?: string) {
454
463
  const addressesId = id || this._id || undefined;
455
-
456
464
  if (addressesId !== undefined) {
457
465
  const response = await this._requestClient.get(
458
466
  `${API_BASE_URL}/addresses/${addressesId}`,
@@ -1,6 +1,10 @@
1
1
  import { normalizeSuiAddress } from '@mysten/sui.js/utils';
2
2
  import { SuiKit } from '@scallop-io/sui-kit';
3
- import { ADDRESSES_ID, SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
3
+ import {
4
+ ADDRESSES_ID,
5
+ SUPPORT_BORROW_INCENTIVE_POOLS,
6
+ SUPPORT_BORROW_INCENTIVE_REWARDS,
7
+ } from '../constants';
4
8
  import { ScallopAddress } from './scallopAddress';
5
9
  import { ScallopUtils } from './scallopUtils';
6
10
  import { ScallopBuilder } from './scallopBuilder';
@@ -782,7 +786,7 @@ export class ScallopClient {
782
786
  for (const stakeMarketCoin of stakeMarketCoins) {
783
787
  const stakeCoinName =
784
788
  this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
785
- const coin = await txBlock.withdraw(stakeMarketCoin, stakeCoinName);
789
+ const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
786
790
  coins.push(coin);
787
791
  }
788
792
  txBlock.transferObjects(coins, sender);
@@ -845,15 +849,15 @@ export class ScallopClient {
845
849
  /**
846
850
  * stake obligaion.
847
851
  *
848
- * @param obligaionId - The obligation account object.
849
- * @param obligaionKeyId - The obligation key account object.
852
+ * @param obligationId - The obligation account object.
853
+ * @param obligationKeyId - The obligation key account object.
850
854
  * @param sign - Decide to directly sign the transaction or return the transaction block.
851
855
  * @param walletAddress - The wallet address of the owner.
852
856
  * @return Transaction block response or transaction block
853
857
  */
854
858
  public async stakeObligation<S extends boolean>(
855
- obligaionId: string,
856
- obligaionKeyId: string,
859
+ obligationId: string,
860
+ obligationKeyId: string,
857
861
  sign: S = true as S,
858
862
  walletAddress?: string
859
863
  ): Promise<ScallopClientFnReturnType<S>> {
@@ -861,7 +865,7 @@ export class ScallopClient {
861
865
  const sender = walletAddress || this.walletAddress;
862
866
  txBlock.setSender(sender);
863
867
 
864
- await txBlock.stakeObligationQuick(obligaionId, obligaionKeyId);
868
+ await txBlock.stakeObligationQuick(obligationId, obligationKeyId);
865
869
 
866
870
  if (sign) {
867
871
  return (await this.suiKit.signAndSendTxn(
@@ -875,15 +879,15 @@ export class ScallopClient {
875
879
  /**
876
880
  * unstake obligaion.
877
881
  *
878
- * @param obligaionId - The obligation account object.
879
- * @param obligaionKeyId - The obligation key account object.
882
+ * @param obligationId - The obligation account object.
883
+ * @param obligationKeyId - The obligation key account object.
880
884
  * @param sign - Decide to directly sign the transaction or return the transaction block.
881
885
  * @param walletAddress - The wallet address of the owner.
882
886
  * @return Transaction block response or transaction block
883
887
  */
884
888
  public async unstakeObligation<S extends boolean>(
885
- obligaionId: string,
886
- obligaionKeyId: string,
889
+ obligationId: string,
890
+ obligationKeyId: string,
887
891
  sign: S = true as S,
888
892
  walletAddress?: string
889
893
  ): Promise<ScallopClientFnReturnType<S>> {
@@ -891,7 +895,7 @@ export class ScallopClient {
891
895
  const sender = walletAddress || this.walletAddress;
892
896
  txBlock.setSender(sender);
893
897
 
894
- await txBlock.unstakeObligationQuick(obligaionId, obligaionKeyId);
898
+ await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
895
899
 
896
900
  if (sign) {
897
901
  return (await this.suiKit.signAndSendTxn(
@@ -914,8 +918,8 @@ export class ScallopClient {
914
918
  */
915
919
  public async claimBorrowIncentive<S extends boolean>(
916
920
  coinName: SupportBorrowIncentiveCoins,
917
- obligaionId: string,
918
- obligaionKeyId: string,
921
+ obligationId: string,
922
+ obligationKeyId: string,
919
923
  sign: S = true as S,
920
924
  walletAddress?: string
921
925
  ): Promise<ScallopClientFnReturnType<S>> {
@@ -923,12 +927,17 @@ export class ScallopClient {
923
927
  const sender = walletAddress || this.walletAddress;
924
928
  txBlock.setSender(sender);
925
929
 
926
- const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
927
- coinName,
928
- obligaionId,
929
- obligaionKeyId
930
- );
931
- txBlock.transferObjects([rewardCoin], sender);
930
+ const rewardCoins = [];
931
+ for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
932
+ const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
933
+ coinName,
934
+ rewardCoinName,
935
+ obligationId,
936
+ obligationKeyId
937
+ );
938
+ rewardCoins.push(rewardCoin);
939
+ }
940
+ txBlock.transferObjects(rewardCoins, sender);
932
941
 
933
942
  if (sign) {
934
943
  return (await this.suiKit.signAndSendTxn(
@@ -14,12 +14,15 @@ import {
14
14
  wormholeCoinIds,
15
15
  voloCoinIds,
16
16
  coinIds,
17
+ UNLOCK_ROUND_DURATION,
18
+ MAX_LOCK_DURATION,
17
19
  } from '../constants';
18
20
  import { queryObligation } from '../queries';
19
21
  import {
20
22
  parseDataFromPythPriceFeed,
21
23
  isMarketCoin,
22
24
  parseAssetSymbol,
25
+ findClosestUnlockRound,
23
26
  } from '../utils';
24
27
  import type {
25
28
  ScallopUtilsParams,
@@ -465,4 +468,46 @@ export class ScallopUtils {
465
468
  public parseApyToApr(apy: number, compoundFrequency = 365) {
466
469
  return ((1 + apy) ** (1 / compoundFrequency) - 1) * compoundFrequency;
467
470
  }
471
+
472
+ /**
473
+ * Give extend lock period to get unlock at in seconds timestamp.
474
+ *
475
+ * @description
476
+ * - When the user without remaining unlock period, If the extended unlock day is not specified,
477
+ * the unlock period will be increased by one day by default.
478
+ * - When the given extended day plus the user's remaining unlock period exceeds the maximum
479
+ * unlock period, the maximum unlock period is used as unlock period.
480
+ *
481
+ * @param extendLockPeriodInDay The extend lock period in day.
482
+ * @param unlockAtInSecondTimestamp The unlock timestamp from veSca object.
483
+ * @return New unlock at in seconds timestamp.
484
+ */
485
+ public getUnlockAt(
486
+ extendLockPeriodInDay?: number,
487
+ unlockAtInSecondTimestamp?: number
488
+ ) {
489
+ const now = Math.floor(new Date().getTime() / 1000);
490
+ const remainingLockPeriod = unlockAtInSecondTimestamp
491
+ ? Math.max(unlockAtInSecondTimestamp - now, 0)
492
+ : 0;
493
+
494
+ let newUnlockAtInSecondTimestamp = 0;
495
+
496
+ if (remainingLockPeriod === 0) {
497
+ const lockPeriod = (extendLockPeriodInDay ?? 1) * UNLOCK_ROUND_DURATION;
498
+ newUnlockAtInSecondTimestamp = Math.min(
499
+ now + lockPeriod,
500
+ now + MAX_LOCK_DURATION
501
+ );
502
+ } else {
503
+ const lockPeriod = Math.min(
504
+ extendLockPeriodInDay
505
+ ? extendLockPeriodInDay * UNLOCK_ROUND_DURATION + remainingLockPeriod
506
+ : remainingLockPeriod,
507
+ MAX_LOCK_DURATION
508
+ );
509
+ newUnlockAtInSecondTimestamp = now + lockPeriod;
510
+ }
511
+ return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
512
+ }
468
513
  }
@@ -1,12 +1,13 @@
1
1
  import { normalizeStructTag } from '@mysten/sui.js/utils';
2
2
  import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
3
+ import {
4
+ SUPPORT_BORROW_INCENTIVE_POOLS,
5
+ SUPPORT_BORROW_INCENTIVE_REWARDS,
6
+ } from '../constants';
4
7
  import {
5
8
  parseOriginBorrowIncentivePoolData,
6
- calculateBorrowIncentivePoolData,
7
- parseOriginBorrowIncentiveRewardPoolData,
8
- calculateBorrowIncentiveRewardPoolData,
9
9
  parseOriginBorrowIncentiveAccountData,
10
+ calculateBorrowIncentivePoolPointData,
10
11
  } from '../utils';
11
12
  import type { ScallopQuery } from '../models';
12
13
  import type {
@@ -15,7 +16,9 @@ import type {
15
16
  BorrowIncentiveAccountsQueryInterface,
16
17
  BorrowIncentiveAccounts,
17
18
  SupportBorrowIncentiveCoins,
18
- SupportAssetCoins,
19
+ SupportBorrowIncentiveRewardCoins,
20
+ BorrowIncentivePoolPoints,
21
+ OptionalKeys,
19
22
  } from '../types';
20
23
 
21
24
  /**
@@ -36,97 +39,109 @@ export const queryBorrowIncentivePools = async (
36
39
  ];
37
40
  const queryPkgId = query.address.get('borrowIncentive.query');
38
41
  const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
42
+
39
43
  const txBlock = new SuiKitTxBlock();
40
44
  const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
41
- // The reward coin type currently only support sui, so bring it in directly here.
42
- txBlock.moveCall(queryTarget, [incentivePoolsId], ['0x2::sui::SUI']);
45
+ txBlock.moveCall(queryTarget, [incentivePoolsId]);
43
46
  const queryResult = await query.suiKit.inspectTxn(txBlock);
44
47
  const borrowIncentivePoolsQueryData = queryResult.events[0]
45
48
  .parsedJson as BorrowIncentivePoolsQueryInterface;
46
49
 
47
- const parsedBorrowIncentiveRewardPoolData =
48
- parseOriginBorrowIncentiveRewardPoolData(
49
- borrowIncentivePoolsQueryData.reward_pool
50
- );
51
- const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
52
- const rewardCoinName =
53
- query.utils.parseCoinNameFromType<SupportAssetCoins>(rewardCoinType);
54
- const coinPrices = await query.utils.getCoinPrices(
55
- [...new Set([...borrowIncentiveCoinNames, rewardCoinName])] ?? []
56
- );
57
-
58
50
  const borrowIncentivePools: BorrowIncentivePools = {};
59
51
 
60
52
  if (indexer) {
61
- const borrowIncentivePoolsIndexer =
62
- await query.indexer.getBorrowIncentivePools();
63
- for (const borrowIncentivePool of Object.values(
64
- borrowIncentivePoolsIndexer
65
- )) {
66
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
67
- continue;
68
- borrowIncentivePool.coinPrice =
69
- coinPrices[borrowIncentivePool.coinName] ||
70
- borrowIncentivePool.coinPrice;
71
- borrowIncentivePool.rewardCoinPrice =
72
- coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
73
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
74
- }
75
- return borrowIncentivePools;
53
+ // TODO: Implement indexer query.
54
+ // const borrowIncentivePoolsIndexer =
55
+ // await query.indexer.getBorrowIncentivePools();
56
+ // for (const borrowIncentivePool of Object.values(
57
+ // borrowIncentivePoolsIndexer
58
+ // )) {
59
+ // if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
60
+ // continue;
61
+ // borrowIncentivePool.coinPrice =
62
+ // coinPrices[borrowIncentivePool.coinName] ||
63
+ // borrowIncentivePool.coinPrice;
64
+ // borrowIncentivePool.rewardCoinPrice =
65
+ // coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
66
+ // borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
67
+ // }
68
+ // return borrowIncentivePools;
76
69
  }
77
70
 
78
71
  for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
79
- const coinType = normalizeStructTag(pool.pool_type.name);
80
- const coinName =
81
- query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(coinType);
82
- const rewardCoinName =
83
- query.utils.parseCoinNameFromType<SupportAssetCoins>(rewardCoinType);
84
-
85
- // Filter pools not yet supported by the SDK.
86
- if (!borrowIncentiveCoinNames.includes(coinName)) {
87
- continue;
88
- }
89
-
72
+ const borrowIncentivePoolPoints: OptionalKeys<
73
+ Record<'sui' | 'sca', BorrowIncentivePoolPoints>
74
+ > = {};
90
75
  const parsedBorrowIncentivePoolData =
91
76
  parseOriginBorrowIncentivePoolData(pool);
92
77
 
93
- const coinPrice = coinPrices?.[coinName] ?? 0;
94
- const coinDecimal = query.utils.getCoinDecimal(coinName);
95
- const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
96
- parsedBorrowIncentivePoolData,
97
- coinPrice,
98
- coinDecimal
78
+ const coinPrices = await query.utils.getCoinPrices(
79
+ [
80
+ ...new Set([
81
+ ...borrowIncentiveCoinNames,
82
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS,
83
+ ]),
84
+ ] ?? []
99
85
  );
100
86
 
101
- const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
102
- const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
103
- const calculatedBorrowIncentiveRewardPoolData =
104
- calculateBorrowIncentiveRewardPoolData(
87
+ const poolCoinType = normalizeStructTag(pool.pool_type.name);
88
+ const poolCoinName =
89
+ query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(
90
+ poolCoinType
91
+ );
92
+
93
+ const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
94
+ const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
95
+
96
+ // Filter pools not yet supported by the SDK.
97
+ if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
98
+ continue;
99
+ }
100
+ // pool points for borrow incentive reward ('sui' and 'sca')
101
+ for (const [coinName, poolPoint] of Object.entries(
102
+ parsedBorrowIncentivePoolData.poolPoints
103
+ )) {
104
+ const rewardCoinType = normalizeStructTag(poolPoint.pointType);
105
+ const rewardCoinName =
106
+ query.utils.parseCoinNameFromType<SupportBorrowIncentiveRewardCoins>(
107
+ rewardCoinType
108
+ );
109
+ const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
110
+ const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
111
+
112
+ const symbol = query.utils.parseSymbol(rewardCoinName);
113
+ const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
114
+
115
+ const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
105
116
  parsedBorrowIncentivePoolData,
106
- parsedBorrowIncentiveRewardPoolData,
107
- calculatedBorrowIncentivePoolData,
117
+ poolPoint,
108
118
  rewardCoinPrice,
109
- rewardCoinDecimal
119
+ rewardCoinDecimal,
120
+ poolCoinPrice,
121
+ poolCoinDecimal
110
122
  );
111
123
 
112
- borrowIncentivePools[coinName] = {
113
- coinName: coinName,
114
- symbol: query.utils.parseSymbol(coinName),
115
- coinType: coinType,
116
- rewardCoinType: rewardCoinType,
117
- coinDecimal: coinDecimal,
118
- rewardCoinDecimal: rewardCoinDecimal,
119
- coinPrice: coinPrice,
120
- rewardCoinPrice: rewardCoinPrice,
121
- maxPoint: parsedBorrowIncentivePoolData.maxPoint,
122
- distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
123
- maxStake: parsedBorrowIncentivePoolData.maxStake,
124
- ...calculatedBorrowIncentivePoolData,
125
- exchangeRateNumerator:
126
- parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
127
- exchangeRateDenominator:
128
- parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
129
- ...calculatedBorrowIncentiveRewardPoolData,
124
+ borrowIncentivePoolPoints[coinName as SupportBorrowIncentiveRewardCoins] =
125
+ {
126
+ symbol,
127
+ coinName: rewardCoinName,
128
+ coinType: rewardCoinType,
129
+ coinDecimal,
130
+ coinPrice: rewardCoinPrice,
131
+ points: poolPoint.points,
132
+ distributedPoint: poolPoint.distributedPoint,
133
+ weightedAmount: poolPoint.weightedAmount,
134
+ ...calculatedPoolPoint,
135
+ };
136
+ }
137
+
138
+ borrowIncentivePools[poolCoinName] = {
139
+ coinName: poolCoinName,
140
+ symbol: query.utils.parseSymbol(poolCoinName),
141
+ coinType: poolCoinType,
142
+ coinDecimal: poolCoinDecimal,
143
+ coinPrice: poolCoinPrice,
144
+ points: borrowIncentivePoolPoints,
130
145
  };
131
146
  }
132
147
 
@@ -153,6 +168,7 @@ export const queryBorrowIncentiveAccounts = async (
153
168
  'borrowIncentive.incentiveAccounts'
154
169
  );
155
170
  const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
171
+
156
172
  const txBlock = new SuiKitTxBlock();
157
173
  txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
158
174
  const queryResult = await query.suiKit.inspectTxn(txBlock);
@@ -160,7 +176,7 @@ export const queryBorrowIncentiveAccounts = async (
160
176
  .parsedJson as BorrowIncentiveAccountsQueryInterface;
161
177
 
162
178
  const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
163
- borrowIncentiveAccountsQueryData.incentive_states
179
+ borrowIncentiveAccountsQueryData.pool_records
164
180
  ).reduce((accounts, accountData) => {
165
181
  const parsedBorrowIncentiveAccount =
166
182
  parseOriginBorrowIncentiveAccountData(accountData);
@@ -172,13 +188,7 @@ export const queryBorrowIncentiveAccounts = async (
172
188
  borrowIncentiveCoinNames &&
173
189
  borrowIncentiveCoinNames.includes(coinName)
174
190
  ) {
175
- accounts[coinName] = {
176
- poolType: poolType,
177
- amount: parsedBorrowIncentiveAccount.amount,
178
- points: parsedBorrowIncentiveAccount.points,
179
- totalPoints: parsedBorrowIncentiveAccount.totalPoints,
180
- index: parsedBorrowIncentiveAccount.index,
181
- };
191
+ accounts[coinName] = parsedBorrowIncentiveAccount;
182
192
  }
183
193
 
184
194
  return accounts;
@@ -310,7 +310,7 @@ export const getMarketPool = async (
310
310
  // Get balance sheet.
311
311
  const balanceSheetParentId =
312
312
  fields.vault.fields.balance_sheets.fields.table.fields.id.id;
313
- const balanceSheetDdynamicFieldObjectResponse = await query.suiKit
313
+ const balanceSheetDynamicFieldObjectResponse = await query.suiKit
314
314
  .client()
315
315
  .getDynamicFieldObject({
316
316
  parentId: balanceSheetParentId,
@@ -321,14 +321,14 @@ export const getMarketPool = async (
321
321
  },
322
322
  },
323
323
  });
324
- const balanceSheetDdynamicFieldObject =
325
- balanceSheetDdynamicFieldObjectResponse.data;
324
+ const balanceSheetDynamicFieldObject =
325
+ balanceSheetDynamicFieldObjectResponse.data;
326
326
  if (
327
- balanceSheetDdynamicFieldObject &&
328
- balanceSheetDdynamicFieldObject.content &&
329
- 'fields' in balanceSheetDdynamicFieldObject.content
327
+ balanceSheetDynamicFieldObject &&
328
+ balanceSheetDynamicFieldObject.content &&
329
+ 'fields' in balanceSheetDynamicFieldObject.content
330
330
  ) {
331
- const dynamicFields = balanceSheetDdynamicFieldObject.content
331
+ const dynamicFields = balanceSheetDynamicFieldObject.content
332
332
  .fields as any;
333
333
  balanceSheet = dynamicFields.value.fields;
334
334
  }
@@ -581,7 +581,7 @@ export const getMarketCollateral = async (
581
581
 
582
582
  // Get risk model.
583
583
  const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
584
- const riskModelDdynamicFieldObjectResponse = await query.suiKit
584
+ const riskModelDynamicFieldObjectResponse = await query.suiKit
585
585
  .client()
586
586
  .getDynamicFieldObject({
587
587
  parentId: riskModelParentId,
@@ -592,15 +592,14 @@ export const getMarketCollateral = async (
592
592
  },
593
593
  },
594
594
  });
595
- const riskModelDdynamicFieldObject =
596
- riskModelDdynamicFieldObjectResponse.data;
595
+ const riskModelDynamicFieldObject =
596
+ riskModelDynamicFieldObjectResponse.data;
597
597
  if (
598
- riskModelDdynamicFieldObject &&
599
- riskModelDdynamicFieldObject.content &&
600
- 'fields' in riskModelDdynamicFieldObject.content
598
+ riskModelDynamicFieldObject &&
599
+ riskModelDynamicFieldObject.content &&
600
+ 'fields' in riskModelDynamicFieldObject.content
601
601
  ) {
602
- const dynamicFields = riskModelDdynamicFieldObject.content
603
- .fields as any;
602
+ const dynamicFields = riskModelDynamicFieldObject.content.fields as any;
604
603
  riskModel = dynamicFields.value.fields;
605
604
  }
606
605
 
@@ -686,7 +685,7 @@ export const getObligations = async (
686
685
  query.address.get('core.object') || PROTOCOL_OBJECT_ID;
687
686
  const keyObjectsResponse: SuiObjectResponse[] = [];
688
687
  let hasNextPage = false;
689
- let nextCursor: string | null = null;
688
+ let nextCursor: string | null | undefined = null;
690
689
  do {
691
690
  const paginatedKeyObjectsResponse = await query.suiKit
692
691
  .client()
@@ -796,7 +795,7 @@ export const getCoinAmounts = async (
796
795
  const owner = ownerAddress || query.suiKit.currentAddress();
797
796
  const coinObjectsResponse: SuiObjectResponse[] = [];
798
797
  let hasNextPage = false;
799
- let nextCursor: string | null = null;
798
+ let nextCursor: string | null | undefined = null;
800
799
  do {
801
800
  const paginatedCoinObjectsResponse = await query.suiKit
802
801
  .client()
@@ -868,7 +867,7 @@ export const getCoinAmount = async (
868
867
  const coinType = query.utils.parseCoinType(assetCoinName);
869
868
  const coinObjectsResponse: SuiObjectResponse[] = [];
870
869
  let hasNextPage = false;
871
- let nextCursor: string | null = null;
870
+ let nextCursor: string | null | undefined = null;
872
871
  do {
873
872
  const paginatedCoinObjectsResponse = await query.suiKit
874
873
  .client()
@@ -931,7 +930,7 @@ export const getMarketCoinAmounts = async (
931
930
  const owner = ownerAddress || query.suiKit.currentAddress();
932
931
  const marketCoinObjectsResponse: SuiObjectResponse[] = [];
933
932
  let hasNextPage = false;
934
- let nextCursor: string | null = null;
933
+ let nextCursor: string | null | undefined = null;
935
934
  do {
936
935
  const paginatedMarketCoinObjectsResponse = await query.suiKit
937
936
  .client()
@@ -1006,7 +1005,7 @@ export const getMarketCoinAmount = async (
1006
1005
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
1007
1006
  const marketCoinObjectsResponse: SuiObjectResponse[] = [];
1008
1007
  let hasNextPage = false;
1009
- let nextCursor: string | null = null;
1008
+ let nextCursor: string | null | undefined = null;
1010
1009
  do {
1011
1010
  const paginatedMarketCoinObjectsResponse = await query.suiKit
1012
1011
  .client()
@@ -3,3 +3,4 @@ export * from './spoolQuery';
3
3
  export * from './borrowIncentiveQuery';
4
4
  export * from './priceQuery';
5
5
  export * from './portfolioQuery';
6
+ export * from './vescaQuery';