Skip to content

nzubepolycap-hub/Kora-Contract

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Kora Protocol

On-chain Invoice Financing for African Trade Finance

License: MIT Built on Stellar Rust

Tokenize unpaid invoices. Unlock instant liquidity. Power African trade.


Overview

Kora is a decentralized invoice financing protocol built on Stellar Soroban. It enables small and medium enterprises (SMEs) β€” particularly across African markets β€” to tokenize their unpaid invoices as NFTs and sell them at a discount to liquidity providers, receiving immediate working capital without waiting 30–90 days for invoice settlement.

The protocol is designed for:

  • African trade finance infrastructure β€” addressing the $81B+ SME financing gap on the continent
  • Institutional DeFi β€” production-grade contract architecture with formal access control and risk scoring
  • Real-world asset (RWA) tokenization β€” invoices as on-chain NFTs with IPFS-backed metadata
  • Scalable fintech rails β€” modular contracts that can be extended for factoring, supply chain finance, and trade credit

How It Works

SME                    Marketplace              Investors
 β”‚                         β”‚                       β”‚
 │── mint_invoice() ──────►│                       β”‚
 β”‚                         │── list_invoice() ────►│
 β”‚                         β”‚                       │── fund_invoice()
 β”‚                         │◄──────────────────────│
 │◄── funds released ──────│                       β”‚
 β”‚                         β”‚                       β”‚
 │── repay() ─────────────►│                       β”‚
 β”‚                         │── distribute yield ──►│
  1. SME mints an invoice NFT β€” invoice metadata (amount, debtor, due date, IPFS CID) is stored on-chain. Sensitive debtor PII is hashed; full details live on IPFS.
  2. Invoice is listed on the marketplace β€” SME sets an asking price (discounted from face value) and a funding deadline.
  3. Investors fund the invoice β€” partial funding is supported. The marketplace collects a protocol fee on each contribution.
  4. Funds are released to the SME β€” once fully funded, the financing pool releases net proceeds to the SME.
  5. SME repays the face value β€” on or before the due date.
  6. Investors receive principal + yield β€” the spread between the discounted price paid and the face value repaid is the investor's return.
  7. Defaults are handled on-chain β€” if the SME fails to repay, the admin can mark the invoice as defaulted and distribute any partial recovery to investors.

Contract Architecture

Contract Responsibility
invoice_nft Mints and manages invoice NFTs. Owns the canonical invoice state machine.
marketplace Lists invoices, accepts investor funding, collects fees, triggers pool release.
financing_pool Holds investor funds, tracks positions, distributes repayments and yield.
treasury Accumulates protocol fees. Admin-controlled withdrawal.
risk_registry Verifier-managed SME and debtor risk scoring.
access_control Protocol-wide pause/unpause, role management, admin transfer.
shared Common types, errors, events, and validation utilities.

See ARCHITECTURE.md for a detailed breakdown.


Project Structure

Kora-Contract/
β”œβ”€β”€ Cargo.toml                    # Workspace root
β”œβ”€β”€ Makefile                      # Build, test, deploy targets
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ shared/                   # Shared types, errors, events, validation
β”‚   β”œβ”€β”€ invoice_nft/              # Invoice NFT contract
β”‚   β”œβ”€β”€ marketplace/              # Marketplace contract
β”‚   β”œβ”€β”€ financing_pool/           # Financing pool contract
β”‚   β”œβ”€β”€ treasury/                 # Treasury/fee contract
β”‚   β”œβ”€β”€ risk_registry/            # Risk registry contract
β”‚   β”œβ”€β”€ access_control/           # Access control contract
β”‚   └── tests/                    # Integration test suite
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.sh                 # Full deployment script
β”‚   └── interact.sh               # Shell helpers for contract interaction
β”œβ”€β”€ deployments/                  # Generated deployment manifests (gitignored)
└── docs/
    β”œβ”€β”€ ARCHITECTURE.md
    β”œβ”€β”€ CONTRACTS.md
    └── SECURITY.md

Getting Started

Prerequisites

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Add WASM target
rustup target add wasm32-unknown-unknown

# Install stellar CLI
cargo install stellar-cli --locked

Build

