~/arifin
GitHub ↗
~/arifin · Indonesia
WorkWritingAbout
GitHub ↗LinkedIn ↗Email
← work
2026·Solo build·oss

Quicklend

OSS ↗
backgroundMost on-chain lending protocols are monolithic and opaque; understanding how they actually work requires reading a lot of code.
goalBuild a decentralized, non-custodial lending protocol from first principles — not a fork — to understand the math and mechanics deeply.
outcomeQuicklend — a working lending protocol with supply, borrow, repay, and liquidation flows, 119 passing tests, and a full-stack deployment.
TypeScriptSolidityDeFiSmart ContractsEVMFoundrySoladyOpenZeppelinNext.jsWagmi

I wanted to build a lending protocol from first principles — not fork Aave or Compound, but actually implement the math myself: interest rate models based on utilization, health factor calculations, collateral factor weighting, liquidation logic. It was part learning exercise, part proof that the system could be built cleanly without copying an existing codebase.

The protocol has four core contracts. LendingPool is the main entry point for supply, borrow, repay, and liquidation. qToken represents pool shares and handles yield accrual. InterestRateModel calculates rates algorithmically based on pool utilization — rates rise as utilization increases to incentivize repayment and new supply. UiPoolDataProvider aggregates position data for the frontend in a single call. Smart contracts in Solidity 0.8.20 with Foundry, using OpenZeppelin for access control and Solady for gas-efficient operations. The frontend is Next.js 16 with React 19 and Wagmi. A Fastify-based indexer with PostgreSQL and Redis handles off-chain data aggregation. Docker Compose spins up the whole stack with a local Anvil chain via make up.

The health factor math is straightforward on paper but subtle in implementation. Off-by-one errors in collateral factor calculations led to positions being flagged as liquidatable before they should be, and to positions that should be liquidatable slipping through. The 119 tests in the suite exist largely because I kept finding edge cases in the interest accrual logic under extreme utilization scenarios — particularly around what happens when utilization hits 100% and the interest rate model hits its ceiling.

Building this from scratch was the fastest path to actually understanding how lending protocols work. Reading Aave's codebase is useful; implementing the health factor check yourself, getting it wrong, and debugging the failure is a different level of understanding entirely.

← all workwriting →
OSS ↗
TypeScriptSolidityDeFiSmart ContractsEVMFoundrySoladyOpenZeppelinNext.jsWagmi
← all workwriting →