UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

27 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accrueInterests = void 0; const math_js_1 = require("./math.js"); const accrueInterests = (lastBlockTimestamp, marketState, borrowRate) => { const elapsed = BigInt(lastBlockTimestamp) - BigInt(marketState.lastUpdate); if (elapsed === 0n || marketState.totalBorrowAssets === 0n) { return marketState; } const interest = (0, math_js_1.wMulDown)(marketState.totalBorrowAssets, (0, math_js_1.wTaylorCompounded)(borrowRate, elapsed)); const marketWithNewTotal = { ...marketState, totalBorrowAssets: marketState.totalBorrowAssets + interest, totalSupplyAssets: marketState.totalSupplyAssets + interest, }; if (marketWithNewTotal.fee === 0n) { return marketWithNewTotal; } const feeAmount = (0, math_js_1.wMulDown)(interest, marketWithNewTotal.fee); const feeShares = (0, math_js_1.toSharesDown)(feeAmount, BigInt(marketWithNewTotal.totalSupplyAssets) - feeAmount, BigInt(marketWithNewTotal.totalSupplyShares)); return { ...marketWithNewTotal, totalSupplyShares: BigInt(marketWithNewTotal.totalSupplyShares) + feeShares, }; }; exports.accrueInterests = accrueInterests; //# sourceMappingURL=accrueInterests.js.map