Verified contractPartialUNLICENSED
MetricCreate3Factory
Address0x677d2b1100b48a227cc525ce174cf812ea1071ef
- Balance
0 ETH
- Transactions
7
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 99,999 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,984,147
- Creation transaction
- 0xb1229d22a4…32000158af
script/utils/MetricCreate3Factory.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {Create3} from "@openzeppelin/contracts-v5/utils/Create3.sol";
/// @notice CREATE2-deployed factory; OpenZeppelin Create3 for bytecode-independent child addresses.
contract MetricCreate3Factory {
event Deployed(address indexed deployed, address indexed sender, bytes32 salt, bytes32 bytecodeHash);
function deploy(bytes memory bytecode, bytes32 salt) external payable returns (address deployed) {
bytes32 deploySalt = keccak256(abi.encode(msg.sender, salt));
deployed = Create3.deploy(msg.value, deploySalt, bytecode);
emit Deployed(deployed, msg.sender, salt, keccak256(bytecode));
}
function deployedAddress(bytes memory, address sender, bytes32 salt) external view returns (address) {
bytes32 deploySalt = keccak256(abi.encode(sender, salt));
return Create3.computeAddress(deploySalt);
}
}
lib/openzeppelin-contracts/contracts/utils/Create2.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
import {LowLevelCall} from "./LowLevelCall.sol";
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
}
if (addr == address(0)) {
if (LowLevelCall.returnDataSize() == 0) {
revert Errors.FailedDeployment();
} else {
LowLevelCall.bubbleRevert();
}
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |---------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |---------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 0x55) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
lib/openzeppelin-contracts/contracts/utils/Create3.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Create2} from "./Create2.sol";
import {Errors} from "./Errors.sol";
import {LowLevelCall} from "./LowLevelCall.sol";
/**
* @dev Helper to deploy contracts using the `CREATE3` approach.
* `CREATE3` combines both `CREATE2` and `CREATE` opcodes to deploy arbitrary bytecode at an address that only depends
* on the provided salt and the address of the contract using this library. At a high level, it behaves like a `CREATE2`
* operation that would not use the bytecodehash to generate the contract address.
*
* CREATE3 can be used to compute in advance the address where a smart contract will be deployed, even if the bytecode
* is subject to change.
*
* NOTE: To get the same deployment address on multiple chains, the deployer contract must live at the same address on
* each chain.
*
* See {Create2} for counterfactual deployments that include the bytecodehash in the computation of the address.
*/
library Create3 {
/**
* ===================================[ PROXY CODE ]===================================
* Offset | Opcode | Mnemonic | Stack | Memory
* -------|-------------|------------------|-----------------|-------------------------
* 0x00 | 36 | CALLDATASIZE | cds |
* 0x01 | 5F | PUSH0 | 0 cds |
* 0x02 | 5F | PUSH0 | 0 0 cds |
* 0x03 | 37 | CALLDATACOPY | | [0..cds): calldata
* 0x04 | 36 | CALLDATASIZE | cds | [0..cds): calldata
* 0x05 | 5F | PUSH0 | 0 cds | [0..cds): calldata
* 0x06 | 34 | CALLVALUE | value 0 cds | [0..cds): calldata
* 0x07 | f0 | CREATE | addr | [0..cds): calldata
* 0x08 | 6012 | PUSH1 0x12 | 0x12 addr |
* 0x0A | 57 | JUMPI | |
* 0x0B | 3D | RETURNDATASIZE | rds |
* 0x0C | 5F | PUSH0 | 0 rds |
* 0x0D | 5F | PUSH0 | 0 0 rds |
* 0x0E | 3E | RETURNDATACOPY | | [0..rds): returndata
* 0x0F | 3D | RETURNDATASIZE | rds | [0..rds): returndata
* 0x10 | 5F | PUSH0 | 0 rds | [0..rds): returndata
* 0x11 | FD | REVERT | |
* 0x12 | 5b | JUMPDEST | |
* 0x13 | 00 | STOP | |
*
* ================================[ DEPLOYMENT CODE ]=================================
* Offset | Opcode | Mnemonic | Stack | Memory
* -------|-------------|------------------|-----------------|-------------------------
* 0x00 | 73 bytecode | PUSH20 bytecode | bytecode |
* 0x15 | 5F | PUSH0 | 0 bytecode |
* 0x16 | 52 | MSTORE | | [0x0C..0x20): bytecode
* 0x17 | 6014 | PUSH1 0x14 | 0x14 | [0x0C..0x20): bytecode
* 0x19 | 600C | PUSH1 0x0C | 0x0C 0x14 | [0x0C..0x20): bytecode
* 0x1B | f3 | RETURN | | [0x0C..0x20): bytecode
*/
/// @dev The proxy initialization code.
bytes28 private constant PROXY_INITCODE = 0x73365f5f37365f34f06012573d5f5f3e3d5ffd5b005f526014600cf3;
/// @dev Hash of the `PROXY_INITCODE`.
/// Equivalent to `keccak256(hex"73365f5f37365f34f06012573d5f5f3e3d5ffd5b005f526014600cf3")`.
bytes32 internal constant PROXY_INITCODE_HASH = 0x57a34f6e879358dd76825d6700df87013ad6a3fb43c0d0c602f70a8772c153bd;
/**
* @dev There's no code to deploy.
*/
error Create3EmptyBytecode();
/**
* @dev Deploys a contract using the `CREATE3` mechanism. The address where the contract
* will be deployed can be known in advance via {computeAddress}, and only depends on the salt.
* The bytecode that is deployed DOES NOT affect the location at which it is deployed.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must not have been used already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create3EmptyBytecode();
}
// This fails if the salt was already used. Will never return address(0).
address proxy = Create2.deploy(0, salt, abi.encodePacked(PROXY_INITCODE));
// Perform the actual deployment (create on the proxy with nonce 1).
bool success = LowLevelCall.callNoReturn(proxy, amount, bytecode);
if (!success) {
if (LowLevelCall.returnDataSize() == 0) {
revert Errors.FailedDeployment();
} else {
LowLevelCall.bubbleRevert();
}
}
return _computeCreateAddress(proxy);
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt) internal view returns (address) {
return computeAddress(salt, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, address deployer) internal pure returns (address) {
return _computeCreateAddress(Create2.computeAddress(salt, PROXY_INITCODE_HASH, deployer));
}
/// @dev Compute the address of the first contract that `creator` would deployed using CREATE (nonce 1).
function _computeCreateAddress(address creator) private pure returns (address addr) {
assembly ("memory-safe") {
mstore(0x15, 0x01)
mstore(0x14, creator)
mstore(0x00, 0xd694)
addr := and(keccak256(0x1e, 0x17), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
lib/openzeppelin-contracts/contracts/utils/Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
lib/openzeppelin-contracts/contracts/utils/LowLevelCall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.6.0) (utils/LowLevelCall.sol)
pragma solidity ^0.8.20;
/**
* @dev Library of low level call functions that implement different calling strategies to deal with the return data.
*
* WARNING: Using this library requires an advanced understanding of Solidity and how the EVM works. It is recommended
* to use the {Address} library instead.
*/
library LowLevelCall {
/// @dev Performs a Solidity function call using a low level `call` and ignoring the return data.
function callNoReturn(address target, bytes memory data) internal returns (bool success) {
return callNoReturn(target, 0, data);
}
/// @dev Same as {callNoReturn-address-bytes}, but allows specifying the value to be sent in the call.
function callNoReturn(address target, uint256 value, bytes memory data) internal returns (bool success) {
assembly ("memory-safe") {
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `call` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function callReturn64Bytes(
address target,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
return callReturn64Bytes(target, 0, data);
}
/// @dev Same as {callReturn64Bytes-address-bytes}, but allows specifying the value to be sent in the call.
function callReturn64Bytes(
address target,
uint256 value,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Performs a Solidity function call using a low level `staticcall` and ignoring the return data.
function staticcallNoReturn(address target, bytes memory data) internal view returns (bool success) {
assembly ("memory-safe") {
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `staticcall` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function staticcallReturn64Bytes(
address target,
bytes memory data
) internal view returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Performs a Solidity function call using a low level `delegatecall` and ignoring the return data.
function delegatecallNoReturn(address target, bytes memory data) internal returns (bool success) {
assembly ("memory-safe") {
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `delegatecall` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function delegatecallReturn64Bytes(
address target,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Returns the size of the return data buffer.
function returnDataSize() internal pure returns (uint256 size) {
assembly ("memory-safe") {
size := returndatasize()
}
}
/// @dev Returns a buffer containing the return data from the last call.
function returnData() internal pure returns (bytes memory result) {
assembly ("memory-safe") {
result := mload(0x40)
mstore(result, returndatasize())
returndatacopy(add(result, 0x20), 0x00, returndatasize())
mstore(0x40, add(result, add(0x20, returndatasize())))
}
}
/// @dev Revert with the return data from the last call.
function bubbleRevert() internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
}
function bubbleRevert(bytes memory returndata) internal pure {
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 99999,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"lib/metric-periphery/:@metric-core/=lib/metric-periphery/lib/metric-core/contracts/",
"lib/metric-periphery/:@openzeppelin/contracts/=lib/metric-periphery/lib/metric-core/lib/openzeppelin-contracts/contracts/",
"metric-periphery/=lib/metric-periphery/contracts/",
"@metric-core/=lib/metric-core/contracts/",
"@openzeppelin/contracts/=lib/metric-core/lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts-v5/=lib/openzeppelin-contracts/contracts/",
"@metric-core-test/=lib/metric-periphery/lib/metric-core/test/",
"erc4626-tests/=lib/metric-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/metric-core/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"metric-core/=lib/metric-core/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.