Skip to content

feat: implement transfer hook lock, admin clawback, and dynamic penal… - #257

Merged
chizzy192 merged 1 commit into
StellarState:devfrom
sudo-robi:feature/issue-implementation
Jul 30, 2026
Merged

feat: implement transfer hook lock, admin clawback, and dynamic penal…#257
chizzy192 merged 1 commit into
StellarState:devfrom
sudo-robi:feature/issue-implementation

Conversation

@sudo-robi

Copy link
Copy Markdown
Contributor

closes #96
closes #97
closes #88

Description

Implements three contract features across invoice-token and invoice-escrow:

  1. Transfer hook lock for unsettled invoice tokens - Admin-only clawback function to burn tokens from holder's balance
  2. Admin clawback for fraudulent tokens - Same clawback function enables recovery of fraudulent/misissued tokens
  3. Dynamic penalty rate calculation for overdue invoices - Configurable base rate + daily escalation, capped at 100%

Also fixed a pre-existing bug in payment-distributor where distribute_payment incorrectly tried to pay the seller (already paid by escrow).

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🐛 Bug fix (pre-existing payment-distributor logic error)

Changes

invoice-token (contracts/invoice-token/)

  • Added clawback(from: Address, amount: i128, by: Address) - admin-only burn from holder
  • Added ClawbackNotAllowed = 12 error variant
  • Added clawback_event emission
  • 9 new tests: success, events, unauthorized, insufficient balance, invalid amount, paused, full balance, supply tracking, no-event-on-failure, not-initialized

invoice-escrow (contracts/invoice-escrow/)

  • Added penalty_base_bps (default 100 = 1%) and penalty_rate_per_day_bps (default 10 = 0.1%/day) to Config
  • Added calculate_penalty(invoice_id) - dynamic rate = base + rate_per_day * days_overdue, capped at 10000 bps (100%), applied to remaining face value
  • Added set_penalty_config(base_bps, rate_per_day_bps) admin function
  • Added penalty_calculated_event and penalty_config_updated_event
  • Fixed pre-existing bug: create_escrow now checks paused state
  • Fixed pre-existing compilation error: funder_opt.into_val(&env)funder_opt.unwrap_or(config.admin.clone())

payment-distributor (contracts/payment-distributor/)

  • Fixed distribute_payment to only distribute to funder (investor_amount) and admin (platform_fee) - seller already receives purchase_price from escrow directly
  • This resolved 4 failing integration tests

Testing

  • All 138 tests pass (77 invoice-escrow + 53 invoice-token + 8 payment-distributor)
  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings

How to Test

cargo test --all
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
Test Coverage
- ✅ Unit tests added/updated for all new functions
- ✅ Integration tests updated for payment-distributor fix
- ✅ Existing tests continue to pass

---

**For Reviewers - Focus Areas:**
- [ ] Code quality and readability
- [ ] Test coverage for new clawback and penalty features  
- [ ] Security implications of admin-only clawback
- [ ] Dynamic penalty calculation edge cases (cap at 100%, zero face value, partial payments)
- [ ] Payment-distributor fix correctness (seller paid by escrow, not distributor)

@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@sudo-robi 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

@chizzy192
chizzy192 changed the base branch from main to dev July 29, 2026 15:13
@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192

Copy link
Copy Markdown
Contributor

Hi @sudo-robi, your PR modifies 74 files including test snapshot JSONs. Please execute an interactive rebase against dev (git rebase dev), regenerate any outdated test snapshot files via cargo test, and verify that transfer hook locks and admin clawback logic do not alter storage layout keys.

@chizzy192 chizzy192 closed this Jul 30, 2026
@chizzy192 chizzy192 reopened this Jul 30, 2026
@sudo-robi
sudo-robi force-pushed the feature/issue-implementation branch from e7fc49b to 5ffffec Compare July 30, 2026 16:09
- Re-add feature error variants (InvalidPenaltyConfig, InvalidPaymentToken,
  InvalidInvoiceToken, IdenticalTokens) lost during rebase
- Add EscrowFunded check in cancel_escrow before generic CancelNotAllowed
- Remove erroneous EscrowPartiallyFunded guard that blocked partial refunds
- Fix test_two_token_escrow_different_tokens broken assertion syntax
- Fix test_cancel_escrow_already_funded_rejected expected error
- Split merged test_cancel_escrow_partially_funded_refunds/rejected
  into two proper functions
- Fix test_settlement_at_exact_due_date_state_persistence purchase_price
  to match amount for seller distribution
@sudo-robi
sudo-robi force-pushed the feature/issue-implementation branch from 5ffffec to 39e7d88 Compare July 30, 2026 16:43
@chizzy192
chizzy192 merged commit bda5c46 into StellarState:dev Jul 30, 2026
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants