Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fungible re-exports #21

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions contracts/token/fungible/src/extensions/burnable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod storage;
mod storage;
pub use self::storage::{burn, burn_from};

mod test;

use soroban_sdk::{contractclient, symbol_short, Address, Env};
Expand Down Expand Up @@ -29,8 +31,8 @@ pub trait FungibleBurnable {
///
/// # Errors
///
/// * [`crate::fungible::FungibleTokenError::InsufficientBalance`] - When
/// attempting to burn more tokens than `from` current balance.
/// * [`crate::FungibleTokenError::InsufficientBalance`] - When attempting
/// to burn more tokens than `from` current balance.
///
/// # Events
///
Expand All @@ -39,8 +41,8 @@ pub trait FungibleBurnable {
///
/// # Notes
///
/// We recommend using the [`crate::extensions::burnable::storage::burn()`]
/// function from the `storage` module when implementing this function.
/// We recommend using [`crate::burnable::burn()`] when implementing this
/// function.
fn burn(e: &Env, from: &Address, amount: i128);

/// Destroys `amount` of tokens from `account`. Updates the total
Expand All @@ -55,10 +57,10 @@ pub trait FungibleBurnable {
///
/// # Errors
///
/// * [`crate::fungible::FungibleTokenError::InsufficientBalance`] - When
/// attempting to burn more tokens than `from` current balance.A
/// * [`crate::fungible::FungibleTokenError::InsufficientAllowance`] - When
/// attempting to burn more tokens than `from` allowance.
/// * [`crate::FungibleTokenError::InsufficientBalance`] - When attempting
/// to burn more tokens than `from` current balance.A
/// * [`crate::FungibleTokenError::InsufficientAllowance`] - When attempting
/// to burn more tokens than `from` allowance.
///
/// # Events
///
Expand All @@ -67,8 +69,8 @@ pub trait FungibleBurnable {
///
/// # Notes
///
/// We recommend using the [`crate::extensions::burnable::storage::burn()`]
/// function the `storage` module when implementing this function.
/// We recommend using [`crate::burnable::burn_from()`] when implementing
/// this function.
fn burn_from(e: &Env, spender: &Address, from: &Address, amount: i128);
}

Expand Down
16 changes: 10 additions & 6 deletions contracts/token/fungible/src/extensions/burnable/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ use crate::{
///
/// # Errors
///
/// * [`crate::fungible::FungibleTokenError::InsufficientBalance`] - When
/// attempting to burn more tokens than `from` current balance.
/// * [`crate::FungibleTokenError::InsufficientBalance`] - When attempting to
/// burn more tokens than `from` current balance.
///
/// # Events
///
/// * topics - `["burn", from: Address]`
/// * data - `[amount: i128]`
///
/// # Notes
///
/// Authorization for `from` is required.
pub fn burn(e: &Env, from: &Address, amount: i128) {
from.require_auth();
update(e, Some(from), None, amount);
Expand All @@ -43,10 +47,10 @@ pub fn burn(e: &Env, from: &Address, amount: i128) {
///
/// # Errors
///
/// * [`crate::fungible::FungibleTokenError::InsufficientBalance`] - When
/// attempting to burn more tokens than `from` current balance.
/// * [`FungibleTokenError::InsufficientAllowance`] - When attempting to burn
/// more tokens than `spender`s current allowance.
/// * [`crate::FungibleTokenError::InsufficientBalance`] - When attempting to
/// burn more tokens than `from` current balance.
/// * [`crate::FungibleTokenError::InsufficientAllowance`] - When attempting to
/// burn more tokens than `spender`s current allowance.
///
/// # Events
///
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/fungible/src/extensions/burnable/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use soroban_sdk::{contract, testutils::Address as _, Address, Env};
use crate::{
extensions::{
burnable::storage::{burn, burn_from},
mintable::storage::mint,
mintable::mint,
},
storage::{allowance, approve, balance, total_supply},
};
Expand Down
4 changes: 3 additions & 1 deletion contracts/token/fungible/src/extensions/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod storage;
pub use self::storage::*;
pub use self::storage::{
decimals, get_metadata, name, set_metadata, symbol, Metadata, METADATA_KEY,
};

mod test;
8 changes: 5 additions & 3 deletions contracts/token/fungible/src/extensions/mintable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod storage;
mod storage;
pub use self::storage::mint;

mod test;

use soroban_sdk::{contractclient, symbol_short, Address, Env};
Expand Down Expand Up @@ -30,8 +32,8 @@ pub trait FungibleMintable {
///
/// # Notes
///
/// We recommend using the [`crate::extensions::mintable::storage::mint()`]
/// function from the `storage` module when implementing this function.
/// We recommend using [`crate::mintable::mint()`] when implementing this
/// function.
///
/// IMPORTANT: Please do not forget that, you probably will want to have
/// some authorization controls for minting tokens.
Expand Down
34 changes: 16 additions & 18 deletions contracts/token/fungible/src/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::total_supply()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::total_supply()`] when implementing this
/// function.
fn total_supply(e: &Env) -> i128;

/// Returns the amount of tokens held by `account`.
Expand All @@ -34,8 +34,7 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::balance()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::balance()`] when implementing this function.
fn balance(e: &Env, account: Address) -> i128;

/// Returns the amount of tokens a `spender` is allowed to spend on behalf
Expand All @@ -49,8 +48,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::allowance()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::allowance()`] when implementing this
/// function.
fn allowance(e: &Env, owner: Address, spender: Address) -> i128;

/// Transfers `amount` of tokens from `from` to `to`.
Expand All @@ -74,8 +73,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::transfer()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::transfer()`] when implementing this
/// function.
fn transfer(e: &Env, from: Address, to: Address, amount: i128);

/// Transfers `amount` of tokens from `from` to `to` using the
Expand Down Expand Up @@ -106,8 +105,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::transfer_from()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::transfer_from()`] when implementing this
/// function.
fn transfer_from(e: &Env, spender: Address, from: Address, to: Address, amount: i128);

/// Sets the amount of tokens a `spender` is allowed to spend on behalf of
Expand Down Expand Up @@ -136,8 +135,7 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::storage::approve()`] function from
/// the `storage` module when implementing this function.
/// We recommend using [`crate::approve()`] when implementing this function.
fn approve(e: &Env, owner: Address, spender: Address, amount: i128, live_until_ledger: u32);

/// Returns the number of decimals used to represent amounts of this token.
Expand All @@ -148,8 +146,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::metadata::decimals()`]
/// function from the `metadata` module when implementing this function.
/// We recommend using [`crate::metadata::decimals()`] when implementing
/// this function.
fn decimals(e: &Env) -> u32;

/// Returns the name for this token.
Expand All @@ -160,8 +158,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::metadata::name()`] function
/// from the `metadata` module when implementing this function.
/// We recommend using [`crate::metadata::name()`] when implementing this
/// function.
fn name(e: &Env) -> String;

/// Returns the symbol for this token.
Expand All @@ -172,8 +170,8 @@ pub trait FungibleToken {
///
/// # Notes
///
/// We recommend using the [`crate::metadata::symbol()`]
/// function from the `metadata` module when implementing this function.
/// We recommend using [`crate::metadata::symbol()`] when implementing this
/// function.
fn symbol(e: &Env) -> String;
}

Expand Down
38 changes: 26 additions & 12 deletions contracts/token/fungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
//! By offering this dual-layered approach, developers can choose between
//! convenience and customization, depending on their project requirements.
//!
//! ## Base Module and Extensions
//! ## Structure
//!
//! The base module implements:
//! The base module includes:
//!
//! - Total supply management
//! - Transfers and allowances
//!
//! To extend functionality, the module supports the following optional
//! features:
//! The following optional extensions are available:
//!
//! - Metadata: Provides additional information about the token, such as name,
//! symbol, and decimals.
Expand All @@ -43,10 +42,17 @@
//!
//! ## Compatibility and Compliance
//!
//! The module is designed to ensure full compatibility with SEP-0041, making it
//! easy to integrate into Soroban-based applications. It also closely mirrors
//! the Ethereum ERC-20 standard, facilitating cross-ecosystem familiarity and
//! ease of use.
//! The module is designed to ensure full compatibility with SEP-0041. It also
//! closely mirrors the Ethereum ERC-20 standard, facilitating cross-ecosystem
//! familiarity and ease of use.
//!
//! Developers aiming to create SEP-41-compliant tokens can leverage the
//! `soroban_sdk::token::TokenInterface` trait available in the "soroban-sdk"
//! crate. By implementing `TokenInterface` using the helper functions provided
//! in this library, they can ensure a secure and standardized implementation.
//! Alternatively, developers can combine the implementation of both the
//! [`FungibleToken`] and [`burnable::FungibleBurnable`] traits to create tokens
//! that adhere to SEP-41 while providing greater control and extensibility.
//!
//! ## Notes for Developers
//!
Expand All @@ -58,10 +64,18 @@
//! extensions.
#![no_std]

pub mod extensions;
pub mod fungible;
pub mod storage;
mod extensions;
mod fungible;
mod storage;

pub use extensions::metadata;
pub use extensions::{burnable, metadata, mintable};
pub use fungible::{
emit_approve, emit_transfer, FungibleToken, FungibleTokenClient, FungibleTokenError,
};
pub use storage::{
allowance, allowance_data, approve, balance, do_transfer, set_allowance, spend_allowance,
total_supply, transfer, transfer_from, update, AllowanceData, AllowanceKey, StorageKey,
BALANCE_EXTEND_AMOUNT, BALANCE_TTL_THRESHOLD, INSTANCE_EXTEND_AMOUNT, INSTANCE_TTL_THRESHOLD,
};

mod test;
2 changes: 1 addition & 1 deletion contracts/token/fungible/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use soroban_sdk::{
};

use crate::{
extensions::mintable::storage::mint,
extensions::mintable::mint,
storage::{
allowance, approve, balance, set_allowance, spend_allowance, total_supply, transfer,
transfer_from, update, StorageKey, BALANCE_EXTEND_AMOUNT, INSTANCE_EXTEND_AMOUNT,
Expand Down
Loading