Skip to content

Commit ca4570a

Browse files
committed
cli: Properly support token-2022 mints
#### Problem Although the stake pool program allows for mints on token-2022, the CLI still does not. #### Summary of changes A few changes: * use spl-token-2022 for instruction creators * allow for the token program id to be spl_token::id() or spl_token_2022::id() * derive ATAs with the token program id * use the token program id stored on the stake pool * during pool creation, return a helpful error if the mint is configured incorrectly * add a test script using token-2022
1 parent c3a6906 commit ca4570a

File tree

4 files changed

+197
-66
lines changed

4 files changed

+197
-66
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ spl-stake-pool = { version = "=2.0.1", path = "../../program", features = [
3333
spl-token = { version = "=7.0", features = [
3434
"no-entrypoint",
3535
] }
36+
spl-token-2022 = { version = "=7.0", features = [
37+
"no-entrypoint",
38+
] }
3639
bs58 = "0.5.1"
3740
bincode = "1.3.1"
3841

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to setup a stake pool from scratch. Please modify the parameters to
4+
# create a stake pool to your liking!
5+
6+
cd "$(dirname "$0")" || exit
7+
command_args=()
8+
sol_amount=$1
9+
10+
###################################################
11+
### MODIFY PARAMETERS BELOW THIS LINE FOR YOUR POOL
12+
###################################################
13+
14+
# Epoch fee, assessed as a percentage of rewards earned by the pool every epoch,
15+
# represented as `numerator / denominator`
16+
command_args+=( --epoch-fee-numerator 1 )
17+
command_args+=( --epoch-fee-denominator 100 )
18+
19+
# Withdrawal fee for SOL and stake accounts, represented as `numerator / denominator`
20+
command_args+=( --withdrawal-fee-numerator 2 )
21+
command_args+=( --withdrawal-fee-denominator 100 )
22+
23+
# Deposit fee for SOL and stake accounts, represented as `numerator / denominator`
24+
command_args+=( --deposit-fee-numerator 3 )
25+
command_args+=( --deposit-fee-denominator 100 )
26+
27+
command_args+=( --referral-fee 0 ) # Percentage of deposit fee that goes towards the referrer (a number between 0 and 100, inclusive)
28+
29+
command_args+=( --max-validators 2350 ) # Maximum number of validators in the stake pool, 2350 is the current maximum possible
30+
31+
# (Optional) Deposit authority, required to sign all deposits into the pool.
32+
# Setting this variable makes the pool "private" or "restricted".
33+
# Uncomment and set to a valid keypair if you want the pool to be restricted.
34+
#command_args+=( --deposit-authority keys/authority.json )
35+
36+
###################################################
37+
### MODIFY PARAMETERS ABOVE THIS LINE FOR YOUR POOL
38+
###################################################
39+
40+
keys_dir=keys
41+
spl_stake_pool=spl-stake-pool
42+
# Uncomment to use a local build
43+
spl_stake_pool=../../../target/debug/spl-stake-pool
44+
45+
mkdir -p $keys_dir
46+
47+
create_keypair () {
48+
if test ! -f "$1"
49+
then
50+
solana-keygen new --no-passphrase -s -o "$1"
51+
fi
52+
}
53+
54+
echo "Creating pool"
55+
stake_pool_keyfile=$keys_dir/stake-pool.json
56+
validator_list_keyfile=$keys_dir/validator-list.json
57+
mint_keyfile=$keys_dir/mint.json
58+
reserve_keyfile=$keys_dir/reserve.json
59+
create_keypair $stake_pool_keyfile
60+
create_keypair $validator_list_keyfile
61+
create_keypair $mint_keyfile
62+
create_keypair $reserve_keyfile
63+
64+
spl-token create-token --program-2022 "$mint_keyfile"
65+
66+
set -ex
67+
$spl_stake_pool \
68+
create-pool \
69+
"${command_args[@]}" \
70+
--pool-keypair "$stake_pool_keyfile" \
71+
--validator-list-keypair "$validator_list_keyfile" \
72+
--mint-keypair "$mint_keyfile" \
73+
--reserve-keypair "$reserve_keyfile"
74+
75+
set +ex
76+
stake_pool_pubkey=$(solana-keygen pubkey "$stake_pool_keyfile")
77+
set -ex
78+
79+
echo "Depositing SOL into stake pool"
80+
$spl_stake_pool deposit-sol "$stake_pool_pubkey" "$sol_amount"

0 commit comments

Comments
 (0)