From d4c70d55a2877215ff1848a59a253781a8f187d7 Mon Sep 17 00:00:00 2001 From: doug <4741454+douglance@users.noreply.github.com> Date: Tue, 22 Oct 2024 08:59:58 -0400 Subject: [PATCH] feat: fetch contracts from rollup for automation (#1981) --- .../add-orbit-chain-request.yml | 34 ++----------------- .github/workflows/build-test.yml | 2 +- packages/scripts/package.json | 1 + .../tests/__mocks__/chainDataMocks.ts | 4 +-- .../__snapshots__/transforms.test.ts.snap | 12 +++---- .../addOrbitChain/tests/transforms.test.ts | 4 +-- .../scripts/src/addOrbitChain/transforms.ts | 29 ++++++++++------ 7 files changed, 32 insertions(+), 54 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/add-orbit-chain-request.yml b/.github/ISSUE_TEMPLATE/add-orbit-chain-request.yml index 32a6398dce..75eebf1e8b 100644 --- a/.github/ISSUE_TEMPLATE/add-orbit-chain-request.yml +++ b/.github/ISSUE_TEMPLATE/add-orbit-chain-request.yml @@ -121,50 +121,20 @@ body: attributes: value: | Please fill out this section with your chain configuration details and contract addresses. As a reminder, you can get all contract addresses by running [getAllContracts](https://github.com/OffchainLabs/arbitrum-orbit-sdk/blob/feat-add-verification-scripts/examples/verify-rollup/README.md#get-all-contracts). - - type: input - id: confirmPeriodBlocks - attributes: - label: confirmPeriodBlocks - placeholder: ex. 45818 - validations: - required: true - type: markdown attributes: value: | - ## Rollup contract addresses + ## Rollup contract address - type: markdown attributes: value: | You can find this information under the `"coreContracts" : {...}` key. - - type: input - id: bridge - attributes: - label: bridge - validations: - required: true - - type: input - id: inbox - attributes: - label: inbox - validations: - required: true - - type: input - id: outbox - attributes: - label: outbox - validations: - required: true - type: input id: rollup attributes: label: rollup - validations: - required: true - - type: input - id: sequencerInbox - attributes: - label: sequencerInbox + description: Please provide the address of the rollup contract. Other core contract addresses will be fetched automatically. validations: required: true diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3d60b8d978..e99b5f4bb6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -153,7 +153,7 @@ jobs: - name: Install node_modules uses: OffchainLabs/actions/node-modules/install@main - + - name: Build run: yarn workspace scripts build diff --git a/packages/scripts/package.json b/packages/scripts/package.json index 0c53feef3e..e9d310eb63 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -17,6 +17,7 @@ "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", + "@arbitrum/sdk": "^4.0.1", "@octokit/rest": "^21.0.2", "axios": "^1.7.7", "commander": "^12.1.0", diff --git a/packages/scripts/src/addOrbitChain/tests/__mocks__/chainDataMocks.ts b/packages/scripts/src/addOrbitChain/tests/__mocks__/chainDataMocks.ts index 564357146f..6b47b03366 100644 --- a/packages/scripts/src/addOrbitChain/tests/__mocks__/chainDataMocks.ts +++ b/packages/scripts/src/addOrbitChain/tests/__mocks__/chainDataMocks.ts @@ -180,7 +180,7 @@ export const mockIncomingChainData: IncomingChainData = { description: "This is a test chain.", chainLogo: "https://example.com/testchain.png", color: "#FF0000", - rpcUrl: "https://testrpc.com", + rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc", explorerUrl: "https://testexplorer.com", parentChainId: "421614", confirmPeriodBlocks: "150", @@ -191,7 +191,7 @@ export const mockIncomingChainData: IncomingChainData = { bridge: "0x0000000000000000000000000000000000000001", inbox: "0x0000000000000000000000000000000000000002", outbox: "0x0000000000000000000000000000000000000003", - rollup: "0x0000000000000000000000000000000000000004", + rollup: "0xeedE9367Df91913ab149e828BDd6bE336df2c892", sequencerInbox: "0x0000000000000000000000000000000000000005", parentGatewayRouter: "0x0000000000000000000000000000000000000009", childGatewayRouter: "0x0000000000000000000000000000000000000016", diff --git a/packages/scripts/src/addOrbitChain/tests/__snapshots__/transforms.test.ts.snap b/packages/scripts/src/addOrbitChain/tests/__snapshots__/transforms.test.ts.snap index 70e1a3d876..84d87c2798 100644 --- a/packages/scripts/src/addOrbitChain/tests/__snapshots__/transforms.test.ts.snap +++ b/packages/scripts/src/addOrbitChain/tests/__snapshots__/transforms.test.ts.snap @@ -56,11 +56,11 @@ exports[`Transforms > transformIncomingDataToOrbitChain > should transform incom "chainId": 1234567890, "confirmPeriodBlocks": 150, "ethBridge": { - "bridge": "0x0000000000000000000000000000000000000001", - "inbox": "0x0000000000000000000000000000000000000002", - "outbox": "0x0000000000000000000000000000000000000003", - "rollup": "0x0000000000000000000000000000000000000004", - "sequencerInbox": "0x0000000000000000000000000000000000000005", + "bridge": "0x6c7FAC4edC72E86B3388B48979eF37Ecca5027e6", + "inbox": "0x6396825803B720bc6A43c63caa1DcD7B31EB4dd0", + "outbox": "0xc7491a559b416540427f9f112C5c98b1412c5d51", + "rollup": "0xeedE9367Df91913ab149e828BDd6bE336df2c892", + "sequencerInbox": "0x529a2061A1973be80D315770bA9469F3Da40D938", }, "explorerUrl": "https://testexplorer.com", "isArbitrum": true, @@ -70,7 +70,7 @@ exports[`Transforms > transformIncomingDataToOrbitChain > should transform incom "nativeToken": "0x0000000000000000000000000000000000000006", "parentChainId": 421614, "retryableLifetimeSeconds": 604800, - "rpcUrl": "https://testrpc.com", + "rpcUrl": "https://sepolia-rollup.arbitrum.io/rpc", "slug": "test-chain", "tokenBridge": { "childCustomGateway": "0x0000000000000000000000000000000000000014", diff --git a/packages/scripts/src/addOrbitChain/tests/transforms.test.ts b/packages/scripts/src/addOrbitChain/tests/transforms.test.ts index c7f0690106..d0c078f157 100644 --- a/packages/scripts/src/addOrbitChain/tests/transforms.test.ts +++ b/packages/scripts/src/addOrbitChain/tests/transforms.test.ts @@ -27,11 +27,11 @@ describe("Transforms", () => { }); describe("transformIncomingDataToOrbitChain", () => { - it("should transform incoming chain data to OrbitChain format", () => { + it("should transform incoming chain data to OrbitChain format", async () => { const chainLogoPath = "/images/mockChain_Logo.png"; const nativeTokenLogoPath = "/images/mockChain_NativeTokenLogo.png"; - const result = transformIncomingDataToOrbitChain( + const result = await transformIncomingDataToOrbitChain( mockIncomingChainData as IncomingChainData, chainLogoPath, nativeTokenLogoPath diff --git a/packages/scripts/src/addOrbitChain/transforms.ts b/packages/scripts/src/addOrbitChain/transforms.ts index e34dbf45a2..b90ee3893e 100644 --- a/packages/scripts/src/addOrbitChain/transforms.ts +++ b/packages/scripts/src/addOrbitChain/transforms.ts @@ -3,6 +3,8 @@ import * as core from "@actions/core"; import { warning } from "@actions/core"; +import { getArbitrumNetworkInformationFromRollup } from "@arbitrum/sdk"; +import { JsonRpcProvider } from "@ethersproject/providers"; import axios from "axios"; import * as fs from "fs"; import sharp from "sharp"; @@ -118,7 +120,7 @@ export const createAndValidateOrbitChain = async ( ) => { core.startGroup("Orbit Chain Creation and Validation"); console.log("Creating OrbitChain object..."); - const orbitChain = transformIncomingDataToOrbitChain( + const orbitChain = await transformIncomingDataToOrbitChain( validatedIncomingData, chainLogoPath, nativeTokenLogoPath @@ -131,7 +133,7 @@ export const createAndValidateOrbitChain = async ( }; export const updateAndValidateOrbitChainsList = async ( - orbitChain: ReturnType, + orbitChain: OrbitChain, targetJsonPath: string ) => { core.startGroup("Orbit ChainsList Update and Validation"); @@ -153,7 +155,7 @@ export const commitChangesAndCreatePR = async ( branchName: string, targetJsonPath: string, updatedOrbitChainsList: ReturnType, - orbitChain: ReturnType + orbitChain: OrbitChain ) => { core.startGroup("Commit Changes and Create Pull Request"); console.log("Preparing to commit changes..."); @@ -181,7 +183,7 @@ export const commitChangesAndCreatePR = async ( export const setOutputs = ( branchName: string, - orbitChain: ReturnType, + orbitChain: OrbitChain, targetJsonPath: string ) => { core.startGroup("Set Outputs"); @@ -334,23 +336,28 @@ export const fetchAndSaveImage = async ( return `/${imageSavePath}`; }; -export const transformIncomingDataToOrbitChain = ( +export const transformIncomingDataToOrbitChain = async ( chainData: IncomingChainData, chainLogoPath: string, nativeTokenLogoPath?: string -): OrbitChain => { +): Promise => { const parentChainId = parseInt(chainData.parentChainId, 10); const isTestnet = TESTNET_PARENT_CHAIN_IDS.includes(parentChainId); + const provider = new JsonRpcProvider(chainData.rpcUrl); + const rollupData = await getArbitrumNetworkInformationFromRollup( + chainData.rollup, + provider + ); return { chainId: parseInt(chainData.chainId, 10), - confirmPeriodBlocks: parseInt(chainData.confirmPeriodBlocks, 10), + confirmPeriodBlocks: rollupData.confirmPeriodBlocks, ethBridge: { - bridge: chainData.bridge, - inbox: chainData.inbox, - outbox: chainData.outbox, + bridge: rollupData.ethBridge.bridge, + inbox: rollupData.ethBridge.inbox, + outbox: rollupData.ethBridge.outbox, rollup: chainData.rollup, - sequencerInbox: chainData.sequencerInbox, + sequencerInbox: rollupData.ethBridge.sequencerInbox, }, nativeToken: chainData.nativeTokenAddress, explorerUrl: chainData.explorerUrl,