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

Fix BSC bridges #5855

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 26 additions & 4 deletions src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from
import { useSwapWarning } from '@/__swaps__/screens/Swap/hooks/useSwapWarning';
import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps';
import { swapsStore, useSwapsStore } from '@/state/swaps/swapsStore';
import { parseAssetAndExtend } from '@/__swaps__/utils/swaps';
import { isUnwrapEth, isWrapEth, parseAssetAndExtend } from '@/__swaps__/utils/swaps';
import { ChainId } from '@/__swaps__/types/chains';
import { RainbowError, logger } from '@/logger';
import { QuoteTypeMap, RapSwapActionParameters } from '@/raps/references';
import { Navigation } from '@/navigation';
import { WrappedAlert as Alert } from '@/helpers/alert';
import Routes from '@/navigation/routesNames';
import { ethereumUtils } from '@/utils';
import { getFlashbotsProvider, getProviderForNetwork, isHardHat } from '@/handlers/web3';
import { getFlashbotsProvider, getIsHardhatConnected, getProviderForNetwork, isHardHat } from '@/handlers/web3';
import { loadWallet } from '@/model/wallet';
import { walletExecuteRap } from '@/raps/execute';
import { queryClient } from '@/react-query';
Expand Down Expand Up @@ -215,6 +215,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {

const { errorMessage } = await walletExecuteRap(wallet, type, {
...parameters,
chainId: getIsHardhatConnected() ? ChainId.hardhat : parameters.chainId,
gasParams,
// @ts-expect-error - collision between old gas types and new
gasFeeParamsBySpeed: gasFeeParamsBySpeed,
Expand Down Expand Up @@ -302,7 +303,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
const q = quote.value;

// TODO: What other checks do we need here?
if (!inputAsset || !outputAsset || !q || (q as QuoteError)?.error) {
if (isSwapping.value || !inputAsset || !outputAsset || !q || (q as QuoteError)?.error) {
return;
}

Expand All @@ -313,13 +314,34 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
const quoteData = q as QuoteTypeMap[typeof type];
const flashbots = (SwapSettings.flashbots.value && inputAsset.chainId === ChainId.mainnet) ?? false;

const isNativeWrapOrUnwrap =
isWrapEth({
buyTokenAddress: quoteData.buyTokenAddress,
sellTokenAddress: quoteData.sellTokenAddress,
chainId: inputAsset.chainId,
}) ||
isUnwrapEth({
buyTokenAddress: quoteData.buyTokenAddress,
sellTokenAddress: quoteData.sellTokenAddress,
chainId: inputAsset.chainId,
});

// Do not deleeeet the comment below 😤
// About to get quote
const parameters: Omit<RapSwapActionParameters<typeof type>, 'gasParams' | 'gasFeeParamsBySpeed' | 'selectedGasFee'> = {
sellAmount: quoteData.sellAmount?.toString(),
buyAmount: quoteData.buyAmount?.toString(),
chainId: inputAsset.chainId,
assetToSell: inputAsset,
assetToBuy: outputAsset,
quote: quoteData,
quote: {
...quoteData,
buyAmountDisplay: isNativeWrapOrUnwrap ? quoteData.buyAmount : quoteData.buyAmountDisplay,
sellAmountDisplay: isNativeWrapOrUnwrap ? quoteData.sellAmount : quoteData.sellAmountDisplay,
Comment on lines +339 to +340
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the logic for overriding these two? I don't think it's necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done on the BX so figured it was necessary. If it's not I can remove it

feeInEth: isNativeWrapOrUnwrap ? '0' : quoteData.feeInEth,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this. The SDK should handle it internally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also brought this over from the BX

fromChainId: inputAsset.chainId,
toChainId: outputAsset.chainId,
},
flashbots,
};

Expand Down
7 changes: 3 additions & 4 deletions src/__swaps__/utils/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,10 @@ export const buildQuoteParams = ({

return {
source: source === 'auto' ? undefined : source,
swapType: isCrosschainSwap ? SwapType.crossChain : SwapType.normal,
fromAddress: currentAddress,
chainId: inputAsset.chainId,
toChainId: isCrosschainSwap ? outputAsset.chainId : inputAsset.chainId,
fromAddress: currentAddress,
sellTokenAddress: inputAsset.isNativeAsset ? ETH_ADDRESS : inputAsset.address,
buyTokenAddress: outputAsset.isNativeAsset ? ETH_ADDRESS : outputAsset.address,

// TODO: Handle native input cases below
sellAmount:
lastTypedInput === 'inputAmount' || lastTypedInput === 'inputNativeValue'
Expand All @@ -758,5 +755,7 @@ export const buildQuoteParams = ({
: undefined,
slippage: Number(slippage),
refuel: false,
swapType: isCrosschainSwap ? SwapType.crossChain : SwapType.normal,
toChainId: isCrosschainSwap ? outputAsset.chainId : inputAsset.chainId,
};
};
Loading