Verified contractExactMIT
CornDeployer
Address0x0969f8752a32b4f1f9d07b751c7bacbf6d9ae733
- Balance
0 ETH
- Transactions
129
- Compiler
solc 0.8.25
- Same code
Only this contract
Details
- Compiler
- solc 0.8.25+commit.b61c2a91
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 20,535,549
- Creation transaction
- 0xa9ddb9e9a7…6be5f33360
3 files
- src/deployer/CornDeployer.solmain3.56 KB
- lib/solmate/src/auth/Auth.sol2.58 KB
- src/deployer/Create3.sol4.91 KB
src/deployer/CornDeployer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./Create3.sol";
import {Auth, Authority} from "solmate/auth/Auth.sol";
contract CornDeployer is Auth {
string public constant name = "Corn Deployer";
event ContractDeployed(address indexed contractAddress, string contractName, bytes32 salt);
constructor() Auth(msg.sender, Authority(address(0))) {}
/**
* @notice Deploy a contract using salt in string format and arbitrary runtime code.
* @dev Intended use is: get the future Corn addresses, then deploy the appropriate contract to each address via this method, building the constructor using the mapped addresses
* @dev no enforcment of bytecode at address as we can't know the runtime code in this contract due to space constraints
*/
function _deploy(string memory _saltString, bytes memory _creationCode)
internal
returns (address deployedAddress)
{
bytes32 _salt = keccak256(abi.encodePacked(_saltString));
deployedAddress = Create3.create3(_salt, _creationCode);
emit ContractDeployed(deployedAddress, _saltString, _salt);
}
/**
* @notice Deploy a contract using salt in string format and arbitrary runtime code.
* @dev Intended use is: get the future Corn addresses, then deploy the appropriate contract to each address via this method, building the constructor using the mapped addresses
* @dev no enforcment of bytecode at address as we can't know the runtime code in this contract due to space constraints
*/
function deploy(string memory _saltString, bytes memory _creationCode)
public
requiresAuth
returns (address deployedAddress)
{
return _deploy(_saltString, _creationCode);
}
function deployWithCreationCodeAndConstructorArgs(
string memory _saltString,
bytes memory creationCode,
bytes memory constructionArgs
) external requiresAuth returns (address) {
bytes memory _data = abi.encodePacked(creationCode, constructionArgs);
return _deploy(_saltString, _data);
}
function deployWithCreationCode(string memory _saltString, bytes memory creationCode)
external
requiresAuth
returns (address)
{
return _deploy(_saltString, creationCode);
}
function addressOf(string memory _saltString) external view returns (address) {
bytes32 _salt = keccak256(abi.encodePacked(_saltString));
return Create3.addressOf(_salt);
}
function addressOfSalt(bytes32 _salt) external view returns (address) {
return Create3.addressOf(_salt);
}
/**
* @notice Create the creation code for a contract with the given runtime code.
* @dev credit: https://github.com/0xsequence/create3/blob/master/contracts/test_utils/Create3Imp.sol
*/
function creationCodeFor(bytes memory _code) internal pure returns (bytes memory) {
/*
0x00 0x63 0x63XXXXXX PUSH4 _code.length size
0x01 0x80 0x80 DUP1 size size
0x02 0x60 0x600e PUSH1 14 14 size size
0x03 0x60 0x6000 PUSH1 00 0 14 size size
0x04 0x39 0x39 CODECOPY size
0x05 0x60 0x6000 PUSH1 00 0 size
0x06 0xf3 0xf3 RETURN
<CODE>
*/
return abi.encodePacked(hex"63", uint32(_code.length), hex"80600E6000396000F3", _code);
}
}
lib/solmate/src/auth/Auth.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}
src/deployer/Create3.sol
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.17;
/**
@title A library for deploying contracts EIP-3171 style.
@author Agustin Aguilar <[email protected]>
*/
library Create3 {
error ErrorCreatingProxy();
error ErrorCreatingContract();
error TargetAlreadyExists();
/**
@notice The bytecode for a contract that proxies the creation of another contract
@dev If this code is deployed using CREATE2 it can be used to decouple `creationCode` from the child contract address
0x67363d3d37363d34f03d5260086018f3:
0x00 0x67 0x67XXXXXXXXXXXXXXXX PUSH8 bytecode 0x363d3d37363d34f0
0x01 0x3d 0x3d RETURNDATASIZE 0 0x363d3d37363d34f0
0x02 0x52 0x52 MSTORE
0x03 0x60 0x6008 PUSH1 08 8
0x04 0x60 0x6018 PUSH1 18 24 8
0x05 0xf3 0xf3 RETURN
0x363d3d37363d34f0:
0x00 0x36 0x36 CALLDATASIZE cds
0x01 0x3d 0x3d RETURNDATASIZE 0 cds
0x02 0x3d 0x3d RETURNDATASIZE 0 0 cds
0x03 0x37 0x37 CALLDATACOPY
0x04 0x36 0x36 CALLDATASIZE cds
0x05 0x3d 0x3d RETURNDATASIZE 0 cds
0x06 0x34 0x34 CALLVALUE val 0 cds
0x07 0xf0 0xf0 CREATE addr
*/
bytes internal constant PROXY_CHILD_BYTECODE =
hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3";
// KECCAK256_PROXY_CHILD_BYTECODE = keccak256(PROXY_CHILD_BYTECODE);
bytes32 internal constant KECCAK256_PROXY_CHILD_BYTECODE =
0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f;
/**
@notice Returns the size of the code on a given address
@param _addr Address that may or may not contain code
@return size of the code on the given `_addr`
*/
function codeSize(address _addr) internal view returns (uint256 size) {
assembly {
size := extcodesize(_addr)
}
}
/**
@notice Creates a new contract with given `_creationCode` and `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@param _creationCode Creation code (constructor) of the contract to be deployed, this value doesn't affect the resulting address
@return addr of the deployed contract, reverts on error
*/
function create3(bytes32 _salt, bytes memory _creationCode) internal returns (address addr) {
return create3(_salt, _creationCode, 0);
}
/**
@notice Creates a new contract with given `_creationCode` and `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@param _creationCode Creation code (constructor) of the contract to be deployed, this value doesn't affect the resulting address
@param _value In WEI of ETH to be forwarded to child contract
@return addr of the deployed contract, reverts on error
*/
function create3(
bytes32 _salt,
bytes memory _creationCode,
uint256 _value
) internal returns (address addr) {
// Creation code
bytes memory creationCode = PROXY_CHILD_BYTECODE;
// Get target final address
addr = addressOf(_salt);
if (codeSize(addr) != 0) revert TargetAlreadyExists();
// Create CREATE2 proxy
address proxy;
assembly {
proxy := create2(0, add(creationCode, 32), mload(creationCode), _salt)
}
if (proxy == address(0)) revert ErrorCreatingProxy();
// Call proxy with final init code
(bool success, ) = proxy.call{value: _value}(_creationCode);
if (!success || codeSize(addr) == 0) revert ErrorCreatingContract();
}
/**
@notice Computes the resulting address of a contract deployed using address(this) and the given `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@return addr of the deployed contract, reverts on error
@dev The address creation formula is: keccak256(rlp([keccak256(0xff ++ address(this) ++ _salt ++ keccak256(childBytecode))[12:], 0x01]))
*/
function addressOf(bytes32 _salt) internal view returns (address) {
address proxy = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
address(this),
_salt,
KECCAK256_PROXY_CHILD_BYTECODE
)
)
)
)
);
return address(uint160(uint256(keccak256(abi.encodePacked(hex"d6_94", proxy, hex"01")))));
}
}Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
":@arbitrum/=lib/token-bridge-contracts/node_modules/@arbitrum/",
":@offchainlabs/=lib/token-bridge-contracts/node_modules/@offchainlabs/",
":@openzeppelin/contracts-upgradeable/=lib/token-bridge-contracts/node_modules/@openzeppelin/contracts-upgradeable/",
":@openzeppelin/contracts/=lib/token-bridge-contracts/node_modules/@openzeppelin/contracts/",
":arbitrum-token-bridge/=lib/token-bridge-contracts/contracts/",
":bitcorn-token/=lib/bitcorn-token/src/",
":corn-standard-solidity/=lib/corn-standard-solidity/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":halmos-cheatcodes/=lib/bitcorn-token/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
":openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
":solmate/=lib/solmate/src/",
":token-bridge-contracts/=lib/token-bridge-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.