A Solana lending protocol with an Anchor program and a React/Vite frontend.
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")
Prerequisites: Rust, Anchor CLI, wasm-pack, Node ≥ 18
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)
crates/jbl-math contains the shared interest and share-conversion math used by both the on-chain program and the browser frontend.
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};The crate exposes its public functions to JavaScript via wasm-bindgen when built with the wasm feature.
Install wasm-pack:
cargo install wasm-packRun from the app/ directory:
cd app
npm run wasm:buildThis is equivalent to:
wasm-pack build ../crates/jbl-math-wasm \
--target bundler \
--out-dir ../app/pkg/jbl-mathThe generated package is written to app/pkg/jbl-math/ and is gitignored — rebuild whenever the crate changes.
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-plugin-wasm is already configured in app/vite.config.ts — no additional setup is needed.
cd app
npm install
npm run wasm:build # compile crates/jbl-math-wasm → app/pkg/jbl-math (required before dev/build)
npm run devanchor build
anchor test