Skip to content

smartcontract/cli: fix user-balances and fund underestimating required wallet balance#3213

Open
juan-malbeclabs wants to merge 2 commits intomainfrom
jo/fix/min_balance
Open

smartcontract/cli: fix user-balances and fund underestimating required wallet balance#3213
juan-malbeclabs wants to merge 2 commits intomainfrom
jo/fix/min_balance

Conversation

@juan-malbeclabs
Copy link
Contributor

Summary of Changes

  • access-pass user-balances: was treating wallet_rent_min as a floor on the required amount instead of adding it; after paying for a new User PDA the fee payer still needs to retain its own rent-exempt minimum or Solana rejects the transaction
  • access-pass fund: same bug — wallet_rent_min was the third argument to a chain of .max() calls; fixed to always add it on top of the operational need

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 2 +2 / -2 0
Tests 1 +9 / -9 0

Pure bug fix — no new code, only corrected formulas and updated test expectations.

Key files (click to expand)
  • smartcontract/cli/src/accesspass/user_balances.rsneeds_rent.max(wallet_rent_min)needs_rent + wallet_rent_min
  • smartcontract/cli/src/accesspass/fund.rsneeds_rent.max(min_balance).max(wallet_rent_min)wallet_rent_min + needs_rent.max(min_balance); test expectations updated accordingly

Testing Verification

  • Reproduced by the reporter: wallet with 0.003107 SOL showed missing: 0 but provisioning failed with insufficient funds for rent on account (0) (the fee payer)
  • With the fix, required for 1 remaining slot is ~0.003702 SOL (rent_per_ip + gas + wallet_rent_min), correctly showing a deficit of ~0.000595 SOL
  • All 240 existing unit tests pass with updated expected values

…d wallet balance

The wallet's own rent-exempt minimum was treated as a floor on the
required amount rather than being added to it. When a user account
needs to be provisioned, the fee payer must retain wallet_rent_min
lamports for itself after paying the new account's rent — so the
correct formula is wallet_rent_min + needs_rent, not
needs_rent.max(wallet_rent_min).

- user_balances.rs: needs_rent.max(wallet_rent_min) → needs_rent + wallet_rent_min
- fund.rs: needs_rent.max(min_balance).max(wallet_rent_min) → wallet_rent_min + needs_rent.max(min_balance)
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.

2 participants