store timing config in the proposal datum
.... and mock the value upon creation for now
This commit is contained in:
parent
7da72e9398
commit
d44fe083da
8 changed files with 68 additions and 2 deletions
|
|
@ -73,6 +73,7 @@ import Sample.Shared (
|
||||||
gstUTXORef,
|
gstUTXORef,
|
||||||
minAda,
|
minAda,
|
||||||
proposalPolicySymbol,
|
proposalPolicySymbol,
|
||||||
|
proposalTimingConfig,
|
||||||
proposalValidatorAddress,
|
proposalValidatorAddress,
|
||||||
signer,
|
signer,
|
||||||
signer2,
|
signer2,
|
||||||
|
|
@ -234,6 +235,7 @@ createProposal =
|
||||||
, cosigners = [signer]
|
, cosigners = [signer]
|
||||||
, thresholds = defaultProposalThresholds
|
, thresholds = defaultProposalThresholds
|
||||||
, votes = emptyVotesFor effects
|
, votes = emptyVotesFor effects
|
||||||
|
, timingConfig = proposalTimingConfig
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
proposalOutput :: TxOut
|
proposalOutput :: TxOut
|
||||||
|
|
@ -408,6 +410,7 @@ mintGATs =
|
||||||
, cosigners = [signer, signer2]
|
, cosigners = [signer, signer2]
|
||||||
, thresholds = defaultProposalThresholds
|
, thresholds = defaultProposalThresholds
|
||||||
, votes = proposalVotes
|
, votes = proposalVotes
|
||||||
|
, timingConfig = proposalTimingConfig
|
||||||
}
|
}
|
||||||
proposalInputDatum :: Datum
|
proposalInputDatum :: Datum
|
||||||
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'
|
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ proposalCreation =
|
||||||
, cosigners = [signer]
|
, cosigners = [signer]
|
||||||
, thresholds = defaultProposalThresholds
|
, thresholds = defaultProposalThresholds
|
||||||
, votes = emptyVotesFor effects
|
, votes = emptyVotesFor effects
|
||||||
|
, timingConfig = proposalTimingConfig
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -167,6 +168,7 @@ cosignProposal newSigners =
|
||||||
, cosigners = [signer]
|
, cosigners = [signer]
|
||||||
, thresholds = defaultProposalThresholds
|
, thresholds = defaultProposalThresholds
|
||||||
, votes = emptyVotesFor effects
|
, votes = emptyVotesFor effects
|
||||||
|
, timingConfig = proposalTimingConfig
|
||||||
}
|
}
|
||||||
stakeDatum :: StakeDatum
|
stakeDatum :: StakeDatum
|
||||||
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
|
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ module Sample.Shared (
|
||||||
proposalPolicySymbol,
|
proposalPolicySymbol,
|
||||||
proposalValidatorHash,
|
proposalValidatorHash,
|
||||||
proposalValidatorAddress,
|
proposalValidatorAddress,
|
||||||
|
proposalTimingConfig,
|
||||||
|
|
||||||
-- ** Authority
|
-- ** Authority
|
||||||
authorityToken,
|
authorityToken,
|
||||||
|
|
@ -74,6 +75,9 @@ import Agora.Proposal (
|
||||||
Proposal (..),
|
Proposal (..),
|
||||||
ProposalThresholds (..),
|
ProposalThresholds (..),
|
||||||
)
|
)
|
||||||
|
import Agora.Proposal.Time (
|
||||||
|
ProposalTimingConfig (..),
|
||||||
|
)
|
||||||
import Agora.Stake (Stake (..))
|
import Agora.Stake (Stake (..))
|
||||||
import Agora.Treasury (treasuryValidator)
|
import Agora.Treasury (treasuryValidator)
|
||||||
import Agora.Utils (validatorHashToTokenName)
|
import Agora.Utils (validatorHashToTokenName)
|
||||||
|
|
@ -184,6 +188,15 @@ authorityToken = authorityTokenFromGovernor governor
|
||||||
authorityTokenSymbol :: CurrencySymbol
|
authorityTokenSymbol :: CurrencySymbol
|
||||||
authorityTokenSymbol = authorityTokenSymbolFromGovernor governor
|
authorityTokenSymbol = authorityTokenSymbolFromGovernor governor
|
||||||
|
|
||||||
|
proposalTimingConfig :: ProposalTimingConfig
|
||||||
|
proposalTimingConfig =
|
||||||
|
ProposalTimingConfig
|
||||||
|
{ draftTime = 0
|
||||||
|
, votingTime = 1000
|
||||||
|
, lockingTime = 2000
|
||||||
|
, executingTime = 3000
|
||||||
|
}
|
||||||
|
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
|
|
||||||
treasuryOut :: TxOut
|
treasuryOut :: TxOut
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Spec.Proposal (tests) where
|
||||||
|
|
||||||
import Agora.Proposal (
|
import Agora.Proposal (
|
||||||
Proposal (..),
|
Proposal (..),
|
||||||
ProposalDatum (ProposalDatum),
|
ProposalDatum (..),
|
||||||
ProposalId (ProposalId),
|
ProposalId (ProposalId),
|
||||||
ProposalRedeemer (Cosign),
|
ProposalRedeemer (Cosign),
|
||||||
ProposalStatus (Draft),
|
ProposalStatus (Draft),
|
||||||
|
|
@ -77,6 +77,7 @@ tests =
|
||||||
[ (ResultTag 0, AssocMap.empty)
|
[ (ResultTag 0, AssocMap.empty)
|
||||||
, (ResultTag 1, AssocMap.empty)
|
, (ResultTag 1, AssocMap.empty)
|
||||||
]
|
]
|
||||||
|
, timingConfig = Shared.proposalTimingConfig
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
(Cosign [signer2])
|
(Cosign [signer2])
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ import Plutarch.TryFrom (ptryFrom)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import Agora.Proposal.Time (ProposalTimingConfig (..))
|
||||||
import Plutus.V1.Ledger.Api (
|
import Plutus.V1.Ledger.Api (
|
||||||
CurrencySymbol (..),
|
CurrencySymbol (..),
|
||||||
MintingPolicy,
|
MintingPolicy,
|
||||||
|
|
@ -576,6 +577,8 @@ governorValidator gov =
|
||||||
.& #cosigners .= proposalInputDatumF.cosigners
|
.& #cosigners .= proposalInputDatumF.cosigners
|
||||||
.& #thresholds .= proposalInputDatumF.thresholds
|
.& #thresholds .= proposalInputDatumF.thresholds
|
||||||
.& #votes .= proposalInputDatumF.votes
|
.& #votes .= proposalInputDatumF.votes
|
||||||
|
-- FIXME: copy from the governor datum
|
||||||
|
.& #timingConfig .= pdata (pconstant tmpTimingConfig)
|
||||||
)
|
)
|
||||||
|
|
||||||
tcassert "Unexpected output proposal datum" $
|
tcassert "Unexpected output proposal datum" $
|
||||||
|
|
@ -727,6 +730,16 @@ 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 = 0
|
||||||
|
, votingTime = 1000
|
||||||
|
, lockingTime = 2000
|
||||||
|
, executingTime = 3000
|
||||||
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- | Get the 'CurrencySymbol' of GST.
|
-- | Get the 'CurrencySymbol' of GST.
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ import PlutusTx qualified
|
||||||
import PlutusTx.AssocMap qualified as AssocMap
|
import PlutusTx.AssocMap qualified as AssocMap
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import Agora.Proposal.Time (PProposalTimingConfig, ProposalTimingConfig)
|
||||||
import Agora.SafeMoney (GTTag)
|
import Agora.SafeMoney (GTTag)
|
||||||
import Agora.Utils (pkeysEqual, pnotNull)
|
import Agora.Utils (pkeysEqual, pnotNull)
|
||||||
import Control.Applicative (Const)
|
import Control.Applicative (Const)
|
||||||
|
|
@ -186,6 +188,8 @@ data ProposalDatum = ProposalDatum
|
||||||
-- ^ Thresholds copied over on initialization.
|
-- ^ Thresholds copied over on initialization.
|
||||||
, votes :: ProposalVotes
|
, votes :: ProposalVotes
|
||||||
-- ^ Vote tally on the proposal
|
-- ^ Vote tally on the proposal
|
||||||
|
, timingConfig :: ProposalTimingConfig
|
||||||
|
-- ^ Timing configuration copied over on initialization.
|
||||||
}
|
}
|
||||||
deriving stock (Eq, Show, GHC.Generic)
|
deriving stock (Eq, Show, GHC.Generic)
|
||||||
|
|
||||||
|
|
@ -354,6 +358,7 @@ newtype PProposalDatum (s :: S) = PProposalDatum
|
||||||
, "cosigners" ':= PBuiltinList (PAsData PPubKeyHash)
|
, "cosigners" ':= PBuiltinList (PAsData PPubKeyHash)
|
||||||
, "thresholds" ':= PProposalThresholds
|
, "thresholds" ':= PProposalThresholds
|
||||||
, "votes" ':= PProposalVotes
|
, "votes" ':= PProposalVotes
|
||||||
|
, "timingConfig" ':= PProposalTimingConfig
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ proposalValidator proposal =
|
||||||
, "cosigners"
|
, "cosigners"
|
||||||
, "thresholds"
|
, "thresholds"
|
||||||
, "votes"
|
, "votes"
|
||||||
|
, "timingConfig"
|
||||||
]
|
]
|
||||||
proposalDatum
|
proposalDatum
|
||||||
|
|
||||||
|
|
@ -253,6 +254,7 @@ proposalValidator proposal =
|
||||||
.& #cosigners .= proposalF.cosigners
|
.& #cosigners .= proposalF.cosigners
|
||||||
.& #thresholds .= proposalF.thresholds
|
.& #thresholds .= proposalF.thresholds
|
||||||
.& #votes .= pdata expectedNewVotes
|
.& #votes .= pdata expectedNewVotes
|
||||||
|
.& #timingConfig .= proposalF.timingConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
tcassert "Invalid output proposal" $ proposalOut #== expectedProposalOut
|
tcassert "Invalid output proposal" $ proposalOut #== expectedProposalOut
|
||||||
|
|
@ -342,6 +344,7 @@ proposalValidator proposal =
|
||||||
.& #cosigners .= pdata updatedSigs
|
.& #cosigners .= pdata updatedSigs
|
||||||
.& #thresholds .= proposalF.thresholds
|
.& #thresholds .= proposalF.thresholds
|
||||||
.& #votes .= proposalF.votes
|
.& #votes .= proposalF.votes
|
||||||
|
.& #timingConfig .= proposalF.timingConfig
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
in foldr1
|
in foldr1
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,12 @@ import Plutarch.Api.V1 (
|
||||||
PPOSIXTimeRange,
|
PPOSIXTimeRange,
|
||||||
PUpperBound (PUpperBound),
|
PUpperBound (PUpperBound),
|
||||||
)
|
)
|
||||||
import Plutarch.DataRepr (PDataFields, PIsDataReprInstances (..))
|
import Plutarch.DataRepr (DerivePConstantViaData (..), PDataFields, PIsDataReprInstances (..))
|
||||||
|
import Plutarch.Lift (
|
||||||
|
DerivePConstantViaNewtype (..),
|
||||||
|
PConstantDecl,
|
||||||
|
PUnsafeLiftDecl (..),
|
||||||
|
)
|
||||||
import Plutarch.Numeric (AdditiveSemigroup ((+)))
|
import Plutarch.Numeric (AdditiveSemigroup ((+)))
|
||||||
import Plutarch.Unsafe (punsafeCoerce)
|
import Plutarch.Unsafe (punsafeCoerce)
|
||||||
import Plutus.V1.Ledger.Time (POSIXTime)
|
import Plutus.V1.Ledger.Time (POSIXTime)
|
||||||
|
|
@ -122,10 +127,24 @@ newtype PProposalTime (s :: S)
|
||||||
(PlutusType, PIsData, PDataFields)
|
(PlutusType, PIsData, PDataFields)
|
||||||
via (PIsDataReprInstances PProposalTime)
|
via (PIsDataReprInstances PProposalTime)
|
||||||
|
|
||||||
|
instance PUnsafeLiftDecl PProposalTime where
|
||||||
|
type PLifted PProposalTime = ProposalTime
|
||||||
|
deriving via
|
||||||
|
(DerivePConstantViaData ProposalTime PProposalTime)
|
||||||
|
instance
|
||||||
|
(PConstantDecl ProposalTime)
|
||||||
|
|
||||||
-- | Plutarch-level version of 'ProposalStartingTime'.
|
-- | Plutarch-level version of 'ProposalStartingTime'.
|
||||||
newtype PProposalStartingTime (s :: S) = PProposalStartingTime (Term s PPOSIXTime)
|
newtype PProposalStartingTime (s :: S) = PProposalStartingTime (Term s PPOSIXTime)
|
||||||
deriving (PlutusType, PIsData, PEq, POrd) via (DerivePNewtype PProposalStartingTime PPOSIXTime)
|
deriving (PlutusType, PIsData, PEq, POrd) via (DerivePNewtype PProposalStartingTime PPOSIXTime)
|
||||||
|
|
||||||
|
instance PUnsafeLiftDecl PProposalStartingTime where
|
||||||
|
type PLifted PProposalStartingTime = ProposalStartingTime
|
||||||
|
deriving via
|
||||||
|
(DerivePConstantViaNewtype ProposalStartingTime PProposalStartingTime PPOSIXTime)
|
||||||
|
instance
|
||||||
|
(PConstantDecl ProposalStartingTime)
|
||||||
|
|
||||||
-- | Plutarch-level version of 'ProposalTimingConfig'.
|
-- | Plutarch-level version of 'ProposalTimingConfig'.
|
||||||
newtype PProposalTimingConfig (s :: S) = PProposalTimingConfig
|
newtype PProposalTimingConfig (s :: S) = PProposalTimingConfig
|
||||||
{ getProposalTimingConfig ::
|
{ getProposalTimingConfig ::
|
||||||
|
|
@ -146,6 +165,13 @@ newtype PProposalTimingConfig (s :: S) = PProposalTimingConfig
|
||||||
(PlutusType, PIsData, PDataFields)
|
(PlutusType, PIsData, PDataFields)
|
||||||
via (PIsDataReprInstances PProposalTimingConfig)
|
via (PIsDataReprInstances PProposalTimingConfig)
|
||||||
|
|
||||||
|
instance PUnsafeLiftDecl PProposalTimingConfig where
|
||||||
|
type PLifted PProposalTimingConfig = ProposalTimingConfig
|
||||||
|
deriving via
|
||||||
|
(DerivePConstantViaData ProposalTimingConfig PProposalTimingConfig)
|
||||||
|
instance
|
||||||
|
(PConstantDecl ProposalTimingConfig)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- FIXME: Orphan instance, move this to plutarch-extra.
|
-- FIXME: Orphan instance, move this to plutarch-extra.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue