diff --git a/README.md b/README.md index a9376b2..0d24ceb 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ Check config.js for actual values. With `salt` = `0x0000000000000000000000000000000000000000000000000000000047941987` address must be: -1. `MultipleInstanceFactory` - `0xdacb0a030Bcfc7163922d34092a822cC19D12d40` -2. `InstanceFactoryWithRegistry` - `0x6C1F437dFd70501Ad7f152897051446cc51F1eB6` +1. `MultipleInstanceFactory` - `0x70A8e447E58480D68B56d88EF2C277Efe61e2b22` +2. `InstanceFactoryWithRegistry` - `0xCAfb424689d3995c74a854e54cD24e2Be64C33D4` Check addresses with current config: diff --git a/contracts/InstanceFactory.sol b/contracts/InstanceFactory.sol index f3e5a80..03ac6d1 100644 --- a/contracts/InstanceFactory.sol +++ b/contracts/InstanceFactory.sol @@ -45,12 +45,12 @@ contract InstanceFactory is Ownable { function createInstanceClone(uint256 _denomination, address _token) public virtual returns (address) { bytes32 salt = keccak256(abi.encodePacked(_denomination, _token)); - require(!implementation.predictDeterministicAddress(salt).isContract(), "Instance already exists"); - - address newClone = implementation.cloneDeterministic(salt); - - emit NewInstanceCloneCreated(newClone); - ERC20TornadoCloneable(newClone).init(_denomination, merkleTreeHeight, _token); + address newClone = implementation.predictDeterministicAddress(salt); + if (!newClone.isContract()) { + implementation.cloneDeterministic(salt); + emit NewInstanceCloneCreated(newClone); + ERC20TornadoCloneable(newClone).init(_denomination, merkleTreeHeight, _token); + } return newClone; } diff --git a/contracts/MultipleInstanceFactory.sol b/contracts/MultipleInstanceFactory.sol index 645e682..04307e6 100644 --- a/contracts/MultipleInstanceFactory.sol +++ b/contracts/MultipleInstanceFactory.sol @@ -17,9 +17,11 @@ contract MultipleInstanceFactory is InstanceFactory { * @param _token address of ERC20 token for a new instance * @param _denominations list of denominations for each new instance */ - function createInstanceClones(address _token, uint256[] memory _denominations) external { + function createInstanceClones(address _token, uint256[] memory _denominations) external returns (address[] memory) { + address[] memory newClones = new address[](_denominations.length); for (uint256 i = 0; i < _denominations.length; i++) { - createInstanceClone(_denominations[i], _token); + newClones[i] = createInstanceClone(_denominations[i], _token); } + return newClones; } } diff --git a/test/multiple.instance.factory.test.js b/test/multiple.instance.factory.test.js index 5e4a406..78f3be3 100644 --- a/test/multiple.instance.factory.test.js +++ b/test/multiple.instance.factory.test.js @@ -110,6 +110,13 @@ describe('Multiple Instance Factory Tests', () => { expect(await instance.hasher()).to.be.equal(config.hasher) expect(await instance.levels()).to.be.equal(config.merkleTreeHeight) expect(await instance.denomination()).to.equal(ethers.utils.parseEther('1000')) + + // try to deploy the same instance again + await instanceFactory.connect(sender).createInstanceClone(ethers.utils.parseEther('1000'), config.COMP) + + // check that instance has not been created - no new NewInstanceCloneCreated event + let curLogs = await instanceFactory.queryFilter('NewInstanceCloneCreated') + expect(curLogs.length).to.be.equal(logs.length) }) it('Should successfully add instances', async function () {