Skip to content
Verified contractExactUNLICENSED

Diamond

Address0x50e95f8c19c4c4f260a256a916f80550e3635f80
Balance

0 ETH

 

Transactions

90

 

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
cancun
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,983,986
Creation transaction
0x806aa6bce0…4f7e49ec4a

contracts/router/Diamond.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;

import {IDiamond, IDiamondCut, IDiamondLoupe} from "./interfaces/IDiamond.sol";
import {AccessControlEnumerableFacetStorage} from "./libraries/AccessControlEnumerableFacetStorage.sol";
import {CoreFacetStorage} from "./libraries/CoreFacetStorage.sol";
import {DiamondStorage} from "./libraries/DiamondStorage.sol";


contract Diamond is IDiamond {
    using DiamondStorage for DiamondStorage.DS;
    using CoreFacetStorage for CoreFacetStorage.DS;
    using AccessControlEnumerableFacetStorage for AccessControlEnumerableFacetStorage.DS;

    /// @notice Default admin role identifier (0x00).
    bytes32 private constant DEFAULT_ADMIN_ROLE = 0x00;

    constructor() {
        AccessControlEnumerableFacetStorage.ds().roles[DEFAULT_ADMIN_ROLE].members[msg.sender] = true;
    }

    /// @notice Fallback function to allow the contract to receive ETH.
    /// @dev Triggered when the contract receives ETH without any calldata.
    receive() external payable {}

    /// @notice Delegates calls to the appropriate facet based on function selector.
    /// @dev Uses low-level `delegatecall`. Reverts if no facet implements the selector.
    fallback() external payable {
        address facet = facetAddress(msg.sig);
        if (facet == address(0)) {
            revert FunctionNotFound(msg.sig);
        }
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    /// @inheritdoc IDiamondCut
    function diamondCut(
        FacetCut[] calldata cut,
        address init,
        bytes calldata data
    ) 
        external
    {
        if (!AccessControlEnumerableFacetStorage.ds().roles[DEFAULT_ADMIN_ROLE].members[msg.sender]) {
            revert UnauthorizedCaller();
        }
        if (cut.length == 0) {
            revert EmptyCut();
        }
        DiamondStorage.DS storage ds = DiamondStorage.ds();
        for (uint256 i = 0; i < cut.length; ++i) {
            FacetCutAction action = cut[i].action;
            if (action == FacetCutAction.Add) {
                _addFunctions(ds, cut[i].facetAddress, cut[i].functionSelectors);
            } else if (action == FacetCutAction.Replace) {
                _replaceFunctions(ds, cut[i].facetAddress, cut[i].functionSelectors);
            } else if (action == FacetCutAction.Remove) {
                _removeFunctions(ds, cut[i].functionSelectors);
            } else {
                revert UnknownFacetCutAction();
            }
        }
        emit DiamondCut(cut, init, data);
        if (init != address(0)) {
            if (init.code.length == 0) {
                revert InitHasNoCode();
            }
            (bool success, bytes memory result) = init.delegatecall(data);
            if (!success) assembly {
                revert(add(result, 32), mload(result))
            }
        }
    }

    /// @inheritdoc IDiamondLoupe
    function facetFunctionSelectors(address facet) external view returns (bytes4[] memory) {
        return DiamondStorage.ds().facetToSelectors[facet];
    }

    /// @inheritdoc IDiamondLoupe
    function facetAddresses() external view returns (address[] memory) {
        return DiamondStorage.ds().facets;
    }

    /// @inheritdoc IDiamondLoupe
    function facets() external view returns (Facet[] memory res) {
        DiamondStorage.DS storage ds = DiamondStorage.ds();
        uint256 count = ds.facets.length;
        res = new Facet[](count);
        for (uint256 i = 0; i < count; ++i) {
            address facet = ds.facets[i];
            res[i].facetAddress = facet;
            res[i].functionSelectors = ds.facetToSelectors[facet];
        }
    }

    /// @inheritdoc IDiamondLoupe
    function facetAddress(bytes4 selector) public view override returns (address) {
        return DiamondStorage.ds().selectorToFacet[selector];
    }

    /// @notice Registers new function selectors and maps them to a facet.
    /// @dev O(n) over `selectors`. Reverts: `FacetNotFound` (zero facet), `SelectorAlreadyExists` (selector mapped).
    /// @param ds Reference to Dispatcher storage struct.
    /// @param facet Facet address to assign selectors to.
    /// @param selectors Selectors to register.
    function _addFunctions(
        DiamondStorage.DS storage ds,
        address facet,
        bytes4[] calldata selectors
    ) 
        private 
    {
        if (facet == address(0)) {
            revert FacetNotFound();
        }
        if (selectors.length == 0) {
            revert EmptySelectors();
        }
        if (ds.facetIndex[facet] == 0) {
            ds.facets.push(facet);
            ds.facetIndex[facet] = ds.facets.length;
        }
        for (uint256 i = 0; i < selectors.length; ++i) {
            bytes4 selector = selectors[i];
            if (ds.selectorToFacet[selector] != address(0)) {
                revert SelectorAlreadyExists();
            }
            ds.selectorToFacet[selector] = facet;
            ds.facetToSelectors[facet].push(selector);
        }
    }

    /// @notice Replaces existing selectors with a new facet.
    /// @dev O(n). Reverts: `FacetNotFound` (zero facet), `SelectorAbsent` (selector missing), `SameFacet` (already mapped).
    /// @param ds Dispatcher storage.
    /// @param facet New facet address.
    /// @param selectors Selectors to replace.
    function _replaceFunctions(
        DiamondStorage.DS storage ds,
        address facet,
        bytes4[] calldata selectors
    ) 
        private 
    {
        if (facet == address(0)) {
            revert FacetNotFound();
        }
        if (selectors.length == 0) {
            revert EmptySelectors();
        }
        if (ds.facetIndex[facet] == 0) {
            ds.facets.push(facet);
            ds.facetIndex[facet] = ds.facets.length;
        }
        for (uint256 i = 0; i < selectors.length; ++i) {
            bytes4 selector = selectors[i];
            address oldFacet = ds.selectorToFacet[selector];
            if (oldFacet == address(0)) {
                revert SelectorAbsent();
            }
            if (oldFacet == facet) {
                revert SameFacet();
            }
            _unlinkSelector(ds, oldFacet, selector);
            ds.selectorToFacet[selector] = facet;
            ds.facetToSelectors[facet].push(selector);
        }
    }

    /// @notice Removes selectors from the dispatcher.
    /// @dev O(n). Reverts `SelectorAbsent` if selector not registered. Deletes facet if last selector removed.
    /// @param ds Dispatcher storage.
    /// @param selectors Selectors to remove.
    function _removeFunctions(
        DiamondStorage.DS storage ds,
        bytes4[] calldata selectors
    ) 
        private 
    {
        if (selectors.length == 0) {
            revert EmptySelectors();
        }
        for (uint256 i = 0; i < selectors.length; ++i) {
            bytes4 selector = selectors[i];
            address oldFacet = ds.selectorToFacet[selector];
            if (oldFacet == address(0)) {
                revert SelectorAbsent();
            }
            _unlinkSelector(ds, oldFacet, selector);
            delete ds.selectorToFacet[selector];
        }
    }

    /// @notice Detaches a selector from its facet and prunes facet if empty.
    /// @dev O(n) over facet’s selector list.
    /// @param ds Dispatcher storage.
    /// @param facet Facet address.
    /// @param selector Selector to unlink.
    function _unlinkSelector(
        DiamondStorage.DS storage ds,
        address facet,
        bytes4 selector
    ) 
        private 
    {
        bytes4[] storage selectors = ds.facetToSelectors[facet];
        uint256 length = selectors.length;
        for (uint256 i = 0; i < length; ++i) {
            if (selectors[i] == selector) {
                selectors[i] = selectors[length - 1];
                selectors.pop();
                break;
            }
        }
        if (selectors.length == 0) {
            uint256 currentIndex = ds.facetIndex[facet] - 1;
            uint256 lastIndex = ds.facets.length - 1;
            if (currentIndex != lastIndex) {
                address lastFacet = ds.facets[lastIndex];
                ds.facets[currentIndex] = lastFacet;
                ds.facetIndex[lastFacet] = currentIndex + 1;
            }
            ds.facets.pop();
            delete ds.facetIndex[facet];
        }
    }
}

@openzeppelin/contracts/utils/Counters.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

contracts/router/interfaces/IDiamond.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;

import {IDiamondCut} from "./IDiamondCut.sol";
import {IDiamondLoupe} from "./IDiamondLoupe.sol";


interface IDiamond is IDiamondCut, IDiamondLoupe {
    /// @notice Thrown when an ETH transfer is attempted from an unauthorized sender.
    /// @param sender The address that tried to send ETH.
    error InvalidEthSender(address sender);

    /// @notice Thrown when trying to route a call with a selector that is not registered.
    /// @param selector The function selector that was not found.
    error FunctionNotFound(bytes4 selector);

    /// @notice Thrown when the provided facet address has no code.
    error InitHasNoCode();

    /// @notice Thrown when a facet address is zero during add or replace operation.
    error FacetNotFound();

    /// @notice Thrown when attempting to add a function selector that already exists.
    error SelectorAlreadyExists();

    /// @notice Thrown when trying to replace or remove a selector that does not exist.
    error SelectorAbsent();

    /// @notice Thrown when trying to replace a selector with the same facet it already belongs to.
    error SameFacet();

    /// @notice Thrown when an unknown `FacetCutAction` is passed to the `diamondCut` function.
    error UnknownFacetCutAction();

    /// @notice Thrown when `diamondCut` is called with an empty array.
    error EmptyCut();

    /// @notice Thrown when an empty selector array is passed to add/replace helpers.
    error EmptySelectors();

    /// @notice Thrown when the caller is not authorized to perform the action.
    error UnauthorizedCaller();
}

contracts/router/interfaces/IDiamondCut.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;


interface IDiamondCut {
    /// @notice Enum describing the type of facet cut operation.
    /// @dev Used in `diamondCut` to define how selectors should be applied.
    enum FacetCutAction {
        Add, // Add new selectors
        Replace, // Replace existing selectors with new facet implementation
        Remove // Remove selectors from the diamond
    }

    /// @notice Struct representing a single change to the diamond's function selector table.
    /// @param facetAddress The address of the facet to which the selectors will be added or replaced.
    /// Must be zero address if action is Remove.
    /// @param action The type of operation (Add, Replace, Remove).
    /// @param functionSelectors The list of function selectors to apply.
    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    /// @notice Emitted when the diamond is updated via `diamondCut`.
    /// @param cut The list of facet changes applied.
    /// @param init The address of the initialization contract (if any).
    /// @param data The calldata passed to `init` via delegatecall after the cut.
    event DiamondCut(FacetCut[] cut, address init, bytes data);

    /// @notice Performs add/replace/remove operations on function selectors.
    /// @dev Follows the EIP-2535 `diamondCut` standard. Can optionally delegatecall an init function.
    /// @param cut The array of facet changes to apply.
    /// @param init The address of a contract with an initializer function (optional).
    /// @param data The calldata to pass to the initializer via delegatecall (optional).
    function diamondCut(FacetCut[] calldata cut, address init, bytes calldata data) external;
}

contracts/router/interfaces/IDiamondLoupe.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;


interface IDiamondLoupe {
    /// @notice Struct returned by loupe functions to inspect facets and their selectors.
    /// @param facetAddress The address of the facet.
    /// @param functionSelectors The list of selectors implemented by this facet.
    struct Facet {
        address facetAddress;
        bytes4[] functionSelectors;
    }

    /// @notice Returns all facet addresses and the selectors they implement.
    /// @dev Used by tooling and scanners to inspect the structure of the diamond.
    /// @return An array of all facets with their function selectors.
    function facets() external view returns (Facet[] memory);

    /// @notice Returns the list of selectors for a given facet address.
    /// @param facet The address of the facet to inspect.
    /// @return The list of function selectors implemented by the facet.
    function facetFunctionSelectors(address facet) external view returns (bytes4[] memory);

    /// @notice Returns all unique facet addresses used by the diamond.
    /// @return An array of all facet addresses currently active in the diamond.
    function facetAddresses() external view returns (address[] memory);

    /// @notice Returns the facet address responsible for a specific selector.
    /// @param selector The function selector to lookup.
    /// @return The address of the facet that implements the selector, or address(0) if none.
    function facetAddress(bytes4 selector) external view returns (address);
}

contracts/router/libraries/AccessControlEnumerableFacetStorage.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2026 - all rights reserved
pragma solidity 0.8.25;

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";


library AccessControlEnumerableFacetStorage {
    using EnumerableSet for EnumerableSet.AddressSet;

    /// @notice Fixed storage slot for the AccessControlEnumerableFacet data structure.
    bytes32 private constant POSITION = keccak256("crosscurve.access.control.enumerable.storage");

    /// @notice Structure representing a role and its associated data.
    /// @dev Each role stores its members and the admin role that controls it.
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    /// @notice Layout for all persistent AccessControlEnumerableFacet state.  
    /// @dev Every variable needed by AccessControlEnumerableFacet logic is grouped here and kept
    /// at the single slot defined in `POSITION`.
    struct DS {
        mapping(bytes32 => RoleData) roles;
        mapping(bytes32 => EnumerableSet.AddressSet) roleMembers;
    }

    /// @notice Accessor to the AccessControlEnumerableFacet storage struct.
    /// @dev Assembly ties the returned reference to the predefined slot so the
    /// compiler understands where the struct actually lives in storage.
    /// @return s Pointer to the `DS` struct residing at `POSITION`.
    function ds() internal pure returns (DS storage s) {
        bytes32 pos = POSITION;
        assembly {
            s.slot := pos
        }
    }
}

contracts/router/libraries/CoreFacetStorage.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;

import "@openzeppelin/contracts/utils/Counters.sol";

/// @notice Structure with information about cross-chain transaction delivery.
/// @param hashSynthParams hash from the parameters of a successfully delivered cross-chain transaction.
/// @param crossChainOpState cross-chain transaction delivery status.
struct ProcessedOps {
    bytes32 hashSynthParams;
    uint8 crossChainOpState;
}

library CoreFacetStorage {
    /// @notice Fixed storage slot for the CoreFacet data structure.
    bytes32 private constant POSITION = keccak256("crosscurve.core.facet.storage");

    /// @notice Slot for the currentRequestId.
    /// @dev keccak256("crosscurve.core.facet.transient.currentRequestId");
    bytes32 private constant CURRENT_REQUEST_ID_POS = 0x4c0fc00f7060fb51f491b90bbb038205c36b6fbc6a8aed52d27b18d2967b53f4;

    /// @notice Slot for the currentChainIdFrom.
    /// @dev keccak256("crosscurve.core.facet.transient.currentChainIdFrom");
    bytes32 private constant CURRENT_CHAIN_ID_FROM_POS = 0x67b6f0fb6bca8398a49a7966c252819542f4d36560c9c6961937957fdf20f9f4;

    /// @notice Slot for the currentChainIdFrom.
    /// @dev keccak256("crosscurve.core.facet.transient.currentFrom");
    bytes32 private constant CURRENT_FROM_POS = 0x4cc96c0e8d76f46bce6654a01678006157b186dbd2a67f088c50d86a77976fbb;

    /// @notice Slot for the isOriginNetwork.
    /// @dev keccak256("crosscurve.core.facet.transient.isOriginNetwork");
    bytes32 private constant IS_ORIGIN_NETWORK_POS = 0xb13bd13498ce9409b85a4287d16ff0fcdaca732822a47a97d2bdada3325aa451;

    /// @notice Slot for the isDiamondCall.
    /// @dev keccak256("crosscurve.core.facet.transient.isDiamondCall");
    bytes32 private constant IS_DIAMOND_CALL = 0x2e445143a211ecbb689de5812742d02a96369c482aec76832fc56490cf3cc6f2;

    /// @notice Slot for the isReentrancyLocked.
    /// @dev keccak256("crosscurve.core.facet.transient.isReentrancyLocked");
    bytes32 private constant IS_REENTRANCY_LOCKED = 0x1e0578bb15c7ba996e367f5cb2606a2c0e49f47e3ec9ce25487e41761d562498;

    /// @notice Slot for msgValueLeft budget (origin start only).
    /// @dev keccak256("crosscurve.core.facet.transient.msgValueLeft");
    bytes32 private constant MSG_VALUE_LEFT_POS = 0x7f3e5ed8ce4a8806c618eaa07afc27516c5c690793b80b8262a28aa8675561fc;

    /// @notice Slot for the transient flag that enables msg.value budget accounting.
    /// @dev Stored in EIP-1153 transient storage (tstore/tload).
    ///      When enabled, facets must treat ETH forwarding as spending from the shared per-tx budget
    ///      tracked in {MSG_VALUE_LEFT_POS} via {consumeMsgValue}.
    ///      Used by resume/tail execution (e.g. Break.resumeBr) to prevent multiple ops from
    ///      reusing the same msg.value during delegatecall-based pipelines.
    bytes32 private constant IS_MSG_VALUE_BUDGET_ENABLED_POS = 0xaa921bbd9582456f18c5d5c77ea6f144a03ee74848adceca2809b778dd306508;

    /// @notice Thrown when an op tries to spend more ETH than was provided in msg.value for the whole start().
    error MsgValueBudgetExceeded(uint256 requested, uint256 left);

    /// @notice Layout for all persistent CoreFacet state.  
    /// @dev Every variable needed by CoreFacet logic is grouped here and kept
    /// at the single slot defined in `POSITION`.
    struct DS {
        mapping(address => Counters.Counter) nonces;
        mapping(bytes32 => bytes32) startedOps;
        mapping(bytes32 => ProcessedOps) processedOps;
        address addressBook;
        address treasury;
        address WETH;
    }

    /// @notice Accessor to the CoreFacet storage struct.
    /// @dev Assembly ties the returned reference to the predefined slot so the
    /// compiler understands where the struct actually lives in storage.
    /// @return s Pointer to the `DS` struct residing at `POSITION`.
    function ds() internal pure returns (DS storage s) {
        bytes32 pos = POSITION;
        assembly {
            s.slot := pos
        }
    }

    function setCurrentRequestId(bytes32 currentRequestId_) internal {
        assembly ("memory-safe") {
            tstore(CURRENT_REQUEST_ID_POS, currentRequestId_)
        }
    }

    function currentRequestId() internal view returns (bytes32 currentRequestId_) {
        assembly ("memory-safe") {
            currentRequestId_ := tload(CURRENT_REQUEST_ID_POS)
        }
    }

    function setCurrentChainIdFrom(uint64 currentChainIdFrom_) internal {
        assembly ("memory-safe") {
            tstore(CURRENT_CHAIN_ID_FROM_POS, currentChainIdFrom_)
        }
    }

    function currentChainIdFrom() internal view returns (uint64 currentChainIdFrom_) {
        assembly ("memory-safe") {
            currentChainIdFrom_ := tload(CURRENT_CHAIN_ID_FROM_POS)
        }
    }

    function setCurrentFrom(address currentFrom_) internal {
        assembly ("memory-safe") {
            tstore(CURRENT_FROM_POS, currentFrom_)
        }
    }

    function currentFrom() internal view returns (address currentFrom_) {
        assembly ("memory-safe") {
            currentFrom_ := tload(CURRENT_FROM_POS)
        }
    }

    function setOriginNetwork(bool isOriginNetwork_) internal {
        assembly ("memory-safe") {
            tstore(IS_ORIGIN_NETWORK_POS, isOriginNetwork_)
        }
    }

    function isOriginNetwork() internal view returns (bool isOriginNetwork_) {
        assembly ("memory-safe") {
            isOriginNetwork_ := tload(IS_ORIGIN_NETWORK_POS)
        }
    }

    function setDiamondCall(bool isDiamondCall_) internal {
        assembly ("memory-safe") {
            tstore(IS_DIAMOND_CALL, isDiamondCall_)
        }
    }

    function isDiamondCall() internal view returns (bool isDiamondCall_) {
        assembly ("memory-safe") {
            isDiamondCall_ := tload(IS_DIAMOND_CALL)
        }
    }

    function setReentrancyLock(bool isLocked_) internal {
        assembly ("memory-safe") {
            tstore(IS_REENTRANCY_LOCKED, isLocked_)
        }
    }

    function isReentrancyLocked() internal view returns (bool isLocked_) {
        assembly ("memory-safe") {
            isLocked_ := tload(IS_REENTRANCY_LOCKED)
        }
    }

    function setMsgValueLeft(uint256 msgValueLeft_) internal {
        assembly ("memory-safe") {
            tstore(MSG_VALUE_LEFT_POS, msgValueLeft_)
        }
    }

    function msgValueLeft() internal view returns (uint256 msgValueLeft_) {
        assembly ("memory-safe") {
            msgValueLeft_ := tload(MSG_VALUE_LEFT_POS)
        }
    }

    function setMsgValueBudgetEnabled(bool enabled) internal {
        assembly ("memory-safe") {
            tstore(IS_MSG_VALUE_BUDGET_ENABLED_POS, enabled)
        }
    }

    function isMsgValueBudgetEnabled() internal view returns (bool enabled) {
        assembly ("memory-safe") {
            enabled := tload(IS_MSG_VALUE_BUDGET_ENABLED_POS)
        }
    }

    function consumeMsgValue(uint256 amount) internal {
        uint256 left;
        assembly ("memory-safe") {
            left := tload(MSG_VALUE_LEFT_POS)
        }
        if (amount > left) {
            revert MsgValueBudgetExceeded(amount, left);
        }
        unchecked {
            left -= amount;
        }
        assembly ("memory-safe") {
            tstore(MSG_VALUE_LEFT_POS, left)
        }
    }
}

contracts/router/libraries/DiamondStorage.sol

// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2025 - all rights reserved
pragma solidity 0.8.25;


library DiamondStorage {
    /// @notice Fixed storage slot for the Diamond data structure.
    bytes32 private constant POSITION = keccak256("crosscurve.diamond.storage");

    /// @notice Layout for all persistent Diamond state.  
    /// @dev Every variable needed by Diamond logic is grouped here and kept
    /// at the single slot defined in `POSITION`.
    struct DS {
        mapping(bytes4 => address) selectorToFacet;
        mapping(address => bytes4[]) facetToSelectors;
        address[] facets;
        mapping(address => uint256) facetIndex;
    }

    /// @notice Accessor to the Diamond storage struct.
    /// @dev Assembly ties the returned reference to the predefined slot so the
    /// compiler understands where the struct actually lives in storage.
    /// @return s Pointer to the `DS` struct residing at `POSITION`.
    function ds() internal pure returns (DS storage s) {
        bytes32 pos = POSITION;
        assembly {
            s.slot := pos
        }
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.