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

feat: add function selectors to psp22 trait #316

Merged
Changes from 4 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
39 changes: 25 additions & 14 deletions pop-api/src/v0/fungibles/traits.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
//! 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 have been taken from the PSP22 standard: https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
/// 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 {
/// 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`.
///
/// # 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`
Expand All @@ -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<u8>) -> Result<(), PSP22Error>;

/// Transfers `value` tokens on behalf of `from` to the account `to`
Expand All @@ -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,
Expand All @@ -60,39 +65,39 @@ 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.
///
/// # 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.
///
/// # 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 {
/// Returns the token name.
#[ink(message)]
#[ink(message, selector = 0x3d261bd4)]
fn token_name(&self) -> Option<String>;

/// Returns the token symbol.
#[ink(message)]
#[ink(message, selector = 0x34205be5)]
fn token_symbol(&self) -> Option<String>;

/// Returns the token decimals.
#[ink(message)]
#[ink(message, selector = 0x7271b782)]
fn token_decimals(&self) -> u8;
}

Expand All @@ -101,10 +106,13 @@ pub trait Psp22Metadata {
pub trait Psp22Mintable {
/// Creates `value` amount of tokens and assigns them to `account`, increasing the total supply.
///
/// The selector for this message is `0x7a9da510` (first 4 bytes of
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
/// `blake2b_256("PSP22Burnable::burn")`).
///
/// # Parameters
/// - `account` - The account to be credited with the created tokens.
/// - `value` - The number of tokens to mint.
#[ink(message)]
#[ink(message, selector = 0xfc3c75d4)]
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
fn mint(&mut self, account: AccountId, value: Balance) -> Result<(), PSP22Error>;
}

Expand All @@ -113,9 +121,12 @@ pub trait Psp22Mintable {
pub trait Psp22Burnable {
/// Destroys `value` amount of tokens from `account`, reducing the total supply.
///
/// The selector for this message is `0xfc3c75d4` (first 4 bytes of
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
/// `blake2b_256("PSP22Mintable::mint")`).
///
/// # Parameters
/// - `account` - The account from which the tokens will be destroyed.
/// - `value` - The number of tokens to destroy.
#[ink(message)]
#[ink(message, selector = 0x7a9da510)]
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
fn burn(&mut self, account: AccountId, value: Balance) -> Result<(), PSP22Error>;
}
Loading