Open source
Every GonkaWeightSwap deal is settled by this escrow contract, running entirely on the Gonka network. Read it, copy it, and verify it on your own machine.
At a glance
- Name
- gonka-weight-swap
- Version
- 0.2.0-draft
- Framework
- CosmWasm 2.x (Rust)
- Files
- 8
What the contract guarantees
- No admin and no upgrades: nobody, including the authors, can move funds or change the rules after deployment.
- USDT leaves the contract only in three ways: payment to the host for verified weight, refund to the investor, or a full refund on cancel.
- Deposits must match the terms exactly; wrong amounts or extra tokens are rejected, so nothing gets stuck.
- Total paid to the host can never exceed the budget, and when the target is reached the host receives exactly the budget, with no rounding loss.
- Payout = delivered weight × budget ÷ target weight. The rate is fixed when the offer is published and can't be changed.
- Settlement uses the network's final reward weight for the epoch — after penalties, caps and delegation — so an investor never pays for work the network itself discounted.
- Weight is always read for the host's node (participant) address, which is where the protocol records epoch performance; the investor address only receives GNK rewards and refunds.
- Weight is read only from Gonka's own chain modules — no oracles or external services.
- Each epoch is settled once, in order, and only after the following full epoch has started.
- An epoch the chain has no recorded reward weight for is treated as unreadable, never as zero work, so a gap in history can't cost the host its collateral.
- An investor address can back only one open or active deal, so the same weight is never paid twice.
- Collateral is forfeited only if no qualifying epoch happens within the start window; after that, stopping returns it to the host.
- If nobody settles for 10 epochs after the term, anyone can close the deal and return the unpaid USDT to the investor.
- Every deal, epoch and total is public on-chain, so any dashboard can list and chart all current and past deals.
How a deal works
- Step 1 · Investor or hostPublish
Either side publishes an offer. An investor locks the exact USDT budget; a host locks its GNK collateral (it can be zero, and the market decides what that's worth).
- Step 2 · The other sideAccept
A host accepts an investor's offer by locking the collateral, or an investor accepts a host's offer by locking the budget. The host joins with its node address and points that node's rewards at the investor's address. The deal starts at the next epoch.
- Step 3 · Anyone (usually the host)Settle
Each epoch is settled only after the next full epoch has started, when the network has finished counting weight and paying GNK. The contract reads the node's final reward weight for that epoch — the figure the network itself pays on, after penalties and caps — and pays USDT at the fixed rate.
- Step 4 · ContractFinish
Target reached, term over or downtime limit hit: unspent USDT returns to the investor and collateral to the host. Collateral goes to the investor only if the host never had a qualifying epoch in the start window.
Source code
Package manifest and dependencies.
[package]
name = "gonka-weight-swap"
version = "0.2.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
library = []
[dependencies]
cosmwasm-std = { version = "2.1", features = ["cosmwasm_2_0"] }
cosmwasm-schema = "2.1"
cw-storage-plus = "2.0"
cw-utils = "2.0"
schemars = "0.8"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
overflow-checks = true
Verify it yourself
- Install Rust and the wasm target:
rustup target add wasm32-unknown-unknown - Create a folder and place each file at the path shown above.
- Run the tests:
cargo test - Build the contract:
cargo build --release --target wasm32-unknown-unknown - For a reproducible build, use the
cosmwasm/optimizerDocker image and compare checksums.
Still being finalized
- Contracts read epochs and weight through GetCurrentEpoch and EpochPerformanceSummaryByParticipant, added to the chain's allowed list in gonka-ai/gonka PR #1758 and shipping with upgrade v0.2.16.
- Agreed with the core team (issue #1867): settlement uses the final participant reward weight, keyed by the node's participant address rather than the reward recipient. The field is being added to the epoch performance summary in that upgrade.
- Deals can only cover epochs finalized after the upgrade; earlier epochs carry no reward weight and are rejected by the contract instead of counted as zero.
- Confirmed: anyone can upload and instantiate contracts on Gonka mainnet, and the GNK base denom is ngonka (9 decimals).
- Compile and run the tests, then get an independent security audit before any real funds.
- Connect wallets (Keplr / Leap) on the site so both sides can publish, accept and settle.