Skip to main content

ExecutionEnvironment

The ExecutionEnvironment contract is a fundamental component of the Atlas Protocol, responsible for managing and executing user and solver operations within a metacall transaction. It implements the IExecutionEnvironment interface, ensuring a standardized set of functions for interaction with the Atlas ecosystem.

Each unique combination of a User address and a DAppControl address deploys its own instance of this contract, ensuring isolated and secure execution environments tailored to specific interactions. The Factory contract leverages the ExecutionEnvironment in conjunction with the create2 opcode to deploy these sandboxed environments deterministically. This approach guarantees that each ExecutionEnvironment instance is uniquely and predictably deployed, enhancing both security and isolation for individual User and DAppControl interactions.

By implementing the IExecutionEnvironment interface, the contract provides a consistent API for core functions such as preOpsWrapper, userWrapper, and other essential operations, facilitating seamless integration with other components of the Atlas Protocol.

preOpsWrapper

function preOpsWrapper(UserOperation calldata userOp) external validUser(userOp) onlyAtlasEnvironment returns (bytes memory);

Description

Called by the Atlas contract before executing a UserOperation. It delegates the call to the preOpsCall function of the DAppControl contract associated with the current metacall transaction.

Parameters

NameTypeDescription
userOpUserOperationThe user operation being executed.

Return Values

NameTypeDescription
preOpsDatabytesData to be passed to the next call phase.

Requirements

  • The caller must be the Atlas contract (enforced by onlyAtlasEnvironment modifier).
  • The UserOperation must be valid (enforced by validUser modifier).

Usage Notes

  • This function is crucial for executing any preliminary operations before the main user operation.
  • The returned data can be used to influence subsequent execution phases.

userWrapper

function userWrapper(UserOperation calldata userOp) external payable validUser(userOp) onlyAtlasEnvironment returns (bytes memory returnData);

Description

Executes the main UserOperation. Depending on the CallConfig, it either uses delegatecall or a standard call to execute the user's operation.

Parameters

NameTypeDescription
userOpUserOperationThe user operation being executed.

Return Values

NameTypeDescription
returnDatabytesData returned from the user operation call.

Requirements

  • The caller must be the Atlas contract.
  • The UserOperation must be valid.
  • If using delegatecall, the contract must have sufficient balance to cover the operation's value.

Usage Notes

  • The choice between delegatecall and standard call is determined by the CallConfig.
  • This function is the core of user operation execution within the ExecutionEnvironment.

postOpsWrapper

function postOpsWrapper(bool solved, bytes calldata returnData) external onlyAtlasEnvironment;

Description

Called by the Atlas contract after completing a metacall transaction. It delegates the call to the postOpsCall function of the DAppControl contract.

Parameters

NameTypeDescription
solvedboolIndicates if a winning SolverOperation was successful.
returnDatabytesData returned from the previous call phase.

Return Values

None

Requirements

  • The caller must be the Atlas contract.

Usage Notes

  • This function is important for executing any cleanup or finalization logic after the main operation.

solverPreTryCatch

function solverPreTryCatch(
uint256 bidAmount,
SolverOperation calldata solverOp,
bytes calldata returnData
) external payable onlyAtlasEnvironment validSolver(solverOp) returns (SolverTracker memory solverTracker);

Description

Handles the pre-execution phase of a SolverOperation. It initializes the SolverTracker with bid information and executes any pre-solver hooks if required by the CallConfig.

Parameters

NameTypeDescription
bidAmountuint256The solver's bid amount.
solverOpSolverOperationThe solver operation being executed.
returnDatabytesData returned from the previous call phase.

Return Values

NameTypeDescription
solverTrackerSolverTrackerBid tracking information for the solver.

Requirements

  • The caller must be the Atlas contract.
  • The SolverOperation must be valid.

Usage Notes

  • This function is crucial for setting up the solver's execution context and handling pre-execution logic.

solverPostTryCatch

function solverPostTryCatch(
SolverOperation calldata solverOp,
bytes calldata returnData,
SolverTracker memory solverTracker
) external payable onlyAtlasEnvironment returns (SolverTracker memory);

Description

Handles the post-execution phase of a SolverOperation. It updates the SolverTracker based on the outcome and ensures bid conditions are met.

Parameters

NameTypeDescription
solverOpSolverOperationThe solver operation being executed.
returnDatabytesData returned from the previous call phase.
solverTrackerSolverTrackerBid tracking information for the solver.

Return Values

NameTypeDescription
solverTrackerSolverTrackerUpdated bid tracking information.

Requirements

  • The caller must be the Atlas contract.

Usage Notes

  • This function is essential for finalizing solver operations and ensuring all bid conditions are satisfied.

allocateValue

function allocateValue(
address bidToken,
uint256 bidAmount,
bytes memory allocateData
) external onlyAtlasEnvironment returns (bool allocateValueSucceeded);

Description

Allocates value based on the outcome of a successful SolverOperation. It delegates the call to the allocateValueCall function of the DAppControl contract and handles potential failures based on the CallConfig.

Parameters

NameTypeDescription
bidTokenaddressAddress of the token used for the bid.
bidAmountuint256Amount of the bid.
allocateDatabytesData returned from the previous call phase.

Return Values

NameTypeDescription
allocateValueSucceededboolIndicates if the allocation was successful.

Requirements

  • The caller must be the Atlas contract.

Usage Notes

  • This function is crucial for distributing value after successful solver operations.
  • The behavior on allocation failure can be configured in the CallConfig.

withdrawERC20

function withdrawERC20(address token, uint256 amount) external;

Description

Allows the environment owner to withdraw ERC20 tokens from the ExecutionEnvironment.

Parameters

NameTypeDescription
tokenaddressAddress of the ERC20 token to withdraw.
amountuint256Amount of the ERC20 token to withdraw.

Return Values

None

Requirements

  • The caller must be the environment owner.
  • The Atlas protocol must be in an unlocked state.
  • The contract must have sufficient balance of the specified token.

Usage Notes

  • This function provides a way for the owner to retrieve ERC20 tokens from the execution environment.

withdrawEther

function withdrawEther(uint256 amount) external;

Description

Enables the environment owner to withdraw Ether from the ExecutionEnvironment.

Parameters

NameTypeDescription
amountuint256Amount of Ether to withdraw.

Return Values

None

Requirements

  • The caller must be the environment owner.
  • The Atlas protocol must be in an unlocked state.
  • The contract must have sufficient Ether balance.

Usage Notes

  • This function allows the owner to retrieve Ether from the execution environment.

getUser

function getUser() external pure returns (address user);

Description

Retrieves the address of the user associated with this ExecutionEnvironment.

Parameters

None

Return Values

NameTypeDescription
useraddressAddress of the user.

Requirements

None

Usage Notes

  • This function is useful for identifying the user associated with the execution environment.

getControl

function getControl() external pure returns (address control);

Description

Fetches the address of the DAppControl contract associated with the current metacall transaction.

Parameters

None

Return Values

NameTypeDescription
controladdressAddress of the DAppControl contract.

Requirements

None

Usage Notes

  • This function helps in identifying the DAppControl contract governing the current execution context.

getConfig

function getConfig() external pure returns (uint32 config);

Description

Returns the CallConfig of the current metacall transaction in uint32 form.

Parameters

None

Return Values

NameTypeDescription
configuint32Configuration flags in bitmask format.

Requirements

None

Usage Notes

  • This function is crucial for understanding the current execution configuration.

getEscrow

function getEscrow() external view returns (address);

Description

Retrieves the address of the Atlas/Escrow contract.

Parameters

None

Return Values

NameTypeDescription
addressaddressAddress of the Atlas/Escrow contract.

Requirements

None

Usage Notes

  • This function is useful for interactions that require knowledge of the Escrow contract address.