"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObligationLiquidity = void 0;
const kit_1 = require("@solana/kit"); // eslint-disable-line @typescript-eslint/no-unused-vars
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh"));
const utils_1 = require("../utils");
class ObligationLiquidity {
    borrowReserve;
    cumulativeBorrowRateBsf;
    lastBorrowedAtTimestamp;
    borrowedAmountSf;
    marketValueSf;
    borrowFactorAdjustedMarketValueSf;
    borrowedAmountOutsideElevationGroups;
    fixedTermBorrowRolloverConfig;
    borrowedAmountAtExpiration;
    padding2;
    constructor(fields) {
        this.borrowReserve = fields.borrowReserve;
        this.cumulativeBorrowRateBsf = new types.BigFractionBytes({
            ...fields.cumulativeBorrowRateBsf,
        });
        this.lastBorrowedAtTimestamp = fields.lastBorrowedAtTimestamp;
        this.borrowedAmountSf = fields.borrowedAmountSf;
        this.marketValueSf = fields.marketValueSf;
        this.borrowFactorAdjustedMarketValueSf =
            fields.borrowFactorAdjustedMarketValueSf;
        this.borrowedAmountOutsideElevationGroups =
            fields.borrowedAmountOutsideElevationGroups;
        this.fixedTermBorrowRolloverConfig =
            new types.FixedTermBorrowRolloverConfig({
                ...fields.fixedTermBorrowRolloverConfig,
            });
        this.borrowedAmountAtExpiration = fields.borrowedAmountAtExpiration;
        this.padding2 = fields.padding2;
    }
    static layout(property) {
        return borsh.struct([
            (0, utils_1.borshAddress)("borrowReserve"),
            types.BigFractionBytes.layout("cumulativeBorrowRateBsf"),
            borsh.u64("lastBorrowedAtTimestamp"),
            borsh.u128("borrowedAmountSf"),
            borsh.u128("marketValueSf"),
            borsh.u128("borrowFactorAdjustedMarketValueSf"),
            borsh.u64("borrowedAmountOutsideElevationGroups"),
            types.FixedTermBorrowRolloverConfig.layout("fixedTermBorrowRolloverConfig"),
            borsh.u64("borrowedAmountAtExpiration"),
            borsh.array(borsh.u64(), 4, "padding2"),
        ], property);
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    static fromDecoded(obj) {
        return new ObligationLiquidity({
            borrowReserve: obj.borrowReserve,
            cumulativeBorrowRateBsf: types.BigFractionBytes.fromDecoded(obj.cumulativeBorrowRateBsf),
            lastBorrowedAtTimestamp: obj.lastBorrowedAtTimestamp,
            borrowedAmountSf: obj.borrowedAmountSf,
            marketValueSf: obj.marketValueSf,
            borrowFactorAdjustedMarketValueSf: obj.borrowFactorAdjustedMarketValueSf,
            borrowedAmountOutsideElevationGroups: obj.borrowedAmountOutsideElevationGroups,
            fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfig.fromDecoded(obj.fixedTermBorrowRolloverConfig),
            borrowedAmountAtExpiration: obj.borrowedAmountAtExpiration,
            padding2: obj.padding2,
        });
    }
    static toEncodable(fields) {
        return {
            borrowReserve: fields.borrowReserve,
            cumulativeBorrowRateBsf: types.BigFractionBytes.toEncodable(fields.cumulativeBorrowRateBsf),
            lastBorrowedAtTimestamp: fields.lastBorrowedAtTimestamp,
            borrowedAmountSf: fields.borrowedAmountSf,
            marketValueSf: fields.marketValueSf,
            borrowFactorAdjustedMarketValueSf: fields.borrowFactorAdjustedMarketValueSf,
            borrowedAmountOutsideElevationGroups: fields.borrowedAmountOutsideElevationGroups,
            fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfig.toEncodable(fields.fixedTermBorrowRolloverConfig),
            borrowedAmountAtExpiration: fields.borrowedAmountAtExpiration,
            padding2: fields.padding2,
        };
    }
    toJSON() {
        return {
            borrowReserve: this.borrowReserve,
            cumulativeBorrowRateBsf: this.cumulativeBorrowRateBsf.toJSON(),
            lastBorrowedAtTimestamp: this.lastBorrowedAtTimestamp.toString(),
            borrowedAmountSf: this.borrowedAmountSf.toString(),
            marketValueSf: this.marketValueSf.toString(),
            borrowFactorAdjustedMarketValueSf: this.borrowFactorAdjustedMarketValueSf.toString(),
            borrowedAmountOutsideElevationGroups: this.borrowedAmountOutsideElevationGroups.toString(),
            fixedTermBorrowRolloverConfig: this.fixedTermBorrowRolloverConfig.toJSON(),
            borrowedAmountAtExpiration: this.borrowedAmountAtExpiration.toString(),
            padding2: this.padding2.map((item) => item.toString()),
        };
    }
    static fromJSON(obj) {
        return new ObligationLiquidity({
            borrowReserve: (0, kit_1.address)(obj.borrowReserve),
            cumulativeBorrowRateBsf: types.BigFractionBytes.fromJSON(obj.cumulativeBorrowRateBsf),
            lastBorrowedAtTimestamp: new bn_js_1.default(obj.lastBorrowedAtTimestamp),
            borrowedAmountSf: new bn_js_1.default(obj.borrowedAmountSf),
            marketValueSf: new bn_js_1.default(obj.marketValueSf),
            borrowFactorAdjustedMarketValueSf: new bn_js_1.default(obj.borrowFactorAdjustedMarketValueSf),
            borrowedAmountOutsideElevationGroups: new bn_js_1.default(obj.borrowedAmountOutsideElevationGroups),
            fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfig.fromJSON(obj.fixedTermBorrowRolloverConfig),
            borrowedAmountAtExpiration: new bn_js_1.default(obj.borrowedAmountAtExpiration),
            padding2: obj.padding2.map((item) => new bn_js_1.default(item)),
        });
    }
    toEncodable() {
        return ObligationLiquidity.toEncodable(this);
    }
}
exports.ObligationLiquidity = ObligationLiquidity;
//# sourceMappingURL=ObligationLiquidity.js.map