Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(morpho): Fix utilization rate (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-devatom authored Sep 12, 2022
1 parent 13e8191 commit c4d346f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,23 @@ export class EthereumMorphoAaveV2SupplyContractPositionFetcher extends BaseEther
const supply = +formatUnits(supplyRaw, underlyingToken.decimals);
const supplyUSD = supply * underlyingToken.price;
const borrowRaw = totalMarketBorrowRaw.p2pBorrowAmount.add(totalMarketBorrowRaw.poolBorrowAmount);
const matchedUSD = +formatUnits(borrowRaw, underlyingToken.decimals) * underlyingToken.price;
const borrow = +formatUnits(borrowRaw, underlyingToken.decimals);
const borrowUSD = borrow * underlyingToken.price;
const liquidity = supply * underlyingToken.price;

return { marketAddress, supplyApy, borrowApy, liquidity, p2pDisabled, supply, supplyUSD, borrow, borrowUSD };
return {
marketAddress,
supplyApy,
borrowApy,
liquidity,
p2pDisabled,
supply,
supplyUSD,
borrow,
borrowUSD,
matchedUSD,
};
}

async getTokenBalancesPerPosition({ address, contractPosition, multicall }): Promise<BigNumber[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { formatUnits } from 'ethers/lib/utils';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks';
Expand Down Expand Up @@ -81,11 +82,23 @@ export class EthereumMorphoCompoundSupplyContractPositionFetcher extends BaseEth
const supply = Number(supplyRaw) / 10 ** underlyingToken.decimals;
const supplyUSD = supply * underlyingToken.price;
const borrowRaw = totalMarketBorrowRaw.p2pBorrowAmount.add(totalMarketBorrowRaw.poolBorrowAmount);
const matchedUSD = +formatUnits(borrowRaw, underlyingToken.decimals) * underlyingToken.price;
const borrow = Number(borrowRaw) / 10 ** underlyingToken.decimals;
const borrowUSD = borrow * underlyingToken.price;
const liquidity = supply * underlyingToken.price;

return { marketAddress, supplyApy, borrowApy, liquidity, p2pDisabled, supply, supplyUSD, borrow, borrowUSD };
return {
marketAddress,
supplyApy,
borrowApy,
liquidity,
p2pDisabled,
supply,
supplyUSD,
borrow,
borrowUSD,
matchedUSD,
};
}

async getTokenBalancesPerPosition({ address, contractPosition, multicall }) {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/morpho/ethereum/morpho.position-presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class EthereumMorphoPositionPresenter extends PositionPresenterTemplate {
},
{
label: 'Utilization Rate',
value: liquidationThreshold > 0 ? debt / liquidationThreshold : 0,
value: liquidationThreshold > 0 ? (debt / liquidationThreshold) * 100 : 0,
type: 'pct',
},
];
Expand Down
4 changes: 3 additions & 1 deletion src/apps/morpho/helpers/position-fetcher.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type MorphoContractPositionDataProps = {
supplyUSD: number;
borrow: number;
borrowUSD: number;
matchedUSD: number;
};
export abstract class BaseEthereumMorphoSupplyContractPositionFetcher<
T extends Contract,
Expand Down Expand Up @@ -60,7 +61,7 @@ export abstract class BaseEthereumMorphoSupplyContractPositionFetcher<
}: GetDisplayPropsParams<T, MorphoContractPositionDataProps, DefaultContractPositionDefinition>): Promise<
StatsItem[] | undefined
> {
const { supplyApy, borrowApy, supply, supplyUSD, borrow, borrowUSD } = contractPosition.dataProps;
const { supplyApy, borrowApy, supply, supplyUSD, borrow, borrowUSD, matchedUSD } = contractPosition.dataProps;

return [
{ label: 'Supply APY', value: buildPercentageDisplayItem(supplyApy * 100) },
Expand All @@ -69,6 +70,7 @@ export abstract class BaseEthereumMorphoSupplyContractPositionFetcher<
{ label: 'Borrow APY', value: buildPercentageDisplayItem(borrowApy * 100) },
{ label: 'Total Borrow', value: buildNumberDisplayItem(borrow) },
{ label: 'Total Borrow USD', value: buildDollarDisplayItem(borrowUSD) },
{ label: 'Total USD Value Matched P2P', value: buildDollarDisplayItem(matchedUSD) },
];
}

Expand Down

0 comments on commit c4d346f

Please sign in to comment.