Skip to content
Merged
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ module.exports = {
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/prefer-as-const': 'error',

Expand Down
81 changes: 29 additions & 52 deletions app/markets/components/MarketRowDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,56 @@
import { ExternalLinkIcon } from '@radix-ui/react-icons';
import { zeroAddress } from 'viem';
import { Tooltip } from '@nextui-org/tooltip';
import { ExternalLinkIcon, QuestionMarkCircledIcon } from '@radix-ui/react-icons';
import { OracleFeedInfo } from '@/components/FeedInfo/OracleFeedInfo';
import { Info } from '@/components/Info/info';
import OracleVendorBadge from '@/components/OracleVendorBadge';
import { formatReadable } from '@/utils/balance';
import { getExplorerURL } from '@/utils/external';
import { Market } from '@/utils/types';

export function ExpandedMarketDetail({ market }: { market: Market }) {
console.log('market.oracleFeed', market.oracleFeed);
const oracleData = market.oracle ? market.oracle.data : null;

const hasFeeds =
oracleData &&
(oracleData.baseFeedOne ||
oracleData.baseFeedTwo ||
oracleData.quoteFeedOne ||
oracleData.quoteFeedTwo);

return (
<div className="m-4 flex max-w-xs flex-col gap-2 sm:max-w-sm lg:max-w-none lg:flex-row">
{/* Oracle info */}
<div className="m-4 lg:w-1/3">
{/* warnings */}
<div className="mb-1 flex items-start justify-between text-base">
<p className="mb-2 font-zen">Oracle Info</p>
</div>
<div className="mb-1 flex items-start justify-between">
<p className="font-inter text-sm opacity-80">Oracle:</p>
<div className="flex items-start justify-between">
<p className="font-inter text-sm opacity-80">Vendors:</p>
<a
className="group flex items-center gap-1 no-underline hover:underline"
href={getExplorerURL(market.oracleAddress, market.morphoBlue.chain.id)}
target="_blank"
>
<p className="text-right font-zen text-sm">{market.oracleInfo.type}</p>
<OracleVendorBadge oracleData={oracleData} useTooltip />
<ExternalLinkIcon />
</a>
</div>
{market.oracleFeed && (
<>
<div className="mb-1 flex items-start justify-between">
<p className="font-inter text-xs opacity-80">Base feed</p>

<OracleFeedInfo
address={market.oracleFeed.baseFeedOneAddress}
title={market.oracleFeed.baseFeedOneDescription}
chainId={market.morphoBlue.chain.id}
/>
{hasFeeds && (
<div className="">
<div className="mb-1 flex items-center">
<p className="text-left font-inter text-sm opacity-80">Feed Routes:</p>
<Tooltip
content="Feed routes show how asset prices are derived from different oracle providers"
className="rounded-sm p-2"
>
<QuestionMarkCircledIcon className="ml-2 h-4 w-4 cursor-help text-secondary" />
</Tooltip>
</div>
{/* only shows base feed 2 if non-zero */}
{market.oracleFeed.baseFeedTwoAddress !== zeroAddress && (
<div className="mb-1 flex items-start justify-between">
<p className="font-inter text-xs opacity-80">Base feed 2</p>
<OracleFeedInfo
address={market.oracleFeed.baseFeedTwoAddress}
title={market.oracleFeed.baseFeedTwoDescription}
chainId={market.morphoBlue.chain.id}
/>
</div>
)}

{market.oracleFeed.quoteFeedOneAddress !== zeroAddress && (
<div className="mb-1 flex items-start justify-between">
<p className="font-inter text-xs opacity-80">Quote feed</p>
<OracleFeedInfo
address={market.oracleFeed.quoteFeedOneAddress}
title={market.oracleFeed.quoteFeedOneDescription}
chainId={market.morphoBlue.chain.id}
/>
</div>
)}

{/* only shows quote feed 2 if non-zero */}
{market.oracleFeed.quoteFeedTwoAddress !== zeroAddress && (
<div className="mb-1 flex items-start justify-between">
<p className="font-inter text-xs opacity-80">Quote feed 2</p>
<OracleFeedInfo
address={market.oracleFeed.quoteFeedTwoAddress}
title={market.oracleFeed.quoteFeedTwoDescription}
chainId={market.morphoBlue.chain.id}
/>
</div>
)}
</>
<OracleFeedInfo feed={oracleData.baseFeedOne} chainId={market.morphoBlue.chain.id} />
<OracleFeedInfo feed={oracleData.baseFeedTwo} chainId={market.morphoBlue.chain.id} />
<OracleFeedInfo feed={oracleData.quoteFeedOne} chainId={market.morphoBlue.chain.id} />
<OracleFeedInfo feed={oracleData.quoteFeedTwo} chainId={market.morphoBlue.chain.id} />
Comment thread
antoncoding marked this conversation as resolved.
</div>
)}
</div>

Expand Down
8 changes: 7 additions & 1 deletion app/markets/components/MarketTableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ExternalLinkIcon } from '@radix-ui/react-icons';
import Image from 'next/image';
import { FaShieldAlt } from 'react-icons/fa';
import { GoStarFill, GoStar } from 'react-icons/go';
import OracleVendorBadge from '@/components/OracleVendorBadge';
import { formatReadable } from '@/utils/balance';
import { getMarketURL } from '@/utils/external';
import { getNetworkImg } from '@/utils/networks';
Expand Down Expand Up @@ -116,6 +117,11 @@ export function MarketTableBody({
img={collatImg}
symbol={collatToShow}
/>
<td data-label="Oracle" className="z-50">
<div className="flex justify-center">
<OracleVendorBadge oracleData={item.oracle.data} />
</div>
</td>
<td data-label="LLTV" className="z-50">
{Number(item.lltv) / 1e16}%
</td>
Expand Down Expand Up @@ -174,7 +180,7 @@ export function MarketTableBody({
</tr>
{expandedRowId === item.uniqueKey && (
<tr className={`${item.uniqueKey === expandedRowId ? 'table-body-focused' : ''}`}>
<td className="collaps-viewer bg-hovered" colSpan={12}>
<td className="collaps-viewer bg-hovered" colSpan={13}>
<ExpandedMarketDetail market={item} />
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions app/markets/components/marketsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function MarketsTable({
sortDirection={sortDirection}
targetColumn={SortColumn.CollateralAsset}
/>
<th className="font-normal">Oracle</th>
<HTSortable
label="LLTV"
sortColumn={sortColumn}
Expand Down
10 changes: 9 additions & 1 deletion app/positions/components/SuppliedMarketsDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Tooltip } from '@nextui-org/tooltip';
import { ExternalLinkIcon } from '@radix-ui/react-icons';
import { IoWarningOutline } from 'react-icons/io5';
import OracleVendorBadge from '@/components/OracleVendorBadge';
import { TokenIcon } from '@/components/TokenIcon';
import { formatReadable, formatBalance } from '@/utils/balance';
import { getMarketURL } from '@/utils/external';
Expand Down Expand Up @@ -99,6 +100,7 @@ export function SuppliedMarketsDetail({
<tr>
<th>Market</th>
<th>Collateral</th>
<th>Oracle</th>
<th>LLTV</th>
<th>APY</th>
<th>Supplied</th>
Expand All @@ -111,7 +113,8 @@ export function SuppliedMarketsDetail({
const suppliedAmount = Number(
formatBalance(position.supplyAssets, position.market.loanAsset.decimals),
);
const percentageOfPortfolio = totalSupply > 0 ? (suppliedAmount / totalSupply) * 100 : 0;
const percentageOfPortfolio =
totalSupply > 0 ? (suppliedAmount / totalSupply) * 100 : 0;
const warningColor = getWarningColor(position.warningsWithDetail);

return (
Expand Down Expand Up @@ -163,6 +166,11 @@ export function SuppliedMarketsDetail({
'N/A'
)}
</td>
<td data-label="Oracle" className="text-center">
<div className="flex justify-center">
<OracleVendorBadge oracleData={position.market.oracle.data} useTooltip />
</div>
</td>
<td data-label="LLTV" className="text-center">
{formatBalance(position.market.lltv, 16)}%
</td>
Expand Down
68 changes: 45 additions & 23 deletions src/components/FeedInfo/OracleFeedInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
import { Tooltip } from '@nextui-org/tooltip';
import { ExternalLinkIcon } from '@radix-ui/react-icons';
import Image from 'next/image';
import Link from 'next/link';
import { Address, zeroAddress } from 'viem';
import { IoIosSwap } from 'react-icons/io';
import { IoWarningOutline } from 'react-icons/io5';
import { Address } from 'viem';
import { getSlicedAddress } from '@/utils/address';
import { getExplorerURL } from '@/utils/external';
import { OracleVendors, OracleVendorIcons } from '@/utils/oracle';
import { OracleFeed } from '@/utils/types';

export function OracleFeedInfo({
address,
title,
feed,
chainId,
}: {
address: string;
title: string | null;
feed: OracleFeed | null;
chainId: number;
}): JSX.Element {
const isLink = address !== zeroAddress;
}): JSX.Element | null {
if (!feed) return null;

const fromAsset = feed.pair?.[0] ?? 'Unknown';
const toAsset = feed.pair?.[1] ?? 'Unknown';

const vendorIcon =
OracleVendorIcons[feed.vendor as OracleVendors] ?? OracleVendorIcons[OracleVendors.Unknown];

const content = (
<div className="ml-2 flex w-full items-center justify-between pb-1">
<div className="flex items-center space-x-2 text-xs">
<span>{fromAsset}</span>
<IoIosSwap />
<span>{toAsset}</span>
</div>
{vendorIcon ? (
<Image src={vendorIcon} alt={feed.vendor ?? 'Unknown'} width={16} height={16} />
) : (
<IoWarningOutline size={16} />
)}
</div>
);

if (isLink)
return (
<Link
className="group flex items-center gap-1 text-right no-underline hover:underline"
href={getExplorerURL(address as Address, chainId)}
target="_blank"
<Tooltip
content={feed.description ?? getSlicedAddress(feed.address as Address)}
className="rounded-sm"
>
{title ? (
<p className="text-right font-zen text-xs"> {title} </p>
) : (
<p className="text-right font-zen text-sm"> {getSlicedAddress(address as Address)} </p>
)}
<ExternalLinkIcon />
</Link>
<Link
className="group flex w-full items-center gap-1 text-right no-underline hover:underline"
href={getExplorerURL(feed.address as Address, chainId)}
target="_blank"
>
{content}
<ExternalLinkIcon className="ml-1" />
</Link>
</Tooltip>
);
}

return (
<p className="text-right font-zen text-sm text-yellow-500 hover:no-underline"> Hardcoded 1 </p>
);
}
70 changes: 70 additions & 0 deletions src/components/OracleVendorBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react';
import { Tooltip } from '@nextui-org/tooltip';
import Image from 'next/image';
import { IoWarningOutline } from 'react-icons/io5';
import { OracleVendorIcons, OracleVendors, parseOracleVendors } from '@/utils/oracle';
import { MorphoChainlinkOracleData } from '@/utils/types';

type OracleVendorBadgeProps = {
oracleData: MorphoChainlinkOracleData | null;
useTooltip?: boolean;
};

const renderVendorIcon = (vendor: OracleVendors) => (
OracleVendorIcons[vendor]
? <Image src={OracleVendorIcons[vendor]} alt={vendor} width={16} height={16} />
: <IoWarningOutline className="text-secondary" size={16} />
);

function OracleVendorBadge({ oracleData, useTooltip = true }: OracleVendorBadgeProps) {
const { vendors } = parseOracleVendors(oracleData);

const noFeeds = vendors.length === 0;

const content = (
<div className={`flex items-center space-x-1 ${useTooltip ? '' : 'rounded bg-primary p-1'}`}>
{!useTooltip && (
<span className="mr-1 text-xs font-medium">
{noFeeds ? 'No Oracle' : vendors.join(', ')}:
</span>
)}
{noFeeds ? (
<IoWarningOutline className="text-secondary" size={16} />
) : (
vendors.map((vendor, index) => (
<React.Fragment key={index}>
{renderVendorIcon(vendor)}
</React.Fragment>
))
)}
</div>
);

if (useTooltip) {
return (
<Tooltip
content={
<div className="m-2">
<p className="py-2 text-sm font-medium">
{noFeeds ? 'No Oracle Feed Used' : 'Oracle Vendors:'}
</p>
<ul>
{vendors.map((vendor, index) => (
<li key={index} className="text-xs">
{vendor}
</li>
))}
</ul>
</div>
}
className="rounded-sm"
>
{content}
</Tooltip>
);
}

return content;
};

export default OracleVendorBadge;
1 change: 0 additions & 1 deletion src/components/TokenIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type TokenIconProps = {
export function TokenIcon({ address, chainId, width, height }: TokenIconProps) {
const token = findToken(address, chainId);


if (!token?.img) {
return <div className="rounded-full bg-gray-300" style={{ width, height }} />;
}
Expand Down
Loading