|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.19; |
| 3 | + |
| 4 | +import "../src/AlignedTokenV1.sol"; |
| 5 | +import "../src/ClaimableAirdropV1.sol"; |
| 6 | +import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 7 | +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 8 | +import "forge-std/Script.sol"; |
| 9 | +import {Utils} from "./Utils.sol"; |
| 10 | + |
| 11 | +contract DeployAll is Script { |
| 12 | + function run() public { |
| 13 | + string memory root = vm.projectRoot(); |
| 14 | + string memory path = string.concat(root, "/script-config/config.json"); |
| 15 | + string memory config_json = vm.readFile(path); |
| 16 | + |
| 17 | + address _safe = stdJson.readAddress(config_json, ".safe"); |
| 18 | + bytes32 _salt = stdJson.readBytes32(config_json, ".salt"); |
| 19 | + address _deployer = stdJson.readAddress(config_json, ".deployer"); |
| 20 | + address _beneficiary1 = stdJson.readAddress( |
| 21 | + config_json, |
| 22 | + ".beneficiary1" |
| 23 | + ); |
| 24 | + address _beneficiary2 = stdJson.readAddress( |
| 25 | + config_json, |
| 26 | + ".beneficiary2" |
| 27 | + ); |
| 28 | + address _beneficiary3 = stdJson.readAddress( |
| 29 | + config_json, |
| 30 | + ".beneficiary3" |
| 31 | + ); |
| 32 | + uint256 _mintAmount = stdJson.readUint(config_json, ".mintAmount"); |
| 33 | + uint256 _limitTimestampToClaim = stdJson.readUint( |
| 34 | + config_json, |
| 35 | + ".limitTimestampToClaim" |
| 36 | + ); |
| 37 | + bytes32 _claimMerkleRoot = stdJson.readBytes32( |
| 38 | + config_json, |
| 39 | + ".claimMerkleRoot" |
| 40 | + ); |
| 41 | + uint256 _holderPrivateKey = stdJson.readUint( |
| 42 | + config_json, |
| 43 | + ".holderPrivateKey" |
| 44 | + ); |
| 45 | + |
| 46 | + ProxyAdmin _proxyAdmin = deployProxyAdmin(_safe, _salt, _deployer); |
| 47 | + |
| 48 | + TransparentUpgradeableProxy _tokenProxy = deployAlignedTokenProxy( |
| 49 | + address(_proxyAdmin), |
| 50 | + _salt, |
| 51 | + _deployer, |
| 52 | + _beneficiary1, |
| 53 | + _beneficiary2, |
| 54 | + _beneficiary3, |
| 55 | + _mintAmount |
| 56 | + ); |
| 57 | + |
| 58 | + TransparentUpgradeableProxy _airdropProxy = deployClaimableAirdropProxy( |
| 59 | + address(_proxyAdmin), |
| 60 | + _safe, |
| 61 | + _beneficiary1, |
| 62 | + _salt, |
| 63 | + _deployer, |
| 64 | + address(_tokenProxy), |
| 65 | + _limitTimestampToClaim, |
| 66 | + _claimMerkleRoot |
| 67 | + ); |
| 68 | + |
| 69 | + approve( |
| 70 | + address(_tokenProxy), |
| 71 | + address(_airdropProxy), |
| 72 | + _holderPrivateKey |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + function deployProxyAdmin( |
| 77 | + address _safe, |
| 78 | + bytes32 _salt, |
| 79 | + address _deployer |
| 80 | + ) internal returns (ProxyAdmin) { |
| 81 | + bytes memory _proxyAdminDeploymentData = Utils.proxyAdminDeploymentData( |
| 82 | + _safe |
| 83 | + ); |
| 84 | + address _proxyAdminCreate2Address = Utils.deployWithCreate2( |
| 85 | + _proxyAdminDeploymentData, |
| 86 | + _salt, |
| 87 | + _deployer |
| 88 | + ); |
| 89 | + |
| 90 | + console.log( |
| 91 | + "Proxy Admin Address:", |
| 92 | + _proxyAdminCreate2Address, |
| 93 | + "Owner:", |
| 94 | + _safe |
| 95 | + ); |
| 96 | + vm.serializeAddress("proxyAdmin", "address", _proxyAdminCreate2Address); |
| 97 | + vm.serializeBytes( |
| 98 | + "proxyAdmin", |
| 99 | + "deploymentData", |
| 100 | + _proxyAdminDeploymentData |
| 101 | + ); |
| 102 | + |
| 103 | + return ProxyAdmin(_proxyAdminCreate2Address); |
| 104 | + } |
| 105 | + |
| 106 | + function deployAlignedTokenProxy( |
| 107 | + address _proxyAdmin, |
| 108 | + bytes32 _salt, |
| 109 | + address _deployer, |
| 110 | + address _beneficiary1, |
| 111 | + address _beneficiary2, |
| 112 | + address _beneficiary3, |
| 113 | + uint256 _mintAmount |
| 114 | + ) internal returns (TransparentUpgradeableProxy) { |
| 115 | + vm.broadcast(); |
| 116 | + AlignedTokenV1 _token = new AlignedTokenV1(); |
| 117 | + |
| 118 | + bytes memory _alignedTokenDeploymentData = Utils |
| 119 | + .alignedTokenProxyDeploymentData( |
| 120 | + _proxyAdmin, |
| 121 | + address(_token), |
| 122 | + _beneficiary1, |
| 123 | + _beneficiary2, |
| 124 | + _beneficiary3, |
| 125 | + _mintAmount |
| 126 | + ); |
| 127 | + address _alignedTokenProxy = Utils.deployWithCreate2( |
| 128 | + _alignedTokenDeploymentData, |
| 129 | + _salt, |
| 130 | + _deployer |
| 131 | + ); |
| 132 | + |
| 133 | + console.log( |
| 134 | + "AlignedToken proxy deployed with address:", |
| 135 | + _alignedTokenProxy, |
| 136 | + "and admin:", |
| 137 | + _proxyAdmin |
| 138 | + ); |
| 139 | + vm.serializeAddress("alignedToken", "address", _alignedTokenProxy); |
| 140 | + vm.serializeBytes( |
| 141 | + "alignedToken", |
| 142 | + "deploymentData", |
| 143 | + _alignedTokenDeploymentData |
| 144 | + ); |
| 145 | + |
| 146 | + return TransparentUpgradeableProxy(payable(_alignedTokenProxy)); |
| 147 | + } |
| 148 | + |
| 149 | + function deployClaimableAirdropProxy( |
| 150 | + address _proxyAdmin, |
| 151 | + address _owner, |
| 152 | + address _tokenOwner, |
| 153 | + bytes32 _salt, |
| 154 | + address _deployer, |
| 155 | + address _token, |
| 156 | + uint256 _limitTimestampToClaim, |
| 157 | + bytes32 _claimMerkleRoot |
| 158 | + ) internal returns (TransparentUpgradeableProxy) { |
| 159 | + vm.broadcast(); |
| 160 | + ClaimableAirdropV1 _airdrop = new ClaimableAirdropV1(); |
| 161 | + |
| 162 | + bytes memory _airdropDeploymentData = Utils |
| 163 | + .claimableAirdropProxyDeploymentData( |
| 164 | + _proxyAdmin, |
| 165 | + address(_airdrop), |
| 166 | + _owner, |
| 167 | + _token, |
| 168 | + _tokenOwner, |
| 169 | + _limitTimestampToClaim, |
| 170 | + _claimMerkleRoot |
| 171 | + ); |
| 172 | + address _airdropProxy = Utils.deployWithCreate2( |
| 173 | + _airdropDeploymentData, |
| 174 | + _salt, |
| 175 | + _deployer |
| 176 | + ); |
| 177 | + |
| 178 | + console.log( |
| 179 | + "ClaimableAirdropV1 proxy deployed with address:", |
| 180 | + _airdropProxy, |
| 181 | + "and admin:", |
| 182 | + _proxyAdmin |
| 183 | + ); |
| 184 | + vm.serializeAddress("claimableAirdrop", "address", _airdropProxy); |
| 185 | + vm.serializeBytes( |
| 186 | + "claimableAirdrop", |
| 187 | + "deploymentData", |
| 188 | + _airdropDeploymentData |
| 189 | + ); |
| 190 | + |
| 191 | + return TransparentUpgradeableProxy(payable(_airdropProxy)); |
| 192 | + } |
| 193 | + |
| 194 | + function approve( |
| 195 | + address _tokenContractProxy, |
| 196 | + address _airdropContractProxy, |
| 197 | + uint256 _holderPrivateKey |
| 198 | + ) public { |
| 199 | + vm.startBroadcast(_holderPrivateKey); |
| 200 | + (bool success, bytes memory data) = address(_tokenContractProxy).call( |
| 201 | + abi.encodeCall( |
| 202 | + IERC20.approve, |
| 203 | + (address(_airdropContractProxy), 1 ether) |
| 204 | + ) |
| 205 | + ); |
| 206 | + bool approved; |
| 207 | + assembly { |
| 208 | + approved := mload(add(data, 0x20)) |
| 209 | + } |
| 210 | + |
| 211 | + if (!success || !approved) { |
| 212 | + revert("Failed to give approval to airdrop contract"); |
| 213 | + } |
| 214 | + vm.stopBroadcast(); |
| 215 | + |
| 216 | + console.log("Succesfully gave approval to airdrop contract"); |
| 217 | + } |
| 218 | +} |
0 commit comments