diff --git a/Makefile b/Makefile index 714165f..18a40d7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # This really ought to be `/usr/bin/env bash`, but nix flakes don't like that. SHELL := /bin/sh -.PHONY: hoogle format haddock usage tag format_nix format_haskell format_check lint +.PHONY: hoogle format haddock usage tag format_nix format_haskell format_check lint ps_bridge usage: @echo "usage: make [OPTIONS]" @@ -15,6 +15,7 @@ usage: @echo " format_nix -- Format *.nix files only" @echo " format_check -- Check if all haskell stuff have been formatted correctly" @echo " lint -- Get hlint suggestions for project" + @echo " ps_bridge -- Generate purescript bridge files" hoogle: pkill hoogle || true @@ -42,7 +43,11 @@ haddock: cabal haddock --haddock-html --haddock-hoogle --builddir=haddock tag: - hasktags -x agora agora-bench agora-test + hasktags -x agora agora-bench agora-test agora-testlib agora-sample agora-purescript-bridge lint: - hlint agora agora-bench agora-test + hlint agora agora-bench agora-test agora-testlib agora-sample agora-purescript-bridge + +PS_BRIDGE_OUTPUT_DIR := agora-purescript-bridge/ +ps_bridge: + cabal run exe:agora-purescript-bridge -- -o $(PS_BRIDGE_OUTPUT_DIR) diff --git a/agora-purescript-bridge/AgoraTypes.hs b/agora-purescript-bridge/AgoraTypes.hs new file mode 100644 index 0000000..e56d4d8 --- /dev/null +++ b/agora-purescript-bridge/AgoraTypes.hs @@ -0,0 +1,51 @@ +module AgoraTypes (agoraTypes) where + +-------------------------------------------------------------------------------- + +import Language.PureScript.Bridge ( + Language (Haskell), + SumType, + mkSumType, + ) + +-------------------------------------------------------------------------------- + +import Agora.AuthorityToken qualified as AuthorityToken +import Agora.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawalEffect +import Agora.Governor qualified as Governor +import Agora.MultiSig qualified as MultiSig +import Agora.Proposal qualified as Proposal +import Agora.Stake qualified as Stake +import Agora.Treasury qualified as Treasury + +-------------------------------------------------------------------------------- + +agoraTypes :: [SumType 'Haskell] +agoraTypes = + [ -- Proposal + mkSumType @Proposal.ProposalId + , mkSumType @Proposal.ResultTag + , mkSumType @Proposal.ProposalStatus + , mkSumType @Proposal.ProposalThresholds + , mkSumType @Proposal.ProposalVotes + , mkSumType @Proposal.ProposalDatum + , mkSumType @Proposal.ProposalRedeemer + , mkSumType @Proposal.Proposal + , -- Governor + mkSumType @Governor.GovernorDatum + , mkSumType @Governor.GovernorRedeemer + , mkSumType @Governor.Governor + , -- MultiSig + mkSumType @MultiSig.MultiSig + , -- Stake + mkSumType @Stake.Stake + , mkSumType @Stake.ProposalLock + , mkSumType @Stake.StakeRedeemer + , mkSumType @Stake.StakeDatum + , -- Treasury + mkSumType @Treasury.TreasuryRedeemer + , -- AuthorityToken + mkSumType @AuthorityToken.AuthorityToken + , -- Effects + mkSumType @TreasuryWithdrawalEffect.TreasuryWithdrawalDatum + ] diff --git a/agora-purescript-bridge/Bridge.hs b/agora-purescript-bridge/Bridge.hs new file mode 100644 index 0000000..686d21a --- /dev/null +++ b/agora-purescript-bridge/Bridge.hs @@ -0,0 +1,28 @@ +module Main (main) where + +import Language.PureScript.Bridge ( + buildBridge, + defaultBridge, + writePSTypes, + ) + +-------------------------------------------------------------------------------- + +import Control.Monad (unless) + +-------------------------------------------------------------------------------- + +import AgoraTypes (agoraTypes) +import Options (Options (..), parseOptions) + +-------------------------------------------------------------------------------- + +main :: IO () +main = do + options <- parseOptions + + unless options.quiet $ do + putStrLn $ "Writing purescript stuff to " <> options.output + putStrLn "" + + writePSTypes options.output (buildBridge defaultBridge) agoraTypes diff --git a/agora-purescript-bridge/Options.hs b/agora-purescript-bridge/Options.hs new file mode 100644 index 0000000..b93c50b --- /dev/null +++ b/agora-purescript-bridge/Options.hs @@ -0,0 +1,51 @@ +module Options (Options (..), parseOptions) where + +import Options.Applicative ((<**>)) +import Options.Applicative qualified as Opt + +import Data.Maybe (fromJust) +import Path (fromRelDir, parseRelDir, ()) + +data Options = Options + { output :: FilePath + , quiet :: Bool + } + +outputOpt :: Opt.Parser FilePath +outputOpt = + srcFilePath + <$> Opt.strOption + ( Opt.long "output-path" + <> Opt.short 'o' + <> Opt.metavar "OUTPUT_PATH" + <> Opt.value "./" + <> Opt.help "Output purescripts will be in OUTPUT_PATH/src" + ) + +quietOpt :: Opt.Parser Bool +quietOpt = + Opt.switch $ + Opt.long "quiet" + <> Opt.short 'q' + <> Opt.help "Disable verbose log messages" + +bridgeOpt :: Opt.Parser Options +bridgeOpt = Options <$> outputOpt <*> quietOpt + +parseOptions :: IO Options +parseOptions = Opt.execParser p + where + p = + Opt.info + (bridgeOpt <**> Opt.helper) + ( Opt.fullDesc + <> Opt.progDesc "Generate purescript types of Agora types" + ) + +-- Give a directory path, return the path of its src subdirectory. +srcFilePath :: FilePath -> FilePath +srcFilePath path = fromRelDir $ + fromJust $ do + dir <- parseRelDir path + srcSubDir <- parseRelDir "src" + return $ dir srcSubDir diff --git a/agora-purescript-bridge/src/Agora/AuthorityToken.purs b/agora-purescript-bridge/src/Agora/AuthorityToken.purs new file mode 100644 index 0000000..ad02237 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/AuthorityToken.purs @@ -0,0 +1,24 @@ +-- File auto generated by purescript-bridge! -- +module Agora.AuthorityToken where + +import Prelude + +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import Plutus.V1.Ledger.Value (AssetClass) +import Type.Proxy (Proxy(Proxy)) + +newtype AuthorityToken = AuthorityToken { authority :: AssetClass } + +derive instance Generic AuthorityToken _ + +derive instance Newtype AuthorityToken _ + +-------------------------------------------------------------------------------- + +_AuthorityToken :: Iso' AuthorityToken {authority :: AssetClass} +_AuthorityToken = _Newtype diff --git a/agora-purescript-bridge/src/Agora/Effect/TreasuryWithdrawal.purs b/agora-purescript-bridge/src/Agora/Effect/TreasuryWithdrawal.purs new file mode 100644 index 0000000..23a9e53 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/Effect/TreasuryWithdrawal.purs @@ -0,0 +1,29 @@ +-- File auto generated by purescript-bridge! -- +module Agora.Effect.TreasuryWithdrawal where + +import Prelude + +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import Data.Tuple (Tuple) +import Plutus.V1.Ledger.Credential (Credential) +import Plutus.V1.Ledger.Value (Value) +import Type.Proxy (Proxy(Proxy)) + +newtype TreasuryWithdrawalDatum = TreasuryWithdrawalDatum + { receivers :: Array (Tuple Credential Value) + , treasuries :: Array Credential + } + +derive instance Generic TreasuryWithdrawalDatum _ + +derive instance Newtype TreasuryWithdrawalDatum _ + +-------------------------------------------------------------------------------- + +_TreasuryWithdrawalDatum :: Iso' TreasuryWithdrawalDatum {receivers :: Array (Tuple Credential Value), treasuries :: Array Credential} +_TreasuryWithdrawalDatum = _Newtype diff --git a/agora-purescript-bridge/src/Agora/Governor.purs b/agora-purescript-bridge/src/Agora/Governor.purs new file mode 100644 index 0000000..e8f5384 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/Governor.purs @@ -0,0 +1,77 @@ +-- File auto generated by purescript-bridge! -- +module Agora.Governor where + +import Prelude + +import Agora.Proposal (ProposalId, ProposalThresholds) +import Data.Bounded.Generic (genericBottom, genericTop) +import Data.Enum (class Enum) +import Data.Enum.Generic (genericPred, genericSucc) +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import Type.Proxy (Proxy(Proxy)) + +newtype GovernorDatum = GovernorDatum + { proposalThresholds :: ProposalThresholds + , nextProposalId :: ProposalId + } + +derive instance Generic GovernorDatum _ + +derive instance Newtype GovernorDatum _ + +-------------------------------------------------------------------------------- + +_GovernorDatum :: Iso' GovernorDatum {proposalThresholds :: ProposalThresholds, nextProposalId :: ProposalId} +_GovernorDatum = _Newtype + +-------------------------------------------------------------------------------- + +data GovernorRedeemer + = CreateProposal + | MintGATs + +derive instance Generic GovernorRedeemer _ + +instance Enum GovernorRedeemer where + succ = genericSucc + pred = genericPred + +instance Bounded GovernorRedeemer where + bottom = genericBottom + top = genericTop + +-------------------------------------------------------------------------------- + +_CreateProposal :: Prism' GovernorRedeemer Unit +_CreateProposal = prism' (const CreateProposal) case _ of + CreateProposal -> Just unit + _ -> Nothing + +_MintGATs :: Prism' GovernorRedeemer Unit +_MintGATs = prism' (const MintGATs) case _ of + MintGATs -> Just unit + _ -> Nothing + +-------------------------------------------------------------------------------- + +data Governor = Governor + +derive instance Generic Governor _ + +instance Enum Governor where + succ = genericSucc + pred = genericPred + +instance Bounded Governor where + bottom = genericBottom + top = genericTop + +-------------------------------------------------------------------------------- + +_Governor :: Iso' Governor Unit +_Governor = iso (const unit) (const Governor) diff --git a/agora-purescript-bridge/src/Agora/MultiSig.purs b/agora-purescript-bridge/src/Agora/MultiSig.purs new file mode 100644 index 0000000..0ae74d8 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/MultiSig.purs @@ -0,0 +1,28 @@ +-- File auto generated by purescript-bridge! -- +module Agora.MultiSig where + +import Prelude + +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import GHC.Num.Integer (Integer) +import Plutus.V1.Ledger.Crypto (PubKeyHash) +import Type.Proxy (Proxy(Proxy)) + +newtype MultiSig = MultiSig + { keys :: Array PubKeyHash + , minSigs :: Integer + } + +derive instance Generic MultiSig _ + +derive instance Newtype MultiSig _ + +-------------------------------------------------------------------------------- + +_MultiSig :: Iso' MultiSig {keys :: Array PubKeyHash, minSigs :: Integer} +_MultiSig = _Newtype diff --git a/agora-purescript-bridge/src/Agora/Proposal.purs b/agora-purescript-bridge/src/Agora/Proposal.purs new file mode 100644 index 0000000..317987c --- /dev/null +++ b/agora-purescript-bridge/src/Agora/Proposal.purs @@ -0,0 +1,186 @@ +-- File auto generated by purescript-bridge! -- +module Agora.Proposal where + +import Prelude + +import Agora.SafeMoney (GTTag) +import Data.Bounded.Generic (genericBottom, genericTop) +import Data.Enum (class Enum) +import Data.Enum.Generic (genericPred, genericSucc) +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import Data.Tagged (Tagged) +import Data.Tuple (Tuple) +import GHC.Num.Integer (Integer) +import Plutus.V1.Ledger.Crypto (PubKeyHash) +import Plutus.V1.Ledger.Scripts (DatumHash, ValidatorHash) +import Plutus.V1.Ledger.Value (AssetClass) +import PlutusTx.AssocMap (Map) +import Type.Proxy (Proxy(Proxy)) + +newtype ProposalId = ProposalId { proposalTag :: Integer } + +derive instance Generic ProposalId _ + +derive instance Newtype ProposalId _ + +-------------------------------------------------------------------------------- + +_ProposalId :: Iso' ProposalId {proposalTag :: Integer} +_ProposalId = _Newtype + +-------------------------------------------------------------------------------- + +newtype ResultTag = ResultTag { getResultTag :: Integer } + +derive instance Generic ResultTag _ + +derive instance Newtype ResultTag _ + +-------------------------------------------------------------------------------- + +_ResultTag :: Iso' ResultTag {getResultTag :: Integer} +_ResultTag = _Newtype + +-------------------------------------------------------------------------------- + +data ProposalStatus + = Draft + | VotingReady + | Locked + | Finished + +derive instance Generic ProposalStatus _ + +instance Enum ProposalStatus where + succ = genericSucc + pred = genericPred + +instance Bounded ProposalStatus where + bottom = genericBottom + top = genericTop + +-------------------------------------------------------------------------------- + +_Draft :: Prism' ProposalStatus Unit +_Draft = prism' (const Draft) case _ of + Draft -> Just unit + _ -> Nothing + +_VotingReady :: Prism' ProposalStatus Unit +_VotingReady = prism' (const VotingReady) case _ of + VotingReady -> Just unit + _ -> Nothing + +_Locked :: Prism' ProposalStatus Unit +_Locked = prism' (const Locked) case _ of + Locked -> Just unit + _ -> Nothing + +_Finished :: Prism' ProposalStatus Unit +_Finished = prism' (const Finished) case _ of + Finished -> Just unit + _ -> Nothing + +-------------------------------------------------------------------------------- + +newtype ProposalThresholds = ProposalThresholds + { countVoting :: Tagged GTTag Integer + , create :: Tagged GTTag Integer + , startVoting :: Tagged GTTag Integer + } + +derive instance Generic ProposalThresholds _ + +derive instance Newtype ProposalThresholds _ + +-------------------------------------------------------------------------------- + +_ProposalThresholds :: Iso' ProposalThresholds {countVoting :: Tagged GTTag Integer, create :: Tagged GTTag Integer, startVoting :: Tagged GTTag Integer} +_ProposalThresholds = _Newtype + +-------------------------------------------------------------------------------- + +newtype ProposalVotes = ProposalVotes { getProposalVotes :: Map ResultTag Integer } + +derive instance Generic ProposalVotes _ + +derive instance Newtype ProposalVotes _ + +-------------------------------------------------------------------------------- + +_ProposalVotes :: Iso' ProposalVotes {getProposalVotes :: Map ResultTag Integer} +_ProposalVotes = _Newtype + +-------------------------------------------------------------------------------- + +newtype ProposalDatum = ProposalDatum + { proposalId :: ProposalId + , effects :: Map ResultTag (Array (Tuple ValidatorHash DatumHash)) + , status :: ProposalStatus + , cosigners :: Array PubKeyHash + , thresholds :: ProposalThresholds + , votes :: ProposalVotes + } + +derive instance Generic ProposalDatum _ + +derive instance Newtype ProposalDatum _ + +-------------------------------------------------------------------------------- + +_ProposalDatum :: Iso' ProposalDatum {proposalId :: ProposalId, effects :: Map ResultTag (Array (Tuple ValidatorHash DatumHash)), status :: ProposalStatus, cosigners :: Array PubKeyHash, thresholds :: ProposalThresholds, votes :: ProposalVotes} +_ProposalDatum = _Newtype + +-------------------------------------------------------------------------------- + +data ProposalRedeemer + = Vote ResultTag + | Cosign (Array PubKeyHash) + | Unlock ResultTag + | AdvanceProposal + +derive instance Generic ProposalRedeemer _ + +-------------------------------------------------------------------------------- + +_Vote :: Prism' ProposalRedeemer ResultTag +_Vote = prism' Vote case _ of + (Vote a) -> Just a + _ -> Nothing + +_Cosign :: Prism' ProposalRedeemer (Array PubKeyHash) +_Cosign = prism' Cosign case _ of + (Cosign a) -> Just a + _ -> Nothing + +_Unlock :: Prism' ProposalRedeemer ResultTag +_Unlock = prism' Unlock case _ of + (Unlock a) -> Just a + _ -> Nothing + +_AdvanceProposal :: Prism' ProposalRedeemer Unit +_AdvanceProposal = prism' (const AdvanceProposal) case _ of + AdvanceProposal -> Just unit + _ -> Nothing + +-------------------------------------------------------------------------------- + +newtype Proposal = Proposal + { governorSTAssetClass :: AssetClass + , stakeSTAssetClass :: AssetClass + , maximumCosigners :: Integer + } + +derive instance Generic Proposal _ + +derive instance Newtype Proposal _ + +-------------------------------------------------------------------------------- + +_Proposal :: Iso' Proposal {governorSTAssetClass :: AssetClass, stakeSTAssetClass :: AssetClass, maximumCosigners :: Integer} +_Proposal = _Newtype diff --git a/agora-purescript-bridge/src/Agora/Stake.purs b/agora-purescript-bridge/src/Agora/Stake.purs new file mode 100644 index 0000000..3fcb1d4 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/Stake.purs @@ -0,0 +1,103 @@ +-- File auto generated by purescript-bridge! -- +module Agora.Stake where + +import Prelude + +import Agora.Proposal (ProposalId, ResultTag) +import Agora.SafeMoney (GTTag) +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype) +import Data.Tagged (Tagged) +import GHC.Num.Integer (Integer) +import Plutus.V1.Ledger.Crypto (PubKeyHash) +import Plutus.V1.Ledger.Value (AssetClass) +import Type.Proxy (Proxy(Proxy)) + +newtype Stake = Stake + { gtClassRef :: Tagged GTTag AssetClass + , proposalSTClass :: AssetClass + } + +derive instance Generic Stake _ + +derive instance Newtype Stake _ + +-------------------------------------------------------------------------------- + +_Stake :: Iso' Stake {gtClassRef :: Tagged GTTag AssetClass, proposalSTClass :: AssetClass} +_Stake = _Newtype + +-------------------------------------------------------------------------------- + +newtype ProposalLock = ProposalLock + { vote :: ResultTag + , proposalId :: ProposalId + } + +derive instance Generic ProposalLock _ + +derive instance Newtype ProposalLock _ + +-------------------------------------------------------------------------------- + +_ProposalLock :: Iso' ProposalLock {vote :: ResultTag, proposalId :: ProposalId} +_ProposalLock = _Newtype + +-------------------------------------------------------------------------------- + +data StakeRedeemer + = DepositWithdraw (Tagged GTTag Integer) + | Destroy + | PermitVote ProposalLock + | RetractVotes (Array ProposalLock) + | WitnessStake + +derive instance Generic StakeRedeemer _ + +-------------------------------------------------------------------------------- + +_DepositWithdraw :: Prism' StakeRedeemer (Tagged GTTag Integer) +_DepositWithdraw = prism' DepositWithdraw case _ of + (DepositWithdraw a) -> Just a + _ -> Nothing + +_Destroy :: Prism' StakeRedeemer Unit +_Destroy = prism' (const Destroy) case _ of + Destroy -> Just unit + _ -> Nothing + +_PermitVote :: Prism' StakeRedeemer ProposalLock +_PermitVote = prism' PermitVote case _ of + (PermitVote a) -> Just a + _ -> Nothing + +_RetractVotes :: Prism' StakeRedeemer (Array ProposalLock) +_RetractVotes = prism' RetractVotes case _ of + (RetractVotes a) -> Just a + _ -> Nothing + +_WitnessStake :: Prism' StakeRedeemer Unit +_WitnessStake = prism' (const WitnessStake) case _ of + WitnessStake -> Just unit + _ -> Nothing + +-------------------------------------------------------------------------------- + +newtype StakeDatum = StakeDatum + { stakedAmount :: Tagged GTTag Integer + , owner :: PubKeyHash + , lockedBy :: Array ProposalLock + } + +derive instance Generic StakeDatum _ + +derive instance Newtype StakeDatum _ + +-------------------------------------------------------------------------------- + +_StakeDatum :: Iso' StakeDatum {stakedAmount :: Tagged GTTag Integer, owner :: PubKeyHash, lockedBy :: Array ProposalLock} +_StakeDatum = _Newtype diff --git a/agora-purescript-bridge/src/Agora/Treasury.purs b/agora-purescript-bridge/src/Agora/Treasury.purs new file mode 100644 index 0000000..df58ff2 --- /dev/null +++ b/agora-purescript-bridge/src/Agora/Treasury.purs @@ -0,0 +1,31 @@ +-- File auto generated by purescript-bridge! -- +module Agora.Treasury where + +import Prelude + +import Data.Bounded.Generic (genericBottom, genericTop) +import Data.Enum (class Enum) +import Data.Enum.Generic (genericPred, genericSucc) +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Maybe (Maybe(..)) +import Type.Proxy (Proxy(Proxy)) + +data TreasuryRedeemer = SpendTreasuryGAT + +derive instance Generic TreasuryRedeemer _ + +instance Enum TreasuryRedeemer where + succ = genericSucc + pred = genericPred + +instance Bounded TreasuryRedeemer where + bottom = genericBottom + top = genericTop + +-------------------------------------------------------------------------------- + +_SpendTreasuryGAT :: Iso' TreasuryRedeemer Unit +_SpendTreasuryGAT = iso (const unit) (const SpendTreasuryGAT) diff --git a/agora.cabal b/agora.cabal index 85a1f32..eb41a3f 100644 --- a/agora.cabal +++ b/agora.cabal @@ -120,6 +120,9 @@ common test-deps , tasty-hedgehog , tasty-hunit +common exe-opts + ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0 + library import: lang, deps exposed-modules: @@ -200,3 +203,17 @@ benchmark agora-bench main-is: Main.hs type: exitcode-stdio-1.0 build-depends: agora + +executable agora-purescript-bridge + import: lang, deps, exe-opts + main-is: Bridge.hs + build-depends: + , agora + , optparse-applicative + , path + , purescript-bridge + + hs-source-dirs: agora-purescript-bridge + other-modules: + AgoraTypes + Options diff --git a/agora/Agora/AuthorityToken.hs b/agora/Agora/AuthorityToken.hs index 60d644f..9692ed3 100644 --- a/agora/Agora/AuthorityToken.hs +++ b/agora/Agora/AuthorityToken.hs @@ -11,6 +11,8 @@ module Agora.AuthorityToken ( AuthorityToken (..), ) where +-------------------------------------------------------------------------------- + import Plutarch.Api.V1 ( PAddress (..), PCredential (..), @@ -28,7 +30,9 @@ import Plutarch.Api.V1.Value (PValue (PValue)) import Plutarch.Builtin (pforgetData) import Plutus.V1.Ledger.Value (AssetClass (AssetClass)) -import Prelude +-------------------------------------------------------------------------------- + +import GHC.Generics qualified as GHC -------------------------------------------------------------------------------- @@ -53,6 +57,7 @@ newtype AuthorityToken = AuthorityToken { authority :: AssetClass -- ^ Token that must move in order for minting this to be valid. } + deriving stock (GHC.Generic) -------------------------------------------------------------------------------- diff --git a/agora/Agora/Governor.hs b/agora/Agora/Governor.hs index d31a11f..4f64a76 100644 --- a/agora/Agora/Governor.hs +++ b/agora/Agora/Governor.hs @@ -106,6 +106,7 @@ data Governor = Governor -- ^ Arbitrary limit for maximum amount of cosigners on a proposal. -- See `Agora.Proposal.proposalDatumValid`. } + deriving stock (GHC.Generic) -------------------------------------------------------------------------------- diff --git a/agora/Agora/Proposal.hs b/agora/Agora/Proposal.hs index 7ef627d..eec4687 100644 --- a/agora/Agora/Proposal.hs +++ b/agora/Agora/Proposal.hs @@ -81,7 +81,7 @@ newtype ProposalId = ProposalId {proposalTag :: Integer} @ -} newtype ResultTag = ResultTag {getResultTag :: Integer} - deriving stock (Eq, Show, Ord) + deriving stock (Eq, Show, Ord, GHC.Generic) deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData) {- | The "status" of the proposal. This is only useful for state transitions that @@ -246,7 +246,7 @@ data Proposal = Proposal , maximumCosigners :: Integer -- ^ Arbitrary limit for maximum amount of cosigners on a proposal. } - deriving stock (Show, Eq) + deriving stock (Show, Eq, GHC.Generic) -------------------------------------------------------------------------------- -- Plutarch-land diff --git a/agora/Agora/Stake.hs b/agora/Agora/Stake.hs index 2ce89d7..a33f632 100644 --- a/agora/Agora/Stake.hs +++ b/agora/Agora/Stake.hs @@ -82,6 +82,7 @@ data Stake = Stake -- ^ Used when inlining the AssetClass of a 'PDiscrete' in the script code. , proposalSTClass :: AssetClass } + deriving stock (GHC.Generic) {- | A lock placed on a Stake datum in order to prevent depositing and withdrawing when votes are in place. diff --git a/flake.lock b/flake.lock index 00c46fe..910ca2e 100644 --- a/flake.lock +++ b/flake.lock @@ -48,6 +48,22 @@ "type": "github" } }, + "HTTP_4": { + "flake": false, + "locked": { + "lastModified": 1451647621, + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + }, + "original": { + "owner": "phadej", + "repo": "HTTP", + "type": "github" + } + }, "Shrinker": { "flake": false, "locked": { @@ -168,6 +184,23 @@ "type": "github" } }, + "cabal-32_4": { + "flake": false, + "locked": { + "lastModified": 1603716527, + "narHash": "sha256-X0TFfdD4KZpwl0Zr6x+PLxUt/VyKQfX7ylXHdmZIL+w=", + "owner": "haskell", + "repo": "cabal", + "rev": "48bf10787e27364730dd37a42b603cee8d6af7ee", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.2", + "repo": "cabal", + "type": "github" + } + }, "cabal-34": { "flake": false, "locked": { @@ -219,6 +252,23 @@ "type": "github" } }, + "cabal-34_4": { + "flake": false, + "locked": { + "lastModified": 1640353650, + "narHash": "sha256-N1t6M3/wqj90AEdRkeC8i923gQYUpzSr8b40qVOZ1Rk=", + "owner": "haskell", + "repo": "cabal", + "rev": "942639c18c0cd8ec53e0a6f8d120091af35312cd", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.4", + "repo": "cabal", + "type": "github" + } + }, "cabal-36": { "flake": false, "locked": { @@ -253,6 +303,23 @@ "type": "github" } }, + "cabal-36_3": { + "flake": false, + "locked": { + "lastModified": 1641652457, + "narHash": "sha256-BlFPKP4C4HRUJeAbdembX1Rms1LD380q9s0qVDeoAak=", + "owner": "haskell", + "repo": "cabal", + "rev": "f27667f8ec360c475027dcaee0138c937477b070", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.6", + "repo": "cabal", + "type": "github" + } + }, "cardano-base": { "flake": false, "locked": { @@ -383,6 +450,22 @@ "type": "github" } }, + "cardano-shell_4": { + "flake": false, + "locked": { + "lastModified": 1608537748, + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "cardano-shell", + "type": "github" + } + }, "cryptonite": { "flake": false, "locked": { @@ -400,6 +483,22 @@ "type": "github" } }, + "easy-ps": { + "flake": false, + "locked": { + "lastModified": 1649768932, + "narHash": "sha256-T96xGZV2AEP07smv/L2s5U7jY1LTdJEiTnA90gJ3Fco=", + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "rev": "d56c436a66ec2a8a93b309c83693cef1507dca7a", + "type": "github" + }, + "original": { + "owner": "justinwoo", + "repo": "easy-purescript-nix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -540,6 +639,36 @@ "type": "github" } }, + "flake-utils_4": { + "locked": { + "lastModified": 1631561581, + "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flat": { "flake": false, "locked": { @@ -625,6 +754,23 @@ "type": "github" } }, + "ghc-8.6.5-iohk_4": { + "flake": false, + "locked": { + "lastModified": 1600920045, + "narHash": "sha256-DO6kxJz248djebZLpSzTGD6s8WRpNI9BTwUeOf5RwY8=", + "owner": "input-output-hk", + "repo": "ghc", + "rev": "95713a6ecce4551240da7c96b6176f980af75cae", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "ref": "release/8.6.5-iohk", + "repo": "ghc", + "type": "github" + } + }, "gitignore-nix": { "flake": false, "locked": { @@ -737,6 +883,22 @@ "type": "github" } }, + "hackage_4": { + "flake": false, + "locked": { + "lastModified": 1652404611, + "narHash": "sha256-yfRc3lkxA7k3McDC6uqkj1VLPtl8XmrCJD6UiLm+rbw=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "d1d2ce6bb4bf964e43e015409432748a30960d8d", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "hackage.nix", + "type": "github" + } + }, "haskell-language-server": { "flake": false, "locked": { @@ -931,6 +1093,45 @@ "type": "github" } }, + "haskellNix": { + "inputs": { + "HTTP": "HTTP_4", + "cabal-32": "cabal-32_4", + "cabal-34": "cabal-34_4", + "cabal-36": "cabal-36_3", + "cardano-shell": "cardano-shell_4", + "flake-utils": "flake-utils_5", + "ghc-8.6.5-iohk": "ghc-8.6.5-iohk_4", + "hackage": "hackage_4", + "hpc-coveralls": "hpc-coveralls_4", + "hydra": "hydra", + "nix-tools": "nix-tools_4", + "nixpkgs": [ + "purescript-bridge", + "haskellNix", + "nixpkgs-unstable" + ], + "nixpkgs-2003": "nixpkgs-2003_4", + "nixpkgs-2105": "nixpkgs-2105_4", + "nixpkgs-2111": "nixpkgs-2111_6", + "nixpkgs-unstable": "nixpkgs-unstable_4", + "old-ghc-nix": "old-ghc-nix_4", + "stackage": "stackage_4" + }, + "locked": { + "lastModified": 1652433679, + "narHash": "sha256-sJgwRYdMn4jq4BpRWEvOjEAJ+68Ncrwv32IHdjQAYTU=", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "b66b0445ebec8842270d91d945227898265a114a", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "haskell.nix", + "type": "github" + } + }, "hercules-ci-agent": { "inputs": { "flake-compat": "flake-compat_4", @@ -1023,6 +1224,22 @@ "type": "github" } }, + "hpc-coveralls_4": { + "flake": false, + "locked": { + "lastModified": 1607498076, + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + }, + "original": { + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "type": "github" + } + }, "hs-memory": { "flake": false, "locked": { @@ -1089,6 +1306,30 @@ "type": "github" } }, + "hydra": { + "inputs": { + "nix": "nix", + "nixpkgs": [ + "purescript-bridge", + "haskellNix", + "hydra", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1646878427, + "narHash": "sha256-KtbrofMtN8GlM7D+n90kixr7QpSlVmdN+vK5CA/aRzc=", + "owner": "NixOS", + "repo": "hydra", + "rev": "28b682b85b7efc5cf7974065792a1f22203a5927", + "type": "github" + }, + "original": { + "id": "hydra", + "type": "indirect" + } + }, "iohk-nix": { "flake": false, "locked": { @@ -1137,6 +1378,43 @@ "type": "github" } }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": "nixpkgs_5", + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1643066034, + "narHash": "sha256-xEPeMcNJVOeZtoN+d+aRwolpW8mFSEQx76HTRdlhPhg=", + "owner": "NixOS", + "repo": "nix", + "rev": "a1cd7e58606a41fcf62bf8637804cf8306f17f62", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "2.6.0", + "repo": "nix", + "type": "github" + } + }, "nix-darwin": { "inputs": { "nixpkgs": "nixpkgs_2" @@ -1203,6 +1481,22 @@ "type": "github" } }, + "nix-tools_4": { + "flake": false, + "locked": { + "lastModified": 1649424170, + "narHash": "sha256-XgKXWispvv5RCvZzPb+p7e6Hy3LMuRjafKMl7kXzxGw=", + "owner": "input-output-hk", + "repo": "nix-tools", + "rev": "e109c94016e3b6e0db7ed413c793e2d4bdb24aa7", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "nix-tools", + "type": "github" + } + }, "nixos-20_09": { "locked": { "lastModified": 1623585158, @@ -1300,6 +1594,22 @@ "type": "github" } }, + "nixpkgs-2003_4": { + "locked": { + "lastModified": 1620055814, + "narHash": "sha256-8LEHoYSJiL901bTMVatq+rf8y7QtWuZhwwpKE2fyaRY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-20.03-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-2105": { "locked": { "lastModified": 1642244250, @@ -1348,6 +1658,22 @@ "type": "github" } }, + "nixpkgs-2105_4": { + "locked": { + "lastModified": 1645296114, + "narHash": "sha256-y53N7TyIkXsjMpOG7RhvqJFGDacLs9HlyHeSTBioqYU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "530a53dcbc9437363471167a5e4762c5fcfa34a1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-21.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-2111": { "locked": { "lastModified": 1644510859, @@ -1428,6 +1754,22 @@ "type": "github" } }, + "nixpkgs-2111_6": { + "locked": { + "lastModified": 1648744337, + "narHash": "sha256-bYe1dFJAXovjqiaPKrmAbSBEK5KUkgwVaZcTbSoJ7hg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0a58eebd8ec65ffdef2ce9562784123a73922052", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-21.11-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-nixops": { "locked": { "lastModified": 1630248577, @@ -1444,6 +1786,21 @@ "type": "github" } }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "indirect" + } + }, "nixpkgs-unstable": { "locked": { "lastModified": 1644486793, @@ -1492,6 +1849,22 @@ "type": "github" } }, + "nixpkgs-unstable_4": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1602411953, @@ -1539,6 +1912,21 @@ "type": "github" } }, + "nixpkgs_5": { + "locked": { + "lastModified": 1632864508, + "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.05-small", + "type": "indirect" + } + }, "old-ghc-nix": { "flake": false, "locked": { @@ -1590,6 +1978,23 @@ "type": "github" } }, + "old-ghc-nix_4": { + "flake": false, + "locked": { + "lastModified": 1631092763, + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + }, + "original": { + "owner": "angerman", + "ref": "master", + "repo": "old-ghc-nix", + "type": "github" + } + }, "plutarch": { "inputs": { "Shrinker": "Shrinker", @@ -1758,6 +2163,32 @@ "type": "github" } }, + "purescript-bridge": { + "inputs": { + "easy-ps": "easy-ps", + "flake-utils": "flake-utils_4", + "haskellNix": "haskellNix", + "nixpkgs": [ + "purescript-bridge", + "haskellNix", + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1649710083, + "narHash": "sha256-jd+HN/FUmmXnRy+VXT5G0y9l4YThHCIWuluxWFIffnE=", + "owner": "mlabs-haskell", + "repo": "purescript-bridge", + "rev": "8e6251e8b1f489748f5bbd9ca6384bcf8cefbbef", + "type": "github" + }, + "original": { + "owner": "mlabs-haskell", + "repo": "purescript-bridge", + "rev": "8e6251e8b1f489748f5bbd9ca6384bcf8cefbbef", + "type": "github" + } + }, "root": { "inputs": { "apropos": "apropos", @@ -1771,7 +2202,8 @@ "nixpkgs" ], "nixpkgs-2111": "nixpkgs-2111_3", - "plutarch": "plutarch" + "plutarch": "plutarch", + "purescript-bridge": "purescript-bridge" } }, "sized-functors": { @@ -1903,6 +2335,22 @@ "type": "github" } }, + "stackage_4": { + "flake": false, + "locked": { + "lastModified": 1652404704, + "narHash": "sha256-RAi3IebJ508ceEVisDjsSYJPNUbQbLPHs1SD+L08OYw=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "947645a2ded85ae0e7d1098314f37c44a0227b98", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "stackage.nix", + "type": "github" + } + }, "th-extras": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 3da51ee..d23cd9e 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,10 @@ inputs.apropos.inputs.nixpkgs.follows = "plutarch/haskell-nix/nixpkgs-unstable"; - outputs = inputs@{ self, nixpkgs, haskell-nix, plutarch, ... }: + inputs.purescript-bridge.url = + "github:mlabs-haskell/purescript-bridge?rev=8e6251e8b1f489748f5bbd9ca6384bcf8cefbbef"; + + outputs = inputs@{ self, nixpkgs, haskell-nix, plutarch, purescript-bridge, ... }: let supportedSystems = with nixpkgs.lib.systems.supported; tier1 ++ tier2 ++ tier3; @@ -77,6 +80,12 @@ src = inputs.apropos; subdirs = [ "." ]; } + { + src = inputs.purescript-bridge; + subdirs = [ + "." + ]; + } ]; modules = [ (plutarch.haskellModule system) ]; shell = { @@ -110,6 +119,7 @@ ps.plutarch-safemoney ps.plutarch-test ps.apropos + ps.purescript-bridge ]; }; };