Trait frame_support::traits::tokens::currency::MultiTokenCurrency
source · pub trait MultiTokenCurrency<AccountId> {
type Balance: Balance + MaybeSerializeDeserialize + Into<u128> + TryFrom<u128>;
type CurrencyId: CurrencyId + MaybeSerializeDeserialize;
type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>;
type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>;
Show 18 methods
// Required methods
fn total_balance(
currency_id: Self::CurrencyId,
who: &AccountId
) -> Self::Balance;
fn can_slash(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> bool;
fn total_issuance(currency_id: Self::CurrencyId) -> Self::Balance;
fn minimum_balance(currency_id: Self::CurrencyId) -> Self::Balance;
fn burn(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> Self::PositiveImbalance;
fn issue(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> Self::NegativeImbalance;
fn free_balance(
currency_id: Self::CurrencyId,
who: &AccountId
) -> Self::Balance;
fn ensure_can_withdraw(
currency_id: Self::CurrencyId,
who: &AccountId,
_amount: Self::Balance,
reasons: WithdrawReasons,
new_balance: Self::Balance
) -> DispatchResult;
fn transfer(
currency_id: Self::CurrencyId,
source: &AccountId,
dest: &AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement
) -> DispatchResult;
fn slash(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance);
fn deposit_into_existing(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> Result<Self::PositiveImbalance, DispatchError>;
fn deposit_creating(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> Self::PositiveImbalance;
fn withdraw(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<Self::NegativeImbalance, DispatchError>;
fn make_free_balance_be(
currency_id: Self::CurrencyId,
who: &AccountId,
balance: Self::Balance
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>;
// Provided methods
fn pair(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> (Self::PositiveImbalance, Self::NegativeImbalance) { ... }
fn resolve_into_existing(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::NegativeImbalance
) -> Result<(), Self::NegativeImbalance> { ... }
fn resolve_creating(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::NegativeImbalance
) { ... }
fn settle(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::PositiveImbalance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<(), Self::PositiveImbalance> { ... }
}
Expand description
Abstraction over a fungible assets system.
Required Associated Types§
sourcetype Balance: Balance + MaybeSerializeDeserialize + Into<u128> + TryFrom<u128>
type Balance: Balance + MaybeSerializeDeserialize + Into<u128> + TryFrom<u128>
The balance of an account. Mangata-node expected Balance to be u128, and uses U256 as higher precision type for arithemthics we should refactor to some HigherPrecisionType trait in those pallets eventually and remove the Into<_>
type CurrencyId: CurrencyId + MaybeSerializeDeserialize
sourcetype PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>
type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>
The opaque token type for an imbalance. This is returned by unbalanced operations and must be dealt with. It may be dropped but cannot be cloned.
sourcetype NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>
type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance> + MultiTokenImbalanceWithZeroTrait<Self::CurrencyId>
The opaque token type for an imbalance. This is returned by unbalanced operations and must be dealt with. It may be dropped but cannot be cloned.
Required Methods§
sourcefn total_balance(
currency_id: Self::CurrencyId,
who: &AccountId
) -> Self::Balance
fn total_balance( currency_id: Self::CurrencyId, who: &AccountId ) -> Self::Balance
The combined balance of who
.
sourcefn can_slash(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> bool
fn can_slash( currency_id: Self::CurrencyId, who: &AccountId, value: Self::Balance ) -> bool
Same result as slash(who, value)
(but without the side-effects)
assuming there are no balance changes in the meantime and only the
reserved balance is not taken into account.
sourcefn total_issuance(currency_id: Self::CurrencyId) -> Self::Balance
fn total_issuance(currency_id: Self::CurrencyId) -> Self::Balance
The total amount of issuance in the system.
sourcefn minimum_balance(currency_id: Self::CurrencyId) -> Self::Balance
fn minimum_balance(currency_id: Self::CurrencyId) -> Self::Balance
The minimum balance any single account may have. This is equivalent to
the Balances
module’s ExistentialDeposit
.
sourcefn burn(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> Self::PositiveImbalance
fn burn( currency_id: Self::CurrencyId, amount: Self::Balance ) -> Self::PositiveImbalance
Reduce the total issuance by amount
and return the according
imbalance. The imbalance will typically be used to reduce an account by
the same amount with e.g. settle
.
This is infallible, but doesn’t guarantee that the entire amount
is
burnt, for example in the case of underflow.
sourcefn issue(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> Self::NegativeImbalance
fn issue( currency_id: Self::CurrencyId, amount: Self::Balance ) -> Self::NegativeImbalance
Increase the total issuance by amount
and return the according
imbalance. The imbalance will typically be used to increase an account
by the same amount with e.g. resolve_into_existing
or
resolve_creating
.
This is infallible, but doesn’t guarantee that the entire amount
is
issued, for example in the case of overflow.
sourcefn free_balance(currency_id: Self::CurrencyId, who: &AccountId) -> Self::Balance
fn free_balance(currency_id: Self::CurrencyId, who: &AccountId) -> Self::Balance
The ‘free’ balance of a given account.
This is the only balance that matters in terms of most operations on
tokens. It alone is used to determine the balance when in the contract
execution environment. When this balance falls below the value of
ExistentialDeposit
, then the ‘current account’ is
deleted: specifically FreeBalance
.
system::AccountNonce
is also deleted if ReservedBalance
is also zero
(it also gets collapsed to zero if it ever becomes less than
ExistentialDeposit
.
sourcefn ensure_can_withdraw(
currency_id: Self::CurrencyId,
who: &AccountId,
_amount: Self::Balance,
reasons: WithdrawReasons,
new_balance: Self::Balance
) -> DispatchResult
fn ensure_can_withdraw( currency_id: Self::CurrencyId, who: &AccountId, _amount: Self::Balance, reasons: WithdrawReasons, new_balance: Self::Balance ) -> DispatchResult
Returns Ok
iff the account is able to make a withdrawal of the given
amount for the given reason. Basically, it’s just a dry-run of
withdraw
.
Err(...)
with the reason why not otherwise.
sourcefn transfer(
currency_id: Self::CurrencyId,
source: &AccountId,
dest: &AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement
) -> DispatchResult
fn transfer( currency_id: Self::CurrencyId, source: &AccountId, dest: &AccountId, value: Self::Balance, existence_requirement: ExistenceRequirement ) -> DispatchResult
Transfer some liquid free balance to another staker.
This is a very high-level function. It will ensure all appropriate fees are paid and no imbalance in the system remains.
sourcefn slash(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance)
fn slash( currency_id: Self::CurrencyId, who: &AccountId, value: Self::Balance ) -> (Self::NegativeImbalance, Self::Balance)
Deducts up to value
from the combined balance of who
, preferring to
deduct from the free balance. This function cannot fail.
The resulting imbalance is the first item of the tuple returned.
As much funds up to value
will be deducted as possible. If this is
less than value
, then a non-zero second item will be returned.
sourcefn deposit_into_existing(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> Result<Self::PositiveImbalance, DispatchError>
fn deposit_into_existing( currency_id: Self::CurrencyId, who: &AccountId, value: Self::Balance ) -> Result<Self::PositiveImbalance, DispatchError>
Mints value
to the free balance of who
.
If who
doesn’t exist, nothing is done and an Err returned.
sourcefn deposit_creating(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance
) -> Self::PositiveImbalance
fn deposit_creating( currency_id: Self::CurrencyId, who: &AccountId, value: Self::Balance ) -> Self::PositiveImbalance
Adds up to value
to the free balance of who
. If who
doesn’t exist,
it is created.
Infallible.
sourcefn withdraw(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<Self::NegativeImbalance, DispatchError>
fn withdraw( currency_id: Self::CurrencyId, who: &AccountId, value: Self::Balance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<Self::NegativeImbalance, DispatchError>
Removes some free balance from who
account for reason
if possible.
If liveness
is KeepAlive
, then no less than ExistentialDeposit
must be left remaining.
This checks any locks, vesting, and liquidity requirements. If the
removal is not possible, then it returns Err
.
If the operation is successful, this will return Ok
with a
NegativeImbalance
whose value is value
.
sourcefn make_free_balance_be(
currency_id: Self::CurrencyId,
who: &AccountId,
balance: Self::Balance
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>
fn make_free_balance_be( currency_id: Self::CurrencyId, who: &AccountId, balance: Self::Balance ) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>
Ensure an account’s free balance equals some value; this will create the account if needed.
Returns a signed imbalance and status to indicate if the account was successfully updated or update has led to killing of the account.
Provided Methods§
sourcefn pair(
currency_id: Self::CurrencyId,
amount: Self::Balance
) -> (Self::PositiveImbalance, Self::NegativeImbalance)
fn pair( currency_id: Self::CurrencyId, amount: Self::Balance ) -> (Self::PositiveImbalance, Self::NegativeImbalance)
Produce a pair of imbalances that cancel each other out exactly.
This is just the same as burning and issuing the same amount and has no effect on the total issuance.
sourcefn resolve_into_existing(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::NegativeImbalance
) -> Result<(), Self::NegativeImbalance>
fn resolve_into_existing( currency_id: Self::CurrencyId, who: &AccountId, value: Self::NegativeImbalance ) -> Result<(), Self::NegativeImbalance>
Similar to deposit_creating, only accepts a NegativeImbalance
and
returns nothing on success.
sourcefn resolve_creating(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::NegativeImbalance
)
fn resolve_creating( currency_id: Self::CurrencyId, who: &AccountId, value: Self::NegativeImbalance )
Similar to deposit_creating, only accepts a NegativeImbalance
and
returns nothing on success.
sourcefn settle(
currency_id: Self::CurrencyId,
who: &AccountId,
value: Self::PositiveImbalance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<(), Self::PositiveImbalance>
fn settle( currency_id: Self::CurrencyId, who: &AccountId, value: Self::PositiveImbalance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<(), Self::PositiveImbalance>
Similar to withdraw, only accepts a PositiveImbalance
and returns
nothing on success.