Production-ready Stellar Soroban smart contracts suite for regenerative finance: automated fund distribution and validated participant management.
Vault Distributor on Testnet: CC4XEZG3JIVNTWGNPL4YKIWYECSOTS66SFLIDI3WU6RIJFNDNWPIMVHM
This repository contains two complementary smart contracts:
π¦ Vault Distributor
Simple parameter-based distribution contract for equitable fund allocation.
- β Parameter-based: Recipients provided at distribution time
- πΈ Equitable Division: Automatic calculation of equal amounts
- π Lightweight: ~15KB WASM, 19 tests
- π Admin-controlled: Secure authorization
- Use cases: Payroll, airdrops, rewards, grant distribution
πͺ Event Distributor
Advanced contract with on-chain storage for validated participants and event management.
- π On-chain Storage: Persistent participant data with IPFS metadata
- β Validation System: Admin-controlled participant validation
- π― Event Management: Create events with participant lists
- π Smart Filtering: Automatic distribution to validated participants only
- π Pagination: Query large participant lists efficiently
- π§ͺ Tested: 23 comprehensive tests
- Use cases: ReFi events, validated communities, curated distributions
- Contracts
- Overview
- Architecture
- Frontend Integration
- Quick Start
- Testing
- Deployment
- Documentation
- Project Status
- License
New! Complete integration guide for frontend developers:
π FRONTEND_README.md - Quick start (3 steps)
π docs/FRONTEND_INTEGRATION.md - Complete guide with code
TL;DR: Frontend sends imagen Base64 + direcciΓ³n pΓΊblica β Contract stores on Stellar + IPFS
ReFi Universe is a suite of smart contracts built with Rust and Stellar's Soroban SDK for regenerative finance applications. The contracts enable secure, equitable distribution of tokens with different levels of participant management.
Both contracts implement enterprise-grade patterns:
- SOLID Principles for maintainable architecture
- Repository Pattern for data persistence
- Event-Driven design for auditability
- Comprehensive Validation for security
- 100% Test Coverage for reliability
| Feature | Vault Distributor | Event Distributor |
|---|---|---|
| Storage | Stateless | On-chain participants & events |
| Recipients | Provided at call time | Filtered from stored data |
| Validation | Off-chain | On-chain validation status |
| Use Case | Simple distributions | Event-based with curation |
| WASM Size | ~15KB | ~15KB |
| Tests | 19 | 23 |
- π Admin-Only Operations: All critical operations require authentication
- β Input Validation: Comprehensive parameter checks
- π‘οΈ Overflow Protection: Safe arithmetic with
checked_div() - πΈ Equitable Distribution: Automatic equal amount calculation
- π Event Emission: Full auditability through events
- β‘ Optimized: Small WASM footprint
- π Participant Registry: On-chain storage with IPFS metadata
- β Validation System: Admin-controlled participant approval
- π― Event Management: Create events with participant lists
- π Smart Filtering: Only validated participants receive funds
- π Pagination: Efficient querying of large datasets
graph TB
subgraph "ReFi Universe"
VD[Vault Distributor<br/>Parameter-based]
ED[Event Distributor<br/>Storage-based]
end
subgraph "External Systems"
A[Admin Wallet]
T[Token Contracts<br/>XLM, USDC, etc.]
IPFS[IPFS Network<br/>Metadata Storage]
end
subgraph "Recipients"
R1[Recipient 1]
R2[Recipient 2]
R3[Recipient N]
end
A -->|Manage| VD
A -->|Manage + Validate| ED
VD -->|Transfer| T
ED -->|Transfer| T
ED -.->|Metadata| IPFS
T -->|Distribute| R1
T -->|Distribute| R2
T -->|Distribute| R3
style VD fill:#7D00FF,color:#fff
style ED fill:#FF6B6B,color:#fff
style A fill:#4ECDC4,color:#fff
style T fill:#45B7D1,color:#fff
style IPFS fill:#96CEB4,color:#fff
graph TB
subgraph "Vault Distributor Modules"
L[lib.rs<br/>Entry Point]
A[auth.rs<br/>Admin Auth]
V[validation.rs<br/>Input Checks]
T[token_operations.rs<br/>Transfers]
S[storage.rs<br/>Admin Data]
E[events.rs<br/>Auditability]
R[errors.rs<br/>Error Types]
end
L --> A
L --> V
L --> T
A --> S
L --> E
style L fill:#7D00FF,color:#fff
style A fill:#FF6B6B,color:#fff
style V fill:#4ECDC4,color:#fff
style T fill:#45B7D1,color:#fff
style S fill:#96CEB4,color:#fff
graph TB
subgraph "Event Distributor Modules"
L2[lib.rs<br/>Entry Point<br/>15+ Functions]
M[models.rs<br/>Human + Event]
S2[storage.rs<br/>Repository Pattern<br/>Indexed Storage]
E2[events.rs<br/>7 Event Types]
R2[errors.rs<br/>12 Error Types]
T2[test.rs<br/>23 Unit Tests]
end
L2 --> M
L2 --> S2
L2 --> E2
M --> S2
style L2 fill:#FF6B6B,color:#fff
style M fill:#7D00FF,color:#fff
style S2 fill:#4ECDC4,color:#fff
style E2 fill:#96CEB4,color:#fff
sequenceDiagram
participant Admin
participant Contract
participant Storage
participant Validation
participant Token
participant Recipients
Admin->>Contract: init(admin_address)
Contract->>Storage: set_admin(admin_address)
Storage-->>Contract: β Admin stored
Contract->>Admin: β AdminSetEvent
Admin->>Contract: distribute(token, recipients, amount)
Contract->>Contract: require_admin()
Contract->>Storage: get_admin()
Storage-->>Contract: admin_address
Contract->>Contract: verify authorization
Contract->>Validation: validate_recipients(recipients)
Validation-->>Contract: β Valid
Contract->>Validation: validate_amount(amount)
Validation-->>Contract: β Valid
Contract->>Validation: calculate_amount_per_recipient(amount, count)
Validation-->>Contract: amount_per_recipient
loop For each recipient
Contract->>Token: transfer(from_contract, to_recipient, amount)
Token-->>Recipients: Transfer XLM
end
Contract->>Admin: β DistributionEvent(total, count)
graph LR
subgraph "Presentation Layer"
LIB[lib.rs<br/>Contract Interface]
end
subgraph "Business Logic Layer"
AUTH[auth.rs<br/>Authentication]
VAL[validation.rs<br/>Business Rules]
end
subgraph "Service Layer"
TOK[token_operations.rs<br/>Token Transfers]
end
subgraph "Data Layer"
STOR[storage.rs<br/>Persistence]
end
subgraph "Cross-Cutting Concerns"
EVT[events.rs<br/>Logging]
ERR[errors.rs<br/>Error Handling]
end
LIB --> AUTH
LIB --> VAL
LIB --> TOK
AUTH --> STOR
VAL --> ERR
TOK --> ERR
LIB --> EVT
style LIB fill:#7D00FF,color:#fff
style AUTH fill:#FF6B6B,color:#fff
style VAL fill:#4ECDC4,color:#fff
style TOK fill:#45B7D1,color:#fff
style STOR fill:#96CEB4,color:#fff
style EVT fill:#FFEAA7,color:#333
style ERR fill:#DFE6E9,color:#333
# Clone the repository
git clone https://github.com/refiup/sc.git
cd sc
# Install Rust target
rustup target add wasm32-unknown-unknowncd contracts/vault-distributor
# Run tests (19 tests)
cargo test
# Build WASM
cargo build --target wasm32-unknown-unknown --releasecd contracts/event-distributor
# Run tests (23 tests)
cargo test
# Build WASM
cargo build --target wasm32-unknown-unknown --release# From repository root
cargo test --all
# Expected: 42/42 tests passing// Initialize
client.init(&admin);
// Distribute 100 XLM to 3 recipients (33.33 XLM each)
let recipients = vec![&env, recipient1, recipient2, recipient3];
client.distribute(&token, &recipients, &1000000000);// Initialize
client.init(&admin);
// Add participants
client.add_human(&human1, &String::from_str(&env, "QmHash1"));
client.add_human(&human2, &String::from_str(&env, "QmHash2"));
// Validate some participants
client.update_human_validation(&human1, &true);
// Create event
client.create_event(
&String::from_str(&env, "event_001"),
&String::from_str(&env, "Buenos Aires"),
&1000000000
);
// Add participants to event
client.add_human_to_event(&String::from_str(&env, "event_001"), &human1);
client.add_human_to_event(&String::from_str(&env, "event_001"), &human2);
// Distribute only to validated participants (human1 only)
client.distribute_event_pool(&String::from_str(&env, "event_001"), &token);For complete API documentation:
Parameters:
token: Token contract address (e.g., XLM native token)recipients: Vector of recipient addressestotal_amount: Total amount to distribute (in stroops for XLM)
Emits: DistributionEvent
Errors:
Unauthorized(3): Caller is not adminEmptyRecipients(4): Recipients list is emptyInvalidAmount(5): Amount is zero or negativeZeroAmountPerRecipient(6): Amount too small for distributionMathError(7): Arithmetic overflow
Calculation:
amount_per_recipient = total_amount / recipients.len()# Run all tests (both contracts)
cargo test --all
# Test individual contracts
cd contracts/vault-distributor && cargo test # 19 tests
cd contracts/event-distributor && cargo test # 23 testsCoverage:
- Initialization (2 tests)
- Distribution logic (6 tests)
- Authorization (4 tests)
- Amount calculations (7 tests)
Key Scenarios:
- β Equitable distribution with remainders
- β Large recipient lists (100+)
- β Maximum amount handling (i128::MAX)
- β Zero/negative amount rejection
- β Unauthorized access prevention
Coverage:
- Initialization (3 tests)
- Human management (7 tests)
- Event management (7 tests)
- Distribution with validation (6 tests)
Key Scenarios:
- β On-chain participant storage with IPFS
- β Validation status management
- β Event creation with participant lists
- β Filtering validated participants
- β Pagination for large datasets
- β Distribution to validated humans only
See docs/TESTING.md for detailed test reports.
# Use automated deployment script
./deploy.sh
# Or manual deployment
cd contracts/vault-distributor
cargo build --target wasm32v1-none --release
stellar contract deploy \
--wasm target/wasm32v1-none/release/vault_distributor.wasm \
--source admin \
--network testnet# Deploy to mainnet (after audit)
stellar contract deploy \
--wasm target/wasm32v1-none/release/vault_distributor.wasm \
--source admin \
--network mainnetSee docs/DEPLOYMENT.md for complete deployment guide.
Comprehensive documentation available in the docs/ directory:
| Document | Description |
|---|---|
| ARCHITECTURE.md | SOLID principles, design patterns, and module documentation |
| DEPLOYMENT.md | Step-by-step deployment guide for testnet and mainnet |
| INTEGRATION.md | Frontend integration guide with React + Freighter examples |
| TESTING.md | Complete test coverage report with all 19 tests documented |
| CHANGELOG.md | Version history and release notes |
| BACKLOG.md | Use cases and requirements tracking (11/11 complete) |
| COMPLETION.md | Project completion summary and metrics |
| SUBMISSION.md | EthGlobal BA 2025 submission checklist |
β Production Ready for Testnet
| Metric | Vault Distributor | Event Distributor | Total |
|---|---|---|---|
| Code Lines | ~1,300 | ~1,500 | ~2,800 |
| Modules | 7 | 6 | 13 |
| Tests | 19 | 23 | 42 |
| Test Pass Rate | 100% | 100% | 100% |
| WASM Size | ~15KB | ~15KB | ~30KB |
| Functions | 3 | 11 | 14 |
| Errors | 5 | 12 | 17 |
| Events | 2 | 7 | 9 |
Network: Stellar Testnet
Contract ID: CC4XEZG3JIVNTWGNPL4YKIWYECSOTS66SFLIDI3WU6RIJFNDNWPIMVHM
Explorer: View on Stellar Expert
Status: β
Active & Tested
Transactions: 197+ XLM distributed
Network: Stellar Testnet
Contract ID: CCHFGFX3S52UX46HZEBEGW5N2LDDYMSJDLZF4CQOZ6TSWWKFEG4TFPLS
Explorer: View on Stellar Expert
Status: β
Deployed & Initialized
Tests: 23/23 passing
Language: Rust 1.91.1
Framework: Soroban SDK v23
Blockchain: Stellar (Soroban)
Target: WebAssembly (wasm32-unknown-unknown)
Tools:
- Stellar CLI v23.2.1
- Cargo (Rust package manager)
- Git (version control)
Storage: Persistent on-chain (Event Distributor)
Testing: Native Rust tests (cargo test)
Documentation: 8 comprehensive markdown filesThis project is licensed under the MIT License - see the LICENSE file for details.
Project: ReFi Universe - Smart Contracts Suite
Event: EthGlobal Buenos Aires 2025
Category: Regenerative Finance (ReFi)
Blockchain: Stellar (Soroban)
- Vault Distributor - Simple parameter-based distribution
- Event Distributor - Advanced validated participant management
Organization: RefiUp
Repository: github.com/refiup/sc
- Stellar Development Foundation for the Soroban platform
- Rust Community for excellent tooling
- EthGlobal for organizing the hackathon
- Repository: github.com/refiup/sc
- Vault Distributor Explorer: Stellar Expert
- Stellar Docs: developers.stellar.org
- Soroban SDK: docs.rs/soroban-sdk
Built with β€οΈ for the Stellar ecosystem