module Plutarch.LedgerApi.Value (
  -- * Types
  PRawValue (..),
  PSortedValue,
  PLedgerValue,
  PCurrencySymbol (..),
  PTokenName (..),
  PLovelace (..),
  PAssetClass (..),

  -- * Functions

  -- ** Creation

  -- *** PRawValue
  pemptyRawValue,
  psingletonRawValue,
  psingletonRawValueData,

  -- *** PSortedValue
  pemptySortedValue,
  psingletonSortedValue,
  psingletonSortedValueData,

  -- *** PLedgerValue
  pemptyLedgerValue,
  psingletonLedgerValue,
  psingletonLedgerValueData,

  -- *** PCurrencySymbol
  padaSymbol,
  padaSymbolData,

  -- *** PTokenName
  padaToken,

  -- ** Transformation
  passertSorted,
  ppromoteToSortedValue,
  pforgetSorted,
  ptoLedgerValue,

  -- ** Partial ordering
  plt,
  pleq,
  pcheckBinRel,

  -- ** Combination
  pleftBiasedCurrencyUnion,
  pleftBiasedTokenUnion,
  punionWith,
  punionWithData,

  -- ** Queries
  pvalueOf,
  plovelaceValueOf,
  pisAdaOnlyValue,
  phasZeroTokenQuantities,
  phasAdaEntry,
  phasZeroAdaEntry,

  -- ** Misc (internal use)
  pinsertAdaEntry,
  pnormalizeNoAdaNonZeroTokens,
  pmapAmounts,
) where

import Data.Kind (Type)
import GHC.Generics (Generic)
import Generics.SOP qualified as SOP
import Plutarch.LedgerApi.AssocMap qualified as AssocMap
import Plutarch.LedgerApi.Value.AssetClass (PAssetClass (..))
import Plutarch.LedgerApi.Value.CurrencySymbol (PCurrencySymbol (..), padaSymbol, padaSymbolData)
import Plutarch.LedgerApi.Value.Lovelace (PLovelace (..))
import Plutarch.LedgerApi.Value.TokenName (PTokenName (..), padaToken)
import Plutarch.Prelude hiding (psingleton)
import Plutarch.Unsafe (punsafeCoerce, punsafeDowncast)
import PlutusLedgerApi.V3 qualified as Plutus
import PlutusTx.Prelude qualified as PlutusTx

----------------------------------------------------------------------
-- PRawValue

{- | Represents Values without any guarantees.

Values of this type may be unsorted, have duplicate keys, contain empty token
maps, and include entries with zero token quantities.

@since 3.5.0
-}
newtype PRawValue (s :: S)
  = PRawValue (Term s (AssocMap.PUnsortedMap PCurrencySymbol (AssocMap.PUnsortedMap PTokenName PInteger)))
  deriving stock
    ( -- | @since 3.5.0
      (forall x. PRawValue s -> Rep (PRawValue s) x)
-> (forall x. Rep (PRawValue s) x -> PRawValue s)
-> Generic (PRawValue s)
forall x. Rep (PRawValue s) x -> PRawValue s
forall x. PRawValue s -> Rep (PRawValue s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x. Rep (PRawValue s) x -> PRawValue s
forall (s :: S) x. PRawValue s -> Rep (PRawValue s) x
$cfrom :: forall (s :: S) x. PRawValue s -> Rep (PRawValue s) x
from :: forall x. PRawValue s -> Rep (PRawValue s) x
$cto :: forall (s :: S) x. Rep (PRawValue s) x -> PRawValue s
to :: forall x. Rep (PRawValue s) x -> PRawValue s
Generic
    )
  deriving anyclass
    ( -- | @since 3.5.0
      All SListI (Code (PRawValue s))
All SListI (Code (PRawValue s)) =>
(PRawValue s -> Rep (PRawValue s))
-> (Rep (PRawValue s) -> PRawValue s) -> Generic (PRawValue s)
Rep (PRawValue s) -> PRawValue s
PRawValue s -> Rep (PRawValue s)
forall a.
All SListI (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (s :: S). All SListI (Code (PRawValue s))
forall (s :: S). Rep (PRawValue s) -> PRawValue s
forall (s :: S). PRawValue s -> Rep (PRawValue s)
$cfrom :: forall (s :: S). PRawValue s -> Rep (PRawValue s)
from :: PRawValue s -> Rep (PRawValue s)
$cto :: forall (s :: S). Rep (PRawValue s) -> PRawValue s
to :: Rep (PRawValue s) -> PRawValue s
SOP.Generic
    , -- | @since 3.5.0
      (forall (s :: S). Term s (PAsData PRawValue) -> Term s PRawValue)
-> (forall (s :: S). Term s PRawValue -> Term s PData)
-> PIsData PRawValue
forall (s :: S). Term s (PAsData PRawValue) -> Term s PRawValue
forall (s :: S). Term s PRawValue -> Term s PData
forall (a :: S -> Type).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
$cpfromDataImpl :: forall (s :: S). Term s (PAsData PRawValue) -> Term s PRawValue
pfromDataImpl :: forall (s :: S). Term s (PAsData PRawValue) -> Term s PRawValue
$cpdataImpl :: forall (s :: S). Term s PRawValue -> Term s PData
pdataImpl :: forall (s :: S). Term s PRawValue -> Term s PData
PIsData
    , -- | @since 3.5.0
      (forall (s :: S). Bool -> Term s PRawValue -> Term s PString)
-> PShow PRawValue
forall (s :: S). Bool -> Term s PRawValue -> Term s PString
forall (t :: S -> Type).
(forall (s :: S). Bool -> Term s t -> Term s PString) -> PShow t
$cpshow' :: forall (s :: S). Bool -> Term s PRawValue -> Term s PString
pshow' :: forall (s :: S). Bool -> Term s PRawValue -> Term s PString
PShow
    )
  deriving
    ( -- | @since 3.5.0
      (forall (s :: S). PRawValue s -> Term s (PInner PRawValue))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner PRawValue) -> (PRawValue s -> Term s b) -> Term s b)
-> PlutusType PRawValue
forall (s :: S). PRawValue s -> Term s (PInner PRawValue)
forall (s :: S) (b :: S -> Type).
Term s (PInner PRawValue) -> (PRawValue s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
$cpcon' :: forall (s :: S). PRawValue s -> Term s (PInner PRawValue)
pcon' :: forall (s :: S). PRawValue s -> Term s (PInner PRawValue)
$cpmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PRawValue) -> (PRawValue s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PRawValue) -> (PRawValue s -> Term s b) -> Term s b
PlutusType
    )
    via (DeriveNewtypePlutusType PRawValue)
  deriving
    ( -- | @since 3.6.0
      (forall (s :: S).
 Term s PData -> forall (r :: S -> Type). Term s r -> Term s r)
-> PValidateData PRawValue
forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
forall (a :: S -> Type).
(forall (s :: S).
 Term s PData -> forall (r :: S -> Type). Term s r -> Term s r)
-> PValidateData a
$cpwithValidated :: forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated :: forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
PValidateData
    )
    via ( DeriveNewtypePValidateData
            PRawValue
            (AssocMap.PUnsortedMap PCurrencySymbol (AssocMap.PUnsortedMap PTokenName PInteger))
        )

-- | @since 3.5.0
instance PTryFrom PData (PAsData PRawValue)

-- | @since 3.5.0
deriving via
  DeriveNewtypePLiftable PRawValue Plutus.Value
  instance
    PLiftable PRawValue

----------------------------------------------------------------------
-- PSortedValue

{- | Represents sorted, well-formed Values without empty token maps.

Duplicate currency symbols or duplicate token names within the same
token map are not allowed (since wip).

Compared to 'PRawValue', this type provides stronger guarantees, though
'PSortedValue's may still contain entries with zero token quantities.

@since 3.5.0
-}
newtype PSortedValue (s :: S)
  = PSortedValue (Term s (AssocMap.PSortedMap PCurrencySymbol (AssocMap.PSortedMap PTokenName PInteger)))
  deriving stock
    ( -- | @since 3.5.0
      (forall x. PSortedValue s -> Rep (PSortedValue s) x)
-> (forall x. Rep (PSortedValue s) x -> PSortedValue s)
-> Generic (PSortedValue s)
forall x. Rep (PSortedValue s) x -> PSortedValue s
forall x. PSortedValue s -> Rep (PSortedValue s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x. Rep (PSortedValue s) x -> PSortedValue s
forall (s :: S) x. PSortedValue s -> Rep (PSortedValue s) x
$cfrom :: forall (s :: S) x. PSortedValue s -> Rep (PSortedValue s) x
from :: forall x. PSortedValue s -> Rep (PSortedValue s) x
$cto :: forall (s :: S) x. Rep (PSortedValue s) x -> PSortedValue s
to :: forall x. Rep (PSortedValue s) x -> PSortedValue s
Generic
    )
  deriving anyclass
    ( -- | @since 3.5.0
      All SListI (Code (PSortedValue s))
All SListI (Code (PSortedValue s)) =>
(PSortedValue s -> Rep (PSortedValue s))
-> (Rep (PSortedValue s) -> PSortedValue s)
-> Generic (PSortedValue s)
Rep (PSortedValue s) -> PSortedValue s
PSortedValue s -> Rep (PSortedValue s)
forall a.
All SListI (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (s :: S). All SListI (Code (PSortedValue s))
forall (s :: S). Rep (PSortedValue s) -> PSortedValue s
forall (s :: S). PSortedValue s -> Rep (PSortedValue s)
$cfrom :: forall (s :: S). PSortedValue s -> Rep (PSortedValue s)
from :: PSortedValue s -> Rep (PSortedValue s)
$cto :: forall (s :: S). Rep (PSortedValue s) -> PSortedValue s
to :: Rep (PSortedValue s) -> PSortedValue s
SOP.Generic
    , -- | @since 3.5.0
      (forall (s :: S).
 Term s (PAsData PSortedValue) -> Term s PSortedValue)
-> (forall (s :: S). Term s PSortedValue -> Term s PData)
-> PIsData PSortedValue
forall (s :: S).
Term s (PAsData PSortedValue) -> Term s PSortedValue
forall (s :: S). Term s PSortedValue -> Term s PData
forall (a :: S -> Type).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PSortedValue) -> Term s PSortedValue
pfromDataImpl :: forall (s :: S).
Term s (PAsData PSortedValue) -> Term s PSortedValue
$cpdataImpl :: forall (s :: S). Term s PSortedValue -> Term s PData
pdataImpl :: forall (s :: S). Term s PSortedValue -> Term s PData
PIsData
    , -- | @since 3.5.0
      (forall (s :: S). Bool -> Term s PSortedValue -> Term s PString)
-> PShow PSortedValue
forall (s :: S). Bool -> Term s PSortedValue -> Term s PString
forall (t :: S -> Type).
(forall (s :: S). Bool -> Term s t -> Term s PString) -> PShow t
$cpshow' :: forall (s :: S). Bool -> Term s PSortedValue -> Term s PString
pshow' :: forall (s :: S). Bool -> Term s PSortedValue -> Term s PString
PShow
    )
  deriving
    ( -- | @since 3.5.0
      (forall (s :: S). PSortedValue s -> Term s (PInner PSortedValue))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner PSortedValue)
    -> (PSortedValue s -> Term s b) -> Term s b)
-> PlutusType PSortedValue
forall (s :: S). PSortedValue s -> Term s (PInner PSortedValue)
forall (s :: S) (b :: S -> Type).
Term s (PInner PSortedValue)
-> (PSortedValue s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
$cpcon' :: forall (s :: S). PSortedValue s -> Term s (PInner PSortedValue)
pcon' :: forall (s :: S). PSortedValue s -> Term s (PInner PSortedValue)
$cpmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PSortedValue)
-> (PSortedValue s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PSortedValue)
-> (PSortedValue s -> Term s b) -> Term s b
PlutusType
    )
    via (DeriveNewtypePlutusType PSortedValue)

-- | @since 3.5.0
instance PEq PSortedValue where
  Term s PSortedValue
a #== :: forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
#== Term s PSortedValue
b = Term s PSortedValue -> Term s (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PSortedValue
a Term
  s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term s PBool
forall (s :: S).
Term
  s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s PSortedValue -> Term s (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PSortedValue
b

-- | @since 3.5.0
instance Semigroup (Term s PSortedValue) where
  Term s PSortedValue
a <> :: Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
<> Term s PSortedValue
b = Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall (s :: S).
Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
punionWith Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PInteger :--> (PInteger :--> PInteger))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s PInteger -> Term s PInteger -> Term s PInteger)
-> Term s (PInteger :--> (PInteger :--> PInteger))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PInteger -> Term s PInteger)
-> Term s (c :--> (PInteger :--> PInteger))
plam Term s PInteger -> Term s PInteger -> Term s PInteger
forall a. Num a => a -> a -> a
(+) Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
-> Term s PSortedValue -> Term s (PSortedValue :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
a Term s (PSortedValue :--> PSortedValue)
-> Term s PSortedValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
b

-- | @since 3.5.0
instance PlutusTx.Semigroup (Term s PSortedValue) where
  Term s PSortedValue
a <> :: Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
<> Term s PSortedValue
b = Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall (s :: S).
Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
punionWith Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PInteger :--> (PInteger :--> PInteger))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s PInteger -> Term s PInteger -> Term s PInteger)
-> Term s (PInteger :--> (PInteger :--> PInteger))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PInteger -> Term s PInteger)
-> Term s (c :--> (PInteger :--> PInteger))
plam Term s PInteger -> Term s PInteger -> Term s PInteger
forall a. Num a => a -> a -> a
(+) Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
-> Term s PSortedValue -> Term s (PSortedValue :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
a Term s (PSortedValue :--> PSortedValue)
-> Term s PSortedValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
b

-- | @since 3.5.0
instance PSemigroup PSortedValue where
  {-# INLINEABLE (#<>) #-}
  #<> :: forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
(#<>) = Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
forall a. Semigroup a => a -> a -> a
(<>)

-- | @since 3.5.0
instance Monoid (Term s PSortedValue) where
  mempty :: Term s PSortedValue
mempty = Term s PSortedValue
forall (s :: S). Term s PSortedValue
pemptySortedValue

-- | @since 3.5.0
instance PlutusTx.Monoid (Term s PSortedValue) where
  mempty :: Term s PSortedValue
mempty = Term s PSortedValue
forall (s :: S). Term s PSortedValue
pemptySortedValue

-- | @since 3.5.0
instance PMonoid PSortedValue where
  {-# INLINEABLE pmempty #-}
  pmempty :: forall (s :: S). Term s PSortedValue
pmempty = Term s PSortedValue
forall a. Monoid a => a
mempty

-- | @since 3.5.0
instance PlutusTx.Group (Term s PSortedValue) where
  inv :: Term s PSortedValue -> Term s PSortedValue
inv Term s PSortedValue
a = Term s PRawValue -> Term s PSortedValue
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s PRawValue -> Term s PSortedValue)
-> Term s PRawValue -> Term s PSortedValue
forall a b. (a -> b) -> a -> b
$ Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
forall (s :: S).
Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
pmapAmounts Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
-> Term s (PInteger :--> PInteger)
-> Term s (PRawValue :--> PRawValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s PInteger -> Term s PInteger)
-> Term s (PInteger :--> PInteger)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PInteger) -> Term s (c :--> PInteger)
plam Term s PInteger -> Term s PInteger
forall a. Num a => a -> a
negate Term s (PRawValue :--> PRawValue)
-> Term s PRawValue -> Term s PRawValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue -> Term s PRawValue
forall (s :: S). Term s PSortedValue -> Term s PRawValue
pforgetSorted Term s PSortedValue
a

-- | @since 3.5.0
instance PTryFrom PData (PAsData PSortedValue) where
  ptryFrom' :: forall (s :: S) (r :: S -> Type).
Term s PData
-> ((Term s (PAsData PSortedValue),
     Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
    -> Term s r)
-> Term s r
ptryFrom' Term s PData
opq = TermCont
  s
  (Term s (PAsData PSortedValue),
   Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
-> ((Term s (PAsData PSortedValue),
     Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
    -> Term s r)
-> Term s r
forall (r :: S -> Type) (s :: S) a.
TermCont s a -> (a -> Term s r) -> Term s r
runTermCont (TermCont
   s
   (Term s (PAsData PSortedValue),
    Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
 -> ((Term s (PAsData PSortedValue),
      Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
     -> Term s r)
 -> Term s r)
-> TermCont
     s
     (Term s (PAsData PSortedValue),
      Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
-> ((Term s (PAsData PSortedValue),
     Reduce (PTryFromExcess PData (PAsData PSortedValue) s))
    -> Term s r)
-> Term s r
forall a b. (a -> b) -> a -> b
$ do
    (Term s (PAsData PRawValue)
opq', ()
_) <- (((Term s (PAsData PRawValue), ()) -> Term s r) -> Term s r)
-> TermCont s (Term s (PAsData PRawValue), ())
forall a (s :: S) (r :: S -> Type).
((a -> Term s r) -> Term s r) -> TermCont s a
tcont ((((Term s (PAsData PRawValue), ()) -> Term s r) -> Term s r)
 -> TermCont s (Term s (PAsData PRawValue), ()))
-> (((Term s (PAsData PRawValue), ()) -> Term s r) -> Term s r)
-> TermCont s (Term s (PAsData PRawValue), ())
forall a b. (a -> b) -> a -> b
$ forall (b :: S -> Type) (a :: S -> Type) (s :: S) (r :: S -> Type).
PTryFrom a b =>
Term s a
-> ((Term s b, Reduce (PTryFromExcess a b s)) -> Term s r)
-> Term s r
ptryFrom @(PAsData PRawValue) Term s PData
opq
    Term s PSortedValue
unwrapped <- ((Term s PSortedValue -> Term s r) -> Term s r)
-> TermCont s (Term s PSortedValue)
forall a (s :: S) (r :: S -> Type).
((a -> Term s r) -> Term s r) -> TermCont s a
tcont (((Term s PSortedValue -> Term s r) -> Term s r)
 -> TermCont s (Term s PSortedValue))
-> (Term s (PAsData PRawValue)
    -> (Term s PSortedValue -> Term s r) -> Term s r)
-> Term s (PAsData PRawValue)
-> TermCont s (Term s PSortedValue)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s PSortedValue
-> (Term s PSortedValue -> Term s r) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s a -> (Term s a -> Term s b) -> Term s b
plet (Term s PSortedValue
 -> (Term s PSortedValue -> Term s r) -> Term s r)
-> (Term s (PAsData PRawValue) -> Term s PSortedValue)
-> Term s (PAsData PRawValue)
-> (Term s PSortedValue -> Term s r)
-> Term s r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PRawValue :--> PSortedValue)
-> Term s PRawValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
papp Term s (PRawValue :--> PSortedValue)
forall (s :: S). Term s (PRawValue :--> PSortedValue)
ppromoteToSortedValue (Term s PRawValue -> Term s PSortedValue)
-> (Term s (PAsData PRawValue) -> Term s PRawValue)
-> Term s (PAsData PRawValue)
-> Term s PSortedValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PAsData PRawValue) -> Term s PRawValue
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PRawValue) -> TermCont s (Term s PSortedValue))
-> Term s (PAsData PRawValue) -> TermCont s (Term s PSortedValue)
forall a b. (a -> b) -> a -> b
$ Term s (PAsData PRawValue)
opq'
    (Term s (PAsData PSortedValue), ())
-> TermCont s (Term s (PAsData PSortedValue), ())
forall a. a -> TermCont s a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Term s PSortedValue -> Term s (PAsData PSortedValue)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata Term s PSortedValue
unwrapped, ())

{- | Checks that we have a valid 'PSortedValue'. The underlying map must be
sorted and contain no empty token maps.

@since 3.6.0
-}
instance PValidateData PSortedValue where
  pwithValidated :: forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated Term s PData
opq Term s r
x =
    Term s PSortedValue
-> (Term s PSortedValue -> Term s r) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s a -> (Term s a -> Term s b) -> Term s b
plet
      (Term s (PRawValue :--> PSortedValue)
forall (s :: S). Term s (PRawValue :--> PSortedValue)
ppromoteToSortedValue Term s (PRawValue :--> PSortedValue)
-> Term s PRawValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term s (PAsData PRawValue) -> Term s PRawValue
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PRawValue) -> Term s PRawValue)
-> Term s (PAsData PRawValue) -> Term s PRawValue
forall a b. (a -> b) -> a -> b
$ forall (a :: S -> Type) (s :: S).
(PIsData a, PValidateData a) =>
Term s PData -> Term s (PAsData a)
pparseData @PRawValue Term s PData
opq)
      (Term s r -> Term s PSortedValue -> Term s r
forall a b. a -> b -> a
const Term s r
x)

----------------------------------------------------------------------
-- PLedgerValue

{- | Represents sorted, well-formed Values with a mandatory Ada entry.

Duplicate currency symbols or duplicate token names within the same
token map are not allowed (since wip).

Like 'PSortedValue', but requires the presence of an Ada entry, which may have a
zero quantity. Values of this type may still contain entries with zero token
quantities.

@since 3.5.0
-}
newtype PLedgerValue (s :: S) = PLedgerValue (Term s PSortedValue)
  deriving stock
    ( -- | @since 3.5.0
      (forall x. PLedgerValue s -> Rep (PLedgerValue s) x)
-> (forall x. Rep (PLedgerValue s) x -> PLedgerValue s)
-> Generic (PLedgerValue s)
forall x. Rep (PLedgerValue s) x -> PLedgerValue s
forall x. PLedgerValue s -> Rep (PLedgerValue s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (s :: S) x. Rep (PLedgerValue s) x -> PLedgerValue s
forall (s :: S) x. PLedgerValue s -> Rep (PLedgerValue s) x
$cfrom :: forall (s :: S) x. PLedgerValue s -> Rep (PLedgerValue s) x
from :: forall x. PLedgerValue s -> Rep (PLedgerValue s) x
$cto :: forall (s :: S) x. Rep (PLedgerValue s) x -> PLedgerValue s
to :: forall x. Rep (PLedgerValue s) x -> PLedgerValue s
Generic
    )
  deriving anyclass
    ( -- | @since 3.5.0
      All SListI (Code (PLedgerValue s))
All SListI (Code (PLedgerValue s)) =>
(PLedgerValue s -> Rep (PLedgerValue s))
-> (Rep (PLedgerValue s) -> PLedgerValue s)
-> Generic (PLedgerValue s)
Rep (PLedgerValue s) -> PLedgerValue s
PLedgerValue s -> Rep (PLedgerValue s)
forall a.
All SListI (Code a) =>
(a -> Rep a) -> (Rep a -> a) -> Generic a
forall (s :: S). All SListI (Code (PLedgerValue s))
forall (s :: S). Rep (PLedgerValue s) -> PLedgerValue s
forall (s :: S). PLedgerValue s -> Rep (PLedgerValue s)
$cfrom :: forall (s :: S). PLedgerValue s -> Rep (PLedgerValue s)
from :: PLedgerValue s -> Rep (PLedgerValue s)
$cto :: forall (s :: S). Rep (PLedgerValue s) -> PLedgerValue s
to :: Rep (PLedgerValue s) -> PLedgerValue s
SOP.Generic
    , -- | @since 3.5.0
      (forall (s :: S).
 Term s (PAsData PLedgerValue) -> Term s PLedgerValue)
-> (forall (s :: S). Term s PLedgerValue -> Term s PData)
-> PIsData PLedgerValue
forall (s :: S).
Term s (PAsData PLedgerValue) -> Term s PLedgerValue
forall (s :: S). Term s PLedgerValue -> Term s PData
forall (a :: S -> Type).
(forall (s :: S). Term s (PAsData a) -> Term s a)
-> (forall (s :: S). Term s a -> Term s PData) -> PIsData a
$cpfromDataImpl :: forall (s :: S).
Term s (PAsData PLedgerValue) -> Term s PLedgerValue
pfromDataImpl :: forall (s :: S).
Term s (PAsData PLedgerValue) -> Term s PLedgerValue
$cpdataImpl :: forall (s :: S). Term s PLedgerValue -> Term s PData
pdataImpl :: forall (s :: S). Term s PLedgerValue -> Term s PData
PIsData
    , -- | @since 3.5.0
      (forall (s :: S). Bool -> Term s PLedgerValue -> Term s PString)
-> PShow PLedgerValue
forall (s :: S). Bool -> Term s PLedgerValue -> Term s PString
forall (t :: S -> Type).
(forall (s :: S). Bool -> Term s t -> Term s PString) -> PShow t
$cpshow' :: forall (s :: S). Bool -> Term s PLedgerValue -> Term s PString
pshow' :: forall (s :: S). Bool -> Term s PLedgerValue -> Term s PString
PShow
    )
  deriving
    ( -- | @since 3.5.0
      (forall (s :: S). PLedgerValue s -> Term s (PInner PLedgerValue))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner PLedgerValue)
    -> (PLedgerValue s -> Term s b) -> Term s b)
-> PlutusType PLedgerValue
forall (s :: S). PLedgerValue s -> Term s (PInner PLedgerValue)
forall (s :: S) (b :: S -> Type).
Term s (PInner PLedgerValue)
-> (PLedgerValue s -> Term s b) -> Term s b
forall (a :: S -> Type).
(forall (s :: S). a s -> Term s (PInner a))
-> (forall (s :: S) (b :: S -> Type).
    Term s (PInner a) -> (a s -> Term s b) -> Term s b)
-> PlutusType a
$cpcon' :: forall (s :: S). PLedgerValue s -> Term s (PInner PLedgerValue)
pcon' :: forall (s :: S). PLedgerValue s -> Term s (PInner PLedgerValue)
$cpmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PLedgerValue)
-> (PLedgerValue s -> Term s b) -> Term s b
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner PLedgerValue)
-> (PLedgerValue s -> Term s b) -> Term s b
PlutusType
    )
    via (DeriveNewtypePlutusType PLedgerValue)

