Skip to content

Fix/get usdb supply#119

Merged
JustaLiang merged 6 commits intomainfrom
fix/getUsdbSupply
Mar 9, 2026
Merged

Fix/get usdb supply#119
JustaLiang merged 6 commits intomainfrom
fix/getUsdbSupply

Conversation

@do0x0ob
Copy link
Contributor

@do0x0ob do0x0ob commented Mar 5, 2026

Summary

Fixes getUsdbSupply failing with InvalidPublicFunctionReturnType after upgrading to SDK v2. Circulating supply was showing 0 in the frontend.

Root Cause

Sui PTBs cannot pass references (& or &mut) between commands. The old flow:

  1. Command 0: usdb::borrow_cap_mut(treasury) → returns &mut BorrowCap
  2. Command 1: 0x2::coin::total_supply(that) → uses that reference

With @mysten/sui v2, simulateTransaction enforces this and returns InvalidPublicFunctionReturnType. The code fell back to return 0n, so the frontend saw 0.

Solution

Replace the PTB-based flow with stateService.getCoinInfo to read TreasuryCap total supply directly (no PTB).

Changes

  • src/client.ts: Rewrite getUsdbSupply to use getCoinInfo; fix eqeqeq lint
  • test/e2e/client.test.ts: Add getUsdbSupply e2e test; narrow Oracle test to SUI-only (getAllOraclePrices flakes on main's static config)

Testing

  • pnpm build
  • pnpm lint
  • pnpm vitest run test/e2e/client.test.ts

do0x0ob added 3 commits March 5, 2026 19:30
…rnType

- Replace simulateTransaction + borrow_cap_mut with stateService.getCoinInfo
- PTB cannot pass &mut references between commands; SDK v2 validates and rejects
- Add getUsdbSupply e2e test (expect supply > 0)

Made-with: Cursor
…ness

getAllOraclePrices with all coin types fails on main's static config
(derivative flow / Hermes batch). Single-coin getOraclePrices(SUI)
is stable and sufficient to validate the oracle flow.

Also add SUI_GRPC_URL env support for custom RPC.

Made-with: Cursor
Copy link
Collaborator

@bucket-bot bucket-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

Root cause fix is correct — PTB 無法在 commands 之間傳遞 &mut references,改用 stateService.getCoinInfo 是正確方向。

Checked:

  • ✅ Bug detection: fix 邏輯正確,無新引入 regression
  • ✅ Silent failure: fallback 範圍縮小(只有 treasury undefined 才 return 0n,舊的任何 PTB 錯誤都 return 0n)
  • ✅ Test quality: getUsdbSupply 斷言從 >= 0n> 0n,直接抓到這次 bug
  • ✅ Oracle 測試縮窄有文件說明,合理

一個小 note(非 blocker): mvr.resolveType 多了一次 RPC round-trip,如果 getCoinInfo 其實接受 raw type 的話可以省掉。但如果需要 MVR 正規化才能 lookup 的話就沒問題,不影響正確性。

🤖 Generated with Jarvis (OpenClaw)

describe('Oracle', () => {
it(
'getAllOraclePrices returns positive numbers for all oracle coin types',
'getOraclePrices returns positive numbers for SUI (validates oracle flow)',
Copy link
Collaborator

Choose a reason for hiding this comment

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

這部分不測全部了嗎?

Copy link
Contributor Author

@do0x0ob do0x0ob Mar 9, 2026

Choose a reason for hiding this comment

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

先前因為避開 sCoin 升級問題修改,已經在 commit 382a46e
中加回,測試通過
image

do0x0ob added 2 commits March 9, 2026 16:32
- Update scoin_rule::feed target to 0xb7c07926... (from query-outputs PRICE_OBJS)
- Align static config with merge branch test-results/query-outputs.json
- Restore strict getAllOraclePrices test assertions

Made-with: Cursor
@JustaLiang JustaLiang merged commit 5537c3b into main Mar 9, 2026
3 of 4 checks passed
@JustaLiang JustaLiang deleted the fix/getUsdbSupply branch March 9, 2026 09:49
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.

5 participants