Skip to main content

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

VariableTypeVisibilityDescription
deployeraddresspublicImmutable address of the contract deployer.
atlasaddresspublicAddress 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

NameTypeDescription
userOpUserOperationThe user operation to be simulated.

Return Values

NameTypeDescription
successboolIndicates if the simulation was successful.
simResultResultThe result of the simulation.
uint256uint256Additional 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

NameTypeDescription
userOpUserOperationThe user operation associated with the solver.
solverOpSolverOperationThe solver operation to be simulated.
dAppOpDAppOperationThe decentralized application's operation context.

Return Values

NameTypeDescription
successboolIndicates if the simulation was successful.
simResultResultThe result of the simulation.
uint256uint256Additional 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

NameTypeDescription
userOpUserOperationThe user operation associated with the solvers.
solverOpsSolverOperation[]Array of solver operations to be simulated.
dAppOpDAppOperationThe decentralized application's operation context.

Return Values

NameTypeDescription
successboolIndicates if the simulation was successful.
simResultResultThe result of the simulation.
uint256uint256Additional 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

NameTypeDescription
_atlasaddressNew 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

NameTypeDescription
toaddressAddress 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.