Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,66 @@ const monadTestnetChain: Chain = {
},
};

const chains = {
const citreaTestnetChain: Chain = {
id: 5115,
name: 'Citrea Testnet',
rpcUrls: {
default: {
http: ['https://rpc.testnet.citrea.xyz'],
},
},
nativeCurrency: {
name: 'cBTC',
symbol: 'cBTC',
decimals: 18,
},
};

const inkMainnetChain: Chain = {
id: 57073,
name: 'Ink Mainnet',
rpcUrls: {
default: {
http: ['https://rpc-qnd.inkonchain.com'],
},
},
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
};

const inkSepoliaChain: Chain = {
id: 763373,
name: 'Ink Sepolia',
rpcUrls: {
default: {
http: ['https://ink-sepolia.drpc.org'],
},
},
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
};

export const chains = {
...allChains,
megaEthTestNet: megaEthTestNetChain,
berachainMainnet: berachainMainnetChain,
bepoliaTestnet: bepoliaTestnetChain,
unichain: unichainChain,
monadTestnet: monadTestnetChain,
citreaTestnet: citreaTestnetChain,
inkMainnet: inkMainnetChain,
inkSepolia: inkSepoliaChain,
} as any as { [key: string]: Chain };

// The default rpc urls for these chains are not reliable, so we override them
// This may be a game of cat and mouse, so a better solution may be needed.
const rpcUrlOverrides = {
export const rpcUrlOverrides = {
[chains.mainnet.id]: 'https://eth.merkle.io',
[chains.bsc.id]: 'https://bsc-dataseed1.binance.org/',
[chains.bscTestnet.id]: 'https://bsc-testnet-rpc.publicnode.com',
Expand Down
6 changes: 6 additions & 0 deletions packages/delegation-deployments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export const CHAIN_ID = {
polygon: 137,
base: 8453,
arbitrum: 42161,
inkMainnet: 57073,
linea: 59144,
berachain: 80094,
unichain: 130,
arbitrumNova: 42170,
// Testnets
bscTestnet: 97,
citreaTestnet: 5115,
megaEthTestnet: 6342,
chiado: 10200,
lineaSepolia: 59141,
Expand All @@ -29,6 +31,7 @@ export const CHAIN_ID = {
optimismSepolia: 11155420,
unichainSepolia: 1301,
polygonAmoy: 80002,
inkSepolia: 763373,
monadTestnet: 10143,
// decommissioned
lineaGoerli: 59140,
Expand Down Expand Up @@ -79,6 +82,7 @@ export const DELEGATOR_CONTRACTS: DeployedContracts = {
[CHAIN_ID.bsc]: deployments_1_3_0,
[CHAIN_ID.optimism]: deployments_1_3_0,
[CHAIN_ID.arbitrum]: deployments_1_3_0,
[CHAIN_ID.inkMainnet]: deployments_1_3_0,
[CHAIN_ID.linea]: deployments_1_3_0,
[CHAIN_ID.base]: deployments_1_3_0,
[CHAIN_ID.gnosis]: deployments_1_3_0,
Expand All @@ -87,6 +91,7 @@ export const DELEGATOR_CONTRACTS: DeployedContracts = {
[CHAIN_ID.arbitrumNova]: deployments_1_3_0,
// Testnets
[CHAIN_ID.sepolia]: deployments_1_3_0,
[CHAIN_ID.citreaTestnet]: deployments_1_3_0,
[CHAIN_ID.lineaSepolia]: deployments_1_3_0,
[CHAIN_ID.baseSepolia]: deployments_1_3_0,
[CHAIN_ID.megaEthTestnet]: deployments_1_3_0,
Expand All @@ -97,6 +102,7 @@ export const DELEGATOR_CONTRACTS: DeployedContracts = {
[CHAIN_ID.berachainBepolia]: deployments_1_3_0,
[CHAIN_ID.unichainSepolia]: deployments_1_3_0,
[CHAIN_ID.polygonAmoy]: deployments_1_3_0,
[CHAIN_ID.inkSepolia]: deployments_1_3_0,
[CHAIN_ID.monadTestnet]: deployments_1_3_0,
},
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh damn, I think this file can actually go away. We no longer run this validation as an automated test, because it was causing too many false positives.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I deleted it

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createPublicClient, http } from 'viem';
import * as chains from 'viem/chains';
import type { Chain } from 'viem/chains';

import { DELEGATOR_CONTRACTS } from '../src/index';
import { compareVersions } from 'compare-versions';
import {
chains,
rpcUrlOverrides,
} from '../script/validate-contract-deployments';
/*
This test validates that the DeleGator contracts are deployed on the specified chains,
as specified in the @metamask-private/delegation-deployments package.
Expand All @@ -12,13 +14,6 @@ import { compareVersions } from 'compare-versions';
code is found at the expected address for each contract.
*/

// The default rpc urls for these chains are not reliable, so we override them
// This may be a game of cat and mouse, so a better solution may be needed.
const rpcUrlOverrides = {
[chains.mainnet.id]: 'https://eth.merkle.io',
[chains.bsc.id]: 'https://bsc-dataseed1.binance.org/',
};

const latestVersion = Object.keys(DELEGATOR_CONTRACTS).reduce(
(acc, version) => {
if (compareVersions(version, acc) === 1) {
Expand All @@ -35,12 +30,12 @@ const chainIds = Object.keys(latestContracts);

let hasFailed = false;

const allChains = chainIds.map(async (chainIdAsString) => {
const allChainValidations = chainIds.map(async (chainIdAsString) => {
const chainId = parseInt(chainIdAsString);
const contracts = latestContracts[chainIdAsString];

const transport = http(rpcUrlOverrides[chainId]);
const chain = (chains as any as Chain[]).find((c) => c.id === chainId);
const chain = Object.values(chains).find((c) => c.id === chainId);

if (!chain) {
throw new Error(`Chain ${chainId} not found`);
Expand Down Expand Up @@ -71,7 +66,7 @@ const allChains = chainIds.map(async (chainIdAsString) => {
console.log(`${chain.name} succeeded`);
});

Promise.all(allChains).then(() => {
Promise.all(allChainValidations).then(() => {
if (hasFailed) {
process.exitCode = 1;
console.error('Failed to validate contract deployments');
Expand Down
60 changes: 49 additions & 11 deletions packages/delegation-toolkit/src/blockchain.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this can go away too - and it's corresponding tests.

This used to be part of the public API, before we cleaned it up, and was implemented to support an experiment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I deleted it

Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { CHAIN_ID } from '@metamask/delegation-deployments';

const CHAIN_EXPLORERS = {
[CHAIN_ID.arbitrum]: 'https://arbiscan.io',
[CHAIN_ID.arbitrumNova]: 'https://nova.arbiscan.io',
[CHAIN_ID.arbitrumSepolia]: 'https://sepolia.arbiscan.io',
[CHAIN_ID.base]: 'https://basescan.org',
[CHAIN_ID.baseSepolia]: 'https://sepolia.basescan.org',
[CHAIN_ID.berachain]: 'https://berascan.com',
[CHAIN_ID.berachainBepolia]: 'https://testnet.berascan.com',
[CHAIN_ID.bsc]: 'https://bscscan.com',
[CHAIN_ID.bscTestnet]: 'https://testnet.bscscan.com',
[CHAIN_ID.gnosis]: 'https://gnosisscan.io',
[CHAIN_ID.linea]: 'https://lineascan.build',
[CHAIN_ID.lineaSepolia]: 'https://sepolia.lineascan.build',
[CHAIN_ID.mainnet]: 'https://etherscan.io',
[CHAIN_ID.monadTestnet]: 'https://testnet.monadscan.com',
[CHAIN_ID.optimism]: 'https://optimistic.etherscan.io',
[CHAIN_ID.optimismSepolia]: 'https://sepolia-optimism.etherscan.io',
[CHAIN_ID.polygon]: 'https://polygonscan.com',
[CHAIN_ID.base]: 'https://basescan.org',
[CHAIN_ID.arbitrum]: 'https://arbiscan.io',
[CHAIN_ID.linea]: 'https://lineascan.build',
[CHAIN_ID.polygonAmoy]: 'https://amoy.polygonscan.com',
[CHAIN_ID.sepolia]: 'https://sepolia.etherscan.io',
[CHAIN_ID.lineaSepolia]: 'https://sepolia.lineascan.build',
[CHAIN_ID.unichain]: 'https://uniscan.xyz',
[CHAIN_ID.unichainSepolia]: 'https://sepolia.uniscan.xyz',
};

const getExplorerLink = (chainId: number) => {
Expand All @@ -32,25 +45,50 @@ export const getExplorerTransactionLink = (chainId: number, hash: string) => {
export const shortenHash = (address: string | undefined) =>
address ? `${address.slice(0, 6)}...` : '';

export const getInfuraRpcUrl = (chainId: number, apiKey?: string) => {
/**
* Returns the Infura RPC URL for a given chainId and API key.
* @param chainId - The chain ID.
* @param apiKey - Infura API key.
* @returns The Infura RPC URL.
* @throws If the API key is missing or the chain is unsupported.
*/
export const getInfuraRpcUrl = (chainId: number, apiKey?: string): string => {
if (!apiKey) {
throw new Error('Infura API key is required');
}
switch (chainId) {
case CHAIN_ID.arbitrum:
return `https://arbitrum-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.arbitrumSepolia:
return `https://arbitrum-sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.base:
return `https://base-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.baseSepolia:
return `https://base-sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.bsc:
return `https://bsc-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.bscTestnet:
return `https://bsc-testnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.linea:
return `https://linea-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.lineaSepolia:
return `https://linea-sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.mainnet:
return `https://mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.optimism:
return `https://optimism-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.optimismSepolia:
return `https://optimism-sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.polygon:
return `https://polygon-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.arbitrum:
return `https://arbitrum-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.linea:
return `https://linea-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.polygonAmoy:
return `https://polygon-amoy.infura.io/v3/${apiKey}`;
case CHAIN_ID.sepolia:
return `https://sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.lineaSepolia:
return `https://linea-sepolia.infura.io/v3/${apiKey}`;
case CHAIN_ID.unichain:
return `https://unichain-mainnet.infura.io/v3/${apiKey}`;
case CHAIN_ID.unichainSepolia:
return `https://unichain-sepolia.infura.io/v3/${apiKey}`;
default:
throw new Error(`Unsupported chainId: ${chainId}`);
}
Expand Down
Loading