feat: add per-user daily execution cap with rolling 24h window#776
Merged
Conversation
- New daily_cap module: per-user configurable max auto-trades/day (default 10) - Rolling 24h ledger-time window counter with atomic rollover - Wired check_daily_execution_cap() and record_execution() into execute_trade() - Blocked execution emits daily_execution_cap_blocked event - Fix: renamed LossStreakKey::Config -> ConfigState to avoid Soroban #[contracttype] ConversionError collision with LossStreakConfig struct - Fix: rewrote corrupted loss_streak.rs with proper function boundaries - Fix: removed LossStreakPaused = 51 XDR variant (exceeded 50-variant limit), made it a const alias for TradingPaused - Fix: duplicate [dev-dependencies] in integration_tests/Cargo.toml - Fix: added missing mod escrow declaration in lib.rs - 234/248 tests pass; 12 pre-existing ignores, 2 pre-existing keeper auth failures
|
@GazzyLee 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! 🚀 |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a per-user maximum daily auto-trade execution cap with a rolling 24-hour ledger-time window. Composes correctly with the existing loss-streak pause and drawdown circuits.
Changes
Feature — Daily Execution Cap (
daily_cap.rs)DailyCapConfig— per-user configurable limit (default: 10 executions/day)DailyExecutionCounter— rolling 24h window counter; resets atomically on window rollovercheck_daily_execution_cap()— called before trade execution; returnsDailyTradeLimitExceededwhen at caprecord_execution()— called after successful trade execution to bump the counterdaily_execution_cap_blockedevent (distinct from loss-streak pause)set_daily_cap_config(),get_daily_cap_config(),get_daily_execution_counter()Bug Fixes
LossStreakKey::Config→ConfigState— renamed enum variant to avoid Soroban SDK#[contracttype]ConversionErrorcollision with theLossStreakConfigstruct nameloss_streak.rs— restoredset_loss_streak_threshold()andresume_after_loss_streak()that were lost to file corruptionLossStreakPaused = 51—#[contracterror]enforces ≤50 XDR variants; madeLossStreakPauseda const alias forTradingPaused[dev-dependencies]inintegration_tests/Cargo.tomlmod escrow— missing module declaration inlib.rsTests
daily_capcovering: under cap (allowed), at cap (rejected), window rollover (resets), custom config, and event emissionloss_streaktests pass (6 were failing before the fix)Notes
AutoTradeError::DailyTradeLimitExceeded(error code 7) — no new error variant neededenv.ledger().timestamp(); window keyed by(address, window_start)for efficient lookupCloses #747