From 8be2960a348e5cd664f217415c3e7da9eda47dc1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Sep 2024 21:21:27 -0700 Subject: [PATCH 1/4] added more specific fee tracking for the scenario in which multiple solvers all fail --- lib/forge-std | 2 +- lib/solady | 2 +- src/contracts/atlas/GasAccounting.sol | 18 ++++++++++++++++-- src/contracts/libraries/AccountingMath.sol | 4 ++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index 1ce7535a5..e04104ab9 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1ce7535a517406b9aec7ea1ea27c1b41376f712c +Subproject commit e04104ab93e771441eab03fb76eda1402cb5927b diff --git a/lib/solady b/lib/solady index 4f5098200..156317831 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 4f50982008973b1431768a75fb88ac8eca21b9f6 +Subproject commit 1563178312d50496373c8abeddb37c09db48d7cf diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 5b04b288d..571e95cc5 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -357,8 +357,13 @@ abstract contract GasAccounting is SafetyLocks { S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; } else { // If no successful solvers, only collect partial surcharges from solver's fault failures (if any) - netAtlasGasSurcharge = solverSurcharge(); - if (netAtlasGasSurcharge > 0) S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; + uint256 _solverSurcharge = solverSurcharge(); + if (_solverSurcharge > 0) { + // NOTE: This only works when BUNDLER_SURCHARGE > ATLAS_SURCHARGE. + netAtlasGasSurcharge = _solverSurcharge.getAtlasPortionFromTotalSurcharge(); + adjustedWithdrawals += netAtlasGasSurcharge; + S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; + } return (adjustedWithdrawals, adjustedDeposits, adjustedClaims, adjustedWriteoffs, netAtlasGasSurcharge); } @@ -430,9 +435,18 @@ abstract contract GasAccounting is SafetyLocks { if (ctx.solverSuccessful && _winningSolver != ctx.bundler) { _amountSolverPays += _adjustedClaims; claimsPaidToBundler = _adjustedClaims; + } else if (_winningSolver == ctx.bundler) { + claimsPaidToBundler = 0; } else { claimsPaidToBundler = 0; _winningSolver = ctx.bundler; + + // Get the Bundler portion of the solver surcharge by subtracting the atlas portion from the total + uint256 _solverSurcharge = solverSurcharge(); + if (_solverSurcharge != 0) { + // Add the bundler's portion of the solver surcharge to the amount the solver receives + _amountSolverReceives += (_solverSurcharge - netAtlasGasSurcharge); + } } if (_amountSolverPays > _amountSolverReceives) { diff --git a/src/contracts/libraries/AccountingMath.sol b/src/contracts/libraries/AccountingMath.sol index d30c044e1..7f501cc8f 100644 --- a/src/contracts/libraries/AccountingMath.sol +++ b/src/contracts/libraries/AccountingMath.sol @@ -26,6 +26,10 @@ library AccountingMath { surcharge = amount * _ATLAS_SURCHARGE_RATE / _SCALE; } + function getAtlasPortionFromTotalSurcharge(uint256 totalSurcharge) internal pure returns (uint256 atlasSurcharge) { + atlasSurcharge = totalSurcharge * _ATLAS_SURCHARGE_RATE / (_ATLAS_SURCHARGE_RATE + _BUNDLER_SURCHARGE_RATE); + } + function solverGasLimitScaledDown( uint256 solverOpGasLimit, uint256 dConfigGasLimit From 966c0cf62fdb851dc687cf41a54e4ef28d1c1259 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 24 Sep 2024 10:37:59 -0700 Subject: [PATCH 2/4] simplified formula to balance per ben suggestion --- src/contracts/atlas/GasAccounting.sol | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 571e95cc5..87ae8735f 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -440,13 +440,6 @@ abstract contract GasAccounting is SafetyLocks { } else { claimsPaidToBundler = 0; _winningSolver = ctx.bundler; - - // Get the Bundler portion of the solver surcharge by subtracting the atlas portion from the total - uint256 _solverSurcharge = solverSurcharge(); - if (_solverSurcharge != 0) { - // Add the bundler's portion of the solver surcharge to the amount the solver receives - _amountSolverReceives += (_solverSurcharge - netAtlasGasSurcharge); - } } if (_amountSolverPays > _amountSolverReceives) { From 89d65545f61c8c19c21065e8c3c3aa4e6826af3e Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:32:25 +0200 Subject: [PATCH 3/4] fmt: forge fmt --- src/contracts/atlas/GasAccounting.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 87ae8735f..35773bef2 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -361,7 +361,7 @@ abstract contract GasAccounting is SafetyLocks { if (_solverSurcharge > 0) { // NOTE: This only works when BUNDLER_SURCHARGE > ATLAS_SURCHARGE. netAtlasGasSurcharge = _solverSurcharge.getAtlasPortionFromTotalSurcharge(); - adjustedWithdrawals += netAtlasGasSurcharge; + adjustedWithdrawals += netAtlasGasSurcharge; S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; } return (adjustedWithdrawals, adjustedDeposits, adjustedClaims, adjustedWriteoffs, netAtlasGasSurcharge); From d0add4e344338a274dc1d58dbcc8f822f8f49106 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:33:06 +0200 Subject: [PATCH 4/4] chore: update libs --- lib/forge-std | 2 +- lib/solady | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index e04104ab9..1de6eecf8 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e04104ab93e771441eab03fb76eda1402cb5927b +Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f diff --git a/lib/solady b/lib/solady index 156317831..855e2e834 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 1563178312d50496373c8abeddb37c09db48d7cf +Subproject commit 855e2e834a9d791002586a5c9071b1f4c0796bd1