Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strategy state as config #91

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 14 additions & 1 deletion src/test/TestUSDCIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 19 additions & 7 deletions src/test/TestUSDCSellRepoToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down