From 68a97787b0c74f9cb9131336eb6176ec550590e6 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 15 Apr 2021 02:38:42 +0530 Subject: [PATCH] Added proxy contracts --- contracts/proxy/proxyAdmin.sol | 90 ++++++++++++++++++++++++++++++++++ contracts/proxy/receivers.sol | 8 +++ contracts/proxy/senders.sol | 8 +++ 3 files changed, 106 insertions(+) create mode 100644 contracts/proxy/proxyAdmin.sol create mode 100644 contracts/proxy/receivers.sol create mode 100644 contracts/proxy/senders.sol diff --git a/contracts/proxy/proxyAdmin.sol b/contracts/proxy/proxyAdmin.sol new file mode 100644 index 0000000..ce06b57 --- /dev/null +++ b/contracts/proxy/proxyAdmin.sol @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol"; + +interface IndexInterface { + function master() external view returns (address); +} + +/** + * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an + * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}. + */ +contract InstaMasterProxy { + + IndexInterface immutable public instaIndex; + + constructor(address _instaIndex) { + instaIndex = IndexInterface(_instaIndex); + } + + modifier isMaster() { + require(msg.sender == instaIndex.master(), "Implementations: not-master"); + _; + } + + /** + * @dev Returns the current implementation of `proxy`. + * + * Requirements: + * + * - This contract must be the admin of `proxy`. + */ + function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) { + // We need to manually run the static call since the getter cannot be flagged as view + // bytes4(keccak256("implementation()")) == 0x5c60da1b + (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b"); + require(success); + return abi.decode(returndata, (address)); + } + + /** + * @dev Returns the current admin of `proxy`. + * + * Requirements: + * + * - This contract must be the admin of `proxy`. + */ + function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) { + // We need to manually run the static call since the getter cannot be flagged as view + // bytes4(keccak256("admin()")) == 0xf851a440 + (bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440"); + require(success); + return abi.decode(returndata, (address)); + } + + /** + * @dev Changes the admin of `proxy` to `newAdmin`. + * + * Requirements: + * + * - This contract must be the current admin of `proxy`. + */ + function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual isMaster { + proxy.changeAdmin(newAdmin); + } + + /** + * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}. + * + * Requirements: + * + * - This contract must be the admin of `proxy`. + */ + function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual isMaster { + proxy.upgradeTo(implementation); + } + + /** + * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See + * {TransparentUpgradeableProxy-upgradeToAndCall}. + * + * Requirements: + * + * - This contract must be the admin of `proxy`. + */ + function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual isMaster { + proxy.upgradeToAndCall{value: msg.value}(implementation, data); + } +} \ No newline at end of file diff --git a/contracts/proxy/receivers.sol b/contracts/proxy/receivers.sol new file mode 100644 index 0000000..d03ae2d --- /dev/null +++ b/contracts/proxy/receivers.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol"; + +contract InstaAaveV2MigratorReceiver is TransparentUpgradeableProxy { + constructor(address _logic, address admin_, bytes memory _data) public TransparentUpgradeableProxy(_logic, admin_, _data) {} +} \ No newline at end of file diff --git a/contracts/proxy/senders.sol b/contracts/proxy/senders.sol new file mode 100644 index 0000000..c838291 --- /dev/null +++ b/contracts/proxy/senders.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol"; + +contract InstaAaveV2MigratorSender is TransparentUpgradeableProxy { + constructor(address _logic, address admin_, bytes memory _data) public TransparentUpgradeableProxy(_logic, admin_, _data) {} +} \ No newline at end of file