feat(wrapper): add share_balance getter over the vault share mapping (#716) - #849
Open
aakolawole2-byte wants to merge 1 commit into
Open
Conversation
…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.
|
@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! 🚀 |
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.
Closes #716.
Context
The issue asks for a
ShareBalancepersistent mapping and getters for querying user shares. Digging intocontracts/wrapper, this vault already tracks per-user share balances persistently:wrap()mints a share 1:1 with the wrapped token, andunwrap()/withdraw()/burn()/burn_from()burn 1:1, all backed by the existingDataKey::Balance(Address)entry and exposed via the SEP-41TokenInterface::balancegetter.Rather than introduce a second, parallel
ShareBalancestorage key that duplicatesBalanceand 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 knowbalance()already is the share balance.Changes
contracts/wrapper/src/lib.rs: addedpub fn share_balance(env: Env, user: Address) -> i128, placed next to the existingsupply()vault-accounting getter and documented the same way — delegates toread_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 (matchesbalance()), tracking across transfer/burn/unwrap, and independence across two users.sdk/src/wrapperClient.ts: addedgetShareBalance(address)calling the new contract method, alongside a doc comment cross-referencinggetBalance.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 completecargo 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— passescargo clippy -p bc-forge-wrapper --all-targets --all-features -- -D warnings— passes, no warningsnpm run build+npm testinsdk/— build clean, 23/23 tests pass