Skip to content

Add lido gateway upgrade script#721

Merged
chengwenxi merged 1 commit intomainfrom
lido_upgrade
Feb 17, 2025
Merged

Add lido gateway upgrade script#721
chengwenxi merged 1 commit intomainfrom
lido_upgrade

Conversation

@Kukoomomo
Copy link
Copy Markdown
Contributor

@Kukoomomo Kukoomomo commented Feb 17, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new deployment tool that automates the launch of gateway contracts with built-in address validation and clear deployment status.
  • Bug Fixes

    • Enhanced the upgrade process by enforcing strict input validation and ensuring the proper interaction of contract components for a more reliable upgrade workflow.

@Kukoomomo Kukoomomo requested a review from a team as a code owner February 17, 2025 06:37
@Kukoomomo Kukoomomo requested review from r3aker86 and removed request for a team February 17, 2025 06:37
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 17, 2025

Walkthrough

This pull request introduces two sets of changes. A new deployment script (lido_impl_deploy.ts) is added to deploy the L1LidoGateway and L2LidoGateway contracts via Hardhat, with validations for WstETH addresses and error handling. Additionally, the proxy upgrade task (proxy_upgrade.ts) has been updated to include input validations for Ethereum addresses, update the contract instantiation logic, and modify the call context for retrieving the implementation address during a proxy upgrade.

Changes

File(s) Change Summary
contracts/scripts/lido_impl_deploy.ts Added a new deployment script that validates WstETH addresses, deploys L1LidoGateway and L2LidoGateway via Hardhat, waits for deployment confirmation, and logs deployed contract addresses.
contracts/tasks/proxy_upgrade.ts Updated the upgrade task to validate inputs for proxyadminaddr, proxyaddr, and newimpladdr; modified contract retrieval logic to use precise contract interfaces; adjusted the call context.

Sequence Diagram(s)

sequenceDiagram
    participant Script as LidoDeployScript
    participant Env as Environment Vars
    participant Ethers as ethers.utils
    participant HF as Hardhat
    participant Log as Console Log

    Script->>Env: Fetch WstETH addresses
    Script->>Ethers: Validate addresses
    alt Invalid Address
        Ethers-->>Script: Invalid result
        Script->>Log: Log "token address is invalid"
        Script->>Script: Exit with error
    else Valid Addresses
        Script->>HF: Retrieve contract factories
        Script->>HF: Deploy L1LidoGateway & L2LidoGateway
        HF-->>Script: Return contract instances
        Script->>Log: Log deployed contract addresses
        Script->>Script: End process
    end
Loading
sequenceDiagram
    participant Task as ProxyUpgradeTask
    participant Ethers as hre.ethers.utils
    participant Contract as Contract Instance
    participant Log as Console Log

    Task->>Ethers: Validate proxyadminaddr, proxyaddr, newimpladdr
    alt Any Invalid Address
        Ethers-->>Task: Return invalid result
        Task->>Log: Log "token address invalid"
        Task->>Task: Exit with error
    else Valid Addresses
        Task->>Task: Instantiate ProxyAdmin via correct contract interface
        Task->>Task: Instantiate Proxy using ITransparentUpgradeableProxy
        Task->>Contract: Call static implementation with proxyadminaddr context
        Contract-->>Task: Return implementation address
        Task->>Log: Log proxy upgrade details
    end
Loading

Poem

I'm just a rabbit, hopping with glee,
Deploying contracts under the digital tree.
Validations in place, not a single mistake,
Upgrading proxies, for goodness' sake!
Codes and rabbits, together we soar—
🐰💻 Hoppy changes forevermore!
Let the bytes and hops align once more!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
contracts/scripts/lido_impl_deploy.ts (3)

1-6: Consider using TypeScript imports consistently.

The code mixes CommonJS (require) and ES6 (import) module systems. Consider using ES6 imports consistently.

-const hre = require("hardhat");
+import { ethers } from "hardhat";
 import 'dotenv/config';
-const { ethers } = hre;

9-11: Improve error message specificity.

The current error message "token address invalid" doesn't specify which address is invalid.

-        throw new Error("token address invalid");
+        throw new Error(
+            `Invalid addresses detected:\n${
+                !ethers.utils.isAddress(L1WstETHAddr) ? `- L1WstETH: ${L1WstETHAddr}\n` : ''
+            }${
+                !ethers.utils.isAddress(L2WstETHAddr) ? `- L2WstETH: ${L2WstETHAddr}` : ''
+            }`
+        );

16-20: Add deployment verification and event logging.

The deployment process could benefit from additional verification steps and more detailed logging.

     const l1LidoGatewayImpl = await L1LidoGatewayFactory.deploy(L1WstETHAddr, L2WstETHAddr)
     const l2LidoGatewayImpl = await L2LidoGatewayFactory.deploy(L1WstETHAddr, L2WstETHAddr)
+    console.log('Waiting for deployments to complete...')
     await l1LidoGatewayImpl.deployed()
     await l2LidoGatewayImpl.deployed()
-    console.log(`impl deployed l1LidoGatewayImpl ${l1LidoGatewayImpl.address}, l2LidoGatewayImpl ${l2LidoGatewayImpl.address}`)
+    console.log('Deployments completed successfully:')
+    console.log(`- L1LidoGateway Implementation: ${l1LidoGatewayImpl.address}`)
+    console.log(`- L2LidoGateway Implementation: ${l2LidoGatewayImpl.address}`)
+    
+    // Verify contract code is deployed
+    const l1Code = await ethers.provider.getCode(l1LidoGatewayImpl.address)
+    const l2Code = await ethers.provider.getCode(l2LidoGatewayImpl.address)
+    if (l1Code === '0x' || l2Code === '0x') {
+        throw new Error('Contract deployment verification failed')
+    }
contracts/tasks/proxy_upgrade.ts (2)

12-15: Improve error message specificity.

Similar to the deployment script, the error message should specify which address is invalid.

-            throw new Error("token address invalid");
+            throw new Error(
+                `Invalid addresses detected:\n${
+                    !hre.ethers.utils.isAddress(taskArgs.proxyadminaddr) ? `- ProxyAdmin: ${taskArgs.proxyadminaddr}\n` : ''
+                }${
+                    !hre.ethers.utils.isAddress(taskArgs.proxyaddr) ? `- Proxy: ${taskArgs.proxyaddr}\n` : ''
+                }${
+                    !hre.ethers.utils.isAddress(taskArgs.newimpladdr) ? `- New Implementation: ${taskArgs.newimpladdr}` : ''
+                }`
+            );

24-29: Add upgrade verification and event logging.

The upgrade process should include additional verification steps and more detailed logging.

         const res = await proxyAdmin.upgrade(taskArgs.proxyaddr, taskArgs.newimpladdr)
         const receipt = await res.wait()
-        console.log(`receipt status : ${receipt.status}`)
+        console.log(`Upgrade transaction status: ${receipt.status ? 'Success' : 'Failed'}`)
+        console.log(`Transaction hash: ${receipt.transactionHash}`)
+        
+        // Verify the implementation was updated
         const newImpl = await proxy.connect(hre.waffle.provider).callStatic.implementation({
             from: taskArgs.proxyadminaddr,
         }))
+        if (newImpl.toLowerCase() !== taskArgs.newimpladdr.toLowerCase()) {
+            throw new Error(
+                `Implementation address mismatch.\nExpected: ${taskArgs.newimpladdr}\nActual: ${newImpl}`
+            )
+        }
+        console.log('Implementation address updated successfully')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1c6c5f and 3bb1dfd.

📒 Files selected for processing (2)
  • contracts/scripts/lido_impl_deploy.ts (1 hunks)
  • contracts/tasks/proxy_upgrade.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

@chengwenxi chengwenxi merged commit 9e1d0de into main Feb 17, 2025
2 checks passed
@chengwenxi chengwenxi deleted the lido_upgrade branch February 17, 2025 06:51
@coderabbitai coderabbitai bot mentioned this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants