87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
|
|
import { ethers } from "hardhat";
|
||
|
|
import * as fs from "fs";
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
const [deployer] = await ethers.getSigners();
|
||
|
|
console.log("Deploying to BSC with account:", deployer.address);
|
||
|
|
|
||
|
|
const chainId = 56;
|
||
|
|
const rpcUrl = process.env.BSC_RPC_URL || "https://bsc-dataseed1.binance.org";
|
||
|
|
const ccipRouter = process.env.BSC_CCIP_ROUTER || "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D";
|
||
|
|
const chainSelector = BigInt('11344663589394136015');
|
||
|
|
|
||
|
|
console.log(`\n=== Deploying to BSC (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,
|
||
|
|
"BSC",
|
||
|
|
ethers.ZeroAddress,
|
||
|
|
"https://bscscan.com",
|
||
|
|
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: "BSC",
|
||
|
|
ccipRouter,
|
||
|
|
chainSelector: chainSelector.toString(),
|
||
|
|
};
|
||
|
|
|
||
|
|
console.log(`✓ BSC deployment complete`);
|
||
|
|
console.log(JSON.stringify(deployment, null, 2));
|
||
|
|
|
||
|
|
// Write to file
|
||
|
|
fs.writeFileSync(
|
||
|
|
`deployments-bsc-${chainId}.json`,
|
||
|
|
JSON.stringify(deployment, null, 2)
|
||
|
|
);
|
||
|
|
} catch (error) {
|
||
|
|
console.error(`✗ Failed to deploy to BSC:`, error);
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|
||
|
|
.then(() => process.exit(0))
|
||
|
|
.catch((error) => {
|
||
|
|
console.error(error);
|
||
|
|
process.exit(1);
|
||
|
|
});
|
||
|
|
|