git.delta.rocks / unique-network / refs/commits / d58cb79d60f8

difftreelog

added repartition method to refungible erc20 extensions

Grigoriy Simonov2022-07-22parent: #4fbe604.patch.diff
in: master

7 files changed

modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
2// This file is part of Unique Network.
3
4// Unique Network is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Unique Network is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
16
1extern crate alloc;17extern crate alloc;
2use evm_coder::{generate_stubgen, solidity_interface, types::*};18use evm_coder::{generate_stubgen, solidity_interface, types::*};
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
150 Ok(true)150 Ok(true)
151 }151 }
152
153 #[weight(<SelfWeightOf<T>>::repartition_item())]
154 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {
155 let caller = T::CrossAccountId::from_eth(caller);
156 let amount = amount.try_into().map_err(|_| "amount overflow")?;
157
158 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;
159 Ok(true)
160 }
152}161}
153162
154impl<T: Config> RefungibleTokenHandle<T> {163impl<T: Config> RefungibleTokenHandle<T> {
modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth
31 );31 );
32}32}
33
34// Selector: 79cc6790
35contract ERC20UniqueExtensions is Dummy, ERC165 {
36 // Selector: burnFrom(address,uint256) 79cc6790
37 function burnFrom(address from, uint256 amount) public returns (bool) {
38 require(false, stub_error);
39 from;
40 amount;
41 dummy = 0;
42 return false;
43 }
44}
4533
46// Selector: 942e8b2234// Selector: 942e8b22
47contract ERC20 is Dummy, ERC165, ERC20Events {35contract ERC20 is Dummy, ERC165, ERC20Events {
127 }115 }
128}116}
117
118// Selector: ab8deb37
119contract ERC20UniqueExtensions is Dummy, ERC165 {
120 // Selector: burnFrom(address,uint256) 79cc6790
121 function burnFrom(address from, uint256 amount) public returns (bool) {
122 require(false, stub_error);
123 from;
124 amount;
125 dummy = 0;
126 return false;
127 }
128
129 // Selector: repartition(uint256) d2418ca7
130 function repartition(uint256 amount) public returns (bool) {
131 require(false, stub_error);
132 amount;
133 dummy = 0;
134 return false;
135 }
136}
129137
130contract UniqueRefungibleToken is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}138contract UniqueRefungibleToken is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}
131139
modifiedtests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth
22 );22 );
23}23}
24
25// Selector: 79cc6790
26interface ERC20UniqueExtensions is Dummy, ERC165 {
27 // Selector: burnFrom(address,uint256) 79cc6790
28 function burnFrom(address from, uint256 amount) external returns (bool);
29}
3024
31// Selector: 942e8b2225// Selector: 942e8b22
32interface ERC20 is Dummy, ERC165, ERC20Events {26interface ERC20 is Dummy, ERC165, ERC20Events {
65 returns (uint256);59 returns (uint256);
66}60}
61
62// Selector: ab8deb37
63interface ERC20UniqueExtensions is Dummy, ERC165 {
64 // Selector: burnFrom(address,uint256) 79cc6790
65 function burnFrom(address from, uint256 amount) external returns (bool);
66
67 // Selector: repartition(uint256) d2418ca7
68 function repartition(uint256 amount) external returns (bool);
69}
6770
68interface UniqueRefungibleToken is71interface UniqueRefungibleToken is
69 Dummy,72 Dummy,
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
211 }211 }
212 });212 });
213
214 itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {
215 const alice = privateKeyWrapper('//Alice');
216
217 const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
218
219 const owner = createEthAccount(web3);
220 await transferBalanceToEth(api, alice, owner);
221
222 const receiver = createEthAccount(web3);
223 await transferBalanceToEth(api, alice, receiver);
224
225 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
226
227 const address = tokenIdToAddress(collectionId, tokenId);
228 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});
229
230 await contract.methods.repartition(200).send({from: owner});
231 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);
232 await contract.methods.transfer(receiver, 110).send({from: owner});
233 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);
234 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);
235
236 await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;
237
238 await contract.methods.transfer(receiver, 90).send({from: owner});
239 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);
240 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);
241
242 await contract.methods.repartition(150).send({from: receiver});
243 await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;
244 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);
245 });
213});246});
214247
215describe('Refungible: Fees', () => {248describe('Refungible: Fees', () => {
modifiedtests/src/eth/reFungibleTokenAbi.jsondiffbeforeafterboth
102 "stateMutability": "view",102 "stateMutability": "view",
103 "type": "function"103 "type": "function"
104 },104 },
105 {
106 "inputs": [
107 { "internalType": "uint256", "name": "amount", "type": "uint256" }
108 ],
109 "name": "repartition",
110 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
111 "stateMutability": "nonpayable",
112 "type": "function"
113 },
105 {114 {
106 "inputs": [115 "inputs": [
107 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }116 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }