Repository navigation
time limit transfer compliance module - #745
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis 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. ChangesTime Transfers Limits Module
Example Contract Implementation
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
examples/rwa/compliance-time-transfers-limits/Cargo.tomlexamples/rwa/compliance-time-transfers-limits/src/contract.rsexamples/rwa/compliance-time-transfers-limits/src/lib.rsexamples/rwa/compliance-time-transfers-limits/src/test.rspackages/tokens/src/rwa/compliance/modules/mod.rspackages/tokens/src/rwa/compliance/modules/time_transfers_limits/mod.rspackages/tokens/src/rwa/compliance/modules/time_transfers_limits/storage.rspackages/tokens/src/rwa/compliance/modules/time_transfers_limits/test.rs
…ts/storage.rs Co-authored-by: Boyan Barakov <9572072+brozorec@users.noreply.github.com>
brozorec
left a comment
There was a problem hiding this comment.
Approving this PR, but I'd recommend switching from seconds to ledgers
Fixes #742
PR Checklist
Summary by CodeRabbit
New Features
Tests