{-# LANGUAGE TemplateHaskell #-}

{- |
Module     : Agora.Proposal
Maintainer : emi@haskell.fyi
Description: Proposal scripts encoding effects that operate on the system.

Proposal scripts encoding effects that operate on the system.
-}
module Agora.Proposal (
  -- * Haskell-land
  Proposal (..),
  ProposalDatum (..),
  ProposalRedeemer (..),
  ProposalStatus (..),
  ProposalThresholds (..),
  ProposalVotes (..),
  ProposalId (..),
  ResultTag (..),
  emptyVotesFor,

  -- * Plutarch-land
  PProposalDatum (..),
  PProposalRedeemer (..),
  PProposalStatus (..),
  PProposalThresholds (..),
  PProposalVotes (..),
  PProposalId (..),
  PResultTag (..),

  -- * Plutarch helpers
  proposalDatumValid,
  pemptyVotesFor,
  pwinner,
  pwinner',
  pneutralOption,
  pretractVotes,
) where

import Agora.Proposal.Time (PProposalStartingTime, PProposalTimingConfig, ProposalStartingTime, ProposalTimingConfig)
import Agora.SafeMoney (GTTag)
import Agora.Utils (mustBePJust)
import Data.Tagged (Tagged)
import GHC.Generics qualified as GHC
import Generics.SOP (Generic, I (I))
import Plutarch.Api.V1 (
  KeyGuarantees (Unsorted),
  PDatumHash,
  PMap,
  PPubKeyHash,
  PValidatorHash,
 )
import Plutarch.DataRepr (DerivePConstantViaData (..), PDataFields, PIsDataReprInstances (..))
import Plutarch.Extra.List (pnotNull)
import Plutarch.Extra.Map qualified as PM
import Plutarch.Extra.Map.Unsorted qualified as PUM
import Plutarch.Extra.TermCont (pguardC, pletC)
import Plutarch.Lift (
  DerivePConstantViaNewtype (..),
  PConstantDecl,
  PUnsafeLiftDecl (..),
 )
import Plutarch.SafeMoney (PDiscrete)
import PlutusLedgerApi.V1 (DatumHash, PubKeyHash, ValidatorHash)
import PlutusLedgerApi.V1.Value (AssetClass)
import PlutusTx qualified
import PlutusTx.AssocMap qualified as AssocMap

--------------------------------------------------------------------------------
-- Haskell-land

{- | Identifies a Proposal, issued upon creation of a proposal. In practice,
     this number starts at zero, and increments by one for each proposal.
     The 100th proposal will be @'ProposalId' 99@. This counter lives
     in the 'Agora.Governor.Governor'. See 'Agora.Governor.nextProposalId', and
     'Agora.Governor.pgetNextProposalId'.

     @since 0.1.0
-}
newtype ProposalId = ProposalId {ProposalId -> Integer
proposalTag :: Integer}
  deriving newtype
    ( -- | @since 0.1.0
      ProposalId -> BuiltinData
(ProposalId -> BuiltinData) -> ToData ProposalId
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: ProposalId -> BuiltinData
$ctoBuiltinData :: ProposalId -> BuiltinData
PlutusTx.ToData
    , -- | @since 0.1.0
      BuiltinData -> Maybe ProposalId
(BuiltinData -> Maybe ProposalId) -> FromData ProposalId
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe ProposalId
$cfromBuiltinData :: BuiltinData -> Maybe ProposalId
PlutusTx.FromData
    , -- | @since 0.1.0
      BuiltinData -> ProposalId
(BuiltinData -> ProposalId) -> UnsafeFromData ProposalId
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> ProposalId
$cunsafeFromBuiltinData :: BuiltinData -> ProposalId
PlutusTx.UnsafeFromData
    )
  deriving stock
    ( -- | @since 0.1.0
      ProposalId -> ProposalId -> Bool
(ProposalId -> ProposalId -> Bool)
-> (ProposalId -> ProposalId -> Bool) -> Eq ProposalId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalId -> ProposalId -> Bool
$c/= :: ProposalId -> ProposalId -> Bool
== :: ProposalId -> ProposalId -> Bool
$c== :: ProposalId -> ProposalId -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalId -> ShowS
[ProposalId] -> ShowS
ProposalId -> String
(Int -> ProposalId -> ShowS)
-> (ProposalId -> String)
-> ([ProposalId] -> ShowS)
-> Show ProposalId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalId] -> ShowS
$cshowList :: [ProposalId] -> ShowS
show :: ProposalId -> String
$cshow :: ProposalId -> String
showsPrec :: Int -> ProposalId -> ShowS
$cshowsPrec :: Int -> ProposalId -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalId -> Rep ProposalId x)
-> (forall x. Rep ProposalId x -> ProposalId) -> Generic ProposalId
forall x. Rep ProposalId x -> ProposalId
forall x. ProposalId -> Rep ProposalId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalId x -> ProposalId
$cfrom :: forall x. ProposalId -> Rep ProposalId x
GHC.Generic
    )

{- | Encodes a result. Typically, for a Yes/No proposal, we encode it like this:

     @
     "No"  ~ 'ResultTag' 0
     "Yes" ~ 'ResultTag' 1
     @

     @since 0.1.0
-}
newtype ResultTag = ResultTag {ResultTag -> Integer
getResultTag :: Integer}
  deriving stock
    ( -- | @since 0.1.0
      ResultTag -> ResultTag -> Bool
(ResultTag -> ResultTag -> Bool)
-> (ResultTag -> ResultTag -> Bool) -> Eq ResultTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultTag -> ResultTag -> Bool
$c/= :: ResultTag -> ResultTag -> Bool
== :: ResultTag -> ResultTag -> Bool
$c== :: ResultTag -> ResultTag -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ResultTag -> ShowS
[ResultTag] -> ShowS
ResultTag -> String
(Int -> ResultTag -> ShowS)
-> (ResultTag -> String)
-> ([ResultTag] -> ShowS)
-> Show ResultTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultTag] -> ShowS
$cshowList :: [ResultTag] -> ShowS
show :: ResultTag -> String
$cshow :: ResultTag -> String
showsPrec :: Int -> ResultTag -> ShowS
$cshowsPrec :: Int -> ResultTag -> ShowS
Show
    , -- | @since 0.1.0
      Eq ResultTag
Eq ResultTag
-> (ResultTag -> ResultTag -> Ordering)
-> (ResultTag -> ResultTag -> Bool)
-> (ResultTag -> ResultTag -> Bool)
-> (ResultTag -> ResultTag -> Bool)
-> (ResultTag -> ResultTag -> Bool)
-> (ResultTag -> ResultTag -> ResultTag)
-> (ResultTag -> ResultTag -> ResultTag)
-> Ord ResultTag
ResultTag -> ResultTag -> Bool
ResultTag -> ResultTag -> Ordering
ResultTag -> ResultTag -> ResultTag
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResultTag -> ResultTag -> ResultTag
$cmin :: ResultTag -> ResultTag -> ResultTag
max :: ResultTag -> ResultTag -> ResultTag
$cmax :: ResultTag -> ResultTag -> ResultTag
>= :: ResultTag -> ResultTag -> Bool
$c>= :: ResultTag -> ResultTag -> Bool
> :: ResultTag -> ResultTag -> Bool
$c> :: ResultTag -> ResultTag -> Bool
<= :: ResultTag -> ResultTag -> Bool
$c<= :: ResultTag -> ResultTag -> Bool
< :: ResultTag -> ResultTag -> Bool
$c< :: ResultTag -> ResultTag -> Bool
compare :: ResultTag -> ResultTag -> Ordering
$ccompare :: ResultTag -> ResultTag -> Ordering
Ord
    , -- | @since 0.1.0
      (forall x. ResultTag -> Rep ResultTag x)
-> (forall x. Rep ResultTag x -> ResultTag) -> Generic ResultTag
forall x. Rep ResultTag x -> ResultTag
forall x. ResultTag -> Rep ResultTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResultTag x -> ResultTag
$cfrom :: forall x. ResultTag -> Rep ResultTag x
GHC.Generic
    )
  deriving newtype
    ( -- | @since 0.1.0
      ResultTag -> BuiltinData
(ResultTag -> BuiltinData) -> ToData ResultTag
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: ResultTag -> BuiltinData
$ctoBuiltinData :: ResultTag -> BuiltinData
PlutusTx.ToData
    , -- | @since 0.1.0
      BuiltinData -> Maybe ResultTag
(BuiltinData -> Maybe ResultTag) -> FromData ResultTag
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe ResultTag
$cfromBuiltinData :: BuiltinData -> Maybe ResultTag
PlutusTx.FromData
    , -- | @since 0.1.0
      BuiltinData -> ResultTag
(BuiltinData -> ResultTag) -> UnsafeFromData ResultTag
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> ResultTag
$cunsafeFromBuiltinData :: BuiltinData -> ResultTag
PlutusTx.UnsafeFromData
    )

{- | The "status" of the proposal. This is only useful for state transitions that
     need to happen as a result of a transaction as opposed to time-based "periods".

     See the note on wording & the state machine in the tech-design.

     If the proposal is 'VotingReady', for instance, that doesn't necessarily
     mean that voting is possible, as this also requires the timing to be right.

     @since 0.1.0
-}
data ProposalStatus
  = -- | A draft proposal represents a proposal that has yet to be realized.
    --
    --   In effect, this means one which didn't have enough LQ to be a full
    --   proposal, and needs cosigners to enable that to happen. This is
    --   similar to a "temperature check", but only useful if multiple people
    --   want to pool governance tokens together. If the proposal doesn't get to
    --   'VotingReady' on time, the proposal will __never__ be able to get
    --   voted on.
    Draft
  | -- | The proposal has/had enough GT cosigned in order to be a fully fledged
    --   proposal.
    --
    --   This means that once the timing requirements align,
    --   proposal will be able to be voted on.
    VotingReady
  | -- | The proposal has been voted on, and the votes have been locked
    --   permanently. The proposal now goes into a locking time after the
    --   normal voting time. After this, it's possible to execute the proposal.
    Locked
  | -- | The proposal has finished.
    --
    --   This can mean it's been voted on and completed, but it can also mean
    --   the proposal failed due to time constraints or didn't
    --   get to 'VotingReady' first.
    --
    --   At this stage, the 'votes' field of 'ProposalDatum' is frozen.
    --
    --   See 'AdvanceProposal' for documentation on state transitions.
    --
    --   TODO: The owner of the proposal may choose to reclaim their proposal.
    Finished
  deriving stock
    ( -- | @since 0.1.0
      ProposalStatus -> ProposalStatus -> Bool
(ProposalStatus -> ProposalStatus -> Bool)
-> (ProposalStatus -> ProposalStatus -> Bool) -> Eq ProposalStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalStatus -> ProposalStatus -> Bool
$c/= :: ProposalStatus -> ProposalStatus -> Bool
== :: ProposalStatus -> ProposalStatus -> Bool
$c== :: ProposalStatus -> ProposalStatus -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalStatus -> ShowS
[ProposalStatus] -> ShowS
ProposalStatus -> String
(Int -> ProposalStatus -> ShowS)
-> (ProposalStatus -> String)
-> ([ProposalStatus] -> ShowS)
-> Show ProposalStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalStatus] -> ShowS
$cshowList :: [ProposalStatus] -> ShowS
show :: ProposalStatus -> String
$cshow :: ProposalStatus -> String
showsPrec :: Int -> ProposalStatus -> ShowS
$cshowsPrec :: Int -> ProposalStatus -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalStatus -> Rep ProposalStatus x)
-> (forall x. Rep ProposalStatus x -> ProposalStatus)
-> Generic ProposalStatus
forall x. Rep ProposalStatus x -> ProposalStatus
forall x. ProposalStatus -> Rep ProposalStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalStatus x -> ProposalStatus
$cfrom :: forall x. ProposalStatus -> Rep ProposalStatus x
GHC.Generic
    )

-- | @since 0.1.0
PlutusTx.makeIsDataIndexed ''ProposalStatus [('Draft, 0), ('VotingReady, 1), ('Locked, 2), ('Finished, 3)]

{- | The threshold values for various state transitions to happen.
     This data is stored centrally (in the 'Agora.Governor.Governor') and copied over
     to 'Proposal's when they are created.

     @since 0.1.0
-}
data ProposalThresholds = ProposalThresholds
  { ProposalThresholds -> Tagged @Type GTTag Integer
execute :: Tagged GTTag Integer
  -- ^ How much GT minimum must a particular 'ResultTag' accumulate for it to pass.
  , ProposalThresholds -> Tagged @Type GTTag Integer
create :: Tagged GTTag Integer
  -- ^ How much GT required to "create" a proposal.
  --
  -- It is recommended this be a high enough amount, in order to prevent DOS from bad
  -- actors.
  , ProposalThresholds -> Tagged @Type GTTag Integer
vote :: Tagged GTTag Integer
  -- ^ How much GT required to allow voting to happen.
  -- (i.e. to move into 'VotingReady')
  }
  deriving stock
    ( -- | @since 0.1.0
      ProposalThresholds -> ProposalThresholds -> Bool
(ProposalThresholds -> ProposalThresholds -> Bool)
-> (ProposalThresholds -> ProposalThresholds -> Bool)
-> Eq ProposalThresholds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalThresholds -> ProposalThresholds -> Bool
$c/= :: ProposalThresholds -> ProposalThresholds -> Bool
== :: ProposalThresholds -> ProposalThresholds -> Bool
$c== :: ProposalThresholds -> ProposalThresholds -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalThresholds -> ShowS
[ProposalThresholds] -> ShowS
ProposalThresholds -> String
(Int -> ProposalThresholds -> ShowS)
-> (ProposalThresholds -> String)
-> ([ProposalThresholds] -> ShowS)
-> Show ProposalThresholds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalThresholds] -> ShowS
$cshowList :: [ProposalThresholds] -> ShowS
show :: ProposalThresholds -> String
$cshow :: ProposalThresholds -> String
showsPrec :: Int -> ProposalThresholds -> ShowS
$cshowsPrec :: Int -> ProposalThresholds -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalThresholds -> Rep ProposalThresholds x)
-> (forall x. Rep ProposalThresholds x -> ProposalThresholds)
-> Generic ProposalThresholds
forall x. Rep ProposalThresholds x -> ProposalThresholds
forall x. ProposalThresholds -> Rep ProposalThresholds x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalThresholds x -> ProposalThresholds
$cfrom :: forall x. ProposalThresholds -> Rep ProposalThresholds x
GHC.Generic
    )

-- | @since 0.1.0
PlutusTx.makeIsDataIndexed ''ProposalThresholds [('ProposalThresholds, 0)]

{- | Map which encodes the total tally for each result.
     It's important that the "shape" is consistent with the shape of 'effects'.

     e.g. if the 'effects' field looks like the following:

     @[('ResultTag' 0, []), ('ResultTag' 1, [(vh, dh)])]@

     Then 'ProposalVotes' needs be of the shape:

     @[('ResultTag' 0, n), ('ResultTag' 1, m)]@

     @since 0.1.0
-}
newtype ProposalVotes = ProposalVotes
  { ProposalVotes -> Map ResultTag Integer
getProposalVotes :: AssocMap.Map ResultTag Integer
  }
  deriving newtype
    ( -- | @since 0.1.0
      ProposalVotes -> BuiltinData
(ProposalVotes -> BuiltinData) -> ToData ProposalVotes
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: ProposalVotes -> BuiltinData
$ctoBuiltinData :: ProposalVotes -> BuiltinData
PlutusTx.ToData
    , -- | @since 0.1.0
      BuiltinData -> Maybe ProposalVotes
(BuiltinData -> Maybe ProposalVotes) -> FromData ProposalVotes
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe ProposalVotes
$cfromBuiltinData :: BuiltinData -> Maybe ProposalVotes
PlutusTx.FromData
    , -- | @since 0.1.0
      BuiltinData -> ProposalVotes
(BuiltinData -> ProposalVotes) -> UnsafeFromData ProposalVotes
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> ProposalVotes
$cunsafeFromBuiltinData :: BuiltinData -> ProposalVotes
PlutusTx.UnsafeFromData
    )
  deriving stock
    ( -- | @since 0.1.0
      ProposalVotes -> ProposalVotes -> Bool
(ProposalVotes -> ProposalVotes -> Bool)
-> (ProposalVotes -> ProposalVotes -> Bool) -> Eq ProposalVotes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalVotes -> ProposalVotes -> Bool
$c/= :: ProposalVotes -> ProposalVotes -> Bool
== :: ProposalVotes -> ProposalVotes -> Bool
$c== :: ProposalVotes -> ProposalVotes -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalVotes -> ShowS
[ProposalVotes] -> ShowS
ProposalVotes -> String
(Int -> ProposalVotes -> ShowS)
-> (ProposalVotes -> String)
-> ([ProposalVotes] -> ShowS)
-> Show ProposalVotes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalVotes] -> ShowS
$cshowList :: [ProposalVotes] -> ShowS
show :: ProposalVotes -> String
$cshow :: ProposalVotes -> String
showsPrec :: Int -> ProposalVotes -> ShowS
$cshowsPrec :: Int -> ProposalVotes -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalVotes -> Rep ProposalVotes x)
-> (forall x. Rep ProposalVotes x -> ProposalVotes)
-> Generic ProposalVotes
forall x. Rep ProposalVotes x -> ProposalVotes
forall x. ProposalVotes -> Rep ProposalVotes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalVotes x -> ProposalVotes
$cfrom :: forall x. ProposalVotes -> Rep ProposalVotes x
GHC.Generic
    )

{- | Create a 'ProposalVotes' that has the same shape as the 'effects' field.

     @since 0.1.0
-}
emptyVotesFor :: forall a. AssocMap.Map ResultTag a -> ProposalVotes
emptyVotesFor :: forall a. Map ResultTag a -> ProposalVotes
emptyVotesFor = Map ResultTag Integer -> ProposalVotes
ProposalVotes (Map ResultTag Integer -> ProposalVotes)
-> (Map ResultTag a -> Map ResultTag Integer)
-> Map ResultTag a
-> ProposalVotes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ResultTag -> a -> Integer)
-> Map ResultTag a -> Map ResultTag Integer
forall k a b. (k -> a -> b) -> Map k a -> Map k b
AssocMap.mapWithKey (Integer -> a -> Integer
forall a b. a -> b -> a
const (Integer -> a -> Integer)
-> (ResultTag -> Integer) -> ResultTag -> a -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ResultTag -> Integer
forall a b. a -> b -> a
const Integer
0)

{- | Haskell-level datum for Proposal scripts.

     @since 0.1.0
-}
data ProposalDatum = ProposalDatum
  { ProposalDatum -> ProposalId
proposalId :: ProposalId
  -- ^ Identification of the proposal.
  -- TODO: could we encode this more efficiently?
  -- This is shaped this way for future proofing.
  -- See https://github.com/Liqwid-Labs/agora/issues/39
  , ProposalDatum -> Map ResultTag (Map ValidatorHash DatumHash)
effects :: AssocMap.Map ResultTag (AssocMap.Map ValidatorHash DatumHash)
  -- ^ Effect lookup table. First by result, then by effect hash.
  , ProposalDatum -> ProposalStatus
status :: ProposalStatus
  -- ^ The status the proposal is in.
  , ProposalDatum -> [PubKeyHash]
cosigners :: [PubKeyHash]
  -- ^ Who created the proposal initially, and who cosigned it later.
  , ProposalDatum -> ProposalThresholds
thresholds :: ProposalThresholds
  -- ^ Thresholds copied over on initialization.
  , ProposalDatum -> ProposalVotes
votes :: ProposalVotes
  -- ^ Vote tally on the proposal
  , ProposalDatum -> ProposalTimingConfig
timingConfig :: ProposalTimingConfig
  -- ^ Timing configuration copied over on initialization.
  , ProposalDatum -> ProposalStartingTime
startingTime :: ProposalStartingTime
  -- ^ The time upon the creation of the proposal.
  }
  deriving stock
    ( -- | @since 0.1.0
      ProposalDatum -> ProposalDatum -> Bool
(ProposalDatum -> ProposalDatum -> Bool)
-> (ProposalDatum -> ProposalDatum -> Bool) -> Eq ProposalDatum
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalDatum -> ProposalDatum -> Bool
$c/= :: ProposalDatum -> ProposalDatum -> Bool
== :: ProposalDatum -> ProposalDatum -> Bool
$c== :: ProposalDatum -> ProposalDatum -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalDatum -> ShowS
[ProposalDatum] -> ShowS
ProposalDatum -> String
(Int -> ProposalDatum -> ShowS)
-> (ProposalDatum -> String)
-> ([ProposalDatum] -> ShowS)
-> Show ProposalDatum
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalDatum] -> ShowS
$cshowList :: [ProposalDatum] -> ShowS
show :: ProposalDatum -> String
$cshow :: ProposalDatum -> String
showsPrec :: Int -> ProposalDatum -> ShowS
$cshowsPrec :: Int -> ProposalDatum -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalDatum -> Rep ProposalDatum x)
-> (forall x. Rep ProposalDatum x -> ProposalDatum)
-> Generic ProposalDatum
forall x. Rep ProposalDatum x -> ProposalDatum
forall x. ProposalDatum -> Rep ProposalDatum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalDatum x -> ProposalDatum
$cfrom :: forall x. ProposalDatum -> Rep ProposalDatum x
GHC.Generic
    )

