feat(#828): add configurable max buy quantity per transaction - #847
Open
dedukpe wants to merge 2 commits into
Open
feat(#828): add configurable max buy quantity per transaction#847dedukpe wants to merge 2 commits into
dedukpe wants to merge 2 commits into
Conversation
…action
Add per-creator limit on how many keys a single buy_keys transaction may
purchase, preventing single-tx supply grabs.
- Add set_max_buy_quantity(creator, max_qty) — creator-only setter (1..=10000)
- Add get_max_buy_quantity(creator) — read-only view
- Add buy_keys() entry point that accepts a quantity parameter, enforces the
limit, and processes each key individually along the bonding curve
- Store max_buy_quantity in persistent storage with TTL bump on update
- Emit MaxBuyQuantityUpdatedEvent ("mbq_upd") on limit changes
- QuantityExceedsLimit error when quantity > max_qty
- LimitTooHigh error when max_qty > 10_000
- None bounds / no limit configured: check skipped entirely
Also fixes pre-existing compilation issues:
- Re-indent circuit breaker block inside else branch
- Remove duplicate definitions from incomplete merges
- Add missing type stubs for AuctionConfig, StakingRewardsState, StakePosition, etc.
Closes accesslayerorg#828
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@dedukpe 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! 🚀 |
Member
❌ CI Failed —
|
Member
|
Fix CI and merge conflict |
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-creator limit on how many keys a single
buy_keystransaction may purchase, preventing single-transaction supply grabs.Closes #828
Changes
New Functions
set_max_buy_quantity(creator, max_qty)max_qtyis 1..=10 000. Stores in persistent storage with TTL bump. EmitsMaxBuyQuantityUpdatedEvent.get_max_buy_quantity(creator)Nonewhen no limit is configured.buy_keys(creator, buyer, payment, max_price, quantity, referrer)New Error Variants
QuantityExceedsLimitquantity > max_buy_quantityLimitTooHighmax_qty > 10_000New Event
MaxBuyQuantityUpdatedEvent("mbq_upd"):(MAX_BUY_QUANTITY_UPDATED_EVENT_NAME, creator_id){ creator_id, max_qty, ledger }Key Design Decisions
buy_key/buy_key_with_referrerunchanged — always purchase exactly 1 key. No breaking changes to existing callers (183+ call sites).buy_keysis the new multi-key entry point — acceptsquantity: u32parameter, enforces the per-transaction limit, and processes each key along the bonding curve individually.supply + N.max_buy_quantityis not set (None), the check is skipped entirely with zero overhead.MAX_BUY_QUANTITY_LIMIT = 10_000— hard ceiling for the setter to prevent unreasonable limits.Pre-existing Fixes
The main branch had compilation issues from incomplete merges:
ifblock insideelsebranch (missing closing brace)FEE_COLLECTED_EVENT_NAME,LOCKUP_BLOCKED_EVENT_NAME,credit_staking_rewards_pool, etc.)AuctionConfig,StakingRewardsState,StakePosition, etc.)DataKeyvariants andContractErrorvariantsAcceptance Criteria
QuantityExceedsLimitLimitTooHighUnauthorizedmax_buy_quantity_updatedevent emitted on changeTest Results