import { ethers } from "hardhat"; import * as fs from "fs"; async function main() { const [deployer] = await ethers.getSigners(); console.log("Deploying to Base with account:", deployer.address); const chainId = 8453; const rpcUrl = process.env.BASE_RPC_URL || "https://mainnet.base.org"; const ccipRouter = process.env.BASE_CCIP_ROUTER || "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D"; const chainSelector = BigInt('15971525489660198786'); console.log(`\n=== Deploying to Base (Chain ID: ${chainId}) ===`); try { // Deploy Diamond const Diamond = await ethers.getContractFactory("Diamond"); const diamond = await Diamond.deploy(); await diamond.waitForDeployment(); const diamondAddress = await diamond.getAddress(); console.log(`Diamond deployed to: ${diamondAddress}`); // Deploy Facets const facets = { DiamondCutFacet: await (await ethers.getContractFactory("DiamondCutFacet")).deploy(), LiquidityFacet: await (await ethers.getContractFactory("LiquidityFacet")).deploy(), VaultFacet: await (await ethers.getContractFactory("VaultFacet")).deploy(), ComplianceFacet: await (await ethers.getContractFactory("ComplianceFacet")).deploy(), CCIPFacet: await (await ethers.getContractFactory("CCIPFacet")).deploy(), GovernanceFacet: await (await ethers.getContractFactory("GovernanceFacet")).deploy(), SecurityFacet: await (await ethers.getContractFactory("SecurityFacet")).deploy(), ChainConfigFacet: await (await ethers.getContractFactory("ChainConfigFacet")).deploy(), }; console.log("Facets deployed"); // Configure CCIP const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress); await ccipFacet.setCCIPRouter(ccipRouter); await ccipFacet.setChainSelector(chainId, chainSelector); console.log(`CCIP Router configured: ${ccipRouter}`); // Configure ChainConfig const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress); await chainConfigFacet.setChainConfig( chainId, "Base", ethers.ZeroAddress, "https://basescan.org", BigInt(3000000), BigInt(300) ); await chainConfigFacet.setChainActive(chainId, true); const deployment = { diamond: diamondAddress, facets: Object.fromEntries( Object.entries(facets).map(([name, contract]) => [name, await contract.getAddress()]) ), chainId: chainId, chainName: "Base", ccipRouter, chainSelector: chainSelector.toString(), }; console.log(`✓ Base deployment complete`); console.log(JSON.stringify(deployment, null, 2)); // Write to file fs.writeFileSync( `deployments-base-${chainId}.json`, JSON.stringify(deployment, null, 2) ); } catch (error) { console.error(`✗ Failed to deploy to Base:`, error); throw error; } } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });