219 lines
6.3 KiB
Plaintext
219 lines
6.3 KiB
Plaintext
// FUNCTIONS
|
|
|
|
/// Returns the number of decimals used to represent amounts of this token.
|
|
fn decimals() -> Result<u32, Error>;
|
|
|
|
/// Returns the name for this token.
|
|
fn name() -> Result<String, Error>;
|
|
|
|
// Returns the symbol for this token.
|
|
fn symbol() -> Result<String, Error>;
|
|
|
|
// TOKEN INTERFACE
|
|
|
|
/// Returns the allowance for `spender` to transfer from `from`.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `from` - The address holding the balance of tokens to be drawn from.
|
|
/// * `spender` - The address spending the tokens held by `from`.
|
|
fn allowance(e: &Host, from: Address, spender: Address) -> Result<i128, HostError>;
|
|
|
|
/// Set the allowance by `amount` for `spender` to transfer/burn from
|
|
/// `from`.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `from` - The address holding the balance of tokens to be drawn from.
|
|
/// * `spender` - The address being authorized to spend the tokens held by
|
|
/// `from`.
|
|
/// * `amount` - The tokens to be made availabe to `spender`.
|
|
/// * `live_until_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, sep0011_asset: String], data = [amount: i128, live_until_ledger: u32]`
|
|
fn approve(
|
|
e: &Host,
|
|
from: Address,
|
|
spender: Address,
|
|
amount: i128,
|
|
expiration_ledger: u32,
|
|
) -> Result<(), HostError>;
|
|
|
|
/// 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.
|
|
fn balance(env: Env, id: Address) -> i128;
|
|
|
|
/// Returns true if `id` is authorized to use its balance.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `id` - The address for which token authorization is being checked.
|
|
fn authorized(env: Env, id: Address) -> bool;
|
|
|
|
/// 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, sep0011_asset: String],
|
|
/// data = amount: i128`
|
|
fn transfer(env: Env, from: Address, to: Address, amount: i128);
|
|
|
|
/// Transfer `amount` from `from` to `to`, consuming the allowance of
|
|
/// `spender`. Authorized by spender (`spender.require_auth()`).
|
|
///
|
|
/// # 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, sep0011_asset: String],
|
|
/// data = amount: i128`
|
|
fn transfer_from(env: Env, spender: Address, from: Address, to: Address, amount: i128);
|
|
|
|
/// Burn `amount` from `from`.
|
|
///
|
|
/// # 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, sep0011_asset: String], data = amount:
|
|
/// i128`
|
|
fn burn(env: Env, from: Address, amount: i128);
|
|
|
|
/// Burn `amount` from `from`, consuming the allowance of `spender`.
|
|
///
|
|
/// # 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, sep0011_asset: String], data = amount:
|
|
/// i128`
|
|
fn burn_from(env: Env, spender: Address, from: Address, amount: i128);
|
|
|
|
// ADMIN INTERFACE
|
|
/// Sets the administrator to the specified address `new_admin`.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `new_admin` - The address which will henceforth be the administrator
|
|
/// of this token contract.
|
|
///
|
|
/// # Events
|
|
///
|
|
/// Emits an event with topics `["set_admin", admin: Address, sep0011_asset: String], data =
|
|
/// new_admin: Address`
|
|
fn set_admin(env: Env, new_admin: Address);
|
|
|
|
/// Returns the admin of the contract.
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// If the admin is not set.
|
|
fn admin(env: Env) -> Address;
|
|
|
|
/// 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 not `id` can use its balance.
|
|
///
|
|
/// # Events
|
|
///
|
|
/// Emits an event with topics `["set_authorized", admin: Address, id: Address, sep0011_asset: String], data =
|
|
/// authorize: bool`
|
|
fn set_authorized(env: Env, id: Address, authorize: bool);
|
|
|
|
/// Mints `amount` to `to`.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `to` - The address which will receive the minted tokens.
|
|
/// * `amount` - The amount of tokens to be minted.
|
|
///
|
|
/// # Events
|
|
///
|
|
/// Emits an event with topics `["mint", admin: Address, to: Address, sep0011_asset: String], data
|
|
/// = amount: i128`
|
|
fn mint(env: Env, to: 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, from: Address, sep0011_asset: String],
|
|
/// data = amount: i128`
|
|
fn clawback(env: Env, from: Address, amount: i128);
|
|
|
|
// ENUMS
|
|
|
|
/// Keys for the persistent data associated with token users.
|
|
pub enum DataKey {
|
|
Allowance(AllowanceDataKey),
|
|
Balance(Address),
|
|
}
|
|
|
|
/// Keys for token instance data.
|
|
pub enum InstanceDataKey {
|
|
Admin,
|
|
AssetInfo,
|
|
}
|
|
|
|
// STRUCTS
|
|
|
|
pub struct AllowanceDataKey {
|
|
pub from: Address,
|
|
pub spender: Address,
|
|
}
|
|
|
|
pub struct AllowanceValue {
|
|
pub amount: i128,
|
|
pub expiration_ledger: u32,
|
|
}
|
|
|
|
pub struct BalanceValue {
|
|
pub amount: i128,
|
|
pub authorized: bool,
|
|
pub clawback: bool,
|
|
} |