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