pub trait StellarAssetInterface {
Show 16 methods
// Required methods
fn allowance(env: Env, from: Address, spender: Address) -> i128;
fn approve(
env: Env,
from: Address,
spender: Address,
amount: i128,
expiration_ledger: u32,
);
fn balance(env: Env, id: Address) -> i128;
fn transfer(env: Env, from: Address, to: MuxedAddress, amount: i128);
fn transfer_from(
env: Env,
spender: Address,
from: Address,
to: Address,
amount: i128,
);
fn burn(env: Env, from: Address, amount: i128);
fn burn_from(env: Env, spender: Address, from: Address, amount: i128);
fn decimals(env: Env) -> u32;
fn name(env: Env) -> String;
fn symbol(env: Env) -> String;
fn set_admin(env: Env, new_admin: Address);
fn admin(env: Env) -> Address;
fn set_authorized(env: Env, id: Address, authorize: bool);
fn authorized(env: Env, id: Address) -> bool;
fn mint(env: Env, to: Address, amount: i128);
fn clawback(env: Env, from: Address, amount: i128);
}
Expand description
Interface for admin capabilities for Token contracts, such as the Stellar Asset Contract.
Required Methods§
Sourcefn allowance(env: Env, from: Address, spender: Address) -> i128
fn allowance(env: Env, from: Address, spender: Address) -> i128
Returns the allowance for spender
to transfer from from
.
The amount returned is the amount that spender is allowed to transfer out of from’s balance. When the spender transfers amounts, the allowance will be reduced by the amount transferred.
§Arguments
from
- The address holding the balance of tokens to be drawn from.spender
- The address spending the tokens held byfrom
.
Sourcefn approve(
env: Env,
from: Address,
spender: Address,
amount: i128,
expiration_ledger: u32,
)
fn approve( env: Env, from: Address, spender: Address, amount: i128, expiration_ledger: u32, )
Set the allowance by amount
for spender
to transfer/burn from
from
.
The amount set is the amount that spender is approved to transfer out of from’s balance. The spender will be allowed to transfer amounts, and when an amount is transferred the allowance will be reduced by the amount transferred.
§Arguments
from
- The address holding the balance of tokens to be drawn from.spender
- The address being authorized to spend the tokens held byfrom
.amount
- The tokens to be made available tospender
.expiration_ledger
- The ledger number where this allowance expires. Cannot be less than the current ledger number unless the amount is being set to 0. An expired entry (where expiration_ledger < the current ledger number) should be treated as a 0 amount allowance.
§Events
Emits an event with topics ["approve", from: Address, spender: Address], data = [amount: i128, expiration_ledger: u32]
Sourcefn balance(env: Env, id: Address) -> i128
fn balance(env: Env, id: Address) -> i128
Returns the balance of id
.
§Arguments
id
- The address for which a balance is being queried. If the address has no existing balance, returns 0.
Sourcefn transfer(env: Env, from: Address, to: MuxedAddress, amount: i128)
fn transfer(env: Env, from: Address, to: MuxedAddress, amount: i128)
Transfer amount
from from
to to
.
§Arguments
from
- The address holding the balance of tokens which will be withdrawn from.to
- The address which will receive the transferred tokens.amount
- The amount of tokens to be transferred.
§Events
Emits an event with:
- topics
["transfer", from: Address, to: Address]
- data
{ to_muxed_id: Option<u64>, amount: i128 }: Map
Legacy implementations may emit an event with:
- topics
["transfer", from: Address, to: Address]
- data
amount: i128
Sourcefn transfer_from(
env: Env,
spender: Address,
from: Address,
to: Address,
amount: i128,
)
fn transfer_from( env: Env, spender: Address, from: Address, to: Address, amount: i128, )
Transfer amount
from from
to to
, consuming the allowance that
spender
has on from
’s balance. Authorized by spender
(spender.require_auth()
).
The spender will be allowed to transfer the amount from from’s balance if the amount is less than or equal to the allowance that the spender has on the from’s balance. The spender’s allowance on from’s balance will be reduced by the amount.
§Arguments
spender
- The address authorizing the transfer, and having its allowance consumed during the transfer.from
- The address holding the balance of tokens which will be withdrawn from.to
- The address which will receive the transferred tokens.amount
- The amount of tokens to be transferred.
§Events
Emits an event with topics ["transfer", from: Address, to: Address], data = amount: i128
Sourcefn burn(env: Env, from: Address, amount: i128)
fn burn(env: Env, from: Address, amount: i128)
Burn amount
from from
.
Reduces from’s balance by the amount, without transferring the balance to another holder’s balance.
§Arguments
from
- The address holding the balance of tokens which will be burned from.amount
- The amount of tokens to be burned.
§Events
Emits an event with topics ["burn", from: Address], data = amount: i128
Sourcefn burn_from(env: Env, spender: Address, from: Address, amount: i128)
fn burn_from(env: Env, spender: Address, from: Address, amount: i128)
Burn amount
from from
, consuming the allowance of spender
.
Reduces from’s balance by the amount, without transferring the balance to another holder’s balance.
The spender will be allowed to burn the amount from from’s balance, if the amount is less than or equal to the allowance that the spender has on the from’s balance. The spender’s allowance on from’s balance will be reduced by the amount.
§Arguments
spender
- The address authorizing the burn, and having its allowance consumed during the burn.from
- The address holding the balance of tokens which will be burned from.amount
- The amount of tokens to be burned.
§Events
Emits an event with topics ["burn", from: Address], data = amount: i128
Sourcefn decimals(env: Env) -> u32
fn decimals(env: Env) -> u32
Returns the number of decimals used to represent amounts of this token.
§Panics
If the contract has not yet been initialized.
Sets whether the account is authorized to use its balance. If
authorized
is true, id
should be able to use its balance.
§Arguments
id
- The address being (de-)authorized.authorize
- Whether or notid
can use its balance.
§Events
Emits an event with topics ["set_authorized", id: Address], data = [authorize: bool]
Returns true if id
is authorized to use its balance.
§Arguments
id
- The address for which token authorization is being checked.
Sourcefn clawback(env: Env, from: Address, amount: i128)
fn clawback(env: Env, from: Address, amount: i128)
Clawback amount
from from
account. amount
is burned in the
clawback process.
§Arguments
from
- The address holding the balance from which the clawback will take tokens.amount
- The amount of tokens to be clawed back.
§Events
Emits an event with topics ["clawback", admin: Address, to: Address], data = amount: i128
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.