Overview
RektHub uses optimized libraries for bonding curve calculations. These utilities handle the constant product math that powers price discovery and trading.For Integrators: You typically don’t need to use these libraries
directly—the BondingCurve contract handles all calculations. This reference is
useful if you’re building off-chain quoters, simulators, or custom trading
algorithms.
BondingCurveMath
The core library for constant product (x × y = k) bonding curve calculations. Location:contracts/libraries/BondingCurveMath.sol
Purpose
- Calculate token outputs for buy orders
- Calculate native outputs for sell orders
- Calculate fees as percentages (basis points)
- Pure functions—no state modifications
Functions
calculateBuyReturn
Calculate how many tokens a buyer will receive for a given native token input.nativeAmount(uint256): Amount of native tokens to spend (after fees)virtualNativeReserves(uint256): Current virtual native reserves in the curvevirtualTokenReserves(uint256): Current virtual token reserves in the curve
tokensOut: Amount of tokens the buyer will receive
x * y = k
Example Usage:
Important: This calculates the raw output before considering real reserve
limits. The BondingCurve contract takes the minimum of this calculation and
available real tokens.
calculateSellReturn
Calculate how many native tokens a seller will receive for selling tokens.tokenAmount(uint256): Amount of tokens to sellvirtualNativeReserves(uint256): Current virtual native reserves in the curvevirtualTokenReserves(uint256): Current virtual token reserves in the curve
nativeOut: Amount of native tokens the seller will receive (before fees)
calculateFee
Calculate a fee as a percentage using basis points.amount(uint256): Amount to calculate fee onfeeBasisPoints(uint256): Fee in basis points (100 = 1%, 10000 = 100%)
fee: Calculated fee amount
Next Steps
Bonding Curves Explained
Understand the economics
Bonding Curve Contract
See how it’s implemented
Events Reference
Track trades with events
Interfaces
Contract interfaces and ABIs