mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-09 22:18:00 -05:00
feat(contracts): add ownership transfer scripts (#28)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ The scripts should run as below sequence:
|
||||
```bash
|
||||
export layer1=l1geth # change to actual network name
|
||||
export layer2=l2geth # change to actual network name
|
||||
export owner=0x0000000000000000000000000000000000000000 # change to actual owner
|
||||
|
||||
# deploy contracts in layer 1
|
||||
npx hardhat --network $layer1 run scripts/deploy_proxy_admin.ts
|
||||
@@ -42,6 +43,22 @@ npx hardhat --network $layer2 run scripts/initialize_l2_custom_erc20_gateway.ts
|
||||
npx hardhat --network $layer2 run scripts/initialize_l2_erc1155_gateway.ts
|
||||
npx hardhat --network $layer2 run scripts/initialize_l2_erc721_gateway.ts
|
||||
npx hardhat --network $layer2 run scripts/initialize_l2_token_factory.ts
|
||||
|
||||
# transfer ownership in layer 1
|
||||
env CONTRACT_NAME=ProxyAdmin CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L1ScrollMessenger CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=ZKRollup CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L1GatewayRouter CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L1CustomERC20Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L1ERC721Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L1ERC1155Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer1 scripts/transfer_ownership.ts
|
||||
# transfer ownership in layer 2
|
||||
env CONTRACT_NAME=ProxyAdmin CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L2ScrollMessenger CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L2GatewayRouter CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L2CustomERC20Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L2ERC721Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
env CONTRACT_NAME=L2ERC1155Gateway CONTRACT_OWNER=$owner npx hardhat run --network $layer2 scripts/transfer_ownership.ts
|
||||
```
|
||||
|
||||
Reference testnet [run.sh](https://github.com/scroll-tech/testnet/blob/main/run.sh) for details.
|
||||
|
||||
@@ -8,10 +8,11 @@ async function main() {
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
|
||||
const owner = process.env.CONTRACT_OWNER || deployer.address;
|
||||
if (!addressFile.get("L2ScrollMessenger")) {
|
||||
console.log(">> Deploy L2ScrollMessenger implementation");
|
||||
const L2ScrollMessenger = await ethers.getContractFactory("L2ScrollMessenger", deployer);
|
||||
const impl = await L2ScrollMessenger.deploy(deployer.address);
|
||||
const impl = await L2ScrollMessenger.deploy(owner);
|
||||
console.log(`>> waiting for transaction: ${impl.deployTransaction.hash}`);
|
||||
await impl.deployed();
|
||||
console.log(`✅ L2ScrollMessenger implementation deployed at ${impl.address}`);
|
||||
|
||||
36
contracts/scripts/transfer_ownership.ts
Normal file
36
contracts/scripts/transfer_ownership.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/* eslint-disable node/no-missing-import */
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
import * as hre from "hardhat";
|
||||
import { ethers } from "hardhat";
|
||||
import { selectAddressFile } from "./utils";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
async function main() {
|
||||
const addressFile = selectAddressFile(hre.network.name);
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
|
||||
if (process.env.CONTRACT_NAME === undefined) {
|
||||
throw new Error("env CONTRACT_NAME undefined");
|
||||
}
|
||||
const contractName = process.env.CONTRACT_NAME!;
|
||||
const contractAddress = addressFile.get(`${contractName}.proxy`) || addressFile.get(`${contractName}`);
|
||||
const Contract = await ethers.getContractAt(contractName, contractAddress, deployer);
|
||||
|
||||
const owner = process.env.CONTRACT_OWNER || deployer.address;
|
||||
if ((await Contract.owner()).toLowerCase() !== owner.toLowerCase()) {
|
||||
const tx = await Contract.transferOwnership(owner);
|
||||
console.log(`${contractName} transfer ownership to ${owner}, hash: ${tx.hash}`);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
// and properly handle errors.
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user