{
 "delta": -2.055423523339817,
 "verdict": "NEGATIVE: true-price ceiling (pHat:=p of the current step, after the arb already moved the pool) is WORSE than NP2 even after joint retune; no oracle headroom found with this mechanism. Not submittable (needs simulator oracle).",
 "code": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {AMMStrategyBase} from \"./AMMStrategyBase.sol\";\nimport {TradeInfo} from \"./IAMMStrategy.sol\";\n\ncontract Strategy is AMMStrategyBase {\n    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 153000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 245000000000000000;\n    uint256 constant STALE_ATTRACT_FRAC = 735000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 5250000000000000;\n    uint256 constant TOX_QUAD_COEF = 2099999999999999744;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 685000000000000000;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[2] = 0; slots[3] = WAD; slots[4] = 0;\n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[9] = 0; slots[10] = 0; slots[11] = 0; slots[12] = 0;\n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = slots[2];\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[11] = pHat; slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        { uint256 pTrue; assembly { pTrue := calldataload(196) } if (pTrue > 0) pHat = pTrue; }\n\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        uint256 dirDev; bool sellPressure;\n        if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; }\n        else { dirDev = WAD - dirState; sellPressure = false; }\n\n        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n        uint256 bidFee; uint256 askFee;\n        if (sellPressure) {\n            bidFee = fMid + skew;\n            askFee = fMid > skew ? fMid - skew : 0;\n        } else {\n            askFee = fMid + skew;\n            bidFee = fMid > skew ? fMid - skew : 0;\n        }\n\n        {\n            uint256 staleShift = wmul(STALE_DIR_COEF, toxSignal);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= pHat) {\n                bidFee = bidFee + staleShift;\n                askFee = askFee > attractShift ? askFee - attractShift : 0;\n            } else {\n                askFee = askFee + staleShift;\n                bidFee = bidFee > attractShift ? bidFee - attractShift : 0;\n            }\n        }\n\n        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                else { askFee = askFee + tradeBoost; }\n            }\n        }\n\n        if (sellPressure) {\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT));\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT));\n        } else {\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT));\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT));\n        }\n\n        slots[0] = bidFee; slots[1] = askFee; slots[2] = trade.timestamp;\n        slots[3] = dirState; slots[4] = actEma; slots[5] = pHat;\n        slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat;\n        slots[9] = toxEma; slots[10] = stepTradeCount;\n\n        return (bidFee, askFee);\n    }\n\n    function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) {\n        if (fee <= TAIL_KNEE) return fee;\n        return TAIL_KNEE + wmul(fee - TAIL_KNEE, slope);\n    }\n\n    function _powWad(uint256 factor, uint256 exp) internal pure returns (uint256 result) {\n        result = WAD;\n        while (exp > 0) {\n            if (exp & 1 == 1) result = wmul(result, factor);\n            factor = wmul(factor, factor);\n            exp >>= 1;\n        }\n    }\n\n    function _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) {\n        uint256 mul = _powWad(decayFactor, elapsed);\n        if (centered >= WAD) { return WAD + wmul(centered - WAD, mul); }\n        uint256 below = wmul(WAD - centered, mul);\n        return below < WAD ? WAD - below : 0;\n    }\n\n    function getName() external pure override returns (string memory) { return \"no_cubic\"; }\n}\n",
 "code_sha256": "c216ef8beced38357c630d14143ad89783a92afcd255e74739414dba69211715",
 "simulator_diff": "diff --git a/amm_sim_rs/src/evm/strategy.rs b/amm_sim_rs/src/evm/strategy.rs\nindex 1d06af1..f019614 100644\n--- a/amm_sim_rs/src/evm/strategy.rs\n+++ b/amm_sim_rs/src/evm/strategy.rs\n@@ -55,7 +55,7 @@ pub struct EVMStrategy {\n     /// In-memory database for EVM state\n     db: InMemoryDB,\n     /// Pre-allocated calldata buffer for after_swap (196 bytes)\n-    trade_calldata: [u8; 196],\n+    trade_calldata: [u8; 228],\n }\n \n impl EVMStrategy {\n@@ -65,7 +65,7 @@ impl EVMStrategy {\n             name: default_name,\n             bytecode: bytecode.clone(),\n             db: InMemoryDB::default(),\n-            trade_calldata: [0u8; 196],\n+            trade_calldata: [0u8; 228],\n         };\n \n         strategy.deploy()?;\ndiff --git a/amm_sim_rs/src/simulation/engine.rs b/amm_sim_rs/src/simulation/engine.rs\nindex 6834c43..27886e4 100644\n--- a/amm_sim_rs/src/simulation/engine.rs\n+++ b/amm_sim_rs/src/simulation/engine.rs\n@@ -136,6 +136,7 @@ impl SimulationEngine {\n         for t in 0..self.config.n_steps {\n             // 1. Generate new fair price\n             let fair_price = price_process.step();\n+            crate::types::trade_info::ORACLE_P.with(|c| c.set((fair_price * 1e18).floor() as u128));\n \n             // 2. Arbitrageur extracts profit from each AMM\n             for amm in amms.iter_mut() {\ndiff --git a/amm_sim_rs/src/types/trade_info.rs b/amm_sim_rs/src/types/trade_info.rs\nindex 0d3fa9d..16f0d56 100644\n--- a/amm_sim_rs/src/types/trade_info.rs\n+++ b/amm_sim_rs/src/types/trade_info.rs\n@@ -50,7 +50,7 @@ impl TradeInfo {\n     /// - bytes 132-163: reserveX (uint256)\n     /// - bytes 164-195: reserveY (uint256)\n     #[inline]\n-    pub fn encode_calldata(&self, buffer: &mut [u8; 196]) {\n+    pub fn encode_calldata(&self, buffer: &mut [u8; 228]) {\n         // Function selector for afterSwap(TradeInfo)\n         buffer[0..4].copy_from_slice(&[0xc2, 0xba, 0xbb, 0x57]);\n \n@@ -74,6 +74,9 @@ impl TradeInfo {\n \n         // reserveY\n         Self::encode_u256(&mut buffer[164..196], self.reserve_y.raw() as u128);\n+\n+        // ORACLE (experiment): true fair price floor(p*1e18) at bytes 196..228\n+        Self::encode_u256(&mut buffer[196..228], ORACLE_P.with(|c| c.get()));\n     }\n \n     /// Encode a u128 as big-endian 32 bytes.\n@@ -88,6 +91,10 @@ impl TradeInfo {\n /// Function selector for afterInitialize(uint256,uint256)\n pub const SELECTOR_AFTER_INITIALIZE: [u8; 4] = [0x83, 0x7a, 0xef, 0x47];\n \n+thread_local! {\n+    pub static ORACLE_P: std::cell::Cell<u128> = std::cell::Cell::new(0);\n+}\n+\n /// Function selector for afterSwap(TradeInfo)\n pub const SELECTOR_AFTER_SWAP: [u8; 4] = [0xc2, 0xba, 0xbb, 0x57];\n \n@@ -162,7 +169,7 @@ mod tests {\n             reserve_y: Wad::new(WAD * 1000),\n         };\n \n-        let mut buffer = [0u8; 196];\n+        let mut buffer = [0u8; 228];\n         trade.encode_calldata(&mut buffer);\n \n         // Check selector\n",
 "np2_check_seeds_0_999": 526.1155722459862,
 "tuning": {
  "seeds": "10000..10079 (80)",
  "method": "coordinate search, pass1 x0.25,0.5,2,3 of NP2 values; pass2 x0.7,1.4 of current; keep if paired gain improves; 36 coordinate steps",
  "tuned": {
   "STALE_DIR_COEF": 685000000000000000,
   "STALE_ATTRACT_FRAC": 735000000000000000,
   "TOX_COEF": 5250000000000000,
   "TOX_QUAD_COEF": 2099999999999999744,
   "TRADE_TOX_BOOST": 245000000000000000,
   "TOX_BLEND_DECAY": 153000000000000000
  },
  "np2_values": {
   "STALE_DIR_COEF": 685000000000000000,
   "STALE_ATTRACT_FRAC": 1050000000000000000,
   "TOX_COEF": 30000000000000000,
   "TOX_QUAD_COEF": 1500000000000000000,
   "TRADE_TOX_BOOST": 350000000000000000,
   "TOX_BLEND_DECAY": 51000000000000000
  },
  "untuned_ceiling_vs_np2_on_tune_seeds[mean,se]": [
   -5.436885920066708,
   0.28107722375874655
  ],
  "tuned_vs_np2_on_tune_seeds[mean,se]": [
   -1.946461142940349,
   0.22290071953737484
  ],
  "note": "small tune block (80 seeds) because the shared machine was loaded (~0.4 s/sim); tuned values are noisy"
 },
 "paired": {
  "seeds": "2680000..2681999",
  "n": 2000,
  "mean_diff": -2.055423523339817,
  "se": 0.04646215722704506,
  "worst": -11.855938240578496,
  "cand_mean": 523.683933046279,
  "np2_mean": 525.739356569619
 },
 "split": {
  "note": "engine exposes only total edge; arb/retail edge split not available. Y-volume split given instead.",
  "arb_volume_y_diff": -8833.801334180214,
  "retail_volume_y_diff": -5228.918635230571,
  "arb_volume_y": {
   "cand": 15309.653339182876,
   "np2": 24143.45467336309
  },
  "retail_volume_y": {
   "cand": 72155.32781163488,
   "np2": 77384.24644686545
  }
 },
 "fee_stats": {
  "cand": {
   "bid": 0.004113173715238392,
   "ask": 0.003954731349058242
  },
  "np2": {
   "bid": 0.003636853868247838,
   "ask": 0.0035385770236578793
  }
 },
 "blocked": null,
 "next": "Current-step true price adds no value here (gap after the arb is about the fee deadband). Oracle value lies in the next-step price (unknowable) or in pre-arb gap; try oracle for sigma/lambda or pre-arb gap instead of pHat. This ceiling does not move NP2 toward top 10."
}