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

Commit 675d65b

Browse files
authored
stake-pool-cli: Add more docs around scripts (#2531)
1 parent 203db7b commit 675d65b

File tree

6 files changed

+192
-87
lines changed

6 files changed

+192
-87
lines changed

docs/src/stake-pool.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ Additional information regarding staking and stake programming is available at:
2222
- https://solana.com/staking
2323
- https://docs.solana.com/staking/stake-programming
2424

25+
## Quick Start
26+
27+
If you're looking to get immediately into creating and running a stake pool,
28+
take a look at the
29+
[reference scripts](https://github.com/solana-labs/solana-program-library/tree/master/stake-pool/cli/scripts).
30+
31+
These scripts require the Solana CLI tool suite, which can be downloaded by
32+
following the instructions at (https://docs.solana.com/cli/install-solana-cli-tools).
33+
Additionally, you must have a usable keypair, created at the default location
34+
using `solana-keygen new`.
35+
36+
You'll see the following scripts:
37+
38+
* `setup-local.sh`: sets up a local test validator with validator vote accounts
39+
* `setup-stake-pool.sh`: creates a new stake pool with hardcoded parameters
40+
* `deposit-withdraw.sh`: performs some deposits and withdrawals
41+
42+
The
43+
[CLI README](https://github.com/solana-labs/solana-program-library/tree/master/stake-pool/cli)
44+
contains more information about each of these scripts.
45+
2546
## Motivation
2647

2748
This document is intended for the main actors of the stake pool system:
@@ -172,7 +193,7 @@ document are available at:
172193
## Source
173194

174195
The Stake Pool Program's source is available on
175-
[github](https://github.com/solana-labs/solana-program-library).
196+
[GitHub](https://github.com/solana-labs/solana-program-library).
176197

177198
For information about the types and instructions, the Stake Pool Rust docs are
178199
available at [docs.rs](https://docs.rs/spl-stake-pool/0.5.0/spl_stake_pool/).
@@ -248,7 +269,7 @@ sets the fee on creation. Let's create a pool with a 3% fee and a maximum of 100
248269
validator stake accounts:
249270

250271
```console
251-
$ spl-stake-pool create-pool --fee-numerator 3 --fee-denominator 100 --max-validators 1000
272+
$ spl-stake-pool create-pool --epoch-fee-numerator 3 --epoch-fee-denominator 100 --max-validators 1000
252273
Creating reserve stake DVwDn4LTRztuai4QeenM6fyzgiwUGpVXVNZ1mgKE1Pyc
253274
Creating mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB
254275
Creating associated token account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ to receive stake pool tokens of mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB, owned by 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn
@@ -276,6 +297,31 @@ This account holds onto additional stake used when rebalancing between validator
276297
For a stake pool with 1000 validators, the cost to create a stake pool is less
277298
than 0.5 SOL.
278299

300+
### Create a restricted stake pool
301+
302+
If a manager would like to restrict deposits (stake and SOL) to one key in
303+
particular, they can set a deposit authority at creation:
304+
305+
```console
306+
$ spl-stake-pool create-pool --epoch-fee-numerator 3 --epoch-fee-denominator 100 --max-validators 1000 --deposit-authority authority_keypair.json
307+
Creating reserve stake DVwDn4LTRztuai4QeenM6fyzgiwUGpVXVNZ1mgKE1Pyc
308+
Creating mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB
309+
Creating associated token account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ to receive stake pool tokens of mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB, owned by 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn
310+
Creating pool fee collection account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ
311+
Signature: qQwqahLuC24wPwVdgVXtd7v5htSSPDAH3JxFNmXCv9aDwjjqygQ64VMg3WdPCiNzc4Bn8vtS3qcnUVHVP5MbKgL
312+
Creating stake pool Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR
313+
Deposits will be restricted to 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn only, this can be changed using the set-funding-authority command.
314+
Signature: 5z6uH3EuPcujeWGpAjBtciSUR3TxtMBgWYU4ULagUso4QGzE9JenhYHwYthJ4b3rS57ByUNEXTr2BFyF5PjWC42Y
315+
```
316+
317+
As the output says, the `set-funding-authority` can be used to modify or remove
318+
the deposit authority.
319+
320+
As long as the deposit authority is set, SOL and stake deposits must be signed
321+
by `4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn`, so no one else can participate
322+
in the pool. As mentioned earlier, this feature does not prohibit withdrawals,
323+
so anyone with pool tokens will still be able to withdraw from the pool.
324+
279325
### Set manager
280326

281327
The stake pool manager may pass their administrator privileges to another account.
@@ -921,7 +967,7 @@ source the pool tokens. It's possible to specify the SPL token account using
921967
the `--pool-account` flag.
922968

923969
```console
924-
$ spl-stake-pool withdraw Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR 5 --pool-account 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF
970+
$ spl-stake-pool withdraw-stake Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR 5 --pool-account 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF
925971
Withdrawing ◎5.000000000, or 5 pool tokens, from stake account 3k7Nwu9jUSc6SNG11wzufKYoZXRFgxWamheGLYWp5Rvx, delegated to EhRbKi4Vhm1oUCGWHiLEMYZqDrHwEd7Jgzgi26QJKvfQ
926972
Creating account to receive stake CZF2z3JJoDmJRcVjtsrz1BKUUGNL3VPW5FPFqge1bzmQ
927973
Signature: 2xBPVPJ749AE4hHNCNYdjuHv1EdMvxm9uvvraWfTA7Urrvecwh9w64URCyLLroLQ2RKDGE2QELM2ZHd8qRkjavJM
@@ -932,7 +978,7 @@ accounts in the pool. It's also possible to specify a specific vote account for
932978
the withdraw using the `--vote-account` flag.
933979

934980
```console
935-
$ spl-stake-pool withdraw Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR --amount 5 --vote-account EhRbKi4Vhm1oUCGWHiLEMYZqDrHwEd7Jgzgi26QJKvfQ
981+
$ spl-stake-pool withdraw-stake Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR --amount 5 --vote-account EhRbKi4Vhm1oUCGWHiLEMYZqDrHwEd7Jgzgi26QJKvfQ
936982
Withdrawing ◎5.000000000, or 5 pool tokens, from stake account 3k7Nwu9jUSc6SNG11wzufKYoZXRFgxWamheGLYWp5Rvx, delegated to EhRbKi4Vhm1oUCGWHiLEMYZqDrHwEd7Jgzgi26QJKvfQ
937983
Creating account to receive stake CZF2z3JJoDmJRcVjtsrz1BKUUGNL3VPW5FPFqge1bzmQ
938984
Signature: 2xBPVPJ749AE4hHNCNYdjuHv1EdMvxm9uvvraWfTA7Urrvecwh9w64URCyLLroLQ2RKDGE2QELM2ZHd8qRkjavJM
@@ -953,7 +999,7 @@ reserve, but only if all of the validator stake accounts are at the minimum amou
953999
`0.001 SOL + stake account rent exemption`.
9541000

9551001
```console
956-
$ spl-stake-pool withdraw Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR 5 --use-reserve
1002+
$ spl-stake-pool withdraw-stake Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR 5 --use-reserve
9571003
Withdrawing ◎5.000000000, or 5 pool tokens, from stake account J5XB7mWpeaUZxZ6ogXT57qSCobczx27vLZYSgfSbZoBB
9581004
Creating account to receive stake 51XdXiBSsVzeuY79xJwWAGZgeKzzgFKWajkwvWyrRiNE
9591005
Signature: yQH9n7Go6iCMEYXqWef38ZYBPwXDmbwKAJFJ4EHD6TusBpusKsfNuT3TV9TL8FmxR2N9ExZTZwbD9Njc3rMvUcf

stake-pool/cli/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ have a usable keypair, created at the default location using `solana-keygen new`
1515
Builds the stake pool program and sets up a `solana-test-validator` with some
1616
new validator vote accounts.
1717

18-
The only input it accepts is a number, for the number of vote accounts to create, e.g.:
18+
It accepts the number of vote accounts to create and validator list file path to output
19+
vote accounts, e.g.:
1920

2021
```bash
21-
$ ./setup-local.sh 100
22+
$ ./setup-local.sh 100 validator_list.txt
2223
```
2324

2425
#### Important notes on local network
@@ -39,13 +40,23 @@ $ solana delegate-stake --force stake.json CzDy6uxLTko5Jjcdm46AozMmrARY6R2aDBagd
3940

4041
Creates a new stake pool with the parameters hardcoded in the script:
4142

42-
* fee numerator
43-
* fee denominator
43+
* epoch fee numerator
44+
* epoch fee denominator
45+
* withdrawal fee numerator
46+
* withdrawal fee denominator
47+
* deposit fee numerator
48+
* deposit fee denominator
49+
* referral fee
50+
* manager
51+
* staker
4452
* maximum number of validators
4553
* list of validator vote accounts
54+
* (Optional) deposit authority, for restricted pools
55+
56+
Modify the parameters to suit your needs, and your pool will be created!
4657

4758
```bash
48-
$ ./setup-stake-pool.sh 100 validator_list.txt
59+
$ ./setup-stake-pool.sh
4960
```
5061

5162
### deposit-withdraw.sh
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#!/usr/bin/env bash
22

33
# Script to deposit and withdraw stakes from a pool, given stake pool public key
4-
# and a list of validators
4+
# and a path to a file containing a list of validator vote accounts
55

66
cd "$(dirname "$0")"
77
stake_pool_keyfile=$1
88
validator_list=$2
99

10-
stake_pool_pubkey=$(solana-keygen pubkey $stake_pool_keyfile)
11-
12-
sol_amount=2
13-
half_sol_amount=1
14-
keys_dir=keys
15-
spl_stake_pool=../../../target/debug/spl-stake-pool
16-
17-
mkdir -p $keys_dir
18-
1910
create_keypair () {
2011
if test ! -f $1
2112
then
@@ -26,28 +17,31 @@ create_keypair () {
2617
create_user_stakes () {
2718
validator_list=$1
2819
sol_amount=$2
20+
authority=$3
2921
for validator in $(cat $validator_list)
3022
do
3123
create_keypair $keys_dir/stake_$validator.json
32-
solana create-stake-account $keys_dir/stake_$validator.json $sol_amount
24+
solana create-stake-account $keys_dir/stake_$validator.json $sol_amount --withdraw-authority $authority --stake-authority $authority
3325
done
3426
}
3527

3628
delegate_user_stakes () {
3729
validator_list=$1
30+
authority=$2
3831
for validator in $(cat $validator_list)
3932
do
40-
solana delegate-stake --force $keys_dir/stake_$validator.json $validator
33+
solana delegate-stake --force $keys_dir/stake_$validator.json $validator --stake-authority $authority
4134
done
4235
}
4336

4437
deposit_stakes () {
4538
stake_pool_pubkey=$1
4639
validator_list=$2
40+
authority=$3
4741
for validator in $(cat $validator_list)
4842
do
4943
stake=$(solana-keygen pubkey $keys_dir/stake_$validator.json)
50-
$spl_stake_pool deposit-stake $stake_pool_pubkey $stake
44+
$spl_stake_pool deposit-stake $stake_pool_pubkey $stake --withdraw-authority $authority
5145
done
5246
}
5347

@@ -61,16 +55,29 @@ withdraw_stakes () {
6155
done
6256
}
6357

64-
echo "Creating user stake accounts"
65-
create_user_stakes $validator_list $sol_amount
66-
echo "Delegating user stakes"
67-
delegate_user_stakes $validator_list
58+
sol_amount=2
59+
half_sol_amount=1
60+
keys_dir=keys
61+
spl_stake_pool=../../../target/debug/spl-stake-pool
62+
stake_pool_pubkey=$(solana-keygen pubkey $stake_pool_keyfile)
63+
echo "Setting up keys directory $keys_dir"
64+
mkdir -p $keys_dir
65+
authority=$keys_dir/authority.json
66+
echo "Setting up authority for deposited stake accounts at $authority"
67+
create_keypair $authority
68+
69+
echo "Creating user stake accounts to deposit into the pool"
70+
create_user_stakes $validator_list $sol_amount $authority
71+
echo "Delegating user stakes so that deposit will work"
72+
delegate_user_stakes $validator_list $authority
6873
echo "Waiting for stakes to activate, this may take awhile depending on the network!"
69-
echo "If you are running on localnet with 32 slots per epoch, wait 24 seconds..."
70-
sleep 24
74+
echo "If you are running on localnet with 32 slots per epoch, wait 12 seconds..."
75+
sleep 12
7176
echo "Depositing stakes into stake pool"
72-
deposit_stakes $stake_pool_pubkey $validator_list
77+
deposit_stakes $stake_pool_pubkey $validator_list $authority
7378
echo "Withdrawing stakes from stake pool"
7479
withdraw_stakes $stake_pool_pubkey $validator_list $half_sol_amount
75-
echo "Withdrawing sol from stake pool"
76-
$spl_stake_pool withdraw-sol $stake_pool_pubkey $half_sol_amount
80+
echo "Depositing SOL into stake pool to authority"
81+
$spl_stake_pool deposit-sol $stake_pool_pubkey $sol_amount
82+
echo "Withdrawing SOL from stake pool to authority"
83+
$spl_stake_pool withdraw-sol $stake_pool_pubkey $authority $half_sol_amount

stake-pool/cli/scripts/setup-local.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
#!/usr/bin/env bash
22

33
# Script to setup a local solana-test-validator with the stake pool program
4+
# given a maximum number of validators and a file path to store the list of
5+
# test validator vote accounts.
46

57
cd "$(dirname "$0")"
68
max_validators=$1
79
validator_list=$2
810

9-
keys_dir=keys
10-
mkdir -p $keys_dir
11-
if test -f $validator_list
12-
then
13-
rm $validator_list
14-
fi
15-
1611
create_keypair () {
1712
if test ! -f $1
1813
then
1914
solana-keygen new --no-passphrase -s -o $1
2015
fi
2116
}
2217

23-
build_program () {
18+
build_stake_pool_program () {
2419
cargo build-bpf --manifest-path ../../program/Cargo.toml
2520
}
2621

27-
setup_validator() {
22+
setup_test_validator() {
2823
solana-test-validator --bpf-program SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy ../../../target/deploy/spl_stake_pool.so --quiet --reset --slots-per-epoch 32 &
2924
pid=$!
3025
solana config set --url http://127.0.0.1:8899
@@ -40,17 +35,27 @@ create_vote_accounts () {
4035
do
4136
create_keypair $keys_dir/identity_$number.json
4237
create_keypair $keys_dir/vote_$number.json
43-
solana create-vote-account $keys_dir/vote_$number.json $keys_dir/identity_$number.json --commission 1
38+
create_keypair $keys_dir/withdrawer_$number.json
39+
solana create-vote-account $keys_dir/vote_$number.json $keys_dir/identity_$number.json $keys_dir/withdrawer_$number.json --commission 1
4440
vote_pubkey=$(solana-keygen pubkey $keys_dir/vote_$number.json)
4541
echo $vote_pubkey >> $validator_list
4642
done
4743
}
4844

49-
echo "Building on-chain program"
50-
build_program
5145

52-
echo "Setting up local validator"
53-
setup_validator
46+
echo "Setup keys directory and clear old validator list file if found"
47+
keys_dir=keys
48+
mkdir -p $keys_dir
49+
if test -f $validator_list
50+
then
51+
rm $validator_list
52+
fi
53+
54+
echo "Building on-chain stake pool program"
55+
build_stake_pool_program
56+
57+
echo "Setting up local test validator"
58+
setup_test_validator
5459

55-
echo "Creating vote accounts"
60+
echo "Creating vote accounts, these accounts be added to the stake pool"
5661
create_vote_accounts $max_validators $validator_list

0 commit comments

Comments
 (0)