Coin Decimals

It stores information about Coins' decimals to allow protocols to fetch them. The idea is to pass a single argument CoinDecimals to functions that require several sui::coin::CoinMetadata objects.

Structs

Decimals

struct Decimals has store {
    decimals: u8, 
    scalar: u64
}
  • decimals - decimals of a sui::coin

  • scalar - The scalar of a sui::coin's decimals. It is calculated by 10^decimals. E.g. sui::sui has a scalar of 1_000_000_000 or 1e9.

CoinDecimals

struct CoinDecimals has key, store {
    id: UID
}

The Decimals struct is saved in CoinDecimals using dynamic fields.

Interface

new

It creates a new CoinDecimals.

public fun new(ctx: &mut TxContext): CoinDecimals
  • @return CoinDecimals.

contains

Checks if a coin with type CoinType has been added to self.

public fun contains<CoinType>(self: &CoinDecimals): bool
  • @param self A {CoinDecimals} object.

  • @return bool. True if the coin's decimals and scalar are in the self.

decimals

Returns the decimals of a coin with the type CoinType.

public fun decimals<CoinType>(self: &CoinDecimals): u8
  • @param self A CoinDecimals object.

  • @return u8. The decimals of the coin.

Aborts

  • CoinType has not been added to the self.

scalar

Returns the decimals scalar of a coin with type CoinType.

 public fun scalar<CoinType>(self: &CoinDecimals): u64
  • @param self A {CoinDecimals} object.

  • @return u64. The decimal's scalar. It is calculated by 10^decimals.

Aborts

  • CoinType has not been added to the self.

add

Adds the decimals and decimal scalar of a coin with type CoinType to self.

public fun add<CoinType>(self: &mut CoinDecimals, coin_metadata: &CoinMetadata<CoinType>)
  • @param self A CoinDecimals object.

  • @return coin_metadata The sui::coin::CoinMetadata of a coin with type CoinType.

Last updated