-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implement new cbBTC/USDC Merit Action aprs (#2222)
- Loading branch information
Showing
18 changed files
with
273 additions
and
158 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
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,47 +1,87 @@ | ||
import { ProtocolAction } from '@aave/contract-helpers'; | ||
import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives'; | ||
import { AaveV3Ethereum } from '@bgd-labs/aave-address-book'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useRootStore } from 'src/store/root'; | ||
import { CustomMarket } from 'src/ui-config/marketsConfig'; | ||
|
||
export enum MeritAction { | ||
ETHEREUM_STKGHO = 'ethereum-stkgho', | ||
SUPPLY_CBBTC_BORROW_USDC = 'ethereum-supply-cbbtc-borrow-usdc', | ||
} | ||
|
||
type MeritIncentives = { | ||
totalAPR: number; | ||
actionsAPR: { | ||
stkgho: number; | ||
gho: number; | ||
[key in MeritAction]: number; | ||
}; | ||
}; | ||
|
||
const url = 'https://apps.aavechan.com/api/merit/aprs'; | ||
|
||
export const useMeritIncentives = (asset: 'gho' | 'stkgho') => { | ||
export type MeritReserveIncentiveData = Omit<ReserveIncentiveResponse, 'incentiveAPR'> & { | ||
action: MeritAction; | ||
protocolAction?: ProtocolAction; | ||
}; | ||
|
||
const getMeritData = (market: string, symbol: string): MeritReserveIncentiveData | undefined => | ||
MERIT_DATA_MAP[market]?.[symbol]; | ||
|
||
const MERIT_DATA_MAP: Record<string, Record<string, MeritReserveIncentiveData>> = { | ||
[CustomMarket.proto_mainnet_v3]: { | ||
GHO: { | ||
action: MeritAction.ETHEREUM_STKGHO, | ||
rewardTokenAddress: AaveV3Ethereum.ASSETS.GHO.UNDERLYING, | ||
rewardTokenSymbol: 'GHO', | ||
}, | ||
cbBTC: { | ||
action: MeritAction.SUPPLY_CBBTC_BORROW_USDC, | ||
rewardTokenAddress: AaveV3Ethereum.ASSETS.USDC.A_TOKEN, | ||
rewardTokenSymbol: 'aEthUSDC', | ||
protocolAction: ProtocolAction.supply, | ||
}, | ||
USDC: { | ||
action: MeritAction.SUPPLY_CBBTC_BORROW_USDC, | ||
rewardTokenAddress: AaveV3Ethereum.ASSETS.USDC.A_TOKEN, | ||
rewardTokenSymbol: 'aEthUSDC', | ||
protocolAction: ProtocolAction.borrow, | ||
}, | ||
}, | ||
}; | ||
|
||
export const useMeritIncentives = ({ | ||
symbol, | ||
market, | ||
protocolAction, | ||
}: { | ||
symbol: string; | ||
market: string; | ||
protocolAction?: ProtocolAction; | ||
}) => { | ||
return useQuery({ | ||
queryFn: async () => { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
return data.currentAPR as MeritIncentives; | ||
const meritIncentives = data.currentAPR as MeritIncentives; | ||
|
||
return meritIncentives; | ||
}, | ||
queryKey: ['meritIncentives'], | ||
staleTime: 1000 * 60 * 5, | ||
select: (data) => { | ||
// rewards are always in GHO, for now | ||
const meritReserveIncentiveData = getMeritData(market, symbol); | ||
if (!meritReserveIncentiveData) { | ||
return null; | ||
} | ||
if (meritReserveIncentiveData.protocolAction !== protocolAction) { | ||
return null; | ||
} | ||
|
||
const APR = data.actionsAPR[meritReserveIncentiveData.action]; | ||
return { | ||
incentiveAPR: (data.actionsAPR[asset] / 100).toString(), | ||
rewardTokenAddress: AaveV3Ethereum.ASSETS.GHO.UNDERLYING, | ||
rewardTokenSymbol: 'GHO', | ||
incentiveAPR: (APR / 100).toString(), | ||
rewardTokenAddress: meritReserveIncentiveData.rewardTokenAddress, | ||
rewardTokenSymbol: meritReserveIncentiveData.rewardTokenSymbol, | ||
} as ReserveIncentiveResponse; | ||
}, | ||
}); | ||
}; | ||
|
||
export const useUserMeritIncentives = () => { | ||
const user = useRootStore((store) => store.account); | ||
return useQuery({ | ||
queryFn: async () => { | ||
const response = await fetch(`${url}?user=${user}`); | ||
const data = await response.json(); | ||
return data.currentAPR as MeritIncentives; | ||
}, | ||
queryKey: ['meritIncentives', user], | ||
staleTime: 1000 * 60 * 5, | ||
}); | ||
}; |
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.
9404b69
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.
This commit was deployed on ipfs
9404b69
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.
This commit was deployed on ipfs
9404b69
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.
This commit was deployed on ipfs