Skip to main content

Solidity API

ExecutionEnvironment

An Execution Environment contract is deployed for each unique combination of User address x DAppControl address that interacts with the Atlas protocol via a metacall transaction. IMPORTANT: The contract is not meant to be used as a smart contract wallet with any other protocols other than Atlas

constructor

constructor(address atlas) public

validUser

modifier validUser(struct UserOperation userOp)

preOpsWrapper

function preOpsWrapper(struct UserOperation userOp) external returns (bytes)

The preOpsWrapper function may be called by Atlas before the UserOperation is executed.

This contract is called by the Atlas contract, and delegatecalls the DAppControl contract via the corresponding preOpsCall function.

Parameters

NameTypeDescription
userOpstruct UserOperationThe UserOperation struct.

Return Values

NameTypeDescription
[0]bytespreOpsData Data to be passed to the next call phase.

userWrapper

function userWrapper(struct UserOperation userOp) external payable returns (bytes returnData)

The userWrapper function is called by Atlas to execute the UserOperation.

This contract is called by the Atlas contract, and either delegatecalls or calls the DAppControl contract with userOp.data as calldata, depending on the the needsDelegateUser flag.

Parameters

NameTypeDescription
userOpstruct UserOperationThe UserOperation struct.

Return Values

NameTypeDescription
returnDatabytesData to be passed to the next call phase.

postOpsWrapper

function postOpsWrapper(bool solved, bytes returnData) external

The postOpsWrapper function may be called by Atlas as the last phase of a metacall transaction.

This contract is called by the Atlas contract, and delegatecalls the DAppControl contract via the corresponding postOpsCall function.

Parameters

NameTypeDescription
solvedboolBoolean indicating whether a winning SolverOperation was executed successfully.
returnDatabytesData returned from the previous call phase.

solverPreTryCatch

function solverPreTryCatch(uint256 bidAmount, struct SolverOperation solverOp, bytes returnData) external payable returns (struct SolverTracker solverTracker)

The solverPreTryCatch function is called by Atlas to execute the preSolverCall part of each SolverOperation. A SolverTracker struct is also returned, containing bid info needed to handle the difference in logic between inverted and non-inverted bids.

Note that the DAppControl always has the option for custom logic in a hook between the measurement of solver bids (preSolverCall for invertsBid mode, postSolverCall for normal bid mode) which could potentially affect the solvers' net bid. These hooks should be used with caution and the behaviour should be clearly documented for participating solvers.

Parameters

NameTypeDescription
bidAmountuint256The Solver's bid amount.
solverOpstruct SolverOperationThe SolverOperation struct.
returnDatabytesData returned from the previous call phase.

Return Values

NameTypeDescription
solverTrackerstruct SolverTrackerBid tracking information for the current solver.

solverPostTryCatch

function solverPostTryCatch(struct SolverOperation solverOp, bytes returnData, struct SolverTracker solverTracker) external payable returns (struct SolverTracker)

The solverPostTryCatch function is called by Atlas to execute the postSolverCall part of each SolverOperation. The different logic scenarios depending on the value of invertsBidValue are also handled, and the SolverTracker struct is updated accordingly.

Note that the DAppControl always has the option for custom logic in a hook between the measurement of solver bids (preSolverCall for invertsBid mode, postSolverCall for normal bid mode) which could potentially affect the solvers' net bid. These hooks should be used with caution and the behaviour should be clearly documented for participating solvers.

Parameters

NameTypeDescription
solverOpstruct SolverOperationThe SolverOperation struct.
returnDatabytesData returned from the previous call phase.
solverTrackerstruct SolverTrackerBid tracking information for the current solver.

Return Values

NameTypeDescription
[0]struct SolverTrackersolverTracker Updated bid tracking information for the current solver.

allocateValue

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

The allocateValue function is called by Atlas after a successful SolverOperation.

This contract is called by the Atlas contract, and delegatecalls the DAppControl contract via the corresponding allocateValueCall function.

Parameters

NameTypeDescription
bidTokenaddressThe address of the token used for the winning SolverOperation's bid.
bidAmountuint256The winning bid amount.
allocateDatabytesData returned from the previous call phase.

Return Values

NameTypeDescription
allocateValueSucceededboolBoolean indicating whether the allocateValue delegatecall succeeded (true) or reverted (false). This is useful when allowAllocateValueFailure is set to true, the failure is caught here, but we still need to communicate to Atlas that the hook did not succeed.

withdrawERC20

function withdrawERC20(address token, uint256 amount) external

The withdrawERC20 function allows the environment owner to withdraw ERC20 tokens from this Execution Environment.

This function is only callable by the environment owner and only when Atlas is in an unlocked state.

Parameters

NameTypeDescription
tokenaddressThe address of the ERC20 token to withdraw.
amountuint256The amount of the ERC20 token to withdraw.

withdrawEther

function withdrawEther(uint256 amount) external

The withdrawEther function allows the environment owner to withdraw Ether from this Execution Environment.

This function is only callable by the environment owner and only when Atlas is in an unlocked state.

Parameters

NameTypeDescription
amountuint256The amount of Ether to withdraw.

getUser

function getUser() external pure returns (address user)

The getUser function returns the address of the user of this Execution Environment.

Return Values

NameTypeDescription
useraddressThe address of the user of this Execution Environment.

getControl

function getControl() external pure returns (address control)

The getControl function returns the address of the DAppControl contract of the current metacall transaction.

Return Values

NameTypeDescription
controladdressThe address of the DAppControl contract of the current metacall transaction.

getConfig

function getConfig() external pure returns (uint32 config)

The getConfig function returns the CallConfig of the current metacall transaction.

Return Values

NameTypeDescription
configuint32The CallConfig in uint32 form of the current metacall transaction.

getEscrow

function getEscrow() external view returns (address)

The getEscrow function returns the address of the Atlas/Escrow contract.

Return Values

NameTypeDescription
[0]addressaddress The address of the Atlas/Escrow contract.

_tryBalanceOf

function _tryBalanceOf(address token, bool inPreSolver) internal view returns (uint256)

Calls balanceOf of an arbitrary ERC20 token, and reverts with either a PreSolverFailed or PostSolverFailed, depending on the context in which this function is called, if any error occurs.

This stops malicious errors from bubbling up to the Atlas contract, and triggering unexpected behavior.

receive

receive() external payable

fallback

fallback() external payable