Skip to content

Commit

Permalink
feat: add recplacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Oct 10, 2024
1 parent 84b74dd commit a7b6bce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/addressProviders/ProtocolAddressProvider.vy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ event UpdateGovernance:
ROUTER: constant(bytes32) = keccak256("Router")
KEEPER: constant(bytes32) = keccak256("Keeper")
APR_ORACLE: constant(bytes32) = keccak256("APR Oracle")
REPLACEMENT: constant(bytes32) = keccak256("Replacement")
RELEASE_REGISTRY: constant(bytes32) = keccak256("Release Registry")
BASE_FEE_PROVIDER: constant(bytes32) = keccak256("Base Fee Provider")
COMMON_REPORT_TRIGGER: constant(bytes32) = keccak256("Common Report Trigger")
Expand Down Expand Up @@ -79,6 +80,16 @@ def getAddress(address_id: bytes32) -> address:
def _get_address(address_id: bytes32) -> address:
return self.addresses[address_id]

@view
@external
def getReplacement() -> address:
"""
@notice Get the replacement of the address provider if it exists.
This will return address 0 if this is the latest version.
@return The replacement address provider if any.
"""
return self._get_address(REPLACEMENT)

@view
@external
def getRouter() -> address:
Expand Down Expand Up @@ -214,6 +225,15 @@ def _set_address(address_id: bytes32, new_address: address):

log UpdatedAddress(address_id, old_address, new_address)

@external
def setReplacement(new_address: address):
"""
@notice Set the replacement address provider.
@dev Must be called by the governance.
@param new_address of the replacement address provider.
"""
self._set_address(REPLACEMENT, new_address)

@external
def setRouter(new_address: address):
"""
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/IProtocolAddressProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface IProtocolAddressProvider {

function getAddress(bytes32 _id) external view returns (address);

function setReplacement(address _replacement) external;

function setRouter(address _router) external;

function setKeeper(address _keeper) external;
Expand All @@ -42,6 +44,8 @@ interface IProtocolAddressProvider {

function setRoleManagerFactory(address _roleManagerFactory) external;

function getReplacement() external view returns (address);

function getRouter() external view returns (address);

function getKeeper() external view returns (address);
Expand Down
25 changes: 25 additions & 0 deletions src/test/TestAddressProvider.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract TestAddressProvider is Setup {
assertEq(addressProvider.name(), "Yearn V3 Protocol Address Provider");
assertEq(addressProvider.governance(), daddy);
assertEq(addressProvider.pendingGovernance(), ZERO_ADDRESS);
assertEq(addressProvider.getReplacement(), ZERO_ADDRESS);
assertEq(addressProvider.getRouter(), ZERO_ADDRESS);
assertEq(addressProvider.getKeeper(), ZERO_ADDRESS);
assertEq(addressProvider.getAprOracle(), ZERO_ADDRESS);
Expand Down Expand Up @@ -46,6 +47,29 @@ contract TestAddressProvider is Setup {
assertEq(addressProvider.getAddress(id), newAddress);
}

function test__set_replacement() public {
bytes32 id = AddressIds.REPLACEMENT;
address newAddress = address(0x456);

assertEq(addressProvider.getAddress(id), ZERO_ADDRESS);
assertEq(addressProvider.getReplacement(), ZERO_ADDRESS);

vm.prank(user);
vm.expectRevert("!governance");
addressProvider.setReplacement(newAddress);

assertEq(addressProvider.getAddress(id), ZERO_ADDRESS);
assertEq(addressProvider.getReplacement(), ZERO_ADDRESS);

vm.prank(daddy);
vm.expectEmit(true, true, true, true, address(addressProvider));
emit UpdatedAddress(id, ZERO_ADDRESS, newAddress);
addressProvider.setReplacement(newAddress);

assertEq(addressProvider.getAddress(id), newAddress);
assertEq(addressProvider.getReplacement(), newAddress);
}

function test__set_router() public {
bytes32 id = AddressIds.ROUTER;
address newAddress = address(0x123);
Expand Down Expand Up @@ -407,6 +431,7 @@ library AddressIds {
bytes32 constant ROUTER = keccak256("Router");
bytes32 constant KEEPER = keccak256("Keeper");
bytes32 constant APR_ORACLE = keccak256("APR Oracle");
bytes32 constant REPLACEMENT = keccak256("Replacement");
bytes32 constant RELEASE_REGISTRY = keccak256("Release Registry");
bytes32 constant BASE_FEE_PROVIDER = keccak256("Base Fee Provider");
bytes32 constant COMMON_REPORT_TRIGGER = keccak256("Common Report Trigger");
Expand Down

0 comments on commit a7b6bce

Please sign in to comment.