"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 () => {
    let vTreasuryAddress;
    try {
        vTreasuryAddress = (await hardhat_1.ethers.getContract("VTreasuryV8")).address;
    }
    catch {
        vTreasuryAddress = (await hardhat_1.ethers.getContract("VTreasury")).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,
                },
                {
                    isMock: false,
                    name: "Trust Wallet",
                    symbol: "TWT",
                    decimals: 18,
                    tokenAddress: "0xb99c6b26fdf3678c6e2aff8466e3625a0e7182f8",
                },
                {
                    isMock: true,
                    name: "Solv BTC",
                    symbol: "SolvBTC",
                    decimals: 18,
                },
                {
                    isMock: true,
                    name: "THENA",
                    symbol: "THE",
                    decimals: 18,
                },
                {
                    isMock: true,
                    name: "Solana",
                    symbol: "SOL",
                    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),
                    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 TWT",
                    asset: "TWT",
                    symbol: "vTWT",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: (0, utils_1.convertToUnit)("0.02", 18),
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.2", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.5", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.25", 18),
                    initialSupply: (0, utils_1.convertToUnit)(5000, 18),
                    supplyCap: (0, utils_1.convertToUnit)(2000000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(1000000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus SolvBTC",
                    asset: "SolvBTC",
                    symbol: "vSolvBTC",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.09", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.2", 18),
                    initialSupply: (0, utils_1.convertToUnit)("0.1572404", 18),
                    supplyCap: (0, utils_1.convertToUnit)("100", 18),
                    borrowCap: (0, utils_1.convertToUnit)("55", 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus THE",
                    asset: "THE",
                    symbol: "vTHE",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.09", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.45", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.53", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.25", 18),
                    initialSupply: (0, utils_1.convertToUnit)("12286", 18),
                    supplyCap: (0, utils_1.convertToUnit)("2400000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("1200000", 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus SOL",
                    asset: "Solana",
                    symbol: "vSOL",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: (0, utils_1.convertToUnit)("0.02", 18),
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.2", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.72", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.2", 18),
                    initialSupply: (0, utils_1.convertToUnit)("20", 18),
                    supplyCap: (0, utils_1.convertToUnit)("18000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("9000", 18),
                    vTokenReceiver: vTreasuryAddress,
                },
            ],
        },
        bscmainnet: {
            tokensConfig: [
                {
                    isMock: false,
                    symbol: "FDUSD",
                    tokenAddress: "0xc5f0f7b66764F6ec8C8Dff7BA683102295E16409",
                },
                {
                    isMock: false,
                    symbol: "TWT",
                    tokenAddress: "0x4B0F1812e5Df2A09796481Ff14017e6005508003",
                },
                {
                    isMock: false,
                    name: "Solv BTC",
                    symbol: "SolvBTC",
                    decimals: 18,
                    tokenAddress: "0x4aae823a6a0b376de6a78e74ecc5b079d38cbcf7",
                },
                {
                    isMock: false,
                    name: "THENA",
                    symbol: "THE",
                    decimals: 18,
                    tokenAddress: "0xF4C8E32EaDEC4BFe97E0F595AdD0f4450a863a11",
                },
                {
                    isMock: false,
                    name: "Solana",
                    symbol: "SOL",
                    decimals: 18,
                    tokenAddress: "0x570A5D26f7765Ecb712C0924E4De545B89fD43dF",
                },
            ],
            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),
                    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 TWT",
                    asset: "TWT",
                    symbol: "vTWT",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: (0, utils_1.convertToUnit)("0.02", 18),
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.2", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.5", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.25", 18),
                    initialSupply: (0, utils_1.convertToUnit)(4401, 18),
                    supplyCap: (0, utils_1.convertToUnit)(2000000, 18),
                    borrowCap: (0, utils_1.convertToUnit)(1000000, 18),
                    vTokenReceiver: vTreasuryAddress,
                },
                {
                    name: "Venus SolvBTC",
                    asset: "SolvBTC",
                    symbol: "vSolvBTC",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.09", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("2", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.75", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.2", 18),
                    initialSupply: (0, utils_1.convertToUnit)("0.1572404", 18),
                    supplyCap: (0, utils_1.convertToUnit)("100", 18),
                    borrowCap: (0, utils_1.convertToUnit)("55", 18),
                    vTokenReceiver: "0xD5bAa0C3d61Ba3f4899565f269e5f9b186AAf14B",
                },
                {
                    name: "Venus THE",
                    asset: "THE",
                    symbol: "vTHE",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: "0",
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.09", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3.5", 18),
                    kink_: (0, utils_1.convertToUnit)("0.45", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.53", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.25", 18),
                    initialSupply: (0, utils_1.convertToUnit)("12286", 18),
                    supplyCap: (0, utils_1.convertToUnit)("2400000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("1200000", 18),
                    vTokenReceiver: "0x1c6C2498854662FDeadbC4F14eA2f30ca305104b",
                },
                {
                    name: "Venus SOL",
                    asset: "SOL",
                    symbol: "vSOL",
                    rateModel: InterestRateModels.JumpRate.toString(),
                    baseRatePerYear: (0, utils_1.convertToUnit)("0.02", 18),
                    multiplierPerYear: (0, utils_1.convertToUnit)("0.2", 18),
                    jumpMultiplierPerYear: (0, utils_1.convertToUnit)("3", 18),
                    kink_: (0, utils_1.convertToUnit)("0.5", 18),
                    collateralFactor: (0, utils_1.convertToUnit)("0.72", 18),
                    reserveFactor: (0, utils_1.convertToUnit)("0.2", 18),
                    initialSupply: (0, utils_1.convertToUnit)("21.2829576", 18),
                    supplyCap: (0, utils_1.convertToUnit)("18000", 18),
                    borrowCap: (0, utils_1.convertToUnit)("9000", 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;
