Skip to content

Commit

Permalink
Merge pull request #202 from pooltogether/pool-1715-rename-drawhistor…
Browse files Browse the repository at this point in the history
…y-to-drawbuffer

chore(DrawHistory): rename to DrawBuffer
  • Loading branch information
PierrickGT committed Oct 6, 2021
2 parents 30bdf22 + 1c15c6e commit b039133
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 226 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ https://docs.pooltogether.com
# Overview
- [DrawBeacon](/contracts/DrawBeacon.sol)
- [DrawCalculator](/contracts/DrawCalculator.sol)
- [DrawHistory](/contracts/DrawHistory.sol)
- [DrawBuffer](/contracts/DrawBuffer.sol)
- [PrizeDistributor](/contracts/PrizeDistributor.sol)
- [PrizeSplitStrategy](/contracts/PrizeSplitStrategy.sol)
- [Reserve](/contracts/Reserve.sol)
Expand Down Expand Up @@ -100,7 +100,7 @@ $ ./scripts/setup.sh
# Deployment

## Testnets
Deployment is maintained in a different [repo](https://github.com/pooltogether/v4-testnet).
Deployment is maintained in a different [repo](https://github.com/pooltogether/v4-testnet).

## Mainnet
Todo: insert deployment repo link here.
Todo: insert deployment repo link here.
58 changes: 29 additions & 29 deletions contracts/DrawBeacon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import "@pooltogether/pooltogether-rng-contracts/contracts/RNGInterface.sol";
import "@pooltogether/owner-manager-contracts/contracts/Ownable.sol";

import "./interfaces/IDrawBeacon.sol";
import "./interfaces/IDrawHistory.sol";
import "./interfaces/IDrawBuffer.sol";


/**
* @title PoolTogether V4 DrawBeacon
* @author PoolTogether Inc Team
* @notice Manages RNG (random number generator) requests and pushing Draws onto DrawHistory.
* @notice Manages RNG (random number generator) requests and pushing Draws onto DrawBuffer.
The DrawBeacon has 3 major actions for requesting a random number: start, cancel and complete.
To create a new Draw, the user requests a new random number from the RNG service.
To create a new Draw, the user requests a new random number from the RNG service.
When the random number is available, the user can create the draw using the create() method
which will push the draw onto the DrawHistory.
which will push the draw onto the DrawBuffer.
If the RNG service fails to deliver a rng, when the request timeout elapses, the user can cancel the request.
*/
contract DrawBeacon is IDrawBeacon, Ownable {
Expand All @@ -35,8 +35,8 @@ contract DrawBeacon is IDrawBeacon, Ownable {
/// @notice Current RNG Request
RngRequest internal rngRequest;

/// @notice DrawHistory address
IDrawHistory internal drawHistory;
/// @notice DrawBuffer address
IDrawBuffer internal drawBuffer;

/**
* @notice RNG Request Timeout. In fact, this is really a "complete draw" timeout.
Expand All @@ -51,7 +51,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
uint64 internal beaconPeriodStartedAt;

/**
* @notice Next Draw ID to use when pushing a Draw onto DrawHistory
* @notice Next Draw ID to use when pushing a Draw onto DrawBuffer
* @dev Starts at 1. This way we know that no Draw has been recorded at 0.
*/
uint32 internal nextDrawId;
Expand Down Expand Up @@ -106,15 +106,15 @@ contract DrawBeacon is IDrawBeacon, Ownable {
/**
* @notice Deploy the DrawBeacon smart contract.
* @param _owner Address of the DrawBeacon owner
* @param _drawHistory The address of the draw history to push draws to
* @param _drawBuffer The address of the draw buffer to push draws to
* @param _rng The RNG service to use
* @param _nextDrawId Draw ID at which the DrawBeacon should start. Can't be inferior to 1.
* @param _beaconPeriodStart The starting timestamp of the beacon period.
* @param _beaconPeriodSeconds The duration of the beacon period in seconds
*/
constructor(
address _owner,
IDrawHistory _drawHistory,
IDrawBuffer _drawBuffer,
RNGInterface _rng,
uint32 _nextDrawId,
uint64 _beaconPeriodStart,
Expand All @@ -129,7 +129,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
nextDrawId = _nextDrawId;

_setBeaconPeriodSeconds(_beaconPeriodSeconds);
_setDrawHistory(_drawHistory);
_setDrawBuffer(_drawBuffer);
_setRngService(_rng);
_setRngTimeout(_rngTimeout);

Expand Down Expand Up @@ -191,7 +191,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
}

/// @inheritdoc IDrawBeacon
function calculateNextBeaconPeriodStartTime(uint256 _currentTime)
function calculateNextBeaconPeriodStartTime(uint256 _time)
external
view
override
Expand All @@ -201,7 +201,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
_calculateNextBeaconPeriodStartTime(
beaconPeriodStartedAt,
beaconPeriodSeconds,
uint64(_currentTime)
uint64(_time)
);
}

Expand Down Expand Up @@ -231,7 +231,7 @@ contract DrawBeacon is IDrawBeacon, Ownable {
beaconPeriodSeconds: _beaconPeriodSeconds
});

drawHistory.pushDraw(_draw);
drawBuffer.pushDraw(_draw);

// to avoid clock drift, we should calculate the start time based on the previous period start time.
uint64 nextBeaconPeriodStartedAt = _calculateNextBeaconPeriodStartTime(
Expand Down Expand Up @@ -267,8 +267,8 @@ contract DrawBeacon is IDrawBeacon, Ownable {
return beaconPeriodStartedAt;
}

function getDrawHistory() external view returns (IDrawHistory) {
return drawHistory;
function getDrawBuffer() external view returns (IDrawBuffer) {
return drawBuffer;
}

function getNextDrawId() external view returns (uint32) {
Expand Down Expand Up @@ -298,13 +298,13 @@ contract DrawBeacon is IDrawBeacon, Ownable {
}

/// @inheritdoc IDrawBeacon
function setDrawHistory(IDrawHistory newDrawHistory)
function setDrawBuffer(IDrawBuffer newDrawBuffer)
external
override
onlyOwner
returns (IDrawHistory)
returns (IDrawBuffer)
{
return _setDrawHistory(newDrawHistory);
return _setDrawBuffer(newDrawBuffer);
}

/// @inheritdoc IDrawBeacon
Expand Down Expand Up @@ -428,25 +428,25 @@ contract DrawBeacon is IDrawBeacon, Ownable {
}

/**
* @notice Set global DrawHistory variable.
* @dev All subsequent Draw requests/completions will be pushed to the new DrawHistory.
* @param _newDrawHistory DrawHistory address
* @return DrawHistory
* @notice Set global DrawBuffer variable.
* @dev All subsequent Draw requests/completions will be pushed to the new DrawBuffer.
* @param _newDrawBuffer DrawBuffer address
* @return DrawBuffer
*/
function _setDrawHistory(IDrawHistory _newDrawHistory) internal returns (IDrawHistory) {
IDrawHistory _previousDrawHistory = drawHistory;
require(address(_newDrawHistory) != address(0), "DrawBeacon/draw-history-not-zero-address");
function _setDrawBuffer(IDrawBuffer _newDrawBuffer) internal returns (IDrawBuffer) {
IDrawBuffer _previousDrawBuffer = drawBuffer;
require(address(_newDrawBuffer) != address(0), "DrawBeacon/draw-history-not-zero-address");

require(
address(_newDrawHistory) != address(_previousDrawHistory),
address(_newDrawBuffer) != address(_previousDrawBuffer),
"DrawBeacon/existing-draw-history-address"
);

drawHistory = _newDrawHistory;
drawBuffer = _newDrawBuffer;

emit DrawHistoryUpdated(_newDrawHistory);
emit DrawBufferUpdated(_newDrawBuffer);

return _newDrawHistory;
return _newDrawBuffer;
}

/**
Expand Down
32 changes: 16 additions & 16 deletions contracts/DrawHistory.sol → contracts/DrawBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ pragma solidity 0.8.6;

import "@pooltogether/owner-manager-contracts/contracts/Manageable.sol";

import "./interfaces/IDrawHistory.sol";
import "./interfaces/IDrawBuffer.sol";
import "./interfaces/IDrawBeacon.sol";
import "./interfaces/IDrawBeacon.sol";
import "./libraries/DrawRingBufferLib.sol";

/**
* @title PoolTogether V4 DrawHistory
* @title PoolTogether V4 DrawBuffer
* @author PoolTogether Inc Team
* @notice The DrawHistory provides historical lookups of Draws via a circular ring buffer.
* @notice The DrawBuffer provides historical lookups of Draws via a circular ring buffer.
Historical Draws can be accessed on-chain using a drawId to calculate ring buffer storage slot.
The Draw settings can be created by manager/owner and existing Draws can only be updated the owner.
Once a starting Draw has been added to the ring buffer, all following draws must have a sequential Draw ID.
@dev A DrawHistory store a limited number of Draws before beginning to overwrite (managed via the cardinality) previous Draws.
@dev All mainnet DrawHistory(s) are updated directly from a DrawBeacon, but non-mainnet DrawHistory(s) (Matic, Optimism, Arbitrum, etc...)
@dev A DrawBuffer store a limited number of Draws before beginning to overwrite (managed via the cardinality) previous Draws.
@dev All mainnet DrawBuffer(s) are updated directly from a DrawBeacon, but non-mainnet DrawBuffer(s) (Matic, Optimism, Arbitrum, etc...)
will receive a cross-chain message, duplicating the mainnet Draw configuration - enabling a prize savings liquidity network.
*/
contract DrawHistory is IDrawHistory, Manageable {
contract DrawBuffer is IDrawBuffer, Manageable {
using DrawRingBufferLib for DrawRingBufferLib.Buffer;

/// @notice Draws ring buffer max length.
Expand All @@ -35,8 +35,8 @@ contract DrawHistory is IDrawHistory, Manageable {
/* ============ Deploy ============ */

/**
* @notice Deploy DrawHistory smart contract.
* @param _owner Address of the owner of the DrawHistory.
* @notice Deploy DrawBuffer smart contract.
* @param _owner Address of the owner of the DrawBuffer.
* @param _cardinality Draw ring buffer cardinality.
*/
constructor(address _owner, uint8 _cardinality) Ownable(_owner) {
Expand All @@ -45,17 +45,17 @@ contract DrawHistory is IDrawHistory, Manageable {

/* ============ External Functions ============ */

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getBufferCardinality() external view override returns (uint32) {
return drawRingBuffer.cardinality;
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getDraw(uint32 drawId) external view override returns (IDrawBeacon.Draw memory) {
return _draws[_drawIdToDrawIndex(drawRingBuffer, drawId)];
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getDraws(uint32[] calldata _drawIds)
external
view
Expand All @@ -72,7 +72,7 @@ contract DrawHistory is IDrawHistory, Manageable {
return draws;
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getDrawCount() external view override returns (uint32) {
DrawRingBufferLib.Buffer memory buffer = drawRingBuffer;

Expand All @@ -89,12 +89,12 @@ contract DrawHistory is IDrawHistory, Manageable {
}
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getNewestDraw() external view override returns (IDrawBeacon.Draw memory) {
return _getNewestDraw(drawRingBuffer);
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function getOldestDraw() external view override returns (IDrawBeacon.Draw memory) {
// oldest draw should be next available index, otherwise it's at 0
DrawRingBufferLib.Buffer memory buffer = drawRingBuffer;
Expand All @@ -108,7 +108,7 @@ contract DrawHistory is IDrawHistory, Manageable {
return draw;
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function pushDraw(IDrawBeacon.Draw memory _draw)
external
override
Expand All @@ -118,7 +118,7 @@ contract DrawHistory is IDrawHistory, Manageable {
return _pushDraw(_draw);
}

/// @inheritdoc IDrawHistory
/// @inheritdoc IDrawBuffer
function setDraw(IDrawBeacon.Draw memory _newDraw) external override onlyOwner returns (uint32) {
DrawRingBufferLib.Buffer memory buffer = drawRingBuffer;
uint32 index = buffer.getIndex(_newDraw.drawId);
Expand Down
Loading

0 comments on commit b039133

Please sign in to comment.