Skip to content

Commit

Permalink
Renamed DrawPrize to PrizeDistributor
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Oct 6, 2021
1 parent 5967c1a commit 9551abe
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 43 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)
- [PrizeFlush](/contracts/PrizeFlush.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
2 changes: 1 addition & 1 deletion contracts/PrizeFlush.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./interfaces/IPrizeFlush.sol";
contract PrizeFlush is IPrizeFlush, Manageable {
/**
* @notice Destination address for captured interest.
* @dev Should be set to the DrawPrize address.
* @dev Should be set to the PrizeDistributor address.
*/
address internal destination;

Expand Down
6 changes: 3 additions & 3 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 @@ -24,10 +24,10 @@ interface IDrawCalculator {
IPrizeDistributionHistory indexed prizeDistributionHistory);

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

/**
* @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
2 changes: 1 addition & 1 deletion contracts/interfaces/IPrizeFlush.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ interface IPrizeFlush {
function setStrategy(IStrategy _strategy) external returns (IStrategy);

/**
* @notice Migrate interest from PrizePool to DrawPrize in a single transaction.
* @notice Migrate interest from PrizePool to PrizeDistributor in a single transaction.
* @dev Captures interest, checkpoint data and transfers tokens to final destination.
* @dev Only callable by the owner or manager.
* @return True when operation is successful.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ 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
/// @param _prizeStrategy The new prize strategy. Must implement PrizeDistributorPrizeStrategy
function setPrizeStrategy(address _prizeStrategy) external;

/// @notice Set prize pool ticket.
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 drawPrizeResult = await deploy('PrizeDistributor', {
from: deployer,
args: [deployer, ticketResult.address, drawCalculatorResult.address],
});
displayResult('DrawPrize', drawPrizeResult);
displayResult('PrizeDistributor', drawPrizeResult);

cyan('\nDeploying PrizeSplitStrategy...');
const prizeSplitStrategyResult = await deploy('PrizeSplitStrategy', {
Expand Down
12 changes: 6 additions & 6 deletions test/DrawPrizes.test.ts → test/PrizeDistributor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { getSigners } = ethers;
const { parseEther: toWei } = utils;
const { AddressZero } = constants;

describe('DrawPrize', () => {
describe('PrizeDistributor', () => {
let wallet1: any;
let wallet2: any;
let wallet3: any;
Expand All @@ -31,7 +31,7 @@ describe('DrawPrize', () => {
let IDrawCalculator = await artifacts.readArtifact('IDrawCalculator');
drawCalculator = await deployMockContract(wallet1, IDrawCalculator.abi);

const drawPrizeFactory: ContractFactory = await ethers.getContractFactory('DrawPrize');
const drawPrizeFactory: ContractFactory = await ethers.getContractFactory('PrizeDistributor');

drawPrize = await drawPrizeFactory.deploy(
wallet1.address,
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('DrawPrize', () => {

it('should not allow a zero calculator', async () => {
await expect(drawPrize.setDrawCalculator(AddressZero)).to.be.revertedWith(
'DrawPrize/calc-not-zero',
'PrizeDistributor/calc-not-zero',
);
});

Expand Down Expand Up @@ -124,7 +124,7 @@ describe('DrawPrize', () => {

// try again: should fail!
await expect(drawPrize.claim(wallet1.address, [0], '0x')).to.be.revertedWith(
'DrawPrize/zero-payout',
'PrizeDistributor/zero-payout',
);
});

Expand Down Expand Up @@ -174,13 +174,13 @@ describe('DrawPrize', () => {
it('should fail to withdraw ERC20 tokens if recipient address is address zero', async () => {
await expect(
drawPrize.withdrawERC20(dai.address, AddressZero, withdrawAmount),
).to.be.revertedWith('DrawPrize/recipient-not-zero-address');
).to.be.revertedWith('PrizeDistributor/recipient-not-zero-address');
});

it('should fail to withdraw ERC20 tokens if token address is address zero', async () => {
await expect(
drawPrize.withdrawERC20(AddressZero, wallet1.address, withdrawAmount),
).to.be.revertedWith('DrawPrize/ERC20-not-zero-address');
).to.be.revertedWith('PrizeDistributor/ERC20-not-zero-address');
});

it('should succeed to withdraw ERC20 tokens as owner', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/features/support/PoolEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function PoolEnv() {

this.drawCalculator = async () => await ethers.getContract('DrawCalculator');

this.drawPrize = async (wallet) => (await ethers.getContract('DrawPrize')).connect(wallet);
this.drawPrize = async (wallet) => (await ethers.getContract('PrizeDistributor')).connect(wallet);

this.rng = async () => await ethers.getContract('RNGServiceStub');

Expand Down Expand Up @@ -76,7 +76,7 @@ function PoolEnv() {
debug(`Bought tickets`);
};

this.buyTicketsForDrawPrize = async function ({ user, tickets, drawPrize }) {
this.buyTicketsForPrizeDistributor = async function ({ user, tickets, drawPrize }) {
debug(`Buying tickets...`);
const owner = await this.wallet(0);
let wallet = await this.wallet(user);
Expand Down
2 changes: 1 addition & 1 deletion test/features/ticket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Tickets', () => {
// NOT a COMPLETE test. Needs to be fixed - out of scope for this PR.
it.skip('should allow a user to pull their prizes', async () => {
await env.buyTickets({ user: 1, tickets: 100 });
await env.buyTicketsForDrawPrize({
await env.buyTicketsForPrizeDistributor({
user: 1,
tickets: 100,
drawPrize: (await env.drawPrize()).address,
Expand Down

0 comments on commit 9551abe

Please sign in to comment.