Skip to content

Commit

Permalink
fix: update gsm fees works without set strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Aug 20, 2024
1 parent 5115df8 commit ef472d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
25 changes: 13 additions & 12 deletions src/contracts/misc/GhoGsmSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ contract GhoGsmSteward is RiskCouncilControlled, IGhoGsmSteward {
uint256 sellFee
) external onlyRiskCouncil notTimelocked(_gsmTimelocksByAddress[gsm].gsmFeeStrategyLastUpdated) {
address currentFeeStrategy = IGsm(gsm).getFeeStrategy();
require(currentFeeStrategy != address(0), 'FIXED_FEE_STRATEGY_NOT_FOUND');

uint256 currentBuyFee = IGsmFeeStrategy(currentFeeStrategy).getBuyFee(1e4);
uint256 currentSellFee = IGsmFeeStrategy(currentFeeStrategy).getSellFee(1e4);
require(buyFee != currentBuyFee || sellFee != currentSellFee, 'NO_CHANGE_IN_FEES');
require(
_isDifferenceLowerThanMax(currentBuyFee, buyFee, GSM_FEE_RATE_CHANGE_MAX),
'INVALID_BUY_FEE_UPDATE'
);
require(
_isDifferenceLowerThanMax(currentSellFee, sellFee, GSM_FEE_RATE_CHANGE_MAX),
'INVALID_SELL_FEE_UPDATE'
);
if (currentFeeStrategy != address(0)) {
uint256 currentBuyFee = IGsmFeeStrategy(currentFeeStrategy).getBuyFee(1e4);
uint256 currentSellFee = IGsmFeeStrategy(currentFeeStrategy).getSellFee(1e4);
require(buyFee != currentBuyFee || sellFee != currentSellFee, 'NO_CHANGE_IN_FEES');
require(
_isDifferenceLowerThanMax(currentBuyFee, buyFee, GSM_FEE_RATE_CHANGE_MAX),
'INVALID_BUY_FEE_UPDATE'
);
require(
_isDifferenceLowerThanMax(currentSellFee, sellFee, GSM_FEE_RATE_CHANGE_MAX),
'INVALID_SELL_FEE_UPDATE'
);
}

IFixedFeeStrategyFactory strategyFactory = IFixedFeeStrategyFactory(FIXED_FEE_STRATEGY_FACTORY);
uint256[] memory buyFeeList = new uint256[](1);
Expand Down
29 changes: 15 additions & 14 deletions src/test/TestGhoGsmSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ contract TestGhoGsmSteward is TestGhoBase {
assertEq(newStrategy, cachedStrategies[0]);
}

function testUpdateGsmBuySellFeesNoPreviousStrategy() public {
vm.mockCall(
address(GHO_GSM),
abi.encodeWithSelector(GHO_GSM.getFeeStrategy.selector),
abi.encode(address(0))
);
vm.prank(RISK_COUNCIL);
GHO_GSM_STEWARD.updateGsmBuySellFees(address(GHO_GSM), 0.01e4, 0.01e4);
vm.clearMockedCalls();
address[] memory cachedStrategies = FIXED_FEE_STRATEGY_FACTORY.getFixedFeeStrategies();
assertEq(cachedStrategies.length, 1);
address newStrategy = GHO_GSM.getFeeStrategy();
assertEq(newStrategy, cachedStrategies[0]);
}

function testRevertUpdateGsmBuySellFeesIfUnauthorized() public {
vm.prank(ALICE);
vm.expectRevert('INVALID_CALLER');
Expand All @@ -351,20 +366,6 @@ contract TestGhoGsmSteward is TestGhoBase {
GHO_GSM_STEWARD.updateGsmBuySellFees(address(GHO_GSM), buyFee, sellFee);
}

function testRevertUpdateGsmBuySellFeesIfStrategyNotFound() public {
address feeStrategy = GHO_GSM.getFeeStrategy();
uint256 buyFee = IGsmFeeStrategy(feeStrategy).getBuyFee(1e4);
uint256 sellFee = IGsmFeeStrategy(feeStrategy).getSellFee(1e4);
vm.mockCall(
address(GHO_GSM),
abi.encodeWithSelector(GHO_GSM.getFeeStrategy.selector),
abi.encode(address(0))
);
vm.expectRevert('FIXED_FEE_STRATEGY_NOT_FOUND');
vm.prank(RISK_COUNCIL);
GHO_GSM_STEWARD.updateGsmBuySellFees(address(GHO_GSM), buyFee + 1, sellFee + 1);
}

function testRevertUpdateGsmBuySellFeesIfBuyFeeMoreThanMax() public {
address feeStrategy = GHO_GSM.getFeeStrategy();
uint256 maxFeeUpdate = GHO_GSM_STEWARD.GSM_FEE_RATE_CHANGE_MAX();
Expand Down

0 comments on commit ef472d6

Please sign in to comment.