From fe642ce3670f5023f174ac6921adc4503d862932 Mon Sep 17 00:00:00 2001 From: Silo Chad Date: Thu, 29 Jun 2023 21:52:17 -0500 Subject: [PATCH] wip: incomplete refactors to claim/plant and do x classes --- .../lib/Txn/FarmSteps/silo/ConvertFarmStep.ts | 6 ++--- .../Txn/FarmSteps/silo/TransferFarmStep.ts | 22 ++++++---------- .../Txn/FarmSteps/silo/WithdrawFarmStep.ts | 25 +++++++------------ .../ui/src/lib/Txn/Interface/PlantAndDoX.ts | 9 +++++-- projects/ui/src/util/Crates.ts | 12 +++------ 5 files changed, 29 insertions(+), 45 deletions(-) diff --git a/projects/ui/src/lib/Txn/FarmSteps/silo/ConvertFarmStep.ts b/projects/ui/src/lib/Txn/FarmSteps/silo/ConvertFarmStep.ts index 0ed9301fbb..485763c98c 100644 --- a/projects/ui/src/lib/Txn/FarmSteps/silo/ConvertFarmStep.ts +++ b/projects/ui/src/lib/Txn/FarmSteps/silo/ConvertFarmStep.ts @@ -1,8 +1,8 @@ import { BeanstalkSDK, + Deposit, StepGenerator, Token, - TokenSiloBalance, TokenValue, } from '@beanstalk/sdk'; import { ethers } from 'ethers'; @@ -15,7 +15,7 @@ export class ConvertFarmStep extends FarmStep { _sdk: BeanstalkSDK, private _tokenIn: Token, private _season: number, - private _deposits: TokenSiloBalance['deposits'] + private _deposits: Deposit[] ) { super(_sdk); this._sdk = _sdk; @@ -30,7 +30,7 @@ export class ConvertFarmStep extends FarmStep { /// this logic exists in the SDK but won't work b/c we need to add plant static async _handleConversion( sdk: BeanstalkSDK, - _deposits: TokenSiloBalance['deposits'], + _deposits: Deposit[], _tokenIn: Token, _tokenOut: Token, _amountIn: TokenValue, diff --git a/projects/ui/src/lib/Txn/FarmSteps/silo/TransferFarmStep.ts b/projects/ui/src/lib/Txn/FarmSteps/silo/TransferFarmStep.ts index 1fecae0b26..48383c6023 100644 --- a/projects/ui/src/lib/Txn/FarmSteps/silo/TransferFarmStep.ts +++ b/projects/ui/src/lib/Txn/FarmSteps/silo/TransferFarmStep.ts @@ -1,15 +1,7 @@ -import { - BeanstalkSDK, - Token, - TokenSiloBalance, - TokenValue, -} from '@beanstalk/sdk'; +import { BeanstalkSDK, Deposit, Token, TokenValue } from '@beanstalk/sdk'; import { FarmStep, PlantAndDoX } from '~/lib/Txn/Interface'; import { WithdrawFarmStep } from '~/lib/Txn/FarmSteps'; -// @REMOVEME -type DepositCrate = TokenSiloBalance['deposited']['crates'][number]; - type WithdrawResult = ReturnType; export class TransferFarmStep extends FarmStep { @@ -19,7 +11,7 @@ export class TransferFarmStep extends FarmStep { _sdk: BeanstalkSDK, private _token: Token, private _account: string, - private _crates: DepositCrate[] + private _crates: Deposit[] ) { super(_sdk); this._token = _token; @@ -56,17 +48,17 @@ export class TransferFarmStep extends FarmStep { throw new Error('Nothing to Withdraw.'); } - const seasons = result.crates.map((crate) => crate.season.toString()); + const stems = result.crates.map((crate) => crate.stem.toString()); const amounts = result.crates.map((crate) => crate.amount.blockchainString); - if (seasons.length === 0) { + if (stems.length === 0) { throw new Error('Malformatted crates'); - } else if (seasons.length === 1) { + } else if (stems.length === 1) { const transferDeposit = new this._sdk.farm.actions.TransferDeposit( this._account, toAddress, this._token.address, - seasons[0], + stems[0], amounts[0] ); console.debug( @@ -79,7 +71,7 @@ export class TransferFarmStep extends FarmStep { this._account, toAddress, this._token.address, - seasons, + stems, amounts ); console.debug( diff --git a/projects/ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts b/projects/ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts index bc36c08f07..3d06d7fe3e 100644 --- a/projects/ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts +++ b/projects/ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts @@ -1,14 +1,6 @@ -import { - BeanstalkSDK, - Token, - TokenSiloBalance, - TokenValue, -} from '@beanstalk/sdk'; +import { BeanstalkSDK, Deposit, Token, TokenValue } from '@beanstalk/sdk'; import { FarmStep, PlantAndDoX } from '~/lib/Txn/Interface'; -// @REMOVEME -type DepositCrate = TokenSiloBalance['deposited']['crates'][number]; - type WithdrawResult = ReturnType; export class WithdrawFarmStep extends FarmStep { @@ -17,7 +9,7 @@ export class WithdrawFarmStep extends FarmStep { constructor( _sdk: BeanstalkSDK, private _token: Token, - private _crates: DepositCrate[] + private _crates: Deposit[] ) { super(_sdk); this._token = _token; @@ -52,16 +44,17 @@ export class WithdrawFarmStep extends FarmStep { throw new Error('Nothing to Withdraw.'); } - const seasons = result.crates.map((crate) => crate.season.toString()); + // FIXME + const stems = result.crates.map((crate) => crate.stem.toString()); const amounts = result.crates.map((crate) => crate.amount.blockchainString); - if (seasons.length === 0) { + if (stems.length === 0) { throw new Error('Malformatted crates.'); - } else if (seasons.length === 1) { + } else if (stems.length === 1) { this.pushInput({ input: new this._sdk.farm.actions.WithdrawDeposit( this._token.address, - seasons[0], + stems[0], amounts[0] ), }); @@ -69,7 +62,7 @@ export class WithdrawFarmStep extends FarmStep { this.pushInput({ input: new this._sdk.farm.actions.WithdrawDeposits( this._token.address, - seasons, + stems, amounts ), }); @@ -83,7 +76,7 @@ export class WithdrawFarmStep extends FarmStep { static calculateWithdraw( siloWithdraw: BeanstalkSDK['silo']['siloWithdraw'], whitelistedToken: Token, - _crates: DepositCrate[], + _crates: Deposit[], _amountIn: TokenValue, season: number, plant?: PlantAndDoX diff --git a/projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts b/projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts index fd19c764dc..c87d288f38 100644 --- a/projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts +++ b/projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts @@ -65,11 +65,15 @@ export default class PlantAndDoX { const grownStalk = STALK.amount(0); // asTV => as DepositCrate from SDK; - const crate: TokenSiloBalance['deposited']['crates'][number] = { + const crate: TokenSiloBalance['deposits'][number] = { season: ethers.BigNumber.from(season), amount: earnedBeans, bdv: earnedBeans, - stalk, + stalk: { + total: stalk.add(grownStalk), + base: stalk, + grown: grownStalk, + }, baseStalk: stalk, grownStalk, seeds, @@ -77,6 +81,7 @@ export default class PlantAndDoX { return crate; }, + // as DepositCrate from UI; bigNumber( sdk: BeanstalkSDK, diff --git a/projects/ui/src/util/Crates.ts b/projects/ui/src/util/Crates.ts index 37ac305ae9..e9de5f723d 100644 --- a/projects/ui/src/util/Crates.ts +++ b/projects/ui/src/util/Crates.ts @@ -2,11 +2,7 @@ import BigNumber from 'bignumber.js'; import Token from '~/classes/Token'; import { TokenMap } from '~/constants'; import { Beanstalk } from '~/generated'; -import { - LegacyCrate, - LegacyDepositCrate, - FarmerSiloBalance, -} from '~/state/farmer/silo'; +import { LegacyDepositCrate, FarmerSiloBalance } from '~/state/farmer/silo'; /** * @deprecated TOOD: Remove this @@ -50,10 +46,8 @@ export const selectCratesForEnroot = ( encoded: beanstalk.interface.encodeFunctionData('enrootDeposits', [ addr, // fixme: not sure why TS doesn't pick up the type of `crates` here - crates.map((crate: LegacyCrate) => crate.season.toString()), // seasons - crates.map((crate: LegacyCrate) => - unripeTokens[addr].stringify(crate.amount) - ), // amounts + crates.map((crate) => crate.season.toString()), // seasons + crates.map((crate) => unripeTokens[addr].stringify(crate.amount)), // amounts ]), }; }