Skip to content

Commit

Permalink
User now explicitly allows how much of their deposit is taken (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Jul 23, 2020
1 parent 27450ee commit 88f3214
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion contracts/prize-pool/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ abstract contract PrizePool is OwnableUpgradeSafe, BaseRelayRecipient, Reentranc
/// @param amount The amount of assets to redeem for tickets
/// @param controlledToken The address of the asset token being withdrawn
/// @param sponsorAmount An optional amount of assets paid by the operator used to cover exit fees
/// @param maximumExitFee The maximum exit fee the user is willing to pay. This should be pre-calculated
/// @return exitFee The amount of the fairness fee paid
function withdrawInstantlyFrom(
address from,
uint256 amount,
address controlledToken,
uint256 sponsorAmount
uint256 sponsorAmount,
uint256 maximumExitFee
)
external
nonReentrant
Expand All @@ -170,6 +172,7 @@ abstract contract PrizePool is OwnableUpgradeSafe, BaseRelayRecipient, Reentranc
if (exitFee > maxFee) {
exitFee = maxFee;
}
require(exitFee <= maximumExitFee, "PrizePool/exit-fee-exceeds-user-maximum");

address operator = _msgSender();
uint256 sponsoredExitFeePortion = (exitFee > sponsorAmount) ? sponsorAmount : exitFee;
Expand Down
20 changes: 18 additions & 2 deletions test/CompoundPrizePool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,26 @@ describe('CompoundPrizePool', function() {
await token.mock.transfer.withArgs(wallet._address, toWei('10')).returns(true)
await prizeStrategy.mock.afterWithdrawInstantlyFrom.withArgs(wallet._address, wallet._address, amount, ticket.address, toWei('1'), '0').returns()

await expect(prizePool.withdrawInstantlyFrom(wallet._address, amount, ticket.address, '0'))
await expect(prizePool.withdrawInstantlyFrom(wallet._address, amount, ticket.address, '0', toWei('1')))
.to.emit(prizePool, 'InstantWithdrawal')
.withArgs(wallet._address, wallet._address, ticket.address, amount, toWei('1'), '0')
})

it('should allow a user to set a maximum exit fee', async () => {
let amount = toWei('11')

// updateAwardBalance
await cToken.mock.balanceOfUnderlying.returns('0')
await ticket.mock.totalSupply.returns('0')

await prizeStrategy.mock.beforeWithdrawInstantlyFrom.withArgs(wallet._address, amount, ticket.address).returns(toWei('1'))
await ticket.mock.controllerBurnFrom.withArgs(wallet._address, wallet._address, amount).returns()
await cToken.mock.redeemUnderlying.withArgs(toWei('10')).returns('0')
await token.mock.transfer.withArgs(wallet._address, toWei('10')).returns(true)
await prizeStrategy.mock.afterWithdrawInstantlyFrom.withArgs(wallet._address, wallet._address, amount, ticket.address, toWei('1'), '0').returns()

await expect(prizePool.withdrawInstantlyFrom(wallet._address, amount, ticket.address, '0', toWei('0.5'))).to.be.revertedWith('PrizePool/exit-fee-exceeds-user-maximum')
})
})

describe('withdrawWithTimelockFrom()', () => {
Expand Down Expand Up @@ -394,7 +410,7 @@ describe('CompoundPrizePool', function() {
await token.mock.transfer.withArgs(wallet._address, toWei('11')).returns(true)
// await prizeStrategy.mock.afterWithdrawInstantlyFrom.withArgs(wallet._address, wallet._address, amount, ticket.address, toWei('1'), '0').returns()

await expect(detachedPrizePool.withdrawInstantlyFrom(wallet._address, amount, ticket2.address, '0'))
await expect(detachedPrizePool.withdrawInstantlyFrom(wallet._address, amount, ticket2.address, '0', toWei('1')))
.to.emit(detachedPrizePool, 'InstantWithdrawal')
.withArgs(wallet._address, wallet._address, ticket2.address, amount, toWei('0'), '0')
})
Expand Down
2 changes: 1 addition & 1 deletion test/features/support/PoolEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function PoolEnv() {
let wallet = await this.wallet(user)
let ticket = await this.ticket(wallet)
let prizePool = await this.prizePool(wallet)
await prizePool.withdrawInstantlyFrom(wallet._address, toWei(tickets), ticket.address, '0')
await prizePool.withdrawInstantlyFrom(wallet._address, toWei(tickets), ticket.address, '0', toWei('1000'))
}

this.withdrawInstantlyAtTime = async function ({ user, tickets, elapsed }) {
Expand Down

0 comments on commit 88f3214

Please sign in to comment.