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: Solve solana native token fee issue #160

Merged
merged 1 commit into from
Dec 4, 2024
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 @@ -74,10 +74,12 @@ export const useGetDeBridgeFees = () => {
value: `${formatNumber(Number(protocolFee), 8)} ${nativeToken}`,
});
// Make sure native token can cover the protocol fee
const totalNativeAmount =
selectedToken?.deBridge?.raw?.address === '0x0000000000000000000000000000000000000000'
? BigInt(fees?.fixFee) + parseUnits(sendValue, 18)
: BigInt(fees?.fixFee);
const totalNativeAmount = isNativeToken(
selectedToken?.deBridge?.raw?.address,
fromChain?.chainType,
)
? BigInt(fees?.fixFee) + parseUnits(sendValue, nativeDecimals)
: BigInt(fees?.fixFee);
if (nativeTokenBalance && nativeTokenBalance?.value < totalNativeAmount) {
dispatch(
setRouteError({
Expand Down Expand Up @@ -222,26 +224,6 @@ export const useGetDeBridgeFees = () => {
acc[symbol] += value;
return acc;
}, {} as { [key: string]: number });

if (
fromChain?.chainType === 'solana' &&
isNativeToken(selectedToken?.deBridge?.raw?.address, fromChain?.chainType) &&
nativeToken &&
nativeTokenBalance
) {
const totalNativeTokenCost = Number(result[nativeToken]) + Number(sendValue);
const userNativeTokenBalance = Number(nativeTokenBalance.formatted);

if (userNativeTokenBalance < totalNativeTokenCost) {
dispatch(
setRouteError({
deBridge: `Insufficient ${nativeToken} to cover protocol fee and market maker gas costs`,
}),
);
isDisplayError = true;
}
}

const resultString = Object.keys(result)
.map((symbol) => {
return `${formatFeeAmount(result[symbol])} ${symbol}`;
Expand Down
Loading