JSPM

@pollum-io/vitalfi-programs

0.1.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q80349F
  • License MIT

VitalFi Vault Solana Program IDL and TypeScript types for on-chain medical receivables financing

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

  1. initialize_vault - Create new vault
  2. deposit - User deposits during funding
  3. finalize_funding - Check threshold, activate or cancel
  4. mature_vault - Calculate payout factor after returns
  5. claim - User claims refund or payout
  6. close_vault - Close empty vault, reclaim rent

๐Ÿš€ Installation

Prerequisites

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 devnet

Mainnet

anchor deploy --provider.cluster mainnet

Program ID

146hbPFqGb9a3v3t1BtkmftNeSNqXzoydzVPk95YtJNj

Configured in Anchor.toml and lib.rs.

๐Ÿ“„ License

MIT


Built with ๐Ÿ’œ for healthcare finance on Solana