Skip to content

fix: gas bigint throwing#298

Merged
antoncoding merged 3 commits intomasterfrom
fix/rebalane-bigint
Jan 14, 2026
Merged

fix: gas bigint throwing#298
antoncoding merged 3 commits intomasterfrom
fix/rebalane-bigint

Conversation

@antoncoding
Copy link
Copy Markdown
Owner

@antoncoding antoncoding commented Jan 14, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced gas cost calculation precision across the application through refined numeric computation and representation methods. Refactored transaction fee estimation ensures more accurate and reliable cost projections when executing transactions. This update improves the accuracy of fees displayed to users throughout the platform, helping them make better-informed decisions when evaluating transaction costs before confirmation.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jan 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
monarch Ready Ready Preview, Comment Jan 14, 2026 7:42am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

Gas cost constants are converted from regular numbers to BigInt literals, and a decimal gas multiplier (1.4) is replaced with fractional representation using numerator (14) and denominator (10) values across multiple hooks for consistent bigint arithmetic.

Changes

Cohort / File(s) Summary
Gas constants refactor
src/features/markets/components/constants.ts
Gas cost values converted to BigInt literals (180000 → 180000n, etc.); GAS_MULTIPLIER replaced with GAS_MULTIPLIER_NUMERATOR and GAS_MULTIPLIER_DENOMINATOR constants
Gas calculation updates
src/hooks/useMultiMarketSupply.ts, src/hooks/useRebalance.ts, src/hooks/useSupplyMarket.ts, src/hooks/useVaultV2Deposit.ts
Updated gas variable types to bigint | undefined; replaced gas * GAS_MULTIPLIER with (gas * GAS_MULTIPLIER_NUMERATOR) / GAS_MULTIPLIER_DENOMINATOR in transaction payloads

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

bug

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: gas bigint throwing' directly reflects the core change: converting gas cost constants from numbers to BigInt to fix a throwing/error issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/rebalane-bigint


📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ba6cfe and a962578.

📒 Files selected for processing (5)
  • src/features/markets/components/constants.ts
  • src/hooks/useMultiMarketSupply.ts
  • src/hooks/useRebalance.ts
  • src/hooks/useSupplyMarket.ts
  • src/hooks/useVaultV2Deposit.ts
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-12-09T10:06:39.848Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 231
File: src/hooks/useDeployMorphoMarketV1Adapter.ts:3-3
Timestamp: 2025-12-09T10:06:39.848Z
Learning: In Wagmi v3, useConnection is the correct hook to obtain the connected wallet address, chainId, and connection status (isConnected). This replaces the useAccount hook from Wagmi v2. In your code under src/hooks, use: const { address, chainId, isConnected } = useConnection() from 'wagmi' to access the connected wallet information.

Applied to files:

  • src/hooks/useMultiMarketSupply.ts
  • src/hooks/useVaultV2Deposit.ts
  • src/hooks/useRebalance.ts
  • src/hooks/useSupplyMarket.ts
📚 Learning: 2024-11-20T07:19:08.123Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 83
File: src/hooks/useERC20Approval.ts:45-59
Timestamp: 2024-11-20T07:19:08.123Z
Learning: In `src/hooks/useERC20Approval.ts`, the `approve` function intentionally does not wait for the transaction receipt after `sendTransactionAsync` to allow Safe to batch execute transactions.

Applied to files:

  • src/hooks/useVaultV2Deposit.ts
📚 Learning: 2024-10-07T14:38:04.384Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 57
File: src/hooks/useRebalance.ts:112-114
Timestamp: 2024-10-07T14:38:04.384Z
Learning: In `src/hooks/useRebalance.ts`, adding a delay is necessary because Rabby wallet cannot handle sequential requests.

Applied to files:

  • src/hooks/useRebalance.ts
🧬 Code graph analysis (4)
src/hooks/useMultiMarketSupply.ts (1)
src/features/markets/components/constants.ts (3)
  • GAS_COSTS (19-33)
  • GAS_MULTIPLIER_NUMERATOR (37-37)
  • GAS_MULTIPLIER_DENOMINATOR (38-38)
src/hooks/useVaultV2Deposit.ts (1)
src/features/markets/components/constants.ts (2)
  • GAS_MULTIPLIER_NUMERATOR (37-37)
  • GAS_MULTIPLIER_DENOMINATOR (38-38)
src/hooks/useRebalance.ts (1)
src/features/markets/components/constants.ts (3)
  • GAS_COSTS (19-33)
  • GAS_MULTIPLIER_NUMERATOR (37-37)
  • GAS_MULTIPLIER_DENOMINATOR (38-38)
src/hooks/useSupplyMarket.ts (1)
src/features/markets/components/constants.ts (2)
  • GAS_MULTIPLIER_NUMERATOR (37-37)
  • GAS_MULTIPLIER_DENOMINATOR (38-38)
🔇 Additional comments (16)
src/hooks/useSupplyMarket.ts (3)

15-15: Import updated correctly.


166-166: Explicit typing is good.

Clear that gas can be bigint or undefined.


247-247: Gas calculation looks correct.

Multiplication before division preserves precision. Result will be undefined for ETH wrap and Permit2 flows, which is the intended behavior.

src/hooks/useMultiMarketSupply.ts (4)

13-13: Import aligned with new constants.


79-79: Type annotation matches usage.


124-124: Gas calculation handles multiple supplies correctly.

For N supplies: BUNDLER_SUPPLY + SINGLE_SUPPLY * (N-1). Math checks out.


167-167: Consistent with other hooks.

src/hooks/useVaultV2Deposit.ts (3)

13-13: Import updated.


144-144: Type annotation correct.


203-203: Gas calculation consistent with other hooks.

src/hooks/useRebalance.ts (5)

9-9: Import updated.


258-258: Type annotation correct.


318-326: Gas estimation logic is sound.

Base cost plus incremental cost per additional tx. BigInt conversion handles the arithmetic properly.


328-328: Good call on .toString().

BigInt can cause issues with console.log in some runtimes.


344-344: Consistent fractional gas multiplier.

src/features/markets/components/constants.ts (1)

19-38: Solid approach for bigint-safe gas multiplier.

Fractional representation (14n/10n) correctly handles the 1.4x buffer without floating-point issues. The constants are well-documented. Verified that the new GAS_MULTIPLIER_NUMERATOR and GAS_MULTIPLIER_DENOMINATOR are properly imported and used across all relevant hooks, with the correct pattern (gas * NUMERATOR) / DENOMINATOR applied consistently.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jan 14, 2026
@antoncoding antoncoding merged commit 1d24f02 into master Jan 14, 2026
3 checks passed
@antoncoding antoncoding deleted the fix/rebalane-bigint branch January 14, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant