chore(contracts): Normalize function signatures

This commit is contained in:
Ricardo Guilherme Schmidt 2024-11-25 12:22:27 -03:00
parent 6af73d3883
commit ff94f5e46c
No known key found for this signature in database
GPG Key ID: 54B4454CC123AD17
7 changed files with 46 additions and 54 deletions

View File

@ -172,10 +172,10 @@ abstract contract EpochMath is MultiplierPointMath {
pure
returns (uint256 mpRate, uint256 mpFractional, uint256 epochTarget1, uint256 mpRemainder)
{
mpRate = _accruedMP(_balance, ACCURE_RATE);
mpFractional = mpRate - _accruedMP(_balance, _deltaTime);
mpRate = _accrueMP(_balance, ACCURE_RATE);
mpFractional = mpRate - _accrueMP(_balance, _deltaTime);
uint256 mpTarget = _accruedMaxMP(_balance) + mpFractional;
uint256 mpTarget = _maxAccrueMP(_balance) + mpFractional;
uint256 deltaEpochTarget1 = mpTarget / mpRate;
epochTarget1 = _accountEpoch + deltaEpochTarget1;

View File

@ -31,9 +31,9 @@ abstract contract MultiplierPointMath is IStakeConstants {
* @param _balance Represents the current account balance
* @param _deltaTime The time difference or the duration over which the multiplier points are accrued, expressed in
* seconds
* @return _accruedMP points accrued for given `_amount` and `_seconds`
* @return _accruedMP points accrued for given `_balance` and `_seconds`
*/
function _accruedMP(uint256 _balance, uint256 _deltaTime) internal pure returns (uint256 _accruedMP) {
function _accrueMP(uint256 _balance, uint256 _deltaTime) internal pure returns (uint256 _accruedMP) {
return Math.mulDiv(_balance, _deltaTime * MP_APY, YEAR * 100);
}
@ -42,21 +42,21 @@ abstract contract MultiplierPointMath is IStakeConstants {
* t_lock.
* It is equivalent to the accrued multiplier points function but specifically applied in the context of a locked
* balance.
* @param _amount quantity of tokens
* @param _balance quantity of tokens
* @param _lockedSeconds time in seconds locked
* @return _bonusMP bonus multiplier points for given `_amount` and `_lockedSeconds`
* @return _bonusMP bonus multiplier points for given `_balance` and `_lockedSeconds`
*/
function _bonusMP(uint256 _amount, uint256 _lockedSeconds) internal pure returns (uint256 _bonusMP) {
return _accruedMP(_amount, _lockedSeconds);
function _bonusMP(uint256 _balance, uint256 _lockedSeconds) internal pure returns (uint256 _bonusMP) {
return _accrueMP(_balance, _lockedSeconds);
}
/**
* @notice Calculates the initial multiplier points (MPs) based on the balance change Δa. The result is equal to
* the amount of balance added.
* @param _amount Represents the change in balance.
* @param _balance Represents the change in balance.
*/
function _initialMP(uint256 _amount) internal pure returns (uint256 _initialMP) {
return _amount;
function _initialMP(uint256 _balance) internal pure returns (uint256 _initialMP) {
return _balance;
}
/**
@ -64,17 +64,17 @@ abstract contract MultiplierPointMath is IStakeConstants {
* removed from the total balance a_bal `_balance`.
* The reduction is proportional to the ratio of the removed balance to the total balance, applied to the current
* multiplier points $mp$.
* @param _mp Represents the current multiplier points
* @param _balance The total account balance before the removal of Δa `_reducedBalance`
* @param _mp Represents the current multiplier points
* @param _reducedAmount reduced balance
* @return _reducedMP Multiplier points to reduce from `_mp`
*/
function _reducedMP(
uint256 _mp,
function _reduceMP(
uint256 _balance,
uint256 _mp,
uint256 _reducedAmount
)
public
internal
pure
returns (uint256 _reducedMP)
{
@ -82,11 +82,11 @@ abstract contract MultiplierPointMath is IStakeConstants {
}
/**
* @notice Calculates maximum stake a given `_amount` can be generated with `MAX_MULTIPLIER`
* @notice Calculates maximum stake a given `_balance` can be generated with `MAX_MULTIPLIER`
* @param _balance quantity of tokens
* @return _maxMPAccrued maximum quantity of muliplier points that can be generated for given `_amount`
* @return _maxMPAccrued maximum quantity of muliplier points that can be generated for given `_balance`
*/
function _accruedMaxMP(uint256 _balance) internal pure returns (uint256 _maxMPAccrued) {
function _maxAccrueMP(uint256 _balance) internal pure returns (uint256 _maxMPAccrued) {
return Math.mulDiv(_balance, MP_MPY, 100);
}
@ -97,7 +97,7 @@ abstract contract MultiplierPointMath is IStakeConstants {
* @param _lockTime The time duration for which the balance is locked
* @return _maxMP Maximum Multiplier Points that can be generated for given `_balance` and `_lockTime`
*/
function _totalMaxMP(uint256 _balance, uint256 _lockTime) internal pure returns (uint256 _maxMP) {
function _maxTotalMP(uint256 _balance, uint256 _lockTime) internal pure returns (uint256 _maxMP) {
return _balance + Math.mulDiv(_balance * MP_APY, (MAX_MULTIPLIER * YEAR) + _lockTime, YEAR * 100);
}
@ -107,29 +107,21 @@ abstract contract MultiplierPointMath is IStakeConstants {
* @param _balance quantity of tokens
* @return _maxMPAbsolute Absolute Maximum Multiplier Points
*/
function _absoluteMaxMP(uint256 _balance) internal pure returns (uint256 _maxMPAbsolute) {
function _maxAbsoluteMP(uint256 _balance) internal pure returns (uint256 _maxMPAbsolute) {
return Math.mulDiv(_balance, MP_MPY_ABSOLUTE, 100);
}
/**
* @dev Caution: This value is estimated and can be incorrect due precision loss.
* @notice Calculates the remaining lock time available for a given `_mpMax` and `_balance`
* @param _mpMax Maximum multiplier points calculated from the current balance.
* @param _balance Current balance used to calculate the maximum multiplier points.
* @param _mpMax Maximum multiplier points calculated from the current balance.
* @return _lockTime Amount of lock time allowed to be increased
*/
function _lockTimeAvailable(uint256 _mpMax, uint256 _balance) public pure returns (uint256 _lockTime) {
function _lockTimeAvailable(uint256 _balance, uint256 _mpMax) internal pure returns (uint256 _lockTime) {
return Math.mulDiv((_balance * MP_MPY_ABSOLUTE) - _mpMax, YEAR, _balance * 100);
}
/**
* @notice Calculates the lock time for a given bonus multiplier points and current balance.
* @param _bonusMP bonus multiplier points intended to be generated
* @param _balance current balance
*/
function _lockTime(uint256 _bonusMP, uint256 _balance) internal pure returns (uint256 _lockTime) {
return Math.mulDiv(_bonusMP * 100, YEAR, _balance * MP_APY);
}
/**
* @notice Calculates the time required to accrue a specific multiplier point value.
* @param _balance The current balance.
@ -147,7 +139,7 @@ abstract contract MultiplierPointMath is IStakeConstants {
* @return _bonusMP The calculated bonus multiplier points.
*/
function _retrieveBonusMP(uint256 _balance, uint256 _maxMP) internal pure returns (uint256 _bonusMP) {
return _maxMP - (_balance + _accruedMaxMP(_balance));
return _maxMP - (_balance + _maxAccrueMP(_balance));
}
/**
@ -166,6 +158,6 @@ abstract contract MultiplierPointMath is IStakeConstants {
pure
returns (uint256 _accruedMP)
{
return _totalMP + _accruedMaxMP(_balance) - _maxMP;
return _totalMP + _maxAccrueMP(_balance) - _maxMP;
}
}

View File

@ -179,7 +179,7 @@ contract StakeManager is StakeMath, EpochMath, TrustedCodehashAccess, IStakeMana
revert StakeManager__InvalidLockTime();
}
//mints bonus multiplier points for seconds increased
uint256 bonusMP = _accruedMP(account.balance, _secondsIncrease);
uint256 bonusMP = _accrueMP(account.balance, _secondsIncrease);
//update account storage
account.lockUntil = lockUntil;
@ -339,7 +339,7 @@ contract StakeManager is StakeMath, EpochMath, TrustedCodehashAccess, IStakeMana
* @param epoch Epoch to increment total supply
*/
function _mintMP(Account storage account, uint256 processTime, Epoch storage epoch) private {
uint256 accruedMP = _accruedMP(account.balance, processTime - account.lastMint);
uint256 accruedMP = _accrueMP(account.balance, processTime - account.lastMint);
if (accruedMP + account.totalMP > account.maxMP) {
accruedMP = account.maxMP - account.totalMP; //how much left to reach cap
}
@ -369,7 +369,7 @@ contract StakeManager is StakeMath, EpochMath, TrustedCodehashAccess, IStakeMana
* @return mp multiplier points to mint
*/
function calculateMP(uint256 _balance, uint256 _deltaTime) public pure returns (uint256 mp) {
return _accruedMP(_balance, _deltaTime);
return _accrueMP(_balance, _deltaTime);
}
/**

View File

@ -61,7 +61,7 @@ abstract contract StakeMath is MultiplierPointMath {
}
_deltaMpTotal = _initialMP(_increasedAmount) + deltaMpBonus;
_newMaxMP = _currentMaxMP + _deltaMpTotal + _accruedMP(_increasedAmount, MAX_MULTIPLIER * YEAR);
_newMaxMP = _currentMaxMP + _deltaMpTotal + _accrueMP(_increasedAmount, MAX_MULTIPLIER * YEAR);
require(_newMaxMP <= MP_MPY_ABSOLUTE * (_balance + _increasedAmount), "StakeMath: max multiplier exceeded");
}
@ -136,8 +136,8 @@ abstract contract StakeMath is MultiplierPointMath {
if (newBalance < MIN_BALANCE) {
revert StakeManager__StakeIsTooLow();
}
_deltaMpTotal = _reducedMP(_currentTotalMP, _balance, _reducedAmount);
_deltaMpMax = _reducedMP(_currentMaxMP, _balance, _reducedAmount);
_deltaMpTotal = _reduceMP(_balance, _currentTotalMP, _reducedAmount);
_deltaMpMax = _reduceMP(_balance, _currentMaxMP, _reducedAmount);
}
/**
@ -165,7 +165,7 @@ abstract contract StakeMath is MultiplierPointMath {
revert StakeManager__AccrueTimeNotReached();
}
if (_currentTotalMP < _currentMaxMP) {
_deltaMpTotal = Math.min(_accruedMP(_balance, dt), _currentMaxMP - _currentTotalMP);
_deltaMpTotal = Math.min(_accrueMP(_balance, dt), _currentMaxMP - _currentTotalMP);
}
}

View File

@ -15,7 +15,7 @@ interface IStakeManager is IStakeConstants, ITrustedCodehashAccess {
function totalStaked() external view returns (uint256);
function totalMP() external view returns (uint256);
//function totalMaxMP() external view returns (uint256);
//function maxTotalMP() external view returns (uint256);
function getStakedBalance(address _vault) external view returns (uint256 _balance);
struct Account {

View File

@ -185,7 +185,7 @@ contract DynamicTest is StakeMath, Test {
require(action.args.length == 1, "Incorrect number of arguments");
output.stakeAmount = input.stakeAmount;
output.predictedBonusMP = input.predictedBonusMP;
output.increasedAccruedMP = _accruedMP(input.stakeAmount, action.args[0]);
output.increasedAccruedMP = _accrueMP(input.stakeAmount, action.args[0]);
output.predictedAccruedMP = input.predictedAccruedMP + output.increasedAccruedMP;
}
}
@ -340,8 +340,8 @@ contract DynamicTest is StakeMath, Test {
}
assertEq(streamer.totalStaked(), globalParams[stage].stakeAmount, "wrong total staked");
assertEq(streamer.totalMP(), globalParams[stage].predictedBonusMP, "wrong total MP");
assertEq(streamer.totalMaxMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong totalMaxMP MP");
assertEq(streamer.maxTotalMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong maxTotalMP MP");
}
stage++; // second stage = progress in time
@ -362,8 +362,8 @@ contract DynamicTest is StakeMath, Test {
}
assertEq(streamer.totalStaked(), globalParams[stage].stakeAmount, "wrong total staked");
assertEq(streamer.totalMP(), globalParams[stage].predictedBonusMP, "wrong total MP");
assertEq(streamer.totalMaxMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong totalMaxMP MP");
assertEq(streamer.maxTotalMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong maxTotalMP MP");
}
stage++; // third stage = reduce stake
@ -384,8 +384,8 @@ contract DynamicTest is StakeMath, Test {
}
assertEq(streamer.totalStaked(), globalParams[stage].stakeAmount, "wrong total staked");
assertEq(streamer.totalMP(), globalParams[stage].predictedBonusMP, "wrong total MP");
assertEq(streamer.totalMaxMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong totalMaxMP MP");
assertEq(streamer.maxTotalMP(), globalParams[stage].stakeAmount * MAX_MULTIPLIER +
globalParams[stage].predictedBonusMP, "wrong maxTotalMP MP");
}
}*/
}

View File

@ -137,7 +137,7 @@ contract StakeTest is StakeManagerTest {
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after stake");
assertEq(
maxMP,
_totalMaxMP(stakeAmount, 0),
_maxTotalMP(stakeAmount, 0),
"maxMP of user vault should be equal to stake amount after stake if no lock"
);
assertEq(
@ -146,7 +146,7 @@ contract StakeTest is StakeManagerTest {
vm.prank(testUser);
userVault.lock(lockTime);
uint256 estimatedMaxMP = maxMP + _accruedMP(stakeAmount, lockTime);
uint256 estimatedMaxMP = maxMP + _accrueMP(stakeAmount, lockTime);
uint256 estimatedTotalMP = _initialMP(stakeAmount) + _bonusMP(stakeAmount, lockTime);
(, balance, maxMP, totalMP,,,,) = stakeManager.accounts(address(userVault));
assertEq(balance, stakeAmount, "balance of user vault should be equal to stake amount after lock");
@ -790,11 +790,11 @@ contract UserFlowsTest is StakeManagerTest {
);
uint256 epochTarget1;
uint256 mpRate = _accruedMP(_stakeAmount, ACCURE_RATE);
uint256 mpFractional = mpRate - _accruedMP(_stakeAmount, ACCURE_RATE - _stakeWarpTime);
uint256 mpRate = _accrueMP(_stakeAmount, ACCURE_RATE);
uint256 mpFractional = mpRate - _accrueMP(_stakeAmount, ACCURE_RATE - _stakeWarpTime);
uint256 mpRemainder;
{
uint256 mpTarget = _accruedMaxMP(_stakeAmount) + mpFractional;
uint256 mpTarget = _maxAccrueMP(_stakeAmount) + mpFractional;
uint256 deltaEpochTarget1 = (mpTarget / mpRate);
epochTarget1 = _startEpoch + deltaEpochTarget1;
if (mpTarget % mpRate > 0) {