Skip to content

Commit

Permalink
Merge 5128297 into 42cc633
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg committed Sep 30, 2021
2 parents 42cc633 + 5128297 commit deb8c8e
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 222 deletions.
45 changes: 29 additions & 16 deletions contracts/interfaces/IPrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ interface IPrizePool {
function depositTo(
address to,
uint256 amount
)
external;
) external;

/// @notice Withdraw assets from the Prize Pool instantly. A fairness fee may be charged for an early exit.
/// @param from The address to redeem tokens from.
Expand All @@ -100,6 +99,12 @@ interface IPrizePool {
uint256 amount
) external returns (uint256);

/// @notice Called by the prize strategy to award prizes.
/// @dev The amount awarded must be less than the awardBalance()
/// @param to The address of the winner that receives the award
/// @param amount The amount of assets to be awarded
function award( address to, uint256 amount) external;

/// @notice Returns the balance that is available to award.
/// @dev captureAwardBalance() should be called first
/// @return The total amount of assets to be awarded for the current prize
Expand All @@ -119,17 +124,33 @@ interface IPrizePool {
/// @return The underlying balance of assets
function balance() external returns (uint256);

/**
* @notice Read internal Ticket accounted balance.
* @return uint256 accountBalance
*/
function getAccountedBalance() external view returns (uint256);
/**
* @notice Read internal balanceCap variable
*/
function getBalanceCap() external view returns (uint256);
/**
* @notice Read internal liquidityCap variable
*/
function getLiquidityCap() external view returns (uint256);
/**
* @notice Read ticket variable
*/
function getTicket() external view returns (IControlledToken);
/**
* @notice Read prizeStrategy variable
*/
function getPrizeStrategy() external view returns (address);

/// @dev Checks if a specific token is controlled by the Prize Pool
/// @param _controlledToken The address of the token to check
/// @return True if the token is a controlled token, false otherwise
function isControlled(IControlledToken _controlledToken) external view returns (bool);

/// @notice Called by the prize strategy to award prizes.
/// @dev The amount awarded must be less than the awardBalance()
/// @param to The address of the winner that receives the award
/// @param amount The amount of assets to be awarded
function award( address to, uint256 amount) external;

/// @notice Called by the Prize-Strategy to transfer out external ERC20 tokens
/// @dev Used to transfer out tokens held by the Prize Pool. Could be liquidated, or anything.
/// @param to The address of the winner that receives the award
Expand Down Expand Up @@ -175,19 +196,11 @@ interface IPrizePool {
/// @dev Returns the address of the prize pool ticket.
/// @return The address of the prize pool ticket.
function ticket() external view returns (IControlledToken);

/// @dev Returns the address of the prize pool ticket.
/// @return The address of the prize pool ticket.
function getTicket() external view returns (IControlledToken);

/// @dev Returns the address of the underlying ERC20 asset
/// @return The address of the asset
function token() external view returns (address);

/// @notice The total of all controlled tokens
/// @return The current total of all tokens
function accountedBalance() external view returns (uint256);

/// @notice Delegate the votes for a Compound COMP-like token held by the prize pool
/// @param _compLike The COMP-like token held by the prize pool that should be delegated
/// @param _to The address to delegate to
Expand Down
38 changes: 26 additions & 12 deletions contracts/prize-pool/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ abstract contract PrizePool is IPrizePool, Ownable, ReentrancyGuard, IERC721Rece

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

/// @inheritdoc IPrizePool
function token() external override view returns (address) {
return address(_token());
}

/// @inheritdoc IPrizePool
function balance() external override returns (uint256) {
return _balance();
Expand All @@ -83,7 +78,10 @@ abstract contract PrizePool is IPrizePool, Ownable, ReentrancyGuard, IERC721Rece
function awardBalance() external override view returns (uint256) {
return _currentAwardBalance;
}

// /// @inheritdoc IPrizePool
// function accountedBalance() external override view returns (uint256) {
// return _ticketTotalSupply();
// }
/// @inheritdoc IPrizePool
function canAwardExternal(address _externalToken) external override view returns (bool) {
return _canAwardExternal(_externalToken);
Expand All @@ -93,12 +91,33 @@ abstract contract PrizePool is IPrizePool, Ownable, ReentrancyGuard, IERC721Rece
function isControlled(IControlledToken _controlledToken) external override view returns (bool) {
return _isControlled(_controlledToken);
}

/// @inheritdoc IPrizePool
function getAccountedBalance() external override view returns (uint256) {
return _ticketTotalSupply();
}
/// @inheritdoc IPrizePool
function getBalanceCap() external override view returns (uint256) {
return balanceCap;
}
/// @inheritdoc IPrizePool
function getLiquidityCap() external override view returns (uint256) {
return liquidityCap;
}
/// @inheritdoc IPrizePool
function getTicket() external override view returns (IControlledToken) {
return ticket;
}

/// @inheritdoc IPrizePool
function getPrizeStrategy() external override view returns (address) {
return prizeStrategy;
}

/// @inheritdoc IPrizePool
function token() external override view returns (address) {
return address(_token());
}

/// @inheritdoc IPrizePool
function captureAwardBalance() external override nonReentrant returns (uint256) {

Expand Down Expand Up @@ -256,11 +275,6 @@ abstract contract PrizePool is IPrizePool, Ownable, ReentrancyGuard, IERC721Rece
_setPrizeStrategy(_prizeStrategy);
}

/// @inheritdoc IPrizePool
function accountedBalance() external override view returns (uint256) {
return _ticketTotalSupply();
}

/// @inheritdoc IPrizePool
function compLikeDelegate(ICompLike _compLike, address _to) external override onlyOwner {
if (_compLike.balanceOf(address(this)) > 0) {
Expand Down
14 changes: 13 additions & 1 deletion contracts/test/PrizePoolHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ contract PrizePoolHarness is PrizePool {
function _currentTime() internal override view returns (uint256) {
return currentTime;
}

function internalCurrentTime() external view returns (uint256) {
return super._currentTime();
}

function _canAwardExternal(address _externalToken) internal override view returns (bool) {
return stubYieldSource.canAwardExternal(_externalToken);
Expand All @@ -55,4 +59,12 @@ contract PrizePoolHarness is PrizePool {
function _redeem(uint256 redeemAmount) internal override returns (uint256) {
return stubYieldSource.redeemToken(redeemAmount);
}
}

// function mockOnERC721Received(bytes calldata sig) external pure returns (bytes4) {
// return super.onERC721Received(address(0), address(0), 0, sig);
// }

function setCurrentAwardBalance(uint256 amount) external {
_currentAwardBalance = amount;
}
}
Loading

0 comments on commit deb8c8e

Please sign in to comment.