"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInfoFromName = exports.protocolKeys = exports.riskIdToLabel = exports.IAggVaultName = exports.getContractCollateral = exports.getDeploymentArtifactsByChain = exports.getVaultById = exports.getVaultType = exports.allVaultIds = exports.aggregatorEpochVaultList = exports.aggregatorVaultList = exports.scyEpochVaultList = exports.scyVaultList = exports.scyRebalanceVaultList = exports.vaultModuleList = exports.VaultType = exports.AggregatorVaultConfig = exports.aggregatorWEpochConf = exports.aggregatorConf = exports.RiskLevel = exports.AggregatorVaultType = void 0;
var constants_1 = require("./utils/constants");
var utils_1 = require("./utils");
var strategies_1 = require("./strategies");
var AggregatorVaultType;
(function (AggregatorVaultType) {
    // Used for important solidity params structs.
    // Don't convert to named enums.
    AggregatorVaultType[AggregatorVaultType["Strategy"] = 0] = "Strategy";
    AggregatorVaultType[AggregatorVaultType["Aggregator"] = 1] = "Aggregator";
})(AggregatorVaultType = exports.AggregatorVaultType || (exports.AggregatorVaultType = {}));
var RiskLevel;
(function (RiskLevel) {
    RiskLevel[RiskLevel["LOW"] = 0] = "LOW";
    RiskLevel[RiskLevel["MEDIUM"] = 1] = "MEDIUM";
    RiskLevel[RiskLevel["HIGH"] = 2] = "HIGH";
})(RiskLevel = exports.RiskLevel || (exports.RiskLevel = {}));
var aggregatorConf = function (underlying, risk) { return ({
    contract: 'AggregatorVault',
    underlying: underlying,
    risk: risk,
    name: "".concat(underlying, "-Aggregator-r").concat(risk, "-v0"),
    symbol: "sect".concat(underlying, "-r").concat(risk),
}); };
exports.aggregatorConf = aggregatorConf;
var aggregatorWEpochConf = function (underlying, risk) { return ({
    contract: 'AggregatorWEpochVault',
    underlying: underlying,
    risk: risk,
    name: "".concat(underlying, "-AggregatorWE-r").concat(risk, "-v0"),
    symbol: "sect".concat(underlying, "-r").concat(risk),
}); };
exports.aggregatorWEpochConf = aggregatorWEpochConf;
exports.AggregatorVaultConfig = {
    moonriver: [(0, exports.aggregatorConf)('USDC', RiskLevel.HIGH)],
    optimism: [
        (0, exports.aggregatorConf)('USDC', RiskLevel.HIGH),
        (0, exports.aggregatorConf)('USDC', RiskLevel.LOW),
        (0, exports.aggregatorConf)('ETH', RiskLevel.HIGH),
        (0, exports.aggregatorConf)('ETH', RiskLevel.LOW),
    ],
    arbitrum: [
        (0, exports.aggregatorConf)('USDC', RiskLevel.HIGH),
        (0, exports.aggregatorConf)('USDC', RiskLevel.LOW),
        (0, exports.aggregatorConf)('ETH', RiskLevel.LOW),
        (0, exports.aggregatorConf)('ETH', RiskLevel.HIGH),
    ],
    mainnet: [(0, exports.aggregatorWEpochConf)('USDC', RiskLevel.HIGH)],
};
var VaultType;
(function (VaultType) {
    VaultType["ScionVault"] = "ScionVault";
    VaultType["SCYVault"] = "SCYVault";
    VaultType["SCYWEpochVault"] = "SCYWEpochVault";
    VaultType["AggregatorVault"] = "AggregatorVault";
    VaultType["AggregatorWEpochVault"] = "AggregatorWEpochVault";
})(VaultType = exports.VaultType || (exports.VaultType = {}));
exports.vaultModuleList = [
    'ScionTimelock',
    'SectorTimelock',
    'UpgradeableBeacon',
];
exports.scyRebalanceVaultList = strategies_1.allRebalancingStrategies.map(function (stratConfig) { return stratConfig.symbol + '_Vault'; });
exports.scyVaultList = strategies_1.allScyStrategies.map(function (stratConfig) { return stratConfig.symbol + '_Vault'; });
exports.scyEpochVaultList = strategies_1.allScyEpochStrategies.map(function (stratConfig) { return stratConfig.symbol + '_Vault'; });
exports.aggregatorVaultList = (_a = Object.values(exports.AggregatorVaultConfig).reduce(function (acc, vault) {
    vault.forEach(function (v) {
        if (v.contract === 'AggregatorVault') {
            acc.aggregatorVaultList = Array.from(new Set(__spreadArray(__spreadArray([], __read(acc.aggregatorVaultList), false), [v.name], false))); // remove dupes
        }
        else if (v.contract === 'AggregatorWEpochVault') {
            acc.aggregatorEpochVaultList = Array.from(new Set(__spreadArray(__spreadArray([], __read(acc.aggregatorEpochVaultList), false), [v.name], false))); // remove dupes
        }
    });
    return acc;
}, { aggregatorVaultList: [], aggregatorEpochVaultList: [] }), _a.aggregatorVaultList), exports.aggregatorEpochVaultList = _a.aggregatorEpochVaultList;
var vaultList = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(exports.scyVaultList), false), __read(exports.scyEpochVaultList), false), __read(exports.aggregatorVaultList), false), __read(exports.aggregatorEpochVaultList), false);
exports.allVaultIds = __spreadArray(__spreadArray([], __read(vaultList), false), __read(exports.vaultModuleList), false);
function getVaultType(chain, address) {
    var id = ((0, utils_1.getDeploymentByAddr)(chain, address) || {}).id;
    if (!id)
        return;
    if (exports.scyVaultList.includes(id))
        return VaultType.SCYVault;
    if (exports.scyEpochVaultList.includes(id))
        return VaultType.SCYWEpochVault;
    if (exports.aggregatorVaultList.includes(id))
        return VaultType.AggregatorVault;
    if (exports.aggregatorEpochVaultList.includes(id))
        return VaultType.AggregatorWEpochVault;
}
exports.getVaultType = getVaultType;
function getVaultById(chain, id) {
    var _a, _b;
    if (!id || !chain)
        return null;
    var chainExists = (_b = (_a = constants_1.CHAIN_IDS[chain]) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a);
    if (!chainExists)
        return null;
    if (!vaultList.includes(id))
        return null;
    return (0, utils_1.getContractById)(chain, id);
}
exports.getVaultById = getVaultById;
function getDeploymentArtifactsByChain(chain, list) {
    var _a, _b, _c;
    var chainExists = (_b = (_a = constants_1.CHAIN_IDS[chain]) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a);
    if (!chainExists && chain !== 'ALL')
        throw new Error("chain ".concat(chain, " doesnt exist in CHAIN_IDS"));
    var set = Array.from(new Set(list)); // remove dupes
    var result = set.reduce(function (acc, id) {
        var data = (0, utils_1.getContractById)(chain, id);
        if (!data)
            return acc;
        var address = data.address;
        var isHidden = (0, utils_1.isHiddenVault)(chain, address);
        if (isHidden)
            return acc;
        var isDeprecated = (0, utils_1.isDeprecatedVault)(chain, address);
        var inBeta = (0, utils_1.isInBeta)(chain, address);
        acc.push(__assign(__assign({}, data), { id: id, chain: chain, isDeprecated: isDeprecated, isInBeta: inBeta }));
        return acc;
    }, []);
    if (!result || ((_c = Object.keys(result)) === null || _c === void 0 ? void 0 : _c.length) === 0)
        return null;
    return result;
}
exports.getDeploymentArtifactsByChain = getDeploymentArtifactsByChain;
function getContractCollateral(id) {
    if (!id)
        return null;
    var collateral = (getInfoFromName(id) || {}).collateral;
    return collateral;
}
exports.getContractCollateral = getContractCollateral;
var IAggVaultName;
(function (IAggVaultName) {
    IAggVaultName["Da Vinci"] = "Da Vinci";
    IAggVaultName["Copernicus"] = "Copernicus";
    IAggVaultName["Medici"] = "Medici";
})(IAggVaultName = exports.IAggVaultName || (exports.IAggVaultName = {}));
exports.riskIdToLabel = {
    r0: IAggVaultName['Da Vinci'],
    r1: IAggVaultName.Copernicus,
    r2: IAggVaultName.Medici,
};
exports.protocolKeys = {
    Well: 'Moonwell',
    Solar: 'Solarbeam',
    Xcal: '3xcalibur',
    Velo: 'Velodrome',
    '3crv': 'Curve',
};
function getInfoFromName(id) {
    var _a;
    if (!id)
        throw new Error('no id in getInfoFromName(id)');
    else if (id.includes('Aggregator')) {
        // USDC-Aggregator-r2-v0
        var _b = __read(id.split('-'), 4), collateral = _b[0], type = _b[1], riskNumber = _b[2], version = _b[3];
        var risk = riskNumber && exports.riskIdToLabel[riskNumber];
        return { collateral: collateral, type: type, risk: risk, version: version };
    }
    else if (id.startsWith('LND') ||
        id.startsWith('LLP') ||
        id.startsWith('HLP') ||
        id.startsWith('LCVX')) {
        // LLP_USDC-ETH_Tarot-Xcal_arbitrum_v0_0_Vault
        var _c = __read(id.split('_'), 6), type = _c[0], pool = _c[1], protocolsString = _c[2], network = _c[3], version = _c[4], index = _c[5];
        var _d = __read(pool === null || pool === void 0 ? void 0 : pool.split('-'), 2), collateral = _d[0], volatile = _d[1];
        var protocols = (_a = protocolsString === null || protocolsString === void 0 ? void 0 : protocolsString.split('-')) === null || _a === void 0 ? void 0 : _a.map(function (key) { var _a; return (_a = (key && exports.protocolKeys[key])) !== null && _a !== void 0 ? _a : key; });
        return { type: type, collateral: collateral, volatile: volatile, protocols: protocols, network: network, version: version, index: index };
    }
    else
        return {};
}
exports.getInfoFromName = getInfoFromName;
//# sourceMappingURL=vaults.js.map