</> RAIN RISK MARKETS — SOURCE CODE
✅ MIT licensed — fork freely. Full protocol (Foundry), dApp, and simulator source.
Send feedback, bug reports, or patches (unified diffs) to the site owner via the contact you got this link from.
A demo faucet redeem code is available from the site owner on request.
⬇ DOWNLOAD ZIP (rain-risk-markets-src.zip)
🚀 LAUNCH APP
📊 SIMULATOR
FILES
- CONTRIBUTING.md 1,347 B
- DEPLOYMENT.md 10,441 B
- LICENSE 1,074 B
- README.md 4,067 B
- WHITEPAPER-v0.9.md 36,400 B
- app/SUMMARY.md 4,914 B
- app/abis.js 4,339 B
- app/app.js 50,885 B
- app/index.html 7,999 B
- app/rain-logo-v2.png 2,067 B
- app/roulette.html 9,232 B
- app/roulette.js 35,183 B
- app/style.css 12,118 B
- protocol/foundry.toml 286 B
- protocol/script/Deploy.s.sol 3,469 B
- protocol/script/DeployDemo.s.sol 2,778 B
- protocol/src/FeeSplitter.sol 5,568 B
- protocol/src/MarketRegistry.sol 5,377 B
- protocol/src/RUSD.sol 447 B
- protocol/src/RiskEngine.sol 10,501 B
- protocol/src/RiskVault.sol 6,619 B
- protocol/src/VRFAdapter.sol 2,923 B
- protocol/test/Fuzz.t.sol 6,710 B
- protocol/test/Protocol.t.sol 13,494 B
- simulator/index.html 54,101 B
README
# RAIN Risk Markets
**A permissionless risk-markets protocol on Arbitrum One.** Anyone can sell risk by
depositing into an ERC-4626 vault (earning the house spread), and anyone can buy risk
by taking positions on listed two-outcome markets — settled trustlessly by Chainlink
VRF v2.5. The core design invariant is **value conservation**: every position's
worst-case payout is fully reserved against vault TVL at placement time, so the vault
can never owe more than it holds.
## Live
- 🌐 Site: https://rainsandbox.xyz
- 🚀 dApp (DEMO play-money + LIVE USDC): https://rainsandbox.xyz/app/
- 🎡 Roulette (demo): https://rainsandbox.xyz/app/roulette.html
- 📊 Protocol simulator: https://rainsandbox.xyz/riskmarkets/
- 📄 Whitepaper: [WHITEPAPER-v0.9.md](WHITEPAPER-v0.9.md)
## Contracts — Arbitrum One (42161)
### LIVE stack (USDC)
| Contract | Address |
|---|---|
| MarketRegistry | `0x076149f4293549b78C909315B3465805922fDf70` |
| RiskVault (ERC-4626, asset = USDC) | `0x9eDCB60620Ad062C4EbA71d5B457eA08fc1EadE8` |
| FeeSplitter | `0x0dd5cE18cFdc7345f0caA212B94747c052EfA947` |
| VRFAdapter | `0x2afFca69f8aa481afDCE3c15669225246dC2008B` |
| RiskEngine | `0x16700BA3141Dd73ea0139B1e6663B6b40268d99d` |
### DEMO stack (RUSD play money)
| Contract | Address |
|---|---|
| RUSD (RISK Dollar, 6 dec) | `0x260c7019E760763988843Bc5b873d749b5937469` |
| MarketRegistry (demo) | `0xADf3B1270961231ff925C8885843c597502A3d44` |
| RiskVault (demo, asset = RUSD) | `0xEcF918c851d9259DDaEc48d51D8363CBaDe3A18F` |
| FeeSplitter (demo) | `0x46F8478aeDbE189ffa85CE06BFF767c57b7d403c` |
| VRFAdapter (demo) | `0x17fb4Fc8778aF721D28846F64A391F7D7374d47f` |
| RiskEngine (demo) | `0x4fd901d0f18d738142F86A82AC1895D4B0C6EBa5` |
## Architecture
```
deposit / withdraw (ERC-4626)
LPs ────────────────────────────────────────► RiskVault
▲ │ reserve / release
│ ▼
Traders ──placePosition──► RiskEngine ◄────── MarketRegistry
│ ▲ (markets: prob, payoutX,
requestWords │ │ fulfill EV ≤ 98.75% floor)
▼ │
VRFAdapter ◄────────► Chainlink VRF v2.5
│
fees ─────▼
FeeSplitter (protocol / brand split)
```
- **RiskVault** — ERC-4626 vault; LPs sell risk; TVL cap, high-water mark,
recovery gate, 48h withdrawal delay.
- **MarketRegistry** — permissionless listing of two-outcome markets with a
spread floor (EV ≤ 98.75%).
- **RiskEngine** — places positions, reserves worst-case payouts against the
vault (value-conservation invariant), settles on VRF callback, timeout voids.
- **VRFAdapter** — Chainlink VRF v2.5 consumer.
- **FeeSplitter** — splits spread revenue.
## Build & Test
Requires [Foundry](https://book.getfoundry.sh/).
```bash
cd protocol
forge install OpenZeppelin/openzeppelin-contracts
forge install smartcontractkit/chainlink-brownie-contracts
forge install foundry-rs/forge-std
forge build
forge test -vv # unit + fuzz tests, incl. value-conservation invariant
```
Note: `lib/` is not included in this release — install dependencies with
`forge install` as above (remappings are in `foundry.toml`).
## Directory Layout
```
protocol/ Foundry project — src/ (6 contracts), script/ (deploy), test/
app/ Static dApp (ethers v6, no build step) — index.html, app.js,
roulette.html, roulette.js, abis.js, style.css
simulator/ Single-file protocol simulator (as deployed at /riskmarkets/)
WHITEPAPER-v0.9.md
DEPLOYMENT.md Mainnet deployment log (scrubbed)
```
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).
## License
MIT — see [LICENSE](LICENSE).