Merge branch 'staging' into nini-faroux/comment-fix
This commit is contained in:
commit
b607aea5f4
15 changed files with 2031 additions and 1127 deletions
|
|
@ -30,11 +30,6 @@ import Agora.Governor.Scripts (
|
|||
governorSTAssetClassFromGovernor,
|
||||
)
|
||||
import Agora.Plutarch.Orphans ()
|
||||
import Agora.Utils (
|
||||
isScriptAddress,
|
||||
mustBePDJust,
|
||||
mustBePJust,
|
||||
)
|
||||
import GHC.Generics qualified as GHC
|
||||
import Generics.SOP (Generic, I (I))
|
||||
import Plutarch.Api.V1 (
|
||||
|
|
@ -42,13 +37,17 @@ import Plutarch.Api.V1 (
|
|||
PValidator,
|
||||
PValue,
|
||||
)
|
||||
import Plutarch.Api.V1.ScriptContext (ptryFindDatum)
|
||||
import Plutarch.Api.V1.ScriptContext (pisScriptAddress, ptryFindDatum)
|
||||
import "liqwid-plutarch-extra" Plutarch.Api.V1.Value (pvalueOf)
|
||||
import Plutarch.DataRepr (
|
||||
DerivePConstantViaData (..),
|
||||
PDataFields,
|
||||
PIsDataReprInstances (PIsDataReprInstances),
|
||||
)
|
||||
import Plutarch.Extra.Maybe (
|
||||
passertPDJust,
|
||||
passertPJust,
|
||||
)
|
||||
import Plutarch.Extra.TermCont (pguardC, pletFieldsC)
|
||||
import Plutarch.Lift (PConstantDecl, PLifted, PUnsafeLiftDecl)
|
||||
import PlutusLedgerApi.V1 (TxOutRef)
|
||||
|
|
@ -167,7 +166,7 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
|||
( plam $ \inInfo count ->
|
||||
let address = pfield @"address" #$ pfield @"resolved" # inInfo
|
||||
in pif
|
||||
(isScriptAddress # address)
|
||||
(pisScriptAddress # address)
|
||||
(count + 1)
|
||||
count
|
||||
)
|
||||
|
|
@ -177,7 +176,7 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
|||
|
||||
-- Find the governor input by looking for GST.
|
||||
let inputWithGST =
|
||||
mustBePJust # "Governor input not found" #$ pfind
|
||||
passertPJust # "Governor input not found" #$ pfind
|
||||
# phoistAcyclic
|
||||
( plam $ \inInfo ->
|
||||
let value = pfield @"value" #$ pfield @"resolved" # inInfo
|
||||
|
|
@ -207,10 +206,10 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
|||
gstValueOf # govOutput.value #== 1
|
||||
|
||||
let governorOutputDatumHash =
|
||||
mustBePDJust # "Governor output doesn't have datum" # govOutput.datumHash
|
||||
passertPDJust # "Governor output doesn't have datum" # govOutput.datumHash
|
||||
governorOutputDatum =
|
||||
pfromData @PGovernorDatum $
|
||||
mustBePJust # "Governor output datum not found"
|
||||
passertPJust # "Governor output datum not found"
|
||||
#$ ptryFindDatum # governorOutputDatumHash # txInfoF.datums
|
||||
|
||||
-- Ensure the output governor datum is what we want.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ module Agora.Effect.TreasuryWithdrawal (
|
|||
|
||||
import Agora.Effect (makeEffect)
|
||||
import Agora.Plutarch.Orphans ()
|
||||
import Agora.Utils (isPubKey)
|
||||
import GHC.Generics qualified as GHC
|
||||
import Generics.SOP (Generic, I (I))
|
||||
import Plutarch.Api.V1 (
|
||||
|
|
@ -27,7 +26,7 @@ import Plutarch.Api.V1 (
|
|||
PValue,
|
||||
ptuple,
|
||||
)
|
||||
import Plutarch.Api.V1.ScriptContext (pfindTxInByTxOutRef)
|
||||
import Plutarch.Api.V1.ScriptContext (pfindTxInByTxOutRef, pisPubKey)
|
||||
import "plutarch" Plutarch.Api.V1.Value (pnormalize)
|
||||
import Plutarch.DataRepr (
|
||||
DerivePConstantViaData (..),
|
||||
|
|
@ -199,7 +198,7 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
|||
( \((pfield @"_0" #) . pfromData -> cred) ->
|
||||
cred #== pfield @"credential" # effInput.address
|
||||
#|| pelem # cred # datum.treasuries
|
||||
#|| isPubKey # pfromData cred
|
||||
#|| pisPubKey # pfromData cred
|
||||
)
|
||||
# inputValues
|
||||
|
||||
|
|
|
|||
|
|
@ -70,12 +70,7 @@ import Agora.Stake.Scripts (
|
|||
stakeValidator,
|
||||
)
|
||||
import Agora.Utils (
|
||||
findOutputsToAddress,
|
||||
hasOnlyOneTokenOfCurrencySymbol,
|
||||
mustBePDJust,
|
||||
mustBePJust,
|
||||
mustFindDatum',
|
||||
scriptHashFromAddress,
|
||||
validatorHashToAddress,
|
||||
validatorHashToTokenName,
|
||||
)
|
||||
|
|
@ -98,16 +93,26 @@ import Plutarch.Api.V1.AssetClass (
|
|||
passetClass,
|
||||
passetClassValueOf,
|
||||
)
|
||||
import Plutarch.Api.V1.ScriptContext (pfindTxInByTxOutRef, pisUTXOSpent, ptryFindDatum, pvalueSpent)
|
||||
import "liqwid-plutarch-extra" Plutarch.Api.V1.Value (psymbolValueOf)
|
||||
import Plutarch.Extra.Field (pletAllC)
|
||||
import Plutarch.Extra.IsData (pmatchEnumFromData)
|
||||
import Plutarch.Extra.List (pfirstJust)
|
||||
import Plutarch.Extra.Map (
|
||||
plookup,
|
||||
plookup',
|
||||
)
|
||||
import Plutarch.Extra.Maybe (pisDJust)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
import Plutarch.Api.V1.ScriptContext (
|
||||
pfindOutputsToAddress,
|
||||
pfindTxInByTxOutRef,
|
||||
pisUTXOSpent,
|
||||
pscriptHashFromAddress,
|
||||
ptryFindDatum,
|
||||
pvalueSpent,
|
||||
)
|
||||
import "liqwid-plutarch-extra" Plutarch.Api.V1.Value (phasOnlyOneTokenOfCurrencySymbol, psymbolValueOf)
|
||||
import Plutarch.Extra.Field (pletAllC)
|
||||
import Plutarch.Extra.Maybe (passertPDJust, passertPJust, pisDJust)
|
||||
import Plutarch.Extra.Record (mkRecordConstr, (.&), (.=))
|
||||
import Plutarch.Extra.TermCont (pguardC, pletC, pletFieldsC, pmatchC, ptryFromC)
|
||||
import PlutusLedgerApi.V1 (
|
||||
|
|
@ -168,7 +173,7 @@ governorPolicy gov =
|
|||
|
||||
govOutput <-
|
||||
pletC $
|
||||
mustBePJust
|
||||
passertPJust
|
||||
# "Governor output not found"
|
||||
#$ pfind
|
||||
# plam
|
||||
|
|
@ -282,7 +287,7 @@ governorValidator gov =
|
|||
|
||||
((pfield @"resolved" #) -> ownInput) <-
|
||||
pletC $
|
||||
mustBePJust # "Own input not found"
|
||||
passertPJust # "Own input not found"
|
||||
#$ pfindTxInByTxOutRef # ownInputRef # txInfoF.inputs
|
||||
ownInputF <- pletFieldsC @'["address", "value"] ownInput
|
||||
let ownAddress = pfromData $ ownInputF.address
|
||||
|
|
@ -295,7 +300,7 @@ governorValidator gov =
|
|||
pguardC "Own input should have exactly one state token" $
|
||||
ownInputGSTAmount #== 1
|
||||
|
||||
ownOutputs <- pletC $ findOutputsToAddress # txInfoF.outputs # ownAddress
|
||||
ownOutputs <- pletC $ pfindOutputsToAddress # txInfoF.outputs # ownAddress
|
||||
pguardC "Exactly one utxo should be sent to the governor" $
|
||||
plength # ownOutputs #== 1
|
||||
|
||||
|
|
@ -306,11 +311,11 @@ governorValidator gov =
|
|||
|
||||
-- Check that own output have datum of type 'GovernorDatum'.
|
||||
let outputGovernorStateDatumHash =
|
||||
mustBePDJust # "Governor output doesn't have datum" # ownOutput.datumHash
|
||||
passertPDJust # "Governor output doesn't have datum" # ownOutput.datumHash
|
||||
newGovernorDatum <-
|
||||
pletC $
|
||||
pfromData $
|
||||
mustBePJust # "Ouput governor state datum not found"
|
||||
passertPJust # "Ouput governor state datum not found"
|
||||
#$ ptryFindDatum # outputGovernorStateDatumHash # txInfoF.datums
|
||||
|
||||
pguardC "New datum is valid" $ pisGovernorDatumValid # newGovernorDatum
|
||||
|
|
@ -338,7 +343,7 @@ governorValidator gov =
|
|||
-- Check that exactly one proposal token is being minted.
|
||||
|
||||
pguardC "Exactly one proposal token must be minted" $
|
||||
hasOnlyOneTokenOfCurrencySymbol # ppstSymbol # txInfoF.mint
|
||||
phasOnlyOneTokenOfCurrencySymbol # ppstSymbol # txInfoF.mint
|
||||
|
||||
-- Check that a stake is spent to create the propsal,
|
||||
-- and the value it contains meets the requirement.
|
||||
|
|
@ -432,7 +437,7 @@ governorValidator gov =
|
|||
|
||||
-- Check the output stake has been proposly updated.
|
||||
let stakeOutputDatumHash =
|
||||
mustBePJust # "Output stake should be presented"
|
||||
passertPJust # "Output stake should be presented"
|
||||
#$ pfirstJust
|
||||
# phoistAcyclic
|
||||
( plam
|
||||
|
|
@ -444,7 +449,7 @@ governorValidator gov =
|
|||
(psymbolValueOf # psstSymbol # txOutF.value #== 1)
|
||||
( pcon $
|
||||
PJust $
|
||||
mustBePDJust # "Output stake datum should be presented"
|
||||
passertPDJust # "Output stake datum should be presented"
|
||||
# txOutF.datumHash
|
||||
)
|
||||
(pcon PNothing)
|
||||
|
|
@ -453,7 +458,7 @@ governorValidator gov =
|
|||
# pfromData txInfoF.outputs
|
||||
|
||||
stakeOutputDatum =
|
||||
mustBePJust @(PAsData PStakeDatum) # "Stake output datum presented"
|
||||
passertPJust @(PAsData PStakeDatum) # "Stake output datum presented"
|
||||
#$ ptryFindDatum # stakeOutputDatumHash # txInfoF.datums
|
||||
|
||||
stakeOutputLocks =
|
||||
|
|
@ -489,7 +494,7 @@ governorValidator gov =
|
|||
pletFieldsC @'["datumHash"] $
|
||||
pfield @"resolved"
|
||||
#$ pfromData
|
||||
$ mustBePJust
|
||||
$ passertPJust
|
||||
# "Proposal input not found"
|
||||
#$ pfind
|
||||
# plam
|
||||
|
|
@ -555,14 +560,14 @@ governorValidator gov =
|
|||
output <- pletFieldsC @'["address", "datumHash"] $ output'
|
||||
|
||||
let scriptHash =
|
||||
mustBePJust # "GAT receiver is not a script"
|
||||
#$ scriptHashFromAddress # output.address
|
||||
passertPJust # "GAT receiver is not a script"
|
||||
#$ pscriptHashFromAddress # output.address
|
||||
datumHash =
|
||||
mustBePDJust # "Output to effect should have datum"
|
||||
passertPDJust # "Output to effect should have datum"
|
||||
#$ output.datumHash
|
||||
|
||||
expectedDatumHash =
|
||||
mustBePJust # "Receiver is not in the effect list"
|
||||
passertPJust # "Receiver is not in the effect list"
|
||||
#$ plookup # scriptHash # effects
|
||||
|
||||
pure $
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
{- |
|
||||
Module : Agora.MultiSig
|
||||
Maintainer : riley_kilgore@outlook.com
|
||||
Description: A basic N of M multisignature validation function.
|
||||
|
||||
A basic N of M multisignature validation function.
|
||||
-}
|
||||
module Agora.MultiSig (
|
||||
validatedByMultisig,
|
||||
pvalidatedByMultisig,
|
||||
PMultiSig (..),
|
||||
MultiSig (..),
|
||||
) where
|
||||
|
||||
import GHC.Generics qualified as GHC
|
||||
import Generics.SOP (Generic, I (I))
|
||||
import Plutarch.Api.V1 (
|
||||
PPubKeyHash,
|
||||
PTxInfo (..),
|
||||
)
|
||||
import Plutarch.DataRepr (
|
||||
DerivePConstantViaData (DerivePConstantViaData),
|
||||
PDataFields,
|
||||
PIsDataReprInstances (PIsDataReprInstances),
|
||||
)
|
||||
import Plutarch.Extra.TermCont (pletFieldsC)
|
||||
import Plutarch.Lift (
|
||||
PConstantDecl,
|
||||
PLifted,
|
||||
PUnsafeLiftDecl,
|
||||
)
|
||||
import PlutusLedgerApi.V1.Crypto (PubKeyHash)
|
||||
import PlutusTx qualified
|
||||
import Prelude
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
{- | A MultiSig represents a proof that a particular set of signatures
|
||||
are present on a transaction.
|
||||
|
||||
@since 0.1.0
|
||||
-}
|
||||
data MultiSig = MultiSig
|
||||
{ keys :: [PubKeyHash]
|
||||
-- ^ List of PubKeyHashes that must be present in the list of signatories.
|
||||
, minSigs :: Integer
|
||||
}
|
||||
deriving stock
|
||||
( -- | @since 0.1.0
|
||||
GHC.Generic
|
||||
, -- | @since 0.1.0
|
||||
Eq
|
||||
, -- | @since 0.1.0
|
||||
Show
|
||||
)
|
||||
deriving anyclass
|
||||
( -- | @since 0.1.0
|
||||
Generic
|
||||
)
|
||||
|
||||
PlutusTx.makeLift ''MultiSig
|
||||
PlutusTx.unstableMakeIsData ''MultiSig
|
||||
|
||||
{- | Plutarch-level MultiSig
|
||||
|
||||
@since 0.1.0
|
||||
-}
|
||||
newtype PMultiSig (s :: S) = PMultiSig
|
||||
{ getMultiSig ::
|
||||
Term
|
||||
s
|
||||
( PDataRecord
|
||||
'[ "keys" ':= PBuiltinList (PAsData PPubKeyHash)
|
||||
, "minSigs" ':= PInteger
|
||||
]
|
||||
)
|
||||
}
|
||||
deriving stock
|
||||
( -- | @since 0.1.0
|
||||
GHC.Generic
|
||||
)
|
||||
deriving anyclass
|
||||
( -- | @since 0.1.0
|
||||
Generic
|
||||
)
|
||||
deriving anyclass
|
||||
( -- | @since 0.1.0
|
||||
PIsDataRepr
|
||||
)
|
||||
deriving
|
||||
( -- | @since 0.1.0
|
||||
PlutusType
|
||||
, -- | @since 0.1.0
|
||||
PIsData
|
||||
, -- | @since 0.1.0
|
||||
PDataFields
|
||||
)
|
||||
via (PIsDataReprInstances PMultiSig)
|
||||
|
||||
-- | @since 0.1.0
|
||||
instance PUnsafeLiftDecl PMultiSig where type PLifted PMultiSig = MultiSig
|
||||
|
||||
-- | @since 0.1.0
|
||||
deriving via (DerivePConstantViaData MultiSig PMultiSig) instance (PConstantDecl MultiSig)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
{- | Check if a Haskell-level MultiSig signs this transaction.
|
||||
|
||||
@since 0.1.0
|
||||
-}
|
||||
validatedByMultisig :: MultiSig -> Term s (PTxInfo :--> PBool)
|
||||
validatedByMultisig params =
|
||||
phoistAcyclic $
|
||||
pvalidatedByMultisig # pconstant params
|
||||
|
||||
{- | Check if a Plutarch-level MultiSig signs this transaction.
|
||||
|
||||
@since 0.1.0
|
||||
-}
|
||||
pvalidatedByMultisig :: Term s (PMultiSig :--> PTxInfo :--> PBool)
|
||||
pvalidatedByMultisig =
|
||||
phoistAcyclic $
|
||||
plam $ \multi' txInfo -> unTermCont $ do
|
||||
multi <- pletFieldsC @'["keys", "minSigs"] multi'
|
||||
let signatories = pfield @"signatories" # txInfo
|
||||
pure $
|
||||
pfromData multi.minSigs
|
||||
#<= ( plength #$ pfilter
|
||||
# plam
|
||||
( \a ->
|
||||
pelem # a # pfromData signatories
|
||||
)
|
||||
# multi.keys
|
||||
)
|
||||
|
|
@ -41,7 +41,6 @@ module Agora.Proposal (
|
|||
|
||||
import Agora.Proposal.Time (PProposalStartingTime, PProposalTimingConfig, ProposalStartingTime, ProposalTimingConfig)
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.Utils (withBuiltinPairAsData)
|
||||
import Data.Tagged (Tagged)
|
||||
import GHC.Generics qualified as GHC
|
||||
import Generics.SOP (Generic, I (I))
|
||||
|
|
@ -56,6 +55,7 @@ import Plutarch.Api.V1.AssocMap qualified as PAssocMap
|
|||
import Plutarch.DataRepr (DerivePConstantViaData (..), PDataFields, PIsDataReprInstances (..))
|
||||
import Plutarch.Extra.Comonad (pextract)
|
||||
import Plutarch.Extra.Field (pletAllC)
|
||||
import Plutarch.Extra.Function (pbuiltinUncurry)
|
||||
import Plutarch.Extra.IsData (
|
||||
DerivePConstantViaDataList (..),
|
||||
DerivePConstantViaEnum (..),
|
||||
|
|
@ -836,7 +836,7 @@ pneutralOption = phoistAcyclic $
|
|||
|
||||
f = phoistAcyclic $
|
||||
plam $
|
||||
withBuiltinPairAsData $ \rt el ->
|
||||
pbuiltinUncurry $ \rt el ->
|
||||
pif
|
||||
(PAssocMap.pnull # el)
|
||||
(pcon $ PJust rt)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import Agora.Stake (
|
|||
)
|
||||
import Agora.Utils (
|
||||
getMintingPolicySymbol,
|
||||
mustBePJust,
|
||||
mustFindDatum',
|
||||
pltAsData,
|
||||
)
|
||||
|
|
@ -65,7 +64,7 @@ import Plutarch.Extra.Field (pletAllC)
|
|||
import Plutarch.Extra.IsData (pmatchEnum)
|
||||
import Plutarch.Extra.List (pisUniq', pmapMaybe, pmergeBy, pmsortBy)
|
||||
import Plutarch.Extra.Map (plookup, pupdate)
|
||||
import Plutarch.Extra.Maybe (pfromDJust, pfromJust, pisJust)
|
||||
import Plutarch.Extra.Maybe (passertPJust, pfromDJust, pfromJust, pisJust)
|
||||
import Plutarch.Extra.Record (mkRecordConstr, (.&), (.=))
|
||||
import Plutarch.Extra.TermCont (
|
||||
pguardC,
|
||||
|
|
@ -204,7 +203,7 @@ proposalValidator proposal =
|
|||
-- proposal inputs in one thansaction.
|
||||
ownOutput <-
|
||||
pletC $
|
||||
mustBePJust # "Own output should be present" #$ pfind
|
||||
passertPJust # "Own output should be present" #$ pfind
|
||||
# plam
|
||||
( \input -> unTermCont $ do
|
||||
inputF <- pletAllC input
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import Agora.Stake (
|
|||
pstakeLocked,
|
||||
)
|
||||
import Agora.Utils (
|
||||
mustBePJust,
|
||||
mustFindDatum',
|
||||
pdjust,
|
||||
pdnothing,
|
||||
|
|
@ -44,7 +43,7 @@ import Plutarch.Api.V1.ScriptContext (pfindTxInByTxOutRef, ptxSignedBy, pvalueSp
|
|||
import "liqwid-plutarch-extra" Plutarch.Api.V1.Value (pgeqByClass', pgeqBySymbol, psymbolValueOf)
|
||||
import Plutarch.Extra.Field (pletAllC)
|
||||
import Plutarch.Extra.List (pmapMaybe, pmsortBy)
|
||||
import Plutarch.Extra.Maybe (pfromDJust)
|
||||
import Plutarch.Extra.Maybe (passertPJust, pfromDJust)
|
||||
import Plutarch.Extra.Record (mkRecordConstr, (.&), (.=))
|
||||
import Plutarch.Extra.TermCont (pguardC, pletC, pletFieldsC, pmatchC, ptryFromC)
|
||||
import Plutarch.Internal (punsafeCoerce)
|
||||
|
|
@ -126,7 +125,7 @@ stakePolicy gtClassRef =
|
|||
pguardC "A UTXO must exist with the correct output" $
|
||||
unTermCont $ do
|
||||
let scriptOutputWithStakeST =
|
||||
mustBePJust
|
||||
passertPJust
|
||||
# "Output to script not found"
|
||||
#$ pfind
|
||||
# plam
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue