Minor fixes
Using Utils.hs, fixing fusioning issue, fixing CI build
This commit is contained in:
parent
e08efd173b
commit
4cd6e6f534
1 changed files with 17 additions and 34 deletions
|
|
@ -13,18 +13,16 @@ import GHC.Generics qualified as GHC
|
||||||
import Generics.SOP (Generic, I (I))
|
import Generics.SOP (Generic, I (I))
|
||||||
|
|
||||||
import Agora.Effect (makeEffect)
|
import Agora.Effect (makeEffect)
|
||||||
import Agora.Utils ( passert, passetClassValueOf' )
|
import Agora.Utils (findTxOutByTxOutRef, passert)
|
||||||
import Plutarch (popaque)
|
import Plutarch (popaque)
|
||||||
import Plutarch.Api.V1
|
import Plutarch.Api.V1 (
|
||||||
( PTxInfo,
|
|
||||||
PTxOutRef,
|
|
||||||
PValidator,
|
|
||||||
PTuple,
|
|
||||||
PValue,
|
|
||||||
PCredential,
|
PCredential,
|
||||||
|
PTuple,
|
||||||
|
PValidator,
|
||||||
|
PValue,
|
||||||
ptuple,
|
ptuple,
|
||||||
PTxInInfo,
|
)
|
||||||
PTxOut )
|
|
||||||
import Plutarch.DataRepr (
|
import Plutarch.DataRepr (
|
||||||
DerivePConstantViaData (..),
|
DerivePConstantViaData (..),
|
||||||
PDataFields,
|
PDataFields,
|
||||||
|
|
@ -33,17 +31,17 @@ import Plutarch.DataRepr (
|
||||||
import Plutarch.Lift (PUnsafeLiftDecl (..))
|
import Plutarch.Lift (PUnsafeLiftDecl (..))
|
||||||
import Plutarch.Monadic qualified as P
|
import Plutarch.Monadic qualified as P
|
||||||
import Plutus.V1.Ledger.Credential (Credential)
|
import Plutus.V1.Ledger.Credential (Credential)
|
||||||
import Plutus.V1.Ledger.Value (AssetClass (..), CurrencySymbol, Value)
|
import Plutus.V1.Ledger.Value (CurrencySymbol, Value)
|
||||||
import PlutusTx qualified
|
import PlutusTx qualified
|
||||||
|
|
||||||
data TreasuryWithdrawalDatum = TreasuryWithdrawalDatum {receivers :: [(Credential, Value)]}
|
newtype TreasuryWithdrawalDatum = TreasuryWithdrawalDatum {receivers :: [(Credential, Value)]}
|
||||||
deriving stock (Show, GHC.Generic)
|
deriving stock (Show, GHC.Generic)
|
||||||
deriving anyclass (Generic)
|
deriving anyclass (Generic)
|
||||||
|
|
||||||
PlutusTx.makeLift ''TreasuryWithdrawalDatum
|
PlutusTx.makeLift ''TreasuryWithdrawalDatum
|
||||||
PlutusTx.unstableMakeIsData ''TreasuryWithdrawalDatum
|
PlutusTx.unstableMakeIsData ''TreasuryWithdrawalDatum
|
||||||
|
|
||||||
data PTreasuryWithdrawalDatum (s :: S)
|
newtype PTreasuryWithdrawalDatum (s :: S)
|
||||||
= PTreasuryWithdrawalDatum
|
= PTreasuryWithdrawalDatum
|
||||||
( Term
|
( Term
|
||||||
s
|
s
|
||||||
|
|
@ -64,20 +62,6 @@ deriving via
|
||||||
instance
|
instance
|
||||||
(PConstant TreasuryWithdrawalDatum)
|
(PConstant TreasuryWithdrawalDatum)
|
||||||
|
|
||||||
-- These functions can be replaced with ones on Utils.hs once seungheonoh/util branch get merged.
|
|
||||||
findOwnInput :: Term s (PTxInfo :--> PTxOutRef :--> PTxInInfo)
|
|
||||||
findOwnInput = phoistAcyclic $
|
|
||||||
plam $ \txInfo spending' -> P.do
|
|
||||||
input <- plet $ pfromData $ pfield @"inputs" # txInfo
|
|
||||||
spending <- plet $ pdata spending'
|
|
||||||
PJust result <- pmatch $ pfind # plam (\x -> pfield @"outRef" # x #== spending) # input
|
|
||||||
pfromData result
|
|
||||||
|
|
||||||
findOwnAddress :: Term s (PTxInfo :--> PTxOutRef :--> PTxOut)
|
|
||||||
findOwnAddress = phoistAcyclic $
|
|
||||||
plam $ \txInfo spending -> P.do
|
|
||||||
pfromData $ pfield @"resolved" #$ findOwnInput # txInfo # spending
|
|
||||||
|
|
||||||
treasuryWithdrawalValidator :: forall {s :: S}. CurrencySymbol -> Term s PValidator
|
treasuryWithdrawalValidator :: forall {s :: S}. CurrencySymbol -> Term s PValidator
|
||||||
treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
||||||
\_cs (datum' :: Term _ PTreasuryWithdrawalDatum) txOutRef' txInfo' -> P.do
|
\_cs (datum' :: Term _ PTreasuryWithdrawalDatum) txOutRef' txInfo' -> P.do
|
||||||
|
|
@ -93,21 +77,20 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
||||||
)
|
)
|
||||||
#$ txInfo.outputs
|
#$ txInfo.outputs
|
||||||
outputContentMatchesRecivers =
|
outputContentMatchesRecivers =
|
||||||
pall # plam id #$ pmap
|
pall # plam (\out -> pelem # out # outputValues)
|
||||||
# plam (\out -> pelem # out # outputValues)
|
|
||||||
#$ receivers
|
#$ receivers
|
||||||
outputNumberMatchesReceivers = plength # receivers #== plength # (pfromData txInfo.outputs)
|
outputNumberMatchesReceivers = plength # receivers #== plength # (pfromData txInfo.outputs)
|
||||||
outputIsNotPayingToEffect = P.do
|
outputIsNotPayingToEffect = P.do
|
||||||
input <- pletFields @'["address", "value"] $ findOwnAddress # pfromData txInfo' # txOutRef'
|
PJust txOut <- pmatch $ findTxOutByTxOutRef # txOutRef' # pfromData txInfo'
|
||||||
let correctMinimum = passetClassValueOf' (AssetClass ("", "")) # input.value #== 2000000
|
input <- pletFields @'["address", "value"] $ txOut
|
||||||
notPayingToEffect =
|
let notPayingToEffect =
|
||||||
pnot #$ pany
|
pnot #$ pany
|
||||||
# plam
|
# plam
|
||||||
( \x ->
|
( \x ->
|
||||||
input.address #== pfield @"address" # pfromData x
|
input.address #== pfield @"address" # pfromData x
|
||||||
)
|
)
|
||||||
# pfromData txInfo.outputs
|
# pfromData txInfo.outputs
|
||||||
correctMinimum #&& notPayingToEffect
|
notPayingToEffect
|
||||||
|
|
||||||
passert "Transaction output does not match receivers" outputContentMatchesRecivers
|
passert "Transaction output does not match receivers" outputContentMatchesRecivers
|
||||||
passert "" outputNumberMatchesReceivers
|
passert "" outputNumberMatchesReceivers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue