Skip to content

Commit

Permalink
feat: add helper for fetching current implementation (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Oct 20, 2022
1 parent 0e7a51a commit 2118f43
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/ProxyHelpers.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.7.5 <0.9.0;

import "forge-std/Vm.sol";
import 'forge-std/Vm.sol';

library ProxyHelpers {
function getInitializableAdminUpgradeabilityProxyAdmin(Vm vm, address proxy) internal returns (address) {
address slot = address(
uint160(uint256(vm.load(
proxy,
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
))));
return slot;
}
}
function getInitializableAdminUpgradeabilityProxyAdmin(Vm vm, address proxy)
internal
returns (address)
{
address slot = address(
uint160(
uint256(vm.load(proxy, 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103))
)
);
return slot;
}

function getInitializableAdminUpgradeabilityProxyImplementation(Vm vm, address proxy)
internal
returns (address)
{
address slot = address(
uint160(
uint256(vm.load(proxy, 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc))
)
);
return slot;
}
}
8 changes: 8 additions & 0 deletions src/test/ProxyHelpers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ contract ProxyHelpersTest is Test {
);
assertEq(admin, GovHelpers.LONG_EXECUTOR);
}

function testImplementation() public {
address implementation = ProxyHelpers.getInitializableAdminUpgradeabilityProxyImplementation(
vm,
0x41A08648C3766F9F9d85598fF102a08f4ef84F84
);
assertEq(implementation, 0xadC74A134082eA85105258407159FBB428a73782);
}
}

0 comments on commit 2118f43

Please sign in to comment.