Files
solace-bg-dubai/contracts/scripts/deploy-chain138.ts
defiQUG c94eb595f8
Some checks failed
CI / lint-and-test (push) Has been cancelled
Initial commit: add .gitignore and README
2026-02-09 21:51:53 -08:00

85 lines
3.1 KiB
TypeScript

import { ethers } from "hardhat";
import * as fs from "fs";
import * as path from "path";
async function main() {
const network = await ethers.provider.getNetwork();
console.log("Deploying to network:", network.name, "Chain ID:", network.chainId);
if (network.chainId !== 138n) {
throw new Error("This script is only for Chain 138. Use --network chain138");
}
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const balance = await ethers.provider.getBalance(deployer.address);
console.log("Account balance:", ethers.formatEther(balance), "ETH");
if (balance === 0n) {
throw new Error("Deployer account has no balance. Please fund the account first.");
}
// Deploy SubAccountFactory
console.log("\nDeploying SubAccountFactory...");
const SubAccountFactory = await ethers.getContractFactory("SubAccountFactory");
const factory = await SubAccountFactory.deploy();
await factory.waitForDeployment();
const factoryAddress = await factory.getAddress();
console.log("SubAccountFactory deployed to:", factoryAddress);
// Deploy a TreasuryWallet with initial owners
// Note: In production, this would be done by the frontend when a user creates a treasury
// For now, we deploy an example treasury with the deployer as the only owner
console.log("\nDeploying example TreasuryWallet...");
const owners = [deployer.address]; // Replace with actual owners in production
const threshold = 1;
const TreasuryWallet = await ethers.getContractFactory("TreasuryWallet");
const treasury = await TreasuryWallet.deploy(owners, threshold);
await treasury.waitForDeployment();
const treasuryAddress = await treasury.getAddress();
console.log("TreasuryWallet deployed to:", treasuryAddress);
// Save deployment addresses to a JSON file
const deploymentInfo = {
network: "chain138",
chainId: 138,
deployedAt: new Date().toISOString(),
deployer: deployer.address,
contracts: {
SubAccountFactory: factoryAddress,
TreasuryWallet: treasuryAddress,
},
};
const outputDir = path.join(__dirname, "../deployments");
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const outputPath = path.join(outputDir, "chain138.json");
fs.writeFileSync(outputPath, JSON.stringify(deploymentInfo, null, 2));
console.log("\nDeployment Summary:");
console.log("===================");
console.log("Network: Chain 138");
console.log("SubAccountFactory:", factoryAddress);
console.log("Example TreasuryWallet:", treasuryAddress);
console.log("\nDeployment info saved to:", outputPath);
console.log("\nNext steps:");
console.log("1. Update frontend/.env.production with:");
console.log(` NEXT_PUBLIC_SUB_ACCOUNT_FACTORY_ADDRESS=${factoryAddress}`);
console.log(` NEXT_PUBLIC_TREASURY_WALLET_ADDRESS=${treasuryAddress}`);
console.log("2. Update backend/.env with:");
console.log(` CONTRACT_ADDRESS=${treasuryAddress}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});