Skip to content

feat(transfer-restrictions): enforce whitelist in validate_transfer#505

Merged
truthixify merged 3 commits intoDistinctCodes:mainfrom
KevinMB0220:feat/transfer-restrictions-whitelist-enforcement
Feb 23, 2026
Merged

feat(transfer-restrictions): enforce whitelist in validate_transfer#505
truthixify merged 3 commits intoDistinctCodes:mainfrom
KevinMB0220:feat/transfer-restrictions-whitelist-enforcement

Conversation

@KevinMB0220
Copy link
Copy Markdown
Contributor

Closes #472

Summary

  • validate_transfer was a no-op stub that always returned Ok(true), making the whitelist and accreditation config completely ignored. This PR implements the actual enforcement logic.
  • Whitelist gate: if the whitelist for an asset is non-empty, the recipient (to) must be present; otherwise returns Error::TransferRestrictionFailed.
  • Accredited investor gate: if require_accredited = true, the whitelist is used as the MVP proxy registry; returns Error::AccreditedInvestorRequired when to is absent.
  • Zero-friction default preserved: empty whitelist + no restriction config → transfer is allowed.

Changes

src/transfer_restrictions.rs

  • Removed placeholder stub body from validate_transfer.
  • Added whitelist read + membership check before allowing transfer.
  • Added require_accredited check using the same whitelist as MVP proxy (as specified).

src/tests/transfer_restrictions.rs (client integration tests)

  • test_transfer_to_non_whitelisted_failstransfer_tokens panics when recipient is not whitelisted (acceptance criterion 1).
  • test_empty_whitelist_allows_transfer — transfer succeeds when no whitelist is set (acceptance criterion 2).

src/tests/transfer_restrictions_new.rs (unit tests, direct module calls)

  • test_validate_transfer_blocked_when_not_whitelistedvalidate_transfer allows whitelisted address, blocks non-whitelisted.
  • test_validate_transfer_empty_whitelist_allows_all — empty whitelist imposes no restriction.
  • test_validate_transfer_accredited_required_uses_whitelistrequire_accredited flag gates via whitelist.

Test plan

  • cargo fmt — no changes needed
  • cargo clippy — clean, no warnings
  • cargo test — 193/193 tests pass

Acceptance criteria

  • Transfer to non-whitelisted address fails when whitelist is active
  • Empty whitelist = no restrictions
  • validate_transfer integrated into transfer_tokens (was already wired in lib.rs; enforcement now actually runs)

validate_transfer was a stub that always returned Ok(true), ignoring
any whitelist or accreditation config. Now:

- If the whitelist for an asset is non-empty, the recipient (`to`) must
  be present in it; otherwise returns Error::TransferRestrictionFailed.
- If `require_accredited = true`, the whitelist is used as the MVP
  proxy for accredited-investor status; returns
  Error::AccreditedInvestorRequired when `to` is absent.
- No restrictions set and empty whitelist → transfer is still allowed
  (zero-friction default).

Closes DistinctCodes#472
Covers all three acceptance criteria from issue DistinctCodes#472:

transfer_restrictions.rs (client-level integration):
- test_transfer_to_non_whitelisted_fails: transfer_tokens panics when
  recipient is not in an active whitelist
- test_empty_whitelist_allows_transfer: no whitelist → transfer succeeds

transfer_restrictions_new.rs (unit-level, direct module calls):
- test_validate_transfer_blocked_when_not_whitelisted: validate_transfer
  returns Ok for whitelisted address, Err for non-whitelisted
- test_validate_transfer_empty_whitelist_allows_all: empty whitelist
  imposes no restriction
- test_validate_transfer_accredited_required_uses_whitelist: whitelist
  acts as accredited-investor registry for require_accredited flag
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 22, 2026

@KevinMB0220 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

Fixes clippy::bool_assert_comparison lint triggered by -D warnings in CI.
@truthixify truthixify merged commit 7c9f0ad into DistinctCodes:main Feb 23, 2026
4 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

Development

Successfully merging this pull request may close these issues.

[Contract] Build Transfer Restrictions Module with Whitelist Management

2 participants