Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions tasks/migrations/mainnet-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,86 @@ import {
getLendTokenPerNetwork,
} from "../../helpers/constants";

task("main-deployment", "Deployment in mainnet network")
// Define the arguments and flag types for clarity in the action function
interface MainDeploymentArgs {
verify?: boolean; // Corresponds to the flag
}

/**
* Task for deploying and configuring Aave migration contracts on a mainnet environment.
* This sets up AaveToken, LendToAaveMigrator, and their upgradeability proxies.
*/
task("main-deployment", "Deployment and setup for Aave Token mainnet migration.")
.addFlag(
"verify",
"Verify AaveToken, LendToAaveMigrator, and InitializableAdminUpgradeabilityProxy contract."
"If set, contracts (AaveToken, Migrator, Proxy) will be verified on Etherscan."
)
.setAction(async ({ verify }, localBRE) => {
.setAction(async (
{ verify }: MainDeploymentArgs,
localBRE: BuidlerRuntimeEnvironment
) => {
// Ensure BRE is correctly set up for the environment
const BRE: BuidlerRuntimeEnvironment = await localBRE.run("set-bre");
const network = BRE.network.name as eEthereumNetwork;

// --- 1. Get Core Configuration ---
const aaveAdmin = getAaveAdminPerNetwork(network);
const lendTokenAddress = getLendTokenPerNetwork(network);

// --- 2. Admin Validation (Security Check) ---
if (!aaveAdmin) {
throw Error(
"The --admin parameter must be set for mainnet network. Set an Ethereum address as --admin parameter input."
throw new Error(
`Aave Admin address is mandatory for deploying on network '${network}'. ` +
`Check your configuration file (${network} entry) for the required admin address.`
);
}
console.log(`\nDeployment Admin Address: ${aaveAdmin}`);
console.log(`LEND Token Address: ${lendTokenAddress}`);

// If Etherscan verification is enabled, check needed enviroments to prevent loss of gas in failed deployments.

// --- 3. Etherscan Verification Check ---
if (verify) {
console.log("Etherscan verification is ENABLED. Checking prerequisites...");
// Check needed environments (e.g., API Key) to prevent failed deployments.
checkVerification();
} else {
console.log("Etherscan verification is DISABLED.");
}

// --- 4. Deployment Steps (Implementation Contracts) ---

console.log("AAVE ADMIN", aaveAdmin);
// Deploy AaveToken Implementation
console.log(`\n--- Deploying ${eContractid.AaveToken} ---`);
await BRE.run(`deploy-${eContractid.AaveToken}`, { verify });

// Deploy LendToAaveMigrator Implementation
console.log(`\n--- Deploying ${eContractid.LendToAaveMigrator} ---`);
await BRE.run(`deploy-${eContractid.LendToAaveMigrator}`, {
lendTokenAddress,
verify,
});

// The task will only initialize the proxy contract, not implementation
// --- 5. Initialization Steps (Proxy Contracts) ---
// Note: The deployment task should handle the Proxy contract deployment implicitly.

// Initialize the AaveToken Proxy
console.log(`\n--- Initializing ${eContractid.AaveToken} Proxy ---`);
await BRE.run(`initialize-${eContractid.AaveToken}`, {
admin: aaveAdmin,
// CRITICAL: Ensure only the proxy is initialized, not the implementation.
onlyProxy: true,
});

// The task will only initialize the proxy contract, not implementation
// Initialize the LendToAaveMigrator Proxy
console.log(`\n--- Initializing ${eContractid.LendToAaveMigrator} Proxy ---`);
await BRE.run(`initialize-${eContractid.LendToAaveMigrator}`, {
admin: aaveAdmin,
// CRITICAL: Ensure only the proxy is initialized, not the implementation.
onlyProxy: true,
});

// --- 6. Finalization ---
console.log(
"\n✔️ Finished the deployment of the Aave Token Mainnet Enviroment. ✔️"
"\n Finished the deployment and proxy initialization of the Aave Token Mainnet Environment. ✨"
);
});