Skip to content

Commit 41c3349

Browse files
committed
round 2
1 parent 9cb1749 commit 41c3349

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

contracts/sources/liquid_staking.move

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ module liquid_staking::liquid_staking {
227227
self.fees.join(sui_balance.split(mint_fee_amount));
228228

229229
let lst_mint_amount = self.sui_amount_to_lst_amount(sui_balance.value());
230+
assert!(lst_mint_amount > 0, EZeroLstMinted);
230231

231232
emit_event(MintEvent {
232233
typename: type_name::get<P>(),
@@ -236,7 +237,6 @@ module liquid_staking::liquid_staking {
236237
});
237238

238239
let lst = self.lst_treasury_cap.mint(lst_mint_amount, ctx);
239-
assert!(lst.value() > 0, EZeroLstMinted);
240240

241241
// invariant: lst_out / sui_in <= old_lst_supply / old_sui_supply
242242
// -> lst_out * old_sui_supply <= sui_in * old_lst_supply
@@ -338,7 +338,7 @@ module liquid_staking::liquid_staking {
338338
_: &AdminCap<P>,
339339
system_state: &mut SuiSystemState,
340340
validator_address: address,
341-
max_sui_amount: u64,
341+
target_unstake_sui_amount: u64,
342342
ctx: &mut TxContext
343343
): u64 {
344344
self.refresh(system_state, ctx);
@@ -349,7 +349,7 @@ module liquid_staking::liquid_staking {
349349
let sui_amount = self.storage.unstake_approx_n_sui_from_validator(
350350
system_state,
351351
validator_index,
352-
max_sui_amount,
352+
target_unstake_sui_amount,
353353
ctx
354354
);
355355

contracts/sources/storage.move

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module liquid_staking::storage {
99
/* Errors */
1010
const ENotEnoughSuiInSuiPool: u64 = 0;
1111
const ENotActiveValidator: u64 = 1;
12-
const ETooManyValidators: u64 = 0;
12+
const ETooManyValidators: u64 = 2;
13+
const EValidatorAlreadyExists: u64 = 3;
1314

1415
/* Constants */
1516
const MIN_STAKE_THRESHOLD: u64 = 1_000_000_000;
@@ -510,16 +511,25 @@ module liquid_staking::storage {
510511
staking_pool_id: ID,
511512
ctx: &mut TxContext
512513
): u64 {
514+
let mut current_validator_addresses = vector[];
515+
513516
let mut i = 0;
514517
while (i < self.validator_infos.length()) {
515518
if (self.validator_infos[i].staking_pool_id == staking_pool_id) {
516519
return i
517520
};
518521

522+
current_validator_addresses.push_back(self.validator_infos[i].validator_address);
519523
i = i + 1;
520524
};
521525

522526
let validator_address = system_state.validator_address_by_pool_id(&staking_pool_id);
527+
528+
assert!(
529+
!current_validator_addresses.contains(&validator_address),
530+
EValidatorAlreadyExists
531+
);
532+
523533
let active_validator_addresses = system_state.active_validator_addresses();
524534
assert!(
525535
active_validator_addresses.contains(&validator_address),

contracts/tests/storage_tests.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ module liquid_staking::storage_tests {
12241224
}
12251225

12261226
#[test]
1227-
#[expected_failure(abort_code = 0, location = liquid_staking::storage)]
1227+
#[expected_failure(abort_code = 2, location = liquid_staking::storage)]
12281228
fun test_too_many_validators() {
12291229
let mut scenario = test_scenario::begin(@0x0);
12301230

0 commit comments

Comments
 (0)