-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
45 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
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,10 @@ | ||
import { useFusePoolsData } from "hooks/useFusePoolData"; | ||
import { useFusePools, UseFusePoolsReturn } from "./useFusePools"; | ||
|
||
const useAllFusePools = () => { | ||
const { pools } = useFusePools(null); | ||
const fusePoolsData = useFusePoolsData(pools?.map(({ id }) => id) ?? []); | ||
return fusePoolsData; | ||
}; | ||
|
||
export default useAllFusePools; |
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,8 +1,98 @@ | ||
import { useState } from "react"; | ||
import { pools } from "constants/pools"; | ||
import { useMemo } from "react"; | ||
import { convertMantissaToAPY } from "utils/apyUtils"; | ||
import { USDPricedFuseAssetWithTokenData } from "utils/fetchFusePoolData"; | ||
import useAllFusePools from "./useAllFusePools"; | ||
|
||
const useFuseDataForAsset = () => { | ||
const [state, setstate] = useState(true); | ||
return true; | ||
interface AssetInFuse { | ||
totalBorrowedUSD: number; | ||
totalSuppliedUSD: number; | ||
highestSupplyAPY: number; | ||
} | ||
|
||
export const useFuseDataForAsset = (assetSymbol: String): AssetInFuse => { | ||
const allPools = useAllFusePools(); | ||
|
||
const poolsWithThisAsset = useMemo( | ||
() => | ||
allPools?.filter((pool) => | ||
pool.assets.find((asset) => { | ||
const _asset = asset as USDPricedFuseAssetWithTokenData; | ||
return _asset?.tokenData?.symbol === assetSymbol; | ||
}) | ||
), | ||
[assetSymbol, allPools] | ||
); | ||
|
||
const stuff = useMemo(() => { | ||
let totalBorrowedUSD = 0; | ||
let totalSuppliedUSD = 0; | ||
let highestSupplyAPY = 0; | ||
|
||
poolsWithThisAsset?.forEach((pool) => { | ||
// Get the specific asset from the pool | ||
const asset = pool?.assets?.find((_ass) => { | ||
const ass = _ass as USDPricedFuseAssetWithTokenData; | ||
return ass?.tokenData?.symbol === assetSymbol; | ||
}); | ||
|
||
totalBorrowedUSD += asset?.totalBorrowUSD ?? 0; | ||
totalSuppliedUSD += asset?.totalSupplyUSD ?? 0; | ||
|
||
const supplyAPY = convertMantissaToAPY(asset?.supplyRatePerBlock, 365); | ||
if (supplyAPY > highestSupplyAPY) highestSupplyAPY = supplyAPY; | ||
}); | ||
|
||
return { totalBorrowedUSD, totalSuppliedUSD, highestSupplyAPY }; | ||
}, [assetSymbol, poolsWithThisAsset]); | ||
|
||
return stuff; | ||
}; | ||
|
||
export default useFuseDataForAsset; | ||
export const useFuseDataForAssets = (assetSymbols: String[]) => { | ||
const allPools = useAllFusePools(); | ||
|
||
const poolsWithThisAsset = useMemo( | ||
() => | ||
allPools?.filter((pool) => | ||
pool.assets.find((_asset) => { | ||
const asset = _asset as USDPricedFuseAssetWithTokenData; | ||
return asset?.tokenData?.symbol | ||
? assetSymbols.includes(asset.tokenData.symbol) | ||
: false; | ||
}) | ||
), | ||
[assetSymbols, allPools] | ||
); | ||
|
||
const stuff: AssetInFuse[] = useMemo( | ||
() => | ||
assetSymbols.map((assetSymbol) => { | ||
let totalBorrowedUSD = 0; | ||
let totalSuppliedUSD = 0; | ||
let highestSupplyAPY = 0; | ||
|
||
poolsWithThisAsset?.forEach((pool) => { | ||
// Find the specific asset from the pool | ||
const asset = pool?.assets?.find((_ass) => { | ||
const ass = _ass as USDPricedFuseAssetWithTokenData; | ||
return ass?.tokenData?.symbol === assetSymbol; | ||
}); | ||
|
||
totalBorrowedUSD += asset?.totalBorrowUSD ?? 0; | ||
totalSuppliedUSD += asset?.totalSupplyUSD ?? 0; | ||
|
||
const supplyAPY = convertMantissaToAPY( | ||
asset?.supplyRatePerBlock, | ||
365 | ||
); | ||
if (supplyAPY > highestSupplyAPY) highestSupplyAPY = supplyAPY; | ||
}); | ||
|
||
return { totalBorrowedUSD, totalSuppliedUSD, highestSupplyAPY }; | ||
}), | ||
[assetSymbols, poolsWithThisAsset] | ||
); | ||
|
||
return stuff; | ||
}; |
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
8687bf7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bundled size for the package is listed below:
build/static/media: 679.69 KB
build/static/js: 29.25 MB
build/static/css: 27.34 KB
build/static: 29.94 MB
build: 30.02 MB