# Clone the repository
git clone https://github.com/your-org/kora-contract.git
cd kora-contract

# Build all contracts
make build

# Build and optimize WASM binaries
make build-optimized

Test

# Run all unit and integration tests
make test

# Run with output
make test-verbose

Lint

make fmt    # Format code
make lint   # Run clippy (warnings as errors)
make check  # Type-check without building

Deployment

Testnet

export DEPLOYER_SECRET="your-stellar-secret-key"
make deploy-testnet

This will:

  1. Build and optimize all WASM binaries
  2. Deploy each contract to Stellar testnet
  3. Initialize all contracts with correct cross-contract references
  4. Write a deployment manifest to deployments/testnet.json

Mainnet

export DEPLOYER_SECRET="your-stellar-secret-key"
make deploy-mainnet

Mainnet deployment requires manual confirmation at the prompt.


Example Interactions

After deployment, load the interaction helpers:

source scripts/interact.sh testnet

Register a verifier and SME:

kora_add_verifier "$ADMIN_ADDRESS" "$VERIFIER_ADDRESS"
kora_register_sme "$VERIFIER_ADDRESS" "$SME_ADDRESS" 35

Mint an invoice:

kora_mint_invoice \
  "$SME_ADDRESS" \
  "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" \
  10000000000 \
  "USDC" \
  1780000000 \
  "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi" \
  30

List the invoice:

kora_list_invoice "$SME_ADDRESS" 1 9500000000 10000000000 "$USDC_TOKEN" 1750000000

Fund the invoice (investor):

kora_fund_invoice "$INVESTOR_ADDRESS" 1 4750000000

Repay:

kora_repay "$SME_ADDRESS" 1 "$USDC_TOKEN" 10000000000

Query state:

kora_get_invoice 1
kora_get_pool 1
kora_get_sme_profile "$SME_ADDRESS"

Invoice NFT Data Model

pub struct Invoice {
    pub id: u64,
    pub sme: Address,
    pub debtor_hash: Bytes,    // SHA-256 of debtor info β€” PII stays off-chain
    pub amount: i128,          // Face value in stroops (7 decimal places)
    pub currency: Symbol,      // e.g. USDC, EURC
    pub due_date: u64,         // Unix timestamp
    pub ipfs_cid: String,      // IPFS CID of full invoice metadata
    pub risk_score: u32,       // 0–100 (assigned by verifier)
    pub risk_tier: RiskTier,   // AAA / AA / A / B / C
    pub status: InvoiceStatus, // Created β†’ Listed β†’ Funded β†’ Repaid | Defaulted
    pub created_at: u64,
    pub funded_at: Option<u64>,
    pub repaid_at: Option<u64>,
}

Risk Tiers

Tier Score Range Description
AAA 0–20 Lowest risk. Blue-chip debtors, strong SME history.
AA 21–40 Low risk. Established SME, reliable debtor.
A 41–60 Moderate risk. Standard trade finance profile.
B 61–80 Elevated risk. Newer SME or less-known debtor.
C 81–100 High risk. Requires higher yield to attract investors.

Protocol Fees

Fee Default Description
Marketplace fee 0.5% (50 bps) Charged on each investor contribution
Late penalty 2% (200 bps) Applied to late repayments

All fees are configurable by the admin within safe bounds (0–100%).


Security

  • All state-mutating functions require require_auth() on the relevant signer
  • Input validation on all public entry points (amounts, timestamps, scores, strings)
  • Safe arithmetic via checked_mul / checked_div β€” no silent overflows
  • Protocol-wide pause mechanism via access_control
  • Role-based access: Admin, Operator, Verifier
  • Debtor PII never stored on-chain β€” only a SHA-256 hash
  • See docs/SECURITY.md for the full security model

Contributing

We welcome contributions from the community. Please read CONTRIBUTING.md before opening a pull request.


License

MIT β€” see LICENSE.


Acknowledgements

Built with Stellar Soroban. Inspired by the real-world invoice financing gap facing African SMEs and the potential of blockchain infrastructure to close it.

About

Onchain invoice finance protocol

Resources

License

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 94.1%
  • Shell 4.6%
  • Makefile 1.3%