harb/onchain/test/mocks/ExtremeOptimizer.sol
johba d7c2184ccf Add Solidity linting with solhint, Foundry formatter, and pre-commit hooks (#51)
## Changes

### Configuration
- Added .solhint.json with recommended rules + custom config
  - 160 char line length (warn)
  - Double quotes enforcement (error)
  - Explicit visibility required (error)
  - Console statements allowed (scripts/tests need them)
  - Gas optimization warnings enabled
  - Ignores test/helpers/, lib/, out/, cache/, broadcast/

- Added foundry.toml [fmt] section
  - 160 char line length
  - 4-space tabs
  - Double quotes
  - Thousands separators for numbers
  - Sort imports enabled

- Added .lintstagedrc.json for pre-commit auto-fix
  - Runs solhint --fix on .sol files
  - Runs forge fmt on .sol files

- Added husky pre-commit hook via lint-staged

### NPM Scripts
- lint:sol - run solhint
- lint:sol:fix - auto-fix solhint issues
- format:sol - format with forge fmt
- format:sol:check - check formatting
- lint / lint:fix - combined commands

### Code Changes
- Added explicit visibility modifiers (internal) to constants in scripts and tests
- Fixed quote style in DeployLocal.sol
- All Solidity files formatted with forge fmt

## Verification
-  forge fmt --check passes
-  No solhint errors (warnings only)
-  forge build succeeds
-  forge test passes (107/107)

resolves #44

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/51
2025-10-04 15:17:09 +02:00

67 lines
2.3 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;
/**
* @title ExtremeOptimizer
* @notice Pushes parameters to extremes to find breaking points
* @dev Cycles through extreme parameter combinations to stress test the protocol
*/
contract ExtremeOptimizer {
uint256 private callCount;
function getOptimalParameters(
uint256, // percentageStaked
uint256, // avgTaxRate
uint256 // sentiment
)
external
returns (uint256, uint256, uint256, uint256)
{
callCount++;
// Cycle through extreme scenarios
uint256 scenario = callCount % 5;
if (scenario == 0) {
// Extreme capital inefficiency with minimal anchor
return (
1e18, // 100% capital inefficiency (KRAIKEN valued at 170%)
0.01e18, // 1% anchor share (99% to floor)
1, // 1% anchor width (extremely narrow)
10e18 // 10x discovery depth
);
} else if (scenario == 1) {
// Zero capital inefficiency with maximum anchor
return (
0, // 0% capital inefficiency (KRAIKEN valued at 70%)
0.99e18, // 99% anchor share (minimal floor)
100, // 100% anchor width (maximum range)
0.1e18 // 0.1x discovery depth (minimal discovery)
);
} else if (scenario == 2) {
// Oscillating between extremes
return (
callCount % 2 == 0 ? 1e18 : 0, // Flip between 0% and 100%
0.5e18, // 50% anchor share
50, // 50% width
callCount % 2 == 0 ? 10e18 : 0.1e18 // Flip discovery depth
);
} else if (scenario == 3) {
// Edge case: Everything at minimum
return (
0, // Minimum capital inefficiency
0, // Minimum anchor share (all to floor)
1, // Minimum width
0 // No discovery liquidity
);
} else {
// Edge case: Everything at maximum
return (
1e18, // Maximum capital inefficiency
1e18, // Maximum anchor share (no floor)
100, // Maximum width
100e18 // Extreme discovery depth
);
}
}
}