Skip to content

Commit

Permalink
round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Oct 21, 2024
1 parent 9cb1749 commit 41c3349
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions contracts/sources/liquid_staking.move
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ module liquid_staking::liquid_staking {
self.fees.join(sui_balance.split(mint_fee_amount));

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

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

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

// invariant: lst_out / sui_in <= old_lst_supply / old_sui_supply
// -> lst_out * old_sui_supply <= sui_in * old_lst_supply
Expand Down Expand Up @@ -338,7 +338,7 @@ module liquid_staking::liquid_staking {
_: &AdminCap<P>,
system_state: &mut SuiSystemState,
validator_address: address,
max_sui_amount: u64,
target_unstake_sui_amount: u64,
ctx: &mut TxContext
): u64 {
self.refresh(system_state, ctx);
Expand All @@ -349,7 +349,7 @@ module liquid_staking::liquid_staking {
let sui_amount = self.storage.unstake_approx_n_sui_from_validator(
system_state,
validator_index,
max_sui_amount,
target_unstake_sui_amount,
ctx
);

Expand Down
12 changes: 11 additions & 1 deletion contracts/sources/storage.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module liquid_staking::storage {
/* Errors */
const ENotEnoughSuiInSuiPool: u64 = 0;
const ENotActiveValidator: u64 = 1;
const ETooManyValidators: u64 = 0;
const ETooManyValidators: u64 = 2;
const EValidatorAlreadyExists: u64 = 3;

/* Constants */
const MIN_STAKE_THRESHOLD: u64 = 1_000_000_000;
Expand Down Expand Up @@ -510,16 +511,25 @@ module liquid_staking::storage {
staking_pool_id: ID,
ctx: &mut TxContext
): u64 {
let mut current_validator_addresses = vector[];

let mut i = 0;
while (i < self.validator_infos.length()) {
if (self.validator_infos[i].staking_pool_id == staking_pool_id) {
return i
};

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

let validator_address = system_state.validator_address_by_pool_id(&staking_pool_id);

assert!(
!current_validator_addresses.contains(&validator_address),
EValidatorAlreadyExists
);

let active_validator_addresses = system_state.active_validator_addresses();
assert!(
active_validator_addresses.contains(&validator_address),
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/storage_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ module liquid_staking::storage_tests {
}

#[test]
#[expected_failure(abort_code = 0, location = liquid_staking::storage)]
#[expected_failure(abort_code = 2, location = liquid_staking::storage)]
fun test_too_many_validators() {
let mut scenario = test_scenario::begin(@0x0);

Expand Down

0 comments on commit 41c3349

Please sign in to comment.