diff --git a/pop-api/examples/fungibles/lib.rs b/pop-api/examples/fungibles/lib.rs index 9787a43a..6f894349 100644 --- a/pop-api/examples/fungibles/lib.rs +++ b/pop-api/examples/fungibles/lib.rs @@ -6,7 +6,7 @@ use pop_api::{ v0::fungibles::{ self as api, events::{Approval, Created, Transfer}, - traits::{PSP22Burnable, PSP22Metadata, PSP22Mintable, PSP22}, + traits::{Psp22, Psp22Burnable, Psp22Metadata, Psp22Mintable}, PSP22Error, }, }; @@ -57,7 +57,7 @@ mod fungibles { } } - impl PSP22 for Fungible { + impl Psp22 for Fungible { /// Returns the total token supply. #[ink(message)] fn total_supply(&self) -> Balance { @@ -210,7 +210,7 @@ mod fungibles { } } - impl PSP22Metadata for Fungible { + impl Psp22Metadata for Fungible { /// Returns the token name. #[ink(message)] fn token_name(&self) -> Option { @@ -236,7 +236,7 @@ mod fungibles { } } - impl PSP22Mintable for Fungible { + impl Psp22Mintable for Fungible { /// Creates `value` amount of tokens and assigns them to `account`, increasing the total /// supply. /// @@ -255,7 +255,7 @@ mod fungibles { } } - impl PSP22Burnable for Fungible { + impl Psp22Burnable for Fungible { /// Destroys `value` amount of tokens from `account`, reducing the total supply. /// /// # Parameters diff --git a/pop-api/examples/fungibles/tests.rs b/pop-api/examples/fungibles/tests.rs index 2c5b490b..c985024f 100644 --- a/pop-api/examples/fungibles/tests.rs +++ b/pop-api/examples/fungibles/tests.rs @@ -782,18 +782,18 @@ fn deploy( // A set of helper methods to test the contract calls. fn total_supply(session: &mut Session) -> Balance { - call::(session, "PSP22::total_supply", vec![], None).unwrap() + call::(session, "Psp22::total_supply", vec![], None).unwrap() } fn balance_of(session: &mut Session, owner: AccountId) -> Balance { - call::(session, "PSP22::balance_of", vec![owner.to_string()], None) + call::(session, "Psp22::balance_of", vec![owner.to_string()], None) .unwrap() } fn allowance(session: &mut Session, owner: AccountId, spender: AccountId) -> Balance { call::( session, - "PSP22::allowance", + "Psp22::allowance", vec![owner.to_string(), spender.to_string()], None, ) @@ -803,7 +803,7 @@ fn allowance(session: &mut Session, owner: AccountId, spender: AccountId) - fn transfer(session: &mut Session, to: AccountId, amount: Balance) -> Result<(), PSP22Error> { call::( session, - "PSP22::transfer", + "Psp22::transfer", vec![to.to_string(), amount.to_string(), serde_json::to_string::<[u8; 0]>(&[]).unwrap()], None, ) @@ -817,7 +817,7 @@ fn transfer_from( ) -> Result<(), PSP22Error> { call::( session, - "PSP22::transfer_from", + "Psp22::transfer_from", vec![ from.to_string(), to.to_string(), @@ -835,7 +835,7 @@ fn approve( ) -> Result<(), PSP22Error> { call::( session, - "PSP22::approve", + "Psp22::approve", vec![spender.to_string(), value.to_string()], None, ) @@ -848,7 +848,7 @@ fn increase_allowance( ) -> Result<(), PSP22Error> { call::( session, - "PSP22::increase_allowance", + "Psp22::increase_allowance", vec![spender.to_string(), value.to_string()], None, ) @@ -861,30 +861,30 @@ fn decrease_allowance( ) -> Result<(), PSP22Error> { call::( session, - "PSP22::decrease_allowance", + "Psp22::decrease_allowance", vec![spender.to_string(), value.to_string()], None, ) } fn token_name(session: &mut Session) -> Option { - call::, PSP22Error>(session, "PSP22Metadata::token_name", vec![], None) + call::, PSP22Error>(session, "Psp22Metadata::token_name", vec![], None) .unwrap() } fn token_symbol(session: &mut Session) -> Option { - call::, PSP22Error>(session, "PSP22Metadata::token_symbol", vec![], None) + call::, PSP22Error>(session, "Psp22Metadata::token_symbol", vec![], None) .unwrap() } fn token_decimals(session: &mut Session) -> u8 { - call::(session, "PSP22Metadata::token_decimals", vec![], None).unwrap() + call::(session, "Psp22Metadata::token_decimals", vec![], None).unwrap() } fn mint(session: &mut Session, account: AccountId, amount: Balance) -> Result<(), PSP22Error> { call::( session, - "PSP22Mintable::mint", + "Psp22Mintable::mint", vec![account.to_string(), amount.to_string()], None, ) @@ -893,7 +893,7 @@ fn mint(session: &mut Session, account: AccountId, amount: Balance) -> Resu fn burn(session: &mut Session, account: AccountId, amount: Balance) -> Result<(), PSP22Error> { call::( session, - "PSP22Burnable::burn", + "Psp22Burnable::burn", vec![account.to_string(), amount.to_string()], None, ) diff --git a/pop-api/src/v0/fungibles/traits.rs b/pop-api/src/v0/fungibles/traits.rs index fd9e6271..16867c32 100644 --- a/pop-api/src/v0/fungibles/traits.rs +++ b/pop-api/src/v0/fungibles/traits.rs @@ -1,21 +1,26 @@ //! Traits that can be used by contracts. Including standard compliant traits. -use super::*; use core::result::Result; + use ink::prelude::string::String; +use super::*; + +/// Function selectors as per the PSP22 standard: https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md. +/// The mint and burn selectors are not defined in the standard, but have been created in the same way. + /// The PSP22 trait. #[ink::trait_definition] -pub trait PSP22 { +pub trait Psp22 { /// Returns the total token supply. - #[ink(message)] + #[ink(message, selector = 0x162df8c2)] fn total_supply(&self) -> Balance; /// Returns the account balance for the specified `owner`. /// /// # Parameters /// - `owner` - The account whose balance is being queried. - #[ink(message)] + #[ink(message, selector = 0x6568382f)] fn balance_of(&self, owner: AccountId) -> Balance; /// Returns the allowance for a `spender` approved by an `owner`. @@ -23,7 +28,7 @@ pub trait PSP22 { /// # Parameters /// - `owner` - The account that owns the tokens. /// - `spender` - The account that is allowed to spend the tokens. - #[ink(message)] + #[ink(message, selector = 0x4d47d921)] fn allowance(&self, owner: AccountId, spender: AccountId) -> Balance; /// Transfers `value` amount of tokens from the caller's account to account `to` @@ -33,7 +38,7 @@ pub trait PSP22 { /// - `to` - The recipient account. /// - `value` - The number of tokens to transfer. /// - `data` - Additional data in unspecified format. - #[ink(message)] + #[ink(message, selector = 0xdb20f9f5)] fn transfer(&mut self, to: AccountId, value: Balance, data: Vec) -> Result<(), PSP22Error>; /// Transfers `value` tokens on behalf of `from` to the account `to` @@ -44,7 +49,7 @@ pub trait PSP22 { /// - `to` - The recipient account. /// - `value` - The number of tokens to transfer. /// - `data` - Additional data with unspecified format. - #[ink(message)] + #[ink(message, selector = 0x54b3c76e)] fn transfer_from( &mut self, from: AccountId, @@ -60,7 +65,7 @@ pub trait PSP22 { /// # Parameters /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to approve. - #[ink(message)] + #[ink(message, selector = 0xb20f1bbd)] fn approve(&mut self, spender: AccountId, value: Balance) -> Result<(), PSP22Error>; /// Increases the allowance of `spender` by `value` amount of tokens. @@ -68,7 +73,7 @@ pub trait PSP22 { /// # Parameters /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to increase the allowance by. - #[ink(message)] + #[ink(message, selector = 0x96d6b57a)] fn increase_allowance(&mut self, spender: AccountId, value: Balance) -> Result<(), PSP22Error>; /// Decreases the allowance of `spender` by `value` amount of tokens. @@ -76,46 +81,52 @@ pub trait PSP22 { /// # Parameters /// - `spender` - The account that is allowed to spend the tokens. /// - `value` - The number of tokens to decrease the allowance by. - #[ink(message)] + #[ink(message, selector = 0xfecb57d5)] fn decrease_allowance(&mut self, spender: AccountId, value: Balance) -> Result<(), PSP22Error>; } /// The PSP22 Metadata trait. #[ink::trait_definition] -pub trait PSP22Metadata { +pub trait Psp22Metadata { /// Returns the token name. - #[ink(message)] + #[ink(message, selector = 0x3d261bd4)] fn token_name(&self) -> Option; /// Returns the token symbol. - #[ink(message)] + #[ink(message, selector = 0x34205be5)] fn token_symbol(&self) -> Option; /// Returns the token decimals. - #[ink(message)] + #[ink(message, selector = 0x7271b782)] fn token_decimals(&self) -> u8; } /// The PSP22 Mintable trait. #[ink::trait_definition] -pub trait PSP22Mintable { +pub trait Psp22Mintable { /// Creates `value` amount of tokens and assigns them to `account`, increasing the total supply. /// + /// The selector for this message is `0xfc3c75d4` (first 4 bytes of + /// `blake2b_256("PSP22Mintable::mint")`). + /// /// # Parameters /// - `account` - The account to be credited with the created tokens. /// - `value` - The number of tokens to mint. - #[ink(message)] + #[ink(message, selector = 0xfc3c75d4)] fn mint(&mut self, account: AccountId, value: Balance) -> Result<(), PSP22Error>; } /// The PSP22 Burnable trait. #[ink::trait_definition] -pub trait PSP22Burnable { +pub trait Psp22Burnable { /// Destroys `value` amount of tokens from `account`, reducing the total supply. /// + /// The selector for this message is `0x7a9da510` (first 4 bytes of + /// `blake2b_256("PSP22Burnable::burn")`). + /// /// # Parameters /// - `account` - The account from which the tokens will be destroyed. /// - `value` - The number of tokens to destroy. - #[ink(message)] + #[ink(message, selector = 0x7a9da510)] fn burn(&mut self, account: AccountId, value: Balance) -> Result<(), PSP22Error>; }