-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHybridBondingCurve.sol
43 lines (40 loc) · 1.17 KB
/
HybridBondingCurve.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: UNLICENCED
// Copyright: Bonding Labs - Begic Nedim
pragma solidity ^0.8.0;
import "./MathLib.sol";
/**
* @title HybridBondingCurve
* @notice Piecewise log->exp price formula:
* if s < T => P= B*log(1 + s/L), else => B*exp((s-T)/E).
*/
library HybridBondingCurve {
/**
* @dev getPrice in 1e18 scale
* @param supply current token supply
* @param B base price scale
* @param L early-phase sensitivity
* @param E exponential steepness
* @param T transition supply
*/
function getPrice(
uint256 supply,
uint256 B,
uint256 L,
uint256 E,
uint256 T
) internal pure returns (uint256) {
if (supply < T) {
// log regime
uint256 ratio = (supply * 1e18) / L;
uint256 logVal = MathLib.log1p(ratio);
// scale result by B, then /1e18
return (B * logVal) / 1e18;
} else {
// exp regime
uint256 diff = supply > T ? (supply - T) : 0;
int256 y = int256((diff * 1e18) / E);
uint256 expVal = MathLib.expWad(y);
return (B * expVal) / 1e18;
}
}
}