diff --git a/packages/delegation-deployments/script/validate-contract-deployments.ts b/packages/delegation-deployments/script/validate-contract-deployments.ts index c212f5a5..f47e8b06 100644 --- a/packages/delegation-deployments/script/validate-contract-deployments.ts +++ b/packages/delegation-deployments/script/validate-contract-deployments.ts @@ -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', diff --git a/packages/delegation-deployments/src/index.ts b/packages/delegation-deployments/src/index.ts index a544af5d..3edbcb57 100644 --- a/packages/delegation-deployments/src/index.ts +++ b/packages/delegation-deployments/src/index.ts @@ -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, @@ -29,6 +31,7 @@ export const CHAIN_ID = { optimismSepolia: 11155420, unichainSepolia: 1301, polygonAmoy: 80002, + inkSepolia: 763373, monadTestnet: 10143, // decommissioned lineaGoerli: 59140, @@ -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, @@ -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, @@ -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, }, }; diff --git a/packages/delegation-deployments/test/validate-contract-deployments.test.ts b/packages/delegation-deployments/test/validate-contract-deployments.test.ts deleted file mode 100644 index e2c83c72..00000000 --- a/packages/delegation-deployments/test/validate-contract-deployments.test.ts +++ /dev/null @@ -1,81 +0,0 @@ -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'; -/* - This test validates that the DeleGator contracts are deployed on the specified chains, - as specified in the @metamask-private/delegation-deployments package. - - It does this by getting the DeleGatorEnvironment for each chain and then ensuring that - 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) { - return version; - } - return acc; - }, - '0.0.0', -); - -const latestContracts = DELEGATOR_CONTRACTS[latestVersion]; - -const chainIds = Object.keys(latestContracts); - -let hasFailed = false; - -const allChains = 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); - - if (!chain) { - throw new Error(`Chain ${chainId} not found`); - } - - const publicClient = createPublicClient({ - chain, - transport, - }); - - const contractNames = Object.keys(contracts); - - const allContracts = contractNames.map(async (contractName) => { - const contractAddress = contracts[contractName]; - - const code = await publicClient.getCode({ address: contractAddress }); - - if (code === '0x') { - console.error( - `${chain.name}: ${contractName} is not deployed at ${contractAddress}`, - ); - hasFailed = true; - } - }); - - await Promise.all(allContracts); - - console.log(`${chain.name} succeeded`); -}); - -Promise.all(allChains).then(() => { - if (hasFailed) { - process.exitCode = 1; - console.error('Failed to validate contract deployments'); - } else { - console.log('Successfully validated contract deployments'); - } -}); diff --git a/packages/delegation-toolkit/src/blockchain.ts b/packages/delegation-toolkit/src/blockchain.ts deleted file mode 100644 index cbdd5d96..00000000 --- a/packages/delegation-toolkit/src/blockchain.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { CHAIN_ID } from '@metamask/delegation-deployments'; - -const CHAIN_EXPLORERS = { - [CHAIN_ID.mainnet]: 'https://etherscan.io', - [CHAIN_ID.optimism]: 'https://optimistic.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.sepolia]: 'https://sepolia.etherscan.io', - [CHAIN_ID.lineaSepolia]: 'https://sepolia.lineascan.build', -}; - -const getExplorerLink = (chainId: number) => { - const url = CHAIN_EXPLORERS[chainId]; - if (!url) { - throw new Error(`Unsupported chainId: ${chainId}`); - } - return url; -}; - -export const getExplorerAddressLink = (chainId: number, address: string) => { - const prefix = getExplorerLink(chainId); - return `${prefix}/address/${address}`; -}; - -export const getExplorerTransactionLink = (chainId: number, hash: string) => { - const prefix = getExplorerLink(chainId); - return `${prefix}/tx/${hash}`; -}; - -export const shortenHash = (address: string | undefined) => - address ? `${address.slice(0, 6)}...` : ''; - -export const getInfuraRpcUrl = (chainId: number, apiKey?: string) => { - if (!apiKey) { - throw new Error('Infura API key is required'); - } - switch (chainId) { - 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.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.sepolia: - return `https://sepolia.infura.io/v3/${apiKey}`; - case CHAIN_ID.lineaSepolia: - return `https://linea-sepolia.infura.io/v3/${apiKey}`; - default: - throw new Error(`Unsupported chainId: ${chainId}`); - } -};