Struct FungibleToken

Source
pub struct FungibleToken {
    pub accounts: LookupMap<AccountId, Balance>,
    pub total_supply: Balance,
    pub account_storage_usage: StorageUsage,
}
Expand description

Implementation of a FungibleToken standard. Allows to include NEP-141 compatible token to any contract. There are next traits that any contract may implement: - FungibleTokenCore – interface with ft_transfer methods. FungibleToken provides methods for it. - FungibleTokenMetaData – return metadata for the token in NEP-148, up to contract to implement. - StorageManager – interface for NEP-145 for allocating storage per account. FungibleToken provides methods for it. - AccountRegistrar – interface for an account to register and unregister

For example usage, see examples/fungible-token/src/lib.rs.

Fields§

§accounts: LookupMap<AccountId, Balance>

AccountID -> Account balance.

§total_supply: Balance

Total supply of the all token.

§account_storage_usage: StorageUsage

The storage size in bytes for one account.

Implementations§

Source§

impl FungibleToken

Source

pub fn new<S>(prefix: S) -> Self
where S: IntoStorageKey,

Source

pub fn internal_unwrap_balance_of(&self, account_id: &AccountId) -> Balance

Source

pub fn internal_deposit(&mut self, account_id: &AccountId, amount: Balance)

Source

pub fn internal_withdraw(&mut self, account_id: &AccountId, amount: Balance)

Source

pub fn internal_transfer( &mut self, sender_id: &AccountId, receiver_id: &AccountId, amount: Balance, memo: Option<String>, )

Source

pub fn internal_register_account(&mut self, account_id: &AccountId)

Source§

impl FungibleToken

Source

pub fn internal_ft_resolve_transfer( &mut self, sender_id: &AccountId, receiver_id: AccountId, amount: U128, ) -> (u128, u128)

Internal method that returns the amount of burned tokens in a corner case when the sender has deleted (unregistered) their account while the ft_transfer_call was still in flight. Returns (Used token amount, Burned token amount)

Source§

impl FungibleToken

Source

pub fn internal_storage_unregister( &mut self, force: Option<bool>, ) -> Option<(AccountId, Balance)>

Internal method that returns the Account ID and the balance in case the account was unregistered.

Trait Implementations§

Source§

impl BorshDeserialize for FungibleToken

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSchema for FungibleToken

Source§

fn declaration() -> Declaration

Get the name of the type without brackets.
Source§

fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )

Recursively, using DFS, add type definitions required for this type. Type definition partially explains how to serialize/deserialize a type.
Source§

impl BorshSerialize for FungibleToken

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl FungibleTokenCore for FungibleToken

Source§

fn ft_transfer( &mut self, receiver_id: AccountId, amount: U128, memo: Option<String>, )

Transfers positive amount of tokens from the env::predecessor_account_id to receiver_id. Both accounts must be registered with the contract for transfer to succeed. (See NEP-145) This method must to be able to accept attached deposits, and must not panic on attached deposit. Exactly 1 yoctoNEAR must be attached. See the Security section of the standard. Read more
Source§

fn ft_transfer_call( &mut self, receiver_id: AccountId, amount: U128, memo: Option<String>, msg: String, ) -> PromiseOrValue<U128>

Transfers positive amount of tokens from the env::predecessor_account_id to receiver_id account. Then calls ft_on_transfer method on receiver_id contract and attaches a callback to resolve this transfer. ft_on_transfer method must return the amount of tokens unused by the receiver contract, the remaining tokens must be refunded to the predecessor_account_id at the resolve transfer callback. Read more
Source§

fn ft_total_supply(&self) -> U128

Returns the total supply of the token in a decimal string representation.
Source§

fn ft_balance_of(&self, account_id: AccountId) -> U128

Returns the balance of the account. If the account doesn’t exist must returns "0".
Source§

impl FungibleTokenResolver for FungibleToken

Source§

fn ft_resolve_transfer( &mut self, sender_id: AccountId, receiver_id: AccountId, amount: U128, ) -> U128

Source§

impl StorageManagement for FungibleToken

Source§

fn storage_withdraw(&mut self, amount: Option<NearToken>) -> StorageBalance

While storage_withdraw normally allows the caller to retrieve available balance, the basic Fungible Token implementation sets storage_balance_bounds.min == storage_balance_bounds.max, which means available balance will always be 0. So this implementation:

  • panics if amount > 0
  • never transfers Ⓝ to caller
  • returns a storage_balance struct if amount is 0
Source§

fn storage_deposit( &mut self, account_id: Option<AccountId>, registration_only: Option<bool>, ) -> StorageBalance

Source§

fn storage_unregister(&mut self, force: Option<bool>) -> bool

Unregisters the predecessor account and returns the storage NEAR deposit back. Read more
Source§

fn storage_balance_bounds(&self) -> StorageBalanceBounds

Source§

fn storage_balance_of(&self, account_id: AccountId) -> Option<StorageBalance>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.