2025-08-23 22:32:41 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
|
|
2026-02-04 20:58:30 +00:00
|
|
|
import { Optimizer } from "../src/Optimizer.sol";
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
import { OptimizerV2 } from "../src/OptimizerV2.sol";
|
2026-02-04 20:58:30 +00:00
|
|
|
import { ThreePositionStrategy } from "../src/abstracts/ThreePositionStrategy.sol";
|
|
|
|
|
|
|
|
|
|
import { BearMarketOptimizer } from "../test/mocks/BearMarketOptimizer.sol";
|
|
|
|
|
import { BullMarketOptimizer } from "../test/mocks/BullMarketOptimizer.sol";
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
import { ConfigurableOptimizer } from "../test/mocks/ConfigurableOptimizer.sol";
|
2026-02-04 20:58:30 +00:00
|
|
|
|
|
|
|
|
import { ExtremeOptimizer } from "../test/mocks/ExtremeOptimizer.sol";
|
|
|
|
|
import { MaliciousOptimizer } from "../test/mocks/MaliciousOptimizer.sol";
|
|
|
|
|
import { NeutralMarketOptimizer } from "../test/mocks/NeutralMarketOptimizer.sol";
|
|
|
|
|
import { WhaleOptimizer } from "../test/mocks/WhaleOptimizer.sol";
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
import { FuzzingBase } from "./helpers/FuzzingBase.sol";
|
2025-09-16 22:46:43 +02:00
|
|
|
import "forge-std/console2.sol";
|
2025-08-23 22:32:41 +02:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
/// @title StreamlinedFuzzing
|
|
|
|
|
/// @notice Per-run CSV fuzzer: deploys a named optimizer, runs N randomized
|
|
|
|
|
/// trade sequences, and writes one CSV per run with full position snapshots.
|
|
|
|
|
/// Supports ConfigurableOptimizer (env-driven params), uncapped swaps,
|
|
|
|
|
/// and random stake/unstake actions interleaved with trades.
|
|
|
|
|
contract StreamlinedFuzzing is FuzzingBase {
|
2025-08-23 22:32:41 +02:00
|
|
|
// CSV filename for current run
|
|
|
|
|
string csvFilename;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
// Track cumulative fees
|
|
|
|
|
uint256 totalFees0;
|
|
|
|
|
uint256 totalFees1;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
// Track recentering
|
|
|
|
|
uint256 lastRecenterBlock;
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
uint256 recenterCount;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Staking position tracking (max 10 active positions per run)
|
|
|
|
|
uint256[10] activePositions;
|
|
|
|
|
uint256 numActivePositions;
|
|
|
|
|
|
|
|
|
|
// Batch seed for multi-batch uniqueness
|
|
|
|
|
uint256 bSeed;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
function run() public {
|
|
|
|
|
uint256 numRuns = vm.envOr("FUZZING_RUNS", uint256(20));
|
|
|
|
|
uint256 tradesPerRun = vm.envOr("TRADES_PER_RUN", uint256(15));
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
uint256 buyBias = vm.envOr("BUY_BIAS", uint256(50));
|
2025-08-23 22:32:41 +02:00
|
|
|
string memory optimizerClass = vm.envOr("OPTIMIZER_CLASS", string("BullMarketOptimizer"));
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
bool uncapped = vm.envOr("UNCAPPED_SWAPS", false);
|
|
|
|
|
bSeed = vm.envOr("BATCH_SEED", uint256(0));
|
|
|
|
|
uint256 bgLpEthPerLayer = vm.envOr("BG_LP_ETH_PER_LAYER", uint256(0));
|
|
|
|
|
uint256 stakingLevel = vm.envOr("STAKING_LEVEL", uint256(0)); // 0-100%
|
|
|
|
|
uint256 stakingTaxRate = vm.envOr("STAKING_TAX_RATE", uint256(3)); // tax rate index 0-29
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-09-16 22:46:43 +02:00
|
|
|
console2.log("=== Streamlined Fuzzing Analysis ===");
|
|
|
|
|
console2.log("Optimizer:", optimizerClass);
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
console2.log("Uncapped:", uncapped);
|
|
|
|
|
if (bgLpEthPerLayer > 0) {
|
|
|
|
|
console2.log("Background LP: ", bgLpEthPerLayer / 1e18, "ETH/layer x5");
|
|
|
|
|
}
|
|
|
|
|
if (stakingLevel > 0) {
|
|
|
|
|
console2.log("Staking level: ", stakingLevel, "% at tax rate index", stakingTaxRate);
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
_initInfrastructure();
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
string memory scenarioCode = _generateScenarioId(bSeed);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
for (uint256 runIndex = 0; runIndex < numRuns; runIndex++) {
|
|
|
|
|
string memory runId = string(abi.encodePacked(scenarioCode, "-", _padNumber(runIndex, 3)));
|
2025-09-16 22:46:43 +02:00
|
|
|
console2.log("\nRun:", runId);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
csvFilename = string(abi.encodePacked("analysis/fuzz-", runId, ".csv"));
|
2026-02-04 20:58:30 +00:00
|
|
|
string memory header =
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
"action,amount,tick,floor_lower,floor_upper,floor_liq,anchor_lower,anchor_upper,anchor_liq,discovery_lower,discovery_upper,discovery_liq,eth_balance,kraiken_balance,vwap,fees_eth,fees_kraiken,recenter,fee_dest_weth,fee_dest_krk\n";
|
2025-08-23 22:32:41 +02:00
|
|
|
vm.writeFile(csvFilename, header);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Deploy fresh environment per run
|
|
|
|
|
address optimizer = _deployOptimizer(optimizerClass);
|
|
|
|
|
_setupEnvironment(optimizer, runIndex % 2 == 0, uncapped);
|
|
|
|
|
|
|
|
|
|
// Late-initialize OptimizerV2 (needs stake address from setup)
|
|
|
|
|
if (keccak256(bytes(optimizerClass)) == keccak256(bytes("OptimizerV2"))) {
|
|
|
|
|
OptimizerV2(optimizer).initialize(address(kraiken), address(stake));
|
|
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Deploy background LP if configured
|
|
|
|
|
if (bgLpEthPerLayer > 0) {
|
|
|
|
|
_deployBackgroundLP(bgLpEthPerLayer);
|
2026-02-04 20:58:30 +00:00
|
|
|
}
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
|
|
|
|
|
// Pre-seed staking to set initial sentiment
|
|
|
|
|
if (stakingLevel > 0) {
|
|
|
|
|
_seedStaking(stakingLevel, uint32(stakingTaxRate));
|
2026-02-04 20:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Reset tracking
|
|
|
|
|
totalFees0 = 0;
|
|
|
|
|
totalFees1 = 0;
|
|
|
|
|
lastRecenterBlock = block.number;
|
|
|
|
|
recenterCount = 0;
|
|
|
|
|
numActivePositions = 0;
|
|
|
|
|
|
|
|
|
|
// Fund trader
|
|
|
|
|
uint256 traderFund = 500 ether + (uint256(keccak256(abi.encodePacked(bSeed, runIndex, "trader"))) % 500 ether);
|
|
|
|
|
vm.deal(trader, traderFund * 2);
|
2025-08-23 22:32:41 +02:00
|
|
|
vm.prank(trader);
|
2026-02-04 20:58:30 +00:00
|
|
|
weth.deposit{ value: traderFund }();
|
|
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
_recordState("INIT", 0);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
for (uint256 i = 0; i < tradesPerRun; i++) {
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Recenter on average every 3 trades
|
|
|
|
|
uint256 recenterRand = uint256(keccak256(abi.encodePacked(bSeed, runIndex, i, "recenter"))) % 3;
|
2025-08-24 18:38:48 +02:00
|
|
|
if (recenterRand == 0) {
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
if (_tryRecenter()) {
|
|
|
|
|
lastRecenterBlock = block.number;
|
|
|
|
|
recenterCount++;
|
|
|
|
|
// Rebalance background LP every 10 recenters to track market
|
|
|
|
|
// (every recenter is too expensive for 2000-trade runs)
|
|
|
|
|
if (bgLpEthPerLayer > 0 && recenterCount % 10 == 0) {
|
|
|
|
|
_rebalanceBackgroundLP(bgLpEthPerLayer);
|
|
|
|
|
}
|
|
|
|
|
_recordState("RECENTER", 0);
|
|
|
|
|
}
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// 10% chance of staking action instead of trade
|
|
|
|
|
uint256 stakeRand = uint256(keccak256(abi.encodePacked(bSeed, runIndex, i, "stake"))) % 100;
|
|
|
|
|
if (stakeRand < 10) {
|
|
|
|
|
_runStakingAction(runIndex, i);
|
|
|
|
|
continue;
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
uint256 rand = uint256(keccak256(abi.encodePacked(bSeed, runIndex, i))) % 100;
|
|
|
|
|
if (rand < buyBias) {
|
|
|
|
|
_runBuy(runIndex, i);
|
|
|
|
|
} else {
|
|
|
|
|
_runSell(runIndex, i);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Exit all staking positions before liquidation
|
|
|
|
|
_exitAllPositions();
|
|
|
|
|
|
2025-09-16 22:46:43 +02:00
|
|
|
_liquidateTraderHoldings();
|
2025-08-23 22:32:41 +02:00
|
|
|
_recordState("FINAL", 0);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Log fee revenue
|
|
|
|
|
(uint256 feeWeth, uint256 feeKrk) = _getFeeRevenue();
|
|
|
|
|
console2.log("Fee revenue: WETH=", feeWeth / 1e18, "KRK=", feeKrk / 1e18);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
|
|
|
|
|
console2.log("\n=== Analysis Complete ===");
|
|
|
|
|
console2.log("Generated", numRuns, "CSV files with prefix:", scenarioCode);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _runBuy(uint256 runIndex, uint256 tradeIndex) internal {
|
|
|
|
|
uint256 amount = _getTradeAmount(runIndex, tradeIndex, true);
|
|
|
|
|
if (_executeBuy(amount)) {
|
|
|
|
|
_recordState("BUY", amount);
|
2026-02-04 20:58:30 +00:00
|
|
|
} else {
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
_recordState("BUY_FAIL", amount);
|
2026-02-04 20:58:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _runSell(uint256 runIndex, uint256 tradeIndex) internal {
|
|
|
|
|
uint256 amount = _getTradeAmount(runIndex, tradeIndex, false);
|
|
|
|
|
if (_executeSell(amount)) {
|
|
|
|
|
_recordState("SELL", amount);
|
|
|
|
|
} else {
|
|
|
|
|
_recordState("SELL_FAIL", amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _getTradeAmount(uint256 runIndex, uint256 tradeIndex, bool isBuy) internal view returns (uint256) {
|
|
|
|
|
uint256 baseAmount = 10 ether + (uint256(keccak256(abi.encodePacked(bSeed, runIndex, tradeIndex))) % 90 ether);
|
|
|
|
|
return isBuy ? baseAmount : baseAmount * 1000;
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// ── Staking Actions ──────────────────────────────────────────────────
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _runStakingAction(uint256 runIndex, uint256 tradeIndex) internal {
|
|
|
|
|
// If we have active positions, 50/50 stake vs unstake; otherwise always stake
|
|
|
|
|
bool doStake = numActivePositions == 0 || uint256(keccak256(abi.encodePacked(bSeed, runIndex, tradeIndex, "stakeOrUnstake"))) % 2 == 0;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
if (doStake) {
|
|
|
|
|
_tryStake(runIndex, tradeIndex);
|
|
|
|
|
} else {
|
|
|
|
|
_tryUnstake(runIndex, tradeIndex);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _tryStake(uint256 runIndex, uint256 tradeIndex) internal {
|
|
|
|
|
uint256 krkBalance = kraiken.balanceOf(trader);
|
|
|
|
|
if (krkBalance == 0 || numActivePositions >= 10) {
|
|
|
|
|
_recordState("STAKE_SKIP", 0);
|
|
|
|
|
return;
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Stake 5-20% of KRK holdings
|
|
|
|
|
uint256 pct = 5 + (uint256(keccak256(abi.encodePacked(bSeed, runIndex, tradeIndex, "stakePct"))) % 16);
|
|
|
|
|
uint256 stakeAmount = krkBalance * pct / 100;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Check minimum stake
|
|
|
|
|
try kraiken.minStake() returns (uint256 minStake) {
|
|
|
|
|
if (stakeAmount < minStake) stakeAmount = minStake;
|
|
|
|
|
if (stakeAmount > krkBalance) {
|
|
|
|
|
_recordState("STAKE_SKIP", 0);
|
|
|
|
|
return;
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
} catch {
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
_recordState("STAKE_SKIP", 0);
|
|
|
|
|
return;
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Random tax rate index (0-29), bias toward low rates
|
|
|
|
|
uint32 taxRate = uint32(uint256(keccak256(abi.encodePacked(bSeed, runIndex, tradeIndex, "taxRate"))) % 10);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
vm.startPrank(trader);
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
kraiken.approve(address(stake), stakeAmount);
|
|
|
|
|
uint256[] memory empty = new uint256[](0);
|
|
|
|
|
try stake.snatch(stakeAmount, trader, taxRate, empty) returns (uint256 positionId) {
|
|
|
|
|
vm.stopPrank();
|
|
|
|
|
activePositions[numActivePositions] = positionId;
|
|
|
|
|
numActivePositions++;
|
|
|
|
|
_recordState("STAKE", stakeAmount);
|
2025-08-23 22:32:41 +02:00
|
|
|
} catch {
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
vm.stopPrank();
|
|
|
|
|
_recordState("STAKE_FAIL", stakeAmount);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _tryUnstake(uint256 runIndex, uint256 tradeIndex) internal {
|
|
|
|
|
if (numActivePositions == 0) return;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Pick a random position to exit
|
|
|
|
|
uint256 idx = uint256(keccak256(abi.encodePacked(bSeed, runIndex, tradeIndex, "unstakeIdx"))) % numActivePositions;
|
|
|
|
|
uint256 positionId = activePositions[idx];
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Advance time so we pass the 3-day tax floor
|
|
|
|
|
vm.warp(block.timestamp + 4 days);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
vm.prank(trader);
|
|
|
|
|
try stake.exitPosition(positionId) {
|
|
|
|
|
// Remove from tracking by swapping with last
|
|
|
|
|
activePositions[idx] = activePositions[numActivePositions - 1];
|
|
|
|
|
numActivePositions--;
|
|
|
|
|
_recordState("UNSTAKE", positionId);
|
|
|
|
|
} catch {
|
|
|
|
|
_recordState("UNSTAKE_FAIL", positionId);
|
2026-02-04 20:58:30 +00:00
|
|
|
}
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _exitAllPositions() internal {
|
|
|
|
|
for (uint256 i = 0; i < numActivePositions; i++) {
|
|
|
|
|
vm.warp(block.timestamp + 4 days);
|
|
|
|
|
vm.prank(trader);
|
|
|
|
|
try stake.exitPosition(activePositions[i]) { } catch { }
|
|
|
|
|
}
|
|
|
|
|
numActivePositions = 0;
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _generateScenarioId(uint256 seed) internal view returns (string memory) {
|
|
|
|
|
uint256 rand = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, seed)));
|
|
|
|
|
bytes memory chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
|
bytes memory result = new bytes(4);
|
|
|
|
|
for (uint256 i = 0; i < 4; i++) {
|
|
|
|
|
result[i] = chars[rand % chars.length];
|
|
|
|
|
rand = rand / chars.length;
|
|
|
|
|
}
|
|
|
|
|
return string(result);
|
|
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// ── Optimizer Deployment ─────────────────────────────────────────────
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
function _deployOptimizer(string memory optimizerClass) internal returns (address) {
|
|
|
|
|
if (keccak256(bytes(optimizerClass)) == keccak256(bytes("ConfigurableOptimizer"))) {
|
|
|
|
|
uint256 ci = vm.envOr("CI_VALUE", uint256(0));
|
|
|
|
|
uint256 as_ = vm.envOr("AS_VALUE", uint256(100_000_000_000_000_000));
|
|
|
|
|
uint256 aw = vm.envOr("AW_VALUE", uint256(20));
|
|
|
|
|
uint256 dd = vm.envOr("DD_VALUE", uint256(500_000_000_000_000_000));
|
|
|
|
|
return address(new ConfigurableOptimizer(ci, as_, uint24(aw > 100 ? 100 : aw), dd));
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("BullMarketOptimizer"))) {
|
|
|
|
|
return address(new BullMarketOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("BearMarketOptimizer"))) {
|
|
|
|
|
return address(new BearMarketOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("NeutralMarketOptimizer"))) {
|
|
|
|
|
return address(new NeutralMarketOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("WhaleOptimizer"))) {
|
|
|
|
|
return address(new WhaleOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("ExtremeOptimizer"))) {
|
|
|
|
|
return address(new ExtremeOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("MaliciousOptimizer"))) {
|
|
|
|
|
return address(new MaliciousOptimizer());
|
|
|
|
|
} else if (keccak256(bytes(optimizerClass)) == keccak256(bytes("OptimizerV2"))) {
|
|
|
|
|
// Deploy uninitialized — will be initialized after _setupEnvironment
|
|
|
|
|
// when stake address is available
|
|
|
|
|
return address(new OptimizerV2());
|
|
|
|
|
} else {
|
|
|
|
|
return address(new BullMarketOptimizer());
|
2025-09-16 22:46:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// ── CSV Recording ─────────────────────────────────────────────────────
|
|
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
function _recordState(string memory action, uint256 amount) internal {
|
|
|
|
|
string memory row = _buildRowPart1(action, amount);
|
|
|
|
|
row = string(abi.encodePacked(row, _buildRowPart2()));
|
|
|
|
|
row = string(abi.encodePacked(row, _buildRowPart3()));
|
|
|
|
|
vm.writeLine(csvFilename, row);
|
|
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
function _buildRowPart1(string memory action, uint256 amount) internal view returns (string memory) {
|
|
|
|
|
(, int24 tick,,,,,) = pool.slot0();
|
|
|
|
|
(uint128 floorLiq, int24 floorLower, int24 floorUpper) = lm.positions(ThreePositionStrategy.Stage.FLOOR);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
|
|
|
|
return string(
|
|
|
|
|
abi.encodePacked(
|
|
|
|
|
action,
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(amount),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(tick),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(floorLower),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(floorUpper),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(uint256(floorLiq)),
|
|
|
|
|
","
|
|
|
|
|
)
|
|
|
|
|
);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
function _buildRowPart2() internal view returns (string memory) {
|
|
|
|
|
(uint128 anchorLiq, int24 anchorLower, int24 anchorUpper) = lm.positions(ThreePositionStrategy.Stage.ANCHOR);
|
|
|
|
|
(uint128 discoveryLiq, int24 discoveryLower, int24 discoveryUpper) = lm.positions(ThreePositionStrategy.Stage.DISCOVERY);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
|
|
|
|
return string(
|
|
|
|
|
abi.encodePacked(
|
|
|
|
|
vm.toString(anchorLower),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(anchorUpper),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(uint256(anchorLiq)),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(discoveryLower),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(discoveryUpper),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(uint256(discoveryLiq)),
|
|
|
|
|
","
|
|
|
|
|
)
|
|
|
|
|
);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
function _buildRowPart3() internal view returns (string memory) {
|
|
|
|
|
uint256 ethBalance = weth.balanceOf(trader);
|
|
|
|
|
uint256 kraikenBalance = kraiken.balanceOf(trader);
|
2026-02-04 20:58:30 +00:00
|
|
|
|
2025-08-23 22:32:41 +02:00
|
|
|
(uint128 fees0, uint128 fees1) = pool.protocolFees();
|
|
|
|
|
uint256 deltaFees0 = fees0 > totalFees0 ? fees0 - totalFees0 : 0;
|
|
|
|
|
uint256 deltaFees1 = fees1 > totalFees1 ? fees1 - totalFees1 : 0;
|
2026-02-04 20:58:30 +00:00
|
|
|
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
// Fee destination balances (LM fee revenue)
|
|
|
|
|
(uint256 feeDestWeth, uint256 feeDestKrk) = _getFeeRevenue();
|
|
|
|
|
|
2026-02-04 20:58:30 +00:00
|
|
|
return string(
|
|
|
|
|
abi.encodePacked(
|
chore: analysis tooling, research artifacts, and code quality
- Analysis: parameter sweep scripts, adversarial testing, 2D frontier maps
- Research: KRAIKEN_RESEARCH_REPORT, SECURITY_REVIEW, STORAGE_LAYOUT
- FuzzingBase: consolidated fuzzing helper, BackgroundLP simulation
- Sweep results: CSV data for full 4D sweep (1050 combos), bull-bear,
AS sweep, VWAP fix validation
- Code quality: .gitignore for fuzz CSVs, gas snapshot, updated docs
- Remove dead analysis helpers (CSVHelper, CSVManager, ScenarioRecorder)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:22:03 +00:00
|
|
|
vm.toString(ethBalance),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(kraikenBalance),
|
|
|
|
|
",",
|
|
|
|
|
"0,",
|
|
|
|
|
vm.toString(deltaFees0),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(deltaFees1),
|
|
|
|
|
",",
|
|
|
|
|
"0,",
|
|
|
|
|
vm.toString(feeDestWeth),
|
|
|
|
|
",",
|
|
|
|
|
vm.toString(feeDestKrk)
|
2026-02-04 20:58:30 +00:00
|
|
|
)
|
|
|
|
|
);
|
2025-08-23 22:32:41 +02:00
|
|
|
}
|
2025-09-16 22:46:43 +02:00
|
|
|
}
|