pub trait Currency<AccountId> {
    type Balance: Balance + MaybeSerializeDeserialize;
    type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance>;
    type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance>;

Show 21 methods // Required methods fn total_balance(who: &AccountId) -> Self::Balance; fn can_slash(who: &AccountId, value: Self::Balance) -> bool; fn total_issuance() -> Self::Balance; fn minimum_balance() -> Self::Balance; fn burn(amount: Self::Balance) -> Self::PositiveImbalance; fn issue(amount: Self::Balance) -> Self::NegativeImbalance; fn free_balance(who: &AccountId) -> Self::Balance; fn ensure_can_withdraw( who: &AccountId, _amount: Self::Balance, reasons: WithdrawReasons, new_balance: Self::Balance ) -> Result<(), DispatchError>; fn transfer( source: &AccountId, dest: &AccountId, value: Self::Balance, existence_requirement: ExistenceRequirement ) -> Result<(), DispatchError>; fn slash( who: &AccountId, value: Self::Balance ) -> (Self::NegativeImbalance, Self::Balance); fn deposit_into_existing( who: &AccountId, value: Self::Balance ) -> Result<Self::PositiveImbalance, DispatchError>; fn deposit_creating( who: &AccountId, value: Self::Balance ) -> Self::PositiveImbalance; fn withdraw( who: &AccountId, value: Self::Balance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<Self::NegativeImbalance, DispatchError>; fn make_free_balance_be( who: &AccountId, balance: Self::Balance ) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>; // Provided methods fn active_issuance() -> Self::Balance { ... } fn deactivate(_: Self::Balance) { ... } fn reactivate(_: Self::Balance) { ... } fn pair( amount: Self::Balance ) -> (Self::PositiveImbalance, Self::NegativeImbalance) { ... } fn resolve_into_existing( who: &AccountId, value: Self::NegativeImbalance ) -> Result<(), Self::NegativeImbalance> { ... } fn resolve_creating(who: &AccountId, value: Self::NegativeImbalance) { ... } fn settle( who: &AccountId, value: Self::PositiveImbalance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<(), Self::PositiveImbalance> { ... }
}
Expand description

Abstraction over a fungible assets system.

Required Associated Types§

type Balance: Balance + MaybeSerializeDeserialize

The balance of an account.

type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance>

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.

type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance>

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§

fn total_balance(who: &AccountId) -> Self::Balance

The combined balance of who.

fn can_slash(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.

fn total_issuance() -> Self::Balance

The total amount of issuance in the system.

fn minimum_balance() -> Self::Balance

The minimum balance any single account may have. This is equivalent to the Balances module’s ExistentialDeposit.

fn burn(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.

fn issue(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.

fn free_balance(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.

fn ensure_can_withdraw( who: &AccountId, _amount: Self::Balance, reasons: WithdrawReasons, new_balance: Self::Balance ) -> Result<(), DispatchError>

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.

fn transfer( source: &AccountId, dest: &AccountId, value: Self::Balance, existence_requirement: ExistenceRequirement ) -> Result<(), DispatchError>

Transfer some liquid free balance to another staker.

This is a very high-level function. It will ensure no imbalance in the system remains.

fn slash( 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.

fn deposit_into_existing( 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.

fn deposit_creating( 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.

fn withdraw( 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.

fn make_free_balance_be( 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§

fn active_issuance() -> Self::Balance

The total amount of issuance in the system excluding those which are controlled by the system.

fn deactivate(_: Self::Balance)

Reduce the active issuance by some amount.

fn reactivate(_: Self::Balance)

Increase the active issuance by some amount, up to the outstanding amount reduced.

fn pair( 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.

fn resolve_into_existing( who: &AccountId, value: Self::NegativeImbalance ) -> Result<(), Self::NegativeImbalance>

Similar to deposit_creating, only accepts a NegativeImbalance and returns nothing on success.

fn resolve_creating(who: &AccountId, value: Self::NegativeImbalance)

Similar to deposit_creating, only accepts a NegativeImbalance and returns nothing on success.

fn settle( who: &AccountId, value: Self::PositiveImbalance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<(), Self::PositiveImbalance>

Similar to withdraw, only accepts a PositiveImbalance and returns nothing on success.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<AccountId> Currency<AccountId> for ()

§

type Balance = u32

§

type PositiveImbalance = ()

§

type NegativeImbalance = ()

§

fn total_balance(_: &AccountId) -> <() as Currency<AccountId>>::Balance

§

fn can_slash(_: &AccountId, _: <() as Currency<AccountId>>::Balance) -> bool

§

fn total_issuance() -> <() as Currency<AccountId>>::Balance

§

fn minimum_balance() -> <() as Currency<AccountId>>::Balance

§

fn burn( _: <() as Currency<AccountId>>::Balance ) -> <() as Currency<AccountId>>::PositiveImbalance

§

fn issue( _: <() as Currency<AccountId>>::Balance ) -> <() as Currency<AccountId>>::NegativeImbalance

§

fn pair( _: <() as Currency<AccountId>>::Balance ) -> (<() as Currency<AccountId>>::PositiveImbalance, <() as Currency<AccountId>>::NegativeImbalance)

§

fn free_balance(_: &AccountId) -> <() as Currency<AccountId>>::Balance

§

fn ensure_can_withdraw( _: &AccountId, _: <() as Currency<AccountId>>::Balance, _: WithdrawReasons, _: <() as Currency<AccountId>>::Balance ) -> Result<(), DispatchError>

§

fn transfer( _: &AccountId, _: &AccountId, _: <() as Currency<AccountId>>::Balance, _: ExistenceRequirement ) -> Result<(), DispatchError>

§

fn slash( _: &AccountId, _: <() as Currency<AccountId>>::Balance ) -> (<() as Currency<AccountId>>::NegativeImbalance, <() as Currency<AccountId>>::Balance)

§

fn deposit_into_existing( _: &AccountId, _: <() as Currency<AccountId>>::Balance ) -> Result<<() as Currency<AccountId>>::PositiveImbalance, DispatchError>

§

fn resolve_into_existing( _: &AccountId, _: <() as Currency<AccountId>>::NegativeImbalance ) -> Result<(), <() as Currency<AccountId>>::NegativeImbalance>

§

fn deposit_creating( _: &AccountId, _: <() as Currency<AccountId>>::Balance ) -> <() as Currency<AccountId>>::PositiveImbalance

§

fn resolve_creating( _: &AccountId, _: <() as Currency<AccountId>>::NegativeImbalance )

§

fn withdraw( _: &AccountId, _: <() as Currency<AccountId>>::Balance, _: WithdrawReasons, _: ExistenceRequirement ) -> Result<<() as Currency<AccountId>>::NegativeImbalance, DispatchError>

§

fn settle( _: &AccountId, _: <() as Currency<AccountId>>::PositiveImbalance, _: WithdrawReasons, _: ExistenceRequirement ) -> Result<(), <() as Currency<AccountId>>::PositiveImbalance>

§

fn make_free_balance_be( _: &AccountId, _: <() as Currency<AccountId>>::Balance ) -> SignedImbalance<<() as Currency<AccountId>>::Balance, <() as Currency<AccountId>>::PositiveImbalance>

§

impl<T, I> Currency<<T as Config>::AccountId> for Pallet<T, I>
where T: Config<I>, I: 'static, <T as Config<I>>::Balance: MaybeSerializeDeserialize + Debug,

§

fn slash( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> (<Pallet<T, I> as Currency<<T as Config>::AccountId>>::NegativeImbalance, <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance)

Slash a target account who, returning the negative imbalance created and any left over amount that could not be slashed.

Is a no-op if value to be slashed is zero or the account does not exist.

NOTE: slash() prefers free balance, but assumes that reserve balance can be drawn from in extreme circumstances. can_slash() should be used prior to slash() to avoid having to draw from reserved funds, however we err on the side of punishment if things are inconsistent or can_slash wasn’t used appropriately.

§

fn deposit_into_existing( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> Result<<Pallet<T, I> as Currency<<T as Config>::AccountId>>::PositiveImbalance, DispatchError>

Deposit some value into the free balance of an existing target account who.

Is a no-op if the value to be deposited is zero.

§

fn deposit_creating( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::PositiveImbalance

Deposit some value into the free balance of who, possibly creating a new account.

This function is a no-op if:

  • the value to be deposited is zero; or
  • the value to be deposited is less than the required ED and the account does not yet exist; or
  • the deposit would necessitate the account to exist and there are no provider references; or
  • value is so large it would cause the balance of who to overflow.
§

fn withdraw( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance, reasons: WithdrawReasons, liveness: ExistenceRequirement ) -> Result<<Pallet<T, I> as Currency<<T as Config>::AccountId>>::NegativeImbalance, DispatchError>

Withdraw some free balance from an account, respecting existence requirements.

Is a no-op if value to be withdrawn is zero.

§

fn make_free_balance_be( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> SignedImbalance<<Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance, <Pallet<T, I> as Currency<<T as Config>::AccountId>>::PositiveImbalance>

Force the new free balance of a target account who to some new value balance.

§

type Balance = <T as Config<I>>::Balance

§

type PositiveImbalance = PositiveImbalance<T, I>

§

type NegativeImbalance = NegativeImbalance<T, I>

§

fn total_balance( who: &<T as Config>::AccountId ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance

§

fn can_slash( who: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> bool

§

fn total_issuance( ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance

§

fn active_issuance( ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance

§

fn deactivate( amount: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance )

§

fn reactivate( amount: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance )

§

fn minimum_balance( ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance

§

fn burn( amount: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::PositiveImbalance

§

fn issue( amount: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::NegativeImbalance

§

fn free_balance( who: &<T as Config>::AccountId ) -> <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance

§

fn ensure_can_withdraw( who: &<T as Config>::AccountId, amount: <T as Config<I>>::Balance, _reasons: WithdrawReasons, new_balance: <T as Config<I>>::Balance ) -> Result<(), DispatchError>

§

fn transfer( transactor: &<T as Config>::AccountId, dest: &<T as Config>::AccountId, value: <Pallet<T, I> as Currency<<T as Config>::AccountId>>::Balance, existence_requirement: ExistenceRequirement ) -> Result<(), DispatchError>

Implementors§