Skip to content

Instantly share code, notes, and snippets.

@tspoff
Created February 15, 2020 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspoff/b318bb62154ec373580da0d767f5150b to your computer and use it in GitHub Desktop.
Save tspoff/b318bb62154ec373580da0d767f5150b to your computer and use it in GitHub Desktop.
pragma solidity ^0.5.7;
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
/// @title PolynomialCurvedToken - A polynomial bonding curve
/// implementation that is backed by an EIP20 token.
contract PolynomialCurveLogic {
using SafeMath for uint256;
uint256 private constant PRECISION = 10000000000;
uint8 public exponent;
/// @dev constructor Initializes the bonding curve
/// @param _exponent The exponent of the curve
constructor(uint8 _exponent) public {
exponent = _exponent;
}
/// @dev Calculate the integral from 0 to t
/// @param t The number to integrate to
function curveIntegral(uint256 t) internal returns (uint256) {
uint256 nexp = exponent + 1;
// Calculate integral of t^exponent
return PRECISION.div(nexp).mul(t ** nexp).div(PRECISION);
}
function calcMintPrice(uint256 totalSupply, uint256 reserveBalance, uint256 amount)
public
returns (uint256)
{
return curveIntegral(totalSupply.add(amount)).sub(reserveBalance);
}
function calcBurnReward(uint256 totalSupply, uint256 reserveBalance, uint256 amount)
public
returns (uint256)
{
return reserveBalance.sub(curveIntegral(totalSupply.sub(amount)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment