Skip to content

feat: add timestamp-based trade cooldown enforcement (issue #974) - #991

Merged
Chucks1093 merged 5 commits into
accesslayerorg:mainfrom
funds0033-cmyk:feat/cooldown-enforcement-974
Oct 2, 2026
Merged

Chucks1093 merged 5 commits into
accesslayerorg:mainfrom
funds0033-cmyk:feat/cooldown-enforcement-974

Conversation

@funds0033-cmyk

Copy link
Copy Markdown
Contributor

Summary

Completes the trade cooldown implementation by enforcing cooldown checks prior to trade execution and recording last_trade_timestamp state on both buy and sell completion paths.


What Was Done

1. Cooldown Enforcement (Task #4)

  • Buy Operations (buy_keys_with_referrer & buy_key_with_referrer):

  • Added the trade cooldown guard immediately following the whitelist verification.

  • Ensures buyers respect the configured cooldown window before executing key purchases.

  • Sell Operations (sell_key):

  • Inserted the trade cooldown check after the anti-flash-loan lockup validation and before reading base_price.

2. State Timestamp Updates (Task #5)

  • Buy Path:

  • Updated last_trade_timestamp alongside last_buy_timestamp state writes upon key acquisition in both single-key and batch purchase workflows.

  • Sell Path:

  • Stamp last_trade_timestamp prior to publishing KeysSoldEvent once fee and penalty accounting completes.

3. Unit Test Suite

  • Added comprehensive unit test coverage targeting:
  • Cooldown window enforcement across sequential buys and sells.
  • Trade rejection when attempting actions prior to cooldown expiry (TradeCooldownActive).
  • Successful execution once the ledger timestamp advances beyond the cooldown interval.

Acceptance Criteria Checklist

  • Cooldown guards enforced in buy_keys_with_referrer, buy_key_with_referrer, and sell_key.
  • last_trade_timestamp updated on all successful buy and sell execution paths.
  • Unit test suite added covering timestamp edge cases and cooldown window transitions.
  • Codebase committed and pushed to remote feature branch.

Closes #974

@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@funds0033-cmyk 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

Resolved merge conflicts in:
- creator-keys/src/events.rs: Combined cooldown enforcement events with main branch events (graduated curve, leaderboard, platform pause, vault rebalancing, dynamic fee tiers, staking NFT, curve reset, key rating)
- creator-keys/src/lib.rs: Combined cooldown duration/trade timestamp DataKey variants with main branch variants (staking, vault, fee tiers, curve reset, etc.) and merged buy logic to include both cooldown timestamp update and supply cap reached event

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@funds0033-cmyk

Copy link
Copy Markdown
Contributor Author

@Chucks1093 pls kindly merge

funds0033-cmyk and others added 3 commits October 1, 2026 16:54
- Removed extra closing brace in events.rs (line 3756)
- Ran cargo fmt to fix formatting issues in lib.rs and trade_cooldown.rs

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…oan guard

The flash loan guard checks ledger sequence numbers (not timestamps) and runs
before the cooldown check in sell_key. Tests only advanced the timestamp, causing
the flash loan guard to trigger first. Now tests advance both timestamp and ledger
sequence to properly test cooldown behavior.

Fixes failing tests:
- test_sell_blocked_within_cooldown_window
- test_sell_succeeds_after_cooldown_expires

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Chucks1093
Chucks1093 merged commit 20f6edb into accesslayerorg:main Oct 2, 2026
1 check 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.

Add cooldown enforcement to bonding curve trade functions

2 participants