From dfbbb4aea3b6458dc47cc5e5db69da6dd6264f95 Mon Sep 17 00:00:00 2001 From: Hongrui Fang Date: Wed, 20 Apr 2022 12:55:43 +0800 Subject: [PATCH] plet proposal symbol; clean up stuff a little bit --- agora/Agora/Governor.hs | 39 +++++++++++++++------------------------ agora/Agora/Proposal.hs | 1 + agora/Agora/Utils.hs | 5 +++++ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/agora/Agora/Governor.hs b/agora/Agora/Governor.hs index 0f99de1..999f67c 100644 --- a/agora/Agora/Governor.hs +++ b/agora/Agora/Governor.hs @@ -33,7 +33,7 @@ import Generics.SOP (Generic, I (I)) -------------------------------------------------------------------------------- -import Agora.AuthorityToken (authorityTokensValidIn) +import Agora.AuthorityToken (singleAuthorityTokenBurned) import Agora.Proposal ( PProposalDatum, PProposalId, @@ -47,7 +47,6 @@ import Agora.Proposal ( proposalValidator, ) import Agora.Utils ( - allInputs, findOutputsToAddress, hasOnlyOneTokenOfCurrencySymbol, mustFindDatum', @@ -59,6 +58,7 @@ import Agora.Utils ( pisUxtoSpent, pownCurrencySymbol, psymbolValueOf, + containsSingleCurrencySymbol ) -------------------------------------------------------------------------------- @@ -216,7 +216,7 @@ governorPolicy params = #&& passetClassValueOf # ownSymbol # pconstant governorStateTokenName # mintValue #== 1 passert "Nothing is minted other than the state token" $ - (plength #$ pto $ pto $ pto mintValue) #== 1 + containsSingleCurrencySymbol # mintValue popaque (pconstant ()) @@ -282,18 +282,16 @@ governorValidator params = newParams <- pletFields @'["proposalThresholds", "nextProposalId"] newDatum' mint <- plet $ pfromData $ pfield @"mint" # txInfo - mint' <- plet $ pto $ pto $ pto mint case redeemer of PCreateProposal _ -> P.do - -- check that proposal is advanced + pSym <- plet $ pconstant proposalSymbol + passert "Proposal id should be advanced by 1" $ 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" $ - hasOnlyOneTokenOfCurrencySymbol # pps # mint + hasOnlyOneTokenOfCurrencySymbol # pSym # mint outputs <- plet $ findOutputsToAddress # ctx.txInfo # pconstant proposalValidatorAddress passert "Exactly one utxo should be sent to the proposal validator" $ @@ -301,7 +299,7 @@ governorValidator params = output <- pletFields @'["value", "datumHash"] $ phead # outputs 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" $ pisDJust # output.datumHash @@ -334,32 +332,25 @@ governorValidator params = passert "Initial proposal cosigners should be empty" $ pnull #$ pfromData proposalParams.cosigners + -- TODO: proposal impl not done yet ptraceError "Not implemented yet" PMintGATs _ -> P.do -- check datum is not changed passert "Datum should not be changed" $ (pforgetData $ pdata newDatum') #== datum' + -- TODO: any need to check the proposal datum here? + -- check exactly one(?) authority token is minted -- TODO: waiting for impl of proposal ptraceError "Not implemented yet" 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" $ - plength # mint' #== 1 + containsSingleCurrencySymbol # mint + + popaque $ singleAuthorityTokenBurned gatSym ctx.txInfo mint - -- check that GAT is tagged by the address - passert "all input GATs are valid" $ - allInputs @PUnit # txInfo #$ plam $ \txOut _ _ _ -> - authorityTokensValidIn # gatS # txOut - - popaque $ pconstant () where stateTokenAssetClass :: AssetClass stateTokenAssetClass = governorStateTokenAssetClass params @@ -388,8 +379,8 @@ governorValidator params = stateTokenValueOf :: Term s (PValue :--> PInteger) stateTokenValueOf = passetClassValueOf' stateTokenAssetClass - gatS :: Term s PCurrencySymbol - gatS = pconstant params.gatSymbol + gatSym :: Term s PCurrencySymbol + gatSym = pconstant params.gatSymbol -------------------------------------------------------------------------------- diff --git a/agora/Agora/Proposal.hs b/agora/Agora/Proposal.hs index ef50e33..7a01b5e 100644 --- a/agora/Agora/Proposal.hs +++ b/agora/Agora/Proposal.hs @@ -439,6 +439,7 @@ proposalDatumValid proposal = ] -------------------------------------------------------------------------------- + -- | Get next proposal id. pnextProposalId :: Term s (PProposalId :--> PProposalId) pnextProposalId = phoistAcyclic $ plam $ \(pto -> pid) -> pcon $ PProposalId $ pid + 1 diff --git a/agora/Agora/Utils.hs b/agora/Agora/Utils.hs index 13c3eb6..bdff4f2 100644 --- a/agora/Agora/Utils.hs +++ b/agora/Agora/Utils.hs @@ -47,6 +47,7 @@ module Agora.Utils ( hasOnlyOneTokenOfAssetClass', hasOnlyOneTokenOfCurrencySymbol, mustFindDatum', + containsSingleCurrencySymbol ) where -------------------------------------------------------------------------------- @@ -550,3 +551,7 @@ mustFindDatum' = phoistAcyclic $ PDJust ((pfield @"_0" #) -> dh) <- pmatch mdh PJust dt <- pmatch $ pfindDatum # dh # info pfromData $ punsafeCoerce dt + +containsSingleCurrencySymbol :: Term s (PValue :--> PBool) +containsSingleCurrencySymbol = phoistAcyclic $ plam $ \v -> P.do + (plength #$ pto $ pto $ pto v) #== 1 \ No newline at end of file