axelar-cgp-sui

Module 0xa5::coin_info

Defines the CoinInfo type which allows to store information about a coin: either derived from CoinMetadata or manually provided.

use 0x1::ascii;
use 0x1::option;
use 0x1::string;
use 0x2::coin;
use 0xa5::utils;

Struct CoinInfo

struct CoinInfo<T> has store
Fields
name: string::String
symbol: ascii::String
decimals: u8
remote_decimals: u8
metadata: option::Option<coin::CoinMetadata<T>>

Function from_info

Create a new coin info from the given name, symbol and decimals.

public fun from_info<T>(name: string::String, symbol: ascii::String, decimals: u8, remote_decimals: u8): coin_info::CoinInfo<T>
Implementation
public fun from_info<T>(
    name: String,
    symbol: ascii::String,
    decimals: u8,
    remote_decimals: u8,
): CoinInfo<T> {
    CoinInfo {
        name,
        symbol,
        decimals,
        remote_decimals,
        metadata: option::none(),
    }
}

Function from_metadata

Create a new coin info from the given CoinMetadata object.

public fun from_metadata<T>(metadata: coin::CoinMetadata<T>, remote_decimals: u8): coin_info::CoinInfo<T>
Implementation
public fun from_metadata<T>(
    metadata: CoinMetadata<T>,
    remote_decimals: u8,
): CoinInfo<T> {
    CoinInfo {
        name: metadata.get_name(),
        symbol: metadata.get_symbol(),
        decimals: metadata.get_decimals(),
        remote_decimals,
        metadata: option::some(metadata),
    }
}

Function name

public fun name<T>(self: &coin_info::CoinInfo<T>): string::String
Implementation
public fun name<T>(self: &CoinInfo<T>): String {
    self.name
}

Function symbol

public fun symbol<T>(self: &coin_info::CoinInfo<T>): ascii::String
Implementation
public fun symbol<T>(self: &CoinInfo<T>): ascii::String {
    self.symbol
}

Function decimals

public fun decimals<T>(self: &coin_info::CoinInfo<T>): u8
Implementation
public fun decimals<T>(self: &CoinInfo<T>): u8 {
    self.decimals
}

Function remote_decimals

public fun remote_decimals<T>(self: &coin_info::CoinInfo<T>): u8
Implementation
public fun remote_decimals<T>(self: &CoinInfo<T>): u8 {
    self.remote_decimals
}

Function scaling

public fun scaling<T>(self: &coin_info::CoinInfo<T>): u256
Implementation
public fun scaling<T>(self: &CoinInfo<T>): u256 {
    utils::pow(10, self.remote_decimals - self.decimals)
}

Function metadata

public fun metadata<T>(self: &coin_info::CoinInfo<T>): &option::Option<coin::CoinMetadata<T>>
Implementation
public fun metadata<T>(self: &CoinInfo<T>): &Option<CoinMetadata<T>> {
    &self.metadata
}