Evolve provides interface standards for common patterns.
The standard interface for fungible tokens:
pub trait FungibleAsset {
/// Get total supply
fn total_supply(&self, env: &impl Env) -> SdkResult<u128>;
/// Get balance of account
fn balance_of(&self, env: &impl Env, account: AccountId) -> SdkResult<u128>;
/// Transfer tokens
fn transfer(
&self,
env: &impl Env,
to: AccountId,
amount: u128,
) -> SdkResult<()>;
/// Transfer from another account (with allowance)
fn transfer_from(
&self,
env: &impl Env,
from: AccountId,
to: AccountId,
amount: u128,
) -> SdkResult<()>;
/// Approve spender
fn approve(
&self,
env: &impl Env,
spender: AccountId,
amount: u128,
) -> SdkResult<()>;
/// Get allowance
fn allowance(
&self,
env: &impl Env,
owner: AccountId,
spender: AccountId,
) -> SdkResult<u128>;
}The standard interface for account authentication:
pub trait Authentication {
/// Verify a signature
fn verify(
&self,
env: &impl Env,
message: &[u8],
signature: &[u8],
) -> SdkResult<bool>;
/// Get the public key
fn public_key(&self, env: &impl Env) -> SdkResult<Vec<u8>>;
}use evolve_standards::FungibleAsset;
#[account_impl(MyToken)]
pub mod my_token {
// Implement standard methods
#[query]
fn total_supply(env: &impl Env) -> SdkResult<u128> {
TOTAL_SUPPLY.get(env)?.ok_or(ERR_NOT_INITIALIZED)
}
#[query]
fn balance_of(env: &impl Env, account: AccountId) -> SdkResult<u128> {
Ok(BALANCES.get(env, account)?.unwrap_or(0))
}
#[exec]
fn transfer(env: &impl Env, to: AccountId, amount: u128) -> SdkResult<()> {
// Implementation
}
// ... other methods
}// Call any token that implements FungibleAsset
let balance: u128 = env.do_query(
token_id,
&BalanceOfMsg { account: user },
)?;- Interoperability - Modules can interact without knowing implementations
- Composability - Build complex systems from standard components
- Tooling - Wallets and explorers can work with any compliant token
- Testing - Mock implementations for testing