Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Sui Address Balance support and coin-model refactor#1163

Merged
0xh3rman merged 2 commits into
mainfrom
sui-address-balance
May 28, 2026
Merged

Sui Address Balance support and coin-model refactor#1163
0xh3rman merged 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 gemwalletcom/wallet#439.

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".

Test matrix (mainnet, account 0xa9bd0493…)

# input path tx result
1 3.123 SUI native send legacy gas-split 6rLRrJ28H… ✅ refactor didn't break native SUI
2 2.831774 USDC send (address_balance=0) legacy coin merge+split 9dvmMXZf… ✅ refactor didn't break token legacy
3 0.5 USDC send build_amount_coin Path 1 (pure accumulator withdraw) 9PicfzLk… ✅ single FundsWithdrawal(500000), no Coin<USDC> touched
4 1.734 USDC send build_amount_coin Path 2 hybrid Bt3KrkZK… ✅ shortfall withdraw = 734000 only
5 0.5 USDC swap (Near Intents) Path 1 via build_token_transfer_ptb 8CaT6aSq… ✅ Near deposit consumed redeemed coin
6 2.5 USDC swap (Mayan MCTP) Path 2 hybrid via build_input_coin 84ZkRoyh… ✅ shortfall withdraw = 500000 only, Mayan bridge consumed split coin

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
@0xh3rman 0xh3rman merged commit e2aa7ca into main May 28, 2026
4 checks passed
@0xh3rman 0xh3rman deleted the sui-address-balance branch May 28, 2026 10:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant