implement logic to advance proposals
This commit is contained in:
parent
b01b48497c
commit
039fa36620
2 changed files with 102 additions and 10 deletions
|
|
@ -13,11 +13,19 @@ module Agora.Proposal.Scripts (
|
|||
import Agora.Proposal (
|
||||
PProposalDatum (PProposalDatum),
|
||||
PProposalRedeemer (..),
|
||||
PProposalStatus (..),
|
||||
PProposalVotes (PProposalVotes),
|
||||
Proposal (governorSTAssetClass, stakeSTAssetClass),
|
||||
ProposalStatus (VotingReady),
|
||||
ProposalStatus (..),
|
||||
pwinner,
|
||||
)
|
||||
import Agora.Proposal.Time (
|
||||
currentProposalTime,
|
||||
isDraftPeriod,
|
||||
isExecutionPeriod,
|
||||
isLockingPeriod,
|
||||
isVotingPeriod,
|
||||
)
|
||||
import Agora.Proposal.Time (currentProposalTime, isVotingPeriod)
|
||||
import Agora.Stake (PProposalLock (..), PStakeDatum (..), findStakeOwnedBy)
|
||||
import Agora.Utils (
|
||||
findTxOutByTxOutRef,
|
||||
|
|
@ -368,5 +376,89 @@ proposalValidator proposal =
|
|||
PUnlock _r ->
|
||||
popaque (pconstant ())
|
||||
--------------------------------------------------------------------------
|
||||
PAdvanceProposal _r ->
|
||||
popaque (pconstant ())
|
||||
PAdvanceProposal _r -> unTermCont $ do
|
||||
tcassert "No stake input is allowed" $ spentStakeST #== 0
|
||||
|
||||
currentTime <- tclet $ currentProposalTime # txInfoF.validRange
|
||||
proposalOutStatus <- tclet $ pfield @"status" # proposalOut
|
||||
|
||||
thresholdsF <- tcont $ pletFields @'["execute", "draft", "vote"] proposalF.thresholds
|
||||
|
||||
let -- Only the status of proposals should be updated in this case.
|
||||
templateProposalOut =
|
||||
mkRecordConstr
|
||||
PProposalDatum
|
||||
( #proposalId .= proposalF.proposalId
|
||||
.& #effects .= proposalF.effects
|
||||
.& #status .= proposalOutStatus
|
||||
.& #cosigners .= proposalF.cosigners
|
||||
.& #thresholds .= proposalF.thresholds
|
||||
.& #votes .= proposalF.votes
|
||||
.& #timingConfig .= proposalF.timingConfig
|
||||
.& #startingTime .= proposalF.startingTime
|
||||
)
|
||||
|
||||
tcassert "Only status changes in the output proposal" $
|
||||
templateProposalOut #== proposalOut
|
||||
|
||||
inDraftPeriod <- tclet $ isDraftPeriod # proposalF.timingConfig # proposalF.startingTime # currentTime
|
||||
inVotingPeriod <- tclet $ isVotingPeriod # proposalF.timingConfig # proposalF.startingTime # currentTime
|
||||
inLockedPeriod <- tclet $ isLockingPeriod # proposalF.timingConfig # proposalF.startingTime # currentTime
|
||||
inExecutionPeriod <- tclet $ isExecutionPeriod # proposalF.timingConfig # proposalF.startingTime # currentTime
|
||||
|
||||
-- Check the timings.
|
||||
let isFinished = proposalF.status #== pconstantData Finished
|
||||
|
||||
notTooLate = pmatch (pfromData proposalF.status) $ \case
|
||||
PDraft _ -> inDraftPeriod
|
||||
PVotingReady _ -> inVotingPeriod
|
||||
PLocked _ -> inExecutionPeriod
|
||||
_ -> pconstant False
|
||||
|
||||
tcassert "Finished proposals cannnot be advanced" $ pnot # isFinished
|
||||
|
||||
pure $
|
||||
pif
|
||||
notTooLate
|
||||
-- On time: advance to next status.
|
||||
( pmatch (pfromData proposalF.status) $ \case
|
||||
PDraft _ -> unTermCont $ do
|
||||
-- TODO: Perform other necessary checks.
|
||||
|
||||
-- 'Draft' -> 'VotingReady'
|
||||
tcassert "Proposal status set to VotingReady" $
|
||||
proposalOutStatus #== pconstantData VotingReady
|
||||
|
||||
pure $ popaque (pconstant ())
|
||||
PVotingReady _ -> unTermCont $ do
|
||||
-- 'VotingReady' -> 'Locked'
|
||||
tcassert "Proposal status set to Locked" $
|
||||
proposalOutStatus #== pconstantData Locked
|
||||
|
||||
-- Check that the highest votes meet the minimum requirement.
|
||||
let winner = mustBePJust # "Highest votes not found" #$ pwinner # proposalF.votes
|
||||
highestVotes = pfromData $ psndBuiltin # winner
|
||||
|
||||
tcassert "Highest vote count should exceed the threshold" $
|
||||
pto (pto $ pfromData thresholdsF.execute) #< highestVotes
|
||||
|
||||
pure $ popaque (pconstant ())
|
||||
PLocked _ -> unTermCont $ do
|
||||
-- 'Locked' -> 'Finished'
|
||||
tcassert "Proposal status set to Finished" $
|
||||
proposalOutStatus #== pconstantData Finished
|
||||
|
||||
tcassert "Can only unlock after the locking period" $
|
||||
pnot # inLockedPeriod
|
||||
|
||||
-- TODO: Perform other necessary checks.
|
||||
pure $ popaque (pconstant ())
|
||||
_ -> popaque (pconstant ())
|
||||
)
|
||||
-- Too late: failed proposal, status set to 'Finished'.
|
||||
( popaque $
|
||||
ptraceIfFalse "Proposal should fail: not on time" $
|
||||
proposalOutStatus #== pconstantData Finished
|
||||
-- TODO: Should check that the GST is not moved
|
||||
-- if the proposal is in 'Locked' state.
|
||||
)
|
||||
|
|
|
|||
12
bench.csv
12
bench.csv
|
|
@ -2,15 +2,15 @@ name,cpu,mem,size
|
|||
Agora/Effects/Treasury Withdrawal Effect/effect/Simple,340268715,724428,3050
|
||||
Agora/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries ,570029812,1211300,3377
|
||||
Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets,502351827,1071087,3242
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,103830462,228928,7628
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,103830462,228928,7532
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,127968605,266935,3358
|
||||
Agora/Stake/policy/stakeCreation,59776675,126049,2116
|
||||
Agora/Stake/validator/stakeDepositWithdraw deposit,276249331,599197,4024
|
||||
Agora/Stake/validator/stakeDepositWithdraw withdraw,276249331,599197,4016
|
||||
Agora/Proposal/policy/proposalCreation,34784356,68894,1523
|
||||
Agora/Proposal/validator/cosignature/proposal,241204796,510319,4812
|
||||
Agora/Proposal/validator/cosignature/proposal,241651391,511819,5772
|
||||
Agora/Proposal/validator/cosignature/stake,186332635,402961,4561
|
||||
Agora/Proposal/validator/voting/proposal,239645722,489368,4820
|
||||
Agora/Proposal/validator/voting/proposal,240181636,491168,5780
|
||||
Agora/Proposal/validator/voting/stake,154223940,328703,4614
|
||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,25177457,55883,806
|
||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,40266637,88241,900
|
||||
|
|
@ -18,6 +18,6 @@ Agora/Treasury/Validator/Positive/Allows for effect changes,37343572,79744,1841
|
|||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,25177457,55883,806
|
||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,40266637,88241,900
|
||||
Agora/Governor/policy/GST minting,57978053,120125,1833
|
||||
Agora/Governor/validator/proposal creation,330344593,681815,8143
|
||||
Agora/Governor/validator/GATs minting,431952116,934409,8266
|
||||
Agora/Governor/validator/mutate governor state,101019422,223202,7685
|
||||
Agora/Governor/validator/proposal creation,330344593,681815,8047
|
||||
Agora/Governor/validator/GATs minting,431297108,932207,8170
|
||||
Agora/Governor/validator/mutate governor state,101019422,223202,7589
|
||||
|
|
|
|||
|
Loading…
Add table
Add a link
Reference in a new issue