75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
|
|
const { ethers } = require('hardhat');
|
||
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
require('dotenv').config();
|
||
|
|
|
||
|
|
const ROOT = path.resolve(__dirname, '../..');
|
||
|
|
|
||
|
|
function syncAddresses(cUsdc, registry) {
|
||
|
|
const today = new Date().toISOString().slice(0, 10);
|
||
|
|
|
||
|
|
const deployedPath = path.join(ROOT, 'config/z-chain-deployed.v1.json');
|
||
|
|
const deployed = JSON.parse(fs.readFileSync(deployedPath, 'utf8'));
|
||
|
|
deployed.updated = today;
|
||
|
|
deployed.status = 'active';
|
||
|
|
deployed.contracts.cUSDC = cUsdc;
|
||
|
|
deployed.contracts.accountWalletRegistry = registry;
|
||
|
|
fs.writeFileSync(deployedPath, `${JSON.stringify(deployed, null, 2)}\n`);
|
||
|
|
|
||
|
|
const integrationPath = path.join(ROOT, 'config/z-chain-integration.v1.json');
|
||
|
|
const integration = JSON.parse(fs.readFileSync(integrationPath, 'utf8'));
|
||
|
|
integration.contracts.cUSDC = cUsdc;
|
||
|
|
integration.contracts.accountWalletRegistry = registry;
|
||
|
|
fs.writeFileSync(integrationPath, `${JSON.stringify(integration, null, 2)}\n`);
|
||
|
|
|
||
|
|
const hybxPath = path.join(ROOT, 'config/hybx-omnl-cross-chain-lines.json');
|
||
|
|
const hybx = JSON.parse(fs.readFileSync(hybxPath, 'utf8'));
|
||
|
|
for (const line of hybx.lines || []) {
|
||
|
|
if (line.chains?.['900002']) {
|
||
|
|
line.chains['900002'].tokenM1 = cUsdc;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
fs.writeFileSync(hybxPath, `${JSON.stringify(hybx, null, 2)}\n`);
|
||
|
|
|
||
|
|
const broadcastDir = path.join(ROOT, 'broadcast/DeployZChainEmoney.s.sol/900002');
|
||
|
|
fs.mkdirSync(broadcastDir, { recursive: true });
|
||
|
|
const broadcast = {
|
||
|
|
transactions: [
|
||
|
|
{ contractName: 'ZChainUSDC', contractAddress: cUsdc },
|
||
|
|
{ contractName: 'AccountWalletRegistryZ', contractAddress: registry },
|
||
|
|
],
|
||
|
|
};
|
||
|
|
fs.writeFileSync(path.join(broadcastDir, 'run-latest.json'), `${JSON.stringify(broadcast, null, 2)}\n`);
|
||
|
|
|
||
|
|
console.log('\nConfig updated:');
|
||
|
|
console.log(' cUSDC:', cUsdc);
|
||
|
|
console.log(' AccountWalletRegistry:', registry);
|
||
|
|
}
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
const [deployer] = await ethers.getSigners();
|
||
|
|
const network = await ethers.provider.getNetwork();
|
||
|
|
console.log('Deployer:', deployer.address);
|
||
|
|
console.log('Chain ID:', network.chainId.toString());
|
||
|
|
console.log('Balance:', ethers.formatEther(await ethers.provider.getBalance(deployer.address)));
|
||
|
|
|
||
|
|
const ZChainUSDC = await ethers.getContractFactory('ZChainUSDC');
|
||
|
|
const cUsdc = await ZChainUSDC.deploy(deployer.address);
|
||
|
|
await cUsdc.waitForDeployment();
|
||
|
|
const cUsdcAddress = await cUsdc.getAddress();
|
||
|
|
console.log('ZChainUSDC deployed:', cUsdcAddress);
|
||
|
|
|
||
|
|
const AccountWalletRegistry = await ethers.getContractFactory('AccountWalletRegistryZ');
|
||
|
|
const registry = await AccountWalletRegistry.deploy(deployer.address);
|
||
|
|
await registry.waitForDeployment();
|
||
|
|
const registryAddress = await registry.getAddress();
|
||
|
|
console.log('AccountWalletRegistry deployed:', registryAddress);
|
||
|
|
|
||
|
|
syncAddresses(cUsdcAddress, registryAddress);
|
||
|
|
}
|
||
|
|
|
||
|
|
main().catch((err) => {
|
||
|
|
console.error(err);
|
||
|
|
process.exit(1);
|
||
|
|
});
|