"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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();
    const TEN_MINUTES = 60 * 10;
    const NINETY_DAYS = 90 * 24 * 60 * 60;
    const ZERO_ADDRESS = hardhat_1.ethers.constants.AddressZero;
    const stakingPeriod = {
        hardhat: TEN_MINUTES,
        bsctestnet: TEN_MINUTES,
        sepolia: TEN_MINUTES,
        arbitrumsepolia: TEN_MINUTES,
        zksyncsepolia: TEN_MINUTES,
        opsepolia: TEN_MINUTES,
        unichainsepolia: TEN_MINUTES,
        basesepolia: TEN_MINUTES,
        basemainnet: NINETY_DAYS,
        bscmainnet: NINETY_DAYS,
        ethereum: NINETY_DAYS,
        arbitrumone: NINETY_DAYS,
        zksyncmainnet: NINETY_DAYS,
        opmainnet: NINETY_DAYS,
    };
    const xVSVaultPoolId = {
        bsctestnet: 1,
        sepolia: 0,
        arbitrumsepolia: 0,
        bscmainnet: 0,
        ethereum: 0,
        arbitrumone: 0,
        zksyncsepolia: 0,
        zksyncmainnet: 0,
        opsepolia: 0,
        opmainnet: 0,
        unichainsepolia: 0,
        hardhat: 0,
        basesepolia: 0,
        basemainnet: 0,
    };
    const blocksPerYear = {
        bsctestnet: 10512000,
        sepolia: 2628000,
        arbitrumsepolia: 0,
        arbitrumone: 0,
        zksyncsepolia: 0,
        zksyncmainnet: 0,
        opsepolia: 0,
        opmainnet: 0,
        unichainsepolia: 0,
        basesepolia: 0,
        basemainnet: 0,
        bscmainnet: 10512000,
        ethereum: 2628000,
        hardhat: 100,
    };
    const networkName = network.name;
    const maximumXVSCap = hardhat_1.ethers.utils.parseEther("100000");
    const minimumXVS = hardhat_1.ethers.utils.parseEther("1000");
    const xvsVaultAlphaNumerator = 1;
    const xvsVaultAlphaDenominator = 2;
    const loopsLimit = 20;
    const isTimeBased = false; // revise this value when deploying on L2s
    const corePoolAddress = await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "Unitroller");
    const wrappedNativeToken = await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "WBNB");
    const nativeMarket = await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "vBNB");
    const acmAddress = (await deployments.get("AccessControlManager")).address;
    const xvsVaultAddress = (await deployments.get("XVSVaultProxy")).address;
    const xvsAddress = (await deployments.get("XVS")).address;
    const resilientOracleAddress = (await deployments.get("ResilientOracle")).address;
    const adminAccount = {
        sepolia: "0x94fa6078b6b8a26f0b6edffbe6501b22a10470fb",
        ethereum: "0x285960C5B22fD66A736C7136967A3eB15e93CC67",
        opbnbtestnet: "0xb15f6EfEbC276A3b9805df81b5FB3D50C2A62BDf",
        opbnbmainnet: "0xC46796a21a3A9FAB6546aF3434F2eBfFd0604207",
        arbitrumsepolia: "0x1426A5Ae009c4443188DA8793751024E358A61C2",
        arbitrumone: "0x14e0E151b33f9802b3e75b621c1457afc44DcAA0",
        zksyncsepolia: "0xa2f83de95E9F28eD443132C331B6a9C9B7a9F866",
        zksyncmainnet: "0x751Aa759cfBB6CE71A43b48e40e1cCcFC66Ba4aa",
        opsepolia: "0xd57365EE4E850e881229e2F8Aa405822f289e78d",
        opmainnet: "0x2e94dd14E81999CdBF5deDE31938beD7308354b3",
        unichainsepolia: "0x9831D3A641E8c7F082EEA75b8249c99be9D09a34",
        basesepolia: "0xdf3b635d2b535f906BB02abb22AED71346E36a00",
        basemainnet: "0x1803Cf1D3495b43cC628aa1d8638A981F8CD341C",
        bscmainnet: await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "NormalTimelock"),
        bsctestnet: await (0, deploymentConfig_1.getContractAddressOrNullAddress)(deployments, "NormalTimelock"),
    };
    // Explicitly mentioning Default Proxy Admin contract path to fetch it from hardhat-deploy instead of OpenZeppelin
    // as zksync doesnot compile OpenZeppelin contracts using zksolc. It is backward compatible for all networks as well.
    const defaultProxyAdmin = await hre.artifacts.readArtifact("hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol:ProxyAdmin");
    await deploy("PrimeLiquidityProvider", {
        from: deployer,
        log: true,
        deterministicDeployment: false,
        args: [isTimeBased, blocksPerYear[networkName]],
        proxy: {
            owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
            proxyContract: "OptimizedTransparentUpgradeableProxy",
            execute: {
                methodName: "initialize",
                args: [acmAddress, [], [], [], loopsLimit],
            },
            viaAdminContract: {
                name: "DefaultProxyAdmin",
                artifact: defaultProxyAdmin,
            },
        },
    });
    const plp = await hardhat_1.ethers.getContract("PrimeLiquidityProvider");
    await deploy("Prime", {
        from: deployer,
        log: true,
        deterministicDeployment: false,
        args: [
            wrappedNativeToken ? wrappedNativeToken : ZERO_ADDRESS,
            nativeMarket ? nativeMarket : ZERO_ADDRESS,
            blocksPerYear[networkName],
            stakingPeriod[networkName],
            minimumXVS,
            maximumXVSCap,
            isTimeBased,
        ],
        proxy: {
            owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
            proxyContract: "OptimizedTransparentUpgradeableProxy",
            execute: {
                methodName: "initialize",
                args: [
                    xvsVaultAddress,
                    xvsAddress,
                    xVSVaultPoolId[networkName],
                    xvsVaultAlphaNumerator,
                    xvsVaultAlphaDenominator,
                    acmAddress,
                    plp.address,
                    corePoolAddress,
                    resilientOracleAddress,
                    loopsLimit,
                ],
            },
            viaAdminContract: {
                name: "DefaultProxyAdmin",
                artifact: defaultProxyAdmin,
            },
        },
    });
};
func.tags = ["Prime"];
exports.default = func;
