README.md
gno.land/p/moul/x/daily/ratelimit/v0
Deterministic token-bucket rate limiter — a port of golang.org/x/time/rate
with the wall clock replaced by a caller-supplied monotonic tick (on-chain, the
block height).
A Limiter owns a set of per-key token buckets sharing one rate/burst
config. Each bucket refills at rate tokens per tick up to burst; the caller
picks what a key is (typically an address) and passes the current tick on every
call. Pure integer/float math over persistent avl state — no chain imports, no
ambient state, fully replayable.
1import "gno.land/p/moul/x/daily/ratelimit/v0"
2
3l := ratelimit.New(0.5, 5.0) // 0.5 tokens/tick, capacity 5
4l.Allow("g1caller", height) // consume one token; false if empty
5l.AllowN("g1caller", height, 3) // consume 3 atomically; false if <3
6l.Tokens("g1caller", height) // read-only balance (whole tokens)
Live demo: r/moul/x/daily/ratelimitdemo
· render it at /r/moul/x/daily/ratelimitdemo/v0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
Dependency graph:

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.