Skip to content

Add token operations: balance queries, transfers, and token list support#6

Merged
Quantumlyy merged 6 commits intomainfrom
claude/spark-token-operations-ZB1zW
Mar 29, 2026
Merged

Add token operations: balance queries, transfers, and token list support#6
Quantumlyy merged 6 commits intomainfrom
claude/spark-token-operations-ZB1zW

Conversation

@Quantumlyy
Copy link
Copy Markdown
Member

Summary

This PR adds comprehensive token operation support to the MBGA SDK, including fetching token balances, sending tokens, and managing token lists from the btkn-info registry.

Key Changes

Core Actions

  • getTokenBalance: Query token balances for the current connection, with optional filtering by token identifier
  • sendToken: Transfer tokens to a Spark address with amount specified in raw units
  • Both actions support optional connector parameter override and throw appropriate errors when wallet is not connected or action is unsupported

Token List Management

  • validateTokenList: ArkType schema validation for btkn-info token list format
  • fetchTokenList: Fetch and validate token lists from URLs with proper error handling
  • Token and TokenList types: Full TypeScript support matching the btkn-info schema specification

Token Amount Utilities

  • formatTokenAmount: Convert raw bigint amounts to human-readable decimal strings, respecting per-token decimals
  • parseTokenAmount: Parse decimal strings back to raw bigint amounts with validation
  • Both functions handle edge cases (zero, negative values, trailing zeros) and round-trip correctly

React Hooks

  • useTokenBalance: Query hook for fetching token balances with loading/error states and optional enable flag
  • useSendToken: Mutation hook for sending tokens with async and callback variants
  • useTokenList: Query hook for fetching and validating token lists from URLs

Connector Integration

  • Extended sparkSdk connector with getTokenBalance and sendToken implementations
  • Updated mock connector to support configurable token balances for testing
  • Added getTokenBalance and sendToken optional methods to connector interface

Testing

  • Comprehensive test suites for all new utilities, actions, and hooks
  • Mock connector tests with various token balance scenarios
  • Validation tests for token list schema and error cases

Implementation Details

  • Token amounts use bigint for precision without floating-point errors
  • Token list validation uses ArkType for runtime schema checking
  • All new actions follow existing error handling patterns with specific error types
  • React hooks integrate with TanStack Query for state management
  • Decimal handling is token-aware and configurable per token

https://claude.ai/code/session_017mN5apo7AtGo2LJwKNUQrn

Quantumlyy and others added 6 commits March 28, 2026 06:05
Add Token/TokenList types matching the btkn-info schema used by btknlist.org
registry. Implement ArkType schema validation for token lists and a
fetchTokenList utility that fetches and validates token list JSON from URLs.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Generic token amount formatting/parsing that respects per-token decimals,
analogous to existing formatSats/parseSats but parameterized by decimals.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
…rface

Add optional getTokenBalance and sendToken methods to the connector interface.
Implement them in the sparkSdk connector using the Spark SDK's getBalance
(tokenBalances) and transferTokens APIs. Add mock implementations in the
test connector.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Core actions for querying token balances and sending tokens on Spark.
Follow the same connector-delegation pattern as getBalance/sendPayment.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
React hooks for token operations:
- useTokenList: fetches and validates a token list from a URL (query)
- useTokenBalance: queries token balances via the connector (query)
- useSendToken: sends tokens to a Spark address (mutation)

Also re-exports new token types and utilities from @mbga/core.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mbga-site Ready Ready Preview, Comment Mar 28, 2026 6:23am

@Quantumlyy Quantumlyy merged commit 16b534d into main Mar 29, 2026
7 of 8 checks passed
@Quantumlyy Quantumlyy deleted the claude/spark-token-operations-ZB1zW branch March 29, 2026 08:43
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.

1 participant