Skip to content

feat: add protocol trade fee, holder cap, sell lockup and TTL refresh - #774

Merged
Chucks1093 merged 2 commits into
accesslayerorg:mainfrom
vjuliaife:feat/protocol-fee-holder-cap-lockup-ttl
Aug 27, 2026
Merged

feat: add protocol trade fee, holder cap, sell lockup and TTL refresh#774
Chucks1093 merged 2 commits into
accesslayerorg:mainfrom
vjuliaife:feat/protocol-fee-holder-cap-lockup-ttl

Conversation

@vjuliaife

Copy link
Copy Markdown
Contributor

Summary

Adds four protocol-hardening features to the creator-keys contract: a configurable protocol trade fee routed to a treasury address on every buy and sell, a per-creator percentage holding cap enforced during buys, an anti-flash-trade sell lockup window, and systematic persistent-storage TTL maintenance with a new admin refresh entrypoint.

Changes

  • Protocol trade fee (Add a protocol fee collector address that receives a 1% fee on every buy and sell #751): new ProtocolFeeBps storage entry (default 100 bps = 1% via set_protocol_fee with None), deducted from the trade amount before the creator/seller split is computed; fee is credited to the treasury and a fee_collected event carries the amount and treasury address. Admin can update both rate and treasury via set_protocol_fee; 0 bps skips the treasury credit entirely. Adds get_protocol_trade_fee view.
  • Holder cap (Add a max keys per wallet guard to prevent a single address from holding more than 10% of a creator's supply #752): per-creator cap in basis points (default 1000 = 10%) configured via set_holder_cap (creator-only, validated 1%-25%, else InvalidHolderCap). Buys that would push a non-creator wallet above the share of supply revert with MaxHoldingExceeded; the creator wallet is exempt. Adds get_holder_cap view.
  • Sell lockup (Add a sell lockup period preventing a buyer from selling keys within 24 hours of purchase #753): every buy records the ledger timestamp in LastBuyTimestamp(creator, holder); once the admin sets a duration via set_lockup_duration, sells inside the window revert with LockupPeriodActive and emit a lockup_blocked event. Default duration constant 86400s (24h). Adds get_lockup_duration view.
  • TTL maintenance (Add TTL bump calls on every read and write to persistent storage entries to prevent state expiry #749): new TTL_MIN_EXTENSION_LEDGERS (~30 days) floor with bump_persistent_ttl applied after hot persistent reads (key price, fee config, referral bps) and full-window extensions after writes across trades, credits, claims, stakes, transfers, withdrawals and admin config setters; new admin-only refresh_ttl(creators) re-extends all known global entries plus each supplied creator's scoped entries in one call.
  • Appends error codes 41-43 (MaxHoldingExceeded, LockupPeriodActive, InvalidHolderCap) and documents them in docs/error-codes.md; documents the four new storage keys in docs/storage-layout.md. All features are dormant until configured, so existing deployments and tests are unaffected.

Issues

Resolves #753
Resolves #752
Resolves #751
Resolves #749

Verification

Manual code review completed: full diff inspected against all four issue acceptance criteria, rustfmt passes, and no snapshots or generated files were touched. New integration tests were added under creator-keys/tests/ (protocol_trade_fee.rs, holder_cap.rs, sell_lockup.rs, ttl_refresh.rs) covering buy/sell fee routing, cap enforcement and exemption, lockup rejection/expiry/timestamp refresh, and TTL extension plus refresh. cargo build and cargo test were not run.

@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@vjuliaife 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

@Chucks1093
Chucks1093 merged commit aa46355 into accesslayerorg:main Aug 27, 2026
1 check failed
Adejumo-2 added a commit to Adejumo-2/accesslayer-contracts that referenced this pull request Aug 28, 2026
…and accesslayerorg#795

Two PRs (protocol-fee-holder-cap-lockup-ttl and
fix/issues-758-757-756-755) branched from the same base and added
items at positions 41-43 in ContractError, plus different DataKey
variants, storage helpers, contract methods, and event types. When
merged into main, the implementation code was silently dropped while
the test files survived, causing compilation failures.

Restored:
- DataKey variants: RoyaltyConfig, CurveExponent, AuctionConfig,
  StakeUnlockLedger, TotalStaked, StakingRewardsPool, HolderCapBps,
  LastBuyTimestamp, ProtocolFeeBps, LockupDurationSecs
- ContractError variants: BatchSizeExceeded, RoyaltyExceedsLimit,
  InvalidExponent, MaxHoldingExceeded, LockupPeriodActive,
  InvalidHolderCap
- Contract methods: batch_buy, set_royalty, get_royalty_config,
  migrate_curve, get_curve_exponent, refresh_ttl
- Event types: FeeCollectedEvent, LockupBlockedEvent
- Storage helpers: holder_cap_bps, last_buy_timestamp
- AuctionConfig struct
- cargo fmt applied to all affected files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment