Skip to content

Commit

Permalink
In AccountantWithRateProvider change minimumUpdateDelayInHours to be …
Browse files Browse the repository at this point in the history
…in terms of seconds for more granular control
  • Loading branch information
crispymangoes committed Apr 5, 2024
1 parent 6284f97 commit 0dec573
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
27 changes: 10 additions & 17 deletions src/base/Roles/AccountantWithRateProviders.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
* @param allowedExchangeRateChangeLower the min allowed change to exchange rate from an update
* @param lastUpdateTimestamp the block timestamp of the last exchange rate update
* @param isPaused whether or not this contract is paused
* @param minimumUpdateDelayInHours the minimum amount of time that must pass between
* @param minimumUpdateDelayInSeconds the minimum amount of time that must pass between
* exchange rate updates, such that the update won't trigger the contract to be paused
* @param managementFee the management fee
*/
Expand All @@ -36,7 +36,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
uint16 allowedExchangeRateChangeLower;
uint64 lastUpdateTimestamp;
bool isPaused;
uint8 minimumUpdateDelayInHours;
uint32 minimumUpdateDelayInSeconds;
uint16 managementFee;
}

Expand All @@ -49,13 +49,6 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
IRateProvider rateProvider;
}

// ========================================= CONSTANTS =========================================

/**
* @notice 1 hour.
*/
uint256 internal constant ONE_HOUR = 3_600;

// ========================================= STATE =========================================

/**
Expand All @@ -80,7 +73,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {

event Paused();
event Unpaused();
event DelayInHoursUpdated(uint8 oldDelay, uint8 newDelay);
event DelayInSecondsUpdated(uint32 oldDelay, uint32 newDelay);
event UpperBoundUpdated(uint16 oldBound, uint16 newBound);
event LowerBoundUpdated(uint16 oldBound, uint16 newBound);
event ManagementFeeUpdated(uint16 oldFee, uint16 newFee);
Expand Down Expand Up @@ -120,7 +113,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
address _base,
uint16 allowedExchangeRateChangeUpper,
uint16 allowedExchangeRateChangeLower,
uint8 minimumUpdateDelayInHours,
uint8 minimumUpdateDelayInSeconds,
uint16 managementFee
) Auth(_owner, Authority(address(0))) {
base = ERC20(_base);
Expand All @@ -136,7 +129,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
allowedExchangeRateChangeLower: allowedExchangeRateChangeLower,
lastUpdateTimestamp: uint64(block.timestamp),
isPaused: false,
minimumUpdateDelayInHours: minimumUpdateDelayInHours,
minimumUpdateDelayInSeconds: minimumUpdateDelayInSeconds,
managementFee: managementFee
});
}
Expand Down Expand Up @@ -165,10 +158,10 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
* @dev There are no input requirements, as it is possible the admin would want
* the exchange rate updated as frequently as needed.
*/
function updateDelay(uint8 minimumUpdateDelayInHours) external requiresAuth {
uint8 oldDelay = accountantState.minimumUpdateDelayInHours;
accountantState.minimumUpdateDelayInHours = minimumUpdateDelayInHours;
emit DelayInHoursUpdated(oldDelay, minimumUpdateDelayInHours);
function updateDelay(uint32 minimumUpdateDelayInSeconds) external requiresAuth {
uint32 oldDelay = accountantState.minimumUpdateDelayInSeconds;
accountantState.minimumUpdateDelayInSeconds = minimumUpdateDelayInSeconds;
emit DelayInSecondsUpdated(oldDelay, minimumUpdateDelayInSeconds);
}

/**
Expand Down Expand Up @@ -235,7 +228,7 @@ contract AccountantWithRateProviders is Auth, IRateProvider {
uint256 currentExchangeRate = state.exchangeRate;
uint256 currentTotalShares = vault.totalSupply();
if (
currentTime < state.lastUpdateTimestamp + (state.minimumUpdateDelayInHours * ONE_HOUR)
currentTime < state.lastUpdateTimestamp + state.minimumUpdateDelayInSeconds
|| newExchangeRate > currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeUpper, 1e4)
|| newExchangeRate < currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeLower, 1e4)
) {
Expand Down
5 changes: 2 additions & 3 deletions test/AccountantWithRateProviders.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ contract AccountantWithRateProvidersTest is Test, MainnetAddresses {
function testUpdateDelay() external {
accountant.updateDelay(2);

(,,,,,,,, uint8 delay_in_hours,) = accountant.accountantState();
(,,,,,,,, uint32 delay_in_seconds,) = accountant.accountantState();

assertEq(delay_in_hours, 2, "Delay should be 2 hours");
assertEq(delay_in_seconds, 2, "Delay should be 2 seconds");
}

function testUpdateUpper() external {
Expand Down Expand Up @@ -210,7 +210,6 @@ contract AccountantWithRateProvidersTest is Test, MainnetAddresses {
assertTrue(is_paused == false, "Accountant should not be paused");

// Trying to update before the minimum time should succeed but, pause the contract.
skip((1 days / 24) - 1);
new_exchange_rate = uint96(1.0e18);
accountant.updateExchangeRate(new_exchange_rate);

Expand Down

0 comments on commit 0dec573

Please sign in to comment.