DAppControl Contract
The DAppControl contract serves as the foundational base for decentralized applications (dApps) integrating with the Atlas Protocol. Designed as an abstract contract, it outlines essential functionalities and hooks that dApp developers must implement to seamlessly interact with the Atlas ecosystem. By inheriting from DAppControl
, dApps can leverage standardized processes for handling user and solver operations, ensuring consistency, security, and efficiency across the protocol.
For comprehensive guidance on building and integrating dApp modules using this contract, refer to the Building Modules Guide.
Note: While DAppControl
is defined as an abstract contract to enforce the implementation of its functions, concrete dApp modules should inherit from this contract and provide concrete implementations, resulting in non-abstract contracts.
Inheritance
abstract contract DAppControl is DAppControlTemplate, ExecutionBase {
// Contract code...
}
State Variables
Variable | Type | Visibility | Description |
---|---|---|---|
CALL_CONFIG | uint32 | public | Encoded call configuration flags. |
CONTROL | address | public | Immutable address representing the control contract itself. |
ATLAS_VERIFICATION | address | public | Immutable address of the Atlas Verification contract. |
governance | address | public | Current governance address. |
pendingGovernance | address | public | Address proposed to assume governance. |
Events
Event | Description |
---|---|
GovernanceTransferStarted | Emitted when a governance transfer is initiated. |
GovernanceTransferred | Emitted upon successful transfer of governance. |
DeployerWithdrawal | Emitted when the deployer withdraws Ether. |
Constructor
constructor(address atlas, address initialGovernance, CallConfig memory callConfig) ExecutionBase(atlas)
Description
Initializes the DAppControl contract by setting up essential configurations and governance parameters.
Parameters
Name | Type | Description |
---|---|---|
atlas | address | Address of the deployed Atlas protocol contract. |
initialGovernance | address | Address to be set as the initial governance. |
callConfig | CallConfig | Struct containing call configuration flags. |
Modifiers
Modifier | Description |
---|---|
validControl | Ensures operations are executed by the correct control contract. |
onlyPhase | Restricts function execution to specific protocol phases. |
mustBeCalled | Ensures functions are only callable via delegatecalls from the control contract. |
External Functions
preOpsCall
function preOpsCall(UserOperation calldata userOp) external payable validControl onlyAtlasEnvironment onlyPhase(ExecutionPhase.PreOps) returns (bytes memory)
Description
Hook executed before a UserOperation is processed.
preSolverCall
function preSolverCall(SolverOperation calldata solverOp, bytes calldata returnData) external payable validControl validSolver(solverOp) onlyAtlasEnvironment onlyPhase(ExecutionPhase.PreSolver)
Description
Hook executed before a SolverOperation is processed.
postSolverCall
function postSolverCall(SolverOperation calldata solverOp, bytes calldata returnData) external payable validControl validSolver(solverOp) onlyAtlasEnvironment onlyPhase(ExecutionPhase.PostSolver)
Description
Hook executed after a SolverOperation has been processed.
allocateValueCall
function allocateValueCall(address bidToken, uint256 bidAmount, bytes calldata data) external validControl onlyAtlasEnvironment onlyPhase(ExecutionPhase.AllocateValue)
Description
Hook executed after a successful SolverOperation for value allocation.
postOpsCall
function postOpsCall(bool solved, bytes calldata data) external payable validControl onlyAtlasEnvironment onlyPhase(ExecutionPhase.PostOps)
Description
Final hook executed as the last phase of a metacall transaction.
userDelegated
function userDelegated() external view returns (bool delegated)
Description
Checks if user operations need to be delegated.
requireSequentialUserNonces
function requireSequentialUserNonces() external view returns (bool isSequential)
Description
Determines if sequential nonces are required for user operations.
requireSequentialDAppNonces
function requireSequentialDAppNonces() external view returns (bool isSequential)
Description
Determines if sequential nonces are required for dApp operations.
getDAppConfig
function getDAppConfig(UserOperation calldata userOp) external view mustBeCalled returns (DAppConfig memory dConfig)
Description
Retrieves the DAppConfig for a given UserOperation.
getCallConfig
function getCallConfig() external view returns (CallConfig memory)
Description
Retrieves the current call configuration settings.
getDAppSignatory
function getDAppSignatory() external view mustBeCalled returns (address)
Description
Returns the current governance address.
transferGovernance
function transferGovernance(address newGovernance) external mustBeCalled
Description
Initiates the transfer of governance to a new address.
acceptGovernance
function acceptGovernance() external mustBeCalled
Description
Completes the governance transfer process.
Internal Functions
_validateCallConfig
function _validateCallConfig(uint32 callConfig) internal view
Description
Validates the encoded call configuration.
Error Handling
The contract utilizes custom errors inherited from AtlasErrors:
AtlasErrors.InvalidControl()
AtlasErrors.WrongPhase()
AtlasErrors.NoDelegatecall()
AtlasErrors.OnlyGovernance()
AtlasErrors.Unauthorized()
Usage Examples
Implementing a Concrete DAppControl
contract MyDAppControl is DAppControl {
constructor(address atlas, address initialGovernance, CallConfig memory callConfig)
DAppControl(atlas, initialGovernance, callConfig)
{}
function _preOpsCall(UserOperation calldata userOp) internal override returns (bytes memory) {
// Custom pre-operation logic
}
// ... (other overridden functions)
}
Transferring Governance
dAppControl.transferGovernance(newGovernanceAddress);
dAppControl.acceptGovernance();