This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch TVL across all networks using subgraphs
- Loading branch information
1 parent
9317a18
commit a3e365c
Showing
14 changed files
with
241 additions
and
115 deletions.
There are no files selected for viewing
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,4 @@ | ||
VITE_SUBGRAPH_MARKETS_URL_ETHEREUM= | ||
VITE_SUBGRAPH_MARKETS_URL_ARBITRUM_ONE= | ||
VITE_SUBGRAPH_MARKETS_URL_BSC_MAINNET= | ||
VITE_SUBGRAPH_MARKETS_URL_OPBNB_MAINNET= |
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,46 +1,49 @@ | ||
# Getting Started with Create React App | ||
# Venus Protocol Landing Page | ||
|
||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
<p align="center"> | ||
<img src="https://venus.io/share.png"> | ||
</p> | ||
|
||
## Available Scripts | ||
Official repository for the [Venus protocol](https://venus.io) landing page. | ||
|
||
In the project directory, you can run: | ||
## Getting started | ||
|
||
### `yarn start` | ||
Install dependencies with yarn | ||
|
||
Runs the app in the development mode.\ | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
```ssh | ||
yarn | ||
``` | ||
|
||
The page will reload if you make edits.\ | ||
You will also see any lint errors in the console. | ||
Define environment variables by making a copy of `.env.example` and renaming it to `.env` (make sure to add values for each environment variable). | ||
|
||
### `yarn test` | ||
Start the development server | ||
|
||
Launches the test runner in the interactive watch mode.\ | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
```ssh | ||
yarn start | ||
``` | ||
|
||
### `yarn build` | ||
## Useful commands | ||
|
||
Builds the app for production to the `build` folder.\ | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
Check Typescript code | ||
|
||
The build is minified and the filenames include the hashes.\ | ||
Your app is ready to be deployed! | ||
```ssh | ||
yarn tsc | ||
``` | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
Lint code | ||
|
||
### `yarn eject` | ||
```ssh | ||
yarn lint | ||
``` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
Generate production build | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
```ssh | ||
yarn build | ||
``` | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
Start application with production build | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). | ||
```ssh | ||
yarn preview | ||
``` |
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 |
---|---|---|
@@ -1,32 +1,8 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { fetchProposalCount } from '../index'; | ||
|
||
export const useProposalsCountFromApi = () => { | ||
const [data, setData] = useState<number>(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState<Error | undefined>(); | ||
|
||
const fetchData = () => { | ||
fetchProposalCount() | ||
.then(res => { | ||
setData(res); | ||
setIsLoading(false); | ||
}) | ||
.catch(e => { | ||
setError(e); | ||
setIsLoading(false); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
fetchData(); | ||
}, []); | ||
|
||
return { | ||
data, | ||
isLoading, | ||
error, | ||
fetchData, | ||
}; | ||
}; | ||
export const useProposalsCountFromApi = () => | ||
useQuery({ | ||
queryKey: ['proposalCount'], | ||
queryFn: fetchProposalCount, | ||
}); |
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,42 +1,86 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { MarketMapped } from '../types'; | ||
import { getMarketsToRender, getTotal } from '../utils'; | ||
import fetchMarkets from '../index'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { convertCentsToUsd, getMarketsToRender, scale } from '../utils'; | ||
import getLegacyPoolMarkets from '../index'; | ||
import { getIsolatedMarkets } from '../../subgraph/queries/getIsolatedMarkets'; | ||
import { MainChainId } from '../../subgraph/types'; | ||
|
||
const chainIds = Object.values(MainChainId).filter( | ||
(chainId): chainId is MainChainId => !Number.isNaN(Number(chainId)), | ||
); | ||
|
||
export const useVenusApi = () => { | ||
const [data, setData] = useState<MarketMapped[]>(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState<Error | undefined>(); | ||
|
||
const fetchData = () => { | ||
fetchMarkets() | ||
.then(res => { | ||
setData(res); | ||
setIsLoading(false); | ||
}) | ||
.catch(e => { | ||
setError(e); | ||
setIsLoading(false); | ||
}); | ||
}; | ||
const { | ||
data: getLegacyPoolMarketsData, | ||
isLoading: isGetLegacyPoolMarketsLoading, | ||
error: getLegacyPoolMarketsError, | ||
refetch, | ||
} = useQuery({ | ||
queryKey: ['legacyPoolMarkets'], | ||
queryFn: getLegacyPoolMarkets, | ||
}); | ||
|
||
const { | ||
data: getIsolatedPoolMarketsData, | ||
isLoading: isGetIsolatedPoolMarketsLoading, | ||
error: getIsolatedPoolMarketsError, | ||
} = useQuery({ | ||
queryKey: ['isolatedPoolMarkets'], | ||
queryFn: async () => { | ||
const results = await Promise.all(chainIds.map(chainId => getIsolatedMarkets({ chainId }))); | ||
return results.map(result => result.markets).flat(); | ||
}, | ||
}); | ||
|
||
const topMarkets = getMarketsToRender(getLegacyPoolMarketsData); | ||
|
||
const marketCount = | ||
(getLegacyPoolMarketsData?.length || 0) + (getIsolatedPoolMarketsData?.length || 0); | ||
|
||
const legacyPool = (getLegacyPoolMarketsData ?? []).reduce( | ||
(acc, data) => ({ | ||
marketSize: acc.marketSize + data.totalSupplyUsd, | ||
borrowedSum: acc.borrowedSum + data.totalBorrowsUsd, | ||
liquiditySum: acc.liquiditySum + data.liquidity, | ||
}), | ||
{ | ||
marketSize: 0, | ||
borrowedSum: 0, | ||
liquiditySum: 0, | ||
}, | ||
); | ||
|
||
const isolatedPools = (getIsolatedPoolMarketsData ?? []).reduce( | ||
(acc, data) => { | ||
const underlyingTokenPriceUsd = convertCentsToUsd(data.underlyingPriceCents); | ||
|
||
const totalSupplyTokens = scale(data.totalSupplyMantissa, data.underlyingDecimals); | ||
const totalSupplyUsd = totalSupplyTokens * underlyingTokenPriceUsd; | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
fetchData(); | ||
}, []); | ||
const totalBorrowsTokens = scale(data.totalBorrowsMantissa, data.underlyingDecimals); | ||
const totalBorrowsUsd = totalBorrowsTokens * underlyingTokenPriceUsd; | ||
|
||
const markets = getMarketsToRender(data); | ||
const marketSize = getTotal('totalSupplyUsd', data); | ||
const borrowedSum = getTotal('totalBorrowsUsd', data); | ||
const liquiditySum = getTotal('liquidity', data); | ||
return { | ||
marketSize: acc.marketSize + totalSupplyUsd, | ||
borrowedSum: acc.borrowedSum + totalBorrowsUsd, | ||
liquiditySum: acc.liquiditySum + (totalSupplyUsd - totalBorrowsUsd), | ||
}; | ||
}, | ||
{ | ||
marketSize: 0, | ||
borrowedSum: 0, | ||
liquiditySum: 0, | ||
}, | ||
); | ||
|
||
return { | ||
marketSize, | ||
borrowedSum, | ||
liquiditySum, | ||
markets, | ||
isLoading, | ||
error, | ||
fetchData, | ||
marketSize: legacyPool.marketSize + isolatedPools.marketSize, | ||
borrowedSum: legacyPool.borrowedSum + isolatedPools.borrowedSum, | ||
liquiditySum: legacyPool.liquiditySum + isolatedPools.liquiditySum, | ||
topMarkets, | ||
marketCount, | ||
chainCount: chainIds.length, | ||
isLoading: isGetLegacyPoolMarketsLoading || isGetIsolatedPoolMarketsLoading, | ||
error: getLegacyPoolMarketsError || getIsolatedPoolMarketsError, | ||
refetch, | ||
}; | ||
}; |
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
Oops, something went wrong.