@scallop-io/sui-scallop-sdk 0.44.17 → 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.
- package/dist/builders/borrowIncentiveBuilder.d.ts +7 -0
- package/dist/builders/vescaBuilder.d.ts +24 -0
- package/dist/constants/common.d.ts +7 -4
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/vesca.d.ts +5 -0
- package/dist/index.js +878 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +867 -248
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +7 -7
- package/dist/models/scallopUtils.d.ts +16 -14
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/vescaQuery.d.ts +28 -0
- package/dist/types/address.d.ts +9 -0
- package/dist/types/builder/borrowIncentive.d.ts +9 -6
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/builder/vesca.d.ts +33 -0
- package/dist/types/constant/enum.d.ts +1 -1
- package/dist/types/query/borrowIncentive.d.ts +65 -60
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +12 -6
- package/dist/types/query/vesca.d.ts +7 -0
- package/dist/types/utils.d.ts +1 -2
- package/dist/utils/builder.d.ts +6 -0
- package/dist/utils/query.d.ts +4 -10
- package/dist/utils/util.d.ts +7 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +174 -25
- package/src/builders/index.ts +6 -2
- package/src/builders/vescaBuilder.ts +392 -0
- package/src/constants/common.ts +19 -6
- package/src/constants/enum.ts +9 -3
- package/src/constants/index.ts +1 -0
- package/src/constants/vesca.ts +7 -0
- package/src/models/scallopAddress.ts +9 -1
- package/src/models/scallopClient.ts +29 -20
- package/src/models/scallopUtils.ts +45 -0
- package/src/queries/borrowIncentiveQuery.ts +93 -83
- package/src/queries/coreQuery.ts +19 -20
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +79 -41
- package/src/queries/spoolQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +124 -0
- package/src/types/address.ts +9 -0
- package/src/types/builder/borrowIncentive.ts +22 -5
- package/src/types/builder/index.ts +4 -1
- package/src/types/builder/vesca.ts +73 -0
- package/src/types/constant/enum.ts +1 -1
- package/src/types/query/borrowIncentive.ts +195 -74
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +17 -6
- package/src/types/query/vesca.ts +7 -0
- package/src/types/utils.ts +1 -1
- package/src/utils/builder.ts +141 -0
- package/src/utils/query.ts +227 -131
- package/src/utils/util.ts +28 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
'
|
|
45
|
+
ParsedBorrowIncentivePoolPointData,
|
|
46
|
+
'points' | 'distributedPoint' | 'weightedAmount'
|
|
29
47
|
>
|
|
30
48
|
> &
|
|
31
|
-
|
|
32
|
-
BorrowIncentiveRewardPool;
|
|
49
|
+
CalculatedBorrowIncentivePoolPointData;
|
|
33
50
|
|
|
34
|
-
export type
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
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
|
-
|
|
71
|
-
|
|
152
|
+
rewardApr: number;
|
|
153
|
+
rewardPerSec: number;
|
|
72
154
|
};
|
|
73
155
|
|
|
74
|
-
export type BorrowIncentiveRewardPool =
|
|
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
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
219
|
+
debt_amount: string;
|
|
126
220
|
};
|
|
127
221
|
|
|
128
|
-
export type ParsedBorrowIncentiveAccountData = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
149
|
-
total_points: string;
|
|
270
|
+
pool_records: OriginBorrowIncentiveAccountData[];
|
|
150
271
|
}
|
package/src/types/query/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { MarketPool } from './core';
|
|
2
2
|
import type { Spool } from './spool';
|
|
3
|
-
import type {
|
|
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
|
-
|
|
122
|
-
availableClaimAmount: number;
|
|
123
|
-
availableClaimCoin: number;
|
|
134
|
+
rewards: ObligationBorrowIcentiveReward[];
|
|
124
135
|
};
|
|
125
136
|
|
|
126
137
|
export type TotalValueLocked = {
|
package/src/types/utils.ts
CHANGED
package/src/utils/builder.ts
CHANGED
|
@@ -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
|
+
};
|