Skip to content

Add get_token_decimals SDK method #411

Description

@Levi-Ojukwu

Description:

The contract exposes get_token_decimals(token: Address) (at lib.rs:430-434) that returns the decimal precision for a registered token (e.g., 6 for USDC, 7 for XLM). This is critical for correctly formatting token amounts in UI displays.

The contract implementation:

pub fn get_token_decimals(env: Env, token: Address) -> Option<u32> {
    env.storage()
        .persistent()
        .get(&crate::storage::DataKey::TokenDecimals(token))
}

The SDK method should:

  1. Accept a token address parameter
  2. Call the contract's get_token_decimals view
  3. Return number | null (null if token is not registered)
  4. Handle the Stellar address type conversion

Why it matters: Displaying token amounts correctly requires knowing the decimal precision. Without this, 1 USDC (10,000,000 stroops) could be displayed as 10000000 instead of 1.00.

Acceptance Criteria:

  • Create a function in sdk/src/methods/ that calls get_token_decimals
  • Accept a Stellar address string parameter
  • Return Promise<number | null>
  • Add tests with mock client
  • Export from sdk/src/index.ts

Relevant Files: contracts/invoice_liquidity/src/lib.rs:430-434, sdk/src/index.ts


Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions