Skip to content

Traditionally, the implementation of an on-chain curve has been limited to the algebraic functions hard-coded into a contract. Transform curves bring a new paradigm of endless customization

Notifications You must be signed in to change notification settings

nftchance/transform-curves

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transform Curve

TransformCurve is a contract that implements the ability to define any curve on chain with the usage of circular transforms. Inputs are specified as circles with a radius, frequency and phase. The transform function takes in a circle and returns a new circle.

The transform function is applied to the input circle and the result is used as the input for the next transform. The output of the last transform is the output of the curve.

This implementation relies heavily on Solidity Trigonemtry that enables the use of trigonometric functions in Solidity.

Traditionally, the implementation of an on-chain curve has been limited to the algebraic functions hard-coded into a contract. While not all curves make sense to be used in all cases, they can exist with this model -- Goodbye opinion and hello design space!

In action, this means that one can enjoy a world like:

The different of curve transforms

Due to the surrounding complexity of this idea, you can find a more detailed explanation of the implementation in the Transform Curve (coming soon) document.

Functionally, this is as simple as discrete math implementation of a contiuous function.

The margin of error is extremely small and can be improved with the use of $N$ as curve clarity. The higher the $N$, the more accurate the curve will be.

A low number of $N$ will result in a lower gas cost for the curve evaluation. Additionally, when there are few circles and the values are small, the error is negligible. However, if the values are large, the error will be larger and thus the curve will be less accurate. This can be countered (to an extent) with the increase of $N$.

This enables the ability to construct curves using (a far more detailed process than illustrated below) such as:

The mechanism to build a curve

If you would like a more detailed explanation of the implementation, join cosanostra on Discord.

Usage

There are a few things going on here.

  1. My first rough work of this implementation in Python which can be found in /model.
  2. The solidity implementation of it in /contracts accompanied with tests.
    • Need to install hardhat and run npx hardhat test
  3. A supporting front-end to visualize created curves in /frontend.
    • Need to run npm install and then npm run dev

About

Traditionally, the implementation of an on-chain curve has been limited to the algebraic functions hard-coded into a contract. Transform curves bring a new paradigm of endless customization

Resources

Stars

Watchers

Forks