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
Variable | Type | Visibility | Description |
---|---|---|---|
_ATLAS_SURCHARGE_RATE | uint256 | internal | Gas surcharge rate for the Atlas Protocol (10%). |
_BUNDLER_SURCHARGE_RATE | uint256 | internal | Gas surcharge rate for Bundlers (10%). |
_SOLVER_GAS_LIMIT_BUFFER_PERCENTAGE | uint256 | internal | Gas limit buffer percentage for solvers (5%). |
_SCALE | uint256 | internal | Scaling factor used in calculations (10,000,000 representing 100%). |
_FIXED_GAS_OFFSET | uint256 | internal | Fixed 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
Name | Type | Description |
---|---|---|
amount | uint256 | The original amount to be adjusted. |
Return Values
Name | Type | Description |
---|---|---|
adjustedAmount | uint256 | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | The adjusted amount with Bundler surcharge. |
Return Values
Name | Type | Description |
---|---|---|
unadjustedAmount | uint256 | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | The original amount to be adjusted. |
Return Values
Name | Type | Description |
---|---|---|
adjustedAmount | uint256 | The 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
Name | Type | Description |
---|---|---|
amount | uint256 | The original amount to calculate the surcharge for. |
Return Values
Name | Type | Description |
---|---|---|
surcharge | uint256 | The 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
Name | Type | Description |
---|---|---|
solverOpGasLimit | uint256 | The original gas limit set for the solver operation. |
dConfigGasLimit | uint256 | The gas limit defined in the DApp's configuration. |
Return Values
Name | Type | Description |
---|---|---|
gasLimit | uint256 | The adjusted gas limit after scaling down. |