Skip to content

Commit

Permalink
Expose calculateTimelockDuration externally
Browse files Browse the repository at this point in the history
  • Loading branch information
robsecord committed Sep 9, 2020
1 parent d5b549e commit e43ce22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/prize-pool/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,22 @@ abstract contract PrizePool is OwnableUpgradeSafe, RelayRecipient, ReentrancyGua
/// @param amount The amount the user is withdrawing
/// @param controlledToken The type of collateral the user is withdrawing (i.e. ticket or sponsorship)
/// @return durationSeconds The duration of the timelock in seconds
function calculateTimelockDuration(
address from,
address controlledToken,
uint256 amount
)
external
returns (uint256)
{
return _calculateTimelockDuration(from, controlledToken, amount);
}

/// @dev Calculates a timelocked withdrawal duration and credit consumption.
/// @param from The user who is withdrawing
/// @param amount The amount the user is withdrawing
/// @param controlledToken The type of collateral the user is withdrawing (i.e. ticket or sponsorship)
/// @return durationSeconds The duration of the timelock in seconds
function _calculateTimelockDuration(
address from,
address controlledToken,
Expand Down
14 changes: 14 additions & 0 deletions test/CompoundPrizePool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,20 @@ describe('CompoundPrizePool', function() {
})
})

describe('calculateTimelockDuration()', () => {
it('should return the timelock duration', async () => {
let amount = toWei('10')

await cToken.mock.balanceOfUnderlying.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('1')
expect(await call(prizePool, 'calculateTimelockDuration', wallet._address, ticket.address, amount)).to.equal(10)
})
})

describe('estimateAccruedInterestOverBlocks()', () => {
it('should get the supply rate from the yield service to estimate interest per block', async function () {
const deposit = toWei('100')
Expand Down

0 comments on commit e43ce22

Please sign in to comment.