harb/onchain/src/OptimizerV3Push3.sol
openhands ca2022d83b fix: address PR #168 review findings in OptimizerV3Push3
- Add `require(averageTaxRate <= 1e18, "Invalid tax rate")` to match
  the existing `percentageStaked` guard and prevent silent acceptance
  of out-of-range values.
- Expand contract-level NatSpec with a @dev note clarifying this is an
  equivalence proof only: it intentionally exposes `isBullMarket` alone
  and is not a deployable upgrade (full optimizer interface missing).

All 15 Foundry tests pass (15 unit + fuzz).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 18:32:49 +00:00

226 lines
17 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;
/**
* @title OptimizerV3Push3
* @notice Auto-generated from optimizer_v3.push3 via Push3→Solidity transpiler.
* Implements the same isBullMarket logic as OptimizerV3.
* @dev This contract is an equivalence proof, not a deployable upgrade.
* It intentionally exposes only `isBullMarket` and does NOT implement
* the full optimizer interface (e.g. `getLiquidityParams`). Wiring it
* into the proxy upgrade path would require completing that interface first.
*/
contract OptimizerV3Push3 {
/**
* @notice Determines if the market is in bull configuration.
* @param percentageStaked Percentage of authorized stake in use (0 to 1e18).
* @param averageTaxRate Normalized average tax rate from Stake contract (0 to 1e18).
* @return bull True if bull config, false if bear.
*/
function isBullMarket(
uint256 percentageStaked,
uint256 averageTaxRate
) public pure returns (bool bull) {
require(percentageStaked <= 1e18, "Invalid percentage staked");
require(averageTaxRate <= 1e18, "Invalid tax rate");
uint256 taxrate = uint256(averageTaxRate);
uint256 staked = uint256(((percentageStaked * 100) / 1000000000000000000));
bool b33;
if ((staked > 91)) {
uint256 deltas = uint256((100 - staked));
uint256 r28;
if ((taxrate <= 206185567010309)) {
r28 = uint256(0);
} else {
uint256 r27;
if ((taxrate <= 412371134020618)) {
r27 = uint256(1);
} else {
uint256 r26;
if ((taxrate <= 618556701030927)) {
r26 = uint256(2);
} else {
uint256 r25;
if ((taxrate <= 1030927835051546)) {
r25 = uint256(3);
} else {
uint256 r24;
if ((taxrate <= 1546391752577319)) {
r24 = uint256(4);
} else {
uint256 r23;
if ((taxrate <= 2164948453608247)) {
r23 = uint256(5);
} else {
uint256 r22;
if ((taxrate <= 2783505154639175)) {
r22 = uint256(6);
} else {
uint256 r21;
if ((taxrate <= 3608247422680412)) {
r21 = uint256(7);
} else {
uint256 r20;
if ((taxrate <= 4639175257731958)) {
r20 = uint256(8);
} else {
uint256 r19;
if ((taxrate <= 5670103092783505)) {
r19 = uint256(9);
} else {
uint256 r18;
if ((taxrate <= 7216494845360824)) {
r18 = uint256(10);
} else {
uint256 r17;
if ((taxrate <= 9278350515463917)) {
r17 = uint256(11);
} else {
uint256 r16;
if ((taxrate <= 11855670103092783)) {
r16 = uint256(12);
} else {
uint256 r15;
if ((taxrate <= 15979381443298969)) {
r15 = uint256(13);
} else {
uint256 r14;
if ((taxrate <= 22164948453608247)) {
r14 = uint256(14);
} else {
uint256 r13;
if ((taxrate <= 29381443298969072)) {
r13 = uint256(15);
} else {
uint256 r12;
if ((taxrate <= 38144329896907216)) {
r12 = uint256(16);
} else {
uint256 r11;
if ((taxrate <= 49484536082474226)) {
r11 = uint256(17);
} else {
uint256 r10;
if ((taxrate <= 63917525773195876)) {
r10 = uint256(18);
} else {
uint256 r9;
if ((taxrate <= 83505154639175257)) {
r9 = uint256(19);
} else {
uint256 r8;
if ((taxrate <= 109278350515463917)) {
r8 = uint256(20);
} else {
uint256 r7;
if ((taxrate <= 144329896907216494)) {
r7 = uint256(21);
} else {
uint256 r6;
if ((taxrate <= 185567010309278350)) {
r6 = uint256(22);
} else {
uint256 r5;
if ((taxrate <= 237113402061855670)) {
r5 = uint256(23);
} else {
uint256 r4;
if ((taxrate <= 309278350515463917)) {
r4 = uint256(24);
} else {
uint256 r3;
if ((taxrate <= 402061855670103092)) {
r3 = uint256(25);
} else {
uint256 r2;
if ((taxrate <= 520618556701030927)) {
r2 = uint256(26);
} else {
uint256 r1;
if ((taxrate <= 680412371134020618)) {
r1 = uint256(27);
} else {
uint256 r0;
if ((taxrate <= 886597938144329896)) {
r0 = uint256(28);
} else {
r0 = uint256(29);
}
r1 = uint256(r0);
}
r2 = uint256(r1);
}
r3 = uint256(r2);
}
r4 = uint256(r3);
}
r5 = uint256(r4);
}
r6 = uint256(r5);
}
r7 = uint256(r6);
}
r8 = uint256(r7);
}
r9 = uint256(r8);
}
r10 = uint256(r9);
}
r11 = uint256(r10);
}
r12 = uint256(r11);
}
r13 = uint256(r12);
}
r14 = uint256(r13);
}
r15 = uint256(r14);
}
r16 = uint256(r15);
}
r17 = uint256(r16);
}
r18 = uint256(r17);
}
r19 = uint256(r18);
}
r20 = uint256(r19);
}
r21 = uint256(r20);
}
r22 = uint256(r21);
}
r23 = uint256(r22);
}
r24 = uint256(r23);
}
r25 = uint256(r24);
}
r26 = uint256(r25);
}
r27 = uint256(r26);
}
r28 = uint256(r27);
}
uint256 dup29 = uint256(r28);
uint256 r32;
if ((dup29 >= 14)) {
uint256 dup30 = uint256((dup29 + 1));
uint256 r31;
if ((dup30 > 29)) {
r31 = uint256(29);
} else {
r31 = uint256(dup30);
}
r32 = uint256(r31);
} else {
r32 = uint256(dup29);
}
uint256 effidx = uint256(r32);
b33 = (((((deltas * deltas) * deltas) * effidx) / 20) < 50);
} else {
b33 = false;
}
bull = b33;
}
}