Skip to content

Commit

Permalink
adapt to openzeppelin released version
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Korokhov committed May 15, 2024
1 parent 48382b8 commit b88e114
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/contracts/MigratableEntity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ pragma solidity 0.8.25;
import {IMigratableEntityProxy} from "src/interfaces/IMigratableEntityProxy.sol";
import {IMigratableEntity} from "src/interfaces/IMigratableEntity.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

abstract contract MigratableEntity is IMigratableEntity, Initializable, OwnableUpgradeable {
using Address for address;

constructor() {
_disableInitializers();
}
Expand All @@ -24,7 +27,11 @@ abstract contract MigratableEntity is IMigratableEntity, Initializable, OwnableU
* @inheritdoc IMigratableEntity
*/
function migrate(bytes memory) public virtual reinitializer(_getInitializedVersion() + 1) {
if (msg.sender != IMigratableEntityProxy(payable(address(this))).proxyAdmin()) {
address proxyAdmin = abi.decode(
address(this).functionStaticCall(abi.encodeWithSelector(IMigratableEntityProxy.proxyAdmin.selector)),
(address)
);
if (msg.sender != proxyAdmin) {
revert NotProxyAdmin();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/MigratableEntityProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract MigratableEntityProxy is TransparentUpgradeableProxy, IMigratableEntity
/**
* @inheritdoc IMigratableEntityProxy
*/
function proxyAdmin() external view returns (address) {
function proxyAdmin() external returns (address) {
return _proxyAdmin();
}
}
5 changes: 4 additions & 1 deletion src/contracts/MigratablesRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ contract MigratablesRegistry is Factory, Ownable, IMigratablesRegistry {

_versions[entity_] = currentVersion + 1;

ProxyAdmin(IMigratableEntityProxy(entity_).proxyAdmin()).upgradeAndCall(
address proxyAdmin = abi.decode(
entity_.functionStaticCall(abi.encodeWithSelector(IMigratableEntityProxy.proxyAdmin.selector)), (address)
);
ProxyAdmin(proxyAdmin).upgradeAndCall(
ITransparentUpgradeableProxy(entity_),
_whitelistedImplementations.at(currentVersion),
abi.encodeWithSelector(MigratableEntity.migrate.selector, data)
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IMigratableEntityProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface IMigratableEntityProxy {
* @notice Get a proxy admin.
* @return address of the proxy admin
*/
function proxyAdmin() external view returns (address);
function proxyAdmin() external returns (address);
}

0 comments on commit b88e114

Please sign in to comment.