{-# OPTIONS --safe #-}
open import Data.Nat.Properties using (+-0-monoid)
open import Data.Rational using (ℚ)
open import Ledger.Prelude
open import Ledger.Conway.Specification.Gov.Base
open import Ledger.Core.Specification.ProtocolVersion
module Ledger.Conway.Specification.Enact (gs : _) (open GovStructure gs) where
open import Ledger.Conway.Specification.Gov.Actions gs
record EnactEnv : Type where
field
gid : GovActionID
treasury : Treasury
epoch : Epoch
record EnactState : Type where
field
cc : HashProtected (Maybe ((Credential ⇀ Epoch) × ℚ))
constitution : HashProtected (DocHash × Maybe ScriptHash)
pv : HashProtected ProtVer
pparams : HashProtected PParams
withdrawals : Withdrawals
record HasEnactState {a} (A : Type a) : Type a where
field EnactStateOf : A → EnactState
open HasEnactState ⦃...⦄ public
instance
HasPParams-EnactState : HasPParams EnactState
HasPParams-EnactState .PParamsOf = proj₁ ∘ EnactState.pparams
HasccMaxTermLength-EnactState : HasCCMaxTermLength EnactState
HasccMaxTermLength-EnactState .CCMaxTermLengthOf = PParams.ccMaxTermLength ∘ PParamsOf
HasWithdrawals-EnactState : HasWithdrawals EnactState
HasWithdrawals-EnactState .WithdrawalsOf = EnactState.withdrawals
unquoteDecl HasCast-EnactEnv = derive-HasCast
[ (quote EnactEnv , HasCast-EnactEnv) ]
open EnactState
ccCreds : HashProtected (Maybe ((Credential ⇀ Epoch) × ℚ)) → ℙ Credential
ccCreds (just x , _) = dom (x .proj₁)
ccCreds (nothing , _) = ∅
getHash : ∀ {a} → NeedsHash a → Maybe GovActionID
getHash {NoConfidence} h = just h
getHash {UpdateCommittee} h = just h
getHash {NewConstitution} h = just h
getHash {TriggerHardFork} h = just h
getHash {ChangePParams} h = just h
getHash {TreasuryWithdrawal} _ = nothing
getHash {Info} _ = nothing
getHashES : EnactState → GovActionType → Maybe GovActionID
getHashES es NoConfidence = just (es .cc .proj₂)
getHashES es (UpdateCommittee) = just (es .cc .proj₂)
getHashES es (NewConstitution) = just (es .constitution .proj₂)
getHashES es (TriggerHardFork) = just (es .pv .proj₂)
getHashES es (ChangePParams) = just (es .pparams .proj₂)
getHashES es (TreasuryWithdrawal) = nothing
getHashES es Info = nothing
data _⊢_⇀⦇_,ENACT⦈_ : EnactEnv → EnactState → GovAction → EnactState → Type
private variable
s : EnactState
up : PParamsUpdate
new : Credential ⇀ Epoch
rem : ℙ Credential
q : ℚ
dh : DocHash
sh : Maybe ScriptHash
v : ProtVer
wdrl : Withdrawals
t : Treasury
gid : GovActionID
e : Epoch
instance
_ = +-0-monoid
open PParams using (ccMaxTermLength)
open EnactState using (cc)
data _⊢_⇀⦇_,ENACT⦈_ where
Enact-NoConf :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{2858}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{2864}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{2868}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#710}{\htmlId{2881}{\htmlClass{InductiveConstructor}{\text{NoConfidence}}}}\, \\ \,\htmlId{2896}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ record s { cc = nothing , gid }
Enact-UpdComm : let old = maybe proj₁ ∅ (s .cc .proj₁)
maxTerm = CCMaxTermLengthOf s +ᵉ e
in
∀[ term ∈ range new ] term ≤ maxTerm
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{3175}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{3181}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{3185}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#748}{\htmlId{3198}{\htmlClass{InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ \,\htmlId{3216}{\htmlClass{Symbol}{\text{(}}}\,\,\href{Ledger.Conway.Specification.Enact.html#2495}{\htmlId{3217}{\htmlClass{Generalizable}{\text{new}}}}\, , \,\href{Ledger.Conway.Specification.Enact.html#2522}{\htmlId{3223}{\htmlClass{Generalizable}{\text{rem}}}}\, , \,\href{Ledger.Conway.Specification.Enact.html#2543}{\htmlId{3229}{\htmlClass{Generalizable}{\text{q}}}}\,\,\htmlId{3230}{\htmlClass{Symbol}{\text{)}}}\, \end{pmatrix}$ ,ENACT⦈
record s { cc = just ((new ∪ˡ old) ∣ rem ᶜ , q) , gid }
Enact-NewConst :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{3376}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{3382}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{3386}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#786}{\htmlId{3399}{\htmlClass{InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{3417}{\htmlClass{Symbol}{\text{(}}}\,\,\href{Ledger.Conway.Specification.Enact.html#2551}{\htmlId{3418}{\htmlClass{Generalizable}{\text{dh}}}}\, , \,\href{Ledger.Conway.Specification.Enact.html#2566}{\htmlId{3423}{\htmlClass{Generalizable}{\text{sh}}}}\,\,\htmlId{3425}{\htmlClass{Symbol}{\text{)}}}\, \end{pmatrix}$ ,ENACT⦈ record s { constitution = (dh , sh) , gid }
Enact-HF :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{3547}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{3553}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{3557}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#824}{\htmlId{3570}{\htmlClass{InductiveConstructor}{\text{TriggerHardFork}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2590}{\htmlId{3588}{\htmlClass{Generalizable}{\text{v}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { pv = v , gid }
Enact-PParams :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{3697}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{3703}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{3707}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#862}{\htmlId{3720}{\htmlClass{InductiveConstructor}{\text{ChangePParams}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2474}{\htmlId{3736}{\htmlClass{Generalizable}{\text{up}}}}\, \end{pmatrix}$ ,ENACT⦈
record s { pparams = applyUpdate (PParamsOf s) up , gid }
Enact-Wdrl : let newWdrls = s .withdrawals ∪⁺ wdrl in
∑[ x ← newWdrls ] x ≤ t
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{3950}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{3956}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{3960}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#900}{\htmlId{3973}{\htmlClass{InductiveConstructor}{\text{TreasuryWithdrawal}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2604}{\htmlId{3994}{\htmlClass{Generalizable}{\text{wdrl}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { withdrawals = newWdrls }
Enact-Info :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Enact.html#2640}{\htmlId{4113}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2625}{\htmlId{4119}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Specification.Enact.html#2660}{\htmlId{4123}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Gov.Actions.html#938}{\htmlId{4136}{\htmlClass{InductiveConstructor}{\text{Info}}}}\, \\ \,\htmlId{4143}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ s