File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
libs/plutus-preprocessor/src/Cardano/Ledger/Plutus/Preprocessor Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ $datumIsWellformedQ
2929$ inputsOutputsAreNotEmptyNoDatumQ
3030$ inputsOutputsAreNotEmptyWithDatumQ
3131$ inputsOverlapsWithRefInputsQ
32+ $ ensureTreasuryReserveQ
3233
3334-- ================================================================
3435-- Compile and serialize the real functions as Plutus scripts.
@@ -117,3 +118,9 @@ inputsOverlapsWithRefInputsBytes =
117118 ( inputsOverlapsWithRefInputsQ
118119 , PlutusBinary $ PV3. serialiseCompiledCode $$ (P. compile [|| inputsOverlapsWithRefInputs|| ])
119120 )
121+
122+ ensureTreasuryReserveBytes :: (Q [Dec ], PlutusBinary )
123+ ensureTreasuryReserveBytes =
124+ ( ensureTreasuryReserveQ
125+ , PlutusBinary $ PV3. serialiseCompiledCode $$ (P. compile [|| ensureTreasuryReserve|| ])
126+ )
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE NumericUnderscores #-}
12{-# LANGUAGE TemplateHaskell #-}
23
34module Cardano.Ledger.Plutus.Preprocessor.Source.V3 where
@@ -223,3 +224,25 @@ inputsOverlapsWithRefInputsQ =
223224 PV3D.txInfoInputs txInfo
224225 _ -> False
225226 |]
227+
228+ -- | This ensures that a single TreasuryWithdrawal can't withdraw enough to
229+ -- make the treasury have less ADA than the specified reserve amount.
230+ ensureTreasuryReserveQ :: Q [Dec ]
231+ ensureTreasuryReserveQ =
232+ [d |
233+ ensureTreasuryReserve :: P.BuiltinData -> P.BuiltinUnit
234+ ensureTreasuryReserve context =
235+ P.check $
236+ case unsafeFromBuiltinData context of
237+ PV3D.ScriptContext
238+ txInfo
239+ _
240+ (PV3D.ProposingScript _ (PV3D.ProposalProcedure _ _ (PV3D.TreasuryWithdrawals withdrawals _))) ->
241+ let
242+ totalWithdrawal = PAMD.foldr (P.+) 0 withdrawals
243+ in
244+ case PV3D.txInfoCurrentTreasuryAmount txInfo of
245+ Just treasury -> treasury P.- totalWithdrawal P.>= 100_000_000
246+ _ -> False
247+ _ -> False
248+ |]
You can’t perform that action at this time.
0 commit comments