Skip to content

Commit

Permalink
wip: fix plant and do x, related build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
silochad committed Jul 8, 2023
1 parent 3eb5893 commit 4e5b23f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
3 changes: 3 additions & 0 deletions projects/ui/src/components/Silo/Actions/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type WithdrawFormValues = FormStateNew &
tokenOut: ERC20Token | undefined;
};

// Type 'Element | undefined' is not assignable to type 'ReactElement<any, any> | null'.
// Type 'undefined' is not assignable to type 'ReactElement<any, any> | null'.
// @ts-ignore
const WithdrawForm: FC<
FormikProps<WithdrawFormValues> & {
token: Token;
Expand Down
14 changes: 14 additions & 0 deletions projects/ui/src/hooks/beanstalk/useStemTipForToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Token } from '@beanstalk/sdk';
import { ethers } from 'ethers';
import { useMemo } from 'react';
import useSilo from '~/hooks/beanstalk/useSilo';

export default function useStemTipForToken(
token: Token
): ethers.BigNumber | null {
const silo = useSilo();
return useMemo(
() => silo.balances[token.address].stemTip ?? null,
[silo, token.address]
);
}
15 changes: 12 additions & 3 deletions projects/ui/src/hooks/farmer/useFarmerDepositCrateFromPlant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import useSeason from '../beanstalk/useSeason';
import useFarmerSilo from './useFarmerSilo';
import { LegacyDepositCrate } from '~/state/farmer/silo';
import { tokenValueToBN } from '~/util';
import { ZERO_BN } from '~/constants';
import useStemTipForToken from '~/hooks/beanstalk/useStemTipForToken';

/// Returns the deposit crate which will be created via calling 'plant'
export default function useFarmerDepositCrateFromPlant() {
Expand All @@ -13,6 +15,7 @@ export default function useFarmerDepositCrateFromPlant() {

/// Beanstalk
const season = useSeason();
const stemTip = useStemTipForToken(sdk.tokens.BEAN);

/// Farmer
const farmerSilo = useFarmerSilo();
Expand All @@ -27,12 +30,18 @@ export default function useFarmerDepositCrateFromPlant() {
// no stalk is grown yet as it is a new deposit from the current season
const grownStalk = STALK.amount(0);

if (!stemTip) throw new Error('No stem tip loaded for BEAN');

// asBN => as DepositCrate from UI;
const asBN: LegacyDepositCrate = {
season,
stem: stemTip,
amount: earned,
bdv: earned,
stalk: tokenValueToBN(stalk),
stalk: {
total: tokenValueToBN(stalk),
base: tokenValueToBN(stalk),
grown: ZERO_BN,
},
seeds: tokenValueToBN(seeds),
};

Expand All @@ -51,7 +60,7 @@ export default function useFarmerDepositCrateFromPlant() {
asBN,
asTV,
};
}, [farmerSilo.beans.earned, sdk.tokens, season]);
}, [farmerSilo.beans.earned, sdk.tokens, season, stemTip]);

return {
crate,
Expand Down
14 changes: 8 additions & 6 deletions projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class PlantAndDoX {
private _season: number
) {
this._earnedBeans = _earnedBeans;
this._season = _season;
this._season = 0; // FIXME
}

/// Returns whether 'plant' can be called
Expand Down Expand Up @@ -66,16 +66,14 @@ export default class PlantAndDoX {

// asTV => as DepositCrate<TokenValue> from SDK;
const crate: TokenSiloBalance['deposits'][number] = {
season: ethers.BigNumber.from(season),
stem: ethers.BigNumber.from(season), // FIXME
amount: earnedBeans,
bdv: earnedBeans,
stalk: {
total: stalk.add(grownStalk),
base: stalk,
grown: grownStalk,
},
baseStalk: stalk,
grownStalk,
seeds,
};

Expand All @@ -95,10 +93,14 @@ export default class PlantAndDoX {
const seeds = BEAN.getSeeds(earnedTV);

const crate: LegacyDepositCrate = {
season,
stem: ethers.BigNumber.from(season), // FIXME
amount: earnedBeans,
bdv: earnedBeans,
stalk: tokenValueToBN(stalk),
stalk: {
total: tokenValueToBN(stalk),
base: tokenValueToBN(stalk),
grown: new BigNumber(0),
},
seeds: tokenValueToBN(seeds),
};

Expand Down
7 changes: 1 addition & 6 deletions projects/ui/src/state/beanstalk/silo/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const useFetchBeanstalkSilo = () => {
earnedBeansTotal,
// 4
whitelistedAssetTotals,
// 5
stemTips,
] = await Promise.all([
// 0
sdk.contracts.beanstalk.totalStalk().then(tokenResult(STALK)), // Does NOT include Grown Stalk
Expand Down Expand Up @@ -83,9 +81,6 @@ export const useFetchBeanstalkSilo = () => {
}))
)
),

// 5
sdk.silo.getStemTips([...sdk.tokens.siloWhitelist]),
] as const);

console.debug('[beanstalk/silo/useBeanstalkSilo] RESULT', [
Expand All @@ -106,7 +101,7 @@ export const useFetchBeanstalkSilo = () => {
const token = sdk.tokens.findByAddress(curr.address);
if (!token) throw new Error(`Token not found in SDK: ${curr.address}`);

const stemTip = stemTips.get(token);
const stemTip = curr.stemTip;
if (!stemTip)
throw new Error(`Stem Tip not found in SDK: ${curr.address}`);

Expand Down

0 comments on commit 4e5b23f

Please sign in to comment.