Skip to content

time limit transfer compliance module - #745

Merged
ozgunozerk merged 5 commits into
mainfrom
rwa-time-limit-transfer
Jun 5, 2026
Merged

ozgunozerk merged 5 commits into
mainfrom
rwa-time-limit-transfer

Conversation

@ozgunozerk

@ozgunozerk ozgunozerk commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #742

PR Checklist

  • Tests
  • Documentation

Summary by CodeRabbit

  • New Features

    • Added time-window transfer limit compliance module for enforcing cumulative outgoing transfer caps over rolling periods
    • Supports batch operations for configuring and removing limits
    • Enables identity-based transfer aggregation across multiple wallets
    • Automatic counter reset when time windows expire
  • Tests

    • Comprehensive test coverage for time-window transfer limits functionality

@ozgunozerk
ozgunozerk requested a review from brozorec June 3, 2026 15:53
@ozgunozerk ozgunozerk self-assigned this Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: db6264b4-157e-4d6f-b8cc-f774908570c8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR introduces a time-window-based transfer limit compliance module for RWA tokens on Stellar. The module enforces per-identity cumulative outbound transfer caps over rolling time windows, with counter state persisted per token/identity/duration, and automatic window restart upon expiration. An example contract implementation demonstrates integration with the compliance framework.

Changes

Time Transfers Limits Module

Layer / File(s) Summary
Error types and module registration
packages/tokens/src/rwa/compliance/modules/mod.rs
Module export added; ComplianceModuleError extended with TransferLimitExceeded, LimitBoundExceeded, and LimitNotFound variants.
Data types and storage structures
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs
TransferLimit, TransferCounter, and TimeTransfersLimitsStorageKey enums define the on-chain state model; MAX_LIMITS = 8 bound.
Module trait definition and events
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/mod.rs
TimeTransfersLimits contract trait with admin methods for limit config/removal, default getters; event structs TimeTransferLimitSet and TimeTransferLimitRemoved with emitters.
Query and validation helpers
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs
get_time_transfer_limits and get_transfer_counter load persistent state; can_transfer validates sender identity resolution and projected counter against active windows.
Limit configuration and removal
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs
set_time_transfer_limit / batch_set_time_transfer_limit insert or replace limits with bound enforcement; remove_time_transfer_limit / batch_remove_time_transfer_limit delete entries and emit events.
Transfer recording and counter management
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs
on_transfer validates amounts, resolves identity via IRS, restarts expired windows, increments counters with overflow protection, and panics on cap exceed.
Module unit tests
packages/tokens/src/rwa/compliance/modules/time_transfers_limits/test.rs
MockIRSContract test double with identity lookup; comprehensive coverage of limit mutations, transfer validation, cap enforcement, window expiration, identity-based aggregation, and boundary conditions.

Example Contract Implementation

Layer / File(s) Summary
Contract structure and configuration
examples/rwa/compliance-time-transfers-limits/Cargo.toml, src/lib.rs, src/contract.rs (constructor)
Package metadata; TimeTransfersLimitsContract with admin/manager role setup.
Contract trait implementations
examples/rwa/compliance-time-transfers-limits/src/contract.rs
TimeTransfersLimits methods use #[only_role(operator, "manager")] to delegate to storage layer; ComplianceModule implements on_transfer with compliance address authorization, transfer query validation, and no-op create/destroy.
Contract integration tests
examples/rwa/compliance-time-transfers-limits/src/test.rs
Mock IRS contract; client setup; tests for limit CRUD, batch operations, transfer cap enforcement per identity, window expiration and reset, manager authorization, and compliance address persistence.

Sequence Diagram

sequenceDiagram
  participant Sender
  participant TimeTransfersLimitsContract
  participant StorageModule
  participant IRSContract
  Sender->>TimeTransfersLimitsContract: on_transfer(from, to, amount, token)
  TimeTransfersLimitsContract->>StorageModule: get_time_transfer_limits(token)
  StorageModule-->>TimeTransfersLimitsContract: limits: Vec<TransferLimit>
  TimeTransfersLimitsContract->>IRSContract: resolve identity for from
  IRSContract-->>TimeTransfersLimitsContract: identity
  loop for each limit duration
    TimeTransfersLimitsContract->>StorageModule: get_transfer_counter(token, identity, duration)
    StorageModule-->>TimeTransfersLimitsContract: counter {value, deadline}
    alt window expired (deadline <= now)
      TimeTransfersLimitsContract->>StorageModule: reset counter to {0, now+duration}
    end
    TimeTransfersLimitsContract->>StorageModule: increment counter.value
    alt counter.value > limit_value
      TimeTransfersLimitsContract-->>Sender: panic TransferLimitExceeded
    else
      StorageModule->>StorageModule: persist updated counter
    end
  end
  TimeTransfersLimitsContract-->>Sender: success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • brozorec

Poem

🐇 A rabbit hops through time-bound transfers clear,
Counting coins in windows rolling near,
Each identity tracked through its own estate,
Expiring ledgers keep balances straight. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title 'time limit transfer compliance module' clearly describes the main feature being added: a compliance module for time-based transfer limits matching the PR objective.
Description check ✅ Passed PR description references issue #742 and confirms tests and documentation are complete per the template checklist, meeting core requirements.
Linked Issues check ✅ Passed The changeset implements a comprehensive time-based transfer limits compliance module with storage, validation, and contract implementations fully meeting issue #742 objectives.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the time-based transfer limits compliance module; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rwa-time-limit-transfer

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.61%. Comparing base (5dc04f4) to head (b34bcad).

Files with missing lines Patch % Lines
...ompliance/modules/time_transfers_limits/storage.rs 96.07% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #745      +/-   ##
==========================================
- Coverage   96.62%   96.61%   -0.01%     
==========================================
  Files          69       70       +1     
  Lines        7324     7426     +102     
==========================================
+ Hits         7077     7175      +98     
- Misses        247      251       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs`:
- Around line 343-362: Persistent counters
(TimeTransfersLimitsStorageKey::Counter) can be archived when their persistent
TTL reaches zero, causing get_transfer_counter to fail and DoS transfers in an
active limit window; fix by ensuring stored TransferCounter entries live at
least until counter.deadline: when writing the counter in the loop in the
transfer path, set a TTL >= limit.limit_duration (or cap limit.limit_duration to
a safe max) and on reads (get_transfer_counter) call
e.storage().persistent().extend_ttl(&key, TTL_THRESHOLD, EXTEND_AMOUNT) to
extend the TTL proactively; update the write path that sets the key and the
get_transfer_counter read path to implement these TTL semantics and use the
existing limit.limit_duration and counter.deadline values to compute the
required TTL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7dbe8bb-4826-479e-bcc2-f4e4a125cc19

📥 Commits

Reviewing files that changed from the base of the PR and between 76ab671 and e8c0d67.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • examples/rwa/compliance-time-transfers-limits/Cargo.toml
  • examples/rwa/compliance-time-transfers-limits/src/contract.rs
  • examples/rwa/compliance-time-transfers-limits/src/lib.rs
  • examples/rwa/compliance-time-transfers-limits/src/test.rs
  • packages/tokens/src/rwa/compliance/modules/mod.rs
  • packages/tokens/src/rwa/compliance/modules/time_transfers_limits/mod.rs
  • packages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rs
  • packages/tokens/src/rwa/compliance/modules/time_transfers_limits/test.rs

ozgunozerk and others added 2 commits June 4, 2026 12:26
…ts/storage.rs

Co-authored-by: Boyan Barakov <9572072+brozorec@users.noreply.github.com>
@ozgunozerk
ozgunozerk requested a review from brozorec June 5, 2026 11:16

@brozorec brozorec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR, but I'd recommend switching from seconds to ledgers

@ozgunozerk
ozgunozerk merged commit 52a4072 into main Jun 5, 2026
6 of 8 checks passed
@ozgunozerk
ozgunozerk deleted the rwa-time-limit-transfer branch June 5, 2026 13:04
@coderabbitai coderabbitai Bot mentioned this pull request Jun 5, 2026
2 tasks done
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.

🏗️ [Core Feature]: Time Limit Transfer Modules

2 participants