-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: math lib for dynamic exponential curves #5157
Comments
Hi @0xneves, thanks for opening the issue. I like the idea of the curve as a generic primitive since it can be used to build interesting DeFi projects like Uniswap Hooks. I'm wondering if the potential users of this function wouldn't otherwise build their own dedicated curve. I have the impression that any curve in a protocol should remain constant, in which case it'd make more sense to implement the function straight. It'd be great if you have a concrete case where the behavior of the curve is dynamic, so that an audited implementation by OpenZeppelin is required. Answering your questions:
So far nobody has requested it, and normally, math-heavy functions have been a good fit for other community-maintained libraries (see prb-math as an example). I see how future plans may benefit from this primitive but that's not the only thing we consider before merging a PR.
We expect community involvement and discussion first. A PR is welcome when we have a clear understanding of the problem we're tackling and there's enough community input for us to ship an implementation comfortably. This is documented in our CONTRIBUTING docs Once we merge and release a piece of code, it's subject to our Backwards Compatibility practices.
We're happy to take PRs and guide contributors towards a successful contribution. Not all issues have to be solved and some of them become relevant based on the current market conditions. The best way of helping us moving things forward is to bring new opinions to any of the issues already open, so we can find opportunities to make the library better in a responsible and sustainable way. |
Hey @ernestognw , thank you for the very dedicated response! Really appreciated the time. Firstly I agree that having the function in a math-heavy environment would be better. The exponential Euler itself came from Paul's repo. But nonetheless, we need to cease the conversation here! There are a lot of cases that the curve can be a helpful standard for protocols like you said yourself, most of them use constant curves for their means but with every new upgrade in the protocol they have to deploy a new curve with different parameters. ENS is one simple example. Another one could be the Frax Vaults managers or any other protocol that needs to change investment strategies based on liquidity / APY. I've always observed linear or poorly coded curves used in games and Vesting modules because nobody has made them available to the public. Therefore I see that the industry lacks innovative ideas not because they don't want to, but because is a hard task dealing with fixed-point-arithmetics in Solidity, making it impossible for the regular user to use exponential functions. Having an easy-to-use programmable curve could shift the public perspective into building new innovative ideas. Although this is not a standard, it is a ... Thank you for answering all of my questions, it clarified a lot! |
🧐 Motivation
Inspired by ENS's premium decay curve, which reduces the cost of premium names over time, this feature aims to create a more general-purpose curve that can be used in various applications. Since calculating exponentials in Solidity is not easy because of its fixed-point arithmetic, developers are obliged to use simpler equations for growth or decay, and most times linear. This feature provides a more nuanced control over how parameters evolve over time, leading to more sophisticated applications and user experience.
📝 Details
This feature suggests an exponential curve formula designed to handle various time-based events such as token vesting, game mechanics, unlock schedules, and other timestamp-dependent actions. The core functionality is driven by an exponential curve formula allowing for smooth, nonlinear transitions over time, providing a more sophisticated and flexible approach than linear models.
Ascending Curve
Descending Curve
Where:
t
is the current timestamp.t0
is the start timestamp.T
is the end timestamp.k
is the curvature factor, determining the steepness of the curve (2 decimals precision).exp()
is the exponential function with base 'E' (Euler's number, approximately 2.71828).The ascending curve starts at 0% and increases to 100% over time, while the descending curve starts at 100% and decreases to 0% over time.
The curvature factor k allows for fine-tuning the curve's shape, providing a wide range of possibilities for customizing the curve's behavior. A higher k value results in a steeper curve, while a lower k value results in a flatter curve. This flexibility enables developers to create complex time-based scenarios with precise control over the curve's progression. For better precision, the curvature factor is an integer with two (2) decimal places, allowing for a range of -100.00 to 100.00.
Definition of Done
My truly honest question here is:
🔗 Reference
https://github.com/0xneves/EXPCurves/blob/main/contracts/EXPCurves.sol
The text was updated successfully, but these errors were encountered: