add withBuiltinPairAsData
This commit is contained in:
parent
51c4955a37
commit
f6cf4f01db
3 changed files with 52 additions and 22 deletions
|
|
@ -41,7 +41,7 @@ module Agora.Proposal (
|
|||
|
||||
import Agora.Proposal.Time (PProposalStartingTime, PProposalTimingConfig, ProposalStartingTime, ProposalTimingConfig)
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.Utils (mustBePJust)
|
||||
import Agora.Utils (withBuiltinPairAsData)
|
||||
import Data.Tagged (Tagged)
|
||||
import GHC.Generics qualified as GHC
|
||||
import Generics.SOP (Generic, I (I))
|
||||
|
|
@ -62,8 +62,10 @@ import Plutarch.Extra.IsData (
|
|||
EnumIsData (..),
|
||||
ProductIsData (ProductIsData),
|
||||
)
|
||||
import Plutarch.Extra.List (pfirstJust)
|
||||
import Plutarch.Extra.Map qualified as PM
|
||||
import Plutarch.Extra.Map.Unsorted qualified as PUM
|
||||
import Plutarch.Extra.Maybe (pfromJust)
|
||||
import Plutarch.Extra.Other (DerivePNewtype' (..))
|
||||
import Plutarch.Extra.TermCont (pguardC, pletC, pmatchC)
|
||||
import Plutarch.Lift (
|
||||
|
|
@ -810,13 +812,6 @@ phighestVotes = phoistAcyclic $
|
|||
let l :: Term _ (PBuiltinList _)
|
||||
l = pto $ pto votes
|
||||
|
||||
f ::
|
||||
Term
|
||||
_
|
||||
( PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
|
||||
:--> PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
|
||||
:--> PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
|
||||
)
|
||||
f = phoistAcyclic $
|
||||
plam $ \this last ->
|
||||
let lastVotes = pfromData $ psndBuiltin # last
|
||||
|
|
@ -839,13 +834,14 @@ pneutralOption = phoistAcyclic $
|
|||
let l :: Term _ (PBuiltinList (PBuiltinPair (PAsData PResultTag) _))
|
||||
l = pto effects
|
||||
|
||||
f :: Term _ (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted _ _)) :--> PBool)
|
||||
f = phoistAcyclic $
|
||||
plam $ \((pfromData . (psndBuiltin #) -> el)) ->
|
||||
let el' :: Term _ (PBuiltinList _)
|
||||
el' = pto el
|
||||
in pnull # el'
|
||||
in pfromData $ pfstBuiltin #$ mustBePJust # "No neutral option" #$ pfind # f # l
|
||||
plam $
|
||||
withBuiltinPairAsData $ \rt el ->
|
||||
pif
|
||||
(PAssocMap.pnull # el)
|
||||
(pcon $ PJust rt)
|
||||
(pcon PNothing)
|
||||
in pfromJust #$ pfirstJust # f # l
|
||||
|
||||
{- | Return true if the thresholds are valid.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
{-# LANGUAGE QuantifiedConstraints #-}
|
||||
|
||||
{- |
|
||||
Module : Agora.Utils
|
||||
Maintainer : emi@haskell.fyi
|
||||
|
|
@ -20,6 +22,8 @@ module Agora.Utils (
|
|||
isScriptAddress,
|
||||
isPubKey,
|
||||
pltAsData,
|
||||
pon,
|
||||
withBuiltinPairAsData,
|
||||
) where
|
||||
|
||||
import Plutarch.Api.V1 (
|
||||
|
|
@ -206,3 +210,33 @@ pltAsData ::
|
|||
pltAsData = phoistAcyclic $
|
||||
plam $
|
||||
\(pfromData -> l) (pfromData -> r) -> l #< r
|
||||
|
||||
{- | Plutarch level 'Data.Function.on'.
|
||||
|
||||
@since 0.2.0
|
||||
-}
|
||||
pon ::
|
||||
forall (a :: PType) (b :: PType) (c :: PType) (s :: S).
|
||||
Term s ((b :--> b :--> c) :--> (a :--> b) :--> a :--> a :--> c)
|
||||
pon = phoistAcyclic $
|
||||
plam $ \f g x y ->
|
||||
let a = g # x
|
||||
b = g # y
|
||||
in f # a # b
|
||||
|
||||
{- | Extract data stored in a 'PBuiltinPair' and call a function to process it.
|
||||
|
||||
@since 0.2.0
|
||||
-}
|
||||
withBuiltinPairAsData ::
|
||||
forall (a :: PType) (b :: PType) (c :: PType) (s :: S).
|
||||
(PIsData a, PIsData b) =>
|
||||
(Term s a -> Term s b -> Term s c) ->
|
||||
Term
|
||||
s
|
||||
(PBuiltinPair (PAsData a) (PAsData b)) ->
|
||||
Term s c
|
||||
withBuiltinPairAsData f p =
|
||||
let a = pfromData $ pfstBuiltin # p
|
||||
b = pfromData $ psndBuiltin # p
|
||||
in f a b
|
||||
|
|
|
|||
16
bench.csv
16
bench.csv
|
|
@ -2,18 +2,18 @@ name,cpu,mem,size
|
|||
Agora/Effects/Treasury Withdrawal Effect/effect/Simple,333137234,829671,3674
|
||||
Agora/Effects/Treasury Withdrawal Effect/effect/Simple with multiple treasuries ,492197164,1196783,3986
|
||||
Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets,455817227,1103968,3859
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,92825132,256078,8201
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,92825132,256078,8229
|
||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,112671240,312571,3747
|
||||
Agora/Stake/policy/stakeCreation,51008580,149029,2522
|
||||
Agora/Stake/validator/stakeDepositWithdraw deposit,183506412,498838,4745
|
||||
Agora/Stake/validator/stakeDepositWithdraw withdraw,183506412,498838,4733
|
||||
Agora/Proposal/policy (proposal creation)/legal/proposal,33689644,100286,2002
|
||||
Agora/Proposal/policy (proposal creation)/legal/governor,324511293,861435,8681
|
||||
Agora/Proposal/policy (proposal creation)/legal/governor,324511293,861435,8709
|
||||
Agora/Proposal/policy (proposal creation)/legal/stake,153960499,403133,5404
|
||||
Agora/Proposal/policy (proposal creation)/illegal/invalid next proposal id/proposal,33689644,100286,2002
|
||||
Agora/Proposal/policy (proposal creation)/illegal/invalid next proposal id/stake,153960499,403133,5404
|
||||
Agora/Proposal/policy (proposal creation)/illegal/use other's stake/proposal,33689644,100286,1971
|
||||
Agora/Proposal/policy (proposal creation)/illegal/use other's stake/governor,324511293,861435,8650
|
||||
Agora/Proposal/policy (proposal creation)/illegal/use other's stake/governor,324511293,861435,8678
|
||||
Agora/Proposal/policy (proposal creation)/illegal/altered stake/proposal,33689644,100286,2002
|
||||
Agora/Proposal/policy (proposal creation)/illegal/invalid stake locks/proposal,33689644,100286,2010
|
||||
Agora/Proposal/policy (proposal creation)/illegal/invalid stake locks/stake,159394159,417783,5412
|
||||
|
|
@ -66,15 +66,15 @@ Agora/Proposal/validator/advancing/legal/advance to next state/from: VotingReady
|
|||
Agora/Proposal/validator/advancing/legal/advance to next state/from: VotingReady/stake,118915099,307672,5229
|
||||
Agora/Proposal/validator/advancing/legal/advance to next state/from: Locked/propsoal,295366820,822071,8771
|
||||
Agora/Proposal/validator/advancing/legal/advance to next state/from: Locked/stake,156324691,401372,5668
|
||||
Agora/Proposal/validator/advancing/legal/advance to next state/from: Locked/governor,258411069,667386,8946
|
||||
Agora/Proposal/validator/advancing/legal/advance to next state/from: Locked/governor,258666820,668654,8974
|
||||
Agora/Proposal/validator/advancing/legal/advance to failed state/from: VotingReady/propsoal,258602387,722952,8326
|
||||
Agora/Proposal/validator/advancing/legal/advance to failed state/from: VotingReady/stake,118915099,307672,5225
|
||||
Agora/Proposal/validator/advancing/legal/advance to failed state/from: Locked/propsoal,259733365,725356,8326
|
||||
Agora/Proposal/validator/advancing/legal/advance to failed state/from: Locked/stake,118915099,307672,5225
|
||||
Agora/Proposal/validator/advancing/illegal/insufficient votes/stake,118915099,307672,5225
|
||||
Agora/Proposal/validator/advancing/illegal/initial state is Finished/stake,118915099,307672,5217
|
||||
Agora/Proposal/validator/advancing/illegal/invalid stake output/from Lockedwith 1 stakes/governor,258411069,667386,8946
|
||||
Agora/Proposal/validator/advancing/illegal/invalid stake output/from Lockedwith 5 stakes/governor,265599017,688074,9187
|
||||
Agora/Proposal/validator/advancing/illegal/invalid stake output/from Lockedwith 1 stakes/governor,258666820,668654,8974
|
||||
Agora/Proposal/validator/advancing/illegal/invalid stake output/from Lockedwith 5 stakes/governor,265854768,689342,9215
|
||||
Agora/Proposal/validator/unlocking/legal/with 1 proposals/voter: retract votes while voting/stake,125083340,324576,5219
|
||||
Agora/Proposal/validator/unlocking/legal/with 1 proposals/voter: retract votes while voting/propsoal,236574652,665124,8323
|
||||
Agora/Proposal/validator/unlocking/legal/with 1 proposals/voter/creator: retract votes while voting/stake,128314586,333630,5235
|
||||
|
|
@ -233,5 +233,5 @@ Agora/Treasury/Validator/Positive/Allows for effect changes,31277082,80782,1450
|
|||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct simple,20570665,54655,725
|
||||
Agora/AuthorityToken/singleAuthorityTokenBurned/Correct many inputs,32757063,87013,825
|
||||
Agora/Governor/policy/totally legal,60002734,167736,2267
|
||||
Agora/Governor/validator/GATs minting,255328308,682125,8827
|
||||
Agora/Governor/validator/mutate governor state,93971983,261537,8301
|
||||
Agora/Governor/validator/GATs minting,255584059,683393,8855
|
||||
Agora/Governor/validator/mutate governor state,93971983,261537,8329
|
||||
|
|
|
|||
|
Loading…
Add table
Add a link
Reference in a new issue