Skip to content

Commit

Permalink
chore: upgrade BSC, Arbitrum, Optimsm, and Scroll with support for ze…
Browse files Browse the repository at this point in the history
…ro_refund_check
  • Loading branch information
OnahProsperity committed Nov 29, 2024
1 parent d3fdec8 commit 0b7fb54
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions scripts/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { confirmContinue, waitForInput } from "./utils";

const networkConfig = NETWORKS[network.config.chainId as keyof typeof NETWORKS];

async function deployNewImplementation() {
const factory = await ethers.getContractFactory("Gateway");
const newImplementation = await factory.deploy();
await newImplementation.deployed();
console.log("✅ Deployed new implementation: ", newImplementation.address);
return newImplementation.address;
}

async function upgradeProxy() {
await confirmContinue({
contract: "Gateway",
Expand Down Expand Up @@ -51,36 +59,41 @@ async function manualUpgrade() {

const [signer] = await ethers.getSigners(); // Get the signer (the account performing the upgrade)
const balance = await signer.getBalance(); // Get the balance of the signer's address

if (balance.eq(0)) {
throw new Error(`Can't upgrade ${network.config.chainId} with 0 balance`);
}
const proxyContractAddress = networkConfig.GATEWAY_CONTRACT;
const proxy = await ethers.getContractAt("TransparentUpgradeableProxy", proxyContractAddress);
// Get the proxy admin address
const proxyAdminAddress = await proxy.admin();
console.log(`Proxy Admin Address: ${proxyAdminAddress}`);

// Get the Proxy Admin contract
const proxyAdmin = await ethers.getContractAt("ProxyAdmin", proxyAdminAddress);
const currentImplAddress = await upgrades.erc1967.getImplementationAddress(proxyContractAddress);

// Check if IMPLEMENTATION exists in networkConfig
if (!('IMPLEMENTATION' in networkConfig)) {
throw new Error(`No implementation address found for chainId: ${network.config.chainId}`);
}
// Fetch the new implementation address from deployment.json
const newImplementationAddress = networkConfig.IMPLEMENTATION;
// Deploy the new implementation contract
const newImplementationAddress = await deployNewImplementation();

if (!newImplementationAddress) {
throw new Error(`No implementation address found for chainId: ${network.config.chainId}`);
}
// Check if the new implementation address is the same as the current one
if (currentImplAddress.toLowerCase() === newImplementationAddress.toLowerCase()) {
throw new Error("New implementation address is the same as the current implementation.");
}

console.log(`Upgrading proxy to new implementation: ${newImplementationAddress}`);
const proxyAdminAddress = await upgrades.admin.getInstance().then((instance) =>
instance.getProxyAdmin(proxyContractAddress)
);

// Connect to the ProxyAdmin contract
const ProxyAdminABI = [
"function upgrade(address proxy, address implementation) public",
];
const proxyAdmin = new ethers.Contract(proxyAdminAddress, ProxyAdminABI, signer);

// Perform the upgrade
const tx = await proxyAdmin.upgrade(proxyContractAddress, newImplementationAddress);
await tx.wait();

await hre.run("verify:verify", {
address: proxyContractAddress,
});

// Call the upgrade function on the Proxy Admin contract
await proxyAdmin.upgrade(proxyContractAddress, newImplementationAddress);
console.log("✅ Proxy upgraded successfully!");

console.log(`✅ Successfully upgraded proxy at ${proxyContractAddress} to new implementation at ${newImplementationAddress}`);
} catch (error) {
if (error instanceof Error) {
console.error("❌ Upgrade failed: ", error.message);
Expand Down

0 comments on commit 0b7fb54

Please sign in to comment.