Skip to content

Commit 39a5753

Browse files
committed
fix: redeploy address whitelist script
Signed-off-by: Reinis Martinsons <[email protected]>
1 parent 5b33321 commit 39a5753

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ MNEMONIC="your mnemonic phrase here"
1313
# If set to 0x0000000000000000000000000000000000000000, burns ownership to zero address
1414
# WHITELIST_OWNER="0x1234567890123456789012345678901234567890"
1515

16+
# =============================================================================
17+
# ADDRESSWHITELIST REDEPLOYMENT VARIABLES
18+
# =============================================================================
19+
20+
# Required for redeployment: The address of the previous AddressWhitelist contract to duplicate
21+
# PREVIOUS_ADDRESS_WHITELIST="0x1234567890123456789012345678901234567890"
22+
1623
# =============================================================================
1724
# MANAGEDOPTIMISTICORACLEV2-SPECIFIC VARIABLES
1825
# =============================================================================

script/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,55 @@ The `AddressWhitelist` contract:
8181
- Supports adding/removing addresses from whitelist
8282
- Includes ownership management capabilities
8383

84+
## AddressWhitelist Redeployment
85+
86+
The `RedeployAddressWhitelist.s.sol` script deploys a new `AddressWhitelist` contract that duplicates the configuration from a previously deployed contract.
87+
88+
### Environment Variables
89+
90+
| Variable | Required | Description |
91+
|----------|----------|-------------|
92+
| `MNEMONIC` | Yes | The mnemonic phrase for the deployer wallet (uses 0 index address) |
93+
| `PREVIOUS_ADDRESS_WHITELIST` | Yes | The address of the previous AddressWhitelist contract to duplicate |
94+
95+
### Usage Examples
96+
97+
```bash
98+
# Redeploy with configuration from previous contract
99+
forge script script/RedeployAddressWhitelist.s.sol --rpc-url "YOUR_RPC_URL" --broadcast
100+
```
101+
102+
### Features
103+
104+
- **Configuration duplication**: Copies all whitelisted addresses from the previous contract
105+
- **Ownership preservation**: Transfers ownership to the same address if different from deployer
106+
- **Ownership burning**: Burns ownership if the previous contract had no owner
107+
- **Verification**: Includes verification that the whitelist was copied correctly
108+
- **Detailed logging**: Provides comprehensive redeployment information and status updates
109+
110+
### What Gets Copied
111+
112+
- All whitelisted addresses from the previous contract
113+
- Ownership configuration (same owner or burned ownership)
114+
115+
### What Gets Reset
116+
117+
- Contract address (new deployment)
118+
- Contract state (fresh contract instance)
119+
120+
### Etherscan Verification
121+
122+
After redeployment, verify the new contract on Etherscan:
123+
124+
```bash
125+
forge verify-contract <NEW_CONTRACT_ADDRESS> src/common/implementation/AddressWhitelist.sol:AddressWhitelist --chain-id <CHAIN_ID> --etherscan-api-key <YOUR_ETHERSCAN_API_KEY>
126+
```
127+
128+
**Replace:**
129+
- `<NEW_CONTRACT_ADDRESS>` with the newly deployed contract address
130+
- `<CHAIN_ID>` with the network chain ID (1 for Ethereum mainnet, 11155111 for Sepolia, etc.)
131+
- `<YOUR_ETHERSCAN_API_KEY>` with your Etherscan API key
132+
84133
## DisabledAddressWhitelist Deployment
85134

86135
The `DeployDisabledAddressWhitelist.s.sol` script deploys the `DisabledAddressWhitelist` contract with optional configuration.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity ^0.8.0;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
import {AddressWhitelist} from "../src/common/implementation/AddressWhitelist.sol";
7+
8+
/**
9+
* @title Redeployment script for AddressWhitelist
10+
* @notice Deploys a new AddressWhitelist contract duplicating the configuration from a previous deployment
11+
*
12+
* Environment variables:
13+
* - MNEMONIC: Required. The mnemonic phrase for the deployer wallet
14+
* - PREVIOUS_ADDRESS_WHITELIST: Required. The address of the previous AddressWhitelist contract to duplicate
15+
*/
16+
contract RedeployAddressWhitelist is Script {
17+
function run() external {
18+
// Load environment variables from .env file (if it exists)
19+
// This will automatically load variables from .env file in the project root
20+
21+
// Get required environment variables
22+
string memory mnemonic = vm.envString("MNEMONIC");
23+
address previousWhitelist = vm.envAddress("PREVIOUS_ADDRESS_WHITELIST");
24+
25+
// Derive the 0 index address from mnemonic
26+
uint256 deployerPrivateKey = vm.deriveKey(mnemonic, 0);
27+
address deployer = vm.addr(deployerPrivateKey);
28+
29+
console.log("Previous AddressWhitelist:", previousWhitelist);
30+
console.log("Deployer:", deployer);
31+
32+
// Get the previous contract instance
33+
AddressWhitelist previousWhitelistContract = AddressWhitelist(previousWhitelist);
34+
35+
// Get the previous owner
36+
address previousOwner = previousWhitelistContract.owner();
37+
console.log("Previous Owner:", previousOwner);
38+
39+
// Get all whitelisted addresses from the previous contract
40+
address[] memory whitelistedAddresses = previousWhitelistContract.getWhitelist();
41+
console.log("Number of whitelisted addresses to copy:", whitelistedAddresses.length);
42+
43+
// Start broadcasting transactions with the derived private key
44+
vm.startBroadcast(deployerPrivateKey);
45+
46+
// Deploy the new contract with deployer as owner (always safe)
47+
AddressWhitelist newWhitelist = new AddressWhitelist();
48+
console.log("New AddressWhitelist deployed at:", address(newWhitelist));
49+
50+
// Copy all whitelisted addresses from the previous contract
51+
if (whitelistedAddresses.length > 0) {
52+
console.log("Copying whitelisted addresses...");
53+
for (uint256 i = 0; i < whitelistedAddresses.length; i++) {
54+
address addr = whitelistedAddresses[i];
55+
newWhitelist.addToWhitelist(addr);
56+
console.log("Added to whitelist:", addr);
57+
}
58+
console.log("Finished copying whitelisted addresses");
59+
}
60+
61+
// Handle ownership logic
62+
if (previousOwner == address(0)) {
63+
// If the previous contract had no owner (burned), burn ownership on the new contract
64+
console.log("Previous contract had no owner, burning ownership on new contract...");
65+
newWhitelist.renounceOwnership();
66+
console.log("Ownership burned to zero address");
67+
} else if (previousOwner != deployer) {
68+
// If the previous owner is different from deployer, transfer ownership to the same address
69+
console.log("Transferring ownership to previous owner:", previousOwner);
70+
newWhitelist.transferOwnership(previousOwner);
71+
console.log("Ownership transferred to:", previousOwner);
72+
} else {
73+
// If the previous owner is the same as deployer, keep deployer as owner
74+
console.log("Keeping deployer as owner:", deployer);
75+
}
76+
77+
vm.stopBroadcast();
78+
79+
// Output deployment summary
80+
console.log("\n=== Redeployment Summary ===");
81+
console.log("New Contract:", address(newWhitelist));
82+
console.log("Previous Contract:", previousWhitelist);
83+
console.log("Chain ID:", block.chainid);
84+
console.log("Deployer:", deployer);
85+
console.log("Previous Owner:", previousOwner);
86+
console.log("Final Owner:", newWhitelist.owner());
87+
console.log("Whitelisted Addresses Copied:", whitelistedAddresses.length);
88+
89+
// Verify the whitelist was copied correctly
90+
address[] memory newWhitelistAddresses = newWhitelist.getWhitelist();
91+
console.log("New Contract Whitelist Count:", newWhitelistAddresses.length);
92+
93+
if (whitelistedAddresses.length == newWhitelistAddresses.length) {
94+
console.log("[SUCCESS] Whitelist copy verification: SUCCESS");
95+
} else {
96+
console.log("[FAILED] Whitelist copy verification: FAILED");
97+
console.log("Expected:", whitelistedAddresses.length);
98+
console.log("Actual:", newWhitelistAddresses.length);
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)