generated from pooltogether/pooltogether-contracts-template
-
Notifications
You must be signed in to change notification settings - Fork 5
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
16 changed files
with
457 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.6; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBeacon.sol"; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBuffer.sol"; | ||
import "@pooltogether/owner-manager-contracts/contracts/Manageable.sol"; | ||
import "./interfaces/IBeaconTimelockAndPushRouter.sol"; | ||
import "./interfaces/IPrizeDistributionFactory.sol"; | ||
import "./interfaces/IDrawCalculatorTimelock.sol"; | ||
|
||
/** | ||
* @title PoolTogether V4 BeaconTimelockAndPushRouter | ||
* @author PoolTogether Inc Team | ||
* @notice The BeaconTimelockAndPushRouter smart contract is an upgrade of the L1TimelockTimelock smart contract. | ||
Reducing protocol risk by eliminating off-chain computation of PrizeDistribution parameters. The timelock will | ||
only pass the total supply of all tickets in a "PrizePool Network" to the prize distribution factory contract. | ||
*/ | ||
contract BeaconTimelockAndPushRouter is IBeaconTimelockAndPushRouter, Manageable { | ||
/* ============ Global Variables ============ */ | ||
|
||
/// @notice PrizeDistributionFactory reference. | ||
IPrizeDistributionFactory public immutable prizeDistributionFactory; | ||
|
||
/// @notice DrawCalculatorTimelock reference. | ||
IDrawCalculatorTimelock public immutable timelock; | ||
|
||
/* ============ Constructor ============ */ | ||
|
||
/** | ||
* @notice Initialize BeaconTimelockAndPushRouter smart contract. | ||
* @param _owner The smart contract owner | ||
* @param _prizeDistributionFactory PrizeDistributionFactory address | ||
* @param _timelock DrawCalculatorTimelock address | ||
*/ | ||
constructor( | ||
address _owner, | ||
IPrizeDistributionFactory _prizeDistributionFactory, | ||
IDrawCalculatorTimelock _timelock | ||
) Ownable(_owner) { | ||
prizeDistributionFactory = _prizeDistributionFactory; | ||
timelock = _timelock; | ||
emit Deployed(_prizeDistributionFactory, _timelock); | ||
} | ||
|
||
/// @inheritdoc IBeaconTimelockAndPushRouter | ||
function push(IDrawBeacon.Draw memory _draw, uint256 _totalNetworkTicketSupply) | ||
external | ||
override | ||
onlyManagerOrOwner | ||
{ | ||
timelock.lock(_draw.drawId, _draw.timestamp + _draw.beaconPeriodSeconds); | ||
prizeDistributionFactory.pushPrizeDistribution(_draw.drawId, _totalNetworkTicketSupply); | ||
emit DrawLockedAndTotalNetworkTicketSupplyPushed( | ||
_draw.drawId, | ||
_draw, | ||
_totalNetworkTicketSupply | ||
); | ||
} | ||
} |
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
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,65 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.6; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBeacon.sol"; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBuffer.sol"; | ||
import "@pooltogether/owner-manager-contracts/contracts/Manageable.sol"; | ||
import "./interfaces/IReceiverTimelockAndPushRouter.sol"; | ||
import "./interfaces/IPrizeDistributionFactory.sol"; | ||
import "./interfaces/IDrawCalculatorTimelock.sol"; | ||
|
||
/** | ||
* @title PoolTogether V4 ReceiverTimelockAndPushRouter | ||
* @author PoolTogether Inc Team | ||
* @notice The ReceiverTimelockAndPushRouter smart contract is an upgrade of the L2TimelockTimelock smart contract. | ||
Reducing protocol risk by eliminating off-chain computation of PrizeDistribution parameters. The timelock will | ||
only pass the total supply of all tickets in a "PrizePool Network" to the prize distribution factory contract. | ||
*/ | ||
contract ReceiverTimelockAndPushRouter is IReceiverTimelockAndPushRouter, Manageable { | ||
/* ============ Global Variables ============ */ | ||
|
||
/// @notice The DrawBuffer contract address. | ||
IDrawBuffer public immutable drawBuffer; | ||
|
||
/// @notice Internal PrizeDistributionFactory reference. | ||
IPrizeDistributionFactory public immutable prizeDistributionFactory; | ||
|
||
/// @notice Timelock struct reference. | ||
IDrawCalculatorTimelock public immutable timelock; | ||
|
||
/* ============ Constructor ============ */ | ||
|
||
/** | ||
* @notice Initialize ReceiverTimelockAndPushRouter smart contract. | ||
* @param _owner The smart contract owner | ||
* @param _drawBuffer DrawBuffer address | ||
* @param _prizeDistributionFactory PrizeDistributionFactory address | ||
* @param _timelock DrawCalculatorTimelock address | ||
*/ | ||
constructor( | ||
address _owner, | ||
IDrawBuffer _drawBuffer, | ||
IPrizeDistributionFactory _prizeDistributionFactory, | ||
IDrawCalculatorTimelock _timelock | ||
) Ownable(_owner) { | ||
drawBuffer = _drawBuffer; | ||
prizeDistributionFactory = _prizeDistributionFactory; | ||
timelock = _timelock; | ||
emit Deployed(_drawBuffer, _prizeDistributionFactory, _timelock); | ||
} | ||
|
||
/// @inheritdoc IReceiverTimelockAndPushRouter | ||
function push(IDrawBeacon.Draw memory _draw, uint256 _totalNetworkTicketSupply) | ||
external | ||
override | ||
onlyManagerOrOwner | ||
{ | ||
timelock.lock(_draw.drawId, _draw.timestamp + _draw.beaconPeriodSeconds); | ||
drawBuffer.pushDraw(_draw); | ||
prizeDistributionFactory.pushPrizeDistribution(_draw.drawId, _totalNetworkTicketSupply); | ||
emit DrawLockedPushedAndTotalNetworkTicketSupplyPushed( | ||
_draw.drawId, | ||
_draw, | ||
_totalNetworkTicketSupply | ||
); | ||
} | ||
} |
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,38 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.6; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBeacon.sol"; | ||
import "./IPrizeDistributionFactory.sol"; | ||
import "./IDrawCalculatorTimelock.sol"; | ||
|
||
/** | ||
* @title PoolTogether V4 IBeaconTimelockAndPushRouter | ||
* @author PoolTogether Inc Team | ||
* @notice The IBeaconTimelockAndPushRouter smart contract interface... | ||
*/ | ||
interface IBeaconTimelockAndPushRouter { | ||
/// @notice Emitted when the contract is deployed. | ||
event Deployed( | ||
IPrizeDistributionFactory indexed prizeDistributionFactory, | ||
IDrawCalculatorTimelock indexed timelock | ||
); | ||
|
||
/** | ||
* @notice Emitted when Draw is locked and totalNetworkTicketSupply is pushed to PrizeDistributionFactory | ||
* @param drawId Draw ID | ||
* @param draw Draw | ||
* @param totalNetworkTicketSupply totalNetworkTicketSupply | ||
*/ | ||
event DrawLockedAndTotalNetworkTicketSupplyPushed( | ||
uint32 indexed drawId, | ||
IDrawBeacon.Draw draw, | ||
uint256 totalNetworkTicketSupply | ||
); | ||
|
||
/** | ||
* @notice Locks next Draw and pushes totalNetworkTicketSupply to PrizeDistributionFactory | ||
* @dev Restricts new draws for N seconds by forcing timelock on the next target draw id. | ||
* @param draw Draw | ||
* @param totalNetworkTicketSupply totalNetworkTicketSupply | ||
*/ | ||
function push(IDrawBeacon.Draw memory draw, uint256 totalNetworkTicketSupply) external; | ||
} |
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,6 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.6; | ||
|
||
interface IPrizeDistributionFactory { | ||
function pushPrizeDistribution(uint32 _drawId, uint256 _totalNetworkTicketSupply) external; | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.6; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBeacon.sol"; | ||
import "@pooltogether/v4-core/contracts/interfaces/IDrawBuffer.sol"; | ||
import "./IPrizeDistributionFactory.sol"; | ||
import "./IDrawCalculatorTimelock.sol"; | ||
|
||
/** | ||
* @title PoolTogether V4 IReceiverTimelockAndPushRouter | ||
* @author PoolTogether Inc Team | ||
* @notice The IReceiverTimelockAndPushRouter smart contract interface... | ||
*/ | ||
interface IReceiverTimelockAndPushRouter { | ||
/// @notice Emitted when the contract is deployed. | ||
event Deployed( | ||
IDrawBuffer indexed drawBuffer, | ||
IPrizeDistributionFactory indexed prizeDistributionFactory, | ||
IDrawCalculatorTimelock indexed timelock | ||
); | ||
|
||
/** | ||
* @notice Emitted when Draw is locked, pushed to Draw DrawBuffer and totalNetworkTicketSupply is pushed to PrizeDistributionFactory | ||
* @param drawId Draw ID | ||
* @param draw Draw | ||
* @param totalNetworkTicketSupply totalNetworkTicketSupply | ||
*/ | ||
event DrawLockedPushedAndTotalNetworkTicketSupplyPushed( | ||
uint32 indexed drawId, | ||
IDrawBeacon.Draw draw, | ||
uint256 totalNetworkTicketSupply | ||
); | ||
|
||
/** | ||
* @notice Locks next Draw, pushes Draw to DraWBuffer and pushes totalNetworkTicketSupply to PrizeDistributionFactory. | ||
* @dev Restricts new draws for N seconds by forcing timelock on the next target draw id. | ||
* @param draw Draw | ||
* @param totalNetworkTicketSupply totalNetworkTicketSupply | ||
*/ | ||
function push(IDrawBeacon.Draw memory draw, uint256 totalNetworkTicketSupply) external; | ||
} |
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
Oops, something went wrong.