Skip to content
Open
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
186 changes: 31 additions & 155 deletions fractional-NFT/test-artifacts/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -23,210 +23,108 @@ use std::{hash::Hash, storage::storage_string::*, string::String};

storage {
/// The total number of unique assets minted by this contract.
///
/// # Additional Information
///
/// This is the number of NFTs that have been minted.
///
/// Represents the number of NFTs created by this contract.
total_assets: u64 = 0,
/// The total number of tokens minted for a particular asset.
///
/// # Additional Information
/// The total supply of tokens for a given asset.
///
/// This should always be 1 for any asset as this is an NFT contract.
/// In this NFT contract, this will always be 1 for any asset,
/// as NFTs are unique and cannot be duplicated.
total_supply: StorageMap<AssetId, u64> = StorageMap {},
/// The name associated with a particular asset.
/// The name associated with each asset.
name: StorageMap<AssetId, StorageString> = StorageMap {},
/// The symbol associated with a particular asset.
/// The symbol associated with each asset.
symbol: StorageMap<AssetId, StorageString> = StorageMap {},
}

impl SRC20 for Contract {
/// Returns the total number of individual NFTs for this contract.
/// Returns the total number of individual NFTs minted by this contract.
///
/// # Returns
///
/// * [u64] - The number of assets that this contract has minted.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
///
/// # Examples
///
/// ```sway
/// use src20::SRC20;
///
/// fn foo(contract_id: ContractId) {
/// let contract_abi = abi(SRC20, contract_id);
/// let total_assets = contract_abi.total_assets();
/// assert(total_assets != 0);
/// }
/// ```
/// * [u64] - The total number of NFTs minted.
#[storage(read)]
fn total_assets() -> u64 {
_total_assets(storage.total_assets)
}

/// Returns the total supply of tokens for an asset.
///
/// # Additional Information
/// Returns the total supply of tokens for a specific asset.
///
/// This must always be at most 1 for NFTs.
/// NFTs have a supply of at most 1.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to query the total supply.
/// * `asset`: [AssetId] - The asset for which the total supply is queried.
///
/// # Returns
///
/// * [Option<u64>] - The total supply of tokens for `asset`.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
///
/// # Examples
///
/// ```sway
/// use src20::SRC20;
///
/// fn foo(contract_id: ContractId, asset: AssetId) {
/// let contract_abi = abi(SRC20, contract_id);
/// let total_supply = contract_abi.total_supply(asset).unwrap();
/// assert(total_supply == 1);
/// }
/// ```
#[storage(read)]
fn total_supply(asset: AssetId) -> Option<u64> {
_total_supply(storage.total_supply, asset)
}

/// Returns the name of the asset, such as “Ether”.
/// Returns the name of a given asset.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to query the name.
/// * `asset`: [AssetId] - The asset whose name is being queried.
///
/// # Returns
///
/// * [Option<String>] - The name of `asset`.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
///
/// # Examples
///
/// ```sway
/// use src20::SRC20;
/// use std::string::String;
///
/// fn foo(contract_ic: ContractId, asset: AssetId) {
/// let contract_abi = abi(SRC20, contract_id);
/// let name = contract_abi.name(asset).unwrap();
/// assert(name.len() != 0);
/// }
/// ```
#[storage(read)]
fn name(asset: AssetId) -> Option<String> {
_name(storage.name, asset)
}
/// Returns the symbol of the asset, such as “ETH”.

/// Returns the symbol of a given asset.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to query the symbol.
/// * `asset`: [AssetId] - The asset whose symbol is being queried.
///
/// # Returns
///
/// * [Option<String>] - The symbol of `asset`.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
///
/// # Examples
///
/// ```sway
/// use src20::SRC20;
/// use std::string::String;
///
/// fn foo(contract_id: ContractId, asset: AssetId) {
/// let contract_abi = abi(SRC20, contract_id);
/// let symbol = contract_abi.symbol(asset).unwrap();
/// assert(symbol.len() != 0);
/// }
/// ```
#[storage(read)]
fn symbol(asset: AssetId) -> Option<String> {
_symbol(storage.symbol, asset)
}

/// Returns the number of decimals the asset uses.
///
/// # Additional Information
///
/// The standardized decimals for NFTs is 0u8.
/// NFTs typically have 0 decimals since they are indivisible.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to query the decimals.
/// * `asset`: [AssetId] - The asset whose decimal precision is being queried.
///
/// # Returns
///
/// * [Option<u8>] - The decimal precision used by `asset`.
///
/// # Examples
///
/// ```sway
/// use src20::SRC20;
///
/// fn foo(contract_id: ContractId, asset: AssedId) {
/// let contract_abi = abi(SRC20, contract_id);
/// let decimals = contract_abi.decimals(asset).unwrap();
/// assert(decimals == 0u8);
/// }
/// ```
#[storage(read)]
fn decimals(asset: AssetId) -> Option<u8> {
Some(0u8)
}
}

