Files
proofs/formal/lean/DeFi/LiquidStaking.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

102 lines
3.4 KiB
Lean4

/-
Liquid Staking and Yield Protocol
Staked assets earn yield while remaining liquid.
Money at rest is put to work — implicit staking of
idle liquidity in the DEX pools.
Maps to:
- lux/node: validator staking (P-Chain)
- lux/exchange: LP staking rewards
- zoo/contracts: liquid staking derivatives
Properties:
- Yield accrual: staked assets earn validator rewards
- Liquidity: staked assets remain tradeable (liquid derivatives)
- No impermanent loss on single-sided staking
- Compounding: rewards auto-compound into staking position
Author: Zach Kelling (December 2025)
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Tactic
namespace DeFi.LiquidStaking
/-- Staking position -/
structure Position where
principal : Nat -- original staked amount
accrued : Nat -- accumulated rewards
compounded : Nat -- rewards that have been re-staked
liquidDerivatives : Nat -- tradeable staking receipt tokens
stakeDuration : Nat -- blocks staked
/-- Yield rate: annual percentage in basis points (e.g., 500 = 5%) -/
def annualYieldBps : Nat := 500 -- 5% APY baseline
/-- Per-block yield (simplified: annual / ~2.6M blocks per year) -/
def blockYield (principal : Nat) : Nat :=
principal * annualYieldBps / 26000000
/-- Accrue one block of yield -/
def accrueBlock (p : Position) : Position :=
let yield := blockYield (p.principal + p.compounded)
{ p with accrued := p.accrued + yield
, stakeDuration := p.stakeDuration + 1 }
/-- Compound: move accrued rewards into principal -/
def compound (p : Position) : Position :=
{ p with compounded := p.compounded + p.accrued
, accrued := 0 }
/-- YIELD ACCRUAL: Accrued rewards only increase -/
theorem yield_monotone (p : Position) :
(accrueBlock p).accrued ≥ p.accrued := by
simp [accrueBlock]
/-- LIQUIDITY: Liquid derivatives equal principal (1:1 mint) -/
def mintDerivatives (p : Position) : Position :=
{ p with liquidDerivatives := p.principal }
theorem derivatives_equal_principal (p : Position) :
(mintDerivatives p).liquidDerivatives = p.principal := by
simp [mintDerivatives]
/-- COMPOUNDING: After compound, accrued resets to 0 -/
theorem compound_resets_accrued (p : Position) :
(compound p).accrued = 0 := by
simp [compound]
/-- COMPOUNDING: After compound, compounded increases -/
theorem compound_increases_base (p : Position) :
(compound p).compounded ≥ p.compounded := by
simp [compound]
/-- NO IMPERMANENT LOSS: Single-sided staking has no IL.
Unlike LP positions, staked assets don't change ratio. -/
theorem no_impermanent_loss (p : Position) :
(accrueBlock p).principal = p.principal := by
simp [accrueBlock]
/-- DURATION MONOTONE: Stake duration only increases -/
theorem duration_monotone (p : Position) :
(accrueBlock p).stakeDuration > p.stakeDuration := by
simp [accrueBlock]
/-- TOTAL VALUE: principal + compounded + accrued -/
def totalValue (p : Position) : Nat :=
p.principal + p.compounded + p.accrued
/-- TOTAL VALUE MONOTONE: Accruing never decreases total -/
theorem value_monotone (p : Position) :
totalValue (accrueBlock p) ≥ totalValue p := by
simp [totalValue, accrueBlock]
/-- MONEY AT REST: Idle liquidity earns yield.
DEX pool deposits implicitly stake via the liquid staking layer. -/
theorem idle_earns (p : Position) (_h : p.principal > 0) :
totalValue (accrueBlock p) ≥ totalValue p := value_monotone p
end DeFi.LiquidStaking