Files
proofs/formal/lean/DeFi/FeeModel.lean
zooqueenandHanzo Dev ac9676a47a proofs: drive formal/lean library to 0 errors
The formal/lean library (53 files — a separate formalization from lean/) had
~110 type-check errors across 38 files and had never had its Mathlib oleans
built. It now verifies at 0 errors under the project's strict setting:
`lake env lean -D autoImplicit=false`, all 53 files.

Fixed the same families as the sibling lean/ tree (the content is diverged, so
each was repaired directly):
- Crypto (BLS/FROST/Corona/Hybrid/threshold/FHE/Verkle): omega needs in-scope
  structure invariants; Nat-division bounds; noncomputable over opaque verifiers;
  Fin n index → Nat; deriving Inhabited.
- DeFi (AMM/staking/fees/flashloan/HFT/router): constant-product invariant and
  fee bounds via Nat.div_mul_le_self / Nat.div_le_of_le_mul; dead tactics.
- Protocol/Consensus/Warp/Bridge: BFT quorum theorems tightened to n=3f+1;
  pipe-projection parse fixes; split-after-simp; dead tactics; built the
  Consensus/Safety + ThresholdProof dependency oleans from clean source.
- Network/Compute/Trust/Build: record-projection opacity (unfold+split),
  foldl-min monotonicity, BEq parse parens.
- autoImplicit=false: declared previously auto-bound variables (explicit binders
  / variable blocks); the lakefile sets autoImplicit:=false.

Integrity: no sorry/admit/native_decide; no proof-by-assumption axiom cheats.
Statement changes only tightened false/trivial draft theorems to true
invariants. Remaining axioms are trusted-base only (opaque crypto primitives,
protocol modeling / honesty-static, build determinism).

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-02 09:31:40 -07:00

71 lines
2.0 KiB
Lean4

/-
DeFi Fee Model
Maker-taker with volume tiers. Permissionless.
No regulatory fee caps (pure DeFi).
Maps to:
- lux/exchange: fee calculation
- lux/node: fee distribution to validators
Properties:
- Makers ≤ takers (incentivize liquidity)
- Volume tiers: more volume → lower fees
- Validator revenue: portion of fees to validators
- Permissionless: fee schedule is on-chain and transparent
Authors: Zach Kelling (Dec 2025), Woo Bin (Mar 2026)
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Tactic
namespace DeFi.FeeModel
/-- Fee tier -/
structure FeeTier where
minVolume : Nat
makerBps : Nat
takerBps : Nat
deriving DecidableEq, Repr, Inhabited
/-- Standard DeFi tiers -/
def tiers : List FeeTier :=
[ ⟨0, 15, 30⟩ -- Tier 1
, ⟨1000000, 10, 25⟩ -- Tier 2: $1M+
, ⟨10000000, 5, 15⟩ -- Tier 3: $10M+
, ⟨100000000, 0, 10⟩ -- Tier 4: $100M+ (zero maker)
]
/-- Calculate fee -/
def fee (tier : FeeTier) (isMaker : Bool) (value : Nat) : Nat :=
value * (if isMaker then tier.makerBps else tier.takerBps) / 10000
/-- MAKER ≤ TAKER -/
theorem maker_le_taker (t : FeeTier) (v : Nat) (h : t.makerBps ≤ t.takerBps) :
fee t true v ≤ fee t false v := by
simp [fee]; exact Nat.div_le_div_right (Nat.mul_le_mul_left v h)
/-- TOP TIER ZERO MAKER -/
theorem top_tier_zero : (tiers[3]!).makerBps = 0 := by simp [tiers]
/-- VOLUME DISCOUNT -/
theorem volume_discount : (tiers[0]!).takerBps > (tiers[3]!).takerBps := by
simp [tiers]
/-- 4 TIERS -/
theorem four_tiers : tiers.length = 4 := rfl
/-- VALIDATOR SHARE: Portion of fees goes to validators who process trades -/
def validatorShare (totalFee : Nat) (validatorPct : Nat) : Nat :=
totalFee * validatorPct / 100
theorem validator_bounded (totalFee pct : Nat) (h : pct ≤ 100) :
validatorShare totalFee pct ≤ totalFee := by
simp only [validatorShare]
apply Nat.div_le_of_le_mul
calc totalFee * pct ≤ totalFee * 100 := Nat.mul_le_mul_left totalFee h
_ = 100 * totalFee := Nat.mul_comm _ _
end DeFi.FeeModel