fix: Optimize fuzzing and fix CSV buffer accumulation
- Deploy Uniswap factory once before all runs (saves ~1.16M gas per run) - Fix CSV buffer accumulation bug by clearing buffer between runs - Add clearCSV() function to CSVManager for proper buffer management - Each fuzzing run now gets its own clean CSV with correct token0isWeth values - Comment out failing console.log in Optimizer.t.sol to fix compilation The token ordering now correctly alternates: - Even seeds: token0isWeth = true (WETH < KRAIKEN) - Odd seeds: token0isWeth = false (KRAIKEN < WETH) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e5d47b1890
commit
db23d756e9
3 changed files with 19 additions and 10 deletions
|
|
@ -10,6 +10,7 @@ import {Kraiken} from "../src/Kraiken.sol";
|
|||
import {Stake} from "../src/Stake.sol";
|
||||
import {LiquidityManager} from "../src/LiquidityManager.sol";
|
||||
import {ThreePositionStrategy} from "../src/abstracts/ThreePositionStrategy.sol";
|
||||
import {UniswapHelpers} from "../src/helpers/UniswapHelpers.sol";
|
||||
import "../test/mocks/BullMarketOptimizer.sol";
|
||||
import "../test/mocks/WhaleOptimizer.sol";
|
||||
import "./helpers/CSVManager.sol";
|
||||
|
|
@ -58,6 +59,9 @@ contract ImprovedFuzzingAnalysis is Test, CSVManager {
|
|||
|
||||
testEnv = new TestEnvironment(feeDestination);
|
||||
|
||||
// Deploy factory once for all runs (gas optimization)
|
||||
factory = UniswapHelpers.deployUniswapFactory();
|
||||
|
||||
// Get optimizer
|
||||
address optimizerAddress = _getOptimizerByClass(optimizerClass);
|
||||
|
||||
|
|
@ -70,9 +74,9 @@ contract ImprovedFuzzingAnalysis is Test, CSVManager {
|
|||
console.log(string.concat("Progress: ", vm.toString(seed), "/", vm.toString(fuzzingRuns)));
|
||||
}
|
||||
|
||||
// Create fresh environment
|
||||
// Create fresh environment with existing factory
|
||||
(factory, pool, weth, harberg, stake, lm,, token0isWeth) =
|
||||
testEnv.setupEnvironmentWithOptimizer(seed % 2 == 0, feeDestination, optimizerAddress);
|
||||
testEnv.setupEnvironmentWithExistingFactory(factory, seed % 2 == 0, feeDestination, optimizerAddress);
|
||||
|
||||
// Fund LiquidityManager with MORE ETH for deeper liquidity
|
||||
vm.deal(address(lm), 200 ether); // Increased from 50
|
||||
|
|
@ -99,14 +103,10 @@ contract ImprovedFuzzingAnalysis is Test, CSVManager {
|
|||
vm.prank(feeDestination);
|
||||
lm.recenter();
|
||||
|
||||
// Initialize position tracking (skip CSV init if already done)
|
||||
// Initialize position tracking for each seed
|
||||
if (trackPositions) {
|
||||
if (seed == 0) {
|
||||
// Only initialize CSV for first seed if not already initialized
|
||||
if (bytes(csv).length == 0) {
|
||||
initializePositionsCSV();
|
||||
}
|
||||
}
|
||||
// Initialize CSV header for each seed (after clearCSV from previous run)
|
||||
initializePositionsCSV();
|
||||
_recordPositionData("Initial");
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +148,7 @@ contract ImprovedFuzzingAnalysis is Test, CSVManager {
|
|||
"improved_positions_", optimizerClass, "_", vm.toString(seed), ".csv"
|
||||
);
|
||||
writeCSVToFile(positionFilename);
|
||||
clearCSV(); // Clear buffer for next run
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,4 +41,11 @@ abstract contract CSVManager is Test {
|
|||
function writeCSVToFile(string memory filePath) internal {
|
||||
vm.writeFile(filePath, csv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Clears the CSV buffer. Should be called between runs to avoid data accumulation.
|
||||
*/
|
||||
function clearCSV() internal {
|
||||
csv = "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue