-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reinstate fetching markets from the API
This reverts commit 8af944c.
- Loading branch information
1 parent
344e4ce
commit 3bdcf93
Showing
48 changed files
with
8,138 additions
and
3,355 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,8 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { formatToMarket } from 'utilities'; | ||
import apiMarketsResponse from '../api/markets.json'; | ||
|
||
import type { Market } from 'types'; | ||
|
||
export const markets: Market[] = [ | ||
{ | ||
address: '0x74469281310195a04840daf6edf576f559a3de80', | ||
borrowerCount: 306, | ||
supplierCount: 898, | ||
totalXvsDistributedTokens: new BigNumber('318096'), | ||
}, | ||
{ | ||
address: '0xd5c4c2e2facbeb59d0216d0595d63fcdc6f9a1a7', | ||
borrowerCount: 232, | ||
supplierCount: 638, | ||
totalXvsDistributedTokens: new BigNumber('261028'), | ||
}, | ||
{ | ||
address: '0xb7526572ffe56ab9d7489838bf2e18e3323b441a', | ||
borrowerCount: 315, | ||
supplierCount: 736, | ||
totalXvsDistributedTokens: new BigNumber('211354'), | ||
}, | ||
{ | ||
address: '0x08e0a5575de71037ae36abfafb516595fe68e5e4', | ||
borrowerCount: 533, | ||
supplierCount: 2235, | ||
totalXvsDistributedTokens: new BigNumber('928041'), | ||
}, | ||
{ | ||
address: '0x2e7222e51c0f6e98610a1543aa3836e092cde62c', | ||
borrowerCount: 261, | ||
supplierCount: 1700, | ||
totalXvsDistributedTokens: new BigNumber('924581'), | ||
}, | ||
{ | ||
address: '0x6d6f697e34145bb95c54e77482d97cc261dc237e', | ||
borrowerCount: 77, | ||
supplierCount: 326, | ||
totalXvsDistributedTokens: new BigNumber('14741'), | ||
}, | ||
{ | ||
address: '0xb6e9322c49fd75a367fcb17b0fcd62c5070ebcbe', | ||
borrowerCount: 51, | ||
supplierCount: 415, | ||
totalXvsDistributedTokens: new BigNumber('269883'), | ||
}, | ||
{ | ||
address: '0x162d005f0fff510e54958cfc5cf32a3180a84aab', | ||
borrowerCount: 51, | ||
supplierCount: 211, | ||
totalXvsDistributedTokens: new BigNumber('39187'), | ||
}, | ||
{ | ||
address: '0xafc13bc065abee838540823431055d2ea52eba52', | ||
borrowerCount: 15, | ||
supplierCount: 150, | ||
totalXvsDistributedTokens: new BigNumber('56938'), | ||
}, | ||
{ | ||
address: '0x488ab2826a154da01cc4cc16a8c83d4720d3ca2c', | ||
borrowerCount: 31, | ||
supplierCount: 188, | ||
totalXvsDistributedTokens: new BigNumber('54890'), | ||
}, | ||
{ | ||
address: '0x37c28de42ba3d22217995d146fc684b2326ede64', | ||
borrowerCount: 19, | ||
supplierCount: 157, | ||
totalXvsDistributedTokens: new BigNumber('15830'), | ||
}, | ||
{ | ||
address: '0xf912d3001caf6dc4add366a62cc9115b4303c9a9', | ||
borrowerCount: 20, | ||
supplierCount: 9, | ||
totalXvsDistributedTokens: new BigNumber('2487'), | ||
}, | ||
{ | ||
address: '0x3619bddc61189f33365cc572df3a68fb3b316516', | ||
borrowerCount: 7, | ||
supplierCount: 152, | ||
totalXvsDistributedTokens: new BigNumber('11'), | ||
}, | ||
{ | ||
address: '0xedac03d29ff74b5fdc0cc936f6288312e1459bc6', | ||
borrowerCount: 9, | ||
supplierCount: 195, | ||
totalXvsDistributedTokens: new BigNumber('4473'), | ||
}, | ||
{ | ||
address: '0x714db6c38a17883964b68a07d56ce331501d9eb6', | ||
borrowerCount: 6, | ||
supplierCount: 144, | ||
totalXvsDistributedTokens: new BigNumber('805'), | ||
}, | ||
{ | ||
address: '0x3a00d9b02781f47d033bad62edc55fbf8d083fb0', | ||
borrowerCount: 5, | ||
supplierCount: 138, | ||
totalXvsDistributedTokens: new BigNumber('3480'), | ||
}, | ||
{ | ||
address: '0x369fea97f6fb7510755dca389088d9e2e2819278', | ||
borrowerCount: 3, | ||
supplierCount: 133, | ||
totalXvsDistributedTokens: new BigNumber('4020'), | ||
}, | ||
{ | ||
address: '0xf206af85bc2761c4f876d27bd474681cfb335efa', | ||
borrowerCount: 2, | ||
supplierCount: 5, | ||
totalXvsDistributedTokens: new BigNumber('601'), | ||
}, | ||
{ | ||
address: '0x9c3015191d39cf1930f92eb7e7bcbd020bca286a', | ||
borrowerCount: 0, | ||
supplierCount: 3, | ||
totalXvsDistributedTokens: new BigNumber('473'), | ||
}, | ||
]; | ||
export const markets: Market[] = apiMarketsResponse.result.map(apiMarket => | ||
formatToMarket({ apiMarket }), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import type { ChainId, Market } from 'types'; | ||
import { formatToMarket, restService } from 'utilities'; | ||
|
||
export interface ApiMarketData { | ||
address: string; | ||
symbol: string; | ||
name: string; | ||
underlyingAddress: string | null; | ||
underlyingName: string; | ||
underlyingSymbol: string; | ||
underlyingDecimal: number; | ||
borrowerDailyXvsMantissa: string | null; | ||
supplierDailyXvsMantissa: string | null; | ||
xvsBorrowIndex: string | null; | ||
xvsSupplyIndex: string | null; | ||
borrowRatePerBlock: string; | ||
supplyRatePerBlock: string; | ||
exchangeRateMantissa: string; | ||
underlyingPriceMantissa: string; | ||
totalBorrowsMantissa: string; | ||
totalSupplyMantissa: string; | ||
cashMantissa: string; | ||
totalReservesMantissa: string; | ||
reserveFactorMantissa: string; | ||
collateralFactorMantissa: string; | ||
borrowApy: string; | ||
supplyApy: string; | ||
borrowXvsApr: string | null; | ||
supplyXvsApr: string | null; | ||
liquidityCents: string; | ||
tokenPriceCents: string; | ||
totalDistributedMantissa: string | null; | ||
lastCalculatedXvsAccruedBlockNumber: string | null; | ||
supplyCapsMantissa: string; | ||
borrowCapsMantissa: string; | ||
borrowerCount: number; | ||
supplierCount: number; | ||
estimatedPrimeBorrowApyBoost: string | null; | ||
estimatedPrimeSupplyApyBoost: string | null; | ||
pausedActionsBitmap: number; | ||
isListed: boolean; | ||
poolComptrollerAddress: string; | ||
rewardsDistributors: { | ||
marketAddress: string; | ||
rewardTokenAddress: string; | ||
lastRewardingSupplyBlockOrTimestamp: string; | ||
lastRewardingBorrowBlockOrTimestamp: string; | ||
supplySpeed: string; | ||
borrowSpeed: string; | ||
priceMantissa: string; | ||
rewardsDistributorContractAddress: string | null; | ||
}[]; | ||
} | ||
|
||
export interface GetApiMarketsResponse { | ||
result: ApiMarketData[]; | ||
request: { addresses: string[] }; | ||
} | ||
|
||
export interface GetApiMarketsInput { | ||
chainId: ChainId; | ||
poolComptrollerAddress?: string; | ||
} | ||
|
||
export interface GetApiMarketsOutput { | ||
markets: Market[]; | ||
} | ||
|
||
const getApiMarkets = async ({ | ||
chainId, | ||
poolComptrollerAddress, | ||
}: GetApiMarketsInput): Promise<GetApiMarketsOutput> => { | ||
const response = await restService<GetApiMarketsResponse>({ | ||
endpoint: '/markets', | ||
method: 'GET', | ||
params: { | ||
limit: 50, | ||
isListed: 1, | ||
chainId, | ||
poolComptrollerAddress, | ||
}, | ||
}); | ||
|
||
const payload = response.data; | ||
|
||
if (payload && 'error' in payload) { | ||
throw new Error(payload.error); | ||
} | ||
|
||
const markets: Market[] = (payload?.result || []).map(apiMarket => formatToMarket({ apiMarket })); | ||
|
||
return { markets }; | ||
}; | ||
|
||
export default getApiMarkets; |
37 changes: 37 additions & 0 deletions
37
apps/evm/src/clients/api/queries/getApiMarkets/useGetApiMarkets.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { type QueryObserverOptions, useQuery } from '@tanstack/react-query'; | ||
|
||
import getApiMarkets, { | ||
type GetApiMarketsInput, | ||
type GetApiMarketsOutput, | ||
} from 'clients/api/queries/getApiMarkets'; | ||
import FunctionKey from 'constants/functionKey'; | ||
import { useGetToken } from 'libs/tokens'; | ||
import { useChainId } from 'libs/wallet'; | ||
import { callOrThrow } from 'utilities'; | ||
|
||
type TrimmedGetMarketsInput = Omit<GetApiMarketsInput, 'xvs'>; | ||
|
||
export type UseGetMarketsQueryKey = [FunctionKey.GET_MARKETS, TrimmedGetMarketsInput]; | ||
|
||
type Options = QueryObserverOptions< | ||
GetApiMarketsOutput, | ||
Error, | ||
GetApiMarketsOutput, | ||
GetApiMarketsOutput, | ||
UseGetMarketsQueryKey | ||
>; | ||
|
||
const useGetApiMarkets = (options?: Options) => { | ||
const { chainId } = useChainId(); | ||
const xvs = useGetToken({ | ||
symbol: 'XVS', | ||
}); | ||
|
||
return useQuery({ | ||
queryKey: [FunctionKey.GET_MARKETS, { chainId }], | ||
queryFn: () => callOrThrow({ xvs }, params => getApiMarkets({ ...params, chainId })), | ||
...options, | ||
}); | ||
}; | ||
|
||
export default useGetApiMarkets; |
Oops, something went wrong.