update doc string for the 'governorValidator'
This commit is contained in:
parent
d3c05c1dc2
commit
1b8d322cf4
1 changed files with 34 additions and 32 deletions
|
|
@ -42,7 +42,7 @@ import Agora.AuthorityToken (
|
||||||
import Agora.Proposal (
|
import Agora.Proposal (
|
||||||
PProposalDatum,
|
PProposalDatum,
|
||||||
PProposalId,
|
PProposalId,
|
||||||
PProposalStatus (PExecutable, PFinished, PVotingReady, PDraft),
|
PProposalStatus (PExecutable, PFinished, PDraft),
|
||||||
PProposalThresholds,
|
PProposalThresholds,
|
||||||
PProposalVotes (PProposalVotes),
|
PProposalVotes (PProposalVotes),
|
||||||
PResultTag (PResultTag),
|
PResultTag (PResultTag),
|
||||||
|
|
@ -159,11 +159,15 @@ PlutusTx.makeIsDataIndexed
|
||||||
, ('MutateMutateGovernor, 2)
|
, ('MutateMutateGovernor, 2)
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Parameters for creating Governor scripts.
|
{- | Parameters for creating Governor scripts.
|
||||||
|
|
||||||
|
Governance State Token, aka GST, is an NFT which idetifies the governance state utxo.
|
||||||
|
-}
|
||||||
data Governor = Governor
|
data Governor = Governor
|
||||||
{ stORef :: TxOutRef
|
{ gstORef :: TxOutRef
|
||||||
-- ^ An utxo, which will be spent to mint the state token for the governor validator.
|
-- ^ Referenced utxo will be spent to mint the GST
|
||||||
, stName :: TokenName
|
, gstName :: TokenName
|
||||||
|
-- ^ Name of the GST token
|
||||||
}
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -207,20 +211,19 @@ deriving via (DerivePConstantViaData GovernorRedeemer PGovernorRedeemer) instanc
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
{- | Policy for Governors.
|
{- | Policy for Governors.
|
||||||
This policy mints a state token for the 'governorValidator'.
|
This policy mints a GST. It perform the following checks:
|
||||||
It will check:
|
|
||||||
|
|
||||||
- The utxo specified in the Governor parameter is spent.
|
- The utxo specified in the Governor parameter is spent.
|
||||||
- Only one token is minted.
|
- Only one token is minted.
|
||||||
- Ensure the token name is 'stName'.
|
- Ensure the token name is 'gstName'.
|
||||||
-}
|
-}
|
||||||
governorPolicy :: Governor -> ClosedTerm PMintingPolicy
|
governorPolicy :: Governor -> ClosedTerm PMintingPolicy
|
||||||
governorPolicy params =
|
governorPolicy params =
|
||||||
plam $ \_ ctx' -> P.do
|
plam $ \_ ctx' -> P.do
|
||||||
ctx <- pletFields @'["txInfo", "purpose"] ctx'
|
ctx <- pletFields @'["txInfo", "purpose"] ctx'
|
||||||
let oref = pconstant params.stORef
|
let oref = pconstant params.gstORef
|
||||||
ownSymbol = pownCurrencySymbol # ctx'
|
ownSymbol = pownCurrencySymbol # ctx'
|
||||||
ownAssetClass = passetClass # ownSymbol # pconstant params.stName
|
ownAssetClass = passetClass # ownSymbol # pconstant params.gstName
|
||||||
|
|
||||||
mintValue <- plet $ pownMintValue # ctx'
|
mintValue <- plet $ pownMintValue # ctx'
|
||||||
|
|
||||||
|
|
@ -234,31 +237,29 @@ governorPolicy params =
|
||||||
|
|
||||||
{- Validator for Governors.
|
{- Validator for Governors.
|
||||||
|
|
||||||
A state token, minted by 'governorPolicy' is used to identify the datum utxo.
|
|
||||||
|
|
||||||
No matter what redeemer it receives, it will always check:
|
No matter what redeemer it receives, it will always check:
|
||||||
- The utxo which has the state token must be spent.
|
- The utxo which has the GST must be spent.
|
||||||
- The state token always stays at the script address.
|
- The GST always stays at the script address.
|
||||||
- The utxo which holds the state token, has a well well-formed 'GovernorDatum' datum.
|
- The state utxo has a valid 'GovernorDatum' datum.
|
||||||
|
|
||||||
For 'CreateProposal' redeemer, it will check:
|
For 'CreateProposal' redeemers, it will check:
|
||||||
- Exactly one proposal state token is minted.
|
- Governance state 'nextProposalId' must be advanced.
|
||||||
- Exactly one utxo should be sent to the proposal validator.
|
- Exactly one proposal state token is minted, or rather, only one proposal is created.
|
||||||
- The utxo must contain the proposal state token.
|
- Exactly one utxo should be sent to the proposal validator. This utxo must contain the proposal state token, and has a valid datum of type 'ProposalDatum'.
|
||||||
- The datum of said utxo must be correct.
|
- Said proposal copies its id and thresholds from the governor, is in draft state, and has zero votes.
|
||||||
- Proposal id in the governor datum must be advanced.
|
|
||||||
|
|
||||||
For 'MintGATs' redeemer, it will check:
|
For 'MintGATs' redeemers, it will check:
|
||||||
- State datum is not changed.
|
- Governance state datum is not changed.
|
||||||
- Exactly one proposal is being processed.
|
- Exactly one proposal(the input proposal) is being processed.
|
||||||
- Select the right effect group.
|
- The input proposal must be in executable state and have required amount of votes.
|
||||||
- Mint one GAT for every effect.
|
- An appropriate effect group is selected to be executed.
|
||||||
- The GATs is properly tagged. (Should we do this?)
|
- A valid GAT is minted and sent to every effect,
|
||||||
- The GATs are sent to the appropraite effects. (Should we do this?)
|
- Exactly one utxo should be sent back to the proposal validator. This utxo must contain the proposal state token, and also has a valid datum of type 'ProposalDatum'(the output proposal).
|
||||||
|
- Said output proposal's status should be `Finished`. Other than that, nothing should be changed compare to the input proposal.
|
||||||
|
|
||||||
For 'MutateGovernor', it will check:
|
For 'MutateGovernors' redeemers, it will check:
|
||||||
- A GAT is burnt.
|
- Exactly one GAT is burnt.
|
||||||
- Said GAT must be tagged by the effect that is spending it.
|
- Said GAT must be valid.
|
||||||
-}
|
-}
|
||||||
governorValidator :: Governor -> ClosedTerm PValidator
|
governorValidator :: Governor -> ClosedTerm PValidator
|
||||||
governorValidator params =
|
governorValidator params =
|
||||||
|
|
@ -411,6 +412,7 @@ governorValidator params =
|
||||||
|
|
||||||
passert "Proposal must be in executable state in order to execute effects" $ isProposalExecutable
|
passert "Proposal must be in executable state in order to execute effects" $ isProposalExecutable
|
||||||
|
|
||||||
|
-- TODO: not sure if I did the right thing, can't use haskell level constructor here
|
||||||
let fields =
|
let fields =
|
||||||
pdcons @"id" # inputProposalDatum.id
|
pdcons @"id" # inputProposalDatum.id
|
||||||
#$ pdcons @"effects" # inputProposalDatum.effects
|
#$ pdcons @"effects" # inputProposalDatum.effects
|
||||||
|
|
@ -528,7 +530,7 @@ governorValidator params =
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
governorStateTokenAssetClass :: Governor -> AssetClass
|
governorStateTokenAssetClass :: Governor -> AssetClass
|
||||||
governorStateTokenAssetClass gov = AssetClass (symbol, gov.stName)
|
governorStateTokenAssetClass gov = AssetClass (symbol, gov.gstName)
|
||||||
where
|
where
|
||||||
policy :: MintingPolicy
|
policy :: MintingPolicy
|
||||||
policy = mkMintingPolicy $ governorPolicy gov
|
policy = mkMintingPolicy $ governorPolicy gov
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue