Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 9822976

Browse files
committed
Fix python and JS constants
1 parent 1d6cd5d commit 9822976

12 files changed

+59
-30
lines changed

stake-pool/js/src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const TRANSIENT_STAKE_SEED_PREFIX = Buffer.from('transient');
1212

1313
// Minimum amount of staked SOL required in a validator stake account to allow
1414
// for merges without a mismatch on credits observed
15-
export const MINIMUM_ACTIVE_STAKE = LAMPORTS_PER_SOL / 1_000;
15+
export const MINIMUM_ACTIVE_STAKE = LAMPORTS_PER_SOL;

stake-pool/program/tests/update_validator_list_balance.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use {
77
solana_program::{borsh::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey, stake},
88
solana_program_test::*,
99
solana_sdk::{
10-
stake::state::{Authorized, Lockup, StakeState},
1110
signature::{Keypair, Signer},
11+
stake::state::{Authorized, Lockup, StakeState},
1212
system_instruction,
1313
transaction::Transaction,
1414
},
1515
spl_stake_pool::{
16-
find_withdraw_authority_program_address, find_transient_stake_program_address, id, instruction,
16+
find_transient_stake_program_address, find_withdraw_authority_program_address, id,
17+
instruction,
1718
state::{StakePool, StakeStatus, ValidatorList},
1819
MAX_VALIDATORS_TO_UPDATE, MINIMUM_ACTIVE_STAKE, MINIMUM_RESERVE_LAMPORTS,
1920
},
@@ -686,10 +687,20 @@ async fn success_ignoring_hijacked_transient_stake_with_authorized() {
686687
#[tokio::test]
687688
async fn success_ignoring_hijacked_transient_stake_with_lockup() {
688689
let hijacker = Pubkey::new_unique();
689-
check_ignored_hijacked_transient_stake(None, Some(&Lockup { custodian: hijacker, ..Lockup::default() })).await;
690+
check_ignored_hijacked_transient_stake(
691+
None,
692+
Some(&Lockup {
693+
custodian: hijacker,
694+
..Lockup::default()
695+
}),
696+
)
697+
.await;
690698
}
691699

692-
async fn check_ignored_hijacked_transient_stake(hijack_authorized: Option<&Authorized>, hijack_lockup: Option<&Lockup>) {
700+
async fn check_ignored_hijacked_transient_stake(
701+
hijack_authorized: Option<&Authorized>,
702+
hijack_lockup: Option<&Lockup>,
703+
) {
693704
let num_validators = 1;
694705
let (mut context, stake_pool_accounts, stake_accounts, _, lamports, _, mut slot) =
695706
setup(num_validators).await;

stake-pool/py/bot/rebalance.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
from solana.rpc.async_api import AsyncClient
88
from solana.rpc.commitment import Confirmed
99

10-
from stake.constants import STAKE_LEN
10+
from stake.constants import STAKE_LEN, LAMPORTS_PER_SOL
1111
from stake_pool.actions import decrease_validator_stake, increase_validator_stake, update_stake_pool
12+
from stake_pool.constants import MINIMUM_ACTIVE_STAKE
1213
from stake_pool.state import StakePool, ValidatorList
1314

1415

15-
LAMPORTS_PER_SOL: int = 1_000_000_000
16-
MINIMUM_INCREASE_LAMPORTS: int = LAMPORTS_PER_SOL // 100
17-
18-
1916
async def get_client(endpoint: str) -> AsyncClient:
2017
print(f'Connecting to network at {endpoint}')
2118
async_client = AsyncClient(endpoint=endpoint, commitment=Confirmed)
@@ -87,10 +84,10 @@ async def rebalance(endpoint: str, stake_pool_address: PublicKey, staker: Keypai
8784
))
8885
elif validator.active_stake_lamports < lamports_per_validator:
8986
lamports_to_increase = lamports_per_validator - validator.active_stake_lamports
90-
if lamports_to_increase < MINIMUM_INCREASE_LAMPORTS:
87+
if lamports_to_increase < MINIMUM_ACTIVE_STAKE:
9188
print(f'Skipping increase on {validator.vote_account_address}, \
9289
currently at {validator.active_stake_lamports} lamports, \
93-
increase of {lamports_to_increase} less than the minimum of {MINIMUM_INCREASE_LAMPORTS}')
90+
increase of {lamports_to_increase} less than the minimum of {MINIMUM_ACTIVE_STAKE}')
9491
else:
9592
futures.append(increase_validator_stake(
9693
async_client, staker, staker, stake_pool_address,

stake-pool/py/stake/constants.py

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010

1111
STAKE_LEN: int = 200
1212
"""Size of stake account."""
13+
14+
LAMPORTS_PER_SOL: int = 1_000_000_000
15+
"""Number of lamports per SOL"""
16+
17+
MINIMUM_DELEGATION: int = LAMPORTS_PER_SOL
18+
"""Minimum delegation allowed by the stake program"""

stake-pool/py/stake_pool/actions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from stake.state import StakeAuthorize
1717
from stake_pool.constants import \
1818
MAX_VALIDATORS_TO_UPDATE, \
19+
MINIMUM_RESERVE_LAMPORTS, \
1920
STAKE_POOL_PROGRAM_ID, \
2021
find_stake_program_address, \
2122
find_transient_stake_program_address, \
@@ -98,7 +99,7 @@ async def create_all(client: AsyncClient, manager: Keypair, fee: Fee, referral_f
9899
STAKE_POOL_PROGRAM_ID, stake_pool.public_key)
99100

100101
reserve_stake = Keypair()
101-
await create_stake(client, manager, reserve_stake, pool_withdraw_authority, 1)
102+
await create_stake(client, manager, reserve_stake, pool_withdraw_authority, MINIMUM_RESERVE_LAMPORTS)
102103

103104
pool_mint = Keypair()
104105
await create_mint(client, manager, pool_mint, pool_withdraw_authority)

stake-pool/py/stake_pool/constants.py

+7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
from typing import Tuple
44

55
from solana.publickey import PublicKey
6+
from stake.constants import MINIMUM_DELEGATION
67

78
STAKE_POOL_PROGRAM_ID: PublicKey = PublicKey("SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy")
89
"""Public key that identifies the SPL Stake Pool program."""
910

1011
MAX_VALIDATORS_TO_UPDATE: int = 5
1112
"""Maximum number of validators to update during UpdateValidatorListBalance."""
1213

14+
MINIMUM_RESERVE_LAMPORTS: int = MINIMUM_DELEGATION
15+
"""Minimum balance required in the stake pool reserve"""
16+
17+
MINIMUM_ACTIVE_STAKE: int = MINIMUM_DELEGATION
18+
"""Minimum active delegated staked required in a stake account"""
19+
1320

1421
def find_deposit_authority_program_address(
1522
program_id: PublicKey,

stake-pool/py/tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def async_client(event_loop, solana_test_validator) -> Iterator[AsyncClient]:
9292
@pytest.fixture
9393
def payer(event_loop, async_client) -> Keypair:
9494
payer = Keypair()
95-
airdrop_lamports = 10_000_000_000
95+
airdrop_lamports = 20_000_000_000
9696
event_loop.run_until_complete(airdrop(async_client, payer.public_key, airdrop_lamports))
9797
return payer
9898

stake-pool/py/tests/test_a_time_sensitive.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
from spl.token.instructions import get_associated_token_address
66

77
from stake.constants import STAKE_LEN
8-
from stake_pool.state import StakePool, ValidatorList
98
from stake_pool.actions import deposit_sol, decrease_validator_stake, increase_validator_stake, update_stake_pool
9+
from stake_pool.constants import MINIMUM_ACTIVE_STAKE
10+
from stake_pool.state import StakePool, ValidatorList
1011

1112

1213
@pytest.mark.asyncio
1314
async def test_increase_decrease_this_is_very_slow(async_client, validators, payer, stake_pool_addresses, waiter):
1415
(stake_pool_address, validator_list_address) = stake_pool_addresses
1516
resp = await async_client.get_minimum_balance_for_rent_exemption(STAKE_LEN)
1617
stake_rent_exemption = resp['result']
17-
increase_amount = 100_000_000
18+
increase_amount = MINIMUM_ACTIVE_STAKE * 2
1819
decrease_amount = increase_amount // 2
1920
deposit_amount = (increase_amount + stake_rent_exemption) * len(validators)
2021

stake-pool/py/tests/test_bot_rebalance.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from solana.rpc.commitment import Confirmed
44
from spl.token.instructions import get_associated_token_address
55

6-
from stake.constants import STAKE_LEN
7-
from stake_pool.state import StakePool, ValidatorList
6+
from stake.constants import STAKE_LEN, LAMPORTS_PER_SOL
87
from stake_pool.actions import deposit_sol
8+
from stake_pool.constants import MINIMUM_ACTIVE_STAKE, MINIMUM_RESERVE_LAMPORTS
9+
from stake_pool.state import StakePool, ValidatorList
910

1011
from bot.rebalance import rebalance
1112

@@ -18,7 +19,7 @@ async def test_rebalance_this_is_very_slow(async_client, validators, payer, stak
1819
(stake_pool_address, validator_list_address) = stake_pool_addresses
1920
resp = await async_client.get_minimum_balance_for_rent_exemption(STAKE_LEN)
2021
stake_rent_exemption = resp['result']
21-
increase_amount = 100_000_000
22+
increase_amount = MINIMUM_ACTIVE_STAKE
2223
deposit_amount = (increase_amount + stake_rent_exemption) * len(validators)
2324

2425
resp = await async_client.get_account_info(stake_pool_address, commitment=Confirmed)
@@ -32,7 +33,7 @@ async def test_rebalance_this_is_very_slow(async_client, validators, payer, stak
3233

3334
# should only have minimum left
3435
resp = await async_client.get_account_info(stake_pool.reserve_stake, commitment=Confirmed)
35-
assert resp['result']['value']['lamports'] == stake_rent_exemption + 1
36+
assert resp['result']['value']['lamports'] == stake_rent_exemption + MINIMUM_RESERVE_LAMPORTS
3637

3738
# should all be the same
3839
resp = await async_client.get_account_info(validator_list_address, commitment=Confirmed)
@@ -45,12 +46,12 @@ async def test_rebalance_this_is_very_slow(async_client, validators, payer, stak
4546
# Test case 2: Decrease
4647
print('Waiting for next epoch')
4748
await waiter.wait_for_next_epoch(async_client)
48-
await rebalance(ENDPOINT, stake_pool_address, payer, deposit_amount / 1_000_000_000)
49+
await rebalance(ENDPOINT, stake_pool_address, payer, deposit_amount / LAMPORTS_PER_SOL)
4950

5051
# should still only have minimum left + rent exemptions from increase
5152
resp = await async_client.get_account_info(stake_pool.reserve_stake, commitment=Confirmed)
5253
reserve_lamports = resp['result']['value']['lamports']
53-
assert reserve_lamports == stake_rent_exemption * (1 + len(validator_list.validators)) + 1
54+
assert reserve_lamports == stake_rent_exemption * (1 + len(validator_list.validators)) + MINIMUM_RESERVE_LAMPORTS
5455

5556
# should all be decreasing now
5657
resp = await async_client.get_account_info(validator_list_address, commitment=Confirmed)
@@ -63,12 +64,12 @@ async def test_rebalance_this_is_very_slow(async_client, validators, payer, stak
6364
# Test case 3: Do nothing
6465
print('Waiting for next epoch')
6566
await waiter.wait_for_next_epoch(async_client)
66-
await rebalance(ENDPOINT, stake_pool_address, payer, deposit_amount / 1_000_000_000)
67+
await rebalance(ENDPOINT, stake_pool_address, payer, deposit_amount / LAMPORTS_PER_SOL)
6768

6869
# should still only have minimum left + rent exemptions from increase
6970
resp = await async_client.get_account_info(stake_pool.reserve_stake, commitment=Confirmed)
7071
reserve_lamports = resp['result']['value']['lamports']
71-
assert reserve_lamports == stake_rent_exemption + deposit_amount + 1
72+
assert reserve_lamports == stake_rent_exemption + deposit_amount + MINIMUM_RESERVE_LAMPORTS
7273

7374
# should all be decreasing now
7475
resp = await async_client.get_account_info(validator_list_address, commitment=Confirmed)

stake-pool/py/tests/test_create.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from solana.rpc.commitment import Confirmed
44
from spl.token.constants import TOKEN_PROGRAM_ID
55

6-
from stake_pool.constants import find_withdraw_authority_program_address, STAKE_POOL_PROGRAM_ID
6+
from stake_pool.constants import \
7+
find_withdraw_authority_program_address, \
8+
MINIMUM_RESERVE_LAMPORTS, \
9+
STAKE_POOL_PROGRAM_ID
710
from stake_pool.state import StakePool, Fee
811

912
from stake.actions import create_stake
@@ -19,7 +22,7 @@ async def test_create_stake_pool(async_client, payer):
1922
STAKE_POOL_PROGRAM_ID, stake_pool.public_key)
2023

2124
reserve_stake = Keypair()
22-
await create_stake(async_client, payer, reserve_stake, pool_withdraw_authority, 1)
25+
await create_stake(async_client, payer, reserve_stake, pool_withdraw_authority, MINIMUM_RESERVE_LAMPORTS)
2326

2427
pool_mint = Keypair()
2528
await create_mint(async_client, payer, pool_mint, pool_withdraw_authority)

stake-pool/py/tests/test_deposit_withdraw_stake.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from stake.constants import STAKE_LEN
88
from stake.state import StakeState
99
from stake_pool.actions import deposit_stake, withdraw_stake, update_stake_pool
10+
from stake_pool.constants import MINIMUM_ACTIVE_STAKE
1011
from stake_pool.state import StakePool
1112

1213

@@ -17,7 +18,7 @@ async def test_deposit_withdraw_stake(async_client, validators, payer, stake_poo
1718
data = resp['result']['value']['data']
1819
stake_pool = StakePool.decode(data[0], data[1])
1920
validator = next(iter(validators))
20-
stake_amount = 1_000_000
21+
stake_amount = MINIMUM_ACTIVE_STAKE
2122
stake = Keypair()
2223
await create_stake(async_client, payer, stake, payer.public_key, stake_amount)
2324
stake = stake.public_key

stake-pool/py/tests/test_stake.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import pytest
33
from solana.keypair import Keypair
44

5-
from stake.state import StakeAuthorize
65
from stake.actions import authorize, create_stake, delegate_stake
6+
from stake.constants import MINIMUM_DELEGATION
7+
from stake.state import StakeAuthorize
78

89

910
@pytest.mark.asyncio
1011
async def test_create_stake(async_client, payer):
1112
stake = Keypair()
12-
await create_stake(async_client, payer, stake, payer.public_key, 100_000)
13+
await create_stake(async_client, payer, stake, payer.public_key, MINIMUM_DELEGATION)
1314

1415

1516
@pytest.mark.asyncio
@@ -24,7 +25,7 @@ async def test_delegate_stake(async_client, validators, payer):
2425
async def test_authorize_stake(async_client, payer):
2526
stake = Keypair()
2627
new_authority = Keypair()
27-
await create_stake(async_client, payer, stake, payer.public_key, 1_000)
28+
await create_stake(async_client, payer, stake, payer.public_key, MINIMUM_DELEGATION)
2829
await asyncio.gather(
2930
authorize(async_client, payer, payer, stake.public_key, new_authority.public_key, StakeAuthorize.STAKER),
3031
authorize(async_client, payer, payer, stake.public_key, new_authority.public_key, StakeAuthorize.WITHDRAWER)

0 commit comments

Comments
 (0)