Skip to content

add: new gas defaults#263

Merged
L03TJ3 merged 3 commits into
masterfrom
fix/celo-new-gas-pricing
Apr 6, 2026
Merged

add: new gas defaults#263
L03TJ3 merged 3 commits into
masterfrom
fix/celo-new-gas-pricing

Conversation

@sirpy
Copy link
Copy Markdown
Contributor

@sirpy sirpy commented Apr 5, 2026

Summary by Sourcery

Update gas fee handling to use provider fee data with sensible defaults and adjust consumers accordingly.

New Features:

  • Expose full fee data (gasPrice, maxFeePerGas, maxPriorityFeePerGas, lastBaseFeePerGas) from useGasFees instead of only gasPrice.

Enhancements:

  • Initialize gas fee state with higher default values and asynchronously refresh from the connected provider.
  • Simplify default gas overrides in useContractFunctionWithDefaultGasFees to derive max fees from the current gasPrice instead of hardcoded per-chain values.
  • Update claim and faucet hooks to derive minimum balance from the shared useGasFees hook rather than local gasPrice defaults.
  • Change Storybook Web3 wrapper to use Celo as the read-only chain instead of XDC.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In useGasFees, the library.getFeeData() call is not guarded against errors or rejection; consider adding a .catch or try/catch with a safe fallback to avoid leaving the hook stuck with stale defaults if the RPC call fails.
  • The comment in useContractFunctionWithDefaultGasFees says to 'use gasPrice value instead of maxFeePerGas' but the implementation sets maxFeePerGas from gasFees.gasPrice; it would be clearer either to update the comment or explicitly set both gasPrice and maxFeePerGas to reflect the intended behavior.
  • The initial fees state in useGasFees is cast as FeeData, which can hide mismatches if FeeData’s shape changes; consider constructing a fully typed FeeData object without the type assertion to let the compiler catch potential discrepancies.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `useGasFees`, the `library.getFeeData()` call is not guarded against errors or rejection; consider adding a `.catch` or try/catch with a safe fallback to avoid leaving the hook stuck with stale defaults if the RPC call fails.
- The comment in `useContractFunctionWithDefaultGasFees` says to 'use gasPrice value instead of maxFeePerGas' but the implementation sets `maxFeePerGas` from `gasFees.gasPrice`; it would be clearer either to update the comment or explicitly set both `gasPrice` and `maxFeePerGas` to reflect the intended behavior.
- The initial `fees` state in `useGasFees` is cast as `FeeData`, which can hide mismatches if `FeeData`’s shape changes; consider constructing a fully typed `FeeData` object without the type assertion to let the compiler catch potential discrepancies.

## Individual Comments

### Comment 1
<location path="packages/sdk-v2/src/sdk/claim/react.ts" line_range="78-79" />
<code_context>

-  const { gasPrice = BigNumber.from(25.001e9) } = useGasFees();
-  const minBalance = BigNumber.from(chainId === 42220 ? "250000" : "150000").mul(gasPrice);
+  const fees = useGasFees();
+  const minBalance = BigNumber.from(chainId === 42220 ? "250000" : "150000").mul(fees?.gasPrice ?? 0);
   const signer = (library as ethers.providers.JsonRpcProvider)?.getSigner();

</code_context>
<issue_to_address>
**question (bug_risk):** Align minBalance fallback with the default values used in useGasFees to avoid silent behavior changes.

This hook used to default `gasPrice` to `25.001e9` on Celo; now it effectively falls back to `0` via `fees?.gasPrice ?? 0`, while `useGasFees` itself seeds `gasPrice` to `30e9`. To avoid a zero `minBalance` and keep behavior consistent with other call sites, consider either relying on the `fees` default (dropping `?? 0`) or using the same numeric fallback as `useGasFees` here.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +78 to +79
const fees = useGasFees();
const minBalance = BigNumber.from(chainId === 42220 ? "250000" : "150000").mul(fees?.gasPrice ?? 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

question (bug_risk): Align minBalance fallback with the default values used in useGasFees to avoid silent behavior changes.

This hook used to default gasPrice to 25.001e9 on Celo; now it effectively falls back to 0 via fees?.gasPrice ?? 0, while useGasFees itself seeds gasPrice to 30e9. To avoid a zero minBalance and keep behavior consistent with other call sites, consider either relying on the fees default (dropping ?? 0) or using the same numeric fallback as useGasFees here.

Comment thread packages/sdk-v2/src/sdk/base/hooks/useGasFees.ts
@L03TJ3 L03TJ3 merged commit b1caf28 into master Apr 6, 2026
4 checks passed
@L03TJ3 L03TJ3 deleted the fix/celo-new-gas-pricing branch April 6, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants