-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implement ZkSync Ignite incentives program (#2305)
Co-authored-by: Nandy Bâ <[email protected]>
- Loading branch information
Showing
22 changed files
with
419 additions
and
133 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
105 changes: 105 additions & 0 deletions
105
src/components/incentives/ZkSyncIgniteIncentivesTooltipContent.tsx
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,105 @@ | ||
import { Trans } from '@lingui/macro'; | ||
import { Box, Typography } from '@mui/material'; | ||
import { ExtendedReserveIncentiveResponse } from 'src/hooks/useMeritIncentives'; | ||
|
||
import { FormattedNumber } from '../primitives/FormattedNumber'; | ||
import { Link } from '../primitives/Link'; | ||
import { Row } from '../primitives/Row'; | ||
import { TokenIcon } from '../primitives/TokenIcon'; | ||
import { getSymbolMap } from './IncentivesTooltipContent'; | ||
|
||
export const ZkSyncIgniteIncentivesTooltipContent = ({ | ||
zkSyncIgniteIncentives, | ||
}: { | ||
zkSyncIgniteIncentives: ExtendedReserveIncentiveResponse; | ||
}) => { | ||
const typographyVariant = 'secondary12'; | ||
|
||
const zkSyncIgniteIncentivesFormatted = getSymbolMap(zkSyncIgniteIncentives); | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'start', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<img src={`/icons/other/zksync-ignite.svg`} width="100px" height="40px" alt="" /> | ||
|
||
<Typography variant="caption" color="text.primary" mb={3}> | ||
<Trans>Eligible for the ZKSync Ignite program.</Trans> | ||
</Typography> | ||
|
||
<Typography variant="caption" color="text.secondary" mb={3}> | ||
<Trans> | ||
This is a program initiated and implemented by the decentralised ZKSync community. Aave | ||
Labs does not guarantee the program and accepts no liability. | ||
</Trans>{' '} | ||
<Link | ||
href={'https://zksyncignite.xyz/'} | ||
sx={{ textDecoration: 'underline' }} | ||
variant="caption" | ||
color="text.secondary" | ||
> | ||
Learn more | ||
</Link> | ||
</Typography> | ||
|
||
<Typography variant="caption" color="text.secondary" mb={3}> | ||
<Trans>ZKSync Ignite Program rewards are claimed through the</Trans>{' '} | ||
<Link | ||
href="https://app.zksyncignite.xyz/users/" | ||
sx={{ textDecoration: 'underline' }} | ||
variant="caption" | ||
color="text.secondary" | ||
> | ||
official app | ||
</Link> | ||
{'.'} | ||
</Typography> | ||
{zkSyncIgniteIncentives.customMessage ? ( | ||
<Typography variant="caption" color="text.strong" mb={3}> | ||
<Trans>{zkSyncIgniteIncentives.customMessage}</Trans> | ||
</Typography> | ||
) : null} | ||
|
||
<Box sx={{ width: '100%' }}> | ||
<Row | ||
height={32} | ||
caption={ | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
mb: 0, | ||
}} | ||
> | ||
<TokenIcon | ||
aToken={zkSyncIgniteIncentivesFormatted.aToken} | ||
symbol={zkSyncIgniteIncentivesFormatted.tokenIconSymbol} | ||
sx={{ fontSize: '20px', mr: 1 }} | ||
/> | ||
<Typography variant={typographyVariant}> | ||
{zkSyncIgniteIncentivesFormatted.symbol} | ||
</Typography> | ||
</Box> | ||
} | ||
width="100%" | ||
> | ||
<Box sx={{ display: 'inline-flex', alignItems: 'center' }}> | ||
<FormattedNumber | ||
value={+zkSyncIgniteIncentivesFormatted.incentiveAPR} | ||
percent | ||
variant={typographyVariant} | ||
/> | ||
<Typography variant={typographyVariant} sx={{ ml: 1 }}> | ||
<Trans>APR</Trans> | ||
</Typography> | ||
</Box> | ||
</Row> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
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,120 @@ | ||
import { ProtocolAction } from '@aave/contract-helpers'; | ||
import { ReserveIncentiveResponse } from '@aave/math-utils/dist/esm/formatters/incentive/calculate-reserve-incentives'; | ||
import { AaveV3ZkSync } from '@bgd-labs/aave-address-book'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { CustomMarket } from 'src/ui-config/marketsConfig'; | ||
import { Address } from 'viem'; | ||
|
||
enum OpportunityAction { | ||
LEND = 'LEND', | ||
BORROW = 'BORROW', | ||
} | ||
|
||
enum OpportunityStatus { | ||
LIVE = 'LIVE', | ||
PAST = 'PAST', | ||
UPCOMING = 'UPCOMING', | ||
} | ||
|
||
type MerklOpportunity = { | ||
chainId: number; | ||
type: string; | ||
identifier: Address; | ||
name: string; | ||
status: OpportunityStatus; | ||
action: OpportunityAction; | ||
tvl: number; | ||
apr: number; | ||
dailyRewards: number; | ||
tags: []; | ||
id: string; | ||
tokens: [ | ||
{ | ||
id: string; | ||
name: string; | ||
chainId: number; | ||
address: Address; | ||
decimals: number; | ||
icon: string; | ||
verified: boolean; | ||
isTest: boolean; | ||
price: number; | ||
symbol: string; | ||
} | ||
]; | ||
}; | ||
|
||
export type ExtendedReserveIncentiveResponse = ReserveIncentiveResponse & { | ||
customMessage: string; | ||
customForumLink: string; | ||
}; | ||
|
||
const url = 'https://api.merkl.xyz/v4/opportunities?tags=zksync&mainProtocolId=aave'; // Merkl API for ZK Ignite opportunities | ||
|
||
const rewardToken = AaveV3ZkSync.ASSETS.ZK.UNDERLYING; | ||
const rewardTokenSymbol = 'ZK'; | ||
|
||
const checkOpportunityAction = ( | ||
opportunityAction: OpportunityAction, | ||
protocolAction: ProtocolAction | ||
) => { | ||
switch (opportunityAction) { | ||
case OpportunityAction.LEND: | ||
return protocolAction === ProtocolAction.supply; | ||
case OpportunityAction.BORROW: | ||
return protocolAction === ProtocolAction.borrow; | ||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
export const useZkSyncIgniteIncentives = ({ | ||
market, | ||
rewardedAsset, | ||
protocolAction, | ||
}: { | ||
market: string; | ||
rewardedAsset?: string; | ||
protocolAction?: ProtocolAction; | ||
}) => { | ||
return useQuery({ | ||
queryFn: async () => { | ||
if (market === CustomMarket.proto_zksync_v3) { | ||
const response = await fetch(url); | ||
const merklOpportunities: MerklOpportunity[] = await response.json(); | ||
return merklOpportunities; | ||
} else { | ||
return []; | ||
} | ||
}, | ||
queryKey: ['zkIgniteIncentives', market], | ||
staleTime: 1000 * 60 * 5, | ||
select: (merklOpportunities) => { | ||
const opportunities = merklOpportunities.filter( | ||
(opportunitiy) => | ||
rewardedAsset && | ||
opportunitiy.identifier.toLowerCase() === rewardedAsset.toLowerCase() && | ||
protocolAction && | ||
checkOpportunityAction(opportunitiy.action, protocolAction) | ||
); | ||
|
||
if (opportunities.length === 0) { | ||
return null; | ||
} | ||
|
||
const opportunity = opportunities[0]; | ||
|
||
if (opportunity.status !== OpportunityStatus.LIVE) { | ||
return null; | ||
} | ||
|
||
const apr = opportunity.apr / 100; | ||
|
||
return { | ||
incentiveAPR: apr.toString(), | ||
rewardTokenAddress: rewardToken, | ||
rewardTokenSymbol: rewardTokenSymbol, | ||
} as ExtendedReserveIncentiveResponse; | ||
}, | ||
}); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
5147f80
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