module Plutarch.LedgerApi.V3.MintValue (
  PMintValue,
  pemptyMintValue,
  psingletonMintValue,
  ptoMintValue,
) where

import GHC.Generics (Generic)
import Generics.SOP qualified as SOP
import Plutarch.LedgerApi.Value (
  PSortedValue,
  pemptySortedValue,
  pforgetSorted,
  phasAdaEntry,
  phasZeroTokenQuantities,
  pnormalizeNoAdaNonZeroTokens,
  psingletonSortedValue,
 )
import Plutarch.LedgerApi.Value.CurrencySymbol (PCurrencySymbol, padaSymbol)
import Plutarch.LedgerApi.Value.TokenName (PTokenName)
import Plutarch.Prelude hiding (psingleton)
import Plutarch.Unsafe (punsafeCoerce, punsafeDowncast)
import PlutusTx.Prelude qualified as PlutusTx

{- | Represents sorted, well-formed Values without an Ada entry, while all
non-Ada token quantities must be non-zero.

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

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

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

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

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

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

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

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

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

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

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

{- | Checks that we have a valid 'PMintValue'. The underlying map must be
sorted, must not include an ADA entry, and must not contain any empty token maps
or tokens with zero quantities.

@since 3.6.0
-}
instance PValidateData PMintValue where
  pwithValidated :: forall (s :: S).
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated Term s PData
opq Term s r
x =
    forall (a :: S -> Type) (s :: S).
PValidateData a =>
Term s PData -> forall (r :: S -> Type). Term s r -> Term s r
pwithValidated @PSortedValue Term s PData
opq (Term s r -> Term s r) -> Term s r -> Term s r
forall a b. (a -> b) -> a -> b
$
      Term s PSortedValue
-> (Term s PSortedValue -> Term s r) -> Term s r
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s a -> (Term s a -> Term s b) -> Term s b
plet (Term s (PAsData PSortedValue) -> Term s PSortedValue
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (Term s (PAsData PSortedValue) -> Term s PSortedValue)
-> Term s (PAsData PSortedValue) -> Term s PSortedValue
forall a b. (a -> b) -> a -> b
$ forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce @(PAsData PSortedValue) Term s PData
opq) ((Term s PSortedValue -> Term s r) -> Term s r)
-> (Term s PSortedValue -> Term s r) -> Term s r
forall a b. (a -> b) -> a -> b
$ \Term s PSortedValue
value ->
        Term s PBool -> Term s r -> Term s r -> Term s r
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
          ((Term s (PSortedValue :--> PBool)
forall (s :: S). Term s (PSortedValue :--> PBool)
phasAdaEntry Term s (PSortedValue :--> PBool)
-> Term s PSortedValue -> Term s PBool
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PSortedValue
value) Term s PBool -> Term s PBool -> Term s PBool
forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
#|| (Term s (PRawValue :--> PBool)
forall (s :: S). Term s (PRawValue :--> PBool)
phasZeroTokenQuantities 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 PSortedValue -> Term s PRawValue
forall (s :: S). Term s PSortedValue -> Term s PRawValue
pforgetSorted Term s PSortedValue
value))
          Term s r
forall (s :: S) (a :: S -> Type). Term s a
perror
          Term s r
x

{- | Construct an empty 'PMintValue'.

@since 3.6.0
-}
pemptyMintValue :: forall (s :: S). Term s PMintValue
pemptyMintValue :: forall (s :: S). Term s PMintValue
pemptyMintValue = Term s (PInner PMintValue) -> Term s PMintValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast Term s (PInner PMintValue)
Term s PSortedValue
forall (s :: S). Term s PSortedValue
pemptySortedValue

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

= Important note

If the quantity is zero, or if the provided currency symbol is the Ada symbol,
the result is an empty 'PMintValue'.

@since 3.6.0
-}
psingletonMintValue ::
  forall (s :: S).
  Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PMintValue)
psingletonMintValue :: forall (s :: S).
Term
  s
  (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PMintValue)))
psingletonMintValue =
  (forall (s :: S).
 Term
   s
   (PCurrencySymbol
    :--> (PTokenName :--> (PInteger :--> PMintValue))))
-> Term
     s
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PMintValue)))
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 :--> PMintValue))))
 -> Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PMintValue))))
-> (forall (s :: S).
    Term
      s
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PMintValue))))
-> Term
     s
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PMintValue)))
forall a b. (a -> b) -> a -> b
$
    (Term s' PCurrencySymbol
 -> Term s' PTokenName -> Term s' PInteger -> Term s' PMintValue)
-> Term
     s'
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PMintValue)))
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' PMintValue)
-> Term s' (c :--> (PTokenName :--> (PInteger :--> PMintValue)))
plam ((Term s' PCurrencySymbol
  -> Term s' PTokenName -> Term s' PInteger -> Term s' PMintValue)
 -> Term
      s'
      (PCurrencySymbol
       :--> (PTokenName :--> (PInteger :--> PMintValue))))
-> (Term s' PCurrencySymbol
    -> Term s' PTokenName -> Term s' PInteger -> Term s' PMintValue)
-> Term
     s'
     (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PMintValue)))
forall a b. (a -> b) -> a -> b
$ \Term s' PCurrencySymbol
symbol Term s' PTokenName
token Term s' PInteger
amount ->
      Term s' PBool
-> Term s' PMintValue -> Term s' PMintValue -> Term s' PMintValue
forall (a :: S -> Type) (s :: S).
Term s PBool -> Term s a -> Term s a -> Term s a
pif
        (Term s' 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 Term s' PBool -> Term s' PBool -> Term s' PBool
forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
#|| Term s' PCurrencySymbol
symbol Term s' PCurrencySymbol -> Term s' PCurrencySymbol -> Term s' PBool
forall (s :: S).
Term s PCurrencySymbol -> Term s PCurrencySymbol -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s' PCurrencySymbol
forall (s :: S). Term s PCurrencySymbol
padaSymbol)
        Term s' PMintValue
forall a. Monoid a => a
mempty
        ( Term s' (PInner PMintValue) -> Term s' PMintValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s' (PInner PMintValue) -> Term s' PMintValue)
-> Term s' (PInner PMintValue) -> Term s' PMintValue
forall a b. (a -> b) -> a -> b
$
            Term
  s'
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
forall (s :: S).
Term
  s
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
psingletonSortedValue Term
  s'
  (PCurrencySymbol
   :--> (PTokenName :--> (PInteger :--> PSortedValue)))
-> Term s' PCurrencySymbol
-> Term s' (PTokenName :--> (PInteger :--> PSortedValue))
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PCurrencySymbol
symbol Term s' (PTokenName :--> (PInteger :--> PSortedValue))
-> Term s' PTokenName -> Term s' (PInteger :--> PSortedValue)
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PTokenName
token Term s' (PInteger :--> PSortedValue)
-> Term s' PInteger -> Term s' PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
# Term s' PInteger
amount
        )

{- Convert a 'PSortedValue' to a 'PMintValue', ensuring no Ada entry and
non-zero token quantities.

@since 3.5.0
-}
ptoMintValue :: forall (s :: S). Term s (PSortedValue :--> PMintValue)
ptoMintValue :: forall (s :: S). Term s (PSortedValue :--> PMintValue)
ptoMintValue = (Term s PSortedValue -> Term s PMintValue)
-> Term s (PSortedValue :--> PMintValue)
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 PMintValue) -> Term s (c :--> PMintValue)
plam (Term s (PInner PMintValue) -> Term s PMintValue
Term s PSortedValue -> Term s PMintValue
forall (s :: S) (a :: S -> Type). Term s (PInner a) -> Term s a
punsafeDowncast (Term s PSortedValue -> Term s PMintValue)
-> (Term s PSortedValue -> Term s PSortedValue)
-> Term s PSortedValue
-> Term s PMintValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term s (PSortedValue :--> PSortedValue)
-> Term s PSortedValue -> Term s PSortedValue
forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (a :--> b) -> Term s a -> Term s b
papp Term s (PSortedValue :--> PSortedValue)
forall (s :: S). Term s (PSortedValue :--> PSortedValue)
pnormalizeNoAdaNonZeroTokens)