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

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 +888 -255
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +877 -248
  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 +226 -130
  56. package/src/utils/util.ts +34 -1
@@ -1,4 +1,7 @@
1
- import type { SupportBorrowIncentiveCoins } from '../constant';
1
+ import type {
2
+ SupportBorrowIncentiveCoins,
3
+ SupportBorrowIncentiveRewardCoins,
4
+ } from '../constant';
2
5
 
3
6
  export interface BorrowIncentiveAccountKey {
4
7
  id: string;
@@ -13,138 +16,256 @@ export type BorrowIncentivePools = OptionalKeys<
13
16
  Record<SupportBorrowIncentiveCoins, BorrowIncentivePool>
14
17
  >;
15
18
 
16
- export type BorrowIncentivePool = {
17
- coinName: SupportBorrowIncentiveCoins;
19
+ // export type BorrowIncentivePool = {
20
+ // coinName: SupportBorrowIncentiveCoins;
21
+ // symbol: string;
22
+ // coinType: string;
23
+ // rewardCoinType: string;
24
+ // coinDecimal: number;
25
+ // rewardCoinDecimal: number;
26
+ // coinPrice: number;
27
+ // rewardCoinPrice: number;
28
+ // } & Required<
29
+ // Pick<
30
+ // ParsedBorrowIncentivePoolData,
31
+ // 'maxPoints' | 'distributedPoint' | 'maxStake'
32
+ // >
33
+ // > &
34
+ // CalculatedBorrowIncentivePoolData &
35
+ // BorrowIncentiveRewardPool;
36
+
37
+ export type BorrowIncentivePoolPoints = {
18
38
  symbol: string;
39
+ coinName: SupportBorrowIncentiveRewardCoins;
19
40
  coinType: string;
20
- rewardCoinType: string;
21
41
  coinDecimal: number;
22
- rewardCoinDecimal: number;
23
42
  coinPrice: number;
24
- rewardCoinPrice: number;
25
43
  } & Required<
26
44
  Pick<
27
- ParsedBorrowIncentivePoolData,
28
- 'maxPoint' | 'distributedPoint' | 'maxStake'
45
+ ParsedBorrowIncentivePoolPointData,
46
+ 'points' | 'distributedPoint' | 'weightedAmount'
29
47
  >
30
48
  > &
31
- CalculatedBorrowIncentivePoolData &
32
- BorrowIncentiveRewardPool;
49
+ CalculatedBorrowIncentivePoolPointData;
33
50
 
34
- export type OriginBorrowIncentivePoolData = {
35
- created_at: string;
36
- distributed_point: string;
51
+ export type BorrowIncentivePool = {
52
+ coinName: SupportBorrowIncentiveCoins;
53
+ symbol: string;
54
+ coinType: string;
55
+ coinDecimal: number;
56
+ coinPrice: number;
57
+ points: OptionalKeys<
58
+ Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
59
+ >;
60
+ };
61
+
62
+ // export type OriginBorrowIncentivePoolData = {
63
+ // created_at: string;
64
+ // distributed_point: string;
65
+ // distributed_point_per_period: string;
66
+ // index: string;
67
+ // last_update: string;
68
+ // max_distributed_point: string;
69
+ // max_stakes: string;
70
+ // point_distribution_time: string;
71
+ // pool_type: {
72
+ // name: string;
73
+ // };
74
+ // stakes: string;
75
+ // };
76
+
77
+ export type OriginBorrowIncentivePoolPointData = {
78
+ point_type: {
79
+ name: string;
80
+ };
37
81
  distributed_point_per_period: string;
82
+ point_distribution_time: string;
83
+ distributed_point: string;
84
+ points: string;
38
85
  index: string;
86
+ base_weight: string;
87
+ weighted_amount: string;
39
88
  last_update: string;
40
- max_distributed_point: string;
41
- max_stakes: string;
42
- point_distribution_time: string;
89
+ };
90
+
91
+ export type OriginBorrowIncentivePoolData = {
43
92
  pool_type: {
44
93
  name: string;
45
94
  };
95
+ points: OriginBorrowIncentivePoolPointData[]; // one borrow pool can have multiple points (e.g. sui and sca)
96
+ min_stakes: string;
97
+ max_stakes: string;
46
98
  stakes: string;
99
+ created_at: string;
100
+ };
101
+
102
+ export type ParsedBorrowIncentivePoolPointData = {
103
+ pointType: string;
104
+ distributedPointPerPeriod: number;
105
+ period: number;
106
+ distributedPoint: number;
107
+ points: number;
108
+ index: number;
109
+ baseWeight: number;
110
+ weightedAmount: number;
111
+ lastUpdate: number;
47
112
  };
48
113
 
114
+ // export type ParsedBorrowIncentivePoolData = {
115
+ // poolType: string;
116
+ // maxPoint: number;
117
+ // distributedPoint: number;
118
+ // pointPerPeriod: number;
119
+ // period: number;
120
+ // maxStake: number;
121
+ // staked: number;
122
+ // index: number;
123
+ // createdAt: number;
124
+ // lastUpdate: number;
125
+ // };
49
126
  export type ParsedBorrowIncentivePoolData = {
50
127
  poolType: string;
51
- maxPoint: number;
52
- distributedPoint: number;
53
- pointPerPeriod: number;
54
- period: number;
55
- maxStake: number;
128
+ poolPoints: OptionalKeys<
129
+ Record<
130
+ SupportBorrowIncentiveRewardCoins,
131
+ ParsedBorrowIncentivePoolPointData
132
+ >
133
+ >;
134
+ minStakes: number;
135
+ maxStakes: number;
56
136
  staked: number;
57
- index: number;
58
137
  createdAt: number;
59
- lastUpdate: number;
60
138
  };
61
139
 
62
- export type CalculatedBorrowIncentivePoolData = {
140
+ export type CalculatedBorrowIncentivePoolPointData = {
63
141
  stakedAmount: number;
64
142
  stakedCoin: number;
65
143
  stakedValue: number;
144
+ baseWeight: number;
145
+ weightedStakedAmount: number;
146
+ weightedStakedCoin: number;
147
+ weightedStakedValue: number;
66
148
  distributedPointPerSec: number;
67
149
  accumulatedPoints: number;
68
150
  currentPointIndex: number;
69
151
  currentTotalDistributedPoint: number;
70
- startDate: Date;
71
- endDate: Date;
152
+ rewardApr: number;
153
+ rewardPerSec: number;
72
154
  };
73
155
 
74
- export type BorrowIncentiveRewardPool = Required<
75
- Pick<
76
- ParsedBorrowIncentiveRewardPoolData,
77
- 'exchangeRateNumerator' | 'exchangeRateDenominator'
78
- >
79
- > &
80
- CalculatedBorrowIncentiveRewardPoolData;
81
-
82
- export type OriginBorrowIncentiveRewardPoolData = {
83
- claimed_rewards: string;
84
- exchange_rate_denominator: string;
85
- exchange_rate_numerator: string;
86
- remaining_reward: string;
87
- reward_type: {
88
- name: string;
89
- };
90
- };
156
+ // export type BorrowIncentiveRewardPool = CalculatedBorrowIncentiveRewardPoolData;
91
157
 
92
- export type ParsedBorrowIncentiveRewardPoolData = {
93
- rewardType: string;
94
- claimedRewards: number;
95
- exchangeRateDenominator: number;
96
- exchangeRateNumerator: number;
97
- remainingRewards: number;
98
- };
158
+ // export type OriginBorrowIncentiveRewardPoolData = {
159
+ // claimed_rewards: string;
160
+ // exchange_rate_denominator: string;
161
+ // exchange_rate_numerator: string;
162
+ // remaining_reward: string;
163
+ // reward_type: {
164
+ // name: string;
165
+ // };
166
+ // };
99
167
 
100
- export type CalculatedBorrowIncentiveRewardPoolData = {
101
- rewardApr: number;
102
- totalRewardAmount: number;
103
- totalRewardCoin: number;
104
- totalRewardValue: number;
105
- remaindRewardAmount: number;
106
- remaindRewardCoin: number;
107
- remaindRewardValue: number;
108
- claimedRewardAmount: number;
109
- claimedRewardCoin: number;
110
- claimedRewardValue: number;
111
- rewardPerSec: number;
112
- };
168
+ // export type ParsedBorrowIncentiveRewardPoolData = {
169
+ // rewardType: string;
170
+ // claimedRewards: number;
171
+ // exchangeRateDenominator: number;
172
+ // exchangeRateNumerator: number;
173
+ // remainingRewards: number;
174
+ // };
175
+
176
+ // export type CalculatedBorrowIncentiveRewardPoolData = {
177
+ // rewardApr: number;
178
+ // totalRewardAmount: number;
179
+ // totalRewardCoin: number;
180
+ // totalRewardValue: number;
181
+ // // remaindRewardAmount: number;
182
+ // // remaindRewardCoin: number;
183
+ // // remaindRewardValue: number;
184
+ // // claimedRewardAmount: number;
185
+ // // claimedRewardCoin: number;
186
+ // // claimedRewardValue: number;
187
+ // rewardPerSec: number;
188
+ // };
113
189
 
114
190
  export type BorrowIncentiveAccounts = OptionalKeys<
115
191
  Record<SupportBorrowIncentiveCoins, ParsedBorrowIncentiveAccountData>
116
192
  >;
117
193
 
118
- export type OriginBorrowIncentiveAccountData = {
119
- amount: string;
120
- index: string;
194
+ // export type OriginBorrowIncentiveAccountData = {
195
+ // amount: string;
196
+ // index: string;
197
+ // points: string;
198
+ // pool_type: {
199
+ // name: string;
200
+ // };
201
+ // total_points: string;
202
+ // };
203
+
204
+ export type OriginBorrowIncentiveAccountPoolData = {
205
+ point_type: {
206
+ name: string;
207
+ };
208
+ weighted_amount: string;
121
209
  points: string;
210
+ total_points: string;
211
+ index: string;
212
+ };
213
+
214
+ export type OriginBorrowIncentiveAccountData = {
215
+ points_list: OriginBorrowIncentiveAccountPoolData[];
122
216
  pool_type: {
123
217
  name: string;
124
218
  };
125
- total_points: string;
219
+ debt_amount: string;
126
220
  };
127
221
 
128
- export type ParsedBorrowIncentiveAccountData = {
129
- poolType: string;
130
- amount: number;
131
- index: number;
222
+ // export type ParsedBorrowIncentiveAccountData = {
223
+ // poolType: string;
224
+ // amount: number;
225
+ // index: number;
226
+ // points: number;
227
+ // totalPoints: number;
228
+ // };
229
+
230
+ export type ParsedBorrowIncentiveAccountPoolData = {
231
+ pointType: string;
232
+ weightedAmount: number;
132
233
  points: number;
133
234
  totalPoints: number;
235
+ index: number;
236
+ };
237
+
238
+ export type ParsedBorrowIncentiveAccountData = {
239
+ pointList: OptionalKeys<
240
+ Record<
241
+ SupportBorrowIncentiveRewardCoins,
242
+ ParsedBorrowIncentiveAccountPoolData
243
+ >
244
+ >;
245
+ poolType: string;
246
+ debtAmount: number;
134
247
  };
135
248
 
136
249
  /**
137
250
  * The query interface for `incentive_pools_query::incentive_pools_data` inspectTxn.
138
251
  */
252
+ // export interface BorrowIncentivePoolsQueryInterface {
253
+ // incentive_pools: OriginBorrowIncentivePoolData[];
254
+ // reward_pool: OriginBorrowIncentiveRewardPoolData;
255
+ // }
256
+
139
257
  export interface BorrowIncentivePoolsQueryInterface {
140
258
  incentive_pools: OriginBorrowIncentivePoolData[];
141
- reward_pool: OriginBorrowIncentiveRewardPoolData;
142
259
  }
143
260
 
144
261
  /**
145
262
  * The query interface for `incentive_account_query::incentive_account_data` inspectTxn.
146
263
  */
264
+ // export interface BorrowIncentiveAccountsQueryInterface {
265
+ // incentive_states: OriginBorrowIncentiveAccountData[];
266
+ // total_points: string;
267
+ // }
268
+
147
269
  export interface BorrowIncentiveAccountsQueryInterface {
148
- incentive_states: OriginBorrowIncentiveAccountData[];
149
- total_points: string;
270
+ pool_records: OriginBorrowIncentiveAccountData[];
150
271
  }
@@ -2,3 +2,4 @@ export type * from './core';
2
2
  export type * from './spool';
3
3
  export type * from './borrowIncentive';
4
4
  export type * from './portfolio';
5
+ export type * from './vesca';
@@ -1,6 +1,10 @@
1
1
  import type { MarketPool } from './core';
2
2
  import type { Spool } from './spool';
3
- import type { SupportPoolCoins, SupportCollateralCoins } from '../constant';
3
+ import type {
4
+ SupportPoolCoins,
5
+ SupportCollateralCoins,
6
+ SupportBorrowIncentiveRewardCoins,
7
+ } from '../constant';
4
8
 
5
9
  type OptionalKeys<T> = {
6
10
  [K in keyof T]?: T[K];
@@ -110,17 +114,24 @@ export type ObligationDebt = {
110
114
  availableRepayCoin: number;
111
115
  };
112
116
 
117
+ export type ObligationBorrowIcentiveReward = {
118
+ coinName: SupportBorrowIncentiveRewardCoins;
119
+ coinType: string;
120
+ symbol: string;
121
+ coinDecimal: number;
122
+ coinPrice: number;
123
+ availableClaimCoin: number;
124
+ availableClaimAmount: number;
125
+ boostValue: number;
126
+ };
127
+
113
128
  export type ObligationBorrowIncentive = {
114
129
  coinName: SupportPoolCoins;
115
130
  coinType: string;
116
- rewardCoinType: string;
117
131
  symbol: string;
118
132
  coinDecimal: number;
119
- rewardCoinDecimal: number;
120
133
  coinPrice: number;
121
- rewardCoinPrice: number;
122
- availableClaimAmount: number;
123
- availableClaimCoin: number;
134
+ rewards: ObligationBorrowIcentiveReward[];
124
135
  };
125
136
 
126
137
  export type TotalValueLocked = {
@@ -0,0 +1,7 @@
1
+ export type Vesca = {
2
+ id: string;
3
+ keyId: string;
4
+ lockedScaAmount: number;
5
+ lockedScaCoin: number;
6
+ unlockAt: number;
7
+ };
@@ -1,6 +1,6 @@
1
1
  import type { SupportAssetCoins } from './constant';
2
2
 
3
- type OptionalKeys<T> = {
3
+ export type OptionalKeys<T> = {
4
4
  [K in keyof T]?: T[K];
5
5
  };
6
6
 
@@ -1,4 +1,12 @@
1
1
  import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
+ import {
3
+ UNLOCK_ROUND_DURATION,
4
+ MAX_LOCK_DURATION,
5
+ MAX_LOCK_ROUNDS,
6
+ MIN_INITIAL_LOCK_AMOUNT,
7
+ MIN_TOP_UP_AMOUNT,
8
+ } from '../constants';
9
+ import type { SuiObjectArg } from '@scallop-io/sui-kit';
2
10
 
3
11
  /**
4
12
  * Check and get the sender from the transaction block.
@@ -13,3 +21,136 @@ export const requireSender = (txBlock: SuiKitTxBlock) => {
13
21
  }
14
22
  return sender;
15
23
  };
24
+
25
+ export const checkLockSca = (
26
+ scaAmountOrCoin?: number | SuiObjectArg | undefined,
27
+ lockPeriodInDays?: number,
28
+ newUnlockAtInSecondTimestamp?: number,
29
+ prevUnlockAtInSecondTimestamp?: number
30
+ ) => {
31
+ const isInitialLock = !prevUnlockAtInSecondTimestamp;
32
+ const isLockExpired =
33
+ !isInitialLock &&
34
+ prevUnlockAtInSecondTimestamp * 1000 <= new Date().getTime();
35
+ if (isInitialLock || isLockExpired) {
36
+ if (scaAmountOrCoin !== undefined && lockPeriodInDays !== undefined) {
37
+ if (lockPeriodInDays <= 0) {
38
+ throw new Error('Lock period must be greater than 0');
39
+ }
40
+ if (
41
+ typeof scaAmountOrCoin === 'number' &&
42
+ scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT
43
+ ) {
44
+ throw new Error(
45
+ `Minimum lock amount for ${
46
+ isLockExpired ? 'renewing expired veSca' : 'initial lock'
47
+ } is 10 SCA`
48
+ );
49
+ }
50
+ const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
51
+ if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
52
+ throw new Error(
53
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
54
+ );
55
+ }
56
+ } else {
57
+ throw new Error(
58
+ `SCA amount and lock period is required for ${
59
+ isLockExpired ? 'renewing expired veSca' : 'initial lock'
60
+ }`
61
+ );
62
+ }
63
+ } else {
64
+ checkVesca(prevUnlockAtInSecondTimestamp);
65
+ if (
66
+ typeof scaAmountOrCoin === 'number' &&
67
+ scaAmountOrCoin < MIN_TOP_UP_AMOUNT
68
+ ) {
69
+ throw new Error('Minimum top up amount is 1 SCA');
70
+ }
71
+
72
+ if (!!newUnlockAtInSecondTimestamp && !!prevUnlockAtInSecondTimestamp) {
73
+ const totalLockDuration =
74
+ newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp;
75
+ if (totalLockDuration > MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
76
+ throw new Error(
77
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
78
+ );
79
+ }
80
+ }
81
+ }
82
+ };
83
+
84
+ export const checkExtendLockPeriod = (
85
+ lockPeriodInDays: number,
86
+ newUnlockAtInSecondTimestamp: number,
87
+ prevUnlockAtInSecondTimestamp?: number
88
+ ) => {
89
+ checkVesca(prevUnlockAtInSecondTimestamp);
90
+
91
+ if (lockPeriodInDays <= 0) {
92
+ throw new Error('Lock period must be greater than 0');
93
+ }
94
+
95
+ const isInitialLock = !prevUnlockAtInSecondTimestamp;
96
+ const isLockExpired =
97
+ !isInitialLock &&
98
+ prevUnlockAtInSecondTimestamp * 1000 <= new Date().getTime();
99
+ if (isLockExpired) {
100
+ throw new Error('veSca is expired, use renewExpiredVeScaQuick instead');
101
+ }
102
+
103
+ if (prevUnlockAtInSecondTimestamp) {
104
+ const totalLockDuration =
105
+ newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp!;
106
+ if (totalLockDuration > MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
107
+ throw new Error(
108
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
109
+ );
110
+ }
111
+ }
112
+ };
113
+
114
+ export const checkExtendLockAmount = (
115
+ scaAmount: number,
116
+ prevUnlockAtInSecondTimestamp?: number
117
+ ) => {
118
+ checkVesca(prevUnlockAtInSecondTimestamp);
119
+
120
+ if (scaAmount < MIN_TOP_UP_AMOUNT) {
121
+ throw new Error('Minimum top up amount is 1 SCA');
122
+ }
123
+
124
+ const isInitialLock = !prevUnlockAtInSecondTimestamp;
125
+ const isLockExpired =
126
+ !isInitialLock &&
127
+ prevUnlockAtInSecondTimestamp * 1000 <= new Date().getTime();
128
+ if (isLockExpired) {
129
+ throw new Error('veSca is expired, use renewExpiredVeScaQuick instead');
130
+ }
131
+ };
132
+
133
+ export const checkRenewExpiredVeSca = (
134
+ scaAmount: number,
135
+ lockPeriodInDays: number,
136
+ prevUnlockAtInSecondTimestamp?: number
137
+ ) => {
138
+ checkVesca(prevUnlockAtInSecondTimestamp);
139
+
140
+ if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
141
+ throw new Error('Minimum lock amount for renewing expired vesca 10 SCA');
142
+ }
143
+
144
+ const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
145
+ if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
146
+ throw new Error(
147
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
148
+ );
149
+ }
150
+ };
151
+
152
+ export const checkVesca = (prevUnlockAtInSecondTimestamp?: number) => {
153
+ if (prevUnlockAtInSecondTimestamp === undefined) {
154
+ throw new Error('veSca not found');
155
+ }
156
+ };