Skip to content

Commit

Permalink
style: token terminology pop api
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Aug 19, 2024
1 parent 8b51e53 commit 935f99a
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 210 deletions.
3 changes: 1 addition & 2 deletions pop-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ std = [
"pop-primitives/std",
"sp-io/std",
]
assets = []
fungibles = ["assets"]
fungibles = []
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

use ink::prelude::vec::Vec;
use pop_api::{
assets::fungibles::{self as api},
primitives::AssetId,
fungibles::{self as api},
primitives::TokenId,
StatusCode,
};

Expand All @@ -15,12 +14,12 @@ mod create_token_in_constructor {

#[ink(storage)]
pub struct Fungible {
id: AssetId,
id: TokenId,
}

impl Fungible {
#[ink(constructor, payable)]
pub fn new(id: AssetId, min_balance: Balance) -> Result<Self> {
pub fn new(id: TokenId, min_balance: Balance) -> Result<Self> {
let contract = Self { id };
// AccountId of the contract which will be set to the owner of the fungible token.
let owner = contract.env().account_id();
Expand All @@ -29,18 +28,8 @@ mod create_token_in_constructor {
}

#[ink(message)]
pub fn asset_exists(&self) -> Result<bool> {
api::asset_exists(self.id)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[ink::test]
fn default_works() {
PopApiFungiblesExample::new();
pub fn token_exists(&self) -> Result<bool> {
api::token_exists(self.id)
}
}
}
85 changes: 42 additions & 43 deletions pop-api/integration-tests/contracts/fungibles/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

/// Local Fungibles:
/// 1. PSP-22 Interface
/// 2. PSP-22 Metadata Interface
/// 3. Asset Management
///
/// 1. PSP-22
/// 2. PSP-22 Metadata
/// 3. Management
/// 4. PSP-22 Mintable & Burnable
use ink::prelude::vec::Vec;
use pop_api::{
assets::fungibles::{self as api},
primitives::AssetId,
fungibles::{self as api},
primitives::TokenId,
StatusCode,
};

Expand Down Expand Up @@ -40,66 +39,66 @@ mod fungibles {
/// - decrease_allowance

#[ink(message)]
pub fn total_supply(&self, id: AssetId) -> Result<Balance> {
api::total_supply(id)
pub fn total_supply(&self, token: TokenId) -> Result<Balance> {
api::total_supply(token)
}

#[ink(message)]
pub fn balance_of(&self, id: AssetId, owner: AccountId) -> Result<Balance> {
api::balance_of(id, owner)
pub fn balance_of(&self, token: TokenId, owner: AccountId) -> Result<Balance> {
api::balance_of(token, owner)
}

#[ink(message)]
pub fn allowance(
&self,
id: AssetId,
token: TokenId,
owner: AccountId,
spender: AccountId,
) -> Result<Balance> {
api::allowance(id, owner, spender)
api::allowance(token, owner, spender)
}

#[ink(message)]
pub fn transfer(&self, id: AssetId, to: AccountId, value: Balance) -> Result<()> {
api::transfer(id, to, value)
pub fn transfer(&self, token: TokenId, to: AccountId, value: Balance) -> Result<()> {
api::transfer(token, to, value)
}

#[ink(message)]
pub fn transfer_from(
&self,
id: AssetId,
token: TokenId,
from: AccountId,
to: AccountId,
value: Balance,
// In the PSP-22 standard a `[u8]`, but the size needs to be known at compile time.
_data: Vec<u8>,
) -> Result<()> {
api::transfer_from(id, from, to, value)
api::transfer_from(token, from, to, value)
}

#[ink(message)]
pub fn approve(&self, id: AssetId, spender: AccountId, value: Balance) -> Result<()> {
api::approve(id, spender, value)
pub fn approve(&self, token: TokenId, spender: AccountId, value: Balance) -> Result<()> {
api::approve(token, spender, value)
}

#[ink(message)]
pub fn increase_allowance(
&self,
id: AssetId,
token: TokenId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::increase_allowance(id, spender, value)
api::increase_allowance(token, spender, value)
}

#[ink(message)]
pub fn decrease_allowance(
&self,
id: AssetId,
token: TokenId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::decrease_allowance(id, spender, value)
api::decrease_allowance(token, spender, value)
}

/// 2. PSP-22 Metadata Interface:
Expand All @@ -108,70 +107,70 @@ mod fungibles {
/// - token_decimals

#[ink(message)]
pub fn token_name(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_name(id)
pub fn token_name(&self, token: TokenId) -> Result<Vec<u8>> {
api::token_name(token)
}

#[ink(message)]
pub fn token_symbol(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_symbol(id)
pub fn token_symbol(&self, token: TokenId) -> Result<Vec<u8>> {
api::token_symbol(token)
}

#[ink(message)]
pub fn token_decimals(&self, id: AssetId) -> Result<u8> {
api::token_decimals(id)
pub fn token_decimals(&self, token: TokenId) -> Result<u8> {
api::token_decimals(token)
}

/// 3. Asset Management:
/// - create
/// - start_destroy
/// - set_metadata
/// - clear_metadata
/// - asset_exists
/// - token_exists

#[ink(message)]
pub fn create(&self, id: AssetId, admin: AccountId, min_balance: Balance) -> Result<()> {
pub fn create(&self, id: TokenId, admin: AccountId, min_balance: Balance) -> Result<()> {
api::create(id, admin, min_balance)
}

#[ink(message)]
pub fn start_destroy(&self, id: AssetId) -> Result<()> {
api::start_destroy(id)
pub fn start_destroy(&self, token: TokenId) -> Result<()> {
api::start_destroy(token)
}

#[ink(message)]
pub fn set_metadata(
&self,
id: AssetId,
token: TokenId,
name: Vec<u8>,
symbol: Vec<u8>,
decimals: u8,
) -> Result<()> {
api::set_metadata(id, name, symbol, decimals)
api::set_metadata(token, name, symbol, decimals)
}

#[ink(message)]
pub fn clear_metadata(&self, id: AssetId) -> Result<()> {
api::clear_metadata(id)
pub fn clear_metadata(&self, token: TokenId) -> Result<()> {
api::clear_metadata(token)
}

#[ink(message)]
pub fn asset_exists(&self, id: AssetId) -> Result<bool> {
api::asset_exists(id)
pub fn token_exists(&self, token: TokenId) -> Result<bool> {
api::token_exists(token)
}

/// 4. PSP-22 Mintable & Burnable Interface:
/// - mint
/// - burn

#[ink(message)]
pub fn mint(&self, id: AssetId, account: AccountId, amount: Balance) -> Result<()> {
api::mint(id, account, amount)
pub fn mint(&self, token: TokenId, account: AccountId, amount: Balance) -> Result<()> {
api::mint(token, account, amount)
}

#[ink(message)]
pub fn burn(&self, id: AssetId, account: AccountId, amount: Balance) -> Result<()> {
api::burn(id, account, amount)
pub fn burn(&self, token: TokenId, account: AccountId, amount: Balance) -> Result<()> {
api::burn(token, account, amount)
}
}

Expand Down
3 changes: 1 addition & 2 deletions pop-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

use constants::DECODING_FAILED;
use ink::env::chain_extension::{ChainExtensionMethod, FromStatusCode};
#[cfg(feature = "assets")]
pub use v0::assets;
pub use v0::*;

/// Module providing primitives types.
pub mod primitives;
Expand Down
3 changes: 0 additions & 3 deletions pop-api/src/v0/assets/mod.rs

This file was deleted.

Loading

0 comments on commit 935f99a

Please sign in to comment.