Stellar Soroban smart contracts for the RemitWise remittance platform.
This workspace contains the core smart contracts that power RemitWise's post-remittance financial planning features:
- remittance_split: Automatically splits remittances into spending, savings, bills, and insurance
- savings_goals: Goal-based savings with target dates and locked funds
- bill_payments: Automated bill payment tracking and scheduling
- insurance: Micro-insurance policy management and premium payments
- Rust (latest stable version)
- Stellar CLI (soroban-cli)
- Cargo
# Install Soroban CLI
cargo install --locked --version 21.0.0 soroban-cli
# Build all contracts
cargo build --release --target wasm32-unknown-unknownHandles automatic allocation of remittance funds into different categories.
Key Functions:
initialize_split: Set percentage allocation (spending, savings, bills, insurance)get_split: Get current split configurationcalculate_split: Calculate actual amounts from total remittance
Events:
SplitInitializedEvent: Emitted when split configuration is initializedspending_percent,savings_percent,bills_percent,insurance_percent,timestamp
SplitCalculatedEvent: Emitted when split amounts are calculatedtotal_amount,spending_amount,savings_amount,bills_amount,insurance_amount,timestamp
Manages goal-based savings with target dates.
Key Functions:
create_goal: Create a new savings goal (education, medical, etc.)add_to_goal: Add funds to a goalget_goal: Get goal detailsis_goal_completed: Check if goal target is reachedarchive_completed_goals: Archive completed goals to reduce storageget_archived_goals: Query archived goalsrestore_goal: Restore archived goal to active storagecleanup_old_archives: Permanently delete old archivesget_storage_stats: Get storage usage statistics
Events:
GoalCreatedEvent: Emitted when a new savings goal is createdgoal_id,name,target_amount,target_date,timestamp
FundsAddedEvent: Emitted when funds are added to a goalgoal_id,amount,new_total,timestamp
GoalCompletedEvent: Emitted when a goal reaches its target amountgoal_id,name,final_amount,timestamp
Tracks and manages bill payments with recurring support.
Key Functions:
create_bill: Create a new bill (electricity, school fees, etc.)pay_bill: Mark a bill as paid and create next recurring bill if applicableget_unpaid_bills: Get all unpaid billsget_total_unpaid: Get total amount of unpaid billsarchive_paid_bills: Archive paid bills to reduce storageget_archived_bills: Query archived billsrestore_bill: Restore archived bill to active storagebulk_cleanup_bills: Permanently delete old archivesget_storage_stats: Get storage usage statistics
Events:
BillCreatedEvent: Emitted when a new bill is createdbill_id,name,amount,due_date,recurring,timestamp
BillPaidEvent: Emitted when a bill is marked as paidbill_id,name,amount,timestamp
RecurringBillCreatedEvent: Emitted when a recurring bill generates the next billbill_id,parent_bill_id,name,amount,due_date,timestamp
Manages micro-insurance policies and premium payments.
Key Functions:
create_policy: Create a new insurance policypay_premium: Pay monthly premiumget_active_policies: Get all active policiesget_total_monthly_premium: Calculate total monthly premium costdeactivate_policy: Deactivate an insurance policy
Events:
PolicyCreatedEvent: Emitted when a new insurance policy is createdpolicy_id,name,coverage_type,monthly_premium,coverage_amount,timestamp
PremiumPaidEvent: Emitted when a premium is paidpolicy_id,name,amount,next_payment_date,timestamp
PolicyDeactivatedEvent: Emitted when a policy is deactivatedpolicy_id,name,timestamp
All contracts emit events for important state changes, enabling real-time tracking and frontend integration. Events follow Soroban best practices and include:
- Relevant IDs: All events include the ID of the entity being acted upon
- Amounts: Financial events include transaction amounts
- Timestamps: All events include the ledger timestamp for accurate tracking
- Context Data: Additional contextual information (names, dates, etc.)
Each contract uses short symbol topics for efficient event identification:
- Remittance Split:
init,calc - Savings Goals:
created,added,completed - Bill Payments:
created,paid,recurring - Insurance:
created,paid,deactive
Events can be queried from the Stellar network using the Soroban SDK or via the Horizon API for frontend integration. Each event structure is exported and can be decoded using the contract's schema.
Run tests for all contracts:
cargo testRun tests for a specific contract:
cd remittance_split
cargo testcargo test -p remittance_splitexercises the USDC distribution logic with a mocked Stellar Asset Contract (env.register_stellar_asset_contract_v2) and built-in auth mocking.- The suite covers minting the payer account, splitting across spending/savings/bills/insurance, and asserting balances along with the new allocation metadata helper.
- The same command is intended for CI so it runs without manual setup; re-run locally whenever split logic changes or new USDC paths are added.
See docs/gas-optimization.md for methodology, before/after results, and assumptions.
Run the deterministic gas benchmarks:
RUST_TEST_THREADS=1 cargo test -p bill_payments --test gas_bench -- --nocapture
RUST_TEST_THREADS=1 cargo test -p savings_goals --test gas_bench -- --nocapture
RUST_TEST_THREADS=1 cargo test -p insurance --test gas_bench -- --nocapture
RUST_TEST_THREADS=1 cargo test -p family_wallet --test gas_bench -- --nocapture
RUST_TEST_THREADS=1 cargo test -p remittance_split --test gas_bench -- --nocaptureSee the Deployment Guide for comprehensive deployment instructions.
Quick deploy to testnet:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/remittance_split.wasm \
--source <your-key> \
--network testnetThis is a basic MVP implementation. Future enhancements:
- Integration with Stellar Asset Contract (USDC)
- Cross-contract calls for automated allocation
- Multi-signature support for family wallets
- Emergency mode with priority processing
MIT