Package Exports
- @pollum-io/vitalfi-programs
- @pollum-io/vitalfi-programs/idl
- @pollum-io/vitalfi-programs/types
Readme
VitalFi Vault - Solana Program
A Solana smart contract implementing a multi-vault crowdfunding system for financing medical receivables in Brazil.
๐๏ธ Architecture
Core Mechanics
Users deposit during the Funding phase up to the vault's capacity. After the funding period ends or when capacity is reached, the vault is finalized:
- Success: If
total_deposited โฅ ceil(2/3 * cap)โ Vault becomes Active, all funds withdrawn by authority - Failure: If
total_deposited < ceil(2/3 * cap)โ Vault becomes Canceled, users can claim refunds
For successful vaults, the authority deploys funds off-chain to finance medical receivables. At maturity, the authority returns principal + yield to the vault and calls mature_vault(). Users can then claim their proportional payout.
Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. INITIALIZATION โ
โ Authority creates vault with: โ
โ โข cap (max capacity) โ
โ โข target_apy_bps (display only) โ
โ โข funding_end_ts โ
โ โข maturity_ts โ
โ โข min_deposit โ
โ โข asset_mint (SPL token) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 2. FUNDING PHASE (Status: Funding) โ
โ Users deposit SPL tokens: โ
โ โข deposit(amount) โ Creates/updates Position PDA โ
โ โข Validates: time < funding_end_ts, amount โฅ min_deposit โ
โ โข Enforces: total โค cap โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 3. FINALIZATION (After funding_end_ts OR cap reached) โ
โ Authority calls finalize_funding(): โ
โ โ
โ two_thirds = (cap * 2 + 2) / 3 // Safe ceiling โ
โ โ
โ if total_deposited < two_thirds: โ
โ โโ> Status = Canceled โ
โ โโ> Users claim full refunds โ
โ else: โ
โ โโ> Status = Active โ
โ โโ> ALL funds transferred to authority โ
โ โโ> Deploys off-chain to finance receivables โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 4. MATURITY (Status: Active โ Matured) โ
โ Authority returns principal + yield to vault, calls: โ
โ โข mature_vault() โ
โ โข Calculates payout factor: โ
โ payout_num = vault_token_account.amount (returned) โ
โ payout_den = total_deposited โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 5. CLAIMS (Status: Matured OR Canceled) โ
โ Users call claim(): โ
โ โ
โ If Matured: โ
โ entitled = floor(deposited * payout_num / payout_den) โ
โ If Canceled: โ
โ entitled = deposited // Full refund โ
โ โ
โ to_pay = entitled - already_claimed โ
โ โข Supports multiple partial claims โ
โ โข Uses u128 math for precision โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโState Accounts
Vault PDA: ["vault", authority, vault_id_bytes]
- Stores all vault parameters and state
- 210 bytes
Position PDA: ["position", vault, user]
- Tracks user's deposits and claims
- 89 bytes
Vault Token Account: ["vault_token", vault]
- SPL token account holding deposits/returns
- Owned by Vault PDA
Instructions
- initialize_vault - Create new vault
- deposit - User deposits during funding
- finalize_funding - Check threshold, activate or cancel
- mature_vault - Calculate payout factor after returns
- claim - User claims refund or payout
- close_vault - Close empty vault, reclaim rent
๐ Installation
Prerequisites
- Rust 1.75+
- Solana CLI 1.18+
- Anchor Framework 0.31.1
- Node.js 18+ and Yarn
Setup
# Clone repository
git clone <repository-url>
cd vitalfi-programs
# Install dependencies
yarn install
# Build program
anchor build๐งช Tests
Run All Tests
anchor test๐ข Deployment
Devnet
anchor deploy --provider.cluster devnetMainnet
anchor deploy --provider.cluster mainnetProgram ID
146hbPFqGb9a3v3t1BtkmftNeSNqXzoydzVPk95YtJNjConfigured in Anchor.toml and lib.rs.
๐ License
MIT
Built with ๐ for healthcare finance on Solana