correct validation logic for proposals
* simplify using newly added util functions * check vote thresholds * Anything else to check here?
This commit is contained in:
parent
034fc397df
commit
6a5ce88972
1 changed files with 15 additions and 13 deletions
|
|
@ -43,7 +43,6 @@ import Agora.AuthorityToken (
|
||||||
import Agora.Proposal (
|
import Agora.Proposal (
|
||||||
PProposalDatum,
|
PProposalDatum,
|
||||||
PProposalId,
|
PProposalId,
|
||||||
PProposalStatus (PDraft),
|
|
||||||
PProposalThresholds,
|
PProposalThresholds,
|
||||||
PProposalVotes (PProposalVotes),
|
PProposalVotes (PProposalVotes),
|
||||||
PResultTag (PResultTag),
|
PResultTag (PResultTag),
|
||||||
|
|
@ -65,7 +64,6 @@ import Agora.Utils (
|
||||||
passert,
|
passert,
|
||||||
passetClassValueOf,
|
passetClassValueOf,
|
||||||
passetClassValueOf',
|
passetClassValueOf',
|
||||||
pfindDatum,
|
|
||||||
pfindTxInByTxOutRef,
|
pfindTxInByTxOutRef,
|
||||||
pisDJust,
|
pisDJust,
|
||||||
pisUxtoSpent,
|
pisUxtoSpent,
|
||||||
|
|
@ -78,21 +76,17 @@ import Agora.Utils (
|
||||||
|
|
||||||
import Plutarch (popaque)
|
import Plutarch (popaque)
|
||||||
import Plutarch.Api.V1 (
|
import Plutarch.Api.V1 (
|
||||||
PAddress,
|
|
||||||
PCurrencySymbol,
|
PCurrencySymbol,
|
||||||
PDatumHash,
|
|
||||||
PMaybeData (PDJust),
|
|
||||||
PMintingPolicy,
|
PMintingPolicy,
|
||||||
PScriptPurpose (PSpending),
|
PScriptPurpose (PSpending),
|
||||||
PValidator,
|
PValidator,
|
||||||
PValidatorHash,
|
|
||||||
PValue,
|
PValue,
|
||||||
mintingPolicySymbol,
|
mintingPolicySymbol,
|
||||||
mkMintingPolicy,
|
mkMintingPolicy,
|
||||||
mkValidator,
|
mkValidator,
|
||||||
validatorHash,
|
validatorHash,
|
||||||
)
|
)
|
||||||
import Plutarch.Api.V1.Extra (pownMintValue)
|
import Plutarch.Api.V1.Extra (passetClass, passetClassValueOf, pownMintValue)
|
||||||
import Plutarch.DataRepr (
|
import Plutarch.DataRepr (
|
||||||
DerivePConstantViaData (..),
|
DerivePConstantViaData (..),
|
||||||
PDataFields,
|
PDataFields,
|
||||||
|
|
@ -104,8 +98,9 @@ import Plutarch.Unsafe (punsafeCoerce)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
import Plutarch.Builtin (PBuiltinMap, pforgetData)
|
import Plutarch.Builtin (pforgetData)
|
||||||
import Plutarch.Map.Extra (plookup, plookup')
|
import Plutarch.Map.Extra (plookup, plookup')
|
||||||
|
import Plutarch.SafeMoney (puntag)
|
||||||
import Plutus.V1.Ledger.Api (
|
import Plutus.V1.Ledger.Api (
|
||||||
Address (Address),
|
Address (Address),
|
||||||
Credential (ScriptCredential),
|
Credential (ScriptCredential),
|
||||||
|
|
@ -255,6 +250,7 @@ governorPolicy params =
|
||||||
For 'MintGATs' redeemer, it will check:
|
For 'MintGATs' redeemer, it will check:
|
||||||
- State datum is not changed.
|
- State datum is not changed.
|
||||||
- Exactly one proposal is being processed.
|
- Exactly one proposal is being processed.
|
||||||
|
- Select the right effect group.
|
||||||
- Mint one GAT for every effect.
|
- Mint one GAT for every effect.
|
||||||
- The GATs is properly tagged. (Should we do this?)
|
- The GATs is properly tagged. (Should we do this?)
|
||||||
- The GATs are sent to the appropraite effects. (Should we do this?)
|
- The GATs are sent to the appropraite effects. (Should we do this?)
|
||||||
|
|
@ -381,13 +377,20 @@ governorValidator params =
|
||||||
|
|
||||||
proposalDatum <- pletFields @'["id", "effects", "status", "cosigners", "thresholds", "votes"] proposalDatum'
|
proposalDatum <- pletFields @'["id", "effects", "status", "cosigners", "thresholds", "votes"] proposalDatum'
|
||||||
|
|
||||||
|
-- TODO: something else to check here?
|
||||||
|
|
||||||
PProposalVotes votes' <- pmatch $ pfromData proposalDatum.votes
|
PProposalVotes votes' <- pmatch $ pfromData proposalDatum.votes
|
||||||
votes <- plet votes'
|
votes <- plet votes'
|
||||||
|
|
||||||
let yesVotes = plookup' # pyesResultTag # votes
|
let minimumVotes = puntag $ pfromData $ pfield @"execute" # proposalDatum.thresholds
|
||||||
|
|
||||||
|
yesVotes = plookup' # pyesResultTag # votes
|
||||||
noVotes = plookup' # pnoResultTag # votes
|
noVotes = plookup' # pnoResultTag # votes
|
||||||
-- TODO: check thresholds here
|
biggerVotes = pif (yesVotes #< noVotes) noVotes yesVotes
|
||||||
finalResultTag = pif (yesVotes #< noVotes) pnoResultTag pyesResultTag
|
|
||||||
|
passert "Votes should be more than mininum votes" $ minimumVotes #< biggerVotes
|
||||||
|
|
||||||
|
let finalResultTag = pif (yesVotes #< noVotes) pnoResultTag pyesResultTag
|
||||||
|
|
||||||
effects <- plet $ plookup' # finalResultTag #$ proposalDatum.effects
|
effects <- plet $ plookup' # finalResultTag #$ proposalDatum.effects
|
||||||
|
|
||||||
|
|
@ -420,7 +423,7 @@ governorValidator params =
|
||||||
datumHash =
|
datumHash =
|
||||||
mustBePDJust # "Output to effect should have datum"
|
mustBePDJust # "Output to effect should have datum"
|
||||||
#$ output.datumHash
|
#$ output.datumHash
|
||||||
|
|
||||||
expectedDatumHash =
|
expectedDatumHash =
|
||||||
mustBePJust # "Receiver is not in effect list"
|
mustBePJust # "Receiver is not in effect list"
|
||||||
#$ plookup # scriptHash # effects
|
#$ plookup # scriptHash # effects
|
||||||
|
|
@ -432,7 +435,6 @@ governorValidator params =
|
||||||
# (pconstant ())
|
# (pconstant ())
|
||||||
# outputsWithGAT
|
# outputsWithGAT
|
||||||
|
|
||||||
-- TODO: check proposal votes and timing
|
|
||||||
-- TODO: waiting for impl of proposal
|
-- TODO: waiting for impl of proposal
|
||||||
PMutateGovernor _ -> P.do
|
PMutateGovernor _ -> P.do
|
||||||
passert "No token should be burnt other than GAT" $
|
passert "No token should be burnt other than GAT" $
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue