Skip to content

Commit f6d7f08

Browse files
committed
chore: update code to latest
1 parent 7e78e14 commit f6d7f08

32 files changed

+311
-224
lines changed

src/atlas/common/ExecutionEnvironment.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77
import { Base } from "./ExecutionBase.sol";
88

99
import { IAtlas } from "../interfaces/IAtlas.sol";
10-
import { ISolverContract } from "../interfaces/ISolverContract.sol";
1110
import { IDAppControl } from "../interfaces/IDAppControl.sol";
1211
import { AtlasErrors } from "../types/AtlasErrors.sol";
1312
import { CallBits } from "../libraries/CallBits.sol";

src/atlas/core/AtlETH.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ abstract contract AtlETH is Permit69 {
1818
address simulator,
1919
address initialSurchargeRecipient,
2020
address l2GasCalculator,
21+
address taskManager,
2122
address shMonad,
2223
uint64 shMonadPolicyID
2324
)
@@ -27,6 +28,7 @@ abstract contract AtlETH is Permit69 {
2728
simulator,
2829
initialSurchargeRecipient,
2930
l2GasCalculator,
31+
taskManager,
3032
shMonad,
3133
shMonadPolicyID
3234
)

src/atlas/core/Atlas.sol

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import "../types/ValidCalls.sol";
1919
import { CallBits } from "../libraries/CallBits.sol";
2020
import { SafetyBits } from "../libraries/SafetyBits.sol";
2121
import { GasAccLib, GasLedger } from "../libraries/GasAccLib.sol";
22-
import { IL2GasCalculator } from "../interfaces/IL2GasCalculator.sol";
23-
import { IDAppControl } from "../interfaces/IDAppControl.sol";
2422

25-
/// @title Atlas V1.6
23+
/// @title Atlas V1.6.3
2624
/// @author FastLane Labs
2725
/// @notice The Execution Abstraction protocol.
2826
contract Atlas is Escrow, Factory {
@@ -39,6 +37,7 @@ contract Atlas is Escrow, Factory {
3937
address initialSurchargeRecipient,
4038
address l2GasCalculator,
4139
address factoryLib,
40+
address taskManager,
4241
address shMonad,
4342
uint64 shMonadPolicyID
4443
)
@@ -48,6 +47,7 @@ contract Atlas is Escrow, Factory {
4847
simulator,
4948
initialSurchargeRecipient,
5049
l2GasCalculator,
50+
taskManager,
5151
shMonad,
5252
shMonadPolicyID
5353
)
@@ -119,6 +119,8 @@ contract Atlas is Escrow, Factory {
119119

120120
// Gracefully return for results that need nonces to be stored and prevent replay attacks
121121
if (uint8(_validCallsResult) >= _GRACEFUL_RETURN_THRESHOLD && !_dConfig.callConfig.allowsReuseUserOps()) {
122+
// Refund the bundler if they sent any msg.value, then return false and end early.
123+
if (msg.value != 0) SafeTransferLib.safeTransferETH(msg.sender, msg.value);
122124
return false;
123125
}
124126

@@ -200,6 +202,15 @@ contract Atlas is Escrow, Factory {
200202
emit MetacallResult(msg.sender, userOp.from, false, 0, 0);
201203
}
202204

205+
// Use any spare gas to generate additional revenue / fees for the intended gas refund beneficiary by executing
206+
// tasks on the TaskManager.
207+
uint256 _feesSharesEarned = _allocateGasToTaskManager(address(this), 25_000);
208+
209+
// Boost yield with the fees earned from executing tasks on the TaskManager
210+
if (_feesSharesEarned > 0) {
211+
SHMONAD.boostYield(_feesSharesEarned, address(this));
212+
}
213+
203214
// The environment lock is explicitly released here to allow multiple (sequential, not nested) metacalls in a
204215
// single transaction.
205216
_releaseLock();

src/atlas/core/AtlasVerification.sol

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract AtlasVerification is EIP712, NonceManager, DAppIntegration {
3535
address atlas,
3636
address l2GasCalculator
3737
)
38-
EIP712("AtlasVerification", "1.6")
38+
EIP712("AtlasVerification", "1.6.3")
3939
DAppIntegration(atlas, l2GasCalculator)
4040
{ }
4141

@@ -679,38 +679,43 @@ contract AtlasVerification is EIP712, NonceManager, DAppIntegration {
679679
}
680680

681681
allSolversCalldataGas =
682-
GasAccLib.calldataGas(solverDataLenSum + (_SOLVER_OP_BASE_CALLDATA * solverOps.length), L2_GAS_CALCULATOR);
682+
GasAccLib.calldataGas(solverDataLenSum + (_SOLVER_OP_STATIC_LENGTH * solverOps.length), L2_GAS_CALCULATOR);
683683

684684
// NOTE: On Monad, _FIXED_GAS_OFFSET is added here to ensure we have enough gas for the whole metacall upfront.
685685
// But it is not added to the _gasMarker tracker at the start of metacall(), because winning solver must pay all
686686
// remaining gas in _settle() anyway - i.e. they do not get a rebate of gasleft().
687-
uint256 metacallExecutionGas = _BASE_TX_GAS_USED + AccountingMath._FIXED_GAS_OFFSET + userOpGas
688-
+ dConfig.dappGasLimit + allSolversExecutionGas;
687+
uint256 metacallExecutionGas = _BASE_TX_GAS_USED + _PRE_EXECUTE_METACALL_GAS + _POST_SETTLE_METACALL_GAS
688+
+ userOpGas + dConfig.dappGasLimit + allSolversExecutionGas;
689+
// NOTE: On Monad, the _EXECUTE_SOLVER_OVERHEAD per solverOp is not included in the suggested gas limit.
689690

690691
// In both exPostBids and normal bid modes, solvers pay for their own execution gas.
691692
allSolversGasLimit = allSolversExecutionGas;
692693

693694
if (dConfig.callConfig.exPostBids()) {
694695
// Add extra execution gas for bid-finding loop of each solverOp
695-
bidFindOverhead = (solverOpsLen * _BID_FIND_OVERHEAD) + allSolversExecutionGas;
696+
bidFindOverhead = solverOpsLen * _BID_FIND_OVERHEAD + allSolversExecutionGas;
696697
metacallExecutionGas += bidFindOverhead;
697698
// NOTE: allSolversGasLimit excludes calldata in exPostBids mode.
698699
} else {
699700
// Solvers only pay for their calldata if exPostBids = false
700701
allSolversGasLimit += allSolversCalldataGas;
701702
}
702703

703-
uint256 _execGasUpperTolerance = _UPPER_BASE_EXEC_GAS_TOLERANCE + solverOpsLen * _TOLERANCE_PER_SOLVER;
704-
uint256 _execGasLowerTolerance = _LOWER_BASE_EXEC_GAS_TOLERANCE + solverOpsLen * _TOLERANCE_PER_SOLVER;
704+
// If checkMetacallGasLimit is enabled, verify that the execution gas measured by gasleft() at the start of the
705+
// metacall is in line with the expected gas limit, based on the userOp, solverOps, and dAppOp.
706+
if (dConfig.callConfig.checkMetacallGasLimit()) {
707+
uint256 _execGasUpperTolerance = _UPPER_BASE_EXEC_GAS_TOLERANCE + solverOpsLen * _TOLERANCE_PER_SOLVER;
708+
uint256 _execGasLowerTolerance = _LOWER_BASE_EXEC_GAS_TOLERANCE + solverOpsLen * _TOLERANCE_PER_SOLVER;
705709

706-
// Gas limit set by the bundler cannot be too high or too low. Use Simulator contract to estimate gas limit.
707-
// If gas limit is too low, the bonded balance threshold checked may not cover all gas reimbursements.
708-
if (metacallGasLeft < metacallExecutionGas - _execGasLowerTolerance) {
709-
verifyCallsResult = ValidCallsResult.MetacallGasLimitTooLow;
710-
}
711-
// If gas limit is too high, the bonded balance threshold checked could unexpectedly price out solvers.
712-
if (metacallGasLeft > metacallExecutionGas + _execGasUpperTolerance) {
713-
verifyCallsResult = ValidCallsResult.MetacallGasLimitTooHigh;
710+
// Gas limit set by the bundler cannot be too high or too low. Use Simulator contract to estimate gas limit.
711+
// If gas limit is too low, the bonded balance threshold checked may not cover all gas reimbursements.
712+
if (metacallGasLeft < metacallExecutionGas - _execGasLowerTolerance) {
713+
verifyCallsResult = ValidCallsResult.MetacallGasLimitTooLow;
714+
}
715+
// If gas limit is too high, the bonded balance threshold checked could unexpectedly price out solvers.
716+
if (metacallGasLeft > metacallExecutionGas + _execGasUpperTolerance) {
717+
verifyCallsResult = ValidCallsResult.MetacallGasLimitTooHigh;
718+
}
714719
}
715720

716721
return (verifyCallsResult, allSolversGasLimit, allSolversCalldataGas, bidFindOverhead);

src/atlas/core/Escrow.sol

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
66

77
import { AtlETH } from "./AtlETH.sol";
88
import { IExecutionEnvironment } from "../interfaces/IExecutionEnvironment.sol";
9-
import { IAtlas } from "../interfaces/IAtlas.sol";
109
import { ISolverContract } from "../interfaces/ISolverContract.sol";
1110
import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol";
12-
import { IDAppControl } from "../interfaces/IDAppControl.sol";
1311

1412
import { SafeCall } from "../libraries/SafeCall/SafeCall.sol";
1513
import { EscrowBits } from "../libraries/EscrowBits.sol";
@@ -43,6 +41,7 @@ abstract contract Escrow is AtlETH {
4341
address simulator,
4442
address initialSurchargeRecipient,
4543
address l2GasCalculator,
44+
address taskManager,
4645
address shMonad,
4746
uint64 shMonadPolicyID
4847
)
@@ -52,6 +51,7 @@ abstract contract Escrow is AtlETH {
5251
simulator,
5352
initialSurchargeRecipient,
5453
l2GasCalculator,
54+
taskManager,
5555
shMonad,
5656
shMonadPolicyID
5757
)
@@ -220,7 +220,7 @@ abstract contract Escrow is AtlETH {
220220

221221
if (_result.executionSuccessful()) {
222222
// Logic done above `_handleSolverFailAccounting()` is to charge solver for gas used here
223-
ctx.solverOutcome = uint24(_result);
223+
ctx.solverOutcome = _result.toUint24();
224224

225225
// First successful solver call that paid what it bid
226226
emit SolverTxResult(
@@ -256,7 +256,7 @@ abstract contract Escrow is AtlETH {
256256
}
257257

258258
// If we reach this point, the solver call did not execute successfully.
259-
ctx.solverOutcome = uint24(_result);
259+
ctx.solverOutcome = _result.toUint24();
260260

261261
emit SolverTxResult(
262262
solverOp.solver,
@@ -756,5 +756,29 @@ abstract contract Escrow is AtlETH {
756756
ctx.dappGasLeft -= uint32(_gasUsed);
757757
}
758758

759+
/// @notice Allocates any spare gas remaining to executing tasks on the TaskManager, which will generate fees.
760+
/// @dev This is typically called outside of the try/catch and must therefore be careful not to revert.
761+
/// @param feeBeneficiary The recipient of any fees generated from executing tasks.
762+
/// @param targetGasReserve The remaining gas necessary for the calling (outer) function to complete.
763+
/// @return feesCollected The fees generated from executing tasks.
764+
function _allocateGasToTaskManager(address feeBeneficiary, uint256 targetGasReserve) internal returns (uint256) {
765+
// Skip if TASK_MANAGER is not set (e.g., in tests)
766+
if (address(TASK_MANAGER) == address(0)) {
767+
return 0;
768+
}
769+
770+
// Only call if we have enough gas for a full task
771+
if (gasleft() * 63 / 64 < 135_000 + targetGasReserve) {
772+
return 0;
773+
}
774+
775+
// Under no circumstance should we allow a revert here to bubble up
776+
try TASK_MANAGER.executeTasks(feeBeneficiary, targetGasReserve) returns (uint256 _feesEarned) {
777+
return _feesEarned;
778+
} catch {
779+
return 0;
780+
}
781+
}
782+
759783
receive() external payable { }
760784
}

src/atlas/core/GasAccounting.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { CallBits } from "../libraries/CallBits.sol";
1212
import { AccountingMath } from "../libraries/AccountingMath.sol";
1313
import { GasAccLib, GasLedger, BorrowsLedger } from "../libraries/GasAccLib.sol";
1414
import { SolverOperation } from "../types/SolverOperation.sol";
15-
import { DAppConfig } from "../types/ConfigTypes.sol";
16-
import { IL2GasCalculator } from "../interfaces/IL2GasCalculator.sol";
1715
import "../types/EscrowTypes.sol";
1816
import "../types/LockTypes.sol";
1917

@@ -36,6 +34,7 @@ abstract contract GasAccounting is SafetyLocks {
3634
address simulator,
3735
address initialSurchargeRecipient,
3836
address l2GasCalculator,
37+
address taskManager,
3938
address shMonad,
4039
uint64 shMonadPolicyID
4140
)
@@ -45,6 +44,7 @@ abstract contract GasAccounting is SafetyLocks {
4544
simulator,
4645
initialSurchargeRecipient,
4746
l2GasCalculator,
47+
taskManager,
4848
shMonad,
4949
shMonadPolicyID
5050
)

src/atlas/core/Permit69.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
pragma solidity 0.8.28;
33

44
import { SafeTransferLib } from "@solady/utils/SafeTransferLib.sol";
5-
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
65

76
import { GasAccounting } from "./GasAccounting.sol";
87

98
import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "../libraries/SafetyBits.sol";
10-
import "../types/LockTypes.sol";
11-
import "../types/EscrowTypes.sol";
129

1310
// NOTE: Permit69 only works inside of the Atlas environment - specifically
1411
// inside of the custom ExecutionEnvironments that each user deploys when
@@ -31,6 +28,7 @@ abstract contract Permit69 is GasAccounting {
3128
address simulator,
3229
address initialSurchargeRecipient,
3330
address l2GasCalculator,
31+
address taskManager,
3432
address shMonad,
3533
uint64 shMonadPolicyID
3634
)
@@ -40,6 +38,7 @@ abstract contract Permit69 is GasAccounting {
4038
simulator,
4139
initialSurchargeRecipient,
4240
l2GasCalculator,
41+
taskManager,
4342
shMonad,
4443
shMonadPolicyID
4544
)

src/atlas/core/SafetyLocks.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ pragma solidity 0.8.28;
33

44
import { Storage } from "./Storage.sol";
55
import { CallBits } from "../libraries/CallBits.sol";
6-
import "../types/SolverOperation.sol";
7-
import "../types/UserOperation.sol";
86
import "../types/ConfigTypes.sol";
9-
import "../types/EscrowTypes.sol";
107
import "../types/LockTypes.sol";
118

129
/// @title SafetyLocks
@@ -22,6 +19,7 @@ abstract contract SafetyLocks is Storage {
2219
address simulator,
2320
address initialSurchargeRecipient,
2421
address l2GasCalculator,
22+
address taskManager,
2523
address shMonad,
2624
uint64 shMonadPolicyID
2725
)
@@ -31,6 +29,7 @@ abstract contract SafetyLocks is Storage {
3129
simulator,
3230
initialSurchargeRecipient,
3331
l2GasCalculator,
32+
taskManager,
3433
shMonad,
3534
shMonadPolicyID
3635
)

src/atlas/core/Storage.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
pragma solidity 0.8.28;
33

44
import "../types/EscrowTypes.sol";
5-
import "../types/LockTypes.sol";
65
import "../libraries/AccountingMath.sol";
76

87
import { AtlasEvents } from "../types/AtlasEvents.sol";
98
import { AtlasErrors } from "../types/AtlasErrors.sol";
109
import { AtlasConstants } from "../types/AtlasConstants.sol";
1110
import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol";
1211
import { IShMonad } from "../../shmonad/interfaces/IShMonad.sol";
12+
import { ITaskManager } from "../../task-manager/interfaces/ITaskManager.sol";
1313

1414
/// @title Storage
1515
/// @author FastLane Labs
@@ -20,11 +20,11 @@ abstract contract Storage is AtlasEvents, AtlasErrors, AtlasConstants {
2020
address public immutable L2_GAS_CALCULATOR;
2121

2222
IShMonad public immutable SHMONAD;
23+
ITaskManager public immutable TASK_MANAGER;
2324
uint64 public immutable POLICY_ID;
2425

2526
// Gas Accounting public constants
2627
uint256 public constant SCALE = AccountingMath._SCALE;
27-
uint256 public constant FIXED_GAS_OFFSET = AccountingMath._FIXED_GAS_OFFSET;
2828

2929
// Transient storage slots
3030
uint256 internal transient t_lock; // contains activeAddress, callConfig, and phase
@@ -54,6 +54,7 @@ abstract contract Storage is AtlasEvents, AtlasErrors, AtlasConstants {
5454
address simulator,
5555
address initialSurchargeRecipient,
5656
address l2GasCalculator,
57+
address taskManager,
5758
address shMonad,
5859
uint64 shMonadPolicyID
5960
)
@@ -64,6 +65,7 @@ abstract contract Storage is AtlasEvents, AtlasErrors, AtlasConstants {
6465
SIMULATOR = simulator;
6566
L2_GAS_CALCULATOR = l2GasCalculator;
6667
POLICY_ID = shMonadPolicyID;
68+
TASK_MANAGER = ITaskManager(taskManager);
6769

6870
// Check Atlas gas surcharge fits in 24 bits
6971
if(atlasSurchargeRate > type(uint24).max) {

src/atlas/dapp/ControlTemplate.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity 0.8.28;
33

44
import "../types/SolverOperation.sol";
55
import "../types/UserOperation.sol";
6-
import "../types/ConfigTypes.sol";
76
import { AtlasErrors } from "../types/AtlasErrors.sol";
87

98
abstract contract DAppControlTemplate {

0 commit comments

Comments
 (0)