{- | Conversions between ledger API representations of @Value@s and the new
'PBuiltinValue', plus some utility functions.

= Why is this module necessary?

In almost all situations, @Value@s will be provided to a script as their
@Data@ encodings, whether this is through an input or a @PScriptContext@.
@plutarch-ledger-api@ has an extensive collection of functions for dealing
with such representations, as well as a range of @newtype@ wrappers to
provide guarantees of form when doing so.

However, as these operations have to work over (effectively) nested cons
lists, they are not efficient for many operations, especially simpler ones
like lookups or primitive insertions. In this regard, 'PBuiltinValue' excels,
as these are calls to builtin operations, which are much more efficient.
However, some conversion cost must be paid to go from the @Data@ encoding to
a 'PBuiltinValue'.

In addition to this, the @UnValueData@ primitive has quite specific
expectations of any @Data@ it is given. More precisely, the argument must:

* Be made using the @Map@ constructor;
* Every \'key\' must be encoded using the @B@ constructor, and be at most 32
  bytes in length;
* Every \'value\' must be a non-empty list of key-value pairs.
* Every \'inner key\' must be encoded using the @B@ constructor, and be at
  most 32 bytes in length;
* Every \'inner value\' must be encoded using the @I@ constructor, and be
  non-zero, as well as fitting within a 128-bit signed integer;
* \'Keys\', both \'outer\' and \'inner\', must be in strictly ascending
  order, which implies no duplicates.

Any deviation from this will cause the builtin to error. Thus, of all the
@newtype@s provided for structural safety by @plutarch-ledger-api@, only
'PMintValue' is suitable.

To make matters worse, the inverse @ValueData@ builtin does not guarantee
that an arbitrary 'PBuiltinValue' will satisfy the structural requirements of
a 'PMintValue', as it may contain an Ada entry. Thus, if \'converting back\'
is required, we can only guarantee a @PSortedValue@. Any other conversion is
technically speaking unsafe and may error. Worse still, there is no
straightforward way to verify what kind of \'inner\' or \'outer\' keys a
'PBuiltinValue' contains without converting it first!

Thus, this module provides clearly labelled conversions, safe and unsafe, as
well as some helper wrapper functions to make 'PBuiltinValue' easier to use
with other types provided by @plutarch-ledger-api@.

@since 3.7.0
-}
module Plutarch.LedgerApi.V3.Value (
  -- * Conversions

  -- ** Safe
  pfromRawValue,
  pfromSortedValue,
  pfromMintValue,
  ptoSortedValue,
  ptoLedgerValue,
  ptoLedgerValue',
  ptoMintValue,

  -- ** Unsafe
  punsafeFromRawValue,
  punsafeFromSortedValue,
  punsafeToLedgerValue,
  punsafeToMintValue,

  -- * Construction
  pemptyBuiltinValue,
  psingletonBuiltinValue,

  -- * Queries
  pvalueOf,
  plovelaceValueOf,

  -- * Updates
  preplaceAmountPositive,
  preplaceAmountNegative,
  pdeleteAmount,
) where

import Data.Kind (Type)
import Plutarch.Builtin.Value (
  PBuiltinValue,
  pinsertCoin,
  plookupCoin,
  punValueData,
  pvalueData,
 )
import Plutarch.LedgerApi.AssocMap (PUnsortedMap)
import Plutarch.LedgerApi.AssocMap qualified as AssocMap
import Plutarch.LedgerApi.V3.MintValue (PMintValue)
import Plutarch.LedgerApi.Value (
  PLedgerValue,
  PRawValue,
  PSortedValue,
  pinsertAdaEntry,
 )
import Plutarch.LedgerApi.Value.CurrencySymbol (PCurrencySymbol)
import Plutarch.LedgerApi.Value.TokenName (PTokenName)
import Plutarch.Prelude (
  PAsData,
  PBool (PFalse, PTrue),
  PBuiltinList (PCons, PNil),
  PBuiltinPair (PBuiltinPair),
  PInteger,
  PPositive,
  S,
  Term,
  pcon,
  pconstant,
  pdata,
  pfix,
  pforgetData,
  pfromData,
  phoistAcyclic,
  pif,
  plam,
  plet,
  pmatch,
  pnegate,
  pto,
  pupcast,
  (#),
  (#$),
  (#<),
  (#==),
  (:-->),
 )
import Plutarch.Unsafe (punsafeCoerce)
import PlutusCore.Value qualified as PlutusCore

{- | Convert the @Data@ representation of a 'PMintValue' to a 'PBuiltinValue'.
This is done via a builtin (thus efficient), and is safe.

@since 3.7.0
-}
pfromMintValue ::
  forall (s :: S).
  Term s (PAsData PMintValue) -> Term s PBuiltinValue
pfromMintValue :: forall (s :: S).
Term s (PAsData PMintValue) -> Term s PBuiltinValue
pfromMintValue Term s (PAsData PMintValue)
x = Term s (PData :--> PBuiltinValue)
forall (s :: S). Term s (PData :--> PBuiltinValue)
punValueData Term s (PData :--> PBuiltinValue)
-> Term s PData -> Term s PBuiltinValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PAsData PMintValue) -> Term s PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData Term s (PAsData PMintValue)
x

{- | After verifying the conversion is safe, convert a 'PRawValue' @Data@
representation into a 'PBuiltinValue'. To save on allocations, this is
written in a continuation-passing style:

* The second argument is what should happen if validation fails; and
* The third argument is what should happen if validation succeeds.

= Important note

This operation is slow, as it has to check the entire input.

@since 3.7.0
-}
pfromRawValue ::
  forall (r :: S -> Type) (s :: S).
  Term s PRawValue ->
  Term s r ->
  Term s (PBuiltinValue :--> r) ->
  Term s r
pfromRawValue :: forall (r :: S -> Type) (s :: S).
Term s PRawValue
-> Term s r -> Term s (PBuiltinValue :--> r) -> Term s r
pfromRawValue Term s PRawValue
x Term s r
whenFail Term s (PBuiltinValue :--> r)
whenSucceed =
  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 (PRawValue :--> PBool)
forall (s :: S). Term s (PRawValue :--> PBool)
pcanBeBuiltinValue Term s (PRawValue :--> PBool) -> Term s PRawValue -> Term s PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PRawValue
x) (Term s (PBuiltinValue :--> r)
whenSucceed Term s (PBuiltinValue :--> r) -> Term s PBuiltinValue -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term s (PData :--> PBuiltinValue)
forall (s :: S). Term s (PData :--> PBuiltinValue)
punValueData Term s (PData :--> PBuiltinValue)
-> Term s PData -> Term s PBuiltinValue
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 PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData (Term s PRawValue -> Term s (PAsData PRawValue)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata Term s PRawValue
x)) Term s r
whenFail

{- | Convert the @Data@ representation of a 'PRawValue' into a 'PBuiltinValue'
while not doing any checks.

This is /not/ safe, and will error if any of the invariants of
'PBuiltinValue' are violated. Use with care.

@since 3.7.0
-}
punsafeFromRawValue ::
  forall (s :: S).
  Term s (PAsData PRawValue) -> Term s PBuiltinValue
punsafeFromRawValue :: forall (s :: S). Term s (PAsData PRawValue) -> Term s PBuiltinValue
punsafeFromRawValue Term s (PAsData PRawValue)
x = Term s (PData :--> PBuiltinValue)
forall (s :: S). Term s (PData :--> PBuiltinValue)
punValueData Term s (PData :--> PBuiltinValue)
-> Term s PData -> Term s PBuiltinValue
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 PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData Term s (PAsData PRawValue)
x

{- | As 'pfromRawValue', except for 'PSortedValue's instead. This is more
efficient, as we only need to check for the absence of zero amounts.

@since 3.7.0
-}
pfromSortedValue ::
  forall (r :: S -> Type) (s :: S).
  Term s PSortedValue ->
  Term s r ->
  Term s (PBuiltinValue :--> r) ->
  Term s r
pfromSortedValue :: forall (r :: S -> Type) (s :: S).
Term s PSortedValue
-> Term s r -> Term s (PBuiltinValue :--> r) -> Term s r
pfromSortedValue Term s PSortedValue
x Term s r
whenFail Term s (PBuiltinValue :--> r)
whenSucceed =
  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)
pnoZeroAmounts 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
x) (Term s (PBuiltinValue :--> r)
whenSucceed Term s (PBuiltinValue :--> r) -> Term s PBuiltinValue -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
#$ Term s (PData :--> PBuiltinValue)
forall (s :: S). Term s (PData :--> PBuiltinValue)
punValueData Term s (PData :--> PBuiltinValue)
-> Term s PData -> Term s PBuiltinValue
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 PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData (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
x)) Term s r
whenFail

{- | As 'punsafeFromRawValue', except for 'PSortedValue's instead. The same
caveats apply.

@since 3.7.0
-}
punsafeFromSortedValue :: forall (s :: S). Term s (PAsData PSortedValue) -> Term s PBuiltinValue
punsafeFromSortedValue :: forall (s :: S).
Term s (PAsData PSortedValue) -> Term s PBuiltinValue
punsafeFromSortedValue Term s (PAsData PSortedValue)
x = Term s (PData :--> PBuiltinValue)
forall (s :: S). Term s (PData :--> PBuiltinValue)
punValueData Term s (PData :--> PBuiltinValue)
-> Term s PData -> Term s PBuiltinValue
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 PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData Term s (PAsData PSortedValue)
x

{- | Convert a 'PBuiltinValue' into the @Data@ representation of a
'PSortedValue'. This is done via a builtin (thus efficient), and is safe.

If you need to convert to something less specific, use 'pupcast'.

@since 3.7.0
-}
ptoSortedValue ::
  forall (s :: S).
  Term s PBuiltinValue -> Term s (PAsData PSortedValue)
ptoSortedValue :: forall (s :: S).
Term s PBuiltinValue -> Term s (PAsData PSortedValue)
ptoSortedValue Term s PBuiltinValue
v = Term s PData -> Term s (PAsData PSortedValue)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s PData -> Term s (PAsData PSortedValue))
-> Term s PData -> Term s (PAsData PSortedValue)
forall a b. (a -> b) -> a -> b
$ Term s (PBuiltinValue :--> PData)
forall (s :: S). Term s (PBuiltinValue :--> PData)
pvalueData Term s (PBuiltinValue :--> PData)
-> Term s PBuiltinValue -> Term s PData
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v

{- | Checks for an Ada entry in the input 'PBuiltinValue'. If none is found,
produce the second argument; otherwise, convert the 'PBuiltinValue' into a
'PAsData' 'PLedgerValue' and call the third argument with it.

@since 3.7.0
-}
ptoLedgerValue ::
  forall (r :: S -> Type) (s :: S).
  Term s PBuiltinValue ->
  Term s r ->
  Term s (PAsData PLedgerValue :--> r) ->
  Term s r
ptoLedgerValue :: forall (r :: S -> Type) (s :: S).
Term s PBuiltinValue
-> Term s r -> Term s (PAsData PLedgerValue :--> r) -> Term s r
ptoLedgerValue Term s PBuiltinValue
v Term s r
whenInvalid Term s (PAsData PLedgerValue :--> r)
whenValid =
  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 (PBuiltinValue :--> PInteger)
forall (s :: S). Term s (PBuiltinValue :--> PInteger)
plovelaceValueOf Term s (PBuiltinValue :--> PInteger)
-> Term s PBuiltinValue -> Term s PInteger
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v 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).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s PInteger
0) Term s r
whenInvalid (Term s (PAsData PLedgerValue :--> r)
whenValid Term s (PAsData PLedgerValue :--> r)
-> Term s (PAsData PLedgerValue) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PData -> Term s (PAsData PLedgerValue)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s (PBuiltinValue :--> PData)
forall (s :: S). Term s (PBuiltinValue :--> PData)
pvalueData Term s (PBuiltinValue :--> PData)
-> Term s PBuiltinValue -> Term s PData
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v))

{- | As 'ptoLedgerValue', but \'fills in\' a zero ADA entry if one is missing.
This is a costly operation, as it must be done /after/ conversion. Use with
care.

@since 3.7.0
-}
ptoLedgerValue' ::
  forall (s :: S).
  Term s PBuiltinValue ->
  Term s PLedgerValue
ptoLedgerValue' :: forall (s :: S). Term s PBuiltinValue -> Term s PLedgerValue
ptoLedgerValue' Term s PBuiltinValue
v = Term s PSortedValue -> Term s PLedgerValue
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s PSortedValue -> Term s PLedgerValue)
-> Term s PSortedValue -> Term s PLedgerValue
forall a b. (a -> b) -> a -> b
$ Term s (PSortedValue :--> PSortedValue)
forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pinsertAdaEntry 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 (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 PBuiltinValue -> Term s (PAsData PSortedValue))
-> Term s PBuiltinValue
-> Term s PSortedValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s PBuiltinValue -> Term s (PAsData PSortedValue)
forall (s :: S).
Term s PBuiltinValue -> Term s (PAsData PSortedValue)
ptoSortedValue (Term s PBuiltinValue -> Term s PSortedValue)
-> Term s PBuiltinValue -> Term s PSortedValue
forall a b. (a -> b) -> a -> b
$ Term s PBuiltinValue
v)

{- | As 'ptoLedgerValue', except the check is for the /absence/ of an Ada entry,
and the third argument is called with a 'PAsData' 'PMintValue' instead when
appropriate.

@since 3.7.0
-}
ptoMintValue ::
  forall (r :: S -> Type) (s :: S).
  Term s PBuiltinValue ->
  Term s r ->
  Term s (PAsData PMintValue :--> r) ->
  Term s r
ptoMintValue :: forall (r :: S -> Type) (s :: S).
Term s PBuiltinValue
-> Term s r -> Term s (PAsData PMintValue :--> r) -> Term s r
ptoMintValue Term s PBuiltinValue
v Term s r
whenInvalid Term s (PAsData PMintValue :--> r)
whenValid =
  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 (PBuiltinValue :--> PInteger)
forall (s :: S). Term s (PBuiltinValue :--> PInteger)
plovelaceValueOf Term s (PBuiltinValue :--> PInteger)
-> Term s PBuiltinValue -> Term s PInteger
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v 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).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s PInteger
0) (Term s (PAsData PMintValue :--> r)
whenValid Term s (PAsData PMintValue :--> r)
-> Term s (PAsData PMintValue) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PData -> Term s (PAsData PMintValue)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s (PBuiltinValue :--> PData)
forall (s :: S). Term s (PBuiltinValue :--> PData)
pvalueData Term s (PBuiltinValue :--> PData)
-> Term s PBuiltinValue -> Term s PData
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v)) Term s r
whenInvalid

{- | Convert a 'PBuiltinValue' into a 'PAsData' 'PLedgerValue' without checking
anything. Only use this if you are certain that the 'PBuiltinValue' does not
violate any internal invariants of 'PLedgerValue'. In particular, there /must/
be an Ada amount in the argument 'PMintValue'.

@since 3.7.0
-}
punsafeToLedgerValue ::
  forall (s :: S).
  Term s PBuiltinValue -> Term s (PAsData PLedgerValue)
punsafeToLedgerValue :: forall (s :: S).
Term s PBuiltinValue -> Term s (PAsData PLedgerValue)
punsafeToLedgerValue Term s PBuiltinValue
v = Term s PData -> Term s (PAsData PLedgerValue)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s PData -> Term s (PAsData PLedgerValue))
-> Term s PData -> Term s (PAsData PLedgerValue)
forall a b. (a -> b) -> a -> b
$ Term s (PBuiltinValue :--> PData)
forall (s :: S). Term s (PBuiltinValue :--> PData)
pvalueData Term s (PBuiltinValue :--> PData)
-> Term s PBuiltinValue -> Term s PData
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v

{- | Convert a 'PBuiltinValue' into a 'PAsData' 'PLedgerValue' without checking
anything. Only use this if you are certain that the 'PBuiltinValue' does not
violate any internal invariants of 'PMintValue'. In particular, there should
/not/ be an Ada amount in the argument 'PMintValue'.

@since 3.7.0
-}
punsafeToMintValue ::
  forall (s :: S).
  Term s PBuiltinValue -> Term s (PAsData PMintValue)
punsafeToMintValue :: forall (s :: S).
Term s PBuiltinValue -> Term s (PAsData PMintValue)
punsafeToMintValue Term s PBuiltinValue
v = Term s PData -> Term s (PAsData PMintValue)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce (Term s PData -> Term s (PAsData PMintValue))
-> Term s PData -> Term s (PAsData PMintValue)
forall a b. (a -> b) -> a -> b
$ Term s (PBuiltinValue :--> PData)
forall (s :: S). Term s (PBuiltinValue :--> PData)
pvalueData Term s (PBuiltinValue :--> PData)
-> Term s PBuiltinValue -> Term s PData
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PBuiltinValue
v

{- | The 'PBuiltinValue' without any amounts.

@since 3.7.0
-}
pemptyBuiltinValue :: forall (s :: S). Term s PBuiltinValue
pemptyBuiltinValue :: forall (s :: S). Term s PBuiltinValue
pemptyBuiltinValue = AsHaskell PBuiltinValue -> Term s PBuiltinValue
forall (a :: S -> Type) (s :: S).
PLiftable a =>
AsHaskell a -> Term s a
pconstant AsHaskell PBuiltinValue
Value
PlutusCore.empty

{- | A 'PBuiltinValue' containing an amount of a single currency-token name
combination. If the 'PInteger' argument is @0@, this will be identical to
'pemptyBuiltinValue'.

@since 3.7.0
-}
psingletonBuiltinValue ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PBuiltinValue)
psingletonBuiltinValue :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
psingletonBuiltinValue = (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PInteger :--> PBuiltinValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
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 :--> PBuiltinValue))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PBuiltinValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PBuiltinValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
forall a b. (a -> b) -> a -> b
$ (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
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' PBuiltinValue)
-> Term s' (c :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PInteger -> Term s' PBuiltinValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PBuiltinValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PInteger -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PInteger :--> PBuiltinValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
symbol Term s' PTokenName
token Term s' PInteger
amount ->
  Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
forall (s :: S).
Term
  s
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
pinsertCoin Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term s' PByteString
-> Term
     s'
     (PByteString
      :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PCurrencySymbol
symbol Term
  s'
  (PByteString
   :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
-> Term s' PByteString
-> Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PTokenName
token Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
-> Term s' PInteger -> Term s' (PBuiltinValue :--> PBuiltinValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
amount Term s' (PBuiltinValue :--> PBuiltinValue)
-> Term s' PBuiltinValue -> Term s' PBuiltinValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
forall (s :: S). Term s PBuiltinValue
pemptyBuiltinValue

{- | Look up the amount associated with a given combination of 'PCurrencySymbol'
and 'PTokenName' in the given 'PBuiltinValue'. As 'PBuiltinValue' cannot
store zero amounts, if this returns @0@, it means that no amount is
associated with the given combination of 'PCurrencySymbol' and 'PTokenName'
in this 'PBuiltinValue.

@since 3.7.0
-}
pvalueOf ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PBuiltinValue :--> PInteger)
pvalueOf :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PBuiltinValue :--> PInteger)))
pvalueOf = (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PBuiltinValue :--> PInteger))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PInteger)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName :--> (PBuiltinValue :--> PInteger))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PInteger))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PInteger))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PInteger)))
forall a b. (a -> b) -> a -> b
$ (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PBuiltinValue -> Term s' PInteger)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> 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' PTokenName -> Term s' PBuiltinValue -> Term s' PInteger)
-> Term s' (c :--> (PTokenName :--> (PBuiltinValue :--> PInteger)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PBuiltinValue -> Term s' PInteger)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PInteger))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PBuiltinValue -> Term s' PInteger)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PInteger)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
cs Term s' PTokenName
tn Term s' PBuiltinValue
v ->
  Term
  s'
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
forall (s :: S).
Term
  s
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
plookupCoin Term
  s'
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
-> Term s' PByteString
-> Term s' (PByteString :--> (PBuiltinValue :--> 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' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PCurrencySymbol
cs Term s' (PByteString :--> (PBuiltinValue :--> PInteger))
-> Term s' PByteString -> Term s' (PBuiltinValue :--> PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PTokenName
tn Term s' (PBuiltinValue :--> PInteger)
-> Term s' PBuiltinValue -> Term s' PInteger
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
v

{- | As 'pvalueOf', but for Lovelace specifically. The same caveats apply.

@since 3.7.0
-}
plovelaceValueOf ::
  forall (s :: S).
  Term s (PBuiltinValue :--> PInteger)
plovelaceValueOf :: forall (s :: S). Term s (PBuiltinValue :--> PInteger)
plovelaceValueOf = (forall (s :: S). Term s (PBuiltinValue :--> PInteger))
-> Term s (PBuiltinValue :--> PInteger)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PBuiltinValue :--> PInteger))
 -> Term s (PBuiltinValue :--> PInteger))
-> (forall (s :: S). Term s (PBuiltinValue :--> PInteger))
-> Term s (PBuiltinValue :--> PInteger)
forall a b. (a -> b) -> a -> b
$ (Term s' PBuiltinValue -> Term s' PInteger)
-> Term s' (PBuiltinValue :--> 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' PBuiltinValue -> Term s' PInteger)
 -> Term s' (PBuiltinValue :--> PInteger))
-> (Term s' PBuiltinValue -> Term s' PInteger)
-> Term s' (PBuiltinValue :--> PInteger)
forall a b. (a -> b) -> a -> b
$ \Term s' PBuiltinValue
v ->
  Term
  s'
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
forall (s :: S).
Term
  s
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
plookupCoin Term
  s'
  (PByteString :--> (PByteString :--> (PBuiltinValue :--> PInteger)))
-> Term s' PByteString
-> Term s' (PByteString :--> (PBuiltinValue :--> PInteger))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# AsHaskell PByteString -> Term s' PByteString
forall (a :: S -> Type) (s :: S).
PLiftable a =>
AsHaskell a -> Term s a
pconstant ByteString
AsHaskell PByteString
"" Term s' (PByteString :--> (PBuiltinValue :--> PInteger))
-> Term s' PByteString -> Term s' (PBuiltinValue :--> PInteger)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# AsHaskell PByteString -> Term s' PByteString
forall (a :: S -> Type) (s :: S).
PLiftable a =>
AsHaskell a -> Term s a
pconstant ByteString
AsHaskell PByteString
"" Term s' (PBuiltinValue :--> PInteger)
-> Term s' PBuiltinValue -> Term s' PInteger
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
v

{- | Replace the amount at the given currency-token name combination in the
given 'PBuiltinValue' with the given amount. The new amount will be positive.
If the given currency-token name combination does not exist, create it.

= Note

A 'PBuiltinValue' cannot store an amount that would not fit into a 128-bit
signed integer. This function will error if the result would be forced to
store such an amount.

@since 3.7.0
-}
preplaceAmountPositive ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PPositive :--> PBuiltinValue :--> PBuiltinValue)
preplaceAmountPositive :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName
         :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
