Verified contractPartialMIT
MoistAdapterRegistryV2
Address0x63c20ebf3262ef90640c4f4fab472ddbcc322774
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.36
- Same code
Only this contract
Details
- Compiler
- solc 0.8.36+commit.8a079791
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,186,270
- Creation transaction
- 0x1c9eafdd11…054e908547
contracts/MoistAdapterRegistryV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @notice Upgradeable registry mapping adapter identifiers to adapter contracts.
/// @dev V2 adds enumerable adapter ids; routes registered under V1 are
/// backfilled into `adapterIds` by the next `setRoute` for that id.
contract MoistAdapterRegistryV2 {
struct Route {
address destination;
bool enabled;
}
/// @custom:storage-location erc7201:moistly.storage.MoistAdapterRegistry
struct RegistryStorage {
address owner;
address pendingOwner;
address fallbackDestination;
bool initialized;
mapping(bytes32 => Route) routes;
bytes32[] adapterIds;
mapping(bytes32 => uint256) adapterIndexPlusOne;
}
bytes32 private constant REGISTRY_STORAGE_SLOT =
0x0eb8885828e9c5817772d6d310ca04d1b8713be1f7cde18a88252dfab8dd8100;
error AlreadyInitialized();
error InvalidAddress();
error InvalidCalldata();
error RouteNotFound(bytes32 adapterId);
error Unauthorized(address caller);
event Initialized(address indexed owner);
event RouteUpdated(bytes32 indexed adapterId, address indexed destination, bool enabled);
event FallbackUpdated(address indexed previousDestination, address indexed newDestination);
event OwnershipTransferStarted(address indexed previousOwner, address indexed pendingOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_registryStorage().initialized = true;
}
modifier onlyOwner() {
if (msg.sender != _registryStorage().owner) revert Unauthorized(msg.sender);
_;
}
/// @notice Initializes proxy storage and assigns its first owner.
/// @dev Must be supplied atomically to the proxy constructor in production.
function initialize(address initialOwner) external {
RegistryStorage storage state = _registryStorage();
if (state.initialized) revert AlreadyInitialized();
if (initialOwner == address(0)) revert InvalidAddress();
state.initialized = true;
state.owner = initialOwner;
emit Initialized(initialOwner);
emit OwnershipTransferred(address(0), initialOwner);
}
/// @notice Returns the address authorized to administer routes.
function owner() external view returns (address) {
return _registryStorage().owner;
}
/// @notice Returns the address nominated to accept ownership.
function pendingOwner() external view returns (address) {
return _registryStorage().pendingOwner;
}
/// @notice Returns the fallback destination used when no adapter route is enabled.
function fallbackDestination() external view returns (address) {
return _registryStorage().fallbackDestination;
}
/// @notice Returns the configured destination and enabled state for an adapter id.
function route(bytes32 adapterId) external view returns (address destination, bool enabled) {
Route storage configured = _registryStorage().routes[adapterId];
return (configured.destination, configured.enabled);
}
/// @notice Resolves an adapter id to its enabled route or the configured fallback.
function resolve(bytes32 adapterId) public view returns (address destination) {
RegistryStorage storage state = _registryStorage();
Route storage configured = state.routes[adapterId];
if (configured.enabled) return configured.destination;
destination = state.fallbackDestination;
if (destination == address(0)) revert RouteNotFound(adapterId);
}
/// @notice Resolves an adapter identified by a human-readable label such as "across.base".
function resolveLabel(string calldata label) external view returns (address destination) {
return resolve(keccak256(bytes(label)));
}
/// @notice Hashes calldata into an adapter id and resolves it.
function resolveCalldata(bytes calldata data) external view returns (address destination) {
if (data.length < 32) revert InvalidCalldata();
return resolve(keccak256(data));
}
/// @notice Returns every adapter id that currently has a configured route.
function adapterIds() external view returns (bytes32[] memory ids) {
return _registryStorage().adapterIds;
}
/// @notice Returns the number of enumerated adapter ids.
function adapterCount() external view returns (uint256) {
return _registryStorage().adapterIds.length;
}
/// @notice Returns the adapter id at a given enumeration index.
function adapterIdAt(uint256 index) external view returns (bytes32) {
return _registryStorage().adapterIds[index];
}
/// @notice Creates, updates, disables, or removes an adapter route.
/// @dev Enabled destinations must contain deployed contract code. Passing
/// `address(0)` with `enabled=false` removes the route entirely.
function setRoute(bytes32 adapterId, address destination, bool enabled) external onlyOwner {
_setRoute(adapterId, destination, enabled);
}
/// @notice Convenience wrapper registering `keccak256(bytes(label))` as the adapter id.
function setRouteLabel(string calldata label, address destination, bool enabled)
external
onlyOwner
{
_setRoute(keccak256(bytes(label)), destination, enabled);
}
/// @notice Sets the fallback destination; use the zero address to disable fallback routing.
function setFallback(address destination) external onlyOwner {
if (destination != address(0) && destination.code.length == 0) revert InvalidAddress();
RegistryStorage storage state = _registryStorage();
address previous = state.fallbackDestination;
state.fallbackDestination = destination;
emit FallbackUpdated(previous, destination);
}
/// @notice Nominates a new owner, who must call `acceptOwnership`.
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert InvalidAddress();
RegistryStorage storage state = _registryStorage();
state.pendingOwner = newOwner;
emit OwnershipTransferStarted(state.owner, newOwner);
}
/// @notice Accepts ownership from the currently configured pending owner.
function acceptOwnership() external {
RegistryStorage storage state = _registryStorage();
if (msg.sender != state.pendingOwner) revert Unauthorized(msg.sender);
address previous = state.owner;
state.owner = msg.sender;
state.pendingOwner = address(0);
emit OwnershipTransferred(previous, msg.sender);
}
/// @notice Returns the registry implementation API version.
function version() external pure virtual returns (uint256) {
return 2;
}
/// @dev Applies a route update and maintains the adapter id enumeration.
function _setRoute(bytes32 adapterId, address destination, bool enabled) private {
if (enabled && (destination == address(0) || destination.code.length == 0)) {
revert InvalidAddress();
}
RegistryStorage storage state = _registryStorage();
state.routes[adapterId] = Route(destination, enabled);
if (destination == address(0) && !enabled) {
_removeAdapterId(state, adapterId);
} else {
_addAdapterId(state, adapterId);
}
emit RouteUpdated(adapterId, destination, enabled);
}
/// @dev Appends an adapter id to the enumeration if not already present.
function _addAdapterId(RegistryStorage storage state, bytes32 adapterId) private {
if (state.adapterIndexPlusOne[adapterId] != 0) return;
state.adapterIds.push(adapterId);
state.adapterIndexPlusOne[adapterId] = state.adapterIds.length;
}
/// @dev Removes an adapter id from the enumeration via swap-and-pop.
function _removeAdapterId(RegistryStorage storage state, bytes32 adapterId) private {
uint256 indexPlusOne = state.adapterIndexPlusOne[adapterId];
if (indexPlusOne == 0) return;
uint256 index = indexPlusOne - 1;
uint256 lastIndex = state.adapterIds.length - 1;
if (index != lastIndex) {
bytes32 lastId = state.adapterIds[lastIndex];
state.adapterIds[index] = lastId;
state.adapterIndexPlusOne[lastId] = indexPlusOne;
}
state.adapterIds.pop();
delete state.adapterIndexPlusOne[adapterId];
}
/// @dev Returns the ERC-7201 registry storage namespace.
function _registryStorage() private pure returns (RegistryStorage storage state) {
bytes32 slot = REGISTRY_STORAGE_SLOT;
assembly {
state.slot := slot
}
}
}
Compiler settingsShow
{
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": [
"@arbitrum/=node_modules/@arbitrum/",
"@ensdomains/=contracts/v4-core/node_modules/@ensdomains/",
"@eth-optimism/=lib/unruggable-gateways/lib/optimism/packages/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/messagelib/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
"@offchainlabs/=node_modules/@offchainlabs/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/=node_modules/@uniswap/",
"base64-sol/=node_modules/base64-sol/",
"create3-factory/=lib/create3-factory/",
"devtools/=lib/devtools/",
"ds-test/=contracts/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"flap/=contracts/flap/",
"forge-std-1.16.2/=dependencies/forge-std-1.16.2/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=contracts/v4-core/node_modules/hardhat/",
"interfaces/=contracts/interfaces/",
"layerzero-v2/=lib/layerzero-v2/",
"libraries/=contracts/libraries/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"optimism/=lib/unruggable-gateways/lib/optimism/packages/contracts-bedrock/src/",
"solady/=node_modules/solady/",
"solidity-bytes-utils/=lib/solidity-bytes-utils/",
"solmate/=contracts/v4-core/lib/solmate/",
"splits-contracts-monorepo/=contracts/splits-contracts-monorepo/src/",
"unruggable-gateways/=lib/unruggable-gateways/contracts/",
"v4-core/=contracts/v4-core/src/",
"vault/=contracts/vault/",
"contracts/v4-core/:openzeppelin-contracts/=contracts/v4-core/lib/openzeppelin-contracts/",
"contracts/v4-core/:solmate/=contracts/v4-core/lib/solmate/",
"contracts/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=contracts/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"contracts/v4-core/lib/solmate/:ds-test/=contracts/v4-core/lib/solmate/lib/ds-test/src/",
"lib/create3-factory/:solmate/=lib/create3-factory/lib/solmate/src/",
"lib/create3-factory/lib/forge-std/:ds-test/=lib/create3-factory/lib/forge-std/lib/ds-test/src/",
"lib/create3-factory/lib/solmate/:ds-test/=lib/create3-factory/lib/solmate/lib/ds-test/src/",
"lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"lib/openzeppelin-contracts-upgradeable/:openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/unruggable-gateways/:openzeppelin-contracts/=lib/unruggable-gateways/lib/openzeppelin-contracts/",
"lib/unruggable-gateways/lib/openzeppelin-contracts/:erc4626-tests/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"node_modules/@arbitrum/chain-actions/lib/forge-std/:ds-test/=node_modules/@arbitrum/chain-actions/lib/forge-std/lib/ds-test/",
"node_modules/@arbitrum/token-bridge-contracts/:@arbitrum/nitro-contracts/=node_modules/@arbitrum/token-bridge-contracts/node_modules/@arbitrum/nitro-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.