"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _000_psr_1 = __importDefault(require("@venusprotocol/protocol-reserve/dist/deploy/000-psr"));
const hardhat_1 = require("hardhat");
const deploymentConfig_1 = require("../helpers/deploymentConfig");
const func = async function (hre) {
    const { deployments, network, getNamedAccounts } = hre;
    const { deploy } = deployments;
    const { deployer } = await getNamedAccounts();
    // Ensure PSR is deployed
    await (0, _000_psr_1.default)(hre);
    const wBNBAddress = (await deployments.get("WBNB")).address;
    const vBNBAddress = (await deployments.get("vBNB")).address;
    const acmAddress = (await deployments.get("AccessControlManager")).address;
    const protocolShareReserveAddress = (await deployments.get("ProtocolShareReserve")).address;
    const normalVipTimelockAddress = (await deployments.get("NormalTimelock")).address;
    await deploy("VBNBAdmin", {
        contract: "VBNBAdmin",
        from: deployer,
        args: [vBNBAddress, wBNBAddress],
        log: true,
        autoMine: true,
        proxy: {
            owner: network.name === "hardhat" ? deployer : normalVipTimelockAddress,
            proxyContract: "OpenZeppelinTransparentProxy",
            execute: {
                methodName: "initialize",
                args: [protocolShareReserveAddress, acmAddress],
            },
        },
    });
    const vBNBAdmin = await hardhat_1.ethers.getContract("VBNBAdmin");
    if (network.name !== "hardhat") {
        await vBNBAdmin.transferOwnership(normalVipTimelockAddress);
        console.log(`VBNBAdmin Contract (${vBNBAdmin.address}) owner changed from ${deployer} to ${normalVipTimelockAddress}`);
    }
    return hre.network.live; // when live network, record the script as executed to prevent re-execution
};
func.id = "vbnbadmin_deploy"; // id required to prevent re-execution
func.tags = ["VBNBAdmin"];
func.skip = (0, deploymentConfig_1.skipRemoteNetworks)();
exports.default = func;
