Skip to content

Commit

Permalink
Merge pull request #311 from mstable/fix/disable-dhedge-v1-redeem-tra…
Browse files Browse the repository at this point in the history
…nsaction-when-gas-price-is-zero

fix(dHEDGE V1 Deprecation): disable redeem transaction when gas price…
  • Loading branch information
dimlbc authored Oct 1, 2024
2 parents 4f87429 + e12bdd9 commit 932ccbe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
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

0 comments on commit 932ccbe

Please sign in to comment.