Skip to content

Commit

Permalink
Increase MINIMUM_STAKE_ACCOUNT_BALANCE to 1SOL + rent exempt
Browse files Browse the repository at this point in the history
  • Loading branch information
kkonevets committed Oct 10, 2022
1 parent 7ccd608 commit a1b4d54
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
8 changes: 4 additions & 4 deletions cli/maintainer/src/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,10 @@ impl SolidoState {
for (_, detail) in stake_accounts {
total_stake_balance = (total_stake_balance + detail.balance.total())
.expect("If this overflows, there would be more than u64::MAX staked.");
can_be_withdrawn = (can_be_withdrawn
+ (detail.balance.inactive - stake_rent)
.expect("Inactive stake is always greater than rent exempt amount"))
.expect("If this overflows, there would be more than u64::MAX staked.");
let diff = (detail.balance.inactive - stake_rent)
.expect("Inactive stake is always greater than rent exempt amount");
can_be_withdrawn = (can_be_withdrawn + diff)
.expect("If this overflows, there would be more than u64::MAX staked.");
}

let expected_difference_stake =
Expand Down
5 changes: 3 additions & 2 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn find_authority_program_address(
Pubkey::find_program_address(&[&lido_address.to_bytes(), authority], program_id)
}

/// The minimum amount to put in a stake account (1 SOL).
/// The minimum amount to put in a stake account (1 SOL + rent_exempt).
///
/// For stake accounts, there is a minimum balance for the account to be
/// rent-exempt, that depends on the size of the stake program's stake state
Expand All @@ -58,7 +58,8 @@ pub fn find_authority_program_address(
/// need to be able to merge stake accounts, we also need to make sure that they
/// contain enough stake that they will earn at least one lamport per epoch.
/// 1 SOL should be sufficient for that.
pub const MINIMUM_STAKE_ACCOUNT_BALANCE: token::Lamports = token::Lamports(1_000_000_000);
/// https://github.com/solana-labs/solana/issues/24357#issuecomment-1225776709
pub const MINIMUM_STAKE_ACCOUNT_BALANCE: token::Lamports = token::Lamports(1_002_282_880);

/// The maximum number of unstake accounts that a validator can have simultaneously.
pub const MAXIMUM_UNSTAKE_ACCOUNTS: u64 = 3;
Expand Down
9 changes: 5 additions & 4 deletions program/tests/tests/stake_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use lido::error::LidoError;
use lido::processor::StakeType;
use lido::state::{ListEntry, StakeDeposit};
use lido::token::Lamports;
use lido::MINIMUM_STAKE_ACCOUNT_BALANCE;
use solana_program_test::tokio;
use solana_sdk::signer::Signer;

Expand Down Expand Up @@ -228,7 +229,7 @@ async fn test_stake_deposit_fails_if_validator_with_less_stake_exists() {
.stake_deposit(
v1.vote_account,
StakeDeposit::Append,
Lamports(1_000_000_000),
MINIMUM_STAKE_ACCOUNT_BALANCE,
)
.await;

Expand All @@ -238,7 +239,7 @@ async fn test_stake_deposit_fails_if_validator_with_less_stake_exists() {
.try_stake_deposit(
v1.vote_account,
StakeDeposit::Append,
Lamports(1_000_000_000),
MINIMUM_STAKE_ACCOUNT_BALANCE,
)
.await;
assert_solido_error!(result, LidoError::ValidatorWithLessStakeExists);
Expand All @@ -248,7 +249,7 @@ async fn test_stake_deposit_fails_if_validator_with_less_stake_exists() {
.stake_deposit(
v2.vote_account,
StakeDeposit::Append,
Lamports(1_000_000_000),
MINIMUM_STAKE_ACCOUNT_BALANCE,
)
.await;

Expand All @@ -257,7 +258,7 @@ async fn test_stake_deposit_fails_if_validator_with_less_stake_exists() {
.stake_deposit(
v2.vote_account,
StakeDeposit::Append,
Lamports(1_000_000_000),
MINIMUM_STAKE_ACCOUNT_BALANCE,
)
.await;
}
3 changes: 2 additions & 1 deletion program/tests/tests/update_stake_account_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use lido::error::LidoError;
use lido::state::StakeDeposit;
use lido::token::Lamports;
use lido::MINIMUM_STAKE_ACCOUNT_BALANCE;
use solana_program_test::tokio;
use testlib::assert_solido_error;
use testlib::solido_context::Context;
Expand All @@ -25,7 +26,7 @@ async fn test_update_stake_account_balance() {
assert_eq!(solido_before, solido_after);

// Deposit and stake the deposit with the validator. This creates one stake account.
let initial_amount = Lamports(1_000_000_000);
let initial_amount = MINIMUM_STAKE_ACCOUNT_BALANCE;
context.deposit(initial_amount).await;
let stake_account = context
.stake_deposit(validator.vote_account, StakeDeposit::Append, initial_amount)
Expand Down
14 changes: 11 additions & 3 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cd solido_old

# start local validator
rm -rf tests/.keys/ test-ledger/ tests/__pycache__/ && solana-test-validator --slots-per-epoch 300
rm -rf tests/.keys/ test-ledger/ tests/__pycache__/ && solana-test-validator --slots-per-epoch 150

# withdraw SOLs from local validator vote account to start fresh
solana withdraw-from-vote-account test-ledger/vote-account-keypair.json v9zvcQbyuCAuFw6rt7VLedE2qV4NAY8WLaLg37muBM2 999999.9 --authorized-withdrawer test-ledger/vote-account-keypair.json
Expand All @@ -21,6 +21,10 @@ solana withdraw-from-vote-account test-ledger/vote-account-keypair.json v9zvcQby

# EPOCH 1

# receive some rewards

# EPOCH 2

# deactivate validators
../solido/scripts/update_solido_version.py --config ../solido_test.json deactivate-validators --keypair-path ./tests/.keys/maintainer.json > output
./target/debug/solido --config ../solido_test.json --keypair-path ./tests/.keys/maintainer.json multisig approve-batch --transaction-addresses-path output
Expand All @@ -41,7 +45,7 @@ solana --url localhost transfer --allow-unfunded-recipient ../solido_old/tests/.
# propose migration
scripts/update_solido_version.py --config ../solido_test.json propose-migrate --keypair-path ../solido_old/tests/.keys/maintainer.json >> output

# EPOCH 2
# EPOCH 3

# wait for maintainers to remove validators, approve program update and migration
./target/debug/solido --config ../solido_test.json --keypair-path ../solido_old/tests/.keys/maintainer.json multisig approve-batch --transaction-addresses-path output
Expand All @@ -51,7 +55,11 @@ scripts/update_solido_version.py --config ../solido_test.json propose-migrate --
echo ADD_VALIDATOR_TRANSACTION > ../solido/output
./target/debug/solido --config ../solido_test.json --keypair-path ../solido_old/tests/.keys/maintainer.json multisig approve-batch --transaction-addresses-path output

# EPOCH 3
# EPOCH 4

# try to withdraw
./target/debug/solido --config ~/Documents/solido_test.json withdraw --amount-st-sol 1.1

# withdraw developer some fee to self
spl-token transfer --from DEVELOPER_FEE_ADDRESS STSOL_MINT_ADDRESS 0.0001 $(solana-keygen pubkey) --owner ~/developer_fee_key.json
# spl-token account-info --address DEVELOPER_FEE_ADDRESS
27 changes: 27 additions & 0 deletions tests/test_solido.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,30 @@ def set_max_validation_commission(fee: int) -> Any:
)
number_validators = len(solido_instance['validators']['entries'])
assert number_validators == 0


# def test_rewards():
# def balance(v1, v2, v3, reserve):
# return v1 + v2 + v3 + reserve

# s1_before = balance(8.048978427, 9.054659727, 7.948410296, 2.4 + 0.00089088)
# s1 = balance(9.150682817, 9.054659727, 9.150682816, 0.09691397)
# assert s1_before == s1
# s2 = balance(9.210892341, 9.126038084, 9.212256215, 0.10147973)
# rewards = s2 - s1

# def rewards_from_fees(t1, d1, a1, t2, d2, a2):
# dt = t2 - t1
# print(f"dt {dt}, {0.04*rewards}, {dt-0.04*rewards}")
# dd = d2 - d1
# print(f"dd {dd}, {0.01*rewards}, {dd-0.01*rewards}")
# da = a2 - a1
# print(f"da {da}, {0.95*rewards}, {da-0.95*rewards}")
# return dt + dd + da

# rewards_alt = rewards_from_fees(
# 0.008198959, 0.003279583, 0.147581266, 0.016108040, 0.005256852, 0.335421956
# )

# diff = rewards - rewards_alt
# print(diff)

0 comments on commit a1b4d54

Please sign in to comment.