"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const arbitrumone_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/arbitrumone.json"));
const arbitrumsepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/arbitrumsepolia.json"));
const basemainnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/basemainnet.json"));
const basesepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/basesepolia.json"));
const ethereum_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/ethereum.json"));
const opbnbmainnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/opbnbmainnet.json"));
const opbnbtestnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/opbnbtestnet.json"));
const opmainnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/opmainnet.json"));
const opsepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/opsepolia.json"));
const sepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/sepolia.json"));
const unichainmainnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/unichainmainnet.json"));
const unichainsepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/unichainsepolia.json"));
const zksyncmainnet_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/zksyncmainnet.json"));
const zksyncsepolia_json_1 = __importDefault(require("@venusprotocol/governance-contracts/deployments/zksyncsepolia.json"));
const hardhat_1 = require("hardhat");
const deploymentConfig_1 = require("../helpers/deploymentConfig");
const func = async function (hre) {
    const { deployments, getNamedAccounts } = hre;
    const { deployer } = await getNamedAccounts();
    const isTimeBased = false; // configure this value if time based deployment
    const blocksPerYear = {
        bsctestnet: 10512000,
        sepolia: 2628000,
        arbitrumsepolia: 0,
        opsepolia: 0,
        opmainnet: 0,
        arbitrumone: 0,
        zksyncsepolia: 0,
        zksyncmainnet: 0,
        unichainsepolia: 0,
        bscmainnet: 10512000,
        ethereum: 2628000,
        basesepolia: 0,
        basemainnet: 0,
        unichainmainnet: 0,
        berachainbartio: 0,
        hardhat: 100,
    };
    const adminAccount = {
        bscmainnet: await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "NormalTimelock"),
        bsctestnet: await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "NormalTimelock"),
        sepolia: sepolia_json_1.default.contracts.NormalTimelock.address,
        ethereum: ethereum_json_1.default.contracts.NormalTimelock.address,
        opbnbtestnet: opbnbtestnet_json_1.default.contracts.NormalTimelock.address,
        opbnbmainnet: opbnbmainnet_json_1.default.contracts.NormalTimelock.address,
        arbitrumsepolia: arbitrumsepolia_json_1.default.contracts.NormalTimelock.address,
        arbitrumone: arbitrumone_json_1.default.contracts.NormalTimelock.address,
        zksyncsepolia: zksyncsepolia_json_1.default.contracts.NormalTimelock.address,
        zksyncmainnet: zksyncmainnet_json_1.default.contracts.NormalTimelock.address,
        opsepolia: opsepolia_json_1.default.contracts.NormalTimelock.address,
        opmainnet: opmainnet_json_1.default.contracts.NormalTimelock.address,
        basesepolia: basesepolia_json_1.default.contracts.NormalTimelock.address,
        basemainnet: basemainnet_json_1.default.contracts.NormalTimelock.address,
        unichainsepolia: unichainsepolia_json_1.default.contracts.NormalTimelock.address,
        unichainmainnet: unichainmainnet_json_1.default.contracts.NormalTimelock.address,
        berachainbartio: "0x8699D418D8bae5CFdc566E4fce897B08bd9B03B0",
        hardhat: deployer,
    };
    const accessControlManager = await hardhat_1.ethers.getContract("AccessControlManager");
    const xvs = await hardhat_1.ethers.getContract("XVS");
    const xvsVaultProxyDeployment = await hardhat_1.ethers.getContract("XVSVaultProxy");
    const xvsStoreDeployment = await hardhat_1.ethers.getContract("XVSStore");
    let xvsVault = await hardhat_1.ethers.getContract("XVSVaultProxy_Implementation");
    await xvsVaultProxyDeployment._setPendingImplementation(xvsVault.address);
    await xvsVault._become(xvsVaultProxyDeployment.address);
    xvsVault = await hardhat_1.ethers.getContractAt("XVSVault", xvsVaultProxyDeployment.address);
    let txn = await xvsVault.initializeTimeManager(isTimeBased, blocksPerYear[hardhat_1.network.name]);
    await txn.wait();
    txn = await xvsVault.setXvsStore(xvs.address, xvsStoreDeployment.address);
    await txn.wait();
    txn = await xvsVault.setAccessControl(accessControlManager.address);
    await txn.wait();
    await xvsStoreDeployment.setNewOwner(xvsVaultProxyDeployment.address);
    if (!hre.network.live) {
        const tx = await accessControlManager.giveCallPermission(hardhat_1.ethers.constants.AddressZero, "add(address,uint256,address,uint256,uint256)", deployer);
        await tx.wait();
        // Add token pool to xvs vault
        const allocPoint = 100;
        const token = xvs.address;
        const rewardToken = xvs.address;
        const rewardPerBlock = "61805555555555555";
        const lockPeriod = 604800;
        await xvsVault.add(rewardToken, allocPoint, token, rewardPerBlock, lockPeriod);
    }
    else {
        const owner = adminAccount[hre.network.name];
        console.log("Please accept ownership of vault and store");
        txn = await xvsVaultProxyDeployment._setPendingAdmin(owner);
        await txn.wait();
        txn = await xvsStoreDeployment.setPendingAdmin(owner);
        await txn.wait();
    }
};
func.tags = ["xvs-vault"];
func.id = "xvs_vault_configuration"; // id required to prevent re-execution
exports.default = func;
