Skip to content

feat: TIP-1022 virtual address forwarding detection#167

Draft
decofe wants to merge 7 commits intomainfrom
mallesh/tip-1022-virtual-address-support
Draft

feat: TIP-1022 virtual address forwarding detection#167
decofe wants to merge 7 commits intomainfrom
mallesh/tip-1022-virtual-address-support

Conversation

@decofe
Copy link
Copy Markdown
Member

@decofe decofe commented Apr 14, 2026

Summary

Annotates indexed logs with is_virtual_forward so downstream consumers (explorer, tidx.ts) can distinguish the two-hop Transfer events emitted by TIP-1022 virtual address forwarding.

Also includes additive DB migrations for existing PostgreSQL and ClickHouse deployments.

Motivation

TIP-1022 virtual addresses emit two Transfer events per deposit: sender → virtualAddr (attribution hop) and virtualAddr → master (forwarding hop). Without annotation at the indexer level, the explorer and any tidx.ts consumer will:

  • Double-count every virtual deposit as two separate transfers
  • Show misleading balance changes for virtual addresses
  • Inflate holder counts and transfer activity metrics

This PR adds detection at the indexer layer so consumers can filter with WHERE is_virtual_forward = false to exclude forwarding hops, or include them when they need deposit attribution.

TODO (follow-up)

  • Add a DB migration script for existing deployments
  • Update tidx.ts query builder to expose is_virtual_forward filter
  • Explorer: use the flag to collapse two-hop Transfer displays
  • If needed, add a dedicated deposit-attribution sink/table written directly during indexing

Prompted by: mallesh

decofe and others added 7 commits April 17, 2026 02:13
Add is_virtual_forward column to logs table and detection logic to
identify two-hop Transfer event pairs from virtual address forwarding.

When a TIP-20 transfer targets a virtual address, the precompile emits
two Transfer events: sender→virtualAddr (attribution) and
virtualAddr→master (forwarding). Without annotation, downstream
consumers double-count transfers, inflate holder counts, and can't
attribute deposits to specific users.

Changes:
- src/virtual_address.rs: detection logic + 10 unit tests
- types.rs: add is_virtual_forward to LogRow
- decoder.rs: default to false on decode
- engine.rs: mark_virtual_forward_hops after log decoding (all 4 paths)
- writer.rs: include column in PG COPY BINARY (both write_logs and write_batch)
- ch_sink.rs: include column in ClickHouse wire format
- sink.rs: read column in CH backfill fetch_logs
- db/logs.sql + db/clickhouse/logs.sql: schema additions

Co-authored-by: malleshpai <5857042+malleshpai@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d8d8d-a38a-727b-ab3e-125654f1e65a
@o-az o-az force-pushed the mallesh/tip-1022-virtual-address-support branch from 9cc4094 to 5ac34eb Compare April 17, 2026 09:13
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