plet proposal symbol; clean up stuff a little bit

This commit is contained in:
Hongrui Fang 2022-04-20 12:55:43 +08:00 committed by fanghr
parent ff227bcbf5
commit ce4922beb3
3 changed files with 21 additions and 24 deletions

View file

@ -33,7 +33,7 @@ import Generics.SOP (Generic, I (I))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Agora.AuthorityToken (authorityTokensValidIn) import Agora.AuthorityToken (singleAuthorityTokenBurned)
import Agora.Proposal ( import Agora.Proposal (
PProposalDatum, PProposalDatum,
PProposalId, PProposalId,
@ -47,7 +47,6 @@ import Agora.Proposal (
proposalValidator, proposalValidator,
) )
import Agora.Utils ( import Agora.Utils (
allInputs,
findOutputsToAddress, findOutputsToAddress,
hasOnlyOneTokenOfCurrencySymbol, hasOnlyOneTokenOfCurrencySymbol,
mustFindDatum', mustFindDatum',
@ -59,6 +58,7 @@ import Agora.Utils (
pisUxtoSpent, pisUxtoSpent,
pownCurrencySymbol, pownCurrencySymbol,
psymbolValueOf, psymbolValueOf,
containsSingleCurrencySymbol
) )
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -216,7 +216,7 @@ governorPolicy params =
#&& passetClassValueOf # ownSymbol # pconstant governorStateTokenName # mintValue #== 1 #&& passetClassValueOf # ownSymbol # pconstant governorStateTokenName # mintValue #== 1
passert "Nothing is minted other than the state token" $ passert "Nothing is minted other than the state token" $
(plength #$ pto $ pto $ pto mintValue) #== 1 containsSingleCurrencySymbol # mintValue
popaque (pconstant ()) popaque (pconstant ())
@ -282,18 +282,16 @@ governorValidator params =
newParams <- pletFields @'["proposalThresholds", "nextProposalId"] newDatum' newParams <- pletFields @'["proposalThresholds", "nextProposalId"] newDatum'
mint <- plet $ pfromData $ pfield @"mint" # txInfo mint <- plet $ pfromData $ pfield @"mint" # txInfo
mint' <- plet $ pto $ pto $ pto mint
case redeemer of case redeemer of
PCreateProposal _ -> P.do PCreateProposal _ -> P.do
-- check that proposal is advanced pSym <- plet $ pconstant proposalSymbol
passert "Proposal id should be advanced by 1" $ passert "Proposal id should be advanced by 1" $
pnextProposalId # oldParams.nextProposalId #== newParams.nextProposalId pnextProposalId # oldParams.nextProposalId #== newParams.nextProposalId
-- check that exactly one proposal token is minted
pps <- plet $ pconstant proposalSymbol
passert "Exactly one proposal token must be minted" $ passert "Exactly one proposal token must be minted" $
hasOnlyOneTokenOfCurrencySymbol # pps # mint hasOnlyOneTokenOfCurrencySymbol # pSym # mint
outputs <- plet $ findOutputsToAddress # ctx.txInfo # pconstant proposalValidatorAddress outputs <- plet $ findOutputsToAddress # ctx.txInfo # pconstant proposalValidatorAddress
passert "Exactly one utxo should be sent to the proposal validator" $ passert "Exactly one utxo should be sent to the proposal validator" $
@ -301,7 +299,7 @@ governorValidator params =
output <- pletFields @'["value", "datumHash"] $ phead # outputs output <- pletFields @'["value", "datumHash"] $ phead # outputs
passert "The proposal state token must be sent to the proposal validator" $ passert "The proposal state token must be sent to the proposal validator" $
psymbolValueOf # pconstant proposalSymbol # output.value #== 1 psymbolValueOf # pSym # output.value #== 1
passert "The utxo paid to the proposal validator must have datum" $ passert "The utxo paid to the proposal validator must have datum" $
pisDJust # output.datumHash pisDJust # output.datumHash
@ -334,32 +332,25 @@ governorValidator params =
passert "Initial proposal cosigners should be empty" $ passert "Initial proposal cosigners should be empty" $
pnull #$ pfromData proposalParams.cosigners pnull #$ pfromData proposalParams.cosigners
-- TODO: proposal impl not done yet
ptraceError "Not implemented yet" ptraceError "Not implemented yet"
PMintGATs _ -> P.do PMintGATs _ -> P.do
-- check datum is not changed -- check datum is not changed
passert "Datum should not be changed" $ passert "Datum should not be changed" $
(pforgetData $ pdata newDatum') #== datum' (pforgetData $ pdata newDatum') #== datum'
-- TODO: any need to check the proposal datum here?
-- check exactly one(?) authority token is minted -- check exactly one(?) authority token is minted
-- TODO: waiting for impl of proposal -- TODO: waiting for impl of proposal
ptraceError "Not implemented yet" ptraceError "Not implemented yet"
PMutateGovernor _ -> P.do PMutateGovernor _ -> P.do
-- check that input has exactly one GAT and will be burnt
let gatAmount = psymbolValueOf # gatS # mint
passert "One GAT should be burnt" $
gatAmount #== -1
-- nothing should be minted/burnt other than GAT
passert "No token should be minted/burnt other than GAT" $ passert "No token should be minted/burnt other than GAT" $
plength # mint' #== 1 containsSingleCurrencySymbol # mint
-- check that GAT is tagged by the address popaque $ singleAuthorityTokenBurned gatSym ctx.txInfo mint
passert "all input GATs are valid" $
allInputs @PUnit # txInfo #$ plam $ \txOut _ _ _ ->
authorityTokensValidIn # gatS # txOut
popaque $ pconstant ()
where where
stateTokenAssetClass :: AssetClass stateTokenAssetClass :: AssetClass
stateTokenAssetClass = governorStateTokenAssetClass params stateTokenAssetClass = governorStateTokenAssetClass params
@ -388,8 +379,8 @@ governorValidator params =
stateTokenValueOf :: Term s (PValue :--> PInteger) stateTokenValueOf :: Term s (PValue :--> PInteger)
stateTokenValueOf = passetClassValueOf' stateTokenAssetClass stateTokenValueOf = passetClassValueOf' stateTokenAssetClass
gatS :: Term s PCurrencySymbol gatSym :: Term s PCurrencySymbol
gatS = pconstant params.gatSymbol gatSym = pconstant params.gatSymbol
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -439,6 +439,7 @@ proposalDatumValid proposal =
] ]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Get next proposal id. -- | Get next proposal id.
pnextProposalId :: Term s (PProposalId :--> PProposalId) pnextProposalId :: Term s (PProposalId :--> PProposalId)
pnextProposalId = phoistAcyclic $ plam $ \(pto -> pid) -> pcon $ PProposalId $ pid + 1 pnextProposalId = phoistAcyclic $ plam $ \(pto -> pid) -> pcon $ PProposalId $ pid + 1

View file

@ -47,6 +47,7 @@ module Agora.Utils (
hasOnlyOneTokenOfAssetClass', hasOnlyOneTokenOfAssetClass',
hasOnlyOneTokenOfCurrencySymbol, hasOnlyOneTokenOfCurrencySymbol,
mustFindDatum', mustFindDatum',
containsSingleCurrencySymbol
) where ) where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -550,3 +551,7 @@ mustFindDatum' = phoistAcyclic $
PDJust ((pfield @"_0" #) -> dh) <- pmatch mdh PDJust ((pfield @"_0" #) -> dh) <- pmatch mdh
PJust dt <- pmatch $ pfindDatum # dh # info PJust dt <- pmatch $ pfindDatum # dh # info
pfromData $ punsafeCoerce dt pfromData $ punsafeCoerce dt
containsSingleCurrencySymbol :: Term s (PValue :--> PBool)
containsSingleCurrencySymbol = phoistAcyclic $ plam $ \v -> P.do
(plength #$ pto $ pto $ pto v) #== 1