Skip to content

fix: Safe deployment gas estimation on Arbitrum#219

Merged
premiumjibles merged 5 commits into
mainfrom
fix/safe-deployment-gas-estimation
Mar 23, 2026
Merged

fix: Safe deployment gas estimation on Arbitrum#219
premiumjibles merged 5 commits into
mainfrom
fix/safe-deployment-gas-estimation

Conversation

@premiumjibles
Copy link
Copy Markdown
Contributor

@premiumjibles premiumjibles commented Mar 20, 2026

Summary

  • Add explicit estimateGas() + 20% buffer before sending Safe deployment transactions
  • Fixes first-time Safe deployments reverting with out-of-gas on Arbitrum (234K allocated, ~350K+ needed)
  • Matches the existing gas estimation pattern used in simulation.ts for EOA transactions

Test plan

  • Deploy a new Safe on Arbitrum — should no longer revert with out-of-gas
  • Deploy a new Safe on Ethereum mainnet — should still work as before
  • Verify bun run type-check and bun test pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved conversation persistence with automatic fallback recovery to prevent user data loss.
  • Improvements

    • Stablecoin assets in portfolio now exclude 24h price change indicators.
    • Removed loading placeholders from asset metrics.
    • Enhanced transaction processing reliability.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 20, 2026

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

Project Deployment Actions Updated (UTC)
shapeshift-agentic Ready Ready Preview, Comment Mar 23, 2026 2:45am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 22, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0c29579-fce2-4224-b39a-00b69c16b16f

📥 Commits

Reviewing files that changed from the base of the PR and between f9133e6 and 1b4b2c8.

📒 Files selected for processing (11)
  • apps/agentic-chat/src/components/Portfolio/GroupedAssetRow.tsx
  • apps/agentic-chat/src/components/Portfolio/PortfolioAssetRow.tsx
  • apps/agentic-chat/src/components/tools/GetAssetsUI.tsx
  • apps/agentic-chat/src/lib/isStablecoin.ts
  • apps/agentic-chat/src/lib/safe/executeSafeTransaction.ts
  • apps/agentic-chat/src/lib/safe/index.ts
  • apps/agentic-chat/src/lib/safe/safeFactory.ts
  • apps/agentic-chat/src/lib/safe/safeModules.ts
  • apps/agentic-chat/src/lib/safe/types.ts
  • apps/agentic-chat/src/main.tsx
  • apps/agentic-chat/src/stores/chatStore.ts

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

Changes introduce stablecoin detection to conditionally render price-change indicators, enhance Safe transaction execution with a composite provider pattern for read/write routing, remove loading state from asset metrics, implement persistent storage with IDB-to-localStorage fallback recovery, and add browser storage persistence requests during app bootstrap.

Changes

Cohort / File(s) Summary
Stablecoin Detection
apps/agentic-chat/src/lib/isStablecoin.ts, apps/agentic-chat/src/components/Portfolio/GroupedAssetRow.tsx, apps/agentic-chat/src/components/Portfolio/PortfolioAssetRow.tsx
New utility module to identify stablecoin symbols; applied conditionally in asset row components to suppress 24h price-change percent display for stablecoins.
Asset Metrics UI
apps/agentic-chat/src/components/tools/GetAssetsUI.tsx
Removed Skeleton loading state and isLoading prop from StatMetric; metrics now render directly without placeholder UI support.
Safe Provider Composition
apps/agentic-chat/src/lib/safe/types.ts, apps/agentic-chat/src/lib/safe/index.ts, apps/agentic-chat/src/lib/safe/executeSafeTransaction.ts, apps/agentic-chat/src/lib/safe/safeFactory.ts, apps/agentic-chat/src/lib/safe/safeModules.ts
Introduced createSafeProvider to route read-only RPC methods via public client fallback while delegating other operations to wallet provider; all Safe execution paths now use composite provider instead of raw provider. Gas estimation added to deployment flow.
Storage Persistence
apps/agentic-chat/src/main.tsx, apps/agentic-chat/src/stores/chatStore.ts
Added browser storage persistence request; enhanced IDB operations with error handling and localStorage backup/recovery mechanism for conversation state during hydration.

Sequence Diagrams

sequenceDiagram
    participant App
    participant CompositeProvider as Composite Provider
    participant PublicClient as Public Client (RPC)
    participant WalletProvider as Wallet Provider
    participant SafeKit as Safe.init()

    App->>CompositeProvider: createSafeProvider(chainId, provider)
    CompositeProvider->>SafeKit: Pass composite provider
    
    Note over App,SafeKit: Execution phase
    App->>CompositeProvider: request(read-only method)
    CompositeProvider->>PublicClient: Forward eth_call, eth_getCode, etc.
    PublicClient-->>CompositeProvider: Response
    CompositeProvider-->>App: Return result
    
    App->>CompositeProvider: request(other method)
    CompositeProvider->>WalletProvider: Forward transaction/write
    WalletProvider-->>CompositeProvider: Response
    CompositeProvider-->>App: Return result
Loading
sequenceDiagram
    participant Store as Chat Store
    participant IDB as IndexedDB
    participant LocalStorage as localStorage
    participant Hydration as Rehydrate Callback

    Store->>IDB: Read conversations on init
    
    alt IDB Read Success
        IDB-->>Store: Conversations loaded
        alt Conversations empty
            Store->>LocalStorage: Read backup
            LocalStorage-->>Store: Fallback data
            Store->>Store: Validate & assign backup
        else Conversations present
            Store->>Store: Use IDB data
        end
    else IDB Read Fails
        IDB-->>Store: Error logged
        Store->>LocalStorage: Attempt localStorage recovery
        LocalStorage-->>Store: Backup data
        Store->>Store: Validate & assign backup
    end
    
    Store->>Hydration: Mark hydrationVerified = true
    Hydration->>IDB: Enable subsequent writes
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A composite hop through Safe's new lanes,
Read paths split wide, write paths remain,
Storage backed up by cautious design,
Stablecoins shine without the % sign,
Persistence blooms—no data shall fall! 🌟

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/safe-deployment-gas-estimation

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.

premiumjibles and others added 3 commits March 23, 2026 07:22
Safe deployments on Arbitrum revert with out-of-gas because the SDK's
createSafeDeploymentTransaction() returns no gas fields and wallet
estimation underestimates. Add estimateGas() + 20% buffer before
sendTransaction, matching the existing pattern in simulation.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalletConnect wallets (e.g. ShapeShift native) don't properly relay
read-only RPC calls like eth_call and eth_getCode, causing Safe SDK
init to fail with "Missing or invalid parameters. Failed to fetch
Version". Creates a composite provider that routes reads through a
public RPC (with viem fallback transport for resilience) while keeping
write/sign operations on the wallet provider.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…licate RPC transports

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@premiumjibles premiumjibles marked this pull request as ready for review March 23, 2026 02:46
@premiumjibles premiumjibles merged commit 5b1fc45 into main Mar 23, 2026
4 checks passed
@premiumjibles premiumjibles deleted the fix/safe-deployment-gas-estimation branch March 23, 2026 02:46
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.

1 participant