Skip to content

feat: add simulate_buy and simulate_sell view functions (#836) - #843

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
sojetunde8:feat/simulate-view-functions
Sep 4, 2026
Merged

feat: add simulate_buy and simulate_sell view functions (#836)#843
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
sojetunde8:feat/simulate-view-functions

Conversation

@sojetunde8

Copy link
Copy Markdown
Contributor

Summary

Adds simulate_buy and simulate_sell read-only view functions to the CreatorKeysContract that compute bonding curve pricing for any quantity without mutating state. This powers client-side price previews and batch buy total cost estimates.

Closes #836


Motivation

Clients need to show price previews for various quantities without triggering a transaction. These simulation functions allow frontends to:

  • Display real-time buy/sell quotes for any key quantity
  • Estimate total cost before initiating a transaction
  • Support batch buying workflows with accurate cost breakdowns
  • Show fee breakdowns (creator fee + protocol fee) transparently

Changes

creator-keys/src/lib.rs

New struct: SimulateResponse

#[derive(Clone, Debug, PartialEq)]
#[contracttype]
pub struct SimulateResponse {
    pub total_cost: i128,       // Total cost (buy) or net proceeds (sell)
    pub per_unit_price: i128,   // Average price per key
    pub creator_fee: i128,      // Total creator fee portion
    pub protocol_fee: i128,     // Total protocol fee portion
}

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Member

❌ CI Failed — verify (Contracts CI)

The verify check is failing on this PR.

Likely causes:

  • Compile error from a mismatched type or unresolved import
  • cargo fmt not run — CI checks formatting
  • Unused variable or import triggering deny(warnings)

Steps to fix:

  1. Run cargo build locally and fix all compiler errors
  2. Run cargo fmt --all and commit the diff
  3. Push

@freebuff-web
freebuff-web Bot force-pushed the feat/simulate-view-functions branch 2 times, most recently from 3e21ded to f737cb6 Compare September 4, 2026 15:41
…rg#836)

Add read-only simulation functions that compute bonding curve pricing
for buy and sell operations without mutating state, enabling client-side
price previews and batch cost estimates.

Co-Authored-By: sojetunde8 <sojetunde8@gmail.com>
@freebuff-web
freebuff-web Bot force-pushed the feat/simulate-view-functions branch from f737cb6 to db76de3 Compare September 4, 2026 15:43
@Chucks1093
Chucks1093 merged commit 3428d29 into accesslayerorg:main Sep 4, 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 a bonding curve simulation view function that returns the buy and sell price for any supply and quantity without state mutation

2 participants