Simulator
The Simulator contract serves as a testing and simulation tool within the Atlas Protocol. It allows users and developers to simulate UserOperation and SolverOperation transactions without executing them on the main protocol, enhancing the protocol's robustness and reliability.
The contract inherits from AtlasErrors
.
State Variables
Variable | Type | Visibility | Description |
---|---|---|---|
deployer | address | public | Immutable address of the contract deployer. |
atlas | address | public | Address of the deployed Atlas protocol contract. |
Events
DeployerWithdrawal
event DeployerWithdrawal(address indexed to, uint256 amount);
Emitted when the deployer successfully withdraws Ether from the Simulator contract.
Constructor
constructor()
Description
Initializes the Simulator contract by setting the deployer address to the account that deploys the contract.
External Functions
simUserOperation
function simUserOperation(UserOperation calldata userOp)
external
payable
returns (bool success, Result simResult, uint256)
Description
Simulates a UserOperation within the Atlas protocol.
Parameters
Name | Type | Description |
---|---|---|
userOp | UserOperation | The user operation to be simulated. |
Return Values
Name | Type | Description |
---|---|---|
success | bool | Indicates if the simulation was successful. |
simResult | Result | The result of the simulation. |
uint256 | uint256 | Additional error code or information. |
Requirements
- The Simulator contract must have enough Ether to process the simulation.
simSolverCall
function simSolverCall(
UserOperation calldata userOp,
SolverOperation calldata solverOp,
DAppOperation calldata dAppOp
)
external
payable
returns (bool success, Result simResult, uint256)
Description
Simulates a single SolverOperation within a UserOperation.
Parameters
Name | Type | Description |
---|---|---|
userOp | UserOperation | The user operation associated with the solver. |
solverOp | SolverOperation | The solver operation to be simulated. |
dAppOp | DAppOperation | The decentralized application's operation context. |
Return Values
Name | Type | Description |
---|---|---|
success | bool | Indicates if the simulation was successful. |
simResult | Result | The result of the simulation. |
uint256 | uint256 | Additional error code or information. |
Requirements
- The Simulator contract must have enough Ether to process the simulation.
simSolverCalls
function simSolverCalls(
UserOperation calldata userOp,
SolverOperation[] calldata solverOps,
DAppOperation calldata dAppOp
)
external
payable
returns (bool success, Result simResult, uint256)
Description
Simulates multiple SolverOperation instances within a single UserOperation.
Parameters
Name | Type | Description |
---|---|---|
userOp | UserOperation | The user operation associated with the solvers. |
solverOps | SolverOperation[] | Array of solver operations to be simulated. |
dAppOp | DAppOperation | The decentralized application's operation context. |
Return Values
Name | Type | Description |
---|---|---|
success | bool | Indicates if the simulation was successful. |
simResult | Result | The result of the simulation. |
uint256 | uint256 | Additional error code or information. |
Requirements
- The Simulator contract must have enough Ether to process the simulation.
- At least one solver operation must be provided.
setAtlas
function setAtlas(address _atlas) external
Description
Sets or updates the address of the Atlas protocol contract.
Parameters
Name | Type | Description |
---|---|---|
_atlas | address | New address of the deployed Atlas protocol contract. |
Requirements
- Only the deployer can call this function.
withdrawETH
function withdrawETH(address to) external
Description
Allows the deployer to withdraw all Ether from the Simulator contract.
Parameters
Name | Type | Description |
---|---|---|
to | address | Address to receive the withdrawn Ether. |
Requirements
- Only the deployer can call this function.
Internal Functions
_errorCatcher
function _errorCatcher(
UserOperation memory userOp,
SolverOperation[] memory solverOps,
DAppOperation memory dAppOp
)
internal
returns (Result result, uint256 additionalErrorCode)
Description
Handles and interprets errors arising from the simulation of metacall transactions.
metacallSimulation
function metacallSimulation(
UserOperation calldata userOp,
SolverOperation[] calldata solverOps,
DAppOperation calldata dAppOp
)
external
payable
Description
Performs the actual simulation of a metacall transaction.
Error Handling
The Simulator contract utilizes custom errors inherited from AtlasErrors:
SimulatorBalanceTooLow()
Unauthorized()
InvalidEntryFunction()
Usage Examples
For usage examples and implementation details, please refer to the SDK documentation on simulating user operations:
These SDKs provide convenient methods to interact with the Simulator contract and perform simulations of user operations.