"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExactlyFixedBorrowFetcher = void 0;
const ethers_1 = require("ethers");
const exactly_fixed_position_fetcher_1 = require("../common/exactly.fixed-position-fetcher");
class ExactlyFixedBorrowFetcher extends exactly_fixed_position_fetcher_1.ExactlyFixedPositionFetcher {
    constructor() {
        super(...arguments);
        this.groupLabel = 'Variable Borrow';
        this.isDebt = true;
    }
    getTotalAssets({ definition }) {
        return definition.fixedPools.reduce((total, { borrowed }) => total.add(borrowed), ethers_1.constants.Zero);
    }
    getBestRate({ definition }) {
        return definition.fixedPools.reduce((best, { maturity, minBorrowRate: rate }) => (rate.lt(best.rate) ? { maturity, rate } : best), { maturity: ethers_1.constants.Zero, rate: ethers_1.constants.MaxUint256 });
    }
    getBalancePerToken({ address, appToken, multicall, }) {
        return __awaiter(this, void 0, void 0, function* () {
            const { fixedBorrowPositions } = yield this.definitionsResolver.getDefinition({
                multicall,
                network: this.network,
                account: address,
                market: appToken.address,
            });
            return fixedBorrowPositions.reduce((total, { previewValue }) => total.add(previewValue), ethers_1.constants.Zero);
        });
    }
}
exports.ExactlyFixedBorrowFetcher = ExactlyFixedBorrowFetcher;
//# sourceMappingURL=exactly.fixed-borrow.token-fetcher.js.map