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

AST-720, updated invalidstate errors #324

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/AstariaRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ contract AstariaRouter is
) public whenNotPaused returns (address) {
RouterStorage storage s = _loadRouterSlot();
if (s.minEpochLength > epochLength) {
revert IPublicVault.InvalidState(
IPublicVault.InvalidStates.EPOCH_TOO_LOW
revert IPublicVault.InvalidVaultState(
IPublicVault.InvalidVaultStates.EPOCH_TOO_LOW
);
}
if (s.maxEpochLength < epochLength) {
revert IPublicVault.InvalidState(
IPublicVault.InvalidStates.EPOCH_TOO_HIGH
revert IPublicVault.InvalidVaultState(
IPublicVault.InvalidVaultStates.EPOCH_TOO_HIGH
);
}

Expand Down
36 changes: 18 additions & 18 deletions src/LienToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
)
{
if (block.timestamp >= params.encumber.stack[params.position].point.end) {
revert InvalidState(InvalidStates.EXPIRED_LIEN);
revert InvalidLienState(InvalidLienStates.EXPIRED_LIEN);
}
LienStorage storage s = _loadLienStorageSlot();
if (!s.ASTARIA_ROUTER.isValidVault(msg.sender)) {
Expand Down Expand Up @@ -229,7 +229,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
if (
s.collateralStateHash[params.encumber.lien.collateralId] == ACTIVE_AUCTION
) {
revert InvalidState(InvalidStates.COLLATERAL_AUCTION);
revert InvalidLienState(InvalidLienStates.COLLATERAL_AUCTION);
}

if (params.encumber.lien.details.maxAmount < buyout) {
Expand Down Expand Up @@ -286,10 +286,10 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
uint256 i;
for (i; i < stack.length; ) {
if (block.timestamp >= stack[i].point.end) {
revert InvalidState(InvalidStates.EXPIRED_LIEN);
revert InvalidLienState(InvalidLienStates.EXPIRED_LIEN);
}
if (potentialDebt > stack[i].lien.details.maxPotentialDebt) {
revert InvalidState(InvalidStates.DEBT_LIMIT);
revert InvalidLienState(InvalidLienStates.DEBT_LIMIT);
}
potentialDebt += _getOwed(stack[i], stack[i].point.end);
unchecked {
Expand All @@ -301,7 +301,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
for (i; i > 0; ) {
potentialDebt += _getOwed(stack[i - 1], stack[i - 1].point.end);
if (potentialDebt > stack[i - 1].lien.details.liquidationInitialAsk) {
revert InvalidState(InvalidStates.INITIAL_ASK_EXCEEDED);
revert InvalidLienState(InvalidLienStates.INITIAL_ASK_EXCEEDED);
}
unchecked {
--i;
Expand Down Expand Up @@ -359,10 +359,10 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
LienStorage storage s = _loadLienStorageSlot();
bytes32 stateHash = s.collateralStateHash[collateralId];
if (stateHash == bytes32(0) && stack.length != 0) {
revert InvalidState(InvalidStates.EMPTY_STATE);
revert InvalidLienState(InvalidLienStates.EMPTY_STATE);
}
if (stateHash != bytes32(0) && keccak256(abi.encode(stack)) != stateHash) {
revert InvalidState(InvalidStates.INVALID_HASH);
revert InvalidLienState(InvalidLienStates.INVALID_HASH);
}
_;
}
Expand Down Expand Up @@ -450,10 +450,10 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
) public override(ERC721, IERC721) {
LienStorage storage s = _loadLienStorageSlot();
if (_isPublicVault(s, to)) {
revert InvalidState(InvalidStates.PUBLIC_VAULT_RECIPIENT);
revert InvalidLienState(InvalidLienStates.PUBLIC_VAULT_RECIPIENT);
}
if (s.lienMeta[id].atLiquidation) {
revert InvalidState(InvalidStates.COLLATERAL_AUCTION);
revert InvalidLienState(InvalidLienStates.COLLATERAL_AUCTION);
}
delete s.lienMeta[id].payee;
emit PayeeChanged(id, address(0));
Expand Down Expand Up @@ -500,22 +500,22 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
ILienToken.LienActionEncumber calldata params
) internal returns (uint256 newLienId, ILienToken.Stack memory newSlot) {
if (s.collateralStateHash[params.lien.collateralId] == ACTIVE_AUCTION) {
revert InvalidState(InvalidStates.COLLATERAL_AUCTION);
revert InvalidLienState(InvalidLienStates.COLLATERAL_AUCTION);
}
if (
params.lien.details.liquidationInitialAsk < params.amount ||
params.lien.details.liquidationInitialAsk == 0
) {
revert InvalidState(InvalidStates.INVALID_LIQUIDATION_INITIAL_ASK);
revert InvalidLienState(InvalidLienStates.INVALID_LIQUIDATION_INITIAL_ASK);
}

if (params.stack.length > 0) {
if (params.lien.collateralId != params.stack[0].lien.collateralId) {
revert InvalidState(InvalidStates.COLLATERAL_MISMATCH);
revert InvalidLienState(InvalidLienStates.COLLATERAL_MISMATCH);
}

if (params.lien.token != params.stack[0].lien.token) {
revert InvalidState(InvalidStates.ASSET_MISMATCH);
revert InvalidLienState(InvalidLienStates.ASSET_MISMATCH);
}
}

Expand All @@ -536,7 +536,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
Stack memory newSlot
) internal returns (Stack[] memory newStack) {
if (stack.length >= s.maxLiens) {
revert InvalidState(InvalidStates.MAX_LIENS);
revert InvalidLienState(InvalidLienStates.MAX_LIENS);
}

newStack = new Stack[](stack.length + 1);
Expand Down Expand Up @@ -599,7 +599,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
) external view returns (address liquidator) {
liquidator = getAuctionData(collateralId).liquidator;
if (liquidator == address(0)) {
revert InvalidState(InvalidStates.COLLATERAL_NOT_LIQUIDATED);
revert InvalidLienState(InvalidLienStates.COLLATERAL_NOT_LIQUIDATED);
}
}

Expand All @@ -615,7 +615,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
function validateLien(Lien memory lien) public view returns (uint256 lienId) {
lienId = uint256(keccak256(abi.encode(lien)));
if (!_exists(lienId)) {
revert InvalidState(InvalidStates.INVALID_LIEN_ID);
revert InvalidLienState(InvalidLienStates.INVALID_LIEN_ID);
}
}

Expand Down Expand Up @@ -886,7 +886,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {
uint256 lienId = stack.point.lienId;

if (s.lienMeta[lienId].atLiquidation) {
revert InvalidState(InvalidStates.COLLATERAL_AUCTION);
revert InvalidLienState(InvalidLienStates.COLLATERAL_AUCTION);
}
uint64 end = stack.point.end;
// Blocking off payments for a lien that has exceeded the lien.end to prevent repayment unless the msg.sender() is the AuctionHouse
Expand Down Expand Up @@ -992,7 +992,7 @@ contract LienToken is ERC721, ILienToken, AuthInitializable, AmountDeriver {

function getPayee(uint256 lienId) public view returns (address) {
if (!_exists(lienId)) {
revert InvalidState(InvalidStates.INVALID_LIEN_ID);
revert InvalidLienState(InvalidLienStates.INVALID_LIEN_ID);
}
return _getPayee(_loadLienStorageSlot(), lienId);
}
Expand Down
10 changes: 5 additions & 5 deletions src/PublicVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
}

if (epoch < s.currentEpoch) {
revert InvalidState(InvalidStates.EPOCH_TOO_LOW);
revert InvalidVaultState(InvalidVaultStates.EPOCH_TOO_LOW);
}
require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS");
// check for rounding error since we round down in previewRedeem.
Expand Down Expand Up @@ -299,12 +299,12 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
function processEpoch() public {
// check to make sure epoch is over
if (timeToEpochEnd() > 0) {
revert InvalidState(InvalidStates.EPOCH_NOT_OVER);
revert InvalidVaultState(InvalidVaultStates.EPOCH_NOT_OVER);
}
VaultData storage s = _loadStorageSlot();

if (s.withdrawReserve > 0) {
revert InvalidState(InvalidStates.WITHDRAW_RESERVE_NOT_ZERO);
revert InvalidVaultState(InvalidVaultStates.WITHDRAW_RESERVE_NOT_ZERO);
}

WithdrawProxy currentWithdrawProxy = WithdrawProxy(
Expand All @@ -325,7 +325,7 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
}

if (s.epochData[s.currentEpoch].liensOpenForEpoch > 0) {
revert InvalidState(InvalidStates.LIENS_OPEN_FOR_EPOCH_NOT_ZERO);
revert InvalidVaultState(InvalidVaultStates.LIENS_OPEN_FOR_EPOCH_NOT_ZERO);
}

// reset liquidationWithdrawRatio to prepare for re calcualtion
Expand Down Expand Up @@ -606,7 +606,7 @@ contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
}
VIData storage v = _loadVISlot();
if (v.depositCap != 0 && totalAssets() >= v.depositCap) {
revert InvalidState(InvalidStates.DEPOSIT_CAP_EXCEEDED);
revert InvalidVaultState(InvalidVaultStates.DEPOSIT_CAP_EXCEEDED);
}
emit YInterceptChanged(s.yIntercept);
}
Expand Down
12 changes: 6 additions & 6 deletions src/WithdrawProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ contract WithdrawProxy is ERC4626Cloned, WithdrawVaultBase {
uint256 withdrawReserveReceived; // amount received from PublicVault. The WETH balance of this contract - withdrawReserveReceived = amount received from liquidations.
}

enum InvalidStates {
enum InvalidWithdrawStates {
PROCESS_EPOCH_NOT_COMPLETE,
FINAL_AUCTION_NOT_OVER,
NOT_CLAIMED,
CANT_CLAIM
}
error InvalidState(InvalidStates);
error InvalidWithdrawState(InvalidWithdrawStates);

function getState()
public
Expand Down Expand Up @@ -188,7 +188,7 @@ contract WithdrawProxy is ERC4626Cloned, WithdrawVaultBase {
// but the PublicVault hasn't claimed its share, too much money will be sent to LPs
if (s.finalAuctionEnd != 0) {
// if finalAuctionEnd is 0, no auctions were added
revert InvalidState(InvalidStates.NOT_CLAIMED);
revert InvalidWithdrawState(InvalidWithdrawStates.NOT_CLAIMED);
}
_;
}
Expand Down Expand Up @@ -271,14 +271,14 @@ contract WithdrawProxy is ERC4626Cloned, WithdrawVaultBase {
WPStorage storage s = _loadSlot();

if (s.finalAuctionEnd == 0) {
revert InvalidState(InvalidStates.CANT_CLAIM);
revert InvalidWithdrawState(InvalidWithdrawStates.CANT_CLAIM);
}

if (VAULT().getCurrentEpoch() < CLAIMABLE_EPOCH()) {
revert InvalidState(InvalidStates.PROCESS_EPOCH_NOT_COMPLETE);
revert InvalidWithdrawState(InvalidWithdrawStates.PROCESS_EPOCH_NOT_COMPLETE);
}
if (block.timestamp < s.finalAuctionEnd) {
revert InvalidState(InvalidStates.FINAL_AUCTION_NOT_OVER);
revert InvalidWithdrawState(InvalidWithdrawStates.FINAL_AUCTION_NOT_OVER);
}

uint256 transferAmount = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/ICollateralToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ interface ICollateralToken is IERC721 {
error InvalidZone();

enum InvalidCollateralStates {
NO_AUTHORITY,
NO_AUCTION,
FLASH_DISABLED,
AUCTION_ACTIVE,
INVALID_AUCTION_PARAMS,
ACTIVE_LIENS,
ESCROW_ACTIVE
NO_AUTHORITY, // 0
NO_AUCTION, // 1
FLASH_DISABLED, // 2
AUCTION_ACTIVE, // 3
INVALID_AUCTION_PARAMS, // 4
ACTIVE_LIENS, // 5
ESCROW_ACTIVE // 6
}

error FlashActionCallbackFailed();
Expand Down
38 changes: 19 additions & 19 deletions src/interfaces/ILienToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,25 @@ interface ILienToken is IERC721 {
error RefinanceBlocked();
error InvalidLoanState();
error InvalidSender();
enum InvalidStates {
NO_AUTHORITY,
COLLATERAL_MISMATCH,
ASSET_MISMATCH,
NOT_ENOUGH_FUNDS,
INVALID_LIEN_ID,
COLLATERAL_AUCTION,
COLLATERAL_NOT_DEPOSITED,
LIEN_NO_DEBT,
EXPIRED_LIEN,
DEBT_LIMIT,
MAX_LIENS,
INVALID_HASH,
INVALID_LIQUIDATION_INITIAL_ASK,
INITIAL_ASK_EXCEEDED,
EMPTY_STATE,
PUBLIC_VAULT_RECIPIENT,
COLLATERAL_NOT_LIQUIDATED
enum InvalidLienStates {
NO_AUTHORITY, // 0
COLLATERAL_MISMATCH, // 1
ASSET_MISMATCH, // 2
NOT_ENOUGH_FUNDS, // 3
INVALID_LIEN_ID, // 4
COLLATERAL_AUCTION, // 5
COLLATERAL_NOT_DEPOSITED, // 6
LIEN_NO_DEBT, // 7
EXPIRED_LIEN, // 8
DEBT_LIMIT, // 9
MAX_LIENS, // 10
INVALID_HASH, // 11
INVALID_LIQUIDATION_INITIAL_ASK, // 12
INITIAL_ASK_EXCEEDED, // 13
EMPTY_STATE, // 14
PUBLIC_VAULT_RECIPIENT, // 15
COLLATERAL_NOT_LIQUIDATED // 16
}

error InvalidState(InvalidStates);
error InvalidLienState(InvalidLienStates);
}
22 changes: 11 additions & 11 deletions src/interfaces/IPublicVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ interface IPublicVault is IVaultImplementation {

// ERRORS

error InvalidState(InvalidStates);

enum InvalidStates {
EPOCH_TOO_LOW,
EPOCH_TOO_HIGH,
EPOCH_NOT_OVER,
WITHDRAW_RESERVE_NOT_ZERO,
LIENS_OPEN_FOR_EPOCH_NOT_ZERO,
LIQUIDATION_ACCOUNTANT_FINAL_AUCTION_OPEN,
LIQUIDATION_ACCOUNTANT_ALREADY_DEPLOYED_FOR_EPOCH,
DEPOSIT_CAP_EXCEEDED
error InvalidVaultState(InvalidVaultStates);

enum InvalidVaultStates {
EPOCH_TOO_LOW, // 0
EPOCH_TOO_HIGH, // 1
EPOCH_NOT_OVER, // 2
WITHDRAW_RESERVE_NOT_ZERO, // 3
LIENS_OPEN_FOR_EPOCH_NOT_ZERO, // 4
LIQUIDATION_ACCOUNTANT_FINAL_AUCTION_OPEN, // 5
LIQUIDATION_ACCOUNTANT_ALREADY_DEPLOYED_FOR_EPOCH, // 6
DEPOSIT_CAP_EXCEEDED // 7
}

event StrategistFee(uint256 feeInShares);
Expand Down
24 changes: 12 additions & 12 deletions src/interfaces/IVaultImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import {IERC165} from "core/interfaces/IERC165.sol";

interface IVaultImplementation is IAstariaVaultBase, IERC165 {
enum InvalidRequestReason {
NO_AUTHORITY,
OPERATOR_NO_CODE,
INVALID_VAULT,
INVALID_SIGNATURE,
INVALID_COMMITMENT,
INVALID_AMOUNT,
INSUFFICIENT_FUNDS,
INVALID_RATE,
INVALID_POTENTIAL_DEBT,
SHUTDOWN,
PAUSED,
EXPIRED
NO_AUTHORITY, // 0
OPERATOR_NO_CODE, // 1
INVALID_VAULT, // 2
INVALID_SIGNATURE, // 3
INVALID_COMMITMENT, // 4
INVALID_AMOUNT, // 5
INSUFFICIENT_FUNDS, // 6
INVALID_RATE, // 7
INVALID_POTENTIAL_DEBT, // 8
SHUTDOWN, // 9
PAUSED, // 10
EXPIRED // 11
}

error InvalidRequest(InvalidRequestReason reason);
Expand Down
4 changes: 2 additions & 2 deletions src/test/AstariaTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ contract AstariaTest is TestHelpers {
isFirstLien: false,
stack: stack,
revertMessage: abi.encodeWithSelector(
ILienToken.InvalidState.selector,
ILienToken.InvalidStates.EMPTY_STATE
ILienToken.InvalidLienState.selector,
ILienToken.InvalidLienStates.EMPTY_STATE
)
});
}
Expand Down
Loading