Epoch Smart Contracts
Below we describe our smart contracts and functions. We are currently using:
- Solidity version 0.8.12
- OpenZeppelin version 4.7.3
We have implemented the OpenZeppelin upgradeable contract pattern and will be using a multi-sig Gnosis wallet in production in conjunction with the OpenZeppelin Defender deployment and administration platform
We use many OpenZeppelin contracts, including:
- AddressUpgradeable
- CountersUpgradeable
- StringsUpgadable
- MathUpgradeable
- SafeMathUpgradeable
- OwnableUpgradeable
- PausableUpgradeable
- ReentrancyGuardUpgradeable
- Initializable
- ERC20
The Epochs are implemented in the EpochChannel contract. Important implementation details:
- newChan - this is called by the authorized contract starter account (e.g. the contractOwner) CREATE a new channel. A new channel is created by giving the time it will open (timeOpen), the estimated start time (estStarted), the expiration time (timeExpired), the asset, and the percentage price to use. The percentage price is expressed as a percentage of one 18 digit eth, so 1.25 percent is 1.25e16
- startChan - once the time is past the estStarted time this function is called to actually start the Epoch. Starting the channel sets the channel range based on the current spot price based on the previously advertised channel width
- In the case that there is a large investment imbalance between Stay In and Break Out, more than MAX_MULT (e.g. 16), then the Epoch is canceled
- MAX_DELAY is current 180 seconds. This is the maximum time an Epoch can delay after estStarted before starting. After MAX_DELAY the contract is canceled
- buy - this is a payable function. In addition to sending the ETH, you must specify inChan as a boolean, so StayIn side is true, and BreakOut is false
- claim - This is called by BracketX's automation when the Epoch's price breaks out of the price channel, or it is at full term
- pay - The pay function is called by BracketX's automation and transfers the payment amount after the claim into the investors wallet account