Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 125 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,139 @@
# Soroban Project

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.

---

## Project Structure

This repository uses the recommended structure for a Soroban project:
```text
.
β”œβ”€β”€ contracts
β”‚Β Β  └── hello_world
β”‚Β Β  β”œβ”€β”€ hello-world
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ src
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib.rs
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── test.rs
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Cargo.toml
β”‚Β Β  β”‚Β Β  └── Makefile
β”‚Β Β  └── predictify-hybrid
β”‚Β Β  β”œβ”€β”€ src
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib.rs
β”‚Β Β  β”‚Β Β  └── test.rs
β”‚Β Β  └── Cargo.toml
β”‚Β Β  β”œβ”€β”€ Cargo.toml
β”‚Β Β  β”œβ”€β”€ Makefile
β”‚Β Β  └── README.md
β”œβ”€β”€ Cargo.toml
└── README.md
```

- New Soroban contracts can be put in `contracts`, each in their own directory. There is already a `hello_world` contract in there to get you started.
- If you initialized this project with any other example contracts via `--with-example`, those contracts will be in the `contracts` directory as well.
- Contracts should have their own `Cargo.toml` files that rely on the top-level `Cargo.toml` workspace for their dependencies.
- Frontend libraries can be added to the top-level directory as well. If you initialized this project with a frontend template via `--frontend-template` you will have those files already included.
- New Soroban contracts can be added in the `contracts` directory, each in their own subdirectory with its own `Cargo.toml`.
- All contracts share dependencies via the top-level workspace `Cargo.toml`.

---

## Contracts Overview

### 1. hello-world
A minimal example contract for Soroban, demonstrating basic contract structure and testing.

**Functionality:**
- Exposes a single function `hello(to: String) -> Vec<String>` that returns a greeting message.
- Includes a simple test in `test.rs`.

**Example:**
```rust
let words = client.hello(&String::from_str(&env, "Dev"));
// Returns: ["Hello", "Dev"]
```

**Build & Test:**
```bash
cd contracts/hello-world
make build # Build the contract
make test # Run tests
```

---

### 2. predictify-hybrid
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.

**Key Features:**
- Real-time price feeds from the Reflector oracle contract
- Hybrid resolution: combines oracle data with community voting
- Multiple oracle support (Reflector, Pyth, and more)
- Dispute and staking system
- Fee structure (2% platform fee + creation fee)
- Security: authentication, authorization, input validation, and reentrancy protection

**Main Functions:**
- `initialize(admin: Address)`
- `create_reflector_market(...)` and `create_reflector_asset_market(...)`
- `create_pyth_market(...)`
- `fetch_oracle_result(market_id, oracle_contract)`
- `vote(user, market_id, outcome, stake)`
- `resolve_market(market_id)`
- `claim_winnings(user, market_id)`

**Example Usage:**
```javascript
// Create a BTC price prediction market using Reflector oracle
const marketId = await predictifyClient.create_reflector_market(
adminAddress,
"Will BTC price be above $50,000 by December 31, 2024?",
["yes", "no"],
30, // days
"BTC",
5000000, // $50,000 in cents
"gt"
);

// Users vote
await predictifyClient.vote(userAddress, marketId, "yes", 1000000000); // 100 XLM stake

// Fetch oracle result and resolve
const oracleResult = await predictifyClient.fetch_oracle_result(marketId, REFLECTOR_CONTRACT);
const finalResult = await predictifyClient.resolve_market(marketId);
```

**Build & Test:**
```bash
cd contracts/predictify-hybrid
make build # Build the contract
make test # Run tests
```

**Deployment:**
```bash
cargo build --target wasm32-unknown-unknown --release
soroban contract deploy --wasm target/wasm32-unknown-unknown/release/predictify_hybrid.wasm
soroban contract invoke --id <contract_id> -- initialize --admin <admin_address>
```

**Troubleshooting:**
- Ensure the Reflector oracle contract is accessible and the asset symbol is supported.
- Check network connectivity to the Stellar network.
- Review contract logs for oracle call errors.

---

## Workspace Build & Test

From the project root, you can build and test all contracts:

```bash
cargo build --workspace
cargo test --workspace
```

---

## Resources
- [Soroban Documentation](https://developers.stellar.org/docs/build/smart-contracts/overview)
- [Soroban Examples](https://github.com/stellar/soroban-examples)
- [Reflector Oracle](https://github.com/reflector-labs/reflector-oracle)

---

## License
This project is open source and available under the MIT License.
Loading