fungible.test.ts.md•20.4 kB
# Snapshot report for `src/fungible.test.ts`
The actual snapshot is saved in `fungible.test.ts.snap`.
Generated by [AVA](https://avajs.dev).
## basic fungible
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
`
## fungible burnable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
␊
//␊
// Extensions␊
//␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleBurnable for MyToken {}␊
`
## fungible pausable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, owner: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
ownable::set_owner(e, &owner);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
#[when_not_paused]␊
fn transfer(e: &Env, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer(e, &from, &to, amount);␊
}␊
␊
#[when_not_paused]␊
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer_from(e, &spender, &from, &to, amount);␊
}␊
}␊
␊
//␊
// Utils␊
//␊
␊
#[contractimpl]␊
impl Pausable for MyToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
␊
#[only_owner]␊
fn pause(e: &Env, caller: Address) {␊
pausable::pause(e);␊
}␊
␊
#[only_owner]␊
fn unpause(e: &Env, caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl Ownable for MyToken {}␊
`
## fungible burnable pausable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, owner: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
ownable::set_owner(e, &owner);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
#[when_not_paused]␊
fn transfer(e: &Env, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer(e, &from, &to, amount);␊
}␊
␊
#[when_not_paused]␊
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer_from(e, &spender, &from, &to, amount);␊
}␊
}␊
␊
//␊
// Extensions␊
//␊
␊
#[contractimpl]␊
impl FungibleBurnable for MyToken {␊
#[when_not_paused]␊
fn burn(e: &Env, from: Address, amount: i128) {␊
Base::burn(e, &from, amount);␊
}␊
␊
#[when_not_paused]␊
fn burn_from(e: &Env, spender: Address, from: Address, amount: i128) {␊
Base::burn_from(e, &spender, &from, amount);␊
}␊
}␊
␊
//␊
// Utils␊
//␊
␊
#[contractimpl]␊
impl Pausable for MyToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
␊
#[only_owner]␊
fn pause(e: &Env, caller: Address) {␊
pausable::pause(e);␊
}␊
␊
#[only_owner]␊
fn unpause(e: &Env, caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl Ownable for MyToken {}␊
`
## fungible preminted
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, recipient: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
Base::mint(e, &recipient, 1000000000000000000000);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
`
## fungible premint of 0
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
`
## fungible mintable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
`
## fungible ownable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::ownable::{self as ownable, Ownable};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, owner: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
ownable::set_owner(e, &owner);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
␊
//␊
// Utils␊
//␊
␊
#[default_impl]␊
#[contractimpl]␊
impl Ownable for MyToken {}␊
`
## fungible roles
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::access_control::{self as access_control, AccessControl};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, admin: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
access_control::set_admin(e, &admin);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
}␊
␊
//␊
// Utils␊
//␊
␊
#[default_impl]␊
#[contractimpl]␊
impl AccessControl for MyToken {}␊
`
## fungible full - ownable
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, recipient: Address, owner: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
Base::mint(e, &recipient, 2000000000000000000000);␊
ownable::set_owner(e, &owner);␊
}␊
␊
#[only_owner]␊
#[when_not_paused]␊
pub fn mint(e: &Env, account: Address, amount: i128) {␊
Base::mint(e, &account, amount);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
#[when_not_paused]␊
fn transfer(e: &Env, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer(e, &from, &to, amount);␊
}␊
␊
#[when_not_paused]␊
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer_from(e, &spender, &from, &to, amount);␊
}␊
}␊
␊
//␊
// Extensions␊
//␊
␊
#[contractimpl]␊
impl FungibleBurnable for MyToken {␊
#[when_not_paused]␊
fn burn(e: &Env, from: Address, amount: i128) {␊
Base::burn(e, &from, amount);␊
}␊
␊
#[when_not_paused]␊
fn burn_from(e: &Env, spender: Address, from: Address, amount: i128) {␊
Base::burn_from(e, &spender, &from, amount);␊
}␊
}␊
␊
//␊
// Utils␊
//␊
␊
#[contractimpl]␊
impl Pausable for MyToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
␊
#[only_owner]␊
fn pause(e: &Env, _caller: Address) {␊
pausable::pause(e);␊
}␊
␊
#[only_owner]␊
fn unpause(e: &Env, _caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl Ownable for MyToken {}␊
`
## fungible full - roles
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String, Symbol};␊
use stellar_access::access_control::{self as access_control, AccessControl};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_contract_utils::upgradeable::UpgradeableInternal;␊
use stellar_macros::{default_impl, only_role, Upgradeable, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
␊
#[derive(Upgradeable)]␊
#[contract]␊
pub struct MyToken;␊
␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(␊
e: &Env,␊
recipient: Address,␊
admin: Address,␊
pauser: Address,␊
upgrader: Address,␊
minter: Address,␊
) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
Base::mint(e, &recipient, 2000000000000000000000);␊
access_control::set_admin(e, &admin);␊
access_control::grant_role_no_auth(e, &admin, &pauser, &Symbol::new(e, "pauser"));␊
access_control::grant_role_no_auth(e, &admin, &upgrader, &Symbol::new(e, "upgrader"));␊
access_control::grant_role_no_auth(e, &admin, &minter, &Symbol::new(e, "minter"));␊
}␊
␊
#[only_role(caller, "minter")]␊
#[when_not_paused]␊
pub fn mint(e: &Env, account: Address, amount: i128, caller: Address) {␊
Base::mint(e, &account, amount);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for MyToken {␊
type ContractType = Base;␊
␊
#[when_not_paused]␊
fn transfer(e: &Env, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer(e, &from, &to, amount);␊
}␊
␊
#[when_not_paused]␊
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer_from(e, &spender, &from, &to, amount);␊
}␊
}␊
␊
//␊
// Extensions␊
//␊
␊
#[contractimpl]␊
impl FungibleBurnable for MyToken {␊
#[when_not_paused]␊
fn burn(e: &Env, from: Address, amount: i128) {␊
Base::burn(e, &from, amount);␊
}␊
␊
#[when_not_paused]␊
fn burn_from(e: &Env, spender: Address, from: Address, amount: i128) {␊
Base::burn_from(e, &spender, &from, amount);␊
}␊
}␊
␊
//␊
// Utils␊
//␊
␊
impl UpgradeableInternal for MyToken {␊
fn _require_auth(e: &Env, operator: &Address) {␊
access_control::ensure_role(e, operator, &Symbol::new(e, "upgrader"));␊
operator.require_auth();␊
}␊
}␊
␊
#[contractimpl]␊
impl Pausable for MyToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
␊
#[only_role(caller, "pauser")]␊
fn pause(e: &Env, caller: Address) {␊
pausable::pause(e);␊
}␊
␊
#[only_role(caller, "pauser")]␊
fn unpause(e: &Env, caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl AccessControl for MyToken {}␊
`
## fungible full - complex name
> Snapshot 1
`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1␊
#![no_std]␊
␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_contract_utils::upgradeable::UpgradeableInternal;␊
use stellar_macros::{default_impl, only_owner, Upgradeable, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
␊
#[derive(Upgradeable)]␊
#[contract]␊
pub struct CustomToken;␊
␊
#[contractimpl]␊
impl CustomToken {␊
pub fn __constructor(e: &Env, recipient: Address, owner: Address) {␊
Base::set_metadata(e, 18, String::from_str(e, "Custom $ Token"), String::from_str(e, "MTK"));␊
Base::mint(e, &recipient, 2000000000000000000000);␊
ownable::set_owner(e, &owner);␊
}␊
␊
#[only_owner]␊
#[when_not_paused]␊
pub fn mint(e: &Env, account: Address, amount: i128) {␊
Base::mint(e, &account, amount);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl FungibleToken for CustomToken {␊
type ContractType = Base;␊
␊
#[when_not_paused]␊
fn transfer(e: &Env, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer(e, &from, &to, amount);␊
}␊
␊
#[when_not_paused]␊
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128) {␊
Self::ContractType::transfer_from(e, &spender, &from, &to, amount);␊
}␊
}␊
␊
//␊
// Extensions␊
//␊
␊
#[contractimpl]␊
impl FungibleBurnable for CustomToken {␊
#[when_not_paused]␊
fn burn(e: &Env, from: Address, amount: i128) {␊
Base::burn(e, &from, amount);␊
}␊
␊
#[when_not_paused]␊
fn burn_from(e: &Env, spender: Address, from: Address, amount: i128) {␊
Base::burn_from(e, &spender, &from, amount);␊
}␊
}␊
␊
//␊
// Utils␊
//␊
␊
impl UpgradeableInternal for CustomToken {␊
fn _require_auth(e: &Env, _operator: &Address) {␊
ownable::enforce_owner_auth(e);␊
}␊
}␊
␊
#[contractimpl]␊
impl Pausable for CustomToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
␊
#[only_owner]␊
fn pause(e: &Env, _caller: Address) {␊
pausable::pause(e);␊
}␊
␊
#[only_owner]␊
fn unpause(e: &Env, _caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
␊
#[default_impl]␊
#[contractimpl]␊
impl Ownable for CustomToken {}␊
`