Skip to content

Commit

Permalink
Merge 2d3352d into 58140f2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Smith committed Dec 19, 2020
2 parents 58140f2 + 2d3352d commit 06709d9
Show file tree
Hide file tree
Showing 20 changed files with 591 additions and 608 deletions.
32 changes: 4 additions & 28 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ import './lib/Babylonian.sol';
import './lib/FixedPoint.sol';
import './lib/UniswapV2Library.sol';
import './lib/UniswapV2OracleLibrary.sol';
import './utils/Epoch.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';

// fixed window oracle that recomputes the average price for the entire period once every period
// note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period
contract Oracle {
contract Oracle is Epoch {
using FixedPoint for *;
using SafeMath for uint256;

/* ========= CONSTANT VARIABLES ======== */

uint256 public constant PERIOD = 1 days;

/* ========== STATE VARIABLES ========== */

// epoch
uint256 public startTime;
uint256 public epoch = 0;

// uniswap
address public token0;
address public token1;
Expand All @@ -43,8 +36,9 @@ contract Oracle {
address _factory,
address _tokenA,
address _tokenB,
uint256 _period,
uint256 _startTime
) public {
) public Epoch(_period, _startTime, 0) {
IUniswapV2Pair _pair = IUniswapV2Pair(
UniswapV2Library.pairFor(_factory, _tokenA, _tokenB)
);
Expand All @@ -57,24 +51,6 @@ contract Oracle {
uint112 reserve1;
(reserve0, reserve1, blockTimestampLast) = _pair.getReserves();
require(reserve0 != 0 && reserve1 != 0, 'Oracle: NO_RESERVES'); // ensure that there's liquidity in the pair

startTime = _startTime;
}

/* =================== Modifier =================== */

modifier checkEpoch {
require(now >= nextEpochPoint(), 'Oracle: not opened yet');

_;

epoch = epoch.add(1);
}

/* ========== VIEW FUNCTIONS ========== */

function nextEpochPoint() public view returns (uint256) {
return startTime.add(epoch.mul(PERIOD));
}

/* ========== MUTABLE FUNCTIONS ========== */
Expand Down
38 changes: 38 additions & 0 deletions contracts/SimpleERCFund.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma solidity ^0.6.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';

import './owner/Operator.sol';
import './interfaces/ISimpleERCFund.sol';

contract SimpleERCFund is ISimpleERCFund, Operator {
using SafeERC20 for IERC20;

function deposit(
address token,
uint256 amount,
string memory reason
) public override {
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
emit Deposit(msg.sender, now, reason);
}

function withdraw(
address token,
uint256 amount,
address to,
string memory reason
) public override onlyOperator {
IERC20(token).safeTransfer(to, amount);
emit Withdrawal(msg.sender, to, now, reason);
}

event Deposit(address indexed from, uint256 indexed at, string reason);
event Withdrawal(
address indexed from,
address indexed to,
uint256 indexed at,
string reason
);
}

0 comments on commit 06709d9

Please sign in to comment.