Skip to main content

Solidity API

GasAccounting

GasAccounting manages the accounting of gas surcharges and escrow balances for the Atlas protocol.

constructor

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

_initializeAccountingValues

function _initializeAccountingValues(uint256 gasMarker) internal

Sets the initial accounting values for the metacall transaction.

Parameters

NameTypeDescription
gasMarkeruint256The gas marker used to calculate the initial accounting values.

contribute

function contribute() external payable

Contributes ETH to the contract, increasing the deposits if a non-zero value is sent.

borrow

function borrow(uint256 amount) external payable

Borrows ETH from the contract, transferring the specified amount to the caller if available.

Borrowing is only available until the end of the SolverOperation phase, for solver protection.

Parameters

NameTypeDescription
amountuint256The amount of ETH to borrow.

shortfall

function shortfall() external view returns (uint256)

Calculates the current shortfall currently owed by the winning solver.

The shortfall is calculated (claims + withdrawals + fees - writeoffs) - deposits. If this value is less than zero, shortfall returns 0 as there is no shortfall because the solver is in surplus.

Return Values

NameTypeDescription
[0]uint256uint256 The current shortfall amount, or 0 if there is no shortfall.

_deficit

function _deficit() internal view returns (uint256)

reconcile

function reconcile(uint256 maxApprovedGasSpend) external payable returns (uint256 owed)

Allows a solver to settle any outstanding ETH owed, either to repay gas used by their solverOp or to repay any ETH borrowed from Atlas. This debt can be paid either by sending ETH when calling this function (msg.value) or by approving Atlas to use a certain amount of the solver's bonded AtlETH.

The solver can call this function multiple times until the owed amount is zero. Note: reconcile() must be called by the solver to avoid a CallbackNotCalled error in solverCall().

Parameters

NameTypeDescription
maxApprovedGasSpenduint256The maximum amount of the solver's bonded AtlETH that Atlas can deduct to cover the solver's debt.

Return Values

NameTypeDescription
oweduint256The amount owed, if any, by the solver after reconciliation.

_contribute

function _contribute() internal

Internal function to handle ETH contribution, increasing deposits if a non-zero value is sent.

_borrow

function _borrow(uint256 amount) internal returns (bool valid)

Borrows ETH from the contract, transferring the specified amount to the caller if available.

Borrowing should never be allowed after the SolverOperation phase, for solver safety. This is enforced in the external borrow function, and the only other time this internal _borrow function is called is in _solverOpInner which happens at the beginning of the SolverOperation phase.

Parameters

NameTypeDescription
amountuint256The amount of ETH to borrow.

Return Values

NameTypeDescription
validboolA boolean indicating whether the borrowing operation was successful.

_assign

function _assign(address owner, uint256 amount, uint256 gasValueUsed, bool solverWon) internal returns (uint256 deficit)

Takes AtlETH from the owner's bonded balance and, if necessary, from the owner's unbonding balance to increase transient solver deposits.

Parameters

NameTypeDescription
owneraddressThe address of the owner from whom AtlETH is taken.
amountuint256The amount of AtlETH to be taken.
gasValueUseduint256The ETH value of gas used in the SolverOperation.
solverWonboolA boolean indicating whether the solver won the bid.

Return Values

NameTypeDescription
deficituint256The amount of AtlETH that was not repaid, if any.

_credit

function _credit(address owner, uint256 amount, uint256 gasValueUsed) internal

Increases the owner's bonded balance by the specified amount.

Parameters

NameTypeDescription
owneraddressThe address of the owner whose bonded balance will be increased.
amountuint256The amount by which to increase the owner's bonded balance.
gasValueUseduint256The ETH value of gas used in the SolverOperation.

_handleSolverAccounting

function _handleSolverAccounting(struct SolverOperation solverOp, uint256 gasWaterMark, uint256 result, bool includeCalldata) internal

Accounts for the gas cost of a failed SolverOperation, either by increasing writeoffs (if the bundler is blamed for the failure) or by assigning the gas cost to the solver's bonded AtlETH balance (if the solver is blamed for the failure).

