filter SST by assetclass in governor
This commit is contained in:
parent
9fe8448711
commit
007a116d15
3 changed files with 18 additions and 52 deletions
|
|
@ -37,8 +37,8 @@ import Agora.Proposal (
|
||||||
)
|
)
|
||||||
import Agora.Proposal.Time (validateProposalStartingTime)
|
import Agora.Proposal.Time (validateProposalStartingTime)
|
||||||
import Agora.Stake (
|
import Agora.Stake (
|
||||||
PStakeDatum (..),
|
|
||||||
pnumCreatedProposals,
|
pnumCreatedProposals,
|
||||||
|
presolveStakeInputDatum,
|
||||||
)
|
)
|
||||||
import Agora.Utils (
|
import Agora.Utils (
|
||||||
plistEqualsBy,
|
plistEqualsBy,
|
||||||
|
|
@ -55,7 +55,7 @@ import Plutarch.Api.V2 (
|
||||||
PTxOutRef,
|
PTxOutRef,
|
||||||
PValidator,
|
PValidator,
|
||||||
)
|
)
|
||||||
import Plutarch.Extra.AssetClass (passetClass)
|
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass, ptoScottEncoding)
|
||||||
import Plutarch.Extra.Field (pletAll, pletAllC)
|
import Plutarch.Extra.Field (pletAll, pletAllC)
|
||||||
import "liqwid-plutarch-extra" Plutarch.Extra.List (pfindJust, pmapMaybe)
|
import "liqwid-plutarch-extra" Plutarch.Extra.List (pfindJust, pmapMaybe)
|
||||||
import "liqwid-plutarch-extra" Plutarch.Extra.Map (pkeys, ptryLookup)
|
import "liqwid-plutarch-extra" Plutarch.Extra.Map (pkeys, ptryLookup)
|
||||||
|
|
@ -264,14 +264,14 @@ governorValidator ::
|
||||||
-- | Lazy precompiled scripts.
|
-- | Lazy precompiled scripts.
|
||||||
ClosedTerm
|
ClosedTerm
|
||||||
( PAddress
|
( PAddress
|
||||||
:--> PCurrencySymbol
|
:--> PAssetClassData
|
||||||
:--> PCurrencySymbol
|
:--> PCurrencySymbol
|
||||||
:--> PCurrencySymbol
|
:--> PCurrencySymbol
|
||||||
:--> PCurrencySymbol
|
:--> PCurrencySymbol
|
||||||
:--> PValidator
|
:--> PValidator
|
||||||
)
|
)
|
||||||
governorValidator =
|
governorValidator =
|
||||||
plam $ \proposalValidatorAddress sstSymbol gstSymbol pstSymbol atSymbol datum redeemer ctx -> unTermCont $ do
|
plam $ \proposalValidatorAddress sstClass gstSymbol pstSymbol atSymbol datum redeemer ctx -> unTermCont $ do
|
||||||
ctxF <- pletAllC ctx
|
ctxF <- pletAllC ctx
|
||||||
txInfo <- pletC $ pfromData ctxF.txInfo
|
txInfo <- pletC $ pfromData ctxF.txInfo
|
||||||
txInfoF <-
|
txInfoF <-
|
||||||
|
|
@ -335,24 +335,6 @@ governorValidator =
|
||||||
|
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
getStakeDatum :: Term _ (PTxOut :--> PMaybe PStakeDatum) <-
|
|
||||||
pletC $
|
|
||||||
plam $
|
|
||||||
flip (pletFields @'["value", "datum"]) $ \txOutF ->
|
|
||||||
let isStakeUTxO =
|
|
||||||
psymbolValueOf
|
|
||||||
# sstSymbol
|
|
||||||
# txOutF.value
|
|
||||||
#== 1
|
|
||||||
|
|
||||||
datum =
|
|
||||||
ptrace "Resolve stake input datum" $
|
|
||||||
pfromData $
|
|
||||||
pfromOutputDatum
|
|
||||||
# txOutF.datum
|
|
||||||
# txInfoF.datums
|
|
||||||
in pif isStakeUTxO (pjust # datum) pnothing
|
|
||||||
|
|
||||||
getProposalDatum :: Term _ (PTxOut :--> PMaybe PProposalDatum) <-
|
getProposalDatum :: Term _ (PTxOut :--> PMaybe PProposalDatum) <-
|
||||||
pletC $
|
pletC $
|
||||||
plam $
|
plam $
|
||||||
|
|
@ -424,7 +406,10 @@ governorValidator =
|
||||||
passertPJust
|
passertPJust
|
||||||
# "Stake input should present"
|
# "Stake input should present"
|
||||||
#$ pfindJust
|
#$ pfindJust
|
||||||
# plam ((getStakeDatum #) . (pfield @"resolved" #))
|
# ( presolveStakeInputDatum
|
||||||
|
# (ptoScottEncoding # sstClass)
|
||||||
|
# txInfoF.datums
|
||||||
|
)
|
||||||
# pfromData txInfoF.inputs
|
# pfromData txInfoF.inputs
|
||||||
|
|
||||||
stakeInputDatumF <- pletAllC stakeInputDatum
|
stakeInputDatumF <- pletAllC stakeInputDatum
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ data AgoraScriptInfo = AgoraScriptInfo
|
||||||
linker :: Linker Governor (ScriptExport AgoraScriptInfo)
|
linker :: Linker Governor (ScriptExport AgoraScriptInfo)
|
||||||
linker = do
|
linker = do
|
||||||
govPol <- fetchTS @MintingPolicyRole @'[TxOutRef] "agora:governorPolicy"
|
govPol <- fetchTS @MintingPolicyRole @'[TxOutRef] "agora:governorPolicy"
|
||||||
govVal <- fetchTS @ValidatorRole @'[Address, CurrencySymbol, CurrencySymbol, CurrencySymbol, CurrencySymbol] "agora:governorValidator"
|
govVal <- fetchTS @ValidatorRole @'[Address, AssetClass, CurrencySymbol, CurrencySymbol, CurrencySymbol] "agora:governorValidator"
|
||||||
stkPol <- fetchTS @MintingPolicyRole @'[AssetClass] "agora:stakePolicy"
|
stkPol <- fetchTS @MintingPolicyRole @'[AssetClass] "agora:stakePolicy"
|
||||||
stkVal <- fetchTS @ValidatorRole @'[CurrencySymbol, AssetClass, AssetClass] "agora:stakeValidator"
|
stkVal <- fetchTS @ValidatorRole @'[CurrencySymbol, AssetClass, AssetClass] "agora:stakeValidator"
|
||||||
prpPol <- fetchTS @MintingPolicyRole @'[AssetClass] "agora:proposalPolicy"
|
prpPol <- fetchTS @MintingPolicyRole @'[AssetClass] "agora:proposalPolicy"
|
||||||
|
|
@ -63,7 +63,7 @@ linker = do
|
||||||
govVal' =
|
govVal' =
|
||||||
govVal
|
govVal
|
||||||
# propValAddress
|
# propValAddress
|
||||||
# sstSymbol
|
# sstAssetClass
|
||||||
# gstSymbol
|
# gstSymbol
|
||||||
# pstSymbol
|
# pstSymbol
|
||||||
# atSymbol
|
# atSymbol
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import Agora.Stake (
|
||||||
pgetStakeRoles,
|
pgetStakeRoles,
|
||||||
pisIrrelevant,
|
pisIrrelevant,
|
||||||
pisVoter,
|
pisVoter,
|
||||||
|
presolveStakeInputDatum,
|
||||||
)
|
)
|
||||||
import Agora.Utils (
|
import Agora.Utils (
|
||||||
pfromSingleton,
|
pfromSingleton,
|
||||||
|
|
@ -47,7 +48,6 @@ import Plutarch.Api.V2 (
|
||||||
PScriptPurpose (PMinting, PSpending),
|
PScriptPurpose (PMinting, PSpending),
|
||||||
PTxInInfo,
|
PTxInInfo,
|
||||||
PTxInfo (PTxInfo),
|
PTxInfo (PTxInfo),
|
||||||
PTxOut,
|
|
||||||
PValidator,
|
PValidator,
|
||||||
)
|
)
|
||||||
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass, ptoScottEncoding)
|
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass, ptoScottEncoding)
|
||||||
|
|
@ -68,7 +68,6 @@ import Plutarch.Extra.ScriptContext (
|
||||||
pfindTxInByTxOutRef,
|
pfindTxInByTxOutRef,
|
||||||
pfromOutputDatum,
|
pfromOutputDatum,
|
||||||
pisTokenSpent,
|
pisTokenSpent,
|
||||||
ptryFromOutputDatum,
|
|
||||||
)
|
)
|
||||||
import Plutarch.Extra.Sum (PSum (PSum))
|
import Plutarch.Extra.Sum (PSum (PSum))
|
||||||
import "liqwid-plutarch-extra" Plutarch.Extra.TermCont (
|
import "liqwid-plutarch-extra" Plutarch.Extra.TermCont (
|
||||||
|
|
@ -309,35 +308,17 @@ proposalValidator =
|
||||||
|
|
||||||
-- Handle stake inputs/outputs.
|
-- Handle stake inputs/outputs.
|
||||||
|
|
||||||
-- Reslove stake datum if the given UTxO is a stake UTxO.
|
resolveStakeInputDatum <-
|
||||||
getStakeDatum :: Term _ (PTxOut :--> PMaybe PStakeDatum) <-
|
|
||||||
pletC $
|
pletC $
|
||||||
plam $
|
presolveStakeInputDatum
|
||||||
flip (pletFields @'["value", "datum"]) $ \txOutF ->
|
# (ptoScottEncoding # sstClass)
|
||||||
let isStakeUTxO =
|
# txInfoF.datums
|
||||||
-- A stake UTxO is a UTxO that carries SST.
|
|
||||||
passetClassValueOf
|
|
||||||
# (ptoScottEncoding # sstClass)
|
|
||||||
# txOutF.value
|
|
||||||
#== 1
|
|
||||||
|
|
||||||
stake =
|
|
||||||
pfromData $
|
|
||||||
-- If we can't resolve the stake datum, error out.
|
|
||||||
passertPJust
|
|
||||||
# "Stake datum should present"
|
|
||||||
-- Use inline datum to avoid extra map lookup.
|
|
||||||
#$ ptryFromOutputDatum @(PAsData PStakeDatum)
|
|
||||||
# txOutF.datum
|
|
||||||
# txInfoF.datums
|
|
||||||
in pif isStakeUTxO (pjust # stake) pnothing
|
|
||||||
|
|
||||||
spendStakes' :: Term _ ((PStakeInputsContext :--> PUnit) :--> PUnit) <-
|
spendStakes' :: Term _ ((PStakeInputsContext :--> PUnit) :--> PUnit) <-
|
||||||
pletC $
|
pletC $
|
||||||
plam $
|
plam $
|
||||||
let stakeInputs =
|
let stakeInputs =
|
||||||
pmapMaybe
|
pmapMaybe
|
||||||
# plam ((getStakeDatum #) . (pfield @"resolved" #))
|
# resolveStakeInputDatum
|
||||||
# pfromData txInfoF.inputs
|
# pfromData txInfoF.inputs
|
||||||
|
|
||||||
ctx = pcon $ PStakeInputsContext stakeInputs
|
ctx = pcon $ PStakeInputsContext stakeInputs
|
||||||
|
|
@ -380,8 +361,8 @@ proposalValidator =
|
||||||
}
|
}
|
||||||
|
|
||||||
f :: Term _ (_ :--> PTxInInfo :--> _)
|
f :: Term _ (_ :--> PTxInInfo :--> _)
|
||||||
f = plam $ \ctx' ((pfield @"resolved" #) -> txOut) ->
|
f = plam $ \ctx' input ->
|
||||||
let stakeDatum = getStakeDatum # txOut
|
let stakeDatum = resolveStakeInputDatum # input
|
||||||
updateCtx' = updateCtx # ctx'
|
updateCtx' = updateCtx # ctx'
|
||||||
in pmaybe # ctx' # updateCtx' # stakeDatum
|
in pmaybe # ctx' # updateCtx' # stakeDatum
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue