difftreelog
doc(refungible-pallet): add documentation for ERC20 EVM API
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6320,7 +6320,7 @@
[[package]]
name = "pallet-refungible"
-version = "0.1.1"
+version = "0.1.2"
dependencies = [
"ethereum",
"evm-coder",
pallets/refungible/CHANGELOG.mddiffbeforeafterboth--- /dev/null
+++ b/pallets/refungible/CHANGELOG.md
@@ -0,0 +1,6 @@
+## v0.1.2 - 2022-07
+
+### Refungible Pallet
+
+feat(refungible-pallet): add ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))
+test(refungible-pallet): add tests for ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))
\ No newline at end of file
pallets/refungible/Cargo.tomldiffbeforeafterboth--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pallet-refungible"
-version = "0.1.1"
+version = "0.1.2"
license = "GPLv3"
edition = "2021"
pallets/refungible/src/erc_token.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.162117extern crate alloc;22extern crate alloc;18use core::{23use core::{404541#[derive(ToLog)]46#[derive(ToLog)]42pub enum ERC20Events {47pub enum ERC20Events {48 /// @dev This event is emitted when the amount of tokens (value) is sent49 /// from the from address to the to address. In the case of minting new 50 /// tokens, the transfer is usually from the 0 address while in the case51 /// of burning tokens the transfer is to 0.43 Transfer {52 Transfer {44 #[indexed]53 #[indexed]45 from: address,54 from: address,46 #[indexed]55 #[indexed]47 to: address,56 to: address,48 value: uint256,57 value: uint256,49 },58 },59 /// @dev This event is emitted when the amount of tokens (value) is approved60 /// by the owner to be used by the spender.50 Approval {61 Approval {51 #[indexed]62 #[indexed]52 owner: address,63 owner: address,56 },67 },57}68}586970/// @title Standard ERC20 token71/// 72/// @dev Implementation of the basic standard token.73/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md59#[solidity_interface(name = "ERC20", events(ERC20Events))]74#[solidity_interface(name = "ERC20", events(ERC20Events))]60impl<T: Config> RefungibleTokenHandle<T> {75impl<T: Config> RefungibleTokenHandle<T> {76 /// @return the name of the token.61 fn name(&self) -> Result<string> {77 fn name(&self) -> Result<string> {62 Ok(decode_utf16(self.name.iter().copied())78 Ok(decode_utf16(self.name.iter().copied())63 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))79 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))64 .collect::<string>())80 .collect::<string>())65 }81 }8283 /// @return the symbol of the token.66 fn symbol(&self) -> Result<string> {84 fn symbol(&self) -> Result<string> {67 Ok(string::from_utf8_lossy(&self.token_prefix).into())85 Ok(string::from_utf8_lossy(&self.token_prefix).into())68 }86 }8788 /// @dev Total number of tokens in existence69 fn total_supply(&self) -> Result<uint256> {89 fn total_supply(&self) -> Result<uint256> {70 self.consume_store_reads(1)?;90 self.consume_store_reads(1)?;71 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())91 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())72 }92 }739394 /// @dev Not supported74 fn decimals(&self) -> Result<uint8> {95 fn decimals(&self) -> Result<uint8> {75 // Decimals aren't supported for refungible tokens96 // Decimals aren't supported for refungible tokens76 Ok(0)97 Ok(0)77 }98 }7899100 /// @dev Gets the balance of the specified address.101 /// @param owner The address to query the balance of.102 /// @return An uint256 representing the amount owned by the passed address.79 fn balance_of(&self, owner: address) -> Result<uint256> {103 fn balance_of(&self, owner: address) -> Result<uint256> {80 self.consume_store_reads(1)?;104 self.consume_store_reads(1)?;81 let owner = T::CrossAccountId::from_eth(owner);105 let owner = T::CrossAccountId::from_eth(owner);82 let balance = <Balance<T>>::get((self.id, self.1, owner));106 let balance = <Balance<T>>::get((self.id, self.1, owner));83 Ok(balance.into())107 Ok(balance.into())84 }108 }109110 /// @dev Transfer token for a specified address111 /// @param to The address to transfer to.112 /// @param amount The amount to be transferred.85 #[weight(<CommonWeights<T>>::transfer())]113 #[weight(<CommonWeights<T>>::transfer())]86 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {114 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {87 let caller = T::CrossAccountId::from_eth(caller);115 let caller = T::CrossAccountId::from_eth(caller);96 Ok(true)124 Ok(true)97 }125 }126127 /// @dev Transfer tokens from one address to another128 /// @param from address The address which you want to send tokens from129 /// @param to address The address which you want to transfer to130 /// @param amount uint256 the amount of tokens to be transferred98 #[weight(<CommonWeights<T>>::transfer_from())]131 #[weight(<CommonWeights<T>>::transfer_from())]99 fn transfer_from(132 fn transfer_from(100 &mut self,133 &mut self,116 Ok(true)149 Ok(true)117 }150 }151152 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.153 /// Beware that changing an allowance with this method brings the risk that someone may use both the old154 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this155 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:156 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729157 /// @param spender The address which will spend the funds.158 /// @param amount The amount of tokens to be spent.118 #[weight(<SelfWeightOf<T>>::approve())]159 #[weight(<SelfWeightOf<T>>::approve())]119 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {160 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {120 let caller = T::CrossAccountId::from_eth(caller);161 let caller = T::CrossAccountId::from_eth(caller);126 Ok(true)167 Ok(true)127 }168 }169170 /// @dev Function to check the amount of tokens that an owner allowed to a spender.171 /// @param owner address The address which owns the funds.172 /// @param spender address The address which will spend the funds.173 /// @return A uint256 specifying the amount of tokens still available for the spender.128 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {174 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {129 self.consume_store_reads(1)?;175 self.consume_store_reads(1)?;130 let owner = T::CrossAccountId::from_eth(owner);176 let owner = T::CrossAccountId::from_eth(owner);136182137#[solidity_interface(name = "ERC20UniqueExtensions")]183#[solidity_interface(name = "ERC20UniqueExtensions")]138impl<T: Config> RefungibleTokenHandle<T> {184impl<T: Config> RefungibleTokenHandle<T> {185 /// @dev Function that burns an amount of the token of a given account,186 /// deducting from the sender's allowance for said account.187 /// @param from The account whose tokens will be burnt.188 /// @param amount The amount that will be burnt.139 #[weight(<SelfWeightOf<T>>::burn_from())]189 #[weight(<SelfWeightOf<T>>::burn_from())]140 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {190 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {141 let caller = T::CrossAccountId::from_eth(caller);191 let caller = T::CrossAccountId::from_eth(caller);150 Ok(true)200 Ok(true)151 }201 }152202203 /// @dev Function that changes total amount of the tokens.204 /// Throws if `msg.sender` doesn't owns all of the tokens.205 /// @param amount New total amount of the tokens.153 #[weight(<SelfWeightOf<T>>::repartition_item())]206 #[weight(<SelfWeightOf<T>>::repartition_item())]154 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {207 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {155 let caller = T::CrossAccountId::from_eth(caller);208 let caller = T::CrossAccountId::from_eth(caller);