Skip to content

feat: add per-user daily execution cap with rolling 24h window#776

Merged
Mathews-25 merged 1 commit into
AgesEmpire:mainfrom
GazzyLee:feat/daily-execution-cap
Jul 1, 2026
Merged

feat: add per-user daily execution cap with rolling 24h window#776
Mathews-25 merged 1 commit into
AgesEmpire:mainfrom
GazzyLee:feat/daily-execution-cap

Conversation

@GazzyLee

Copy link
Copy Markdown
Contributor

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 rollover
  • check_daily_execution_cap() — called before trade execution; returns DailyTradeLimitExceeded when at cap
  • record_execution() — called after successful trade execution to bump the counter
  • Blocked execution emits daily_execution_cap_blocked event (distinct from loss-streak pause)
  • Public API: set_daily_cap_config(), get_daily_cap_config(), get_daily_execution_counter()

Bug Fixes

  • LossStreakKey::ConfigConfigState — renamed enum variant to avoid Soroban SDK #[contracttype] ConversionError collision with the LossStreakConfig struct name
  • Rewrote loss_streak.rs — restored set_loss_streak_threshold() and resume_after_loss_streak() that were lost to file corruption
  • Removed LossStreakPaused = 51#[contracterror] enforces ≤50 XDR variants; made LossStreakPaused a const alias for TradingPaused
  • Fixed duplicate [dev-dependencies] in integration_tests/Cargo.toml
  • Added mod escrow — missing module declaration in lib.rs

Tests

  • 7 new unit tests for daily_cap covering: under cap (allowed), at cap (rejected), window rollover (resets), custom config, and event emission
  • All 10 loss_streak tests pass (6 were failing before the fix)
  • 234/248 tests pass (2 pre-existing keeper auth failures, 12 pre-existing iceberg ignores)

Notes

  • Reuses existing AutoTradeError::DailyTradeLimitExceeded (error code 7) — no new error variant needed
  • Rolling window uses env.ledger().timestamp(); window keyed by (address, window_start) for efficient lookup

Closes #747

- 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
@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Mathews-25 Mathews-25 merged commit 934cde9 into AgesEmpire:main Jul 1, 2026
2 of 4 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.

auto_trade: Implement a per-user maximum daily auto-trade execution count cap

2 participants