Skip to content

Commit

Permalink
fix(IPrizeDistributionSource): rename interface
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Mar 8, 2022
1 parent cf258cd commit 676d273
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 67 deletions.
24 changes: 12 additions & 12 deletions contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./interfaces/IDrawCalculator.sol";
import "./interfaces/ITicket.sol";
import "./interfaces/IDrawBuffer.sol";
import "./interfaces/IPrizeDistributionBuffer.sol";
import "./interfaces/IPrizeDistributionSplitter.sol";
import "./interfaces/IPrizeDistributionSource.sol";
import "./interfaces/IDrawBeacon.sol";

/**
Expand All @@ -27,7 +27,7 @@ contract DrawCalculator is IDrawCalculator {
ITicket public immutable ticket;

/// @notice The stored history of draw settings. Stored as ring buffer.
IPrizeDistributionSplitter public immutable prizeDistributionSplitter;
IPrizeDistributionSource public immutable prizeDistributionSource;

/// @notice The tiers array length
uint8 public constant TIERS_LENGTH = 16;
Expand All @@ -37,21 +37,21 @@ contract DrawCalculator is IDrawCalculator {
/// @notice Constructor for DrawCalculator
/// @param _ticket Ticket associated with this DrawCalculator
/// @param _drawBuffer The address of the draw buffer to push draws to
/// @param _prizeDistributionSplitter PrizeDistributionSplitter address
/// @param _prizeDistributionSource PrizeDistributionSource address
constructor(
ITicket _ticket,
IDrawBuffer _drawBuffer,
IPrizeDistributionSplitter _prizeDistributionSplitter
IPrizeDistributionSource _prizeDistributionSource
) {
require(address(_ticket) != address(0), "DrawCalc/ticket-not-zero");
require(address(_prizeDistributionSplitter) != address(0), "DrawCalc/pdb-not-zero");
require(address(_prizeDistributionSource) != address(0), "DrawCalc/pdb-not-zero");
require(address(_drawBuffer) != address(0), "DrawCalc/dh-not-zero");

ticket = _ticket;
drawBuffer = _drawBuffer;
prizeDistributionSplitter = _prizeDistributionSplitter;
prizeDistributionSource = _prizeDistributionSource;

emit Deployed(_ticket, _drawBuffer, _prizeDistributionSplitter);
emit Deployed(_ticket, _drawBuffer, _prizeDistributionSource);
}

/* ============ External Functions ============ */
Expand All @@ -69,7 +69,7 @@ contract DrawCalculator is IDrawCalculator {
IDrawBeacon.Draw[] memory draws = drawBuffer.getDraws(_drawIds);

// READ list of IPrizeDistributionBuffer.PrizeDistribution using the drawIds
IPrizeDistributionBuffer.PrizeDistribution[] memory _prizeDistributions = prizeDistributionSplitter
IPrizeDistributionBuffer.PrizeDistribution[] memory _prizeDistributions = prizeDistributionSource
.getPrizeDistributions(_drawIds);

// The userBalances are fractions representing their portion of the liquidity for a draw.
Expand All @@ -93,13 +93,13 @@ contract DrawCalculator is IDrawCalculator {
}

/// @inheritdoc IDrawCalculator
function getPrizeDistributionSource()
function getPrizeDistributionBuffer()
external
view
override
returns (IPrizeDistributionSplitter)
returns (IPrizeDistributionSource)
{
return prizeDistributionSplitter;
return prizeDistributionSource;
}

/// @inheritdoc IDrawCalculator
Expand All @@ -110,7 +110,7 @@ contract DrawCalculator is IDrawCalculator {
returns (uint256[] memory)
{
IDrawBeacon.Draw[] memory _draws = drawBuffer.getDraws(_drawIds);
IPrizeDistributionBuffer.PrizeDistribution[] memory _prizeDistributions = prizeDistributionSplitter
IPrizeDistributionBuffer.PrizeDistribution[] memory _prizeDistributions = prizeDistributionSource
.getPrizeDistributions(_drawIds);

return _getNormalizedBalancesAt(_user, _draws, _prizeDistributions);
Expand Down
6 changes: 3 additions & 3 deletions contracts/PrizeDistributionBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@pooltogether/owner-manager-contracts/contracts/Manageable.sol";

import "./libraries/DrawRingBufferLib.sol";
import "./interfaces/IPrizeDistributionBuffer.sol";
import "./interfaces/IPrizeDistributionSplitter.sol";
import "./interfaces/IPrizeDistributionSource.sol";

/**
* @title PoolTogether V4 PrizeDistributionBuffer
Expand All @@ -17,7 +17,7 @@ import "./interfaces/IPrizeDistributionSplitter.sol";
parameters can only be updated the owner. When adding a new PrizeDistribution basic sanity checks will be used to
validate the incoming parameters.
*/
contract PrizeDistributionBuffer is IPrizeDistributionBuffer, IPrizeDistributionSplitter, Manageable {
contract PrizeDistributionBuffer is IPrizeDistributionBuffer, IPrizeDistributionSource, Manageable {
using DrawRingBufferLib for DrawRingBufferLib.Buffer;

/// @notice The maximum cardinality of the prize distribution ring buffer.
Expand Down Expand Up @@ -68,7 +68,7 @@ contract PrizeDistributionBuffer is IPrizeDistributionBuffer, IPrizeDistribution
return _getPrizeDistribution(bufferMetadata, _drawId);
}

/// @inheritdoc IPrizeDistributionSplitter
/// @inheritdoc IPrizeDistributionSource
function getPrizeDistributions(uint32[] calldata _drawIds)
external
view
Expand Down
18 changes: 9 additions & 9 deletions contracts/PrizeDistributionSplitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.6;

import "./interfaces/IPrizeDistributionSplitter.sol";
import "./interfaces/IPrizeDistributionSource.sol";

/**
* @title PoolTogether V4 PrizeDistributionSplitter
Expand All @@ -14,15 +14,15 @@ import "./interfaces/IPrizeDistributionSplitter.sol";
when calling the `getPrizeDistributions` function with a `drawId` greater than or equal to the one set,
we query the second PrizeDistributionBuffer contract, otherwise we query the first.
*/
contract PrizeDistributionSplitter is IPrizeDistributionSplitter {
contract PrizeDistributionSplitter is IPrizeDistributionSource {
/// @notice DrawId at which the split occured
uint32 public immutable drawId;

/// @notice First PrizeDistributionBuffer source address
IPrizeDistributionSplitter public immutable prizeDistributionSourceBefore;
IPrizeDistributionSource public immutable prizeDistributionSourceBefore;

/// @notice Second PrizeDistributionBuffer source address
IPrizeDistributionSplitter public immutable prizeDistributionSourceAtOrAfter;
IPrizeDistributionSource public immutable prizeDistributionSourceAtOrAfter;

/* ============ Events ============ */

Expand All @@ -38,8 +38,8 @@ contract PrizeDistributionSplitter is IPrizeDistributionSplitter {
* @param prizeDistributionSourceAtOrAfter Second PrizeDistributionBuffer contract address
*/
event PrizeDistributionSourcesSet(
IPrizeDistributionSplitter prizeDistributionSourceBefore,
IPrizeDistributionSplitter prizeDistributionSourceAtOrAfter
IPrizeDistributionSource prizeDistributionSourceBefore,
IPrizeDistributionSource prizeDistributionSourceAtOrAfter
);

/* ============ Constructor ============ */
Expand All @@ -52,8 +52,8 @@ contract PrizeDistributionSplitter is IPrizeDistributionSplitter {
*/
constructor(
uint32 _drawId,
IPrizeDistributionSplitter _prizeDistributionSourceBefore,
IPrizeDistributionSplitter _prizeDistributionSourceAtOrAfter
IPrizeDistributionSource _prizeDistributionSourceBefore,
IPrizeDistributionSource _prizeDistributionSourceAtOrAfter
) {
require(_drawId > 0, "PrizeDistSplitter/drawId-gt-zero");
_requirePrizeDistNotZeroAddress(address(_prizeDistributionSourceBefore));
Expand All @@ -72,7 +72,7 @@ contract PrizeDistributionSplitter is IPrizeDistributionSplitter {

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

/// @inheritdoc IPrizeDistributionSplitter
/// @inheritdoc IPrizeDistributionSource
function getPrizeDistributions(uint32[] calldata _drawIds)
external
view
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IDrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.6;

import "./ITicket.sol";
import "./IDrawBuffer.sol";
import "./IPrizeDistributionSplitter.sol";
import "./IPrizeDistributionSource.sol";
import "../PrizeDistributionBuffer.sol";
import "../PrizeDistributor.sol";

Expand All @@ -23,7 +23,7 @@ interface IDrawCalculator {
event Deployed(
ITicket indexed ticket,
IDrawBuffer indexed drawBuffer,
IPrizeDistributionSplitter indexed prizeDistributionSource
IPrizeDistributionSource indexed prizeDistributionSource
);

///@notice Emitted when the prizeDistributor is set/updated
Expand Down Expand Up @@ -52,7 +52,7 @@ interface IDrawCalculator {
* @notice Read global DrawBuffer variable.
* @return IDrawBuffer
*/
function getPrizeDistributionSource() external view returns (IPrizeDistributionSplitter);
function getPrizeDistributionBuffer() external view returns (IPrizeDistributionSource);

/**
* @notice Returns a users balances expressed as a fraction of the total supply over time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pragma solidity 0.8.6;

import "./IPrizeDistributionBuffer.sol";

/** @title IPrizeDistributionSplitter
/** @title IPrizeDistributionSource
* @author PoolTogether Inc Team
* @notice The PrizeDistributionSplitter interface.
* @notice The PrizeDistributionSource interface.
*/
interface IPrizeDistributionSplitter {
interface IPrizeDistributionSource {
/**
* @notice Gets PrizeDistribution list from array of drawIds
* @param drawIds drawIds to get PrizeDistribution for
Expand Down
60 changes: 23 additions & 37 deletions test/DrawCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ describe('DrawCalculator', () => {
let drawBufferArtifact = await artifacts.readArtifact('DrawBuffer');
drawBuffer = await deployMockContract(wallet1, drawBufferArtifact.abi);

let prizeDistributionSourceArtifact = await artifacts.readArtifact(
let prizeDistributionSplitterArtifact = await artifacts.readArtifact(
'PrizeDistributionSplitter',
);

prizeDistributionSplitter = await deployMockContract(
wallet1,
prizeDistributionSourceArtifact.abi,
prizeDistributionSplitterArtifact.abi,
);

drawCalculator = await deployDrawCalculator(
Expand Down Expand Up @@ -136,9 +136,9 @@ describe('DrawCalculator', () => {
});
});

describe('getPrizeDistributionSource()', () => {
it('should successfully return the PrizeDistributionSplitter contract', async () => {
expect(await drawCalculator.getPrizeDistributionSource()).to.equal(
describe('getPrizeDistributionBuffer()', () => {
it('should succesfully read draw buffer', async () => {
expect(await drawCalculator.getPrizeDistributionBuffer()).to.equal(
prizeDistributionSplitter.address,
);
});
Expand Down Expand Up @@ -583,11 +583,10 @@ describe('DrawCalculator', () => {
.withArgs(offsetStartTimestamps, offsetEndTimestamps)
.returns([utils.parseEther('100'), utils.parseEther('600')]);

const userNormalizedBalances =
await drawCalculator.callStatic.getNormalizedBalancesForDrawIds(
wallet1.address,
[1, 2],
);
const userNormalizedBalances = await drawCalculator.getNormalizedBalancesForDrawIds(
wallet1.address,
[1, 2],
);

expect(userNormalizedBalances[0]).to.eq(utils.parseEther('0.2'));
expect(userNormalizedBalances[1]).to.eq(utils.parseEther('0.05'));
Expand Down Expand Up @@ -651,7 +650,7 @@ describe('DrawCalculator', () => {
.withArgs(offsetStartTimestamps, offsetEndTimestamps)
.returns([utils.parseEther('0'), utils.parseEther('600')]);

const balancesResult = await drawCalculator.callStatic.getNormalizedBalancesForDrawIds(
const balancesResult = await drawCalculator.getNormalizedBalancesForDrawIds(
wallet1.address,
[1, 2],
);
Expand Down Expand Up @@ -702,10 +701,9 @@ describe('DrawCalculator', () => {
.withArgs(offsetStartTimestamps, offsetEndTimestamps)
.returns([utils.parseEther('1000')]);

const result = await drawCalculator.callStatic.getNormalizedBalancesForDrawIds(
wallet1.address,
[1],
);
const result = await drawCalculator.getNormalizedBalancesForDrawIds(wallet1.address, [
1,
]);

expect(result[0]).to.eq(BigNumber.from(0));
});
Expand Down Expand Up @@ -783,7 +781,7 @@ describe('DrawCalculator', () => {

await drawBuffer.mock.getDraws.returns([draw]);

const result = await drawCalculator.callStatic.calculate(
const result = await drawCalculator.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
Expand Down Expand Up @@ -874,11 +872,7 @@ describe('DrawCalculator', () => {
await drawBuffer.mock.getDraws.returns([draw]);

await expect(
drawCalculator.callStatic.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
),
drawCalculator.calculate(wallet1.address, [draw.drawId], pickIndices),
).to.revertedWith('DrawCalc/draw-expired');
});

Expand Down Expand Up @@ -921,11 +915,7 @@ describe('DrawCalculator', () => {
await drawBuffer.mock.getDraws.returns([draw]);

await expect(
drawCalculator.callStatic.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
),
drawCalculator.calculate(wallet1.address, [draw.drawId], pickIndices),
).to.revertedWith('DrawCalc/picks-ascending');
});

Expand Down Expand Up @@ -1037,7 +1027,7 @@ describe('DrawCalculator', () => {

await drawBuffer.mock.getDraws.returns([draw]);

const prizesAwardable = await drawCalculator.callStatic.calculate(
const prizesAwardable = await drawCalculator.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
Expand Down Expand Up @@ -1097,7 +1087,7 @@ describe('DrawCalculator', () => {

await drawBuffer.mock.getDraws.returns([draw]);

const prizesAwardable = await drawCalculator.callStatic.calculate(
const prizesAwardable = await drawCalculator.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
Expand Down Expand Up @@ -1164,7 +1154,7 @@ describe('DrawCalculator', () => {

await drawBuffer.mock.getDraws.returns([draw]);

const prizesAwardable = await drawCalculator.callStatic.calculate(
const prizesAwardable = await drawCalculator.calculate(
wallet1.address,
[draw.drawId],
pickIndices,
Expand Down Expand Up @@ -1248,7 +1238,7 @@ describe('DrawCalculator', () => {
.withArgs([1, 2])
.returns([prizeDistribution, prizeDistribution2]);

const result = await drawCalculator.callStatic.calculate(
const result = await drawCalculator.calculate(
wallet1.address,
[draw1.drawId, draw2.drawId],
pickIndices,
Expand Down Expand Up @@ -1343,7 +1333,7 @@ describe('DrawCalculator', () => {
.returns([prizeDistribution, prizeDistribution]);

await expect(
drawCalculator.callStatic.calculate(
drawCalculator.calculate(
wallet1.address,
[draw1.drawId, draw2.drawId],
pickIndices,
Expand Down Expand Up @@ -1409,11 +1399,7 @@ describe('DrawCalculator', () => {
.returns([prizeDistribution]);

await expect(
drawCalculator.callStatic.calculate(
wallet1.address,
[draw1.drawId],
pickIndices,
),
drawCalculator.calculate(wallet1.address, [draw1.drawId], pickIndices),
).to.revertedWith('DrawCalc/exceeds-max-user-picks');
});

Expand Down Expand Up @@ -1456,7 +1442,7 @@ describe('DrawCalculator', () => {

await drawBuffer.mock.getDraws.returns([draw1]);

const prizesAwardable = await drawCalculator.callStatic.calculate(
const prizesAwardable = await drawCalculator.calculate(
wallet1.address,
[draw1.drawId],
pickIndices,
Expand Down

0 comments on commit 676d273

Please sign in to comment.