PlutusTx.makeIsDataIndexed ''ProposalDatum [('ProposalDatum, 0)]

{- | Haskell-level redeemer for Proposal scripts.

     @since 0.1.0
-}
data ProposalRedeemer
  = -- | Cast one or more votes towards a particular 'ResultTag'.
    Vote ResultTag
  | -- | Add one or more public keys to the cosignature list.
    --   Must be signed by those cosigning.
    --
    --   This is particularly used in the 'Draft' 'ProposalStatus',
    --   where matching 'Agora.Stake.Stake's can be called to advance the proposal,
    --   provided enough GT is shared  among them.
    Cosign [PubKeyHash]
  | -- | Allow unlocking one or more stakes with votes towards particular 'ResultTag'.
    Unlock ResultTag
  | -- | Advance the proposal, performing the required checks for whether that is legal.
    --
    --   These are roughly the checks for each possible transition:
    --
    --   === @'Draft' -> 'VotingReady'@:
    --
    --     1. The sum of all of the cosigner's GT is larger than the 'startVoting' field of 'ProposalThresholds'.
    --     2. The proposal's current time ensures 'isDraftPeriod'.
    --
    --   === @'VotingReady' -> 'Locked'@:
    --
    --     1. The sum of all votes is larger than 'countVoting'.
    --     2. The winning 'ResultTag' has more votes than all other 'ResultTag's.
    --     3. The proposal's current time ensures 'isVotingPeriod'.
    --
    --   === @'Locked' -> 'Finished'@:
    --
    --     1. The proposal's current time ensures 'isExecutionPeriod'.
    --     2. The transaction mints the GATs to the receiving effects.
    --
    --   === @* -> 'Finished'@:
    --
    --     If the proposal has run out of time for the current 'ProposalStatus', it will always be possible
    --     to transition into 'Finished' status, because it has expired (and failed).
    AdvanceProposal
  deriving stock
    ( -- | @since 0.1.0
      ProposalRedeemer -> ProposalRedeemer -> Bool
(ProposalRedeemer -> ProposalRedeemer -> Bool)
-> (ProposalRedeemer -> ProposalRedeemer -> Bool)
-> Eq ProposalRedeemer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalRedeemer -> ProposalRedeemer -> Bool
$c/= :: ProposalRedeemer -> ProposalRedeemer -> Bool
== :: ProposalRedeemer -> ProposalRedeemer -> Bool
$c== :: ProposalRedeemer -> ProposalRedeemer -> Bool
Eq
    , -- | @since 0.1.0
      Int -> ProposalRedeemer -> ShowS
[ProposalRedeemer] -> ShowS
ProposalRedeemer -> String
(Int -> ProposalRedeemer -> ShowS)
-> (ProposalRedeemer -> String)
-> ([ProposalRedeemer] -> ShowS)
-> Show ProposalRedeemer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalRedeemer] -> ShowS
$cshowList :: [ProposalRedeemer] -> ShowS
show :: ProposalRedeemer -> String
$cshow :: ProposalRedeemer -> String
showsPrec :: Int -> ProposalRedeemer -> ShowS
$cshowsPrec :: Int -> ProposalRedeemer -> ShowS
Show
    , -- | @since 0.1.0
      (forall x. ProposalRedeemer -> Rep ProposalRedeemer x)
-> (forall x. Rep ProposalRedeemer x -> ProposalRedeemer)
-> Generic ProposalRedeemer
forall x. Rep ProposalRedeemer x -> ProposalRedeemer
forall x. ProposalRedeemer -> Rep ProposalRedeemer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalRedeemer x -> ProposalRedeemer
$cfrom :: forall x. ProposalRedeemer -> Rep ProposalRedeemer x
GHC.Generic
    )

-- | @since 0.1.0
PlutusTx.makeIsDataIndexed
  ''ProposalRedeemer
  [ ('Vote, 0)
  , ('Cosign, 1)
  , ('Unlock, 2)
  , ('AdvanceProposal, 3)
  ]

{- | Parameters that identify the Proposal validator script.

     @since 0.1.0
-}
data Proposal = Proposal
  { Proposal -> AssetClass
governorSTAssetClass :: AssetClass
  , Proposal -> AssetClass
stakeSTAssetClass :: AssetClass
  , Proposal -> Integer
maximumCosigners :: Integer
  -- ^ Arbitrary limit for maximum amount of cosigners on a proposal.
  }
  deriving stock
    ( -- | @since 0.1.0
      Int -> Proposal -> ShowS
[Proposal] -> ShowS
Proposal -> String
(Int -> Proposal -> ShowS)
-> (Proposal -> String) -> ([Proposal] -> ShowS) -> Show Proposal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Proposal] -> ShowS
$cshowList :: [Proposal] -> ShowS
show :: Proposal -> String
$cshow :: Proposal -> String
showsPrec :: Int -> Proposal -> ShowS
$cshowsPrec :: Int -> Proposal -> ShowS
Show
    , -- | @since 0.1.0
      Proposal -> Proposal -> Bool
(Proposal -> Proposal -> Bool)
-> (Proposal -> Proposal -> Bool) -> Eq Proposal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Proposal -> Proposal -> Bool
$c/= :: Proposal -> Proposal -> Bool
== :: Proposal -> Proposal -> Bool
$c== :: Proposal -> Proposal -> Bool
Eq
    , -- | @since 0.1.0
      (forall x. Proposal -> Rep Proposal x)
-> (forall x. Rep Proposal x -> Proposal) -> Generic Proposal
forall x. Rep Proposal x -> Proposal
forall x. Proposal -> Rep Proposal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Proposal x -> Proposal
$cfrom :: forall x. Proposal -> Rep Proposal x
GHC.Generic
    )

--------------------------------------------------------------------------------
-- Plutarch-land

{- | Plutarch-level version of 'ResultTag'.

     @since 0.1.0
-}
newtype PResultTag (s :: S) = PResultTag (Term s PInteger)
  deriving
    ( -- | @since 0.1.0
      PCon PResultTag
PMatch PResultTag
PCon PResultTag
-> PMatch PResultTag
-> (forall (s :: S) (b :: PType).
    PResultTag s -> Term s (PInner PResultTag b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PResultTag b)
    -> (PResultTag s -> Term s b) -> Term s b)
-> PlutusType PResultTag
forall (s :: S) (b :: PType).
Term s (PInner PResultTag b)
-> (PResultTag s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PResultTag s -> Term s (PInner PResultTag b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PResultTag b)
-> (PResultTag s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PResultTag b)
-> (PResultTag s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PResultTag s -> Term s (PInner PResultTag b)
$cpcon' :: forall (s :: S) (b :: PType).
PResultTag s -> Term s (PInner PResultTag b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S). Term s (PAsData PResultTag) -> Term s PResultTag)
-> (forall (s :: S). Term s PResultTag -> Term s PData)
-> PIsData PResultTag
forall (s :: S). Term s (PAsData PResultTag) -> Term s PResultTag
forall (s :: S). Term s PResultTag -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PResultTag -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PResultTag -> Term s PData
pfromDataImpl :: forall (s :: S). Term s (PAsData PResultTag) -> Term s PResultTag
$cpfromDataImpl :: forall (s :: S). Term s (PAsData PResultTag) -> Term s PResultTag
PIsData
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PResultTag -> Term s PResultTag -> Term s PBool)
-> PEq PResultTag
forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
forall (t :: PType).
(forall (s :: S). Term s t -> Term s t -> Term s PBool) -> PEq t
#== :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
$c#== :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
PEq
    , -- | @since 0.1.0
      PEq PResultTag
PEq PResultTag
-> (forall (s :: S).
    Term s PResultTag -> Term s PResultTag -> Term s PBool)
-> (forall (s :: S).
    Term s PResultTag -> Term s PResultTag -> Term s PBool)
-> POrd PResultTag
forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
forall (t :: PType).
PEq t
-> (forall (s :: S). Term s t -> Term s t -> Term s PBool)
-> (forall (s :: S). Term s t -> Term s t -> Term s PBool)
-> POrd t
#< :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
$c#< :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
#<= :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
$c#<= :: forall (s :: S).
Term s PResultTag -> Term s PResultTag -> Term s PBool
POrd
    )
    via (DerivePNewtype PResultTag PInteger)

-- | @since 0.1.0
instance PUnsafeLiftDecl PResultTag where type PLifted PResultTag = ResultTag

-- | @since 0.1.0
deriving via
  (DerivePConstantViaNewtype ResultTag PResultTag PInteger)
  instance
    (PConstantDecl ResultTag)

-- | @since 0.1.0
deriving via
  PAsData (DerivePNewtype PResultTag PInteger)
  instance
    PTryFrom PData (PAsData PResultTag)

{- | Plutarch-level version of 'PProposalId'.

     @since 0.1.0
-}
newtype PProposalId (s :: S) = PProposalId (Term s PInteger)
  deriving
    ( -- | @since 0.1.0
      PCon PProposalId
PMatch PProposalId
PCon PProposalId
-> PMatch PProposalId
-> (forall (s :: S) (b :: PType).
    PProposalId s -> Term s (PInner PProposalId b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalId b)
    -> (PProposalId s -> Term s b) -> Term s b)
-> PlutusType PProposalId
forall (s :: S) (b :: PType).
Term s (PInner PProposalId b)
-> (PProposalId s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalId s -> Term s (PInner PProposalId b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalId b)
-> (PProposalId s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalId b)
-> (PProposalId s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalId s -> Term s (PInner PProposalId b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalId s -> Term s (PInner PProposalId b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalId) -> Term s PProposalId)
-> (forall (s :: S). Term s PProposalId -> Term s PData)
-> PIsData PProposalId
forall (s :: S). Term s (PAsData PProposalId) -> Term s PProposalId
forall (s :: S). Term s PProposalId -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalId -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalId -> Term s PData
pfromDataImpl :: forall (s :: S). Term s (PAsData PProposalId) -> Term s PProposalId
$cpfromDataImpl :: forall (s :: S). Term s (PAsData PProposalId) -> Term s PProposalId
PIsData
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PProposalId -> Term s PProposalId -> Term s PBool)
-> PEq PProposalId
forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
forall (t :: PType).
(forall (s :: S). Term s t -> Term s t -> Term s PBool) -> PEq t
#== :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
$c#== :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
PEq
    , -- | @since 0.1.0
      PEq PProposalId
PEq PProposalId
-> (forall (s :: S).
    Term s PProposalId -> Term s PProposalId -> Term s PBool)
-> (forall (s :: S).
    Term s PProposalId -> Term s PProposalId -> Term s PBool)
-> POrd PProposalId
forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
forall (t :: PType).
PEq t
-> (forall (s :: S). Term s t -> Term s t -> Term s PBool)
-> (forall (s :: S). Term s t -> Term s t -> Term s PBool)
-> POrd t
#< :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
$c#< :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
#<= :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
$c#<= :: forall (s :: S).
Term s PProposalId -> Term s PProposalId -> Term s PBool
POrd
    )
    via (DerivePNewtype PProposalId PInteger)

-- | @since 0.1.0
deriving via
  PAsData (DerivePNewtype PProposalId PInteger)
  instance
    PTryFrom PData (PAsData PProposalId)

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalId where type PLifted PProposalId = ProposalId

-- | @since 0.1.0
deriving via
  (DerivePConstantViaNewtype ProposalId PProposalId PInteger)
  instance
    (PConstantDecl ProposalId)

{- | Plutarch-level version of 'ProposalStatus'.

     @since 0.1.0
-}
data PProposalStatus (s :: S)
  = -- TODO: 'PProposalStatus' ought te be encoded as 'PInteger'.
    -- e.g. like Tilde used 'pmatchEnum'.
    PDraft (Term s (PDataRecord '[]))
  | PVotingReady (Term s (PDataRecord '[]))
  | PLocked (Term s (PDataRecord '[]))
  | PFinished (Term s (PDataRecord '[]))
  deriving stock
    ( -- | @since 0.1.0
      (forall x. PProposalStatus s -> Rep (PProposalStatus s) x)
-> (forall x. Rep (PProposalStatus s) x -> PProposalStatus s)
-> Generic (PProposalStatus s)
forall x. Rep (PProposalStatus s) x -> PProposalStatus s
forall x. PProposalStatus s -> Rep (PProposalStatus s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x. Rep (PProposalStatus s) x -> PProposalStatus s
forall (s :: S) x. PProposalStatus s -> Rep (PProposalStatus s) x
$cto :: forall (s :: S) x. Rep (PProposalStatus s) x -> PProposalStatus s
$cfrom :: forall (s :: S) x. PProposalStatus s -> Rep (PProposalStatus s) x
GHC.Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      All @[Type] (SListI @Type) (Code (PProposalStatus s))
All @[Type] (SListI @Type) (Code (PProposalStatus s))
-> (PProposalStatus s -> Rep (PProposalStatus s))
-> (Rep (PProposalStatus s) -> PProposalStatus s)
-> Generic (PProposalStatus s)
Rep (PProposalStatus s) -> PProposalStatus s
PProposalStatus s -> Rep (PProposalStatus s)
forall a.
All @[Type] (SListI @Type) (Code a)
-> (a -> Rep a) -> (Rep a -> a) -> Generic a
forall {s :: S}.
All @[Type] (SListI @Type) (Code (PProposalStatus s))
forall (s :: S). Rep (PProposalStatus s) -> PProposalStatus s
forall (s :: S). PProposalStatus s -> Rep (PProposalStatus s)
to :: Rep (PProposalStatus s) -> PProposalStatus s
$cto :: forall (s :: S). Rep (PProposalStatus s) -> PProposalStatus s
from :: PProposalStatus s -> Rep (PProposalStatus s)
$cfrom :: forall (s :: S). PProposalStatus s -> Rep (PProposalStatus s)
Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      PIsData PProposalStatus
PlutusType PProposalStatus
PlutusType PProposalStatus
-> PIsData PProposalStatus
-> (forall (s :: S).
    PProposalStatus s
    -> Term s (PDataSum (PIsDataReprRepr PProposalStatus)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr PProposalStatus))
    -> (PProposalStatus s -> Term s b) -> Term s b)
-> PIsDataRepr PProposalStatus
forall (s :: S).
PProposalStatus s
-> Term s (PDataSum (PIsDataReprRepr PProposalStatus))
forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalStatus))
-> (PProposalStatus s -> Term s b) -> Term s b
forall (a :: PType).
PlutusType a
-> PIsData a
-> (forall (s :: S). a s -> Term s (PDataSum (PIsDataReprRepr a)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr a))
    -> (a s -> Term s b) -> Term s b)
-> PIsDataRepr a
pmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalStatus))
-> (PProposalStatus s -> Term s b) -> Term s b
$cpmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalStatus))
-> (PProposalStatus s -> Term s b) -> Term s b
pconRepr :: forall (s :: S).
PProposalStatus s
-> Term s (PDataSum (PIsDataReprRepr PProposalStatus))
$cpconRepr :: forall (s :: S).
PProposalStatus s
-> Term s (PDataSum (PIsDataReprRepr PProposalStatus))
PIsDataRepr
    )
  deriving
    ( -- | @since 0.1.0
      PCon PProposalStatus
PMatch PProposalStatus
PCon PProposalStatus
-> PMatch PProposalStatus
-> (forall (s :: S) (b :: PType).
    PProposalStatus s -> Term s (PInner PProposalStatus b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalStatus b)
    -> (PProposalStatus s -> Term s b) -> Term s b)
-> PlutusType PProposalStatus
forall (s :: S) (b :: PType).
Term s (PInner PProposalStatus b)
-> (PProposalStatus s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalStatus s -> Term s (PInner PProposalStatus b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalStatus b)
-> (PProposalStatus s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalStatus b)
-> (PProposalStatus s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalStatus s -> Term s (PInner PProposalStatus b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalStatus s -> Term s (PInner PProposalStatus b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalStatus) -> Term s PProposalStatus)
-> (forall (s :: S). Term s PProposalStatus -> Term s PData)
-> PIsData PProposalStatus
forall (s :: S).
Term s (PAsData PProposalStatus) -> Term s PProposalStatus
forall (s :: S). Term s PProposalStatus -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalStatus -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalStatus -> Term s PData
pfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalStatus) -> Term s PProposalStatus
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalStatus) -> Term s PProposalStatus
PIsData
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PProposalStatus -> Term s PProposalStatus -> Term s PBool)
-> PEq PProposalStatus
forall (s :: S).
Term s PProposalStatus -> Term s PProposalStatus -> Term s PBool
forall (t :: PType).
(forall (s :: S). Term s t -> Term s t -> Term s PBool) -> PEq t
#== :: forall (s :: S).
Term s PProposalStatus -> Term s PProposalStatus -> Term s PBool
$c#== :: forall (s :: S).
Term s PProposalStatus -> Term s PProposalStatus -> Term s PBool
PEq
    )
    via PIsDataReprInstances PProposalStatus

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalStatus where type PLifted PProposalStatus = ProposalStatus

-- | @since 0.1.0
deriving via PAsData (PIsDataReprInstances PProposalStatus) instance PTryFrom PData (PAsData PProposalStatus)

-- | @since 0.1.0
deriving via (DerivePConstantViaData ProposalStatus PProposalStatus) instance (PConstantDecl ProposalStatus)

{- | Plutarch-level version of 'ProposalThresholds'.

     @since 0.1.0
-}
newtype PProposalThresholds (s :: S) = PProposalThresholds
  { forall (s :: S).
PProposalThresholds s
-> Term
     s
     (PDataRecord
        ((':)
           @PLabeledType
           ("execute" ':= PDiscrete @Type GTTag)
           ((':)
              @PLabeledType
              ("create" ':= PDiscrete @Type GTTag)
              ((':)
                 @PLabeledType
                 ("vote" ':= PDiscrete @Type GTTag)
                 ('[] @PLabeledType)))))
getProposalThresholds ::
      Term
        s
        ( PDataRecord
            '[ "execute" ':= PDiscrete GTTag
             , "create" ':= PDiscrete GTTag
             , "vote" ':= PDiscrete GTTag
             ]
        )
  }
  deriving stock
    ( -- | @since 0.1.0
      (forall x. PProposalThresholds s -> Rep (PProposalThresholds s) x)
-> (forall x.
    Rep (PProposalThresholds s) x -> PProposalThresholds s)
-> Generic (PProposalThresholds s)
forall x. Rep (PProposalThresholds s) x -> PProposalThresholds s
forall x. PProposalThresholds s -> Rep (PProposalThresholds s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x.
Rep (PProposalThresholds s) x -> PProposalThresholds s
forall (s :: S) x.
PProposalThresholds s -> Rep (PProposalThresholds s) x
$cto :: forall (s :: S) x.
Rep (PProposalThresholds s) x -> PProposalThresholds s
$cfrom :: forall (s :: S) x.
PProposalThresholds s -> Rep (PProposalThresholds s) x
GHC.Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      All @[Type] (SListI @Type) (Code (PProposalThresholds s))
All @[Type] (SListI @Type) (Code (PProposalThresholds s))
-> (PProposalThresholds s -> Rep (PProposalThresholds s))
-> (Rep (PProposalThresholds s) -> PProposalThresholds s)
-> Generic (PProposalThresholds s)
Rep (PProposalThresholds s) -> PProposalThresholds s
PProposalThresholds s -> Rep (PProposalThresholds s)
forall a.
All @[Type] (SListI @Type) (Code a)
-> (a -> Rep a) -> (Rep a -> a) -> Generic a
forall {s :: S}.
All @[Type] (SListI @Type) (Code (PProposalThresholds s))
forall (s :: S).
Rep (PProposalThresholds s) -> PProposalThresholds s
forall (s :: S).
PProposalThresholds s -> Rep (PProposalThresholds s)
to :: Rep (PProposalThresholds s) -> PProposalThresholds s
$cto :: forall (s :: S).
Rep (PProposalThresholds s) -> PProposalThresholds s
from :: PProposalThresholds s -> Rep (PProposalThresholds s)
$cfrom :: forall (s :: S).
PProposalThresholds s -> Rep (PProposalThresholds s)
Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      PIsData PProposalThresholds
PlutusType PProposalThresholds
PlutusType PProposalThresholds
-> PIsData PProposalThresholds
-> (forall (s :: S).
    PProposalThresholds s
    -> Term s (PDataSum (PIsDataReprRepr PProposalThresholds)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
    -> (PProposalThresholds s -> Term s b) -> Term s b)
-> PIsDataRepr PProposalThresholds
forall (s :: S).
PProposalThresholds s
-> Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
-> (PProposalThresholds s -> Term s b) -> Term s b
forall (a :: PType).
PlutusType a
-> PIsData a
-> (forall (s :: S). a s -> Term s (PDataSum (PIsDataReprRepr a)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr a))
    -> (a s -> Term s b) -> Term s b)
-> PIsDataRepr a
pmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
-> (PProposalThresholds s -> Term s b) -> Term s b
$cpmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
-> (PProposalThresholds s -> Term s b) -> Term s b
pconRepr :: forall (s :: S).
PProposalThresholds s
-> Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
$cpconRepr :: forall (s :: S).
PProposalThresholds s
-> Term s (PDataSum (PIsDataReprRepr PProposalThresholds))
PIsDataRepr
    )
  deriving
    ( -- | @since 0.1.0
      PCon PProposalThresholds
PMatch PProposalThresholds
PCon PProposalThresholds
-> PMatch PProposalThresholds
-> (forall (s :: S) (b :: PType).
    PProposalThresholds s -> Term s (PInner PProposalThresholds b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalThresholds b)
    -> (PProposalThresholds s -> Term s b) -> Term s b)
-> PlutusType PProposalThresholds
forall (s :: S) (b :: PType).
Term s (PInner PProposalThresholds b)
-> (PProposalThresholds s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalThresholds s -> Term s (PInner PProposalThresholds b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalThresholds b)
-> (PProposalThresholds s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalThresholds b)
-> (PProposalThresholds s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalThresholds s -> Term s (PInner PProposalThresholds b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalThresholds s -> Term s (PInner PProposalThresholds b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalThresholds) -> Term s PProposalThresholds)
-> (forall (s :: S). Term s PProposalThresholds -> Term s PData)
-> PIsData PProposalThresholds
forall (s :: S).
Term s (PAsData PProposalThresholds) -> Term s PProposalThresholds
forall (s :: S). Term s PProposalThresholds -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalThresholds -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalThresholds -> Term s PData
pfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalThresholds) -> Term s PProposalThresholds
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalThresholds) -> Term s PProposalThresholds
PIsData
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PProposalThresholds
 -> Term s (PDataRecord (PFields PProposalThresholds)))
-> PDataFields PProposalThresholds
forall (s :: S).
Term s PProposalThresholds
-> Term s (PDataRecord (PFields PProposalThresholds))
forall (a :: PType).
(forall (s :: S). Term s a -> Term s (PDataRecord (PFields a)))
-> PDataFields a
ptoFields :: forall (s :: S).
Term s PProposalThresholds
-> Term s (PDataRecord (PFields PProposalThresholds))
$cptoFields :: forall (s :: S).
Term s PProposalThresholds
-> Term s (PDataRecord (PFields PProposalThresholds))
PDataFields
    )
    via (PIsDataReprInstances PProposalThresholds)

-- | @since 0.1.0
deriving via
  PAsData (PIsDataReprInstances PProposalThresholds)
  instance
    PTryFrom PData (PAsData PProposalThresholds)

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalThresholds where type PLifted PProposalThresholds = ProposalThresholds

-- | @since 0.1.0
deriving via
  (DerivePConstantViaData ProposalThresholds PProposalThresholds)
  instance
    (PConstantDecl ProposalThresholds)

{- | Plutarch-level version of 'ProposalVotes'.

     @since 0.1.0
-}
newtype PProposalVotes (s :: S)
  = PProposalVotes (Term s (PMap 'Unsorted PResultTag PInteger))
  deriving
    ( -- | @since 0.1.0
      PCon PProposalVotes
PMatch PProposalVotes
PCon PProposalVotes
-> PMatch PProposalVotes
-> (forall (s :: S) (b :: PType).
    PProposalVotes s -> Term s (PInner PProposalVotes b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalVotes b)
    -> (PProposalVotes s -> Term s b) -> Term s b)
-> PlutusType PProposalVotes
forall (s :: S) (b :: PType).
Term s (PInner PProposalVotes b)
-> (PProposalVotes s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalVotes s -> Term s (PInner PProposalVotes b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalVotes b)
-> (PProposalVotes s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalVotes b)
-> (PProposalVotes s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalVotes s -> Term s (PInner PProposalVotes b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalVotes s -> Term s (PInner PProposalVotes b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalVotes) -> Term s PProposalVotes)
-> (forall (s :: S). Term s PProposalVotes -> Term s PData)
-> PIsData PProposalVotes
forall (s :: S).
Term s (PAsData PProposalVotes) -> Term s PProposalVotes
forall (s :: S). Term s PProposalVotes -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalVotes -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalVotes -> Term s PData
pfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalVotes) -> Term s PProposalVotes
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalVotes) -> Term s PProposalVotes
PIsData
    )
    via (DerivePNewtype PProposalVotes (PMap 'Unsorted PResultTag PInteger))

-- | @since 0.1.0
deriving via
  PAsData (DerivePNewtype PProposalVotes (PMap 'Unsorted PResultTag PInteger))
  instance
    PTryFrom PData (PAsData PProposalVotes)

{- | Retract votes given the option and the amount of votes.

     @since 0.1.0
-}
pretractVotes :: Term s (PResultTag :--> PInteger :--> PProposalVotes :--> PProposalVotes)
pretractVotes :: forall (s :: S).
Term
  s
  (PResultTag
   :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes)))
pretractVotes = (forall (s :: S).
 Term
   s
   (PResultTag
    :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes))))
-> Term
     s
     (PResultTag
      :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes)))
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PResultTag
     :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes))))
 -> Term
      s
      (PResultTag
       :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes))))
-> (forall (s :: S).
    Term
      s
      (PResultTag
       :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes))))
-> Term
     s
     (PResultTag
      :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes)))
forall a b. (a -> b) -> a -> b
$
  (Term s PResultTag
 -> Term s (PInteger @S)
 -> Term s PProposalVotes
 -> Term s PProposalVotes)
-> Term
     s
     (PResultTag
      :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes)))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term s PResultTag
  -> Term s (PInteger @S)
  -> Term s PProposalVotes
  -> Term s PProposalVotes)
 -> Term
      s
      (PResultTag
       :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes))))
-> (Term s PResultTag
    -> Term s (PInteger @S)
    -> Term s PProposalVotes
    -> Term s PProposalVotes)
-> Term
     s
     (PResultTag
      :--> (PInteger @S :--> (PProposalVotes :--> PProposalVotes)))
forall a b. (a -> b) -> a -> b
$ \Term s PResultTag
rt Term s (PInteger @S)
count Term s PProposalVotes
votes ->
    let voteMap :: Term _ (PMap 'Unsorted PResultTag PInteger)
        voteMap :: Term s (PMap 'Unsorted PResultTag (PInteger @S))
voteMap = Term s PProposalVotes
-> forall (b :: PType). Term s (PInner PProposalVotes b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto Term s PProposalVotes
votes
     in PProposalVotes s -> Term s PProposalVotes
forall (a :: PType) (s :: S). PCon a => a s -> Term s a
pcon (PProposalVotes s -> Term s PProposalVotes)
-> PProposalVotes s -> Term s PProposalVotes
forall a b. (a -> b) -> a -> b
$
          Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
forall (s :: S).
Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
PProposalVotes (Term s (PMap 'Unsorted PResultTag (PInteger @S))
 -> PProposalVotes s)
-> Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
forall a b. (a -> b) -> a -> b
$
            Term
  s
  ((PInteger @S :--> PMaybe (PInteger @S))
   :--> (PResultTag
         :--> (PMap 'Unsorted PResultTag (PInteger @S)
               :--> PMap 'Unsorted PResultTag (PInteger @S))))
forall (k :: PType) (v :: PType) (keys :: KeyGuarantees) (s :: S).
(PIsData k, PIsData v) =>
Term
  s
  ((v :--> PMaybe v)
   :--> (k :--> (PMap keys k v :--> PMap keys k v)))
PM.pupdate
              # plam
                ( \oldCount -> unTermCont $ do
                    newCount <- pletC $ oldCount - count
                    pguardC "Resulting vote count greater or equal to 0" $ 0 #<= newCount
                    pure $ pcon $ PJust newCount
                )
              # rt
              # voteMap

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalVotes where type PLifted PProposalVotes = ProposalVotes

-- | @since 0.1.0
deriving via
  (DerivePConstantViaNewtype ProposalVotes PProposalVotes (PMap 'Unsorted PResultTag PInteger))
  instance
    (PConstantDecl ProposalVotes)

{- | Plutarch-level version of 'emptyVotesFor'.

     @since 0.1.0
-}
pemptyVotesFor :: forall s a. (PIsData a) => Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
pemptyVotesFor :: forall (s :: S) (a :: PType).
PIsData a =>
Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
pemptyVotesFor =
  ClosedTerm (PMap 'Unsorted PResultTag a :--> PProposalVotes)
-> Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic (ClosedTerm (PMap 'Unsorted PResultTag a :--> PProposalVotes)
 -> Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes))
-> ClosedTerm (PMap 'Unsorted PResultTag a :--> PProposalVotes)
-> Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
forall a b. (a -> b) -> a -> b
$
    (Term s (PMap 'Unsorted PResultTag a) -> Term s PProposalVotes)
-> Term s (PMap 'Unsorted PResultTag a :--> PProposalVotes)
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam
      ( \Term s (PMap 'Unsorted PResultTag a)
m ->
          PProposalVotes s -> Term s PProposalVotes
forall (a :: PType) (s :: S). PCon a => a s -> Term s a
pcon (PProposalVotes s -> Term s PProposalVotes)
-> PProposalVotes s -> Term s PProposalVotes
forall a b. (a -> b) -> a -> b
$
            Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
forall (s :: S).
Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
PProposalVotes (Term s (PMap 'Unsorted PResultTag (PInteger @S))
 -> PProposalVotes s)
-> Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> PProposalVotes s
forall a b. (a -> b) -> a -> b
$ Term
  s
  ((a :--> PInteger @S)
   :--> (PMap 'Unsorted PResultTag a
         :--> PMap 'Unsorted PResultTag (PInteger @S)))
forall (k :: PType) (a :: PType) (b :: PType)
       (keys :: KeyGuarantees) (s :: S).
(PIsData k, PIsData a, PIsData b) =>
Term s ((a :--> b) :--> (PMap keys k a :--> PMap keys k b))
PM.pmap Term
  s
  ((a :--> PInteger @S)
   :--> (PMap 'Unsorted PResultTag a
         :--> PMap 'Unsorted PResultTag (PInteger @S)))
-> Term s (a :--> PInteger @S)
-> Term
     s
     (PMap 'Unsorted PResultTag a
      :--> PMap 'Unsorted PResultTag (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s a -> Term s (PInteger @S)) -> Term s (a :--> PInteger @S)
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam (Term s (PInteger @S) -> Term s a -> Term s (PInteger @S)
forall a b. a -> b -> a
const (Term s (PInteger @S) -> Term s a -> Term s (PInteger @S))
-> Term s (PInteger @S) -> Term s a -> Term s (PInteger @S)
forall a b. (a -> b) -> a -> b
$ PLifted (PInteger @S) -> Term s (PInteger @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant PLifted (PInteger @S)
0) Term
  s
  (PMap 'Unsorted PResultTag a
   :--> PMap 'Unsorted PResultTag (PInteger @S))
-> Term s (PMap 'Unsorted PResultTag a)
-> Term s (PMap 'Unsorted PResultTag (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PMap 'Unsorted PResultTag a)
m
      )

{- | Plutarch-level version of 'ProposalDatum'.

     @since 0.1.0
-}
newtype PProposalDatum (s :: S) = PProposalDatum
  { forall (s :: S).
PProposalDatum s
-> Term
     s
     (PDataRecord
        ((':)
           @PLabeledType
           ("proposalId" ':= PProposalId)
           ((':)
              @PLabeledType
              ("effects"
               ':= PMap
                     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
              ((':)
                 @PLabeledType
                 ("status" ':= PProposalStatus)
                 ((':)
                    @PLabeledType
                    ("cosigners" ':= PBuiltinList (PAsData PPubKeyHash))
                    ((':)
                       @PLabeledType
                       ("thresholds" ':= PProposalThresholds)
                       ((':)
                          @PLabeledType
                          ("votes" ':= PProposalVotes)
                          ((':)
                             @PLabeledType
                             ("timingConfig" ':= PProposalTimingConfig)
                             ((':)
                                @PLabeledType
                                ("startingTime" ':= PProposalStartingTime)
                                ('[] @PLabeledType))))))))))
getProposalDatum ::
      Term
        s
        ( PDataRecord
            '[ "proposalId" ':= PProposalId
             , "effects" ':= PMap 'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
             , "status" ':= PProposalStatus
             , "cosigners" ':= PBuiltinList (PAsData PPubKeyHash)
             , "thresholds" ':= PProposalThresholds
             , "votes" ':= PProposalVotes
             , "timingConfig" ':= PProposalTimingConfig
             , "startingTime" ':= PProposalStartingTime
             ]
        )
  }
  deriving stock
    ( -- | @since 0.1.0
      (forall x. PProposalDatum s -> Rep (PProposalDatum s) x)
-> (forall x. Rep (PProposalDatum s) x -> PProposalDatum s)
-> Generic (PProposalDatum s)
forall x. Rep (PProposalDatum s) x -> PProposalDatum s
forall x. PProposalDatum s -> Rep (PProposalDatum s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x. Rep (PProposalDatum s) x -> PProposalDatum s
forall (s :: S) x. PProposalDatum s -> Rep (PProposalDatum s) x
$cto :: forall (s :: S) x. Rep (PProposalDatum s) x -> PProposalDatum s
$cfrom :: forall (s :: S) x. PProposalDatum s -> Rep (PProposalDatum s) x
GHC.Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      All @[Type] (SListI @Type) (Code (PProposalDatum s))
All @[Type] (SListI @Type) (Code (PProposalDatum s))
-> (PProposalDatum s -> Rep (PProposalDatum s))
-> (Rep (PProposalDatum s) -> PProposalDatum s)
-> Generic (PProposalDatum s)
Rep (PProposalDatum s) -> PProposalDatum s
PProposalDatum s -> Rep (PProposalDatum s)
forall a.
All @[Type] (SListI @Type) (Code a)
-> (a -> Rep a) -> (Rep a -> a) -> Generic a
forall {s :: S}.
All @[Type] (SListI @Type) (Code (PProposalDatum s))
forall (s :: S). Rep (PProposalDatum s) -> PProposalDatum s
forall (s :: S). PProposalDatum s -> Rep (PProposalDatum s)
to :: Rep (PProposalDatum s) -> PProposalDatum s
$cto :: forall (s :: S). Rep (PProposalDatum s) -> PProposalDatum s
from :: PProposalDatum s -> Rep (PProposalDatum s)
$cfrom :: forall (s :: S). PProposalDatum s -> Rep (PProposalDatum s)
Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      PIsData PProposalDatum
PlutusType PProposalDatum
PlutusType PProposalDatum
-> PIsData PProposalDatum
-> (forall (s :: S).
    PProposalDatum s
    -> Term s (PDataSum (PIsDataReprRepr PProposalDatum)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr PProposalDatum))
    -> (PProposalDatum s -> Term s b) -> Term s b)
-> PIsDataRepr PProposalDatum
forall (s :: S).
PProposalDatum s
-> Term s (PDataSum (PIsDataReprRepr PProposalDatum))
forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalDatum))
-> (PProposalDatum s -> Term s b) -> Term s b
forall (a :: PType).
PlutusType a
-> PIsData a
-> (forall (s :: S). a s -> Term s (PDataSum (PIsDataReprRepr a)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr a))
    -> (a s -> Term s b) -> Term s b)
-> PIsDataRepr a
pmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalDatum))
-> (PProposalDatum s -> Term s b) -> Term s b
$cpmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalDatum))
-> (PProposalDatum s -> Term s b) -> Term s b
pconRepr :: forall (s :: S).
PProposalDatum s
-> Term s (PDataSum (PIsDataReprRepr PProposalDatum))
$cpconRepr :: forall (s :: S).
PProposalDatum s
-> Term s (PDataSum (PIsDataReprRepr PProposalDatum))
PIsDataRepr
    )
  deriving
    ( -- | @since 0.1.0
      PCon PProposalDatum
PMatch PProposalDatum
PCon PProposalDatum
-> PMatch PProposalDatum
-> (forall (s :: S) (b :: PType).
    PProposalDatum s -> Term s (PInner PProposalDatum b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalDatum b)
    -> (PProposalDatum s -> Term s b) -> Term s b)
-> PlutusType PProposalDatum
forall (s :: S) (b :: PType).
Term s (PInner PProposalDatum b)
-> (PProposalDatum s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalDatum s -> Term s (PInner PProposalDatum b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalDatum b)
-> (PProposalDatum s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalDatum b)
-> (PProposalDatum s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalDatum s -> Term s (PInner PProposalDatum b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalDatum s -> Term s (PInner PProposalDatum b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalDatum) -> Term s PProposalDatum)
-> (forall (s :: S). Term s PProposalDatum -> Term s PData)
-> PIsData PProposalDatum
forall (s :: S).
Term s (PAsData PProposalDatum) -> Term s PProposalDatum
forall (s :: S). Term s PProposalDatum -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalDatum -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalDatum -> Term s PData
pfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalDatum) -> Term s PProposalDatum
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalDatum) -> Term s PProposalDatum
PIsData
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PProposalDatum
 -> Term s (PDataRecord (PFields PProposalDatum)))
-> PDataFields PProposalDatum
forall (s :: S).
Term s PProposalDatum
-> Term s (PDataRecord (PFields PProposalDatum))
forall (a :: PType).
(forall (s :: S). Term s a -> Term s (PDataRecord (PFields a)))
-> PDataFields a
ptoFields :: forall (s :: S).
Term s PProposalDatum
-> Term s (PDataRecord (PFields PProposalDatum))
$cptoFields :: forall (s :: S).
Term s PProposalDatum
-> Term s (PDataRecord (PFields PProposalDatum))
PDataFields
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s PProposalDatum -> Term s PProposalDatum -> Term s PBool)
-> PEq PProposalDatum
forall (s :: S).
Term s PProposalDatum -> Term s PProposalDatum -> Term s PBool
forall (t :: PType).
(forall (s :: S). Term s t -> Term s t -> Term s PBool) -> PEq t
#== :: forall (s :: S).
Term s PProposalDatum -> Term s PProposalDatum -> Term s PBool
$c#== :: forall (s :: S).
Term s PProposalDatum -> Term s PProposalDatum -> Term s PBool
PEq
    )
    via (PIsDataReprInstances PProposalDatum)

-- | @since 0.1.0
deriving via PAsData (PIsDataReprInstances PProposalDatum) instance PTryFrom PData (PAsData PProposalDatum)

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalDatum where type PLifted PProposalDatum = ProposalDatum

-- | @since 0.1.0
deriving via (DerivePConstantViaData ProposalDatum PProposalDatum) instance (PConstantDecl ProposalDatum)

{- | Plutarch-level version of 'ProposalRedeemer'.

     @since 0.1.0
-}
data PProposalRedeemer (s :: S)
  = PVote (Term s (PDataRecord '["resultTag" ':= PResultTag]))
  | PCosign (Term s (PDataRecord '["newCosigners" ':= PBuiltinList (PAsData PPubKeyHash)]))
  | PUnlock (Term s (PDataRecord '["resultTag" ':= PResultTag]))
  | PAdvanceProposal (Term s (PDataRecord '[]))
  deriving stock
    ( -- | @since 0.1.0
      (forall x. PProposalRedeemer s -> Rep (PProposalRedeemer s) x)
-> (forall x. Rep (PProposalRedeemer s) x -> PProposalRedeemer s)
-> Generic (PProposalRedeemer s)
forall x. Rep (PProposalRedeemer s) x -> PProposalRedeemer s
forall x. PProposalRedeemer s -> Rep (PProposalRedeemer s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x.
Rep (PProposalRedeemer s) x -> PProposalRedeemer s
forall (s :: S) x.
PProposalRedeemer s -> Rep (PProposalRedeemer s) x
$cto :: forall (s :: S) x.
Rep (PProposalRedeemer s) x -> PProposalRedeemer s
$cfrom :: forall (s :: S) x.
PProposalRedeemer s -> Rep (PProposalRedeemer s) x
GHC.Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      All @[Type] (SListI @Type) (Code (PProposalRedeemer s))
All @[Type] (SListI @Type) (Code (PProposalRedeemer s))
-> (PProposalRedeemer s -> Rep (PProposalRedeemer s))
-> (Rep (PProposalRedeemer s) -> PProposalRedeemer s)
-> Generic (PProposalRedeemer s)
Rep (PProposalRedeemer s) -> PProposalRedeemer s
PProposalRedeemer s -> Rep (PProposalRedeemer s)
forall a.
All @[Type] (SListI @Type) (Code a)
-> (a -> Rep a) -> (Rep a -> a) -> Generic a
forall {s :: S}.
All @[Type] (SListI @Type) (Code (PProposalRedeemer s))
forall (s :: S). Rep (PProposalRedeemer s) -> PProposalRedeemer s
forall (s :: S). PProposalRedeemer s -> Rep (PProposalRedeemer s)
to :: Rep (PProposalRedeemer s) -> PProposalRedeemer s
$cto :: forall (s :: S). Rep (PProposalRedeemer s) -> PProposalRedeemer s
from :: PProposalRedeemer s -> Rep (PProposalRedeemer s)
$cfrom :: forall (s :: S). PProposalRedeemer s -> Rep (PProposalRedeemer s)
Generic
    )
  deriving anyclass
    ( -- | @since 0.1.0
      PIsData PProposalRedeemer
PlutusType PProposalRedeemer
PlutusType PProposalRedeemer
-> PIsData PProposalRedeemer
-> (forall (s :: S).
    PProposalRedeemer s
    -> Term s (PDataSum (PIsDataReprRepr PProposalRedeemer)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
    -> (PProposalRedeemer s -> Term s b) -> Term s b)
-> PIsDataRepr PProposalRedeemer
forall (s :: S).
PProposalRedeemer s
-> Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
-> (PProposalRedeemer s -> Term s b) -> Term s b
forall (a :: PType).
PlutusType a
-> PIsData a
-> (forall (s :: S). a s -> Term s (PDataSum (PIsDataReprRepr a)))
-> (forall (s :: S) (b :: PType).
    Term s (PDataSum (PIsDataReprRepr a))
    -> (a s -> Term s b) -> Term s b)
-> PIsDataRepr a
pmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
-> (PProposalRedeemer s -> Term s b) -> Term s b
$cpmatchRepr :: forall (s :: S) (b :: PType).
Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
-> (PProposalRedeemer s -> Term s b) -> Term s b
pconRepr :: forall (s :: S).
PProposalRedeemer s
-> Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
$cpconRepr :: forall (s :: S).
PProposalRedeemer s
-> Term s (PDataSum (PIsDataReprRepr PProposalRedeemer))
PIsDataRepr
    )
  deriving
    ( -- | @since 0.1.0
      PCon PProposalRedeemer
PMatch PProposalRedeemer
PCon PProposalRedeemer
-> PMatch PProposalRedeemer
-> (forall (s :: S) (b :: PType).
    PProposalRedeemer s -> Term s (PInner PProposalRedeemer b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner PProposalRedeemer b)
    -> (PProposalRedeemer s -> Term s b) -> Term s b)
-> PlutusType PProposalRedeemer
forall (s :: S) (b :: PType).
Term s (PInner PProposalRedeemer b)
-> (PProposalRedeemer s -> Term s b) -> Term s b
forall (s :: S) (b :: PType).
PProposalRedeemer s -> Term s (PInner PProposalRedeemer b)
forall (a :: PType).
PCon a
-> PMatch a
-> (forall (s :: S) (b :: PType). a s -> Term s (PInner a b))
-> (forall (s :: S) (b :: PType).
    Term s (PInner a b) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
pmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalRedeemer b)
-> (PProposalRedeemer s -> Term s b) -> Term s b
$cpmatch' :: forall (s :: S) (b :: PType).
Term s (PInner PProposalRedeemer b)
-> (PProposalRedeemer s -> Term s b) -> Term s b
pcon' :: forall (s :: S) (b :: PType).
PProposalRedeemer s -> Term s (PInner PProposalRedeemer b)
$cpcon' :: forall (s :: S) (b :: PType).
PProposalRedeemer s -> Term s (PInner PProposalRedeemer b)
PlutusType
    , -- | @since 0.1.0
      (forall (s :: S).
 Term s (PAsData PProposalRedeemer) -> Term s PProposalRedeemer)
-> (forall (s :: S). Term s PProposalRedeemer -> Term s PData)
-> PIsData PProposalRedeemer
forall (s :: S).
Term s (PAsData PProposalRedeemer) -> Term s PProposalRedeemer
forall (s :: S). Term s PProposalRedeemer -> Term s PData
forall (a :: PType).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
pdataImpl :: forall (s :: S). Term s PProposalRedeemer -> Term s PData
$cpdataImpl :: forall (s :: S). Term s PProposalRedeemer -> Term s PData
pfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalRedeemer) -> Term s PProposalRedeemer
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PProposalRedeemer) -> Term s PProposalRedeemer
PIsData
    )
    via PIsDataReprInstances PProposalRedeemer

-- | @since 0.1.0
deriving via
  PAsData (PIsDataReprInstances PProposalRedeemer)
  instance
    PTryFrom PData (PAsData PProposalRedeemer)

-- | @since 0.1.0
instance PUnsafeLiftDecl PProposalRedeemer where type PLifted PProposalRedeemer = ProposalRedeemer

-- | @since 0.1.0
deriving via (DerivePConstantViaData ProposalRedeemer PProposalRedeemer) instance (PConstantDecl ProposalRedeemer)

--------------------------------------------------------------------------------

{- | Check for various invariants a proposal must uphold.
     This can be used to check both upon creation and
     upon any following state transitions in the proposal.

     @since 0.1.0
-}
proposalDatumValid :: Proposal -> Term s (Agora.Proposal.PProposalDatum :--> PBool)
proposalDatumValid :: forall (s :: S). Proposal -> Term s (PProposalDatum :--> PBool)
proposalDatumValid Proposal
proposal =
  ClosedTerm (PProposalDatum :--> PBool)
-> Term s (PProposalDatum :--> PBool)
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic (ClosedTerm (PProposalDatum :--> PBool)
 -> Term s (PProposalDatum :--> PBool))
-> ClosedTerm (PProposalDatum :--> PBool)
-> Term s (PProposalDatum :--> PBool)
forall a b. (a -> b) -> a -> b
$
    (Term s PProposalDatum -> Term s PBool)
-> Term s (PProposalDatum :--> PBool)
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term s PProposalDatum -> Term s PBool)
 -> Term s (PProposalDatum :--> PBool))
-> (Term s PProposalDatum -> Term s PBool)
-> Term s (PProposalDatum :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s PProposalDatum
datum' -> TermCont @PBool s (Term s PBool) -> Term s PBool
forall (a :: PType) (s :: S). TermCont @a s (Term s a) -> Term s a
unTermCont (TermCont @PBool s (Term s PBool) -> Term s PBool)
-> TermCont @PBool s (Term s PBool) -> Term s PBool
forall a b. (a -> b) -> a -> b
$ do
      HRec
  ((':)
     @(Symbol, Type)
     '("effects",
       Term
         s
         (PAsData
            (PMap
               'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
     ((':)
        @(Symbol, Type)
        '("cosigners",
          Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
        ((':)
           @(Symbol, Type)
           '("votes", Term s (PAsData PProposalVotes))
           ('[] @(Symbol, Type)))))
datum <- ((HRec
    ((':)
       @(Symbol, Type)
       '("effects",
         Term
           s
           (PAsData
              (PMap
                 'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
       ((':)
          @(Symbol, Type)
          '("cosigners",
            Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
          ((':)
             @(Symbol, Type)
             '("votes", Term s (PAsData PProposalVotes))
             ('[] @(Symbol, Type)))))
  -> Term s PBool)
 -> Term s PBool)
-> TermCont
     @PBool
     s
     (HRec
        ((':)
           @(Symbol, Type)
           '("effects",
             Term
               s
               (PAsData
                  (PMap
                     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
           ((':)
              @(Symbol, Type)
              '("cosigners",
                Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
              ((':)
                 @(Symbol, Type)
                 '("votes", Term s (PAsData PProposalVotes))
                 ('[] @(Symbol, Type))))))
forall a (s :: S) (r :: PType).
((a -> Term s r) -> Term s r) -> TermCont @r s a
tcont (((HRec
     ((':)
        @(Symbol, Type)
        '("effects",
          Term
            s
            (PAsData
               (PMap
                  'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
        ((':)
           @(Symbol, Type)
           '("cosigners",
             Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
           ((':)
              @(Symbol, Type)
              '("votes", Term s (PAsData PProposalVotes))
              ('[] @(Symbol, Type)))))
   -> Term s PBool)
  -> Term s PBool)
 -> TermCont
      @PBool
      s
      (HRec
         ((':)
            @(Symbol, Type)
            '("effects",
              Term
                s
                (PAsData
                   (PMap
                      'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
            ((':)
               @(Symbol, Type)
               '("cosigners",
                 Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
               ((':)
                  @(Symbol, Type)
                  '("votes", Term s (PAsData PProposalVotes))
                  ('[] @(Symbol, Type)))))))
-> ((HRec
       ((':)
          @(Symbol, Type)
          '("effects",
            Term
              s
              (PAsData
                 (PMap
                    'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
          ((':)
             @(Symbol, Type)
             '("cosigners",
               Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
             ((':)
                @(Symbol, Type)
                '("votes", Term s (PAsData PProposalVotes))
                ('[] @(Symbol, Type)))))
     -> Term s PBool)
    -> Term s PBool)
-> TermCont
     @PBool
     s
     (HRec
        ((':)
           @(Symbol, Type)
           '("effects",
             Term
               s
               (PAsData
                  (PMap
                     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
           ((':)
              @(Symbol, Type)
              '("cosigners",
                Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
              ((':)
                 @(Symbol, Type)
                 '("votes", Term s (PAsData PProposalVotes))
                 ('[] @(Symbol, Type))))))
forall a b. (a -> b) -> a -> b
$ forall (fs :: [Symbol]) (a :: PType) (s :: S) (b :: PType)
       (ps :: [PLabeledType]) (bs :: [ToBind]).
(PDataFields a,
 (ps :: [PLabeledType]) ~ (PFields a :: [PLabeledType]),
 (bs :: [ToBind]) ~ (Bindings ps fs :: [ToBind]),
 BindFields ps bs) =>
Term s a -> (HRecOf a fs s -> Term s b) -> Term s b
pletFields @'["effects", "cosigners", "votes"] (Term s PProposalDatum
 -> (HRecOf
       PProposalDatum
       ((':)
          @Symbol
          "effects"
          ((':) @Symbol "cosigners" ((':) @Symbol "votes" ('[] @Symbol))))
       s
     -> Term s PBool)
 -> Term s PBool)
-> Term s PProposalDatum
-> (HRecOf
      PProposalDatum
      ((':)
         @Symbol
         "effects"
         ((':) @Symbol "cosigners" ((':) @Symbol "votes" ('[] @Symbol))))
      s
    -> Term s PBool)
-> Term s PBool
forall a b. (a -> b) -> a -> b
$ Term s PProposalDatum
datum'

      let atLeastOneNegativeResult :: Term s PBool
atLeastOneNegativeResult =
            Term
  s
  ((PBuiltinPair
      (PAsData PResultTag)
      (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
    :--> PBool)
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PResultTag)
              (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
         :--> PBool))
forall (list :: PType -> PType) (a :: PType) (s :: S).
PIsListLike list a =>
Term s ((a :--> PBool) :--> (list a :--> PBool))
pany
              # phoistAcyclic
                (plam $ \m -> pnull #$ pto $ pfromData $ psndBuiltin # m)
              #$ pto
              $ pfromData datum.effects

      Term s PBool -> TermCont @PBool s (Term s PBool)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Term s PBool -> TermCont @PBool s (Term s PBool))
-> Term s PBool -> TermCont @PBool s (Term s PBool)
forall a b. (a -> b) -> a -> b
$
        (Term s PBool -> Term s PBool -> Term s PBool)
-> [Term s PBool] -> Term s PBool
forall (t :: Type -> Type) a.
Foldable t =>
(a -> a -> a) -> t a -> a
foldr1
          Term s PBool -> Term s PBool -> Term s PBool
forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
(#&&)
          [ Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Proposal has at least one ResultTag has no effects" Term s PBool
atLeastOneNegativeResult
          , Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Proposal has at least one cosigner" (Term s PBool -> Term s PBool) -> Term s PBool -> Term s PBool
forall a b. (a -> b) -> a -> b
$ Term s (PBuiltinList (PAsData PPubKeyHash) :--> PBool)
forall (a :: PType) (s :: S) (list :: PType -> PType).
PIsListLike list a =>
Term s (list a :--> PBool)
pnotNull Term s (PBuiltinList (PAsData PPubKeyHash) :--> PBool)
-> Term s (PBuiltinList (PAsData PPubKeyHash)) -> Term s PBool
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PAsData (PBuiltinList (PAsData PPubKeyHash)))
-> Term s (PBuiltinList (PAsData PPubKeyHash))
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData HRec
  ((':)
     @(Symbol, Type)
     '("effects",
       Term
         s
         (PAsData
            (PMap
               'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
     ((':)
        @(Symbol, Type)
        '("cosigners",
          Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
        ((':)
           @(Symbol, Type)
           '("votes", Term s (PAsData PProposalVotes))
           ('[] @(Symbol, Type)))))
datum.cosigners
          , Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Proposal has fewer cosigners than the limit" (Term s PBool -> Term s PBool) -> Term s PBool -> Term s PBool
forall a b. (a -> b) -> a -> b
$ Term s (PBuiltinList (PAsData PPubKeyHash) :--> PInteger @S)
forall (list :: PType -> PType) (a :: PType) (s :: S).
PIsListLike list a =>
Term s (list a :--> PInteger @S)
plength Term s (PBuiltinList (PAsData PPubKeyHash) :--> PInteger @S)
-> Term s (PBuiltinList (PAsData PPubKeyHash))
-> Term s (PInteger @S)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PAsData (PBuiltinList (PAsData PPubKeyHash)))
-> Term s (PBuiltinList (PAsData PPubKeyHash))
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData HRec
  ((':)
     @(Symbol, Type)
     '("effects",
       Term
         s
         (PAsData
            (PMap
               'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
     ((':)
        @(Symbol, Type)
        '("cosigners",
          Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
        ((':)
           @(Symbol, Type)
           '("votes", Term s (PAsData PProposalVotes))
           ('[] @(Symbol, Type)))))
datum.cosigners Term s (PInteger @S) -> Term s (PInteger @S) -> Term s PBool
forall (t :: PType) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#<= PLifted (PInteger @S) -> Term s (PInteger @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant Proposal
proposal.maximumCosigners
          , Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Proposal votes and effects are compatible with each other" (Term s PBool -> Term s PBool) -> Term s PBool -> Term s PBool
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
   :--> (PMap 'Unsorted PResultTag (PInteger @S) :--> PBool))
forall (k :: PType) (a :: PType) (b :: PType) (s :: S).
(POrd k, PIsData k) =>
Term s (PMap 'Unsorted k a :--> (PMap 'Unsorted k b :--> PBool))
PUM.pkeysEqual Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
   :--> (PMap 'Unsorted PResultTag (PInteger @S) :--> PBool))
-> Term
     s
     (PMap
        'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
-> Term s (PMap 'Unsorted PResultTag (PInteger @S) :--> PBool)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# HRec
  ((':)
     @(Symbol, Type)
     '("effects",
       Term
         s
         (PAsData
            (PMap
               'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
     ((':)
        @(Symbol, Type)
        '("cosigners",
          Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
        ((':)
           @(Symbol, Type)
           '("votes", Term s (PAsData PProposalVotes))
           ('[] @(Symbol, Type)))))
datum.effects Term s (PMap 'Unsorted PResultTag (PInteger @S) :--> PBool)
-> Term s (PMap 'Unsorted PResultTag (PInteger @S)) -> Term s PBool
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PProposalVotes
-> forall (b :: PType). Term s (PInner PProposalVotes b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto (Term s (PAsData PProposalVotes) -> Term s PProposalVotes
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData HRec
  ((':)
     @(Symbol, Type)
     '("effects",
       Term
         s
         (PAsData
            (PMap
               'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))))
     ((':)
        @(Symbol, Type)
        '("cosigners",
          Term s (PAsData (PBuiltinList (PAsData PPubKeyHash))))
        ((':)
           @(Symbol, Type)
           '("votes", Term s (PAsData PProposalVotes))
           ('[] @(Symbol, Type)))))
datum.votes)
          ]

{- | Wrapper for 'pwinner''. When the winner cannot be found,
      the 'neutral' option will be returned.

     @since 0.1.0
-}
pwinner ::
  Term
    s
    ( PProposalVotes
        :--> PInteger
        :--> PResultTag
        :--> PResultTag
    )
pwinner :: forall (s :: S).
Term
  s
  (PProposalVotes
   :--> (PInteger @S :--> (PResultTag :--> PResultTag)))
pwinner = (forall (s :: S).
 Term
   s
   (PProposalVotes
    :--> (PInteger @S :--> (PResultTag :--> PResultTag))))
-> Term
     s
     (PProposalVotes
      :--> (PInteger @S :--> (PResultTag :--> PResultTag)))
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PProposalVotes
     :--> (PInteger @S :--> (PResultTag :--> PResultTag))))
 -> Term
      s
      (PProposalVotes
       :--> (PInteger @S :--> (PResultTag :--> PResultTag))))
-> (forall (s :: S).
    Term
      s
      (PProposalVotes
       :--> (PInteger @S :--> (PResultTag :--> PResultTag))))
-> Term
     s
     (PProposalVotes
      :--> (PInteger @S :--> (PResultTag :--> PResultTag)))
forall a b. (a -> b) -> a -> b
$
  (Term s PProposalVotes
 -> Term s (PInteger @S) -> Term s PResultTag -> Term s PResultTag)
-> Term
     s
     (PProposalVotes
      :--> (PInteger @S :--> (PResultTag :--> PResultTag)))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term s PProposalVotes
  -> Term s (PInteger @S) -> Term s PResultTag -> Term s PResultTag)
 -> Term
      s
      (PProposalVotes
       :--> (PInteger @S :--> (PResultTag :--> PResultTag))))
-> (Term s PProposalVotes
    -> Term s (PInteger @S) -> Term s PResultTag -> Term s PResultTag)
-> Term
     s
     (PProposalVotes
      :--> (PInteger @S :--> (PResultTag :--> PResultTag)))
forall a b. (a -> b) -> a -> b
$ \Term s PProposalVotes
votes Term s (PInteger @S)
quorum Term s PResultTag
neutral -> Term s (PMaybe PResultTag)
-> (PMaybe PResultTag s -> Term s PResultTag) -> Term s PResultTag
forall (a :: PType) (s :: S) (b :: PType).
PMatch a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
forall (s :: S).
Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
pwinner' Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
-> Term s PProposalVotes
-> Term s (PInteger @S :--> PMaybe PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PProposalVotes
votes Term s (PInteger @S :--> PMaybe PResultTag)
-> Term s (PInteger @S) -> Term s (PMaybe PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PInteger @S)
quorum) ((PMaybe PResultTag s -> Term s PResultTag) -> Term s PResultTag)
-> (PMaybe PResultTag s -> Term s PResultTag) -> Term s PResultTag
forall a b. (a -> b) -> a -> b
$ \case
    PMaybe PResultTag s
PNothing -> Term s PResultTag
neutral
    PJust Term s PResultTag
winner -> Term s PResultTag
winner

{- | Find the winner result tag, given the votes and the quorum.

     The winner should be unambiguous, meaning that if two options have the same highest votes,
       the function will return 'PNothing'.

     @since 0.1.0
-}
pwinner' ::
  Term
    s
    ( PProposalVotes
        :--> PInteger
        :--> PMaybe PResultTag
    )
pwinner' :: forall (s :: S).
Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
pwinner' = (forall (s :: S).
 Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag)))
-> Term
     s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic ((forall (s :: S).
  Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag)))
 -> Term
      s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag)))
-> (forall (s :: S).
    Term s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag)))
-> Term
     s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
forall a b. (a -> b) -> a -> b
$
  (Term s PProposalVotes
 -> Term s (PInteger @S) -> Term s (PMaybe PResultTag))
-> Term
     s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term s PProposalVotes
  -> Term s (PInteger @S) -> Term s (PMaybe PResultTag))
 -> Term
      s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag)))
-> (Term s PProposalVotes
    -> Term s (PInteger @S) -> Term s (PMaybe PResultTag))
-> Term
     s (PProposalVotes :--> (PInteger @S :--> PMaybe PResultTag))
forall a b. (a -> b) -> a -> b
$ \Term s PProposalVotes
votes Term s (PInteger @S)
quorum -> TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag))
-> Term s (PMaybe PResultTag)
forall (a :: PType) (s :: S). TermCont @a s (Term s a) -> Term s a
unTermCont (TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag))
 -> Term s (PMaybe PResultTag))
-> TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag))
-> Term s (PMaybe PResultTag)
forall a b. (a -> b) -> a -> b
$ do
    Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
winner <- Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> TermCont
     @(PMaybe PResultTag)
     s
     (Term
        s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall {r :: PType} (s :: S) (a :: PType).
Term s a -> TermCont @r s (Term s a)
pletC (Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
 -> TermCont
      @(PMaybe PResultTag)
      s
      (Term
         s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> TermCont
     @(PMaybe PResultTag)
     s
     (Term
        s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PProposalVotes
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S).
Term
  s
  (PProposalVotes
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
phighestVotes Term
  s
  (PProposalVotes
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s PProposalVotes
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PProposalVotes
votes
    Term s PResultTag
winnerResultTag <- Term s PResultTag
-> TermCont @(PMaybe PResultTag) s (Term s PResultTag)
forall {r :: PType} (s :: S) (a :: PType).
Term s a -> TermCont @r s (Term s a)
pletC (Term s PResultTag
 -> TermCont @(PMaybe PResultTag) s (Term s PResultTag))
-> Term s PResultTag
-> TermCont @(PMaybe PResultTag) s (Term s PResultTag)
forall a b. (a -> b) -> a -> b
$ Term s (PAsData PResultTag) -> Term s PResultTag
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PResultTag) -> Term s PResultTag)
-> Term s (PAsData PResultTag) -> Term s PResultTag
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> a)
pfstBuiltin Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData PResultTag)
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s (PAsData PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
winner
    Term s (PInteger @S)
highestVotes <- Term s (PInteger @S)
-> TermCont @(PMaybe PResultTag) s (Term s (PInteger @S))
forall {r :: PType} (s :: S) (a :: PType).
Term s a -> TermCont @r s (Term s a)
pletC (Term s (PInteger @S)
 -> TermCont @(PMaybe PResultTag) s (Term s (PInteger @S)))
-> Term s (PInteger @S)
-> TermCont @(PMaybe PResultTag) s (Term s (PInteger @S))
forall a b. (a -> b) -> a -> b
$ Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData (PInteger @S)) -> Term s (PInteger @S))
-> Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> b)
psndBuiltin Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s (PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
winner

    let l :: Term _ (PBuiltinList _)
        l :: Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
l = Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> forall (b :: PType).
   Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto (Term s (PMap 'Unsorted PResultTag (PInteger @S))
 -> forall (b :: PType).
    Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b))
-> Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> forall (b :: PType).
   Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b)
forall a b. (a -> b) -> a -> b
$ Term s PProposalVotes
-> forall (b :: PType). Term s (PInner PProposalVotes b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto Term s PProposalVotes
votes

        f ::
          Term
            _
            ( PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
                :--> PInteger
                :--> PInteger
            )
        f :: Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PInteger @S :--> PInteger @S))
f = (Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
 -> Term s (PInteger @S) -> Term s (PInteger @S))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PInteger @S :--> PInteger @S))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term
    s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
  -> Term s (PInteger @S) -> Term s (PInteger @S))
 -> Term
      s
      (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
       :--> (PInteger @S :--> PInteger @S)))
-> (Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
    -> Term s (PInteger @S) -> Term s (PInteger @S))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PInteger @S :--> PInteger @S))
forall a b. (a -> b) -> a -> b
$ \(Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData (PInteger @S)) -> Term s (PInteger @S))
-> (Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
    -> Term s (PAsData (PInteger @S)))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s (PInteger @S)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> b)
psndBuiltin #) -> Term s (PInteger @S)
thisVotes) Term s (PInteger @S)
i ->
          Term s PBool
-> Term s (PInteger @S)
-> Term s (PInteger @S)
-> Term s (PInteger @S)
forall (s :: S) (a :: PType).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
            (Term s (PInteger @S)
thisVotes Term s (PInteger @S) -> Term s (PInteger @S) -> Term s PBool
forall (t :: PType) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s (PInteger @S)
highestVotes)
            (Term s (PInteger @S)
i Term s (PInteger @S)
-> Term s (PInteger @S) -> Term s (PInteger @S)
forall a. Num a => a -> a -> a
+ Term s (PInteger @S)
1)
            Term s (PInteger @S)
i

        noDuplicateHighestVotes :: Term s PBool
noDuplicateHighestVotes =
          Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Ambiguous winner" (Term s PBool -> Term s PBool) -> Term s PBool -> Term s PBool
forall a b. (a -> b) -> a -> b
$
            Term
  s
  ((PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
    :--> (PInteger @S :--> PInteger @S))
   :--> (PInteger @S
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
               :--> PInteger @S)))
forall (list :: PType -> PType) (a :: PType) (s :: S) (b :: PType).
PIsListLike list a =>
Term s ((a :--> (b :--> b)) :--> (b :--> (list a :--> b)))
pfoldr Term
  s
  ((PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
    :--> (PInteger @S :--> PInteger @S))
   :--> (PInteger @S
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
               :--> PInteger @S)))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PInteger @S :--> PInteger @S))
-> Term
     s
     (PInteger @S
      :--> (PBuiltinList
              (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
            :--> PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PInteger @S :--> PInteger @S))
f Term
  s
  (PInteger @S
   :--> (PBuiltinList
           (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
         :--> PInteger @S))
-> Term s (PInteger @S)
-> Term
     s
     (PBuiltinList
        (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
      :--> PInteger @S)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PInteger @S)
0 Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
   :--> PInteger @S)
-> Term
     s
     (PBuiltinList
        (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term s (PInteger @S)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
l Term s (PInteger @S) -> Term s (PInteger @S) -> Term s PBool
forall (t :: PType) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s (PInteger @S)
1

        exceedQuorum :: Term s PBool
exceedQuorum =
          Term s (PString @S) -> Term s PBool -> Term s PBool
forall (s :: S).
Term s (PString @S) -> Term s PBool -> Term s PBool
ptraceIfFalse Term s (PString @S)
"Highest vote count should exceed the minimum threshold" (Term s PBool -> Term s PBool) -> Term s PBool -> Term s PBool
forall a b. (a -> b) -> a -> b
$
            Term s (PInteger @S)
quorum Term s (PInteger @S) -> Term s (PInteger @S) -> Term s PBool
forall (t :: PType) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#< Term s (PInteger @S)
highestVotes

    Term s (PMaybe PResultTag)
-> TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Term s (PMaybe PResultTag)
 -> TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag)))
-> Term s (PMaybe PResultTag)
-> TermCont @(PMaybe PResultTag) s (Term s (PMaybe PResultTag))
forall a b. (a -> b) -> a -> b
$
      Term s PBool
-> Term s (PMaybe PResultTag)
-> Term s (PMaybe PResultTag)
-> Term s (PMaybe PResultTag)
forall (s :: S) (a :: PType).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s PBool
noDuplicateHighestVotes Term s PBool -> Term s PBool -> Term s PBool
forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
#&& Term s PBool
exceedQuorum)
        (PMaybe PResultTag s -> Term s (PMaybe PResultTag)
forall (a :: PType) (s :: S). PCon a => a s -> Term s a
pcon (PMaybe PResultTag s -> Term s (PMaybe PResultTag))
-> PMaybe PResultTag s -> Term s (PMaybe PResultTag)
forall a b. (a -> b) -> a -> b
$ Term s PResultTag -> PMaybe PResultTag s
forall (a :: PType) (s :: S). Term s a -> PMaybe a s
PJust Term s PResultTag
winnerResultTag)
        (PMaybe PResultTag s -> Term s (PMaybe PResultTag)
forall (a :: PType) (s :: S). PCon a => a s -> Term s a
pcon PMaybe PResultTag s
forall (a :: PType) (s :: S). PMaybe a s
PNothing)

{- | Find the outcome with the highest vote count given the votes.

     @since 0.1.0
-}
phighestVotes ::
  Term
    s
    ( PProposalVotes
        :--> PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
    )
phighestVotes :: forall (s :: S).
Term
  s
  (PProposalVotes
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
phighestVotes = (forall (s :: S).
 Term
   s
   (PProposalVotes
    :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PProposalVotes
      :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PProposalVotes
     :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
 -> Term
      s
      (PProposalVotes
       :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> (forall (s :: S).
    Term
      s
      (PProposalVotes
       :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PProposalVotes
      :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall a b. (a -> b) -> a -> b
$
  (Term s PProposalVotes
 -> Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PProposalVotes
      :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term s PProposalVotes
  -> Term
       s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
 -> Term
      s
      (PProposalVotes
       :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> (Term s PProposalVotes
    -> Term
         s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PProposalVotes
      :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall a b. (a -> b) -> a -> b
$ \Term s PProposalVotes
votes ->
    let l :: Term _ (PBuiltinList _)
        l :: Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
l = Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> forall (b :: PType).
   Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto (Term s (PMap 'Unsorted PResultTag (PInteger @S))
 -> forall (b :: PType).
    Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b))
-> Term s (PMap 'Unsorted PResultTag (PInteger @S))
-> forall (b :: PType).
   Term s (PInner (PMap 'Unsorted PResultTag (PInteger @S)) b)
forall a b. (a -> b) -> a -> b
$ Term s PProposalVotes
-> forall (b :: PType). Term s (PInner PProposalVotes b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto Term s PProposalVotes
votes

        f ::
          Term
            _
            ( PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
                :--> PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
                :--> PBuiltinPair (PAsData PResultTag) (PAsData PInteger)
            )
        f :: Term
  w
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
f = ClosedTerm
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     w
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic (ClosedTerm
   (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
    :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
          :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
 -> Term
      w
      (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
       :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
             :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))))
-> ClosedTerm
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     w
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall a b. (a -> b) -> a -> b
$
          (Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
 -> Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
 -> Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term
    s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
  -> Term
       s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
  -> Term
       s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
 -> Term
      s
      (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
       :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
             :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))))
-> (Term
      s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
    -> Term
         s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
    -> Term
         s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall a b. (a -> b) -> a -> b
$ \Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
this Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
last ->
            let lastVotes :: Term s (PInteger @S)
lastVotes = Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData (PInteger @S)) -> Term s (PInteger @S))
-> Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> b)
psndBuiltin Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s (PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
last
                thisVotes :: Term s (PInteger @S)
thisVotes = Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData (PInteger @S)) -> Term s (PInteger @S))
-> Term s (PAsData (PInteger @S)) -> Term s (PInteger @S)
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> b)
psndBuiltin Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> PAsData (PInteger @S))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term s (PAsData (PInteger @S))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
this
             in Term s PBool
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S) (a :: PType).
Term s PBool -> Term s a -> Term s a -> Term s a
pif (Term s (PInteger @S)
lastVotes Term s (PInteger @S) -> Term s (PInteger @S) -> Term s PBool
forall (t :: PType) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#< Term s (PInteger @S)
thisVotes) Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
this Term s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
last
     in Term
  s
  ((PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
    :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
          :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
               :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))))
forall (list :: PType -> PType) (a :: PType) (s :: S) (b :: PType).
PIsListLike list a =>
Term s ((a :--> (b :--> b)) :--> (b :--> (list a :--> b)))
pfoldr Term
  s
  ((PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
    :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
          :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
               :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
      :--> (PBuiltinList
              (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
            :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
ClosedTerm
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
         :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
f Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))
   :--> (PBuiltinList
           (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
         :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term
     s
     (PBuiltinList
        (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
      :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# (Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (list :: PType -> PType) (a :: PType) (s :: S).
(PListLike list, PElemConstraint list a) =>
Term s (list a :--> a)
phead Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term
     s
     (PBuiltinList
        (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
l) Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
   :--> PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
-> Term
     s
     (PBuiltinList
        (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
-> Term
     s (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinList
     (PBuiltinPair (PAsData PResultTag) (PAsData (PInteger @S))))
l

{- | Find the "neutral" option (a dummy outcome with no effect) given the effects.

     @since 0.1.0
-}
pneutralOption ::
  Term
    s
    ( PMap 'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
        :--> PResultTag
    )
pneutralOption :: forall (s :: S).
Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
   :--> PResultTag)
pneutralOption = (forall (s :: S).
 Term
   s
   (PMap
      'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
    :--> PResultTag))
-> Term
     s
     (PMap
        'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
      :--> PResultTag)
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PMap
       'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
     :--> PResultTag))
 -> Term
      s
      (PMap
         'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
       :--> PResultTag))
-> (forall (s :: S).
    Term
      s
      (PMap
         'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
       :--> PResultTag))
-> Term
     s
     (PMap
        'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
      :--> PResultTag)
forall a b. (a -> b) -> a -> b
$
  (Term
   s
   (PMap
      'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
 -> Term s PResultTag)
-> Term
     s
     (PMap
        'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
      :--> PResultTag)
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term
    s
    (PMap
       'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
  -> Term s PResultTag)
 -> Term
      s
      (PMap
         'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
       :--> PResultTag))
-> (Term
      s
      (PMap
         'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
    -> Term s PResultTag)
-> Term
     s
     (PMap
        'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash)
      :--> PResultTag)
forall a b. (a -> b) -> a -> b
$ \Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
effects ->
    let l :: Term _ (PBuiltinList (PBuiltinPair (PAsData PResultTag) _))
        l :: Term
  s
  (PBuiltinList
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
l = Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
-> forall (b :: PType).
   Term
     s
     (PInner
        (PMap
           'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
        b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto Term
  s
  (PMap
     'Unsorted PResultTag (PMap 'Unsorted PValidatorHash PDatumHash))
effects

        f :: Term _ (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted _ _)) :--> PBool)
        f :: Term
  w
  (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
   :--> PBool)
f = ClosedTerm
  (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
   :--> PBool)
-> Term
     w
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
      :--> PBool)
forall (a :: PType) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic (ClosedTerm
   (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
    :--> PBool)
 -> Term
      w
      (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
       :--> PBool))
-> ClosedTerm
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
      :--> PBool)
-> Term
     w
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
      :--> PBool)
forall a b. (a -> b) -> a -> b
$
          (Term
   s
   (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w)))
 -> Term s PBool)
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
      :--> PBool)
forall a (b :: PType) (s :: S) (c :: PType).
PLamN a b s =>
(Term s c -> a) -> Term s (c :--> b)
plam ((Term
    s
    (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w)))
  -> Term s PBool)
 -> Term
      s
      (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
       :--> PBool))
-> (Term
      s
      (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w)))
    -> Term s PBool)
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
      :--> PBool)
forall a b. (a -> b) -> a -> b
$ \((Term s (PAsData (PMap 'Unsorted w w))
-> Term s (PMap 'Unsorted w w)
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData (PMap 'Unsorted w w))
 -> Term s (PMap 'Unsorted w w))
-> (Term
      s
      (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w)))
    -> Term s (PAsData (PMap 'Unsorted w w)))
-> Term
     s
     (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w)))
-> Term s (PMap 'Unsorted w w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term
  s
  (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
   :--> PAsData (PMap 'Unsorted w w))
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> b)
psndBuiltin #) -> Term s (PMap 'Unsorted w w)
el)) ->
            let el' :: Term _ (PBuiltinList _)
                el' :: Term s (PBuiltinList (PBuiltinPair (PAsData w) (PAsData w)))
el' = Term s (PMap 'Unsorted w w)
-> forall (b :: PType). Term s (PInner (PMap 'Unsorted w w) b)
forall (s :: S) (a :: PType).
Term s a -> forall (b :: PType). Term s (PInner a b)
pto Term s (PMap 'Unsorted w w)
el
             in Term
  s (PBuiltinList (PBuiltinPair (PAsData w) (PAsData w)) :--> PBool)
forall (list :: PType -> PType) (a :: PType) (s :: S).
(PListLike list, PElemConstraint list a) =>
Term s (list a :--> PBool)
pnull Term
  s (PBuiltinList (PBuiltinPair (PAsData w) (PAsData w)) :--> PBool)
-> Term s (PBuiltinList (PBuiltinPair (PAsData w) (PAsData w)))
-> Term s PBool
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PBuiltinList (PBuiltinPair (PAsData w) (PAsData w)))
el'
     in Term s (PAsData PResultTag) -> Term s PResultTag
forall (a :: PType) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PResultTag) -> Term s PResultTag)
-> Term s (PAsData PResultTag) -> Term s PResultTag
forall a b. (a -> b) -> a -> b
$ Term
  s
  (PBuiltinPair
     (PAsData PResultTag)
     (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
   :--> PAsData PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (PBuiltinPair a b :--> a)
pfstBuiltin Term
  s
  (PBuiltinPair
     (PAsData PResultTag)
     (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
   :--> PAsData PResultTag)
-> Term
     s
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
-> Term s (PAsData PResultTag)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s
  (PString @S
   :--> (PMaybe
           (PBuiltinPair
              (PAsData PResultTag)
              (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
         :--> PBuiltinPair
                (PAsData PResultTag)
                (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
forall (a :: PType) (s :: S).
Term s (PString @S :--> (PMaybe a :--> a))
mustBePJust Term
  s
  (PString @S
   :--> (PMaybe
           (PBuiltinPair
              (PAsData PResultTag)
              (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
         :--> PBuiltinPair
                (PAsData PResultTag)
                (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
-> Term s (PString @S)
-> Term
     s
     (PMaybe
        (PBuiltinPair
           (PAsData PResultTag)
           (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
      :--> PBuiltinPair
             (PAsData PResultTag)
             (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PString @S)
"No neutral option" Term
  s
  (PMaybe
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
   :--> PBuiltinPair
          (PAsData PResultTag)
          (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
-> Term
     s
     (PMaybe
        (PBuiltinPair
           (PAsData PResultTag)
           (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
-> Term
     s
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s
  ((PBuiltinPair
      (PAsData PResultTag)
      (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
    :--> PBool)
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PResultTag)
              (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
         :--> PMaybe
                (PBuiltinPair
                   (PAsData PResultTag)
                   (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))))
forall (l :: PType -> PType) (a :: PType) (s :: S).
PIsListLike l a =>
Term s ((a :--> PBool) :--> (l a :--> PMaybe a))
pfind Term
  s
  ((PBuiltinPair
      (PAsData PResultTag)
      (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
    :--> PBool)
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PResultTag)
              (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
         :--> PMaybe
                (PBuiltinPair
                   (PAsData PResultTag)
                   (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))))
-> Term
     s
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
      :--> PBool)
-> Term
     s
     (PBuiltinList
        (PBuiltinPair
           (PAsData PResultTag)
           (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
      :--> PMaybe
             (PBuiltinPair
                (PAsData PResultTag)
                (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinPair
     (PAsData PResultTag)
     (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))
   :--> PBool)
forall {w :: S} {w :: PType} {w :: PType}.
Term
  w
  (PBuiltinPair (PAsData PResultTag) (PAsData (PMap 'Unsorted w w))
   :--> PBool)
f Term
  s
  (PBuiltinList
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash)))
   :--> PMaybe
          (PBuiltinPair
             (PAsData PResultTag)
             (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
-> Term
     s
     (PBuiltinList
        (PBuiltinPair
           (PAsData PResultTag)
           (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
-> Term
     s
     (PMaybe
        (PBuiltinPair
           (PAsData PResultTag)
           (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s
  (PBuiltinList
     (PBuiltinPair
        (PAsData PResultTag)
        (PAsData (PMap 'Unsorted PValidatorHash PDatumHash))))
l