remove TreasuryDatum, PTryFrom for PTreasuryRedeemer
This commit is contained in:
parent
7f62b04268
commit
33bf2facb1
1 changed files with 46 additions and 47 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
Module: Agora.Treasury
|
Module: Agora.Treasury
|
||||||
Maintainer: jack@mlabs.city
|
Maintainer: jack@mlabs.city
|
||||||
|
|
@ -8,23 +10,58 @@ treasury.
|
||||||
-}
|
-}
|
||||||
module Agora.Treasury (module Agora.Treasury) where
|
module Agora.Treasury (module Agora.Treasury) where
|
||||||
|
|
||||||
|
import Agora.AuthorityToken (singleAuthorityTokenBurned)
|
||||||
|
import Agora.Utils (passert)
|
||||||
import GHC.Generics qualified as GHC
|
import GHC.Generics qualified as GHC
|
||||||
import Generics.SOP
|
import Generics.SOP
|
||||||
|
import Plutarch.Api.V1 (PValidator)
|
||||||
import Plutarch.Api.V1.Contexts (PScriptPurpose (PMinting))
|
import Plutarch.Api.V1.Contexts (PScriptPurpose (PMinting))
|
||||||
import Plutarch.Api.V1.Value (PCurrencySymbol, PValue)
|
import Plutarch.Api.V1.Value (PValue)
|
||||||
import Plutarch.DataRepr (
|
import Plutarch.DataRepr (
|
||||||
PDataFields,
|
DerivePConstantViaData (..),
|
||||||
PIsDataReprInstances (PIsDataReprInstances),
|
PIsDataReprInstances (PIsDataReprInstances),
|
||||||
)
|
)
|
||||||
|
import Plutarch.Lift (PConstantDecl (..), PLifted (..), PUnsafeLiftDecl)
|
||||||
import Plutarch.Monadic qualified as P
|
import Plutarch.Monadic qualified as P
|
||||||
|
import Plutarch.TryFrom (PTryFrom, ptryFrom)
|
||||||
import Plutus.V1.Ledger.Value (CurrencySymbol)
|
import Plutus.V1.Ledger.Value (CurrencySymbol)
|
||||||
|
import PlutusTx qualified
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
import Agora.AuthorityToken (singleAuthorityTokenBurned)
|
data TreasuryRedeemer
|
||||||
import Agora.Utils (passert)
|
= SpendTreasuryGAT
|
||||||
import Plutarch.Api.V1 (PValidator)
|
deriving stock (Eq, Show, GHC.Generic)
|
||||||
import Plutarch.Unsafe (punsafeCoerce)
|
|
||||||
|
PlutusTx.makeIsDataIndexed
|
||||||
|
''TreasuryRedeemer
|
||||||
|
[ ('SpendTreasuryGAT, 0)
|
||||||
|
]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
{- | Plutarch level type representing valid redeemers of the
|
||||||
|
treasury.
|
||||||
|
-}
|
||||||
|
newtype PTreasuryRedeemer (s :: S)
|
||||||
|
= -- | Alters treasury parameters, subject to the burning of a
|
||||||
|
-- governance authority token.
|
||||||
|
PSpendTreasuryGAT (Term s (PDataRecord '[]))
|
||||||
|
deriving stock (GHC.Generic)
|
||||||
|
deriving anyclass (Generic, PIsDataRepr)
|
||||||
|
deriving
|
||||||
|
(PlutusType, PIsData)
|
||||||
|
via PIsDataReprInstances PTreasuryRedeemer
|
||||||
|
|
||||||
|
deriving via
|
||||||
|
PAsData (PIsDataReprInstances PTreasuryRedeemer)
|
||||||
|
instance
|
||||||
|
PTryFrom PData (PAsData PTreasuryRedeemer)
|
||||||
|
|
||||||
|
instance PUnsafeLiftDecl PTreasuryRedeemer where type PLifted PTreasuryRedeemer = TreasuryRedeemer
|
||||||
|
deriving via (DerivePConstantViaData TreasuryRedeemer PTreasuryRedeemer) instance (PConstantDecl TreasuryRedeemer)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
{- | Validator ensuring that transactions consuming the treasury
|
{- | Validator ensuring that transactions consuming the treasury
|
||||||
do so in a valid manner.
|
do so in a valid manner.
|
||||||
|
|
@ -32,12 +69,8 @@ import Plutarch.Unsafe (punsafeCoerce)
|
||||||
treasuryValidator ::
|
treasuryValidator ::
|
||||||
CurrencySymbol ->
|
CurrencySymbol ->
|
||||||
ClosedTerm PValidator
|
ClosedTerm PValidator
|
||||||
treasuryValidator gatCs' = plam $ \datum redeemer ctx' -> P.do
|
treasuryValidator gatCs' = plam $ \_datum redeemer ctx' -> P.do
|
||||||
-- TODO: Use PTryFrom
|
(treasuryRedeemer, _) <- ptryFrom redeemer
|
||||||
let treasuryRedeemer :: Term _ (PAsData PTreasuryRedeemer)
|
|
||||||
treasuryRedeemer = punsafeCoerce redeemer
|
|
||||||
_treasuryDatum' :: Term _ (PAsData PTreasuryDatum)
|
|
||||||
_treasuryDatum' = punsafeCoerce datum
|
|
||||||
|
|
||||||
-- plet required fields from script context.
|
-- plet required fields from script context.
|
||||||
ctx <- pletFields @["txInfo", "purpose"] ctx'
|
ctx <- pletFields @["txInfo", "purpose"] ctx'
|
||||||
|
|
@ -46,7 +79,7 @@ treasuryValidator gatCs' = plam $ \datum redeemer ctx' -> P.do
|
||||||
PMinting _ <- pmatch ctx.purpose
|
PMinting _ <- pmatch ctx.purpose
|
||||||
|
|
||||||
-- Ensure redeemer type is valid.
|
-- Ensure redeemer type is valid.
|
||||||
PAlterTreasuryParams _ <- pmatch $ pfromData treasuryRedeemer
|
PSpendTreasuryGAT _ <- pmatch $ pfromData treasuryRedeemer
|
||||||
|
|
||||||
-- Get the minted value from txInfo.
|
-- Get the minted value from txInfo.
|
||||||
txInfo' <- plet ctx.txInfo
|
txInfo' <- plet ctx.txInfo
|
||||||
|
|
@ -59,37 +92,3 @@ treasuryValidator gatCs' = plam $ \datum redeemer ctx' -> P.do
|
||||||
passert "A single authority token has been burned" $ singleAuthorityTokenBurned gatCs txInfo' mint
|
passert "A single authority token has been burned" $ singleAuthorityTokenBurned gatCs txInfo' mint
|
||||||
|
|
||||||
popaque $ pconstant ()
|
popaque $ pconstant ()
|
||||||
|
|
||||||
{- | Plutarch level type representing datum of the treasury.
|
|
||||||
Contains:
|
|
||||||
|
|
||||||
- @stateThread@ representing the asset class of the
|
|
||||||
treasury's state thread token.
|
|
||||||
-}
|
|
||||||
newtype PTreasuryDatum (s :: S)
|
|
||||||
= PTreasuryDatum
|
|
||||||
( Term
|
|
||||||
s
|
|
||||||
( PDataRecord
|
|
||||||
'[ "stateThread" ':= PCurrencySymbol
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
deriving stock (GHC.Generic)
|
|
||||||
deriving anyclass (Generic, PIsDataRepr)
|
|
||||||
deriving
|
|
||||||
(PlutusType, PIsData, PDataFields)
|
|
||||||
via PIsDataReprInstances PTreasuryDatum
|
|
||||||
|
|
||||||
{- | Plutarch level type representing valid redeemers of the
|
|
||||||
treasury.
|
|
||||||
-}
|
|
||||||
newtype PTreasuryRedeemer (s :: S)
|
|
||||||
= -- | Alters treasury parameters, subject to the burning of a
|
|
||||||
-- governance authority token.
|
|
||||||
PAlterTreasuryParams (Term s (PDataRecord '[]))
|
|
||||||
deriving stock (GHC.Generic)
|
|
||||||
deriving anyclass (Generic, PIsDataRepr)
|
|
||||||
deriving
|
|
||||||
(PlutusType, PIsData)
|
|
||||||
via PIsDataReprInstances PTreasuryRedeemer
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue