Skip to content
Verified contractPartialLicenseRef-BUSL

HubConfigurator

Address0x2207f01e4eae1ade3339b96b11f01aa3c196d3a2
Balance

0 ETH

 

Transactions

8

 

Compiler

solc 0.8.28

 

Same code

3 more contracts

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 44,444,444 runs
EVM version
cancun
License
LicenseRef-BUSL
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,386,082
Creation transaction
0x466e4db5f2…d1d0629a79
Main copy (most transactions)
0xa0ed3ecc…30d77b70

src/hub/HubConfigurator.sol

// SPDX-License-Identifier: LicenseRef-BUSL
pragma solidity 0.8.28;

import {IERC20Metadata} from 'src/dependencies/openzeppelin/IERC20Metadata.sol';
import {AccessManaged} from 'src/dependencies/openzeppelin/AccessManaged.sol';
import {SafeCast} from 'src/dependencies/openzeppelin/SafeCast.sol';
import {IHub} from 'src/hub/interfaces/IHub.sol';
import {IHubConfigurator} from 'src/hub/interfaces/IHubConfigurator.sol';

/// @title HubConfigurator
/// @author Aave Labs
/// @notice Handles administrative functions on the Hub.
/// @dev Must be granted permission by the Hub.
contract HubConfigurator is AccessManaged, IHubConfigurator {
  using SafeCast for uint256;

  /// @dev Constructor.
  /// @param authority_ The address of the authority contract which manages permissions.
  constructor(address authority_) AccessManaged(authority_) {
    require(authority_ != address(0), InvalidAddress());
  }

  /// @inheritdoc IHubConfigurator
  function addAsset(
    address hub,
    address underlying,
    address feeReceiver,
    uint256 liquidityFee,
    address irStrategy,
    bytes calldata irData
  ) external restricted returns (uint256) {
    IHub targetHub = IHub(hub);
    uint256 assetId = targetHub.addAsset(
      underlying,
      IERC20Metadata(underlying).decimals(),
      feeReceiver,
      irStrategy,
      irData
    );
    _updateLiquidityFee(targetHub, assetId, liquidityFee);
    return assetId;
  }

  /// @inheritdoc IHubConfigurator
  function addAssetWithDecimals(
    address hub,
    address underlying,
    uint8 decimals,
    address feeReceiver,
    uint256 liquidityFee,
    address irStrategy,
    bytes calldata irData
  ) external restricted returns (uint256) {
    IHub targetHub = IHub(hub);
    uint256 assetId = targetHub.addAsset(underlying, decimals, feeReceiver, irStrategy, irData);
    _updateLiquidityFee(targetHub, assetId, liquidityFee);
    return assetId;
  }

  /// @inheritdoc IHubConfigurator
  function updateLiquidityFee(
    address hub,
    uint256 assetId,
    uint256 liquidityFee
  ) external restricted {
    _updateLiquidityFee(IHub(hub), assetId, liquidityFee);
  }

  /// @inheritdoc IHubConfigurator
  function updateFeeReceiver(
    address hub,
    uint256 assetId,
    address feeReceiver
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.AssetConfig memory config = targetHub.getAssetConfig(assetId);
    config.feeReceiver = feeReceiver;
    targetHub.updateAssetConfig(assetId, config, new bytes(0));
  }

  /// @inheritdoc IHubConfigurator
  function updateFeeConfig(
    address hub,
    uint256 assetId,
    uint256 liquidityFee,
    address feeReceiver
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.AssetConfig memory config = targetHub.getAssetConfig(assetId);
    config.liquidityFee = liquidityFee.toUint16();
    config.feeReceiver = feeReceiver;
    targetHub.updateAssetConfig(assetId, config, new bytes(0));
  }

  /// @inheritdoc IHubConfigurator
  function updateInterestRateStrategy(
    address hub,
    uint256 assetId,
    address irStrategy,
    bytes calldata irData
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.AssetConfig memory config = targetHub.getAssetConfig(assetId);
    config.irStrategy = irStrategy;
    targetHub.updateAssetConfig(assetId, config, irData);
  }

  /// @inheritdoc IHubConfigurator
  function updateReinvestmentController(
    address hub,
    uint256 assetId,
    address reinvestmentController
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.AssetConfig memory config = targetHub.getAssetConfig(assetId);
    config.reinvestmentController = reinvestmentController;
    targetHub.updateAssetConfig(assetId, config, new bytes(0));
  }

  /// @inheritdoc IHubConfigurator
  function resetAssetCaps(address hub, uint256 assetId) external restricted {
    IHub targetHub = IHub(hub);
    uint256 spokesCount = targetHub.getSpokeCount(assetId);

    for (uint256 i = 0; i < spokesCount; ++i) {
      address spoke = targetHub.getSpokeAddress(assetId, i);
      IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
      config.addCap = 0;
      config.drawCap = 0;
      targetHub.updateSpokeConfig(assetId, spoke, config);
    }
  }

  /// @inheritdoc IHubConfigurator
  function deactivateAsset(address hub, uint256 assetId) external restricted {
    IHub targetHub = IHub(hub);
    uint256 spokesCount = targetHub.getSpokeCount(assetId);
    for (uint256 i = 0; i < spokesCount; ++i) {
      address spoke = targetHub.getSpokeAddress(assetId, i);
      IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
      config.active = false;
      targetHub.updateSpokeConfig(assetId, spoke, config);
    }
  }

  /// @inheritdoc IHubConfigurator
  function haltAsset(address hub, uint256 assetId) external restricted {
    IHub targetHub = IHub(hub);
    uint256 spokesCount = targetHub.getSpokeCount(assetId);
    for (uint256 i = 0; i < spokesCount; ++i) {
      address spoke = targetHub.getSpokeAddress(assetId, i);
      IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
      config.halted = true;
      targetHub.updateSpokeConfig(assetId, spoke, config);
    }
  }

  /// @inheritdoc IHubConfigurator
  function addSpoke(
    address hub,
    address spoke,
    uint256 assetId,
    IHub.SpokeConfig calldata config
  ) external restricted {
    IHub(hub).addSpoke(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function addSpokeToAssets(
    address hub,
    address spoke,
    uint256[] calldata assetIds,
    IHub.SpokeConfig[] calldata configs
  ) external restricted {
    uint256 assetCount = assetIds.length;
    require(assetCount == configs.length, MismatchedConfigs());
    for (uint256 i = 0; i < assetCount; ++i) {
      IHub(hub).addSpoke(assetIds[i], spoke, configs[i]);
    }
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeActive(
    address hub,
    uint256 assetId,
    address spoke,
    bool active
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
    config.active = active;
    targetHub.updateSpokeConfig(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeHalted(
    address hub,
    uint256 assetId,
    address spoke,
    bool halted
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
    config.halted = halted;
    targetHub.updateSpokeConfig(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeAddCap(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 addCap
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
    config.addCap = addCap.toUint40();
    targetHub.updateSpokeConfig(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeDrawCap(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 drawCap
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
    config.drawCap = drawCap.toUint40();
    targetHub.updateSpokeConfig(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeRiskPremiumThreshold(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 riskPremiumThreshold
  ) external restricted {
    IHub targetHub = IHub(hub);
    IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
    config.riskPremiumThreshold = riskPremiumThreshold.toUint24();
    targetHub.updateSpokeConfig(assetId, spoke, config);
  }

  /// @inheritdoc IHubConfigurator
  function updateSpokeCaps(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 addCap,
    uint256 drawCap
  ) external restricted {
    _updateSpokeCaps(IHub(hub), assetId, spoke, addCap, drawCap);
  }

  /// @inheritdoc IHubConfigurator
  function deactivateSpoke(address hub, address spoke) external restricted {
    IHub targetHub = IHub(hub);
    uint256 assetCount = targetHub.getAssetCount();
    for (uint256 assetId = 0; assetId < assetCount; ++assetId) {
      if (targetHub.isSpokeListed(assetId, spoke)) {
        IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
        config.active = false;
        targetHub.updateSpokeConfig(assetId, spoke, config);
      }
    }
  }

  /// @inheritdoc IHubConfigurator
  function haltSpoke(address hub, address spoke) external restricted {
    IHub targetHub = IHub(hub);
    uint256 assetCount = targetHub.getAssetCount();
    for (uint256 assetId = 0; assetId < assetCount; ++assetId) {
      if (targetHub.isSpokeListed(assetId, spoke)) {
        IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
        config.halted = true;
        targetHub.updateSpokeConfig(assetId, spoke, config);
      }
    }
  }

  /// @inheritdoc IHubConfigurator
  function resetSpokeCaps(address hub, address spoke) external restricted {
    IHub targetHub = IHub(hub);
    uint256 assetCount = targetHub.getAssetCount();
    for (uint256 assetId = 0; assetId < assetCount; ++assetId) {
      if (targetHub.isSpokeListed(assetId, spoke)) {
        IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
        config.addCap = 0;
        config.drawCap = 0;
        targetHub.updateSpokeConfig(assetId, spoke, config);
      }
    }
  }

  /// @inheritdoc IHubConfigurator
  function updateInterestRateData(
    address hub,
    uint256 assetId,
    bytes calldata irData
  ) external restricted {
    IHub(hub).setInterestRateData(assetId, irData);
  }

  /// @dev Updates spoke caps without changing the active flag.
  function _updateSpokeCaps(
    IHub hub,
    uint256 assetId,
    address spoke,
    uint256 addCap,
    uint256 drawCap
  ) internal {
    IHub.SpokeConfig memory config = hub.getSpokeConfig(assetId, spoke);
    config.addCap = addCap.toUint40();
    config.drawCap = drawCap.toUint40();
    hub.updateSpokeConfig(assetId, spoke, config);
  }

  function _updateLiquidityFee(IHub hub, uint256 assetId, uint256 liquidityFee) internal {
    IHub.AssetConfig memory config = hub.getAssetConfig(assetId);
    config.liquidityFee = liquidityFee.toUint16();
    hub.updateAssetConfig(assetId, config, new bytes(0));
  }
}

src/dependencies/openzeppelin/AccessManaged.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/manager/AccessManaged.sol)

pragma solidity ^0.8.20;

import {AuthorityUtils} from './AuthorityUtils.sol';
import {IAccessManager} from './IAccessManager.sol';
import {IAccessManaged} from './IAccessManaged.sol';
import {Context} from './Context.sol';

/**
 * @dev This contract module makes available a {restricted} modifier. Functions decorated with this modifier will be
 * permissioned according to an "authority": a contract like {AccessManager} that follows the {IAuthority} interface,
 * implementing a policy that allows certain callers to access certain functions.
 *
 * IMPORTANT: The `restricted` modifier should never be used on `internal` functions, judiciously used in `public`
 * functions, and ideally only used in `external` functions. See {restricted}.
 */
abstract contract AccessManaged is Context, IAccessManaged {
  address private _authority;

  bool private _consumingSchedule;

  /**
   * @dev Initializes the contract connected to an initial authority.
   */
  constructor(address initialAuthority) {
    _setAuthority(initialAuthority);
  }

  /**
   * @dev Restricts access to a function as defined by the connected Authority for this contract and the
   * caller and selector of the function that entered the contract.
   *
   * [IMPORTANT]
   * ====
   * In general, this modifier should only be used on `external` functions. It is okay to use it on `public`
   * functions that are used as external entry points and are not called internally. Unless you know what you're
   * doing, it should never be used on `internal` functions. Failure to follow these rules can have critical security
   * implications! This is because the permissions are determined by the function that entered the contract, i.e. the
   * function at the bottom of the call stack, and not the function where the modifier is visible in the source code.
   * ====
   *
   * [WARNING]
   * ====
   * Avoid adding this modifier to the https://docs.soliditylang.org/en/v0.8.20/contracts.html#receive-ether-function[`receive()`]
   * function or the https://docs.soliditylang.org/en/v0.8.20/contracts.html#fallback-function[`fallback()`]. These
   * functions are the only execution paths where a function selector cannot be unambiguously determined from the calldata
   * since the selector defaults to `0x00000000` in the `receive()` function and similarly in the `fallback()` function
   * if no calldata is provided. (See {_checkCanCall}).
   *
   * The `receive()` function will always panic whereas the `fallback()` may panic depending on the calldata length.
   * ====
   */
  modifier restricted() {
    _checkCanCall(_msgSender(), _msgData());
    _;
  }

  /// @inheritdoc IAccessManaged
  function authority() public view virtual returns (address) {
    return _authority;
  }

  /// @inheritdoc IAccessManaged
  function setAuthority(address newAuthority) public virtual {
    address caller = _msgSender();
    if (caller != authority()) {
      revert AccessManagedUnauthorized(caller);
    }
    if (newAuthority.code.length == 0) {
      revert AccessManagedInvalidAuthority(newAuthority);
    }
    _setAuthority(newAuthority);
  }

  /// @inheritdoc IAccessManaged
  function isConsumingScheduledOp() public view returns (bytes4) {
    return _consumingSchedule ? this.isConsumingScheduledOp.selector : bytes4(0);
  }

  /**
   * @dev Transfers control to a new authority. Internal function with no access restriction. Allows bypassing the
   * permissions set by the current authority.
   */
  function _setAuthority(address newAuthority) internal virtual {
    _authority = newAuthority;
    emit AuthorityUpdated(newAuthority);
  }

  /**
   * @dev Reverts if the caller is not allowed to call the function identified by a selector. Panics if the calldata
   * is less than 4 bytes long.
   */
  function _checkCanCall(address caller, bytes calldata data) internal virtual {
    (bool immediate, uint32 delay) = AuthorityUtils.canCallWithDelay(
      authority(),
      caller,
      address(this),
      bytes4(data[0:4])
    );
    if (!immediate) {
      if (delay > 0) {
        _consumingSchedule = true;
        IAccessManager(authority()).consumeScheduledOp(caller, data);
        _consumingSchedule = false;
      } else {
        revert AccessManagedUnauthorized(caller);
      }
    }
  }
}

src/dependencies/openzeppelin/AuthorityUtils.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (access/manager/AuthorityUtils.sol)

pragma solidity ^0.8.20;

import {IAuthority} from './IAuthority.sol';

library AuthorityUtils {
  /**
   * @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
   * for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
   * This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
   */
  function canCallWithDelay(
    address authority,
    address caller,
    address target,
    bytes4 selector
  ) internal view returns (bool immediate, uint32 delay) {
    bytes memory data = abi.encodeCall(IAuthority.canCall, (caller, target, selector));

    assembly ('memory-safe') {
      mstore(0x00, 0x00)
      mstore(0x20, 0x00)

      if staticcall(gas(), authority, add(data, 0x20), mload(data), 0x00, 0x40) {
        immediate := mload(0x00)
        delay := mload(0x20)

        // If delay does not fit in a uint32, return 0 (no delay)
        // equivalent to: if gt(delay, 0xFFFFFFFF) { delay := 0 }
        delay := mul(delay, iszero(shr(32, delay)))
      }
    }
  }
}

src/dependencies/openzeppelin/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
  function _msgSender() internal view virtual returns (address) {
    return msg.sender;
  }

  function _msgData() internal view virtual returns (bytes calldata) {
    return msg.data;
  }

  function _contextSuffixLength() internal view virtual returns (uint256) {
    return 0;
  }
}

src/dependencies/openzeppelin/IAccessManaged.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/manager/IAccessManaged.sol)

pragma solidity >=0.8.4;

interface IAccessManaged {
  /**
   * @dev Authority that manages this contract was updated.
   */
  event AuthorityUpdated(address authority);

  error AccessManagedUnauthorized(address caller);
  error AccessManagedRequiredDelay(address caller, uint32 delay);
  error AccessManagedInvalidAuthority(address authority);

  /**
   * @dev Returns the current authority.
   */
  function authority() external view returns (address);

  /**
   * @dev Transfers control to a new authority. The caller must be the current authority.
   */
  function setAuthority(address) external;

  /**
   * @dev Returns true only in the context of a delayed restricted call, at the moment that the scheduled operation is
   * being consumed. Prevents denial of service for delayed restricted calls in the case that the contract performs
   * attacker controlled calls.
   */
  function isConsumingScheduledOp() external view returns (bytes4);
}

src/dependencies/openzeppelin/IAccessManager.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (access/manager/IAccessManager.sol)

pragma solidity >=0.8.4;

interface IAccessManager {
  /**
   * @dev A delayed operation was scheduled.
   */
  event OperationScheduled(
    bytes32 indexed operationId,
    uint32 indexed nonce,
    uint48 schedule,
    address caller,
    address target,
    bytes data
  );

  /**
   * @dev A scheduled operation was executed.
   */
  event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);

  /**
   * @dev A scheduled operation was canceled.
   */
  event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);

  /**
   * @dev Informational labelling for a roleId.
   */
  event RoleLabel(uint64 indexed roleId, string label);

  /**
   * @dev Emitted when `account` is granted `roleId`.
   *
   * NOTE: The meaning of the `since` argument depends on the `newMember` argument.
   * If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
   * otherwise it indicates the execution delay for this account and roleId is updated.
   */
  event RoleGranted(
    uint64 indexed roleId,
    address indexed account,
    uint32 delay,
    uint48 since,
    bool newMember
  );

  /**
   * @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.
   */
  event RoleRevoked(uint64 indexed roleId, address indexed account);

  /**
   * @dev Role acting as admin over a given `roleId` is updated.
   */
  event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);

  /**
   * @dev Role acting as guardian over a given `roleId` is updated.
   */
  event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);

  /**
   * @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.
   */
  event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);

  /**
   * @dev Target mode is updated (true = closed, false = open).
   */
  event TargetClosed(address indexed target, bool closed);

  /**
   * @dev Role required to invoke `selector` on `target` is updated to `roleId`.
   */
  event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);

  /**
   * @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.
   */
  event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);

  error AccessManagerAlreadyScheduled(bytes32 operationId);
  error AccessManagerNotScheduled(bytes32 operationId);
  error AccessManagerNotReady(bytes32 operationId);
  error AccessManagerExpired(bytes32 operationId);
  error AccessManagerLockedRole(uint64 roleId);
  error AccessManagerBadConfirmation();
  error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
  error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
  error AccessManagerUnauthorizedConsume(address target);
  error AccessManagerUnauthorizedCancel(
    address msgsender,
    address caller,
    address target,
    bytes4 selector
  );
  error AccessManagerInvalidInitialAdmin(address initialAdmin);

  /**
   * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
   * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
   * & {execute} workflow.
   *
   * This function is usually called by the targeted contract to control immediate execution of restricted functions.
   * Therefore we only return true if the call can be performed without any delay. If the call is subject to a
   * previously set delay (not zero), then the function should return false and the caller should schedule the operation
   * for future execution.
   *
   * If `allowed` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
   * the operation can be executed if and only if delay is greater than 0.
   *
   * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
   * is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
   * to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
   *
   * NOTE: This function does not report the permissions of the admin functions in the manager itself. These are defined by the
   * {AccessManager} documentation.
   */
  function canCall(
    address caller,
    address target,
    bytes4 selector
  ) external view returns (bool allowed, uint32 delay);

  /**
   * @dev Expiration delay for scheduled proposals. Defaults to 1 week.
   *
   * IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
   * disabling any scheduling usage.
   */
  function expiration() external view returns (uint32);

  /**
   * @dev Minimum setback for all delay updates, with the exception of execution delays. It
   * can be increased without setback (and reset via {revokeRole} in the event of an
   * accidental increase). Defaults to 5 days.
   */
  function minSetback() external view returns (uint32);

  /**
   * @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
   *
   * NOTE: When the manager itself is closed, admin functions are still accessible to avoid locking the contract.
   */
  function isTargetClosed(address target) external view returns (bool);

  /**
   * @dev Get the role required to call a function.
   */
  function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);

  /**
   * @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.
   */
  function getTargetAdminDelay(address target) external view returns (uint32);

  /**
   * @dev Get the id of the role that acts as an admin for the given role.
   *
   * The admin permission is required to grant the role, revoke the role and update the execution delay to execute
   * an operation that is restricted to this role.
   */
  function getRoleAdmin(uint64 roleId) external view returns (uint64);

  /**
   * @dev Get the role that acts as a guardian for a given role.
   *
   * The guardian permission allows canceling operations that have been scheduled under the role.
   */
  function getRoleGuardian(uint64 roleId) external view returns (uint64);

  /**
   * @dev Get the role current grant delay.
   *
   * Its value may change at any point without an event emitted following a call to {setGrantDelay}.
   * Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.
   */
  function getRoleGrantDelay(uint64 roleId) external view returns (uint32);

  /**
   * @dev Get the access details for a given account for a given role. These details include the timepoint at which
   * membership becomes active, and the delay applied to all operations by this user that requires this permission
   * level.
   *
   * Returns:
   * [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.
   * [1] Current execution delay for the account.
   * [2] Pending execution delay for the account.
   * [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.
   */
  function getAccess(
    uint64 roleId,
    address account
  ) external view returns (uint48 since, uint32 currentDelay, uint32 pendingDelay, uint48 effect);

  /**
   * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
   * permission might be associated with an execution delay. {getAccess} can provide more details.
   */
  function hasRole(
    uint64 roleId,
    address account
  ) external view returns (bool isMember, uint32 executionDelay);

  /**
   * @dev Give a label to a role, for improved role discoverability by UIs.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {RoleLabel} event.
   */
  function labelRole(uint64 roleId, string calldata label) external;

  /**
   * @dev Add `account` to `roleId`, or change its execution delay.
   *
   * This gives the account the authorization to call any function that is restricted to this role. An optional
   * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
   * that is restricted to members of this role. The user will only be able to execute the operation after the delay has
   * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
   *
   * If the account has already been granted this role, the execution delay will be updated. This update is not
   * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
   * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
   * operation executed in the 3 hours that follows this update was indeed scheduled before this update.
   *
   * Requirements:
   *
   * - the caller must be an admin for the role (see {getRoleAdmin})
   * - granted role must not be the `PUBLIC_ROLE`
   *
   * Emits a {RoleGranted} event.
   */
  function grantRole(uint64 roleId, address account, uint32 executionDelay) external;

  /**
   * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
   * no effect.
   *
   * Requirements:
   *
   * - the caller must be an admin for the role (see {getRoleAdmin})
   * - revoked role must not be the `PUBLIC_ROLE`
   *
   * Emits a {RoleRevoked} event if the account had the role.
   */
  function revokeRole(uint64 roleId, address account) external;

  /**
   * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
   * the role this call has no effect.
   *
   * Requirements:
   *
   * - the caller must be `callerConfirmation`.
   *
   * Emits a {RoleRevoked} event if the account had the role.
   */
  function renounceRole(uint64 roleId, address callerConfirmation) external;

  /**
   * @dev Change admin role for a given role.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {RoleAdminChanged} event
   */
  function setRoleAdmin(uint64 roleId, uint64 admin) external;

  /**
   * @dev Change guardian role for a given role.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {RoleGuardianChanged} event
   */
  function setRoleGuardian(uint64 roleId, uint64 guardian) external;

  /**
   * @dev Update the delay for granting a `roleId`.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {RoleGrantDelayChanged} event.
   */
  function setGrantDelay(uint64 roleId, uint32 newDelay) external;

  /**
   * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {TargetFunctionRoleUpdated} event per selector.
   */
  function setTargetFunctionRole(
    address target,
    bytes4[] calldata selectors,
    uint64 roleId
  ) external;

  /**
   * @dev Set the delay for changing the configuration of a given target contract.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {TargetAdminDelayUpdated} event.
   */
  function setTargetAdminDelay(address target, uint32 newDelay) external;

  /**
   * @dev Set the closed flag for a contract.
   *
   * Closing the manager itself won't disable access to admin methods to avoid locking the contract.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   *
   * Emits a {TargetClosed} event.
   */
  function setTargetClosed(address target, bool closed) external;

  /**
   * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
   * operation is not yet scheduled, has expired, was executed, or was canceled.
   */
  function getSchedule(bytes32 id) external view returns (uint48);

  /**
   * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
   * been scheduled.
   */
  function getNonce(bytes32 id) external view returns (uint32);

  /**
   * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
   * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
   * required for the caller. The special value zero will automatically set the earliest possible time.
   *
   * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
   * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
   * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
   *
   * Emits a {OperationScheduled} event.
   *
   * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
   * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
   * contract if it is using standard Solidity ABI encoding.
   */
  function schedule(
    address target,
    bytes calldata data,
    uint48 when
  ) external returns (bytes32 operationId, uint32 nonce);

  /**
   * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
   * execution delay is 0.
   *
   * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
   * operation wasn't previously scheduled (if the caller doesn't have an execution delay).
   *
   * Emits an {OperationExecuted} event only if the call was scheduled and delayed.
   */
  function execute(address target, bytes calldata data) external payable returns (uint32);

  /**
   * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
   * operation that is cancelled.
   *
   * Requirements:
   *
   * - the caller must be the proposer, a guardian of the targeted function, or a global admin
   *
   * Emits a {OperationCanceled} event.
   */
  function cancel(address caller, address target, bytes calldata data) external returns (uint32);

  /**
   * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
   * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
   *
   * This is useful for contracts that want to enforce that calls targeting them were scheduled on the manager,
   * with all the verifications that it implies.
   *
   * Emit a {OperationExecuted} event.
   */
  function consumeScheduledOp(address caller, bytes calldata data) external;

  /**
   * @dev Hashing function for delayed operations.
   */
  function hashOperation(
    address caller,
    address target,
    bytes calldata data
  ) external view returns (bytes32);

  /**
   * @dev Changes the authority of a target managed by this manager instance.
   *
   * Requirements:
   *
   * - the caller must be a global admin
   */
  function updateAuthority(address target, address newAuthority) external;
}

src/dependencies/openzeppelin/IAuthority.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/manager/IAuthority.sol)

pragma solidity >=0.4.16;

/**
 * @dev Standard interface for permissioning originally defined in Dappsys.
 */
interface IAuthority {
  /**
   * @dev Returns true if the caller can invoke on a target the function identified by a function selector.
   */
  function canCall(
    address caller,
    address target,
    bytes4 selector
  ) external view returns (bool allowed);
}

src/dependencies/openzeppelin/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
  /**
   * @dev Emitted when `value` tokens are moved from one account (`from`) to
   * another (`to`).
   *
   * Note that `value` may be zero.
   */
  event Transfer(address indexed from, address indexed to, uint256 value);

  /**
   * @dev Emitted when the allowance of a `spender` for an `owner` is set by
   * a call to {approve}. `value` is the new allowance.
   */
  event Approval(address indexed owner, address indexed spender, uint256 value);

  /**
   * @dev Returns the value of tokens in existence.
   */
  function totalSupply() external view returns (uint256);

  /**
   * @dev Returns the value of tokens owned by `account`.
   */
  function balanceOf(address account) external view returns (uint256);

  /**
   * @dev Moves a `value` amount of tokens from the caller's account to `to`.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * Emits a {Transfer} event.
   */
  function transfer(address to, uint256 value) external returns (bool);

  /**
   * @dev Returns the remaining number of tokens that `spender` will be
   * allowed to spend on behalf of `owner` through {transferFrom}. This is
   * zero by default.
   *
   * This value changes when {approve} or {transferFrom} are called.
   */
  function allowance(address owner, address spender) external view returns (uint256);

  /**
   * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
   * caller's tokens.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * IMPORTANT: Beware that changing an allowance with this method brings the risk
   * that someone may use both the old and the new allowance by unfortunate
   * transaction ordering. One possible solution to mitigate this race
   * condition is to first reduce the spender's allowance to 0 and set the
   * desired value afterwards:
   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
   *
   * Emits an {Approval} event.
   */
  function approve(address spender, uint256 value) external returns (bool);

  /**
   * @dev Moves a `value` amount of tokens from `from` to `to` using the
   * allowance mechanism. `value` is then deducted from the caller's
   * allowance.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * Emits a {Transfer} event.
   */
  function transferFrom(address from, address to, uint256 value) external returns (bool);
}

src/dependencies/openzeppelin/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from './IERC20.sol';

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
  /**
   * @dev Returns the name of the token.
   */
  function name() external view returns (string memory);

  /**
   * @dev Returns the symbol of the token.
   */
  function symbol() external view returns (string memory);

  /**
   * @dev Returns the decimals places of the token.
   */
  function decimals() external view returns (uint8);
}

src/dependencies/openzeppelin/SafeCast.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
  /**
   * @dev Value doesn't fit in an uint of `bits` size.
   */
  error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

  /**
   * @dev An int value doesn't fit in an uint of `bits` size.
   */
  error SafeCastOverflowedIntToUint(int256 value);

  /**
   * @dev Value doesn't fit in an int of `bits` size.
   */
  error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

  /**
   * @dev An uint value doesn't fit in an int of `bits` size.
   */
  error SafeCastOverflowedUintToInt(uint256 value);

  /**
   * @dev Returns the downcasted uint248 from uint256, reverting on
   * overflow (when the input is greater than largest uint248).
   *
   * Counterpart to Solidity's `uint248` operator.
   *
   * Requirements:
   *
   * - input must fit into 248 bits
   */
  function toUint248(uint256 value) internal pure returns (uint248) {
    if (value > type(uint248).max) {
      revert SafeCastOverflowedUintDowncast(248, value);
    }
    return uint248(value);
  }

  /**
   * @dev Returns the downcasted uint240 from uint256, reverting on
   * overflow (when the input is greater than largest uint240).
   *
   * Counterpart to Solidity's `uint240` operator.
   *
   * Requirements:
   *
   * - input must fit into 240 bits
   */
  function toUint240(uint256 value) internal pure returns (uint240) {
    if (value > type(uint240).max) {
      revert SafeCastOverflowedUintDowncast(240, value);
    }
    return uint240(value);
  }

  /**
   * @dev Returns the downcasted uint232 from uint256, reverting on
   * overflow (when the input is greater than largest uint232).
   *
   * Counterpart to Solidity's `uint232` operator.
   *
   * Requirements:
   *
   * - input must fit into 232 bits
   */
  function toUint232(uint256 value) internal pure returns (uint232) {
    if (value > type(uint232).max) {
      revert SafeCastOverflowedUintDowncast(232, value);
    }
    return uint232(value);
  }

  /**
   * @dev Returns the downcasted uint224 from uint256, reverting on
   * overflow (when the input is greater than largest uint224).
   *
   * Counterpart to Solidity's `uint224` operator.
   *
   * Requirements:
   *
   * - input must fit into 224 bits
   */
  function toUint224(uint256 value) internal pure returns (uint224) {
    if (value > type(uint224).max) {
      revert SafeCastOverflowedUintDowncast(224, value);
    }
    return uint224(value);
  }

  /**
   * @dev Returns the downcasted uint216 from uint256, reverting on
   * overflow (when the input is greater than largest uint216).
   *
   * Counterpart to Solidity's `uint216` operator.
   *
   * Requirements:
   *
   * - input must fit into 216 bits
   */
  function toUint216(uint256 value) internal pure returns (uint216) {
    if (value > type(uint216).max) {
      revert SafeCastOverflowedUintDowncast(216, value);
    }
    return uint216(value);
  }

  /**
   * @dev Returns the downcasted uint208 from uint256, reverting on
   * overflow (when the input is greater than largest uint208).
   *
   * Counterpart to Solidity's `uint208` operator.
   *
   * Requirements:
   *
   * - input must fit into 208 bits
   */
  function toUint208(uint256 value) internal pure returns (uint208) {
    if (value > type(uint208).max) {
      revert SafeCastOverflowedUintDowncast(208, value);
    }
    return uint208(value);
  }

  /**
   * @dev Returns the downcasted uint200 from uint256, reverting on
   * overflow (when the input is greater than largest uint200).
   *
   * Counterpart to Solidity's `uint200` operator.
   *
   * Requirements:
   *
   * - input must fit into 200 bits
   */
  function toUint200(uint256 value) internal pure returns (uint200) {
    if (value > type(uint200).max) {
      revert SafeCastOverflowedUintDowncast(200, value);
    }
    return uint200(value);
  }

  /**
   * @dev Returns the downcasted uint192 from uint256, reverting on
   * overflow (when the input is greater than largest uint192).
   *
   * Counterpart to Solidity's `uint192` operator.
   *
   * Requirements:
   *
   * - input must fit into 192 bits
   */
  function toUint192(uint256 value) internal pure returns (uint192) {
    if (value > type(uint192).max) {
      revert SafeCastOverflowedUintDowncast(192, value);
    }
    return uint192(value);
  }

  /**
   * @dev Returns the downcasted uint184 from uint256, reverting on
   * overflow (when the input is greater than largest uint184).
   *
   * Counterpart to Solidity's `uint184` operator.
   *
   * Requirements:
   *
   * - input must fit into 184 bits
   */
  function toUint184(uint256 value) internal pure returns (uint184) {
    if (value > type(uint184).max) {
      revert SafeCastOverflowedUintDowncast(184, value);
    }
    return uint184(value);
  }

  /**
   * @dev Returns the downcasted uint176 from uint256, reverting on
   * overflow (when the input is greater than largest uint176).
   *
   * Counterpart to Solidity's `uint176` operator.
   *
   * Requirements:
   *
   * - input must fit into 176 bits
   */
  function toUint176(uint256 value) internal pure returns (uint176) {
    if (value > type(uint176).max) {
      revert SafeCastOverflowedUintDowncast(176, value);
    }
    return uint176(value);
  }

  /**
   * @dev Returns the downcasted uint168 from uint256, reverting on
   * overflow (when the input is greater than largest uint168).
   *
   * Counterpart to Solidity's `uint168` operator.
   *
   * Requirements:
   *
   * - input must fit into 168 bits
   */
  function toUint168(uint256 value) internal pure returns (uint168) {
    if (value > type(uint168).max) {
      revert SafeCastOverflowedUintDowncast(168, value);
    }
    return uint168(value);
  }

  /**
   * @dev Returns the downcasted uint160 from uint256, reverting on
   * overflow (when the input is greater than largest uint160).
   *
   * Counterpart to Solidity's `uint160` operator.
   *
   * Requirements:
   *
   * - input must fit into 160 bits
   */
  function toUint160(uint256 value) internal pure returns (uint160) {
    if (value > type(uint160).max) {
      revert SafeCastOverflowedUintDowncast(160, value);
    }
    return uint160(value);
  }

  /**
   * @dev Returns the downcasted uint152 from uint256, reverting on
   * overflow (when the input is greater than largest uint152).
   *
   * Counterpart to Solidity's `uint152` operator.
   *
   * Requirements:
   *
   * - input must fit into 152 bits
   */
  function toUint152(uint256 value) internal pure returns (uint152) {
    if (value > type(uint152).max) {
      revert SafeCastOverflowedUintDowncast(152, value);
    }
    return uint152(value);
  }

  /**
   * @dev Returns the downcasted uint144 from uint256, reverting on
   * overflow (when the input is greater than largest uint144).
   *
   * Counterpart to Solidity's `uint144` operator.
   *
   * Requirements:
   *
   * - input must fit into 144 bits
   */
  function toUint144(uint256 value) internal pure returns (uint144) {
    if (value > type(uint144).max) {
      revert SafeCastOverflowedUintDowncast(144, value);
    }
    return uint144(value);
  }

  /**
   * @dev Returns the downcasted uint136 from uint256, reverting on
   * overflow (when the input is greater than largest uint136).
   *
   * Counterpart to Solidity's `uint136` operator.
   *
   * Requirements:
   *
   * - input must fit into 136 bits
   */
  function toUint136(uint256 value) internal pure returns (uint136) {
    if (value > type(uint136).max) {
      revert SafeCastOverflowedUintDowncast(136, value);
    }
    return uint136(value);
  }

  /**
   * @dev Returns the downcasted uint128 from uint256, reverting on
   * overflow (when the input is greater than largest uint128).
   *
   * Counterpart to Solidity's `uint128` operator.
   *
   * Requirements:
   *
   * - input must fit into 128 bits
   */
  function toUint128(uint256 value) internal pure returns (uint128) {
    if (value > type(uint128).max) {
      revert SafeCastOverflowedUintDowncast(128, value);
    }
    return uint128(value);
  }

  /**
   * @dev Returns the downcasted uint120 from uint256, reverting on
   * overflow (when the input is greater than largest uint120).
   *
   * Counterpart to Solidity's `uint120` operator.
   *
   * Requirements:
   *
   * - input must fit into 120 bits
   */
  function toUint120(uint256 value) internal pure returns (uint120) {
    if (value > type(uint120).max) {
      revert SafeCastOverflowedUintDowncast(120, value);
    }
    return uint120(value);
  }

  /**
   * @dev Returns the downcasted uint112 from uint256, reverting on
   * overflow (when the input is greater than largest uint112).
   *
   * Counterpart to Solidity's `uint112` operator.
   *
   * Requirements:
   *
   * - input must fit into 112 bits
   */
  function toUint112(uint256 value) internal pure returns (uint112) {
    if (value > type(uint112).max) {
      revert SafeCastOverflowedUintDowncast(112, value);
    }
    return uint112(value);
  }

  /**
   * @dev Returns the downcasted uint104 from uint256, reverting on
   * overflow (when the input is greater than largest uint104).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 104 bits
   */
  function toUint104(uint256 value) internal pure returns (uint104) {
    if (value > type(uint104).max) {
      revert SafeCastOverflowedUintDowncast(104, value);
    }
    return uint104(value);
  }

  /**
   * @dev Returns the downcasted uint96 from uint256, reverting on
   * overflow (when the input is greater than largest uint96).
   *
   * Counterpart to Solidity's `uint96` operator.
   *
   * Requirements:
   *
   * - input must fit into 96 bits
   */
  function toUint96(uint256 value) internal pure returns (uint96) {
    if (value > type(uint96).max) {
      revert SafeCastOverflowedUintDowncast(96, value);
    }
    return uint96(value);
  }

  /**
   * @dev Returns the downcasted uint88 from uint256, reverting on
   * overflow (when the input is greater than largest uint88).
   *
   * Counterpart to Solidity's `uint88` operator.
   *
   * Requirements:
   *
   * - input must fit into 88 bits
   */
  function toUint88(uint256 value) internal pure returns (uint88) {
    if (value > type(uint88).max) {
      revert SafeCastOverflowedUintDowncast(88, value);
    }
    return uint88(value);
  }

  /**
   * @dev Returns the downcasted uint80 from uint256, reverting on
   * overflow (when the input is greater than largest uint80).
   *
   * Counterpart to Solidity's `uint80` operator.
   *
   * Requirements:
   *
   * - input must fit into 80 bits
   */
  function toUint80(uint256 value) internal pure returns (uint80) {
    if (value > type(uint80).max) {
      revert SafeCastOverflowedUintDowncast(80, value);
    }
    return uint80(value);
  }

  /**
   * @dev Returns the downcasted uint72 from uint256, reverting on
   * overflow (when the input is greater than largest uint72).
   *
   * Counterpart to Solidity's `uint72` operator.
   *
   * Requirements:
   *
   * - input must fit into 72 bits
   */
  function toUint72(uint256 value) internal pure returns (uint72) {
    if (value > type(uint72).max) {
      revert SafeCastOverflowedUintDowncast(72, value);
    }
    return uint72(value);
  }

  /**
   * @dev Returns the downcasted uint64 from uint256, reverting on
   * overflow (when the input is greater than largest uint64).
   *
   * Counterpart to Solidity's `uint64` operator.
   *
   * Requirements:
   *
   * - input must fit into 64 bits
   */
  function toUint64(uint256 value) internal pure returns (uint64) {
    if (value > type(uint64).max) {
      revert SafeCastOverflowedUintDowncast(64, value);
    }
    return uint64(value);
  }

  /**
   * @dev Returns the downcasted uint56 from uint256, reverting on
   * overflow (when the input is greater than largest uint56).
   *
   * Counterpart to Solidity's `uint56` operator.
   *
   * Requirements:
   *
   * - input must fit into 56 bits
   */
  function toUint56(uint256 value) internal pure returns (uint56) {
    if (value > type(uint56).max) {
      revert SafeCastOverflowedUintDowncast(56, value);
    }
    return uint56(value);
  }

  /**
   * @dev Returns the downcasted uint48 from uint256, reverting on
   * overflow (when the input is greater than largest uint48).
   *
   * Counterpart to Solidity's `uint48` operator.
   *
   * Requirements:
   *
   * - input must fit into 48 bits
   */
  function toUint48(uint256 value) internal pure returns (uint48) {
    if (value > type(uint48).max) {
      revert SafeCastOverflowedUintDowncast(48, value);
    }
    return uint48(value);
  }

  /**
   * @dev Returns the downcasted uint40 from uint256, reverting on
   * overflow (when the input is greater than largest uint40).
   *
   * Counterpart to Solidity's `uint40` operator.
   *
   * Requirements:
   *
   * - input must fit into 40 bits
   */
  function toUint40(uint256 value) internal pure returns (uint40) {
    if (value > type(uint40).max) {
      revert SafeCastOverflowedUintDowncast(40, value);
    }
    return uint40(value);
  }

  /**
   * @dev Returns the downcasted uint32 from uint256, reverting on
   * overflow (when the input is greater than largest uint32).
   *
   * Counterpart to Solidity's `uint32` operator.
   *
   * Requirements:
   *
   * - input must fit into 32 bits
   */
  function toUint32(uint256 value) internal pure returns (uint32) {
    if (value > type(uint32).max) {
      revert SafeCastOverflowedUintDowncast(32, value);
    }
    return uint32(value);
  }

  /**
   * @dev Returns the downcasted uint24 from uint256, reverting on
   * overflow (when the input is greater than largest uint24).
   *
   * Counterpart to Solidity's `uint24` operator.
   *
   * Requirements:
   *
   * - input must fit into 24 bits
   */
  function toUint24(uint256 value) internal pure returns (uint24) {
    if (value > type(uint24).max) {
      revert SafeCastOverflowedUintDowncast(24, value);
    }
    return uint24(value);
  }

  /**
   * @dev Returns the downcasted uint16 from uint256, reverting on
   * overflow (when the input is greater than largest uint16).
   *
   * Counterpart to Solidity's `uint16` operator.
   *
   * Requirements:
   *
   * - input must fit into 16 bits
   */
  function toUint16(uint256 value) internal pure returns (uint16) {
    if (value > type(uint16).max) {
      revert SafeCastOverflowedUintDowncast(16, value);
    }
    return uint16(value);
  }

  /**
   * @dev Returns the downcasted uint8 from uint256, reverting on
   * overflow (when the input is greater than largest uint8).
   *
   * Counterpart to Solidity's `uint8` operator.
   *
   * Requirements:
   *
   * - input must fit into 8 bits
   */
  function toUint8(uint256 value) internal pure returns (uint8) {
    if (value > type(uint8).max) {
      revert SafeCastOverflowedUintDowncast(8, value);
    }
    return uint8(value);
  }

  /**
   * @dev Converts a signed int256 into an unsigned uint256.
   *
   * Requirements:
   *
   * - input must be greater than or equal to 0.
   */
  function toUint256(int256 value) internal pure returns (uint256) {
    if (value < 0) {
      revert SafeCastOverflowedIntToUint(value);
    }
    return uint256(value);
  }

  /**
   * @dev Returns the downcasted int248 from int256, reverting on
   * overflow (when the input is less than smallest int248 or
   * greater than largest int248).
   *
   * Counterpart to Solidity's `int248` operator.
   *
   * Requirements:
   *
   * - input must fit into 248 bits
   */
  function toInt248(int256 value) internal pure returns (int248 downcasted) {
    downcasted = int248(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(248, value);
    }
  }

  /**
   * @dev Returns the downcasted int240 from int256, reverting on
   * overflow (when the input is less than smallest int240 or
   * greater than largest int240).
   *
   * Counterpart to Solidity's `int240` operator.
   *
   * Requirements:
   *
   * - input must fit into 240 bits
   */
  function toInt240(int256 value) internal pure returns (int240 downcasted) {
    downcasted = int240(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(240, value);
    }
  }

  /**
   * @dev Returns the downcasted int232 from int256, reverting on
   * overflow (when the input is less than smallest int232 or
   * greater than largest int232).
   *
   * Counterpart to Solidity's `int232` operator.
   *
   * Requirements:
   *
   * - input must fit into 232 bits
   */
  function toInt232(int256 value) internal pure returns (int232 downcasted) {
    downcasted = int232(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(232, value);
    }
  }

  /**
   * @dev Returns the downcasted int224 from int256, reverting on
   * overflow (when the input is less than smallest int224 or
   * greater than largest int224).
   *
   * Counterpart to Solidity's `int224` operator.
   *
   * Requirements:
   *
   * - input must fit into 224 bits
   */
  function toInt224(int256 value) internal pure returns (int224 downcasted) {
    downcasted = int224(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(224, value);
    }
  }

  /**
   * @dev Returns the downcasted int216 from int256, reverting on
   * overflow (when the input is less than smallest int216 or
   * greater than largest int216).
   *
   * Counterpart to Solidity's `int216` operator.
   *
   * Requirements:
   *
   * - input must fit into 216 bits
   */
  function toInt216(int256 value) internal pure returns (int216 downcasted) {
    downcasted = int216(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(216, value);
    }
  }

  /**
   * @dev Returns the downcasted int208 from int256, reverting on
   * overflow (when the input is less than smallest int208 or
   * greater than largest int208).
   *
   * Counterpart to Solidity's `int208` operator.
   *
   * Requirements:
   *
   * - input must fit into 208 bits
   */
  function toInt208(int256 value) internal pure returns (int208 downcasted) {
    downcasted = int208(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(208, value);
    }
  }

  /**
   * @dev Returns the downcasted int200 from int256, reverting on
   * overflow (when the input is less than smallest int200 or
   * greater than largest int200).
   *
   * Counterpart to Solidity's `int200` operator.
   *
   * Requirements:
   *
   * - input must fit into 200 bits
   */
  function toInt200(int256 value) internal pure returns (int200 downcasted) {
    downcasted = int200(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(200, value);
    }
  }

  /**
   * @dev Returns the downcasted int192 from int256, reverting on
   * overflow (when the input is less than smallest int192 or
   * greater than largest int192).
   *
   * Counterpart to Solidity's `int192` operator.
   *
   * Requirements:
   *
   * - input must fit into 192 bits
   */
  function toInt192(int256 value) internal pure returns (int192 downcasted) {
    downcasted = int192(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(192, value);
    }
  }

  /**
   * @dev Returns the downcasted int184 from int256, reverting on
   * overflow (when the input is less than smallest int184 or
   * greater than largest int184).
   *
   * Counterpart to Solidity's `int184` operator.
   *
   * Requirements:
   *
   * - input must fit into 184 bits
   */
  function toInt184(int256 value) internal pure returns (int184 downcasted) {
    downcasted = int184(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(184, value);
    }
  }

  /**
   * @dev Returns the downcasted int176 from int256, reverting on
   * overflow (when the input is less than smallest int176 or
   * greater than largest int176).
   *
   * Counterpart to Solidity's `int176` operator.
   *
   * Requirements:
   *
   * - input must fit into 176 bits
   */
  function toInt176(int256 value) internal pure returns (int176 downcasted) {
    downcasted = int176(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(176, value);
    }
  }

  /**
   * @dev Returns the downcasted int168 from int256, reverting on
   * overflow (when the input is less than smallest int168 or
   * greater than largest int168).
   *
   * Counterpart to Solidity's `int168` operator.
   *
   * Requirements:
   *
   * - input must fit into 168 bits
   */
  function toInt168(int256 value) internal pure returns (int168 downcasted) {
    downcasted = int168(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(168, value);
    }
  }

  /**
   * @dev Returns the downcasted int160 from int256, reverting on
   * overflow (when the input is less than smallest int160 or
   * greater than largest int160).
   *
   * Counterpart to Solidity's `int160` operator.
   *
   * Requirements:
   *
   * - input must fit into 160 bits
   */
  function toInt160(int256 value) internal pure returns (int160 downcasted) {
    downcasted = int160(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(160, value);
    }
  }

  /**
   * @dev Returns the downcasted int152 from int256, reverting on
   * overflow (when the input is less than smallest int152 or
   * greater than largest int152).
   *
   * Counterpart to Solidity's `int152` operator.
   *
   * Requirements:
   *
   * - input must fit into 152 bits
   */
  function toInt152(int256 value) internal pure returns (int152 downcasted) {
    downcasted = int152(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(152, value);
    }
  }

  /**
   * @dev Returns the downcasted int144 from int256, reverting on
   * overflow (when the input is less than smallest int144 or
   * greater than largest int144).
   *
   * Counterpart to Solidity's `int144` operator.
   *
   * Requirements:
   *
   * - input must fit into 144 bits
   */
  function toInt144(int256 value) internal pure returns (int144 downcasted) {
    downcasted = int144(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(144, value);
    }
  }

  /**
   * @dev Returns the downcasted int136 from int256, reverting on
   * overflow (when the input is less than smallest int136 or
   * greater than largest int136).
   *
   * Counterpart to Solidity's `int136` operator.
   *
   * Requirements:
   *
   * - input must fit into 136 bits
   */
  function toInt136(int256 value) internal pure returns (int136 downcasted) {
    downcasted = int136(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(136, value);
    }
  }

  /**
   * @dev Returns the downcasted int128 from int256, reverting on
   * overflow (when the input is less than smallest int128 or
   * greater than largest int128).
   *
   * Counterpart to Solidity's `int128` operator.
   *
   * Requirements:
   *
   * - input must fit into 128 bits
   */
  function toInt128(int256 value) internal pure returns (int128 downcasted) {
    downcasted = int128(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(128, value);
    }
  }

  /**
   * @dev Returns the downcasted int120 from int256, reverting on
   * overflow (when the input is less than smallest int120 or
   * greater than largest int120).
   *
   * Counterpart to Solidity's `int120` operator.
   *
   * Requirements:
   *
   * - input must fit into 120 bits
   */
  function toInt120(int256 value) internal pure returns (int120 downcasted) {
    downcasted = int120(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(120, value);
    }
  }

  /**
   * @dev Returns the downcasted int112 from int256, reverting on
   * overflow (when the input is less than smallest int112 or
   * greater than largest int112).
   *
   * Counterpart to Solidity's `int112` operator.
   *
   * Requirements:
   *
   * - input must fit into 112 bits
   */
  function toInt112(int256 value) internal pure returns (int112 downcasted) {
    downcasted = int112(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(112, value);
    }
  }

  /**
   * @dev Returns the downcasted int104 from int256, reverting on
   * overflow (when the input is less than smallest int104 or
   * greater than largest int104).
   *
   * Counterpart to Solidity's `int104` operator.
   *
   * Requirements:
   *
   * - input must fit into 104 bits
   */
  function toInt104(int256 value) internal pure returns (int104 downcasted) {
    downcasted = int104(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(104, value);
    }
  }

  /**
   * @dev Returns the downcasted int96 from int256, reverting on
   * overflow (when the input is less than smallest int96 or
   * greater than largest int96).
   *
   * Counterpart to Solidity's `int96` operator.
   *
   * Requirements:
   *
   * - input must fit into 96 bits
   */
  function toInt96(int256 value) internal pure returns (int96 downcasted) {
    downcasted = int96(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(96, value);
    }
  }

  /**
   * @dev Returns the downcasted int88 from int256, reverting on
   * overflow (when the input is less than smallest int88 or
   * greater than largest int88).
   *
   * Counterpart to Solidity's `int88` operator.
   *
   * Requirements:
   *
   * - input must fit into 88 bits
   */
  function toInt88(int256 value) internal pure returns (int88 downcasted) {
    downcasted = int88(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(88, value);
    }
  }

  /**
   * @dev Returns the downcasted int80 from int256, reverting on
   * overflow (when the input is less than smallest int80 or
   * greater than largest int80).
   *
   * Counterpart to Solidity's `int80` operator.
   *
   * Requirements:
   *
   * - input must fit into 80 bits
   */
  function toInt80(int256 value) internal pure returns (int80 downcasted) {
    downcasted = int80(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(80, value);
    }
  }

  /**
   * @dev Returns the downcasted int72 from int256, reverting on
   * overflow (when the input is less than smallest int72 or
   * greater than largest int72).
   *
   * Counterpart to Solidity's `int72` operator.
   *
   * Requirements:
   *
   * - input must fit into 72 bits
   */
  function toInt72(int256 value) internal pure returns (int72 downcasted) {
    downcasted = int72(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(72, value);
    }
  }

  /**
   * @dev Returns the downcasted int64 from int256, reverting on
   * overflow (when the input is less than smallest int64 or
   * greater than largest int64).
   *
   * Counterpart to Solidity's `int64` operator.
   *
   * Requirements:
   *
   * - input must fit into 64 bits
   */
  function toInt64(int256 value) internal pure returns (int64 downcasted) {
    downcasted = int64(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(64, value);
    }
  }

  /**
   * @dev Returns the downcasted int56 from int256, reverting on
   * overflow (when the input is less than smallest int56 or
   * greater than largest int56).
   *
   * Counterpart to Solidity's `int56` operator.
   *
   * Requirements:
   *
   * - input must fit into 56 bits
   */
  function toInt56(int256 value) internal pure returns (int56 downcasted) {
    downcasted = int56(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(56, value);
    }
  }

  /**
   * @dev Returns the downcasted int48 from int256, reverting on
   * overflow (when the input is less than smallest int48 or
   * greater than largest int48).
   *
   * Counterpart to Solidity's `int48` operator.
   *
   * Requirements:
   *
   * - input must fit into 48 bits
   */
  function toInt48(int256 value) internal pure returns (int48 downcasted) {
    downcasted = int48(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(48, value);
    }
  }

  /**
   * @dev Returns the downcasted int40 from int256, reverting on
   * overflow (when the input is less than smallest int40 or
   * greater than largest int40).
   *
   * Counterpart to Solidity's `int40` operator.
   *
   * Requirements:
   *
   * - input must fit into 40 bits
   */
  function toInt40(int256 value) internal pure returns (int40 downcasted) {
    downcasted = int40(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(40, value);
    }
  }

  /**
   * @dev Returns the downcasted int32 from int256, reverting on
   * overflow (when the input is less than smallest int32 or
   * greater than largest int32).
   *
   * Counterpart to Solidity's `int32` operator.
   *
   * Requirements:
   *
   * - input must fit into 32 bits
   */
  function toInt32(int256 value) internal pure returns (int32 downcasted) {
    downcasted = int32(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(32, value);
    }
  }

  /**
   * @dev Returns the downcasted int24 from int256, reverting on
   * overflow (when the input is less than smallest int24 or
   * greater than largest int24).
   *
   * Counterpart to Solidity's `int24` operator.
   *
   * Requirements:
   *
   * - input must fit into 24 bits
   */
  function toInt24(int256 value) internal pure returns (int24 downcasted) {
    downcasted = int24(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(24, value);
    }
  }

  /**
   * @dev Returns the downcasted int16 from int256, reverting on
   * overflow (when the input is less than smallest int16 or
   * greater than largest int16).
   *
   * Counterpart to Solidity's `int16` operator.
   *
   * Requirements:
   *
   * - input must fit into 16 bits
   */
  function toInt16(int256 value) internal pure returns (int16 downcasted) {
    downcasted = int16(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(16, value);
    }
  }

  /**
   * @dev Returns the downcasted int8 from int256, reverting on
   * overflow (when the input is less than smallest int8 or
   * greater than largest int8).
   *
   * Counterpart to Solidity's `int8` operator.
   *
   * Requirements:
   *
   * - input must fit into 8 bits
   */
  function toInt8(int256 value) internal pure returns (int8 downcasted) {
    downcasted = int8(value);
    if (downcasted != value) {
      revert SafeCastOverflowedIntDowncast(8, value);
    }
  }

  /**
   * @dev Converts an unsigned uint256 into a signed int256.
   *
   * Requirements:
   *
   * - input must be less than or equal to maxInt256.
   */
  function toInt256(uint256 value) internal pure returns (int256) {
    // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
    if (value > uint256(type(int256).max)) {
      revert SafeCastOverflowedUintToInt(value);
    }
    return int256(value);
  }

  /**
   * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
   */
  function toUint(bool b) internal pure returns (uint256 u) {
    assembly ('memory-safe') {
      u := iszero(iszero(b))
    }
  }
}

src/hub/interfaces/IHub.sol

// SPDX-License-Identifier: LicenseRef-BUSL
pragma solidity ^0.8.0;

import {IAccessManaged} from 'src/dependencies/openzeppelin/IAccessManaged.sol';
import {IHubBase} from 'src/hub/interfaces/IHubBase.sol';

/// @title IHub
/// @author Aave Labs
/// @notice Full interface for the Hub.
interface IHub is IHubBase, IAccessManaged {
  /// @notice Asset position and configuration data.
  /// @dev liquidity The liquidity available to be accessed, expressed in asset units.
  /// @dev realizedFees The amount of fees realized but not yet minted, expressed in asset units.
  /// @dev decimals The number of decimals of the underlying asset.
  /// @dev addedShares The total shares added across all spokes.
  /// @dev swept The outstanding liquidity which has been invested by the reinvestment controller, expressed in asset units.
  /// @dev premiumOffsetRay The total premium offset across all spokes, used to calculate the premium, expressed in asset units and scaled by RAY.
  /// @dev drawnShares The total drawn shares across all spokes.
  /// @dev premiumShares The total premium shares across all spokes.
  /// @dev liquidityFee The protocol fee charged on drawn and premium liquidity growth, expressed in BPS.
  /// @dev drawnIndex The drawn index which monotonically increases according to the drawn rate, expressed in RAY.
  /// @dev drawnRate The rate at which drawn assets grow, expressed in RAY.
  /// @dev lastUpdateTimestamp The timestamp of the last accrual.
  /// @dev underlying The address of the underlying asset.
  /// @dev irStrategy The address of the interest rate strategy.
  /// @dev reinvestmentController The address of the reinvestment controller.
  /// @dev feeReceiver The address of the fee receiver spoke.
  /// @dev deficitRay The amount of outstanding bad debt across all spokes, expressed in asset units and scaled by RAY.
  struct Asset {
    uint120 liquidity;
    uint120 realizedFees;
    uint8 decimals;
    //
    uint120 addedShares;
    uint120 swept;
    //
    int200 premiumOffsetRay;
    //
    uint120 drawnShares;
    uint120 premiumShares;
    uint16 liquidityFee;
    //
    uint120 drawnIndex;
    uint96 drawnRate;
    uint40 lastUpdateTimestamp;
    //
    address underlying;
    //
    address irStrategy;
    //
    address reinvestmentController;
    //
    address feeReceiver;
    //
    uint200 deficitRay;
  }

  /// @notice Asset configuration. Subset of the `Asset` struct.
  struct AssetConfig {
    address feeReceiver;
    uint16 liquidityFee;
    address irStrategy;
    address reinvestmentController;
  }

  /// @notice Spoke position and configuration data.
  /// @dev drawnShares The drawn shares of a spoke for a given asset.
  /// @dev premiumShares The premium shares of a spoke for a given asset.
  /// @dev premiumOffsetRay The premium offset of a spoke for a given asset, used to calculate the premium, expressed in asset units and scaled by RAY.
  /// @dev addedShares The added shares of a spoke for a given asset.
  /// @dev addCap The maximum amount that can be added by a spoke, expressed in whole assets (not scaled by decimals). A value of `MAX_ALLOWED_SPOKE_CAP` indicates no cap.
  /// @dev drawCap The maximum amount that can be drawn by a spoke, expressed in whole assets (not scaled by decimals). A value of `MAX_ALLOWED_SPOKE_CAP` indicates no cap.
  /// @dev riskPremiumThreshold The maximum ratio of premium to drawn shares a spoke can have, expressed in BPS. A value of `MAX_RISK_PREMIUM_THRESHOLD` indicates no threshold.
  /// @dev active True if the Spoke is allowed to perform any action.
  /// @dev halted True if the Spoke is prevented from performing actions that instantly update liquidity.
  /// @dev deficitRay The deficit reported by a spoke for a given asset, expressed in asset units and scaled by RAY.
  struct SpokeData {
    uint120 drawnShares;
    uint120 premiumShares;
    //
    int200 premiumOffsetRay;
    //
    uint120 addedShares;
    uint40 addCap;
    uint40 drawCap;
    uint24 riskPremiumThreshold;
    bool active;
    bool halted;
    //
    uint200 deficitRay;
  }

  /// @notice Spoke configuration data. Subset of the `SpokeData` struct.
  struct SpokeConfig {
    uint40 addCap;
    uint40 drawCap;
    uint24 riskPremiumThreshold;
    bool active;
    bool halted;
  }

  /// @notice Emitted when an asset is added.
  /// @param assetId The identifier of the asset.
  /// @param underlying The address of the underlying asset.
  /// @param decimals The number of decimals of the asset.
  event AddAsset(uint256 indexed assetId, address indexed underlying, uint8 decimals);

  /// @notice Emitted when an asset is updated.
  /// @param assetId The identifier of the asset.
  /// @param drawnIndex The new drawn index of the asset.
  /// @param drawnRate The new drawn rate of the asset.
  /// @param accruedFees The accrued fees of the asset since the last mint.
  event UpdateAsset(
    uint256 indexed assetId,
    uint256 drawnIndex,
    uint256 drawnRate,
    uint256 accruedFees
  );

  /// @notice Emitted when an asset configuration is updated.
  /// @param assetId The identifier of the asset.
  /// @param config The new asset configuration struct.
  event UpdateAssetConfig(uint256 indexed assetId, AssetConfig config);

  /// @notice Emitted when a spoke is added.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  event AddSpoke(uint256 indexed assetId, address indexed spoke);

  /// @notice Emitted when a spoke configuration is updated.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param config The new spoke configuration struct.
  event UpdateSpokeConfig(uint256 indexed assetId, address indexed spoke, SpokeConfig config);

  /// @notice Emitted when fees are minted to the fee receiver spoke.
  /// @param assetId The identifier of the asset.
  /// @param feeReceiver The address of the current fee receiver spoke.
  /// @param shares The amount of shares minted.
  /// @param assets The amount of assets used to mint the shares.
  event MintFeeShares(
    uint256 indexed assetId,
    address indexed feeReceiver,
    uint256 shares,
    uint256 assets
  );

  /// @notice Emitted when liquidity is invested by the reinvestment controller.
  /// @param assetId The identifier of the asset.
  /// @param reinvestmentController The active asset controller.
  /// @param amount The amount invested.
  event Sweep(uint256 indexed assetId, address indexed reinvestmentController, uint256 amount);

  /// @notice Emitted when liquidity is reclaimed (from swept liquidity) by the reinvestment controller.
  /// @param assetId The identifier of the asset.
  /// @param reinvestmentController The active asset controller.
  /// @param amount The amount reclaimed.
  event Reclaim(uint256 indexed assetId, address indexed reinvestmentController, uint256 amount);

  /// @notice Emitted when a deficit is eliminated.
  /// @param assetId The identifier of the asset.
  /// @param callerSpoke The spoke that eliminated the deficit using its added shares.
  /// @param coveredSpoke The spoke for which the deficit was eliminated.
  /// @param shares The amount of shares removed.
  /// @param deficitAmountRay The amount of deficit eliminated, expressed in asset units and scaled by RAY.
  event EliminateDeficit(
    uint256 indexed assetId,
    address indexed callerSpoke,
    address indexed coveredSpoke,
    uint256 shares,
    uint256 deficitAmountRay
  );

  /// @notice Thrown when an underlying asset is already listed.
  error UnderlyingAlreadyListed();

  /// @notice Thrown when an asset is not listed.
  error AssetNotListed();

  /// @notice Thrown when the add cap is exceeded.
  /// @param addCap The current `addCap` of the asset, expressed in whole assets (not scaled by decimals).
  error AddCapExceeded(uint256 addCap);

  /// @notice Thrown when the available liquidity is insufficient.
  /// @param liquidity The current available liquidity.
  error InsufficientLiquidity(uint256 liquidity);

  /// @notice Thrown when the transferred liquidity is insufficient.
  /// @param liquidityNeeded The amount of additional liquidity needed.
  error InsufficientTransferred(uint256 liquidityNeeded);

  /// @notice Thrown when the draw cap is exceeded.
  /// @param drawCap The current `drawCap` of the asset, expressed in whole assets (not scaled by decimals).
  error DrawCapExceeded(uint256 drawCap);

  /// @notice Thrown when a surplus amount of drawn is restored.
  /// @param maxAllowedRestore The maximum allowed drawn amount to restore.
  error SurplusDrawnRestored(uint256 maxAllowedRestore);

  /// @notice Thrown when a surplus amount of premium is restored.
  /// @param maxAllowedRestoreRay The maximum allowed premium amount to restore, expressed in asset units and scaled by RAY.
  error SurplusPremiumRayRestored(uint256 maxAllowedRestoreRay);

  /// @notice Thrown when the premium change is invalid.
  error InvalidPremiumChange();

  /// @notice Thrown when a surplus amount of drawn is reported as deficit.
  /// @param maxAllowedDeficit The maximum allowed drawn to report as deficit.
  error SurplusDrawnDeficitReported(uint256 maxAllowedDeficit);

  /// @notice Thrown when a surplus amount of premium is reported as deficit.
  /// @param maxAllowedDeficitRay The maximum allowed premium to report as deficit, expressed in asset units and scaled by RAY.
  error SurplusPremiumRayDeficitReported(uint256 maxAllowedDeficitRay);

  /// @notice Thrown when a spoke is not active.
  error SpokeNotActive();

  /// @notice Thrown when a spoke is halted.
  error SpokeHalted();

  /// @notice Thrown when a new reinvestment controller is the zero address and the asset has existing swept liquidity.
  error InvalidReinvestmentController();

  /// @notice Thrown when an invalid reinvestment controller attempts to perform a `sweep` action.
  error OnlyReinvestmentController();

  /// @notice Thrown when a spoke being added is already listed.
  error SpokeAlreadyListed();

  /// @notice Thrown when a spoke being updated is not listed.
  error SpokeNotListed();

  /// @notice Thrown when the amount is invalid.
  error InvalidAmount();

  /// @notice Thrown when the shares amount is invalid.
  error InvalidShares();

  /// @notice Thrown when an input address is invalid.
  error InvalidAddress();

  /// @notice Thrown if the liquidity fee is invalid when updating an asset configuration.
  error InvalidLiquidityFee();

  /// @notice Thrown when the asset decimals exceed the maximum allowed decimals.
  error InvalidAssetDecimals();

  /// @notice Thrown if the interest rate strategy or data are invalid when updating an asset configuration.
  /// @dev The `irData` must be empty if the interest rate strategy is not updated.
  error InvalidInterestRateStrategy();

  /// @notice Adds a new asset to the Hub.
  /// @dev The same underlying asset address cannot be added as an asset multiple times.
  /// @dev The fee receiver is added as a new spoke with maximum add cap and zero draw cap.
  /// @param underlying The address of the underlying asset.
  /// @param decimals The number of decimals of `underlying`.
  /// @param feeReceiver The address of the fee receiver spoke.
  /// @param irStrategy The address of the interest rate strategy contract.
  /// @param irData The interest rate data to apply to the given asset encoded in bytes.
  /// @return The unique identifier of the added asset.
  function addAsset(
    address underlying,
    uint8 decimals,
    address feeReceiver,
    address irStrategy,
    bytes calldata irData
  ) external returns (uint256);

  /// @notice Updates the configuration of an asset.
  /// @dev If the fee receiver is updated, adds it as a new spoke with maximum add cap and zero draw cap, and sets old fee receiver caps to zero.
  /// @dev If the fee receiver is updated, accrued fees are minted as shares before the update if their value exceeds one share.
  /// @dev If the interest rate strategy is updated, it is configured with `irData`. Otherwise, `irData` must be empty.
  /// @param assetId The identifier of the asset.
  /// @param config The new configuration for the asset.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  function updateAssetConfig(
    uint256 assetId,
    AssetConfig calldata config,
    bytes calldata irData
  ) external;

  /// @notice Registers a new spoke for a specific asset in the Hub.
  /// @dev Reverts with `SpokeAlreadyListed` if spoke is already listed.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke to add.
  /// @param params The configuration parameters for the Spoke.
  function addSpoke(uint256 assetId, address spoke, SpokeConfig calldata params) external;

  /// @notice Updates the configuration of a spoke for a specific asset.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke to update.
  /// @param config The new configuration for the Spoke.
  function updateSpokeConfig(uint256 assetId, address spoke, SpokeConfig calldata config) external;

  /// @notice Updates the interest rate strategy for a specified asset.
  /// @param assetId The identifier of the asset.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  function setInterestRateData(uint256 assetId, bytes calldata irData) external;

  /// @notice Mints shares to the fee receiver from accrued fees.
  /// @dev No op when fees are worth less than one share.
  /// @param assetId The identifier of the asset.
  /// @return The amount of shares minted.
  function mintFeeShares(uint256 assetId) external returns (uint256);

  /// @notice Eliminates deficit by removing added shares of caller spoke.
  /// @dev Only callable by active and authorized spokes.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount of deficit to eliminate.
  /// @param spoke The spoke for which the deficit is eliminated.
  /// @return The amount of added shares removed.
  /// @return The amount of deficit eliminated, expressed in asset units.
  function eliminateDeficit(
    uint256 assetId,
    uint256 amount,
    address spoke
  ) external returns (uint256, uint256);

  /// @notice Allows a spoke to transfer its added shares of an asset to another spoke.
  /// @dev Only callable by spokes.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of shares to move.
  /// @param toSpoke The address of the recipient spoke.
  function transferShares(uint256 assetId, uint256 shares, address toSpoke) external;

  /// @notice Sweeps an amount of liquidity of the corresponding asset and sends it to the configured reinvestment controller.
  /// @dev The controller handles the actual reinvestment of funds, redistribution of interest, and investment caps.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount to sweep.
  function sweep(uint256 assetId, uint256 amount) external;

  /// @notice Reclaims an amount of liquidity of the corresponding asset from the configured reinvestment controller.
  /// @dev The controller can only reclaim up to swept amount. All accrued interest is distributed offchain.
  /// @dev Underlying assets must be transferred to the Hub before invocation.
  /// @dev Extra untracked underlying liquidity in the Hub can be skimmed into the Hub's liquidity accounting through this action.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount to reclaim.
  function reclaim(uint256 assetId, uint256 amount) external;

  /// @notice Returns whether the underlying is listed as an asset.
  /// @param underlying The address of the underlying asset.
  /// @return True if the underlying asset is listed.
  function isUnderlyingListed(address underlying) external view returns (bool);

  /// @notice Returns the number of listed assets.
  function getAssetCount() external view returns (uint256);

  /// @notice Returns information regarding the specified asset.
  /// @dev `drawnIndex`, `drawnRate` and `lastUpdateTimestamp` can be outdated due to passage of time.
  /// @param assetId The identifier of the asset.
  /// @return The asset struct.
  function getAsset(uint256 assetId) external view returns (Asset memory);

  /// @notice Returns the asset configuration for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The asset configuration struct.
  function getAssetConfig(uint256 assetId) external view returns (AssetConfig memory);

  /// @notice Returns the accrued fees for the asset, expressed in asset units.
  /// @dev Accrued fees are excluded from total added assets.
  /// @param assetId The identifier of the asset.
  /// @return The amount of accrued fees.
  function getAssetAccruedFees(uint256 assetId) external view returns (uint256);

  /// @notice Returns the amount of liquidity swept by the reinvestment controller for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of liquidity swept.
  function getAssetSwept(uint256 assetId) external view returns (uint256);

  /// @notice Calculates the current drawn rate for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The current drawn rate of the asset.
  function getAssetDrawnRate(uint256 assetId) external view returns (uint256);

  /// @notice Returns the number of spokes listed for the specified asset.
  /// @param assetId The identifier of the asset.
  function getSpokeCount(uint256 assetId) external view returns (uint256);

  /// @notice Returns whether the Spoke is listed for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return True if the Spoke is listed.
  function isSpokeListed(uint256 assetId, address spoke) external view returns (bool);

  /// @notice Returns the address of the Spoke for an asset at the given index.
  /// @param assetId The identifier of the asset.
  /// @param index The index of the Spoke.
  /// @return The address of the Spoke.
  function getSpokeAddress(uint256 assetId, uint256 index) external view returns (address);

  /// @notice Returns the Spoke data struct.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The spoke data struct.
  function getSpoke(uint256 assetId, address spoke) external view returns (SpokeData memory);

  /// @notice Returns the Spoke configuration struct.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The spoke configuration struct.
  function getSpokeConfig(
    uint256 assetId,
    address spoke
  ) external view returns (SpokeConfig memory);

  /// @notice Returns the maximum allowed number of decimals for the underlying asset.
  /// @return The maximum number of decimals (inclusive).
  function MAX_ALLOWED_UNDERLYING_DECIMALS() external view returns (uint8);

  /// @notice Returns the minimum allowed number of decimals for the underlying asset.
  /// @return The minimum number of decimals (inclusive).
  function MIN_ALLOWED_UNDERLYING_DECIMALS() external view returns (uint8);

  /// @notice Returns the maximum value for any spoke cap (add or draw).
  /// @dev The value is not inclusive; using the maximum value indicates no cap.
  /// @return The maximum cap value, expressed in asset units.
  function MAX_ALLOWED_SPOKE_CAP() external view returns (uint40);

  /// @notice Returns the maximum value for any spoke risk premium threshold.
  /// @dev The value is not inclusive; using the maximum value indicates no threshold.
  /// @return The maximum risk premium threshold, expressed in BPS.
  function MAX_RISK_PREMIUM_THRESHOLD() external view returns (uint24);
}

src/hub/interfaces/IHubBase.sol

// SPDX-License-Identifier: LicenseRef-BUSL
pragma solidity ^0.8.0;

/// @title IHubBase
/// @author Aave Labs
/// @notice Minimal interface for Hub.
interface IHubBase {
  /// @notice Changes to premium owed accounting.
  /// @dev sharesDelta The change in premium shares.
  /// @dev offsetRayDelta The change in premium offset, expressed in asset units and scaled by RAY.
  /// @dev restoredPremiumRay The restored premium, expressed in asset units and scaled by RAY.
  struct PremiumDelta {
    int256 sharesDelta;
    int256 offsetRayDelta;
    uint256 restoredPremiumRay;
  }

  /// @notice Emitted on the `add` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param shares The amount of shares added.
  /// @param amount The amount of assets added.
  event Add(uint256 indexed assetId, address indexed spoke, uint256 shares, uint256 amount);

  /// @notice Emitted on the `remove` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param shares The amount of shares removed.
  /// @param amount The amount of assets removed.
  event Remove(uint256 indexed assetId, address indexed spoke, uint256 shares, uint256 amount);

  /// @notice Emitted on the `draw` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param drawnShares The amount of drawn shares.
  /// @param drawnAmount The amount of drawn assets.
  event Draw(
    uint256 indexed assetId,
    address indexed spoke,
    uint256 drawnShares,
    uint256 drawnAmount
  );

  /// @notice Emitted on the `restore` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param drawnShares The amount of drawn shares.
  /// @param premiumDelta The premium delta data struct.
  /// @param drawnAmount The amount of drawn assets restored.
  /// @param premiumAmount The amount of premium assets restored.
  event Restore(
    uint256 indexed assetId,
    address indexed spoke,
    uint256 drawnShares,
    PremiumDelta premiumDelta,
    uint256 drawnAmount,
    uint256 premiumAmount
  );

  /// @notice Emitted on the `refreshPremium` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param premiumDelta The premium delta data struct.
  event RefreshPremium(uint256 indexed assetId, address indexed spoke, PremiumDelta premiumDelta);

  /// @notice Emitted on the `reportDeficit` action.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param drawnShares The amount of drawn shares reported as deficit.
  /// @param premiumDelta The premium delta data struct.
  /// @param deficitAmountRay The amount of deficit reported, expressed in asset units and scaled by RAY.
  event ReportDeficit(
    uint256 indexed assetId,
    address indexed spoke,
    uint256 drawnShares,
    PremiumDelta premiumDelta,
    uint256 deficitAmountRay
  );

  /// @notice Emitted on the `transferShares` action.
  /// @param assetId The identifier of the asset.
  /// @param sender The address of the sender.
  /// @param receiver The address of the receiver.
  /// @param shares The amount of shares transferred.
  event TransferShares(
    uint256 indexed assetId,
    address indexed sender,
    address indexed receiver,
    uint256 shares
  );

  /// @notice Adds assets on behalf of a user.
  /// @dev Only callable by active spokes.
  /// @dev Underlying assets must be transferred to the Hub before invocation.
  /// @dev Extra untracked underlying liquidity in the Hub can be skimmed into the Hub's liquidity accounting through this action.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount of asset liquidity to add.
  /// @return The amount of shares added.
  function add(uint256 assetId, uint256 amount) external returns (uint256);

  /// @notice Removes assets on behalf of a user.
  /// @dev Only callable by active spokes.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount of asset liquidity to remove.
  /// @param to The address to transfer the assets to.
  /// @return The amount of shares removed.
  function remove(uint256 assetId, uint256 amount, address to) external returns (uint256);

  /// @notice Draws assets on behalf of a user.
  /// @dev Only callable by active spokes.
  /// @param assetId The identifier of the asset.
  /// @param amount The amount of assets to draw.
  /// @param to The address to transfer the underlying assets to.
  /// @return The amount of drawn shares.
  function draw(uint256 assetId, uint256 amount, address to) external returns (uint256);

  /// @notice Restores assets on behalf of a user.
  /// @dev Only callable by active spokes.
  /// @dev Interest is always paid off first from premium, then from drawn.
  /// @dev Underlying assets must be transferred to the Hub before invocation.
  /// @dev Extra untracked underlying liquidity in the Hub can be skimmed into the Hub's liquidity accounting through this action.
  /// @param assetId The identifier of the asset.
  /// @param drawnAmount The drawn amount to restore.
  /// @param premiumDelta The premium delta to apply which signals premium repayment.
  /// @return The amount of drawn shares restored.
  function restore(
    uint256 assetId,
    uint256 drawnAmount,
    PremiumDelta calldata premiumDelta
  ) external returns (uint256);

  /// @notice Reports an owed amount by the caller Spoke as a deficit.
  /// @dev Only callable by active spokes.
  /// @param assetId The identifier of the asset.
  /// @param drawnAmount The drawn amount to report as deficit.
  /// @param premiumDelta The premium delta to apply which signals premium deficit.
  /// @return The amount of drawn shares reported as deficit.
  /// @return The amount of deficit reported, expressed in asset units.
  function reportDeficit(
    uint256 assetId,
    uint256 drawnAmount,
    PremiumDelta calldata premiumDelta
  ) external returns (uint256, uint256);

  /// @notice Refreshes premium accounting.
  /// @dev Only callable by active spokes.
  /// @dev Asset and spoke premium should not decrease.
  /// @param assetId The identifier of the asset.
  /// @param premiumDelta The change in premium.
  function refreshPremium(uint256 assetId, PremiumDelta calldata premiumDelta) external;

  /// @notice Transfers an amount of added shares of the caller Spoke to the fee receiver Spoke.
  /// @dev It can be used to execute one-time payments to the fee receiver Spoke (e.g., liquidation fees).
  /// @dev Only callable by active spokes.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of shares to pay to feeReceiver.
  function payFeeShares(uint256 assetId, uint256 shares) external;

  /// @notice Converts the specified amount of assets to shares upon an `add` action.
  /// @dev Rounds down to the nearest shares amount.
  /// @dev Defaults to a 1:1 exchange rate.
  /// @param assetId The identifier of the asset.
  /// @param assets The amount of assets to convert to shares amount.
  /// @return The amount of shares converted from assets amount.
  function previewAddByAssets(uint256 assetId, uint256 assets) external view returns (uint256);

  /// @notice Converts the specified shares amount to assets amount added upon an `add` action.
  /// @dev Rounds up to the nearest assets amount.
  /// @dev Defaults to a 1:1 exchange rate.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of shares to convert to assets amount.
  /// @return The amount of assets converted from shares amount.
  function previewAddByShares(uint256 assetId, uint256 shares) external view returns (uint256);

  /// @notice Converts the specified amount of assets to shares amount removed upon a `remove` action.
  /// @dev Rounds up to the nearest shares amount.
  /// @dev Defaults to a 1:1 exchange rate.
  /// @param assetId The identifier of the asset.
  /// @param assets The amount of assets to convert to shares amount.
  /// @return The amount of shares converted from assets amount.
  function previewRemoveByAssets(uint256 assetId, uint256 assets) external view returns (uint256);

  /// @notice Converts the specified amount of shares to assets amount removed upon a `remove` action.
  /// @dev Rounds down to the nearest assets amount.
  /// @dev Defaults to a 1:1 exchange rate.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of shares to convert to assets amount.
  /// @return The amount of assets converted from shares amount.
  function previewRemoveByShares(uint256 assetId, uint256 shares) external view returns (uint256);

  /// @notice Converts the specified amount of assets to shares amount drawn upon a `draw` action.
  /// @dev Rounds up to the nearest shares amount.
  /// @param assetId The identifier of the asset.
  /// @param assets The amount of assets to convert to shares amount.
  /// @return The amount of shares converted from assets amount.
  function previewDrawByAssets(uint256 assetId, uint256 assets) external view returns (uint256);

  /// @notice Converts the specified amount of shares to assets amount drawn upon a `draw` action.
  /// @dev Rounds down to the nearest assets amount.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of shares to convert to assets amount.
  /// @return The amount of assets converted from shares amount.
  function previewDrawByShares(uint256 assetId, uint256 shares) external view returns (uint256);

  /// @notice Converts the specified amount of assets to shares amount restored upon a `restore` action.
  /// @dev Rounds down to the nearest shares amount.
  /// @param assetId The identifier of the asset.
  /// @param assets The amount of assets to convert to shares amount.
  /// @return The amount of shares converted from assets amount.
  function previewRestoreByAssets(uint256 assetId, uint256 assets) external view returns (uint256);

  /// @notice Converts the specified amount of shares to assets amount restored upon a `restore` action.
  /// @dev Rounds up to the nearest assets amount.
  /// @param assetId The identifier of the asset.
  /// @param shares The amount of drawn shares to convert to assets amount.
  /// @return The amount of assets converted from shares amount.
  function previewRestoreByShares(uint256 assetId, uint256 shares) external view returns (uint256);

  /// @notice Returns the asset identifier for the specified underlying asset.
  /// @dev Reverts with `AssetNotListed` if the underlying is not listed.
  /// @param underlying The address of the underlying asset.
  function getAssetId(address underlying) external view returns (uint256);

  /// @notice Returns the underlying address and decimals of the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The underlying address of the asset.
  /// @return The decimals of the asset.
  function getAssetUnderlyingAndDecimals(uint256 assetId) external view returns (address, uint8);

  /// @notice Calculates the current drawn index for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The current drawn index of the asset.
  function getAssetDrawnIndex(uint256 assetId) external view returns (uint256);

  /// @notice Returns the total amount of the specified asset added to the Hub.
  /// @param assetId The identifier of the asset.
  /// @return The amount of the asset added.
  function getAddedAssets(uint256 assetId) external view returns (uint256);

  /// @notice Returns the total amount of shares of the specified asset added to the Hub.
  /// @param assetId The identifier of the asset.
  /// @return The amount of shares of the asset added.
  function getAddedShares(uint256 assetId) external view returns (uint256);

  /// @notice Returns the amount of owed drawn and premium assets for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of owed drawn assets.
  /// @return The amount of owed premium assets.
  function getAssetOwed(uint256 assetId) external view returns (uint256, uint256);

  /// @notice Returns the total amount of assets owed to the Hub.
  /// @param assetId The identifier of the asset.
  /// @return The total amount of the assets owed.
  function getAssetTotalOwed(uint256 assetId) external view returns (uint256);

  /// @notice Returns the amount of owed premium with full precision for specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of premium owed, expressed in asset units and scaled by RAY.
  function getAssetPremiumRay(uint256 assetId) external view returns (uint256);

  /// @notice Returns the amount of drawn shares of the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of drawn shares.
  function getAssetDrawnShares(uint256 assetId) external view returns (uint256);

  /// @notice Returns the information regarding premium shares of the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of premium shares owed to the asset.
  /// @return The premium offset of the asset, expressed in asset units and scaled by RAY.
  function getAssetPremiumData(uint256 assetId) external view returns (uint256, int256);

  /// @notice Returns the amount of available liquidity for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of available liquidity.
  function getAssetLiquidity(uint256 assetId) external view returns (uint256);

  /// @notice Returns the amount of deficit with full precision of the specified asset.
  /// @param assetId The identifier of the asset.
  /// @return The amount of deficit, expressed in asset units and scaled by RAY.
  function getAssetDeficitRay(uint256 assetId) external view returns (uint256);

  /// @notice Returns the total amount of the specified assets added to the Hub by the specified spoke.
  /// @dev If spoke is `asset.feeReceiver`, includes converted `unrealizedFeeShares` in return value.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of added assets.
  function getSpokeAddedAssets(uint256 assetId, address spoke) external view returns (uint256);

  /// @notice Returns the total amount of shares of the specified asset added to the Hub by the specified spoke.
  /// @dev If spoke is `asset.feeReceiver`, includes `unrealizedFeeShares` in return value.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of added shares.
  function getSpokeAddedShares(uint256 assetId, address spoke) external view returns (uint256);

  /// @notice Returns the amount of the specified assets owed to the Hub by the specified spoke.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of owed drawn assets.
  /// @return The amount of owed premium assets.
  function getSpokeOwed(uint256 assetId, address spoke) external view returns (uint256, uint256);

  /// @notice Returns the total amount of the specified asset owed to the Hub by the specified spoke.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The total amount of the asset owed.
  function getSpokeTotalOwed(uint256 assetId, address spoke) external view returns (uint256);

  /// @notice Returns the amount of owed premium with full precision for specified asset and spoke.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of owed premium assets, expressed in asset units and scaled by RAY.
  function getSpokePremiumRay(uint256 assetId, address spoke) external view returns (uint256);

  /// @notice Returns the amount of drawn shares of the specified asset by the specified spoke.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of drawn shares.
  function getSpokeDrawnShares(uint256 assetId, address spoke) external view returns (uint256);

  /// @notice Returns the information regarding premium shares of the specified asset for the specified spoke.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of premium shares.
  /// @return The premium offset, expressed in asset units and scaled by RAY.
  function getSpokePremiumData(
    uint256 assetId,
    address spoke
  ) external view returns (uint256, int256);

  /// @notice Returns the amount of a given spoke's deficit with full precision for the specified asset.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @return The amount of deficit, expressed in asset units and scaled by RAY.
  function getSpokeDeficitRay(uint256 assetId, address spoke) external view returns (uint256);
}

src/hub/interfaces/IHubConfigurator.sol

// SPDX-License-Identifier: LicenseRef-BUSL
pragma solidity ^0.8.0;

import {IHub} from 'src/hub/interfaces/IHub.sol';

/// @title IHubConfigurator
/// @author Aave Labs
/// @notice Interface for HubConfigurator.
interface IHubConfigurator {
  /// @notice Thrown when an address parameter is the zero address.
  error InvalidAddress();

  /// @notice Thrown when the list of assets and spoke configs are not the same length in `addSpokeToAssets`.
  error MismatchedConfigs();

  /// @notice Adds a new asset to a specified Hub.
  /// @dev Retrieves the decimals of the underlying asset from its ERC20 contract.
  /// @dev The fee receiver is automatically added as a Spoke with maximum caps.
  /// @param hub The address of the Hub.
  /// @param underlying The address of the underlying asset.
  /// @param feeReceiver The address of the fee receiver Spoke.
  /// @param liquidityFee The liquidity fee of the asset, expressed in BPS.
  /// @param irStrategy The address of the interest rate strategy contract.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  /// @return The unique identifier of the added asset.
  function addAsset(
    address hub,
    address underlying,
    address feeReceiver,
    uint256 liquidityFee,
    address irStrategy,
    bytes calldata irData
  ) external returns (uint256);

  /// @notice Adds a new asset to a specified Hub with explicit decimals.
  /// @dev The fee receiver is automatically added as a Spoke with maximum caps.
  /// @param hub The address of the Hub.
  /// @param underlying The address of the underlying asset.
  /// @param decimals The number of decimals of the asset.
  /// @param feeReceiver The address of the fee receiver Spoke.
  /// @param liquidityFee The liquidity fee of the asset, expressed in BPS.
  /// @param irStrategy The address of the interest rate strategy contract.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  /// @return The unique identifier of the added asset.
  function addAssetWithDecimals(
    address hub,
    address underlying,
    uint8 decimals,
    address feeReceiver,
    uint256 liquidityFee,
    address irStrategy,
    bytes calldata irData
  ) external returns (uint256);

  /// @notice Updates the liquidity fee of an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param liquidityFee The new liquidity fee.
  function updateLiquidityFee(address hub, uint256 assetId, uint256 liquidityFee) external;

  /// @notice Updates the fee receiver of an asset on a specified hub.
  /// @dev The fee receiver cannot be zero.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param feeReceiver The new fee receiver.
  function updateFeeReceiver(address hub, uint256 assetId, address feeReceiver) external;

  /// @notice Updates the liquidity fee and fee receiver of an asset on a specified Hub.
  /// @dev The fee receiver cannot be zero.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param liquidityFee The new liquidity fee.
  /// @param feeReceiver The new fee receiver.
  function updateFeeConfig(
    address hub,
    uint256 assetId,
    uint256 liquidityFee,
    address feeReceiver
  ) external;

  /// @notice Updates the interest rate strategy of an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param irStrategy The new interest rate strategy.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  function updateInterestRateStrategy(
    address hub,
    uint256 assetId,
    address irStrategy,
    bytes calldata irData
  ) external;

  /// @notice Updates the reinvestment controller of an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param reinvestmentController The new reinvestment controller.
  function updateReinvestmentController(
    address hub,
    uint256 assetId,
    address reinvestmentController
  ) external;

  /// @notice Resets all Spokes' add and draw caps to zero for an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  function resetAssetCaps(address hub, uint256 assetId) external;

  /// @notice Deactivates an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  function deactivateAsset(address hub, uint256 assetId) external;

  /// @notice Halts an asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  function haltAsset(address hub, uint256 assetId) external;

  /// @notice Registers the Spoke for the specified asset on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param spoke The address of the Spoke.
  /// @param assetId The identifier of the asset to register the Spoke for.
  /// @param config The Spoke configuration to register.
  function addSpoke(
    address hub,
    address spoke,
    uint256 assetId,
    IHub.SpokeConfig calldata config
  ) external;

  /// @notice Registers the same Spoke for multiple assets on a specified Hub, each with their own configuration.
  /// @dev The i-th asset identifier in `assetIds` corresponds to the i-th configuration in `configs`.
  /// @param hub The address of the Hub.
  /// @param spoke The address of the Spoke.
  /// @param assetIds The list of asset identifiers to register the Spoke for.
  /// @param configs The list of Spoke configurations to register.
  function addSpokeToAssets(
    address hub,
    address spoke,
    uint256[] calldata assetIds,
    IHub.SpokeConfig[] calldata configs
  ) external;

  /// @notice Updates the active flag of an asset's Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param active The new active flag.
  function updateSpokeActive(address hub, uint256 assetId, address spoke, bool active) external;

  /// @notice Updates the halted flag of an asset's Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param halted The new halted flag.
  function updateSpokeHalted(address hub, uint256 assetId, address spoke, bool halted) external;

  /// @notice Updates the add cap of an asset's spoke on a specified hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param addCap The new add cap.
  function updateSpokeAddCap(address hub, uint256 assetId, address spoke, uint256 addCap) external;

  /// @notice Updates the draw cap of an asset's Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param drawCap The new draw cap.
  function updateSpokeDrawCap(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 drawCap
  ) external;

  /// @notice Updates the risk premium threshold of an asset's Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param riskPremiumThreshold The new risk premium threshold.
  function updateSpokeRiskPremiumThreshold(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 riskPremiumThreshold
  ) external;

  /// @notice Updates the caps of an asset's Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param spoke The address of the Spoke.
  /// @param addCap The new add cap.
  /// @param drawCap The new draw cap.
  function updateSpokeCaps(
    address hub,
    uint256 assetId,
    address spoke,
    uint256 addCap,
    uint256 drawCap
  ) external;

  /// @notice Deactivates all assets of a Spoke on a specified Hub by setting the active flag to false.
  /// @param hub The address of the Hub.
  /// @param spoke The address of the Spoke.
  function deactivateSpoke(address hub, address spoke) external;

  /// @notice Halts all assets of a Spoke on a specified Hub by setting the halted flag to true.
  /// @param hub The address of the Hub.
  /// @param spoke The address of the Spoke.
  function haltSpoke(address hub, address spoke) external;

  /// @notice Resets draw cap and add cap to zero for a Spoke on a specified Hub.
  /// @param hub The address of the Hub.
  /// @param spoke The address of the Spoke.
  function resetSpokeCaps(address hub, address spoke) external;

  /// @notice Updates the interest rate data for an asset.
  /// @param hub The address of the Hub.
  /// @param assetId The identifier of the asset.
  /// @param irData The interest rate data to apply to the given asset, encoded in bytes.
  function updateInterestRateData(address hub, uint256 assetId, bytes calldata irData) external;
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 44444444,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "erc4626-tests/=lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.