"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calcVesectRequiredForMaxBoostWeight = exports.calcBoost = exports.calcBoostWeight = exports.canWithdraw = exports.getMinLockDur = exports.lockDurations = exports.DAYS_IN_YEAR = exports.DAYS_IN_MONTH = exports.DAYS_IN_WEEK = exports.canConvertToLock = exports.canCreateLock = exports.didQuit = exports.lockExists = exports.isDelegated = exports.wouldExtendDuration = exports.getUnlockTime = exports.durationToWeek = exports.floorToWeek = exports.CANNOT_ADD_TO_QUIT_TOAST = exports.CANNOT_ADD_TO_DELEGATED_LOCK = exports.DURATION_WARNING = exports.VESECT_WEIGHT = exports.DEPOSIT_WEIGHT = exports.SEC_IN_YEAR = exports.SECONDS_IN_MONTH = exports.SECONDS_IN_WEEK = exports.SECONDS_IN_DAY = exports.SECT_DEC = exports.SECT_CHAIN = void 0;
exports.SECT_CHAIN = process.env.NODE_ENV === 'production' ? 'arbitrum' : 'localhost';
exports.SECT_DEC = 18;
exports.SECONDS_IN_DAY = 60 * 60 * 24;
exports.SECONDS_IN_WEEK = exports.SECONDS_IN_DAY * 7;
exports.SECONDS_IN_MONTH = exports.SECONDS_IN_DAY * 30;
exports.SEC_IN_YEAR = exports.SECONDS_IN_DAY * 365;
exports.DEPOSIT_WEIGHT = 0.4;
exports.VESECT_WEIGHT = 0.6;
exports.DURATION_WARNING = 'Note: Minting will extend the duration of your pre-existing lock, as only one veSECT lock may exist per account. If you would prefer to have multiple vesting durations, you may use another wallet.';
exports.CANNOT_ADD_TO_DELEGATED_LOCK = {
    title: 'Transaction Will Fail',
    message: 'Cannot add to an existing delegated lock. Please undelegate or use a different account.',
};
exports.CANNOT_ADD_TO_QUIT_TOAST = {
    title: 'Transaction Will Fail',
    message: "Cannot add to a previously quit lock. Please transfer tokens and try with a different account.",
};
function floorToWeek(unlockTime) {
    return Math.floor(unlockTime / exports.SECONDS_IN_WEEK) * exports.SECONDS_IN_WEEK;
}
exports.floorToWeek = floorToWeek;
function durationToWeek(seconds) {
    var now = Math.floor(Date.now() / 1000);
    var approxUnlockTime = now + seconds;
    var roundedUnlockTime = floorToWeek(approxUnlockTime);
    return roundedUnlockTime - now;
}
exports.durationToWeek = durationToWeek;
function getUnlockTime(seconds) {
    return floorToWeek(Math.floor(Date.now() / 1000) + seconds);
}
exports.getUnlockTime = getUnlockTime;
function wouldExtendDuration(lockStruct, unlockTime) {
    var _a, _b;
    if (!(lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end))
        return false;
    if ((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _a === void 0 ? void 0 : _a.isZero())
        return false;
    var oldEnd = (_b = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _b === void 0 ? void 0 : _b.toNumber();
    if (oldEnd >= floorToWeek(unlockTime))
        return false;
    return true;
}
exports.wouldExtendDuration = wouldExtendDuration;
function isDelegated(lockStruct, account) {
    var _a;
    if (!lockStruct || !account)
        return false;
    return !(lockStruct.delegatee == account || ((_a = lockStruct.amount) === null || _a === void 0 ? void 0 : _a.isZero()));
}
exports.isDelegated = isDelegated;
function lockExists(lockStruct) {
    var _a;
    if (!lockStruct)
        return false;
    if ((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.amount) === null || _a === void 0 ? void 0 : _a.gt(0))
        return true;
    return false;
}
exports.lockExists = lockExists;
function didQuit(lockStruct) {
    var _a, _b;
    if (!lockStruct)
        return false;
    if (((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.amount) === null || _a === void 0 ? void 0 : _a.isZero()) && ((_b = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _b === void 0 ? void 0 : _b.gt(0))) {
        return true;
    }
    else
        return false;
}
exports.didQuit = didQuit;
function canCreateLock(lockStruct, account, unlockTime) {
    if (!lockExists(lockStruct))
        return true;
    if (wouldExtendDuration(lockStruct, unlockTime))
        return true;
    return false;
}
exports.canCreateLock = canCreateLock;
function canConvertToLock(lockStruct, account, unlockTime) {
    var _a;
    if (!lockExists(lockStruct))
        return true;
    if (((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _a === void 0 ? void 0 : _a.toNumber()) === unlockTime)
        return true;
    if (wouldExtendDuration(lockStruct, unlockTime))
        return true;
    return false;
}
exports.canConvertToLock = canConvertToLock;
exports.DAYS_IN_WEEK = 7;
exports.DAYS_IN_MONTH = 30;
exports.DAYS_IN_YEAR = 365;
function lockDurations(seconds) {
    // return `${seconds} Week${seconds > 1 ? 's' : ''}`;
    // Note about below: Probably dont want to show "1 Year" because actually 1 year = 4 weeks * 12
    if (seconds === exports.SECONDS_IN_WEEK)
        return '1 Week';
    if (seconds < exports.SECONDS_IN_MONTH)
        return "".concat(seconds / exports.SECONDS_IN_WEEK, " Weeks");
    if (seconds === exports.SECONDS_IN_MONTH)
        return '1 Month';
    if (seconds < exports.SEC_IN_YEAR)
        return "".concat(seconds / exports.SECONDS_IN_MONTH, " Months");
    if (seconds === exports.SEC_IN_YEAR)
        return '1 Year';
    return "".concat(seconds / exports.SEC_IN_YEAR, " Years");
}
exports.lockDurations = lockDurations;
function getMinLockDur(lockStruct) {
    var _a, _b;
    // Returns seconds
    if (!((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _a === void 0 ? void 0 : _a.gt(0)))
        return exports.DAYS_IN_WEEK;
    return ((_b = lockStruct.end) === null || _b === void 0 ? void 0 : _b.toNumber()) - Math.floor(Date.now() / 1000);
}
exports.getMinLockDur = getMinLockDur;
function canWithdraw(lockStruct) {
    var _a, _b;
    if (!((_a = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _a === void 0 ? void 0 : _a.gt(0)))
        return false;
    var end = (_b = lockStruct === null || lockStruct === void 0 ? void 0 : lockStruct.end) === null || _b === void 0 ? void 0 : _b.toNumber();
    if (!end)
        return false;
    return end < Date.now() / 1000;
}
exports.canWithdraw = canWithdraw;
function calcBoostWeight(deposited, tvl, veBalance, veSupply) {
    return Math.min(deposited, deposited * exports.DEPOSIT_WEIGHT + ((tvl * veBalance) / veSupply) * exports.VESECT_WEIGHT);
}
exports.calcBoostWeight = calcBoostWeight;
function calcBoost(deposited, tvl, veBalance, veSupply) {
    return (calcBoostWeight(deposited, tvl, veBalance, veSupply) /
        deposited /
        exports.DEPOSIT_WEIGHT);
}
exports.calcBoost = calcBoost;
function calcVesectRequiredForMaxBoostWeight(deposited, tvl, veSupply) {
    return (deposited / tvl) * veSupply;
}
exports.calcVesectRequiredForMaxBoostWeight = calcVesectRequiredForMaxBoostWeight;
//# sourceMappingURL=sect.js.map