A staking pool sounds like a loop. Every second, a fixed amount of reward tokens is released. Each staker gets a slice in proportion to their share of the pool. So: every second, go through all stakers and add to their balance.
That loop cannot run on a blockchain. Nothing executes on its own every second, and a transaction that touches every staker gets more expensive with every new one. The pool needs a way to know what each staker has earned without ever visiting them all.
There is a well-known trick for this, the reward-per-token accumulator, and staking is the project where I implemented it: stake an SPL token and earn another one, paid per second , in proportion to your share of the pool. It is built with Anchor 1.2 and token_interface , so it works with SPL Token or Token-2022.
The warning from the README first: not audited, devnet / localnet only. This is a learning project.…