Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bean UI - Fixed Pod orders using ETH/WETH #623

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -425,26 +422,31 @@ 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(
`[FillListing] using FarmFromMode = ${finalFromMode}`,
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', [
{
Expand Down Expand Up @@ -499,12 +501,12 @@ const FillListingForm: FC<{
podListing,
signer,
Eth,
Weth,
refetchFarmerField,
refetchFarmerBalances,
balances,
sdk,
beanstalk.interface,
beanstalk.address
]
);

Expand Down