Program for staking and receiving rewards.
draw.io editable
- This code is unaudited. Use at your own risk.
# Toolchains
rustup default 1.83.0
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
cargo install --git https://github.com/coral-xyz/anchor avm --force
avm install 0.31.1 && avm use 0.31.1
npm i -g yarn
# Smoke test
solana-test-validator -r &
sleep 5
solana config set -ul
solana airdrop 2
# Program
anchor build -p reward_pool -- --features local-testing,test-id
anchor test -p reward_pool -- --features local-testing,test-id
# Troubleshooting
cargo tree -p reward-pool -i openssl-sys # should output nothingAnchor is used for developoment, and it's recommended workflow is used here. To get started, see the guide.
rustup default 1.83.0
cargo install --locked anchor-cli@0.31.1
sh -c "$(curl -sSfL https://release.solana.com/v2.3.2/install)"Verify versions:
rustc --version
cargo --version
anchor --version
solana --versionanchor build --verifiable
The --verifiable flag should be used before deploying so that your build artifacts
can be deterministically generated with docker.
When testing locally, be sure to build with feature "local-testing" to enable the testing IDs. You can do this by editing programs/step-staking/Cargo.toml and uncommenting the default feature set line.
anchor test
To verify the program deployed on Solana matches your local source code, change directory
into the program you want to verify, e.g., cd program, and run
anchor verify <program-id | write-buffer>A list of build artifacts can be found under releases.
To deploy the program, configure your CLI to the desired network/wallet and run
solana program deploy --programid <keypair> target/verifiable/reward_pool.soI would not suggest using anchor deploy at this time; it wouldn't/couldn't really add much value. Be sure to use --programid <keypair> to deploy to the correct address.
Note: By default, programs are deployed to accounts that are twice the size of the original deployment. Doing so leaves room for program growth in future redeployments. For this program, I beleive that's proper - I wouldn't want to limit further, but I do see some possibility for growth, but not beyond double.
There is no initial migration required with this program.
| Account | PDA seeds | Notes |
|---|---|---|
| Pool signer | [pool.key()] |
Authority for staking/reward vaults |
| User | [owner.key(), pool.key()] |
Tracks stake and reward checkpoints; bump stored in nonce |
| Vaults | n/a | Owned by pool signer, close authority = None |
# start a validator
solana-test-validator --reset &
# airdrop some SOL
solana airdrop 10
# build and deploy the program
anchor build -p reward_pool
anchor deploy -p reward_pool
# example instruction flow (Anchor scripts)
anchor run initialize_pool
anchor run create_user
anchor run stake
anchor run fund
anchor run claim
anchor run unstake
The anchor run scripts are placeholders showing call order; the TypeScript SDK can drive the same instructions.
