From 8efc7785a9c72c9e9f4ed05434a6826c1128e97f Mon Sep 17 00:00:00 2001 From: Andrew Zhou Date: Thu, 12 Sep 2024 13:42:43 -0700 Subject: [PATCH] sanity checks on setting new controllers and discount rate adapters --- src/Strategy.sol | 5 ++++- src/interfaces/term/ITermController.sol | 2 ++ src/interfaces/term/ITermDiscountRateAdapter.sol | 2 ++ src/test/mocks/MockTermController.sol | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Strategy.sol b/src/Strategy.sol index 2607f6a4..6dcc3788 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -120,6 +120,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { address newTermController ) external onlyManagement { require(newTermController != address(0)); + require(ITermController(newTermController).getProtocolReserveAddress() != address(0)); address current = address(currTermController); TERM_VAULT_EVENT_EMITTER.emitTermControllerUpdated( current, @@ -136,11 +137,13 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard { function setDiscountRateAdapter( address newAdapter ) external onlyManagement { + ITermDiscountRateAdapter newDiscountRateAdapter = ITermDiscountRateAdapter(newAdapter); + require(address(newDiscountRateAdapter.TERM_CONTROLLER()) != address(0)); TERM_VAULT_EVENT_EMITTER.emitDiscountRateAdapterUpdated( address(discountRateAdapter), newAdapter ); - discountRateAdapter = ITermDiscountRateAdapter(newAdapter); + discountRateAdapter = newDiscountRateAdapter; } /** diff --git a/src/interfaces/term/ITermController.sol b/src/interfaces/term/ITermController.sol index c8f3d2d7..e121fd11 100644 --- a/src/interfaces/term/ITermController.sol +++ b/src/interfaces/term/ITermController.sol @@ -10,5 +10,7 @@ struct AuctionMetadata { interface ITermController { function isTermDeployed(address contractAddress) external view returns (bool); + function getProtocolReserveAddress() external view returns (address); + function getTermAuctionResults(bytes32 termRepoId) external view returns (AuctionMetadata[] memory auctionMetadata, uint8 numOfAuctions); } diff --git a/src/interfaces/term/ITermDiscountRateAdapter.sol b/src/interfaces/term/ITermDiscountRateAdapter.sol index feba49c3..c441b436 100644 --- a/src/interfaces/term/ITermDiscountRateAdapter.sol +++ b/src/interfaces/term/ITermDiscountRateAdapter.sol @@ -1,7 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.18; +import {ITermController} from "./ITermController.sol"; interface ITermDiscountRateAdapter { + function TERM_CONTROLLER() external view returns (ITermController); function repoRedemptionHaircut(address) external view returns (uint256); function getDiscountRate(address repoToken) external view returns (uint256); } diff --git a/src/test/mocks/MockTermController.sol b/src/test/mocks/MockTermController.sol index 08fa6ed5..f953a53f 100644 --- a/src/test/mocks/MockTermController.sol +++ b/src/test/mocks/MockTermController.sol @@ -15,6 +15,10 @@ contract MockTermController is ITermController { return true; } + function getProtocolReserveAddress() external view returns (address) { + return address(100); + } + function setOracleRate(bytes32 termRepoId, uint256 oracleRate) external { AuctionMetadata memory metadata;