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
18 changes: 13 additions & 5 deletions src/data-sources/morpho-api/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import type { SupportedNetworks } from '@/utils/networks';
import { blacklistTokens } from '@/utils/tokens';
import type { Market } from '@/utils/types';
import { morphoGraphqlFetcher } from './fetchers';
import { zeroAddress } from 'viem';

// API response type - matches the new Morpho API shape where oracleAddress is nested
type MorphoApiMarket = Omit<Market, 'oracleAddress'> & {
oracle: { address: string } | null;
};

type MarketGraphQLResponse = {
data: {
marketByUniqueKey: Market;
marketByUniqueKey: MorphoApiMarket;
};
errors?: { message: string }[];
};
Expand All @@ -15,7 +21,7 @@ type MarketGraphQLResponse = {
type MarketsGraphQLResponse = {
data: {
markets: {
items: Market[];
items: MorphoApiMarket[];
pageInfo: {
countTotal: number;
count: number;
Expand All @@ -27,10 +33,12 @@ type MarketsGraphQLResponse = {
errors?: { message: string }[];
};

const processMarketData = (market: Market): Market => {
// Transform API response to internal Market type
const processMarketData = (market: MorphoApiMarket): Market => {
const { oracle, ...rest } = market;
return {
...market,
// Standard API always have USD price!
...rest,
oracleAddress: oracle?.address ?? zeroAddress,
hasUSDPrice: true,
};
};
Expand Down
8 changes: 6 additions & 2 deletions src/graphql/morpho-api-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const commonMarketFields = `
lltv
uniqueKey
irmAddress
oracleAddress
oracle {
address
}
collateralPrice
whitelisted
morphoBlue {
Expand Down Expand Up @@ -169,7 +171,9 @@ export const marketsQuery = `
lltv
uniqueKey
irmAddress
oracleAddress
oracle {
address
}
collateralPrice
whitelisted
morphoBlue {
Expand Down