Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Fix/drain expected (#312)
Browse files Browse the repository at this point in the history
* updated WithdrawProxy.drain() to decrement expected

* added more tests and fixed division by 0 in processEpoch()

* Delete loanProofGenerator.js

* remove clones-with-immutable-args

* cleaned up tests
  • Loading branch information
SantiagoGregory authored Apr 26, 2023
1 parent 3c1ecca commit 2c86cc0
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/PublicVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
if ((address(currentWithdrawProxy) != address(0))) {
uint256 proxySupply = currentWithdrawProxy.totalSupply();

s.liquidationWithdrawRatio = proxySupply.mulDivDown(1e18, totalSupply());
s.liquidationWithdrawRatio = totalSupply() == 0 ? 0 : proxySupply.mulDivDown(1e18, totalSupply());

currentWithdrawProxy.setWithdrawRatio(s.liquidationWithdrawRatio);
uint256 expected = currentWithdrawProxy.getExpected();
Expand Down Expand Up @@ -414,7 +414,7 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {

address withdrawProxy = s.epochData[s.currentEpoch].withdrawProxy;
if (
s.withdrawReserve > 0 &&
s.withdrawReserve > 0 && // only happens if previous withdrawProxy exists
timeToEpochEnd() == 0 &&
withdrawProxy != address(0)
) {
Expand Down
4 changes: 4 additions & 0 deletions src/WithdrawProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,14 @@ contract WithdrawProxy is ERC4626Cloned, WithdrawVaultBase {
uint256 amount,
address withdrawProxy
) public onlyVault returns (uint256) {
WPStorage storage s = _loadSlot();

uint256 balance = ERC20(asset()).balanceOf(address(this));
if (amount > balance) {
amount = balance;
}

s.expected -= amount;
ERC20(asset()).safeTransfer(withdrawProxy, amount);
return amount;
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/TestHelpers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ contract TestHelpers is Deploy, ConsiderationTester {
//warps to the first second after the epoch end
assertTrue(
block.timestamp <
PublicVault(vault).getEpochEnd(PublicVault(vault).getCurrentEpoch()) + 1
PublicVault(vault).getEpochEnd(PublicVault(vault).getCurrentEpoch()) + 1,
"warp failed"
);
vm.warp(
PublicVault(vault).getEpochEnd(PublicVault(vault).getCurrentEpoch()) + 1
Expand Down
Loading

0 comments on commit 2c86cc0

Please sign in to comment.