Skip to content

Conversation

@Foulks-Plb
Copy link
Contributor

Some data can be considered static and does not need to be fetched at a specific block on a regular basis.

Quick win: This PR introduces a small optimization by treating token metadata and the feeRecipient address as static, avoiding unnecessary refetching every 5 seconds.

@Foulks-Plb Foulks-Plb self-assigned this Jan 21, 2026
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: 1dd0c26970

ℹ️ 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".

Comment on lines 54 to 58
{
token,
chainId,
blockTag,
blockNumber,
deployless,
account,

Choose a reason for hiding this comment

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

P1 Badge Include blockNumber in token query key

The query key now omits blockNumber/blockTag, so React Query will reuse cached token data across different historical blocks even when callers pass a block-specific read. That breaks per-block accuracy for dynamic token data such as wstETH’s stEthPerToken in fetchToken() (packages/blue-sdk-viem/src/fetch/Token.ts), and can yield stale wrap/unwrap conversions in simulations or historical snapshots. Please keep block-specific parameters in the key (or explicitly document and guard against dynamic tokens) to avoid cross-block cache pollution.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think it’s indeed preferable to keep blockNumber and blockTag in the queryKey so we preserve the previous logic if it’s needed later.

Comment on lines 144 to 148
const feeRecipient = useReadContract({
...parameters,
blockNumber: block?.number,
address: morpho,
abi: blueAbi,
functionName: "feeRecipient",

Choose a reason for hiding this comment

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

P1 Badge Query feeRecipient at the requested block

The feeRecipient read no longer includes blockNumber, so when useSimulationState is given a historical block, the fee recipient is fetched at the latest chain head instead of that block. This can mis-assign accrued fees in historical simulations because feeRecipient is mutable (see setFeeRecipient in IMorpho). Consider restoring blockNumber: block?.number or documenting that feeRecipient is always “latest” and excluding it from historical simulations.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

@Foulks-Plb Foulks-Plb Jan 21, 2026

Choose a reason for hiding this comment

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

This is intentional in this case, but if it doesn’t align with the general vision of the useSimulationState function, let me know @morpho-org/sdk-engineers and we can copy this function into the consumer app with these modifications.

Copy link
Collaborator

@oumar-fall oumar-fall left a comment

Choose a reason for hiding this comment

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

You will now query these data at latest block all the time, this will at best have same RPC usage (it can even increase it)

This is the opposite of what you want to achieve

UPDATE:
It wouldn't be the case if you don't rely on wagmi automatic refetching (if you use blocks to refetch)

@Foulks-Plb Foulks-Plb closed this Jan 22, 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.

3 participants