Skip to content
Verified contractExactMIT

Proxy

Address0xe8d0d5693b8ba01751f5d26adb9c39d6438edca0
Balance

0 ETH

 

Transactions

105

 

Compiler

solc 0.8.4

 

Same code

6 more contracts

 

Details

Compiler
solc 0.8.4+commit.c7e474f2
Language
solidity
Optimization
No
EVM version
istanbul
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
13,823,092
Creation transaction
0x44878da107…cd8670dd86
Main copy (most transactions)
0xaa874a0f…f7a0ba52

contracts/utils/Proxy.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
contract Proxy {
	address implementation_;
	address public admin;

	constructor(address impl) {
		implementation_ = impl;
		admin = msg.sender;
	}

	receive() external payable {}

	function setImplementation(address newImpl) public {
		require(msg.sender == admin);
		implementation_ = newImpl;
	}

	function implementation() public view returns (address impl) {
		impl = implementation_;
	}

	function transferOwnership(address newOwner) external {
		require(msg.sender == admin);
		admin = newOwner;
	}

	/**
	 * @dev Delegates the current call to `implementation`.
	 *
	 * This function does not return to its internall call site, it will return directly to the external caller.
	 */
	function _delegate(address implementation__) internal virtual {
		assembly {
			// Copy msg.data. We take full control of memory in this inline assembly
			// block because it will not return to Solidity code. We overwrite the
			// Solidity scratch pad at memory position 0.
			calldatacopy(0, 0, calldatasize())

			// Call the implementation.
			// out and outsize are 0 because we don't know the size yet.
			let result := delegatecall(gas(), implementation__, 0, calldatasize(), 0, 0)

			// Copy the returned data.
			returndatacopy(0, 0, returndatasize())

			switch result
			// delegatecall returns 0 on error.
			case 0 {
				revert(0, returndatasize())
			}
			default {
				return(0, returndatasize())
			}
		}
	}

	/**
	 * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
	 * and {_fallback} should delegate.
	 */
	function _implementation() internal view returns (address) {
		return implementation_;
	}

	/**
	 * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
	 * function in the contract matches the call data.
	 */
	fallback() external payable virtual {
		_delegate(_implementation());
	}
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "istanbul",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.