Skip to content

Commit

Permalink
remove timelock from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aodhgan committed Jul 5, 2021
1 parent 3d1ae51 commit 0b66e0a
Show file tree
Hide file tree
Showing 24 changed files with 30 additions and 812 deletions.
6 changes: 0 additions & 6 deletions contracts/builders/PoolWithMultipleWinnersBuilder.sol
Expand Up @@ -34,20 +34,17 @@ contract PoolWithMultipleWinnersBuilder {
struct CompoundPrizePoolConfig {
CTokenInterface cToken;
uint256 maxExitFeeMantissa;
uint256 maxTimelockDuration;
}

/// @notice The configuration used to initialize the Compound Prize Pool
struct YieldSourcePrizePoolConfig {
IYieldSource yieldSource;
uint256 maxExitFeeMantissa;
uint256 maxTimelockDuration;
}

struct StakePrizePoolConfig {
IERC20Upgradeable token;
uint256 maxExitFeeMantissa;
uint256 maxTimelockDuration;
}

RegistryInterface public reserveRegistry;
Expand Down Expand Up @@ -91,7 +88,6 @@ contract PoolWithMultipleWinnersBuilder {
reserveRegistry,
_tokens(prizeStrategy),
prizePoolConfig.maxExitFeeMantissa,
prizePoolConfig.maxTimelockDuration,
CTokenInterface(prizePoolConfig.cToken)
);
prizePool.setPrizeStrategy(prizeStrategy);
Expand Down Expand Up @@ -121,7 +117,6 @@ contract PoolWithMultipleWinnersBuilder {
reserveRegistry,
_tokens(prizeStrategy),
prizePoolConfig.maxExitFeeMantissa,
prizePoolConfig.maxTimelockDuration,
prizePoolConfig.yieldSource
);
prizePool.setPrizeStrategy(prizeStrategy);
Expand Down Expand Up @@ -151,7 +146,6 @@ contract PoolWithMultipleWinnersBuilder {
reserveRegistry,
_tokens(prizeStrategy),
prizePoolConfig.maxExitFeeMantissa,
prizePoolConfig.maxTimelockDuration,
prizePoolConfig.token
);
prizePool.setPrizeStrategy(prizeStrategy);
Expand Down
170 changes: 8 additions & 162 deletions contracts/prize-pool/PrizePool.sol
Expand Up @@ -33,8 +33,7 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
/// @dev Emitted when an instance is initialized
event Initialized(
address reserveRegistry,
uint256 maxExitFeeMantissa,
uint256 maxTimelockDuration
uint256 maxExitFeeMantissa
);

/// @dev Event emitted when controlled token is added
Expand All @@ -60,14 +59,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
address referrer
);

/// @dev Event emitted when timelocked funds are re-deposited
event TimelockDeposited(
address indexed operator,
address indexed to,
address indexed token,
uint256 amount
);

/// @dev Event emitted when interest is awarded to a winner
event Awarded(
address indexed winner,
Expand Down Expand Up @@ -111,14 +102,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
uint256 amount
);

/// @dev Event emitted when timelocked funds are swept back to a user
event TimelockedWithdrawalSwept(
address indexed operator,
address indexed from,
uint256 amount,
uint256 redeemed
);

/// @dev Event emitted when the Liquidity Cap is set
event LiquidityCapSet(
uint256 liquidityCap
Expand Down Expand Up @@ -174,12 +157,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
/// For example, if the maxExitFeeMantissa is "0.1 ether", then the maximum exit fee for a withdrawal of 100 Dai will be 10 Dai
uint256 public maxExitFeeMantissa;

/// @dev The maximum possible timelock duration for a timelocked withdrawal (in seconds).
uint256 public maxTimelockDuration;

/// @dev The total funds that are timelocked.
uint256 public timelockTotalSupply;

/// @dev The total funds that have been allocated to the reserve
uint256 public reserveTotalSupply;

Expand All @@ -189,12 +166,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
/// @dev the The awardable balance
uint256 internal _currentAwardBalance;

/// @dev The timelocked balances for each user
mapping(address => uint256) internal _timelockBalances;

/// @dev The unlock timestamps for each user
mapping(address => uint256) internal _unlockTimestamps;

/// @dev Stores the credit plan for each token.
mapping(address => CreditPlan) internal _tokenCreditPlans;

Expand All @@ -204,12 +175,10 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
/// @notice Initializes the Prize Pool
/// @param _controlledTokens Array of ControlledTokens that are controlled by this Prize Pool.
/// @param _maxExitFeeMantissa The maximum exit fee size
/// @param _maxTimelockDuration The maximum length of time the withdraw timelock
function initialize (
RegistryInterface _reserveRegistry,
ControlledTokenInterface[] memory _controlledTokens,
uint256 _maxExitFeeMantissa,
uint256 _maxTimelockDuration
uint256 _maxExitFeeMantissa
)
public
initializer
Expand All @@ -225,12 +194,10 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc

reserveRegistry = _reserveRegistry;
maxExitFeeMantissa = _maxExitFeeMantissa;
maxTimelockDuration = _maxTimelockDuration;

emit Initialized(
address(_reserveRegistry),
maxExitFeeMantissa,
maxTimelockDuration
maxExitFeeMantissa
);
}

Expand All @@ -253,28 +220,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
return _canAwardExternal(_externalToken);
}

/// @notice Deposits timelocked tokens for a user back into the Prize Pool as another asset.
/// @param to The address receiving the tokens
/// @param amount The amount of timelocked assets to re-deposit
/// @param controlledToken The type of token to be minted in exchange (i.e. tickets or sponsorship)
function timelockDepositTo(
address to,
uint256 amount,
address controlledToken
)
external
onlyControlledToken(controlledToken)
canAddLiquidity(amount)
nonReentrant
{
address operator = _msgSender();
_mint(to, amount, controlledToken, address(0));
_timelockBalances[operator] = _timelockBalances[operator].sub(amount);
timelockTotalSupply = timelockTotalSupply.sub(amount);

emit TimelockDeposited(operator, to, controlledToken, amount);
}

/// @notice Deposit assets into the Prize Pool in exchange for tokens
/// @param to The address receiving the newly minted tokens
/// @param amount The amount of assets to deposit
Expand Down Expand Up @@ -350,28 +295,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
return exitFee;
}

/// @notice Adds to a user's timelock balance. It will attempt to sweep before updating the balance.
/// Note that this will overwrite the previous unlock timestamp.
/// @param user The user whose timelock balance should increase
/// @param amount The amount to increase by
/// @param timestamp The new unlock timestamp
function _mintTimelock(address user, uint256 amount, uint256 timestamp) internal {
// Sweep the old balance, if any
address[] memory users = new address[](1);
users[0] = user;
_sweepTimelockBalances(users);

timelockTotalSupply = timelockTotalSupply.add(amount);
_timelockBalances[user] = _timelockBalances[user].add(amount);

_unlockTimestamps[user] = timestamp;

// if the funds should already be unlocked
if (timestamp <= _currentTime()) {
_sweepTimelockBalances(users);
}
}

/// @notice Updates the Prize Strategy when tokens are transferred between holders.
/// @param from The address the tokens are being transferred from (0 if minting)
/// @param to The address the tokens are being transferred to (0 if burning)
Expand Down Expand Up @@ -581,69 +504,6 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
return FixedPoint.multiplyUintByMantissa(amount, reserveRateMantissa);
}

/// @notice Sweep all timelocked balances and transfer unlocked assets to owner accounts
/// @param users An array of account addresses to sweep balances for
/// @return The total amount of assets swept from the Prize Pool
function sweepTimelockBalances(
address[] calldata users
)
external override
nonReentrant
returns (uint256)
{
return _sweepTimelockBalances(users);
}

/// @notice Sweep available timelocked balances to their owners. The full balances will be swept to the owners.
/// @param users An array of owner addresses
/// @return The total amount of assets swept from the Prize Pool
function _sweepTimelockBalances(
address[] memory users
)
internal
returns (uint256)
{
address operator = _msgSender();

uint256[] memory balances = new uint256[](users.length);

uint256 totalWithdrawal;

uint256 i;
for (i = 0; i < users.length; i++) {
address user = users[i];
if (_unlockTimestamps[user] <= _currentTime()) { // move _currentTime() outside loop
totalWithdrawal = totalWithdrawal.add(_timelockBalances[user]);
balances[i] = _timelockBalances[user];
delete _timelockBalances[user];
}
}

// if there is nothing to do, just quit
if (totalWithdrawal == 0) {
return 0;
}

timelockTotalSupply = timelockTotalSupply.sub(totalWithdrawal);

uint256 redeemed = _redeem(totalWithdrawal);

IERC20Upgradeable underlyingToken = IERC20Upgradeable(_token());

for (i = 0; i < users.length; i++) {
if (balances[i] > 0) {
delete _unlockTimestamps[users[i]];
uint256 shareMantissa = FixedPoint.calculateMantissa(balances[i], totalWithdrawal);
uint256 transferAmount = FixedPoint.multiplyUintByMantissa(redeemed, shareMantissa);
underlyingToken.safeTransfer(users[i], transferAmount);
emit TimelockedWithdrawalSwept(operator, users[i], balances[i], transferAmount);
}
}

return totalWithdrawal;
}


/// @notice Calculates the early exit fee for the given amount
/// @param from The user who is withdrawing
/// @param controlledToken The type of collateral being withdrawn
Expand Down Expand Up @@ -940,22 +800,8 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
return block.timestamp;
}

/// @notice The timestamp at which an account's timelocked balance will be made available to sweep
/// @param user The address of an account with timelocked assets
/// @return The timestamp at which the locked assets will be made available
function timelockBalanceAvailableAt(address user) external override view returns (uint256) {
return _unlockTimestamps[user];
}

/// @notice The balance of timelocked assets for an account
/// @param user The address of an account with timelocked assets
/// @return The amount of assets that have been timelocked
function timelockBalanceOf(address user) external override view returns (uint256) {
return _timelockBalances[user];
}

/// @notice The total of all controlled tokens and timelock.
/// @return The current total of all tokens and timelock.
/// @notice The total of all controlled tokens
/// @return The current total of all tokens
function accountedBalance() external override view returns (uint256) {
return _tokenTotalSupply();
}
Expand All @@ -969,10 +815,10 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc
}
}

/// @notice The total of all controlled tokens and timelock.
/// @return The current total of all tokens and timelock.
/// @notice The total of all controlled tokens
/// @return The current total of all tokens
function _tokenTotalSupply() internal view returns (uint256) {
uint256 total = timelockTotalSupply.add(reserveTotalSupply);
uint256 total = reserveTotalSupply;
address currentToken = _tokens.start();
while (currentToken != address(0) && currentToken != _tokens.end()) {
total = total.add(IERC20Upgradeable(currentToken).totalSupply());
Expand Down
23 changes: 2 additions & 21 deletions contracts/prize-pool/PrizePoolInterface.sol
Expand Up @@ -97,15 +97,6 @@ interface PrizePoolInterface {
)
external;

/// @notice Sweep all timelocked balances and transfer unlocked assets to owner accounts
/// @param users An array of account addresses to sweep balances for
/// @return The total amount of assets swept from the Prize Pool
function sweepTimelockBalances(
address[] calldata users
)
external
returns (uint256);

/// @notice Calculates the early exit fee for the given amount
/// @param from The user who is withdrawing
/// @param controlledToken The type of collateral being withdrawn
Expand Down Expand Up @@ -182,17 +173,7 @@ interface PrizePoolInterface {
/// @return An array of controlled token addresses
function tokens() external view returns (address[] memory);

/// @notice The timestamp at which an account's timelocked balance will be made available to sweep
/// @param user The address of an account with timelocked assets
/// @return The timestamp at which the locked assets will be made available
function timelockBalanceAvailableAt(address user) external view returns (uint256);

/// @notice The balance of timelocked assets for an account
/// @param user The address of an account with timelocked assets
/// @return The amount of assets that have been timelocked
function timelockBalanceOf(address user) external view returns (uint256);

/// @notice The total of all controlled tokens and timelock.
/// @return The current total of all tokens and timelock.
/// @notice The total of all controlled tokens
/// @return The current total of all tokens
function accountedBalance() external view returns (uint256);
}
5 changes: 1 addition & 4 deletions contracts/prize-pool/compound/CompoundPrizePool.sol
Expand Up @@ -25,13 +25,11 @@ contract CompoundPrizePool is PrizePool {
/// @notice Initializes the Prize Pool and Yield Service with the required contract connections
/// @param _controlledTokens Array of addresses for the Ticket and Sponsorship Tokens controlled by the Prize Pool
/// @param _maxExitFeeMantissa The maximum exit fee size, relative to the withdrawal amount
/// @param _maxTimelockDuration The maximum length of time the withdraw timelock could be
/// @param _cToken Address of the Compound cToken interface
function initialize (
RegistryInterface _reserveRegistry,
ControlledTokenInterface[] memory _controlledTokens,
uint256 _maxExitFeeMantissa,
uint256 _maxTimelockDuration,
CTokenInterface _cToken
)
public
Expand All @@ -40,8 +38,7 @@ contract CompoundPrizePool is PrizePool {
PrizePool.initialize(
_reserveRegistry,
_controlledTokens,
_maxExitFeeMantissa,
_maxTimelockDuration
_maxExitFeeMantissa
);
cToken = _cToken;

Expand Down
5 changes: 1 addition & 4 deletions contracts/prize-pool/stake/StakePrizePool.sol
Expand Up @@ -15,13 +15,11 @@ contract StakePrizePool is PrizePool {
/// @notice Initializes the Prize Pool and Yield Service with the required contract connections
/// @param _controlledTokens Array of addresses for the Ticket and Sponsorship Tokens controlled by the Prize Pool
/// @param _maxExitFeeMantissa The maximum exit fee size, relative to the withdrawal amount
/// @param _maxTimelockDuration The maximum length of time the withdraw timelock could be
/// @param _stakeToken Address of the stake token
function initialize (
RegistryInterface _reserveRegistry,
ControlledTokenInterface[] memory _controlledTokens,
uint256 _maxExitFeeMantissa,
uint256 _maxTimelockDuration,
IERC20Upgradeable _stakeToken
)
public
Expand All @@ -30,8 +28,7 @@ contract StakePrizePool is PrizePool {
PrizePool.initialize(
_reserveRegistry,
_controlledTokens,
_maxExitFeeMantissa,
_maxTimelockDuration
_maxExitFeeMantissa
);
stakeToken = _stakeToken;

Expand Down

0 comments on commit 0b66e0a

Please sign in to comment.