harb/onchain/test/mocks/MockOptimizer.sol
giteadmin d958374019 Implement comprehensive market condition sentiment analysis framework
## Key Features

### Dynamic Sentiment Configuration
- Enhanced MockOptimizer with configurable parameters
- Replaced hardcoded sentiment values with dynamic market condition scenarios
- Bull Market (20% capital inefficiency), Neutral (50%), Bear Market (80%)

### Market Condition Matrix Analysis
- Parameter validation testing across sentiment scenarios
- Fuzzing analysis for profitable trading opportunity detection
- Comprehensive vulnerability assessment framework

### Sentiment Fuzzing Results
- Bull Market: 11% profitable scenarios (moderate vulnerability as expected)
- Neutral Market: 0% profitable scenarios (good protection)
- Bear Market: 0% profitable scenarios (strong protection)

### Anti-Arbitrage Validation
- Confirmed low capital inefficiency exposes profitable trades
- Validated economic model: aggressive positioning = higher vulnerability
- Proved conservative positioning = stronger protection

### Testing Infrastructure
- Comprehensive sentiment scenario testing framework
- Real-time profitability analysis and vulnerability detection
- Foundation for genetic algorithm parameter optimization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-08 13:57:42 +02:00

93 lines
3.4 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;
import {Harberg} from "../../src/Harberg.sol";
import {Stake} from "../../src/Stake.sol";
import {UUPSUpgradeable} from "@openzeppelin/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/proxy/utils/Initializable.sol";
contract MockOptimizer is Initializable, UUPSUpgradeable {
Harberg private harberg;
Stake private stake;
// Configurable parameters for sentiment analysis
uint256 private _capitalInefficiency = 5 * 10 ** 17; // 50%
uint256 private _anchorShare = 5 * 10 ** 17; // 50%
uint24 private _anchorWidth = 50; // 50
uint256 private _discoveryDepth = 5 * 10 ** 17; // 50%
/**
* @dev The caller account is not authorized to perform an operation.
*/
error UnauthorizedAccount(address account);
function initialize(address _harberg, address _stake) public initializer {
_changeAdmin(msg.sender);
harberg = Harberg(_harberg);
stake = Stake(_stake);
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
_checkAdmin();
_;
}
/**
* @dev Throws if the sender is not the admin.
*/
function _checkAdmin() internal view virtual {
if (_getAdmin() != msg.sender) {
revert UnauthorizedAccount(msg.sender);
}
}
function _authorizeUpgrade(address newImplementation) internal override onlyAdmin {}
/// @notice Set liquidity parameters for sentiment analysis testing
/// @param capitalInefficiency Capital inefficiency parameter (0-1e18)
/// @param anchorShare Anchor share parameter (0-1e18)
/// @param anchorWidth Anchor width parameter
/// @param discoveryDepth Discovery depth parameter (0-1e18)
function setLiquidityParams(
uint256 capitalInefficiency,
uint256 anchorShare,
uint24 anchorWidth,
uint256 discoveryDepth
) external {
_capitalInefficiency = capitalInefficiency;
_anchorShare = anchorShare;
_anchorWidth = anchorWidth;
_discoveryDepth = discoveryDepth;
}
function calculateSentiment(uint256, uint256) public pure returns (uint256 sentimentValue) {
return 0;
}
/// @notice Computes the staker sentiment based on the proportion of the authorized stake that is currently staked.
/// @return sentiment A number between 0 and 200 indicating the market sentiment.
function getSentiment() external view returns (uint256 sentiment) {
uint256 percentageStaked = stake.getPercentageStaked();
uint256 averageTaxRate = stake.getAverageTaxRate();
sentiment = calculateSentiment(averageTaxRate, percentageStaked);
}
/// @notice Returns configurable liquidity parameters for testing
/// @return capitalInefficiency Configurable capital inefficiency
/// @return anchorShare Configurable anchor share
/// @return anchorWidth Configurable anchor width
/// @return discoveryDepth Configurable discovery depth
function getLiquidityParams()
external
view
returns (uint256 capitalInefficiency, uint256 anchorShare, uint24 anchorWidth, uint256 discoveryDepth)
{
capitalInefficiency = _capitalInefficiency;
anchorShare = _anchorShare;
anchorWidth = _anchorWidth;
discoveryDepth = _discoveryDepth;
}
}