add remaining scripts, export to json file, fix compile
This commit is contained in:
parent
56090bc5cc
commit
bc59671025
7 changed files with 83 additions and 20 deletions
|
|
@ -23,14 +23,14 @@ opt =
|
||||||
( Opt.long "config"
|
( Opt.long "config"
|
||||||
<> Opt.short 'c'
|
<> Opt.short 'c'
|
||||||
<> Opt.metavar "CONFIG_PATH"
|
<> Opt.metavar "CONFIG_PATH"
|
||||||
<> Opt.value "./"
|
<> Opt.value "./agora-scripts/agora-params.json"
|
||||||
<> Opt.help "The path where the script configuration is."
|
<> Opt.help "The path where the script configuration is."
|
||||||
)
|
)
|
||||||
<*> Opt.strOption
|
<*> Opt.strOption
|
||||||
( Opt.long "output"
|
( Opt.long "output"
|
||||||
<> Opt.short 'o'
|
<> Opt.short 'o'
|
||||||
<> Opt.metavar "OUTPUT_PATH"
|
<> Opt.metavar "OUTPUT_PATH"
|
||||||
<> Opt.value "./"
|
<> Opt.value "./agora-scripts/agora-scripts.json"
|
||||||
<> Opt.help "Output where generated scripts will be."
|
<> Opt.help "Output where generated scripts will be."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,40 @@ Description: Export scripts given configuration.
|
||||||
|
|
||||||
Export scripts given configuration.
|
Export scripts given configuration.
|
||||||
-}
|
-}
|
||||||
module Scripts (main) where
|
module Main (main) where
|
||||||
|
|
||||||
|
import Agora.AuthorityToken (AuthorityToken, authorityTokenPolicy)
|
||||||
import Agora.Governor (Governor (Governor))
|
import Agora.Governor (Governor (Governor))
|
||||||
import Agora.Governor qualified as Governor
|
import Agora.Governor qualified as Governor
|
||||||
import Agora.Governor.Scripts (governorPolicy)
|
import Agora.Governor.Scripts (
|
||||||
|
authorityTokenFromGovernor,
|
||||||
|
authorityTokenSymbolFromGovernor,
|
||||||
|
governorPolicy,
|
||||||
|
governorValidator,
|
||||||
|
proposalFromGovernor,
|
||||||
|
stakeFromGovernor,
|
||||||
|
)
|
||||||
|
import Agora.Proposal (Proposal)
|
||||||
|
import Agora.Proposal.Scripts (proposalPolicy, proposalValidator)
|
||||||
import Agora.SafeMoney (GTTag)
|
import Agora.SafeMoney (GTTag)
|
||||||
import Agora.ScriptInfo (PolicyInfo, mkPolicyInfo)
|
import Agora.ScriptInfo (PolicyInfo, ValidatorInfo, mkPolicyInfo, mkValidatorInfo)
|
||||||
|
import Agora.Stake (Stake)
|
||||||
|
import Agora.Stake.Scripts (stakePolicy, stakeValidator)
|
||||||
|
import Agora.Treasury (treasuryValidator)
|
||||||
import Control.Monad ((>=>))
|
import Control.Monad ((>=>))
|
||||||
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 Options (Options (..), parseOptions)
|
import Options (Options (..), parseOptions)
|
||||||
|
import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy)
|
||||||
import Plutarch.SafeMoney (Tagged)
|
import Plutarch.SafeMoney (Tagged)
|
||||||
import Plutus.V1.Ledger.Api (TxOutRef)
|
import Plutus.V1.Ledger.Api (TxOutRef)
|
||||||
import Plutus.V1.Ledger.Value (AssetClass)
|
import Plutus.V1.Ledger.Value (AssetClass, CurrencySymbol)
|
||||||
|
import Plutus.V1.Ledger.Value qualified as Value
|
||||||
import System.Exit (exitFailure)
|
import System.Exit (exitFailure)
|
||||||
|
import Text.Printf (printf)
|
||||||
|
|
||||||
data ScriptsConfig = ScriptsConfig
|
-- | Params required for creating script export.
|
||||||
|
data ScriptParams = ScriptParams
|
||||||
{ governorInitialSpend :: TxOutRef
|
{ governorInitialSpend :: TxOutRef
|
||||||
, gtClassRef :: Tagged GTTag AssetClass
|
, gtClassRef :: Tagged GTTag AssetClass
|
||||||
, maximumCosigners :: Integer
|
, maximumCosigners :: Integer
|
||||||
|
|
@ -29,38 +46,68 @@ data ScriptsConfig = ScriptsConfig
|
||||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||||
deriving stock (Show, Eq, GHC.Generic)
|
deriving stock (Show, Eq, GHC.Generic)
|
||||||
|
|
||||||
|
-- | Scripts that get exported.
|
||||||
data AgoraScripts = AgoraScripts
|
data AgoraScripts = AgoraScripts
|
||||||
{ governorPolicyInfo :: PolicyInfo
|
{ governorPolicyInfo :: PolicyInfo
|
||||||
|
, governorValidatorInfo :: ValidatorInfo
|
||||||
|
, stakePolicyInfo :: PolicyInfo
|
||||||
|
, stakeValidatorInfo :: ValidatorInfo
|
||||||
|
, proposalPolicyInfo :: PolicyInfo
|
||||||
|
, proposalValidatorInfo :: ValidatorInfo
|
||||||
|
, treasuryValidatorInfo :: ValidatorInfo
|
||||||
|
, authorityTokenPolicyInfo :: PolicyInfo
|
||||||
}
|
}
|
||||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||||
deriving stock (Show, Eq, GHC.Generic)
|
deriving stock (Show, Eq, GHC.Generic)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
putStrLn "Hello, world!"
|
|
||||||
|
|
||||||
options <- parseOptions
|
options <- parseOptions
|
||||||
|
|
||||||
params <-
|
params <-
|
||||||
Aeson.eitherDecodeFileStrict @ScriptsConfig options.config
|
Aeson.eitherDecodeFileStrict @ScriptParams options.config
|
||||||
>>= either (putStrLn >=> const exitFailure) pure
|
>>= either (putStrLn >=> const exitFailure) pure
|
||||||
|
|
||||||
let scripts = agoraScripts params
|
let scripts = agoraScripts params
|
||||||
|
|
||||||
print params
|
Aeson.encodeFile options.output scripts
|
||||||
print scripts
|
|
||||||
|
|
||||||
pure ()
|
printf "Done! Wrote to %s\n" options.output
|
||||||
|
|
||||||
agoraScripts :: ScriptsConfig -> AgoraScripts
|
-- | Create scripts from params.
|
||||||
agoraScripts config =
|
agoraScripts :: ScriptParams -> AgoraScripts
|
||||||
|
agoraScripts params =
|
||||||
AgoraScripts
|
AgoraScripts
|
||||||
{ governorPolicyInfo = mkPolicyInfo (governorPolicy governor)
|
{ governorPolicyInfo = mkPolicyInfo (governorPolicy governor)
|
||||||
|
, governorValidatorInfo = mkValidatorInfo (governorValidator governor)
|
||||||
|
, stakePolicyInfo = mkPolicyInfo (stakePolicy params.gtClassRef)
|
||||||
|
, stakeValidatorInfo = mkValidatorInfo (stakeValidator stake)
|
||||||
|
, proposalPolicyInfo = mkPolicyInfo (proposalPolicy governorSTAssetClass)
|
||||||
|
, proposalValidatorInfo = mkValidatorInfo (proposalValidator proposal)
|
||||||
|
, treasuryValidatorInfo = mkValidatorInfo (treasuryValidator authorityTokenSymbol)
|
||||||
|
, authorityTokenPolicyInfo = mkPolicyInfo (authorityTokenPolicy authorityToken)
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
|
governor :: Governor
|
||||||
governor =
|
governor =
|
||||||
Governor
|
Governor
|
||||||
{ Governor.gstOutRef = config.governorInitialSpend
|
{ Governor.gstOutRef = params.governorInitialSpend
|
||||||
, Governor.gtClassRef = config.gtClassRef
|
, Governor.gtClassRef = params.gtClassRef
|
||||||
, Governor.maximumCosigners = config.maximumCosigners
|
, Governor.maximumCosigners = params.maximumCosigners
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authorityToken :: AuthorityToken
|
||||||
|
authorityToken = authorityTokenFromGovernor governor
|
||||||
|
|
||||||
|
authorityTokenSymbol :: CurrencySymbol
|
||||||
|
authorityTokenSymbol = authorityTokenSymbolFromGovernor governor
|
||||||
|
|
||||||
|
governorSTAssetClass :: AssetClass
|
||||||
|
governorSTAssetClass =
|
||||||
|
Value.assetClass (mintingPolicySymbol $ mkMintingPolicy $ governorPolicy governor) ""
|
||||||
|
|
||||||
|
proposal :: Proposal
|
||||||
|
proposal = proposalFromGovernor governor
|
||||||
|
|
||||||
|
stake :: Stake
|
||||||
|
stake = stakeFromGovernor governor
|
||||||
|
|
|
||||||
11
agora-scripts/agora-params.json
Normal file
11
agora-scripts/agora-params.json
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"governorInitialSpend": {
|
||||||
|
"txOutRefId": "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be",
|
||||||
|
"txOutRefIdx": 0
|
||||||
|
},
|
||||||
|
"gtClassRef": [
|
||||||
|
"",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"maximumCosigners": 5
|
||||||
|
}
|
||||||
1
agora-scripts/agora-scripts.json
Normal file
1
agora-scripts/agora-scripts.json
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -145,11 +145,10 @@ library
|
||||||
Agora.Treasury
|
Agora.Treasury
|
||||||
Agora.Utils
|
Agora.Utils
|
||||||
Agora.Utils.Value
|
Agora.Utils.Value
|
||||||
|
|
||||||
Agora.ScriptInfo
|
Agora.ScriptInfo
|
||||||
Agora.Aeson.Orphans
|
|
||||||
|
|
||||||
other-modules:
|
other-modules:
|
||||||
|
Agora.Aeson.Orphans
|
||||||
hs-source-dirs: agora
|
hs-source-dirs: agora
|
||||||
|
|
||||||
library pprelude
|
library pprelude
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ import Plutus.V1.Ledger.Value (CurrencySymbol)
|
||||||
-- | Bundle containing a 'Validator' and its hash.
|
-- | Bundle containing a 'Validator' and its hash.
|
||||||
data ValidatorInfo = ValidatorInfo
|
data ValidatorInfo = ValidatorInfo
|
||||||
{ script :: Validator
|
{ script :: Validator
|
||||||
|
-- ^ The validator script.
|
||||||
, hash :: ValidatorHash
|
, hash :: ValidatorHash
|
||||||
|
-- ^ Hash of the validator.
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, GHC.Generic)
|
deriving stock (Show, Eq, GHC.Generic)
|
||||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||||
|
|
@ -43,7 +45,9 @@ mkValidatorInfo term =
|
||||||
-- | Bundle containing a 'MintingPolicy' and its symbol.
|
-- | Bundle containing a 'MintingPolicy' and its symbol.
|
||||||
data PolicyInfo = PolicyInfo
|
data PolicyInfo = PolicyInfo
|
||||||
{ policy :: MintingPolicy
|
{ policy :: MintingPolicy
|
||||||
|
-- ^ The minting policy.
|
||||||
, currencySymbol :: CurrencySymbol
|
, currencySymbol :: CurrencySymbol
|
||||||
|
-- ^ The symbol given by the minting policy.
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, GHC.Generic)
|
deriving stock (Show, Eq, GHC.Generic)
|
||||||
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
deriving anyclass (Aeson.ToJSON, Aeson.FromJSON)
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ deriving via
|
||||||
do so in a valid manner.
|
do so in a valid manner.
|
||||||
-}
|
-}
|
||||||
treasuryValidator ::
|
treasuryValidator ::
|
||||||
|
-- | Governance Authority Token that can unlock this validator.
|
||||||
CurrencySymbol ->
|
CurrencySymbol ->
|
||||||
ClosedTerm PValidator
|
ClosedTerm PValidator
|
||||||
treasuryValidator gatCs' = plam $ \_datum redeemer ctx' -> unTermCont $ do
|
treasuryValidator gatCs' = plam $ \_datum redeemer ctx' -> unTermCont $ do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue