Add initial project structure and documentation files
- Created .gitignore to exclude sensitive files and directories. - Added API documentation in API_DOCUMENTATION.md. - Included deployment instructions in DEPLOYMENT.md. - Established project structure documentation in PROJECT_STRUCTURE.md. - Updated README.md with project status and team information. - Added recommendations and status tracking documents. - Introduced testing guidelines in TESTING.md. - Set up CI workflow in .github/workflows/ci.yml. - Created Dockerfile for backend and frontend setups. - Added various service and utility files for backend functionality. - Implemented frontend components and pages for user interface. - Included mobile app structure and services. - Established scripts for deployment across multiple chains.
This commit is contained in:
145
scripts/deploy-multichain.ts
Normal file
145
scripts/deploy-multichain.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
import { ethers } from "hardhat";
|
||||
import { Contract } from "ethers";
|
||||
|
||||
async function main() {
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log("Deploying with account:", deployer.address);
|
||||
|
||||
// Chain configurations
|
||||
const chains = [
|
||||
{ name: "Ethereum", chainId: 1, rpcUrl: process.env.ETHEREUM_RPC_URL },
|
||||
{ name: "Polygon", chainId: 137, rpcUrl: process.env.POLYGON_RPC_URL },
|
||||
{ name: "Arbitrum", chainId: 42161, rpcUrl: process.env.ARBITRUM_RPC_URL },
|
||||
{ name: "Optimism", chainId: 10, rpcUrl: process.env.OPTIMISM_RPC_URL },
|
||||
{ name: "BSC", chainId: 56, rpcUrl: process.env.BSC_RPC_URL },
|
||||
{ name: "Avalanche", chainId: 43114, rpcUrl: process.env.AVALANCHE_RPC_URL },
|
||||
{ name: "Base", chainId: 8453, rpcUrl: process.env.BASE_RPC_URL },
|
||||
];
|
||||
|
||||
// CCIP Router addresses (mainnet)
|
||||
const ccipRouters: { [key: number]: string } = {
|
||||
1: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Ethereum
|
||||
137: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Polygon
|
||||
42161: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Arbitrum
|
||||
10: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Optimism
|
||||
56: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // BSC
|
||||
43114: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Avalanche
|
||||
8453: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Base
|
||||
};
|
||||
|
||||
// Chain selectors for CCIP
|
||||
const chainSelectors: { [key: number]: bigint } = {
|
||||
1: BigInt('5009297550715157269'), // Ethereum Mainnet
|
||||
137: BigInt('4051577828743386545'), // Polygon
|
||||
42161: BigInt('4949039107694359620'), // Arbitrum
|
||||
10: BigInt('3734403246176062136'), // Optimism
|
||||
56: BigInt('11344663589394136015'), // BSC
|
||||
43114: BigInt('6433500567565415381'), // Avalanche
|
||||
8453: BigInt('15971525489660198786'), // Base
|
||||
};
|
||||
|
||||
const deployments: { [key: number]: any } = {};
|
||||
|
||||
for (const chain of chains) {
|
||||
if (!chain.rpcUrl) {
|
||||
console.log(`Skipping ${chain.name} - no RPC URL configured`);
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`\n=== Deploying to ${chain.name} (Chain ID: ${chain.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(),
|
||||
};
|
||||
|
||||
console.log("Facets deployed");
|
||||
|
||||
// Configure CCIP
|
||||
const ccipRouter = ccipRouters[chain.chainId];
|
||||
if (ccipRouter) {
|
||||
const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress);
|
||||
await ccipFacet.setCCIPRouter(ccipRouter);
|
||||
console.log(`CCIP Router configured: ${ccipRouter}`);
|
||||
|
||||
// Set chain selector
|
||||
const selector = chainSelectors[chain.chainId];
|
||||
if (selector) {
|
||||
await ccipFacet.setChainSelector(chain.chainId, selector);
|
||||
console.log(`Chain selector set: ${selector}`);
|
||||
}
|
||||
|
||||
// Set supported chains
|
||||
const supportedChains = chains.map(c => c.chainId);
|
||||
for (const supportedChainId of supportedChains) {
|
||||
if (supportedChainId !== chain.chainId) {
|
||||
await ccipFacet.setSupportedChain(supportedChainId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure ChainConfigFacet if deployed
|
||||
try {
|
||||
const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress);
|
||||
await chainConfigFacet.setChainConfig(
|
||||
chain.chainId,
|
||||
chain.name,
|
||||
ethers.ZeroAddress, // Native token
|
||||
`https://${chain.name.toLowerCase()}.explorer.com`, // Explorer URL
|
||||
BigInt(3000000), // Gas limit
|
||||
BigInt(300) // Message timeout
|
||||
);
|
||||
await chainConfigFacet.setChainActive(chain.chainId, true);
|
||||
console.log(`Chain config set for ${chain.name}`);
|
||||
} catch (error) {
|
||||
console.log(`ChainConfigFacet not available, skipping...`);
|
||||
}
|
||||
|
||||
deployments[chain.chainId] = {
|
||||
diamond: diamondAddress,
|
||||
facets: Object.fromEntries(
|
||||
Object.entries(facets).map(([name, contract]) => [name, contract.target])
|
||||
),
|
||||
chainId: chain.chainId,
|
||||
chainName: chain.name,
|
||||
};
|
||||
|
||||
console.log(`✓ ${chain.name} deployment complete`);
|
||||
} catch (error) {
|
||||
console.error(`✗ Failed to deploy to ${chain.name}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Save deployment addresses
|
||||
console.log("\n=== Deployment Summary ===");
|
||||
console.log(JSON.stringify(deployments, null, 2));
|
||||
|
||||
// Write to file
|
||||
const fs = require("fs");
|
||||
fs.writeFileSync(
|
||||
"deployments.json",
|
||||
JSON.stringify(deployments, null, 2)
|
||||
);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user