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(dHEDGE V1 Deprecation): disable redeem transaction when gas price… #311

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 ||
Expand Down
4 changes: 2 additions & 2 deletions libs/dhedge/withdraw/src/hooks/useBaseFeeAndMaxFeePerGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
29 changes: 16 additions & 13 deletions libs/dhedge/withdraw/src/hooks/useRedeemCallConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading