Skip to main content

Solidity API

Escrow

This Escrow component of Atlas handles execution of stages by calling corresponding functions on the Execution Environment contract.

constructor

constructor(uint256 escrowDuration, uint256 atlasSurchargeRate, uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator) internal

_executePreOpsCall

function _executePreOpsCall(struct Context ctx, struct DAppConfig dConfig, struct UserOperation userOp) internal returns (bytes)

Executes the preOps logic defined in the Execution Environment.

Parameters

NameTypeDescription
ctxstruct ContextMetacall context data from the Context struct.
dConfigstruct DAppConfigConfiguration data for the DApp involved, containing execution parameters and settings.
userOpstruct UserOperationUserOperation struct of the current metacall tx.

Return Values

NameTypeDescription
[0]bytespreOpsData The data returned by the preOps call, if successful.

_executeUserOperation

function _executeUserOperation(struct Context ctx, struct DAppConfig dConfig, struct UserOperation userOp, bytes returnData) internal returns (bytes)

Executes the user operation logic defined in the Execution Environment.

Parameters

NameTypeDescription
ctxstruct ContextMetacall context data from the Context struct.
dConfigstruct DAppConfigConfiguration data for the DApp involved, containing execution parameters and settings.
userOpstruct UserOperationUserOperation struct containing the user's transaction data.
returnDatabytesData returned from previous call phases.

Return Values

NameTypeDescription
[0]bytesuserData Data returned from executing the UserOperation, if the call was successful.

_checkTrustedOpHash

function _checkTrustedOpHash(struct DAppConfig dConfig, bool prevalidated, struct UserOperation userOp, struct SolverOperation solverOp, uint256 result) internal returns (uint256)

Checks if the trusted operation hash matches and sets the appropriate error bit if it doesn't.

Parameters

NameTypeDescription
dConfigstruct DAppConfigConfiguration data for the DApp involved, containing execution parameters and settings.
prevalidatedboolBoolean flag indicating whether the SolverOperation has been prevalidated to skip certain checks.
userOpstruct UserOperationUserOperation struct containing the user's transaction data relevant to this SolverOperation.
solverOpstruct SolverOperationSolverOperation struct containing the solver's bid and execution data.
resultuint256The current result bitmask that tracks the status of various checks and validations.

Return Values

NameTypeDescription
[0]uint256The updated result bitmask with the AltOpHashMismatch bit set if the operation hash does not match.

_executeSolverOperation

function _executeSolverOperation(struct Context ctx, struct DAppConfig dConfig, struct UserOperation userOp, struct SolverOperation solverOp, uint256 bidAmount, bool prevalidated, bytes returnData) internal returns (uint256)

Attempts to execute a SolverOperation and determine if it wins the auction.

Parameters

NameTypeDescription
ctxstruct ContextContext struct containing the current state of the escrow lock.
dConfigstruct DAppConfigConfiguration data for the DApp involved, containing execution parameters and settings.
userOpstruct UserOperationUserOperation struct containing the user's transaction data relevant to this SolverOperation.
solverOpstruct SolverOperationSolverOperation struct containing the solver's bid and execution data.
bidAmountuint256The amount of bid submitted by the solver for this operation.
prevalidatedboolBoolean flag indicating whether the SolverOperation has been prevalidated to skip certain
returnDatabytesData returned from UserOp execution, used as input if necessary.

Return Values

NameTypeDescription
[0]uint256bidAmount The determined bid amount for the SolverOperation if all validations pass and the operation is executed successfully; otherwise, returns 0.

_allocateValue

function _allocateValue(struct Context ctx, struct DAppConfig dConfig, uint256 bidAmount, bytes returnData) internal

Allocates the winning bid amount after a successful SolverOperation execution.

This function handles the allocation of the bid amount to the appropriate recipients as defined in the DApp's configuration. It calls the allocateValue function in the Execution Environment, which is responsible for distributing the bid amount. Note that balance discrepancies leading to payment failures are typically due to issues in the DAppControl contract, not the execution environment itself.

Parameters

NameTypeDescription
ctxstruct ContextContext struct containing the current state of the escrow lock.
dConfigstruct DAppConfigConfiguration data for the DApp involved, containing execution parameters and settings.
bidAmountuint256The winning solver's bid amount, to be allocated.
returnDatabytesData returned from the execution of the UserOperation, which may influence how the bid amount is allocated.

_executePostOpsCall

function _executePostOpsCall(struct Context ctx, bool solved, bytes returnData) internal

Executes post-operation logic after SolverOperation, depending on the outcome of the auction.

Calls the postOpsWrapper function in the Execution Environment, which handles any necessary cleanup or finalization logic after the winning SolverOperation.

Parameters

NameTypeDescription
ctxstruct ContextContext struct containing the current state of the escrow lock.
solvedboolBoolean indicating whether a SolverOperation was successful and won the auction.
returnDatabytesData returned from execution of the UserOp call, which may be required for the postOps logic.

_validateSolverOpGasAndValue

function _validateSolverOpGasAndValue(struct DAppConfig dConfig, struct SolverOperation solverOp, uint256 gasWaterMark, uint256 result) internal view returns (uint256, uint256 gasLimit)

Validates a SolverOperation's gas requirements against the escrow state.

