store proposal timing conf in the governor datum
This commit is contained in:
parent
50bf78aae8
commit
fbe3edc45a
7 changed files with 32 additions and 30 deletions
|
|
@ -67,13 +67,13 @@ import Agora.Stake (
|
|||
import Sample.Shared (
|
||||
authorityTokenSymbol,
|
||||
defaultProposalThresholds,
|
||||
defaultProposalTimingConfig,
|
||||
govAssetClass,
|
||||
govSymbol,
|
||||
govValidatorAddress,
|
||||
gstUTXORef,
|
||||
minAda,
|
||||
proposalPolicySymbol,
|
||||
proposalTimingConfig,
|
||||
proposalValidatorAddress,
|
||||
signer,
|
||||
signer2,
|
||||
|
|
@ -114,6 +114,7 @@ mintGST =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
governorOutputDatum :: Datum
|
||||
governorOutputDatum = Datum $ toBuiltinData governorOutputDatum'
|
||||
|
|
@ -207,6 +208,7 @@ createProposal =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = thisProposalId
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
@ -236,7 +238,7 @@ createProposal =
|
|||
, cosigners = [signer]
|
||||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = proposalTimingConfig
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
}
|
||||
)
|
||||
|
|
@ -378,6 +380,7 @@ mintGATs =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 5
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
@ -412,7 +415,7 @@ mintGATs =
|
|||
, cosigners = [signer, signer2]
|
||||
, thresholds = defaultProposalThresholds
|
||||
, votes = proposalVotes
|
||||
, timingConfig = proposalTimingConfig
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
}
|
||||
proposalInputDatum :: Datum
|
||||
|
|
@ -565,6 +568,7 @@ mutateState =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 5
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import Plutus.V1.Ledger.Value qualified as Value
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
import Agora.Governor (
|
||||
GovernorDatum (GovernorDatum, nextProposalId, proposalThresholds),
|
||||
GovernorDatum (..),
|
||||
)
|
||||
import Agora.Proposal (
|
||||
Proposal (..),
|
||||
|
|
@ -79,7 +79,7 @@ proposalCreation =
|
|||
, cosigners = [signer]
|
||||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = proposalTimingConfig
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
}
|
||||
)
|
||||
|
|
@ -91,6 +91,7 @@ proposalCreation =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
)
|
||||
govAfter :: Datum
|
||||
|
|
@ -100,6 +101,7 @@ proposalCreation =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 1
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
}
|
||||
)
|
||||
in ScriptContext
|
||||
|
|
@ -174,7 +176,7 @@ cosignProposal newSigners =
|
|||
, cosigners = [signer]
|
||||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = proposalTimingConfig
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
}
|
||||
stakeDatum :: StakeDatum
|
||||
|
|
@ -185,7 +187,7 @@ cosignProposal newSigners =
|
|||
validTimeRange =
|
||||
closedBoundedInterval
|
||||
10
|
||||
(proposalTimingConfig.draftTime - 10)
|
||||
(defaultProposalTimingConfig.draftTime - 10)
|
||||
in TxInfo
|
||||
{ txInfoInputs =
|
||||
[ TxInInfo
|
||||
|
|
@ -295,7 +297,7 @@ voteOnProposal params =
|
|||
, cosigners = [stakeOwner]
|
||||
, thresholds = defaultProposalThresholds
|
||||
, votes = ProposalVotes initialVotes
|
||||
, timingConfig = proposalTimingConfig
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
}
|
||||
proposalInputDatum :: Datum
|
||||
|
|
@ -384,7 +386,7 @@ voteOnProposal params =
|
|||
---
|
||||
|
||||
validTimeRange =
|
||||
closedBoundedInterval (proposalTimingConfig.draftTime + 1) (proposalTimingConfig.votingTime - 1)
|
||||
closedBoundedInterval (defaultProposalTimingConfig.draftTime + 1) (defaultProposalTimingConfig.votingTime - 1)
|
||||
in TxInfo
|
||||
{ txInfoInputs =
|
||||
[ TxInInfo proposalRef proposalInput
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ module Sample.Shared (
|
|||
proposalPolicySymbol,
|
||||
proposalValidatorHash,
|
||||
proposalValidatorAddress,
|
||||
proposalTimingConfig,
|
||||
defaultProposalTimingConfig,
|
||||
tmpProposalStartingTime,
|
||||
|
||||
-- ** Authority
|
||||
|
|
@ -190,8 +190,8 @@ authorityToken = authorityTokenFromGovernor governor
|
|||
authorityTokenSymbol :: CurrencySymbol
|
||||
authorityTokenSymbol = authorityTokenSymbolFromGovernor governor
|
||||
|
||||
proposalTimingConfig :: ProposalTimingConfig
|
||||
proposalTimingConfig =
|
||||
defaultProposalTimingConfig :: ProposalTimingConfig
|
||||
defaultProposalTimingConfig =
|
||||
ProposalTimingConfig
|
||||
{ draftTime = 50
|
||||
, votingTime = 1000
|
||||
|
|
|
|||
|
|
@ -38,19 +38,19 @@ tests =
|
|||
[ validatorSucceedsWith
|
||||
"proposal creation"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 0))
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 0) Shared.defaultProposalTimingConfig)
|
||||
CreateProposal
|
||||
createProposal
|
||||
, validatorSucceedsWith
|
||||
"GATs minting"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5))
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig)
|
||||
MintGATs
|
||||
mintGATs
|
||||
, validatorSucceedsWith
|
||||
"mutate governor state"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5))
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig)
|
||||
MutateGovernor
|
||||
mutateState
|
||||
]
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ tests =
|
|||
[ (ResultTag 0, AssocMap.empty)
|
||||
, (ResultTag 1, AssocMap.empty)
|
||||
]
|
||||
, timingConfig = Shared.proposalTimingConfig
|
||||
, timingConfig = Shared.defaultProposalTimingConfig
|
||||
, startingTime = Shared.tmpProposalStartingTime
|
||||
}
|
||||
)
|
||||
|
|
@ -117,7 +117,7 @@ tests =
|
|||
, (ResultTag 1, 4242)
|
||||
]
|
||||
)
|
||||
, timingConfig = Shared.proposalTimingConfig
|
||||
, timingConfig = Shared.defaultProposalTimingConfig
|
||||
, startingTime = Shared.tmpProposalStartingTime
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import Agora.Proposal (
|
|||
ProposalId (ProposalId),
|
||||
ProposalThresholds,
|
||||
)
|
||||
import Agora.Proposal.Time (PProposalTimingConfig, ProposalTimingConfig)
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.Utils (tclet)
|
||||
|
||||
|
|
@ -66,6 +67,9 @@ data GovernorDatum = GovernorDatum
|
|||
-- ^ Gets copied over upon creation of a 'Agora.Proposal.ProposalDatum'.
|
||||
, nextProposalId :: ProposalId
|
||||
-- ^ What tag the next proposal will get upon creating.
|
||||
, proposalTimings :: ProposalTimingConfig
|
||||
-- ^ The timing configuration for proposals.
|
||||
-- Will get copied over upon the creation of proposals.
|
||||
}
|
||||
deriving stock (Show, GHC.Generic)
|
||||
|
||||
|
|
@ -118,6 +122,7 @@ newtype PGovernorDatum (s :: S) = PGovernorDatum
|
|||
( PDataRecord
|
||||
'[ "proposalThresholds" ':= PProposalThresholds
|
||||
, "nextProposalId" ':= PProposalId
|
||||
, "proposalTimings" ':= PProposalTimingConfig
|
||||
]
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ import Plutarch.TryFrom (ptryFrom)
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
import Agora.Proposal.Time (ProposalStartingTime (..), ProposalTimingConfig (..))
|
||||
import Agora.Proposal.Time (ProposalStartingTime (..))
|
||||
import Plutus.V1.Ledger.Api (
|
||||
CurrencySymbol (..),
|
||||
MintingPolicy,
|
||||
|
|
@ -300,7 +300,7 @@ governorValidator gov =
|
|||
let ownAddress = pfromData $ ownInputF.address
|
||||
|
||||
(pfromData -> (oldGovernorDatum :: Term _ PGovernorDatum), _) <- tcont $ ptryFrom datum'
|
||||
oldGovernorDatumF <- tcont $ pletFields @'["proposalThresholds", "nextProposalId"] oldGovernorDatum
|
||||
oldGovernorDatumF <- tcont $ pletFields @'["proposalThresholds", "nextProposalId", "proposalTimings"] oldGovernorDatum
|
||||
|
||||
-- Check that GST will be returned to the governor.
|
||||
let ownInputGSTAmount = psymbolValueOf # pgstSymbol # ownInputF.value
|
||||
|
|
@ -337,6 +337,7 @@ governorValidator gov =
|
|||
PGovernorDatum
|
||||
( #proposalThresholds .= oldGovernorDatumF.proposalThresholds
|
||||
.& #nextProposalId .= pdata expectedNextProposalId
|
||||
.& #proposalTimings .= oldGovernorDatumF.proposalTimings
|
||||
)
|
||||
tcassert "Unexpected governor state datum" $
|
||||
newGovernorDatum #== expectedNewDatum
|
||||
|
|
@ -578,7 +579,7 @@ governorValidator gov =
|
|||
.& #thresholds .= proposalInputDatumF.thresholds
|
||||
.& #votes .= proposalInputDatumF.votes
|
||||
-- FIXME: copy from the governor datum
|
||||
.& #timingConfig .= pdata (pconstant tmpTimingConfig)
|
||||
.& #timingConfig .= oldGovernorDatumF.proposalTimings
|
||||
-- FIXME: calculate from 'txInfoValidRange'
|
||||
.& #startingTime .= pdata (pconstant tmpProposalStartingTime)
|
||||
)
|
||||
|
|
@ -732,16 +733,6 @@ governorValidator gov =
|
|||
let sym = governorSTSymbolFromGovernor gov
|
||||
in phoistAcyclic $ pconstant sym
|
||||
|
||||
-- TODO: remove this. This is temperary.
|
||||
tmpTimingConfig :: ProposalTimingConfig
|
||||
tmpTimingConfig =
|
||||
ProposalTimingConfig
|
||||
{ draftTime = 50
|
||||
, votingTime = 1000
|
||||
, lockingTime = 2000
|
||||
, executingTime = 3000
|
||||
}
|
||||
|
||||
-- TODO: remove this.
|
||||
tmpProposalStartingTime :: ProposalStartingTime
|
||||
tmpProposalStartingTime = ProposalStartingTime 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue