Skip to content

Commit

Permalink
Merge pull request #91 from term-finance/config
Browse files Browse the repository at this point in the history
strategy state as config
  • Loading branch information
aazhou1 authored Nov 9, 2024
2 parents 4b5321d + 1ca1835 commit 48b5aa2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
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

0 comments on commit 48b5aa2

Please sign in to comment.