Performs a series of checks to ensure that a SolverOperation can be executed within the defined parameters and limits. This includes verifying that the operation is within the gas limit and that the solver has sufficient balance in escrow to cover the gas costs.

Parameters

NameTypeDescription
dConfigstruct DAppConfigDApp configuration data, including solver gas limits and operation parameters.
solverOpstruct SolverOperationThe SolverOperation being validated.
gasWaterMarkuint256The initial gas measurement before validation begins, used to ensure enough gas remains for validation logic.
resultuint256The current result bitmap, which will be updated with the outcome of the gas validation checks.

Return Values

NameTypeDescription
[0]uint256result Updated result flags after performing the validation checks, including any new errors encountered.
gasLimituint256The calculated gas limit for the SolverOperation, considering the operation's gas usage and the protocol's gas buffers.

_validateSolverOpDeadline

function _validateSolverOpDeadline(struct SolverOperation solverOp, struct DAppConfig dConfig) internal view returns (uint256 result)

Validates a SolverOperation's deadline against the current block.

Parameters

NameTypeDescription
solverOpstruct SolverOperationThe SolverOperation being validated.
dConfigstruct DAppConfigDApp configuration data, including solver gas limits and operation parameters.

Return Values

NameTypeDescription
resultuint256Updated result flags after performing the validation checks, including any new errors

_getBidAmount

function _getBidAmount(struct Context ctx, struct DAppConfig dConfig, struct UserOperation userOp, struct SolverOperation solverOp, bytes returnData) internal returns (uint256 bidAmount)

Determines the bid amount for a SolverOperation based on verification and validation results.

This function assesses whether a SolverOperation meets the criteria for execution by verifying it against the Atlas protocol's rules and the current Context lock state. It checks for valid execution based on the SolverOperation's specifics, like gas usage and deadlines. The function aims to protect against malicious bundlers by ensuring solvers are not unfairly charged for on-chain bid finding gas usage. If the operation passes verification and validation, and if it's eligible for bid amount determination, the function attempts to execute and determine the bid amount.

Parameters

NameTypeDescription
ctxstruct ContextThe Context struct containing the current state of the escrow lock.
dConfigstruct DAppConfigThe DApp configuration data, including parameters relevant to solver bid validation.
userOpstruct UserOperationThe UserOperation associated with this SolverOperation, providing context for the bid amount determination.
solverOpstruct SolverOperationThe SolverOperation being assessed, containing the solver's bid amount.
returnDatabytesData returned from the execution of the UserOp call.

Return Values

NameTypeDescription
bidAmountuint256The determined bid amount for the SolverOperation if all validations pass and the operation is executed successfully; otherwise, returns 0.

_handleAltOpHash

function _handleAltOpHash(struct UserOperation userOp, struct SolverOperation solverOp) internal returns (bool)

Validates UserOp hashes provided by the SolverOperation, using the alternative set of hashed parameters.

Parameters

NameTypeDescription
userOpstruct UserOperationThe UserOperation struct, providing the baseline parameters for comparison.
solverOpstruct SolverOperationThe SolverOperation struct being validated against the UserOperation.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the SolverOperation passed the alternative hash check, with true meaning it is considered valid

_checkSolverBidToken

function _checkSolverBidToken(address solverBidToken, address dConfigBidToken, uint256 result) internal pure returns (uint256)

Checks if the solver's bid token matches the dApp's bid token.

Parameters

NameTypeDescription
solverBidTokenaddressThe solver's bid token address.
dConfigBidTokenaddressThe dApp's bid token address.
resultuint256The current result bitmap, which will be updated with the outcome of the bid token check.

Return Values

NameTypeDescription
[0]uint256The updated result bitmap, with the SolverOutcome.InvalidBidToken flag set if the bid token check fails.

_solverOpWrapper

function _solverOpWrapper(struct Context ctx, struct SolverOperation solverOp, uint256 bidAmount, uint256 gasLimit, bytes returnData) internal returns (uint256 result, struct SolverTracker solverTracker)

Wraps the execution of a SolverOperation and handles potential errors.

Parameters

NameTypeDescription
ctxstruct ContextThe current lock data.
solverOpstruct SolverOperationThe SolverOperation struct containing the operation's execution data.
bidAmountuint256The bid amount associated with the SolverOperation.
gasLimituint256The gas limit for executing the SolverOperation, calculated based on the operation's requirements and protocol buffers.
returnDatabytesData returned from the execution of the associated UserOperation, which may be required for the SolverOperation's logic.

Return Values

NameTypeDescription
resultuint256SolverOutcome enum value encoded as a uint256 bitmap, representing the result of the SolverOperation
solverTrackerstruct SolverTrackerTracking data for the solver's bid

solverCall

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

Executes the SolverOperation logic, including preSolver and postSolver hooks via the Execution Environment, as well as the actual solver call directly from Atlas to the solver contract.

Parameters

NameTypeDescription
ctxstruct ContextThe Context struct containing lock data and the Execution Environment address.
solverOpstruct SolverOperationThe SolverOperation to be executed.
bidAmountuint256The bid amount associated with the SolverOperation.
returnDatabytesData returned from previous call phases.

Return Values

NameTypeDescription
solverTrackerstruct SolverTrackerAdditional data for handling the solver's bid in different scenarios.

receive

receive() external payable