Skip to content

Commit

Permalink
Renamed DrawPrize to PrizeDistributor (#200)
Browse files Browse the repository at this point in the history
* Renamed DrawPrize to PrizeDistributor

* Renamed drawPrize instances to prizeDistributor
  • Loading branch information
asselstine committed Oct 6, 2021
1 parent dbb4c61 commit 30bdf22
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ https://docs.pooltogether.com
- [DrawBeacon](/contracts/DrawBeacon.sol)
- [DrawCalculator](/contracts/DrawCalculator.sol)
- [DrawHistory](/contracts/DrawHistory.sol)
- [DrawPrize](/contracts/DrawPrize.sol)
- [PrizeDistributor](/contracts/PrizeDistributor.sol)
- [PrizeSplitStrategy](/contracts/PrizeSplitStrategy.sol)
- [Reserve](/contracts/Reserve.sol)

Expand Down
2 changes: 1 addition & 1 deletion contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.6;

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

import "./DrawPrize.sol";
import "./PrizeDistributor.sol";

import "./interfaces/IDrawCalculator.sol";
import "./interfaces/ITicket.sol";
Expand Down
36 changes: 18 additions & 18 deletions contracts/DrawPrize.sol → contracts/PrizeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@pooltogether/owner-manager-contracts/contracts/Ownable.sol";

import "./interfaces/IDrawPrize.sol";
import "./interfaces/IPrizeDistributor.sol";
import "./interfaces/IDrawCalculator.sol";
import "./interfaces/IDrawBeacon.sol";

/**
* @title PoolTogether V4 DrawPrize
* @title PoolTogether V4 PrizeDistributor
* @author PoolTogether Inc Team
* @notice The DrawPrize contract holds Tickets (captured interest) and distributes tickets to users with winning draw claims.
DrawPrize uses an external IDrawCalculator to validate a users draw claim, before awarding payouts. To prevent users
* @notice The PrizeDistributor contract holds Tickets (captured interest) and distributes tickets to users with winning draw claims.
PrizeDistributor uses an external IDrawCalculator to validate a users draw claim, before awarding payouts. To prevent users
from reclaiming prizes, a payout history for each draw claim is mapped to user accounts. Reclaiming a draw can occur
if an "optimal" prize was not included in previous claim pick indices and the new claims updated payout is greater then
the previous draw prize claim payout.
the previous prize distributor claim payout.
*/
contract DrawPrize is IDrawPrize, Ownable {
contract PrizeDistributor is IPrizeDistributor, Ownable {
using SafeERC20 for IERC20;

/* ============ Global Variables ============ */
Expand All @@ -36,7 +36,7 @@ contract DrawPrize is IDrawPrize, Ownable {
/* ============ Initialize ============ */

/**
* @notice Initialize DrawPrize smart contract.
* @notice Initialize PrizeDistributor smart contract.
* @param _owner Owner address
* @param _token Token address
* @param _drawCalculator DrawCalculator address
Expand All @@ -47,14 +47,14 @@ contract DrawPrize is IDrawPrize, Ownable {
IDrawCalculator _drawCalculator
) Ownable(_owner) {
_setDrawCalculator(_drawCalculator);
require(address(_token) != address(0), "DrawPrize/token-not-zero-address");
require(address(_token) != address(0), "PrizeDistributor/token-not-zero-address");
token = _token;
emit TokenSet(_token);
}

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

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function claim(
address _user,
uint32[] calldata _drawIds,
Expand All @@ -75,7 +75,7 @@ contract DrawPrize is IDrawPrize, Ownable {
}

// helpfully short-circuit, in case the user screwed something up.
require(payoutDiff > 0, "DrawPrize/zero-payout");
require(payoutDiff > 0, "PrizeDistributor/zero-payout");

totalPayout += payoutDiff;

Expand All @@ -87,14 +87,14 @@ contract DrawPrize is IDrawPrize, Ownable {
return totalPayout;
}

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function withdrawERC20(
IERC20 _erc20Token,
address _to,
uint256 _amount
) external override onlyOwner returns (bool) {
require(_to != address(0), "DrawPrize/recipient-not-zero-address");
require(address(_erc20Token) != address(0), "DrawPrize/ERC20-not-zero-address");
require(_to != address(0), "PrizeDistributor/recipient-not-zero-address");
require(address(_erc20Token) != address(0), "PrizeDistributor/ERC20-not-zero-address");

_erc20Token.safeTransfer(_to, _amount);

Expand All @@ -103,12 +103,12 @@ contract DrawPrize is IDrawPrize, Ownable {
return true;
}

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function getDrawCalculator() external view override returns (IDrawCalculator) {
return drawCalculator;
}

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function getDrawPayoutBalanceOf(address _user, uint32 _drawId)
external
view
Expand All @@ -118,12 +118,12 @@ contract DrawPrize is IDrawPrize, Ownable {
return _getDrawPayoutBalanceOf(_user, _drawId);
}

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function getToken() external view override returns (IERC20) {
return token;
}

/// @inheritdoc IDrawPrize
/// @inheritdoc IPrizeDistributor
function setDrawCalculator(IDrawCalculator _newCalculator)
external
override
Expand Down Expand Up @@ -157,7 +157,7 @@ contract DrawPrize is IDrawPrize, Ownable {
* @param _newCalculator DrawCalculator address
*/
function _setDrawCalculator(IDrawCalculator _newCalculator) internal {
require(address(_newCalculator) != address(0), "DrawPrize/calc-not-zero");
require(address(_newCalculator) != address(0), "PrizeDistributor/calc-not-zero");
drawCalculator = _newCalculator;

emit DrawCalculatorSet(_newCalculator);
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/IDrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity 0.8.6;
import "./ITicket.sol";
import "./IDrawHistory.sol";
import "../PrizeDistributionHistory.sol";
import "../DrawPrize.sol";
import "../PrizeDistributor.sol";

/**
* @title PoolTogether V4 IDrawCalculator
Expand All @@ -23,11 +23,11 @@ interface IDrawCalculator {
IDrawHistory indexed drawHistory,
IPrizeDistributionHistory indexed prizeDistributionHistory);

///@notice Emitted when the drawPrize is set/updated
event DrawPrizeSet(DrawPrize indexed drawPrize);
///@notice Emitted when the prizeDistributor is set/updated
event PrizeDistributorSet(PrizeDistributor indexed prizeDistributor);

/**
* @notice Calculates the prize amount for a user for Multiple Draws. Typically called by a DrawPrize.
* @notice Calculates the prize amount for a user for Multiple Draws. Typically called by a PrizeDistributor.
* @param user User for which to calculate prize amount.
* @param drawIds drawId array for which to calculate prize amounts for.
* @param data The ABI encoded pick indices for all Draws. Expected to be winning picks. Pick indices must be less than the totalUserPicks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./IDrawHistory.sol";
import "./IDrawCalculator.sol";

/** @title IDrawPrize
/** @title IPrizeDistributor
* @author PoolTogether Inc Team
* @notice The DrawPrize interface.
* @notice The PrizeDistributor interface.
*/
interface IDrawPrize {
interface IPrizeDistributor {

/**
* @notice Emit when user has claimed token from the PrizeDistributor.
* @param user User address receiving draw claim payouts
Expand Down Expand Up @@ -45,7 +47,7 @@ interface IDrawPrize {
Prizes are always paid out to the designated user account and not the caller (msg.sender).
Claiming prizes is not limited to a single transaction. Reclaiming can be executed
subsequentially if an "optimal" prize was not included in previous claim pick indices. The
payout difference for the new claim is calculated during the award process and transfered to user.
payout difference for the new claim is calculated during the award process and transfered to user.
* @param user Address of user to claim awards for. Does NOT need to be msg.sender
* @param drawIds Draw IDs from global DrawHistory reference
* @param data The data to pass to the draw calculator
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IPrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ interface IPrizePool {
function setLiquidityCap(uint256 liquidityCap) external;

/// @notice Sets the prize strategy of the prize pool. Only callable by the owner.
/// @param prizeStrategy The new prize strategy. Must implement DrawPrizePrizeStrategy
function setPrizeStrategy(address prizeStrategy) external;
/// @param _prizeStrategy The new prize strategy.
function setPrizeStrategy(address _prizeStrategy) external;

/// @notice Set prize pool ticket.
/// @param ticket Address of the ticket to set.
Expand Down
6 changes: 3 additions & 3 deletions deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ module.exports = async (hardhat) => {
});
displayResult('DrawCalculator', drawCalculatorResult);

cyan('\nDeploying DrawPrize...');
const drawPrizeResult = await deploy('DrawPrize', {
cyan('\nDeploying PrizeDistributor...');
const prizeDistributorResult = await deploy('PrizeDistributor', {
from: deployer,
args: [deployer, ticketResult.address, drawCalculatorResult.address],
});
displayResult('DrawPrize', drawPrizeResult);
displayResult('PrizeDistributor', prizeDistributorResult);

cyan('\nDeploying PrizeSplitStrategy...');
const prizeSplitStrategyResult = await deploy('PrizeSplitStrategy', {
Expand Down
4 changes: 2 additions & 2 deletions test/DrawHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ describe('DrawHistory', () => {

describe('pushDraw()', () => {
it('should fail to create a new draw when called from non-draw-manager', async () => {
const drawPrizeWallet2 = drawHistory.connect(wallet2);
const prizeDistributorWallet2 = drawHistory.connect(wallet2);

await expect(drawPrizeWallet2.pushDraw(newDraw({ drawId: 1 }))).to.be.revertedWith(
await expect(prizeDistributorWallet2.pushDraw(newDraw({ drawId: 1 }))).to.be.revertedWith(
'Manageable/caller-not-manager',
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/PrizeDistributionHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ describe('PrizeDistributionHistory', () => {
});

it('should fail to create a new draw when called from non-draw-manager', async () => {
const drawPrizeWallet2 = prizeDistributionHistory.connect(wallet2);
const prizeDistributorWallet2 = prizeDistributionHistory.connect(wallet2);

await expect(
drawPrizeWallet2.pushPrizeDistribution(1, newPrizeDistribution()),
prizeDistributorWallet2.pushPrizeDistribution(1, newPrizeDistribution()),
).to.be.revertedWith('Manageable/caller-not-manager-or-owner');
});

Expand Down
Loading

0 comments on commit 30bdf22

Please sign in to comment.