A CosmWasm smart contract implementing a digital tontine system on Safrochain. The contract manages all deposits, rules, and payouts in SAF tokens automatically.
- Circle Management: Create, join, and manage tontine circles with configurable parameters
- Automatic Payouts: Scheduled payouts based on cycle duration and payout order
- Penalty System: Late fees and penalties for missed payments
- Security Controls: Emergency stop, arbitration, and pause/unpause functionality
- Transparent Tracking: On-chain event logging for all operations
- Flexible Membership: Public or invite-only circles with configurable member limits
src/contract.rs- Entry points (instantiate, execute, query)src/execute.rs- Execute message handlerssrc/query.rs- Query message handlerssrc/state.rs- State definitions and storagesrc/msg.rs- Message typessrc/error.rs- Error types
- Rust 1.70+
wasm32-unknown-unknowntarget- CosmWasm optimizer (optional, for optimized builds)
# Install wasm32 target
rustup target add wasm32-unknown-unknown
# Build the contract
cargo build --release --target wasm32-unknown-unknown
# Generate schemas (optional)
cargo run --example schema# Install cosmwasm-optimizer
docker pull cosmwasm/workspace-optimizer:0.14.0
# Optimize the contract
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0The optimized WASM file will be in artifacts/safrimba_contract.wasm after optimization.
Deploy to Safrochain testnet using:
# Upload the contract
safrochaind tx wasm store artifacts/safrimba_contract.wasm \
--from <your-key> \
--chain-id safrochain-testnet \
--gas auto \
--gas-adjustment 1.3 \
--fees 1000000saf
# Instantiate the contract
safrochaind tx wasm instantiate <code-id> \
'{"platform_fee_percent": 100, "platform_address": "addr_safro..."}' \
--from <your-key> \
--chain-id safrochain-testnet \
--label "Safrimba Contract" \
--admin <admin-address> \
--gas auto \
--fees 1000000saf{
"create_circle": {
"circle_name": "My Tontine Circle",
"circle_description": "A savings circle for friends",
"max_members": 10,
"min_members_required": 5,
"contribution_amount": "1000000",
"total_cycles": 10,
"cycle_duration_days": 30,
"payout_order_type": "random_order",
"auto_payout_enabled": true,
...
}
}{
"join_circle": {
"circle_id": 1
}
}Send SAF tokens along with:
{
"deposit_contribution": {
"circle_id": 1
}
}{
"process_payout": {
"circle_id": 1
}
}{
"get_circle": {
"circle_id": 1
}
}{
"get_circle_members": {
"circle_id": 1
}
}{
"get_current_cycle": {
"circle_id": 1
}
}[Your License Here]