diff --git a/deploy/deploy-advanced-features/01_deploy_advanced_features.js b/deploy/deploy-advanced-features/01_deploy_advanced_features.js new file mode 100644 index 00000000..7ec24268 --- /dev/null +++ b/deploy/deploy-advanced-features/01_deploy_advanced_features.js @@ -0,0 +1,18 @@ +// Advanced Features Deployment +const { deployAdvancedFeatures } = require("../../scripts/setup/deploy/deployAdvancedFeatures"); +const { initializeAdvancedFeatures } = require("../../scripts/setup/deploy/initializeAdvancedFeatures"); + +module.exports = async ({ getNamedAccounts, deployments, getChainId }) => { + console.log("🚀 Starting Advanced Features Deployment..."); + + // Deploy the advanced feature contracts + await deployAdvancedFeatures(getNamedAccounts, deployments); + + // Initialize the advanced features + await initializeAdvancedFeatures(deployments, getChainId); + + console.log("✅ Advanced Features Deployment Complete!"); +}; + +module.exports.tags = ["DeployAdvancedFeatures"]; +module.exports.dependencies = ["DeployMain"]; // Ensure main contracts are deployed first diff --git a/scripts/setup/deploy/deployAdvancedFeatures.js b/scripts/setup/deploy/deployAdvancedFeatures.js new file mode 100644 index 00000000..18a633e4 --- /dev/null +++ b/scripts/setup/deploy/deployAdvancedFeatures.js @@ -0,0 +1,60 @@ +async function deployAdvancedFeatures(getNamedAccounts, deployments) { + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + console.log("🚀 Deploying Advanced Stablecoin Features..."); + + // Deploy TWAP Price Feed + console.log("📊 Deploying TWAP Price Feed..."); + await deploy("TWAPPriceFeed", { + from: deployer, + args: [], + log: true, + }); + + // Deploy Liquidation Protector + console.log("🛡️ Deploying Liquidation Protector..."); + await deploy("LiquidationProtector", { + from: deployer, + args: [], + log: true, + }); + + // Deploy Stability Fee Optimizer + console.log("⚡ Deploying Stability Fee Optimizer..."); + await deploy("StabilityFeeOptimizer", { + from: deployer, + args: [], + log: true, + }); + + // Deploy Vault Insurance Pool + console.log("🏦 Deploying Vault Insurance Pool..."); + await deploy("VaultInsurancePool", { + from: deployer, + args: [], + log: true, + }); + + // Deploy Cross Collateral Manager + console.log("🔗 Deploying Cross Collateral Manager..."); + await deploy("CrossCollateralManager", { + from: deployer, + args: [], + log: true, + }); + + // Deploy Emergency Coordinator + console.log("🚨 Deploying Emergency Coordinator..."); + await deploy("EmergencyCoordinator", { + from: deployer, + args: [], + log: true, + }); + + console.log("✅ Advanced Features Deployment Complete!"); +} + +module.exports = { + deployAdvancedFeatures, +}; diff --git a/scripts/setup/deploy/initializeAdvancedFeatures.js b/scripts/setup/deploy/initializeAdvancedFeatures.js new file mode 100644 index 00000000..17344655 --- /dev/null +++ b/scripts/setup/deploy/initializeAdvancedFeatures.js @@ -0,0 +1,97 @@ +const { ethers } = require("hardhat"); + +async function initializeAdvancedFeatures(deployments, getChainId) { + const chainId = await getChainId(); + console.log("🔧 Initializing Advanced Features for chain:", chainId); + + // Get deployed contracts + const bookKeeper = await deployments.get("BookKeeper"); + const stablecoin = await deployments.get("FathomStablecoin"); + const accessControlConfig = await deployments.get("AccessControlConfig"); + const systemDebtEngine = await deployments.get("SystemDebtEngine"); + + const { deployer } = await ethers.getNamedSigners(); + + try { + // Initialize TWAP Price Feed + console.log("📊 Initializing TWAP Price Feed..."); + const twapPriceFeed = await deployments.get("TWAPPriceFeed"); + const twapContract = await ethers.getContractAt("TWAPPriceFeed", twapPriceFeed.address); + + // Example initialization with a base price feed (would need to be configured based on actual deployment) + // await twapContract.initialize( + // basePriceFeedAddress, + // accessControlConfig.address, + // ethers.utils.formatBytes32String("ETH-A"), + // 3600, // 1 hour window + // 300 // 5 minute observation window + // ); + + // Initialize Liquidation Protector + console.log("🛡️ Initializing Liquidation Protector..."); + const liquidationProtector = await deployments.get("LiquidationProtector"); + const protectorContract = await ethers.getContractAt("LiquidationProtector", liquidationProtector.address); + + await protectorContract.initialize( + bookKeeper.address, + accessControlConfig.address, + deployer.address, // Fee recipient + 7200, // 2 hour grace period + ethers.utils.parseEther("0.05") // 5% max protection fee + ); + + // Initialize Stability Fee Optimizer + console.log("⚡ Initializing Stability Fee Optimizer..."); + const stabilityOptimizer = await deployments.get("StabilityFeeOptimizer"); + const optimizerContract = await ethers.getContractAt("StabilityFeeOptimizer", stabilityOptimizer.address); + + await optimizerContract.initialize( + bookKeeper.address, + stablecoin.address, + bookKeeper.address, // Placeholder for stablecoin price oracle + 3600 // 1 hour update frequency + ); + + // Initialize Vault Insurance Pool + console.log("🏦 Initializing Vault Insurance Pool..."); + const insurancePool = await deployments.get("VaultInsurancePool"); + const poolContract = await ethers.getContractAt("VaultInsurancePool", insurancePool.address); + + await poolContract.initialize( + bookKeeper.address, + 2000, // 20% reserve ratio + 500, // 5% staking reward rate + 30 * 24 * 3600 // 30 day claim time limit + ); + + // Initialize Cross Collateral Manager + console.log("🔗 Initializing Cross Collateral Manager..."); + const crossCollateralManager = await deployments.get("CrossCollateralManager"); + const managerContract = await ethers.getContractAt("CrossCollateralManager", crossCollateralManager.address); + + await managerContract.initialize( + bookKeeper.address, + ethers.utils.parseEther("1.05") // 105% liquidation threshold + ); + + // Initialize Emergency Coordinator + console.log("🚨 Initializing Emergency Coordinator..."); + const emergencyCoordinator = await deployments.get("EmergencyCoordinator"); + const coordinatorContract = await ethers.getContractAt("EmergencyCoordinator", emergencyCoordinator.address); + + await coordinatorContract.initialize( + bookKeeper.address, + true // Auto resolution enabled + ); + + console.log("✅ Advanced Features Initialization Complete!"); + + } catch (error) { + console.error("❌ Error initializing advanced features:", error); + throw error; + } +} + +module.exports = { + initializeAdvancedFeatures, +};