"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hardhat_1 = __importDefault(require("hardhat"));
const deploymentConfig_1 = require("../helpers/deploymentConfig");
const func = async function ({ getNamedAccounts, deployments, network }) {
    const { deploy } = deployments;
    const { deployer } = await getNamedAccounts();
    const proxyOwnerAddress = network.live ? deploymentConfig_1.ADDRESSES[network.name].timelock : deployer;
    const defaultProxyAdmin = await hardhat_1.default.artifacts.readArtifact("hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol:ProxyAdmin");
    const sequencer = deploymentConfig_1.SEQUENCER[network.name];
    let contractName = "ChainlinkOracle";
    if (sequencer !== undefined)
        contractName = "SequencerChainlinkOracle";
    await deploy("RedStoneOracle", {
        contract: network.live ? contractName : "MockChainlinkOracle",
        from: deployer,
        log: true,
        deterministicDeployment: false,
        skipIfAlreadyDeployed: true,
        args: sequencer ? [sequencer] : [],
        proxy: {
            owner: proxyOwnerAddress,
            proxyContract: "OptimizedTransparentUpgradeableProxy",
            execute: {
                methodName: "initialize",
                args: network.live ? [deploymentConfig_1.ADDRESSES[network.name].acm] : [],
            },
            viaAdminContract: {
                name: "DefaultProxyAdmin",
                artifact: defaultProxyAdmin,
            },
        },
    });
    const redStoneOracle = await hardhat_1.default.ethers.getContract("RedStoneOracle");
    const redStoneOracleOwner = await redStoneOracle.owner();
    if (redStoneOracleOwner === deployer && network.live) {
        await redStoneOracle.transferOwnership(proxyOwnerAddress);
        console.log(`Ownership of RedstoneOracle transfered from deployer to Timelock (${proxyOwnerAddress})`);
    }
};
func.tags = ["deploy-redstone"];
func.skip = async (env) => !env.network.live;
exports.default = func;
//# sourceMappingURL=2-deploy-redstone-oracle.js.map