Skip to content

feat: add fetchHoldings to blue-sdk-viem#515

Closed
remiroyc wants to merge 4 commits intomainfrom
add-fetch-holdings
Closed

feat: add fetchHoldings to blue-sdk-viem#515
remiroyc wants to merge 4 commits intomainfrom
add-fetch-holdings

Conversation

@remiroyc
Copy link
Contributor

@remiroyc remiroyc commented Feb 19, 2026

Summary

  • Adds fetchHoldings(user, tokens, client, parameters?) to @morpho-org/blue-sdk-viem — a batch function that fetches holdings for multiple tokens in parallel, reusing the existing fetchHolding primitive.

Why

Today in consumer apps, holdings are fetched at render time (via React Query) but consumed later at click time (for encoding/signing). Nothing guarantees data freshness at the moment of usage.

This is particularly problematic for ERC-2612 permit nonces: erc2612Nonce is captured when getRequirements() runs, but the user may click "Continue" minutes later. By then, the nonce can be stale (e.g. if the user signed another permit in another tab), causing the transaction to revert.

fetchHoldings gives consumers a simple way to re-fetch holdings right before encoding, without any React dependency:

const freshHoldings = await fetchHoldings(user, tokens, client);
// then encode with fresh data

This decouples data freshness from React Query cache timing and fixes the stale-nonce class of bugs at the architectural level.

Test plan

  • pnpm --filter @morpho-org/blue-sdk-viem build passes (type-check + build)
  • Integration: consumer app calls fetchHoldings before encoding to get fresh erc2612Nonce

🤖 Generated with Claude Code

Adds a batch fetch function that retrieves holdings for multiple tokens
in parallel, reusing the existing fetchHolding primitive. This enables
consumers to refresh user holdings at the point of use (e.g. before
encoding transactions) without depending on React Query cache freshness.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c11dfe4312

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Avoids N redundant getChainId RPC calls when fetching holdings for N
tokens in parallel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@remiroyc
Copy link
Contributor Author

@codex review

No need for a separate file — fetchHoldings is a thin wrapper over
fetchHolding and belongs in the same module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@remiroyc
Copy link
Contributor Author

Closing — fetchHoldings is trivial consumer-side code, no need to add it to the SDK. The real fix for stale nonces belongs in consumer-sdk's encodeErc20Permit.

@remiroyc remiroyc closed this Feb 19, 2026
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