Skip to content

Commit

Permalink
fix: add max number of supported markets allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
junkim012 committed May 11, 2024
1 parent 0f78d89 commit bc3ad91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vault/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy
error MarketsAndAllocationCapLengthMustBeEqual();
error IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength();
error InvalidFeePercentage();
error MaxSupportedMarketsReached();

event UpdateSupplyQueue(address indexed caller, IIonPool[] newSupplyQueue);
event UpdateWithdrawQueue(address indexed caller, IIonPool[] newWithdrawQueue);
Expand All @@ -69,6 +70,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy

IERC20 public immutable BASE_ASSET;

uint8 public constant MAX_SUPPORTED_MARKETS = 32;

EnumerableSet.AddressSet supportedMarkets;

IIonPool[] public supplyQueue;
Expand Down Expand Up @@ -167,6 +170,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy
}
}

if (supportedMarkets.length() > MAX_SUPPORTED_MARKETS) revert MaxSupportedMarketsReached();

updateSupplyQueue(newSupplyQueue);
updateWithdrawQueue(newWithdrawQueue);
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/concrete/vault/Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ contract VaultSetUpTest is VaultSharedSetup {

function test_Revert_AddSupportedMarkets_MarketAlreadySupported() public { }

function test_Revert_AddSupportedMarkets_MaxSupportedMarketsReached() public {
vault = new Vault(BASE_ASSET, FEE_RECIPIENT, ZERO_FEES, "Ion Vault Token", "IVT", INITIAL_DELAY, VAULT_ADMIN);

vm.startPrank(vault.defaultAdmin());
vault.grantRole(vault.OWNER_ROLE(), OWNER);
vault.grantRole(vault.ALLOCATOR_ROLE(), OWNER);
vm.stopPrank();

IIonPool[] memory markets = new IIonPool[](vault.MAX_SUPPORTED_MARKETS() + 1);
uint256[] memory allocationCaps = new uint256[](vault.MAX_SUPPORTED_MARKETS() + 1);

for (uint8 i = 0; i < vault.MAX_SUPPORTED_MARKETS() + 1; i++) {
markets[i] = deployIonPool(BASE_ASSET, WEETH, address(this));
allocationCaps[i] = 1 ether;
}

vm.startPrank(OWNER);
vm.expectRevert(Vault.MaxSupportedMarketsReached.selector);
vault.addSupportedMarkets(markets, allocationCaps, markets, markets);
vm.stopPrank();
}

function test_RemoveSingleSupportedMarket() public {
uint256[] memory allocationCaps = new uint256[](1);
allocationCaps[0] = 1e18;
Expand Down

0 comments on commit bc3ad91

Please sign in to comment.