-- | @since 3.5.0
instance PEq PLedgerValue where
  Term s PLedgerValue
a #== :: forall (s :: S).
Term s PLedgerValue -> Term s PLedgerValue -> Term s PBool
#== Term s PLedgerValue
b = Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
a Term s PSortedValue -> Term s PSortedValue -> Term s PBool
forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
b

-- | @since 3.5.0
instance Semigroup (Term s PLedgerValue) where
  Term s PLedgerValue
a <> :: Term s PLedgerValue -> Term s PLedgerValue -> Term s PLedgerValue
<> Term s PLedgerValue
b = Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s (PInner PLedgerValue) -> Term s PLedgerValue)
-> Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall a b. (a -> b) -> a -> b
$ Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
a Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
forall a. Semigroup a => a -> a -> a
<> Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
b

-- | @since 3.5.0
instance PlutusTx.Semigroup (Term s PLedgerValue) where
  Term s PLedgerValue
a <> :: Term s PLedgerValue -> Term s PLedgerValue -> Term s PLedgerValue
<> Term s PLedgerValue
b = Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s (PInner PLedgerValue) -> Term s PLedgerValue)
-> Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall a b. (a -> b) -> a -> b
$ Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
a Term s PSortedValue -> Term s PSortedValue -> Term s PSortedValue
forall a. Semigroup a => a -> a -> a
<> Term s PLedgerValue -> Term s (PInner PLedgerValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PLedgerValue
b

-- | @since 3.5.0
instance PSemigroup PLedgerValue where
  {-# INLINEABLE (#<>) #-}
  #<> :: forall (s :: S).
Term s PLedgerValue -> Term s PLedgerValue -> Term s PLedgerValue
(#<>) = Term s PLedgerValue -> Term s PLedgerValue -> Term s PLedgerValue
forall a. Semigroup a => a -> a -> a
(<>)

-- | @since 3.5.0
instance Monoid (Term s PLedgerValue) where
  mempty :: Term s PLedgerValue
mempty = Term s PLedgerValue
forall (s :: S). Term s PLedgerValue
pemptyLedgerValue

-- | @since 3.5.0
instance PlutusTx.Monoid (Term s PLedgerValue) where
  mempty :: Term s PLedgerValue
mempty = Term s PLedgerValue
forall (s :: S). Term s PLedgerValue
pemptyLedgerValue

-- | @since 3.5.0
instance PMonoid PLedgerValue where
  {-# INLINEABLE pmempty #-}
  pmempty :: forall (s :: S). Term s PLedgerValue
pmempty = Term s PLedgerValue
forall a. Monoid a => a
mempty

-- | @since 3.5.0
instance PlutusTx.Group (Term s PLedgerValue) where
  inv :: Term s PLedgerValue -> Term s PLedgerValue
inv = Term s (PInner PLedgerValue) -> Term s PLedgerValue
Term s PSortedValue -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s PSortedValue -> Term s PLedgerValue)
-> (Term s PLedgerValue -> Term s PSortedValue)
-> Term s PLedgerValue
-> Term s PLedgerValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s PSortedValue -> Term s PSortedValue
forall a. Group a => a -> a
PlutusTx.inv (Term s PSortedValue -> Term s PSortedValue)
-> (Term s PLedgerValue -> Term s PSortedValue)
-> Term s PLedgerValue
-> Term s PSortedValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s PLedgerValue -> Term s (PInner PLedgerValue)
Term s PLedgerValue -> Term s PSortedValue
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto

-- | @since 3.5.0
instance PTryFrom PData (PAsData PLedgerValue) where
  ptryFrom' :: forall (s :: S) (r :: S -> Type).
Term s PData
-> ((Term s (PAsData PLedgerValue),
     Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
    -> Term s r)
-> Term s r
ptryFrom' Term s PData
opq = TermCont
  s
  (Term s (PAsData PLedgerValue),
   Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
-> ((Term s (PAsData PLedgerValue),
     Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
    -> Term s r)
-> Term s r
forall (r :: S -> Type) (s :: S) a.
TermCont s a -> (a -> Term s r) -> Term s r
runTermCont (TermCont
   s
   (Term s (PAsData PLedgerValue),
    Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
 -> ((Term s (PAsData PLedgerValue),
      Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
     -> Term s r)
 -> Term s r)
-> TermCont
     s
     (Term s (PAsData PLedgerValue),
      Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
-> ((Term s (PAsData PLedgerValue),
     Reduce (PTryFromExcess PData (PAsData PLedgerValue) s))
    -> Term s r)
-> Term s r
forall a b. (a -> b) -> a -> b
$ do
    (Term s (PAsData PSortedValue)
opq', ()
_) <- (((Term s (PAsData PSortedValue), ()) -> Term s r) -> Term s r)
-> TermCont s (Term s (PAsData PSortedValue), ())
forall a (s :: S) (r :: S -> Type).
((a -> Term s r) -> Term s r) -> TermCont s a
tcont ((((Term s (PAsData PSortedValue), ()) -> Term s r) -> Term s r)
 -> TermCont s (Term s (PAsData PSortedValue), ()))
-> (((Term s (PAsData PSortedValue), ()) -> Term s r) -> Term s r)
-> TermCont s (Term s (PAsData PSortedValue), ())
forall a b. (a -> b) -> a -> b
$ forall (b :: S -> Type) (a :: S -> Type) (s :: S) (r :: S -> Type).
PTryFrom a b =>
Term s a
-> ((Term s b, Reduce (PTryFromExcess a b s)) -> Term s r)
-> Term s r
ptryFrom @(PAsData PSortedValue) Term s PData
opq
    Term s PLedgerValue
unwrapped <- ((Term s PLedgerValue -> Term s r) -> Term s r)
-> TermCont s (Term s PLedgerValue)
forall a (s :: S) (r :: S -> Type).
((a -> Term s r) -> Term s r) -> TermCont s a
tcont (((Term s PLedgerValue -> Term s r) -> Term s r)
 -> TermCont s (Term s PLedgerValue))
-> (Term s (PAsData PSortedValue)
    -> (Term s PLedgerValue -> Term s r) -> Term s r)
-> Term s (PAsData PSortedValue)
-> TermCont s (Term s PLedgerValue)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s PLedgerValue
-> (Term s PLedgerValue -> Term s r) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s a -> (Term s a -> Term s b) -> Term s b
plet (Term s PLedgerValue
 -> (Term s PLedgerValue -> Term s r) -> Term s r)
-> (Term s (PAsData PSortedValue) -> Term s PLedgerValue)
-> Term s (PAsData PSortedValue)
-> (Term s PLedgerValue -> Term s r)
-> Term s r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PSortedValue :--> PLedgerValue)
-> Term s PSortedValue -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
papp Term s (PSortedValue :--> PLedgerValue)
forall (s :: S). Term s (PSortedValue :--> PLedgerValue)
ptoLedgerValue (Term s PSortedValue -> Term s PLedgerValue)
-> (Term s (PAsData PSortedValue) -> Term s PSortedValue)
-> Term s (PAsData PSortedValue)
-> Term s PLedgerValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PAsData PSortedValue) -> Term s PSortedValue
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PSortedValue) -> TermCont s (Term s PLedgerValue))
-> Term s (PAsData PSortedValue)
-> TermCont s (Term s PLedgerValue)
forall a b. (a -> b) -> a -> b
$ Term s (PAsData PSortedValue)
opq'
    (Term s (PAsData PLedgerValue), ())
-> TermCont s (Term s (PAsData PLedgerValue), ())
forall a. a -> TermCont s a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (Term s PLedgerValue -> Term s (PAsData PLedgerValue)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata Term s PLedgerValue
unwrapped, ())

{- | Checks that we have a valid 'PLedgerValue'. The underlying map must be
sorted, contain no empty token maps, and include an ADA entry.

@since 3.6.0
-}
instance PValidateData PLedgerValue where
  pwithValidated :: forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated Term s PData
opq Term s r
x =
    forall (a :: S -> Type) (s :: S).
PValidateData a =>
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated @PSortedValue Term s PData
opq (Term s r -> Term s r) -> Term s r -> Term s r
forall a b. (a -> b) -> a -> b
$
      Term s PBool -> Term s r -> Term s r -> Term s r
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s (PSortedValue :--> PBool)
forall (s :: S). Term s (PSortedValue :--> PBool)
phasAdaEntry Term s (PSortedValue :--> PBool)
-> Term s PSortedValue -> Term s PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term s (PAsData PSortedValue) -> Term s PSortedValue
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PSortedValue) -> Term s PSortedValue)
-> Term s (PAsData PSortedValue) -> Term s PSortedValue
forall a b. (a -> b) -> a -> b
$ forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce @(PAsData PSortedValue) Term s PData
opq)
        Term s r
x
        Term s r
forall (s :: S) (a :: S -> Type). Term s a
perror

----------------------------------------------------------------------
-- Creation

-- PRawValue --

{- | Construct an empty 'PRawValue'.

@since 3.5.0
-}
pemptyRawValue :: forall (s :: S). Term s PRawValue
pemptyRawValue :: forall (s :: S). Term s PRawValue
pemptyRawValue = Term s (PInner PRawValue) -> Term s PRawValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast Term s (PInner PRawValue)
Term
  s (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v) =>
Term s (t k v)
AssocMap.pempty

{- | Construct a singleton 'PRawValue' containing only the given quantity of the
given currency.

@since 3.5.0
-}
psingletonRawValue ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PRawValue)
psingletonRawValue :: forall (s :: S).
Term
  s
  (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue)))
psingletonRawValue = (forall (s :: S).
 Term
   s
   (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue))))
-> Term
     s
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue))))
 -> Term
      s
      (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue))))
-> Term
     s
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue)))
forall a b. (a -> b) -> a -> b
$
  (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PRawValue)
-> Term
     s'
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PRawValue)
-> Term s' (c :--> (PTokenName :--> (PInteger :--> PRawValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PInteger -> Term s' PRawValue)
 -> Term
      s'
      (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PInteger -> Term s' PRawValue)
-> Term
     s'
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PRawValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
symbol Term s' PTokenName
token Term s' PInteger
amount ->
    Term s' (PInner PRawValue) -> Term s' PRawValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PRawValue) -> Term s' PRawValue)
-> Term s' (PInner PRawValue) -> Term s' PRawValue
forall a b. (a -> b) -> a -> b
$
      Term
  s'
  (PCurrencySymbol
   :--> (PUnsortedMap PTokenName PInteger
         :--> PUnsortedMap
                PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v, PIsData k, PIsData v) =>
Term s (k :--> (v :--> t k v))
AssocMap.psingleton Term
  s'
  (PCurrencySymbol
   :--> (PUnsortedMap PTokenName PInteger
         :--> PUnsortedMap
                PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
-> Term s' PCurrencySymbol
-> Term
     s'
     (PUnsortedMap PTokenName PInteger
      :--> PUnsortedMap
             PCurrencySymbol (PUnsortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol
symbol Term
  s'
  (PUnsortedMap PTokenName PInteger
   :--> PUnsortedMap
          PCurrencySymbol (PUnsortedMap PTokenName PInteger))
-> Term s' (PUnsortedMap PTokenName PInteger)
-> Term
     s'
     (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s'
  (PTokenName :--> (PInteger :--> PUnsortedMap PTokenName PInteger))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v, PIsData k, PIsData v) =>
Term s (k :--> (v :--> t k v))
AssocMap.psingleton Term
  s'
  (PTokenName :--> (PInteger :--> PUnsortedMap PTokenName PInteger))
-> Term s' PTokenName
-> Term s' (PInteger :--> PUnsortedMap PTokenName PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName
token Term s' (PInteger :--> PUnsortedMap PTokenName PInteger)
-> Term s' PInteger -> Term s' (PUnsortedMap PTokenName PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
amount

{- | Construct a singleton 'PRawValue' containing only the given quantity of the
given currency, taking data-encoded parameters.

@since 3.5.0
-}
psingletonRawValueData ::
  forall (s :: S).
  Term
    s
    ( PAsData PCurrencySymbol
        :--> PAsData PTokenName
        :--> PAsData PInteger
        :--> PRawValue
    )
psingletonRawValueData :: forall (s :: S).
Term
  s
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
psingletonRawValueData = (forall (s :: S).
 Term
   s
   (PAsData PCurrencySymbol
    :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PAsData PCurrencySymbol
     :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue))))
 -> Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue))))
-> (forall (s :: S).
    Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
forall a b. (a -> b) -> a -> b
$
  (Term s' (PAsData PCurrencySymbol)
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PRawValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PRawValue)
-> Term
     s'
     (c
      :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
plam ((Term s' (PAsData PCurrencySymbol)
  -> Term s' (PAsData PTokenName)
  -> Term s' (PAsData PInteger)
  -> Term s' PRawValue)
 -> Term
      s'
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue))))
-> (Term s' (PAsData PCurrencySymbol)
    -> Term s' (PAsData PTokenName)
    -> Term s' (PAsData PInteger)
    -> Term s' PRawValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName :--> (PAsData PInteger :--> PRawValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' (PAsData PCurrencySymbol)
symbol Term s' (PAsData PTokenName)
token Term s' (PAsData PInteger)
amount ->
    Term s' PBool
-> Term s' PRawValue -> Term s' PRawValue -> Term s' PRawValue
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
      (Term s' (PAsData PInteger)
amount Term s' (PAsData PInteger)
-> Term s' (PAsData PInteger) -> Term s' PBool
forall (s :: S).
Term s (PAsData PInteger)
-> Term s (PAsData PInteger) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' (PAsData PInteger)
forall (s :: S). Term s (PAsData PInteger)
zeroData)
      Term s' PRawValue
forall (s :: S). Term s PRawValue
pemptyRawValue
      ( Term s' (PInner PRawValue) -> Term s' PRawValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PRawValue) -> Term s' PRawValue)
-> Term s' (PInner PRawValue) -> Term s' PRawValue
forall a b. (a -> b) -> a -> b
$
          Term
  s'
  (PAsData PCurrencySymbol
   :--> (PAsData (PUnsortedMap PTokenName PInteger)
         :--> PUnsortedMap
                PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v) =>
Term s (PAsData k :--> (PAsData v :--> t k v))
AssocMap.psingletonData
            # symbol
            # pdata (AssocMap.psingletonData # token # amount)
      )

-- PSortedValue --

{- | Construct an empty 'PSortedValue'.

@since 3.5.0
-}
pemptySortedValue :: forall (s :: S). Term s PSortedValue
pemptySortedValue :: forall (s :: S). Term s PSortedValue
pemptySortedValue = Term s (PInner PSortedValue) -> Term s PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast Term s (PInner PSortedValue)
Term
  s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v) =>
Term s (t k v)
AssocMap.pempty

{- | Construct a singleton 'PSortedValue' containing only the given quantity of
the given currency.

@since 3.5.0
-}
psingletonSortedValue ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PSortedValue)
psingletonSortedValue :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
psingletonSortedValue =
  (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PInteger :--> PSortedValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName :--> (PInteger :--> PSortedValue))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PSortedValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PSortedValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PSortedValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PSortedValue)
-> Term s' (c :--> (PTokenName :--> (PInteger :--> PSortedValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PInteger -> Term s' PSortedValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PSortedValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PInteger -> Term s' PSortedValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
symbol Term s' PTokenName
token Term s' PInteger
amount ->
      Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
        Term
  s'
  (PCurrencySymbol
   :--> (PSortedMap PTokenName PInteger
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v, PIsData k, PIsData v) =>
Term s (k :--> (v :--> t k v))
AssocMap.psingleton Term
  s'
  (PCurrencySymbol
   :--> (PSortedMap PTokenName PInteger
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term s' PCurrencySymbol
-> Term
     s'
     (PSortedMap PTokenName PInteger
      :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol
symbol Term
  s'
  (PSortedMap PTokenName PInteger
   :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term s' (PSortedMap PTokenName PInteger)
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s' (PTokenName :--> (PInteger :--> PSortedMap PTokenName PInteger))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v, PIsData k, PIsData v) =>
Term s (k :--> (v :--> t k v))
AssocMap.psingleton Term
  s' (PTokenName :--> (PInteger :--> PSortedMap PTokenName PInteger))
-> Term s' PTokenName
-> Term s' (PInteger :--> PSortedMap PTokenName PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName
token Term s' (PInteger :--> PSortedMap PTokenName PInteger)
-> Term s' PInteger -> Term s' (PSortedMap PTokenName PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
amount

{- | Like 'psingletonSortedValue', but accepts data-encoded arguments.

@since 3.5.0
-}
psingletonSortedValueData ::
  forall (s :: S).
  Term
    s
    ( PAsData PCurrencySymbol
        :--> PAsData PTokenName
        :--> PAsData PInteger
        :--> PSortedValue
    )
psingletonSortedValueData :: forall (s :: S).
Term
  s
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName
         :--> (PAsData PInteger :--> PSortedValue)))
psingletonSortedValueData =
  (forall (s :: S).
 Term
   s
   (PAsData PCurrencySymbol
    :--> (PAsData PTokenName
          :--> (PAsData PInteger :--> PSortedValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PSortedValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PAsData PCurrencySymbol
     :--> (PAsData PTokenName
           :--> (PAsData PInteger :--> PSortedValue))))
 -> Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PSortedValue))))
-> (forall (s :: S).
    Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PSortedValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' (PAsData PCurrencySymbol)
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PSortedValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PSortedValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PSortedValue)
-> Term
     s'
     (c
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PSortedValue)))
plam ((Term s' (PAsData PCurrencySymbol)
  -> Term s' (PAsData PTokenName)
  -> Term s' (PAsData PInteger)
  -> Term s' PSortedValue)
 -> Term
      s'
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PSortedValue))))
-> (Term s' (PAsData PCurrencySymbol)
    -> Term s' (PAsData PTokenName)
    -> Term s' (PAsData PInteger)
    -> Term s' PSortedValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' (PAsData PCurrencySymbol)
symbol Term s' (PAsData PTokenName)
token Term s' (PAsData PInteger)
amount ->
      Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
        Term
  s'
  (PAsData PCurrencySymbol
   :--> (PAsData (PSortedMap PTokenName PInteger)
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (v :: S -> Type) (s :: S).
(PInner (t k v) ~ PAssocMap k v) =>
Term s (PAsData k :--> (PAsData v :--> t k v))
AssocMap.psingletonData
          # symbol
          # pdata (AssocMap.psingletonData # token # amount)

-- PLedgerValue --

{- | Construct an empty 'PLedgerValue' with a mandatory zero Ada entry.

@since 3.5.0
-}
pemptyLedgerValue :: forall (s :: S). Term s PLedgerValue
pemptyLedgerValue :: forall (s :: S). Term s PLedgerValue
pemptyLedgerValue =
  Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s (PInner PLedgerValue) -> Term s PLedgerValue)
-> Term s (PInner PLedgerValue) -> Term s PLedgerValue
forall a b. (a -> b) -> a -> b
$
    Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
psingletonSortedValue Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
-> Term s PCurrencySymbol
-> Term s (PTokenName :--> (PInteger :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PCurrencySymbol
forall (s :: S). Term s PCurrencySymbol
padaSymbol Term s (PTokenName :--> (PInteger :--> PSortedValue))
-> Term s PTokenName -> Term s (PInteger :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PTokenName
forall (s :: S). Term s PTokenName
padaToken Term s (PInteger :--> PSortedValue)
-> Term s PInteger -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PInteger
0

{- | Construct a singleton 'PLedgerValue' containing the given quantity of the
given currency, together with a mandatory Ada entry (which may be zero).

@since 3.5.0
-}
psingletonLedgerValue ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PLedgerValue)
psingletonLedgerValue :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
psingletonLedgerValue =
  (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PInteger :--> PLedgerValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName :--> (PInteger :--> PLedgerValue))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PLedgerValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PLedgerValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PLedgerValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PLedgerValue)
-> Term s' (c :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PInteger -> Term s' PLedgerValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PLedgerValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PInteger -> Term s' PLedgerValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PLedgerValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
symbol Term s' PTokenName
token Term s' PInteger
amount ->
      Term s' (PSortedValue :--> PLedgerValue)
forall (s :: S). Term s (PSortedValue :--> PLedgerValue)
ptoLedgerValue Term s' (PSortedValue :--> PLedgerValue)
-> Term s' PSortedValue -> Term s' PLedgerValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s'
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
psingletonSortedValue Term
  s'
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
-> Term s' PCurrencySymbol
-> Term s' (PTokenName :--> (PInteger :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol
symbol Term s' (PTokenName :--> (PInteger :--> PSortedValue))
-> Term s' PTokenName -> Term s' (PInteger :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName
token Term s' (PInteger :--> PSortedValue)
-> Term s' PInteger -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
amount

{- | Like 'psingletonLedgerValue', but accepts data-encoded arguments.

@since 3.5.0
-}
psingletonLedgerValueData ::
  forall (s :: S).
  Term
    s
    ( PAsData PCurrencySymbol
        :--> PAsData PTokenName
        :--> PAsData PInteger
        :--> PLedgerValue
    )
psingletonLedgerValueData :: forall (s :: S).
Term
  s
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName
         :--> (PAsData PInteger :--> PLedgerValue)))
psingletonLedgerValueData =
  (forall (s :: S).
 Term
   s
   (PAsData PCurrencySymbol
    :--> (PAsData PTokenName
          :--> (PAsData PInteger :--> PLedgerValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PLedgerValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PAsData PCurrencySymbol
     :--> (PAsData PTokenName
           :--> (PAsData PInteger :--> PLedgerValue))))
 -> Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PLedgerValue))))
-> (forall (s :: S).
    Term
      s
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PLedgerValue))))
-> Term
     s
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PLedgerValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' (PAsData PCurrencySymbol)
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PLedgerValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PLedgerValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' (PAsData PTokenName)
 -> Term s' (PAsData PInteger)
 -> Term s' PLedgerValue)
-> Term
     s'
     (c
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PLedgerValue)))
plam ((Term s' (PAsData PCurrencySymbol)
  -> Term s' (PAsData PTokenName)
  -> Term s' (PAsData PInteger)
  -> Term s' PLedgerValue)
 -> Term
      s'
      (PAsData PCurrencySymbol
       :--> (PAsData PTokenName
             :--> (PAsData PInteger :--> PLedgerValue))))
-> (Term s' (PAsData PCurrencySymbol)
    -> Term s' (PAsData PTokenName)
    -> Term s' (PAsData PInteger)
    -> Term s' PLedgerValue)
-> Term
     s'
     (PAsData PCurrencySymbol
      :--> (PAsData PTokenName
            :--> (PAsData PInteger :--> PLedgerValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' (PAsData PCurrencySymbol)
symbol Term s' (PAsData PTokenName)
token Term s' (PAsData PInteger)
amount ->
      Term s' (PSortedValue :--> PLedgerValue)
forall (s :: S). Term s (PSortedValue :--> PLedgerValue)
ptoLedgerValue Term s' (PSortedValue :--> PLedgerValue)
-> Term s' PSortedValue -> Term s' PLedgerValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s'
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName
         :--> (PAsData PInteger :--> PSortedValue)))
forall (s :: S).
Term
  s
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName
         :--> (PAsData PInteger :--> PSortedValue)))
psingletonSortedValueData Term
  s'
  (PAsData PCurrencySymbol
   :--> (PAsData PTokenName
         :--> (PAsData PInteger :--> PSortedValue)))
-> Term s' (PAsData PCurrencySymbol)
-> Term
     s' (PAsData PTokenName :--> (PAsData PInteger :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PAsData PCurrencySymbol)
symbol Term
  s' (PAsData PTokenName :--> (PAsData PInteger :--> PSortedValue))
-> Term s' (PAsData PTokenName)
-> Term s' (PAsData PInteger :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PAsData PTokenName)
token Term s' (PAsData PInteger :--> PSortedValue)
-> Term s' (PAsData PInteger) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PAsData PInteger)
amount

-----------------------------------------------------------------------
-- Transformation

{- | Attempt to promote a 'PRawValue' to 'PSortedValue'.

The conversion succeeds only if the input Value is already sorted and does not
contain empty token maps. Otherwise, the function fails with an error.

@since 2.1.1
-}
{-# DEPRECATED passertSorted "Use ppromoteToSortedValue instead" #-}
passertSorted :: forall (s :: S). Term s (PRawValue :--> PSortedValue)
passertSorted :: forall (s :: S). Term s (PRawValue :--> PSortedValue)
passertSorted = (forall (s :: S). Term s (PRawValue :--> PSortedValue))
-> Term s (PRawValue :--> PSortedValue)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PRawValue :--> PSortedValue))
 -> Term s (PRawValue :--> PSortedValue))
-> (forall (s :: S). Term s (PRawValue :--> PSortedValue))
-> Term s (PRawValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$
  (Term s' PRawValue -> Term s' PSortedValue)
-> Term s' (PRawValue :--> PSortedValue)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PSortedValue)
-> Term s' (c :--> PSortedValue)
plam ((Term s' PRawValue -> Term s' PSortedValue)
 -> Term s' (PRawValue :--> PSortedValue))
-> (Term s' PRawValue -> Term s' PSortedValue)
-> Term s' (PRawValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$ \Term s' PRawValue
value ->
    Term s' PBool
-> Term s' PSortedValue
-> Term s' PSortedValue
-> Term s' PSortedValue
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
      ( Term
  s'
  ((PUnsortedMap PTokenName PInteger :--> PBool)
   :--> (PUnsortedMap
           PCurrencySymbol (PUnsortedMap PTokenName PInteger)
         :--> PBool))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
PIsData v =>
Term s ((v :--> PBool) :--> (PUnsortedMap k v :--> PBool))
AssocMap.pany
          # plam
            ( \submap ->
                AssocMap.pnull
                  # AssocMap.pforgetSorted (AssocMap.ppromoteToSortedMap # submap)
            )
          # pto value
      )
      (Term s' PString -> Term s' PSortedValue
forall (a :: S -> Type) (s :: S). Term s PString -> Term s a
ptraceInfoError Term s' PString
"Abnormal Value")
      ( Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast
          -- punsafeCoerce since we know that the token maps are sorted at this point
          (Term
  s'
  (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k) =>
Term s (PUnsortedMap k v :--> PSortedMap k v)
AssocMap.ppromoteToSortedMap Term
  s'
  (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term
  s'
  (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
-> Term
     s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term
   s'
   (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
 -> Term
      s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
-> Term
     s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall a b. (a -> b) -> a -> b
$ Term s' PRawValue -> Term s' (PInner PRawValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PRawValue
value)
      )

{- | Attempt to promote a 'PRawValue' to 'PSortedValue'.

The conversion succeeds only if the input Value is already sorted and does not
contain empty token maps. Otherwise, the function fails with an error.

@since 3.6.0
-}
ppromoteToSortedValue :: forall (s :: S). Term s (PRawValue :--> PSortedValue)
ppromoteToSortedValue :: forall (s :: S). Term s (PRawValue :--> PSortedValue)
ppromoteToSortedValue = Term s (PRawValue :--> PSortedValue)
forall (s :: S). Term s (PRawValue :--> PSortedValue)
passertSorted

{- | Safely demote a 'PSortedValue' to a 'PRawValue'.

@since 3.5.0
-}
pforgetSorted :: forall (s :: S). Term s PSortedValue -> Term s PRawValue
pforgetSorted :: forall (s :: S). Term s PSortedValue -> Term s PRawValue
pforgetSorted = Term s PSortedValue -> Term s PRawValue
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce

{- | Convert a 'PSortedValue' to a 'PLedgerValue', inserting the mandatory Ada
entry if missing.

@since 3.5.0
-}
ptoLedgerValue :: forall (s :: S). Term s (PSortedValue :--> PLedgerValue)
ptoLedgerValue :: forall (s :: S). Term s (PSortedValue :--> PLedgerValue)
ptoLedgerValue = (Term s PSortedValue -> Term s PLedgerValue)
-> Term s (PSortedValue :--> PLedgerValue)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PLedgerValue) -> Term s (c :--> PLedgerValue)
plam (Term s (PInner PLedgerValue) -> Term s PLedgerValue
Term s PSortedValue -> Term s PLedgerValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s PSortedValue -> Term s PLedgerValue)
-> (Term s PSortedValue -> Term s PSortedValue)
-> Term s PSortedValue
-> Term s PLedgerValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PSortedValue :--> PSortedValue)
-> Term s PSortedValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
papp Term s (PSortedValue :--> PSortedValue)
forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pinsertAdaEntry)

----------------------------------------------------------------------
-- Partial ordering

{- | Mimics the @lt@ operation on @plutus-ledger-api@'s @Value@.

@since 3.5.0
-}
plt :: forall (s :: S). Term s PSortedValue -> Term s PSortedValue -> Term s PBool
plt :: forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
plt Term s PSortedValue
t1 Term s PSortedValue
t2 = Term s PSortedValue -> Term s PSortedValue -> Term s PBool
forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
pleq Term s PSortedValue
t1 Term s PSortedValue
t2 Term s PBool -> Term s PBool -> Term s PBool
forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
#&& (Term s (PBool :--> PBool)
forall (s :: S). Term s (PBool :--> PBool)
pnot Term s (PBool :--> PBool) -> Term s PBool -> Term s PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s PSortedValue
t1 Term s PSortedValue -> Term s PSortedValue -> Term s PBool
forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s PSortedValue
t2))

{- | Mimics the @leq@ operation on @plutus-ledger-api@'s @Value@.

@since 3.5.0
-}
pleq :: forall (s :: S). Term s PSortedValue -> Term s PSortedValue -> Term s PBool
pleq :: forall (s :: S).
Term s PSortedValue -> Term s PSortedValue -> Term s PBool
pleq Term s PSortedValue
t1 Term s PSortedValue
t2 =
  (forall (s' :: S).
 Term s' (PSortedValue :--> (PSortedValue :--> PBool)))
-> Term s (PSortedValue :--> (PSortedValue :--> PBool))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic (Term
  s'
  ((PInteger :--> (PInteger :--> PBool))
   :--> (PSortedValue :--> (PSortedValue :--> PBool)))
forall (s :: S).
Term
  s
  ((PInteger :--> (PInteger :--> PBool))
   :--> (PSortedValue :--> (PSortedValue :--> PBool)))
pcheckBinRel Term
  s'
  ((PInteger :--> (PInteger :--> PBool))
   :--> (PSortedValue :--> (PSortedValue :--> PBool)))
-> Term s' (PInteger :--> (PInteger :--> PBool))
-> Term s' (PSortedValue :--> (PSortedValue :--> PBool))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ (forall (s' :: S). Term s' (PInteger :--> (PInteger :--> PBool)))
-> Term s' (PInteger :--> (PInteger :--> PBool))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s' :: S). Term s' (PInteger :--> (PInteger :--> PBool)))
 -> Term s' (PInteger :--> (PInteger :--> PBool)))
-> (forall (s' :: S).
    Term s' (PInteger :--> (PInteger :--> PBool)))
-> Term s' (PInteger :--> (PInteger :--> PBool))
forall a b. (a -> b) -> a -> b
$ (Term s' PInteger -> Term s' PInteger -> Term s' PBool)
-> Term s' (PInteger :--> (PInteger :--> PBool))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PInteger -> Term s' PBool)
-> Term s' (c :--> (PInteger :--> PBool))
plam Term s' PInteger -> Term s' PInteger -> Term s' PBool
forall (s :: S). Term s PInteger -> Term s PInteger -> Term s PBool
forall (t :: S -> Type) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
(#<=)) Term s (PSortedValue :--> (PSortedValue :--> PBool))
-> Term s PSortedValue -> Term s (PSortedValue :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
t1 Term s (PSortedValue :--> PBool)
-> Term s PSortedValue -> Term s PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
t2

{- | Given a description of a relation on amounts, check whether that relation
holds over 'PSortedValue's.

= Important note

This is intended for use with boolean comparison functions, which must define
at least a partial order (total orders and equivalences are acceptable as
well). Use of this with anything else is not guaranteed to give anything
resembling a sensible answer. Use with extreme care.

@since 2.0.0
-}
pcheckBinRel ::
  forall (s :: S).
  Term
    s
    ( (PInteger :--> PInteger :--> PBool)
        :--> PSortedValue
        :--> PSortedValue
        :--> PBool
    )
pcheckBinRel :: forall (s :: S).
Term
  s
  ((PInteger :--> (PInteger :--> PBool))
   :--> (PSortedValue :--> (PSortedValue :--> PBool)))
pcheckBinRel = (forall (s :: S).
 Term
   s
   ((PInteger :--> (PInteger :--> PBool))
    :--> (PSortedValue :--> (PSortedValue :--> PBool))))
-> Term
     s
     ((PInteger :--> (PInteger :--> PBool))
      :--> (PSortedValue :--> (PSortedValue :--> PBool)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    ((PInteger :--> (PInteger :--> PBool))
     :--> (PSortedValue :--> (PSortedValue :--> PBool))))
 -> Term
      s
      ((PInteger :--> (PInteger :--> PBool))
       :--> (PSortedValue :--> (PSortedValue :--> PBool))))
-> (forall (s :: S).
    Term
      s
      ((PInteger :--> (PInteger :--> PBool))
       :--> (PSortedValue :--> (PSortedValue :--> PBool))))
-> Term
     s
     ((PInteger :--> (PInteger :--> PBool))
      :--> (PSortedValue :--> (PSortedValue :--> PBool)))
forall a b. (a -> b) -> a -> b
$
  (Term s' (PInteger :--> (PInteger :--> PBool))
 -> Term s' PSortedValue -> Term s' PSortedValue -> Term s' PBool)
-> Term
     s'
     ((PInteger :--> (PInteger :--> PBool))
      :--> (PSortedValue :--> (PSortedValue :--> PBool)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PSortedValue -> Term s' PSortedValue -> Term s' PBool)
-> Term s' (c :--> (PSortedValue :--> (PSortedValue :--> PBool)))
plam ((Term s' (PInteger :--> (PInteger :--> PBool))
  -> Term s' PSortedValue -> Term s' PSortedValue -> Term s' PBool)
 -> Term
      s'
      ((PInteger :--> (PInteger :--> PBool))
       :--> (PSortedValue :--> (PSortedValue :--> PBool))))
-> (Term s' (PInteger :--> (PInteger :--> PBool))
    -> Term s' PSortedValue -> Term s' PSortedValue -> Term s' PBool)
-> Term
     s'
     ((PInteger :--> (PInteger :--> PBool))
      :--> (PSortedValue :--> (PSortedValue :--> PBool)))
forall a b. (a -> b) -> a -> b
$ \Term s' (PInteger :--> (PInteger :--> PBool))
f Term s' PSortedValue
val0 Term s' PSortedValue
val1 ->
    forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k, PIsData v) =>
Term
  s
  ((v :--> (v :--> PBool))
   :--> (v :--> (PSortedMap k v :--> (PSortedMap k v :--> PBool))))
AssocMap.pcheckBinRel @PCurrencySymbol
      # (AssocMap.pcheckBinRel @PTokenName # f # 0)
      # AssocMap.pempty
      # pto val0
      # pto val1

----------------------------------------------------------------------
-- Combination

{- | Combine two 'PSortedValue's, taking the tokens from the left only, if a
currency occurs on both sides.

@since 2.1.1
-}
pleftBiasedCurrencyUnion :: forall (s :: S). Term s (PSortedValue :--> PSortedValue :--> PSortedValue)
pleftBiasedCurrencyUnion :: forall (s :: S).
Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
pleftBiasedCurrencyUnion =
  (forall (s :: S).
 Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
 -> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> (forall (s :: S).
    Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a b. (a -> b) -> a -> b
$
    (Term s' PSortedValue
 -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (c :--> (PSortedValue :--> PSortedValue))
plam ((Term s' PSortedValue
  -> Term s' PSortedValue -> Term s' PSortedValue)
 -> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> (Term s' PSortedValue
    -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
x Term s' PSortedValue
y ->
      Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
        Term
  s'
  (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k, PIsData v) =>
Term s (PSortedMap k v :--> (PSortedMap k v :--> PSortedMap k v))
AssocMap.pleftBiasedUnion Term
  s'
  (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
      :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
x Term
  s'
  (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
y

{- | Combine two 'PSortedValue's, taking the tokens from the left only, if a
token name of the same currency occurs on both sides.

@since 2.1.1
-}
pleftBiasedTokenUnion :: forall (s :: S). Term s (PSortedValue :--> PSortedValue :--> PSortedValue)
pleftBiasedTokenUnion :: forall (s :: S).
Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
pleftBiasedTokenUnion = (forall (s :: S).
 Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
 -> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> (forall (s :: S).
    Term s (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> Term s (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a b. (a -> b) -> a -> b
$
  (Term s' PSortedValue
 -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (c :--> (PSortedValue :--> PSortedValue))
plam ((Term s' PSortedValue
  -> Term s' PSortedValue -> Term s' PSortedValue)
 -> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue)))
-> (Term s' PSortedValue
    -> Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> (PSortedValue :--> PSortedValue))
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
x Term s' PSortedValue
y ->
    Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
      Term
  s'
  ((PSortedMap PTokenName PInteger
    :--> (PSortedMap PTokenName PInteger
          :--> PSortedMap PTokenName PInteger))
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
               :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k, PIsData v) =>
Term
  s
  ((v :--> (v :--> v))
   :--> (PSortedMap k v :--> (PSortedMap k v :--> PSortedMap k v)))
AssocMap.punionWith
        # plam (\x' y' -> AssocMap.pleftBiasedUnion # x' # y')
        # pto x
        # pto y

{- | Combine two 'PSortedValue's applying the given function to any pair of
quantities with the same asset class.

@since 3.5.0
-}
punionWith ::
  forall (s :: S).
  Term
    s
    ( (PInteger :--> PInteger :--> PInteger)
        :--> PSortedValue
        :--> PSortedValue
        :--> PSortedValue
    )
punionWith :: forall (s :: S).
Term
  s
  ((PInteger :--> (PInteger :--> PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
punionWith =
  (forall (s :: S).
 Term
   s
   ((PInteger :--> (PInteger :--> PInteger))
    :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> Term
     s
     ((PInteger :--> (PInteger :--> PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    ((PInteger :--> (PInteger :--> PInteger))
     :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
 -> Term
      s
      ((PInteger :--> (PInteger :--> PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> (forall (s :: S).
    Term
      s
      ((PInteger :--> (PInteger :--> PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> Term
     s
     ((PInteger :--> (PInteger :--> PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' (PInteger :--> (PInteger :--> PInteger))
 -> Term s' PSortedValue
 -> Term s' PSortedValue
 -> Term s' PSortedValue)
-> Term
     s'
     ((PInteger :--> (PInteger :--> PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PSortedValue
 -> Term s' PSortedValue
 -> Term s' PSortedValue)
-> Term
     s' (c :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
plam ((Term s' (PInteger :--> (PInteger :--> PInteger))
  -> Term s' PSortedValue
  -> Term s' PSortedValue
  -> Term s' PSortedValue)
 -> Term
      s'
      ((PInteger :--> (PInteger :--> PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> (Term s' (PInteger :--> (PInteger :--> PInteger))
    -> Term s' PSortedValue
    -> Term s' PSortedValue
    -> Term s' PSortedValue)
-> Term
     s'
     ((PInteger :--> (PInteger :--> PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' (PInteger :--> (PInteger :--> PInteger))
combine Term s' PSortedValue
x Term s' PSortedValue
y ->
      Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
        Term
  s'
  ((PSortedMap PTokenName PInteger
    :--> (PSortedMap PTokenName PInteger
          :--> PSortedMap PTokenName PInteger))
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
               :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k, PIsData v) =>
Term
  s
  ((v :--> (v :--> v))
   :--> (PSortedMap k v :--> (PSortedMap k v :--> PSortedMap k v)))
AssocMap.punionWith
          # plam (\x' y' -> AssocMap.punionWith # combine # x' # y')
          # pto x
          # pto y

{- | Combine two 'PSortedValue's applying the given function to any pair of
data-encoded quantities with the same asset class.

@since 3.5.0
-}
punionWithData ::
  forall (s :: S).
  Term
    s
    ( (PAsData PInteger :--> PAsData PInteger :--> PAsData PInteger)
        :--> PSortedValue
        :--> PSortedValue
        :--> PSortedValue
    )
punionWithData :: forall (s :: S).
Term
  s
  ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
   :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
punionWithData = (forall (s :: S).
 Term
   s
   ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
    :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> Term
     s
     ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
     :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
 -> Term
      s
      ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> (forall (s :: S).
    Term
      s
      ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> Term
     s
     ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$
  (Term
   s' (PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
 -> Term s' PSortedValue
 -> Term s' PSortedValue
 -> Term s' PSortedValue)
-> Term
     s'
     ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PSortedValue
 -> Term s' PSortedValue
 -> Term s' PSortedValue)
-> Term
     s' (c :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
plam ((Term
    s' (PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
  -> Term s' PSortedValue
  -> Term s' PSortedValue
  -> Term s' PSortedValue)
 -> Term
      s'
      ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
       :--> (PSortedValue :--> (PSortedValue :--> PSortedValue))))
-> (Term
      s' (PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
    -> Term s' PSortedValue
    -> Term s' PSortedValue
    -> Term s' PSortedValue)
-> Term
     s'
     ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
      :--> (PSortedValue :--> (PSortedValue :--> PSortedValue)))
forall a b. (a -> b) -> a -> b
$ \Term
  s' (PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger))
combine Term s' PSortedValue
x Term s' PSortedValue
y ->
    Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
      Term
  s'
  ((PSortedMap PTokenName PInteger
    :--> (PSortedMap PTokenName PInteger
          :--> PSortedMap PTokenName PInteger))
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
               :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
(POrd k, PIsData k, PIsData v) =>
Term
  s
  ((v :--> (v :--> v))
   :--> (PSortedMap k v :--> (PSortedMap k v :--> PSortedMap k v)))
AssocMap.punionWith
        # plam (\x' y' -> AssocMap.punionWithData # combine # x' # y')
        # pto x
        # pto y

----------------------------------------------------------------------
-- Queries

{- | Get the quantity of the given currency in the 'PSortedValue'.

@since 3.6.0
-}
pvalueOf :: forall (s :: S). Term s (PSortedValue :--> PCurrencySymbol :--> PTokenName :--> PInteger)
pvalueOf :: forall (s :: S).
Term
  s
  (PSortedValue
   :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
pvalueOf = (forall (s :: S).
 Term
   s
   (PSortedValue
    :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))))
-> Term
     s
     (PSortedValue
      :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PSortedValue
     :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))))
 -> Term
      s
      (PSortedValue
       :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))))
-> (forall (s :: S).
    Term
      s
      (PSortedValue
       :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))))
-> Term
     s
     (PSortedValue
      :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
forall a b. (a -> b) -> a -> b
$
  (Term s' PSortedValue
 -> Term s' PCurrencySymbol
 -> Term s' PTokenName
 -> Term s' PInteger)
-> Term
     s'
     (PSortedValue
      :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' PCurrencySymbol
 -> Term s' PTokenName
 -> Term s' PInteger)
-> Term
     s' (c :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
plam ((Term s' PSortedValue
  -> Term s' PCurrencySymbol
  -> Term s' PTokenName
  -> Term s' PInteger)
 -> Term
      s'
      (PSortedValue
       :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))))
-> (Term s' PSortedValue
    -> Term s' PCurrencySymbol
    -> Term s' PTokenName
    -> Term s' PInteger)
-> Term
     s'
     (PSortedValue
      :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value Term s' PCurrencySymbol
symbol Term s' PTokenName
token ->
    Term
  s'
  (PCurrencySymbol
   :--> (PInteger
         :--> ((PAsData (PSortedMap PTokenName PInteger) :--> PInteger)
               :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
                     :--> PInteger))))
forall (k :: S -> Type) (v :: S -> Type) (r :: S -> Type) (s :: S).
PIsData k =>
Term
  s
  (k :--> (r :--> ((PAsData v :--> r) :--> (PSortedMap k v :--> r))))
AssocMap.pfoldAt
      # symbol
      # 0
      # plam (\m -> AssocMap.pfoldAt # token # 0 # plam pfromData # pfromData m)
      # pto value

{- | Get the amount of Lovelace in the 'PSortedValue'.

@since 2.1.1
-}
plovelaceValueOf :: forall (s :: S). Term s (PSortedValue :--> PInteger)
plovelaceValueOf :: forall (s :: S). Term s (PSortedValue :--> PInteger)
plovelaceValueOf = (forall (s :: S). Term s (PSortedValue :--> PInteger))
-> Term s (PSortedValue :--> PInteger)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PSortedValue :--> PInteger))
 -> Term s (PSortedValue :--> PInteger))
-> (forall (s :: S). Term s (PSortedValue :--> PInteger))
-> Term s (PSortedValue :--> PInteger)
forall a b. (a -> b) -> a -> b
$
  (Term s' PSortedValue -> Term s' PInteger)
-> Term s' (PSortedValue :--> PInteger)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PInteger) -> Term s' (c :--> PInteger)
plam ((Term s' PSortedValue -> Term s' PInteger)
 -> Term s' (PSortedValue :--> PInteger))
-> (Term s' PSortedValue -> Term s' PInteger)
-> Term s' (PSortedValue :--> PInteger)
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value ->
    Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PInteger)
-> Term s' PInteger
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term
  s'
  (PInner
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s'
   (PInner
      (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
 -> Term
      s'
      (PInner
         (PInner
            (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall a b. (a -> b) -> a -> b
$ Term
  s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term
      s'
      (PInner
         (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall a b. (a -> b) -> a -> b
$ Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
value) ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PSortedMap PTokenName PInteger)))
    s'
  -> Term s' PInteger)
 -> Term s' PInteger)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PInteger)
-> Term s' PInteger
forall a b. (a -> b) -> a -> b
$ \case
      PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
  s'
PNil -> Term s' PInteger
0
      PCons Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
_ -> Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s'
    -> Term s' PInteger)
-> Term s' PInteger
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x ((PBuiltinPair
    (PAsData PCurrencySymbol)
    (PAsData (PSortedMap PTokenName PInteger))
    s'
  -> Term s' PInteger)
 -> Term s' PInteger)
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s'
    -> Term s' PInteger)
-> Term s' PInteger
forall a b. (a -> b) -> a -> b
$ \(PBuiltinPair Term s' (PAsData PCurrencySymbol)
xFst Term s' (PAsData (PSortedMap PTokenName PInteger))
xSnd) ->
        Term s' PBool
-> Term s' PInteger -> Term s' PInteger -> Term s' PInteger
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
          (Term s' (PAsData PCurrencySymbol)
xFst Term s' (PAsData PCurrencySymbol)
-> Term s' (PAsData PCurrencySymbol) -> Term s' PBool
forall (s :: S).
Term s (PAsData PCurrencySymbol)
-> Term s (PAsData PCurrencySymbol) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' (PAsData PCurrencySymbol)
forall (s :: S). Term s (PAsData PCurrencySymbol)
padaSymbolData)
          ( Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
    -> Term s' PInteger)
-> Term s' PInteger
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
   :--> PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
forall (a :: S -> Type) (s :: S).
PElemConstraint PBuiltinList a =>
Term s (PBuiltinList a :--> a)
forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (s :: S).
(PListLike list, PElemConstraint list a) =>
Term s (list a :--> a)
phead Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
   :--> PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
-> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term s' (PAssocMap PTokenName PInteger)
-> Term s' (PInner (PAssocMap PTokenName PInteger))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term s' (PAssocMap PTokenName PInteger)
 -> Term s' (PInner (PAssocMap PTokenName PInteger)))
-> Term s' (PAssocMap PTokenName PInteger)
-> Term s' (PInner (PAssocMap PTokenName PInteger))
forall a b. (a -> b) -> a -> b
$ Term s' (PSortedMap PTokenName PInteger)
-> Term s' (PInner (PSortedMap PTokenName PInteger))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term s' (PSortedMap PTokenName PInteger)
 -> Term s' (PInner (PSortedMap PTokenName PInteger)))
-> Term s' (PSortedMap PTokenName PInteger)
-> Term s' (PInner (PSortedMap PTokenName PInteger))
forall a b. (a -> b) -> a -> b
$ Term s' (PAsData (PSortedMap PTokenName PInteger))
-> Term s' (PSortedMap PTokenName PInteger)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData (PSortedMap PTokenName PInteger))
xSnd) ((PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
  -> Term s' PInteger)
 -> Term s' PInteger)
-> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
    -> Term s' PInteger)
-> Term s' PInteger
forall a b. (a -> b) -> a -> b
$ \(PBuiltinPair Term s' (PAsData PTokenName)
_ Term s' (PAsData PInteger)
quantity) ->
              Term s' (PAsData PInteger) -> Term s' PInteger
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData PInteger)
quantity
          )
          Term s' PInteger
0

{- | Test if the 'PSortedValue' contains nothing except an Ada entry.

= Note

This function does not verify that Ada is positive and may return 'PTrue'
for zero or negative Ada amounts.

@since 2.1.1
-}
pisAdaOnlyValue :: forall (s :: S). Term s (PSortedValue :--> PBool)
pisAdaOnlyValue :: forall (s :: S). Term s (PSortedValue :--> PBool)
pisAdaOnlyValue = (forall (s :: S). Term s (PSortedValue :--> PBool))
-> Term s (PSortedValue :--> PBool)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PSortedValue :--> PBool))
 -> Term s (PSortedValue :--> PBool))
-> (forall (s :: S). Term s (PSortedValue :--> PBool))
-> Term s (PSortedValue :--> PBool)
forall a b. (a -> b) -> a -> b
$
  (Term s' PSortedValue -> Term s' PBool)
-> Term s' (PSortedValue :--> PBool)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PBool) -> Term s' (c :--> PBool)
plam ((Term s' PSortedValue -> Term s' PBool)
 -> Term s' (PSortedValue :--> PBool))
-> (Term s' PSortedValue -> Term s' PBool)
-> Term s' (PSortedValue :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value ->
    Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term
  s'
  (PInner
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s'
   (PInner
      (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
 -> Term
      s'
      (PInner
         (PInner
            (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall a b. (a -> b) -> a -> b
$ Term
  s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term
      s'
      (PInner
         (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall a b. (a -> b) -> a -> b
$ Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
value) ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PSortedMap PTokenName PInteger)))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
      PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
  s'
PNil -> PBool s' -> Term s' PBool
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PBool s'
forall (s :: S). PBool s
PTrue
      PCons Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
xs ->
        Term s' (PBool :--> (PBool :--> PBool))
forall (s :: S). Term s (PBool :--> (PBool :--> PBool))
pand'
          # (pnull # xs)
          # pmatch
            x
            ( \(PBuiltinPair cs _) ->
                cs #== padaSymbolData
            )

{- | Check if the given Value contains zero token quantities.

@since 3.6.0
-}
phasZeroTokenQuantities :: forall (s :: S). Term s (PRawValue :--> PBool)
phasZeroTokenQuantities :: forall (s :: S). Term s (PRawValue :--> PBool)
phasZeroTokenQuantities =
  (Term s PRawValue -> Term s PBool) -> Term s (PRawValue :--> PBool)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PBool) -> Term s (c :--> PBool)
plam ((Term s PRawValue -> Term s PBool)
 -> Term s (PRawValue :--> PBool))
-> (Term s PRawValue -> Term s PBool)
-> Term s (PRawValue :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s PRawValue
value ->
    Term
  s
  ((PUnsortedMap PTokenName PInteger :--> PBool)
   :--> (PUnsortedMap
           PCurrencySymbol (PUnsortedMap PTokenName PInteger)
         :--> PBool))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
PIsData v =>
Term s ((v :--> PBool) :--> (PUnsortedMap k v :--> PBool))
AssocMap.pany
      # plam (AssocMap.pany # plam (0 #==) #)
      # pto value

{- | Check if the given 'PSortedValue' contains an ADA entry (can be zero).

@since 3.6.0
-}
phasAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PBool)
phasAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PBool)
phasAdaEntry =
  (forall (s :: S). Term s (PSortedValue :--> PBool))
-> Term s (PSortedValue :--> PBool)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PSortedValue :--> PBool))
 -> Term s (PSortedValue :--> PBool))
-> (forall (s :: S). Term s (PSortedValue :--> PBool))
-> Term s (PSortedValue :--> PBool)
forall a b. (a -> b) -> a -> b
$
    (Term s' PSortedValue -> Term s' PBool)
-> Term s' (PSortedValue :--> PBool)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PBool) -> Term s' (c :--> PBool)
plam ((Term s' PSortedValue -> Term s' PBool)
 -> Term s' (PSortedValue :--> PBool))
-> (Term s' PSortedValue -> Term s' PBool)
-> Term s' (PSortedValue :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value ->
      Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term
  s'
  (PInner
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s'
   (PInner
      (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
 -> Term
      s'
      (PInner
         (PInner
            (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall a b. (a -> b) -> a -> b
$ Term
  s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term
      s'
      (PInner
         (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall a b. (a -> b) -> a -> b
$ Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
value) ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PSortedMap PTokenName PInteger)))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
        PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
  s'
PNil -> PBool s' -> Term s' PBool
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PBool s'
forall (s :: S). PBool s
PFalse
        PCons Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
_ ->
          Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x ((PBuiltinPair
    (PAsData PCurrencySymbol)
    (PAsData (PSortedMap PTokenName PInteger))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \(PBuiltinPair Term s' (PAsData PCurrencySymbol)
cs Term s' (PAsData (PSortedMap PTokenName PInteger))
_) ->
            Term s' (PAsData PCurrencySymbol)
cs Term s' (PAsData PCurrencySymbol)
-> Term s' (PAsData PCurrencySymbol) -> Term s' PBool
forall (s :: S).
Term s (PAsData PCurrencySymbol)
-> Term s (PAsData PCurrencySymbol) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' (PAsData PCurrencySymbol)
forall (s :: S). Term s (PAsData PCurrencySymbol)
padaSymbolData

{- | Check if the given 'PSortedValue' has a zero ADA entry.

@since 3.6.0
-}
phasZeroAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PBool)
phasZeroAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PBool)
phasZeroAdaEntry =
  (Term s PSortedValue -> Term s PBool)
-> Term s (PSortedValue :--> PBool)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s c -> Term s PBool) -> Term s (c :--> PBool)
plam ((Term s PSortedValue -> Term s PBool)
 -> Term s (PSortedValue :--> PBool))
-> (Term s PSortedValue -> Term s PBool)
-> Term s (PSortedValue :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s PSortedValue
value ->
    Term
  s
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s
    -> Term s PBool)
-> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch (Term
  s
  (PInner
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s
   (PInner
      (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
 -> Term
      s
      (PInner
         (PInner
            (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))))
-> Term
     s
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s
     (PInner
        (PInner
           (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
forall a b. (a -> b) -> a -> b
$ Term
  s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
   s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term
      s
      (PInner
         (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))))
-> Term
     s (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s
     (PInner
        (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall a b. (a -> b) -> a -> b
$ Term s PSortedValue -> Term s (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s PSortedValue
value) ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PSortedMap PTokenName PInteger)))
    s
  -> Term s PBool)
 -> Term s PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger)))
      s
    -> Term s PBool)
-> Term s PBool
forall a b. (a -> b) -> a -> b
$ \case
      PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
  s
PNil -> PBool s -> Term s PBool
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PBool s
forall (s :: S). PBool s
PFalse
      PCons Term
  s
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x Term
  s
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
_ ->
        Term
  s
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s
    -> Term s PBool)
-> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term
  s
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger)))
x ((PBuiltinPair
    (PAsData PCurrencySymbol)
    (PAsData (PSortedMap PTokenName PInteger))
    s
  -> Term s PBool)
 -> Term s PBool)
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PSortedMap PTokenName PInteger))
      s
    -> Term s PBool)
-> Term s PBool
forall a b. (a -> b) -> a -> b
$ \(PBuiltinPair Term s (PAsData PCurrencySymbol)
cs Term s (PAsData (PSortedMap PTokenName PInteger))
tokenMap) ->
          (Term s (PAsData PCurrencySymbol)
cs Term s (PAsData PCurrencySymbol)
-> Term s (PAsData PCurrencySymbol) -> Term s PBool
forall (s :: S).
Term s (PAsData PCurrencySymbol)
-> Term s (PAsData PCurrencySymbol) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s (PAsData PCurrencySymbol)
forall (s :: S). Term s (PAsData PCurrencySymbol)
padaSymbolData)
            #&& (tokenMap #== pdata (AssocMap.psingleton # padaToken # 0))

----------------------------------------------------------------------
-- Helpers

zeroData :: forall (s :: S). Term s (PAsData PInteger)
zeroData :: forall (s :: S). Term s (PAsData PInteger)
zeroData = Term s PInteger -> Term s (PAsData PInteger)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata Term s PInteger
0

-- Applies a function to every amount in the map.
pmapAmounts :: forall (s :: S). Term s ((PInteger :--> PInteger) :--> PRawValue :--> PRawValue)
pmapAmounts :: forall (s :: S).
Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
pmapAmounts =
  (forall (s :: S).
 Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue)))
-> Term
     s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue)))
 -> Term
      s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue)))
-> (forall (s :: S).
    Term s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue)))
-> Term
     s ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
forall a b. (a -> b) -> a -> b
$
    (Term s' (PInteger :--> PInteger)
 -> Term s' PRawValue -> Term s' PRawValue)
-> Term
     s' ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PRawValue -> Term s' PRawValue)
-> Term s' (c :--> (PRawValue :--> PRawValue))
plam ((Term s' (PInteger :--> PInteger)
  -> Term s' PRawValue -> Term s' PRawValue)
 -> Term
      s' ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue)))
-> (Term s' (PInteger :--> PInteger)
    -> Term s' PRawValue -> Term s' PRawValue)
-> Term
     s' ((PInteger :--> PInteger) :--> (PRawValue :--> PRawValue))
forall a b. (a -> b) -> a -> b
$ \Term s' (PInteger :--> PInteger)
f Term s' PRawValue
v ->
      Term s' (PInner PRawValue) -> Term s' PRawValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PRawValue) -> Term s' PRawValue)
-> Term s' (PInner PRawValue) -> Term s' PRawValue
forall a b. (a -> b) -> a -> b
$
        Term
  s'
  ((PUnsortedMap PTokenName PInteger
    :--> PUnsortedMap PTokenName PInteger)
   :--> (PUnsortedMap
           PCurrencySymbol (PUnsortedMap PTokenName PInteger)
         :--> PUnsortedMap
                PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
(PInner (t k a) ~ PAssocMap k a, PInner (t k b) ~ PAssocMap k b,
 PIsData a, PIsData b) =>
Term s ((a :--> b) :--> (t k a :--> t k b))
AssocMap.pmap
          # plam (AssocMap.pmap # f #)
          # pto v

{- | Ensure that the given 'PSortedValue' contains an Ada entry.
If missing, a zero Ada entry is inserted at the head of the underlying sorted map.
-}
pinsertAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pinsertAdaEntry :: forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pinsertAdaEntry =
  (forall (s :: S). Term s (PSortedValue :--> PSortedValue))
-> Term s (PSortedValue :--> PSortedValue)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PSortedValue :--> PSortedValue))
 -> Term s (PSortedValue :--> PSortedValue))
-> (forall (s :: S). Term s (PSortedValue :--> PSortedValue))
-> Term s (PSortedValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$
    (Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> PSortedValue)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PSortedValue)
-> Term s' (c :--> PSortedValue)
plam ((Term s' PSortedValue -> Term s' PSortedValue)
 -> Term s' (PSortedValue :--> PSortedValue))
-> (Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value ->
      Term s' PBool
-> Term s' PSortedValue
-> Term s' PSortedValue
-> Term s' PSortedValue
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s' (PSortedValue :--> PBool)
forall (s :: S). Term s (PSortedValue :--> PBool)
phasAdaEntry Term s' (PSortedValue :--> PBool)
-> Term s' PSortedValue -> Term s' PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PSortedValue
value)
        Term s' PSortedValue
value
        ( Term s' (PInner PSortedValue) -> Term s' PSortedValue
Term
  s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term
   s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term s' PSortedValue)
-> (Term
      s'
      (PBuiltinList
         (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PSortedMap PTokenName PInteger))))
    -> Term
         s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PSortedMap PTokenName PInteger))))
-> Term s' PSortedValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term
  s'
  (PInner
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
Term
  s' (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term
   s' (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger))
 -> Term
      s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> (Term
      s'
      (PBuiltinList
         (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PSortedMap PTokenName PInteger))))
    -> Term
         s' (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PSortedMap PTokenName PInteger))))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term
  s'
  (PInner
     (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s' (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger))
Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PSortedMap PTokenName PInteger))))
-> Term
     s' (PAssocMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term
   s'
   (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PSortedMap PTokenName PInteger))))
 -> Term s' PSortedValue)
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PSortedMap PTokenName PInteger))))
-> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
            Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PSortedMap PTokenName PInteger))
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PSortedMap PTokenName PInteger)))
         :--> PBuiltinList
                (PBuiltinPair
                   (PAsData PCurrencySymbol)
                   (PAsData (PSortedMap PTokenName PInteger)))))
forall (a :: S -> Type) (s :: S).
PElemConstraint PBuiltinList a =>
Term s (a :--> (PBuiltinList a :--> PBuiltinList a))
forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (s :: S).
(PListLike list, PElemConstraint list a) =>
Term s (a :--> (list a :--> list a))
pcons
              # (ppairDataBuiltin # padaSymbolData # pdata (AssocMap.psingleton # padaToken # 0))
              # pto (pto $ pto value)
        )

{- | Normalize the argument to contain no Ada entries and no zero token
quantities.
-}
pnormalizeNoAdaNonZeroTokens :: forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pnormalizeNoAdaNonZeroTokens :: forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pnormalizeNoAdaNonZeroTokens = (forall (s :: S). Term s (PSortedValue :--> PSortedValue))
-> Term s (PSortedValue :--> PSortedValue)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PSortedValue :--> PSortedValue))
 -> Term s (PSortedValue :--> PSortedValue))
-> (forall (s :: S). Term s (PSortedValue :--> PSortedValue))
-> Term s (PSortedValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$
  (Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> PSortedValue)
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' PSortedValue)
-> Term s' (c :--> PSortedValue)
plam ((Term s' PSortedValue -> Term s' PSortedValue)
 -> Term s' (PSortedValue :--> PSortedValue))
-> (Term s' PSortedValue -> Term s' PSortedValue)
-> Term s' (PSortedValue :--> PSortedValue)
forall a b. (a -> b) -> a -> b
$ \Term s' PSortedValue
value ->
    Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PSortedValue) -> Term s' PSortedValue)
-> Term s' (PInner PSortedValue) -> Term s' PSortedValue
forall a b. (a -> b) -> a -> b
$
      Term
  s'
  ((PCurrencySymbol
    :--> (PSortedMap PTokenName PInteger
          :--> PMaybe (PSortedMap PTokenName PInteger)))
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
(PInner (t k a) ~ PAssocMap k a, PInner (t k b) ~ PAssocMap k b,
 PIsData k, PIsData a, PIsData b) =>
Term s ((k :--> (a :--> PMaybe b)) :--> (t k a :--> t k b))
AssocMap.pmapMaybeWithKey Term
  s'
  ((PCurrencySymbol
    :--> (PSortedMap PTokenName PInteger
          :--> PMaybe (PSortedMap PTokenName PInteger)))
   :--> (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PCurrencySymbol
      :--> (PSortedMap PTokenName PInteger
            :--> PMaybe (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
      :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s' PCurrencySymbol
 -> Term s' (PSortedMap PTokenName PInteger)
 -> Term s' (PMaybe (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (PCurrencySymbol
      :--> (PSortedMap PTokenName PInteger
            :--> PMaybe (PSortedMap PTokenName PInteger)))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c
 -> Term s' (PSortedMap PTokenName PInteger)
 -> Term s' (PMaybe (PSortedMap PTokenName PInteger)))
-> Term
     s'
     (c
      :--> (PSortedMap PTokenName PInteger
            :--> PMaybe (PSortedMap PTokenName PInteger)))
plam Term s' PCurrencySymbol
-> Term s' (PSortedMap PTokenName PInteger)
-> Term s' (PMaybe (PSortedMap PTokenName PInteger))
forall (t' :: (S -> Type) -> (S -> Type) -> S -> Type) (s' :: S)
       (k :: S -> Type).
(PInner (t' k PInteger) ~ PAssocMap k PInteger) =>
Term s' PCurrencySymbol
-> Term s' (t' k PInteger) -> Term s' (PMaybe (t' k PInteger))
normalizeTokenMap Term
  s'
  (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
value
  where
    normalizeTokenMap ::
      forall
        (t' :: (S -> Type) -> (S -> Type) -> S -> Type)
        (s' :: S)
        (k :: S -> Type).
      PInner (t' k PInteger) ~ AssocMap.PAssocMap k PInteger =>
      Term s' PCurrencySymbol ->
      Term s' (t' k PInteger) ->
      Term s' (PMaybe (t' k PInteger))
    normalizeTokenMap :: forall (t' :: (S -> Type) -> (S -> Type) -> S -> Type) (s' :: S)
       (k :: S -> Type).
(PInner (t' k PInteger) ~ PAssocMap k PInteger) =>
Term s' PCurrencySymbol
-> Term s' (t' k PInteger) -> Term s' (PMaybe (t' k PInteger))
normalizeTokenMap Term s' PCurrencySymbol
cs Term s' (t' k PInteger)
tokenMap =
      Term s' PBool
-> Term s' (PMaybe (t' k PInteger))
-> Term s' (PMaybe (t' k PInteger))
-> Term s' (PMaybe (t' k PInteger))
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s' PCurrencySymbol
cs Term s' PCurrencySymbol -> Term s' PCurrencySymbol -> Term s' PBool
forall (s :: S).
Term s PCurrencySymbol -> Term s PCurrencySymbol -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' PCurrencySymbol
forall (s :: S). Term s PCurrencySymbol
padaSymbol)
        (PMaybe (t' k PInteger) s' -> Term s' (PMaybe (t' k PInteger))
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PMaybe (t' k PInteger) s'
forall (a :: S -> Type) (s :: S). PMaybe a s
PNothing)
        ( Term s' (t' k PInteger)
-> (Term s' (t' k PInteger) -> Term s' (PMaybe (t' k PInteger)))
-> Term s' (PMaybe (t' k PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s a -> (Term s a -> Term s b) -> Term s b
plet (Term
  s'
  ((PAsData PInteger :--> PMaybe (PAsData PInteger))
   :--> (t' k PInteger :--> t' k PInteger))
forall (t :: (S -> Type) -> (S -> Type) -> S -> Type)
       (k :: S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
(PInner (t k a) ~ PAssocMap k a, PInner (t k b) ~ PAssocMap k b) =>
Term
  s ((PAsData a :--> PMaybe (PAsData b)) :--> (t k a :--> t k b))
AssocMap.pmapMaybeData Term
  s'
  ((PAsData PInteger :--> PMaybe (PAsData PInteger))
   :--> (t' k PInteger :--> t' k PInteger))
-> Term s' (PAsData PInteger :--> PMaybe (PAsData PInteger))
-> Term s' (t' k PInteger :--> t' k PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s' (PAsData PInteger) -> Term s' (PMaybe (PAsData PInteger)))
-> Term s' (PAsData PInteger :--> PMaybe (PAsData PInteger))
forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: S -> Type).
HasCallStack =>
(Term s' c -> Term s' (PMaybe (PAsData PInteger)))
-> Term s' (c :--> PMaybe (PAsData PInteger))
plam Term s' (PAsData PInteger) -> Term s' (PMaybe (PAsData PInteger))
forall (s' :: S).
Term s' (PAsData PInteger) -> Term s' (PMaybe (PAsData PInteger))
nonZero Term s' (t' k PInteger :--> t' k PInteger)
-> Term s' (t' k PInteger) -> Term s' (t' k PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (t' k PInteger)
tokenMap) ((Term s' (t' k PInteger) -> Term s' (PMaybe (t' k PInteger)))
 -> Term s' (PMaybe (t' k PInteger)))
