Biequity

Permissionless tokenized stock issuance on Base — deposit USDC, receive on-chain equity tokens backed 1:1 by real shares held in custody.

8 min

Biequity - Open Access to Global Markets

Biequity lets anyone swap USDC for tokenized US equities — bieAAPL, bieTSLA, bieMSFT — directly from a wallet. No broker account. No wire transfer. No waiting.

The goal: make US equities accessible to everyone, everywhere, by leveraging Base and ERC-3643 identity protocols to bring compliance on-chain.

Web App · GitHub


The Problem

Billions of people have no practical access to US equities. Not because the markets are closed to them — but because the on-ramps are broken. Opening a brokerage account from most of Africa means jumping through a gauntlet of KYC requirements designed for Western ID documents, waiting weeks for approval, paying foreign exchange conversion fees, and then watching your position exposed to currency risk before you even pick a stock.

DeFi already solved this kind of access problem for dollars — stablecoins let anyone hold USD from any wallet. The same logic should apply to US equities. If I can hold USDC from a wallet in Lagos, I should be able to hold tokenized AAPL the same way.

That was the idea behind Biequity.


What It Does

Each token is minted on-chain and backed 1:1 by a real share purchased and held by a brokerage partner. The price is sourced live from Pyth Network. The compliance layer is baked into the token itself via ERC-3643 — transfers are gated by an on-chain identity registry so only KYC-verified addresses can hold or move them.

The full flow looks like this:

  1. User deposits USDC into BiequityCore.buy("AAPL", amount)
  2. The contract queries the Pyth oracle for the live AAPL/USD price, calculates token quantity, deducts a 3% fee, and mints bieAAPL to the user's wallet
  3. Asynchronously, a Cloudflare Worker picks up the TokensMinted event and places a real market order on the brokerage side via API
  4. Once the share is confirmed purchased, the worker calls BiequityCore.settleTokens() on-chain — the 1:1 backing is now live
  5. The user's bieAAPL is fully backed and redeemable at any time

Architecture

The project is a Turborepo monorepo with three layers: smart contracts on Base Sepolia, a Next.js 15 frontend, and a Cloudflare Worker that bridges on-chain events to the brokerage API.

┌─────────────────────────────────────────────────────┐
│               Next.js 15 Frontend                   │
│  shadcn/ui · Wagmi v2 · Zustand · TanStack Query    │
│  Trade UI · Token Selector · Transaction Dialog     │
├─────────────────────────────────────────────────────┤
│              Smart Contracts (Base Sepolia)          │
│                                                     │
│  BiequityCore ──────────── BiequityTokenFactory     │
│  buy() · redeem()          deploys one token        │
│  settleTokens()            per stock symbol         │
│  fee collection                    │                │
│                             BiequityToken           │
│  IdentityRegistry           ERC-3643 · ERC20Permit  │
│  KYC whitelist              transfer gating         │
│                                                     │
│  Pyth Network Oracle — live AAPL/TSLA/MSFT pricing  │
├─────────────────────────────────────────────────────┤
│           Cloudflare Worker (Hono)                  │
│  Cron: read TokensMinted events                     │
│  → AlpacaService.placeMarketOrder()                 │
│  → BiequityCore.settleTokens() (on-chain write)     │
├─────────────────────────────────────────────────────┤
│            Brokerage Layer (Alpaca API)              │
│  Market orders · Position tracking · Settlement     │
└─────────────────────────────────────────────────────┘

Smart Contract Map

ContractRole
BiequityCoreProtocol entry — buy(), redeem(), settleTokens(), fee collection
BiequityTokenFactoryDeploys one BiequityToken per registered stock symbol
BiequityTokenERC-3643 ERC-20 — transfer gating, ERC20Permit, ERC20Pausable
IdentityRegistryOn-chain KYC whitelist — isVerified(address) called on every transfer

Deployed on Base Sepolia: BiequityCore at 0x8B0EF8eD5D6F3ceF0803c26Ea7471ba83CB6cB80


Tech Stack

Smart Contracts

Foundry for development, testing, and deployment. Contracts written in Solidity — BiequityToken extends OpenZeppelin's ERC-20 with ERC-3643 transfer compliance hooks, ERC20Permit for gasless approvals, and ERC20Pausable for emergency freezes.

Frontend

Next.js 15 (App Router) with TypeScript throughout. UI built on shadcn/ui with a custom neobrutalist design system. State managed with Zustand (trade state, balances, prices). Server state via TanStack Query. Wallet integration through Wagmi v2 + Viem + Reown (WalletConnect v2).

Settlement Worker

Cloudflare Workers running the Hono framework. A built-in cron trigger wakes the worker periodically, reads recent TokensMinted events via Viem, places a market order through the Alpaca brokerage API, and calls settleTokens() back on-chain. Zero infrastructure overhead — no server to manage.

