-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
461 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
interface ICurve { | ||
function minSupply() external view returns (uint256); | ||
|
||
function maxSupply() external view returns (uint256); | ||
|
||
function minCeiling() external view returns (uint256); | ||
|
||
function maxCeiling() external view returns (uint256); | ||
|
||
function calcCeiling(uint256 _supply) external view returns (uint256); | ||
} | ||
|
||
abstract contract Curve is ICurve { | ||
/* ========== EVENTS ========== */ | ||
|
||
event MinSupplyChanged( | ||
address indexed operator, | ||
uint256 _old, | ||
uint256 _new | ||
); | ||
|
||
event MaxSupplyChanged( | ||
address indexed operator, | ||
uint256 _old, | ||
uint256 _new | ||
); | ||
|
||
event MinCeilingChanged( | ||
address indexed operator, | ||
uint256 _old, | ||
uint256 _new | ||
); | ||
|
||
event MaxCeilingChanged( | ||
address indexed operator, | ||
uint256 _old, | ||
uint256 _new | ||
); | ||
|
||
/* ========== STATE VARIABLES ========== */ | ||
|
||
uint256 public override minSupply; | ||
uint256 public override maxSupply; | ||
|
||
uint256 public override minCeiling; | ||
uint256 public override maxCeiling; | ||
|
||
/* ========== GOVERNANCE ========== */ | ||
|
||
function setMinSupply(uint256 _newMinSupply) public virtual { | ||
uint256 oldMinSupply = minSupply; | ||
minSupply = _newMinSupply; | ||
emit MinSupplyChanged(msg.sender, oldMinSupply, _newMinSupply); | ||
} | ||
|
||
function setMaxSupply(uint256 _newMaxSupply) public virtual { | ||
uint256 oldMaxSupply = maxSupply; | ||
maxSupply = _newMaxSupply; | ||
emit MaxSupplyChanged(msg.sender, oldMaxSupply, _newMaxSupply); | ||
} | ||
|
||
function setMinCeiling(uint256 _newMinCeiling) public virtual { | ||
uint256 oldMinCeiling = _newMinCeiling; | ||
minCeiling = _newMinCeiling; | ||
emit MinCeilingChanged(msg.sender, oldMinCeiling, _newMinCeiling); | ||
} | ||
|
||
function setMaxCeiling(uint256 _newMaxCeiling) public virtual { | ||
uint256 oldMaxCeiling = _newMaxCeiling; | ||
maxCeiling = _newMaxCeiling; | ||
emit MaxCeilingChanged(msg.sender, oldMaxCeiling, _newMaxCeiling); | ||
} | ||
|
||
function calcCeiling(uint256 _supply) | ||
external | ||
view | ||
virtual | ||
override | ||
returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol'; | ||
|
||
import {Operator} from '../owner/Operator.sol'; | ||
import {Curve} from './Curve.sol'; | ||
|
||
contract LinearThreshold is Operator, Curve { | ||
using SafeMath for uint256; | ||
|
||
/* ========== CONSTRUCTOR ========== */ | ||
|
||
constructor( | ||
uint256 _minSupply, | ||
uint256 _maxSupply, | ||
uint256 _minCeiling, | ||
uint256 _maxCeiling | ||
) public { | ||
minSupply = _minSupply; | ||
maxSupply = _maxSupply; | ||
minCeiling = _minCeiling; | ||
maxCeiling = _maxCeiling; | ||
} | ||
|
||
/* ========== GOVERNANCE ========== */ | ||
|
||
function setMinSupply(uint256 _newMinSupply) public override onlyOperator { | ||
super.setMinSupply(_newMinSupply); | ||
} | ||
|
||
function setMaxSupply(uint256 _newMaxSupply) public override onlyOperator { | ||
super.setMaxSupply(_newMaxSupply); | ||
} | ||
|
||
function setMinCeiling(uint256 _newMinCeiling) | ||
public | ||
override | ||
onlyOperator | ||
{ | ||
super.setMinCeiling(_newMinCeiling); | ||
} | ||
|
||
function setMaxCeiling(uint256 _newMaxCeiling) | ||
public | ||
override | ||
onlyOperator | ||
{ | ||
super.setMaxCeiling(_newMaxCeiling); | ||
} | ||
|
||
/* ========== VIEW FUNCTIONS ========== */ | ||
|
||
function calcCeiling(uint256 _supply) | ||
public | ||
view | ||
override | ||
returns (uint256) | ||
{ | ||
if (_supply <= minSupply) { | ||
return maxCeiling; | ||
} | ||
if (_supply >= maxSupply) { | ||
return minCeiling; | ||
} | ||
|
||
uint256 slope = | ||
maxCeiling.sub(minCeiling).mul(1e18).div(maxSupply.sub(minSupply)); | ||
uint256 ceiling = | ||
maxCeiling.sub(slope.mul(_supply.sub(minSupply)).div(1e18)); | ||
|
||
return ceiling; | ||
} | ||
} |
Oops, something went wrong.