爆发 BaofaBaofa Documentation
中文 Open the App

Architecture

Four diamonds, one factory, one coin contract and PancakeSwap v2. How the pieces fit, where value sits and what the design refuses to do.

Updated 2026-11-04Contracts baofa-rewrite-2026-11-04-a727bfe

Baofa is a set of EIP-2535 diamonds written in Solidity 0.8.38 for BNB Smart Chain, compiled for the Cancun EVM. Each diamond is a module with a fixed responsibility; the coin contract and the factory are plain contracts. The protocol was written from a complete specification of the reference Solana programs, instruction by instruction, and is compared against them by differential tests; it is not a port of another EVM code base.

The Pieces#

Contract Role Holds value
BaofaCore curves: create, buy, sell, graduation, creator fee ledgers, holder rewards, incentives, quote asset registry, protocol parameters curve reserves and fee ledgers, all as WBNB
BaofaFees fee rates and tiers per consumer, fee sharing configurations, social fee accounts, donation accounts, buyback sweeps shared and social fee ledgers, as WBNB
BaofaFrenzy the Frenzy trading programme: caps, windows, the trader role, sweeps, the end-of-window burn its vault, in BNB
BaofaRelay the donation relay: campaign donations, epoch close, swap to the settlement asset and distribution by the relayer donations in flight
BaofaCoinFactory deploys one BaofaCoin per launch with CREATE2 nothing
BaofaCoin the coin: ERC-20 with permit, one gate that opens at graduation nothing
Baofa AMM (not deployed) the protocol's own graduation venue, attachable later by governance n/a

External dependencies on BNB Smart Chain: WBNB, the PancakeSwap v2 factory (pair creation at graduation) and the PancakeSwap v2 router (relay swaps). The addresses are on the Addresses page.

Where Value Sits#

Curve reserves, creator fee accruals and protocol fee accruals are held as WBNB inside the core, booked to per-coin and per-recipient ledgers. No diamond other than the Frenzy vault keeps plain BNB at rest: a payable entry wraps exactly what it books, and the stateful invariant suite asserts after every call that the core, fees and relay diamonds hold no native balance. Two consequences:

  • Nothing in the protocol depends on a diamond's raw balance, so a direct BNB transfer to a diamond cannot change any accounting. Such a transfer is stranded value that only the owner's rescueNative can return, and it cannot touch ledgers.
  • Every payment out is either a pull by the recipient (creator and protocol fee claims, migration fee) or a push with a WBNB fallback (holder rewards, sharing distributions, social claims), so no recipient can block a trade or anybody else's payment.

Call Flow of a Trade#

  1. The trader calls buyExactIn or sell on the core with a deadline and a slippage floor.
  2. The core reads the fee rates for the coin's quote class and market cap tier from the fees module.
  3. The core applies the curve maths in integer arithmetic, moves the fee parts to their ledgers, moves coins between the trader and the curve, and emits Trade.
  4. If the buy drained the real coin reserve, the core emits Complete; graduation is a separate, permissionless migrate call.

The reentrancy lock is a transient-storage guard per diamond, held for the whole external call. External token transfers happen after state is settled.

Upgradeability and Ownership#

Each diamond has an owner who can change facets through diamondCut and move ownership in two steps (transferOwnership, acceptOwnership). The owner can also renounce, which with the removal of the cut selector makes a diamond immutable. At deployment the owner of every diamond is the deployer; the governance structure that replaces it is described under Roles and Governance.

The coin contract and the factory have no owner and no upgrade path.

What the Design Refuses#

Refused How
Pausing trades on curves the core has no pause function
Blacklisting a trader or a coin no such function exists
Minting a coin after creation BaofaCoin has no mint
Pre-seeding a coin's PancakeSwap pair the coin refuses transfers to its pair until graduation
Keeping graduation liquidity the liquidity tokens go to the dead address in the graduation transaction
A recipient holding trades hostage pull payments, WBNB fallback
A whitelist that exempts an arbitrary address from fees the whitelist can only be the Frenzy diamond or nobody

Source and Verification#

The contracts are verified on BscScan at deployment, with the compiler settings above and optimiser runs set to 200. The review package handed to external reviewers contains the same 75 Solidity files as the deployment; see Assurance.

Baofa Documentation. Built from the launch contracts package baofa-rewrite-2026-11-04-a727bfe · 2026-11-04

baofa.fun · X @baofadotfun