Skip to content

Commit

Permalink
feat(VaultUtils): add accruedInterest util
Browse files Browse the repository at this point in the history
  • Loading branch information
oumar-fall committed Jan 28, 2025
1 parent 21e528c commit 87f282a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/blue-sdk/src/vault/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type IVaultMarketAllocation,
VaultMarketAllocation,
} from "./VaultMarketAllocation.js";
import { VaultUtils } from "./VaultUtils";

export interface Pending<T> {
value: T;
Expand Down Expand Up @@ -293,6 +294,13 @@ export class AccrualVault extends Vault implements IAccrualVault {
return MathLib.wMulDown(this.apy, MathLib.WAD - this.fee);
}

/**
* Total interest paid by borrowers, increased with unrealized bad debt.
*/
get accruedInterest() {
return VaultUtils.accruedInterest(this);
}

public getAllocationProportion(marketId: MarketId) {
if (this.totalAssets === 0n) return 0n;

Expand Down
19 changes: 19 additions & 0 deletions packages/blue-sdk/src/vault/VaultUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,23 @@ export namespace VaultUtils {
rounding,
);
}

export function accruedInterest({
totalAssets,
totalSupply,
decimalsOffset,
}: {
totalAssets: BigIntish;
totalSupply: BigIntish;
decimalsOffset: BigIntish;
}) {
return (
BigInt(totalAssets) -
toAssets(
totalSupply,
{ totalAssets: 0n, totalSupply: 0n, decimalsOffset },
"Down",
)
);
}
}

0 comments on commit 87f282a

Please sign in to comment.