-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Morpho Rewards endpoint (#1544)
* rates working, need to adjust scaling factor * dynamic morpho rate working * change to morpho rate * set mainnet pool id * cleaned up * use correct market name * relative path * cleanup hook * remove position type * remove position type * update pool row * updates per comments
- Loading branch information
1 parent
eca55d0
commit 90c02f8
Showing
4 changed files
with
72 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { fixed, FixedPoint } from "@delvtech/fixed-point-wasm"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Address } from "viem"; | ||
|
||
const marketPoolIds: Record<Address, string> = { | ||
// Key: Hyperdrive contract address for the market | ||
// Value: Corresponding Morpho pool ID | ||
// Market:Base 182d Morpho cbETH/USDC | ||
"0x2a1ca35Ded36C531F77c614b5AAA0d4F86edbB06": | ||
"0xdba352d93a64b17c71104cbddc6aef85cd432322a1446b5b65163cbbc615cd0c", | ||
}; | ||
|
||
export function useMorphoRate({ | ||
chainId, | ||
hyperdriveAddress, | ||
}: { | ||
chainId: number; | ||
hyperdriveAddress: Address; | ||
}): { | ||
morphoRate: FixedPoint | undefined; | ||
} { | ||
const { data: rewardsData } = useQuery< | ||
{ | ||
current_rates: { | ||
per_dollar_per_year: string; | ||
pool_ids: string[]; | ||
}[]; | ||
}, | ||
Error | ||
>({ | ||
queryKey: ["morphoRate", chainId, hyperdriveAddress], | ||
staleTime: Infinity, | ||
retry: 3, | ||
queryFn: async () => { | ||
const response = await fetch( | ||
`https://rewards.morpho.org/v1/programs/?chains=${chainId}&active=true&type=uniform-reward`, | ||
); | ||
const result = await response.json(); | ||
return result.data[0]; | ||
}, | ||
}); | ||
|
||
let morphoRate: FixedPoint | undefined = undefined; | ||
|
||
if (rewardsData) { | ||
const poolId = marketPoolIds[hyperdriveAddress]; | ||
let matchingRate = rewardsData.current_rates.find((rate) => | ||
rate.pool_ids.some((id) => id.toLowerCase().startsWith(poolId)), | ||
)?.per_dollar_per_year; | ||
|
||
// If there is no matching rate, just use the first one in the current_rates array | ||
if (!matchingRate) { | ||
matchingRate = rewardsData.current_rates[0].per_dollar_per_year; | ||
} | ||
|
||
// The morpho rate is formatted to 15 decimal places | ||
morphoRate = fixed(matchingRate ?? 0, 15); | ||
} | ||
|
||
return { | ||
morphoRate, | ||
}; | ||
} |
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