Trait frame_support::traits::tokens::fungibles::Balanced

source ·
pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
    type OnDropDebt: HandleImbalanceDrop<Self::AssetId, Self::Balance>;
    type OnDropCredit: HandleImbalanceDrop<Self::AssetId, Self::Balance>;

    // Provided methods
    fn rescind(
        asset: Self::AssetId,
        amount: Self::Balance,
    ) -> Debt<AccountId, Self> { ... }
    fn issue(
        asset: Self::AssetId,
        amount: Self::Balance,
    ) -> Credit<AccountId, Self> { ... }
    fn pair(
        asset: Self::AssetId,
        amount: Self::Balance,
    ) -> Result<(Debt<AccountId, Self>, Credit<AccountId, Self>), DispatchError> { ... }
    fn deposit(
        asset: Self::AssetId,
        who: &AccountId,
        value: Self::Balance,
        precision: Precision,
    ) -> Result<Debt<AccountId, Self>, DispatchError> { ... }
    fn withdraw(
        asset: Self::AssetId,
        who: &AccountId,
        value: Self::Balance,
        precision: Precision,
        preservation: Preservation,
        force: Fortitude,
    ) -> Result<Credit<AccountId, Self>, DispatchError> { ... }
    fn resolve(
        who: &AccountId,
        credit: Credit<AccountId, Self>,
    ) -> Result<(), Credit<AccountId, Self>> { ... }
    fn settle(
        who: &AccountId,
        debt: Debt<AccountId, Self>,
        preservation: Preservation,
    ) -> Result<Credit<AccountId, Self>, Debt<AccountId, Self>> { ... }
    fn done_rescind(_asset: Self::AssetId, _amount: Self::Balance) { ... }
    fn done_issue(_asset: Self::AssetId, _amount: Self::Balance) { ... }
    fn done_deposit(
        _asset: Self::AssetId,
        _who: &AccountId,
        _amount: Self::Balance,
    ) { ... }
    fn done_withdraw(
        _asset: Self::AssetId,
        _who: &AccountId,
        _amount: Self::Balance,
    ) { ... }
}
Expand description

A fungible token class where any creation and deletion of tokens is semi-explicit and where the total supply is maintained automatically.

This is auto-implemented when a token class has Unbalanced implemented.

Required Associated Types§

source

type OnDropDebt: HandleImbalanceDrop<Self::AssetId, Self::Balance>

The type for managing what happens when an instance of Debt is dropped without being used.

source

type OnDropCredit: HandleImbalanceDrop<Self::AssetId, Self::Balance>

The type for managing what happens when an instance of Credit is dropped without being used.

Provided Methods§

source

fn rescind(asset: Self::AssetId, amount: Self::Balance) -> Debt<AccountId, Self>

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.

source

fn issue(asset: Self::AssetId, amount: Self::Balance) -> Credit<AccountId, Self>

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.

source

fn pair( asset: Self::AssetId, amount: Self::Balance, ) -> Result<(Debt<AccountId, Self>, Credit<AccountId, Self>), DispatchError>

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.

This is infallible, but doesn’t guarantee that the entire amount is used to create the pair, for example in the case where the amounts would cause overflow or underflow in Balanced::issue or Balanced::rescind.

source

fn deposit( asset: Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result<Debt<AccountId, Self>, DispatchError>

Mints value into the account of who, creating it as needed.

If precision is BestEffort and value in full could not be minted (e.g. due to overflow), then the maximum is minted, up to value. If precision is Exact, then exactly value must be minted into the account of who or the operation will fail with an Err and nothing will change.

If the operation is successful, this will return Ok with a Debt of the total value added to the account.

source

fn withdraw( asset: Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result<Credit<AccountId, Self>, DispatchError>

Removes value balance from who account if possible.

If precision is BestEffort and value in full could not be removed (e.g. due to underflow), then the maximum is removed, up to value. If precision is Exact, then exactly value must be removed from the account of who or the operation will fail with an Err and nothing will change.

If the removal is needed but not possible, then it returns Err and nothing is changed. If the account needed to be deleted, then slightly more than value may be removed from the account owning since up to (but not including) minimum balance may also need to be removed.

If the operation is successful, this will return Ok with a Credit of the total value removed from the account.

source

fn resolve( who: &AccountId, credit: Credit<AccountId, Self>, ) -> Result<(), Credit<AccountId, Self>>

The balance of who is increased in order to counter credit. If the whole of credit cannot be countered, then nothing is changed and the original credit is returned in an Err.

Please note: If credit.peek() is less than Self::minimum_balance(), then who must already exist for this to succeed.

source

fn settle( who: &AccountId, debt: Debt<AccountId, Self>, preservation: Preservation, ) -> Result<Credit<AccountId, Self>, Debt<AccountId, Self>>

The balance of who is decreased in order to counter debt. If the whole of debt cannot be countered, then nothing is changed and the original debt is returned in an Err.

source

fn done_rescind(_asset: Self::AssetId, _amount: Self::Balance)

source

fn done_issue(_asset: Self::AssetId, _amount: Self::Balance)

source

fn done_deposit(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance)

source

fn done_withdraw( _asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance, )

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Left: Balanced<AccountId>, Right: Balanced<AccountId, Balance = Left::Balance>, Criterion: Convert<AssetKind, Either<(), Right::AssetId>>, AssetKind: AssetId, AccountId> Balanced<AccountId> for frame_support::traits::tokens::fungible::UnionOf<Left, Right, Criterion, AssetKind, AccountId>

§

type OnDropDebt = ConvertImbalanceDropHandler<<Left as Balanced<AccountId>>::OnDropDebt, <Right as Balanced<AccountId>>::OnDropDebt, Criterion, AssetKind, <Left as Inspect<AccountId>>::Balance, <Right as Inspect<AccountId>>::AssetId, AccountId>

§

type OnDropCredit = ConvertImbalanceDropHandler<<Left as Balanced<AccountId>>::OnDropCredit, <Right as Balanced<AccountId>>::OnDropCredit, Criterion, AssetKind, <Left as Inspect<AccountId>>::Balance, <Right as Inspect<AccountId>>::AssetId, AccountId>

source§

impl<Left: Balanced<AccountId>, Right: Balanced<AccountId, Balance = Left::Balance>, Criterion: Convert<AssetKind, Either<Left::AssetId, Right::AssetId>>, AssetKind: AssetId, AccountId> Balanced<AccountId> for frame_support::traits::tokens::fungibles::UnionOf<Left, Right, Criterion, AssetKind, AccountId>

§

type OnDropDebt = ConvertImbalanceDropHandler<<Left as Balanced<AccountId>>::OnDropDebt, <Right as Balanced<AccountId>>::OnDropDebt, <Left as Inspect<AccountId>>::AssetId, <Right as Inspect<AccountId>>::AssetId, Criterion, AssetKind, <Left as Inspect<AccountId>>::Balance, AccountId>

§

type OnDropCredit = ConvertImbalanceDropHandler<<Left as Balanced<AccountId>>::OnDropCredit, <Right as Balanced<AccountId>>::OnDropCredit, <Left as Inspect<AccountId>>::AssetId, <Right as Inspect<AccountId>>::AssetId, Criterion, AssetKind, <Left as Inspect<AccountId>>::Balance, AccountId>