Skip to content

Commit

Permalink
VAL-132 Allow cancellation of full requested balance (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ams9198 authored Feb 8, 2023
1 parent 5622ecc commit 027ecfa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
9 changes: 1 addition & 8 deletions contracts/libraries/PoolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,7 @@ library PoolLib {
IPoolWithdrawState memory state,
uint256 requestCancellationFeeBps
) public pure returns (uint256) {
uint256 sharesRemaining = state.requestedShares + state.eligibleShares;

uint256 sharesFee = calculateCancellationFee(
sharesRemaining,
requestCancellationFeeBps
);

return Math.max(sharesRemaining - sharesFee, 0);
return state.requestedShares + state.eligibleShares;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/libraries/PoolLib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ describe("PoolLib", () => {
).to.equal(72);
});

it("returns the number of shares minus fees", async () => {
it("returns the number of shares irrespective of fees ", async () => {
const { poolLibWrapper } = await loadFixture(deployFixture);

const fees = 1200; // 12%
Expand All @@ -892,7 +892,7 @@ describe("PoolLib", () => {

expect(
await poolLibWrapper.calculateMaxCancellation(withdrawState, fees)
).to.equal(63);
).to.equal(72);
});
});
});
34 changes: 31 additions & 3 deletions test/scenarios/pool/withdraw-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,43 @@ describe("Withdraw Requests", () => {
expect(await pool.maxWithdraw(bobLender.address)).to.equal(6);

// Cancel a request
expect(await pool.maxRequestCancellation(aliceLender.address)).to.equal(16);
expect(await pool.maxRequestCancellation(bobLender.address)).to.equal(3);
expect(await pool.maxRequestCancellation(aliceLender.address)).to.equal(17);
expect(await pool.maxRequestCancellation(bobLender.address)).to.equal(4);

// Cancel Bob's request
const bobBalance = await pool.balanceOf(bobLender.address);
await pool.connect(bobLender).cancelRedeemRequest(3);

// Expect a fee to be paid
expect(await pool.balanceOf(bobLender.address)).to.equal(bobBalance.sub(1));
expect(await pool.maxRequestCancellation(bobLender.address)).to.equal(0);
expect(await pool.maxRequestCancellation(bobLender.address)).to.equal(1);
});

it("allows canceling a full request balance", async () => {
const { pool, aliceLender, bobLender, withdrawController } =
await loadFixture(loadPoolFixture);

// Alice requests full redemption
await pool
.connect(aliceLender)
.requestRedeem(await pool.maxRedeemRequest(aliceLender.address));
expect(
await withdrawController.requestedBalanceOf(aliceLender.address)
).to.equal(90);

// Check max request cancellation
expect(await pool.maxRequestCancellation(aliceLender.address)).to.equal(90);

// Cancel request
const txn = await pool.connect(aliceLender).cancelRedeemRequest(90);

// Check that the cancellation burned a PT in fees
// 1% cancellation fee of 90 == 1 token
await expect(txn).to.changeTokenBalance(pool, aliceLender.address, -1);

// Check requested balance is now zeroed out
expect(
await withdrawController.requestedBalanceOf(aliceLender.address)
).to.equal(0);
});
});

0 comments on commit 027ecfa

Please sign in to comment.