diff --git a/agora/Agora/Effect.hs b/agora/Agora/Effect.hs index a4e3782..e8c3794 100644 --- a/agora/Agora/Effect.hs +++ b/agora/Agora/Effect.hs @@ -5,11 +5,15 @@ Description: Helpers for constructing effects Helpers for constructing effects. -} -module Agora.Effect (makeEffect) where +module Agora.Effect ( + makeEffect, + noopEffect, +) where import Agora.AuthorityToken (singleAuthorityTokenBurned) import Agora.Utils (passert) -import Plutarch.Api.V1 (PScriptPurpose (PSpending), PTxInfo, PTxOutRef, PValidator, PValue) +import Plutarch (popaque) +import Plutarch.Api.V1 (PCurrencySymbol, PScriptPurpose (PSpending), PTxInfo, PTxOutRef, PValidator, PValue) import Plutarch.Internal (punsafeCoerce) import Plutarch.Monadic qualified as P import Plutus.V1.Ledger.Value (CurrencySymbol) @@ -26,13 +30,14 @@ makeEffect :: forall (datum :: PType). PIsData datum => CurrencySymbol -> - (forall (s :: S). Term s datum -> Term s PTxOutRef -> Term s (PAsData PTxInfo) -> Term s POpaque) -> + (forall (s :: S). Term s PCurrencySymbol -> Term s datum -> Term s PTxOutRef -> Term s (PAsData PTxInfo) -> Term s POpaque) -> ClosedTerm PValidator makeEffect gatCs' f = plam $ \datum _redeemer ctx' -> P.do ctx <- pletFields @'["txInfo", "purpose"] ctx' txInfo' <- plet ctx.txInfo + -- TODO: Use PTryFrom let datum' :: Term _ datum datum' = pfromData $ punsafeCoerce datum @@ -45,8 +50,16 @@ makeEffect gatCs' f = gatCs <- plet $ pconstant gatCs' - passert "singleAuthorityTokenBurned" $ singleAuthorityTokenBurned gatCs txInfo' mint + passert "A single authority token has been burned" $ singleAuthorityTokenBurned gatCs txInfo' mint - f datum' txOutRef' txInfo' + f gatCs datum' txOutRef' txInfo' -------------------------------------------------------------------------------- + +-- | Dummy effect which can only burn its GAT. +noopEffect :: CurrencySymbol -> ClosedTerm PValidator +noopEffect = + ( `makeEffect` + \_gatCs (_datum :: Term _ PUnit) _txOutRef _txInfo -> P.do + popaque (pconstant ()) + ) diff --git a/agora/Agora/Governor.hs b/agora/Agora/Governor.hs index 34777ad..db24681 100644 --- a/agora/Agora/Governor.hs +++ b/agora/Agora/Governor.hs @@ -18,14 +18,16 @@ module Agora.Governor ( governorValidator, ) where -import Agora.Proposal (ProposalThresholds) +import Agora.Proposal (ProposalTag, ProposalThresholds) import Plutarch (popaque) import Plutarch.Api.V1 (PMintingPolicy, PValidator) -- | Datum for the Governor script. -newtype GovernorDatum = GovernorDatum +data GovernorDatum = GovernorDatum { proposalThresholds :: ProposalThresholds -- ^ Gets copied over upon creation of a 'Agora.Proposal.ProposalDatum'. + , nextProposalTag :: ProposalTag + -- ^ What tag the next proposal will get upon creating. } {- | Redeemer for Governor script. The governor has two primary diff --git a/agora/Agora/Proposal.hs b/agora/Agora/Proposal.hs index f8a9357..a7df633 100644 --- a/agora/Agora/Proposal.hs +++ b/agora/Agora/Proposal.hs @@ -158,7 +158,11 @@ data ProposalDatum = ProposalDatum PlutusTx.makeIsDataIndexed ''ProposalDatum [('ProposalDatum, 0)] --- | Identifies a Proposal, issued upon creation of a proposal. +{- | Identifies a Proposal, issued upon creation of a proposal. + In practice, this number starts at zero, and increments by one + for each proposal. The 100th proposal will be @'ProposalTag' 99@. + This counter lives in the 'Governor', see 'nextProposalTag'. +-} newtype ProposalTag = ProposalTag {proposalTag :: Integer} deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData) deriving stock (Eq, Show, GHC.Generic) diff --git a/agora/Agora/SafeMoney.hs b/agora/Agora/SafeMoney.hs index 8791ff9..f94ae8d 100644 --- a/agora/Agora/SafeMoney.hs +++ b/agora/Agora/SafeMoney.hs @@ -3,7 +3,7 @@ Module : Agora.SafeMoney Maintainer : emi@haskell.fyi Description: Tags and bonuses for Plutarch.SafeMoney. -Tags and bonuses for "Plutarch.SafeMoney". +Tags and extras for "Plutarch.SafeMoney". -} module Agora.SafeMoney ( ADATag, diff --git a/agora/Agora/Stake.hs b/agora/Agora/Stake.hs index 9ee7c3c..234510c 100644 --- a/agora/Agora/Stake.hs +++ b/agora/Agora/Stake.hs @@ -100,7 +100,7 @@ newtype Stake = Stake Vaguely this is the dependency graph for this locking interaction. Both the stake validator and the proposal - validator are only able to check for eachother through + validator are only able to check for one another through the datum belonging to the ST: @ @@ -143,7 +143,8 @@ data StakeRedeemer PermitVote ProposalLock | -- | Retract a vote, removing it from the 'lockedBy' field. See 'ProposalLock'. -- This action checks for permission of the 'Proposal'. Finished proposals are - -- always allowed to be retracted with. + -- always allowed to have votes retracted and won't affect the Proposal datum, + -- allowing 'Stake's to be unlocked. RetractVotes [ProposalLock] deriving stock (Show, GHC.Generic) @@ -166,7 +167,7 @@ data StakeDatum = StakeDatum -- TODO Support for MultiSig/Scripts is tracked here: -- https://github.com/Liqwid-Labs/agora/issues/45 , lockedBy :: [ProposalLock] - -- ^ The proposal locks in place. This field must be empty + -- ^ The current proposals locking this stake. This field must be empty -- for the stake to be usable for deposits and withdrawals. } deriving stock (Show, GHC.Generic) diff --git a/agora/Agora/Treasury.hs b/agora/Agora/Treasury.hs index 71eee81..3f48a1f 100644 --- a/agora/Agora/Treasury.hs +++ b/agora/Agora/Treasury.hs @@ -57,7 +57,7 @@ treasuryValidator gatCs' = plam $ \datum redeemer ctx' -> P.do gatCs <- plet $ pconstant gatCs' - passert "singleAuthorityTokenBurned" $ singleAuthorityTokenBurned gatCs txInfo' mint + passert "A single authority token has been burned" $ singleAuthorityTokenBurned gatCs txInfo' mint popaque $ pconstant ()