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

Commit

Permalink
add testLiquidationNearBoundaryNoWithdraws (#89)
Browse files Browse the repository at this point in the history
* add testLiquidationNearBoundaryNoWithdraws

* delete files

* Delete loanProofGenerator.js

* added 5 eth bid

* remove decreaseYIntercept in WithdrawProxy.claim()

* fix updateYIntercept

Co-authored-by: Joseph Delong <[email protected]>
  • Loading branch information
SantiagoGregory and dangerousfood authored Nov 9, 2022
1 parent 040d590 commit 8472b50
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/LienToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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
);
}
Expand Down
55 changes: 55 additions & 0 deletions src/test/WithdrawTesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 8472b50

Please sign in to comment.