Skip to content

Commit

Permalink
wip: incomplete refactors to claim/plant and do x classes
Browse files Browse the repository at this point in the history
  • Loading branch information
silochad committed Jun 30, 2023
1 parent 2677e62 commit fe642ce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 45 deletions.
6 changes: 3 additions & 3 deletions projects/ui/src/lib/Txn/FarmSteps/silo/ConvertFarmStep.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
BeanstalkSDK,
Deposit,
StepGenerator,
Token,
TokenSiloBalance,
TokenValue,
} from '@beanstalk/sdk';
import { ethers } from 'ethers';
Expand All @@ -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;
Expand All @@ -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,
Expand Down
22 changes: 7 additions & 15 deletions projects/ui/src/lib/Txn/FarmSteps/silo/TransferFarmStep.ts
Original file line number Diff line number Diff line change
@@ -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<typeof WithdrawFarmStep['calculateWithdraw']>;

export class TransferFarmStep extends FarmStep {
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -79,7 +71,7 @@ export class TransferFarmStep extends FarmStep {
this._account,
toAddress,
this._token.address,
seasons,
stems,
amounts
);
console.debug(
Expand Down
25 changes: 9 additions & 16 deletions projects/ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts
Original file line number Diff line number Diff line change
@@ -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<typeof WithdrawFarmStep['calculateWithdraw']>;

export class WithdrawFarmStep extends FarmStep {
Expand All @@ -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;
Expand Down Expand Up @@ -52,24 +44,25 @@ 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]
),
});
} else {
this.pushInput({
input: new this._sdk.farm.actions.WithdrawDeposits(
this._token.address,
seasons,
stems,
amounts
),
});
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions projects/ui/src/lib/Txn/Interface/PlantAndDoX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,23 @@ export default class PlantAndDoX {
const grownStalk = STALK.amount(0);

// asTV => as DepositCrate<TokenValue> 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,
};

return crate;
},

// as DepositCrate from UI;
bigNumber(
sdk: BeanstalkSDK,
Expand Down
12 changes: 3 additions & 9 deletions projects/ui/src/util/Crates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
]),
};
}
Expand Down

0 comments on commit fe642ce

Please sign in to comment.