impl SRC3 for Contract {
/// Mints new tokens using the `sub_id` sub-identifier.
///
/// # Additional Information
/// Mints a new NFT using a unique sub-identifier.
///
/// This conforms to the SRC-20 NFT portion of the standard for a maximum
/// mint amount of 1 token per asset.
/// This contract adheres to the SRC-20 NFT standard, allowing a maximum mint amount of 1 token per asset.
///
/// # Arguments
///
/// * `recipient`: [Identity] - The user to which the newly minted tokens are transferred to.
/// * `sub_id`: [SubId] - The sub-identifier of the newly minted token.
/// * `amount`: [u64] - The quantity of tokens to mint.
/// * `recipient`: [Identity] - The recipient of the minted token.
/// * `sub_id`: [SubId] - A unique identifier for the newly minted token.
/// * `amount`: [u64] - The quantity of tokens to mint. Must be exactly 1 for NFTs.
///
/// # Reverts
///
/// * When amount is greater than one.
/// * When `amount` is greater than 1.
/// * When the asset has already been minted.
/// * When more than 100,000 NFTs have been minted.
///
/// # Number of Storage Accesses
///
/// * Reads: `3`
/// * Writes: `2`
///
/// # Examples
///
/// ```sway
/// use src3::SRC3;
///
/// fn foo(contract_id: ContractId) {
/// let contract_abi = abi(SR3, contract_id);
/// contract_abi.mint(Identity::ContractId(this_contract()), ZERO_B256, 1);
/// }
/// ```
#[storage(read, write)]
fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
let asset = AssetId::new(ContractId::this(), sub_id);
Expand Down Expand Up @@ -256,37 +154,15 @@ impl SRC3 for Contract {
amount,
);
}
/// Burns tokens sent with the given `sub_id`.
///
/// # Additional Information

/// Burns a specified NFT using the given sub-identifier.
///
/// NOTE: The sha-256 hash of `(ContractId, SubId)` must match the `AssetId` where `ContractId` is the id of
/// the implementing contract and `SubId` is the given `sub_id` argument.
/// NFTs can be burned, removing them from circulation.
///
/// # Arguments
///
/// * `sub_id`: [SubId] - The sub-identifier of the token to burn.
/// * `amount`: [u64] - The quantity of tokens to burn.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
/// * Writes: `1`
///
/// # Examples
///
/// ```sway
/// use src3::SRC3;
///
/// fn foo(contract_id: ContractId, asset_id: AssetId) {
/// let contract_abi = abi(SR3, contract_id);
/// contract_abi.burn {
/// gas: 10000,
/// coins: 1,
/// asset_id: AssetId,
/// } (ZERO_B256, 1);
/// }
/// ```
/// * `sub_id`: [SubId] - The unique sub-identifier of the token to be burned.
/// * `amount`: [u64] - The quantity of tokens to burn. For NFTs, this should typically be 1.
#[payable]
#[storage(read, write)]
fn burn(sub_id: SubId, amount: u64) {
Expand Down