fix(xlm_wrapper): minimum reserve check before XLM deposit - #1042
Merged
Ceejaytech25 merged 1 commit intoSep 2, 2026
Merged
Ceejaytech25 merged 1 commit into
Ceejaytech25 merged 1 commit into
Conversation
…oratory#1002) Prevent wrapping requests that would leave an account below the Stellar network minimum reserve (0.5 XLM × number of ledger entries). Changes to contracts/xlm_wrapper/src/lib.rs: - Add DataKey::TrustlineCount(Address) to track per-account trustline count - Define BASE_RESERVE_STROOPS = 5_000_000 (0.5 XLM in stroops) and MIN_ACCOUNT_ENTRIES = 2 (base account entry requirement) - deposit(): before transferring XLM, compute available = current_balance - (MIN_ACCOUNT_ENTRIES + trustlines) × 0.5 XLM and reject with 'InsufficientReserve' if amount > available - Add set_trustline_count(admin, account, count) — admin-only setter so a trusted oracle can record the account's real trustline count on-chain - Add get_min_reserve(account) — view function returning the minimum reserve in stroops for a given account - Update existing test helpers (fund_user) to mint amount + 10_000_000 (base reserve) so that pre-existing tests continue to pass - New unit tests: - test_deposit_respects_base_reserve: deposit of exactly available succeeds - test_deposit_below_base_reserve_rejected: zero available → panic - test_deposit_exceeding_available_balance_rejected: over available → panic - test_get_min_reserve_default: 2 × 5_000_000 = 10_000_000 - test_get_min_reserve_with_trustlines: 5 × 5_000_000 = 25_000_000 - test_deposit_with_trustlines_enforces_higher_reserve: extra TLs → higher guard - test_deposit_with_trustlines_within_available: deposit within available passes Closes ceejaylaboratory#1002
|
@boseshittu2323-design 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! 🚀 |
Contributor
|
Nice implementation, LGTM! |
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.
Summary
Reject XLM wrapping requests that would leave an account's native balance below the Stellar network minimum reserve, preventing accounts from being stranded without enough XLM to pay transaction fees.
Problem
deposit()transferred XLM without checking whether the sender would retain the mandatory Stellar account reserve (0.5 XLM × number of ledger entries), which could render accounts non-functional.Changes (
contracts/xlm_wrapper/src/lib.rs)DataKey::TrustlineCount(Address)— tracks per-account trustline countBASE_RESERVE_STROOPS = 5_000_000— 0.5 XLM in stroops (7 decimals)MIN_ACCOUNT_ENTRIES = 2— base account entry requirementdeposit()— before transferring, computesavailable = current_balance − (2 + trustlines) × 0.5 XLMand panics
"InsufficientReserve"ifamount > availableset_trustline_count(admin, account, count)— admin-only setter for per-account trustline countget_min_reserve(account)— view function returning minimum reserve in stroopsfund_userhelpers updated to mintamount + 10_000_000so tests pass the new guardCloses #1002