generated from defi-wonderland/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Operator Access Module #52
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
17ca3b8
feat: ebo access module
ashitakah 0c8bd5b
fix: use `bound` instead of `vm.assume` (#53)
xorsal db96f64
test: remove `horizonStaking` as constructor param
xorsal 630ce61
feat: remove `horizonStaking` as constructor param
xorsal 59fdc19
test: use _assumeFuzzable for constructor param in tests
xorsal 4a93673
feat: update external HorizonStaking interface
xorsal 4eab453
chore: remove unused import
xorsal 9153e5d
feat: update EBOAccessModule interface
xorsal 13be099
chore: remove resolved todos
xorsal 3534df6
feat: remove duplicate function definition
xorsal 64ecc28
chore: update dependencies (#54)
xorsal 25c3341
Merge branch 'feat/access-control' into feat/ebo-access-module
xorsal a2e83e7
chore: remove unused variables
xorsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.26; | ||
|
||
import { | ||
IAccessModule, | ||
IArbitrable, | ||
IEBOAccessModule, | ||
IHorizonAccountingExtension, | ||
IHorizonStaking, | ||
IOracle | ||
} from 'interfaces/IEBOAccessModule.sol'; | ||
|
||
import {IModule, Module} from '@defi-wonderland/prophet-core/solidity/contracts/Module.sol'; | ||
|
||
contract EBOAccessModule is IEBOAccessModule, Module { | ||
/// @inheritdoc IEBOAccessModule | ||
IArbitrable public immutable ARBITRABLE; | ||
/// @inheritdoc IEBOAccessModule | ||
IHorizonStaking public horizonStaking; | ||
/// @inheritdoc IEBOAccessModule | ||
IHorizonAccountingExtension public horizonAccountingExtension; | ||
|
||
/** | ||
* @notice Constructor | ||
* @param _oracle The address of the Oracle | ||
* @param _arbitrable The address of the Arbitrable contract | ||
* @param _horizonAccountingExtension The address of the Horizon Accounting Extension contract | ||
*/ | ||
constructor( | ||
IOracle _oracle, | ||
IArbitrable _arbitrable, | ||
IHorizonAccountingExtension _horizonAccountingExtension | ||
) Module(_oracle) { | ||
ARBITRABLE = _arbitrable; | ||
_setHorizonAccountingExtension(_horizonAccountingExtension); | ||
} | ||
|
||
/// @inheritdoc IAccessModule | ||
function decodeAccessControlParameters(bytes calldata _data) | ||
public | ||
pure | ||
returns (IAccessModule.AccessControlParameters memory _params) | ||
{ | ||
_params = abi.decode(_data, (IAccessModule.AccessControlParameters)); | ||
} | ||
|
||
/// @inheritdoc IAccessModule | ||
function hasAccess(bytes calldata _data) external view returns (bool _hasAccess) { | ||
IAccessModule.AccessControlParameters memory _params = decodeAccessControlParameters(_data); | ||
_hasAccess = | ||
horizonStaking.isAuthorized(_params.accessControl.user, address(horizonAccountingExtension), _params.sender); | ||
0xJabberwock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// @inheritdoc IEBOAccessModule | ||
function setHorizonAccountingExtension(IHorizonAccountingExtension _horizonAccountingExtension) external { | ||
ARBITRABLE.validateArbitrator(msg.sender); | ||
|
||
_setHorizonAccountingExtension(_horizonAccountingExtension); | ||
} | ||
|
||
/// @inheritdoc IModule | ||
function moduleName() external pure returns (string memory _moduleName) { | ||
_moduleName = 'EBOAccessModule'; | ||
} | ||
|
||
/** | ||
* @notice Internal function to set the horizon accounting extension contract. | ||
* @dev It also updates the `horizonStaking` address. | ||
* @param _horizonAccountingExtension The new horizon accounting extension contract. | ||
*/ | ||
function _setHorizonAccountingExtension(IHorizonAccountingExtension _horizonAccountingExtension) internal { | ||
horizonAccountingExtension = _horizonAccountingExtension; | ||
|
||
// also update horizon staking address using the accounting extension view function | ||
horizonStaking = _horizonAccountingExtension.HORIZON_STAKING(); | ||
|
||
emit HorizonAccountingExtensionSet(_horizonAccountingExtension); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.26; | ||
|
||
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol'; | ||
import {IAccessModule} from '@defi-wonderland/prophet-core/solidity/interfaces/modules/access/IAccessModule.sol'; | ||
|
||
import {IHorizonAccountingExtension} from 'interfaces/IHorizonAccountingExtension.sol'; | ||
|
||
import {IHorizonStaking} from 'interfaces/external/IHorizonStaking.sol'; | ||
|
||
import {IArbitrable} from 'interfaces/IArbitrable.sol'; | ||
|
||
interface IEBOAccessModule is IAccessModule { | ||
/*/////////////////////////////////////////////////////////////// | ||
EVENTS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Emitted when the Horizon Accounting Extension contract is set | ||
* @param _horizonAccountingExtension The new Horizon Accounting Extension contract | ||
*/ | ||
event HorizonAccountingExtensionSet(IHorizonAccountingExtension indexed _horizonAccountingExtension); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice The Arbitrable contract | ||
* @return _arbitrable The Arbitrable contract | ||
*/ | ||
function ARBITRABLE() external view returns (IArbitrable _arbitrable); | ||
|
||
/** | ||
* @notice The Horizon Accounting Extension contract | ||
* @return _horizonAccountingExtension The Horizon Accounting Extension contract | ||
*/ | ||
function horizonAccountingExtension() external view returns (IHorizonAccountingExtension _horizonAccountingExtension); | ||
|
||
/** | ||
* @notice The Horizon Staking contract | ||
* @return _horizonStaking The Horizon Staking contract | ||
*/ | ||
function horizonStaking() external view returns (IHorizonStaking _horizonStaking); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Sets the Horizon Accounting Extension contract | ||
* @param _horizonAccountingExtension The new Horizon Accounting Extension contract | ||
*/ | ||
function setHorizonAccountingExtension(IHorizonAccountingExtension _horizonAccountingExtension) external; | ||
} |
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
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HorizonAccountingExtension
features an immutable state variable forHorizonStaking
, which is inconsistent with how it is treated here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn’t aware of
IHorizonStakingExtension::HORIZON_STAKING()
. I wouldn't say it's inconsistent, it could definitely lead to unexpected behavior if the wrong addresses are set during deployment.But more importantly, if
horizonStaking
can be obtained via a call (staticcall
?) tohorizonAccountingExtension
, then I propose removing thehorizonStaking
state variable and instead callingHorizonStakingExtension::HORIZON_STAKING
every time it’s needed, which is only inside of thehasAccess
function.Would this make sense to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performing an external call ad infinitum to get an immutable variable doesn't make sense to me in terms of gas efficiency, compared to storing it once. The
HorizonStaking
address could be sent in the constructor or got through a single external call in it—however, this last option requiresHorizonAccountingExtension
to have been deployed, which might not be desirable.Beware that
HorizonStaking
,HorizonStakingExtension
andHorizonAccountingExtension
refer to different contracts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I mixed up the contract names.
HorizonAccountingExtension
is the one that has the external viewHORIZON_STAKING
The HorizonAccountingExtension should be already deployed when
EBOAccessModule
is live because it's used inhasAccess
to do theisAuthorized
call.And if that isn't the case, the module also have
setHorizonAccountingExtension
to update its address whenever necessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now whenever the
horizonAccountingExtension
is updated, it will also callHORIZON_STAKING
and update thehorizonStaking
address.Relevant changes in: 630ce61