From 331af7b45027d8c49d1f67bd6f59b954a6c7b1da Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:25:50 -0300 Subject: [PATCH 1/5] Add Grown Stalk to Deposits table --- projects/sdk/src/lib/silo.ts | 2 +- .../src/queries/silo/getSiloBalance.graphql | 1 + .../src/queries/silo/getSiloBalances.graphql | 1 + .../src/components/Silo/Actions/Deposits.tsx | 60 ++++++++++++++++--- projects/ui/src/state/farmer/silo/updater.ts | 11 ++-- 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/projects/sdk/src/lib/silo.ts b/projects/sdk/src/lib/silo.ts index e07ab23b5e..5786339548 100644 --- a/projects/sdk/src/lib/silo.ts +++ b/projects/sdk/src/lib/silo.ts @@ -332,7 +332,7 @@ export class Silo { if (!stemTip) throw new Error(`No stem tip found for ${token.address}`); utils.applyDeposit(balance, token, stemTip, { - stem: deposit.season, // FIXME + stem: deposit.stem || deposit.season, amount: deposit.amount, bdv: deposit.bdv }); diff --git a/projects/sdk/src/queries/silo/getSiloBalance.graphql b/projects/sdk/src/queries/silo/getSiloBalance.graphql index 162c8ed525..51404c3692 100644 --- a/projects/sdk/src/queries/silo/getSiloBalance.graphql +++ b/projects/sdk/src/queries/silo/getSiloBalance.graphql @@ -11,6 +11,7 @@ query getSiloBalance($token: String, $account: ID!, $season: Int!) { } ) { season + stem token #amount amount diff --git a/projects/sdk/src/queries/silo/getSiloBalances.graphql b/projects/sdk/src/queries/silo/getSiloBalances.graphql index 27e7767b17..0a399271d2 100644 --- a/projects/sdk/src/queries/silo/getSiloBalances.graphql +++ b/projects/sdk/src/queries/silo/getSiloBalances.graphql @@ -10,6 +10,7 @@ query getSiloBalances($account: ID!, $season: Int!) { } ) { season + stem token #amount amount diff --git a/projects/ui/src/components/Silo/Actions/Deposits.tsx b/projects/ui/src/components/Silo/Actions/Deposits.tsx index 3a1391bdf8..7d0ba8c0fc 100644 --- a/projects/ui/src/components/Silo/Actions/Deposits.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposits.tsx @@ -2,10 +2,12 @@ import React, { useMemo } from 'react'; import { useAccount as useWagmiAccount } from 'wagmi'; import { Stack, Tooltip, Typography } from '@mui/material'; import { GridColumns } from '@mui/x-data-grid'; +import { ERC20Token } from '@beanstalk/sdk'; +import { BigNumber } from 'ethers'; import { Token } from '~/classes'; import { FarmerSiloTokenBalance } from '~/state/farmer/silo'; import type { LegacyDepositCrate } from '~/state/farmer/silo'; -import { displayBN, displayFullBN } from '~/util'; +import { displayBN, displayFullBN, transform } from '~/util'; import { STALK } from '~/constants/tokens'; import { ZERO_BN } from '~/constants'; import useSiloTokenToFiat from '~/hooks/beanstalk/useSiloTokenToFiat'; @@ -14,6 +16,8 @@ import Fiat from '~/components/Common/Fiat'; import TableCard, { TableCardProps } from '../../Common/TableCard'; import StatHorizontal from '~/components/Common/StatHorizontal'; import { FC } from '~/types'; +import useStemTipForToken from '~/hooks/beanstalk/useStemTipForToken'; +import useSdk from '~/hooks/sdk'; const Deposits: FC< { @@ -22,8 +26,15 @@ const Deposits: FC< useLegacySeason?: boolean; } & Partial > = ({ token, siloBalance, useLegacySeason, ...props }) => { + const sdk = useSdk(); const getUSD = useSiloTokenToFiat(); const account = useWagmiAccount(); + const newToken = sdk.tokens.findBySymbol(token.symbol) as ERC20Token; + + const seeds = transform(newToken.rewards?.seeds.toBlockchain() || "0", 'ethers', sdk.tokens.SEEDS); + const stemTip = useStemTipForToken(newToken); + const lastStem = stemTip ? stemTip.sub(siloBalance?.mowStatus.lastStem || Number(0)) : Number(0); + const mowableStalk = transform(((stemTip?.sub(lastStem) || BigNumber.from(0)).mul(seeds)), 'bnjs', sdk.tokens.STALK); const rows: (LegacyDepositCrate & { id: string })[] = useMemo( () => @@ -37,7 +48,6 @@ const Deposits: FC< const columns = useMemo( () => [ - COLUMNS.depositId(useLegacySeason ? 'Season' : 'Stem'), { field: 'amount', flex: 1, @@ -87,8 +97,8 @@ const Deposits: FC< field: 'stalk', flex: 1, headerName: 'Stalk', - align: 'right', - headerAlign: 'right', + align: 'left', + headerAlign: 'left', valueFormatter: (params) => displayBN(params.value.total), renderCell: (params) => ( {displayFullBN(params.row.stalk.base, 2, 2)} - - {displayFullBN(params.row.stalk.grown, 2, 2)} - } > @@ -120,9 +127,46 @@ const Deposits: FC< ), sortable: false, }, + { + field: 'stalk.grown', + flex: 1, + headerName: 'Grown Stalk', + align: 'right', + headerAlign: 'right', + valueFormatter: (params) => displayBN(params.value), + renderCell: (params) => ( + + + {displayFullBN(mowableStalk, 2, 2)} + + + {displayFullBN(params.row.stalk.total.minus(mowableStalk), 2, 2)} + + + } + > + + + {displayFullBN( + params.row.stalk.grown, + STALK.displayDecimals, + STALK.displayDecimals + )} + + + {displayBN(params.row.stalk.grown)} + + + + ), + sortable: false, + }, COLUMNS.seeds, ] as GridColumns, - [useLegacySeason, token] + [mowableStalk, token] ); const amount = siloBalance?.deposited.amount; diff --git a/projects/ui/src/state/farmer/silo/updater.ts b/projects/ui/src/state/farmer/silo/updater.ts index 79c6d5d0e9..b1aa3fbb8f 100644 --- a/projects/ui/src/state/farmer/silo/updater.ts +++ b/projects/ui/src/state/farmer/silo/updater.ts @@ -112,12 +112,11 @@ export const useFetchFarmerSilo = () => { // Get the mowStatus struct for each whitelisted token Promise.all( - [] - // [...sdk.tokens.siloWhitelist].map((token) => - // sdk.contracts.beanstalk - // .getMowStatus(account, token.address) - // .then((status) => [token, status] as const) - // ) + [...sdk.tokens.siloWhitelist].map((token) => + sdk.contracts.beanstalk + .getMowStatus(account, token.address) + .then((status) => [token, status] as const) + ) ).then( (statuses) => new Map< From fadb47828902a973dbd03e4d54cf554056d986b1 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:11:31 -0300 Subject: [PATCH 2/5] Fix Mowed Grown Stalk calculation --- projects/ui/src/components/Silo/Actions/Deposits.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ui/src/components/Silo/Actions/Deposits.tsx b/projects/ui/src/components/Silo/Actions/Deposits.tsx index 7d0ba8c0fc..be75670078 100644 --- a/projects/ui/src/components/Silo/Actions/Deposits.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposits.tsx @@ -143,7 +143,7 @@ const Deposits: FC< {displayFullBN(mowableStalk, 2, 2)} - {displayFullBN(params.row.stalk.total.minus(mowableStalk), 2, 2)} + {displayFullBN(params.row.stalk.grown.minus(mowableStalk), 2, 2)} } From 8be1fa2b368541a08adcb18161e2978d3ba9c7bc Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:22:00 -0300 Subject: [PATCH 3/5] Updated Mowable Grown Stalk calculation --- .../src/components/Silo/Actions/Deposits.tsx | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/projects/ui/src/components/Silo/Actions/Deposits.tsx b/projects/ui/src/components/Silo/Actions/Deposits.tsx index be75670078..cf6bf99a91 100644 --- a/projects/ui/src/components/Silo/Actions/Deposits.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposits.tsx @@ -31,10 +31,9 @@ const Deposits: FC< const account = useWagmiAccount(); const newToken = sdk.tokens.findBySymbol(token.symbol) as ERC20Token; - const seeds = transform(newToken.rewards?.seeds.toBlockchain() || "0", 'ethers', sdk.tokens.SEEDS); - const stemTip = useStemTipForToken(newToken); - const lastStem = stemTip ? stemTip.sub(siloBalance?.mowStatus.lastStem || Number(0)) : Number(0); - const mowableStalk = transform(((stemTip?.sub(lastStem) || BigNumber.from(0)).mul(seeds)), 'bnjs', sdk.tokens.STALK); + const stemTip = useStemTipForToken(newToken) || BigNumber.from(0); + const lastStem = siloBalance?.mowStatus.lastStem || BigNumber.from(0); + const deltaStem = stemTip?.sub(lastStem) || BigNumber.from(0); const rows: (LegacyDepositCrate & { id: string })[] = useMemo( () => @@ -139,25 +138,18 @@ const Deposits: FC< placement="bottom" title={ - - {displayFullBN(mowableStalk, 2, 2)} - - {displayFullBN(params.row.stalk.grown.minus(mowableStalk), 2, 2)} + {displayBN(params.row.stalk.grown.minus(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs')))} } > - {displayFullBN( - params.row.stalk.grown, - STALK.displayDecimals, - STALK.displayDecimals - )} + {displayBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'))} - {displayBN(params.row.stalk.grown)} + {displayBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'))} @@ -166,7 +158,7 @@ const Deposits: FC< }, COLUMNS.seeds, ] as GridColumns, - [mowableStalk, token] + [deltaStem, sdk.tokens.BEAN, sdk.tokens.STALK, token] ); const amount = siloBalance?.deposited.amount; From efe803a5043c3c9841dce8b74bcb596b1b4bcbe2 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Tue, 3 Oct 2023 22:58:36 -0300 Subject: [PATCH 4/5] Updated Silo Deposits table --- .../ui/src/components/Silo/Actions/Deposits.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/projects/ui/src/components/Silo/Actions/Deposits.tsx b/projects/ui/src/components/Silo/Actions/Deposits.tsx index cf6bf99a91..2d306a69d7 100644 --- a/projects/ui/src/components/Silo/Actions/Deposits.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposits.tsx @@ -129,7 +129,7 @@ const Deposits: FC< { field: 'stalk.grown', flex: 1, - headerName: 'Grown Stalk', + headerName: 'Stalk Grown', align: 'right', headerAlign: 'right', valueFormatter: (params) => displayBN(params.value), @@ -138,18 +138,21 @@ const Deposits: FC< placement="bottom" title={ - - {displayBN(params.row.stalk.grown.minus(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs')))} + + {displayFullBN(params.row.stalk.grown.minus(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs')), 2, 2)} + + + {displayFullBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'), 2, 2)} } > - {displayBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'))} + {displayFullBN(params.row.stalk.grown, 2, 2)} - {displayBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'))} + {displayFullBN(params.row.stalk.grown, 2, 2)} From 839fcdaca0f43d92563cc92ceaa0f58407e4df12 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:05:33 -0300 Subject: [PATCH 5/5] Cleanup --- .../ui/src/components/Silo/Actions/Deposits.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/projects/ui/src/components/Silo/Actions/Deposits.tsx b/projects/ui/src/components/Silo/Actions/Deposits.tsx index 2d306a69d7..aec1f29ed2 100644 --- a/projects/ui/src/components/Silo/Actions/Deposits.tsx +++ b/projects/ui/src/components/Silo/Actions/Deposits.tsx @@ -32,16 +32,19 @@ const Deposits: FC< const newToken = sdk.tokens.findBySymbol(token.symbol) as ERC20Token; const stemTip = useStemTipForToken(newToken) || BigNumber.from(0); - const lastStem = siloBalance?.mowStatus.lastStem || BigNumber.from(0); - const deltaStem = stemTip?.sub(lastStem) || BigNumber.from(0); + const lastStem = siloBalance?.mowStatus?.lastStem || BigNumber.from(0); + const deltaStem = transform(stemTip.sub(lastStem), 'bnjs'); + + const decimalShift = sdk.tokens.BEAN.decimals - sdk.tokens.STALK.decimals; const rows: (LegacyDepositCrate & { id: string })[] = useMemo( () => siloBalance?.deposited.crates.map((deposit) => ({ id: deposit.stem?.toString(), + mowableStalk: deposit.bdv?.multipliedBy(deltaStem).shiftedBy(decimalShift), ...deposit, })) || [], - [siloBalance?.deposited.crates] + [siloBalance?.deposited.crates, deltaStem, decimalShift] ); const columns = useMemo( @@ -139,10 +142,10 @@ const Deposits: FC< title={ - {displayFullBN(params.row.stalk.grown.minus(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs')), 2, 2)} + {displayFullBN(params.row.stalk.grown.minus(params.row.mowableStalk), 2, 2)} - {displayFullBN(transform(sdk.tokens.STALK.fromBlockchain(transform(params.row.bdv, 'tokenValue', sdk.tokens.BEAN).toBigNumber().mul(deltaStem)), 'bnjs'), 2, 2)} + {displayFullBN(params.row.mowableStalk, 2, 2)} } @@ -161,7 +164,7 @@ const Deposits: FC< }, COLUMNS.seeds, ] as GridColumns, - [deltaStem, sdk.tokens.BEAN, sdk.tokens.STALK, token] + [token] ); const amount = siloBalance?.deposited.amount;