🐛 fix(sdk): recognize long-form SUI in history classifier (correct principal asset)#101
Open
ngna3007 wants to merge 1 commit into
Open
🐛 fix(sdk): recognize long-form SUI in history classifier (correct principal asset)#101ngna3007 wants to merge 1 commit into
ngna3007 wants to merge 1 commit into
Conversation
…incipal asset) History reads on the Sui GraphQL transport return SUI's coin type fully expanded (0x000…0002::sui::SUI). The shared classifier excluded SUI gas by strict-comparing the SHORT 0x2::sui::SUI, so the long-form SUI delta passed through as a "non-SUI" change and extractTransferDetails could pick it as the transaction's principal — rendering e.g. a $1 USDC send as "-0.003 SUI" (wrong asset, amount, and direction). Triggers on common small stablecoin transfers / swaps where the SUI gas raw (9 decimals) out-magnitudes the stable raw (6 decimals). Display-only — no funds at risk. Fix: compare canonical struct tags (normalizeStructTag) via a new isSuiCoinType helper, replacing the three raw `coinType !== SUI_TYPE` checks (extractTransferDetails + both refineLendingLabel finds). Form-insensitive, without false-matching an impostor 0xother::sui::SUI. Per token-data-architecture.mdc — never raw-string-compare coin types. Regression test: a larger-raw long-form SUI gas delta + a smaller USDC inflow must resolve to USDC/1/in (fails without the fix → SUI/5/out). Verified: 424 SDK tests, typecheck, lint (0 errors).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Transaction history mis-identifies the principal asset/amount of a tx.
History reads now use the Sui GraphQL transport, which returns SUI's coin type fully expanded (
0x000…0002::sui::SUI). But the shared classifier (wallet/classify.ts) excludes SUI gas by strict-comparing the short0x2::sui::SUI:extractTransferDetails(line ~248) —userNonSui = filter(coinType !== SUI_TYPE)→ runs on every history txrefineLendingLabel(lines ~168/173) — same compareSo the long-form SUI delta passes through as a "non-SUI" change.
extractTransferDetailsthen picks the largest-by-raw-units change as the principal — and since SUI is 9 decimals vs stablecoins' 6, a normal gas spend (~0.001–0.005 SUI) often out-magnitudes a small stablecoin transfer.Impact (display-only, no funds at risk): a "$1 USDC send" renders in history as "−0.003 SUI" — wrong asset, amount, and direction. Hits a common everyday case (small stablecoin sends/swaps). Surfaces in
t2 historyand any SDK consumer reading history. JSON-RPC emitted short-form SUI, so this only appeared after the GraphQL migration.Fix
Compare canonical struct tags instead of raw strings — new
isSuiCoinType(coinType)usingnormalizeStructTag, replacing the threecoinType !== SUI_TYPEchecks. Form-insensitive (detects SUI in either address form) without false-matching an impostor0xother::sui::SUI(the package address is part of the normalized tag). Aligns withtoken-data-architecture.mdc(never raw-string-compare coin types).Verification
classify.test.ts): a larger-raw long-form SUI gas delta + a smaller USDC inflow must resolve toUSDC/1/in. Fails without the fix (SUI/5/out), passes with it — confirmed by running before/after.Notes
Found while reconciling an (abandoned, now-superseded) gRPC read-migration branch against current main — this is the one real bug that survived; it's live on
v5.6.0.