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

[SDK] expose estimateUserOpGasCost #6370

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Feb 28, 2025

Fixes TOOL-3521


PR-Codex overview

This PR introduces a new utility function to estimate the gas cost of user operations, enhances existing functions for better async handling, and updates tests to validate the new functionality.

Detailed summary

  • Added estimateUserOpGasCost() for estimating gas costs of user operations.
  • Updated getEntrypointFromFactory to be exported.
  • Changed isOpStackChain to an async function with additional checks.
  • Enhanced tests to include gas cost estimation.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Feb 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 🛑 Canceled (Inspect) Feb 28, 2025 9:39pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 28, 2025 9:39pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 28, 2025 9:39pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 28, 2025 9:39pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 28, 2025 9:39pm

Copy link

changeset-bot bot commented Feb 28, 2025

🦋 Changeset detected

Latest commit: 46bbfb7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Minor
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@joaquim-verges joaquim-verges marked this pull request as ready for review February 28, 2025 10:31
@joaquim-verges joaquim-verges requested review from a team as code owners February 28, 2025 10:31
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Feb 28, 2025
Copy link

linear bot commented Feb 28, 2025

Copy link
Member Author

joaquim-verges commented Feb 28, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

github-actions bot commented Feb 28, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 46.82 KB (-0.1% 🔽) 937 ms (-0.1% 🔽) 172 ms (+182.05% 🔺) 1.2 s
thirdweb (cjs) 127.18 KB (+0.03% 🔺) 2.6 s (+0.03% 🔺) 254 ms (+51.7% 🔺) 2.8 s
thirdweb (minimal + tree-shaking) 5.6 KB (0%) 112 ms (0%) 68 ms (+1414.18% 🔺) 180 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 26 ms (+1597.33% 🔺) 36 ms
thirdweb/react (minimal + tree-shaking) 19.38 KB (0%) 388 ms (0%) 83 ms (+412.58% 🔺) 471 ms

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 57.65766% with 47 lines in your changes missing coverage. Please review.

Project coverage is 54.71%. Comparing base (56301bc) to head (46bbfb7).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
packages/thirdweb/src/wallets/smart/lib/userop.ts 6.06% 31 Missing ⚠️
packages/thirdweb/src/wallets/smart/lib/bundler.ts 83.87% 10 Missing ⚠️
packages/thirdweb/src/chains/constants.ts 57.14% 6 Missing ⚠️

❌ Your patch status has failed because the patch coverage (57.65%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6370      +/-   ##
==========================================
+ Coverage   54.60%   54.71%   +0.11%     
==========================================
  Files         874      874              
  Lines       54525    54617      +92     
  Branches     3682     3719      +37     
==========================================
+ Hits        29774    29885     +111     
+ Misses      24656    24637      -19     
  Partials       95       95              
Flag Coverage Δ
packages 54.71% <57.65%> (+0.11%) ⬆️
Files with missing lines Coverage Δ
...rdweb/src/transaction/actions/estimate-gas-cost.ts 84.21% <100.00%> (ø)
packages/thirdweb/src/wallets/smart/index.ts 61.03% <100.00%> (ø)
packages/thirdweb/src/chains/constants.ts 82.85% <57.14%> (-17.15%) ⬇️
packages/thirdweb/src/wallets/smart/lib/bundler.ts 71.49% <83.87%> (+4.62%) ⬆️
packages/thirdweb/src/wallets/smart/lib/userop.ts 74.52% <6.06%> (+7.03%) ⬆️

Copy link
Member

@jnsdls jnsdls left a comment

Choose a reason for hiding this comment

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

LGTM minus lint failures

@joaquim-verges joaquim-verges force-pushed the 02-28-_sdk_expose_estimateuseropgascost branch 3 times, most recently from ad087ba to db7490d Compare February 28, 2025 21:23
Comment on lines 187 to 192
gasLimit =
BigInt(userOp.paymasterVerificationGasLimit ?? 0) +
BigInt(userOp.paymasterPostOpGasLimit ?? 0) +
BigInt(userOp.verificationGasLimit ?? 0) +
BigInt(userOp.preVerificationGas ?? 0) +
BigInt(userOp.preVerificationGas ?? 0) +
BigInt(userOp.callGasLimit ?? 0);
Copy link

Choose a reason for hiding this comment

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

There appears to be a duplicate addition of preVerificationGas in the gas limit calculation, which will result in an inflated total gas cost estimate. The line BigInt(userOp.preVerificationGas ?? 0) appears twice in the sum. Removing one instance will provide more accurate gas estimates.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines 187 to 192
gasLimit =
BigInt(userOp.paymasterVerificationGasLimit ?? 0) +
BigInt(userOp.paymasterPostOpGasLimit ?? 0) +
BigInt(userOp.verificationGasLimit ?? 0) +
BigInt(userOp.preVerificationGas ?? 0) +
BigInt(userOp.preVerificationGas ?? 0) +
BigInt(userOp.callGasLimit ?? 0);
Copy link

Choose a reason for hiding this comment

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

preVerificationGas is being added twice in this calculation, which will result in an inflated gas cost estimate. Consider removing one of these duplicate additions to ensure accurate gas cost estimation.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants