Skip to content
Merged
Show file tree
Hide file tree
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
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: FundStar CI

on:
push:
branches: [ main, master, level-belt-3.0, level-belt-4.0 ]
pull_request:
branches: [ main, master ]

jobs:
test-contracts:
name: Test Smart Contracts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32v1-none

- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install Stellar CLI
uses: stellar/stellar-cli@v23.3.0

- name: Build Reward Token (Dependency)
run: stellar contract build --package reward_token

- name: Run Contract Tests
run: cargo test

build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: Install Dependencies
run: |
cd frontend
npm install

- name: Build Next.js
run: |
cd frontend
npm run build
env:
NEXT_PUBLIC_SOROBAN_RPC_URL: "https://soroban-testnet.stellar.org"
NEXT_PUBLIC_FUNDSTAR_CONTRACT_ID: ${{ secrets.NEXT_PUBLIC_FUNDSTAR_CONTRACT_ID }}
NEXT_PUBLIC_REWARD_TOKEN_ID: ${{ secrets.NEXT_PUBLIC_REWARD_TOKEN_ID }}
NEXT_PUBLIC_TOKEN_CONTRACT_ID: ${{ secrets.NEXT_PUBLIC_TOKEN_CONTRACT_ID }}
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ FundStar has been upgraded to meet the high standards of the Level 3 (Orange Bel
### 🎥 Demo Video
[Watch the 1-minute demo video](https://www.loom.com/share/695d03e93cc743b8b52e1d4bb752740c)

### 🧪 Test Output (14 Passing)
### 🧪 Test Output (15 Passing)
FundStar uses a robust testing suite in Rust to ensure the safety of all crowdfunding operations.

```bash
running 14 tests
running 15 tests
test tests::test_create_campaign_current_time_deadline ... ok
test tests::test_create_campaign_invalid_goal_zero ... ok
test tests::test_get_campaign_count_empty ... ok
Expand All @@ -237,10 +237,37 @@ test tests::test_multiple_campaigns_sequential_ids ... ok
test tests::test_fund_campaign_success ... ok
test tests::test_withdraw_fails_if_goal_not_reached ... ok
test tests::test_withdraw_funds_success ... ok
test tests::test_reward_minting_on_funding ... ok

test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s
test result: ok. 15 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.12s
```

## 🟢 Level 4 - Green Belt Submission

FundStar has been upgraded with advanced inter-contract patterns and production-ready CI/CD infrastructure.

[![FundStar CI](https://github.com/Kingscliq/fundstar/actions/workflows/ci.yml/badge.svg)](https://github.com/Kingscliq/fundstar/actions/workflows/ci.yml)

### ✅ Level 4 Requirements
- [x] **Inter-contract call working**: FundStar now mints STAR tokens via the Reward Token contract.
- [x] **Custom token deployed**: The `STAR` Loyalty Token (SAC interface) is live.
- [x] **CI/CD running**: GitHub Actions pipeline active for automated testing and builds.
- [x] **Mobile responsive**: UI fully optimized for mobile devices.
- [x] **Advanced event streaming**: Real-time contribution tracking via on-chain event indexing.

### ⛓️ Advanced Contract Details
- **Main Contract:** `CAOAJBZA5JI5QSF3LY2QCVGHDIFQW5PQ7KBIE2JPUY6NBVWZYHDW4VCQ`
- **Reward Token (STAR):** `ADD_TOKEN_ADDRESS_HERE`
- **Inter-Contract Minting TX:** `ADD_TX_HASH_HERE`

### 📱 Mobile UI Proof
![Mobile Responsive View](./screenshots/mobile-responsive.png)

### 🚀 Key Features (Level 4)
- **Loyalty Reward System**: Automated inter-contract minting of STAR tokens for every backer.
- **Automated QA**: Every push is verified by GitHub Actions (Rust tests + Next.js build).
- **Production Persistence**: Persistent session caching and optimized mobile layout.

## Security Notes

1. Commit scripts (`scripts/contract.sh`, `scripts/invoke.sh`)
Expand Down
69 changes: 69 additions & 0 deletions Recommendations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 🚀 Production Readiness & Security Roadmap

This document outlines the "Senior-level" improvements required to transition FundStar from a functional prototype to a mainnet-ready financial ecosystem. These are structured as GitHub-ready issues.

---

## 🔒 Security & Access Control

### Issue #1: Protect Initialization from Front-Running
- **Problem**: The `init` functions are public and callable by anyone. A bot could see the contract deployment and call `init` before the deployer, seizing admin control.
- **Solution**: Implement a "Deployer Pattern" where the contract is initialized in the same transaction as deployment, or check that the caller is the contract's official creator.
- **Impact**: **Critical**. Prevents hostile takeovers of the contract.

### Issue #2: Implement an Emergency "Circuit Breaker"
- **Problem**: If an exploit is discovered in the funding or withdrawal logic, there is currently no way to stop transactions.
- **Solution**: Add a `is_paused` state variable and a `toggle_pause` function (Admin only). Ensure `fund_campaign` and `withdraw_funds` check this flag.
- **Impact**: **High**. Essential for damage control during a security incident.

---

## 🏗️ State & Lifecycle Management

### 3. Campaign Management & Investor Protection
While the current system allows for creation and funding, a production-grade DApp requires a graceful "exit" strategy for failed or disputed campaigns.

* **Campaign Cancellation**: Implement a `cancel_campaign` function restricted to the creator. This should change the campaign state to `Cancelled`, preventing further funding.
* **On-Chain Refund System**: If a campaign is cancelled or fails to hit its goal by the deadline, a `claim_refund` function should be available. This is more complex than it sounds, as it requires tracking individual contributions in a `Map` or `Persistent` storage to ensure each user gets back exactly what they sent.
* **Admin Circuit Breaker**: For extreme cases (security issues), a contract admin should have the power to pause all funding and withdrawals globally.

### 4. Storage & Performance (Version 2)
As the number of campaigns grows, the current `get_all_campaigns` loop will become expensive in terms of gas (XLM).

### Issue #3: Automated Rent Bumping (Storage Persistence)
- **Problem**: Soroban data has an expiration. If a campaign is long-lived and nobody interacts with it, its data will be archived, breaking the contract.
- **Solution**: Integrate `env.storage().persistent().extend_ttl()` inside the `fund_campaign` function to automatically extend the campaign's life every time it is interacted with.
- **Impact**: **High**. Ensures long-term data availability.

### Issue #4: Contract Upgradeability (WASM Hash Update)
- **Problem**: The contract address is currently tied to a specific version of the code. Bug fixes require a new address, which orphans existing data.
- **Solution**: Implement the `upgrade` function pattern. Allow an authorized admin to update the WASM code hash of the contract without changing the Contract ID.
- **Impact**: **Medium**. Allows for maintenance and bug fixes post-deployment.

---

## ⚖️ Governance & Logic

### Issue #5: Decentralized Admin (Multisig)
- **Problem**: A single private key controls the entire ecosystem. If that key is lost or stolen, the project is dead.
- **Solution**: Transition the `admin` address to a Stellar **Multisig** account or a simple DAO contract.
- **Impact**: **Medium**. Removes the "Single Point of Failure."

### Issue #6: Price Oracle Integration for Rewards
- **Problem**: The 10% reward is currently fixed. If the value of STAR vs XLM fluctuates wildly, the reward might become economically unsustainable.
- **Solution**: Integrate a price oracle (e.g., Pyth or Switchboard) to calculate the `reward_amount` based on real-time market value.
- **Impact**: **Low**. Improves the economic stability of the token.

---

## 📊 Observability & Performance

### Issue #7: Detailed Event Indexing
- **Problem**: Current events are basic. It's hard for external indexers to build a full history of the project.
- **Solution**: Expand events to include `campaign_updated`, `admin_changed`, and `reward_minted` with indexed topics for easier tracking by tools like Mercury or StellarExpert.
- **Impact**: **Medium**. Improves frontend transparency and data discoverability.

### Issue #8: Off-Chain Indexing & Data Caching (Indexer Pattern)
- **Problem**: Querying the blockchain directly for large lists of campaigns is slow and gas-inefficient as the project scales. The frontend "wait time" increases with every new campaign.
- **Solution**: Implement an **Indexer** (using tools like **Mercury** or a custom Node.js service). The indexer listens for `campaign_created` and `fund_received` events and syncs them to a traditional database (e.g., PostgreSQL or Supabase). The frontend then queries this DB for lightning-fast list views.
- **Impact**: **High**. Drastically improves User Experience (UX) and reduces unnecessary load on the Stellar RPC.
Loading
Loading