WinSaf Contracts
Provably-fair on-chain lottery for Safrochain — CosmWasm, Apache-2.0
WinSaf is a non-custodial Telegram lottery on Safrochain. This repository contains the open-source CosmWasm smart contract — lottery, treasury, referral, and verifiable randomness in one consolidated contract.
The product stack (Mini App, API, MPC wallet, bot) lives in the private winsaf monorepo, with this repo checked out as a git submodule at contracts/cosmwasm/.
| Field | Value |
|---|---|
| Network | safro-testnet-1 |
| Contract | addr_safro1aqkst3m7cvv9ku9nfcq8w3njl8w37fsjjff64kqmjfxvpht3gwnqqdveaq |
| Code ID | 146 |
| Ticket price | 5 SAF (5_000_000 usaf) |
| Fund split | 75% prize · 10% referral · 15% treasury |
See deployment-testnet.json for the canonical record in this repo.
Everything runs in a single Wasm instance — no inter-contract calls:
- Lottery — rounds, ticket sales, draws, pull-based prize claims
- Treasury — 15% ops cut accrues on-chain; admin withdraws via
WithdrawTreasury - Referral — immutable referrer binding + pull claims
- Randomness — drand BLS, commit-reveal, or mock (dev only); never block hash/time
git clone git@github.com:Dev-Community-IO/winsaf-contracts.git
cd winsaf-contracts
rustup target add wasm32-unknown-unknown
cargo test --all # 88+ unit tests
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warningsBuild optimized Wasm for Safrochain (requires binaryen):
./scripts/optimize.sh
# → artifacts/winsaf.wasm + artifacts/checksums.txtRegenerate JSON schemas for integrators:
./scripts/schema.sh├── contracts/winsaf/ # Main CosmWasm contract (instantiate / execute / query / migrate)
├── packages/winsaf-shared/ # Shared types: FundSplitBps, RoundStatus, money helpers
├── scripts/
│ ├── optimize.sh # Safrochain-compatible wasm build (bulk-memory lowering)
│ ├── schema.sh # JSON schema generation
│ └── deploy.sh # Testnet deploy helper (mainnet blocked by default)
├── deployment-testnet.json # Deployed address + code_id
└── .github/ # CI, issue templates, Dependabot
| Bucket | Bps | % |
|---|---|---|
| Prize pool | 7500 | 75% |
| Referral | 1000 | 10% |
| Treasury | 1500 | 15% |
Admin can update via SetConfig (must still sum to 10_000 bps). On-chain config is the source of truth.
| Role | Powers |
|---|---|
| Players | Buy tickets, claim own prizes |
| Keeper / submitters | Permissionless close/draw; authorized randomness delivery |
| Admin | Pause, config, treasury withdraw, wasm migrate (CosmWasm admin) |
- Funds are integer
usafonly — overflow checks enabled in release builds - Randomness is cryptographically verified before draws (drand BLS or commit-reveal)
- Upgrade path:
wasm migrateto a verifiedcode_idonly — see SECURITY.md
Report vulnerabilities privately: Security advisories
| VM | CosmWasm only (no EVM) |
| Runtime | wasmd 0.54.1 / wasmvm 2.2.4 |
| Chain ID (testnet) | safro-testnet-1 |
| Address prefix | addr_safro |
| Denom | usaf (6 decimals) · display SAF |
| Doc | Purpose |
|---|---|
| CONTRIBUTING.md | How to contribute, PR requirements |
| SECURITY.md | Threat model, upgrade policy, reporting |
| CHANGELOG.md | Release history |
| docs/DEPLOYMENT.md | Store, instantiate, migrate, verify checksums |
| SETUP_GITHUB.md | GitHub org credentials & branch protection |
Apache-2.0 — see LICENSE.
- Product: winsaf.xyz
- Safrochain explorer: testnet
- Faucet: faucet.testnet.safrochain.com