apply Jack's PR suggestions

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

View file

@ -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 ())
)

View file

@ -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

View file

@ -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)

View file

@ -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,

View file

@ -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)

View file

@ -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 ()