referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::tokens::fungibles::Balanced

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,
    ) -> Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit> { ... }
    fn issue(
        asset: Self::AssetId,
        amount: Self::Balance,
    ) -> Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt> { ... }
    fn pair(
        asset: Self::AssetId,
        amount: Self::Balance,
    ) -> Result<(Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>), DispatchError> { ... }
    fn deposit(
        asset: Self::AssetId,
        who: &AccountId,
        value: Self::Balance,
        precision: Precision,
    ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, DispatchError> { ... }
    fn withdraw(
        asset: Self::AssetId,
        who: &AccountId,
        value: Self::Balance,
        precision: Precision,
        preservation: Preservation,
        force: Fortitude,
    ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, DispatchError> { ... }
    fn resolve(
        who: &AccountId,
        credit: Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>,
    ) -> Result<(), Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>> { ... }
    fn settle(
        who: &AccountId,
        debt: Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>,
        preservation: Preservation,
    ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>> { ... }
    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§

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

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

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§

fn rescind( asset: Self::AssetId, amount: Self::Balance, ) -> Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>

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( asset: Self::AssetId, amount: Self::Balance, ) -> Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>

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 pair( asset: Self::AssetId, amount: Self::Balance, ) -> Result<(Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>), 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.

fn deposit( asset: Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, 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.

fn withdraw( asset: Self::AssetId, who: &AccountId, value: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, 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.

fn resolve( who: &AccountId, credit: Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, ) -> Result<(), Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>>

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.

fn settle( who: &AccountId, debt: Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, preservation: Preservation, ) -> Result<Imbalance<Self::AssetId, Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, Imbalance<Self::AssetId, Self::Balance, Self::OnDropDebt, Self::OnDropCredit>>

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.

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, )

Object Safety§

This trait is not object safe.

Implementors§

§

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

§

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>

§

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

§

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>