"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.markets = void 0;
const utils_1 = require("ethers/lib/utils");
const hardhat_1 = require("hardhat");
const tokens_1 = require("../tokens");
const bscmainnet_1 = __importDefault(require("./bscmainnet"));
const bsctestnet_1 = __importDefault(require("./bsctestnet"));
const hardhat_2 = __importDefault(require("./hardhat"));
const parseWpRateModel = (raw) => {
    return {
        ...raw,
        baseRatePerYear: (0, utils_1.parseUnits)(raw.baseRatePerYear, 18),
        multiplierPerYear: (0, utils_1.parseUnits)(raw.multiplierPerYear, 18),
    };
};
const parseJumpRateModel = (raw) => {
    return {
        ...raw,
        baseRatePerYear: (0, utils_1.parseUnits)(raw.baseRatePerYear, 18),
        multiplierPerYear: (0, utils_1.parseUnits)(raw.multiplierPerYear, 18),
        jumpMultiplierPerYear: (0, utils_1.parseUnits)(raw.jumpMultiplierPerYear, 18),
        kink: (0, utils_1.parseUnits)(raw.kink, 18),
    };
};
const parseTwoKinksRateModel = (raw) => {
    return {
        ...raw,
        baseRatePerYear: (0, utils_1.parseUnits)(raw.baseRatePerYear, 18),
        multiplierPerYear: (0, utils_1.parseUnits)(raw.multiplierPerYear, 18),
        kink: (0, utils_1.parseUnits)(raw.kink, 18),
        baseRatePerYear2: (0, utils_1.parseUnits)(raw.baseRatePerYear2, 18),
        multiplierPerYear2: (0, utils_1.parseUnits)(raw.multiplierPerYear2, 18),
        kink2: (0, utils_1.parseUnits)(raw.kink2, 18),
        jumpMultiplierPerYear: (0, utils_1.parseUnits)(raw.jumpMultiplierPerYear, 18),
    };
};
const parseRateModel = (raw) => {
    switch (raw.model) {
        case "whitepaper":
            return parseWpRateModel(raw);
        case "jump":
            return parseJumpRateModel(raw);
        case "two-kinks":
            return parseTwoKinksRateModel(raw);
    }
};
const parseMarket = (chain, raw) => {
    const { supplyCap, borrowCap } = raw.riskParameters;
    const { MaxUint256 } = hardhat_1.ethers.constants;
    return {
        ...raw,
        asset: (0, tokens_1.getToken)(chain, raw.asset),
        interestRateModel: parseRateModel(raw.interestRateModel),
        riskParameters: {
            collateralFactor: (0, utils_1.parseUnits)(raw.riskParameters.collateralFactor, 18),
            reserveFactor: (0, utils_1.parseUnits)(raw.riskParameters.reserveFactor, 18),
            supplyCap: supplyCap === "uncapped" ? MaxUint256 : (0, tokens_1.parseTokens)(supplyCap, chain, raw.asset),
            borrowCap: borrowCap === "uncapped" ? MaxUint256 : (0, tokens_1.parseTokens)(borrowCap, chain, raw.asset),
        },
        initialSupply: raw.initialSupply
            ? {
                amount: (0, tokens_1.parseTokens)(raw.initialSupply.amount, chain, raw.asset),
                vTokenReceiver: raw.initialSupply.vTokenReceiver,
            }
            : undefined,
    };
};
const parseMarkets = (chain, configs) => {
    return configs.map(config => parseMarket(chain, config));
};
exports.markets = {
    hardhat: parseMarkets("hardhat", hardhat_2.default),
    bscmainnet: parseMarkets("bscmainnet", bscmainnet_1.default),
    bsctestnet: parseMarkets("bsctestnet", bsctestnet_1.default),
    sepolia: [],
    ethereum: [],
    opbnbtestnet: [],
    opbnbmainnet: [],
    arbitrumsepolia: [],
    arbitrumone: [],
    opsepolia: [],
    opmainnet: [],
    basesepolia: [],
    basemainnet: [],
    unichainsepolia: [],
    unichainmainnet: [],
    berachainbepolia: [],
    zksyncsepolia: [],
    zksyncmainnet: [],
};
