Menu

1 / 5

staking: per-second token rewards on Solana with a reward-per-token accumulator

DEV Community: opensource·Abdeldjalil Chougui·3 days ago
#hPwXeKwG
#devtoopensource#devto#dev#pool#user
Long article (1216 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.