Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds rollup data fetching from Orbit template #1981

Merged
merged 48 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9398e29
feat: adds new scripts project
douglance Sep 27, 2024
0a58302
prettier fix
douglance Sep 27, 2024
35a2145
Merge branch 'master' into dl/new-script-proj
douglance Oct 1, 2024
660785c
Merge branch 'master' into dl/new-script-proj
douglance Oct 1, 2024
dd3847e
respond to pr feedback
douglance Oct 1, 2024
52d57b2
remove error for contract acheck
douglance Oct 1, 2024
f51e11d
preserve order of json file
douglance Oct 1, 2024
ca7d0af
fix ordering
douglance Oct 1, 2024
4ac1c8c
fix output of transform
douglance Oct 1, 2024
7273524
Merge branch 'master' into dl/new-script-proj
douglance Oct 2, 2024
8520033
remove goerli
douglance Oct 2, 2024
a23aca6
update tests in ci
douglance Oct 2, 2024
0352235
Merge branch 'master' into dl/new-script-proj
douglance Oct 2, 2024
943b3cc
update trigger
douglance Oct 2, 2024
e268280
update triggers
douglance Oct 2, 2024
dbb8aa7
fix project name
douglance Oct 2, 2024
1dba588
migrate to chainsdata
douglance Oct 2, 2024
03f2abe
build the validation script
douglance Oct 2, 2024
87840c4
Merge branch 'master' into dl/new-script-proj
douglance Oct 3, 2024
e35e65d
more cleanup
douglance Oct 3, 2024
f11556d
update issue template to use dropdown
douglance Oct 3, 2024
92a2614
Update packages/scripts/src/addOrbitChain/schemas.ts
douglance Oct 3, 2024
b1f7332
address PR comments
douglance Oct 3, 2024
6edf09d
update holesky placeholders
douglance Oct 3, 2024
63dfe53
update url transform
douglance Oct 3, 2024
f40e167
Merge branch 'master' into dl/new-script-proj
douglance Oct 4, 2024
33c5f90
addresses PR comments
douglance Oct 4, 2024
ad68c13
fix extra space
douglance Oct 7, 2024
7bcd724
feat: adds rollup data fetching to simplify input
douglance Oct 9, 2024
d1cec7d
fix name
douglance Oct 9, 2024
84f036f
fix types
douglance Oct 9, 2024
402fc64
Merge branch 'master' into dl/fs-905
fionnachan Oct 10, 2024
edb4fff
Merge branch 'master' into dl/fs-905
douglance Oct 10, 2024
4da6794
Merge branch 'master' into dl/fs-905
douglance Oct 10, 2024
0b1ccd2
update the rollup data fetching to arb/sdk
douglance Oct 14, 2024
9ed56ad
Merge branch 'master' into dl/fs-905
douglance Oct 14, 2024
c86d1e4
remove comments
douglance Oct 14, 2024
eb5ceca
Merge branch 'master' into dl/fs-905
douglance Oct 17, 2024
46c6563
revert yarn lock changes
douglance Oct 18, 2024
0b81040
Merge branch 'main' into dl/fs-905
douglance Oct 18, 2024
eda964b
Merge branch 'master' into dl/fs-905
fionnachan Oct 18, 2024
b9a81eb
fix yarn.lock after merge potentially
douglance Oct 18, 2024
87353c4
Merge branch 'dl/fs-905' of github.com:OffchainLabs/arbitrum-token-br…
douglance Oct 18, 2024
7abf2c0
actually fix yarn lock
douglance Oct 18, 2024
00b52eb
fix prettier
douglance Oct 18, 2024
c1a17dc
Merge branch 'master' into dl/fs-905
douglance Oct 21, 2024
3a6db91
make rollup addresses singular
douglance Oct 21, 2024
e1f8993
Merge branch 'master' into dl/fs-905
spsjvc Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions .github/ISSUE_TEMPLATE/add-orbit-chain-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ 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:
Expand All @@ -135,34 +128,11 @@ body:
attributes:
douglance marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
101 changes: 101 additions & 0 deletions packages/scripts/src/addOrbitChain/network.ts
Copy link
Member

Choose a reason for hiding this comment

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

arb sdk has a method called getArbitrumNetworkInformationFromRollup that gives all these info

https://github.com/OffchainLabs/arbitrum-sdk/blob/792a7ee3ccf09842653bc49b771671706894cbb4/src/lib/dataEntities/networks.ts#L363

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing that out! we're now using that function 🫡

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { ethers } from "ethers";

export async function getProvider(rpcUrl: string) {
console.log(`Connecting to provider at ${rpcUrl}`);
try {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
await provider.getNetwork(); // Test the connection
console.log("Successfully connected to the provider");
return provider;
} catch (error) {
console.error("Failed to connect to the provider:", error);
throw error;
}
}

export async function getRollupContract(
rollupAddress: string,
provider: ethers.providers.Provider
) {
console.log(`Creating rollup contract instance at address ${rollupAddress}`);
const rollupABI = [
"function bridge() view returns (address)",
"function inbox() view returns (address)",
"function sequencerInbox() view returns (address)",
"function outbox() view returns (address)",
"function confirmPeriodBlocks() view returns (uint256)",
];
return new ethers.Contract(rollupAddress, rollupABI, provider);
}

async function callContractMethod(
contract: ethers.Contract,
methodName: string
) {
console.log(`Calling ${methodName} method on contract`);
try {
const result = await contract[methodName]();
console.log(`${methodName} call successful:`, result);
return result;
} catch (error) {
console.error(`Error calling ${methodName}:`, error);
throw error;
}
}

export async function getBridge(rollupContract: ethers.Contract) {
return await callContractMethod(rollupContract, "bridge");
}

export async function getInbox(rollupContract: ethers.Contract) {
return await callContractMethod(rollupContract, "inbox");
}

export async function getSequencerInbox(rollupContract: ethers.Contract) {
return await callContractMethod(rollupContract, "sequencerInbox");
}

export async function getOutbox(rollupContract: ethers.Contract) {
return await callContractMethod(rollupContract, "outbox");
}

export async function getConfirmPeriodBlocks(rollupContract: ethers.Contract) {
const confirmPeriodBlocks = await callContractMethod(
rollupContract,
"confirmPeriodBlocks"
);
return confirmPeriodBlocks.toNumber();
}

export async function fetchRollupContractData(
rollupAddress: string,
rpcUrl: string
) {
console.log(`Fetching rollup contract data for address ${rollupAddress}`);
try {
const provider = await getProvider(rpcUrl);
const rollupContract = await getRollupContract(rollupAddress, provider);

console.log("Fetching contract data...");
const [bridge, inbox, sequencerInbox, outbox, confirmPeriodBlocks] =
await Promise.all([
getBridge(rollupContract),
getInbox(rollupContract),
getSequencerInbox(rollupContract),
getOutbox(rollupContract),
getConfirmPeriodBlocks(rollupContract),
]);

console.log("Successfully fetched all contract data");
return {
bridge,
inbox,
sequencerInbox,
outbox,
confirmPeriodBlocks,
};
} catch (error) {
console.error("Error fetching rollup contract data:", error);
throw error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -191,7 +191,7 @@ export const mockIncomingChainData: IncomingChainData = {
bridge: "0x0000000000000000000000000000000000000001",
inbox: "0x0000000000000000000000000000000000000002",
outbox: "0x0000000000000000000000000000000000000003",
rollup: "0x0000000000000000000000000000000000000004",
rollup: "0xeedE9367Df91913ab149e828BDd6bE336df2c892",
sequencerInbox: "0x0000000000000000000000000000000000000005",
parentGatewayRouter: "0x0000000000000000000000000000000000000009",
childGatewayRouter: "0x0000000000000000000000000000000000000016",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
91 changes: 91 additions & 0 deletions packages/scripts/src/addOrbitChain/tests/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
fetchRollupContractData,
getProvider,
getRollupContract,
} from "../network";

describe("Network Functions", () => {
it("fetches rollup contract data for an Arbitrum Orbit chain", async () => {
const parentChainRpcUrl = "https://sepolia-rollup.arbitrum.io/rpc";
const orbitChainRollupAddress =
"0xeedE9367Df91913ab149e828BDd6bE336df2c892";

console.log("Starting test with the following parameters:");
console.log("Parent Chain RPC URL:", parentChainRpcUrl);
console.log("Orbit Chain Rollup Address:", orbitChainRollupAddress);

try {
// check if we can connect to the provider
const provider = await getProvider(parentChainRpcUrl);
const network = await provider.getNetwork();
console.log(
"Connected to network:",
network.name,
"chainId:",
network.chainId
);

// check if the contract exists
const code = await provider.getCode(orbitChainRollupAddress);
if (code === "0x") {
throw new Error("No contract found at the given address");
}
console.log("Contract found at the given address");

// ry to interact with the contract
const contract = await getRollupContract(
orbitChainRollupAddress,
provider
);

// try to call each method individually and log the result
for (const method of [
"bridge",
"inbox",
"sequencerInbox",
"outbox",
"confirmPeriodBlocks",
]) {
try {
const result = await contract[method]();
console.log(`${method}() call successful:`, result);
} catch (error) {
console.error(`Error calling ${method}():`, error);
}
}

const rollupData = await fetchRollupContractData(
orbitChainRollupAddress,
parentChainRpcUrl
);

// Log the fetched data
console.log(
"Fetched Rollup Contract Data:",
JSON.stringify(rollupData, null, 2)
);

// Assertions to verify the structure and content of the fetched data
expect(rollupData).toHaveProperty("bridge");
expect(rollupData).toHaveProperty("inbox");
expect(rollupData).toHaveProperty("sequencerInbox");
expect(rollupData).toHaveProperty("outbox");
expect(rollupData).toHaveProperty("confirmPeriodBlocks");

// Check that the addresses are valid Ethereum addresses
const addressRegex = /^0x[a-fA-F0-9]{40}$/;
expect(rollupData.bridge).toMatch(addressRegex);
expect(rollupData.inbox).toMatch(addressRegex);
expect(rollupData.sequencerInbox).toMatch(addressRegex);
expect(rollupData.outbox).toMatch(addressRegex);

// Check that confirmPeriodBlocks is a positive number
expect(rollupData.confirmPeriodBlocks).toBeGreaterThan(0);

console.log("All assertions passed successfully");
} catch (error) {
console.error("Test failed with error:", error);
throw error;
}
}, 30000); // Increase timeout to 30 seconds for network calls
});
4 changes: 2 additions & 2 deletions packages/scripts/src/addOrbitChain/tests/transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,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
Expand Down
29 changes: 18 additions & 11 deletions packages/scripts/src/addOrbitChain/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getIssue,
updateContent,
} from "./github";
import { fetchRollupContractData } from "./network";
import {
chainDataLabelToKey,
IncomingChainData,
Expand Down Expand Up @@ -116,7 +117,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
Expand All @@ -129,7 +130,7 @@ export const createAndValidateOrbitChain = async (
};

export const updateAndValidateOrbitChainsList = async (
orbitChain: ReturnType<typeof transformIncomingDataToOrbitChain>,
orbitChain: OrbitChain,
targetJsonPath: string
) => {
core.startGroup("Orbit ChainsList Update and Validation");
Expand All @@ -151,7 +152,7 @@ export const commitChangesAndCreatePR = async (
branchName: string,
targetJsonPath: string,
updatedOrbitChainsList: ReturnType<typeof updateOrbitChainsFile>,
orbitChain: ReturnType<typeof transformIncomingDataToOrbitChain>
orbitChain: OrbitChain
) => {
core.startGroup("Commit Changes and Create Pull Request");
console.log("Preparing to commit changes...");
Expand All @@ -170,7 +171,7 @@ export const commitChangesAndCreatePR = async (

export const setOutputs = (
branchName: string,
orbitChain: ReturnType<typeof transformIncomingDataToOrbitChain>,
orbitChain: OrbitChain,
targetJsonPath: string
) => {
core.startGroup("Set Outputs");
Expand Down Expand Up @@ -279,23 +280,29 @@ export const fetchAndSaveImage = async (
return `/${imageSavePath}`;
};

export const transformIncomingDataToOrbitChain = (
export const transformIncomingDataToOrbitChain = async (
chainData: IncomingChainData,
chainLogoPath: string,
nativeTokenLogoPath?: string
): OrbitChain => {
): Promise<OrbitChain> => {
const parentChainId = parseInt(chainData.parentChainId, 10);
const isTestnet = TESTNET_PARENT_CHAIN_IDS.includes(parentChainId);

// Fetch rollup contract data
const rollupData = await fetchRollupContractData(
chainData.rollup,
chainData.rpcUrl
);

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.bridge,
inbox: rollupData.inbox,
outbox: rollupData.outbox,
rollup: chainData.rollup,
sequencerInbox: chainData.sequencerInbox,
sequencerInbox: rollupData.sequencerInbox,
},
nativeToken: chainData.nativeTokenAddress,
explorerUrl: chainData.explorerUrl,
Expand Down
Loading