Skip to content

fix(treasury): Review and document gas usage for treasury contract hot paths#1265

Open
NUMBER72857 wants to merge 1 commit into
MyFanss:mainfrom
NUMBER72857:fix/906-treasury-gas-review
Open

fix(treasury): Review and document gas usage for treasury contract hot paths#1265
NUMBER72857 wants to merge 1 commit into
MyFanss:mainfrom
NUMBER72857:fix/906-treasury-gas-review

Conversation

@NUMBER72857
Copy link
Copy Markdown

Summary

Adds correctness tests for the three treasury hot paths — deposit, withdraw, and the implicit balance-read inside withdraw — documenting their cost drivers and storage-tier choices with inline analysis.

Changes

  • gas_benchmarks.rs: 10 tests covering deposit accumulation, overdraft rejection, zero/negative-amount guards, paused-contract short-circuit, balance consistency, and full-withdrawal
  • Inline doc table documents dominant costs and optimization status:
    • deposit: single SAC transfer call — no further reduction available
    • withdraw: auth before storage read (cheap early-abort) + balance check
    • Both: amount guard fires before require_auth for cheapest rejection
  • All keys use instance storage (cheapest TTL tier, shared with contract lifetime)
  • All tests run immediately — wired to real TreasuryClient + StellarAssetClient

Gas optimization notes

  • Amount validation before require_auth in both hot paths keeps bad-input calls maximally cheap
  • Auth check before token I/O in withdraw ensures unauthorized calls abort before any cross-contract calls
  • Instance storage for ADMIN/TOKEN/PAUSED/MIN_BALANCE is the correct tier (no per-entry TTL cost)

Closes #906

MyFanss#906)

- gas_benchmarks.rs: correctness tests for deposit, withdraw, and balance-read
  hot paths using TreasuryClient + StellarAssetClient test helpers
- Covers: deposit accumulation, overdraft rejection, zero/negative-amount guards,
  paused-contract short-circuit, and balance consistency between token_client
  and treasury internal reads
- Inline doc table documents cost drivers and storage-tier choices:
  instance storage for all keys, auth-before-storage ordering in withdraw,
  amount guard before require_auth in deposit
- All tests run immediately (no #[ignore]) — wired to real TreasuryClient

Closes MyFanss#906
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@NUMBER72857 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.

Contract treasury: Review gas usage for hot paths

1 participant