Replace hardcoded anchorWidth=100 with dynamic calculation that uses staking data as a decentralized oracle. Changes: - Add _calculateAnchorWidth() function to Optimizer.sol - Base width 40% with adjustments based on staking percentage and average tax rate - Staking adjustment: -20% to +20% (inverse relationship) - Tax rate adjustment: -10% to +30% (direct relationship) - Final range clamped to 10-80% for safety Rationale: - High staking % = bullish sentiment → narrower anchor (20-35%) for fee optimization - Low staking % = bearish/uncertain → wider anchor (60-80%) for defensive positioning - High tax rates = volatility expected → wider anchor to reduce rebalancing - Low tax rates = stability expected → narrower anchor for fee collection The Harberger tax mechanism acts as a prediction market where stakers' self-assessed valuations reveal market expectations. Tests: - Add comprehensive unit tests in test/Optimizer.t.sol - Add mock contracts for testing (MockStake.sol, MockKraiken.sol) - Manual verification confirms all scenarios calculate correctly Documentation: - Add detailed analysis of anchorWidth price ranges - Add staking-based strategy recommendations - Add verification of calculation logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
No EOL
1.4 KiB
Solidity
46 lines
No EOL
1.4 KiB
Solidity
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
pragma solidity ^0.8.19;
|
|
|
|
/**
|
|
* @title MockStake
|
|
* @notice Mock implementation of Stake contract for testing Optimizer
|
|
* @dev Allows setting percentageStaked and averageTaxRate for testing different scenarios
|
|
*/
|
|
contract MockStake {
|
|
uint256 private _percentageStaked;
|
|
uint256 private _averageTaxRate;
|
|
|
|
/**
|
|
* @notice Set the percentage staked for testing
|
|
* @param percentage Value between 0 and 1e18
|
|
*/
|
|
function setPercentageStaked(uint256 percentage) external {
|
|
require(percentage <= 1e18, "Percentage too high");
|
|
_percentageStaked = percentage;
|
|
}
|
|
|
|
/**
|
|
* @notice Set the average tax rate for testing
|
|
* @param rate Value between 0 and 1e18
|
|
*/
|
|
function setAverageTaxRate(uint256 rate) external {
|
|
require(rate <= 1e18, "Rate too high");
|
|
_averageTaxRate = rate;
|
|
}
|
|
|
|
/**
|
|
* @notice Returns the mocked percentage staked
|
|
* @return percentageStaked A number between 0 and 1e18
|
|
*/
|
|
function getPercentageStaked() external view returns (uint256) {
|
|
return _percentageStaked;
|
|
}
|
|
|
|
/**
|
|
* @notice Returns the mocked average tax rate
|
|
* @return averageTaxRate A number between 0 and 1e18
|
|
*/
|
|
function getAverageTaxRate() external view returns (uint256) {
|
|
return _averageTaxRate;
|
|
}
|
|
} |