Skip to content

Added token allowance and balace precheck#514

Merged
1nonlypiece merged 3 commits into
Commitlabs-Org:masterfrom
ayandipe:feature/fund-escrow-balance-precheck
May 28, 2026
Merged

Added token allowance and balace precheck#514
1nonlypiece merged 3 commits into
Commitlabs-Org:masterfrom
ayandipe:feature/fund-escrow-balance-precheck

Conversation

@ayandipe
Copy link
Copy Markdown
Contributor

Close #459

Title: feat: precheck balance before fund_escrow transfer

  • Summary: Add an explicit balance pre-check and a clear InsufficientBalance contract error before transferring tokens into escrow. This prevents opaque token panic errors and keeps the Created -> Funded transition atomic.

  • Why: Previously fund_escrow called the token transfer directly; token-side failures surfaced as opaque panics. We now surface a stable contract error when the owner lacks sufficient tokens.

  • Changes

    • lib.rs: Added InsufficientBalance #[contracterror] and a precheck of owner token balance in fund_escrow. Ensures no state change occurs unless funds are available. (lib.rs)
    • test.rs: Added fund_fails_insufficient_balance unit test that asserts fund_escrow returns InsufficientBalance when owner has no balance. (test.rs)
    • README.md: Documented the new InsufficientBalance error and rationale. (README.md)
  • Testing

    • Run locally from repo root:
      . $HOME/.cargo/env
      cd contracts/escrow
      cargo test --lib
    • Test summary from my run: 11 passed; 0 failed.
  • Behavior & compatibility

    • Adds numeric error code InsufficientBalance = 10 (stable contract error).
    • Keeps Created -> Funded atomic: balance is checked before any state mutation.
    • No change to refund/release/dispute semantics.
    • Note: I intentionally removed an allowance precheck to avoid breaking owner-authenticated owner->contract transfers in the test environment (owner-auth calls are allowed to transfer without prior explicit allowance in tests). If you want an allowance check for non-owner scenarios, we can add it later with clear semantics.
  • Docs

    • README.md updated to include InsufficientBalance and the rationale for prechecking before transfer.
  • Commit message

    • feat: precheck balance before fund_escrow transfer
  • Next steps (optional)

    • Update backend normalizeContractError mapping to handle the new error code if needed.
    • Push branch and open PR (I can do this for you).

@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@ayandipe is attempting to deploy a commit to the 1nonly's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@ayandipe 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

@1nonlypiece
Copy link
Copy Markdown
Contributor

Please resolve the conflicts

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

@1nonlypiece 1nonlypiece merged commit 76988af into Commitlabs-Org:master May 28, 2026
1 check failed
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.

Contracts - Add token allowance and balance precheck before fund_escrow transfer

2 participants