Skip to content

calma-labs/calma

Repository files navigation

jbl

A Solana lending protocol with an Anchor program and a React/Vite frontend.

Setup

flowchart LR
    I("npm install") -->
    A("npm run setup\n─────────────\nanchor build\n+ npm run wasm")

    A --> B("npm run dev\n─────────────\nstart Vite\ndev server")

    A --> C("npm run test\n─────────────\nrun Anchor\nintegration tests")

    A --> D("npm run build\n─────────────\nwasm → app/dist\nproduction bundle")

    D --> E("npm run preview\n─────────────\npreview production\nbuild locally")
Loading

Prerequisites: Rust, Anchor CLI, wasm-pack, Node ≥ 18

Repository layout

programs/jbl/          Anchor smart contract
crates/jbl-math/       Pure-Rust math library (no external dependencies)
crates/jbl-math-wasm/  Wasm entrypoint — re-exports jbl-math via wasm-bindgen
app/                   React + TypeScript + Vite frontend
tests/                 Anchor integration tests (TypeScript / LiteSVM)

jbl-math — Rust crate

crates/jbl-math contains the shared interest and share-conversion math used by both the on-chain program and the browser frontend.

Using from Rust

The crate is included as a path dependency in programs/jbl/Cargo.toml with no additional features required.

[dependencies]
jbl-math = { path = "../../crates/jbl-math" }
use jbl_math::{compute_interest, amount_to_shares, shares_to_amount, amount_to_shares_burned};

Using from the frontend (WebAssembly)

The crate exposes its public functions to JavaScript via wasm-bindgen when built with the wasm feature.

Prerequisites

Install wasm-pack:

cargo install wasm-pack

Build

Run from the app/ directory:

cd app
npm run wasm:build

This is equivalent to:

wasm-pack build ../crates/jbl-math-wasm \
  --target bundler \
  --out-dir ../app/pkg/jbl-math

The generated package is written to app/pkg/jbl-math/ and is gitignored — rebuild whenever the crate changes.

Import in TypeScript

import { sharesToAmount, computeInterest, amountToShares, amountToSharesBurned } from './lib/jblMath'

// The bundler target auto-initializes the .wasm binary on import — no init() call needed.
// All u64 arguments and return values use JavaScript BigInt.
// Option<u64> return types map to bigint | undefined (undefined on overflow).
const interest = computeInterest(1_000_000n, 500, 31_557_600n)

Vite integration

vite-plugin-wasm is already configured in app/vite.config.ts — no additional setup is needed.


Frontend (app/)

cd app
npm install
npm run wasm:build   # compile crates/jbl-math-wasm → app/pkg/jbl-math (required before dev/build)
npm run dev

Anchor program

anchor build
anchor test

About

Powered by Solana. Built by lenders. Institutional-grade lending infrastructure for capital that doesn't sit idle.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors