Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VAL-132 Allow cancellation of full requested balance #173

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});