Skip to content
Verified contractExactGPL-3.0-only

UpgradeableProxy

Address0xcafea6063d4ec6b045d9676e58897c1f0882ca32
Balance

0 ETH

 

Transactions

72

 

Compiler

solc 0.8.28

 

Same code

5 more contracts

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
GPL-3.0-only
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
23,682,581
Creation transaction
0x116e7b36ce…a81c9da47c
Proxy implementation
0xcafea466…3b7da830Governor
Main copy (most transactions)
0xcafea2c5…e7236b9e

contracts/modules/governance/UpgradeableProxy.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.28;

import "../../interfaces/IUpgradeableProxy.sol";

contract UpgradeableProxy is IUpgradeableProxy {

  bytes32 private constant IMPLEMENTATION_POSITION = bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1);
  bytes32 private constant PROXY_OWNER_POSITION = bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1);

  modifier onlyProxyOwner() {
    require(msg.sender == proxyOwner());
    _;
  }

  constructor() {
    _sstore(PROXY_OWNER_POSITION, msg.sender);
  }

  function _sload(bytes32 position) internal view returns (address value) {
    // solhint-disable-next-line no-inline-assembly
    assembly { value := sload(position) }
  }

  function _sstore(bytes32 position, address value) internal {
    // solhint-disable-next-line no-inline-assembly
    assembly { sstore(position, value) }
  }

  function proxyOwner() public view returns (address owner) {
    return _sload(PROXY_OWNER_POSITION);
  }

  function implementation() public view returns (address impl) {
    return _sload(IMPLEMENTATION_POSITION);
  }

  function transferProxyOwnership(address _newOwner) public onlyProxyOwner {
    require(_newOwner != address(0), InvalidAddress());
    address _previousOwner = _sload(PROXY_OWNER_POSITION);
    _sstore(PROXY_OWNER_POSITION, _newOwner);
    emit ProxyOwnershipTransferred(_previousOwner, _newOwner);
  }

  function upgradeTo(address _newImplementation) public onlyProxyOwner {
    _sstore(IMPLEMENTATION_POSITION, _newImplementation);
    emit Upgraded(_newImplementation);
  }

  function _delegate() internal {
    address _impl = implementation();
    require(_impl != address(0));

    // solhint-disable-next-line no-inline-assembly
    assembly {
      let ptr := mload(0x40)
      calldatacopy(ptr, 0, calldatasize())
      let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
      let size := returndatasize()
      returndatacopy(ptr, 0, size)

      switch result
      case 0 {revert(ptr, size)}
      default {return (ptr, size)}
    }
  }

  fallback() external payable {
    _delegate();
  }

  receive() external payable {
    _delegate();
  }
}

contracts/interfaces/IUpgradeableProxy.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IUpgradeableProxy {

  event Upgraded(address indexed implementation);
  event ProxyOwnershipTransferred(address previousOwner, address newOwner);

  function proxyOwner() external view returns (address);

  function implementation() external view returns (address);

  function transferProxyOwnership(address _newOwner) external;

  function upgradeTo(address _newImplementation) external;

  error InvalidAddress();

}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.