Skip to main content

AccountingMath

The AccountingMath library provides a comprehensive set of utility functions for handling gas accounting within the Atlas Protocol. It facilitates the calculation of surcharges, bid adjustments, and gas limit scaling to ensure efficient and accurate transaction processing. Designed to manage various financial calculations related to gas accounting, the library includes functions to adjust bid amounts based on predefined surcharge rates and to scale down gas limits appropriately. This robust toolkit ensures that transactions are processed smoothly, maintaining both efficiency and precision within the Atlas ecosystem.

State Variables

VariableTypeVisibilityDescription
_ATLAS_SURCHARGE_RATEuint256internalGas surcharge rate for the Atlas Protocol (10%).
_BUNDLER_SURCHARGE_RATEuint256internalGas surcharge rate for Bundlers (10%).
_SOLVER_GAS_LIMIT_BUFFER_PERCENTAGEuint256internalGas limit buffer percentage for solvers (5%).
_SCALEuint256internalScaling factor used in calculations (10,000,000 representing 100%).
_FIXED_GAS_OFFSETuint256internalFixed gas offset value (85,000).

Functions

withBundlerSurcharge

function withBundlerSurcharge(uint256 amount) internal pure returns (uint256 adjustedAmount)

Description

Calculates the adjusted amount by applying the Bundler surcharge to the original amount.

Parameters

NameTypeDescription
amountuint256The original amount to be adjusted.

Return Values

NameTypeDescription
adjustedAmountuint256The amount after applying the Bundler surcharge.

Example

uint256 originalAmount = 1000;
uint256 adjusted = AccountingMath.withBundlerSurcharge(originalAmount);
// adjusted = 1100

withoutBundlerSurcharge

function withoutBundlerSurcharge(uint256 amount) internal pure returns (uint256 unadjustedAmount)

Description

Calculates the original amount by removing the Bundler surcharge from the adjusted amount.

Parameters

NameTypeDescription
amountuint256The adjusted amount with Bundler surcharge.

Return Values

NameTypeDescription
unadjustedAmountuint256The original amount before applying the surcharge.

Example

uint256 adjustedAmount = 1100;
uint256 original = AccountingMath.withoutBundlerSurcharge(adjustedAmount);
// original = 1000

withAtlasAndBundlerSurcharges

function withAtlasAndBundlerSurcharges(uint256 amount) internal pure returns (uint256 adjustedAmount)

Description

Applies both Atlas and Bundler surcharges to the original amount.

Parameters

NameTypeDescription
amountuint256The original amount to be adjusted.

Return Values

NameTypeDescription
adjustedAmountuint256The amount after applying both surcharges.

Example

uint256 originalAmount = 1000;
uint256 adjusted = AccountingMath.withAtlasAndBundlerSurcharges(originalAmount);
// adjusted = 1200

getAtlasSurcharge

function getAtlasSurcharge(uint256 amount) internal pure returns (uint256 surcharge)

Description

Calculates the Atlas surcharge based on the original amount.

Parameters

NameTypeDescription
amountuint256The original amount to calculate the surcharge for.

Return Values

NameTypeDescription
surchargeuint256The calculated Atlas surcharge.

Example

uint256 originalAmount = 1000;
uint256 surcharge = AccountingMath.getAtlasSurcharge(originalAmount);
// surcharge = 100

solverGasLimitScaledDown

function solverGasLimitScaledDown(
uint256 solverOpGasLimit,
uint256 dConfigGasLimit
) internal pure returns (uint256 gasLimit)

Description

Scales down the solver's gas limit based on the configuration and buffer percentage to ensure efficient gas usage.

Parameters

NameTypeDescription
solverOpGasLimituint256The original gas limit set for the solver operation.
dConfigGasLimituint256The gas limit defined in the DApp's configuration.

Return Values

NameTypeDescription
gasLimituint256The adjusted gas limit after scaling down.