-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9157ea
commit c57c89a
Showing
12 changed files
with
72 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.21; | ||
|
||
import {IHub} from "./interfaces/IHub.sol"; | ||
import {IRegistry} from "./interfaces/IRegistry.sol"; | ||
import {App} from "./interfaces/IApp.sol"; | ||
import {Adapter} from "./interfaces/IAdapter.sol"; | ||
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol"; | ||
|
||
contract Hub is IHub, AccessManaged { | ||
IRegistry public immutable registryAddress; | ||
uint256 private _appIdSalt; | ||
/** | ||
* @title Hub | ||
* @notice This contract is used to manage apps in the protocol | ||
*/ | ||
|
||
mapping(bytes32 => App) private _apps; | ||
|
||
constructor(IRegistry registryAddress_, address accessManagement_) AccessManaged(accessManagement_) { | ||
registryAddress = registryAddress_; | ||
contract Hub is AccessManaged { | ||
struct App { | ||
address appAddress; | ||
} | ||
|
||
modifier checkIsRegistryAdapter(bytes32 adapterId_) { | ||
if (!registryAddress.isAdapter(adapterId_)) { | ||
revert IHub.Hub_AdapterNotFound(adapterId_); | ||
} | ||
_; | ||
} | ||
/// @notice The salt used to generate appIds | ||
uint256 private s_appIdSalt; | ||
|
||
mapping(bytes32 => App) private s_apps; | ||
|
||
function createApp( | ||
bytes32 adapterId_, | ||
address appAddress_ | ||
) external checkIsRegistryAdapter(adapterId_) restricted returns (bytes32) { | ||
App memory app = App({adapter: _getRegistryAdapter(adapterId_), appAddress: appAddress_}); | ||
/// @notice Emitted when an app is added to the hub | ||
event Hub_AppAdded(bytes32 indexed appId_); | ||
|
||
bytes32 appId = keccak256(abi.encodePacked(_appIdSalt++, adapterId_, appAddress_, msg.sender)); | ||
constructor(address accessManagement_) AccessManaged(accessManagement_) {} | ||
|
||
_apps[appId] = app; | ||
/** | ||
* @notice Adds an app to the hub | ||
* @param appAddress_ The address of the app contract | ||
* @return The id of the app | ||
*/ | ||
function addApp(address appAddress_) external restricted returns (bytes32) { | ||
bytes32 appId = _getNextAppId(appAddress_); | ||
s_apps[appId] = App({appAddress: appAddress_}); | ||
|
||
emit IHub.Hub_AppCreated(appId); | ||
emit Hub_AppAdded(appId); | ||
|
||
return appId; | ||
} | ||
|
||
function _getRegistryAdapter(bytes32 adapterId_) internal view returns (Adapter memory) { | ||
return registryAddress.getAdapter(adapterId_); | ||
/** | ||
* @notice Gets the next app id | ||
* @param appAddress_ The address of the app contract | ||
* @return The id of the app | ||
*/ | ||
function _getNextAppId(address appAddress_) private returns (bytes32) { | ||
return keccak256(abi.encodePacked(_getNextAppIdSalt(), msg.sender, appAddress_)); | ||
} | ||
|
||
/** | ||
* @notice Gets the next app id salt | ||
* @return The next app id salt | ||
*/ | ||
function _getNextAppIdSalt() private returns (uint256) { | ||
return s_appIdSalt++; | ||
} | ||
|
||
/** | ||
* @notice Gets an app from the hub | ||
* @param appId_ The id of the app | ||
* @return The app | ||
*/ | ||
function getApp(bytes32 appId_) external view returns (App memory) { | ||
return _apps[appId_]; | ||
return s_apps[appId_]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
test/access-management/fixtures.ts → test/accessManagement/fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.