← Back to projects
·● Active

BankX Protocol

A fractional-algorithmic stablecoin protocol pegging XSD to 1/1000th of a troy ounce of silver — with no liquidations, on-chain interest for minters, and a deficit-driven liquidity incentive system.

SolidityOpenZeppelinChainlinkUniswap V2 ForkWETHCustom ERC-20PID Controller

What is BankX?

BankX is a DeFi protocol I built from the ground up for a client, centred on a single differentiating idea: the stablecoin should belong to the individual who creates it, not to the bank.

The protocol issues XSD — a stablecoin pegged to 1/1000th of a troy ounce of silver (XAG/1000), tracked in real time via Chainlink's XAG/USD price feed. Users deposit ETH as collateral, mint XSD directly to their wallet, earn interest on their outstanding position, and redeem on their own terms — with no liquidation risk, ever.

The second token, BankX, serves as fractional collateral, absorbs algorithmic backing at lower collateral ratios, and is distributed as interest and liquidity rewards.

Architecture

The system is built around five core contracts that coordinate through a shared state machine:

  • XSDStablecoin — ERC-20 XSD; manages the pool whitelist that gates all mint/burn access.
  • BankXToken — ERC-20 BankX; shares the XSD pool registry as its mint/burn gate.
  • CollateralPool — The main vault. Accepts WETH, mints XSD in three modes (1:1, fractional, algorithmic), tracks per-user weighted-average interest, and implements a two-step redemption to block flash loans.
  • PIDController — Reads AMM pool prices via a 10-slot rolling average and adjusts the global collateral ratio in 0.25% steps. Also manages three deficit buckets that trigger liquidity incentive campaigns.
  • Router — UniswapV2-fork router with three-tier circuit breakers: per-token price deviation limits, per-swap volume caps, and a global 5-minute volume ceiling.

Key Engineering Decisions

No liquidations. This is the core product promise and required the entire stability mechanism to work without position-level collateral seizure. Instead, stability is maintained through CR adjustments, buyback-and-burn mechanics, and the deficit/incentive system.

Silver peg, not dollar peg. XSD's target price in USD floats with silver markets. Every price calculation in the codebase derives from xag_usd_price() / 1000. Getting this right throughout the interest math, collateral calculations, and PID logic was non-trivial — a subtle constant error (311035 for grams-per-troy-oz × 10,000) propagates through the entire interest formula.

Weighted-average interest. Minters can add to a position at any time. The system recalculates a weighted-average rate so neither tranche is charged the wrong rate — a standard weighted mean updated on every mint and accrued to the current timestamp on every redeem.

Block-delay as flash-loan defence. Rather than relying purely on reentrancy guards, I implemented a cross-contract block-delay: every mint, redeem, and swap requires a priceCheck() call recorded at least 2 blocks prior. This makes same-transaction flash-loan attacks structurally impossible for fractional operations.

Deficit-driven liquidity. AMM pool depth and collateral levels are monitored every time systemCalculations() is called. When a threshold is breached, a deficit bucket opens and the protocol pays elevated, tiered rewards (denominated in USD, paid in BankX + XSD) to community members who fill the gap.