Skip to content

Support Stellar token IDs with 'issuer::code'#993

Merged
gemcoder21 merged 2 commits intomainfrom
stellar-usdc-fix
Mar 6, 2026
Merged

Support Stellar token IDs with 'issuer::code'#993
gemcoder21 merged 2 commits intomainfrom
stellar-usdc-fix

Conversation

@0xh3rman
Copy link
Collaborator

@0xh3rman 0xh3rman commented Mar 6, 2026

  • Allow Stellar token IDs to be either a 56-char issuer or an issuer::symbol pair when formatting token IDs.
  • Update mapping to build Stellar asset IDs via AssetId::sub_token_id instead of the previous "{code}-{issuer}" string, and update the USDC constant to include the ::USDC suffix.
  • Remove the now-unused map_token_balances_by_ids helper and add tests for the new Stellar format.
  • Files changed:
    • chain_primitives/src/token_id.rs
    • gem_stellar/src/provider/balances_mapper.rs
    • primitives/src/asset_constants.rs

Allow Stellar token IDs to be either a 56-char issuer or an issuer::symbol pair when formatting token IDs. Update mapping to build Stellar asset IDs via AssetId::sub_token_id instead of the previous "{code}-{issuer}" string, and update the USDC constant to include the ::USDC suffix. Remove the now-unused map_token_balances_by_ids helper and add tests for the new Stellar format. Files changed: chain_primitives/src/token_id.rs, gem_stellar/src/provider/balances_mapper.rs, primitives/src/asset_constants.rs.
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 6, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/chain_primitives/src/token_id.rs  12% smaller
  crates/gem_stellar/src/provider/balances_mapper.rs  2% smaller
  crates/primitives/src/asset_constants.rs  0% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the handling of Stellar token identifiers by introducing support for a more explicit issuer::code format. This change improves the precision of asset identification within the Stellar ecosystem and streamlines the internal construction of asset IDs. It also includes a cleanup of unused code and updates a relevant constant to reflect the new formatting convention.

Highlights

  • Stellar Token ID Format: The format_token_id function for Stellar now supports token IDs in the issuer::code format, in addition to the existing issuer only format. This allows for more specific identification of Stellar assets.
  • Stellar Asset ID Construction: The internal logic for constructing Stellar asset IDs has been updated to use AssetId::sub_token_id with the issuer and asset code, replacing the previous string formatting approach.
  • USDC Stellar Constant Update: The USDC_STELLAR_ASSET_ID constant has been modified to explicitly include the ::USDC suffix, aligning with the new token ID formatting.
  • Code Removal: The map_token_balances_by_ids helper function, which was no longer needed, has been removed from the Stellar balances mapper.
  • New Tests: New unit tests have been added to validate the updated Stellar token ID formatting logic, covering both valid and invalid issuer::code and issuer only formats.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • crates/chain_primitives/src/token_id.rs
    • Modified format_token_id to accept Stellar token IDs in issuer::code format.
    • Added new tests for Stellar token ID formatting, covering various valid and invalid inputs.
  • crates/gem_stellar/src/provider/balances_mapper.rs
    • Updated Stellar token ID construction to use AssetId::sub_token_id instead of string concatenation.
    • Removed the map_token_balances_by_ids helper function as it is no longer required.
  • crates/primitives/src/asset_constants.rs
    • Updated the USDC_STELLAR_ASSET_ID constant to include the ::USDC suffix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for Stellar token IDs in the issuer::code format, in addition to the existing issuer-only format. The changes correctly update the token ID formatting logic, the asset constant for Stellar USDC, and the balance mapping to use the new format. The removal of the unused map_token_balances_by_ids function is a good cleanup. I've added one suggestion to improve performance in the balance mapping logic.

// Token balances
if let (Some(asset_issuer), Some(asset_code)) = (&balance.asset_issuer, &balance.asset_code) {
let token_id = format!("{}-{}", asset_code, asset_issuer);
let token_id = AssetId::sub_token_id(&[asset_issuer.clone(), asset_code.clone()]);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved performance and conciseness, consider using format! directly. This avoids cloning strings and allocating an intermediate array. While this hardcodes the :: separator, it's more efficient for this two-part token ID construction.

Suggested change
let token_id = AssetId::sub_token_id(&[asset_issuer.clone(), asset_code.clone()]);
let token_id = format!("{}::{}", asset_issuer, asset_code);

Tighten Stellar token validation in format_token_id by removing the fallback that accepted bare Stellar account IDs (56 chars starting with 'G'). Now only the issuer::symbol form is considered valid. Updated unit test to reflect that a standalone Stellar public key is no longer accepted.
@gemcoder21 gemcoder21 marked this pull request as ready for review March 6, 2026 16:36
@gemcoder21 gemcoder21 merged commit 72a7516 into main Mar 6, 2026
4 checks passed
@gemcoder21 gemcoder21 deleted the stellar-usdc-fix branch March 6, 2026 16:36
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