Skip to content

Conversation

@wlmyng
Copy link
Contributor

@wlmyng wlmyng commented Dec 19, 2025

Description

Add two new apis, get_address_balance and list_address_balances to the consistent store api service, backed up by a new column family/ index in the consistent store.

While an individual balance can be looked up directly through on-chain data, listing an address's balances involves going to KV store to retrieve the bag id from the AccumulatorOwner dynamic field before using the existing object_by_owner index to filter AccumulatorMetadata. Since the consistent-store does not store object contents, only object references, the actual data resolution then goes back to KV. As a first party feature, we choose to privilege this with an index as we do the existing balances derived from coin aggregations.

Stack

  1. In a subsequent PR, we'll rename the existing balances related API to coin_balances.
  2. Add to graphql beta

Test plan

New tests in consistent_store_address_balance_tests.rs, WIP to be added to thsi PR


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • Indexing Framework:

@vercel
Copy link

vercel bot commented Dec 19, 2025

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

Project Deployment Review Updated (UTC)
sui-docs Ready Ready Preview, Comment Dec 19, 2025 10:19pm
2 Skipped Deployments
Project Deployment Review Updated (UTC)
multisig-toolkit Ignored Ignored Preview Dec 19, 2025 10:19pm
sui-kiosk Ignored Ignored Preview Dec 19, 2025 10:19pm

@wlmyng wlmyng temporarily deployed to sui-typescript-aws-kms-test-env December 19, 2025 20:26 — with GitHub Actions Inactive
optional string owner = 1;

// Required. The marker type for the balance, e.g. `0x2::sui::SUI`.
optional string coin_type = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we want to use coin_type to refer to the inner T of both Balance<T> and Coin<T>?

optional End end = 103;
}

message ListAddressBalancesResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

while these grpc types look very similar to Balances (soon-to-be CoinBalances), I think we should still keep them separate, given coin balances are something we'd hope to phase out, and address balances may undergo further evolution

/// Submit a write for every checkpoint, for snapshotting purposes.
const MAX_BATCH_CHECKPOINTS: usize = 1;

/// No batching actually happens, because `MAX_BATCH_CHECKPOINTS` is 1.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is directly lifted from the existing consistent-store pipelines

let address_balances = &conn.store.schema().address_balances;

for (key, val) in batch {
if *val == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the balances handler has a compaction filter that drops entries with 0 balances. For AddressBalances, we don't have to calculate deltas and merge balances, as this is done on-chain, so we can directly use the balance information.


/// All tables written to and read from the consistent store.
pub(crate) struct Schema {
/// Tracks ... address balances.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll return to this with a better doc comment!

… we want to order by coin type, potentially not aligned with how things are returned. or if we want to order by balance. and finally, for a reader, doing lookups against kv, then consulting consistent store, doesnt seem ergonomic
dont need (coin)balances-specific filtering logic
@wlmyng wlmyng force-pushed the feature/h-implement-address-balances-consistent-reader branch from 4de3012 to 54998dd Compare December 19, 2025 20:38
@wlmyng wlmyng temporarily deployed to sui-typescript-aws-kms-test-env December 19, 2025 20:38 — with GitHub Actions Inactive
@wlmyng wlmyng marked this pull request as ready for review December 19, 2025 22:14
@wlmyng wlmyng requested a review from a team as a code owner December 19, 2025 22:14
@wlmyng wlmyng temporarily deployed to sui-typescript-aws-kms-test-env December 19, 2025 22:14 — with GitHub Actions Inactive
@wlmyng wlmyng temporarily deployed to sui-typescript-aws-kms-test-env December 19, 2025 22:15 — with GitHub Actions Inactive
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