From 0b66e0a28b16b2dcccc1e4ca7ecbfa9b274bdd87 Mon Sep 17 00:00:00 2001 From: Aodhgan Date: Mon, 5 Jul 2021 12:23:59 -0700 Subject: [PATCH] remove timelock from tests --- .../PoolWithMultipleWinnersBuilder.sol | 6 - contracts/prize-pool/PrizePool.sol | 170 +----------- contracts/prize-pool/PrizePoolInterface.sol | 23 +- .../prize-pool/compound/CompoundPrizePool.sol | 5 +- contracts/prize-pool/stake/StakePrizePool.sol | 5 +- .../yield-source/YieldSourcePrizePool.sol | 5 +- contracts/test/CompoundPrizePoolHarness.sol | 4 - contracts/test/PrizePoolHarness.sol | 8 +- contracts/test/StakePrizePoolHarness.sol | 4 - .../test/YieldSourcePrizePoolHarness.sol | 4 - js/deployTestPool.js | 9 +- .../createAndRunYieldSourcePrizePool.js | 3 +- scripts/fork/pools/createUSDTPool.js | 3 +- scripts/fork/usdtDeposit.js | 3 +- test/CompoundPrizePool.test.js | 4 +- test/PoolWithMultipleWinnersBuilder.test.js | 10 +- test/PrizePool.test.js | 250 +----------------- test/StakePrizePool.test.js | 5 +- test/YieldSourcePrizePool.test.js | 5 +- test/features/support/PoolEnv.js | 62 ----- test/features/ticketWithdrawal.stake.test.js | 74 ------ test/features/ticketWithdrawal.test.js | 64 ----- .../ticketWithdrawal.yieldSource.test.js | 64 ----- test/features/timelockDeposit.test.js | 52 ---- 24 files changed, 30 insertions(+), 812 deletions(-) delete mode 100644 test/features/timelockDeposit.test.js diff --git a/contracts/builders/PoolWithMultipleWinnersBuilder.sol b/contracts/builders/PoolWithMultipleWinnersBuilder.sol index b5cd69ef..9b126fe3 100644 --- a/contracts/builders/PoolWithMultipleWinnersBuilder.sol +++ b/contracts/builders/PoolWithMultipleWinnersBuilder.sol @@ -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; @@ -91,7 +88,6 @@ contract PoolWithMultipleWinnersBuilder { reserveRegistry, _tokens(prizeStrategy), prizePoolConfig.maxExitFeeMantissa, - prizePoolConfig.maxTimelockDuration, CTokenInterface(prizePoolConfig.cToken) ); prizePool.setPrizeStrategy(prizeStrategy); @@ -121,7 +117,6 @@ contract PoolWithMultipleWinnersBuilder { reserveRegistry, _tokens(prizeStrategy), prizePoolConfig.maxExitFeeMantissa, - prizePoolConfig.maxTimelockDuration, prizePoolConfig.yieldSource ); prizePool.setPrizeStrategy(prizeStrategy); @@ -151,7 +146,6 @@ contract PoolWithMultipleWinnersBuilder { reserveRegistry, _tokens(prizeStrategy), prizePoolConfig.maxExitFeeMantissa, - prizePoolConfig.maxTimelockDuration, prizePoolConfig.token ); prizePool.setPrizeStrategy(prizeStrategy); diff --git a/contracts/prize-pool/PrizePool.sol b/contracts/prize-pool/PrizePool.sol index 49ce593c..e261bb51 100644 --- a/contracts/prize-pool/PrizePool.sol +++ b/contracts/prize-pool/PrizePool.sol @@ -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 @@ -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, @@ -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 @@ -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; @@ -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; @@ -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 @@ -225,12 +194,10 @@ abstract contract PrizePool is PrizePoolInterface, OwnableUpgradeable, Reentranc reserveRegistry = _reserveRegistry; maxExitFeeMantissa = _maxExitFeeMantissa; - maxTimelockDuration = _maxTimelockDuration; emit Initialized( address(_reserveRegistry), - maxExitFeeMantissa, - maxTimelockDuration + maxExitFeeMantissa ); } @@ -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 @@ -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) @@ -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 @@ -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(); } @@ -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()); diff --git a/contracts/prize-pool/PrizePoolInterface.sol b/contracts/prize-pool/PrizePoolInterface.sol index 19fce21f..5bcb3b8c 100644 --- a/contracts/prize-pool/PrizePoolInterface.sol +++ b/contracts/prize-pool/PrizePoolInterface.sol @@ -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 @@ -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); } diff --git a/contracts/prize-pool/compound/CompoundPrizePool.sol b/contracts/prize-pool/compound/CompoundPrizePool.sol index da3d71d1..2d98c9b9 100644 --- a/contracts/prize-pool/compound/CompoundPrizePool.sol +++ b/contracts/prize-pool/compound/CompoundPrizePool.sol @@ -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 @@ -40,8 +38,7 @@ contract CompoundPrizePool is PrizePool { PrizePool.initialize( _reserveRegistry, _controlledTokens, - _maxExitFeeMantissa, - _maxTimelockDuration + _maxExitFeeMantissa ); cToken = _cToken; diff --git a/contracts/prize-pool/stake/StakePrizePool.sol b/contracts/prize-pool/stake/StakePrizePool.sol index a0d346a5..fb479fbc 100644 --- a/contracts/prize-pool/stake/StakePrizePool.sol +++ b/contracts/prize-pool/stake/StakePrizePool.sol @@ -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 @@ -30,8 +28,7 @@ contract StakePrizePool is PrizePool { PrizePool.initialize( _reserveRegistry, _controlledTokens, - _maxExitFeeMantissa, - _maxTimelockDuration + _maxExitFeeMantissa ); stakeToken = _stakeToken; diff --git a/contracts/prize-pool/yield-source/YieldSourcePrizePool.sol b/contracts/prize-pool/yield-source/YieldSourcePrizePool.sol index 734ecb16..b13fead9 100644 --- a/contracts/prize-pool/yield-source/YieldSourcePrizePool.sol +++ b/contracts/prize-pool/yield-source/YieldSourcePrizePool.sol @@ -19,13 +19,11 @@ contract YieldSourcePrizePool 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 _yieldSource Address of the yield source function initializeYieldSourcePrizePool ( RegistryInterface _reserveRegistry, ControlledTokenInterface[] memory _controlledTokens, uint256 _maxExitFeeMantissa, - uint256 _maxTimelockDuration, IYieldSource _yieldSource ) public @@ -35,8 +33,7 @@ contract YieldSourcePrizePool is PrizePool { PrizePool.initialize( _reserveRegistry, _controlledTokens, - _maxExitFeeMantissa, - _maxTimelockDuration + _maxExitFeeMantissa ); yieldSource = _yieldSource; diff --git a/contracts/test/CompoundPrizePoolHarness.sol b/contracts/test/CompoundPrizePoolHarness.sol index 649df082..7915e063 100644 --- a/contracts/test/CompoundPrizePoolHarness.sol +++ b/contracts/test/CompoundPrizePoolHarness.sol @@ -11,10 +11,6 @@ contract CompoundPrizePoolHarness is CompoundPrizePool { currentTime = _currentTime; } - function setTimelockBalance(uint256 _timelockBalance) external { - timelockTotalSupply = _timelockBalance; - } - function _currentTime() internal override view returns (uint256) { return currentTime; } diff --git a/contracts/test/PrizePoolHarness.sol b/contracts/test/PrizePoolHarness.sol index db63d6f1..646d6c59 100644 --- a/contracts/test/PrizePoolHarness.sol +++ b/contracts/test/PrizePoolHarness.sol @@ -13,7 +13,6 @@ contract PrizePoolHarness is PrizePool { RegistryInterface _reserveRegistry, ControlledTokenInterface[] memory _controlledTokens, uint256 _maxExitFeeMantissa, - uint256 _maxTimelockDuration, YieldSourceStub _stubYieldSource ) public @@ -21,8 +20,7 @@ contract PrizePoolHarness is PrizePool { PrizePool.initialize( _reserveRegistry, _controlledTokens, - _maxExitFeeMantissa, - _maxTimelockDuration + _maxExitFeeMantissa ); stubYieldSource = _stubYieldSource; } @@ -39,10 +37,6 @@ contract PrizePoolHarness is PrizePool { currentTime = _currentTime; } - function setTimelockBalance(uint256 _timelockBalance) external { - timelockTotalSupply = _timelockBalance; - } - function _currentTime() internal override view returns (uint256) { return currentTime; } diff --git a/contracts/test/StakePrizePoolHarness.sol b/contracts/test/StakePrizePoolHarness.sol index 3a10c744..52df03ef 100644 --- a/contracts/test/StakePrizePoolHarness.sol +++ b/contracts/test/StakePrizePoolHarness.sol @@ -11,10 +11,6 @@ contract StakePrizePoolHarness is StakePrizePool { currentTime = _currentTime; } - function setTimelockBalance(uint256 _timelockBalance) external { - timelockTotalSupply = _timelockBalance; - } - function _currentTime() internal override view returns (uint256) { return currentTime; } diff --git a/contracts/test/YieldSourcePrizePoolHarness.sol b/contracts/test/YieldSourcePrizePoolHarness.sol index 12802f6d..ea343ac8 100644 --- a/contracts/test/YieldSourcePrizePoolHarness.sol +++ b/contracts/test/YieldSourcePrizePoolHarness.sol @@ -11,10 +11,6 @@ contract YieldSourcePrizePoolHarness is YieldSourcePrizePool { currentTime = _currentTime; } - function setTimelockBalance(uint256 _timelockBalance) external { - timelockTotalSupply = _timelockBalance; - } - function _currentTime() internal override view returns (uint256) { return currentTime; } diff --git a/js/deployTestPool.js b/js/deployTestPool.js index 7ac02d69..1faf6e57 100644 --- a/js/deployTestPool.js +++ b/js/deployTestPool.js @@ -15,7 +15,6 @@ async function deployTestPool({ prizePeriodStart = 0, prizePeriodSeconds, maxExitFeeMantissa, - maxTimelockDuration, creditLimit, creditRate, externalERC20Awards, @@ -70,7 +69,7 @@ async function deployTestPool({ let prizePool if(poolType == 'stake') { debug('deploying stake pool') - const stakePoolConfig = {token: tokenResult.address, maxExitFeeMantissa, maxTimelockDuration} + const stakePoolConfig = {token: tokenResult.address, maxExitFeeMantissa} let tx = await poolBuilder.createStakeMultipleWinners(stakePoolConfig, multipleWinnersConfig, await token.decimals()) let events = await getEvents(poolBuilder, tx) let event = events[0] @@ -79,8 +78,7 @@ async function deployTestPool({ else if (poolType == 'compound') { const compoundPrizePoolConfig = { cToken: cTokenResult.address, - maxExitFeeMantissa, - maxTimelockDuration + maxExitFeeMantissa } let tx = await poolBuilder.createCompoundMultipleWinners(compoundPrizePoolConfig, multipleWinnersConfig, await token.decimals()) let events = await getEvents(poolBuilder, tx) @@ -90,8 +88,7 @@ async function deployTestPool({ else if (poolType == 'yieldSource') { const yieldSourcePrizePoolConfig = { yieldSource: cTokenYieldSource.address, - maxExitFeeMantissa, - maxTimelockDuration + maxExitFeeMantissa } let tx = await poolBuilder.createYieldSourceMultipleWinners(yieldSourcePrizePoolConfig, multipleWinnersConfig, await token.decimals()) let events = await getEvents(poolBuilder, tx) diff --git a/scripts/fork/helpers/createAndRunYieldSourcePrizePool.js b/scripts/fork/helpers/createAndRunYieldSourcePrizePool.js index 6462e597..282841f3 100644 --- a/scripts/fork/helpers/createAndRunYieldSourcePrizePool.js +++ b/scripts/fork/helpers/createAndRunYieldSourcePrizePool.js @@ -25,8 +25,7 @@ async function createAndRunYieldSourcePrizePool(signer, yieldSourceAddress) { const yieldSourcePrizePoolConfig = { yieldSource: yieldSourceAddress, - maxExitFeeMantissa: ethers.utils.parseEther('0.1'), - maxTimelockDuration: 365 * 24 * 3600 + maxExitFeeMantissa: ethers.utils.parseEther('0.1') } const multipleWinnersConfig = { diff --git a/scripts/fork/pools/createUSDTPool.js b/scripts/fork/pools/createUSDTPool.js index 04ceec63..000009a7 100644 --- a/scripts/fork/pools/createUSDTPool.js +++ b/scripts/fork/pools/createUSDTPool.js @@ -29,8 +29,7 @@ async function run() { const compoundPrizePoolConfig = { cToken: cUSDT, - maxExitFeeMantissa: ethers.utils.parseEther('0.1').toString(), - maxTimelockDuration: 365 * 24 * 3600 + maxExitFeeMantissa: ethers.utils.parseEther('0.1').toString() } const multipleWinnersConfig = { diff --git a/scripts/fork/usdtDeposit.js b/scripts/fork/usdtDeposit.js index d1dad5c5..a529129f 100644 --- a/scripts/fork/usdtDeposit.js +++ b/scripts/fork/usdtDeposit.js @@ -108,8 +108,7 @@ async function run() { const compoundPrizePoolConfig = { cToken: "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9", - maxExitFeeMantissa: toWei("0.5"), - maxTimelockDuration: 1000, + maxExitFeeMantissa: toWei("0.5") } const multipleWinnersConfig = { rngService: rngServiceMock.address, diff --git a/test/CompoundPrizePool.test.js b/test/CompoundPrizePool.test.js index 97669ae5..ffd97d4c 100644 --- a/test/CompoundPrizePool.test.js +++ b/test/CompoundPrizePool.test.js @@ -16,7 +16,6 @@ describe('CompoundPrizePool', function() { let prizePool, erc20token, erc721token, cToken, prizeStrategy, registry let poolMaxExitFee = toWei('0.5') - let poolMaxTimelockDuration = 10000 let ticket @@ -53,11 +52,10 @@ describe('CompoundPrizePool', function() { ticket = await deployMockContract(wallet, ControlledToken.abi, overrides) await ticket.mock.controller.returns(prizePool.address) - initializeTxPromise = prizePool['initialize(address,address[],uint256,uint256,address)']( + initializeTxPromise = prizePool['initialize(address,address[],uint256,address)']( registry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, cToken.address ) diff --git a/test/PoolWithMultipleWinnersBuilder.test.js b/test/PoolWithMultipleWinnersBuilder.test.js index 15d3b9dc..6dd5bc29 100644 --- a/test/PoolWithMultipleWinnersBuilder.test.js +++ b/test/PoolWithMultipleWinnersBuilder.test.js @@ -71,7 +71,6 @@ describe('PoolWithMultipleWinnersBuilder', () => { compoundPrizePoolConfig = { cToken: cToken.address, maxExitFeeMantissa: toWei('0.5'), - maxTimelockDuration: 1000 } }) @@ -107,7 +106,6 @@ describe('PoolWithMultipleWinnersBuilder', () => { expect(await prizePool.cToken()).to.equal(compoundPrizePoolConfig.cToken) expect(await prizePool.maxExitFeeMantissa()).to.equal(compoundPrizePoolConfig.maxExitFeeMantissa) - expect(await prizePool.maxTimelockDuration()).to.equal(compoundPrizePoolConfig.maxTimelockDuration) expect(await prizePool.owner()).to.equal(wallet.address) }) }) @@ -118,8 +116,7 @@ describe('PoolWithMultipleWinnersBuilder', () => { beforeEach(async () => { stakePrizePoolConfig = { token: cToken.address, - maxExitFeeMantissa: toWei('0.5'), - maxTimelockDuration: 1000 + maxExitFeeMantissa: toWei('0.5') } }) @@ -149,7 +146,6 @@ describe('PoolWithMultipleWinnersBuilder', () => { expect(await prizePool.token()).to.equal(stakePrizePoolConfig.token) expect(await prizePool.maxExitFeeMantissa()).to.equal(stakePrizePoolConfig.maxExitFeeMantissa) - expect(await prizePool.maxTimelockDuration()).to.equal(stakePrizePoolConfig.maxTimelockDuration) }) }) @@ -159,8 +155,7 @@ describe('PoolWithMultipleWinnersBuilder', () => { beforeEach(async () => { yieldSourcePrizePoolConfig = { yieldSource: cDaiYieldSource.address, - maxExitFeeMantissa: toWei('0.5'), - maxTimelockDuration: 1000 + maxExitFeeMantissa: toWei('0.5') } }) @@ -189,7 +184,6 @@ describe('PoolWithMultipleWinnersBuilder', () => { expect(await prizePool.prizeStrategy()).to.equal(prizeStrategy.address) expect(await prizePool.owner()).to.equal(wallet.address) expect(await prizePool.maxExitFeeMantissa()).to.equal(yieldSourcePrizePoolConfig.maxExitFeeMantissa) - expect(await prizePool.maxTimelockDuration()).to.equal(yieldSourcePrizePoolConfig.maxTimelockDuration) expect(await prizeStrategy.owner()).to.equal(wallet.address) }) diff --git a/test/PrizePool.test.js b/test/PrizePool.test.js index 19735002..8c4ea359 100644 --- a/test/PrizePool.test.js +++ b/test/PrizePool.test.js @@ -22,7 +22,6 @@ describe('PrizePool', function() { let multiTokenPrizePool, multiTokenPrizeStrategy let poolMaxExitFee = toWei('0.5') - let poolMaxTimelockDuration = 10000 let ticket, sponsorship @@ -74,7 +73,6 @@ describe('PrizePool', function() { reserve.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) @@ -82,8 +80,7 @@ describe('PrizePool', function() { .to.emit(prizePool, 'Initialized') .withArgs( reserve.address, - poolMaxExitFee, - poolMaxTimelockDuration + poolMaxExitFee ) await expect(tx) @@ -105,7 +102,6 @@ describe('PrizePool', function() { reserveRegistry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) await prizePool.setPrizeStrategy(prizeStrategy.address) @@ -200,7 +196,6 @@ describe('PrizePool', function() { reserveRegistry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ] let initArgs @@ -221,26 +216,6 @@ describe('PrizePool', function() { }) describe('depositTo()', () => { - it('should mint timelock tokens to the user', async () => { - const amount = toWei('11') - - // updateAwardBalance - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns(amount) - await ticket.mock.balanceOf.withArgs(wallet2.address).returns(amount) - - await erc20token.mock.transferFrom.withArgs(wallet.address, prizePool.address, amount).returns(true) - await yieldSourceStub.mock.supply.withArgs(amount).returns() - await prizeStrategy.mock.beforeTokenMint.withArgs(wallet2.address, amount, ticket.address, AddressZero).returns() - await ticket.mock.controllerMint.withArgs(wallet2.address, amount).returns() - - // Test depositTo - await expect(prizePool.depositTo(wallet2.address, amount, ticket.address, AddressZero)) - .to.emit(prizePool, 'Deposited') - .withArgs(wallet.address, wallet2.address, ticket.address, amount, AddressZero) - - }) - it('should revert when deposit exceeds liquidity cap', async () => { const amount = toWei('1') const liquidityCap = toWei('1000') @@ -253,19 +228,6 @@ describe('PrizePool', function() { }) }) - describe('timelockDepositTo', () => { - it('should revert when deposit exceeds liquidity cap', async () => { - const amount = toWei('1') - const liquidityCap = toWei('1000') - - await ticket.mock.totalSupply.returns(liquidityCap) - await prizePool.setLiquidityCap(liquidityCap) - - await expect(prizePool.timelockDepositTo(wallet2.address, amount, ticket.address)) - .to.be.revertedWith("PrizePool/exceeds-liquidity-cap") - }) - }) - describe('captureAwardBalance()', () => { it('should handle when the balance is less than the collateral', async () => { await ticket.mock.totalSupply.returns(toWei('100')) @@ -535,206 +497,6 @@ describe('PrizePool', function() { }) }) - describe('withdrawWithTimelockFrom()', () => { - it('should allow a user to withdraw with a timelock', async () => { - let amount = toWei('10') - // updateAwardBalance - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns(amount) - await ticket.mock.balanceOf.withArgs(wallet.address).returns(amount) - - // force current time - await prizePool.setCurrentTime('1') - - // expect a ticket burn - await ticket.mock.controllerBurnFrom.withArgs(wallet.address, wallet.address, amount).returns() - - // expect finish - - // setup timelocked withdrawal - await prizePool.withdrawWithTimelockFrom(wallet.address, amount, ticket.address) - - expect(await prizePool.timelockBalanceOf(wallet.address)).to.equal(amount) - expect(await prizePool.timelockBalanceAvailableAt(wallet.address)).to.equal(11) - expect(await prizePool.timelockTotalSupply()).to.equal(amount) - }) - - it('should limit the duration of the timelock', async () => { - - await prizePool.setCreditPlanOf(ticket.address, toWei('0.000000000000000001'), toWei('0.9')) - - let amount = toWei('10') - - // updateAwardBalance - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns(amount) - await ticket.mock.balanceOf.withArgs(wallet.address).returns(amount) - - // force current time - await prizePool.setCurrentTime('1') - - // expect a ticket burn - await ticket.mock.controllerBurnFrom - .withArgs(wallet.address, wallet.address, amount) - .returns() - - // expect finish - - // setup timelocked withdrawal - await prizePool.withdrawWithTimelockFrom(wallet.address, amount, ticket.address) - - expect(await prizePool.timelockBalanceOf(wallet.address)).to.equal(amount) - expect(await prizePool.timelockBalanceAvailableAt(wallet.address)).to.equal(1 + poolMaxTimelockDuration) // current time + 10000 - expect(await prizePool.timelockTotalSupply()).to.equal(amount) - }) - }) - - describe('sweepTimelockBalances()', () => { - it('should do nothing when no balances are available', async () => { - // updateAwardBalance - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns('0') - - // now execute timelock withdrawal - await expect(prizePool.sweepTimelockBalances([wallet.address])) - .not.to.emit(prizePool, 'TimelockedWithdrawalSwept') - .withArgs(wallet.address, wallet.address, toWei('10'), toWei('10')) - }) - - it('should sweep only balances that are unlocked', async () => { - - let amount1 = toWei('11') - let amount2 = toWei('22') - - // updateAwardBalance - await yieldSourceStub.mock.balance.returns(toWei('33')) - await ticket.mock.totalSupply.returns(toWei('33')) - await ticket.mock.balanceOf.withArgs(wallet.address).returns(amount1) - await ticket.mock.balanceOf.withArgs(wallet2.address).returns(amount2) - - // force current time - await prizePool.setCurrentTime(1) - - // expect ticket burns from both - await ticket.mock.controllerBurnFrom.returns() - - await prizePool.withdrawWithTimelockFrom(wallet.address, amount1, ticket.address) - - // Second will unlock at 21 - await prizePool.setCurrentTime(11) - - await prizePool.withdrawWithTimelockFrom(wallet2.address, amount2, ticket.address) - - // Only first deposit is unlocked - await prizePool.setCurrentTime(15) - - // expect the redeem && transfer for only the unlocked amount - await yieldSourceStub.mock.redeem.withArgs(amount1).returns(amount1) - await erc20token.mock.transfer.withArgs(wallet.address, amount1).returns(true) - - // Let's sweep - await expect(prizePool.sweepTimelockBalances([wallet.address, wallet2.address])) - .to.emit(prizePool, 'TimelockedWithdrawalSwept') - .withArgs(wallet.address, wallet.address, amount1, amount1) - - // first user has cleared - expect(await prizePool.timelockBalanceOf(wallet.address)).to.equal(toWei('0')) - expect(await prizePool.timelockBalanceAvailableAt(wallet.address)).to.equal('0') - - // second has not - expect(await prizePool.timelockBalanceOf(wallet2.address)).to.equal(amount2) - expect(await prizePool.timelockBalanceAvailableAt(wallet2.address)).to.equal(21) - - expect(await prizePool.timelockTotalSupply()).to.equal(amount2) - }) - - it('should sweep timelock balances that have unlocked', async () => { - let amount = toWei('10') - let amount2 = toWei('30') - - // updateAwardBalance - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns(amount) - await ticket.mock.balanceOf.withArgs(wallet.address).returns(amount) - await ticket.mock.balanceOf.withArgs(wallet2.address).returns(amount2) - - // force current time - await prizePool.setCurrentTime(1) - - // expect a ticket burn - await ticket.mock.controllerBurnFrom.withArgs(wallet.address, wallet.address, amount).returns() - await ticket.mock.controllerBurnFrom.withArgs(wallet2.address, wallet2.address, amount2).returns() - - // expect finish - - // setup timelocked withdrawal - await prizePool.withdrawWithTimelockFrom(wallet.address, amount, ticket.address) - await prizePool.connect(wallet2).withdrawWithTimelockFrom(wallet2.address, amount2, ticket.address) - - // expect the redeem && transfer - // NOTE: Only 12 tokens are returned here - await yieldSourceStub.mock.redeem.withArgs(toWei('40')).returns(toWei('20')) - await erc20token.mock.transfer.withArgs(wallet.address, toWei('5')).returns(true) - await erc20token.mock.transfer.withArgs(wallet2.address, toWei('15')).returns(true) - - // ensure time is after - await prizePool.setCurrentTime(11) - - // now execute timelock withdrawal - // const tx = - - let tx = prizePool.sweepTimelockBalances([wallet.address, wallet2.address]) - - await expect(tx) - .to.emit(prizePool, 'TimelockedWithdrawalSwept') - .withArgs(wallet.address, wallet.address, amount, toWei('5')) - - await expect(tx) - .to.emit(prizePool, 'TimelockedWithdrawalSwept') - .withArgs(wallet.address, wallet2.address, amount2, toWei('15')) - - expect(await prizePool.timelockBalanceOf(wallet.address)).to.equal('0') - expect(await prizePool.timelockBalanceAvailableAt(wallet.address)).to.equal('0') - expect(await prizePool.timelockBalanceOf(wallet2.address)).to.equal('0') - expect(await prizePool.timelockBalanceAvailableAt(wallet2.address)).to.equal('0') - }) - }) - - describe('calculateTimelockDuration()', () => { - it('should return the timelock duration', async () => { - let amount = toWei('10') - - await yieldSourceStub.mock.balance.returns('0') - await ticket.mock.totalSupply.returns(amount) - await ticket.mock.balanceOf.withArgs(wallet.address).returns(amount) - - // force current time and check - await prizePool.setCurrentTime('10') - expect(await call(prizePool, 'calculateTimelockDuration', wallet.address, ticket.address, amount)).to.deep.equal([ - ethers.BigNumber.from('10'), - ethers.BigNumber.from('0') - ]) - - // trigger a credit update - await prizePool.calculateTimelockDuration(wallet.address, ticket.address, amount) - - // fast forward 5 seconds - await prizePool.setCurrentTime('15') - - // timelock duration should be less due to credit - expect(await call(prizePool, 'calculateTimelockDuration', wallet.address, ticket.address, amount)).to.deep.equal([ - ethers.BigNumber.from('5'), - toWei('0.5') - ]) - - // trigger a credit update - await prizePool.calculateTimelockDuration(wallet.address, ticket.address, amount) - - // credit should not be burned - expect(await call(prizePool, 'balanceOfCredit', wallet.address, ticket.address)).to.equal(toWei('0.5')) - }) - }) - describe('balance()', () => { it('should return zero if no deposits have been made', async () => { await yieldSourceStub.mock.balance.returns(toWei('11')) @@ -823,7 +585,6 @@ describe('PrizePool', function() { reserveRegistry.address, [ticket.address, sponsorship.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) @@ -832,12 +593,12 @@ describe('PrizePool', function() { }) describe('accountedBalance()', () => { - it('should return the total accounted balance for all tokens including timelocked deposits', async () => { + it('should return the total accounted balance for all tokens', async () => { await ticket.mock.totalSupply.returns(toWei('123')) await sponsorship.mock.totalSupply.returns(toWei('456')) - await multiTokenPrizePool.setTimelockBalance(toWei('789')) - expect(await multiTokenPrizePool.accountedBalance()).to.equal(toWei('1368')) + + expect(await multiTokenPrizePool.accountedBalance()).to.equal(toWei('579')) }) it('should include the reserve', async () => { @@ -864,7 +625,6 @@ describe('PrizePool', function() { prizeStrategy.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) await prizePool.setPrizeStrategy(prizeStrategy.address) @@ -899,7 +659,6 @@ describe('PrizePool', function() { prizeStrategy.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) await prizePool.setPrizeStrategy(prizeStrategy.address) @@ -935,7 +694,6 @@ describe('PrizePool', function() { prizeStrategy.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSourceStub.address ) await prizePool.setPrizeStrategy(prizeStrategy.address) diff --git a/test/StakePrizePool.test.js b/test/StakePrizePool.test.js index 67e5c764..71f793d2 100644 --- a/test/StakePrizePool.test.js +++ b/test/StakePrizePool.test.js @@ -16,7 +16,7 @@ describe('StakePrizePool', function() { let prizePool, erc20token, erc721token, stakeToken, prizeStrategy, registry let poolMaxExitFee = toWei('0.5') - let poolMaxTimelockDuration = 10000 + let ticket @@ -55,11 +55,10 @@ describe('StakePrizePool', function() { ticket = await deployMockContract(wallet, ControlledToken.abi, overrides) await ticket.mock.controller.returns(prizePool.address) - initializeTxPromise = prizePool['initialize(address,address[],uint256,uint256,address)']( + initializeTxPromise = prizePool['initialize(address,address[],uint256,address)']( registry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, stakeToken.address ) diff --git a/test/YieldSourcePrizePool.test.js b/test/YieldSourcePrizePool.test.js index 0c26f17e..7b7c11b5 100644 --- a/test/YieldSourcePrizePool.test.js +++ b/test/YieldSourcePrizePool.test.js @@ -15,7 +15,7 @@ describe('YieldSourcePrizePool', function() { let prizePool, erc20token, prizeStrategy, reserveRegistry, yieldSource, YieldSourcePrizePoolHarness let poolMaxExitFee = toWei('0.5') - let poolMaxTimelockDuration = 10000 + let ticket @@ -54,7 +54,6 @@ describe('YieldSourcePrizePool', function() { reserveRegistry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, yieldSource.address ) @@ -81,7 +80,6 @@ describe('YieldSourcePrizePool', function() { reserveRegistry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, ethers.constants.AddressZero )).to.be.revertedWith("YieldSourcePrizePool/yield-source-zero") }) @@ -94,7 +92,6 @@ describe('YieldSourcePrizePool', function() { reserveRegistry.address, [ticket.address], poolMaxExitFee, - poolMaxTimelockDuration, prizePool.address )).to.be.revertedWith("YieldSourcePrizePool/invalid-yield-source") }) diff --git a/test/features/support/PoolEnv.js b/test/features/support/PoolEnv.js index b767ccf7..3fdec1dd 100644 --- a/test/features/support/PoolEnv.js +++ b/test/features/support/PoolEnv.js @@ -24,7 +24,6 @@ function PoolEnv() { creditLimit, creditRate, maxExitFeeMantissa = toWei('0.5'), - maxTimelockDuration = 1000, externalERC20Awards = [], poolType }) { @@ -49,7 +48,6 @@ function PoolEnv() { prizePeriodStart, prizePeriodSeconds, maxExitFeeMantissa, - maxTimelockDuration, creditLimit: toWei(creditLimit), creditRate: toWei(creditRate), externalERC20Awards: [], @@ -177,22 +175,6 @@ function PoolEnv() { debug(`Bought tickets`) } - this.timelockBuyTickets = async function ({ user, tickets }) { - debug(`Buying tickets with timelocked tokens...`) - let wallet = await this.wallet(user) - - debug('wallet is ', wallet.address) - - let ticket = await this.ticket(wallet) - let prizePool = await this.prizePool(wallet) - - let amount = toWei('' + tickets) - - await prizePool.timelockDepositTo(wallet.address, amount, ticket.address, this.overrides) - - debug(`Bought tickets with timelocked tokens`) - } - this.transferCompoundTokensToPrizePool = async function ({ user, tokens }) { let wallet = await this.wallet(user) let amount = toWei(tokens) @@ -208,22 +190,6 @@ function PoolEnv() { await this.env.cTokenYieldSource.connect(wallet).supplyTokenTo(amount, this.env.prizePool.address) } - this.timelockBuySponsorship = async function ({ user, sponsorship }) { - debug(`Buying sponsorship with timelocked tokens...`) - let wallet = await this.wallet(user) - - debug('wallet is ', wallet.address) - - let sponsorshipContract = await this.sponsorship(wallet) - let prizePool = await this.prizePool(wallet) - - let amount = toWei('' + sponsorship) - - await prizePool.timelockDepositTo(wallet.address, amount, sponsorshipContract.address, this.overrides) - - debug(`Bought sponsorship with timelocked tokens`) - } - this.expectUserToHaveTickets = async function ({ user, tickets }) { let wallet = await this.wallet(user) let ticket = await this.ticket(wallet) @@ -271,21 +237,6 @@ function PoolEnv() { expect(ticketInterest).to.equalish(toWei(credit), 300) } - this.expectUserToHaveTimelock = async function ({ user, timelock }) { - let wallet = await this.wallet(user) - let prizePool = await this.prizePool(wallet) - let timelockBalance = await prizePool.timelockBalanceOf(wallet.address) - expect(timelockBalance).to.equalish(toWei(timelock), 300) - } - - this.expectUserTimelockAvailableAt = async function ({ user, elapsed }) { - let wallet = await this.wallet(user) - let prizeStrategy = await this.prizeStrategy(wallet) - let prizePool = await this.prizePool(wallet) - let startTime = await prizeStrategy.prizePeriodStartedAt() - let time = startTime.add(elapsed) - expect(await prizePool.timelockBalanceAvailableAt(wallet.address)).to.equal(time) - } this.expectUserToHaveExternalAwardAmount = async function ({ user, externalAward, amount }) { let wallet = await this.wallet(user) @@ -352,19 +303,6 @@ function PoolEnv() { debug("done withdraw instantly") } - this.withdrawWithTimelock = async function ({user, tickets}) { - let wallet = await this.wallet(user) - let ticket = await this.ticket(wallet) - let prizePool = await this.prizePool(wallet) - await prizePool.withdrawWithTimelockFrom(wallet.address, toWei(tickets), ticket.address, []) - } - - this.sweepTimelockBalances = async function ({ user }) { - let wallet = await this.wallet(user) - let prizePool = await this.prizePool(wallet) - await prizePool.sweepTimelockBalances([wallet.address, wallet.address]) - } - this.balanceOfTickets = async function ({ user }) { let wallet = await this.wallet(user) let ticket = await this.ticket(wallet) diff --git a/test/features/ticketWithdrawal.stake.test.js b/test/features/ticketWithdrawal.stake.test.js index 3bc90e81..5b0928ba 100644 --- a/test/features/ticketWithdrawal.stake.test.js +++ b/test/features/ticketWithdrawal.stake.test.js @@ -102,78 +102,4 @@ describe('StakePool Withdraw Feature', () => { }) }) }) - - - describe('timelocked', () => { - it('should have the maximum timelock when the user has zero credit', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01', poolType: 'stake' }) - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - - await env.poolAccrues({ tickets: 1000 }) - - await env.sweepTimelockBalances({ user: 1 }) - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - }) - - it('should consume a users credit to shorten the timelock', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01', poolType: 'stake' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.setCurrentTime(0) - await env.buyTickets({ user: 1, tickets: 100 }) - - // withdraw at half time so credit should have accrued - await env.setCurrentTime(6) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - - await env.poolAccrues({ tickets: 1000 }) - - await env.sweepTimelockBalances({ user: 1 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - - it('should not have any timelock when a user accrues all the credit', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01', poolType: 'stake' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - - await env.setCurrentTime(10) - await env.expectUserToHaveCredit({ user: 1, credit: 10 }) - - // withdraw with timelock should be immediate - await env.setCurrentTime(17) - - await env.poolAccrues({ tickets: 1000 }) - - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 0 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - }) }) diff --git a/test/features/ticketWithdrawal.test.js b/test/features/ticketWithdrawal.test.js index fd568b44..9ba3f606 100644 --- a/test/features/ticketWithdrawal.test.js +++ b/test/features/ticketWithdrawal.test.js @@ -92,68 +92,4 @@ describe('Compound Withdraw Feature', () => { }) }) }) - - describe('timelocked', () => { - it('should have the maximum timelock when the user has zero credit', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - await env.sweepTimelockBalances({ user: 1 }) - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - }) - - it('should consume a users credit to shorten the timelock', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.setCurrentTime(0) - await env.buyTickets({ user: 1, tickets: 100 }) - - // withdraw at half time so credit should have accrued - await env.setCurrentTime(6) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - await env.sweepTimelockBalances({ user: 1 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - - it('should not have any timelock when a user accrues all the credit', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - - await env.setCurrentTime(10) - await env.expectUserToHaveCredit({ user: 1, credit: 10 }) - - // withdraw with timelock should be immediate - await env.setCurrentTime(17) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 0 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - }) }) diff --git a/test/features/ticketWithdrawal.yieldSource.test.js b/test/features/ticketWithdrawal.yieldSource.test.js index f48b5761..794c3562 100644 --- a/test/features/ticketWithdrawal.yieldSource.test.js +++ b/test/features/ticketWithdrawal.yieldSource.test.js @@ -92,68 +92,4 @@ describe('YieldSource Prize Pool /w Compound yield source withdrawals', () => { }) }) }) - - describe('timelocked', () => { - it('should have the maximum timelock when the user has zero credit', async () => { - await env.createPool({ poolType: 'yieldSource', prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - await env.sweepTimelockBalances({ user: 1 }) - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - }) - - it('should consume a users credit to shorten the timelock', async () => { - await env.createPool({ poolType: 'yieldSource', prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.setCurrentTime(0) - await env.buyTickets({ user: 1, tickets: 100 }) - - // withdraw at half time so credit should have accrued - await env.setCurrentTime(6) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - // sweep balances - await env.setCurrentTime(10) - await env.sweepTimelockBalances({ user: 1 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - - it('should not have any timelock when a user accrues all the credit', async () => { - await env.createPool({ poolType: 'yieldSource', prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - - // buy at time zero so that it is considered a 'full' ticket - await env.buyTickets({ user: 1, tickets: 100 }) - - await env.setCurrentTime(10) - await env.expectUserToHaveCredit({ user: 1, credit: 10 }) - - // withdraw with timelock should be immediate - await env.setCurrentTime(17) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.expectUserToHaveTimelock({ user: 1, timelock: 0 }) - - // expect balance - await env.expectUserToHaveTokens({ user: 1, tokens: 100 }) - await env.expectUserToHaveCredit({ user: 1, credit: 0 }) - }) - }) }) diff --git a/test/features/timelockDeposit.test.js b/test/features/timelockDeposit.test.js deleted file mode 100644 index 47eea39e..00000000 --- a/test/features/timelockDeposit.test.js +++ /dev/null @@ -1,52 +0,0 @@ -const { PoolEnv } = require('./support/PoolEnv') - -describe('Re-deposit Timelocked Tokens', () => { - - let env - - beforeEach(() => { - env = new PoolEnv() - }) - - describe('convert timelock to tickets', () => { - it('should allow the user to re-deposit timelock as tickets', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - // buy at time zero so that it is considered a 'full' ticket - await env.setCurrentTime(0) - await env.buyTickets({ user: 1, tickets: 100 }) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.setCurrentTime(10) - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - await env.timelockBuyTickets({ user: 1, tickets: 100 }) - - // expect balance - await env.expectUserToHaveTickets({ user: 1, tickets: 100 }) - await env.expectUserToHaveTimelock({ user: 1, timelock: 0 }) - }) - }) - - describe('convert timelock to sponsorship', () => { - it('should allow the user to re-deposit timelock as tickets', async () => { - await env.createPool({ prizePeriodSeconds: 10, creditLimit: '0.1', creditRate: '0.01' }) - // buy at time zero so that it is considered a 'full' ticket - await env.setCurrentTime(0) - await env.buyTickets({ user: 1, tickets: 100 }) - await env.withdrawWithTimelock({ user: 1, tickets: 100 }) - - // tickets are converted to timelock - await env.setCurrentTime(10) - await env.expectUserToHaveTimelock({ user: 1, timelock: 100 }) - await env.expectUserTimelockAvailableAt({ user: 1, elapsed: 10 }) - - await env.timelockBuySponsorship({ user: 1, sponsorship: 100 }) - - // expect balance - await env.expectUserToHaveSponsorship({ user: 1, sponsorship: 100 }) - await env.expectUserToHaveTimelock({ user: 1, timelock: 0 }) - }) - }) -})