Skip to content

Pool Reaping Transition

{-# OPTIONS --safe #-}

open import Ledger.Conway.Specification.Abstract
open import Ledger.Conway.Specification.Transaction

module Ledger.Conway.Specification.PoolReap
  (txs : _) (open TransactionStructure txs)
  (abs : AbstractFunctions txs)
  where
open import Ledger.Prelude
open import Ledger.Conway.Specification.Utxo txs abs
open import Ledger.Conway.Specification.Certs govStructure
record PoolReapState : Type where
  constructor ⟦_,_,_,_⟧ᵖ
  field
    utxoSt     : UTxOState   -- utxo state
    acnt       : Acnt        -- accounting
    dState     : DState      -- delegation state
    pState     : PState      -- pool state
instance
  unquoteDecl HasCast-PoolReapState = derive-HasCast
                [ (quote PoolReapState , HasCast-PoolReapState) ]

private variable
  e lastEpoch : Epoch
  poolReapState : PoolReapState

data
  _⊢_⇀⦇_,POOLREAP⦈_ :   PoolReapState  Epoch  PoolReapState  Type where
  POOLREAP : let
    open PoolReapState poolReapState
    open StakePoolParams
    open UTxOState
    open PState
    open DState
    open Acnt
    open PParams

    retired    = pState .retiring ⁻¹ e
    rewardAcnts : DepositPurpose  Credential
    rewardAcnts =
      mapKeys PoolDeposit $
      mapValues rewardAccount $
      pState .pools  retired

    rewardAcnts' : Credential  Coin
    rewardAcnts' = aggregateBy (rewardAcnts ˢ) (utxoSt .deposits)

    refunds : Credential  Coin
    refunds = rewardAcnts'  dom (dState .rewards)

    mRefunds = rewardAcnts'  dom (dState .rewards) 

    unclaimed  = getCoin mRefunds

    retiredDeposits :  DepositPurpose
    retiredDeposits = mapˢ PoolDeposit retired

    utxoSt' = record utxoSt { deposits = utxoSt .deposits  retiredDeposits  }

    acnt' = record acnt { treasury = acnt .treasury + unclaimed }

    dState' =
      $\begin{pmatrix} \,\href{Ledger.Conway.Specification.PoolReap.html#671}{\htmlId{1967}{\htmlClass{Function}{\text{dState}}}}\, \,\htmlId{1974}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4418}{\htmlId{1975}{\htmlClass{Field}{\text{voteDelegs}}}}\,
      \\ \,\href{Ledger.Conway.Specification.PoolReap.html#671}{\htmlId{1994}{\htmlClass{Function}{\text{dState}}}}\, \,\htmlId{2001}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4448}{\htmlId{2002}{\htmlClass{Field}{\text{stakeDelegs}}}}\, \,\href{Axiom.Set.Map.html#17084}{\htmlId{2014}{\htmlClass{Function Operator}{\text{∣\^{}}}}}\, \,\href{Ledger.Conway.Specification.PoolReap.html#1242}{\htmlId{2017}{\htmlClass{Bound}{\text{retired}}}}\, \,\href{Axiom.Set.Map.html#17084}{\htmlId{2025}{\htmlClass{Function Operator}{\text{ᶜ}}}}\,
      \\ \,\href{Ledger.Conway.Specification.PoolReap.html#671}{\htmlId{2035}{\htmlClass{Function}{\text{dState}}}}\, \,\htmlId{2042}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4479}{\htmlId{2043}{\htmlClass{Field}{\text{rewards}}}}\, \,\href{Axiom.Set.Map.Dec.html#2052}{\htmlId{2051}{\htmlClass{Function Operator}{\text{∪⁺}}}}\, \,\href{Ledger.Conway.Specification.PoolReap.html#1540}{\htmlId{2054}{\htmlClass{Bound}{\text{refunds}}}}\,
      \end{pmatrix}$

    pState' =
      $\begin{pmatrix} \,\href{Ledger.Conway.Specification.PoolReap.html#720}{\htmlId{2093}{\htmlClass{Function}{\text{pState}}}}\, \,\htmlId{2100}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4542}{\htmlId{2101}{\htmlClass{Field}{\text{pools}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2107}{\htmlClass{Function Operator}{\text{∣}}}}\, \,\href{Ledger.Conway.Specification.PoolReap.html#1242}{\htmlId{2109}{\htmlClass{Bound}{\text{retired}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2117}{\htmlClass{Function Operator}{\text{ᶜ}}}}\,
      \\ \,\href{Ledger.Conway.Specification.PoolReap.html#720}{\htmlId{2127}{\htmlClass{Function}{\text{pState}}}}\, \,\htmlId{2134}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4564}{\htmlId{2135}{\htmlClass{Field}{\text{fPools}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2142}{\htmlClass{Function Operator}{\text{∣}}}}\, \,\href{Ledger.Conway.Specification.PoolReap.html#1242}{\htmlId{2144}{\htmlClass{Bound}{\text{retired}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2152}{\htmlClass{Function Operator}{\text{ᶜ}}}}\,
      \\ \,\href{Ledger.Conway.Specification.PoolReap.html#720}{\htmlId{2162}{\htmlClass{Function}{\text{pState}}}}\, \,\htmlId{2169}{\htmlClass{Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Specification.Certs.html#4586}{\htmlId{2170}{\htmlClass{Field}{\text{retiring}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2179}{\htmlClass{Function Operator}{\text{∣}}}}\, \,\href{Ledger.Conway.Specification.PoolReap.html#1242}{\htmlId{2181}{\htmlClass{Bound}{\text{retired}}}}\, \,\href{Axiom.Set.Map.html#12840}{\htmlId{2189}{\htmlClass{Function Operator}{\text{ᶜ}}}}\,
      \end{pmatrix}$

    in
    ────────────────────────────────
    _  $\begin{pmatrix} \,\href{Ledger.Conway.Specification.PoolReap.html#585}{\htmlId{2254}{\htmlClass{Function}{\text{utxoSt}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#628}{\htmlId{2263}{\htmlClass{Function}{\text{acnt}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#671}{\htmlId{2270}{\htmlClass{Function}{\text{dState}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#720}{\htmlId{2279}{\htmlClass{Function}{\text{pState}}}}\, \end{pmatrix}$ ⇀⦇ e ,POOLREAP⦈ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.PoolReap.html#1801}{\htmlId{2306}{\htmlClass{Bound}{\text{utxoSt'}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#1882}{\htmlId{2316}{\htmlClass{Bound}{\text{acnt'}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#1949}{\htmlId{2324}{\htmlClass{Bound}{\text{dState'}}}}\, \\ \,\href{Ledger.Conway.Specification.PoolReap.html#2075}{\htmlId{2334}{\htmlClass{Bound}{\text{pState'}}}}\, \end{pmatrix}$