From 1ca18358ab6e90cf29d26a8db3ef827838e5b963 Mon Sep 17 00:00:00 2001 From: aazhou1 Date: Fri, 8 Nov 2024 22:10:29 -0500 Subject: [PATCH] strategy state as config --- src/Strategy.sol | 28 ++++++++++++++-------------- src/test/TestUSDCIntegration.t.sol | 15 ++++++++++++++- src/test/TestUSDCSellRepoToken.t.sol | 26 +++++++++++++++++++------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/Strategy.sol b/src/Strategy.sol index c4b7b355..b38340ec 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -109,6 +109,8 @@ contract Strategy is BaseStrategy, Pausable, AccessControl { uint256 internal requiredReserveRatio; // 1e18 uint256 internal discountRateMarkup; // 1e18 uint256 internal repoTokenConcentrationLimit; // 1e18 + + StrategyState public strategyState; mapping(address => bool) public repoTokenBlacklist; modifier notBlacklisted(address repoToken) { @@ -518,20 +520,6 @@ contract Strategy is BaseStrategy, Pausable, AccessControl { ); } - function getStrategyState() external view returns (StrategyState memory) { - return StrategyState({ - assetVault: address(YEARN_VAULT), - eventEmitter: address(TERM_VAULT_EVENT_EMITTER), - prevTermController: address(prevTermController), - currTermController: address(currTermController), - discountRateAdapter: address(discountRateAdapter), - timeToMaturityThreshold: timeToMaturityThreshold, - requiredReserveRatio: requiredReserveRatio, - discountRateMarkup: discountRateMarkup, - repoTokenConcentrationLimit: repoTokenConcentrationLimit - }); - } - /*////////////////////////////////////////////////////////////// INTERNAL FUNCTIONS //////////////////////////////////////////////////////////////*/ @@ -1190,6 +1178,18 @@ contract Strategy is BaseStrategy, Pausable, AccessControl { discountRateMarkup = _params._discountRateMarkup; repoTokenConcentrationLimit = _params._repoTokenConcentrationLimit; + strategyState = StrategyState({ + assetVault: address(YEARN_VAULT), + eventEmitter: address(TERM_VAULT_EVENT_EMITTER), + prevTermController: address(0), + currTermController: address(currTermController), + discountRateAdapter: address(discountRateAdapter), + timeToMaturityThreshold: timeToMaturityThreshold, + requiredReserveRatio: requiredReserveRatio, + discountRateMarkup: discountRateMarkup, + repoTokenConcentrationLimit: repoTokenConcentrationLimit + }); + _grantRole(GOVERNOR_ROLE, _params._governorAddress); } diff --git a/src/test/TestUSDCIntegration.t.sol b/src/test/TestUSDCIntegration.t.sol index aeab4595..515a4854 100644 --- a/src/test/TestUSDCIntegration.t.sol +++ b/src/test/TestUSDCIntegration.t.sol @@ -365,7 +365,20 @@ contract TestUSDCIntegration is Setup { termStrategy.setDiscountRateAdapter(address(valid)); vm.stopPrank(); - assertEq(address(valid), address(termStrategy.getStrategyState().discountRateAdapter)); + ( + address assetVault, + address eventEmitter, + address prevTermController, + address currTermController, + address discountRateAdapter, + uint256 timeToMaturityThreshold, + uint256 requiredReserveRatio, + uint256 discountRateMarkup, + uint256 repoTokenConcentrationLimit + ) = termStrategy.strategyState(); + + + assertEq(address(valid), discountRateAdapter); } function _getRepoTokenAmountGivenPurchaseTokenAmount( diff --git a/src/test/TestUSDCSellRepoToken.t.sol b/src/test/TestUSDCSellRepoToken.t.sol index 3e4fb4ca..27bbbcad 100644 --- a/src/test/TestUSDCSellRepoToken.t.sol +++ b/src/test/TestUSDCSellRepoToken.t.sol @@ -413,39 +413,51 @@ contract TestUSDCSellRepoToken is Setup { vm.prank(governor); termStrategy.setTermController(address(0)); - address currentController = address(termStrategy.getStrategyState().currTermController); + ( + address assetVault, + address eventEmitter, + address prevTermController, + address currTermController, + address discountRateAdapter, + uint256 timeToMaturityThreshold, + uint256 requiredReserveRatio, + uint256 discountRateMarkup, + uint256 repoTokenConcentrationLimit + ) = termStrategy.strategyState(); + + address currentController = currTermController; vm.prank(governor); termStrategy.setTermController(address(newController)); - assertEq(address(termStrategy.getStrategyState().currTermController), address(newController)); - assertEq(address(termStrategy.getStrategyState().currTermController), currentController); + assertEq(currTermController, address(newController)); + assertEq(currTermController, currentController); vm.expectRevert(); termStrategy.setTimeToMaturityThreshold(12345); vm.prank(governor); termStrategy.setTimeToMaturityThreshold(12345); - assertEq(termStrategy.getStrategyState().timeToMaturityThreshold, 12345); + assertEq(timeToMaturityThreshold, 12345); vm.expectRevert(); termStrategy.setRequiredReserveRatio(12345); vm.prank(governor); termStrategy.setRequiredReserveRatio(12345); - assertEq(termStrategy.getStrategyState().requiredReserveRatio, 12345); + assertEq(requiredReserveRatio, 12345); vm.expectRevert(); termStrategy.setDiscountRateMarkup(12345); vm.prank(governor); termStrategy.setDiscountRateMarkup(12345); - assertEq(termStrategy.getStrategyState().discountRateMarkup, 12345); + assertEq(discountRateMarkup, 12345); vm.expectRevert(); termStrategy.setCollateralTokenParams(address(mockCollateral), 12345); vm.prank(governor); termStrategy.setCollateralTokenParams(address(mockCollateral), 12345); - assertEq(termStrategy.getStrategyState().discountRateMarkup, 12345); + assertEq(discountRateMarkup, 12345); } function testRepoTokenValidationFailures() public {