"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaturityTimestampReserveKind = exports.FixedRateReserveKind = exports.FloatRateReserveKind = exports.ReserveKind = void 0;
/**
 * Base class for reserve kind identification.
 * Since a market can have multiple reserves for the same mint (with different terms),
 * this kind specifies which reserve to select.
 */
class ReserveKind {
}
exports.ReserveKind = ReserveKind;
/**
 * Represents an open-term reserve with no fixed maturity.
 */
class FloatRateReserveKind extends ReserveKind {
    /**
     * Checks if a reserve matches this open-term reserve kind
     */
    matches(reserve) {
        return reserve.state.config.debtTermSeconds.eqn(0) && reserve.state.config.debtMaturityTimestamp.eqn(0);
    }
    toString() {
        return 'FloatRate';
    }
    isFloatRate() {
        return true;
    }
    isFixedRate() {
        return false;
    }
    isMaturityTimestampKind() {
        return false;
    }
}
exports.FloatRateReserveKind = FloatRateReserveKind;
/**
 * Represents a fixed-term reserve with specific loan parameters.
 */
class FixedRateReserveKind extends ReserveKind {
    debtTermSeconds;
    borrowRateBps;
    /**
     * @param debtTermSeconds The debt term in seconds (e.g., new BN(30 * 24 * 60 * 60) for 30 days)
     * @param borrowRateBps The maximum borrow rate in basis points (e.g., 500 for 5%)
     */
    constructor(debtTermSeconds, borrowRateBps) {
        super();
        this.debtTermSeconds = debtTermSeconds;
        this.borrowRateBps = borrowRateBps;
    }
    /**
     * Checks if a reserve matches this fixed-term reserve kind
     */
    matches(reserve) {
        // Check debt term matches
        if (!reserve.state.config.debtTermSeconds.eq(this.debtTermSeconds)) {
            return false;
        }
        // For fixed-term reserves, all points on the borrow rate curve should have the same rate
        const curvePoints = reserve.state.config.borrowRateCurve.points;
        // Check if all points have the expected borrow rate
        return curvePoints.every((point) => point.borrowRateBps === this.borrowRateBps);
    }
    toString() {
        return `FixedRate(term=${this.debtTermSeconds.toString()}s, rate=${this.borrowRateBps}bps)`;
    }
    isFloatRate() {
        return false;
    }
    isFixedRate() {
        return true;
    }
    isMaturityTimestampKind() {
        return false;
    }
}
exports.FixedRateReserveKind = FixedRateReserveKind;
/**
 * Represents a reserve with a fixed maturity timestamp at which all debts become liquidatable.
 */
class MaturityTimestampReserveKind extends ReserveKind {
    debtMaturityTimestamp;
    /**
     * @param debtMaturityTimestamp The unix timestamp at which all debts from this reserve become liquidatable
     */
    constructor(debtMaturityTimestamp) {
        super();
        this.debtMaturityTimestamp = debtMaturityTimestamp;
    }
    /**
     * Checks if a reserve matches this maturity timestamp reserve kind
     */
    matches(reserve) {
        return reserve.state.config.debtMaturityTimestamp.eq(this.debtMaturityTimestamp);
    }
    toString() {
        return `MaturityTimestamp(ts=${this.debtMaturityTimestamp.toString()})`;
    }
    isFloatRate() {
        return false;
    }
    isFixedRate() {
        return false;
    }
    isMaturityTimestampKind() {
        return true;
    }
}
exports.MaturityTimestampReserveKind = MaturityTimestampReserveKind;
//# sourceMappingURL=ReserveKind.js.map