Oracle

Pyth Network for live equity price feeds. Pyth's pull-based model (~400ms update cadence) was chosen over Chainlink's push-based model for lower latency and broader US equity feed coverage.

Monorepo

Turborepo with Bun workspaces. Shared packages for UI components, TypeScript config, and Pyth feed IDs used across both the frontend and the worker.


Key Engineering Decisions

Why ERC-3643 instead of a plain ERC-20?

Tokenized equities are regulated instruments. A vanilla ERC-20 lets any address receive or transfer the token — which conflicts with securities law in essentially every jurisdiction that has addressed the question. ERC-3643 (the T-REX standard, used in production by Ondo Finance and xStocks) embeds the compliance check inside the token's own transfer function. The _update() override queries the IdentityRegistry before every peer-to-peer transfer and reverts if either party isn't verified. Compliance becomes protocol-level, not app-level — you can't route around it through a different UI.

// BiequityToken._update() — called on every transfer
if (!isMint && !isBurn) {
    if (!identityRegistry.isVerified(from)) revert TransferNotCompliant(from, to);
    if (!identityRegistry.isVerified(to))   revert TransferNotCompliant(from, to);
}

The trade-off is DeFi composability: compliant tokens don't drop into Uniswap or Aave directly. The production path is a whitelisted ERC-20 wrapper — the underlying position stays compliant, a separate wrapper is whitelisted for specific DeFi pools. That's the natural next step.

Why Cloudflare Workers for the settlement layer?

The worker does one thing: wake up, read events, place an order, write back to chain. That's a stateless, I/O-bound task that runs for a few hundred milliseconds. A traditional backend would require provisioning, uptime monitoring, and scaling logic for something Cloudflare handles natively with a built-in cron trigger and zero infrastructure. At higher scale, you'd want Cloudflare Durable Objects or a proper queue for durability guarantees — but for a protocol at this stage, Workers are the right abstraction.

Why Pyth over Chainlink?

Two reasons: update latency and equity coverage. Pyth pushes price updates ~every 400ms; Chainlink's push model updates on deviation thresholds, often 1–3 minutes for equity feeds. For a protocol where the oracle price directly determines how many tokens a user receives per dollar of USDC, a 2-minute stale price during a volatile move is meaningful slippage exposure. Pyth also has broader US equity feed coverage in its current catalogue.


The Alpaca ITN Problem

This is the honest part of the story.

The original intention was to use Alpaca's Instant Tokenization Network (ITN) as the settlement backbone — a single API for in-kind minting and redemption of tokenized US equities, with instant settlement and no T+2 delay. Architecturally, the worker was designed around it: AlpacaService.mintTokenizedAsset() maps directly to Alpaca's POST /v2/tokenization/mint endpoint.

Then I ran into the actual product.

Alpaca's ITN launched in October 2024 at TOKEN2049 Singapore with Solana as its exclusive settlement chain. Base (EVM) was listed as "coming soon." The Biequity contracts run on Base — so the ITN is, for now, a non-starter.

Beyond chain support, the ITN is designed for authorized participants — US-regulated financial institutions and their non-US affiliates that have completed a formal onboarding relationship with Alpaca. It's not available to individual developers, hackathon teams, or independent projects. The access model is institutional by design.

So what I set out to build — a permissionless on-ramp to US equities on Base, powered by Alpaca's settlement rails — ran directly into the limits of what's actually available to build on today.

The worker now runs in MOCK_MODE=true by default. MockProviderService intercepts every brokerage and tokenization call and returns realistic responses with simulated latency, auto-settling after 2 seconds. The code path is architecturally identical to the production path — switching to live mode is a configuration change, not a code change. The plumbing is all there. The infrastructure just isn't open yet.


What This Project Is, Honestly

Biequity is an experimental research project deployed on Base Sepolia testnet. It handles no real money.

But it's also a clear technical proof of concept for a real problem. The architecture is sound. The contracts are tested. The settlement flow is implemented and waiting on infrastructure that is actively being built.

There's a plausible path to mainnet once a few things resolve:

  • EVM support on Alpaca ITN — Solana-only today, EVM is on the roadmap
  • Authorized participant access — currently institutional; individual developer access is unclear
  • Regulatory clarity — operating this at scale likely requires a broker-dealer relationship or partnership in the jurisdictions you're serving
  • DeFi composability — a whitelisted ERC-20 wrapper over the ERC-3643 tokens would unlock lending and yield strategies

If you're building in this space — tokenized RWA infrastructure, Africa-focused DeFi, or compliant on-chain equities — open an issue or reach out. The conversation is worth having.


Status

Testnet only · MOCK_MODE by default · Not production-ready

Built with Foundry · Next.js 15 · Cloudflare Workers · Pyth Network · Wagmi · Base Sepolia

Spread the word