difftreelog
added `transferFromCross` method in `ERC20` refungible pallet interface
in: master
5 files changed
pallets/refungible/src/erc_token.rsdiffbeforeafterboth300 Ok(true)300 Ok(true)301 }301 }302303 /// @dev Transfer tokens from one address to another304 /// @param from address The address which you want to send tokens from305 /// @param to address The address which you want to transfer to306 /// @param amount uint256 the amount of tokens to be transferred307 #[weight(<CommonWeights<T>>::transfer_from())]308 fn transfer_from_cross(309 &mut self,310 caller: caller,311 from: EthCrossAccount,312 to: EthCrossAccount,313 amount: uint256,314 ) -> Result<bool> {315 let caller = T::CrossAccountId::from_eth(caller);316 let from = from.into_sub_cross_account::<T>()?;317 let to = to.into_sub_cross_account::<T>()?;318 let amount = amount.try_into().map_err(|_| "amount overflow")?;319 let budget = self320 .recorder321 .weight_calls_budget(<StructureWeight<T>>::find_parent());322323 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)324 .map_err(dispatch_to_evm::<T>)?;325 Ok(true)326 }302}327}303328304impl<T: Config> RefungibleTokenHandle<T> {329impl<T: Config> RefungibleTokenHandle<T> {pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth36 }36 }37}37}383839/// @dev the ERC-165 identifier for this interface is 0x34b53e2039/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b40contract ERC20UniqueExtensions is Dummy, ERC165 {40contract ERC20UniqueExtensions is Dummy, ERC165 {41 /// @dev Function that burns an amount of the token of a given account,41 /// @dev Function that burns an amount of the token of a given account,42 /// deducting from the sender's allowance for said account.42 /// deducting from the sender's allowance for said account.108 return false;108 return false;109 }109 }110111 /// @dev Transfer tokens from one address to another112 /// @param from address The address which you want to send tokens from113 /// @param to address The address which you want to transfer to114 /// @param amount uint256 the amount of tokens to be transferred115 /// @dev EVM selector for this function is: 0xd5cf430b,116 /// or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)117 function transferFromCross(118 EthCrossAccount memory from,119 EthCrossAccount memory to,120 uint256 amount121 ) public returns (bool) {122 require(false, stub_error);123 from;124 to;125 amount;126 dummy = 0;127 return false;128 }110}129}111130112/// @dev Cross account struct131/// @dev Cross account structtests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth222 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],222 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],223 "stateMutability": "nonpayable",223 "stateMutability": "nonpayable",224 "type": "function"224 "type": "function"225 }225 },226 {227 "inputs": [228 {229 "components": [230 { "internalType": "address", "name": "eth", "type": "address" },231 { "internalType": "uint256", "name": "sub", "type": "uint256" }232 ],233 "internalType": "struct EthCrossAccount",234 "name": "from",235 "type": "tuple"236 },237 {238 "components": [239 { "internalType": "address", "name": "eth", "type": "address" },240 { "internalType": "uint256", "name": "sub", "type": "uint256" }241 ],242 "internalType": "struct EthCrossAccount",243 "name": "to",244 "type": "tuple"245 },246 { "internalType": "uint256", "name": "amount", "type": "uint256" }247 ],248 "name": "transferFromCross",249 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],250 "stateMutability": "nonpayable",251 "type": "function"252 }226]253]227254tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth23 function parentTokenId() external view returns (uint256);23 function parentTokenId() external view returns (uint256);24}24}252526/// @dev the ERC-165 identifier for this interface is 0x34b53e2026/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b27interface ERC20UniqueExtensions is Dummy, ERC165 {27interface ERC20UniqueExtensions is Dummy, ERC165 {28 /// @dev Function that burns an amount of the token of a given account,28 /// @dev Function that burns an amount of the token of a given account,29 /// deducting from the sender's allowance for said account.29 /// deducting from the sender's allowance for said account.66 /// or in textual repr: transferCross((address,uint256),uint256)66 /// or in textual repr: transferCross((address,uint256),uint256)67 function transferCross(EthCrossAccount memory to, uint256 amount) external returns (bool);67 function transferCross(EthCrossAccount memory to, uint256 amount) external returns (bool);6869 /// @dev Transfer tokens from one address to another70 /// @param from address The address which you want to send tokens from71 /// @param to address The address which you want to transfer to72 /// @param amount uint256 the amount of tokens to be transferred73 /// @dev EVM selector for this function is: 0xd5cf430b,74 /// or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)75 function transferFromCross(76 EthCrossAccount memory from,77 EthCrossAccount memory to,78 uint256 amount79 ) external returns (bool);68}80}698170/// @dev Cross account struct82/// @dev Cross account structtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth224 }224 }225 });225 });226 227 itEth('Can perform transferFromCross()', async ({helper}) => {228 const owner = await helper.eth.createAccountWithBalance(donor);229 const ownerCross = helper.ethCrossAccount.fromAddress(owner);230 const spender = await helper.eth.createAccountWithBalance(donor);231 const receiver = helper.eth.createAccount();232 const receiverCross = helper.ethCrossAccount.fromAddress(receiver);233 const collection = await helper.rft.mintCollection(alice);234 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});235236 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);237 const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);238239 await contract.methods.approve(spender, 100).send();240241 {242 const result = await contract.methods.transferFromCross(ownerCross, receiverCross, 49).send({from: spender});243 let event = result.events.Transfer;244 expect(event.address).to.be.equal(tokenAddress);245 expect(event.returnValues.from).to.be.equal(owner);246 expect(event.returnValues.to).to.be.equal(receiver);247 expect(event.returnValues.value).to.be.equal('49');248249 event = result.events.Approval;250 expect(event.address).to.be.equal(tokenAddress);251 expect(event.returnValues.owner).to.be.equal(owner);252 expect(event.returnValues.spender).to.be.equal(spender);253 expect(event.returnValues.value).to.be.equal('51');254 }255256 {257 const balance = await contract.methods.balanceOf(receiver).call();258 expect(+balance).to.equal(49);259 }260261 {262 const balance = await contract.methods.balanceOf(owner).call();263 expect(+balance).to.equal(151);264 }265 });226266227 itEth('Can perform transfer()', async ({helper}) => {267 itEth('Can perform transfer()', async ({helper}) => {228 const owner = await helper.eth.createAccountWithBalance(donor);268 const owner = await helper.eth.createAccountWithBalance(donor);