Skip to content

Dev-Community-IO/winsaf-contracts

Repository files navigation

WinSaf Contracts
Provably-fair on-chain lottery for Safrochain — CosmWasm, Apache-2.0

CI License Safrochain CosmWasm


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

Live deployment (testnet)

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.

Why one contract?

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

Quick start

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 warnings

Build optimized Wasm for Safrochain (requires binaryen):

./scripts/optimize.sh
# → artifacts/winsaf.wasm + artifacts/checksums.txt

Regenerate JSON schemas for integrators:

./scripts/schema.sh

Repository layout

├── 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

Economics (on-chain defaults)

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.

Security model

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 usaf only — overflow checks enabled in release builds
  • Randomness is cryptographically verified before draws (drand BLS or commit-reveal)
  • Upgrade path: wasm migrate to a verified code_id only — see SECURITY.md

Report vulnerabilities privately: Security advisories

Chain facts

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

Documentation

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

License

Apache-2.0 — see LICENSE.

Links

About

Open-source CosmWasm lottery contract for WinSaf on Safrochain (Apache-2.0)

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors