Skip to content

Commit 4882d30

Browse files
Merge pull request #222 from lista-dao/chore/increase-max-supply-queue-length
chore(moolah-vault): increase MAX_QUEUE_LENGTH from 100 to 1000
2 parents 9940a55 + ba75a70 commit 4882d30

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

src/moolah-vault/libraries/ConstantsLib.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ library ConstantsLib {
1212
uint256 internal constant MIN_TIMELOCK = 1 days;
1313

1414
/// @dev The maximum number of markets in the supply/withdraw queue.
15-
uint256 internal constant MAX_QUEUE_LENGTH = 100;
15+
/// @dev Capped at 600 so a full-length setSupplyQueue (one cold SSTORE plus a validation SLOAD
16+
/// per element, ~24.9k gas) stays under the BEP-652 per-transaction gas limit (16,777,216).
17+
uint256 internal constant MAX_QUEUE_LENGTH = 600;
1618

1719
/// @dev The maximum fee the vault can have (50%).
1820
uint256 internal constant MAX_FEE = 0.5e18;

test/moolah-vault/MarketTest.sol

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,38 @@ contract MarketTest is IntegrationTest {
121121
}
122122

123123
function testAcceptCapMaxQueueLengthExceeded() public {
124-
for (uint256 i = 3; i < ConstantsLib.MAX_QUEUE_LENGTH - 1; ++i) {
125-
_setCap(allMarkets[i], CAP);
124+
// Fill the withdraw queue up to MAX_QUEUE_LENGTH by enabling fresh markets.
125+
// setUp already enabled some markets (idle + markets 0..2), so top up the remainder.
126+
uint256 toFill = ConstantsLib.MAX_QUEUE_LENGTH - vault.withdrawQueueLength();
127+
for (uint256 i; i < toFill; ++i) {
128+
MarketParams memory mp = _createFreshMarket(i);
129+
vm.prank(CURATOR_ADDR);
130+
vault.setCap(mp, CAP);
126131
}
132+
assertEq(vault.withdrawQueueLength(), ConstantsLib.MAX_QUEUE_LENGTH);
127133

128-
MarketParams memory marketParams = allMarkets[ConstantsLib.MAX_QUEUE_LENGTH];
129-
130-
vm.startPrank(CURATOR_ADDR);
134+
// Enabling one more market pushes the withdraw queue past the max.
135+
MarketParams memory extra = _createFreshMarket(toFill);
136+
vm.prank(CURATOR_ADDR);
131137
vm.expectRevert(ErrorsLib.MaxQueueLengthExceeded.selector);
132-
vault.setCap(marketParams, CAP);
138+
vault.setCap(extra, CAP);
139+
}
140+
141+
/// @dev Creates and enables a fresh Moolah market with a unique, low lltv that cannot
142+
/// collide with the markets created in setUp (lltv = 0.8e18 / (i + 1)).
143+
function _createFreshMarket(uint256 salt) internal returns (MarketParams memory mp) {
144+
uint256 lltv = salt + 1;
145+
mp = MarketParams({
146+
loanToken: address(loanToken),
147+
collateralToken: address(collateralToken),
148+
oracle: address(oracle),
149+
irm: address(irm),
150+
lltv: lltv
151+
});
152+
153+
vm.startPrank(MOOLAH_OWNER);
154+
moolah.enableLltv(lltv);
155+
moolah.createMarket(mp);
133156
vm.stopPrank();
134157
}
135158

test/moolah-vault/helpers/BaseTest.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ uint256 constant BLOCK_TIME = 1;
3131
uint256 constant MIN_TEST_ASSETS = 1e8;
3232
uint256 constant MAX_TEST_ASSETS = 1e28;
3333
uint184 constant CAP = type(uint128).max;
34-
uint256 constant NB_MARKETS = ConstantsLib.MAX_QUEUE_LENGTH + 1;
34+
// Number of markets created in setUp. Kept fixed (and independent of
35+
// ConstantsLib.MAX_QUEUE_LENGTH) so the shared setUp stays cheap; the max-queue-length
36+
// boundary is exercised by dedicated tests that create markets on demand.
37+
uint256 constant NB_MARKETS = 100;
3538

3639
contract BaseTest is Test {
3740
using MathLib for uint256;

0 commit comments

Comments
 (0)