Skip to content

Commit

Permalink
feat: proxy admin control utils
Browse files Browse the repository at this point in the history
  • Loading branch information
seinmyung25 committed Mar 15, 2024
1 parent a9fbba3 commit c50e927
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
69 changes: 69 additions & 0 deletions contracts/access/CallAccess.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { EcoOwnable } from "./EcoOwnable.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { StorageSlot } from "@openzeppelin/contracts/utils/StorageSlot.sol";

interface ICallAccess {
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) external payable returns (bytes memory);

function functionMultiCallWithValue(
address target,
bytes[] memory data,
uint256[] memory value
) external payable returns (bytes[] memory);

function functionDelegateCall(address target, bytes memory data) external payable returns (bytes memory);

function setSlot(bytes32 slot, bytes32 value) external;

function getSlot(bytes32 slot) external view returns (bytes32 value);
}

abstract contract CallAccess is ICallAccess, EcoOwnable {
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) public payable override onlyOwner returns (bytes memory) {
return Address.functionCallWithValue(target, data, value);
}

function functionMultiCallWithValue(
address target,
bytes[] memory data,
uint256[] memory value
) public payable override onlyOwner returns (bytes[] memory) {
require(data.length == value.length, "call count");
uint256 valueSum;
unchecked {
for (uint256 i; i < data.length; i++) {
data[i] = Address.functionCallWithValue(target, data[i], value[i]);
valueSum += value[i];
}
}
require(valueSum == msg.value, "value sum");
return data;
}

function functionDelegateCall(
address target,
bytes memory data
) public payable override onlyOwner returns (bytes memory) {
return Address.functionDelegateCall(target, data);
}

function setSlot(bytes32 slot, bytes32 value) public override onlyOwner {
StorageSlot.getBytes32Slot(slot).value = value;
}

function getSlot(bytes32 slot) external view override onlyOwner returns (bytes32 value) {
return StorageSlot.getBytes32Slot(slot).value;
}
}
3 changes: 2 additions & 1 deletion contracts/proxy/admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.20;
import { ITransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import { IEcoOwnable, EcoOwnable } from "../access/EcoOwnable.sol";
import { CallAccess } from "../access/CallAccess.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

interface IEcoProxyAdmin {
Expand All @@ -16,7 +17,7 @@ interface IEcoProxyAdmin {
* @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 EcoProxyAdmin is IEcoProxyAdmin, EcoOwnable {
contract EcoProxyAdmin is IEcoProxyAdmin, EcoOwnable, CallAccess {
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgrade(address)`
* and `upgradeAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
Expand Down

0 comments on commit c50e927

Please sign in to comment.