Skip to content

Commit

Permalink
feat: pipeconvert integration finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Sep 23, 2024
1 parent 9862d19 commit 50692ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import WarningAlert from '~/components/Common/Alert/WarningAlert';
import TxnAccordion from '~/components/Common/TxnAccordion';
import StatHorizontal from '~/components/Common/StatHorizontal';

import { ActionType, displayFullBN, transform } from '~/util';
import { ActionType, displayFullBN } from '~/util';
import { useAppSelector } from '~/state';
import { BaseConvertFormProps } from './types';

Expand Down Expand Up @@ -145,7 +145,7 @@ const PipelineConvertFormInner = ({
);

setFieldValue('pipe.structs', advPipeCalls);

setFieldValue('pipe.amountOut', new BigNumber(amountOut.toHuman()));
return {
amountOut,
advPipeCalls
Expand Down Expand Up @@ -178,8 +178,6 @@ const PipelineConvertFormInner = ({
targetToken.address,
data.advPipeCalls
);
const toAmount = transform(result.toAmount, 'bnjs', targetToken);
setFieldValue('pipe.amountOut', toAmount);

setConvertResults({
toAmount: result.toAmount,
Expand Down
36 changes: 25 additions & 11 deletions projects/ui/src/components/Silo/Actions/Convert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const ConvertFormsWrapper = ({ fromToken }: ConvertProps) => {

const pipelineConvertSubmitHandler = usePipelineConvertSubmitHandler({
sdk,
fromToken,
farmerSilo,
middleware,
initialValues,
Expand Down Expand Up @@ -243,9 +244,11 @@ function usePipelineConvertSubmitHandler({
sdk,
farmerSilo,
middleware,
fromToken,
initialValues,
}: {
sdk: BeanstalkSDK;
fromToken: ERC20Token;
farmerSilo: FarmerSilo;
middleware: ReturnType<typeof useFormMiddleware>;
initialValues: ConvertFormValues;
Expand Down Expand Up @@ -276,7 +279,7 @@ function usePipelineConvertSubmitHandler({

const advPipeStructs = values.pipe?.structs || [];
const slippage = values?.settings?.slippage;
const farmerBalances = farmerSilo.balancesSdk.get(tokenIn);
const farmerBalances = farmerSilo.balancesSdk.get(fromToken);
const amountIn = tokenIn?.amount(_amountIn?.toString() || '0'); // amount of from token
const amountOut = tokenOut?.amount(_amountOut?.toString() || '0'); // amount of to token

Expand Down Expand Up @@ -308,16 +311,26 @@ function usePipelineConvertSubmitHandler({
throw new Error('Could not find any crates to convert');
}

// farm.add(
// new sdk.farm.actions.PipelineConvert(
// tokenIn as ERC20Token,
// crates.map((c) => c.stem),
// crates.map((c) => c.amount.toBigNumber()),
// tokenOut as ERC20Token,
// amountOut,
// advPipeStructs
// )
// );
farm.add(() => ({
name: 'pipe-convert',
amountOut: amountOut.toBigNumber(),
prepare: () => ({
target: sdk.contracts.beanstalk.address,
callData: sdk.contracts.beanstalk.interface.encodeFunctionData(
'pipelineConvert',
[
tokenIn.address,
crates.map((c) => c.stem),
crates.map((c) => c.amount.toBigNumber()),
tokenOut.address,
advPipeStructs,
]
),
clipboard: undefined,
}),
decode: () => undefined,
decodeResult: () => undefined,
}));

const gasEstimate = await farm.estimateGas(amountIn, { slippage });
const adjustedGas = Math.round(gasEstimate.toNumber() * 1.2).toString();
Expand Down Expand Up @@ -351,6 +364,7 @@ function usePipelineConvertSubmitHandler({
[
sdk,
account,
fromToken,
farmerSilo.balancesSdk,
initialValues,
middleware,
Expand Down

0 comments on commit 50692ad

Please sign in to comment.