apply Jack's PR suggestions

This commit is contained in:
Emily Martins 2022-04-05 12:03:30 +02:00
parent 6e1726de30
commit 1004951ef6
6 changed files with 33 additions and 13 deletions

View file

@ -5,11 +5,15 @@ Description: Helpers for constructing effects
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.AuthorityToken (singleAuthorityTokenBurned)
import Agora.Utils (passert) 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.Internal (punsafeCoerce)
import Plutarch.Monadic qualified as P import Plutarch.Monadic qualified as P
import Plutus.V1.Ledger.Value (CurrencySymbol) import Plutus.V1.Ledger.Value (CurrencySymbol)
@ -26,13 +30,14 @@ makeEffect ::
forall (datum :: PType). forall (datum :: PType).
PIsData datum => PIsData datum =>
CurrencySymbol -> 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 ClosedTerm PValidator
makeEffect gatCs' f = makeEffect gatCs' f =
plam $ \datum _redeemer ctx' -> P.do plam $ \datum _redeemer ctx' -> P.do
ctx <- pletFields @'["txInfo", "purpose"] ctx' ctx <- pletFields @'["txInfo", "purpose"] ctx'
txInfo' <- plet ctx.txInfo txInfo' <- plet ctx.txInfo
-- TODO: Use PTryFrom
let datum' :: Term _ datum let datum' :: Term _ datum
datum' = pfromData $ punsafeCoerce datum datum' = pfromData $ punsafeCoerce datum
@ -45,8 +50,16 @@ makeEffect gatCs' f =
gatCs <- plet $ pconstant gatCs' 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 ())
)

View file

@ -18,14 +18,16 @@ module Agora.Governor (
governorValidator, governorValidator,
) where ) where
import Agora.Proposal (ProposalThresholds) import Agora.Proposal (ProposalTag, ProposalThresholds)
import Plutarch (popaque) import Plutarch (popaque)
import Plutarch.Api.V1 (PMintingPolicy, PValidator) import Plutarch.Api.V1 (PMintingPolicy, PValidator)
-- | Datum for the Governor script. -- | Datum for the Governor script.
newtype GovernorDatum = GovernorDatum data GovernorDatum = GovernorDatum
{ proposalThresholds :: ProposalThresholds { proposalThresholds :: ProposalThresholds
-- ^ Gets copied over upon creation of a 'Agora.Proposal.ProposalDatum'. -- ^ 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 {- | Redeemer for Governor script. The governor has two primary

View file

@ -158,7 +158,11 @@ data ProposalDatum = ProposalDatum
PlutusTx.makeIsDataIndexed ''ProposalDatum [('ProposalDatum, 0)] 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} newtype ProposalTag = ProposalTag {proposalTag :: Integer}
deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData) deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData)
deriving stock (Eq, Show, GHC.Generic) deriving stock (Eq, Show, GHC.Generic)

View file

@ -3,7 +3,7 @@ Module : Agora.SafeMoney
Maintainer : emi@haskell.fyi Maintainer : emi@haskell.fyi
Description: Tags and bonuses for Plutarch.SafeMoney. Description: Tags and bonuses for Plutarch.SafeMoney.
Tags and bonuses for "Plutarch.SafeMoney". Tags and extras for "Plutarch.SafeMoney".
-} -}
module Agora.SafeMoney ( module Agora.SafeMoney (
ADATag, ADATag,

View file

@ -100,7 +100,7 @@ newtype Stake = Stake
Vaguely this is the dependency graph for this locking Vaguely this is the dependency graph for this locking
interaction. Both the stake validator and the proposal 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: the datum belonging to the ST:
@ @
@ -143,7 +143,8 @@ data StakeRedeemer
PermitVote ProposalLock PermitVote ProposalLock
| -- | Retract a vote, removing it from the 'lockedBy' field. See 'ProposalLock'. | -- | Retract a vote, removing it from the 'lockedBy' field. See 'ProposalLock'.
-- This action checks for permission of the 'Proposal'. Finished proposals are -- 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] RetractVotes [ProposalLock]
deriving stock (Show, GHC.Generic) deriving stock (Show, GHC.Generic)
@ -166,7 +167,7 @@ data StakeDatum = StakeDatum
-- TODO Support for MultiSig/Scripts is tracked here: -- TODO Support for MultiSig/Scripts is tracked here:
-- https://github.com/Liqwid-Labs/agora/issues/45 -- https://github.com/Liqwid-Labs/agora/issues/45
, lockedBy :: [ProposalLock] , 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. -- for the stake to be usable for deposits and withdrawals.
} }
deriving stock (Show, GHC.Generic) deriving stock (Show, GHC.Generic)

View file

@ -57,7 +57,7 @@ treasuryValidator gatCs' = plam $ \datum redeemer ctx' -> P.do
gatCs <- plet $ pconstant gatCs' gatCs <- plet $ pconstant gatCs'
passert "singleAuthorityTokenBurned" $ singleAuthorityTokenBurned gatCs txInfo' mint passert "A single authority token has been burned" $ singleAuthorityTokenBurned gatCs txInfo' mint
popaque $ pconstant () popaque $ pconstant ()