-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Korokhov
committed
May 17, 2024
1 parent
5acbacb
commit aaa1e99
Showing
9 changed files
with
109 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
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"; | ||
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
|
||
abstract contract MigratableEntity is IMigratableEntity, Initializable, OwnableUpgradeable { | ||
using Address for address; | ||
abstract contract MigratableEntity is Initializable, UUPSUpgradeable, OwnableUpgradeable, IMigratableEntity { | ||
// keccak256(abi.encode(uint256(keccak256("symbiotic.storage.MigratableEntity")) - 1)) & ~bytes32(uint256(0xff)) | ||
bytes32 private constant MigratableEntityStorageLocation = | ||
0x22b5f4baea4997f81f8aeb6360e0bdae13f074e0e55c27a8a6fab78cbad46200; | ||
|
||
modifier onlyProxyAdmin() { | ||
if (msg.sender != proxyAdmin()) { | ||
revert NotProxyAdmin(); | ||
} | ||
_; | ||
} | ||
|
||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
/** | ||
* @inheritdoc IMigratableEntity | ||
*/ | ||
function proxyAdmin() public view returns (address) { | ||
return _getMigratableEntityStorage()._proxyAdmin; | ||
} | ||
|
||
/** | ||
* @inheritdoc IMigratableEntity | ||
*/ | ||
function initialize(bytes memory data) public virtual initializer { | ||
address owner = abi.decode(data, (address)); | ||
__Ownable_init(owner); | ||
__UUPSUpgradeable_init(); | ||
|
||
MigratableEntityStorage storage $ = _getMigratableEntityStorage(); | ||
$._proxyAdmin = msg.sender; | ||
} | ||
|
||
/** | ||
* @inheritdoc IMigratableEntity | ||
*/ | ||
function migrate(bytes memory) public virtual reinitializer(_getInitializedVersion() + 1) { | ||
address proxyAdmin = abi.decode( | ||
address(this).functionStaticCall(abi.encodeWithSelector(IMigratableEntityProxy.proxyAdmin.selector)), | ||
(address) | ||
); | ||
if (msg.sender != proxyAdmin) { | ||
revert NotProxyAdmin(); | ||
function migrate(bytes memory) public virtual onlyProxyAdmin reinitializer(_getInitializedVersion() + 1) {} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal override onlyProxyAdmin {} | ||
|
||
function _getMigratableEntityStorage() private pure returns (MigratableEntityStorage storage $) { | ||
assembly { | ||
$.slot := MigratableEntityStorageLocation | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.