From 6e1b455ffa6b2f597abfcf6e6406a6a6e24d80cc Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:50:13 -0300 Subject: [PATCH 1/2] Bean UI - Fixed Pod orders with ETH/WETH --- .../PodsV2/Actions/Buy/FillListingForm.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx b/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx index 8ac49e83af..d52cf20bd7 100644 --- a/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx +++ b/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx @@ -412,10 +412,7 @@ const FillListingForm: FC<{ finalFromMode = optimizeFromMode(amountBeans, balances[Bean.address]); farm = sdk.farm.create(); tokenInNew = sdk.tokens.BEAN; // FIXME - } - - /// Swap to BEAN and buy - else if (tokenIn === Eth || tokenIn === Weth) { + } else { /// Swap to BEAN and buy // Require a quote if (!formData.amountOut) throw new Error(`No quote available for ${formData.token.symbol}`); @@ -425,19 +422,13 @@ const FillListingForm: FC<{ const swap = sdk.swap.buildSwap( tokenInNew, sdk.tokens.BEAN, - tokenIn === Weth - ? optimizeFromMode(formData.amountOut, balances[Weth.address]) - : FarmFromMode.EXTERNAL + optimizeFromMode(formData.amount, balances[tokenIn.address]) ); // At the end of the Swap step, the assets will be in our INTERNAL balance. // The Swap decides where to route them from (see handleQuote). finalFromMode = FarmFromMode.INTERNAL_TOLERANT; farm = swap.getFarm(); - } else { - throw new Error( - `Filling a Listing via ${tokenIn.symbol} is not currently supported` - ); } console.debug( @@ -445,6 +436,17 @@ const FillListingForm: FC<{ podListing ); + // If not using Bean, add Bean approval step after conversion + if (tokenIn !== Bean) { + farm.add((amountInStep) => + beanstalk.interface.encodeFunctionData('approveToken', [ + beanstalk.address, + Bean.address, + amountInStep + ]) + ); + } + farm.add((amountInStep) => beanstalk.interface.encodeFunctionData('fillPodListing', [ { @@ -499,12 +501,12 @@ const FillListingForm: FC<{ podListing, signer, Eth, - Weth, refetchFarmerField, refetchFarmerBalances, balances, sdk, beanstalk.interface, + beanstalk.address ] ); From 6de81e8d74adcf538df2711e0415235c76132586 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sun, 3 Sep 2023 23:26:04 -0300 Subject: [PATCH 2/2] Fixed pre-fill swap --- .../PodsV2/Actions/Buy/FillListingForm.tsx | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx b/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx index d52cf20bd7..42014cc7fe 100644 --- a/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx +++ b/projects/ui/src/components/Market/PodsV2/Actions/Buy/FillListingForm.tsx @@ -371,7 +371,7 @@ const FillListingForm: FC<{ // Checks if (!podListing) throw new Error('No Pod Listing found'); - if (!signer) throw new Error('Connect a wallet'); + if (!signer || !account) throw new Error('Connect a wallet'); if (values.tokens.length > 1) throw new Error('Only one input token supported'); if ( @@ -422,12 +422,14 @@ const FillListingForm: FC<{ const swap = sdk.swap.buildSwap( tokenInNew, sdk.tokens.BEAN, - optimizeFromMode(formData.amount, balances[tokenIn.address]) + account, + optimizeFromMode(formData.amount, balances[tokenIn.address]), + FarmToMode.INTERNAL ); // At the end of the Swap step, the assets will be in our INTERNAL balance. // The Swap decides where to route them from (see handleQuote). - finalFromMode = FarmFromMode.INTERNAL_TOLERANT; + finalFromMode = FarmFromMode.INTERNAL; farm = swap.getFarm(); } @@ -436,17 +438,6 @@ const FillListingForm: FC<{ podListing ); - // If not using Bean, add Bean approval step after conversion - if (tokenIn !== Bean) { - farm.add((amountInStep) => - beanstalk.interface.encodeFunctionData('approveToken', [ - beanstalk.address, - Bean.address, - amountInStep - ]) - ); - } - farm.add((amountInStep) => beanstalk.interface.encodeFunctionData('fillPodListing', [ { @@ -506,7 +497,7 @@ const FillListingForm: FC<{ balances, sdk, beanstalk.interface, - beanstalk.address + account ] );