commit ec70bfd539fe2e27fd48f5f76395400287ac72d7
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Tue Oct 18 18:58:59 2022 -0500
use LSE
commit 25fff9b3ad1f2dde4cd7cf36977530b06a87d23c
Merge: 01cd3aa 1821dd6
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Tue Oct 18 18:17:45 2022 -0500
Merge branch 'staging' into seungheonoh/ply
commit 01cd3aa7a235e6fe6658246ca1026fa26dc71a83
Author: Hongrui Fang <chfanghr@gmail.com>
Date: Tue Oct 11 12:02:03 2022 +0800
update benchmark
commit a8513244892ce33cfdc9edf8cd501c4985ae8008
Author: Hongrui Fang <chfanghr@gmail.com>
Date: Tue Oct 11 11:59:22 2022 +0800
fix tests
commit 20ca40823485c2e2f78253643cf4453ac7b7ddd5
Author: Hongrui Fang <chfanghr@gmail.com>
Date: Tue Oct 11 11:57:37 2022 +0800
better import
commit a19fe49424210891bd03db71e4083fc1e0edfd98
Author: Hongrui Fang <chfanghr@gmail.com>
Date: Tue Oct 11 11:08:20 2022 +0800
update flake inputs
commit c93b21f1f9441e5c6f54525bf7c6a54757ec36cc
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Mon Oct 10 12:54:12 2022 -0500
tried to make tests pass
commit 1046ae1237299a33c58b48661bdb6d325a22147e
Merge: 2bf4e36 363bd83
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Mon Oct 10 12:18:48 2022 -0500
Merge branch 'staging' into seungheonoh/ply
commit 2bf4e3627c1b229f58078695082da85c80efd560
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Mon Oct 10 10:48:36 2022 -0500
remove junkpile
commit a1dbc9ad9e531fe0d0a0480c4aef9cf9ffa90f1d
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Mon Oct 10 10:47:25 2022 -0500
versions
commit 4542a06ac733858297d3a48c53368fad19dedc43
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Thu Oct 6 22:57:48 2022 -0500
script exporting interface
commit 6bd8c1a1d57e4bf9dc25c3068a9c8eae6bf6a19d
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Thu Oct 6 22:58:41 2022 -0500
fixed tests
commit d3ce2cf95633d336f3e621833677bd5bf10ee2c8
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Sun Oct 2 00:55:18 2022 -0500
fixed tests
commit 1ae64c9f692652b77b0506013853b2ba44267c65
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Sat Oct 1 13:28:20 2022 -0500
linker
commit db88cb75c7b74843141ad8ab4e6522b66d0dcfbc
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Sat Oct 1 01:03:50 2022 -0500
exporting scripts
commit 6389fce28e885a8a7f8669629c266f59c0edb51f
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Sat Oct 1 00:51:49 2022 -0500
made scripts parameterized on the script level
commit aea1e518a8890550bdebd0e5251da11d915c53a9
Author: Seungheon Oh <seungheon.ooh@gmail.com>
Date: Wed Sep 28 19:53:29 2022 -0500
Use `TypedScriptEnvelope` for `Agora.Bootstrap`
313 lines
8.1 KiB
Haskell
313 lines
8.1 KiB
Haskell
{-# OPTIONS_GHC -Wno-orphans #-}
|
|
|
|
{- |
|
|
Module : Sample.Shared
|
|
Maintainer : emi@haskell.fyi
|
|
Description: Shared useful values for creating Samples for testing.
|
|
|
|
Shared useful values for creating Samples for testing.
|
|
-}
|
|
module Sample.Shared (
|
|
-- * Misc
|
|
signer,
|
|
signer2,
|
|
minAda,
|
|
deterministicTracingConfing,
|
|
mkRedeemer,
|
|
fromDiscrete,
|
|
|
|
-- * Agora Scripts
|
|
agoraScripts,
|
|
|
|
-- * Components
|
|
|
|
-- ** Stake
|
|
stakeAssetClass,
|
|
stakePolicy,
|
|
stakeValidator,
|
|
stakeValidatorHash,
|
|
stakeAddress,
|
|
stakeSymbol,
|
|
|
|
-- ** Governor
|
|
governor,
|
|
govPolicy,
|
|
govValidator,
|
|
govSymbol,
|
|
govAssetClass,
|
|
govValidatorAddress,
|
|
govValidatorHash,
|
|
gstUTXORef,
|
|
|
|
-- ** Proposal
|
|
proposalPolicy,
|
|
proposalPolicySymbol,
|
|
proposalValidator,
|
|
proposalValidatorHash,
|
|
proposalValidatorAddress,
|
|
proposalStartingTimeFromTimeRange,
|
|
|
|
-- ** Authority
|
|
authorityTokenPolicy,
|
|
authorityTokenSymbol,
|
|
|
|
-- ** Treasury
|
|
treasuryOut,
|
|
gatTn,
|
|
gatCs,
|
|
mockTrEffect,
|
|
mockTrEffectHash,
|
|
trValidator,
|
|
trCredential,
|
|
wrongEffHash,
|
|
) where
|
|
|
|
import Agora.Bootstrap qualified as Bootstrap
|
|
import Agora.Governor (Governor (Governor))
|
|
import Agora.Linker (linker)
|
|
import Agora.Proposal (ProposalThresholds (..))
|
|
import Agora.Proposal.Time (
|
|
MaxTimeRangeWidth (..),
|
|
ProposalStartingTime (ProposalStartingTime),
|
|
ProposalTimingConfig (..),
|
|
)
|
|
import Agora.Utils (
|
|
validatorHashToTokenName,
|
|
)
|
|
import Data.Coerce (coerce)
|
|
import Data.Default.Class (Default (..))
|
|
import Data.Map (Map, (!))
|
|
import Data.Tagged (Tagged (..))
|
|
import Data.Text (Text)
|
|
import Optics (view)
|
|
import Plutarch (Config (..), TracingMode (DetTracing))
|
|
import Plutarch.Api.V2 (
|
|
mintingPolicySymbol,
|
|
validatorHash,
|
|
)
|
|
import Plutarch.SafeMoney (Discrete (Discrete))
|
|
import PlutusLedgerApi.V1.Address (scriptHashAddress)
|
|
import PlutusLedgerApi.V1.Value (AssetClass (AssetClass), TokenName, Value)
|
|
import PlutusLedgerApi.V1.Value qualified as Value (
|
|
assetClass,
|
|
singleton,
|
|
)
|
|
import PlutusLedgerApi.V2 (
|
|
Address (Address),
|
|
Credential (ScriptCredential),
|
|
CurrencySymbol,
|
|
Extended (..),
|
|
Interval (..),
|
|
LowerBound (..),
|
|
MintingPolicy (..),
|
|
OutputDatum (NoOutputDatum),
|
|
POSIXTimeRange,
|
|
PubKeyHash,
|
|
Redeemer (..),
|
|
Script,
|
|
ToData (toBuiltinData),
|
|
TxOut (
|
|
TxOut,
|
|
txOutAddress,
|
|
txOutDatum,
|
|
txOutReferenceScript,
|
|
txOutValue
|
|
),
|
|
TxOutRef (TxOutRef),
|
|
UpperBound (..),
|
|
Validator (Validator),
|
|
ValidatorHash (ValidatorHash),
|
|
)
|
|
import PlutusTx qualified
|
|
import ScriptExport.ScriptInfo (runLinker)
|
|
|
|
-- Plutarch compiler configauration.
|
|
-- TODO: add the ability to change this value. Maybe wrap everything in a
|
|
-- Reader monad?
|
|
deterministicTracingConfing :: Config
|
|
deterministicTracingConfing = Config DetTracing
|
|
|
|
governor :: Governor
|
|
governor = Governor oref gt mc
|
|
where
|
|
oref = gstUTXORef
|
|
gt =
|
|
Tagged $
|
|
Value.assetClass
|
|
"da8c30857834c6ae7203935b89278c532b3995245295456f993e1d24"
|
|
"LQ"
|
|
mc = 20
|
|
|
|
agoraScripts :: Map Text Script
|
|
agoraScripts =
|
|
either
|
|
(error . show)
|
|
(view #scripts)
|
|
( runLinker
|
|
linker
|
|
(Bootstrap.agoraScripts deterministicTracingConfing)
|
|
governor
|
|
)
|
|
|
|
stakePolicy :: MintingPolicy
|
|
stakePolicy = MintingPolicy $ agoraScripts ! "agora:stakePolicy"
|
|
|
|
stakeSymbol :: CurrencySymbol
|
|
stakeSymbol = mintingPolicySymbol stakePolicy
|
|
|
|
stakeAssetClass :: AssetClass
|
|
stakeAssetClass = AssetClass (stakeSymbol, validatorHashToTokenName stakeValidatorHash)
|
|
|
|
stakeValidator :: Validator
|
|
stakeValidator = Validator $ agoraScripts ! "agora:stakeValidator"
|
|
|
|
stakeValidatorHash :: ValidatorHash
|
|
stakeValidatorHash = validatorHash stakeValidator
|
|
|
|
stakeAddress :: Address
|
|
stakeAddress = Address (ScriptCredential stakeValidatorHash) Nothing
|
|
|
|
gstUTXORef :: TxOutRef
|
|
gstUTXORef = TxOutRef "f28cd7145c24e66fd5bcd2796837aeb19a48a2656e7833c88c62a2d0450bd00d" 0
|
|
|
|
govPolicy :: MintingPolicy
|
|
govPolicy = MintingPolicy $ agoraScripts ! "agora:governorPolicy"
|
|
|
|
govValidator :: Validator
|
|
govValidator = Validator $ agoraScripts ! "agora:governorValidator"
|
|
|
|
govSymbol :: CurrencySymbol
|
|
govSymbol = mintingPolicySymbol govPolicy
|
|
|
|
govAssetClass :: AssetClass
|
|
govAssetClass = AssetClass (govSymbol, "")
|
|
|
|
govValidatorHash :: ValidatorHash
|
|
govValidatorHash = validatorHash govValidator
|
|
|
|
govValidatorAddress :: Address
|
|
govValidatorAddress = scriptHashAddress govValidatorHash
|
|
|
|
proposalPolicy :: MintingPolicy
|
|
proposalPolicy = MintingPolicy $ agoraScripts ! "agora:proposalPolicy"
|
|
|
|
proposalPolicySymbol :: CurrencySymbol
|
|
proposalPolicySymbol = mintingPolicySymbol proposalPolicy
|
|
|
|
-- | A sample 'PubKeyHash'.
|
|
signer :: PubKeyHash
|
|
signer = "8a30896c4fd5e79843e4ca1bd2cdbaa36f8c0bc3be7401214142019c"
|
|
|
|
-- | Another sample 'PubKeyHash'.
|
|
signer2 :: PubKeyHash
|
|
signer2 = "8a30896c4fd5e79843e4ca1bd2cdbaa36f8c0bc3be74012141420192"
|
|
|
|
proposalValidator :: Validator
|
|
proposalValidator = Validator $ agoraScripts ! "agora:proposalValidator"
|
|
|
|
proposalValidatorHash :: ValidatorHash
|
|
proposalValidatorHash = validatorHash proposalValidator
|
|
|
|
proposalValidatorAddress :: Address
|
|
proposalValidatorAddress = scriptHashAddress proposalValidatorHash
|
|
|
|
{- | Default value of 'Agora.Proposal.ProposalThresholds'.
|
|
For testing purpose only.
|
|
-}
|
|
instance Default ProposalThresholds where
|
|
def =
|
|
ProposalThresholds
|
|
{ execute = Tagged 1000
|
|
, create = Tagged 1
|
|
, toVoting = Tagged 100
|
|
, vote = Tagged 100
|
|
, cosign = Tagged 100
|
|
}
|
|
|
|
authorityTokenPolicy :: MintingPolicy
|
|
authorityTokenPolicy = MintingPolicy $ agoraScripts ! "agora:authorityTokenPolicy"
|
|
|
|
authorityTokenSymbol :: CurrencySymbol
|
|
authorityTokenSymbol = mintingPolicySymbol authorityTokenPolicy
|
|
|
|
{- | Default value of 'Agora.Governor.GovernorDatum.proposalTimings'.
|
|
For testing purpose only.
|
|
-}
|
|
instance Default ProposalTimingConfig where
|
|
def =
|
|
ProposalTimingConfig
|
|
{ draftTime = 50
|
|
, votingTime = 1000
|
|
, lockingTime = 2000
|
|
, executingTime = 3000
|
|
}
|
|
|
|
{- | Default value of 'Agora.Governor.GovernorDatum.createProposalTimeRangeMaxWidth'.
|
|
For testing purpose only.
|
|
-}
|
|
instance Default MaxTimeRangeWidth where
|
|
def = MaxTimeRangeWidth 10
|
|
|
|
{- | Get the starting time of a proposal, given a closed finite time range.
|
|
Tightness of the time range is not checked. See 'Agora.Proposal.Time.createProposalStartingTime'.
|
|
-}
|
|
proposalStartingTimeFromTimeRange :: POSIXTimeRange -> ProposalStartingTime
|
|
proposalStartingTimeFromTimeRange
|
|
(Interval (LowerBound (Finite l) True) (UpperBound (Finite u) True)) =
|
|
ProposalStartingTime $ (l + u) `div` 2
|
|
proposalStartingTimeFromTimeRange _ = error "Given time range should be finite and closed"
|
|
|
|
mkRedeemer :: forall redeemer. PlutusTx.ToData redeemer => redeemer -> Redeemer
|
|
mkRedeemer = Redeemer . toBuiltinData
|
|
|
|
fromDiscrete :: forall tag. Discrete tag -> Integer
|
|
fromDiscrete = coerce
|
|
|
|
------------------------------------------------------------------
|
|
|
|
treasuryOut :: TxOut
|
|
treasuryOut =
|
|
TxOut
|
|
{ txOutAddress = Address trCredential Nothing
|
|
, txOutValue = minAda
|
|
, txOutDatum = NoOutputDatum
|
|
, txOutReferenceScript = Nothing
|
|
}
|
|
|
|
{- | Arbitrary 'CurrencySymbol', representing the 'CurrencySymbol'
|
|
of a valid governance authority token (GAT).
|
|
-}
|
|
gatCs :: CurrencySymbol
|
|
gatCs = authorityTokenSymbol
|
|
|
|
trValidator :: Validator
|
|
trValidator = Validator $ agoraScripts ! "agora:treasuryValidator"
|
|
|
|
-- | `ScriptCredential` used for the dummy treasury validator.
|
|
trCredential :: Credential
|
|
trCredential = ScriptCredential $ validatorHash trValidator
|
|
|
|
-- | `TokenName` for GAT generated from address of `mockTrEffect`.
|
|
gatTn :: TokenName
|
|
gatTn = validatorHashToTokenName $ validatorHash mockTrEffect
|
|
|
|
-- | Mock treasury effect script, used for testing.
|
|
mockTrEffect :: Validator
|
|
mockTrEffect = Validator $ agoraScripts ! "agora:noOpValidator"
|
|
|
|
-- | Mock treasury effect validator hash
|
|
mockTrEffectHash :: ValidatorHash
|
|
mockTrEffectHash = validatorHash mockTrEffect
|
|
|
|
{- | A SHA-256 hash which (in all certainty) should not match the
|
|
hash of the dummy effect script.
|
|
-}
|
|
wrongEffHash :: ValidatorHash
|
|
wrongEffHash =
|
|
ValidatorHash
|
|
"a21bc4a1d95600f9fa0a00b97ed0fa49a152a72de76253cb706f90b4b40f837b"
|
|
|
|
------------------------------------------------------------------
|
|
|
|
minAda :: Value
|
|
minAda = Value.singleton "" "" 10_000_000
|