Merge pull request #113 from Liqwid-Labs/emiflake/update-fix-docs

Bump plutarch
This commit is contained in:
Emily 2022-06-04 12:51:27 +02:00 committed by GitHub
commit 7b65700b4b
52 changed files with 2774 additions and 3999 deletions

View file

@ -7,18 +7,16 @@ import Data.ByteString.Lazy qualified as LBS
import Data.ByteString.Short qualified as SBS import Data.ByteString.Short qualified as SBS
import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=)) import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=))
import Data.List (intercalate) import Data.List (intercalate)
import Data.Maybe (fromJust)
import Data.Text (Text, pack) import Data.Text (Text, pack)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Plutus.V1.Ledger.Api ( import Plutarch.Evaluate (evalScript)
import PlutusLedgerApi.V1 (
ExBudget (ExBudget), ExBudget (ExBudget),
ExCPU (..), ExCPU (..),
ExMemory (..), ExMemory (..),
Script, Script,
) )
import Plutus.V1.Ledger.Api qualified as Plutus
import Prettyprinter (Pretty (pretty), indent, vsep) import Prettyprinter (Pretty (pretty), indent, vsep)
import Test.Specification ( import Test.Specification (
Specification (Specification), Specification (Specification),
SpecificationExpectation (Success), SpecificationExpectation (Success),
@ -67,18 +65,9 @@ instance DefaultOrdered Benchmark where
benchmarkScript :: String -> Script -> Benchmark benchmarkScript :: String -> Script -> Benchmark
benchmarkScript name script = Benchmark (pack name) cpu mem size benchmarkScript name script = Benchmark (pack name) cpu mem size
where where
(ExBudget cpu mem) = evalScriptCounting . serialiseScriptShort $ script (_res, ExBudget cpu mem, _traces) = evalScript script
size = SBS.length . SBS.toShort . LBS.toStrict . serialise $ script
serialiseScriptShort :: Script -> SBS.ShortByteString size = SBS.length . SBS.toShort . LBS.toStrict . serialise $ script
serialiseScriptShort = SBS.toShort . LBS.toStrict . serialise -- Using `flat` here breaks `evalScriptCounting`
evalScriptCounting :: Plutus.SerializedScript -> Plutus.ExBudget
evalScriptCounting script =
let costModel = fromJust Plutus.defaultCostModelParams
(_logout, e) = Plutus.evaluateScriptCounting Plutus.Verbose costModel script []
in case e of
Left evalError -> error ("Eval Error: " <> show evalError)
Right exbudget -> exbudget
specificationTreeToBenchmarks :: SpecificationTree -> [Benchmark] specificationTreeToBenchmarks :: SpecificationTree -> [Benchmark]
specificationTreeToBenchmarks = go [] specificationTreeToBenchmarks = go []

View file

@ -2,6 +2,7 @@ module AgoraTypes (agoraTypes) where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Data.Proxy (Proxy (..))
import Language.PureScript.Bridge ( import Language.PureScript.Bridge (
Language (Haskell), Language (Haskell),
SumType, SumType,
@ -24,30 +25,30 @@ import Agora.Treasury qualified as Treasury
agoraTypes :: [SumType 'Haskell] agoraTypes :: [SumType 'Haskell]
agoraTypes = agoraTypes =
[ -- Proposal [ -- Proposal
mkSumType @Proposal.ProposalId mkSumType (Proxy @Proposal.ProposalId)
, mkSumType @Proposal.ResultTag , mkSumType (Proxy @Proposal.ResultTag)
, mkSumType @Proposal.ProposalStatus , mkSumType (Proxy @Proposal.ProposalStatus)
, mkSumType @Proposal.ProposalThresholds , mkSumType (Proxy @Proposal.ProposalThresholds)
, mkSumType @Proposal.ProposalVotes , mkSumType (Proxy @Proposal.ProposalVotes)
, mkSumType @Proposal.ProposalDatum , mkSumType (Proxy @Proposal.ProposalDatum)
, mkSumType @Proposal.ProposalRedeemer , mkSumType (Proxy @Proposal.ProposalRedeemer)
, mkSumType @Proposal.Proposal , mkSumType (Proxy @Proposal.Proposal)
, -- Governor , -- Governor
mkSumType @Governor.GovernorDatum mkSumType (Proxy @Governor.GovernorDatum)
, mkSumType @Governor.GovernorRedeemer , mkSumType (Proxy @Governor.GovernorRedeemer)
, mkSumType @Governor.Governor , mkSumType (Proxy @Governor.Governor)
, -- MultiSig , -- MultiSig
mkSumType @MultiSig.MultiSig mkSumType (Proxy @MultiSig.MultiSig)
, -- Stake , -- Stake
mkSumType @Stake.Stake mkSumType (Proxy @Stake.Stake)
, mkSumType @Stake.ProposalLock , mkSumType (Proxy @Stake.ProposalLock)
, mkSumType @Stake.StakeRedeemer , mkSumType (Proxy @Stake.StakeRedeemer)
, mkSumType @Stake.StakeDatum , mkSumType (Proxy @Stake.StakeDatum)
, -- Treasury , -- Treasury
mkSumType @Treasury.TreasuryRedeemer mkSumType (Proxy @Treasury.TreasuryRedeemer)
, -- AuthorityToken , -- AuthorityToken
mkSumType @AuthorityToken.AuthorityToken mkSumType (Proxy @AuthorityToken.AuthorityToken)
, -- Effects , -- Effects
mkSumType @TreasuryWithdrawalEffect.TreasuryWithdrawalDatum mkSumType (Proxy @TreasuryWithdrawalEffect.TreasuryWithdrawalDatum)
, mkSumType @GovernorMutation.MutateGovernorDatum , mkSumType (Proxy @GovernorMutation.MutateGovernorDatum)
] ]

View file

@ -9,7 +9,7 @@ import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype AuthorityToken = AuthorityToken { authority :: AssetClass } newtype AuthorityToken = AuthorityToken { authority :: AssetClass }

View file

@ -10,7 +10,7 @@ import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Plutus.V1.Ledger.Tx (TxOutRef) import PlutusLedgerApi.V1.Tx (TxOutRef)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype MutateGovernorDatum = MutateGovernorDatum newtype MutateGovernorDatum = MutateGovernorDatum

View file

@ -10,8 +10,8 @@ import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Plutus.V1.Ledger.Credential (Credential) import PlutusLedgerApi.V1.Credential (Credential)
import Plutus.V1.Ledger.Value (Value) import PlutusLedgerApi.V1.Value (Value)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype TreasuryWithdrawalDatum = TreasuryWithdrawalDatum newtype TreasuryWithdrawalDatum = TreasuryWithdrawalDatum

View file

@ -17,8 +17,8 @@ import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tagged (Tagged) import Data.Tagged (Tagged)
import GHC.Num.Integer (Integer) import GHC.Num.Integer (Integer)
import Plutus.V1.Ledger.Tx (TxOutRef) import PlutusLedgerApi.V1.Tx (TxOutRef)
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype GovernorDatum = GovernorDatum newtype GovernorDatum = GovernorDatum

View file

@ -10,7 +10,7 @@ import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import GHC.Num.Integer (Integer) import GHC.Num.Integer (Integer)
import Plutus.V1.Ledger.Crypto (PubKeyHash) import PlutusLedgerApi.V1.Crypto (PubKeyHash)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype MultiSig = MultiSig newtype MultiSig = MultiSig

View file

@ -16,9 +16,9 @@ import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tagged (Tagged) import Data.Tagged (Tagged)
import GHC.Num.Integer (Integer) import GHC.Num.Integer (Integer)
import Plutus.V1.Ledger.Crypto (PubKeyHash) import PlutusLedgerApi.V1.Crypto (PubKeyHash)
import Plutus.V1.Ledger.Scripts (DatumHash, ValidatorHash) import PlutusLedgerApi.V1.Scripts (DatumHash, ValidatorHash)
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
import PlutusTx.AssocMap (Map) import PlutusTx.AssocMap (Map)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))

View file

@ -13,8 +13,8 @@ import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tagged (Tagged) import Data.Tagged (Tagged)
import GHC.Num.Integer (Integer) import GHC.Num.Integer (Integer)
import Plutus.V1.Ledger.Crypto (PubKeyHash) import PlutusLedgerApi.V1.Crypto (PubKeyHash)
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
import Type.Proxy (Proxy(Proxy)) import Type.Proxy (Proxy(Proxy))
newtype Stake = Stake newtype Stake = Stake

View file

@ -31,9 +31,9 @@ import Data.Tagged (Tagged)
import GHC.Generics qualified as GHC import GHC.Generics qualified as GHC
import Options (Options (..), parseOptions) import Options (Options (..), parseOptions)
import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy) import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy)
import Plutus.V1.Ledger.Api (TxOutRef) import PlutusLedgerApi.V1 (TxOutRef)
import Plutus.V1.Ledger.Value (AssetClass, CurrencySymbol) import PlutusLedgerApi.V1.Value (AssetClass, CurrencySymbol)
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import System.Exit (exitFailure) import System.Exit (exitFailure)
import Text.Printf (printf) import Text.Printf (printf)

File diff suppressed because one or more lines are too long

View file

@ -21,8 +21,8 @@ module Property.Generator (
import Control.Applicative (Applicative (liftA2)) import Control.Applicative (Applicative (liftA2))
import Data.ByteString.Char8 qualified as C (ByteString, pack) import Data.ByteString.Char8 qualified as C (ByteString, pack)
import Data.ByteString.Hash (sha2) import Data.ByteString.Hash (sha2_256)
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (Address), Address (Address),
Credential (..), Credential (..),
PubKeyHash (PubKeyHash), PubKeyHash (PubKeyHash),
@ -30,7 +30,7 @@ import Plutus.V1.Ledger.Api (
Value, Value,
toBuiltin, toBuiltin,
) )
import Plutus.V1.Ledger.Value ( import PlutusLedgerApi.V1.Value (
AssetClass (AssetClass), AssetClass (AssetClass),
assetClassValue, assetClassValue,
currencySymbol, currencySymbol,
@ -50,7 +50,7 @@ Hashs cannot be shrunken; functions utilizing this function,
therefore, cannot be shrunken as well. therefore, cannot be shrunken as well.
-} -}
genHashByteString :: Gen C.ByteString genHashByteString :: Gen C.ByteString
genHashByteString = sha2 . C.pack . show <$> (chooseAny :: Gen Integer) genHashByteString = sha2_256 . C.pack . show <$> (chooseAny :: Gen Integer)
-- TODO: How do I need to ensure uniqueness? -- TODO: How do I need to ensure uniqueness?

View file

@ -24,7 +24,7 @@ import Plutarch.Context.Spending (
signedWith, signedWith,
spendingContext, spendingContext,
) )
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
ScriptContext (scriptContextTxInfo), ScriptContext (scriptContextTxInfo),
TxInfo (txInfoSignatories), TxInfo (txInfoSignatories),
) )

View file

@ -24,8 +24,7 @@ import Agora.Proposal (ProposalId (..), ProposalThresholds (..))
import Data.Tagged (Tagged (..)) import Data.Tagged (Tagged (..))
import Plutarch.Api.V1 (mkValidator, validatorHash) import Plutarch.Api.V1 (mkValidator, validatorHash)
import Plutus.V1.Ledger.Address (scriptHashAddress) import PlutusLedgerApi.V1 (
import Plutus.V1.Ledger.Api (
Address, Address,
Datum (..), Datum (..),
ToData (..), ToData (..),
@ -37,9 +36,10 @@ import Plutus.V1.Ledger.Api (
Validator, Validator,
ValidatorHash (..), ValidatorHash (..),
) )
import Plutus.V1.Ledger.Api qualified as Interval import PlutusLedgerApi.V1 qualified as Interval
import Plutus.V1.Ledger.Value (AssetClass, assetClass) import PlutusLedgerApi.V1.Address (scriptHashAddress)
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value (AssetClass, assetClass)
import PlutusLedgerApi.V1.Value qualified as Value
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -20,7 +20,7 @@ module Sample.Effect.TreasuryWithdrawal (
) where ) where
import Plutarch.Api.V1 (mkValidator, validatorHash) import Plutarch.Api.V1 (mkValidator, validatorHash)
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (Address), Address (Address),
Credential (..), Credential (..),
CurrencySymbol (CurrencySymbol), CurrencySymbol (CurrencySymbol),
@ -50,11 +50,11 @@ import Plutus.V1.Ledger.Api (
Value, Value,
toBuiltin, toBuiltin,
) )
import Plutus.V1.Ledger.Interval qualified as Interval import PlutusLedgerApi.V1.Interval qualified as Interval
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import Data.ByteString.Char8 qualified as C import Data.ByteString.Char8 qualified as C
import Data.ByteString.Hash (sha2) import Data.ByteString.Hash (sha2_256)
import Agora.Effect.TreasuryWithdrawal ( import Agora.Effect.TreasuryWithdrawal (
TreasuryWithdrawalDatum (TreasuryWithdrawalDatum), TreasuryWithdrawalDatum (TreasuryWithdrawalDatum),
@ -71,11 +71,11 @@ signer = "8a30896c4fd5e79843e4ca1bd2cdbaa36f8c0bc3be7401214142019c"
-- | List of users who the effect will pay to. -- | List of users who the effect will pay to.
users :: [Credential] users :: [Credential]
users = PubKeyCredential . PubKeyHash . toBuiltin . sha2 . C.pack . show <$> ([1 ..] :: [Integer]) users = PubKeyCredential . PubKeyHash . toBuiltin . sha2_256 . C.pack . show <$> ([1 ..] :: [Integer])
-- | List of users who the effect will pay to. -- | List of users who the effect will pay to.
treasuries :: [Credential] treasuries :: [Credential]
treasuries = ScriptCredential . ValidatorHash . toBuiltin . sha2 . C.pack . show <$> ([1 ..] :: [Integer]) treasuries = ScriptCredential . ValidatorHash . toBuiltin . sha2_256 . C.pack . show <$> ([1 ..] :: [Integer])
inputGAT :: TxInInfo inputGAT :: TxInInfo
inputGAT = inputGAT =
@ -87,6 +87,7 @@ inputGAT =
, txOutDatumHash = Just (DatumHash "") , txOutDatumHash = Just (DatumHash "")
} }
-- | Create an input given the index of the treasury and the 'Value' at this input.
inputTreasury :: Int -> Value -> TxInInfo inputTreasury :: Int -> Value -> TxInInfo
inputTreasury indx val = inputTreasury indx val =
TxInInfo TxInInfo
@ -97,6 +98,7 @@ inputTreasury indx val =
, txOutDatumHash = Just (DatumHash "") , txOutDatumHash = Just (DatumHash "")
} }
-- | Create a input given the index of the user and the 'Value' at this input.
inputUser :: Int -> Value -> TxInInfo inputUser :: Int -> Value -> TxInInfo
inputUser indx val = inputUser indx val =
TxInInfo TxInInfo
@ -107,6 +109,7 @@ inputUser indx val =
, txOutDatumHash = Just (DatumHash "") , txOutDatumHash = Just (DatumHash "")
} }
-- | Create a input representing the collateral given by a user.
inputCollateral :: Int -> TxInInfo inputCollateral :: Int -> TxInInfo
inputCollateral indx = inputCollateral indx =
TxInInfo -- Initiator TxInInfo -- Initiator
@ -117,6 +120,7 @@ inputCollateral indx =
, txOutDatumHash = Just (DatumHash "") , txOutDatumHash = Just (DatumHash "")
} }
-- | Create an output at the nth treasury with the given 'Value'.
outputTreasury :: Int -> Value -> TxOut outputTreasury :: Int -> Value -> TxOut
outputTreasury indx val = outputTreasury indx val =
TxOut TxOut
@ -125,6 +129,7 @@ outputTreasury indx val =
, txOutDatumHash = Nothing , txOutDatumHash = Nothing
} }
-- | Create an output at the nth user with the given 'Value'.
outputUser :: Int -> Value -> TxOut outputUser :: Int -> Value -> TxOut
outputUser indx val = outputUser indx val =
TxOut TxOut
@ -133,6 +138,7 @@ outputUser indx val =
, txOutDatumHash = Nothing , txOutDatumHash = Nothing
} }
-- | Create a list of the outputs that are required as encoded in 'TreasuryWithdrawalDatum'.
buildReceiversOutputFromDatum :: TreasuryWithdrawalDatum -> [TxOut] buildReceiversOutputFromDatum :: TreasuryWithdrawalDatum -> [TxOut]
buildReceiversOutputFromDatum (TreasuryWithdrawalDatum xs _) = f <$> xs buildReceiversOutputFromDatum (TreasuryWithdrawalDatum xs _) = f <$> xs
where where
@ -147,7 +153,7 @@ buildReceiversOutputFromDatum (TreasuryWithdrawalDatum xs _) = f <$> xs
validator :: Validator validator :: Validator
validator = mkValidator $ treasuryWithdrawalValidator currSymbol validator = mkValidator $ treasuryWithdrawalValidator currSymbol
-- | 'TokenName' that represents the hash of the 'Stake' validator. -- | 'TokenName' that represents the hash of the 'Agora.Stake.Stake' validator.
validatorHashTN :: TokenName validatorHashTN :: TokenName
validatorHashTN = let ValidatorHash vh = validatorHash validator in TokenName vh validatorHashTN = let ValidatorHash vh = validatorHash validator in TokenName vh

View file

@ -19,10 +19,11 @@ import Plutarch.Api.V1 (mkValidator, validatorHash)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Address (scriptHashAddress) import PlutusLedgerApi.V1 (
import Plutus.V1.Ledger.Api (
Address (..), Address (..),
BuiltinData (BuiltinData),
Credential (ScriptCredential), Credential (ScriptCredential),
Data (I),
Datum (..), Datum (..),
ScriptContext (..), ScriptContext (..),
ScriptPurpose (Minting, Spending), ScriptPurpose (Minting, Spending),
@ -35,12 +36,12 @@ import Plutus.V1.Ledger.Api (
Validator, Validator,
ValidatorHash (..), ValidatorHash (..),
) )
import Plutus.V1.Ledger.Interval qualified as Interval import PlutusLedgerApi.V1.Address (scriptHashAddress)
import Plutus.V1.Ledger.Scripts (unitDatum) import PlutusLedgerApi.V1.Interval qualified as Interval
import Plutus.V1.Ledger.Value ( import PlutusLedgerApi.V1.Value (
AssetClass (..), AssetClass (..),
) )
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -92,6 +93,10 @@ import Data.Default.Class (Default (def))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Unit datum
unitDatum :: Datum
unitDatum = Datum . BuiltinData $ I 0 -- This could be anything, really. It doesn't matter.
{- | A valid 'ScriptContext' for minting GST. {- | A valid 'ScriptContext' for minting GST.
- Only the minting policy will be ran in the transaction. - Only the minting policy will be ran in the transaction.

View file

@ -29,7 +29,7 @@ import Plutarch.Api.V1 (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (Address), Address (Address),
Credential (ScriptCredential), Credential (ScriptCredential),
Datum (Datum), Datum (Datum),
@ -46,7 +46,7 @@ import Plutus.V1.Ledger.Api (
TxOutRef (TxOutRef), TxOutRef (TxOutRef),
ValidatorHash, ValidatorHash,
) )
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -431,9 +431,9 @@ voteOnProposal params =
-- | Parameters for state transition of proposals. -- | Parameters for state transition of proposals.
data TransitionParameters = TransitionParameters data TransitionParameters = TransitionParameters
{ -- The initial status of the propsoal. { -- The initial status of the propsoal.
initialProposalStatus :: ProposalStatus initialProposalStatus :: ProposalStatus
, -- The starting time of the propsoal. , -- The starting time of the propsoal.
proposalStartingTime :: ProposalStartingTime proposalStartingTime :: ProposalStartingTime
} }
-- | Create a 'TxInfo' that update the status of a proposal. -- | Create a 'TxInfo' that update the status of a proposal.

View file

@ -92,8 +92,7 @@ import Plutarch.Api.V1 (
mkValidator, mkValidator,
validatorHash, validatorHash,
) )
import Plutus.V1.Ledger.Address (scriptHashAddress) import PlutusLedgerApi.V1 (
import Plutus.V1.Ledger.Api (
Address (Address), Address (Address),
Credential (ScriptCredential), Credential (ScriptCredential),
CurrencySymbol, CurrencySymbol,
@ -107,12 +106,13 @@ import Plutus.V1.Ledger.Api (
UpperBound (..), UpperBound (..),
Value, Value,
) )
import Plutus.V1.Ledger.Contexts ( import PlutusLedgerApi.V1.Address (scriptHashAddress)
import PlutusLedgerApi.V1.Contexts (
TxOut (..), TxOut (..),
) )
import Plutus.V1.Ledger.Scripts (Validator, ValidatorHash (..)) import PlutusLedgerApi.V1.Scripts (Validator, ValidatorHash (..))
import Plutus.V1.Ledger.Value (AssetClass, TokenName) import PlutusLedgerApi.V1.Value (AssetClass, TokenName)
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -25,7 +25,7 @@ import Plutarch.Api.V1 (
mkValidator, mkValidator,
validatorHash, validatorHash,
) )
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (Address), Address (Address),
Credential (ScriptCredential), Credential (ScriptCredential),
Datum (Datum), Datum (Datum),
@ -38,10 +38,10 @@ import Plutus.V1.Ledger.Api (
TxOut (txOutAddress, txOutDatumHash, txOutValue), TxOut (txOutAddress, txOutDatumHash, txOutValue),
ValidatorHash (ValidatorHash), ValidatorHash (ValidatorHash),
) )
import Plutus.V1.Ledger.Contexts (TxOut (TxOut), TxOutRef (TxOutRef)) import PlutusLedgerApi.V1.Contexts (TxOut (TxOut), TxOutRef (TxOutRef))
import Plutus.V1.Ledger.Interval qualified as Interval import PlutusLedgerApi.V1.Interval qualified as Interval
import Plutus.V1.Ledger.Value (TokenName (TokenName)) import PlutusLedgerApi.V1.Value (TokenName (TokenName))
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -18,13 +18,13 @@ module Sample.Treasury (
) where ) where
import Plutarch.Api.V1 (validatorHash) import Plutarch.Api.V1 (validatorHash)
import Plutus.V1.Ledger.Address (Address (..)) import PlutusLedgerApi.V1 (
import Plutus.V1.Ledger.Api (
BuiltinByteString, BuiltinByteString,
Credential (PubKeyCredential), Credential (PubKeyCredential),
PubKeyHash (PubKeyHash), PubKeyHash (PubKeyHash),
) )
import Plutus.V1.Ledger.Contexts ( import PlutusLedgerApi.V1.Address (Address (..))
import PlutusLedgerApi.V1.Contexts (
ScriptContext (..), ScriptContext (..),
ScriptPurpose (Minting), ScriptPurpose (Minting),
TxInInfo (..), TxInInfo (..),
@ -32,12 +32,12 @@ import Plutus.V1.Ledger.Contexts (
TxOut (..), TxOut (..),
TxOutRef (..), TxOutRef (..),
) )
import Plutus.V1.Ledger.Credential (Credential (ScriptCredential)) import PlutusLedgerApi.V1.Credential (Credential (ScriptCredential))
import Plutus.V1.Ledger.Interval qualified as Interval import PlutusLedgerApi.V1.Interval qualified as Interval
import Plutus.V1.Ledger.Scripts ( import PlutusLedgerApi.V1.Scripts (
ValidatorHash (ValidatorHash), ValidatorHash (ValidatorHash),
) )
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import Sample.Shared ( import Sample.Shared (
gatCs, gatCs,
gatTn, gatTn,

View file

@ -17,7 +17,7 @@ import Prelude
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (Address), Address (Address),
Credential (PubKeyCredential, ScriptCredential), Credential (PubKeyCredential, ScriptCredential),
CurrencySymbol, CurrencySymbol,
@ -29,8 +29,8 @@ import Plutus.V1.Ledger.Api (
ValidatorHash (ValidatorHash), ValidatorHash (ValidatorHash),
Value, Value,
) )
import Plutus.V1.Ledger.Interval qualified as Interval import PlutusLedgerApi.V1.Interval qualified as Interval
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
import Test.Specification ( import Test.Specification (
SpecificationTree, SpecificationTree,
@ -69,6 +69,7 @@ singleAuthorityTokenBurnedTest mint outs =
perror perror
in compile s in compile s
-- | The SpecificationTree exported by this module.
specs :: [SpecificationTree] specs :: [SpecificationTree]
specs = specs =
[ -- This is better suited for plutarch-test [ -- This is better suited for plutarch-test

View file

@ -5,7 +5,7 @@ import Agora.Governor (GovernorDatum (..), GovernorRedeemer (MutateGovernor))
import Agora.Governor.Scripts (governorValidator) import Agora.Governor.Scripts (governorValidator)
import Agora.Proposal (ProposalId (..)) import Agora.Proposal (ProposalId (..))
import Data.Default.Class (Default (def)) import Data.Default.Class (Default (def))
import Plutus.V1.Ledger.Api (ScriptContext (ScriptContext), ScriptPurpose (Spending)) import PlutusLedgerApi.V1 (ScriptContext (ScriptContext), ScriptPurpose (Spending))
import Sample.Effect.GovernorMutation ( import Sample.Effect.GovernorMutation (
effectRef, effectRef,
govRef, govRef,

View file

@ -11,7 +11,7 @@ import Agora.Effect.TreasuryWithdrawal (
TreasuryWithdrawalDatum (TreasuryWithdrawalDatum), TreasuryWithdrawalDatum (TreasuryWithdrawalDatum),
treasuryWithdrawalValidator, treasuryWithdrawalValidator,
) )
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import Sample.Effect.TreasuryWithdrawal ( import Sample.Effect.TreasuryWithdrawal (
buildReceiversOutputFromDatum, buildReceiversOutputFromDatum,
buildScriptContext, buildScriptContext,

View file

@ -28,6 +28,7 @@ import Test.Specification (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | The SpecificationTree exported by this module.
specs :: [SpecificationTree] specs :: [SpecificationTree]
specs = specs =
[ group [ group

View file

@ -41,7 +41,7 @@ import Agora.Stake (
import Agora.Stake.Scripts (stakeValidator) import Agora.Stake.Scripts (stakeValidator)
import Data.Default.Class (Default (def)) import Data.Default.Class (Default (def))
import Data.Tagged (Tagged (Tagged), untag) import Data.Tagged (Tagged (Tagged), untag)
import Plutus.V1.Ledger.Api (ScriptContext (..), ScriptPurpose (..)) import PlutusLedgerApi.V1 (ScriptContext (..), ScriptPurpose (..))
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
import Sample.Proposal qualified as Proposal import Sample.Proposal qualified as Proposal
import Sample.Shared (signer, signer2) import Sample.Shared (signer, signer2)
@ -184,8 +184,8 @@ specs =
[ [
( ResultTag 0 ( ResultTag 0
, case initialState of , case initialState of
Draft -> 0 Draft -> 0
_ -> untag (def :: ProposalThresholds).countVoting + 1 _ -> untag (def :: ProposalThresholds).countVoting + 1
) )
, (ResultTag 1, 0) , (ResultTag 1, 0)
] ]
@ -231,8 +231,8 @@ specs =
[ [
( ResultTag 0 ( ResultTag 0
, case initialState of , case initialState of
Draft -> 0 Draft -> 0
_ -> untag (def :: ProposalThresholds).countVoting + 1 _ -> untag (def :: ProposalThresholds).countVoting + 1
) )
, (ResultTag 1, 0) , (ResultTag 1, 0)
] ]

View file

@ -34,6 +34,7 @@ import Test.Util (toDatum)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | The SpecificationTree exported by this module.
specs :: [SpecificationTree] specs :: [SpecificationTree]
specs = specs =
[ group [ group

View file

@ -25,18 +25,18 @@ import Agora.Treasury (
TreasuryRedeemer (SpendTreasuryGAT), TreasuryRedeemer (SpendTreasuryGAT),
treasuryValidator, treasuryValidator,
) )
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
DCert (DCertDelegRegKey), DCert (DCertDelegRegKey),
) )
import Plutus.V1.Ledger.Contexts ( import PlutusLedgerApi.V1.Contexts (
ScriptContext (scriptContextPurpose, scriptContextTxInfo), ScriptContext (scriptContextPurpose, scriptContextTxInfo),
ScriptPurpose (Certifying, Rewarding, Spending), ScriptPurpose (Certifying, Rewarding, Spending),
TxInfo (txInfoInputs, txInfoMint), TxInfo (txInfoInputs, txInfoMint),
) )
import Plutus.V1.Ledger.Credential ( import PlutusLedgerApi.V1.Credential (
StakingCredential (StakingHash), StakingCredential (StakingHash),
) )
import Plutus.V1.Ledger.Value qualified as Value import PlutusLedgerApi.V1.Value qualified as Value
import Sample.Shared ( import Sample.Shared (
trCredential, trCredential,
) )

View file

@ -51,7 +51,7 @@ import Plutarch.Api.V1 (PMintingPolicy, PValidator)
import Plutarch.Builtin (pforgetData) import Plutarch.Builtin (pforgetData)
import Plutarch.Evaluate (evalScript) import Plutarch.Evaluate (evalScript)
import Plutarch.Lift (PUnsafeLiftDecl (PLifted)) import Plutarch.Lift (PUnsafeLiftDecl (PLifted))
import Plutus.V1.Ledger.Api (Script, ScriptContext) import PlutusLedgerApi.V1 (Script, ScriptContext)
import PlutusTx.IsData qualified as PlutusTx (ToData) import PlutusTx.IsData qualified as PlutusTx (ToData)
import Test.Tasty (TestTree, testGroup) import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (assertFailure, testCase) import Test.Tasty.HUnit (assertFailure, testCase)

View file

@ -25,8 +25,8 @@ import Data.ByteString.Lazy qualified as ByteString.Lazy
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutarch.Crypto (pblake2b_256) import Plutarch.Crypto (pblake2b_256)
import Plutus.V1.Ledger.Interval as PlutusTx import PlutusLedgerApi.V1.Interval as PlutusTx
import Plutus.V1.Ledger.Scripts (Datum (Datum), DatumHash (DatumHash)) import PlutusLedgerApi.V1.Scripts (Datum (Datum), DatumHash (DatumHash))
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
import PlutusTx.Builtins qualified as PlutusTx import PlutusTx.Builtins qualified as PlutusTx
import PlutusTx.IsData qualified as PlutusTx import PlutusTx.IsData qualified as PlutusTx
@ -34,11 +34,11 @@ import PlutusTx.Ord qualified as PlutusTx
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
{- | Create a pair from data for use in 'txInfoData'. {- | Create a pair from data for use in 'PlutusLedgerApi.V1.Contexts.txInfoData'.
Example: Example:
@ @
myTxInfo { 'txInfoData' = ['datumPair' myDatum] } myTxInfo { 'PlutusLedgerApi.V1.Contexts.txInfoData' = ['datumPair' myDatum] }
@ @
-} -}
datumPair :: PlutusTx.ToData a => a -> (DatumHash, Datum) datumPair :: PlutusTx.ToData a => a -> (DatumHash, Datum)

View file

@ -67,6 +67,7 @@ common lang
PatternGuards PatternGuards
PolyKinds PolyKinds
PostfixOperators PostfixOperators
QualifiedDo
RankNTypes RankNTypes
RelaxedPolyRec RelaxedPolyRec
ScopedTypeVariables ScopedTypeVariables
@ -80,7 +81,6 @@ common lang
UndecidableInstances UndecidableInstances
ViewPatterns ViewPatterns
OverloadedRecordDot OverloadedRecordDot
QualifiedDo
default-language: Haskell2010 default-language: Haskell2010
@ -128,6 +128,7 @@ common test-deps
, tasty-hunit , tasty-hunit
, tasty-quickcheck , tasty-quickcheck
, universe , universe
, universe-base
common exe-opts common exe-opts
ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0 ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0
@ -219,6 +220,7 @@ benchmark agora-bench
, agora-specs , agora-specs
, agora-testlib , agora-testlib
, cassava , cassava
, mtl
, optparse-applicative , optparse-applicative
executable agora-scripts executable agora-scripts

View file

@ -18,9 +18,9 @@ import Data.Text.Encoding qualified as T
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api qualified as Plutus import PlutusLedgerApi.V1 qualified as Plutus
import Plutus.V1.Ledger.Bytes qualified as Plutus import PlutusLedgerApi.V1.Bytes qualified as Plutus
import Plutus.V1.Ledger.Value qualified as Plutus import PlutusLedgerApi.V1.Value qualified as Plutus
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -60,7 +60,7 @@ instance (Coercible a Plutus.LedgerBytes) => Aeson.ToJSON (AsBase16Bytes a) wher
instance (Coercible Plutus.LedgerBytes a) => Aeson.FromJSON (AsBase16Bytes a) where instance (Coercible Plutus.LedgerBytes a) => Aeson.FromJSON (AsBase16Bytes a) where
parseJSON v = parseJSON v =
Aeson.parseJSON @T.Text v Aeson.parseJSON @T.Text v
>>= either (Aeson.parserThrowError []) (pure . coerce @_ @(AsBase16Bytes a)) >>= either (Aeson.parserThrowError [] . show) (pure . coerce @_ @(AsBase16Bytes a))
. Plutus.fromHex . Plutus.fromHex
. T.encodeUtf8 . T.encodeUtf8

View file

@ -14,6 +14,8 @@ module Agora.AuthorityToken (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutarch.Api.V1 ( import Plutarch.Api.V1 (
AmountGuarantees,
KeyGuarantees,
PAddress (..), PAddress (..),
PCredential (..), PCredential (..),
PCurrencySymbol (..), PCurrencySymbol (..),
@ -28,7 +30,7 @@ import Plutarch.Api.V1.AssetClass (passetClass, passetClassValueOf)
import Plutarch.Api.V1.AssocMap (PMap (PMap)) import Plutarch.Api.V1.AssocMap (PMap (PMap))
import "plutarch" Plutarch.Api.V1.Value (PValue (PValue)) import "plutarch" Plutarch.Api.V1.Value (PValue (PValue))
import Plutarch.Builtin (pforgetData) import Plutarch.Builtin (pforgetData)
import Plutus.V1.Ledger.Value (AssetClass (AssetClass)) import PlutusLedgerApi.V1.Value (AssetClass (AssetClass))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -100,10 +102,10 @@ authorityTokensValidIn = phoistAcyclic $
-- | Assert that a single authority token has been burned. -- | Assert that a single authority token has been burned.
singleAuthorityTokenBurned :: singleAuthorityTokenBurned ::
forall (s :: S). forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s PCurrencySymbol -> Term s PCurrencySymbol ->
Term s (PAsData PTxInfo) -> Term s (PAsData PTxInfo) ->
Term s PValue -> Term s (PValue keys amounts) ->
Term s PBool Term s PBool
singleAuthorityTokenBurned gatCs txInfo mint = unTermCont $ do singleAuthorityTokenBurned gatCs txInfo mint = unTermCont $ do
let gatAmountMinted :: Term _ PInteger let gatAmountMinted :: Term _ PInteger

View file

@ -11,7 +11,7 @@ import Agora.AuthorityToken (singleAuthorityTokenBurned)
import Agora.Utils (tcassert, tclet, tcmatch, tctryFrom) import Agora.Utils (tcassert, tclet, tcmatch, tctryFrom)
import Plutarch.Api.V1 (PCurrencySymbol, PScriptPurpose (PSpending), PTxInfo, PTxOutRef, PValidator, PValue) import Plutarch.Api.V1 (PCurrencySymbol, PScriptPurpose (PSpending), PTxInfo, PTxOutRef, PValidator, PValue)
import Plutarch.TryFrom () import Plutarch.TryFrom ()
import Plutus.V1.Ledger.Value (CurrencySymbol) import PlutusLedgerApi.V1.Value (CurrencySymbol)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -43,7 +43,7 @@ makeEffect gatCs' f =
-- fetch minted values to ensure single GAT is burned -- fetch minted values to ensure single GAT is burned
txInfo <- tcont $ pletFields @'["mint"] txInfo' txInfo <- tcont $ pletFields @'["mint"] txInfo'
let mint :: Term _ PValue let mint :: Term _ (PValue _ _)
mint = txInfo.mint mint = txInfo.mint
-- fetch script context -- fetch script context

View file

@ -43,8 +43,8 @@ import Plutarch.Unsafe (punsafeCoerce)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api (TxOutRef) import PlutusLedgerApi.V1 (TxOutRef)
import Plutus.V1.Ledger.Value (AssetClass (..)) import PlutusLedgerApi.V1.Value (AssetClass (..))
import PlutusTx qualified import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -208,7 +208,7 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
return $ popaque $ pconstant () return $ popaque $ pconstant ()
where where
-- Get the amount of GST in the a given value. -- Get the amount of GST in the a given value.
gstValueOf :: Term s (PValue :--> PInteger) gstValueOf :: Term s (PValue _ _ :--> PInteger)
gstValueOf = phoistAcyclic $ plam $ \v -> pvalueOf # v # pconstant cs # pconstant tn gstValueOf = phoistAcyclic $ plam $ \v -> pvalueOf # v # pconstant cs # pconstant tn
where where
AssetClass (cs, tn) = governorSTAssetClassFromGovernor gov AssetClass (cs, tn) = governorSTAssetClassFromGovernor gov

View file

@ -12,7 +12,7 @@ import Control.Applicative (Const)
import Agora.Effect (makeEffect) import Agora.Effect (makeEffect)
import Plutarch.Api.V1 (PValidator) import Plutarch.Api.V1 (PValidator)
import Plutarch.TryFrom (PTryFrom (..)) import Plutarch.TryFrom (PTryFrom (..))
import Plutus.V1.Ledger.Value (CurrencySymbol) import PlutusLedgerApi.V1.Value (CurrencySymbol)
-- | Dummy datum for NoOp effect. -- | Dummy datum for NoOp effect.
newtype PNoOp (s :: S) = PNoOp (Term s PUnit) newtype PNoOp (s :: S) = PNoOp (Term s PUnit)

View file

@ -20,12 +20,15 @@ import Generics.SOP (Generic, I (I))
import Agora.Effect (makeEffect) import Agora.Effect (makeEffect)
import Agora.Utils (findTxOutByTxOutRef, isPubKey, paddValue, tcassert, tclet, tcmatch) import Agora.Utils (findTxOutByTxOutRef, isPubKey, paddValue, tcassert, tclet, tcmatch)
import Plutarch.Api.V1 ( import Plutarch.Api.V1 (
AmountGuarantees (Positive),
KeyGuarantees (Sorted),
PCredential (..), PCredential (..),
PTuple, PTuple,
PValidator, PValidator,
PValue, PValue,
ptuple, ptuple,
) )
import "plutarch" Plutarch.Api.V1.Value (pnormalize)
import Plutarch.Internal (punsafeCoerce) import Plutarch.Internal (punsafeCoerce)
import Plutarch.DataRepr ( import Plutarch.DataRepr (
@ -35,8 +38,8 @@ import Plutarch.DataRepr (
) )
import Plutarch.Lift (PConstantDecl, PUnsafeLiftDecl (..)) import Plutarch.Lift (PConstantDecl, PUnsafeLiftDecl (..))
import Plutarch.TryFrom (PTryFrom (..)) import Plutarch.TryFrom (PTryFrom (..))
import Plutus.V1.Ledger.Credential (Credential) import PlutusLedgerApi.V1.Credential (Credential)
import Plutus.V1.Ledger.Value (CurrencySymbol, Value) import PlutusLedgerApi.V1.Value (CurrencySymbol, Value)
import PlutusTx qualified import PlutusTx qualified
{- | Datum that encodes behavior of Treasury Withdrawal effect. {- | Datum that encodes behavior of Treasury Withdrawal effect.
@ -63,7 +66,7 @@ newtype PTreasuryWithdrawalDatum (s :: S)
( Term ( Term
s s
( PDataRecord ( PDataRecord
'[ "receivers" ':= PBuiltinList (PAsData (PTuple PCredential PValue)) '[ "receivers" ':= PBuiltinList (PAsData (PTuple PCredential (PValue 'Sorted 'Positive)))
, "treasuries" ':= PBuiltinList (PAsData PCredential) , "treasuries" ':= PBuiltinList (PAsData PCredential)
] ]
) )
@ -135,8 +138,8 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
# plam (\((pfield @"_0" #) . pfromData -> cred) -> pelem # cred # datum.treasuries) # plam (\((pfield @"_0" #) . pfromData -> cred) -> pelem # cred # datum.treasuries)
sumValues = sumValues =
pfoldr pfoldr
# plam (\((pfield @"_1" #) . pfromData -> x) y -> paddValue # pfromData x # y) # plam (\((pfield @"_1" #) . pfromData -> x) ((pnormalize #) -> y) -> paddValue # pfromData x # y)
# pconstant (mempty :: Value) # punsafeCoerce (pconstant (mempty :: Value))
treasuryInputValuesSum = sumValues #$ ofTreasury # inputValues treasuryInputValuesSum = sumValues #$ ofTreasury # inputValues
treasuryOutputValuesSum = sumValues #$ ofTreasury # outputValues treasuryOutputValuesSum = sumValues #$ ofTreasury # outputValues
receiverValuesSum = sumValues # datum.receivers receiverValuesSum = sumValues # datum.receivers

View file

@ -63,8 +63,8 @@ import Plutarch.Unsafe (punsafeCoerce)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api (TxOutRef) import PlutusLedgerApi.V1 (TxOutRef)
import Plutus.V1.Ledger.Value (AssetClass (..)) import PlutusLedgerApi.V1.Value (AssetClass (..))
import PlutusTx qualified import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -127,15 +127,15 @@ data Governor = Governor
-- | Plutarch-level datum for the Governor script. -- | Plutarch-level datum for the Governor script.
newtype PGovernorDatum (s :: S) = PGovernorDatum newtype PGovernorDatum (s :: S) = PGovernorDatum
{ getGovernorDatum :: { getGovernorDatum ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "proposalThresholds" ':= PProposalThresholds '[ "proposalThresholds" ':= PProposalThresholds
, "nextProposalId" ':= PProposalId , "nextProposalId" ':= PProposalId
, "proposalTimings" ':= PProposalTimingConfig , "proposalTimings" ':= PProposalTimingConfig
, "createProposalTimeRangeMaxWidth" ':= PMaxTimeRangeWidth , "createProposalTimeRangeMaxWidth" ':= PMaxTimeRangeWidth
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
@ -183,6 +183,7 @@ getNextProposalId (ProposalId pid) = ProposalId $ pid + 1
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Check whether a particular 'PGovernorDatum' is well-formed.
governorDatumValid :: Term s (PGovernorDatum :--> PBool) governorDatumValid :: Term s (PGovernorDatum :--> PBool)
governorDatumValid = phoistAcyclic $ governorDatumValid = phoistAcyclic $
plam $ \datum -> unTermCont $ do plam $ \datum -> unTermCont $ do

View file

@ -125,12 +125,12 @@ import Plutarch.TryFrom ()
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
CurrencySymbol (..), CurrencySymbol (..),
MintingPolicy, MintingPolicy,
) )
import Plutus.V1.Ledger.Scripts (ValidatorHash (..)) import PlutusLedgerApi.V1.Scripts (ValidatorHash (..))
import Plutus.V1.Ledger.Value ( import PlutusLedgerApi.V1.Value (
AssetClass (..), AssetClass (..),
) )
@ -203,15 +203,15 @@ governorPolicy gov =
- The UTXO which holds the GST must be spent. - The UTXO which holds the GST must be spent.
- The GST always stays at the validator's address. - The GST always stays at the validator's address.
- The new state UTXO has a valid datum of type 'GovernorDatum'. - The new state UTXO has a valid datum of type 'Agora.Governor.GovernorDatum'.
== Creating a Proposal == Creating a Proposal
When the redeemer is 'CreateProposal', the script will check: When the redeemer is 'Agora.Governor.CreateProposal', the script will check:
- For governor's state datum: - For governor's state datum:
* 'nextProposalId' is advanced. * 'Agora.Governor.nextProposalId' is advanced.
* Nothing is changed other that that. * Nothing is changed other that that.
- Exactly one stake (the "input stake") must be provided in the input: - Exactly one stake (the "input stake") must be provided in the input:
@ -236,7 +236,7 @@ governorPolicy gov =
== Minting GATs == Minting GATs
When the redeemer is 'MintGATs', the script will check: When the redeemer is 'Agora.Governor.MintGATs', the script will check:
- Governor's state is not changed. - Governor's state is not changed.
- Exactly only one proposal is in the inputs. Let's call this the /input proposal/. - Exactly only one proposal is in the inputs. Let's call this the /input proposal/.
@ -272,7 +272,7 @@ governorPolicy gov =
== Changing the State == Changing the State
Redeemer 'MutateGovernor' allows the state datum to be changed by an external effect. Redeemer 'Agora.Governor.MutateGovernor' allows the state datum to be changed by an external effect.
In this case, the script will check In this case, the script will check
@ -631,7 +631,7 @@ governorValidator gov =
tcassert "Output GATs is more than minted GATs" $ tcassert "Output GATs is more than minted GATs" $
plength # outputsWithGAT #== gatCount plength # outputsWithGAT #== gatCount
let gatOutputValidator' :: Term s (PMap PValidatorHash PDatumHash :--> PAsData PTxOut :--> PBool) let gatOutputValidator' :: Term s (PMap _ PValidatorHash PDatumHash :--> PAsData PTxOut :--> PBool)
gatOutputValidator' = gatOutputValidator' =
phoistAcyclic $ phoistAcyclic $
plam plam
@ -679,7 +679,7 @@ governorValidator gov =
pure $ popaque $ singleAuthorityTokenBurned patSymbol ctxF.txInfo txInfoF.mint pure $ popaque $ singleAuthorityTokenBurned patSymbol ctxF.txInfo txInfoF.mint
where where
-- Get th amount of governance tokens in a value. -- Get th amount of governance tokens in a value.
pgtValueOf :: Term s (PValue :--> PDiscrete GTTag) pgtValueOf :: Term s (PValue _ _ :--> PDiscrete GTTag)
pgtValueOf = phoistAcyclic $ pvalueDiscrete' gov.gtClassRef pgtValueOf = phoistAcyclic $ pvalueDiscrete' gov.gtClassRef
-- The currency symbol of authority token. -- The currency symbol of authority token.

View file

@ -29,7 +29,7 @@ import Plutarch.Lift (
PUnsafeLiftDecl, PUnsafeLiftDecl,
) )
import Plutus.V1.Ledger.Crypto (PubKeyHash) import PlutusLedgerApi.V1.Crypto (PubKeyHash)
import PlutusTx qualified import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -57,13 +57,13 @@ PlutusTx.unstableMakeIsData ''MultiSig
-- | Plutarch-level MultiSig -- | Plutarch-level MultiSig
newtype PMultiSig (s :: S) = PMultiSig newtype PMultiSig (s :: S) = PMultiSig
{ getMultiSig :: { getMultiSig ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "keys" ':= PBuiltinList (PAsData PPubKeyHash) '[ "keys" ':= PBuiltinList (PAsData PPubKeyHash)
, "minSigs" ':= PInteger , "minSigs" ':= PInteger
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)

View file

@ -38,6 +38,7 @@ module Agora.Proposal (
import GHC.Generics qualified as GHC import GHC.Generics qualified as GHC
import Generics.SOP (Generic, I (I)) import Generics.SOP (Generic, I (I))
import Plutarch.Api.V1 ( import Plutarch.Api.V1 (
KeyGuarantees (Unsorted),
PDatumHash, PDatumHash,
PMap, PMap,
PPubKeyHash, PPubKeyHash,
@ -63,8 +64,8 @@ import Plutarch.Lift (
import Plutarch.SafeMoney (PDiscrete) import Plutarch.SafeMoney (PDiscrete)
import Plutarch.TryFrom (PTryFrom (PTryFromExcess, ptryFrom')) import Plutarch.TryFrom (PTryFrom (PTryFromExcess, ptryFrom'))
import Plutarch.Unsafe (punsafeCoerce) import Plutarch.Unsafe (punsafeCoerce)
import Plutus.V1.Ledger.Api (DatumHash, PubKeyHash, ValidatorHash) import PlutusLedgerApi.V1 (DatumHash, PubKeyHash, ValidatorHash)
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Haskell-land -- Haskell-land
@ -322,14 +323,14 @@ deriving via (DerivePConstantViaData ProposalStatus PProposalStatus) instance (P
-- | Plutarch-level version of 'ProposalThresholds'. -- | Plutarch-level version of 'ProposalThresholds'.
newtype PProposalThresholds (s :: S) = PProposalThresholds newtype PProposalThresholds (s :: S) = PProposalThresholds
{ getProposalThresholds :: { getProposalThresholds ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "execute" ':= PDiscrete GTTag '[ "execute" ':= PDiscrete GTTag
, "draft" ':= PDiscrete GTTag , "draft" ':= PDiscrete GTTag
, "vote" ':= PDiscrete GTTag , "vote" ':= PDiscrete GTTag
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
@ -343,17 +344,17 @@ deriving via (DerivePConstantViaData ProposalThresholds PProposalThresholds) ins
-- | Plutarch-level version of 'ProposalVotes'. -- | Plutarch-level version of 'ProposalVotes'.
newtype PProposalVotes (s :: S) newtype PProposalVotes (s :: S)
= PProposalVotes (Term s (PMap PResultTag PInteger)) = PProposalVotes (Term s (PMap 'Unsorted PResultTag PInteger))
deriving (PlutusType, PIsData) via (DerivePNewtype PProposalVotes (PMap PResultTag PInteger)) deriving (PlutusType, PIsData) via (DerivePNewtype PProposalVotes (PMap 'Unsorted PResultTag PInteger))
instance PUnsafeLiftDecl PProposalVotes where type PLifted PProposalVotes = ProposalVotes instance PUnsafeLiftDecl PProposalVotes where type PLifted PProposalVotes = ProposalVotes
deriving via deriving via
(DerivePConstantViaNewtype ProposalVotes PProposalVotes (PMap PResultTag PInteger)) (DerivePConstantViaNewtype ProposalVotes PProposalVotes (PMap 'Unsorted PResultTag PInteger))
instance instance
(PConstantDecl ProposalVotes) (PConstantDecl ProposalVotes)
-- Plutarch-level version of 'emptyVotesFor'. -- | Plutarch-level version of 'emptyVotesFor'.
pemptyVotesFor :: forall s a. (PIsData a) => Term s (PMap PResultTag a :--> PProposalVotes) pemptyVotesFor :: forall s a. (PIsData a) => Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
pemptyVotesFor = pemptyVotesFor =
phoistAcyclic $ phoistAcyclic $
plam plam
@ -365,19 +366,19 @@ pemptyVotesFor =
-- | Plutarch-level version of 'ProposalDatum'. -- | Plutarch-level version of 'ProposalDatum'.
newtype PProposalDatum (s :: S) = PProposalDatum newtype PProposalDatum (s :: S) = PProposalDatum
{ getProposalDatum :: { getProposalDatum ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "proposalId" ':= PProposalId '[ "proposalId" ':= PProposalId
, "effects" ':= PMap PResultTag (PMap PValidatorHash PDatumHash) , "effects" ':= PMap 'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
, "status" ':= PProposalStatus , "status" ':= PProposalStatus
, "cosigners" ':= PBuiltinList (PAsData PPubKeyHash) , "cosigners" ':= PBuiltinList (PAsData PPubKeyHash)
, "thresholds" ':= PProposalThresholds , "thresholds" ':= PProposalThresholds
, "votes" ':= PProposalVotes , "votes" ':= PProposalVotes
, "timingConfig" ':= PProposalTimingConfig , "timingConfig" ':= PProposalTimingConfig
, "startingTime" ':= PProposalStartingTime , "startingTime" ':= PProposalStartingTime
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
@ -451,7 +452,7 @@ proposalDatumValid proposal =
, ptraceIfFalse "Proposal votes and effects are compatible with each other" $ pkeysEqual # datum.effects # pto (pfromData datum.votes) , ptraceIfFalse "Proposal votes and effects are compatible with each other" $ pkeysEqual # datum.effects # pto (pfromData datum.votes)
] ]
{- Find the winner result tag, given the votes, the quorum the "neutral" result tag. {- | Find the winner result tag, given the votes, the quorum the "neutral" result tag.
The winner should be unambiguous, meaning that if two options have the same highest votes, The winner should be unambiguous, meaning that if two options have the same highest votes,
the "neutral" option will be the winner. the "neutral" option will be the winner.
@ -530,7 +531,7 @@ phighestVotes = phoistAcyclic $
pneutralOption :: pneutralOption ::
Term Term
s s
( PMap PResultTag (PMap PValidatorHash PDatumHash) ( PMap 'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
:--> PResultTag :--> PResultTag
) )
pneutralOption = phoistAcyclic $ pneutralOption = phoistAcyclic $
@ -538,7 +539,7 @@ pneutralOption = phoistAcyclic $
let l :: Term _ (PBuiltinList (PBuiltinPair (PAsData PResultTag) _)) let l :: Term _ (PBuiltinList (PBuiltinPair (PAsData PResultTag) _))
l = pto effects l = pto effects
f :: Term _ (PBuiltinPair (PAsData PResultTag) (PAsData (PMap _ _)) :--> PBool) f :: Term _ (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted _ _)) :--> PBool)
f = phoistAcyclic $ f = phoistAcyclic $
plam $ \((pfromData . (psndBuiltin #) -> el)) -> plam $ \((pfromData . (psndBuiltin #) -> el)) ->
let el' :: Term _ (PBuiltinList _) let el' :: Term _ (PBuiltinList _)

View file

@ -56,7 +56,7 @@ import Plutarch.Extra.Map (plookup)
import Plutarch.Extra.Record (mkRecordConstr, (.&), (.=)) import Plutarch.Extra.Record (mkRecordConstr, (.&), (.=))
import Plutarch.Extra.TermCont (pmatchC) import Plutarch.Extra.TermCont (pmatchC)
import Plutarch.SafeMoney (PDiscrete (..)) import Plutarch.SafeMoney (PDiscrete (..))
import Plutus.V1.Ledger.Value (AssetClass (AssetClass)) import PlutusLedgerApi.V1.Value (AssetClass (AssetClass))
{- | Policy for Proposals. {- | Policy for Proposals.

View file

@ -52,7 +52,7 @@ import Plutarch.Lift (
) )
import Plutarch.Numeric.Additive (AdditiveSemigroup ((+))) import Plutarch.Numeric.Additive (AdditiveSemigroup ((+)))
import Plutarch.Unsafe (punsafeCoerce) import Plutarch.Unsafe (punsafeCoerce)
import Plutus.V1.Ledger.Time (POSIXTime) import PlutusLedgerApi.V1.Time (POSIXTime)
import PlutusTx qualified import PlutusTx qualified
import Prelude hiding ((+)) import Prelude hiding ((+))
@ -83,7 +83,7 @@ data ProposalTimingConfig = ProposalTimingConfig
PlutusTx.makeIsDataIndexed ''ProposalTimingConfig [('ProposalTimingConfig, 0)] PlutusTx.makeIsDataIndexed ''ProposalTimingConfig [('ProposalTimingConfig, 0)]
-- | Represents the maximum width of a 'POSIXTimeRange'. -- | Represents the maximum width of a 'PlutusLedgerApi.V1.Time.POSIXTimeRange'.
newtype MaxTimeRangeWidth = MaxTimeRangeWidth {getMaxWidth :: POSIXTime} newtype MaxTimeRangeWidth = MaxTimeRangeWidth {getMaxWidth :: POSIXTime}
deriving stock (Eq, Show, Ord, GHC.Generic) deriving stock (Eq, Show, Ord, GHC.Generic)
deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData) deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData)
@ -101,15 +101,19 @@ newtype MaxTimeRangeWidth = MaxTimeRangeWidth {getMaxWidth :: POSIXTime}
determine if we are able to perform certain actions, we need to know what determine if we are able to perform certain actions, we need to know what
time it roughly is, compared to when the proposal was created. time it roughly is, compared to when the proposal was created.
'ProposalTime' represents "the time according to the proposal". 'PProposalTime' represents "the time according to the proposal".
Its representation is opaque, and doesn't matter. Its representation is opaque, and doesn't matter.
Various functions work simply on 'ProposalTime' and 'ProposalTimingConfig'. Various functions work simply on 'PProposalTime' and 'ProposalTimingConfig'.
In particular, 'currentProposalTime' is useful for extracting the time In particular, 'currentProposalTime' is useful for extracting the time
from the 'Plutus.V1.Ledger.Api.txInfoValidPeriod' field from the 'PlutusLedgerApi.V1.txInfoValidPeriod' field
of 'Plutus.V1.Ledger.Api.TxInfo'. of 'PlutusLedgerApi.V1.TxInfo'.
We avoid 'PPOSIXTimeRange' where we can in order to save on operations. We avoid 'PPOSIXTimeRange' where we can in order to save on operations.
Note: 'PProposalTime' doesn't need a Haskell-level equivalent because it
is only used in scripts, and does not go in datums. It is also scott-encoded
which is more efficient in usage.
-} -}
data PProposalTime (s :: S) = PProposalTime data PProposalTime (s :: S) = PProposalTime
{ lowerBound :: Term s PPOSIXTime { lowerBound :: Term s PPOSIXTime
@ -132,15 +136,15 @@ deriving via
-- | Plutarch-level version of 'ProposalTimingConfig'. -- | Plutarch-level version of 'ProposalTimingConfig'.
newtype PProposalTimingConfig (s :: S) = PProposalTimingConfig newtype PProposalTimingConfig (s :: S) = PProposalTimingConfig
{ getProposalTimingConfig :: { getProposalTimingConfig ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "draftTime" ':= PPOSIXTime '[ "draftTime" ':= PPOSIXTime
, "votingTime" ':= PPOSIXTime , "votingTime" ':= PPOSIXTime
, "lockingTime" ':= PPOSIXTime , "lockingTime" ':= PPOSIXTime
, "executingTime" ':= PPOSIXTime , "executingTime" ':= PPOSIXTime
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
@ -173,7 +177,7 @@ deriving via
instance AdditiveSemigroup (Term s PPOSIXTime) where instance AdditiveSemigroup (Term s PPOSIXTime) where
(punsafeCoerce @_ @_ @PInteger -> x) + (punsafeCoerce @_ @_ @PInteger -> y) = punsafeCoerce $ x + y (punsafeCoerce @_ @_ @PInteger -> x) + (punsafeCoerce @_ @_ @PInteger -> y) = punsafeCoerce $ x + y
{- | Get the starting time of a proposal, from the 'Plutus.V1.Ledger.Api.txInfoValidPeriod' field. {- | Get the starting time of a proposal, from the 'PlutusLedgerApi.V1.txInfoValidPeriod' field.
For every proposal, this is only meant to run once upon creation. Given time range should be For every proposal, this is only meant to run once upon creation. Given time range should be
tight enough, meaning that the width of the time range should be less than the maximum value. tight enough, meaning that the width of the time range should be less than the maximum value.
-} -}
@ -195,7 +199,7 @@ createProposalStartingTime = phoistAcyclic $
pure $ pcon $ PProposalStartingTime startingTime pure $ pcon $ PProposalStartingTime startingTime
{- | Get the current proposal time, from the 'Plutus.V1.Ledger.Api.txInfoValidPeriod' field. {- | Get the current proposal time, from the 'PlutusLedgerApi.V1.txInfoValidPeriod' field.
If it's impossible to get a fully-bounded time, (e.g. either end of the 'PPOSIXTimeRange' is If it's impossible to get a fully-bounded time, (e.g. either end of the 'PPOSIXTimeRange' is
an infinity) then we error out. an infinity) then we error out.

View file

@ -16,7 +16,7 @@ module Agora.SafeMoney (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Value (AssetClass (AssetClass)) import PlutusLedgerApi.V1.Value (AssetClass (AssetClass))
import Data.Tagged (Tagged (Tagged)) import Data.Tagged (Tagged (Tagged))

View file

@ -19,8 +19,8 @@ import Agora.Aeson.Orphans ()
import Data.Aeson qualified as Aeson import Data.Aeson qualified as Aeson
import GHC.Generics qualified as GHC import GHC.Generics qualified as GHC
import Plutarch.Api.V1 (PMintingPolicy, PValidator, mintingPolicySymbol, mkMintingPolicy, mkValidator, validatorHash) import Plutarch.Api.V1 (PMintingPolicy, PValidator, mintingPolicySymbol, mkMintingPolicy, mkValidator, validatorHash)
import Plutus.V1.Ledger.Api (MintingPolicy, Validator, ValidatorHash) import PlutusLedgerApi.V1 (MintingPolicy, Validator, ValidatorHash)
import Plutus.V1.Ledger.Value (CurrencySymbol) import PlutusLedgerApi.V1.Value (CurrencySymbol)
-- | Bundle containing a 'Validator' and its hash. -- | Bundle containing a 'Validator' and its hash.
data ValidatorInfo = ValidatorInfo data ValidatorInfo = ValidatorInfo

View file

@ -32,7 +32,7 @@ import Prelude hiding (Num (..))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api (PubKeyHash) import PlutusLedgerApi.V1 (PubKeyHash)
import PlutusTx qualified import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -53,7 +53,7 @@ import Plutarch.DataRepr (
) )
import Plutarch.Internal (punsafeCoerce) import Plutarch.Internal (punsafeCoerce)
import Plutarch.Lift (PConstantDecl, PUnsafeLiftDecl (..)) import Plutarch.Lift (PConstantDecl, PUnsafeLiftDecl (..))
import Plutus.V1.Ledger.Value (AssetClass) import PlutusLedgerApi.V1.Value (AssetClass)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -175,14 +175,14 @@ PlutusTx.makeIsDataIndexed ''StakeDatum [('StakeDatum, 0)]
-- | Plutarch-level datum for Stake scripts. -- | Plutarch-level datum for Stake scripts.
newtype PStakeDatum (s :: S) = PStakeDatum newtype PStakeDatum (s :: S) = PStakeDatum
{ getStakeDatum :: { getStakeDatum ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "stakedAmount" ':= PDiscrete GTTag '[ "stakedAmount" ':= PDiscrete GTTag
, "owner" ':= PPubKeyHash , "owner" ':= PPubKeyHash
, "lockedBy" ':= PBuiltinList (PAsData PProposalLock) , "lockedBy" ':= PBuiltinList (PAsData PProposalLock)
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
@ -226,13 +226,13 @@ deriving via (DerivePConstantViaData StakeRedeemer PStakeRedeemer) instance (PCo
-- | Plutarch-level version of 'ProposalLock'. -- | Plutarch-level version of 'ProposalLock'.
newtype PProposalLock (s :: S) = PProposalLock newtype PProposalLock (s :: S) = PProposalLock
{ getProposalLock :: { getProposalLock ::
Term Term
s s
( PDataRecord ( PDataRecord
'[ "vote" ':= PResultTag '[ "vote" ':= PResultTag
, "proposalTag" ':= PProposalId , "proposalTag" ':= PProposalId
] ]
) )
} }
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)

View file

@ -28,12 +28,14 @@ import Agora.Utils (
) )
import Data.Tagged (Tagged (..), untag) import Data.Tagged (Tagged (..), untag)
import Plutarch.Api.V1 ( import Plutarch.Api.V1 (
AmountGuarantees (Positive),
PCredential (PPubKeyCredential, PScriptCredential), PCredential (PPubKeyCredential, PScriptCredential),
PMintingPolicy, PMintingPolicy,
PScriptPurpose (PMinting, PSpending), PScriptPurpose (PMinting, PSpending),
PTokenName, PTokenName,
PTxInfo, PTxInfo,
PValidator, PValidator,
PValue,
mintingPolicySymbol, mintingPolicySymbol,
mkMintingPolicy, mkMintingPolicy,
) )
@ -45,7 +47,7 @@ import Plutarch.SafeMoney (
pdiscreteValue', pdiscreteValue',
pvalueDiscrete', pvalueDiscrete',
) )
import Plutus.V1.Ledger.Value (AssetClass (AssetClass)) import PlutusLedgerApi.V1.Value (AssetClass (AssetClass))
import Prelude hiding (Num (..)) import Prelude hiding (Num (..))
{- | Policy for Stake state threads. {- | Policy for Stake state threads.
@ -57,7 +59,7 @@ import Prelude hiding (Num (..))
- Check that exactly one state thread is minted. - Check that exactly one state thread is minted.
- Check that an output exists with a state thread and a valid datum. - Check that an output exists with a state thread and a valid datum.
- Check that no state thread is an input. - Check that no state thread is an input.
- assert @'Plutus.V1.Ledger.Api.TokenName' == 'Plutus.V1.Ledger.Api.ValidatorHash'@ - assert @'PlutusLedgerApi.V1.TokenName' == 'PlutusLedgerApi.V1.ValidatorHash'@
of the script that we pay to. of the script that we pay to.
=== For burning: === For burning:
@ -226,7 +228,8 @@ stakeValidator stake =
PJust txInInfo <- tcmatch $ pfindTxInByTxOutRef # (pfield @"_0" # txOutRef) # txInfoF.inputs PJust txInInfo <- tcmatch $ pfindTxInByTxOutRef # (pfield @"_0" # txOutRef) # txInfoF.inputs
ownAddress <- tclet $ pfield @"address" #$ pfield @"resolved" # txInInfo ownAddress <- tclet $ pfield @"address" #$ pfield @"resolved" # txInInfo
let continuingValue = pfield @"value" #$ pfield @"resolved" # txInInfo let continuingValue :: Term _ (PValue _ _)
continuingValue = pfield @"value" #$ pfield @"resolved" # txInInfo
-- Whether the owner signs this transaction or not. -- Whether the owner signs this transaction or not.
ownerSignsTransaction <- tclet $ ptxSignedBy # txInfoF.signatories # stakeDatum.owner ownerSignsTransaction <- tclet $ ptxSignedBy # txInfoF.signatories # stakeDatum.owner
@ -413,8 +416,11 @@ stakeValidator stake =
) )
datumCorrect = stakeOut #== expectedDatum datumCorrect = stakeOut #== expectedDatum
let expectedValue = let valueDelta :: Term _ (PValue _ 'Positive)
paddValue # continuingValue # (pdiscreteValue' stake.gtClassRef # delta) valueDelta = pdiscreteValue' stake.gtClassRef # delta
expectedValue =
paddValue # continuingValue # valueDelta
valueCorrect = valueCorrect =
foldr1 foldr1

View file

@ -23,7 +23,7 @@ import Plutarch.DataRepr (
) )
import Plutarch.Lift (PConstantDecl (..), PLifted (..), PUnsafeLiftDecl) import Plutarch.Lift (PConstantDecl (..), PLifted (..), PUnsafeLiftDecl)
import Plutarch.TryFrom () import Plutarch.TryFrom ()
import Plutus.V1.Ledger.Value (CurrencySymbol) import PlutusLedgerApi.V1.Value (CurrencySymbol)
import PlutusTx qualified import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -90,7 +90,7 @@ treasuryValidator gatCs' = plam $ \_datum redeemer ctx' -> unTermCont $ do
-- Get the minted value from txInfo. -- Get the minted value from txInfo.
txInfo' <- tclet ctx.txInfo txInfo' <- tclet ctx.txInfo
txInfo <- tcont $ pletFields @'["mint"] txInfo' txInfo <- tcont $ pletFields @'["mint"] txInfo'
let mint :: Term _ PValue let mint :: Term _ (PValue _ _)
mint = txInfo.mint mint = txInfo.mint
gatCs <- tclet $ pconstant gatCs' gatCs <- tclet $ pconstant gatCs'

View file

@ -65,18 +65,20 @@ module Agora.Utils (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutus.V1.Ledger.Api ( import PlutusLedgerApi.V1 (
Address (..), Address (..),
Credential (..), Credential (..),
CurrencySymbol, CurrencySymbol,
TokenName (..), TokenName (..),
ValidatorHash (..), ValidatorHash (..),
) )
import Plutus.V1.Ledger.Value (AssetClass (..)) import PlutusLedgerApi.V1.Value (AssetClass (..))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Plutarch.Api.V1 ( import Plutarch.Api.V1 (
AmountGuarantees (NoGuarantees, NonZero, Positive),
KeyGuarantees (Sorted, Unsorted),
PAddress, PAddress,
PCredential (PScriptCredential), PCredential (PScriptCredential),
PCurrencySymbol, PCurrencySymbol,
@ -103,6 +105,7 @@ import Plutarch.Builtin (pforgetData, ppairDataBuiltin)
import Plutarch.Extra.Map (pkeys) import Plutarch.Extra.Map (pkeys)
import Plutarch.Reducible (Reducible (Reduce)) import Plutarch.Reducible (Reducible (Reduce))
import Plutarch.TryFrom (PTryFrom (PTryFromExcess)) import Plutarch.TryFrom (PTryFrom (PTryFromExcess))
import Plutarch.Unsafe (punsafeCoerce)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- TermCont-based combinators. Some of these will live in plutarch eventually. -- TermCont-based combinators. Some of these will live in plutarch eventually.
@ -222,7 +225,9 @@ pisJust = phoistAcyclic $
PNothing -> pconstant False PNothing -> pconstant False
-- | Get the sum of all values belonging to a particular CurrencySymbol. -- | Get the sum of all values belonging to a particular CurrencySymbol.
psymbolValueOf :: Term s (PCurrencySymbol :--> PValue :--> PInteger) psymbolValueOf ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s (PCurrencySymbol :--> PValue keys amounts :--> PInteger)
psymbolValueOf = psymbolValueOf =
phoistAcyclic $ phoistAcyclic $
plam $ \sym value'' -> unTermCont $ do plam $ \sym value'' -> unTermCont $ do
@ -233,33 +238,46 @@ psymbolValueOf =
pure $ pfoldr # plam (\x v -> pfromData (psndBuiltin # x) + v) # 0 # m pure $ pfoldr # plam (\x v -> pfromData (psndBuiltin # x) + v) # 0 # m
-- | Extract amount from PValue belonging to a Haskell-level AssetClass. -- | Extract amount from PValue belonging to a Haskell-level AssetClass.
passetClassValueOf' :: AssetClass -> Term s (PValue :--> PInteger) passetClassValueOf' ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
AssetClass ->
Term s (PValue keys amounts :--> PInteger)
passetClassValueOf' (AssetClass (sym, token)) = passetClassValueOf' (AssetClass (sym, token)) =
phoistAcyclic $ plam $ \value -> pvalueOf # value # pconstant sym # pconstant token phoistAcyclic $ plam $ \value -> pvalueOf # value # pconstant sym # pconstant token
-- | Return '>=' on two values comparing by only a particular AssetClass. -- | Return '>=' on two values comparing by only a particular AssetClass.
pgeqByClass :: Term s (PCurrencySymbol :--> PTokenName :--> PValue :--> PValue :--> PBool) pgeqByClass ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s (PCurrencySymbol :--> PTokenName :--> PValue keys amounts :--> PValue keys amounts :--> PBool)
pgeqByClass = pgeqByClass =
phoistAcyclic $ phoistAcyclic $
plam $ \cs tn a b -> plam $ \cs tn a b ->
pvalueOf # b # cs # tn #<= pvalueOf # a # cs # tn pvalueOf # b # cs # tn #<= pvalueOf # a # cs # tn
-- | Return '>=' on two values comparing by only a particular CurrencySymbol. -- | Return '>=' on two values comparing by only a particular CurrencySymbol.
pgeqBySymbol :: Term s (PCurrencySymbol :--> PValue :--> PValue :--> PBool) pgeqBySymbol ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s (PCurrencySymbol :--> PValue keys amounts :--> PValue keys amounts :--> PBool)
pgeqBySymbol = pgeqBySymbol =
phoistAcyclic $ phoistAcyclic $
plam $ \cs a b -> plam $ \cs a b ->
psymbolValueOf # cs # b #<= psymbolValueOf # cs # a psymbolValueOf # cs # b #<= psymbolValueOf # cs # a
-- | Return '>=' on two values comparing by only a particular Haskell-level AssetClass. -- | Return '>=' on two values comparing by only a particular Haskell-level AssetClass.
pgeqByClass' :: AssetClass -> Term s (PValue :--> PValue :--> PBool) pgeqByClass' ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
AssetClass ->
Term s (PValue keys amounts :--> PValue keys amounts :--> PBool)
pgeqByClass' ac = pgeqByClass' ac =
phoistAcyclic $ phoistAcyclic $
plam $ \a b -> plam $ \a b ->
passetClassValueOf' ac # b #<= passetClassValueOf' ac # a passetClassValueOf' ac # b #<= passetClassValueOf' ac # a
-- | Union two maps using a merge function on collisions. -- | Union two maps using a merge function on collisions.
pmapUnionWith :: forall k v s. PIsData v => Term s ((v :--> v :--> v) :--> PMap k v :--> PMap k v :--> PMap k v) pmapUnionWith ::
forall (k :: PType) (v :: PType) (keys :: KeyGuarantees) (s :: S).
PIsData v =>
Term s ((v :--> v :--> v) :--> PMap keys k v :--> PMap keys k v :--> PMap keys k v)
pmapUnionWith = phoistAcyclic $ pmapUnionWith = phoistAcyclic $
-- TODO: this function is kinda suspect. I feel like a lot of optimizations could be done here -- TODO: this function is kinda suspect. I feel like a lot of optimizations could be done here
plam $ \f xs' ys' -> unTermCont $ do plam $ \f xs' ys' -> unTermCont $ do
@ -301,7 +319,10 @@ pmapMaybe = phoistAcyclic $
_ -> self # f # xs _ -> self # f # xs
-- | / O(n) /. Update the value at a given key in a `PMap`, have the same functionalities as 'Data.Map.update'. -- | / O(n) /. Update the value at a given key in a `PMap`, have the same functionalities as 'Data.Map.update'.
pupdate :: forall s k v. (PIsData k, PIsData v) => Term s ((v :--> PMaybe v) :--> k :--> PMap k v :--> PMap k v) pupdate ::
forall (k :: PType) (v :: PType) (keys :: KeyGuarantees) (s :: S).
(PIsData k, PIsData v) =>
Term s ((v :--> PMaybe v) :--> k :--> PMap keys k v :--> PMap keys k v)
pupdate = phoistAcyclic $ pupdate = phoistAcyclic $
plam $ \f (pdata -> tk) (pto -> (ps :: Term _ (PBuiltinList _))) -> plam $ \f (pdata -> tk) (pto -> (ps :: Term _ (PBuiltinList _))) ->
pcon $ pcon $
@ -324,7 +345,10 @@ pupdate = phoistAcyclic $
# ps # ps
-- | / O(n) /. Map a function over all values in a 'PMap'. -- | / O(n) /. Map a function over all values in a 'PMap'.
pmapMap :: forall s k a b. (PIsData k, PIsData a, PIsData b) => Term s ((a :--> b) :--> PMap k a :--> PMap k b) pmapMap ::
forall (k :: PType) (a :: PType) (b :: PType) (keys :: KeyGuarantees) (s :: S).
(PIsData k, PIsData a, PIsData b) =>
Term s ((a :--> b) :--> PMap keys k a :--> PMap keys k b)
pmapMap = phoistAcyclic $ pmapMap = phoistAcyclic $
plam $ \f (pto -> (ps :: Term _ (PBuiltinList _))) -> plam $ \f (pto -> (ps :: Term _ (PBuiltinList _))) ->
pcon $ pcon $
@ -340,8 +364,15 @@ pmapMap = phoistAcyclic $
) )
# ps # ps
-- | Compute the guarantees known after adding two values.
type family AddGuarantees (a :: AmountGuarantees) (b :: AmountGuarantees) where
AddGuarantees 'Positive 'Positive = 'Positive
AddGuarantees _ _ = 'NoGuarantees
-- | Add two 'PValue's together. -- | Add two 'PValue's together.
paddValue :: forall s. Term s (PValue :--> PValue :--> PValue) paddValue ::
forall (keys :: KeyGuarantees) (as :: AmountGuarantees) (bs :: AmountGuarantees) (s :: S).
Term s (PValue keys as :--> PValue keys bs :--> PValue keys (AddGuarantees as bs))
paddValue = phoistAcyclic $ paddValue = phoistAcyclic $
plam $ \a' b' -> unTermCont $ do plam $ \a' b' -> unTermCont $ do
PValue a <- tcmatch a' PValue a <- tcmatch a'
@ -353,7 +384,9 @@ paddValue = phoistAcyclic $
) )
-- | Sum of all value at input. -- | Sum of all value at input.
pvalueSpent :: Term s (PBuiltinList (PAsData PTxInInfo) :--> PValue) pvalueSpent ::
forall (s :: S).
Term s (PBuiltinList (PAsData PTxInInfo) :--> PValue 'Sorted 'Positive)
pvalueSpent = phoistAcyclic $ pvalueSpent = phoistAcyclic $
plam $ \inputs -> plam $ \inputs ->
pfoldr pfoldr
@ -368,7 +401,8 @@ pvalueSpent = phoistAcyclic $
(\(PTxOut o) -> pfromData $ pfield @"value" # o) (\(PTxOut o) -> pfromData $ pfield @"value" # o)
# v # v
) )
# pconstant mempty -- TODO: This should be possible without coercions, but I can't figure out the types atm.
# punsafeCoerce (pconstant mempty :: Term _ (PValue 'Unsorted 'NonZero))
# inputs # inputs
-- | Find the TxInInfo by a TxOutRef. -- | Find the TxInInfo by a TxOutRef.
@ -415,7 +449,10 @@ ptokenSpent =
{- | True if both maps have exactly the same keys. {- | True if both maps have exactly the same keys.
Using @'#=='@ is not sufficient, because keys returned are not ordered. Using @'#=='@ is not sufficient, because keys returned are not ordered.
-} -}
pkeysEqual :: (POrd k, PIsData k) => forall (s :: S) a b. Term s (PMap k a :--> PMap k b :--> PBool) pkeysEqual ::
forall (k :: PType) (a :: PType) (b :: PType) (keys :: KeyGuarantees) (s :: S).
(POrd k, PIsData k) =>
Term s (PMap keys k a :--> PMap keys k b :--> PBool)
pkeysEqual = phoistAcyclic $ pkeysEqual = phoistAcyclic $
plam $ \p q -> unTermCont $ do plam $ \p q -> unTermCont $ do
pks <- tclet $ pkeys # p pks <- tclet $ pkeys # p
@ -575,7 +612,9 @@ phalve = phoistAcyclic $ plam $ \l -> go # l # l
-} -}
-- | Create a value with a single asset class. -- | Create a value with a single asset class.
psingletonValue :: forall s. Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PValue) psingletonValue ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PValue keys amounts)
psingletonValue = phoistAcyclic $ psingletonValue = phoistAcyclic $
plam $ \sym tok int -> plam $ \sym tok int ->
let innerTup = pcon $ PMap $ psingleton #$ ppairDataBuiltin # pdata tok # pdata int let innerTup = pcon $ PMap $ psingleton #$ ppairDataBuiltin # pdata tok # pdata int
@ -645,7 +684,9 @@ getMintingPolicySymbol :: ClosedTerm PMintingPolicy -> CurrencySymbol
getMintingPolicySymbol v = mintingPolicySymbol $ mkMintingPolicy v getMintingPolicySymbol v = mintingPolicySymbol $ mkMintingPolicy v
-- | The entire value only contains one token of the given currency symbol. -- | The entire value only contains one token of the given currency symbol.
hasOnlyOneTokenOfCurrencySymbol :: Term s (PCurrencySymbol :--> PValue :--> PBool) hasOnlyOneTokenOfCurrencySymbol ::
forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S).
Term s (PCurrencySymbol :--> PValue keys amounts :--> PBool)
hasOnlyOneTokenOfCurrencySymbol = phoistAcyclic $ hasOnlyOneTokenOfCurrencySymbol = phoistAcyclic $
plam $ \cs vs -> P.do plam $ \cs vs -> P.do
psymbolValueOf # cs # vs #== 1 psymbolValueOf # cs # vs #== 1
@ -687,5 +728,6 @@ mustBePDJust = phoistAcyclic $
PDJust ((pfield @"_0" #) -> v) -> v PDJust ((pfield @"_0" #) -> v) -> v
_ -> ptraceError emsg _ -> ptraceError emsg
-- | Create an 'Address' from a given 'ValidatorHash' with no 'PlutusLedgerApi.V1.Credential.StakingCredential'.
validatorHashToAddress :: ValidatorHash -> Address validatorHashToAddress :: ValidatorHash -> Address
validatorHashToAddress vh = Address (ScriptCredential vh) Nothing validatorHashToAddress vh = Address (ScriptCredential vh) Nothing

View file

@ -1,29 +1,29 @@
name,cpu,mem,size name,cpu,mem,size
Agora/Effects/Treasury Withdrawal Effect/effect/Simple,340268715,724428,3050 Agora/Effects/Treasury Withdrawal Effect/effect/Simple,317467035,778238,3172
Agora/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries ,570029812,1211300,3377 Agora/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries ,555940189,1350738,3499
Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets,502351827,1071087,3242 Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets,488765974,1174701,3364
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,103830462,228928,7629 Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,83689582,228928,7629
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,127968605,266935,3358 Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,97345575,266935,3358
Agora/Stake/policy/stakeCreation,59776675,126049,2116 Agora/Stake/policy/stakeCreation,43459609,126049,2116
Agora/Stake/validator/stakeDepositWithdraw deposit,276249331,599197,4024 Agora/Stake/validator/stakeDepositWithdraw deposit,226083166,599197,4024
Agora/Stake/validator/stakeDepositWithdraw withdraw,276249331,599197,4016 Agora/Stake/validator/stakeDepositWithdraw withdraw,226083166,599197,4016
Agora/Proposal/policy/proposalCreation,34784356,68894,1523 Agora/Proposal/policy/proposalCreation,23071177,68894,1523
Agora/Proposal/validator/cosignature/proposal,241651391,511819,5644 Agora/Proposal/validator/cosignature/proposal,190181087,511819,5644
Agora/Proposal/validator/cosignature/stake,186332635,402961,4561 Agora/Proposal/validator/cosignature/stake,162540553,402961,4561
Agora/Proposal/validator/voting/proposal,240181636,491168,5652 Agora/Proposal/validator/voting/proposal,181998338,491168,5652
Agora/Proposal/validator/voting/stake,154223940,328703,4614 Agora/Proposal/validator/voting/stake,127693475,328703,4614
Agora/Proposal/validator/advancing/successfully advance to next state/Draft -> VotringReady,131365724,260351,5030 Agora/Proposal/validator/advancing/successfully advance to next state/Draft -> VotringReady,98071575,260351,5030
Agora/Proposal/validator/advancing/successfully advance to next state/VotingReady -> Locked,130643392,258848,5039 Agora/Proposal/validator/advancing/successfully advance to next state/VotingReady -> Locked,97228153,258848,5039
Agora/Proposal/validator/advancing/successfully advance to next state/Locked -> Finished,132128827,262454,5039 Agora/Proposal/validator/advancing/successfully advance to next state/Locked -> Finished,98924620,262454,5039
Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Draft -> Finished,129853757,257621,5032 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Draft -> Finished,96941774,257621,5032
Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/VotingReady -> Finished,128636280,254916,5039 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/VotingReady -> Finished,95532863,254916,5039
Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Locked -> Finished,129626570,257320,5039 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Locked -> Finished,96663841,257320,5039
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,25177457,55883,806 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,21017788,55883,806
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,40266637,88241,900 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,33204186,88241,900
Agora/Treasury/Validator/Positive/Allows for effect changes,37343572,79744,1841 Agora/Treasury/Validator/Positive/Allows for effect changes,29938856,79744,1841
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,25177457,55883,806 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,21017788,55883,806
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,40266637,88241,900 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,33204186,88241,900
Agora/Governor/policy/GST minting,57978053,120125,1833 Agora/Governor/policy/GST minting,43087287,120125,1833
Agora/Governor/validator/proposal creation,330344593,681815,8145 Agora/Governor/validator/proposal creation,258936253,681815,8145
Agora/Governor/validator/GATs minting,442720585,955552,8268 Agora/Governor/validator/GATs minting,358292569,955552,8266
Agora/Governor/validator/mutate governor state,101019422,223202,7686 Agora/Governor/validator/mutate governor state,81661538,223202,7682

1 name cpu mem size
2 Agora/Effects/Treasury Withdrawal Effect/effect/Simple 340268715 317467035 724428 778238 3050 3172
3 Agora/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries 570029812 555940189 1211300 1350738 3377 3499
4 Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets 502351827 488765974 1071087 1174701 3242 3364
5 Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass 103830462 83689582 228928 7629
6 Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass 127968605 97345575 266935 3358
7 Agora/Stake/policy/stakeCreation 59776675 43459609 126049 2116
8 Agora/Stake/validator/stakeDepositWithdraw deposit 276249331 226083166 599197 4024
9 Agora/Stake/validator/stakeDepositWithdraw withdraw 276249331 226083166 599197 4016
10 Agora/Proposal/policy/proposalCreation 34784356 23071177 68894 1523
11 Agora/Proposal/validator/cosignature/proposal 241651391 190181087 511819 5644
12 Agora/Proposal/validator/cosignature/stake 186332635 162540553 402961 4561
13 Agora/Proposal/validator/voting/proposal 240181636 181998338 491168 5652
14 Agora/Proposal/validator/voting/stake 154223940 127693475 328703 4614
15 Agora/Proposal/validator/advancing/successfully advance to next state/Draft -> VotringReady 131365724 98071575 260351 5030
16 Agora/Proposal/validator/advancing/successfully advance to next state/VotingReady -> Locked 130643392 97228153 258848 5039
17 Agora/Proposal/validator/advancing/successfully advance to next state/Locked -> Finished 132128827 98924620 262454 5039
18 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Draft -> Finished 129853757 96941774 257621 5032
19 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/VotingReady -> Finished 128636280 95532863 254916 5039
20 Agora/Proposal/validator/advancing/successfully advance to failed state: timeout/Locked -> Finished 129626570 96663841 257320 5039
21 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple 25177457 21017788 55883 806
22 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs 40266637 33204186 88241 900
23 Agora/Treasury/Validator/Positive/Allows for effect changes 37343572 29938856 79744 1841
24 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple 25177457 21017788 55883 806
25 Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs 40266637 33204186 88241 900
26 Agora/Governor/policy/GST minting 57978053 43087287 120125 1833
27 Agora/Governor/validator/proposal creation 330344593 258936253 681815 8145
28 Agora/Governor/validator/GATs minting 442720585 358292569 955552 8268 8266
29 Agora/Governor/validator/mutate governor state 101019422 81661538 223202 7686 7682

View file

@ -17,5 +17,5 @@ The following is a list of terms that are used frequently throughout the documen
- **DAO**: decentralised autonomous organisation. - **DAO**: decentralised autonomous organisation.
- **Proposal**: a set of changes to a Cardano protocol, suggested by a community member. Will be enacted, if passed by the community. - **Proposal**: a set of changes to a Cardano protocol, suggested by a community member. Will be enacted, if passed by the community.
- **Governance token (GT)**: the token that confers the right to vote on proposals within the protocol. May affect the user's eligibility for rewards. Examples include Liqwid's LQ. - **Governance token (GT)**: the token that confers the right to vote on proposals within the protocol. May affect the user's eligibility for rewards. Examples include Liqwid's LQ.
- **Governance authority token (GAT)**: A token that grants the effects of a proposal the authority to alter the system. More information can be read [here](./tech-design/authority-tokens.md). - **Governance authority token (GAT)**: A token that grants the effects of a proposal the authority to alter the system. More information can be read [here](https://liqwid.notion.site/Authority-Tokens-b25d2011c8114e04ac9e73514e6b9421).
- **Effect**: A script for implementing changes suggested by a proposal. An effect can make numerous changes and a proposal may have multiple effects. - **Effect**: A script for implementing changes suggested by a proposal. An effect can make numerous changes and a proposal may have multiple effects.

5882
flake.lock generated

File diff suppressed because it is too large Load diff

256
flake.nix
View file

@ -3,13 +3,14 @@
inputs.nixpkgs.follows = "plutarch/nixpkgs"; inputs.nixpkgs.follows = "plutarch/nixpkgs";
inputs.haskell-nix.follows = "plutarch/haskell-nix"; inputs.haskell-nix.follows = "plutarch/haskell-nix";
inputs.nixpkgs-latest.url = "github:NixOS/nixpkgs?rev=a0a69be4b5ee63f1b5e75887a406e9194012b492";
# temporary fix for nix versions that have the transitive follows bug # temporary fix for nix versions that have the transitive follows bug
# see https://github.com/NixOS/nix/issues/6013 # see https://github.com/NixOS/nix/issues/6013
inputs.nixpkgs-2111 = { url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; }; inputs.nixpkgs-2111 = { url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin"; };
# Plutarch and its friends # Plutarch and its friends
inputs.plutarch.url = inputs.plutarch.url =
"github:liqwid-labs/plutarch/staging"; "github:liqwid-labs/plutarch?rev=e7ef565645146e26e75ec29fe97122a74e52c6b7";
inputs.plutarch.inputs.emanote.follows = inputs.plutarch.inputs.emanote.follows =
"plutarch/haskell-nix/nixpkgs-unstable"; "plutarch/haskell-nix/nixpkgs-unstable";
inputs.plutarch.inputs.nixpkgs.follows = inputs.plutarch.inputs.nixpkgs.follows =
@ -28,74 +29,131 @@
inputs.plutarch-context-builder.url = inputs.plutarch-context-builder.url =
"git+ssh://git@github.com/Liqwid-Labs/plutarch-context-builder?ref=main"; "git+ssh://git@github.com/Liqwid-Labs/plutarch-context-builder?ref=main";
# Purescript outputs = inputs@{ self, nixpkgs, nixpkgs-latest, haskell-nix, plutarch, ... }:
inputs.purescript-bridge.url =
"github:mlabs-haskell/purescript-bridge?rev=8e6251e8b1f489748f5bbd9ca6384bcf8cefbbef";
outputs = inputs@{ self, nixpkgs, haskell-nix, plutarch, purescript-bridge, ... }:
let let
supportedSystems = with nixpkgs.lib.systems.supported; supportedSystems = nixpkgs-latest.lib.systems.flakeExposed;
tier1 ++ tier2 ++ tier3;
perSystem = nixpkgs.lib.genAttrs supportedSystems; perSystem = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = system: pkgsFor = system: import nixpkgs {
import nixpkgs { inherit system;
inherit system; overlays = [ haskell-nix.overlay (import "${plutarch.inputs.iohk-nix}/overlays/crypto") ];
overlays = [ haskell-nix.overlay ]; # This only does bad things for us...
inherit (haskell-nix) config; # inherit (haskell-nix) config;
}; };
nixpkgsFor' = system: pkgsFor' = system: import nixpkgs-latest { inherit system; };
import nixpkgs {
inherit system; fourmoluFor = system: (pkgsFor' system).haskell.packages.ghc922.fourmolu_0_6_0_0;
inherit (haskell-nix) config;
defaultGhcVersion = "ghc923";
nonReinstallablePkgs = [
"array"
"array"
"base"
"binary"
"bytestring"
"Cabal"
"containers"
"deepseq"
"directory"
"exceptions"
"filepath"
"ghc"
"ghc-bignum"
"ghc-boot"
"ghc-boot"
"ghc-boot-th"
"ghc-compact"
"ghc-heap"
# "ghci"
# "haskeline"
"ghcjs-prim"
"ghcjs-th"
"ghc-prim"
"ghc-prim"
"hpc"
"integer-gmp"
"integer-simple"
"mtl"
"parsec"
"pretty"
"process"
"rts"
"stm"
"template-haskell"
"terminfo"
"text"
"time"
"transformers"
"unix"
"Win32"
"xhtml"
];
haskellModules = [
({ config, pkgs, hsPkgs, ... }: {
inherit nonReinstallablePkgs; # Needed for a lot of different things
packages = {
cardano-binary.doHaddock = false;
cardano-binary.ghcOptions = [ "-Wwarn" ];
cardano-crypto-class.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
cardano-crypto-class.doHaddock = false;
cardano-crypto-class.ghcOptions = [ "-Wwarn" ];
cardano-crypto-praos.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
cardano-prelude.doHaddock = false; # somehow above options are not applied?
cardano-prelude.ghcOptions = [ "-Wwarn" ];
# Workaround missing support for build-tools:
# https://github.com/input-output-hk/haskell.nix/issues/231
plutarch-test.components.exes.plutarch-test.build-tools = [
config.hsPkgs.hspec-discover
];
};
})
];
myhackage = system: compiler-nix-name: plutarch.inputs.haskell-nix-extra-hackage.mkHackageFor system compiler-nix-name (
[
"${inputs.plutarch.inputs.flat}"
"${inputs.plutarch.inputs.protolude}"
"${inputs.plutarch.inputs.cardano-prelude}/cardano-prelude"
"${inputs.plutarch.inputs.cardano-crypto}"
"${inputs.plutarch.inputs.cardano-base}/binary"
"${inputs.plutarch.inputs.cardano-base}/cardano-crypto-class"
"${inputs.plutarch.inputs.plutus}/plutus-core"
"${inputs.plutarch.inputs.plutus}/plutus-ledger-api"
"${inputs.plutarch.inputs.plutus}/plutus-tx"
"${inputs.plutarch.inputs.plutus}/prettyprinter-configurable"
"${inputs.plutarch.inputs.plutus}/word-array"
"${inputs.plutarch.inputs.secp256k1-haskell}"
"${inputs.plutarch.inputs.plutus}/plutus-tx-plugin" # necessary for FFI tests
# Custom deps as a consumer
"${inputs.plutarch}"
"${inputs.plutarch}/plutarch-extra"
"${inputs.liqwid-plutarch-extra}"
"${inputs.plutarch-numeric}"
"${inputs.plutarch-safe-money}"
"${inputs.plutarch-quickcheck}"
"${inputs.plutarch-context-builder}"
]
);
applyDep = pkgs: o:
let h = myhackage pkgs.system o.compiler-nix-name; in
(plutarch.applyPlutarchDep pkgs o) // {
modules = haskellModules ++ [ h.module ] ++ (o.modules or [ ]);
extra-hackages = [ (import h.hackageNix) ] ++ (o.extra-hackages or [ ]);
extra-hackage-tarballs = { _xNJUd_plutarch-hackage = h.hackageTarball; } // (o.extra-hackage-tarballs or { });
}; };
ghcVersion = "ghc921"; projectForGhc = compiler-nix-name: system:
let pkgs = pkgsFor system; in
projectFor = system: let pkgs' = pkgsFor' system; in
let pkgs = nixpkgsFor system; let pkgSet = pkgs.haskell-nix.cabalProject' (applyDep pkgs {
in
let pkgs' = nixpkgsFor' system;
in
(nixpkgsFor system).haskell-nix.cabalProject' {
src = ./.; src = ./.;
compiler-nix-name = ghcVersion; inherit compiler-nix-name;
inherit (plutarch) cabalProjectLocal; modules = [ ];
extraSources = plutarch.extraSources ++ [
{
src = inputs.plutarch;
subdirs = [
"."
"plutarch-extra"
];
}
{
src = inputs.liqwid-plutarch-extra;
subdirs = [ "." ];
}
{
src = inputs.plutarch-numeric;
subdirs = [ "." ];
}
{
src = inputs.plutarch-safe-money;
subdirs = [ "." ];
}
{
src = inputs.plutarch-quickcheck;
subdirs = [ "." ];
}
{
src = inputs.plutarch-context-builder;
subdirs = [ "." ];
}
{
src = inputs.purescript-bridge;
subdirs = [ "." ];
}
];
modules = [ (plutarch.haskellModule system) ];
shell = { shell = {
withHoogle = true; withHoogle = true;
@ -103,58 +161,27 @@
# We use the ones from Nixpkgs, since they are cached reliably. # We use the ones from Nixpkgs, since they are cached reliably.
# Eventually we will probably want to build these with haskell.nix. # Eventually we will probably want to build these with haskell.nix.
nativeBuildInputs = with pkgs'; [ nativeBuildInputs = [
entr pkgs'.cabal-install
haskellPackages.apply-refact pkgs'.hlint
git pkgs'.haskellPackages.cabal-fmt
fd (fourmoluFor system)
cabal-install pkgs'.nixpkgs-fmt
haskell.packages."${ghcVersion}".hlint (plutarch.hlsFor compiler-nix-name system)
haskellPackages.cabal-fmt
nixpkgs-fmt
graphviz
];
inherit (plutarch) tools;
additional = ps: [
# plutarch
ps.plutarch
ps.liqwid-plutarch-extra
ps.plutarch-numeric
ps.plutarch-safe-money
# purescript
ps.purescript-bridge
# testing
ps.tasty-quickcheck
ps.plutarch-quickcheck
ps.plutarch-context-builder
]; ];
}; };
}; }); in
pkgSet;
projectFor = projectForGhc defaultGhcVersion;
formatCheckFor = system: formatCheckFor = system:
let let
pkgs = nixpkgsFor system; pkgs' = pkgsFor' system;
pkgs' = nixpkgsFor' system;
inherit (pkgs.haskell-nix.tools ghcVersion {
inherit (plutarch.tools) fourmolu;
})
fourmolu;
in in
pkgs.runCommand "format-check" pkgs'.runCommand "format-check"
{ {
nativeBuildInputs = [ nativeBuildInputs = [ pkgs'.haskellPackages.cabal-fmt pkgs'.nixpkgs-fmt (fourmoluFor system) pkgs'.hlint ];
pkgs'.git
pkgs'.fd
pkgs'.haskellPackages.cabal-fmt
pkgs'.nixpkgs-fmt
fourmolu
pkgs'.haskell.packages."${ghcVersion}".hlint
];
} '' } ''
export LC_CTYPE=C.UTF-8 export LC_CTYPE=C.UTF-8
export LC_ALL=C.UTF-8 export LC_ALL=C.UTF-8
@ -163,12 +190,13 @@
make format_check || (echo " Please run 'make format'" ; exit 1) make format_check || (echo " Please run 'make format'" ; exit 1)
find -name '*.hs' -not -path './dist*/*' -not -path './haddock/*' | xargs hlint find -name '*.hs' -not -path './dist*/*' -not -path './haddock/*' | xargs hlint
mkdir $out mkdir $out
''; ''
;
benchCheckFor = system: agora-bench: benchCheckFor = system: agora-bench:
let let
pkgs = nixpkgsFor system; pkgs = pkgsFor system;
pkgs' = nixpkgsFor' system; pkgs' = pkgsFor' system;
in in
pkgs.runCommand "bench-check" pkgs.runCommand "bench-check"
{ {
@ -184,7 +212,6 @@
make bench_check || (echo " Please run 'make bench'" ; exit 1) make bench_check || (echo " Please run 'make bench'" ; exit 1)
mkdir $out mkdir $out
''; '';
in in
{ {
project = perSystem projectFor; project = perSystem projectFor;
@ -195,7 +222,7 @@
haddock = haddock =
let let
agora-doc = self.flake.${system}.packages."agora:lib:agora".doc; agora-doc = self.flake.${system}.packages."agora:lib:agora".doc;
pkgs = nixpkgsFor system; pkgs = pkgsFor system;
in in
pkgs.runCommand "haddock-merge" { } '' pkgs.runCommand "haddock-merge" { } ''
cd ${self} cd ${self}
@ -208,12 +235,13 @@
checks = perSystem (system: checks = perSystem (system:
self.flake.${system}.checks // { self.flake.${system}.checks // {
formatCheck = formatCheckFor system; formatCheck = formatCheckFor system;
benchCheck = benchCheckFor system self.flake.${system}.packages."agora:bench:agora-bench"; # benchCheck = benchCheckFor system self.flake.${system}.packages."agora:bench:agora-bench";
agora = self.flake.${system}.packages."agora:lib:agora"; agora = self.flake.${system}.packages."agora:lib:agora";
agora-test = self.flake.${system}.packages."agora:test:agora-test"; agora-test = self.flake.${system}.packages."agora:test:agora-test";
benchCheck = benchCheckFor system self.flake.${system}.packages."agora:bench:agora-bench";
}); });
check = perSystem (system: check = perSystem (system:
(nixpkgsFor system).runCommand "combined-test" (pkgsFor system).runCommand "combined-test"
{ {
checksss = builtins.attrValues self.checks.${system}; checksss = builtins.attrValues self.checks.${system};
} '' } ''