assist/types/token

A Token is a safe type for some asset on Cardano. A Token can be combined with another Token to form Tokens, a list of Token. This should be a safe and clean way to build out the value type inside of datums and redeemers instead of building out the value type directly which could be harmful.

Types

A token type for a safe single policy id and asset name value.

Constructors

  • Token { pid: PolicyId, tkn: AssetName, amt: Int }

A tokens type for a safe value as a list of Tokens.

Alias

Tokens = List<Token>

Functions

add_token_to_value(the_value: Value, token: Token) -> Value

Add a Token type to a Value type. This should be a very safe way to increment a value on a UTxO. The other option is having the redeemer be the general Value type and potentially allow badly formed values to be used.

add_token_to_value(token, this_value)

add_tokens_to_value(the_value: Value, tokens: Tokens) -> Value

Add a list of Token types to a Value type. This should be a very safe way to increment a value on a UTxO. The other option is having the redeemer be the general Value type and potentially allow badly formed values to be used.

add_tokens_to_value(redeemer.tokens, this_value)

addition_only(tokens: Tokens) -> Bool

Check that each token is greater than zero in a list tokens.

token.addition_only(redeemer.tokens)

contains(target: Tokens, total: Tokens) -> Bool

Check if a target list of tokens exist inside another list of tokens. The token amount must be greater than or equal to the target amount. If nothing is found then it returns False.

token.contains(target, total)

divide(token: Token, n: Int) -> Token

Divide a token by some integer. The divisor must be positive. This is integer division so the token amount will be rounded towards negative infinity.

token.divide(that_token, 2)

exists(target: Token, total: Tokens) -> Bool

Check if a Token exists in a list of Tokens. The amount has to be greater than or equal to the target.

token.exists(target_token, total_tokens)

from_value(v: Value) -> Tokens

Convert a value into a list of tokens. This conversation is a fast way to be able to do multiplication on a value.

token.from_value(this_value)

multiply(token: Token, n: Int) -> Token

Multiply a token by some integer. This linearly scales the token amount on the token.

token.multiply(that_token, 4)

negate(tokens: Tokens) -> Tokens

Negate all the tokens in the list.

token.negate(these_tokens)

negative(tkn: Token) -> Token

Give the negative of a token.

token.negative(this_token)

subtraction_only(tokens: Tokens) -> Bool

Check that each token is less than zero in a list tokens.

token.subtraction_only(redeemer.tokens)
Search Document