harb/onchain/test/mocks/MockSentimenter.sol
giteadmin bb34d0725f feature/simulations (#11)
this pull request:
- creates a unit test that can take any scenario file (default: `out/scenario.json` and play it back on the deployment
- during the playback a debug trace generated in `timeSeries.csv`
- extracts the sentimenter into a separate upgradeable contract

Co-authored-by: JulesCrown <admin@noip.localhost>
Co-authored-by: giteadmin <gite@admin.com>
Reviewed-on: http://gitea.loseyourip.com:4000/dark-meme-society/harb/pulls/11
2024-11-07 15:33:40 +00:00

59 lines
1.8 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 MockSentimenter is Initializable, UUPSUpgradeable {
Harberg private harberg;
Stake private stake;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error UnauthorizedAccount(address account);
function initialize(address _harberg, address _stake) initializer public {
_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 {}
function calculateSentiment(uint256 averageTaxRate, uint256 percentageStaked) 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 returns (uint256 sentiment) {
uint256 percentageStaked = stake.getPercentageStaked();
uint256 averageTaxRate = stake.getAverageTaxRate();
sentiment = calculateSentiment(averageTaxRate, percentageStaked);
}
}