feat: add graduated bonding curve with supply milestones (#829) - #849
Open
ayomustap wants to merge 3 commits into
Open
feat: add graduated bonding curve with supply milestones (#829)#849ayomustap wants to merge 3 commits into
ayomustap wants to merge 3 commits into
Conversation
…org#829) Implement a configurable graduated bonding curve where the pricing exponent switches at configurable supply milestones. Adds: - set_graduated_curve: creator-authorized config of (supply_threshold, exponent) milestone pairs; panics with CurveAlreadyActive once sales have started. - get_graduated_curve: read-only view of configured milestones. - compute_bonding_curve_price now prefers the graduated curve and selects the exponent for the current supply before falling back to CurveExponent/presets. - CurveConfigError enum (CurveAlreadyActive, InvalidExponent, InvalidMilestoneOrder, EmptyMilestones, NotRegistered). - GRADUATED_CURVE_CONFIGURED_EVENT_NAME + GraduatedCurveConfiguredEvent + graduated_curve_configured_topics. - test_graduated_curve acceptance tests. Also repairs the non-compiling baseline in lib.rs/events.rs so the feature can build: closes the unclosed brace in the buy circuit breaker, restores the threshold_pct read, removes duplicate definitions (events, DataKey variants, storage helpers, credit_staking_rewards_pool), adds missing ContractError variants, DataKey variants, structs, storage helpers, and events, and adds missing testutils::Ledger imports. Reconciles the staking rewards pool storage (StakingRewardsState) between fee crediting and the staking entrypoints.
|
@ayomustap 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
|
Fix MC |
Author
|
@Chucks1093 fixed |
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
Implements a graduated bonding curve (issue #829): a configurable pricing schedule where the bonding curve exponent switches at configurable supply milestones, allowing creators to steepen price growth as supply grows.
Closes #829
What changed
Graduated curve feature
set_graduated_curve(env, creator, milestones)— a creator-authorized entrypoint that configures the curve as a list of(supply_threshold, exponent)milestone pairs.CurveConfigError::CurveAlreadyActiveif any keys have already been sold (read_creator_supply != 0), enforcing that the curve must be set before sales start.1..=5(InvalidExponent).InvalidMilestoneOrder).EmptyMilestones).NotRegistered).get_graduated_curve(env, creator)— read-only view; returns the configured milestones or an empty vector.compute_bonding_curve_pricenow takes the graduated curve into account (highest precedence): it selects the exponent for the current supply viagraduated_exponent_for_supply(using the last milestone whose threshold<= supply, otherwise the base exponent1) before falling back to the existingCurveExponent/preset path.CurveConfigError— a new error enum becauseContractErrorwas already at Soroban's 50-variant cap. Variants are appended at the end of their enum to preserve ABI discriminants.graduated_curve_configured(GRADUATED_CURVE_CONFIGURED_EVENT_NAME) emitted with payloadGraduatedCurveConfiguredEvent { creator, milestones, ledger }. Event fields are appended (not reordered) for schema stability.DataKey::GraduatedCurve(Address)variant with agraduated_curve(creator)storage helper.Tests
creator-keys/src/test_graduated_curve.rswith acceptance tests covering:CurveAlreadyActivepanic when configuration is attempted after a sale has occurred (test sets a high circuit-breaker threshold before buying so supply becomes> 0).get_graduated_curveview + thegraduated_curve_configuredevent emission.Build/completeness repair (required to build & test the feature)
The base branch (
f251b81) did not compile — it had an unclosed delimiter plus many pre-existing compile errors from a corrupted merge. These had to be repaired for the feature to build and be validated without regressions:buy_key_with_referrercircuit-breaker block (root cause of the unclosed delimiter).threshold_pctread (unwrap_or(30)) in the circuit-breaker logic.FEE_COLLECTED_EVENT_NAME/LOCKUP_BLOCKED_EVENT_NAMEand their topic/event types, duplicateRoyaltyConfig/CurveExponentDataKeyvariants, duplicateholder_cap_bps/last_buy_timestampstorage helpers, and the first duplicatecredit_staking_rewards_pool.ContractError::GlobalTradingHalted/FreezeQuantityExceedsBalance, severalDataKeyvariants, structs (StakingKey,StakePosition,StakingRewardsState,StakeExit,StakeRewardClaim,AuctionConfig), storage helpers,AuctionPurchaseEvent, and theStakingKeyimport.StakingRewardsStatebetween fee crediting (credit_staking_rewards_pool) and the staking entrypoints, which previously wrote/read conflicting types to the same key.use soroban_sdk::testutils::Ledgertotests/launch_penalty.rs(a pre-existing compile fix unrelated to the feature).Verification
cargo build -p creator-keys— compiles (only a pre-existingfinal_proceedsunused-assignment warning remains, untouched/out of scope).cargo test -p creator-keys --lib— 134 passed, 0 failed, including the newtest_graduated_curvetests and the previously-failing staking lifecycle test.Note on remaining pre-existing breakage
Some integration tests under
creator-keys/tests/(co_creator_removal,prelaunch_auction,auction_bonding_curve_transition,staking_reward_claim) still fail to compile because they reference features (e.g.remove_co_creator,configure_auction,get_stake_unlock_ledger, and related event types) that were never implemented/merged intolib.rsin the base. These are pre-existing, out of scope for this issue, and were already non-compiling at the baseline.