Skip to content

feat(wrapper): add share_balance getter over the vault share mapping (#716) - #849

Open
aakolawole2-byte wants to merge 1 commit into
BCPathway:mainfrom
aakolawole2-byte:feature/issue-716-share-balance-mapping
Open

feat(wrapper): add share_balance getter over the vault share mapping (#716)#849
aakolawole2-byte wants to merge 1 commit into
BCPathway:mainfrom
aakolawole2-byte:feature/issue-716-share-balance-mapping

Conversation

@aakolawole2-byte

Copy link
Copy Markdown

Closes #716.

Context

The issue asks for a ShareBalance persistent mapping and getters for querying user shares. Digging into contracts/wrapper, this vault already tracks per-user share balances persistently: wrap() mints a share 1:1 with the wrapped token, and unwrap()/withdraw()/burn()/burn_from() burn 1:1, all backed by the existing DataKey::Balance(Address) entry and exposed via the SEP-41 TokenInterface::balance getter.

Rather than introduce a second, parallel ShareBalance storage key that duplicates Balance and risks drifting out of sync with it, this reuses the existing mapping as the single source of truth and adds the missing piece: a getter named in vault vocabulary, so callers reasoning about "shares" don't have to know balance() already is the share balance.

Changes

  • contracts/wrapper/src/lib.rs: added pub fn share_balance(env: Env, user: Address) -> i128, placed next to the existing supply() vault-accounting getter and documented the same way — delegates to read_balance (no new storage key).
  • contracts/wrapper/src/test.rs: unit tests for the uninitialized-panic case, zero balance for an address that never wrapped, value after wrap (matches balance()), tracking across transfer/burn/unwrap, and independence across two users.
  • sdk/src/wrapperClient.ts: added getShareBalance(address) calling the new contract method, alongside a doc comment cross-referencing getBalance.
  • sdk/src/wrapperClient.test.ts: asserts the new method is present on the client surface.

Testing

  • cargo check -p bc-forge-wrapper --tests — passes (this Windows machine's local linker can't complete cargo test, so this is a full type/borrow-check against the real Soroban SDK; CI's Linux runner executes the actual test suite)
  • cargo fmt -p bc-forge-wrapper -- --check — passes
  • cargo clippy -p bc-forge-wrapper --all-targets --all-features -- -D warnings — passes, no warnings
  • npm run build + npm test in sdk/ — build clean, 23/23 tests pass

…CPathway#716)

Vault shares are already tracked persistently — the wrapper mints a share
1:1 with the wrapped token on wrap() and burns it 1:1 on unwrap/withdraw/
burn/burn_from, backed by the existing per-user DataKey::Balance entry and
exposed via the SEP-41 TokenInterface::balance getter. Reusing that storage
key (rather than introducing a parallel ShareBalance entry) avoids splitting
a single value across two ledger entries that could drift out of sync.

What was actually missing was a getter under vault vocabulary, since callers
reasoning about "shares" shouldn't have to know balance() is the same value.
Adds share_balance(user) to the contract (mirrors the existing supply()
getter's doc style) and getShareBalance() to the TS SDK, with unit tests for
the zero-balance case, post-wrap value, transfers/burns/unwraps, and
per-user independence.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@aakolawole2-byte Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

[Storage] Define ShareBalance mapping

1 participant