Verified contractPartialMIT
AddressLookup
Address0x6add49a791ff1dddcd91f0afcb70cd91c81821ca
- Balance
0 ETH
- Transactions
5
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,694,386
- Creation transaction
- 0xbe9666ba9c…a2aeb2cc68
5 files
- src/AddressLookup.solmain2.28 KB
- lib/clones/Clones.sol3.33 KB
- lib/ilookup/IAddressLookup.sol495 B
- lib/ilookup/IMaker.sol363 B
- lib/ilookup/IUintToAddressMaker.sol1.07 KB
src/AddressLookup.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {IAddressLookup} from "ilookup/IAddressLookup.sol";
import {IUintToAddressMaker} from "ilookup/IUintToAddressMaker.sol";
import {Clones} from "clones/Clones.sol";
/// @notice Immutably map a single predictable contract address to a chain specific address.
/// The same contract deployed to the same address on different chains can return
/// different values based on the chain ID.
/// @dev Deterministic deployment provides a trustless reference with no governance or upgrade risk.
/// Contracts, SDKs, and UIs can hardcode one address and resolve everywhere.
/// Typical uses include cross-chain endpoints (oracles, messengers, executors), wallets,
/// bridges, and explorers that require a single uniform reference across chains.
/// @dev The implementation is also a factory, allowing anyone to easily deploy an AddressLookups.
contract AddressLookup is IAddressLookup, IUintToAddressMaker {
address public immutable PROTO = address(this);
/// @inheritdoc IAddressLookup
address public value;
/// @inheritdoc IUintToAddressMaker
function made(KeyValue[] memory keyValues) public view returns (bool exists, address home, bytes32 salt) {
salt = keccak256(abi.encode(keyValues));
home = Clones.predictDeterministicAddress(PROTO, salt, PROTO);
exists = home.code.length > 0;
}
/// @inheritdoc IUintToAddressMaker
function make(KeyValue[] memory keyValues) public returns (address home) {
bool exists;
bytes32 salt;
(exists, home, salt) = made(keyValues);
if (!exists) {
address value_;
for (uint256 i; i < keyValues.length; ++i) {
if (keyValues[i].key == block.chainid) {
value_ = keyValues[i].value;
break;
}
}
Clones.cloneDeterministic(address(this), salt, 0);
AddressLookup(home).zzInit(value_);
emit Made(home, salt);
}
}
/// @dev Only PROTO should call zzInit.
/// @param value_ The value address for the current chain.
function zzInit(address value_) public {
if (msg.sender != PROTO) revert Unauthorized();
value = value_;
}
}
lib/clones/Clones.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/Clones.sol)
pragma solidity ^0.8.30;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[ERC-1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* This is a stripped-down version of OpenZeppelin's Clones library (v5.3.0), containing only
* deterministic CREATE2 deployment functions with explicit value parameter support.
* The following functions have been removed: clone(), and the overloads of cloneDeterministic()
* and predictDeterministicAddress() that omit the value or deployer parameters.
*
* Original source: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.3.0/contracts/proxy/Clones.sol
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
* the clones cannot be deployed twice at the same address.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministic(
address implementation,
bytes32 salt,
uint256 value
) internal returns (address instance) {
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(
0x00,
or(
shr(0xe8, shl(0x60, implementation)),
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000
)
)
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(
0x20,
or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)
)
instance := create2(value, 0x09, 0x37, salt)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := and(
keccak256(add(ptr, 0x43), 0x55),
0xffffffffffffffffffffffffffffffffffffffff
)
}
}
}
lib/ilookup/IAddressLookup.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
/**
* @notice Map a single predictable contract address to a chain-specific address.
*/
/**
* @dev This deterministic lookup pattern enables the creation of immutable contracts
* at deterministic addresses even if they depend on initialization data that varies by chain.
*/
interface IAddressLookup {
/**
* @return local address for the current chain.
*/
function value() external view returns (address local);
}
lib/ilookup/IMaker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
/**
* @notice Events and errors for makers.
*/
interface IMaker {
/**
* @notice Emit when something is made.
*/
event Made(address indexed home, bytes32 indexed salt);
/**
* @notice Revert if someone tries to reinitialize something made.
*/
error Unauthorized();
}
lib/ilookup/IUintToAddressMaker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {IMaker} from "./IMaker.sol";
/**
* @notice Make a lookup mapping uint256 to address.
*/
interface IUintToAddressMaker is IMaker {
/**
* @notice Map a key to a value.
*/
struct KeyValue {
uint256 key;
address value;
}
/**
* @notice Predict the address of a lookup.
* @param keyValues The array of key value pairs sorted by key.
* @return exists Whether the lookup already exists.
* @return home The predicted address of the lookup.
* @return salt The salt used to create the lookup. salt = keccak256(abi.encode(keyValues));
*/
function made(KeyValue[] memory keyValues) external view returns (bool exists, address home, bytes32 salt);
/**
* @notice Create a lookup if it doesn't already exist.
* @param keyValues The array of key value pairs sorted by key.
* @return home The address of the new or existing lookup.
*/
function make(KeyValue[] memory keyValues) external returns (address home);
}
Compiler settingsShow
{
"debug": {
"revertStrings": "default"
},
"viaIR": true,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"crucible/=lib/crucible/",
"ilookup/=lib/ilookup/",
"clones/=lib/clones/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.