-> (Term s' (t' k PInteger) -> Term s' (PMaybe (t' k PInteger)))
-> Term s' (PMaybe (t' k PInteger))
forall a b. (a -> b) -> a -> b
$ \Term s' (t' k PInteger)
normalMap ->
            Term s' PBool
-> Term s' (PMaybe (t' k PInteger))
-> Term s' (PMaybe (t' k PInteger))
-> Term s' (PMaybe (t' k PInteger))
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
              (Term s' (PUnsortedMap k PInteger :--> PBool)
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
Term s (PUnsortedMap k v :--> PBool)
AssocMap.pnull Term s' (PUnsortedMap k PInteger :--> PBool)
-> Term s' (PUnsortedMap k PInteger) -> Term s' PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PInner (PUnsortedMap k PInteger))
-> Term s' (PUnsortedMap k PInteger)
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (t' k PInteger) -> Term s' (PInner (t' k PInteger))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' (t' k PInteger)
normalMap))
              (PMaybe (t' k PInteger) s' -> Term s' (PMaybe (t' k PInteger))
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PMaybe (t' k PInteger) s'
forall (a :: S -> Type) (s :: S). PMaybe a s
PNothing)
              (PMaybe (t' k PInteger) s' -> Term s' (PMaybe (t' k PInteger))
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon (PMaybe (t' k PInteger) s' -> Term s' (PMaybe (t' k PInteger)))
-> PMaybe (t' k PInteger) s' -> Term s' (PMaybe (t' k PInteger))
forall a b. (a -> b) -> a -> b
$ Term s' (t' k PInteger) -> PMaybe (t' k PInteger) s'
forall (a :: S -> Type) (s :: S). Term s a -> PMaybe a s
PJust Term s' (t' k PInteger)
normalMap)
        )
    nonZero ::
      forall (s' :: S).
      Term s' (PAsData PInteger) ->
      Term s' (PMaybe (PAsData PInteger))
    nonZero :: forall (s' :: S).
Term s' (PAsData PInteger) -> Term s' (PMaybe (PAsData PInteger))
nonZero Term s' (PAsData PInteger)
intData =
      Term s' PBool
-> Term s' (PMaybe (PAsData PInteger))
-> Term s' (PMaybe (PAsData PInteger))
-> Term s' (PMaybe (PAsData PInteger))
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif (Term s' (PAsData PInteger)
intData Term s' (PAsData PInteger)
-> Term s' (PAsData PInteger) -> Term s' PBool
forall (s :: S).
Term s (PAsData PInteger)
-> Term s (PAsData PInteger) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' (PAsData PInteger)
forall (s :: S). Term s (PAsData PInteger)
zeroData) (PMaybe (PAsData PInteger) s' -> Term s' (PMaybe (PAsData PInteger))
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon PMaybe (PAsData PInteger) s'
forall (a :: S -> Type) (s :: S). PMaybe a s
PNothing) (PMaybe (PAsData PInteger) s' -> Term s' (PMaybe (PAsData PInteger))
forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon (PMaybe (PAsData PInteger) s'
 -> Term s' (PMaybe (PAsData PInteger)))
-> PMaybe (PAsData PInteger) s'
-> Term s' (PMaybe (PAsData PInteger))
forall a b. (a -> b) -> a -> b
$ Term s' (PAsData PInteger) -> PMaybe (PAsData PInteger) s'
forall (a :: S -> Type) (s :: S). Term s a -> PMaybe a s
PJust Term s' (PAsData PInteger)
intData)