"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.skipSourceNetworks = exports.skipRemoteNetworks = exports.onlyHardhat = exports.getContractAddressOrNullAddress = exports.getTokenConfig = exports.getConfig = exports.getGlobalConfig = exports.InterestRateModels = void 0;
const hardhat_1 = require("hardhat");
const utils_1 = require("./utils");
var InterestRateModels;
(function (InterestRateModels) {
    InterestRateModels[InterestRateModels["WhitePaper"] = 0] = "WhitePaper";
    InterestRateModels[InterestRateModels["JumpRate"] = 1] = "JumpRate";
})(InterestRateModels = exports.InterestRateModels || (exports.InterestRateModels = {}));
const getGlobalConfig = async () => {
    const vTreasuryAddress = (await hardhat_1.ethers.getContract("VTreasuryV8")).address;
    return {
        hardhat: {
            tokensConfig: [
                {
                    isMock: true,
                    name: "First Digital USD",
                    symbol: "FDUSD",
                    decimals: 18,
                },
                {
                    isMock: true,
                    name: "Wrapped BNB",
                    symbol: "WBNB",
                    decimals: 18,
                },
                {
                    isMock: true,
                    name: "DOGE",
                    symbol: "DOGE",
                    decimals: 18,
                },
                {
                    isMock: true,
                    name: "USDT",
                    symbol: "USDT",
                    decimals: 18,
                },
            ],
            marketsConfig: [
                {
                    name: "Venus FDUSD",
                    asset: "FDUSD",
                    symbol: "vFDUSD",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.06875", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.8", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)(9000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(5500000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(4400000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus DOGE",
                    asset: "DOGE",
                    symbol: "vDOGE",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.06875", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.9", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.95", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)("9000", 18),
                    supplyCap: (0, utils_1.convertToUnit)("5500000000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("4400000000", 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus USDT",
                    asset: "USDT",
                    symbol: "vUSDT",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.06875", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.9", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.95", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)("9000", 18),
                    supplyCap: (0, utils_1.convertToUnit)("5500000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("4400000", 18),
                    vTokenReceiver: vTreasuryAddress,
                },
            ],
        },
        bsctestnet: {
            tokensConfig: [
                {
                    isMock: true,
                    name: "First Digital USD",
                    symbol: "FDUSD",
                    decimals: 18,
                },
            ],
            marketsConfig: [
                {
                    name: "Venus FDUSD",
                    asset: "FDUSD",
                    symbol: "vFDUSD",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.06875", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.8", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)(9000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(5500000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(4400000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
            ],
        },
        bscmainnet: {
            tokensConfig: [
                {
                    isMock: false,
                    symbol: "FDUSD",
                    tokenAddress: "0xc5f0f7b66764F6ec8C8Dff7BA683102295E16409",
                },
            ],
            marketsConfig: [
                {
                    name: "Venus FDUSD",
                    asset: "FDUSD",
                    symbol: "vFDUSD",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.075", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("5.0", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.8", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)(9000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(5500000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(4400000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus DOGE",
                    asset: "DOGE",
                    symbol: "vDOGE",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.06875", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.8", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)(9000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(5500000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(4400000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus USDT",
                    asset: "USDT",
                    symbol: "vUSDT",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.1", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.8", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    liquidationThreshold: (0, utils_1.convertToUnit)("0.8", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.1", 18),
                    initialSupply: (0, utils_1.convertToUnit)(9000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(5500000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(4400000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
            ],
        },
    };
};
exports.getGlobalConfig = getGlobalConfig;
async function getConfig(networkName) {
    const globalConfig = await (0, exports.getGlobalConfig)();
    switch (networkName) {
        case "hardhat":
            return globalConfig.hardhat;
        case "bsctestnet":
            return globalConfig.bsctestnet;
        case "bscmainnet":
            return globalConfig.bscmainnet;
        default:
            throw new Error(`config for network ${networkName} is not available.`);
    }
}
exports.getConfig = getConfig;
function getTokenConfig(tokenSymbol, tokens) {
    const tokenCofig = tokens.find(({ symbol }) => symbol.toLocaleLowerCase().trim() === tokenSymbol.toLocaleLowerCase().trim());
    if (tokenCofig) {
        return tokenCofig;
    }
    else {
        throw Error(`Token ${tokenSymbol} is not found in the config`);
    }
}
exports.getTokenConfig = getTokenConfig;
const getContractAddressOrNullAddress = async (deployments, name) => {
    try {
        return (await deployments.get(name)).address;
    }
    catch (e) {
        console.error(`${name} not found returning null address`);
        return "0x0000000000000000000000000000000000000000";
    }
};
exports.getContractAddressOrNullAddress = getContractAddressOrNullAddress;
const onlyHardhat = () => async (hre) => {
    return hre.network.name !== "hardhat";
};
exports.onlyHardhat = onlyHardhat;
const skipRemoteNetworks = () => async (hre) => {
    return hre.network.name !== "bscmainnet" && hre.network.name !== "bsctestnet" && hre.network.name !== "hardhat";
};
exports.skipRemoteNetworks = skipRemoteNetworks;
const skipSourceNetworks = ({ hardhat } = { hardhat: false }) => async (hre) => {
    return hre.network.name === "bsctestnet" || hre.network.name === "bscmainnet" || hardhat;
};
exports.skipSourceNetworks = skipSourceNetworks;
