Skip to content

Commit

Permalink
handle arb case (#329)
Browse files Browse the repository at this point in the history
* handle arb case

* comment
  • Loading branch information
jmzwar authored Jun 24, 2024
1 parent fac755f commit b8699d3
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions liquidity/lib/useApr/useApr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,33 @@ export function useApr(customNetwork?: Network) {
const supportedAprNetworks = [8453, 84532, 42161];

export async function fetchApr(networkId?: number) {
const response = await fetch(getAprUrl(networkId));
try {
const isSupported = networkId && supportedAprNetworks.includes(networkId);
const response = await fetch(getAprUrl(networkId));

const data = await response.json();
const data = await response.json();

return {
// 0 meaning not the right network
combinedApr:
networkId && supportedAprNetworks.includes(networkId)
// Arbitrum has multiple collateral types
const highestAprCollateral =
networkId === 8453
? data
: data?.sort((a: { apr28d: number }, b: { apr28d: number }) => b.apr28d - a.apr28d)[0];

return {
combinedApr: isSupported
? networkId === 42161
? data.apr24h * 100
: data.apr28d * 100
? highestAprCollateral.apr24h * 100
: highestAprCollateral.apr28d * 100
: 0,
cumulativePnl: networkId && supportedAprNetworks.includes(networkId) ? data.cumulativePnl : 0,
};
cumulativePnl: isSupported ? highestAprCollateral.cumulativePnl : 0,
collateralAprs: networkId === 8453 ? [data] : data,
};
} catch (error) {
console.error(error);
return {
combinedApr: 0,
cumulativePnl: 0,
collateralAprs: [],
};
}
}

0 comments on commit b8699d3

Please sign in to comment.