> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canton.network/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# Splice.Amulet.TokenApiUtils

> Documentation for Splice.Amulet.TokenApiUtils

Common utilities for implementing the token APIs for Amulet.

## Typeclasses

**class** ToAnyValue a **where**

> Values that can be converted to AnyValue
>
> toAnyValue
> : a -> AnyValue
>
> **instance** ToAnyValue TimeLock
>
> **instance** ToAnyValue [Bool](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-bool-66265)
>
> **instance** ToAnyValue [Decimal](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-decimal-18135)
>
> **instance** ToAnyValue [Int](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-int-37261)
>
> **instance** ToAnyValue [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)
>
> **instance** ToAnyValue ([ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t)
>
> **instance** ToAnyValue [Date](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-date-32253)
>
> **instance** ToAnyValue [Party](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-party-57932)
>
> **instance** ToAnyValue [Time](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-time-63886)
>
> **instance** ToAnyValue [RelTime](https://docs.canton.network/appdev/reference/daml-standard-library/da-time.md#type-da-time-types-reltime-23082)
>
> **instance** ToAnyValue ChoiceContext
>
> **instance** ToAnyValue a => ToAnyValue \[a]

**class** FromAnyValue a **where**

> Attempt to parse a value from AnyValue.
>
> If a type implements both `ToAnyValue` and `FromAnyValue` then it must hold that `fromAnyValue (toAnyValue x) = Right x` for all `x`.
>
> fromAnyValue
> : AnyValue -> [Either](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-types-either-56020) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) a
>
> **instance** FromAnyValue TimeLock
>
> **instance** FromAnyValue [Bool](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-bool-66265)
>
> **instance** FromAnyValue [Decimal](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-decimal-18135)
>
> **instance** FromAnyValue [Int](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-int-37261)
>
> **instance** FromAnyValue [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)
>
> **instance** [Template](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-template-functions-template-31804) t => FromAnyValue ([ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t)
>
> **instance** FromAnyValue [Date](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-date-32253)
>
> **instance** FromAnyValue [Party](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-party-57932)
>
> **instance** FromAnyValue [Time](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-time-63886)
>
> **instance** FromAnyValue [RelTime](https://docs.canton.network/appdev/reference/daml-standard-library/da-time.md#type-da-time-types-reltime-23082)
>
> **instance** FromAnyValue ChoiceContext
>
> **instance** FromAnyValue a => FromAnyValue \[a]

## Orphan Typeclass Instances

**instance** [Semigroup](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-prelude-semigroup-78998) Metadata

**instance** [Monoid](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-prelude-monoid-6742) Metadata

## Data Types

**data** TxKind

> Internal type for the transaction kind.
>
> TxKind\_Transfer
>
> TxKind\_Unlock
>
> TxKind\_MergeSplit
>
> TxKind\_Burn
>
> TxKind\_Mint
>
> TxKind\_ExpireDust
>
> **instance** [Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) TxKind

## Functions

splicePrefix
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

amuletPrefix
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

amuletInstrumentId
: [Party](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-party-57932) -> InstrumentId

Shared definition of the instrument-id used for amulets.

optionalMetadata
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> (a -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Add an optional metadata entry.

nonZeroMetadata
: ([Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) a, [Additive](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-num-additive-25881) a, [Show](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-show-show-65360) a) => [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> a -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Add an metadata entry if it is non-zero number.

optionalNonZeroMetadata
: ([Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) a, [Additive](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-num-additive-25881) a, [Show](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-show-show-65360) a) => [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Add an metadata entry for an optional value if it is non-zero number.

createdInRoundMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

ratePerRoundMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

svRewardAmountMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

appRewardAmountMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

unclaimedActivityRecordAmountMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

validatorRewardAmountMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

appRewardBeneficiariesMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

appRewardBeneficiaryWeightsMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

developmentFundAmountMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

reasonMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Short, human-readable reason for the transaction.

txKindMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Kind of the transaction.

senderMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

The sender of a transfer.

burnedMetaKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

The amount of token holdings burned as part of a transaction.

holdingTxMeta
: TxKind -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) [Party](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-party-57932) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) [Decimal](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-decimal-18135) -> Metadata

Build the metadata for a transaction affecting the amulet holdings.

txKindToText
: TxKind -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Exported for testing only

simpleHoldingTxMeta
: TxKind -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) [Decimal](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-decimal-18135) -> Metadata

Simplified version for a few of the common cases.

externalPartyConfigStateContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

featuredAppRightContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

transferPreapprovalContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

lockContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

The key used to embed all the lock specification in the choice context.

lockExpiresAtContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

lockHoldersContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

lockContextContextKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

The context description of a lock.

expireLockKey
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)

Key used to signal to a choice whether an expired locked amulet should be unlocked.

beneficiariesFromMetadata
: Metadata -> [Either](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-types-either-56020) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) ([Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) \[AppRewardBeneficiary])

parseCommaSeparated
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> ([Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a) -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Either](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-types-either-56020) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) \[a]

addOptionalAnyValue
: ToAnyValue a => [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) AnyValue -> [TextMap](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-textmap-11691) AnyValue

Convenience function to create maps that contain an optional value if it is set. See its use sites for examples.

lookupFromContext
: FromAnyValue a => ChoiceContext -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Either](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-types-either-56020) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) ([Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a)

Lookup and decode a value within a choice context.

getFromContext
: FromAnyValue a => ChoiceContext -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Either](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-types-either-56020) [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) a

Get a value from a choice context, failing if it is not present or fails to parse.

lookupFromContextU
: FromAnyValue a => ChoiceContext -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) ([Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a)

Convenience version of `lookupFromContext` that raises the failure within the `Update`.

getFromContextU
: FromAnyValue a => ChoiceContext -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) a

Convenience version of `getFromContext` that raises the failure within the `Update`.
