diff --git a/src/LienToken.sol b/src/LienToken.sol index 3e3b88b5..74c02e78 100644 --- a/src/LienToken.sol +++ b/src/LienToken.sol @@ -276,9 +276,7 @@ contract LienToken is ERC721, ILienToken, Auth { s.lienMeta[stack[i].point.lienId].amountAtLiquidation = owed; } if ( - IPublicVault(_getPayee(s, lienIds[i])).supportsInterface( - type(IPublicVault).interfaceId - ) + s.ASTARIA_ROUTER.isValidVault(_getPayee(s, lienIds[i])) ) { // update the public vault state and get the liquidation accountant back if any address withdrawProxyIfNearBoundary = IPublicVault(_getPayee(s, lienIds[i])) @@ -395,11 +393,11 @@ contract LienToken is ERC721, ILienToken, Auth { { LienStorage storage s = _loadLienStorageSlot(); for (uint256 i = 0; i < remainingLiens.length; i++) { - address owner = ownerOf(remainingLiens[i]); + address payee = _getPayee(s, remainingLiens[i]); if ( - IPublicVault(owner).supportsInterface(type(IPublicVault).interfaceId) + s.ASTARIA_ROUTER.isValidVault(payee) ) { - IPublicVault(owner).decreaseYIntercept( + IPublicVault(payee).decreaseYIntercept( s.lienMeta[remainingLiens[i]].amountAtLiquidation ); } diff --git a/src/test/WithdrawTesting.t.sol b/src/test/WithdrawTesting.t.sol index 3ff68fa5..43287cfe 100644 --- a/src/test/WithdrawTesting.t.sol +++ b/src/test/WithdrawTesting.t.sol @@ -797,4 +797,59 @@ contract WithdrawTest is TestHelpers { "PublicVault balance should be 0" ); } + + function testLiquidationNearBoundaryNoWithdraws() public { + TestNFT nft = new TestNFT(1); + address tokenContract = address(nft); + uint256 tokenId = uint256(0); + + // create a PublicVault with a 14-day epoch + address publicVault = _createPublicVault({ + strategist: strategistOne, + delegate: strategistTwo, + epochLength: 14 days + }); + + // lend 50 ether to the PublicVault as address(1) + _lendToVault( + Lender({addr: address(1), amountToLend: 50 ether}), + publicVault + ); + + ILienToken.Details memory details = standardLienDetails; + details.duration = 13 days; + + // borrow 10 eth against the dummy NFT + (, ILienToken.Stack[] memory stack) = _commitToLien({ + vault: publicVault, + strategist: strategistOne, + strategistPK: strategistOnePK, + tokenContract: tokenContract, + tokenId: tokenId, + lienDetails: details, + amount: 10 ether, + isFirstLien: true + }); + + vm.warp(block.timestamp + 13 days); + uint256 collateralId = tokenContract.computeId(tokenId); + assertEq(LIEN_TOKEN.getOwed(stack[0]), uint192(10534246575335200000), "Incorrect lien interest"); + ASTARIA_ROUTER.liquidate(collateralId, uint8(0), stack); + _bid(address(3), collateralId, 5 ether); + + _warpToEpochEnd(publicVault); + PublicVault(publicVault).processEpoch(); + + vm.warp(block.timestamp + 4 days); + AUCTION_HOUSE.endAuction(collateralId); + assertEq(address(this), COLLATERAL_TOKEN.ownerOf(collateralId), "liquidator did not receive NFT"); + + address withdrawProxy = PublicVault(publicVault).getWithdrawProxy(0); + WithdrawProxy(withdrawProxy).claim(); + + assertEq(WETH9.balanceOf(publicVault), 44350000000000000000, "Incorrect PublicVault balance"); + assertEq(PublicVault(publicVault).getYIntercept(), 44350000000000000000, "Incorrect PublicVault YIntercept"); + assertEq(PublicVault(publicVault).totalAssets(), 44350000000000000000, "Incorrect PublicVault totalAssets()"); + assertEq(PublicVault(publicVault).getSlope(), 0, "Incorrect PublicVault slope"); + } }