git.delta.rocks / unique-network / refs/commits / 90fcef986d5a

difftreelog

source

pallets/nft/src/eth/erc.rs4.2 KiBsourcehistory
1use evm_coder::{solidity_interface, solidity, types::*, ToLog};2use sp_std::vec::Vec;34#[solidity_interface]5pub trait InlineNameSymbol {6    type Error;78    fn name(&self) -> Result<string, Self::Error>;9    fn symbol(&self) -> Result<string, Self::Error>;10}1112#[solidity_interface]13pub trait InlineTotalSupply {14    type Error;1516    fn total_supply(&self) -> Result<uint256, Self::Error>;17}1819#[solidity_interface]20pub trait ERC165 {21    type Error;2223    fn supports_interface(&self, interface_id: bytes4) -> Result<bool, Self::Error>;24}2526#[solidity_interface(inline_is(InlineNameSymbol))]27pub trait ERC721Metadata {28    type Error;2930    #[solidity(rename_selector = "tokenURI")]31    fn token_uri(&self, token_id: uint256) -> Result<string, Self::Error>;32}3334#[solidity_interface(inline_is(InlineTotalSupply))]35pub trait ERC721Enumerable {36    type Error;3738    fn token_by_index(&self, index: uint256) -> Result<uint256, Self::Error>;39    fn token_of_owner_by_index(&self, owner: address, index: uint256) -> Result<uint256, Self::Error>;40}414243#[derive(ToLog)]44pub enum ERC721Events {45    Transfer {46        #[indexed] from: address,47        #[indexed] to: address,48        #[indexed] token_id: uint256,49    },50    Approval {51        #[indexed] owner: address,52        #[indexed] approved: address,53        #[indexed] token_id: uint256,54    },55    #[allow(dead_code)]56    ApprovalForAll {57        #[indexed] owner: address,58        #[indexed] operator: address,59        approved: bool,60    }61}6263#[solidity_interface(is(ERC165), events(ERC721Events))]64pub trait ERC721 {65    type Error;6667    fn balance_of(&self, owner: address) -> Result<uint256, Self::Error>;68    fn owner_of(&self, token_id: uint256) -> Result<address, Self::Error>;6970    #[solidity(rename_selector = "safeTransferFrom")]71    fn safe_transfer_from_with_data(&mut self, from: address, to: address, token_id: uint256, data: bytes, value: value) -> Result<void, Self::Error>;72    fn safe_transfer_from(&mut self, from: address, to: address, token_id: uint256, value: value) -> Result<void, Self::Error>;7374    fn transfer_from(&mut self, caller: caller, from: address, to: address, token_id: uint256, value: value) -> Result<void, Self::Error>;75    fn approve(&mut self, caller: caller, approved: address, token_id: uint256, value: value) -> Result<void, Self::Error>;76    fn set_approval_for_all(&mut self, caller: caller, operator: address, approved: bool) -> Result<void, Self::Error>;7778    fn get_approved(&self, token_id: uint256) -> Result<address, Self::Error>;79    fn is_approved_for_all(&self, owner: address, operator: address) -> Result<address, Self::Error>;80}8182#[solidity_interface]83pub trait ERC721UniqueExtensions {84    type Error;8586    fn transfer(&mut self, caller: caller, to: address, token_id: uint256, value: value) -> Result<void, Self::Error>;87}8889#[solidity_interface(is(ERC165, ERC721, ERC721Metadata, ERC721Enumerable, ERC721UniqueExtensions))]90pub trait UniqueNFT {91    type Error;92}9394#[derive(ToLog)]95pub enum ERC20Events {96    Transfer {97        #[indexed] from: address,98        #[indexed] to: address,99        value: uint256,100    },101    Approval {102        #[indexed] owner: address,103        #[indexed] spender: address,104        value: uint256,105    }106}107108#[solidity_interface(inline_is(InlineNameSymbol, InlineTotalSupply), events(ERC20Events))]109pub trait ERC20 {110    type Error;111    112    fn decimals(&self) -> Result<uint8, Self::Error>;113    fn balance_of(&self, owner: address) -> Result<uint256, Self::Error>;114    fn transfer(&mut self, caller: caller, to: address, value: uint256) -> Result<bool, Self::Error>;115    fn transfer_from(&mut self, caller: caller, from: address, to: address, value: uint256) -> Result<bool, Self::Error>;116    fn approve(&mut self, caller: caller, spender: address, value: uint256) -> Result<bool, Self::Error>;117    fn allowance(&self, owner: address, spender: address) -> Result<uint256, Self::Error>;118}119120#[solidity_interface(is(ERC165, ERC20))]121pub trait UniqueFungible {122    type Error;123}124125/// Runtime metadata like helpers for evm126#[solidity_interface]127trait UniqueHelpers {128    type Error;129130    /// Returns interface for NFT collections131    fn nft_interface(&self) -> Result<string, Self::Error>;132    /// Returns interface for Fungible collections133    fn fungible_interface(&self) -> Result<string, Self::Error>;134}