Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separated glv token incentives from market token incentives, fixed Buy page max APY displaying #1291

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/Synthetics/GmList/GmList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Props = {
glvTokensApyData: MarketTokensAPRData | undefined;
marketsTokensApyData: MarketTokensAPRData | undefined;
marketsTokensIncentiveAprData: MarketTokensAPRData | undefined;
glvTokensIncentiveAprData: MarketTokensAPRData | undefined;
marketsTokensLidoAprData: MarketTokensAPRData | undefined;
shouldScrollToTop?: boolean;
isDeposit: boolean;
Expand All @@ -76,6 +77,7 @@ export function GmList({
marketsTokensApyData,
glvTokensApyData,
marketsTokensIncentiveAprData,
glvTokensIncentiveAprData,
marketsTokensLidoAprData,
shouldScrollToTop,
isDeposit,
Expand Down Expand Up @@ -207,6 +209,7 @@ export function GmList({
token={token}
marketTokensData={marketTokensData}
marketsTokensApyData={marketsTokensApyData}
glvTokensIncentiveAprData={glvTokensIncentiveAprData}
marketsTokensIncentiveAprData={marketsTokensIncentiveAprData}
marketsTokensLidoAprData={marketsTokensLidoAprData}
glvTokensApyData={glvTokensApyData}
Expand Down Expand Up @@ -358,6 +361,7 @@ function GmListItem({
token,
marketsTokensApyData,
marketsTokensIncentiveAprData,
glvTokensIncentiveAprData,
marketsTokensLidoAprData,
glvTokensApyData,
shouldScrollToTop,
Expand All @@ -369,6 +373,7 @@ function GmListItem({
token: TokenData;
marketsTokensApyData: MarketTokensAPRData | undefined;
marketsTokensIncentiveAprData: MarketTokensAPRData | undefined;
glvTokensIncentiveAprData: MarketTokensAPRData | undefined;
marketsTokensLidoAprData: MarketTokensAPRData | undefined;
glvTokensApyData: MarketTokensAPRData | undefined;
shouldScrollToTop: boolean | undefined;
Expand Down Expand Up @@ -447,7 +452,9 @@ function GmListItem({
const apy = isGlv
? getByKey(glvTokensApyData, marketOrGlvTokenAddress)
: getByKey(marketsTokensApyData, token?.address);
const incentiveApr = getByKey(marketsTokensIncentiveAprData, token?.address);
const incentiveApr = isGlv
? getByKey(glvTokensIncentiveAprData, token?.address)
: getByKey(marketsTokensIncentiveAprData, token?.address);
const lidoApr = getByKey(marketsTokensLidoAprData, token?.address);
const marketEarnings = getByKey(userEarnings?.byMarketAddress, token?.address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Props = {
marketInfo?: GlvOrMarketInfo;
marketToken?: TokenData;
marketsTokensApyData: MarketTokensAPRData | undefined;
glvTokensIncentiveAprData: MarketTokensAPRData | undefined;
marketsTokensIncentiveAprData: MarketTokensAPRData | undefined;
marketsTokensLidoAprData: MarketTokensAPRData | undefined;
glvTokensApyData: MarketTokensAPRData | undefined;
Expand All @@ -60,6 +61,7 @@ export function MarketStatsWithComposition(p: Props) {
marketsInfoData,
marketTokensData,
marketsTokensIncentiveAprData,
glvTokensIncentiveAprData,
marketsTokensLidoAprData,
glvTokensApyData,
} = p;
Expand Down Expand Up @@ -92,7 +94,10 @@ export function MarketStatsWithComposition(p: Props) {
);

const apy = getByKey(marketsTokensApyData, marketInfo && getGlvOrMarketAddress(marketInfo));
const incentiveApr = getByKey(marketsTokensIncentiveAprData, marketInfo && getGlvOrMarketAddress(marketInfo));
const glvOrMarketAddress = marketInfo && getGlvOrMarketAddress(marketInfo);
const incentiveApr = isGlv
? getByKey(glvTokensIncentiveAprData, glvOrMarketAddress)
: getByKey(marketsTokensIncentiveAprData, glvOrMarketAddress);
const lidoApr = getByKey(marketsTokensLidoAprData, marketInfo && getGlvOrMarketAddress(marketInfo));

const indexName = marketInfo && getMarketIndexName(marketInfo);
Expand Down
18 changes: 12 additions & 6 deletions src/components/TokenCard/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ export default function TokenCard({ showRedirectModal }: Props) {
const {
marketsTokensApyData: arbApy,
marketsTokensIncentiveAprData: arbIncentiveApr,
glvTokensIncentiveAprData: arbGlvIncentiveApr,
glvApyInfoData: arbGlvApy,
} = useGmMarketsApy(ARBITRUM);
const {
marketsTokensApyData: avaxApy,
marketsTokensIncentiveAprData: avaxIncentiveApr,
glvTokensIncentiveAprData: avaxGlvIncentiveApr,
glvApyInfoData: avaxGlvApy,
} = useGmMarketsApy(AVALANCHE);

const maxApyText = useMemo(() => {
const maxMarketApyText = useMemo(() => {
if (!arbApy || !arbIncentiveApr || !avaxApy || !avaxIncentiveApr)
return {
[ARBITRUM]: "...%",
Expand All @@ -166,13 +168,17 @@ export default function TokenCard({ showRedirectModal }: Props) {
}, [arbApy, arbIncentiveApr, avaxApy, avaxIncentiveApr]);

const maxGlvApyText = useMemo(() => {
const arb = !arbGlvApy ? "...%" : `${formatAmount(calculateMaxApr(arbGlvApy, {}, ARBITRUM), 28, 2)}%`;
const avax = !avaxGlvApy ? "...%" : `${formatAmount(calculateMaxApr(avaxGlvApy, {}, AVALANCHE), 28, 2)}%`;
const arb = !arbGlvApy
? "...%"
: `${formatAmount(calculateMaxApr(arbGlvApy, arbGlvIncentiveApr ?? {}, ARBITRUM), 28, 2)}%`;
const avax = !avaxGlvApy
? "...%"
: `${formatAmount(calculateMaxApr(avaxGlvApy, avaxGlvIncentiveApr ?? {}, AVALANCHE), 28, 2)}%`;
return {
[ARBITRUM]: isGlvEnabled(ARBITRUM) ? arb : undefined,
[AVALANCHE]: isGlvEnabled(AVALANCHE) ? avax : undefined,
};
}, [arbGlvApy, avaxGlvApy]);
}, [arbGlvApy, avaxGlvApy, arbGlvIncentiveApr, avaxGlvIncentiveApr]);

const poolsIncentivizedLabel = useMemo(() => {
const sparkle = <img src={sparkleIcon} alt="sparkle" className="relative -top-2 -mr-10 inline h-10 align-top" />;
Expand Down Expand Up @@ -351,8 +357,8 @@ export default function TokenCard({ showRedirectModal }: Props) {
<div className="mt-15 rounded-4 bg-cold-blue-900 px-15 py-8 text-15">{poolsIncentivizedLabel}</div>
)}
<div className="Home-token-card-option-apr">
<Trans>Arbitrum Max. APY:</Trans> {maxApyText?.[ARBITRUM]},{" "}
<Trans>Avalanche Max. APY: {maxApyText?.[AVALANCHE]}</Trans>{" "}
<Trans>Arbitrum Max. APY:</Trans> {maxMarketApyText?.[ARBITRUM]},{" "}
<Trans>Avalanche Max. APY: {maxMarketApyText?.[AVALANCHE]}</Trans>{" "}
</div>
</div>

Expand Down
31 changes: 22 additions & 9 deletions src/domain/synthetics/markets/useGmMarketsApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTokensDataRequest } from "../tokens";
import { GlvAndGmMarketsInfoData, MarketInfo, MarketTokensAPRData } from "./types";
import { useDaysConsideredInMarketsApr } from "./useDaysConsideredInMarketsApr";
import { useMarketTokensData } from "./useMarketTokensData";
import { getPoolUsdWithoutPnl, isMarketInfo } from "domain/synthetics/markets";
import { getPoolUsdWithoutPnl, GlvInfoData, isMarketInfo } from "domain/synthetics/markets";
import { getTokenBySymbolSafe } from "config/tokens";

import TokenAbi from "abis/Token.json";
Expand All @@ -40,6 +40,7 @@ type RawPoolValue = {

type GmGlvTokensAPRResult = {
glvApyInfoData: MarketTokensAPRData;
glvTokensIncentiveAprData?: MarketTokensAPRData;
marketsTokensIncentiveAprData?: MarketTokensAPRData;
marketsTokensLidoAprData?: MarketTokensAPRData;
marketsTokensApyData?: MarketTokensAPRData;
Expand Down Expand Up @@ -140,12 +141,13 @@ function useExcludedLiquidityMarketMap(

function useIncentivesBonusApr(
chainId: number,
marketsInfoData: GlvAndGmMarketsInfoData | undefined
): MarketTokensAPRData {
marketsInfoData: GlvAndGmMarketsInfoData | undefined,
glvData: GlvInfoData | undefined
) {
const liquidityProvidersIncentives = useLiquidityProvidersIncentives(chainId);
const { tokensData } = useTokensDataRequest(chainId);
const marketAddresses = useMarketAddresses(marketsInfoData);
const { marketTokensData } = useMarketTokensData(chainId, { isDeposit: false });
const { marketTokensData } = useMarketTokensData(chainId, { isDeposit: false, withGlv: true, glvData });
const tokenAddress = liquidityProvidersIncentives?.token;
const excludedLiquidityMarketMap = useExcludedLiquidityMarketMap(chainId, marketsInfoData);

Expand Down Expand Up @@ -185,15 +187,18 @@ function useIncentivesBonusApr(
return undefined;
}, [marketToken, regularToken]);

const marketTokensAPRData = useMemo<MarketTokensAPRData>(() => {
const marketTokensAPRData = useMemo(() => {
if (!liquidityProvidersIncentives || !token) return {};

const marketTokensAPRData: MarketTokensAPRData = {};
const glvTokensAPRData: MarketTokensAPRData = {};

for (const marketAddress of marketAddresses) {
const market = getByKey(marketsInfoData, marketAddress);
if (!market) {
continue;
}

const marketToken = marketTokensData?.[marketAddress];
const poolValue = market?.poolValueMin;

Expand All @@ -215,10 +220,17 @@ function useIncentivesBonusApr(
poolValueWithoutExcludedLPs
) * yearMultiplier;

marketTokensAPRData[marketAddress] = apr;
if (isGlvInfo(market)) {
glvTokensAPRData[marketAddress] = apr;
} else {
marketTokensAPRData[marketAddress] = apr;
}
}

return marketTokensAPRData;
return {
marketTokensAPRData,
glvTokensAPRData,
};
}, [
excludedLiquidityMarketMap,
liquidityProvidersIncentives,
Expand Down Expand Up @@ -400,7 +412,7 @@ export function useGmMarketsApy(chainId: number): GmGlvTokensAPRResult {
},
});

const marketsTokensIncentiveAprData = useIncentivesBonusApr(chainId, marketsInfoData);
const marketsTokensIncentiveAprData = useIncentivesBonusApr(chainId, marketsInfoData, glvData);

const glvApyInfoData = useMemo(() => {
if (!glvData || !data?.marketsTokensApyData) {
Expand Down Expand Up @@ -441,7 +453,8 @@ export function useGmMarketsApy(chainId: number): GmGlvTokensAPRResult {
return {
glvApyInfoData,
marketsTokensLidoAprData: data?.marketsTokensLidoAprData,
marketsTokensIncentiveAprData,
marketsTokensIncentiveAprData: marketsTokensIncentiveAprData.marketTokensAPRData,
glvTokensIncentiveAprData: marketsTokensIncentiveAprData.glvTokensAPRData,
avgMarketsApy: data?.avgMarketsApy,
marketsTokensApyData: data?.marketsTokensApyData,
};
Expand Down
6 changes: 4 additions & 2 deletions src/domain/synthetics/markets/useMarketTokensData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ export function useMarketTokensDataRequest(

export function useMarketTokensData(
chainId: number,
p: { isDeposit: boolean; withGlv?: boolean }
p: { isDeposit: boolean; withGlv?: boolean; glvData?: GlvInfoData }
): MarketTokensDataResult {
const { isDeposit } = p;
const account = useSelector((s) => s.globals.account);
const glvData = useSelector(selectGlvInfo);
const storedGlvData = useSelector(selectGlvInfo);

const glvData = p.glvData || storedGlvData;

return useMarketTokensDataRequest(chainId, {
isDeposit,
Expand Down
11 changes: 9 additions & 2 deletions src/pages/MarketPoolsPage/MarketPoolsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ export function MarketPoolsPage() {
const depositMarketTokensData = useSelector(selectDepositMarketTokensData);
const { marketTokensData: withdrawalMarketTokensData } = useMarketTokensData(chainId, { isDeposit: false });

const { marketsTokensApyData, marketsTokensIncentiveAprData, marketsTokensLidoAprData, glvApyInfoData } =
useGmMarketsApy(chainId);
const {
marketsTokensApyData,
marketsTokensIncentiveAprData,
marketsTokensLidoAprData,
glvApyInfoData,
glvTokensIncentiveAprData,
} = useGmMarketsApy(chainId);

const [operation, setOperation] = useState<Operation>(Operation.Deposit);
let [mode, setMode] = useState<Mode>(Mode.Single);
Expand Down Expand Up @@ -94,6 +99,7 @@ export function MarketPoolsPage() {
<MarketStatsWithComposition
marketsTokensApyData={marketsTokensApyData}
marketsTokensIncentiveAprData={marketsTokensIncentiveAprData}
glvTokensIncentiveAprData={glvTokensIncentiveAprData}
marketsTokensLidoAprData={marketsTokensLidoAprData}
marketTokensData={depositMarketTokensData}
marketsInfoData={marketsInfoData}
Expand Down Expand Up @@ -123,6 +129,7 @@ export function MarketPoolsPage() {
</div>
<GmList
glvTokensApyData={glvApyInfoData}
glvTokensIncentiveAprData={glvTokensIncentiveAprData}
marketsTokensApyData={marketsTokensApyData}
marketsTokensIncentiveAprData={marketsTokensIncentiveAprData}
marketsTokensLidoAprData={marketsTokensLidoAprData}
Expand Down
10 changes: 8 additions & 2 deletions src/pages/Stake/StakeV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,13 @@ export default function StakeV2() {
];

const { marketTokensData } = useMarketTokensData(chainId, { isDeposit: false });
const { marketsTokensApyData, marketsTokensIncentiveAprData, marketsTokensLidoAprData, glvApyInfoData } =
useGmMarketsApy(chainId);
const {
marketsTokensApyData,
marketsTokensIncentiveAprData,
glvTokensIncentiveAprData,
marketsTokensLidoAprData,
glvApyInfoData,
} = useGmMarketsApy(chainId);
const vestingData = useVestingData(account);
const govTokenAmount = useGovTokenAmount(chainId);
const govTokenDelegatesAddress = useGovTokenDelegates(chainId);
Expand Down Expand Up @@ -2390,6 +2395,7 @@ export default function StakeV2() {
<GmList
marketsTokensApyData={marketsTokensApyData}
marketsTokensIncentiveAprData={marketsTokensIncentiveAprData}
glvTokensIncentiveAprData={glvTokensIncentiveAprData}
marketsTokensLidoAprData={marketsTokensLidoAprData}
glvTokensApyData={glvApyInfoData}
isDeposit={false}
Expand Down