fix treasury implementation and tests
This commit is contained in:
parent
8fbd6b9343
commit
92ea81f0cd
6 changed files with 28 additions and 119 deletions
|
|
@ -17,7 +17,6 @@ import Agora.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawalEffect
|
||||||
import Agora.Governor qualified as Governor
|
import Agora.Governor qualified as Governor
|
||||||
import Agora.Proposal qualified as Proposal
|
import Agora.Proposal qualified as Proposal
|
||||||
import Agora.Stake qualified as Stake
|
import Agora.Stake qualified as Stake
|
||||||
import Agora.Treasury qualified as Treasury
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -39,8 +38,6 @@ agoraTypes =
|
||||||
mkSumType (Proxy @Stake.ProposalLock)
|
mkSumType (Proxy @Stake.ProposalLock)
|
||||||
, mkSumType (Proxy @Stake.StakeRedeemer)
|
, mkSumType (Proxy @Stake.StakeRedeemer)
|
||||||
, mkSumType (Proxy @Stake.StakeDatum)
|
, mkSumType (Proxy @Stake.StakeDatum)
|
||||||
, -- Treasury
|
|
||||||
mkSumType (Proxy @Treasury.TreasuryRedeemer)
|
|
||||||
, -- AuthorityToken
|
, -- AuthorityToken
|
||||||
mkSumType (Proxy @AuthorityToken.AuthorityToken)
|
mkSumType (Proxy @AuthorityToken.AuthorityToken)
|
||||||
, -- Effects
|
, -- Effects
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ module Sample.Treasury (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
MintingBuilder,
|
SpendingBuilder,
|
||||||
buildMinting',
|
buildSpending',
|
||||||
credential,
|
credential,
|
||||||
input,
|
input,
|
||||||
mint,
|
mint,
|
||||||
|
|
@ -27,8 +27,8 @@ import Plutarch.Context (
|
||||||
script,
|
script,
|
||||||
signedWith,
|
signedWith,
|
||||||
txId,
|
txId,
|
||||||
withMinting,
|
|
||||||
withRefTxId,
|
withRefTxId,
|
||||||
|
withSpendingOutRefId,
|
||||||
withValue,
|
withValue,
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1.Address (Address (..))
|
import PlutusLedgerApi.V1.Address (Address (..))
|
||||||
|
|
@ -55,7 +55,7 @@ import Sample.Shared (
|
||||||
wrongEffHash,
|
wrongEffHash,
|
||||||
)
|
)
|
||||||
|
|
||||||
baseCtxBuilder :: MintingBuilder
|
baseCtxBuilder :: SpendingBuilder
|
||||||
baseCtxBuilder =
|
baseCtxBuilder =
|
||||||
let treasury =
|
let treasury =
|
||||||
mconcat
|
mconcat
|
||||||
|
|
@ -69,7 +69,7 @@ baseCtxBuilder =
|
||||||
, mint (Value.singleton gatCs gatTn (-1))
|
, mint (Value.singleton gatCs gatTn (-1))
|
||||||
, input treasury
|
, input treasury
|
||||||
, output treasury
|
, output treasury
|
||||||
, withMinting gatCs
|
, withSpendingOutRefId "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049"
|
||||||
]
|
]
|
||||||
|
|
||||||
{- | A `ScriptContext` that should be compatible with treasury
|
{- | A `ScriptContext` that should be compatible with treasury
|
||||||
|
|
@ -77,7 +77,7 @@ baseCtxBuilder =
|
||||||
-}
|
-}
|
||||||
validCtx :: ScriptContext
|
validCtx :: ScriptContext
|
||||||
validCtx =
|
validCtx =
|
||||||
let builder :: MintingBuilder
|
let builder :: SpendingBuilder
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ baseCtxBuilder
|
[ baseCtxBuilder
|
||||||
|
|
@ -88,7 +88,7 @@ validCtx =
|
||||||
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
in buildMinting' builder
|
in buildSpending' builder
|
||||||
|
|
||||||
treasuryRef :: TxOutRef
|
treasuryRef :: TxOutRef
|
||||||
treasuryRef =
|
treasuryRef =
|
||||||
|
|
@ -121,7 +121,7 @@ walletIn =
|
||||||
|
|
||||||
trCtxGATNameNotAddress :: ScriptContext
|
trCtxGATNameNotAddress :: ScriptContext
|
||||||
trCtxGATNameNotAddress =
|
trCtxGATNameNotAddress =
|
||||||
let builder :: MintingBuilder
|
let builder :: SpendingBuilder
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ baseCtxBuilder
|
[ baseCtxBuilder
|
||||||
|
|
@ -132,4 +132,4 @@ trCtxGATNameNotAddress =
|
||||||
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
in buildMinting' builder
|
in buildSpending' builder
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ Tests need to fail when:
|
||||||
module Spec.Treasury (specs) where
|
module Spec.Treasury (specs) where
|
||||||
|
|
||||||
import Agora.Treasury (
|
import Agora.Treasury (
|
||||||
TreasuryRedeemer (SpendTreasuryGAT),
|
|
||||||
treasuryValidator,
|
treasuryValidator,
|
||||||
)
|
)
|
||||||
import Agora.Utils (CompiledValidator (CompiledValidator))
|
import Agora.Utils (CompiledValidator (CompiledValidator))
|
||||||
|
|
@ -34,7 +33,7 @@ import PlutusLedgerApi.V1.Value qualified as Value (singleton)
|
||||||
import PlutusLedgerApi.V2 (DCert (DCertDelegRegKey))
|
import PlutusLedgerApi.V2 (DCert (DCertDelegRegKey))
|
||||||
import PlutusLedgerApi.V2.Contexts (
|
import PlutusLedgerApi.V2.Contexts (
|
||||||
ScriptContext (scriptContextPurpose, scriptContextTxInfo),
|
ScriptContext (scriptContextPurpose, scriptContextTxInfo),
|
||||||
ScriptPurpose (Certifying, Rewarding, Spending),
|
ScriptPurpose (Certifying, Minting, Rewarding),
|
||||||
TxInfo (txInfoInputs, txInfoMint),
|
TxInfo (txInfoInputs, txInfoMint),
|
||||||
)
|
)
|
||||||
import Sample.Shared (deterministicTracingConfing, trCredential)
|
import Sample.Shared (deterministicTracingConfing, trCredential)
|
||||||
|
|
@ -42,7 +41,6 @@ import Sample.Treasury (
|
||||||
gatCs,
|
gatCs,
|
||||||
gatTn,
|
gatTn,
|
||||||
trCtxGATNameNotAddress,
|
trCtxGATNameNotAddress,
|
||||||
treasuryRef,
|
|
||||||
validCtx,
|
validCtx,
|
||||||
walletIn,
|
walletIn,
|
||||||
)
|
)
|
||||||
|
|
@ -53,7 +51,7 @@ import Test.Specification (
|
||||||
validatorSucceedsWith,
|
validatorSucceedsWith,
|
||||||
)
|
)
|
||||||
|
|
||||||
compiledTreasuryValidator :: CompiledValidator () TreasuryRedeemer
|
compiledTreasuryValidator :: CompiledValidator () ()
|
||||||
compiledTreasuryValidator =
|
compiledTreasuryValidator =
|
||||||
CompiledValidator $
|
CompiledValidator $
|
||||||
mkValidator deterministicTracingConfing $
|
mkValidator deterministicTracingConfing $
|
||||||
|
|
@ -69,32 +67,32 @@ specs =
|
||||||
"Allows for effect changes"
|
"Allows for effect changes"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
validCtx
|
validCtx
|
||||||
, validatorSucceedsWith
|
, validatorSucceedsWith
|
||||||
"Fails when GAT token name is not script address"
|
"Fails when GAT token name is not script address"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
trCtxGATNameNotAddress
|
trCtxGATNameNotAddress
|
||||||
]
|
]
|
||||||
, group
|
, group
|
||||||
"Negative"
|
"Negative"
|
||||||
[ group
|
[ group
|
||||||
"Fails with ScriptPurpose not Minting"
|
"Fails with ScriptPurpose not Spending"
|
||||||
[ validatorFailsWith
|
[ validatorFailsWith
|
||||||
"Spending"
|
"Minting"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
validCtx
|
validCtx
|
||||||
{ scriptContextPurpose = Spending treasuryRef
|
{ scriptContextPurpose = Minting ""
|
||||||
}
|
}
|
||||||
, validatorFailsWith
|
, validatorFailsWith
|
||||||
"Rewarding"
|
"Rewarding"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
validCtx
|
validCtx
|
||||||
{ scriptContextPurpose =
|
{ scriptContextPurpose =
|
||||||
Rewarding $
|
Rewarding $
|
||||||
|
|
@ -104,7 +102,7 @@ specs =
|
||||||
"Certifying"
|
"Certifying"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
validCtx
|
validCtx
|
||||||
{ scriptContextPurpose =
|
{ scriptContextPurpose =
|
||||||
Certifying $
|
Certifying $
|
||||||
|
|
@ -116,7 +114,7 @@ specs =
|
||||||
"Fails when multiple GATs burned"
|
"Fails when multiple GATs burned"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
validCtx
|
validCtx
|
||||||
{ scriptContextTxInfo =
|
{ scriptContextTxInfo =
|
||||||
validCtx.scriptContextTxInfo
|
validCtx.scriptContextTxInfo
|
||||||
|
|
@ -131,7 +129,7 @@ specs =
|
||||||
"Fails with wallet as input"
|
"Fails with wallet as input"
|
||||||
compiledTreasuryValidator
|
compiledTreasuryValidator
|
||||||
()
|
()
|
||||||
SpendTreasuryGAT
|
()
|
||||||
( let txInfo = validCtx.scriptContextTxInfo
|
( let txInfo = validCtx.scriptContextTxInfo
|
||||||
inputs = txInfo.txInfoInputs
|
inputs = txInfo.txInfoInputs
|
||||||
newInputs =
|
newInputs =
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ module Agora.Scripts (
|
||||||
import Agora.Governor (GovernorDatum, GovernorRedeemer)
|
import Agora.Governor (GovernorDatum, GovernorRedeemer)
|
||||||
import Agora.Proposal (ProposalDatum, ProposalRedeemer)
|
import Agora.Proposal (ProposalDatum, ProposalRedeemer)
|
||||||
import Agora.Stake (StakeDatum, StakeRedeemer)
|
import Agora.Stake (StakeDatum, StakeRedeemer)
|
||||||
import Agora.Treasury (TreasuryRedeemer)
|
|
||||||
import Agora.Utils (
|
import Agora.Utils (
|
||||||
CompiledMintingPolicy (getCompiledMintingPolicy),
|
CompiledMintingPolicy (getCompiledMintingPolicy),
|
||||||
CompiledValidator (getCompiledValidator),
|
CompiledValidator (getCompiledValidator),
|
||||||
|
|
@ -54,7 +53,7 @@ data AgoraScripts = AgoraScripts
|
||||||
, compiledStakeValidator :: CompiledValidator StakeDatum StakeRedeemer
|
, compiledStakeValidator :: CompiledValidator StakeDatum StakeRedeemer
|
||||||
, compiledProposalPolicy :: CompiledMintingPolicy ()
|
, compiledProposalPolicy :: CompiledMintingPolicy ()
|
||||||
, compiledProposalValidator :: CompiledValidator ProposalDatum ProposalRedeemer
|
, compiledProposalValidator :: CompiledValidator ProposalDatum ProposalRedeemer
|
||||||
, compiledTreasuryValidator :: CompiledValidator () TreasuryRedeemer
|
, compiledTreasuryValidator :: CompiledValidator () ()
|
||||||
, compiledAuthorityTokenPolicy :: CompiledMintingPolicy ()
|
, compiledAuthorityTokenPolicy :: CompiledMintingPolicy ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,96 +9,15 @@ Contains the datum, redeemer and validator for a template DAO
|
||||||
treasury.
|
treasury.
|
||||||
-}
|
-}
|
||||||
module Agora.Treasury (
|
module Agora.Treasury (
|
||||||
TreasuryRedeemer (..),
|
|
||||||
PTreasuryRedeemer (..),
|
|
||||||
treasuryValidator,
|
treasuryValidator,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Agora.AuthorityToken (singleAuthorityTokenBurned)
|
import Agora.AuthorityToken (singleAuthorityTokenBurned)
|
||||||
import Generics.SOP qualified as SOP
|
|
||||||
import Plutarch.Api.V1.Value (PValue)
|
import Plutarch.Api.V1.Value (PValue)
|
||||||
import Plutarch.Api.V2 (PScriptPurpose (PMinting), PValidator)
|
import Plutarch.Api.V2 (PScriptPurpose (PSpending), PValidator)
|
||||||
import Plutarch.Builtin (pforgetData)
|
|
||||||
import Plutarch.Extra.IsData (
|
|
||||||
DerivePConstantViaEnum (DerivePConstantEnum),
|
|
||||||
EnumIsData (EnumIsData),
|
|
||||||
PlutusTypeEnumData,
|
|
||||||
)
|
|
||||||
import Plutarch.Extra.TermCont (pguardC, pletC, pletFieldsC, pmatchC)
|
import Plutarch.Extra.TermCont (pguardC, pletC, pletFieldsC, pmatchC)
|
||||||
import Plutarch.Lift (PConstantDecl, PLifted, PUnsafeLiftDecl)
|
|
||||||
import Plutarch.TryFrom ()
|
import Plutarch.TryFrom ()
|
||||||
import PlutusLedgerApi.V1.Value (CurrencySymbol)
|
import PlutusLedgerApi.V1.Value (CurrencySymbol)
|
||||||
import PlutusTx qualified
|
|
||||||
|
|
||||||
{- | Redeemer for Treasury actions.
|
|
||||||
|
|
||||||
@since 0.1.0
|
|
||||||
-}
|
|
||||||
data TreasuryRedeemer
|
|
||||||
= -- | Allow transaction to pass by delegating to GAT burn.
|
|
||||||
SpendTreasuryGAT
|
|
||||||
deriving stock
|
|
||||||
( -- | @since 0.1.0
|
|
||||||
Eq
|
|
||||||
, -- | @since 0.1.0
|
|
||||||
Show
|
|
||||||
, -- | @since 0.1.0
|
|
||||||
Generic
|
|
||||||
, -- | @since 0.2.0
|
|
||||||
Enum
|
|
||||||
, -- | @since 0.2.0
|
|
||||||
Bounded
|
|
||||||
)
|
|
||||||
deriving anyclass
|
|
||||||
( -- | @since 0.2.0
|
|
||||||
SOP.Generic
|
|
||||||
)
|
|
||||||
deriving
|
|
||||||
( -- | @since 0.1.0
|
|
||||||
PlutusTx.ToData
|
|
||||||
, -- | @since 0.1.0
|
|
||||||
PlutusTx.FromData
|
|
||||||
)
|
|
||||||
via (EnumIsData TreasuryRedeemer)
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
{- | Plutarch level type representing valid redeemers of the
|
|
||||||
treasury.
|
|
||||||
|
|
||||||
@since 0.1.0
|
|
||||||
-}
|
|
||||||
data PTreasuryRedeemer (s :: S)
|
|
||||||
= PSpendTreasuryGAT
|
|
||||||
deriving stock
|
|
||||||
( -- | @since 0.1.0
|
|
||||||
Generic
|
|
||||||
, -- | @since 0.2.0
|
|
||||||
Bounded
|
|
||||||
, -- | @since 0.2.0
|
|
||||||
Enum
|
|
||||||
)
|
|
||||||
deriving anyclass
|
|
||||||
( -- | @since 0.1.0
|
|
||||||
PlutusType
|
|
||||||
, -- | @since 0.1.0
|
|
||||||
PIsData
|
|
||||||
)
|
|
||||||
|
|
||||||
instance DerivePlutusType PTreasuryRedeemer where
|
|
||||||
type DPTStrat _ = PlutusTypeEnumData
|
|
||||||
|
|
||||||
-- | @since 0.1.0
|
|
||||||
instance PUnsafeLiftDecl PTreasuryRedeemer where
|
|
||||||
type PLifted PTreasuryRedeemer = TreasuryRedeemer
|
|
||||||
|
|
||||||
-- | @since 0.1.0
|
|
||||||
deriving via
|
|
||||||
(DerivePConstantViaEnum 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.
|
||||||
|
|
@ -109,16 +28,12 @@ treasuryValidator ::
|
||||||
-- | Governance Authority Token that can unlock this validator.
|
-- | 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 $ \_ _ ctx' -> unTermCont $ do
|
||||||
-- plet required fields from script context.
|
-- plet required fields from script context.
|
||||||
ctx <- pletFieldsC @["txInfo", "purpose"] ctx'
|
ctx <- pletFieldsC @["txInfo", "purpose"] ctx'
|
||||||
|
|
||||||
-- Ensure that script is for burning i.e. minting a negative amount.
|
-- Ensure that script is for spending.
|
||||||
PMinting _ <- pmatchC ctx.purpose
|
PSpending _ <- pmatchC ctx.purpose
|
||||||
|
|
||||||
-- Ensure redeemer type is valid.
|
|
||||||
pguardC "Redeemer should be SpendTreasuryGAT" $
|
|
||||||
redeemer #== pforgetData (pconstantData SpendTreasuryGAT)
|
|
||||||
|
|
||||||
-- Get the minted value from txInfo.
|
-- Get the minted value from txInfo.
|
||||||
txInfo <- pletFieldsC @'["mint", "inputs"] ctx.txInfo
|
txInfo <- pletFieldsC @'["mint", "inputs"] ctx.txInfo
|
||||||
|
|
|
||||||
|
|
@ -621,8 +621,8 @@ Agora/Proposal/validator/unlocking/illegal/with 42 proposals/creator: retract vo
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,24929970,68747,726
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,24929970,68747,726
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,47662922,128817,826
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,47662922,128817,826
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct even though scripts don't match,24929970,68747,725
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct even though scripts don't match,24929970,68747,725
|
||||||
Agora/Treasury/Validator/Positive/Allows for effect changes,40927846,108662,1430
|
Agora/Treasury/Validator/Positive/Allows for effect changes,39447993,107460,1386
|
||||||
Agora/Treasury/Validator/Positive/Fails when GAT token name is not script address,40927846,108662,1466
|
Agora/Treasury/Validator/Positive/Fails when GAT token name is not script address,39447993,107460,1422
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,24929970,68747,726
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,24929970,68747,726
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,47662922,128817,826
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,47662922,128817,826
|
||||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct even though scripts don't match,24929970,68747,725
|
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct even though scripts don't match,24929970,68747,725
|
||||||
|
|
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue