"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContractAddressOrNullAddress = exports.getTokenConfig = exports.getConfig = exports.globalConfig = exports.InterestRateModels = void 0;
const bscmainnet_json_1 = require("@venusprotocol/governance-contracts/deployments/bscmainnet.json");
const bsctestnet_json_1 = require("@venusprotocol/governance-contracts/deployments/bsctestnet.json");
const bscmainnet_addresses_json_1 = require("../deployments/bscmainnet_addresses.json");
const bsctestnet_addresses_json_1 = require("../deployments/bsctestnet_addresses.json");
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 preconfiguredAddresses = {
    hardhat: {
        VTreasury: "account:deployer",
    },
    bsctestnet: {
        VTreasury: bsctestnet_addresses_json_1.addresses.VTreasury,
        NormalTimelock: bsctestnet_json_1.contracts.NormalTimelock.address,
        VTokenImpl: "0x8d79c8f4400fe68fd17040539fe5e1706c1f2850",
    },
    bscmainnet: {
        VTreasury: bscmainnet_addresses_json_1.addresses.VTreasury,
        NormalTimelock: bscmainnet_json_1.contracts.NormalTimelock.address,
        VTokenImpl: "0xc3279442a5acacf0a2ecb015d1cddbb3e0f3f775",
    },
};
exports.globalConfig = {
    hardhat: {
        tokensConfig: [
            {
                isMock: true,
                name: "First Digital USD",
                symbol: "FDUSD",
                decimals: 18,
            },
            {
                isMock: true,
                name: "Wrapped BNB",
                symbol: "WBNB",
                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: bsctestnet_addresses_json_1.addresses.VTreasury,
            },
        ],
        preconfiguredAddresses: preconfiguredAddresses.bsctestnet,
    },
    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: bsctestnet_addresses_json_1.addresses.VTreasury,
            },
        ],
        preconfiguredAddresses: preconfiguredAddresses.bsctestnet,
    },
    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.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: bscmainnet_addresses_json_1.addresses.VTreasury,
            },
        ],
        preconfiguredAddresses: preconfiguredAddresses.bscmainnet,
    },
};
async function getConfig(networkName) {
    switch (networkName) {
        case "hardhat":
            return exports.globalConfig.hardhat;
        case "bsctestnet":
            return exports.globalConfig.bsctestnet;
        case "bscmainnet":
            return exports.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;
