Skip to content

Commit

Permalink
use correct APR in confirm stake
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-d committed Jan 13, 2025
1 parent db6b72f commit cce958d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
28 changes: 26 additions & 2 deletions web/src/components/ConfirmStake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "wagmi";
import useWriteContract from "@/fixtures/wagmi/useWriteContract";
import { sqrtPriceX96ToPrice, snapTickToSpacing } from "@/lib/math";
import { useEffect, useCallback } from "react";
import { useEffect, useCallback, useMemo } from "react";
import { Hash } from "viem";
import Confirm from "@/components/sequence/Confirm";
import { EnableSpending } from "@/components/sequence/EnableSpending";
Expand All @@ -30,6 +30,16 @@ import { TokenIcon } from "./TokenIcon";
import { useFeatureFlag } from "@/hooks/useFeatureFlag";
import { usePositions } from "@/hooks/usePostions";
import { superpositionMainnet, superpositionTestnet } from "@/config/chains";
import { graphql, useFragment } from "@/gql";
import { useGraphqlGlobal } from "@/hooks/useGraphql";

export const ConfirmStakeFragment = graphql(`
fragment ConfirmStakeFragment on SeawaterPool {
APR {
total
}
}
`);

type ConfirmStakeProps =
| {
Expand Down Expand Up @@ -92,6 +102,20 @@ export const ConfirmStake = ({
feePercentage,
} = useStakeStore();

const { data: dataGlobal } = useGraphqlGlobal();
// the selected pool
const pool = useMemo(
() =>
dataGlobal?.pools?.find(
(pool) =>
pool.address.toLowerCase() === token0.address.toLowerCase() ||
pool.address.toLowerCase() === token1.address.toLowerCase(),
),
[dataGlobal?.pools, token0.address, token1.address],
);
const poolApr = useFragment(ConfirmStakeFragment, pool);
const stakeApr = Number(poolApr?.APR.total).toFixed(2);

const { updatePositionLocal } = usePositions();

// Price of the current pool
Expand Down Expand Up @@ -813,7 +837,7 @@ export const ConfirmStake = ({
<div className="mt-[15px] flex flex-row justify-between">
<div>APR</div>
<div className="iridescent rounded px-1 text-black">
12.09%
{stakeApr}%
</div>
</div>

Expand Down
9 changes: 7 additions & 2 deletions web/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const documents = {
"\n fragment ManagePoolFragment on SeawaterPool {\n address\n id\n liquidity {\n liquidity\n }\n token {\n symbol\n name\n decimals\n }\n earnedFeesAPRFUSDC\n liquidityCampaigns {\n campaignId\n tickLower\n tickUpper\n fromTimestamp\n endTimestamp\n }\n }\n": types.ManagePoolFragmentFragmentDoc,
"\n fragment SwapExploreFragment on SeawaterPool {\n token {\n name\n symbol\n address\n decimals\n }\n price\n }\n": types.SwapExploreFragmentFragmentDoc,
"\n fragment NotesFragment on Note {\n content\n placement\n }\n": types.NotesFragmentFragmentDoc,
"\n fragment ConfirmStakeFragment on SeawaterPool {\n APR {\n total\n }\n }\n": types.ConfirmStakeFragmentFragmentDoc,
"\n fragment MyPositionsInventoryWalletFragment on Wallet {\n id\n positions {\n positions {\n id\n pool {\n token {\n name\n address\n symbol\n }\n }\n }\n }\n }\n": types.MyPositionsInventoryWalletFragmentFragmentDoc,
"\n fragment TradeTabTransactionsFragment on SeawaterSwap {\n timestamp\n amountIn {\n token {\n symbol\n }\n valueScaled\n }\n amountOut {\n token {\n symbol\n }\n valueScaled\n }\n }\n": types.TradeTabTransactionsFragmentFragmentDoc,
"\n fragment StakeFormFragment on SeawaterPool {\n address\n earnedFeesAPRFUSDC\n fee\n config {\n classification\n }\n priceOverTime {\n daily\n }\n liquidity {\n tickLower\n tickUpper\n price\n liquidity\n }\n }\n": types.StakeFormFragmentFragmentDoc,
Expand All @@ -26,7 +27,7 @@ const documents = {
"\n fragment SwapProPoolFragment on SeawaterPool {\n address\n token {\n address\n symbol\n }\n liquidity {\n liquidity\n }\n priceOverTime {\n daily\n monthly\n }\n volumeOverTime {\n monthly {\n token1 {\n timestamp\n valueUsd\n }\n fusdc {\n timestamp\n valueUsd\n }\n }\n daily {\n token1 {\n timestamp\n valueUsd\n }\n fusdc {\n timestamp\n valueUsd\n }\n }\n }\n liquidityOverTime {\n daily {\n timestamp\n fusdc {\n valueUsd\n }\n }\n monthly {\n timestamp\n fusdc {\n valueUsd\n }\n }\n }\n APR {\n total\n }\n swaps {\n swaps {\n transactionHash\n timestamp\n amountIn {\n valueScaled\n token {\n symbol\n }\n }\n amountOut {\n valueScaled\n token {\n symbol\n }\n }\n }\n }\n }\n": types.SwapProPoolFragmentFragmentDoc,
"\n fragment TokensFragment on SeawaterPool {\n token {\n address\n decimals\n name\n symbol\n image\n }\n }\n": types.TokensFragmentFragmentDoc,
"\n fragment FusdcFragment on Token {\n address\n decimals\n name\n symbol\n image\n }\n": types.FusdcFragmentFragmentDoc,
"\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n }\n }\n": types.AllDataDocument,
"\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n ...ConfirmStakeFragment\n }\n }\n": types.AllDataDocument,
"\n query ForUser($wallet: String!) {\n getSwapsForUser(wallet: $wallet, first: 10) {\n data {\n swaps {\n # add transaction fragments here\n ...TradeTabTransactionsFragment\n }\n }\n }\n\n getWallet(address: $wallet) {\n # add wallet fragments here\n ...MyPositionsInventoryWalletFragment\n ...PositionsFragment\n }\n\n notes(wallet: $wallet) {\n # add notes fragments here\n ...NotesFragment\n }\n }\n": types.ForUserDocument,
"\n query queryGetPoints($wallet: String!) {\n getPointsComponent(wallet: $wallet)\n }\n": types.QueryGetPointsDocument,
"\n query queryGetPool($token: String!) {\n getPool(token: $token) {\n ...StakeFormPoolFragment\n ...ManagePoolFragment\n }\n }\n": types.QueryGetPoolDocument,
Expand Down Expand Up @@ -67,6 +68,10 @@ export function graphql(source: "\n fragment SwapExploreFragment on SeawaterPoo
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment NotesFragment on Note {\n content\n placement\n }\n"): (typeof documents)["\n fragment NotesFragment on Note {\n content\n placement\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment ConfirmStakeFragment on SeawaterPool {\n APR {\n total\n }\n }\n"): (typeof documents)["\n fragment ConfirmStakeFragment on SeawaterPool {\n APR {\n total\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down Expand Up @@ -102,7 +107,7 @@ export function graphql(source: "\n fragment FusdcFragment on Token {\n addr
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n }\n }\n"): (typeof documents)["\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n }\n }\n"];
export function graphql(source: "\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n ...ConfirmStakeFragment\n }\n }\n"): (typeof documents)["\n query AllData {\n fusdc {\n address\n ...FusdcFragment\n }\n pools {\n # used for the pool selector\n address\n\n # add general fragments here\n ...SwapProPoolFragment\n ...AllPoolsFragment\n ...SelectPrimeAssetFragment\n ...SwapExploreFragment\n ...ManagePoolFragment\n ...SwapFormFragment\n ...StakeFormFragment\n ...TokensFragment\n ...ConfirmStakeFragment\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit cce958d

Please sign in to comment.