Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(VaultUtils): add accruedInterest util #256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Total interest paid by borrowers, increased with unrealized bad debt.
* Total interest paid by borrowers to this vault plus unrealized bad debt.
* In the case of MetaMorphoV1.1 vaults, also contains realized bad debt.

Or we pass totalAssets - lostAssets to accruedInterest

*/
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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Down",

Optional: this is the default behavior and it sematnically corresponds to what's expected: the canonical assets value of all shares

)
);
}
}
Loading