Parameters

NameTypeDescription
solverOpstruct SolverOperationThe current SolverOperation for which to account.
gasWaterMarkuint256The gasleft() watermark taken at the start of executing the SolverOperation.
resultuint256The result bitmap of the SolverOperation execution.
includeCalldataboolWhether to include calldata cost in the gas calculation.

_writeOffBidFindGasCost

function _writeOffBidFindGasCost(uint256 gasUsed) internal

_adjustAccountingForFees

function _adjustAccountingForFees(struct Context ctx, uint256 solverGasLimit) internal returns (uint256 adjustedWithdrawals, uint256 adjustedDeposits, uint256 adjustedClaims, uint256 adjustedWriteoffs, uint256 netAtlasGasSurcharge)

This function is called internally to adjust the accounting for fees based on the gas usage. Note: The behavior of this function depends on whether _bidFindingIteration() or _bidKnownIteration() is used, as they both use a different order of execution.

Parameters

NameTypeDescription
ctxstruct ContextContext struct containing relevant context information for the Atlas auction.
solverGasLimituint256The maximum gas limit for a solver, as set in the DAppConfig

Return Values

NameTypeDescription
adjustedWithdrawalsuint256Withdrawals of the current metacall, adjusted by adding the Atlas gas surcharge.
adjustedDepositsuint256Deposits of the current metacall, no adjustments applied.
adjustedClaimsuint256Claims of the current metacall, adjusted by subtracting the unused gas scaled to include bundler surcharge.
adjustedWriteoffsuint256Writeoffs of the current metacall, adjusted by adding the bundler gas overage penalty if applicable.
netAtlasGasSurchargeuint256The net gas surcharge of the metacall, taken by Atlas.

_settle

function _settle(struct Context ctx, uint256 solverGasLimit, address gasRefundBeneficiary) internal returns (uint256 claimsPaidToBundler, uint256 netAtlasGasSurcharge)

Settle makes the final adjustments to accounting variables based on gas used in the metacall. AtlETH is either taken (via _assign) or given (via _credit) to the winning solver, the bundler is sent the appropriate refund for gas spent, and Atlas' gas surcharge is updated.

Parameters

NameTypeDescription
ctxstruct ContextContext struct containing relevant context information for the Atlas auction.
solverGasLimituint256The dApp's maximum gas limit for a solver, as set in the DAppConfig.
gasRefundBeneficiaryaddressThe address to receive the gas refund.

Return Values

NameTypeDescription
claimsPaidToBundleruint256The amount of ETH paid to the bundler in this function.
netAtlasGasSurchargeuint256The net gas surcharge of the metacall, taken by Atlas.

_updateAnalytics

function _updateAnalytics(struct EscrowAccountAccessData aData, bool auctionWon, uint256 gasValueUsed) internal pure

Updates auctionWins, auctionFails, and totalGasUsed values of a solver's EscrowAccountAccessData.

This function is only ever called in the context of bidFind = false so no risk of doublecounting changes.

Parameters

NameTypeDescription
aDatastruct EscrowAccountAccessDataThe Solver's EscrowAccountAccessData struct to update.
auctionWonboolA boolean indicating whether the solver's solverOp won the auction.
gasValueUseduint256The ETH value of gas used by the solverOp. Should be calculated as gasUsed * tx.gasprice.

_getCalldataCost

function _getCalldataCost(uint256 calldataLength) internal view returns (uint256 calldataCost)

Calculates the gas cost of the calldata used to execute a SolverOperation.

Parameters

NameTypeDescription
calldataLengthuint256The length of the data field in the SolverOperation.

Return Values

NameTypeDescription
calldataCostuint256The gas cost of the calldata used to execute the SolverOperation.

_isBalanceReconciled

function _isBalanceReconciled() internal view returns (bool)

Checks if the current balance is reconciled.

Compares the deposits with the sum of claims, withdrawals, fees, and write-offs to ensure the balance is correct.

Return Values

NameTypeDescription
[0]boolTrue if the balance is reconciled, false otherwise.