diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index 2fe2b340..efc246db 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -101,9 +101,8 @@ contract Atlas is Escrow, Factory { try this.execute(_dConfig, userOp, solverOps, _executionEnvironment, _bundler, dAppOp.userOpHash, _isSimulation) returns (Context memory ctx) { // Gas Refund to sender only if execution is successful - (uint256 _ethPaidToBundler, uint256 _netGasSurcharge) = _settle( - ctx, _dConfig.solverGasLimit, gasRefundBeneficiary != address(0) ? gasRefundBeneficiary : msg.sender - ); + (uint256 _ethPaidToBundler, uint256 _netGasSurcharge) = + _settle(ctx, _dConfig.solverGasLimit, gasRefundBeneficiary); auctionWon = ctx.solverSuccessful; emit MetacallResult( diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 6d2c70b6..3e8562a4 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -428,6 +428,8 @@ abstract contract GasAccounting is SafetyLocks { // If a solver won, their address is still in the _solverLock (address _winningSolver,,) = _solverLockData(); + if (gasRefundBeneficiary == address(0)) gasRefundBeneficiary = ctx.bundler; + // Load what we can from storage so that it shows up in the gasleft() calc uint256 _claims; @@ -457,8 +459,9 @@ abstract contract GasAccounting is SafetyLocks { } else if (_winningSolver == ctx.bundler) { claimsPaidToBundler = 0; } else { + // this else block is only executed if there is no successful solver claimsPaidToBundler = 0; - _winningSolver = ctx.bundler; + _winningSolver = gasRefundBeneficiary; } if (_amountSolverPays > _amountSolverReceives) { @@ -473,10 +476,6 @@ abstract contract GasAccounting is SafetyLocks { } claimsPaidToBundler -= _currentDeficit; } else { - if (_winningSolver == ctx.bundler) { - _winningSolver = gasRefundBeneficiary; - } - _credit(_winningSolver, _amountSolverReceives - _amountSolverPays, _adjustedClaims); }