Skip to content

feat(aggkit): resolve token origin and wrapped tokens on-chain - #43

Merged
joanestebanr merged 4 commits into
mainfrom
feat/token-equivalents-pm-31
Oct 6, 2026
Merged

joanestebanr merged 4 commits into
mainfrom
feat/token-equivalents-pm-31

Conversation

@joanestebanr

Copy link
Copy Markdown
Contributor

Context

Needed by agglayer/agglayer-dev-ui#31: when the user changes "Bridge from", the UI must show the tokens it already knows in their wrapped version on that network, even when the wrapped token was created after the token was added.

Changes

Two on-chain helpers on AggkitBridgeAggregator, built on reads native/bridge already exposes:

  • getTokenOrigin(tokenAddress, networkId) reads wrappedTokenToTokenInfo on that network's bridge and returns { originNetwork, originTokenAddress, isWrapped }. A zero origin address means the token originates on that network (origin network 0 is L1 and is valid).
  • getWrappedTokens({ networkId, origins }) reads getTokenWrappedAddress for each origin and returns found / absent / error per entry, in order. One failing lookup does not reject the batch. If networkId is the token's origin network no call is made.

Why on-chain and not /token-mappings: it does not depend on a bridge-service syncer being up to date (a lagging syncer would answer "no mapping" for a wrapped token that exists) and needs no aggkit change. absent is not final: the wrapped token appears after the first bridge to that network.

getTokenOrigin does not prove the address is a token (an unknown address also reads as "not wrapped"); callers validate first, e.g. with getTokenMetadata. Both methods need the network registered with a bridgeAddress.

Also bumps the version to 1.0.0-beta.33, following the repo's convention.

Testing

  • npx vitest run: 213 tests pass, 8 of them new (origin: wrapped / not wrapped / no bridge address; wrapped tokens: found+absent+origin-network short-circuit, per-entry error, no bridge address).
  • tsc --noEmit clean.

Not verified: reads against a live network. The lint-staged hook reformats the whole of types.ts; I dropped that in a separate commit, as an earlier PR did.

🤖 Generated with Claude Code

joanestebanr and others added 3 commits October 5, 2026 11:18
Add AggkitBridgeAggregator.getTokenOrigin and getWrappedTokens, built on
the bridge's wrappedTokenToTokenInfo and getTokenWrappedAddress reads.
They let a UI map a token known on one network to its address on another
without depending on bridge-service sync state.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@joanestebanr

Copy link
Copy Markdown
Contributor Author

@claude review

- getTokenOrigin: answer the native token (zero address) without an
  on-chain read
- getWrappedTokens: report the native token on another network as error
  instead of absent; reuse one Bridge reader per call; return only
  originNetwork/originTokenAddress from each input

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@joanestebanr joanestebanr self-assigned this Oct 6, 2026
@joanestebanr
joanestebanr merged commit 16469d7 into main Oct 6, 2026
4 checks passed
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.

2 participants