Skip to content

Commit

Permalink
Merge pull request #1 from Tenderize/nv/fix-withdraw
Browse files Browse the repository at this point in the history
fix withdraw liablities
  • Loading branch information
kyriediculous authored Oct 28, 2024
2 parents 5fb269c + a98f7a4 commit e3e0136
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lpETH/LpETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ contract LpETH is

uint256 available = ud(amount).mul(UNIT_60x18.sub(ud($.unlocking).div(ud($.liabilities)))).unwrap();

if (available < amount) {
if (available < amount && available > 0) {
requestId = $.withdrawQueue.createRequest(uint128(amount - available), payable(msg.sender));
}

Expand All @@ -233,7 +233,7 @@ contract LpETH is
if (lpShares > maxLpSharesBurnt) revert ErrorSlippage(lpShares, maxLpSharesBurnt);

// Update liabilities
$.liabilities -= amount;
$.liabilities -= available;

// Burn LP tokens from the caller
LPTOKEN.burn(msg.sender, lpShares);
Expand Down Expand Up @@ -567,7 +567,9 @@ contract LpETH is
}

function claimWithdrawRequest(uint256 id) external returns (uint256 amount) {
amount = _loadStorageSlot().withdrawQueue.claimRequest(id);
Data storage $ = _loadStorageSlot();
amount = $.withdrawQueue.claimRequest(id);
$.liabilities -= amount;
emit ClaimWithdrawRequest(id, msg.sender, amount);
}

Expand Down Expand Up @@ -650,6 +652,9 @@ contract LpETH is

UD60x18 gauge = getFeeGauge(asset);
// total fee = gauge x (baseFee * amount + nom/denom)
if ($.liabilities <= $.unlocking) {
return 0;
}
uint256 fee = BASE_FEE.mul(x).add(nom.div(denom)).mul(gauge).unwrap();
fee = fee >= amount ? amount : fee;
unchecked {
Expand Down

0 comments on commit e3e0136

Please sign in to comment.