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 939cf33
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
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
4 changes: 4 additions & 0 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ echo ADD_VALIDATOR_TRANSACTION > ../solido/output

# 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 939cf33

Please sign in to comment.