|
1 | | -# Soroban Project |
| 1 | +# Predictify Contracts Mainnet Deployment Guide |
2 | 2 |
|
3 | | -This repository contains smart contracts built for the Stellar Soroban platform, organized as a Rust workspace. It includes both example and advanced contracts, with a focus on prediction markets and oracle integration. |
| 3 | +> **Platform:** Stellar Soroban Mainnet |
| 4 | +> **Audience:** Developers, DevOps, and maintainers deploying Predictify contracts to production |
4 | 5 |
|
5 | 6 | --- |
6 | 7 |
|
7 | | -## Project Structure |
8 | | - |
9 | | -```text |
10 | | -. |
11 | | -├── contracts |
12 | | -│ ├── hello-world |
13 | | -│ │ ├── src |
14 | | -│ │ │ ├── lib.rs |
15 | | -│ │ │ └── test.rs |
16 | | -│ │ ├── Cargo.toml |
17 | | -│ │ └── Makefile |
18 | | -│ └── predictify-hybrid |
19 | | -│ ├── src |
20 | | -│ │ ├── lib.rs |
21 | | -│ │ └── test.rs |
22 | | -│ ├── Cargo.toml |
23 | | -│ ├── Makefile |
24 | | -│ └── README.md |
25 | | -├── Cargo.toml |
26 | | -└── README.md |
27 | | -``` |
28 | | - |
29 | | -- New Soroban contracts can be added in the `contracts` directory, each in their own subdirectory with its own `Cargo.toml`. |
30 | | -- All contracts share dependencies via the top-level workspace `Cargo.toml`. |
| 8 | +## 📋 Table of Contents |
| 9 | +1. [Project Summary](#project-summary) |
| 10 | +2. [Prerequisites](#prerequisites) |
| 11 | +3. [Configuration for Mainnet](#configuration-for-mainnet) |
| 12 | +4. [Deployment Instructions](#deployment-instructions) |
| 13 | +5. [Oracle Setup](#oracle-setup) |
| 14 | +6. [Testing Deployment](#testing-deployment) |
| 15 | +7. [Monitoring and Alerts](#monitoring-and-alerts) |
| 16 | +8. [Security Checklist](#security-checklist) |
| 17 | +9. [Rollback Procedures](#rollback-procedures) |
| 18 | +10. [Maintenance Procedures](#maintenance-procedures) |
31 | 19 |
|
32 | 20 | --- |
33 | 21 |
|
34 | | -## Contracts Overview |
| 22 | +## 🧠 Project Summary |
| 23 | +This repository contains smart contracts for Stellar's Soroban platform, organized in a Rust workspace. Key components include: |
35 | 24 |
|
36 | | -### 1. hello-world |
37 | | -A minimal example contract for Soroban, demonstrating basic contract structure and testing. |
| 25 | +- `hello-world`: A basic example contract for testing and structure reference. |
| 26 | +- `predictify-hybrid`: A hybrid prediction market with oracle integration (Reflector, Pyth), staking, dispute resolution, and community voting. |
38 | 27 |
|
39 | | -**Functionality:** |
40 | | -- Exposes a single function `hello(to: String) -> Vec<String>` that returns a greeting message. |
41 | | -- Includes a simple test in `test.rs`. |
| 28 | +--- |
42 | 29 |
|
43 | | -**Example:** |
44 | | -```rust |
45 | | -let words = client.hello(&String::from_str(&env, "Dev")); |
46 | | -// Returns: ["Hello", "Dev"] |
47 | | -``` |
| 30 | +## 🛠️ Prerequisites |
| 31 | +- [Rust](https://www.rust-lang.org/tools/install) |
| 32 | +- [Soroban CLI](https://github.com/stellar/soroban-tools) |
| 33 | +- Stellar-funded deployer account (mainnet) |
| 34 | +- Admin account (preferably multisig-secured) |
48 | 35 |
|
49 | | -**Build & Test:** |
| 36 | +Install tools: |
50 | 37 | ```bash |
51 | | -cd contracts/hello-world |
52 | | -make build # Build the contract |
53 | | -make test # Run tests |
| 38 | +rustup update |
| 39 | +cargo install --locked --version 20.0.0 soroban-cli |
54 | 40 | ``` |
55 | 41 |
|
56 | 42 | --- |
57 | 43 |
|
58 | | -### 2. predictify-hybrid |
59 | | -A hybrid prediction market contract that integrates with real oracles (notably the Reflector Oracle) and supports community voting for market resolution. This contract is suitable for real-world prediction markets on Stellar. |
60 | | - |
61 | | -**Key Features:** |
62 | | -- Real-time price feeds from the Reflector oracle contract |
63 | | -- Hybrid resolution: combines oracle data with community voting |
64 | | -- Multiple oracle support (Reflector, Pyth, and more) |
65 | | -- Dispute and staking system |
66 | | -- Fee structure (2% platform fee + creation fee) |
67 | | -- Security: authentication, authorization, input validation, and reentrancy protection |
68 | | - |
69 | | -**Main Functions:** |
70 | | -- `initialize(admin: Address)` |
71 | | -- `create_reflector_market(...)` and `create_reflector_asset_market(...)` |
72 | | -- `create_pyth_market(...)` |
73 | | -- `fetch_oracle_result(market_id, oracle_contract)` |
74 | | -- `vote(user, market_id, outcome, stake)` |
75 | | -- `resolve_market(market_id)` |
76 | | -- `claim_winnings(user, market_id)` |
77 | | - |
78 | | -**Example Usage:** |
79 | | -```javascript |
80 | | -// Create a BTC price prediction market using Reflector oracle |
81 | | -const marketId = await predictifyClient.create_reflector_market( |
82 | | - adminAddress, |
83 | | - "Will BTC price be above $50,000 by December 31, 2024?", |
84 | | - ["yes", "no"], |
85 | | - 30, // days |
86 | | - "BTC", |
87 | | - 5000000, // $50,000 in cents |
88 | | - "gt" |
89 | | -); |
90 | | - |
91 | | -// Users vote |
92 | | -await predictifyClient.vote(userAddress, marketId, "yes", 1000000000); // 100 XLM stake |
93 | | - |
94 | | -// Fetch oracle result and resolve |
95 | | -const oracleResult = await predictifyClient.fetch_oracle_result(marketId, REFLECTOR_CONTRACT); |
96 | | -const finalResult = await predictifyClient.resolve_market(marketId); |
| 44 | +## ⚙️ Configuration for Mainnet |
| 45 | + |
| 46 | +Add Stellar mainnet config: |
| 47 | +```bash |
| 48 | +soroban config network add mainnet \ |
| 49 | + --rpc-url https://rpc.mainnet.stellar.org:443 \ |
| 50 | + --network-passphrase "Public Global Stellar Network ; September 2015" |
| 51 | +``` |
| 52 | + |
| 53 | +Create a `.env.mainnet` file: |
| 54 | +```env |
| 55 | +NETWORK=mainnet |
| 56 | +DEPLOYER_SECRET_KEY="SB..." |
| 57 | +ADMIN_ADDRESS="GB..." |
| 58 | +ORACLE_CONTRACT="..." |
97 | 59 | ``` |
98 | 60 |
|
99 | | -**Build & Test:** |
| 61 | +--- |
| 62 | + |
| 63 | +## 🚀 Deployment Instructions |
| 64 | + |
| 65 | +### Build Contracts |
100 | 66 | ```bash |
101 | 67 | cd contracts/predictify-hybrid |
102 | | -make build # Build the contract |
103 | | -make test # Run tests |
| 68 | +make build |
104 | 69 | ``` |
105 | 70 |
|
106 | | -**Deployment:** |
| 71 | +### Deploy to Mainnet |
107 | 72 | ```bash |
108 | | -cargo build --target wasm32-unknown-unknown --release |
109 | | -soroban contract deploy --wasm target/wasm32-unknown-unknown/release/predictify_hybrid.wasm |
110 | | -soroban contract invoke --id <contract_id> -- initialize --admin <admin_address> |
| 73 | +soroban contract deploy \ |
| 74 | + --wasm target/wasm32-unknown-unknown/release/predictify_hybrid.wasm \ |
| 75 | + --network $NETWORK \ |
| 76 | + --source $DEPLOYER_SECRET_KEY |
111 | 77 | ``` |
112 | 78 |
|
113 | | -**Troubleshooting:** |
114 | | -- Ensure the Reflector oracle contract is accessible and the asset symbol is supported. |
115 | | -- Check network connectivity to the Stellar network. |
116 | | -- Review contract logs for oracle call errors. |
| 79 | +### Initialize Contract |
| 80 | +```bash |
| 81 | +soroban contract invoke \ |
| 82 | + --id <contract_id> \ |
| 83 | + --fn initialize \ |
| 84 | + --network $NETWORK \ |
| 85 | + --source $DEPLOYER_SECRET_KEY \ |
| 86 | + --arg admin=$ADMIN_ADDRESS |
| 87 | +``` |
| 88 | + |
| 89 | +Record and store the contract ID securely. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## 🔮 Oracle Setup |
| 94 | + |
| 95 | +### Oracle Options |
| 96 | +- Primary support: Reflector Oracle |
| 97 | +- Others: Pyth or custom signed payloads |
| 98 | + |
| 99 | +### Setup Steps |
| 100 | +1. Deploy the oracle contract (if required). |
| 101 | +2. Ensure oracle contract ID is stored in the main contract via admin call. |
| 102 | +3. Off-chain oracle should: |
| 103 | + - Sign market outcomes |
| 104 | + - Submit results via `fetch_oracle_result()` or similar entrypoints |
| 105 | + |
| 106 | +Oracle JSON Payload Example: |
| 107 | +```json |
| 108 | +{ |
| 109 | + "market_id": "001", |
| 110 | + "result": "yes", |
| 111 | + "timestamp": "2025-07-04T12:00:00Z" |
| 112 | +} |
| 113 | +``` |
117 | 114 |
|
118 | 115 | --- |
119 | 116 |
|
120 | | -## Workspace Build & Test |
| 117 | +## 🧪 Testing Deployment |
121 | 118 |
|
122 | | -From the project root, you can build and test all contracts: |
| 119 | +### Unit and Integration Tests |
| 120 | +```bash |
| 121 | +make test |
| 122 | +``` |
123 | 123 |
|
| 124 | +### Dry-Run on Futurenet |
124 | 125 | ```bash |
125 | | -cargo build --workspace |
126 | | -cargo test --workspace |
| 126 | +soroban config network use futurenet |
| 127 | +soroban contract deploy ... |
127 | 128 | ``` |
128 | 129 |
|
| 130 | +### Post-Mainnet Checks |
| 131 | +- Use `soroban contract inspect` to verify deployment |
| 132 | +- Validate end-to-end market creation, voting, oracle submission, and claiming |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## 📊 Monitoring and Alerts |
| 137 | + |
| 138 | +### Tools: |
| 139 | +- [Stellar Expert](https://stellar.expert/explorer/public) |
| 140 | +- Custom CLI scripts to watch tx status |
| 141 | +- Error tracking via logs + alerting via Slack/Discord/Webhooks |
| 142 | + |
| 143 | +### Metrics to Monitor: |
| 144 | +- Oracle submission frequency and failures |
| 145 | +- Market volume anomalies |
| 146 | +- Dispute activations and unresolved markets |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## 🔐 Security Checklist |
| 151 | + |
| 152 | +### ✅ Account Security |
| 153 | +- [ ] Admin/deployer keys stored in hardware wallets or secure key vaults |
| 154 | +- [ ] Avoid deploying from hot wallets or CLI-stored keys |
| 155 | +- [ ] Multisig setup for critical contract ownership (if supported) |
| 156 | + |
| 157 | +### ✅ Smart Contract Safeguards |
| 158 | +- [ ] All admin functions require `require_auth(admin)` |
| 159 | +- [ ] Oracle IDs must be validated against allowlist |
| 160 | +- [ ] Reentrancy protected via Soroban execution model |
| 161 | +- [ ] Input sanitization for all string, numeric, and enum arguments |
| 162 | +- [ ] Dispute logic isolated from oracle resolution path |
| 163 | +- [ ] `initialize()` callable once only; enforce init guard |
| 164 | + |
| 165 | +### ✅ Network and Deployment |
| 166 | +- [ ] Contract ID recorded and versioned |
| 167 | +- [ ] Use Soroban’s `--network` config to prevent misdeployments |
| 168 | +- [ ] Securely store and manage all `.env` files |
| 169 | +- [ ] Validate deployed WASM checksum matches build artifact |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## 🔁 Rollback Procedures |
| 174 | +- Use pausable logic if available (e.g., freeze all markets via admin call) |
| 175 | +- Deploy new contract instance if bug is unpatchable |
| 176 | +- Migrate state via admin oracles (if implemented) |
| 177 | +- Revoke oracle privileges for breached sources |
| 178 | + |
129 | 179 | --- |
130 | 180 |
|
131 | | -## Resources |
132 | | -- [Soroban Documentation](https://developers.stellar.org/docs/build/smart-contracts/overview) |
133 | | -- [Soroban Examples](https://github.com/stellar/soroban-examples) |
134 | | -- [Reflector Oracle](https://github.com/reflector-labs/reflector-oracle) |
| 181 | +## 🛠️ Maintenance Procedures |
| 182 | +- Monitor oracle reliability and submission cadence |
| 183 | +- Add/remove oracles via controlled admin processes |
| 184 | +- Periodically test and patch contracts via redeployments |
| 185 | +- Log usage metrics for governance and market integrity |
| 186 | +- Respond to disputes in <48 hours using automated + manual review |
135 | 187 |
|
136 | 188 | --- |
137 | 189 |
|
| 190 | +## 📎 Suggested Enhancements |
| 191 | +- GitHub Actions for CI + testnet deploy |
| 192 | +- Soroban integration test suite with mocked oracles |
| 193 | +- Publish deployed contract IDs in README |
| 194 | +- Oracle dashboard or visual monitor tool (Grafana, etc.) |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +For deployment support or technical questions, please open an issue or contact the Predictify core team. |
| 199 | + |
138 | 200 | ## License |
139 | 201 | This project is open source and available under the MIT License. |
| 202 | + |
0 commit comments