From e52cc32dd3b1f57a0e5db2204c3f85a7520719fd Mon Sep 17 00:00:00 2001 From: b00ste Date: Wed, 21 Feb 2024 12:11:25 +0200 Subject: [PATCH] refactror: remove legacy contracts & tests --- contracts/Factories/Create2Factory.sol | 88 ------------- .../Legacy/Registries/AddressRegistry.sol | 52 -------- .../AddressRegistryRequiresERC725.sol | 37 ------ .../Legacy/UniversalReceiverAddressStore.sol | 64 --------- contracts/Mocks/NFTStorage.sol | 17 --- tests/Mocks/AddressRegistry.test.ts | 122 ------------------ tests/Mocks/NFTStorage.test.ts | 58 --------- 7 files changed, 438 deletions(-) delete mode 100644 contracts/Factories/Create2Factory.sol delete mode 100644 contracts/Legacy/Registries/AddressRegistry.sol delete mode 100644 contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol delete mode 100644 contracts/Legacy/UniversalReceiverAddressStore.sol delete mode 100644 contracts/Mocks/NFTStorage.sol delete mode 100644 tests/Mocks/AddressRegistry.test.ts delete mode 100644 tests/Mocks/NFTStorage.test.ts diff --git a/contracts/Factories/Create2Factory.sol b/contracts/Factories/Create2Factory.sol deleted file mode 100644 index 05cc2052d..000000000 --- a/contracts/Factories/Create2Factory.sol +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.4; - -// DO NOT TOUCH -// -------------------- -// bytecode -// solidity compiler 0.6.1, no optimization -// 0x608060405234801561001057600080fd5b50610520806100206000396000f3fe6080604052600436106100345760003560e01c8063481286e61461003957806378065306146100be578063cdcb760a14610163575b600080fd5b34801561004557600080fd5b5061007c6004803603604081101561005c57600080fd5b810190808035906020019092919080359060200190929190505050610268565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100ca57600080fd5b50610121600480360360608110156100e157600080fd5b810190808035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061027d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102266004803603604081101561017957600080fd5b8101908080359060200190929190803590602001906401000000008111156101a057600080fd5b8201836020820111156101b257600080fd5b803590602001918460018302840111640100000000831117156101d457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610346565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600061027583833061027d565b905092915050565b60008060ff60f81b83868660405160200180857effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681526001018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018381526020018281526020019450505050506040516020818303038152906040528051906020012090508060001c9150509392505050565b60008060003490506000845114156103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f437265617465323a2062797465636f6465206c656e677468206973207a65726f81525060200191505060405180910390fd5b8484516020860183f59150600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610474576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f437265617465323a204661696c6564206f6e206465706c6f790000000000000081525060200191505060405180910390fd5b7fc16bb3dbd36917c7aa3e76b988c2cd35e74bb230a02fef61e7376d8b4bfaea778286604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a181925050509291505056fea26469706673582212208e45d684157bfc10076a3d284f8c3899cd5ecf31abade0a086223e0886a8a68164736f6c63430006010033 -// -// fixed deployment, compiled with 0.6.12 -// 0xC2f81D5a8c51c1E877B2720E0bEB59642c807315 -// deployer address: 0x0a481e47Fcf329d0CafDd74A46f54f21eeDF5d68 -// cost 0.0801 -// RAW Tx: -// 0xf9059380852e90edd0008306f2cc8080b90540608060405234801561001057600080fd5b50610520806100206000396000f3fe6080604052600436106100345760003560e01c8063481286e61461003957806378065306146100be578063cdcb760a14610163575b600080fd5b34801561004557600080fd5b5061007c6004803603604081101561005c57600080fd5b810190808035906020019092919080359060200190929190505050610268565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100ca57600080fd5b50610121600480360360608110156100e157600080fd5b810190808035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061027d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102266004803603604081101561017957600080fd5b8101908080359060200190929190803590602001906401000000008111156101a057600080fd5b8201836020820111156101b257600080fd5b803590602001918460018302840111640100000000831117156101d457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610346565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600061027583833061027d565b905092915050565b60008060ff60f81b83868660405160200180857effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681526001018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018381526020018281526020019450505050506040516020818303038152906040528051906020012090508060001c9150509392505050565b60008060003490506000845114156103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f437265617465323a2062797465636f6465206c656e677468206973207a65726f81525060200191505060405180910390fd5b8484516020860183f59150600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610474576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f437265617465323a204661696c6564206f6e206465706c6f790000000000000081525060200191505060405180910390fd5b7fc16bb3dbd36917c7aa3e76b988c2cd35e74bb230a02fef61e7376d8b4bfaea778286604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a181925050509291505056fea26469706673582212208e45d684157bfc10076a3d284f8c3899cd5ecf31abade0a086223e0886a8a68164736f6c634300060100331ba01234123412341234123412341234123412341234123412341234123412341234a01234123412341234123412341234123412341234123412341234123412341234 - -/** - * @title contract to deploy contracts with precomputed addresses, using create2 opcode - * based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Create2.sol - * DO NOT TOUCH - */ - -// NOTE -// fix proxy deployement -// change deploy to do: create2, then call init -// the salt needs to be the inital owner -// pick you identicon by generating different initial owner keys - -contract Create2Factory { - event ContractCreated(address addr, bytes32 salt); - - /** - * @dev Deploys a contract using `CREATE2`. The address where the contract - * will be deployed can be known in advance via {computeAddress}. - * - * The bytecode for a contract can be obtained from Solidity with - * `type(contractName).creationCode`. - * - * Requirements: - * - * - `bytecode` must not be empty. - * - `salt` must have not been used for `bytecode` already. - */ - function deploy( - bytes32 salt, - bytes memory bytecode - ) public payable returns (address) { - address addr; - uint256 amount = msg.value; - - require(bytecode.length != 0, "Create2: bytecode length is zero"); - // solhint-disable-next-line no-inline-assembly - assembly { - addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt) - } - require(addr != address(0), "Create2: Failed on deploy"); - - emit ContractCreated(addr, salt); - - return addr; - } - - /** - * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the - * `bytecodeHash` or `salt` will result in a new destination address. - */ - function computeAddress( - bytes32 salt, - bytes32 bytecodeHash - ) public view returns (address) { - return computeAddress(salt, bytecodeHash, address(this)); - } - - /** - * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at - * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}. - */ - function computeAddress( - bytes32 salt, - bytes32 bytecodeHash, - address deployer - ) public pure returns (address) { - bytes32 _data = keccak256( - abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash) - ); - return address(uint160(uint256(_data))); - } -} diff --git a/contracts/Legacy/Registries/AddressRegistry.sol b/contracts/Legacy/Registries/AddressRegistry.sol deleted file mode 100644 index e2d109c1e..000000000 --- a/contracts/Legacy/Registries/AddressRegistry.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.4; - -// libraries -import { - EnumerableSet -} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -// modules -import { - ERC165Storage -} from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol"; - -contract AddressRegistry is ERC165Storage { - using EnumerableSet for EnumerableSet.AddressSet; - - EnumerableSet.AddressSet internal _addressStore; - - function addAddress(address _address) public virtual returns (bool) { - return _addressStore.add(_address); - } - - function removeAddress(address _address) public virtual returns (bool) { - return _addressStore.remove(_address); - } - - function getAddress(uint256 _index) public view returns (address) { - return _addressStore.at(_index); - } - - function getIndex(address _address) public view returns (uint256) { - require( - _addressStore.contains(_address), - "EnumerableSet: Index not found" - ); - return - _addressStore._inner._indexes[bytes32(uint256(uint160(_address)))] - - 1; - } - - function getAllRawValues() public view returns (bytes32[] memory) { - return _addressStore._inner._values; - } - - function containsAddress(address _address) public view returns (bool) { - return _addressStore.contains(_address); - } - - function length() public view returns (uint256) { - return _addressStore.length(); - } -} diff --git a/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol b/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol deleted file mode 100644 index 5dff87e56..000000000 --- a/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.4; - -// libraries -import { - EnumerableSet -} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -// modules -import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; -import {AddressRegistry} from "./AddressRegistry.sol"; - -// constants -import { - _INTERFACEID_ERC725Y -} from "@erc725/smart-contracts/contracts/constants.sol"; - -contract AddressRegistryRequiresERC725 is AddressRegistry { - using EnumerableSet for EnumerableSet.AddressSet; - - function addAddress(address _address) public override returns (bool) { - require( - ERC165(_address).supportsInterface(_INTERFACEID_ERC725Y), - "Only ERC725Y addresses can be added" - ); - return _addressStore.add(_address); - } - - function removeAddress(address _address) public override returns (bool) { - require( - ERC165(msg.sender).supportsInterface(_INTERFACEID_ERC725Y), - "Only ERC725Y can call this function" - ); - require(msg.sender == _address, "Only an address can remove itself."); - return _addressStore.remove(_address); - } -} diff --git a/contracts/Legacy/UniversalReceiverAddressStore.sol b/contracts/Legacy/UniversalReceiverAddressStore.sol deleted file mode 100644 index cdf186902..000000000 --- a/contracts/Legacy/UniversalReceiverAddressStore.sol +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.4; - -// libraries -import { - EnumerableSet -} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -// modules -import { - ERC165Storage -} from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol"; -import {AddressRegistry} from "./Registries/AddressRegistry.sol"; - -contract UniversalReceiverAddressStore is ERC165Storage, AddressRegistry { - using EnumerableSet for EnumerableSet.AddressSet; - - bytes4 internal constant _INTERFACE_ID_LSP1DELEGATE = 0xa245bbda; - - bytes32 internal constant _TOKENS_RECIPIENT_INTERFACE_HASH = - 0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b; // keccak256("ERC777TokensRecipient") - - address public account; - - constructor(address _account) { - account = _account; - _registerInterface(_INTERFACE_ID_LSP1DELEGATE); - } - - function addAddress( - address _address - ) public override onlyAccount returns (bool) { - return _addressStore.add(_address); - } - - function removeAddress( - address _address - ) public override onlyAccount returns (bool) { - return _addressStore.remove(_address); - } - - function universalReceiverDelegate( - address sender, - uint256 /* value */, - bytes32 typeId, - bytes memory - ) external onlyAccount returns (bytes memory) { - // require(typeId == _TOKENS_RECIPIENT_INTERFACE_HASH, 'UniversalReceiverDelegate: Type not supported'); - - // store tokens only if received, DO NOT revert on _TOKENS_SENDER_INTERFACE_HASH - if (typeId == _TOKENS_RECIPIENT_INTERFACE_HASH) addAddress(sender); - - return abi.encodePacked(typeId); - } - - /* Modifers */ - modifier onlyAccount() { - require( - msg.sender == account, - "Only the connected account call this function" - ); - _; - } -} diff --git a/contracts/Mocks/NFTStorage.sol b/contracts/Mocks/NFTStorage.sol deleted file mode 100644 index c37aabfb1..000000000 --- a/contracts/Mocks/NFTStorage.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.4; - -// libraries -import { - MerkleProof -} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; - -contract NFTStorageMerkle { - function verifyMerkleProof( - bytes32[] memory _proof, - bytes32 _root, - bytes32 _leaf - ) public pure returns (bool) { - return MerkleProof.verify(_proof, _root, _leaf); - } -} diff --git a/tests/Mocks/AddressRegistry.test.ts b/tests/Mocks/AddressRegistry.test.ts deleted file mode 100644 index 672cc7c11..000000000 --- a/tests/Mocks/AddressRegistry.test.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; -import { ethers } from 'hardhat'; -import { expect } from 'chai'; -import { - AddressRegistry, - AddressRegistryRequiresERC725, - AddressRegistryRequiresERC725__factory, - AddressRegistry__factory, - UniversalProfile, - UniversalProfile__factory, -} from '../../types'; - -describe('Address Registry contracts', () => { - let addressRegistry: AddressRegistry; - let accounts: SignerWithAddress[]; - - before(async () => { - accounts = await ethers.getSigners(); - addressRegistry = await new AddressRegistry__factory(accounts[1]).deploy(); - }); - - describe('AddressRegistry', () => { - it('add address', async () => { - await addressRegistry.addAddress(accounts[1].address); - expect(await addressRegistry.getAddress(0)).to.equal(accounts[1].address); - }); - - it('add same address', async () => { - expect(await addressRegistry.containsAddress(accounts[1].address)).to.be.true; - - await addressRegistry.addAddress(accounts[1].address); - expect(await addressRegistry.getAddress(0)).to.equal(accounts[1].address); - }); - - it('should add and remove address', async () => { - await addressRegistry.addAddress(accounts[4].address); - expect(await addressRegistry.containsAddress(accounts[4].address)).to.be.true; - - await addressRegistry.removeAddress(accounts[4].address); - expect(await addressRegistry.containsAddress(accounts[4].address)).to.be.false; - }); - - it('should give the right count', async () => { - expect(await addressRegistry.length()).to.equal('1'); - // add new entry - await addressRegistry.addAddress(accounts[2].address); - expect(await addressRegistry.length()).to.equal('2'); - }); - - it('get correct index', async () => { - expect(await addressRegistry.getIndex(accounts[1].address)).to.equal('0'); - expect(await addressRegistry.getIndex(accounts[2].address)).to.equal('1'); - - await expect(addressRegistry.getIndex(accounts[4].address)).to.be.revertedWith( - 'EnumerableSet: Index not found', - ); - }); - - it('can list all values of the registry', async () => { - const length = await (await addressRegistry.length()).toNumber(); - const values = []; - - for (let i = 0; i < length; i++) { - values.push(await addressRegistry.getAddress(i)); - } - - expect(values).to.deep.equal([accounts[1].address, accounts[2].address]); - }); - - it('can get all raw values in one call', async () => { - expect(await addressRegistry.getAllRawValues()).to.deep.equal([ - '0x000000000000000000000000' + accounts[1].address.replace('0x', '').toLowerCase(), - '0x000000000000000000000000' + accounts[2].address.replace('0x', '').toLowerCase(), - ]); - }); - }); - - // Require ERC725 - describe('AddressRegistryRequiresERC725', () => { - let addressRegistryRequireERC725: AddressRegistryRequiresERC725, - account: UniversalProfile, - owner: SignerWithAddress; - - before(async () => { - owner = accounts[3]; - account = await new UniversalProfile__factory(owner).deploy(owner.address); - addressRegistryRequireERC725 = await new AddressRegistryRequiresERC725__factory( - owner, - ).deploy(); - }); - - it('add address', async () => { - const abi = addressRegistryRequireERC725.interface.encodeFunctionData('addAddress', [ - account.address, - ]); - - await account.connect(owner).execute(0, addressRegistryRequireERC725.address, 0, abi, { - gasLimit: 3_000_000, - }); - expect(await addressRegistryRequireERC725.getAddress(0)).to.equal(account.address); - }); - - it('external account adds address', async () => { - await addressRegistryRequireERC725.connect(accounts[5]).addAddress(account.address); - expect(await addressRegistryRequireERC725.getAddress(0)).to.equal(account.address); - }); - - it('remove address', async () => { - const abi = addressRegistryRequireERC725.interface.encodeFunctionData('removeAddress', [ - account.address, - ]); - - await account.connect(owner).execute(0, addressRegistryRequireERC725.address, 0, abi); - expect(await addressRegistryRequireERC725.containsAddress(account.address)).to.equal(false); - }); - - it('should fail if called by a regular address', async () => { - // simply reverts as no ERC165 is detected - await expect(addressRegistryRequireERC725.addAddress(accounts[5].address)).to.be.reverted; - }); - }); -}); diff --git a/tests/Mocks/NFTStorage.test.ts b/tests/Mocks/NFTStorage.test.ts deleted file mode 100644 index acb753814..000000000 --- a/tests/Mocks/NFTStorage.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import keccak256 from 'keccak256'; -import { MerkleTree } from 'merkletreejs'; - -import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; -import { ethers } from 'hardhat'; -import { expect } from 'chai'; -import { NFTStorageMerkle, NFTStorageMerkle__factory } from '../../types'; - -describe('NFTStorageMerkle', () => { - describe('Testing Merkle Tree', () => { - let accounts: SignerWithAddress[]; - let owner, nftList; - - let nftStorage: NFTStorageMerkle; - let leaves; - let merkletree; - - before(async () => { - accounts = await ethers.getSigners(); - owner = accounts[0]; - nftList = [ - accounts[1].address, - accounts[2].address, - accounts[3].address, - accounts[4].address, // verify this leaf - accounts[5].address, - accounts[6].address, - accounts[7].address, - accounts[8].address, - ]; - - nftStorage = await new NFTStorageMerkle__factory(owner).deploy(); - - leaves = nftList.map((x) => keccak256(x)); - merkletree = new MerkleTree(leaves, keccak256, { sortPairs: true }); - }); - - it('Should return 8 for leaves count', () => { - const count = merkletree.getHexLeaves().length; - expect(count).to.equal(8); - }); - - it('Keccak256 hash should match for the first NFT address', async () => { - const firstNFT = merkletree.getHexLeaves()[0]; - - expect(firstNFT).to.equal(ethers.utils.keccak256(nftList[0])); - }); - - it('Should verify the proof in the smart contract', async () => { - const root = merkletree.getHexRoot(); - const leaf = merkletree.getHexLeaves()[3]; - const proof = merkletree.getHexProof(leaf); - - const result = await nftStorage.callStatic.verifyMerkleProof(proof, root, leaf); - expect(result).to.be.true; - }); - }); -});