From e12bdd95d5441a8d99e4e6f6004d9d70a81a433c Mon Sep 17 00:00:00 2001 From: Dmitry Lobachevsky Date: Mon, 30 Sep 2024 09:39:07 +0200 Subject: [PATCH] fix(dHEDGE V1 Deprecation): disable redeem transaction when gas price is 0 --- .../InputStep/components/SubmitButton.tsx | 16 ++++++++-- .../src/hooks/useBaseFeeAndMaxFeePerGas.tsx | 4 +-- .../withdraw/src/hooks/useRedeemCallConfig.ts | 29 ++++++++++--------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/libs/dhedge/withdraw/src/components/BurnForm/components/InputStep/components/SubmitButton.tsx b/libs/dhedge/withdraw/src/components/BurnForm/components/InputStep/components/SubmitButton.tsx index 6e1042bc..dca0bec7 100644 --- a/libs/dhedge/withdraw/src/components/BurnForm/components/InputStep/components/SubmitButton.tsx +++ b/libs/dhedge/withdraw/src/components/BurnForm/components/InputStep/components/SubmitButton.tsx @@ -31,13 +31,13 @@ export const SubmitButton = ({ disabled }: SubmitButtonProps) => { const { l1token, isError, reset } = useTrackedState(); const needsApproval = useNeedsApproval(); - const config = useRedeemCallConfig(); + const { config, zeroGasFeeParams } = useRedeemCallConfig(); const { data: submitConfig, error: estimateError } = usePrepareContractWrite(config); const { data: submitData, - write: submit, + write, isLoading: isWriteLoading, isSuccess: isWriteSuccess, } = useContractWrite({ @@ -103,6 +103,18 @@ export const SubmitButton = ({ disabled }: SubmitButtonProps) => { onSettled: reset, }); + const submit = () => { + if (zeroGasFeeParams) { + pushNotification({ + title: 'Transaction Cancelled', + content: 'Gas fee is 0. Please reload the page and try again.', + severity: 'info', + }); + return; + } + write(); + }; + if ( !l1token.amount || needsApproval || diff --git a/libs/dhedge/withdraw/src/hooks/useBaseFeeAndMaxFeePerGas.tsx b/libs/dhedge/withdraw/src/hooks/useBaseFeeAndMaxFeePerGas.tsx index 002706fd..e4eea275 100644 --- a/libs/dhedge/withdraw/src/hooks/useBaseFeeAndMaxFeePerGas.tsx +++ b/libs/dhedge/withdraw/src/hooks/useBaseFeeAndMaxFeePerGas.tsx @@ -18,8 +18,8 @@ export const useBaseFeeAndMaxFeePerGas = ({ chainId }: { chainId: number }) => { } const block = await provider.getBlock(blockNumber); - // increase base fee by 15% - const baseFee = block.baseFeePerGas.mul(115).div(100); + // increase base fee by 20% + const baseFee = block.baseFeePerGas.mul(120).div(100); const priorityFeePerGas = ethers.utils.parseUnits('2', 'gwei'); diff --git a/libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts b/libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts index 62307b9d..1807babc 100644 --- a/libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts +++ b/libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts @@ -31,19 +31,22 @@ export const useRedeemCallConfig = () => { }); const ethValue = maxSubmissionCost.add(l2MaxFeePerGas.mul(redeemGasLimit)); return { - functionName: 'redeem', - args: [ - l1token.contract.address, - l2token.contract.address, - l1token.amount.exact, - walletAddress, - encodedArbAdditionalData, - { value: ethValue }, - ], - enabled: !isError && !l1token.amount.exact.isZero() && !needsApproval, - address: l1ComptrollerContract.address, - abi: l1ComptrollerContract.abi, - chainId: l1ComptrollerContract.chainId, + config: { + functionName: 'redeem', + args: [ + l1token.contract.address, + l2token.contract.address, + l1token.amount.exact, + walletAddress, + encodedArbAdditionalData, + { value: ethValue }, + ], + enabled: !isError && !l1token.amount.exact.isZero() && !needsApproval, + address: l1ComptrollerContract.address, + abi: l1ComptrollerContract.abi, + chainId: l1ComptrollerContract.chainId, + }, + zeroGasFeeParams: l1BaseFee.isZero() || l2MaxFeePerGas.isZero(), }; }, [ isError,