difftreelog
feat impl transfer, transer_from, transfer_cross, transfer_from_cross,
in: master
6 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth1use crate::Config;1use crate::Config;2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};3use frame_support::traits::Currency;3use frame_support::traits::{Currency, ExistenceRequirement};4use pallet_common::erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult};4use pallet_common::{5 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},6 eth::CrossAddress,7};5use pallet_evm_coder_substrate::{8use pallet_evm_coder_substrate::{6 call, dispatch_to_evm,9 call, dispatch_to_evm,7 execution::{PreDispatch, Result},10 execution::{PreDispatch, Result},828583 // #[weight(<SelfWeightOf<T>>::transfer())]86 // #[weight(<SelfWeightOf<T>>::transfer())]84 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {87 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {85 // let caller = T::CrossAccountId::from_eth(caller);88 let caller = T::CrossAccountId::from_eth(caller);86 // let to = T::CrossAccountId::from_eth(to);89 let to = T::CrossAccountId::from_eth(to);87 // let amount = amount.try_into().map_err(|_| "amount overflow")?;90 let amount = amount.try_into().map_err(|_| "amount overflow")?;88 // let budget = self91 // let budget = self89 // .recorder92 // .recorder90 // .weight_calls_budget(<StructureWeight<T>>::find_parent());93 // .weight_calls_budget(<StructureWeight<T>>::find_parent());919492 // <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;95 // <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;93 // Ok(true)96 <T as Config>::Currency::transfer(97 caller.as_sub(),94 todo!()98 to.as_sub(),99 amount,100 ExistenceRequirement::KeepAlive,101 )102 .map_err(dispatch_to_evm::<T>);103 Ok(true)95 }104 }9610597 // #[weight(<SelfWeightOf<T>>::transfer_from())]106 // #[weight(<SelfWeightOf<T>>::transfer_from())]102 to: Address,111 to: Address,103 amount: U256,112 amount: U256,104 ) -> Result<bool> {113 ) -> Result<bool> {105 // let caller = T::CrossAccountId::from_eth(caller);114 let caller = T::CrossAccountId::from_eth(caller);106 // let from = T::CrossAccountId::from_eth(from);115 let from = T::CrossAccountId::from_eth(from);107 // let to = T::CrossAccountId::from_eth(to);116 let to = T::CrossAccountId::from_eth(to);108 // let amount = amount.try_into().map_err(|_| "amount overflow")?;117 let amount = amount.try_into().map_err(|_| "amount overflow")?;118119 if (from != to) {120 return Err("no permission".into());121 }109 // let budget = self122 // let budget = self110 // .recorder123 // .recorder111 // .weight_calls_budget(<StructureWeight<T>>::find_parent());124 // .weight_calls_budget(<StructureWeight<T>>::find_parent());112125113 // <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)126 // <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)114 // .map_err(dispatch_to_evm::<T>)?;127 // .map_err(dispatch_to_evm::<T>)?;115 // Ok(true)128 <T as Config>::Currency::transfer(129 caller.as_sub(),116 todo!()130 to.as_sub(),131 amount,132 ExistenceRequirement::KeepAlive,133 )134 .map_err(dispatch_to_evm::<T>);135 Ok(true)117 }136 }118}137}138139#[solidity_interface(name = ERC20UniqueExtensions, enum(derive(PreDispatch)), enum_attr(weight))]140impl<T: Config> NativeFungibleHandle<T>141where142 T::AccountId: From<[u8; 32]>,143{144 // #[weight(<SelfWeightOf<T>>::transfer())]145 fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {146 let caller = T::CrossAccountId::from_eth(caller);147 let to = to.into_sub_cross_account::<T>()?;148 let amount = amount.try_into().map_err(|_| "amount overflow")?;149 // let budget = self150 // .recorder151 // .weight_calls_budget(<StructureWeight<T>>::find_parent());152153 // <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;154 <T as Config>::Currency::transfer(155 caller.as_sub(),156 to.as_sub(),157 amount,158 ExistenceRequirement::KeepAlive,159 )160 .map_err(dispatch_to_evm::<T>);161 Ok(true)162 }163164 // #[weight(<SelfWeightOf<T>>::transfer_from())]165 fn transfer_from_cross(166 &mut self,167 caller: Caller,168 from: CrossAddress,169 to: CrossAddress,170 amount: U256,171 ) -> Result<bool> {172 let caller = T::CrossAccountId::from_eth(caller);173 let from = from.into_sub_cross_account::<T>()?;174 let to = to.into_sub_cross_account::<T>()?;175 let amount = amount.try_into().map_err(|_| "amount overflow")?;176177 if (from != to) {178 return Err("no permission".into());179 }180181 // let budget = self182 // .recorder183 // .weight_calls_budget(<StructureWeight<T>>::find_parent());184185 // <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)186 // .map_err(dispatch_to_evm::<T>)?;187 <T as Config>::Currency::transfer(188 caller.as_sub(),189 to.as_sub(),190 amount,191 ExistenceRequirement::KeepAlive,192 )193 .map_err(dispatch_to_evm::<T>);194 Ok(true)195 }196}119197120#[solidity_interface(198#[solidity_interface(121 name = UniqueNativeFungible,199 name = UniqueNativeFungible,122 is(ERC20),200 is(ERC20, ERC20UniqueExtensions),123 enum(derive(PreDispatch))201 enum(derive(PreDispatch))124)]202)]125impl<T: Config> NativeFungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}203impl<T: Config> NativeFungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}pallets/balances-adapter/src/lib.rsdiffbeforeafterboth17 Self::AccountId,17 Self::AccountId,18 Balance = Self::CurrencyBalance,18 Balance = Self::CurrencyBalance,19 >;19 >;20 type CurrencyBalance: Into<U256>;20 type CurrencyBalance: Into<U256> + TryFrom<U256>;212122 type Decimals: Get<u8>;22 type Decimals: Get<u8>;23 type Name: Get<String>;23 type Name: Get<String>;pallets/balances-adapter/src/stubs/UniqueNativeFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/balances-adapter/src/stubs/UniqueNativeFungible.soldiffbeforeafterboth17 }17 }18}18}1920/// @dev the ERC-165 identifier for this interface is 0xff15c6f421contract ERC20UniqueExtensions is Dummy, ERC165 {22 /// @dev EVM selector for this function is: 0x2ada85ff,23 /// or in textual repr: transferCross((address,uint256),uint256)24 function transferCross(CrossAddress memory to, uint256 amount) public returns (bool) {25 require(false, stub_error);26 to;27 amount;28 dummy = 0;29 return false;30 }3132 /// @dev EVM selector for this function is: 0xd5cf430b,33 /// or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)34 function transferFromCross(35 CrossAddress memory from,36 CrossAddress memory to,37 uint256 amount38 ) public returns (bool) {39 require(false, stub_error);40 from;41 to;42 amount;43 dummy = 0;44 return false;45 }46}4748/// Cross account struct49struct CrossAddress {50 address eth;51 uint256 sub;52}195320/// @dev inlined interface54/// @dev inlined interface21contract ERC20Events {55contract ERC20Events {255926/// @dev the ERC-165 identifier for this interface is 0x942e8b2260/// @dev the ERC-165 identifier for this interface is 0x942e8b2227contract ERC20 is Dummy, ERC165, ERC20Events {61contract ERC20 is Dummy, ERC165, ERC20Events {28 /// @dev EVM selector for this function is: 0x06fdde03,62 /// @dev EVM selector for this function is: 0xdd62ed3e,29 /// or in textual repr: name()63 /// or in textual repr: allowance(address,address)30 function name() public view returns (string memory) {64 function allowance(address owner, address spender) public view returns (uint256) {31 require(false, stub_error);65 require(false, stub_error);66 owner;67 spender;32 dummy;68 dummy;33 return "";69 return 0;34 }70 }357136 /// @dev EVM selector for this function is: 0x95d89b41,72 /// @dev EVM selector for this function is: 0x095ea7b3,37 /// or in textual repr: symbol()73 /// or in textual repr: approve(address,uint256)38 function symbol() public view returns (string memory) {74 function approve(address spender, uint256 amount) public returns (bool) {39 require(false, stub_error);75 require(false, stub_error);76 spender;77 amount;40 dummy;78 dummy = 0;41 return "";79 return false;42 }80 }438144 /// @dev EVM selector for this function is: 0x18160ddd,82 /// @dev EVM selector for this function is: 0x70a08231,45 /// or in textual repr: totalSupply()83 /// or in textual repr: balanceOf(address)46 function totalSupply() public view returns (uint256) {84 function balanceOf(address owner) public view returns (uint256) {47 require(false, stub_error);85 require(false, stub_error);86 owner;48 dummy;87 dummy;49 return 0;88 return 0;50 }89 }57 return 0;96 return 0;58 }97 }599860 /// @dev EVM selector for this function is: 0x70a08231,99 /// @dev EVM selector for this function is: 0x06fdde03,61 /// or in textual repr: balanceOf(address)100 /// or in textual repr: name()62 function balanceOf(address owner) public view returns (uint256) {101 function name() public view returns (string memory) {63 require(false, stub_error);102 require(false, stub_error);64 owner;65 dummy;103 dummy;66 return 0;104 return "";67 }105 }6810669 /// @dev EVM selector for this function is: 0xa9059cbb,107 /// @dev EVM selector for this function is: 0x95d89b41,70 /// or in textual repr: transfer(address,uint256)108 /// or in textual repr: symbol()71 function transfer(address to, uint256 amount) public returns (bool) {109 function symbol() public view returns (string memory) {72 require(false, stub_error);110 require(false, stub_error);73 to;74 amount;75 dummy = 0;111 dummy;76 return false;112 return "";77 }113 }7811479 /// @dev EVM selector for this function is: 0x23b872dd,115 /// @dev EVM selector for this function is: 0x18160ddd,80 /// or in textual repr: transferFrom(address,address,uint256)116 /// or in textual repr: totalSupply()81 function transferFrom(117 function totalSupply() public view returns (uint256) {82 address from,83 address to,84 uint256 amount85 ) public returns (bool) {86 require(false, stub_error);118 require(false, stub_error);87 from;88 to;89 amount;90 dummy = 0;119 dummy;91 return false;120 return 0;92 }121 }9312294 /// @dev EVM selector for this function is: 0x095ea7b3,123 /// @dev EVM selector for this function is: 0xa9059cbb,95 /// or in textual repr: approve(address,uint256)124 /// or in textual repr: transfer(address,uint256)96 function approve(address spender, uint256 amount) public returns (bool) {125 function transfer(address to, uint256 amount) public returns (bool) {97 require(false, stub_error);126 require(false, stub_error);98 spender;127 to;99 amount;128 amount;100 dummy = 0;129 dummy = 0;101 return false;130 return false;102 }131 }103132104 /// @dev EVM selector for this function is: 0xdd62ed3e,133 /// @dev EVM selector for this function is: 0x23b872dd,105 /// or in textual repr: allowance(address,address)134 /// or in textual repr: transferFrom(address,address,uint256)106 function allowance(address owner, address spender) public view returns (uint256) {135 function transferFrom(136 address from,137 address to,138 uint256 amount139 ) public returns (bool) {107 require(false, stub_error);140 require(false, stub_error);108 owner;141 from;109 spender;142 to;143 amount;110 dummy;144 dummy = 0;111 return 0;145 return false;112 }146 }113}147}114148115contract UniqueNativeFungible is Dummy, ERC165, ERC20 {}149contract UniqueNativeFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}116150tests/src/eth/abi/nativeFungible.jsondiffbeforeafterboth125 "stateMutability": "nonpayable",125 "stateMutability": "nonpayable",126 "type": "function"126 "type": "function"127 },127 },128 {129 "inputs": [130 {131 "components": [132 { "internalType": "address", "name": "eth", "type": "address" },133 { "internalType": "uint256", "name": "sub", "type": "uint256" }134 ],135 "internalType": "struct CrossAddress",136 "name": "to",137 "type": "tuple"138 },139 { "internalType": "uint256", "name": "amount", "type": "uint256" }140 ],141 "name": "transferCross",142 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],143 "stateMutability": "nonpayable",144 "type": "function"145 },128 {146 {129 "inputs": [147 "inputs": [130 { "internalType": "address", "name": "from", "type": "address" },148 { "internalType": "address", "name": "from", "type": "address" },135 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],153 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],136 "stateMutability": "nonpayable",154 "stateMutability": "nonpayable",137 "type": "function"155 "type": "function"138 }156 },157 {158 "inputs": [159 {160 "components": [161 { "internalType": "address", "name": "eth", "type": "address" },162 { "internalType": "uint256", "name": "sub", "type": "uint256" }163 ],164 "internalType": "struct CrossAddress",165 "name": "from",166 "type": "tuple"167 },168 {169 "components": [170 { "internalType": "address", "name": "eth", "type": "address" },171 { "internalType": "uint256", "name": "sub", "type": "uint256" }172 ],173 "internalType": "struct CrossAddress",174 "name": "to",175 "type": "tuple"176 },177 { "internalType": "uint256", "name": "amount", "type": "uint256" }178 ],179 "name": "transferFromCross",180 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],181 "stateMutability": "nonpayable",182 "type": "function"183 }139]184]140185tests/src/eth/api/UniqueNativeFungible.soldiffbeforeafterboth12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}13}1415/// @dev the ERC-165 identifier for this interface is 0xff15c6f416interface ERC20UniqueExtensions is Dummy, ERC165 {17 /// @dev EVM selector for this function is: 0x2ada85ff,18 /// or in textual repr: transferCross((address,uint256),uint256)19 function transferCross(CrossAddress memory to, uint256 amount) external returns (bool);2021 /// @dev EVM selector for this function is: 0xd5cf430b,22 /// or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)23 function transferFromCross(24 CrossAddress memory from,25 CrossAddress memory to,26 uint256 amount27 ) external returns (bool);28}2930/// Cross account struct31struct CrossAddress {32 address eth;33 uint256 sub;34}143515/// @dev inlined interface36/// @dev inlined interface16interface ERC20Events {37interface ERC20Events {204121/// @dev the ERC-165 identifier for this interface is 0x942e8b2242/// @dev the ERC-165 identifier for this interface is 0x942e8b2222interface ERC20 is Dummy, ERC165, ERC20Events {43interface ERC20 is Dummy, ERC165, ERC20Events {23 /// @dev EVM selector for this function is: 0x06fdde03,44 /// @dev EVM selector for this function is: 0xdd62ed3e,24 /// or in textual repr: name()45 /// or in textual repr: allowance(address,address)25 function name() external view returns (string memory);46 function allowance(address owner, address spender) external view returns (uint256);264727 /// @dev EVM selector for this function is: 0x95d89b41,48 /// @dev EVM selector for this function is: 0x095ea7b3,28 /// or in textual repr: symbol()49 /// or in textual repr: approve(address,uint256)29 function symbol() external view returns (string memory);50 function approve(address spender, uint256 amount) external returns (bool);305131 /// @dev EVM selector for this function is: 0x18160ddd,52 /// @dev EVM selector for this function is: 0x70a08231,32 /// or in textual repr: totalSupply()53 /// or in textual repr: balanceOf(address)33 function totalSupply() external view returns (uint256);54 function balanceOf(address owner) external view returns (uint256);345535 /// @dev EVM selector for this function is: 0x313ce567,56 /// @dev EVM selector for this function is: 0x313ce567,36 /// or in textual repr: decimals()57 /// or in textual repr: decimals()37 function decimals() external view returns (uint8);58 function decimals() external view returns (uint8);385939 /// @dev EVM selector for this function is: 0x70a08231,60 /// @dev EVM selector for this function is: 0x06fdde03,40 /// or in textual repr: balanceOf(address)61 /// or in textual repr: name()62 function name() external view returns (string memory);6364 /// @dev EVM selector for this function is: 0x95d89b41,65 /// or in textual repr: symbol()66 function symbol() external view returns (string memory);6768 /// @dev EVM selector for this function is: 0x18160ddd,69 /// or in textual repr: totalSupply()41 function balanceOf(address owner) external view returns (uint256);70 function totalSupply() external view returns (uint256);427143 /// @dev EVM selector for this function is: 0xa9059cbb,72 /// @dev EVM selector for this function is: 0xa9059cbb,44 /// or in textual repr: transfer(address,uint256)73 /// or in textual repr: transfer(address,uint256)52 uint256 amount81 uint256 amount53 ) external returns (bool);82 ) external returns (bool);5455 /// @dev EVM selector for this function is: 0x095ea7b3,56 /// or in textual repr: approve(address,uint256)57 function approve(address spender, uint256 amount) external returns (bool);5859 /// @dev EVM selector for this function is: 0xdd62ed3e,60 /// or in textual repr: allowance(address,address)61 function allowance(address owner, address spender) external view returns (uint256);62}83}638464interface UniqueNativeFungible is Dummy, ERC165, ERC20 {}85interface UniqueNativeFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}6586