Skip to content

Sui Address Balance support and coin-model refactor#1163

Open
0xh3rman wants to merge 2 commits into
mainfrom
sui-address-balance
Open

Sui Address Balance support and coin-model refactor#1163
0xh3rman wants to merge 2 commits into
mainfrom
sui-address-balance

Conversation

@0xh3rman
Copy link
Copy Markdown
Collaborator

@0xh3rman 0xh3rman commented May 28, 2026

Support Sui token transfers and swaps where the token amount lives in the per-address Balance accumulator. Gas payment still comes from a regular Coin<SUI> object owned by the sender; sponsored / fully gasless transactions are tracked separately in #1164.

Changes:

  • SuiClient::get_coins joins ListOwnedObjects with GetBalance and returns OwnedCoins<Coin> { coin_type, coins, address_balance }. Spend builders route through 0x2::coin::redeem_funds<T> when Address Balance covers the amount; mixed token sources use coin objects as the base and withdraw only the shortfall.
  • Merge SuiCoin + CoinAsset + Coin into a single Coin model with strong-typed Object { object_id: Address, digest: Digest, version: u64 }. Removes the From<SuiCoin> for Coin / TryFrom<SuiCoin> for CoinAsset converters and get_coin_assets_by_type.
  • Native SUI / staking: support pure-accumulator and pure-coin paths. Hybrid is rejected early because gas budget is unknown at build time. Pure-accumulator paths still require at least one Coin<SUI> for gas; missing gas coins are rejected with "No SUI coins available for gas".

Verification: gem_sui 63 tests pass (--all-features, includes live mainnet integration); swapper 230 tests pass. New tests cover pure-withdraw, mixed shortfall-only withdrawal (asserts the withdrawal amount is exactly amount - coin_total), missing-gas-coin rejection, and hybrid-native rejection.

Copy link
Copy Markdown
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 refactors the Sui integration to introduce the OwnedCoins struct, which encapsulates both individual coin objects and address-level balances. It updates balance validation, transfer builders, and staking logic to utilize this new structure. The review feedback highlights critical correctness bugs in the staking and transfer builders when the required amount is partially covered by the address balance and partially by coin objects, as well as a potential overflow panic in the coin_total calculation.

Comment thread crates/gem_sui/src/tx_builder/stake.rs
Comment thread crates/gem_sui/src/tx_builder/transfer.rs
Comment thread crates/gem_sui/src/models/coin.rs
@0xh3rman 0xh3rman marked this pull request as ready for review May 28, 2026 08:17
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