Trait polkadot_sdk_frame::traits::tokens::fungible::Balanced
pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
type OnDropDebt: HandleImbalanceDrop<Self::Balance>;
type OnDropCredit: HandleImbalanceDrop<Self::Balance>;
// Provided methods
fn rescind(
amount: Self::Balance,
) -> Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit> { ... }
fn issue(
amount: Self::Balance,
) -> Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt> { ... }
fn pair(
amount: Self::Balance,
) -> Result<(Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>), DispatchError> { ... }
fn deposit(
who: &AccountId,
value: Self::Balance,
precision: Precision,
) -> Result<Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, DispatchError> { ... }
fn withdraw(
who: &AccountId,
value: Self::Balance,
precision: Precision,
preservation: Preservation,
force: Fortitude,
) -> Result<Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, DispatchError> { ... }
fn resolve(
who: &AccountId,
credit: Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>,
) -> Result<(), Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>> { ... }
fn settle(
who: &AccountId,
debt: Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>,
preservation: Preservation,
) -> Result<Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>> { ... }
fn done_rescind(_amount: Self::Balance) { ... }
fn done_issue(_amount: Self::Balance) { ... }
fn done_deposit(_who: &AccountId, _amount: Self::Balance) { ... }
fn done_withdraw(_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::Balance>
type OnDropDebt: HandleImbalanceDrop<Self::Balance>
The type for managing what happens when an instance of Debt
is dropped without being used.
type OnDropCredit: HandleImbalanceDrop<Self::Balance>
type OnDropCredit: HandleImbalanceDrop<Self::Balance>
The type for managing what happens when an instance of Credit
is dropped without being
used.
Provided Methods§
fn rescind(
amount: Self::Balance,
) -> Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>
fn rescind( amount: Self::Balance, ) -> Imbalance<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. Balanced::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,
) -> Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>
fn issue( amount: Self::Balance, ) -> Imbalance<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.
Balanced::resolve
.
This is infallible, but doesn’t guarantee that the entire amount
is issued, for example
in the case of overflow.
fn pair(
amount: Self::Balance,
) -> Result<(Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>), DispatchError>
fn pair( amount: Self::Balance, ) -> Result<(Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, Imbalance<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 could fail when we cannot issue and redeem the entire amount
, for example in the
case where the amount would cause overflow or underflow in Balanced::issue
or
Balanced::rescind
.
fn deposit(
who: &AccountId,
value: Self::Balance,
precision: Precision,
) -> Result<Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, DispatchError>
fn deposit( who: &AccountId, value: Self::Balance, precision: Precision, ) -> Result<Imbalance<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(
who: &AccountId,
value: Self::Balance,
precision: Precision,
preservation: Preservation,
force: Fortitude,
) -> Result<Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, DispatchError>
fn withdraw( who: &AccountId, value: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude, ) -> Result<Imbalance<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::Balance, Self::OnDropCredit, Self::OnDropDebt>,
) -> Result<(), Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>>
fn resolve( who: &AccountId, credit: Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, ) -> Result<(), Imbalance<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 Inspect::minimum_balance()
, then who
must
already exist for this to succeed.
fn settle(
who: &AccountId,
debt: Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>,
preservation: Preservation,
) -> Result<Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>>
fn settle( who: &AccountId, debt: Imbalance<Self::Balance, Self::OnDropDebt, Self::OnDropCredit>, preservation: Preservation, ) -> Result<Imbalance<Self::Balance, Self::OnDropCredit, Self::OnDropDebt>, Imbalance<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
.