preplaceAmountPositive = (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName
          :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName
           :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall a b. (a -> b) -> a -> b
$ (Term s' PCurrencySymbol
 -> Term s' PTokenName
 -> Term s' PPositive
 -> Term s' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
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' PPositive
 -> Term s' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s'
     (c
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName
  -> Term s' PPositive
  -> Term s' PBuiltinValue
  -> Term s' PBuiltinValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName
    -> Term s' PPositive
    -> Term s' PBuiltinValue
    -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
cs Term s' PTokenName
tn Term s' PPositive
amount Term s' PBuiltinValue
v ->
  Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
forall (s :: S).
Term
  s
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
pinsertCoin Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term s' PByteString
-> Term
     s'
     (PByteString
      :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PCurrencySymbol
cs Term
  s'
  (PByteString
   :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
-> Term s' PByteString
-> Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PTokenName
tn Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
-> Term s' PInteger -> Term s' (PBuiltinValue :--> PBuiltinValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PPositive -> Term s' PInteger
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PPositive
amount Term s' (PBuiltinValue :--> PBuiltinValue)
-> Term s' PBuiltinValue -> Term s' PBuiltinValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
v

{- | Replace the amount at the given currency-token name combination in the
given 'PBuiltinValue' with the given amount. The new amount will be negative.
If the given currency-token name combination does not exist, create it.

= Note

A 'PBuiltinValue' cannot store an amount that would not fit into a 128-bit
signed integer. This function will error if the result would be forced to
store such an amount.

@since 3.7.0
-}
preplaceAmountNegative ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PPositive :--> PBuiltinValue :--> PBuiltinValue)
preplaceAmountNegative :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName
         :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
preplaceAmountNegative = (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName
          :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName
           :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall a b. (a -> b) -> a -> b
$ (Term s' PCurrencySymbol
 -> Term s' PTokenName
 -> Term s' PPositive
 -> Term s' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
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' PPositive
 -> Term s' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s'
     (c
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName
  -> Term s' PPositive
  -> Term s' PBuiltinValue
  -> Term s' PBuiltinValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName
             :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue)))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName
    -> Term s' PPositive
    -> Term s' PBuiltinValue
    -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName
            :--> (PPositive :--> (PBuiltinValue :--> PBuiltinValue))))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
cs Term s' PTokenName
tn Term s' PPositive
amount Term s' PBuiltinValue
v ->
  Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
forall (s :: S).
Term
  s
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
pinsertCoin Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term s' PByteString
-> Term
     s'
     (PByteString
      :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PCurrencySymbol
cs Term
  s'
  (PByteString
   :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
-> Term s' PByteString
-> Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PTokenName
tn Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
-> Term s' PInteger -> Term s' (PBuiltinValue :--> PBuiltinValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s' (PInteger :--> PInteger)
forall (s :: S). Term s (PInteger :--> PInteger)
forall (a :: S -> Type) (s :: S).
PAdditiveGroup a =>
Term s (a :--> a)
pnegate Term s' (PInteger :--> PInteger)
-> Term s' PInteger -> Term s' PInteger
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PPositive -> Term s' PInteger
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PPositive
amount) Term s' (PBuiltinValue :--> PBuiltinValue)
-> Term s' PBuiltinValue -> Term s' PBuiltinValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
v

{- | Remove any amount associated with the given currency-token name combination
in the given 'PBuiltinValue'. If there is no such combination in the given
'PBuiltinValue', this does nothing.

@since 3.7.0
-}
pdeleteAmount ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PBuiltinValue :--> PBuiltinValue)
pdeleteAmount :: forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
pdeleteAmount = (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S).
  Term
    s
    (PCurrencySymbol
     :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term
     s
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
forall a b. (a -> b) -> a -> b
$ (Term s' PCurrencySymbol
 -> Term s' PTokenName
 -> Term s' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
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' PBuiltinValue
 -> Term s' PBuiltinValue)
-> Term
     s' (c :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName
  -> Term s' PBuiltinValue
  -> Term s' PBuiltinValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName
    -> Term s' PBuiltinValue
    -> Term s' PBuiltinValue)
-> Term
     s'
     (PCurrencySymbol
      :--> (PTokenName :--> (PBuiltinValue :--> PBuiltinValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
cs Term s' PTokenName
tn Term s' PBuiltinValue
v ->
  Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
forall (s :: S).
Term
  s
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
pinsertCoin Term
  s'
  (PByteString
   :--> (PByteString
         :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue))))
-> Term s' PByteString
-> Term
     s'
     (PByteString
      :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PCurrencySymbol
cs Term
  s'
  (PByteString
   :--> (PInteger :--> (PBuiltinValue :--> PBuiltinValue)))
-> Term s' PByteString
-> Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName -> Term s' PByteString
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
PSubtype a b =>
Term s b -> Term s a
pupcast Term s' PTokenName
tn Term s' (PInteger :--> (PBuiltinValue :--> PBuiltinValue))
-> Term s' PInteger -> Term s' (PBuiltinValue :--> PBuiltinValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
0 Term s' (PBuiltinValue :--> PBuiltinValue)
-> Term s' PBuiltinValue -> Term s' PBuiltinValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PBuiltinValue
v

-- Helpers

pcanBeBuiltinValue :: forall (s :: S). Term s (PRawValue :--> PBool)
pcanBeBuiltinValue :: forall (s :: S). Term s (PRawValue :--> PBool)
pcanBeBuiltinValue = (forall (s :: S). Term s (PRawValue :--> PBool))
-> Term s (PRawValue :--> PBool)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s :: S). Term s (PRawValue :--> PBool))
 -> Term s (PRawValue :--> PBool))
-> (forall (s :: S). Term s (PRawValue :--> PBool))
-> Term s (PRawValue :--> PBool)
forall a b. (a -> b) -> a -> b
$ (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
v -> Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap 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
     (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
-> Term
     s'
     (PInner
        (PInner
           (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term
  s'
  (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger))
-> Term
     s'
     (PInner
        (PUnsortedMap PCurrencySymbol (PUnsortedMap PTokenName PInteger)))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term s' PRawValue -> Term s' (PInner PRawValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PRawValue
v))) ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PUnsortedMap PTokenName PInteger)))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
  PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap 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 (PUnsortedMap PTokenName PInteger)))
x Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
xs -> Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger)))
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PUnsortedMap 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 (PUnsortedMap PTokenName PInteger)))
x ((PBuiltinPair
    (PAsData PCurrencySymbol)
    (PAsData (PUnsortedMap PTokenName PInteger))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PUnsortedMap PTokenName PInteger))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
    PBuiltinPair Term s' (PAsData PCurrencySymbol)
prevK Term s' (PAsData (PUnsortedMap PTokenName PInteger))
innerMap ->
      Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
forall (s' :: S).
Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
verifyInner Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
-> Term s' (PAsData (PUnsortedMap PTokenName 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' (PAsData (PUnsortedMap PTokenName PInteger))
innerMap)
        ( Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap 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'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
xs ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PUnsortedMap PTokenName PInteger)))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
            PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap 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 (PUnsortedMap PTokenName PInteger)))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
ys -> Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
forall (s' :: S).
Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
goOuter Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
-> Term s' PCurrencySymbol
-> Term
     s'
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))
      :--> (PBuiltinList
              (PBuiltinPair
                 (PAsData PCurrencySymbol)
                 (PAsData (PUnsortedMap PTokenName PInteger)))
            :--> PBool))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PAsData PCurrencySymbol) -> Term s' PCurrencySymbol
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData PCurrencySymbol)
prevK Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger))
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger)))
         :--> PBool))
-> Term
     s'
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger)))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger)))
      :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger)))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger)))
   :--> PBool)
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName 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'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
ys
        )
        (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)
  where
    verifyInner ::
      forall (s' :: S).
      Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
    verifyInner :: forall (s' :: S).
Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
verifyInner = (forall (s' :: S).
 Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool))
-> Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s' :: S).
  Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool))
 -> Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool))
-> (forall (s' :: S).
    Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool))
-> Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
forall a b. (a -> b) -> a -> b
$ (Term s' (PAsData (PUnsortedMap PTokenName PInteger))
 -> Term s' PBool)
-> Term s' (PAsData (PUnsortedMap PTokenName 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' PBool) -> Term s' (c :--> PBool)
plam ((Term s' (PAsData (PUnsortedMap PTokenName PInteger))
  -> Term s' PBool)
 -> Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool))
-> (Term s' (PAsData (PUnsortedMap PTokenName PInteger))
    -> Term s' PBool)
-> Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s' (PAsData (PUnsortedMap PTokenName PInteger))
innerMap -> Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData 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' (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' (PUnsortedMap PTokenName PInteger)
-> Term s' (PInner (PUnsortedMap PTokenName PInteger))
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto (Term s' (PAsData (PUnsortedMap PTokenName PInteger))
-> Term s' (PUnsortedMap PTokenName PInteger)
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData (PUnsortedMap PTokenName PInteger))
innerMap))) ((PBuiltinList
    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
      -- Invalid to have an empty inner map
      PBuiltinList
  (PBuiltinPair (PAsData PTokenName) (PAsData 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 PTokenName) (PAsData PInteger))
x Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
xs -> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> (PBuiltinPair (PAsData PTokenName) (PAsData 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 PTokenName) (PAsData PInteger))
x ((PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
        PBuiltinPair Term s' (PAsData PTokenName)
prevK Term s' (PAsData PInteger)
amount ->
          Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
            (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)
amount 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).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' PInteger
0)
            (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)
            ( Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData 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'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
xs ((PBuiltinList
    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
                PBuiltinList
  (PBuiltinPair (PAsData PTokenName) (PAsData 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 PTokenName) (PAsData PInteger))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
ys -> Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
forall (s' :: S).
Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
goInner Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
-> Term s' PTokenName
-> Term
     s'
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
      :--> (PBuiltinList
              (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
            :--> PBool))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PAsData PTokenName) -> Term s' PTokenName
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData PTokenName)
prevK Term
  s'
  (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
   :--> (PBuiltinList
           (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
         :--> PBool))
-> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
      :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
   :--> PBool)
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair (PAsData PTokenName) (PAsData 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'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
ys
            )
    goOuter ::
      forall (s' :: S).
      Term
        s'
        ( PCurrencySymbol
            :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PUnsortedMap PTokenName PInteger))
            :--> PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PUnsortedMap PTokenName PInteger)))
            :--> PBool
        )
    goOuter :: forall (s' :: S).
Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
goOuter = (forall (s' :: S).
 Term
   s'
   (PCurrencySymbol
    :--> (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PUnsortedMap PTokenName PInteger))
          :--> (PBuiltinList
                  (PBuiltinPair
                     (PAsData PCurrencySymbol)
                     (PAsData (PUnsortedMap PTokenName PInteger)))
                :--> PBool))))
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s' :: S).
  Term
    s'
    (PCurrencySymbol
     :--> (PBuiltinPair
             (PAsData PCurrencySymbol)
             (PAsData (PUnsortedMap PTokenName PInteger))
           :--> (PBuiltinList
                   (PBuiltinPair
                      (PAsData PCurrencySymbol)
                      (PAsData (PUnsortedMap PTokenName PInteger)))
                 :--> PBool))))
 -> Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool))))
-> (forall (s' :: S).
    Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool))))
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ (Term
   s'
   (PCurrencySymbol
    :--> (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PUnsortedMap PTokenName PInteger))
          :--> (PBuiltinList
                  (PBuiltinPair
                     (PAsData PCurrencySymbol)
                     (PAsData (PUnsortedMap PTokenName PInteger)))
                :--> PBool)))
 -> Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool))))
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
(Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
pfix ((Term
    s'
    (PCurrencySymbol
     :--> (PBuiltinPair
             (PAsData PCurrencySymbol)
             (PAsData (PUnsortedMap PTokenName PInteger))
           :--> (PBuiltinList
                   (PBuiltinPair
                      (PAsData PCurrencySymbol)
                      (PAsData (PUnsortedMap PTokenName PInteger)))
                 :--> PBool)))
  -> Term
       s'
       (PCurrencySymbol
        :--> (PBuiltinPair
                (PAsData PCurrencySymbol)
                (PAsData (PUnsortedMap PTokenName PInteger))
              :--> (PBuiltinList
                      (PBuiltinPair
                         (PAsData PCurrencySymbol)
                         (PAsData (PUnsortedMap PTokenName PInteger)))
                    :--> PBool))))
 -> Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool))))
-> (Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool)))
    -> Term
         s'
         (PCurrencySymbol
          :--> (PBuiltinPair
                  (PAsData PCurrencySymbol)
                  (PAsData (PUnsortedMap PTokenName PInteger))
                :--> (PBuiltinList
                        (PBuiltinPair
                           (PAsData PCurrencySymbol)
                           (PAsData (PUnsortedMap PTokenName PInteger)))
                      :--> PBool))))
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ \Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
self -> (Term s' PCurrencySymbol
 -> Term
      s'
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap PTokenName PInteger)))
 -> Term
      s'
      (PBuiltinList
         (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PUnsortedMap PTokenName PInteger))))
 -> Term s' PBool)
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName 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'
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap PTokenName PInteger)))
 -> Term
      s'
      (PBuiltinList
         (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PUnsortedMap PTokenName PInteger))))
 -> Term s' PBool)
-> Term
     s'
     (c
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
plam ((Term s' PCurrencySymbol
  -> Term
       s'
       (PBuiltinPair
          (PAsData PCurrencySymbol)
          (PAsData (PUnsortedMap PTokenName PInteger)))
  -> Term
       s'
       (PBuiltinList
          (PBuiltinPair
             (PAsData PCurrencySymbol)
             (PAsData (PUnsortedMap PTokenName PInteger))))
  -> Term s' PBool)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))
             :--> (PBuiltinList
                     (PBuiltinPair
                        (PAsData PCurrencySymbol)
                        (PAsData (PUnsortedMap PTokenName PInteger)))
                   :--> PBool))))
-> (Term s' PCurrencySymbol
    -> Term
         s'
         (PBuiltinPair
            (PAsData PCurrencySymbol)
            (PAsData (PUnsortedMap PTokenName PInteger)))
    -> Term
         s'
         (PBuiltinList
            (PBuiltinPair
               (PAsData PCurrencySymbol)
               (PAsData (PUnsortedMap PTokenName PInteger))))
    -> Term s' PBool)
-> Term
     s'
     (PCurrencySymbol
      :--> (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger))
            :--> (PBuiltinList
                    (PBuiltinPair
                       (PAsData PCurrencySymbol)
                       (PAsData (PUnsortedMap PTokenName PInteger)))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
prevK Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger)))
curr Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
rest -> Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger)))
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PUnsortedMap 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 (PUnsortedMap PTokenName PInteger)))
curr ((PBuiltinPair
    (PAsData PCurrencySymbol)
    (PAsData (PUnsortedMap PTokenName PInteger))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinPair
      (PAsData PCurrencySymbol)
      (PAsData (PUnsortedMap PTokenName PInteger))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
      PBuiltinPair Term s' (PAsData PCurrencySymbol)
currK Term s' (PAsData (PUnsortedMap PTokenName PInteger))
currV -> Term s' PCurrencySymbol
-> (Term s' PCurrencySymbol -> Term s' PBool) -> Term s' PBool
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 PCurrencySymbol) -> Term s' PCurrencySymbol
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData PCurrencySymbol)
currK) ((Term s' PCurrencySymbol -> Term s' PBool) -> Term s' PBool)
-> (Term s' PCurrencySymbol -> Term s' PBool) -> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
currK' ->
        Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
          (Term s' PCurrencySymbol
prevK 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).
POrd t =>
Term s t -> Term s t -> Term s PBool
#< Term s' PCurrencySymbol
currK')
          ( Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
              (Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
forall (s' :: S).
Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
verifyInner Term s' (PAsData (PUnsortedMap PTokenName PInteger) :--> PBool)
-> Term s' (PAsData (PUnsortedMap PTokenName 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' (PAsData (PUnsortedMap PTokenName PInteger))
currV)
              ( Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap 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'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
rest ((PBuiltinList
    (PBuiltinPair
       (PAsData PCurrencySymbol)
       (PAsData (PUnsortedMap PTokenName PInteger)))
    s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair
         (PAsData PCurrencySymbol)
         (PAsData (PUnsortedMap PTokenName PInteger)))
      s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
                  PBuiltinList
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap 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 (PUnsortedMap PTokenName PInteger)))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
ys -> Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
self Term
  s'
  (PCurrencySymbol
   :--> (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger))
         :--> (PBuiltinList
                 (PBuiltinPair
                    (PAsData PCurrencySymbol)
                    (PAsData (PUnsortedMap PTokenName PInteger)))
               :--> PBool)))
-> Term s' PCurrencySymbol
-> Term
     s'
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))
      :--> (PBuiltinList
              (PBuiltinPair
                 (PAsData PCurrencySymbol)
                 (PAsData (PUnsortedMap PTokenName PInteger)))
            :--> PBool))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol
currK' Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger))
   :--> (PBuiltinList
           (PBuiltinPair
              (PAsData PCurrencySymbol)
              (PAsData (PUnsortedMap PTokenName PInteger)))
         :--> PBool))
-> Term
     s'
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger)))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName PInteger)))
      :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term
  s'
  (PBuiltinPair
     (PAsData PCurrencySymbol)
     (PAsData (PUnsortedMap PTokenName PInteger)))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger)))
   :--> PBool)
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair
           (PAsData PCurrencySymbol)
           (PAsData (PUnsortedMap PTokenName 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'
  (PBuiltinList
     (PBuiltinPair
        (PAsData PCurrencySymbol)
        (PAsData (PUnsortedMap PTokenName PInteger))))
ys
              )
              (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)
          )
          (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)
    goInner ::
      forall (s' :: S).
      Term
        s'
        ( PTokenName
            :--> PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> PBuiltinList (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
            :--> PBool
        )
    goInner :: forall (s' :: S).
Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
goInner = (forall (s' :: S).
 Term
   s'
   (PTokenName
    :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
          :--> (PBuiltinList
                  (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                :--> PBool))))
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s' :: S).
  Term
    s'
    (PTokenName
     :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
           :--> (PBuiltinList
                   (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                 :--> PBool))))
 -> Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool))))
-> (forall (s' :: S).
    Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool))))
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ (Term
   s'
   (PTokenName
    :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
          :--> (PBuiltinList
                  (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                :--> PBool)))
 -> Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool))))
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
forall (a :: S -> Type) (b :: S -> Type) (s :: S).
(Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
pfix ((Term
    s'
    (PTokenName
     :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
           :--> (PBuiltinList
                   (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                 :--> PBool)))
  -> Term
       s'
       (PTokenName
        :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
              :--> (PBuiltinList
                      (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                    :--> PBool))))
 -> Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool))))
-> (Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool)))
    -> Term
         s'
         (PTokenName
          :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
                :--> (PBuiltinList
                        (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                      :--> PBool))))
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ \Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
self -> (Term s' PTokenName
 -> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
 -> Term
      s'
      (PBuiltinList
         (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
 -> Term s' PBool)
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData 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' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
 -> Term
      s'
      (PBuiltinList
         (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
 -> Term s' PBool)
-> Term
     s'
     (c
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
plam ((Term s' PTokenName
  -> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
  -> Term
       s'
       (PBuiltinList
          (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
  -> Term s' PBool)
 -> Term
      s'
      (PTokenName
       :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
             :--> (PBuiltinList
                     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                   :--> PBool))))
-> (Term s' PTokenName
    -> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
    -> Term
         s'
         (PBuiltinList
            (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
    -> Term s' PBool)
-> Term
     s'
     (PTokenName
      :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
            :--> (PBuiltinList
                    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
                  :--> PBool)))
forall a b. (a -> b) -> a -> b
$ \Term s' PTokenName
prevK Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
curr Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
rest -> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> (PBuiltinPair (PAsData PTokenName) (PAsData 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 PTokenName) (PAsData PInteger))
curr ((PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger) s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
      PBuiltinPair Term s' (PAsData PTokenName)
currK Term s' (PAsData PInteger)
currV -> Term s' PTokenName
-> (Term s' PTokenName -> Term s' PBool) -> Term s' PBool
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 PTokenName) -> Term s' PTokenName
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s' (PAsData PTokenName)
currK) ((Term s' PTokenName -> Term s' PBool) -> Term s' PBool)
-> (Term s' PTokenName -> Term s' PBool) -> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \Term s' PTokenName
currK' ->
        Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
          (Term s' PTokenName
prevK Term s' PTokenName -> Term s' PTokenName -> Term s' PBool
forall (s :: S).
Term s PTokenName -> Term s PTokenName -> Term s PBool
forall (t :: S -> Type) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#< Term s' PTokenName
currK')
          ( Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
              (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)
currV 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).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' PInteger
0)
              (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)
              ( Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData 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'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
rest ((PBuiltinList
    (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
  -> Term s' PBool)
 -> Term s' PBool)
-> (PBuiltinList
      (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)) s'
    -> Term s' PBool)
-> Term s' PBool
forall a b. (a -> b) -> a -> b
$ \case
                  PBuiltinList
  (PBuiltinPair (PAsData PTokenName) (PAsData 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 PTokenName) (PAsData PInteger))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
ys -> Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
self Term
  s'
  (PTokenName
   :--> (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
         :--> (PBuiltinList
                 (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
               :--> PBool)))
-> Term s' PTokenName
-> Term
     s'
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
      :--> (PBuiltinList
              (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
            :--> PBool))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName
currK' Term
  s'
  (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)
   :--> (PBuiltinList
           (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
         :--> PBool))
-> Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
      :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
y Term
  s'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger))
   :--> PBool)
-> Term
     s'
     (PBuiltinList
        (PBuiltinPair (PAsData PTokenName) (PAsData 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'
  (PBuiltinList
     (PBuiltinPair (PAsData PTokenName) (PAsData PInteger)))
ys
              )
          )
          (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)

pnoZeroAmounts :: forall (s :: S). Term s (PSortedValue :--> PBool)
pnoZeroAmounts :: forall (s :: S). Term s (PSortedValue :--> PBool)
pnoZeroAmounts = (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
v -> Term
  s'
  ((PSortedMap PTokenName PInteger :--> PBool)
   :--> (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PBool))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
PIsData v =>
Term s ((v :--> PBool) :--> (PUnsortedMap k v :--> PBool))
AssocMap.pall Term
  s'
  ((PSortedMap PTokenName PInteger :--> PBool)
   :--> (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
         :--> PBool))
-> Term s' (PSortedMap PTokenName PInteger :--> PBool)
-> Term
     s'
     (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
      :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PSortedMap PTokenName PInteger :--> PBool)
forall (s' :: S).
Term s' (PSortedMap PTokenName PInteger :--> PBool)
go Term
  s'
  (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger)
   :--> PBool)
-> Term
     s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName 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' (PSortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
-> Term
     s' (PUnsortedMap PCurrencySymbol (PSortedMap PTokenName PInteger))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
Term s (PSortedMap k v) -> Term s (PUnsortedMap k v)
AssocMap.pforgetSorted (Term s' PSortedValue -> Term s' (PInner PSortedValue)
forall (a :: S -> Type) (s :: S). Term s a -> Term s (PInner a)
pto Term s' PSortedValue
v)
  where
    go :: forall (s' :: S). Term s' (AssocMap.PSortedMap PTokenName PInteger :--> PBool)
    go :: forall (s' :: S).
Term s' (PSortedMap PTokenName PInteger :--> PBool)
go = (forall (s' :: S).
 Term s' (PSortedMap PTokenName PInteger :--> PBool))
-> Term s' (PSortedMap PTokenName PInteger :--> PBool)
forall (a :: S -> Type) (s :: S).
HasCallStack =>
(forall (s' :: S). Term s' a) -> Term s a
phoistAcyclic ((forall (s' :: S).
  Term s' (PSortedMap PTokenName PInteger :--> PBool))
 -> Term s' (PSortedMap PTokenName PInteger :--> PBool))
-> (forall (s' :: S).
    Term s' (PSortedMap PTokenName PInteger :--> PBool))
-> Term s' (PSortedMap PTokenName PInteger :--> PBool)
forall a b. (a -> b) -> a -> b
$ (Term s' (PSortedMap PTokenName PInteger) -> Term s' PBool)
-> Term s' (PSortedMap PTokenName 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' PBool) -> Term s' (c :--> PBool)
plam ((Term s' (PSortedMap PTokenName PInteger) -> Term s' PBool)
 -> Term s' (PSortedMap PTokenName PInteger :--> PBool))
-> (Term s' (PSortedMap PTokenName PInteger) -> Term s' PBool)
-> Term s' (PSortedMap PTokenName PInteger :--> PBool)
forall a b. (a -> b) -> a -> b
$ \Term s' (PSortedMap PTokenName PInteger)
m ->
      Term
  s'
  ((PInteger :--> PBool)
   :--> (PUnsortedMap PTokenName PInteger :--> PBool))
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
PIsData v =>
Term s ((v :--> PBool) :--> (PUnsortedMap k v :--> PBool))
AssocMap.pall Term
  s'
  ((PInteger :--> PBool)
   :--> (PUnsortedMap PTokenName PInteger :--> PBool))
-> Term s' (PInteger :--> PBool)
-> Term s' (PUnsortedMap PTokenName PInteger :--> PBool)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# (Term s' PInteger -> Term s' PBool)
-> Term s' (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' PBool) -> Term s' (c :--> PBool)
plam (\Term s' PInteger
i -> Term s' PBool -> Term s' PBool -> Term s' PBool -> Term s' PBool
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif (Term s' PInteger
i 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).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' PInteger
0) (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) (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)) Term s' (PUnsortedMap PTokenName PInteger :--> PBool)
-> Term s' (PUnsortedMap PTokenName 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' (PSortedMap PTokenName PInteger)
-> Term s' (PUnsortedMap PTokenName PInteger)
forall (k :: S -> Type) (v :: S -> Type) (s :: S).
Term s (PSortedMap k v) -> Term s (PUnsortedMap k v)
AssocMap.pforgetSorted Term s' (PSortedMap PTokenName PInteger)
m