Skip to content

Centralize asset/token resolution behind a single resolver - #2654

Merged
fnando merged 3 commits into
mainfrom
centralize-token-resolution
Jul 23, 2026
Merged

Centralize asset/token resolution behind a single resolver#2654
fnando merged 3 commits into
mainfrom
centralize-token-resolution

Conversation

@fnando

@fnando fnando commented Jul 22, 2026

Copy link
Copy Markdown
Member

What

Introduces a single token resolver in a new config::token module and migrates the scattered asset/token → contract-id derivations onto it, resolving #2652.

  • UnresolvedToken — a token reference parsed from a user string (native/CODE:ISSUER → asset; C… strkey or alias → contract).
  • ResolvedToken { contract_id, kind } where TokenKind is Sac(xdr::Asset) or Contract — the single answer to both "what contract id?" and "is this a SAC, and for which asset?". Helpers: is_sac() / asset().

Migrated call sites:

  • commands::token::args — dropped the old TokenTarget; not_deployed_error is now keyed off ResolvedToken::kind, keeping the sac_not_deployed vs contract_not_found split. args::Error now carries only the two token-aware variants it actually produces.
  • commands::token::{balance,transfer}--id is now UnresolvedToken; both resolve once and thread the ResolvedToken through.
  • commands::contract::{id,deploy}::asset — derive the id (and, for deploy, the wrap-tx asset) via the resolver. Deploy resolves up front, before any RPC, so an invalid asset fails fast.
  • config::alias::resolve_reserved — the reserved native alias now resolves through the shared resolver.

utils::contract_id_hash_from_asset remains the low-level primitive the resolver builds on.

Why

Resolving a token/asset reference to a contract id — and knowing whether it's a Stellar Asset Contract and for which asset — was spread across several overlapping places, with no single type answering both questions. This surfaced in #2651, where native had to be special-cased as a SAC. The resolver makes SAC-awareness consistent everywhere (errors, deploy, id).

Known limitations

snapshot::create is intentionally left unmigrated: that site parses the asset to extract the issuer for account search, not to derive a contract id, so ResolvedToken's shape doesn't fit.

Copilot AI review requested due to automatic review settings July 22, 2026 14:25
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Jul 22, 2026
@fnando fnando self-assigned this Jul 22, 2026
@fnando fnando moved this from Backlog (Not Ready) to Needs Review in DevX Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Centralizes token and Stellar Asset Contract resolution in config::token and migrates token and contract commands to use the shared resolver.

Changes:

  • Adds unresolved/resolved token types with SAC classification.
  • Migrates balance, transfer, asset ID, deployment, and native alias resolution.
  • Preserves token-aware missing-contract errors.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
config/token.rs Implements centralized token resolution.
config/mod.rs Exports the token module.
config/locator.rs Passes locator context to reserved aliases.
config/alias.rs Resolves native through the shared resolver.
commands/token/transfer.rs Uses resolved token metadata.
commands/token/balance.rs Shares resolved tokens across reads.
commands/token/args.rs Classifies missing contracts from resolved tokens.
commands/contract/id/asset.rs Derives SAC IDs through the resolver.
commands/contract/deploy/asset.rs Resolves SAC identity and asset before RPC.
commands/contract/alias/ls.rs Supplies locator context for native aliases.

Comment thread cmd/soroban-cli/src/commands/token/args.rs
Comment thread cmd/soroban-cli/src/commands/contract/id/asset.rs Outdated
Comment thread cmd/soroban-cli/src/commands/contract/deploy/asset.rs Outdated
@leighmcculloch leighmcculloch linked an issue Jul 23, 2026 that may be closed by this pull request
@fnando
fnando force-pushed the centralize-token-resolution branch from c94d536 to 68d851b Compare July 23, 2026 17:55
@fnando
fnando merged commit 9c92633 into main Jul 23, 2026
229 of 230 checks passed
@fnando
fnando deleted the centralize-token-resolution branch July 23, 2026 21:28
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in DevX Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Centralize asset/token resolution behind a single resolver

3 participants