feat(rpc): add tempo_simulateV1 with TIP-20 token metadata enrichment#3449
feat(rpc): add tempo_simulateV1 with TIP-20 token metadata enrichment#3449
Conversation
Adds `tempo_simulateV1` RPC method that wraps standard `eth_simulateV1` and enriches the response with TIP-20 token metadata (name, symbol, decimals, currency) for all tokens appearing in Transfer event logs. Eliminates the second roundtrip the wallet needs to fetch token info after simulation. Co-authored-by: Georgios Konstantopoulos <17802178+gakonst@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d5428-5f7d-7428-ad0e-ab26a32589b2
Pre-extract TIP-20 addresses from request call targets and resolve metadata concurrently with the simulation via tokio::join!. Only tokens that appear in simulation logs but weren't in the prefetched set trigger a second (small) metadata lookup. Co-Authored-By: Georgios Konstantopoulos <17802178+gakonst@users.noreply.github.com>
Decimals are always 6 for TIP-20 tokens — no need to read from storage. Co-Authored-By: Georgios Konstantopoulos <17802178+gakonst@users.noreply.github.com>
crates/node/src/rpc/simulate.rs
Outdated
| pub struct TempoSimulate<EthApi> { | ||
| eth_api: EthApi, | ||
| } |
There was a problem hiding this comment.
We could consider using a cache since TIP20 metadata is immutable and most calls will likely target set of frequently used tokens. Just a note for the future we can do this in a follow-on PR.
- Use tempo_contracts::precompiles::DECIMALS instead of local const - Move decimals to top-level response (constant across all TIP-20 tokens) - Use HashSet for extra token addresses instead of Vec + sort/dedup Co-Authored-By: 0xKitsune <77890308+0xKitsune@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d54e7-2118-72eb-aa66-24969aad6efc
tempo-contracts was only in dev-dependencies — moved to dependencies so tempo_contracts::precompiles::DECIMALS resolves. Merged duplicate reth_provider imports for nightly fmt. Co-authored-by: 0xKitsune <77890308+0xKitsune@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d54e7-2118-72eb-aa66-24969aad6efc
| #[serde(with = "alloy_serde::quantity")] | ||
| pub decimals: u8, |
There was a problem hiding this comment.
Do we need to include decimals if this is always 6 decimals for all TIP20s?
Uses state_at_block_id_or_latest(block) instead of latest_state() so token metadata is read from the same block the simulation targets. Derives hardfork spec from the target block's timestamp instead of u64::MAX. Co-authored-by: 0xKitsune <77890308+0xKitsune@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d54e7-2118-72eb-aa66-24969aad6efc
mattsse
left a comment
There was a problem hiding this comment.
just for obtaining
"0x20c0...": {
"name": "Path USD",
"symbol": "pUSD",
"decimals": 6,
"currency": "USD"
}
this doesnt really make a lot of sense imo, because all of these are immutable, so it would make more sense to cache these client side imo
| let token = TempoToken::new(eth_api.clone()); | ||
| let eth_ext = TempoEthExt::new(eth_api); | ||
| let eth_ext = TempoEthExt::new(eth_api.clone()); | ||
| let simulate = TempoSimulate::new(eth_api); |
There was a problem hiding this comment.
i think we probably want this to not be enabled by default? same for token namespace and eth_ext
|
Can we figure out a way to merge this in with or without cache by Monday EOD? Impacts wallet performance, I understand the concern that we should just cache it if u guys can take it over |
Adds
tempo_simulateV1RPC method that wrapseth_simulateV1and enriches the response with TIP-20 token metadata (name, symbol, decimals, currency) for all tokens appearing in Transfer event logs. This eliminates the second roundtrip the wallet app needs to fetch token symbols/decimals after simulation.The wallet currently calls
eth_simulateV1withtraceTransfers: trueto get balance diffs as synthetic Transfer logs, then makes separate calls for each token's metadata.tempo_simulateV1returns both in a single response:{ "blocks": [ /* standard eth_simulateV1 blocks */ ], "tokenMetadata": { "0x20c0...": { "name": "Path USD", "symbol": "pUSD", "decimals": 6, "currency": "USD" } } }Callable from viem as
client.request({ method: 'tempo_simulateV1', params: [...] }).Prompted by: georgios