From 656b4a5f6cd22d4d3b1ce08f5cb4fe64dfdb8865 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Mon, 23 Dec 2024 20:25:23 -0300 Subject: [PATCH] Small fixes and deletions --- claim_contracts/README.md | 4 +- .../script/UpgradeToAlignedTokenV2.s.sol | 59 ------- .../script/UpgradeToAlignedTokenV3.s.sol | 59 ------- .../UpgradeToClaimableAirdropV2Data.s.sol | 58 ------- claim_contracts/script/UpgradeToken.s.sol | 53 ------- claim_contracts/src/ExampleAlignedTokenV2.sol | 23 --- claim_contracts/src/ExampleAlignedTokenV3.sol | 61 ------- .../src/ExampleClaimableAirdropV2.sol | 149 ------------------ 8 files changed, 2 insertions(+), 464 deletions(-) delete mode 100644 claim_contracts/script/UpgradeToAlignedTokenV2.s.sol delete mode 100644 claim_contracts/script/UpgradeToAlignedTokenV3.s.sol delete mode 100644 claim_contracts/script/UpgradeToClaimableAirdropV2Data.s.sol delete mode 100644 claim_contracts/script/UpgradeToken.s.sol delete mode 100644 claim_contracts/src/ExampleAlignedTokenV2.sol delete mode 100644 claim_contracts/src/ExampleAlignedTokenV3.sol delete mode 100644 claim_contracts/src/ExampleClaimableAirdropV2.sol diff --git a/claim_contracts/README.md b/claim_contracts/README.md index 12db0c387..1a5ad4a28 100644 --- a/claim_contracts/README.md +++ b/claim_contracts/README.md @@ -173,7 +173,7 @@ Go into the `config.mainnet.json` file inside the `script-config` directory and ``` { "foundation": "", - "contractProxy": "", + "contractProxy": "" } ``` @@ -187,7 +187,7 @@ Run the script with ``` cd script && \ - forge script \ + forge script \ --sig "run(string)" \ mainnet \ --private-key \ diff --git a/claim_contracts/script/UpgradeToAlignedTokenV2.s.sol b/claim_contracts/script/UpgradeToAlignedTokenV2.s.sol deleted file mode 100644 index db7224259..000000000 --- a/claim_contracts/script/UpgradeToAlignedTokenV2.s.sol +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -// import "../src/TestToken.sol"; -import "../src/ExampleAlignedTokenV2.sol"; -import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; -import "forge-std/Script.sol"; -import {Vm} from "forge-std/Vm.sol"; -import {Utils} from "./Utils.sol"; - -/// @notice This script upgrades the ClaimableAirdrop contract to ClaimableAirdropV2. -/// @dev The `ProxyAdmin` owner must be the runner of this script since it is the -/// one that will call the upgradeAndCall function of the `ProxyAdmin`. -contract UpgradeToAlignedTokenV2 is Script { - function run(string memory config) public { - string memory root = vm.projectRoot(); - string memory path = string.concat( - root, - "/script-config/config.", - config, - ".json" - ); - string memory config_json = vm.readFile(path); - - address _currentTokenProxy = stdJson.readAddress( - config_json, - ".tokenProxy" - ); - - vm.broadcast(); - ExampleAlignedTokenV2 _newToken = new ExampleAlignedTokenV2(); - - bytes memory _tokenUpgradeData = abi.encodeCall( - ProxyAdmin.upgradeAndCall, - ( - ITransparentUpgradeableProxy(_currentTokenProxy), - address(_newToken), - abi.encodeCall(ExampleAlignedTokenV2.reinitialize, ()) - ) - ); - - console.log( - "To finalize the upgrade, call", - getAdminAddress(_currentTokenProxy), - "with the following calldata" - ); - console.logBytes(_tokenUpgradeData); - } - - function getAdminAddress(address proxy) internal view returns (address) { - address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; - Vm vm = Vm(CHEATCODE_ADDRESS); - - bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); - return address(uint160(uint256(adminSlot))); - } -} diff --git a/claim_contracts/script/UpgradeToAlignedTokenV3.s.sol b/claim_contracts/script/UpgradeToAlignedTokenV3.s.sol deleted file mode 100644 index 23653a0df..000000000 --- a/claim_contracts/script/UpgradeToAlignedTokenV3.s.sol +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -// import "../src/TestToken.sol"; -import "../src/ExampleAlignedTokenV3.sol"; -import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; -import "forge-std/Script.sol"; -import {Vm} from "forge-std/Vm.sol"; -import {Utils} from "./Utils.sol"; - -/// @notice This script upgrades the ClaimableAirdrop contract to ClaimableAirdropV2. -/// @dev The `ProxyAdmin` owner must be the runner of this script since it is the -/// one that will call the upgradeAndCall function of the `ProxyAdmin`. -contract UpgradeToAlignedTokenV3 is Script { - function run(string memory config) public { - string memory root = vm.projectRoot(); - string memory path = string.concat( - root, - "/script-config/config.", - config, - ".json" - ); - string memory config_json = vm.readFile(path); - - address _currentTokenProxy = stdJson.readAddress( - config_json, - ".tokenProxy" - ); - - vm.broadcast(); - ExampleAlignedTokenV3 _newToken = new ExampleAlignedTokenV3(); - - bytes memory _tokenUpgradeData = abi.encodeCall( - ProxyAdmin.upgradeAndCall, - ( - ITransparentUpgradeableProxy(_currentTokenProxy), - address(_newToken), - abi.encodeCall(ExampleAlignedTokenV3.reinitialize, ()) - ) - ); - - console.log( - "To finalize the upgrade, call", - getAdminAddress(_currentTokenProxy), - "with the following calldata" - ); - console.logBytes(_tokenUpgradeData); - } - - function getAdminAddress(address proxy) internal view returns (address) { - address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; - Vm vm = Vm(CHEATCODE_ADDRESS); - - bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); - return address(uint160(uint256(adminSlot))); - } -} diff --git a/claim_contracts/script/UpgradeToClaimableAirdropV2Data.s.sol b/claim_contracts/script/UpgradeToClaimableAirdropV2Data.s.sol deleted file mode 100644 index 7c21dc2be..000000000 --- a/claim_contracts/script/UpgradeToClaimableAirdropV2Data.s.sol +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -// import "../src/TestToken.sol"; -import "../src/ExampleAlignedTokenV2.sol"; -import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; -import "forge-std/Script.sol"; -import {Vm} from "forge-std/Vm.sol"; -import {Utils} from "./Utils.sol"; - -/// @notice This script upgrades the ClaimableAirdrop contract to ClaimableAirdropV2. -/// @dev The `ProxyAdmin` owner must be the runner of this script since it is the -/// one that will call the upgradeAndCall function of the `ProxyAdmin`. -contract UpgradeToAlignedTokenV2 is Script { - function run(string memory config) public { - string memory root = vm.projectRoot(); - string memory path = string.concat( - root, - "/script-config/config.", - config, - ".json" - ); - string memory config_json = vm.readFile(path); - - address _currentClaimableAirdropProxy = stdJson.readAddress( - config_json, - ".claimableProxy" - ); - - vm.broadcast(); - ExampleAlignedTokenV2 _newClaimable = new ExampleAlignedTokenV2(); - - bytes memory _upgradeCalldata = abi.encodeCall( - ProxyAdmin.upgradeAndCall, - ( - ITransparentUpgradeableProxy(_currentClaimableAirdropProxy), - address(_newClaimable), - abi.encodeCall(ExampleAlignedTokenV2.reinitialize, ()) - ) - ); - - console.logBytes(_upgradeCalldata); - console.log( - "Proxy Admin to call:", - getAdminAddress(_currentClaimableAirdropProxy) - ); - } - - function getAdminAddress(address proxy) internal view returns (address) { - address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; - Vm vm = Vm(CHEATCODE_ADDRESS); - - bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); - return address(uint160(uint256(adminSlot))); - } -} diff --git a/claim_contracts/script/UpgradeToken.s.sol b/claim_contracts/script/UpgradeToken.s.sol deleted file mode 100644 index 3dd2478ea..000000000 --- a/claim_contracts/script/UpgradeToken.s.sol +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -// import "../src/TestToken.sol"; -import "../src/ExampleAlignedTokenV2.sol"; -import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; -import "forge-std/Script.sol"; -import {Vm} from "forge-std/Vm.sol"; -import {Utils} from "./Utils.sol"; - -/// @notice This script upgrades the ClaimableAirdrop contract to ClaimableAirdropV2. -/// @dev The `ProxyAdmin` owner must be the runner of this script since it is the -/// one that will call the upgradeAndCall function of the `ProxyAdmin`. -contract UpgradeToAlignedTokenV2 is Script { - function run(string memory config) public { - string memory root = vm.projectRoot(); - string memory path = string.concat( - root, - "/script-config/config.", - config, - ".json" - ); - string memory config_json = vm.readFile(path); - - address _currentTokenProxy = stdJson.readAddress( - config_json, - ".tokenProxy" - ); - - vm.startBroadcast(); - ExampleAlignedTokenV2 _newToken = new ExampleAlignedTokenV2(); - - address _adminAddress = getAdminAddress(_currentTokenProxy); - - ProxyAdmin(_adminAddress).upgradeAndCall( - ITransparentUpgradeableProxy(_currentTokenProxy), - address(_newToken), - abi.encodeCall(ExampleAlignedTokenV2.reinitialize, ()) - ); - - vm.stopBroadcast(); - } - - function getAdminAddress(address proxy) internal view returns (address) { - address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; - Vm vm = Vm(CHEATCODE_ADDRESS); - - bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); - return address(uint160(uint256(adminSlot))); - } -} diff --git a/claim_contracts/src/ExampleAlignedTokenV2.sol b/claim_contracts/src/ExampleAlignedTokenV2.sol deleted file mode 100644 index 04b35138d..000000000 --- a/claim_contracts/src/ExampleAlignedTokenV2.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.13; - -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; -import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; -import "./AlignedToken.sol"; - -contract ExampleAlignedTokenV2 is AlignedToken { - /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { - _disableInitializers(); - } - - function reinitialize() public reinitializer(2) {} - - function helloWorld() public pure returns (string memory) { - return "Hello World"; - } -} diff --git a/claim_contracts/src/ExampleAlignedTokenV3.sol b/claim_contracts/src/ExampleAlignedTokenV3.sol deleted file mode 100644 index 61d5a25ed..000000000 --- a/claim_contracts/src/ExampleAlignedTokenV3.sol +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; - -contract ExampleAlignedTokenV3 is - Initializable, - ERC20Upgradeable, - ERC20PermitUpgradeable, - ERC20BurnableUpgradeable, - Ownable2StepUpgradeable -{ - /// @notice Name of the token. - string public constant NAME = "Test Token"; - - /// @notice Symbol of the token. - string public constant SYMBOL = "TESTITO"; - - /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { - _disableInitializers(); - } - - /// @notice Initializes the contract. - /// @dev This initializer should be called only once. - /// @param _foundation address of the foundation. - /// @param _tokenDistributor address of the claim supplier. This is the address - /// that will give the tokens to the users that claim them. - function initialize( - address _foundation, - address _tokenDistributor - ) public initializer { - require( - _foundation != address(0) && _tokenDistributor != address(0), - "Invalid _foundation or _tokenDistributor" - ); - __ERC20_init(NAME, SYMBOL); - __ERC20Permit_init(NAME); - __ERC20Burnable_init(); - __Ownable2Step_init(); // default is msg.sender - _transferOwnership(_foundation); - _mint(_foundation, 7_300_000_000e18); // 7.3 billion - _mint(_tokenDistributor, 2_700_000_000e18); // 2.7 billion - } - - function reinitialize() public reinitializer(3) {} - - /// @notice Mints `amount` of tokens. - function mint(address to, uint256 amount) external onlyOwner { - _mint(to, amount * 2); - } - - /// @notice Prevents the owner from renouncing ownership. - function renounceOwnership() public view override onlyOwner { - revert("Cannot renounce ownership"); - } -} diff --git a/claim_contracts/src/ExampleClaimableAirdropV2.sol b/claim_contracts/src/ExampleClaimableAirdropV2.sol deleted file mode 100644 index 97919b118..000000000 --- a/claim_contracts/src/ExampleClaimableAirdropV2.sol +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.28; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; -import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; -import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; -import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; - -/// @title Claimable Airdrop -/// @notice This contract is the implementation of the Claimable Airdrop -/// @dev This contract is upgradeable and should be used only through the proxy contract -/// @custom:security-contact security@alignedfoundation.org -contract ExampleClaimableAirdropV2 is - Initializable, - ReentrancyGuardUpgradeable, - PausableUpgradeable, - Ownable2StepUpgradeable -{ - /// @notice Address of the token contract to claim. - address public tokenProxy; - - /// @notice Address of the wallet that has the tokens to distribute to the claimants. - address public tokenDistributor; - - /// @notice Timestamp until which the claimants can claim the tokens. - uint256 public limitTimestampToClaim; - - /// @notice Merkle root of the claimants. - bytes32 public claimMerkleRoot; - - /// @notice Mapping of the claimants that have claimed the tokens. - /// @dev true if the claimant has claimed the tokens. - mapping(address claimer => bool claimed) public hasClaimed; - - /// @notice Event emitted when a claimant claims the tokens. - /// @param to address of the claimant. - /// @param amount amount of tokens claimed. - event TokensClaimed(address indexed to, uint256 indexed amount); - - /// @notice Event emitted when the Merkle root is updated. - /// @param newRoot new Merkle root. - event MerkleRootUpdated(bytes32 indexed newRoot); - - /// @notice Event emitted when the claim period is extended. - /// @param newTimestamp new timestamp until which the claimants can claim the tokens. - event ClaimPeriodExtended(uint256 indexed newTimestamp); - - /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { - _disableInitializers(); - } - - /// @notice Initializes the contract. - /// @dev This initializer should be called only once. - /// @param _foundation address of the Aligned foundation. - /// @param _tokenProxy address of the token contract. - /// @param _tokenDistributor address of the wallet that has the tokens to distribute to the claimants. - function initialize( - address _foundation, - address _tokenProxy, - address _tokenDistributor - ) external initializer { - require(_foundation != address(0), "Invalid foundation address"); - require(_tokenProxy != address(0), "Invalid token contract address"); - require(_tokenDistributor != address(0), "Invalid token owner address"); - - __Ownable_init(_foundation); - __Pausable_init(); - __ReentrancyGuard_init(); - - tokenProxy = _tokenProxy; - tokenDistributor = _tokenDistributor; - limitTimestampToClaim = 0; - claimMerkleRoot = 0; - - _pause(); - } - - /// @notice Claim the tokens. - /// @param amount amount of tokens to claim. - /// @param merkleProof Merkle proof of the claim. - function claim( - uint256 amount, - bytes32[] calldata merkleProof - ) external nonReentrant whenNotPaused { - require( - !hasClaimed[msg.sender], - "Account has already claimed the drop" - ); - require( - block.timestamp <= limitTimestampToClaim, - "Drop is no longer claimable" - ); - - bytes32 leaf = keccak256( - bytes.concat(keccak256(abi.encode(msg.sender, amount))) - ); - bool verifies = MerkleProof.verify(merkleProof, claimMerkleRoot, leaf); - - require(verifies, "Invalid Merkle proof"); - - // Done before the transfer call to make sure the reentrancy bug is not possible - hasClaimed[msg.sender] = true; - - bool success = IERC20(tokenProxy).transferFrom( - tokenDistributor, - msg.sender, - amount - ); - - require(success, "Failed to transfer funds"); - - emit TokensClaimed(msg.sender, amount); - } - - /// @notice Update the Merkle root. - /// @param newRoot new Merkle root. - function updateMerkleRoot(bytes32 newRoot) external whenPaused onlyOwner { - require(newRoot != 0 && newRoot != claimMerkleRoot, "Invalid root"); - claimMerkleRoot = newRoot; - emit MerkleRootUpdated(newRoot); - } - - /// @notice Extend the claim period. - /// @param newTimestamp new timestamp until which the claimants can claim the tokens. - function extendClaimPeriod( - uint256 newTimestamp - ) external whenPaused onlyOwner { - require( - newTimestamp > limitTimestampToClaim && - newTimestamp > block.timestamp, - "Can only extend from current timestamp" - ); - limitTimestampToClaim = newTimestamp; - emit ClaimPeriodExtended(newTimestamp); - } - - /// @notice Pause the contract. - function pause() external onlyOwner { - _pause(); - } - - /// @notice Unpause the contract. - function unpause() external onlyOwner { - _unpause(); - } -}