From a0dc8fff4c3b090c33c6f121597f872d227537b7 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:28:37 +0200 Subject: [PATCH 01/70] fix: conditionally forward `returnData` to solvers --- src/contracts/atlas/Escrow.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 27c633fbf..c2ae85de7 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -609,8 +609,8 @@ abstract contract Escrow is AtlETH { solverOp.bidToken, bidAmount, solverOp.data, - // Only pass the returnData to solver if it came from userOp call and not from preOps call. - _activeCallConfig().needsUserReturnData() ? returnData : new bytes(0) + // Only pass the returnData (either from userOp or preOps) if the dApp requires it + _activeCallConfig().forwardReturnData() ? returnData : new bytes(0) ) ) ); From b46981ca0aa47e151b2d95adf9f12cf1c94d0b83 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:39:22 +0200 Subject: [PATCH 02/70] fix: enforce `userOp.gas` as userOp's gas limit --- src/contracts/atlas/Escrow.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 27c633fbf..ede162311 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -96,7 +96,7 @@ abstract contract Escrow is AtlETH { revert InsufficientEscrow(); } - (_success, _data) = ctx.executionEnvironment.call{ value: userOp.value }( + (_success, _data) = ctx.executionEnvironment.call{ value: userOp.value, gas: userOp.gas }( abi.encodePacked( abi.encodeCall(IExecutionEnvironment.userWrapper, userOp), ctx.setAndPack(ExecutionPhase.UserOperation) ) From 5e05707005d8cfcddf2bebbd3b9fb699a716b104 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:49:44 +0200 Subject: [PATCH 03/70] fix: use smaller of `userOp.gas` and `gasleft()` as limit --- src/contracts/atlas/Escrow.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index ede162311..e133cd204 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -91,12 +91,13 @@ abstract contract Escrow is AtlETH { { bool _success; bytes memory _data; + uint256 _gasLimit = userOp.gas > gasleft() ? gasleft() : userOp.gas; if (!_borrow(userOp.value)) { revert InsufficientEscrow(); } - (_success, _data) = ctx.executionEnvironment.call{ value: userOp.value, gas: userOp.gas }( + (_success, _data) = ctx.executionEnvironment.call{ value: userOp.value, gas: _gasLimit }( abi.encodePacked( abi.encodeCall(IExecutionEnvironment.userWrapper, userOp), ctx.setAndPack(ExecutionPhase.UserOperation) ) From 4c9c5e3f93a47b97697841a65fecb73a7e69e6a5 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:48:55 +0200 Subject: [PATCH 04/70] chore: update Atlas license --- LICENSE | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index 3f19c92f6..e4058c4eb 100644 --- a/LICENSE +++ b/LICENSE @@ -9,14 +9,14 @@ Parameters Licensor: Fastlane Labs -Licensed Work: FastLane Protocol - The Licensed Work is (c) 2023 Fastlane Labs +Licensed Work: Atlas Protocol + The Licensed Work is (c) 2024 Fastlane Labs Additional Use Grant: Any uses listed and defined at - fastlane-protocol-license.fastlane.finance + atlas-license.fastlane.finance -Change Date: The earlier of 2025-07-01 or a date specified at - fastlane-protocol-license.fastlane.finance +Change Date: The earlier of 2026-07-01 or a date specified at + atlas-license.fastlane.finance Change License: GNU General Public License v2.0 or later From a448c9864a3a6c22d400ab37c7c45e6349f074da Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:02:12 +0200 Subject: [PATCH 05/70] chore: update Atlas license --- LICENSE | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index e4058c4eb..11b0fd732 100644 --- a/LICENSE +++ b/LICENSE @@ -12,11 +12,7 @@ Licensor: Fastlane Labs Licensed Work: Atlas Protocol The Licensed Work is (c) 2024 Fastlane Labs -Additional Use Grant: Any uses listed and defined at - atlas-license.fastlane.finance - -Change Date: The earlier of 2026-07-01 or a date specified at - atlas-license.fastlane.finance +Change Date: 2026-07-01 Change License: GNU General Public License v2.0 or later From cf271a6c6535f9bfd46d037f0fb4840b29d5b19a Mon Sep 17 00:00:00 2001 From: jj1980a Date: Sat, 7 Sep 2024 10:35:52 +0400 Subject: [PATCH 06/70] base L2 gas calculator contract --- lib/openzeppelin-contracts | 2 +- .../gasCalculator/BaseGasCalculator.sol | 44 +++++++++++++++++++ src/contracts/interfaces/IL2GasCalculator.sol | 2 +- src/contracts/types/SolverOperation.sol | 4 +- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/contracts/gasCalculator/BaseGasCalculator.sol diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts index dbb6104ce..bd325d56b 160000 --- a/lib/openzeppelin-contracts +++ b/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit dbb6104ce834628e473d2173bbc9d47f81a9eec3 +Subproject commit bd325d56b4c62c9c5c1aff048c37c6bb18ac0290 diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol new file mode 100644 index 000000000..bcff04c7c --- /dev/null +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -0,0 +1,44 @@ +//SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.25; + +import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; + +/// @notice Implementation: +/// https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/GasPriceOracle.sol +/// @notice Deployment on Base: https://basescan.org/address/0x420000000000000000000000000000000000000f +interface IGasPriceOracle { + function getL1FeeUpperBound(uint256 _unsignedTxSize) external view returns (uint256); +} + +contract BaseGasCalculator is IL2GasCalculator { + uint256 public constant _CALLDATA_LENGTH_PREMIUM = 32; // TODO: copied value from Atlas, should it be different for + // Base? + uint256 internal constant _BASE_TRANSACTION_GAS_USED = 21_000; + + address public immutable gasPriceOracle; + + constructor(address _gasPriceOracle) { + gasPriceOracle = _gasPriceOracle; + } + + /// @notice Calculate the cost of calldata in ETH on a L2 with a different fee structure than mainnet + /// @param calldataLength The length of the calldata in bytes + function getCalldataCost(uint256 calldataLength) external view override returns (uint256 calldataCost) { + // `getL1FeeUpperBound` returns the upper bound of the L1 fee in wei. It expects an unsigned transaction size in + // bytes, *not calldata length only*, which makes this function a rough estimate. + + // Base execution cost. + calldataCost = calldataLength * _CALLDATA_LENGTH_PREMIUM * tx.gasprice; + + // L1 data cost. + // `getL1FeeUpperBound` adds 68 to the size because it expects an unsigned transaction size. + // Remove 68 to the length to account for this. + calldataCost += IGasPriceOracle(gasPriceOracle).getL1FeeUpperBound(calldataLength - 68); + } + + /// @notice Gets the cost of initial gas used for a transaction with a different calldata fee than mainnet + /// @param calldataLength The length of the calldata in bytes + function initialGasUsed(uint256 calldataLength) external pure override returns (uint256 gasUsed) { + return _BASE_TRANSACTION_GAS_USED + (calldataLength * _CALLDATA_LENGTH_PREMIUM); + } +} diff --git a/src/contracts/interfaces/IL2GasCalculator.sol b/src/contracts/interfaces/IL2GasCalculator.sol index 33f7cc0be..387aab8e8 100644 --- a/src/contracts/interfaces/IL2GasCalculator.sol +++ b/src/contracts/interfaces/IL2GasCalculator.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.25; interface IL2GasCalculator { /// @notice Calculate the cost of calldata in ETH on a L2 with a different fee structure than mainnet - function getCalldataCost(uint256 length) external view returns (uint256 calldataCostETH); + function getCalldataCost(uint256 calldataLength) external view returns (uint256 calldataCost); /// @notice Gets the cost of initial gas used for a transaction with a different calldata fee than mainnet function initialGasUsed(uint256 calldataLength) external view returns (uint256 gasUsed); } diff --git a/src/contracts/types/SolverOperation.sol b/src/contracts/types/SolverOperation.sol index 7e6bf94bf..ffd9392e6 100644 --- a/src/contracts/types/SolverOperation.sol +++ b/src/contracts/types/SolverOperation.sol @@ -6,8 +6,8 @@ bytes32 constant SOLVER_TYPEHASH = keccak256( ); // NOTE: The calldata length of this SolverOperation struct is 608 bytes when the `data` field is excluded. This value -// is stored in the `_SOLVER_OP_BASE_CALLDATA` constant in Storage.sol and must be kept up-to-date with any changes to -// this struct. +// is stored in the `_SOLVER_OP_BASE_CALLDATA` constant in AtlasConstants.sol and must be kept up-to-date with any +// changes to this struct. struct SolverOperation { address from; // Solver address address to; // Atlas address From f5e9dd1fdb7fb6ba8aadf857d65a9c39ad4e0f38 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 10 Sep 2024 12:05:52 +0400 Subject: [PATCH 07/70] contract ownable --- src/contracts/gasCalculator/BaseGasCalculator.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index bcff04c7c..bbdd4c3b8 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -1,6 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; +import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; /// @notice Implementation: @@ -10,14 +11,13 @@ interface IGasPriceOracle { function getL1FeeUpperBound(uint256 _unsignedTxSize) external view returns (uint256); } -contract BaseGasCalculator is IL2GasCalculator { - uint256 public constant _CALLDATA_LENGTH_PREMIUM = 32; // TODO: copied value from Atlas, should it be different for - // Base? +contract BaseGasCalculator is IL2GasCalculator, Ownable { + uint256 internal constant _CALLDATA_LENGTH_PREMIUM = 32; uint256 internal constant _BASE_TRANSACTION_GAS_USED = 21_000; address public immutable gasPriceOracle; - constructor(address _gasPriceOracle) { + constructor(address _gasPriceOracle) Ownable(msg.sender) { gasPriceOracle = _gasPriceOracle; } From f8dbebce10dcf375d3b6ebbd9ccd22595625d482 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 10 Sep 2024 12:24:26 +0400 Subject: [PATCH 08/70] introduce a customizable offset value to be added to passed call data length --- .../gasCalculator/BaseGasCalculator.sol | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index bbdd4c3b8..a0dfc09ef 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -16,9 +16,11 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { uint256 internal constant _BASE_TRANSACTION_GAS_USED = 21_000; address public immutable gasPriceOracle; + int256 public calldataLengthOffset; - constructor(address _gasPriceOracle) Ownable(msg.sender) { + constructor(address _gasPriceOracle, int256 _calldataLengthOffset) Ownable(msg.sender) { gasPriceOracle = _gasPriceOracle; + calldataLengthOffset = _calldataLengthOffset; } /// @notice Calculate the cost of calldata in ETH on a L2 with a different fee structure than mainnet @@ -33,7 +35,18 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { // L1 data cost. // `getL1FeeUpperBound` adds 68 to the size because it expects an unsigned transaction size. // Remove 68 to the length to account for this. - calldataCost += IGasPriceOracle(gasPriceOracle).getL1FeeUpperBound(calldataLength - 68); + if (calldataLength < 68) { + calldataLength = 0; + } else { + calldataLength -= 68; + } + + if (calldataLengthOffset < 0 && calldataLength < uint256(-calldataLengthOffset)) { + return calldataCost; + } + + calldataLength += uint256(calldataLengthOffset); + calldataCost += IGasPriceOracle(gasPriceOracle).getL1FeeUpperBound(calldataLength); } /// @notice Gets the cost of initial gas used for a transaction with a different calldata fee than mainnet @@ -41,4 +54,10 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { function initialGasUsed(uint256 calldataLength) external pure override returns (uint256 gasUsed) { return _BASE_TRANSACTION_GAS_USED + (calldataLength * _CALLDATA_LENGTH_PREMIUM); } + + /// @notice Sets the calldata length offset + /// @param _calldataLengthOffset The new calldata length offset + function setCalldataLengthOffset(int256 _calldataLengthOffset) external onlyOwner { + calldataLengthOffset = _calldataLengthOffset; + } } From fd33c385a0c34414e6526db61112995ae78b7a8f Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 10 Sep 2024 12:46:25 +0400 Subject: [PATCH 09/70] deploy script --- package.json | 2 ++ script/deploy-gas-calculator.s.sol | 46 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 script/deploy-gas-calculator.s.sol diff --git a/package.json b/package.json index 87452d747..fa096bdc3 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,8 @@ "solver-deposit": "source .env && forge script script/solver-deposit.s.sol:SolverAtlasDepositScript --fork-url http://localhost:8545 --broadcast --non-interactive", "setup-demo": "npm run deploy-atlas-swap-intent-tx-builder && npm run deploy-solver && npm run solver-deposit", + "deploy-gas-calculator-base": "source .env && forge script script/deploy-gas-calculator.s.sol:DeployGasCalculatorScript --rpc-url ${BASE_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", + "atlas-addr": "echo 'ATLAS:' && jq -r '.ATLAS' deployments.json", "swap-intent-addr": "echo 'SWAP INTENT DAPP CONTROL:' && jq -r '.SWAP_INTENT_DAPP_CONTROL' deployments.json", "tx-builder-addr": "echo 'TX BUILDER:' && jq -r '.TX_BUILDER' deployments.json", diff --git a/script/deploy-gas-calculator.s.sol b/script/deploy-gas-calculator.s.sol new file mode 100644 index 000000000..8c52a0e71 --- /dev/null +++ b/script/deploy-gas-calculator.s.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.25; + +import "forge-std/Test.sol"; + +import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { BaseGasCalculator } from "src/contracts/gasCalculator/BaseGasCalculator.sol"; + +contract DeployGasCalculatorScript is DeployBaseScript { + function run() external { + console.log("\n=== DEPLOYING GasCalculator ===\n"); + + console.log("Deploying to chain: \t\t", _getDeployChain()); + + uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + + uint256 chainId = block.chainid; + string memory deploymentName; + address deploymentAddr; + + vm.startBroadcast(deployerPrivateKey); + + if (chainId == 8453 || chainId == 84_532) { + // Base or Base Sepolia + BaseGasCalculator gasCalculator = new BaseGasCalculator({ + _gasPriceOracle: address(0), // Insert gas price oracle address here + _calldataLengthOffset: 0 // Insert calldata length offset here (can be negative) + }); + deploymentName = "BASE_GAS_CALCULATOR"; + deploymentAddr = address(gasCalculator); + } else { + revert("Error: Chain ID not supported"); + } + + vm.stopBroadcast(); + + _writeAddressToDeploymentsJson(deploymentName, deploymentAddr); + + console.log("\n"); + console.log("Deployed contract: ", deploymentName); + console.log("Deployed at address: ", deploymentAddr); + console.log("\n"); + console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); + } +} From 2448be065ffc5cfa94a97c8f40f07f4475b0502e Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 10 Sep 2024 12:51:58 +0400 Subject: [PATCH 10/70] forge update --- lib/forge-std | 2 +- lib/openzeppelin-contracts | 2 +- lib/solady | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index e4aef94c1..1ce7535a5 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e4aef94c1768803a16fe19f7ce8b65defd027cfd +Subproject commit 1ce7535a517406b9aec7ea1ea27c1b41376f712c diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts index bd325d56b..dbb6104ce 160000 --- a/lib/openzeppelin-contracts +++ b/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit bd325d56b4c62c9c5c1aff048c37c6bb18ac0290 +Subproject commit dbb6104ce834628e473d2173bbc9d47f81a9eec3 diff --git a/lib/solady b/lib/solady index bb4b43b44..f833eadd4 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit bb4b43b44bec3c5d42604c08904bca0442e0bc78 +Subproject commit f833eadd4591da7e8e455eab779bf1d918486847 From 8fcf58f0b253fa4afdfb8726bca2f7f4a7a2d9fd Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 Sep 2024 12:32:16 -0700 Subject: [PATCH 11/70] back-end approach --- lib/forge-std | 2 +- lib/solady | 2 +- src/contracts/atlas/GasAccounting.sol | 23 +++++++++++++++++------ src/contracts/atlas/Storage.sol | 12 ++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index e4aef94c1..1ce7535a5 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e4aef94c1768803a16fe19f7ce8b65defd027cfd +Subproject commit 1ce7535a517406b9aec7ea1ea27c1b41376f712c diff --git a/lib/solady b/lib/solady index bb4b43b44..4f5098200 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit bb4b43b44bec3c5d42604c08904bca0442e0bc78 +Subproject commit 4f50982008973b1431768a75fb88ac8eca21b9f6 diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 63f9cdd48..b22c496f1 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -40,6 +40,7 @@ abstract contract GasAccounting is SafetyLocks { // Atlas surcharge is based on the raw claims value. _setFees(_rawClaims.getAtlasSurcharge()); _setDeposits(msg.value); + _setSolverSurcharge(0); // Explicitly set writeoffs and withdrawals to 0 in case multiple metacalls in single tx. _setWriteoffs(0); @@ -285,6 +286,7 @@ abstract contract GasAccounting is SafetyLocks { } else { // CASE: Solver failed, so we calculate what they owe. uint256 _gasUsedWithSurcharges = _gasUsed.withAtlasAndBundlerSurcharges(); + _setSolverSurcharge(solverSurcharge() + _gasUsedWithSurcharges - _gasUsed); _assign(solverOp.from, _gasUsedWithSurcharges, _gasUsedWithSurcharges, false); } } @@ -319,24 +321,33 @@ abstract contract GasAccounting is SafetyLocks { ) { uint256 _surcharge = S_cumulativeSurcharge; - uint256 _fees = fees(); adjustedWithdrawals = withdrawals(); adjustedDeposits = deposits(); adjustedClaims = claims(); adjustedWriteoffs = writeoffs(); + uint256 _fees = fees(); uint256 _gasLeft = gasleft(); // Hold this constant for the calculations // Estimate the unspent, remaining gas that the Solver will not be liable for. uint256 _gasRemainder = _gasLeft * tx.gasprice; - // Calculate the preadjusted netAtlasGasSurcharge - netAtlasGasSurcharge = _fees - _gasRemainder.getAtlasSurcharge(); - adjustedClaims -= _gasRemainder.withBundlerSurcharge(); - adjustedWithdrawals += netAtlasGasSurcharge; - S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge + + if (ctx.solverSuccessful) { + // Calculate the preadjusted netAtlasGasSurcharge + netAtlasGasSurcharge = _fees - _gasRemainder.getAtlasSurcharge(); + + adjustedWithdrawals += netAtlasGasSurcharge; + + S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge + + } else { + netAtlasGasSurcharge = solverSurcharge(); + S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge + return (adjustedWithdrawals, adjustedDeposits, adjustedClaims, adjustedWriteoffs, netAtlasGasSurcharge); + } // Calculate whether or not the bundler used an excessive amount of gas and, if so, reduce their // gas rebate. By reducing the claims, solvers end up paying less in total. diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 4a20052b1..4ae1171c6 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -35,11 +35,13 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { bytes32 private constant _T_LOCK_SLOT = keccak256("ATLAS_LOCK"); bytes32 private constant _T_SOLVER_LOCK_SLOT = keccak256("ATLAS_SOLVER_LOCK"); bytes32 private constant _T_SOLVER_TO_SLOT = keccak256("ATLAS_SOLVER_TO"); + bytes32 private constant _T_CLAIMS_SLOT = keccak256("ATLAS_CLAIMS"); bytes32 private constant _T_FEES_SLOT = keccak256("ATLAS_FEES"); bytes32 private constant _T_WRITEOFFS_SLOT = keccak256("ATLAS_WRITEOFFS"); bytes32 private constant _T_WITHDRAWALS_SLOT = keccak256("ATLAS_WITHDRAWALS"); bytes32 private constant _T_DEPOSITS_SLOT = keccak256("ATLAS_DEPOSITS"); + bytes32 private constant _T_SOLVER_SURCHARGE_SLOT = keccak256("ATLAS_SOLVER_SURCHARGE"); // AtlETH storage uint256 internal S_totalSupply; @@ -169,6 +171,10 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { return uint256(_tload(_T_DEPOSITS_SLOT)); } + function solverSurcharge() internal view returns (uint256) { + return uint256(_tload(_T_SOLVER_SURCHARGE_SLOT)); + } + function _lock() internal view returns (address activeEnvironment, uint32 callConfig, uint8 phase) { bytes32 _lockData = _tload(_T_LOCK_SLOT); activeEnvironment = address(uint160(uint256(_lockData >> 40))); @@ -262,6 +268,12 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { _tstore(_T_DEPOSITS_SLOT, bytes32(newDeposits)); } + // NOTE: Only captures surcharges for failed solver Ops where + // solver is at fault + function _setSolverSurcharge(uint256 newSurcharge) internal { + _tstore(_T_SOLVER_SURCHARGE_SLOT, bytes32(newSurcharge)); + } + // ------------------------------------------------------ // // Transient Storage Helpers // // ------------------------------------------------------ // From 47bcfd80412e309f9a974bdf44dcb6a2c532d065 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:56:47 +0200 Subject: [PATCH 12/70] fmt: forge fmt --- src/contracts/atlas/GasAccounting.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index b22c496f1..613027eeb 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -342,7 +342,6 @@ abstract contract GasAccounting is SafetyLocks { adjustedWithdrawals += netAtlasGasSurcharge; S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge - } else { netAtlasGasSurcharge = solverSurcharge(); S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge From 44eb8e0bab8e453e2cd2ae0041b9a90f11d8a55e Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:43:44 +0200 Subject: [PATCH 13/70] fix: TrebleSwap tests to handle new surcharge rules --- test/TrebleSwap.t.sol | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/TrebleSwap.t.sol b/test/TrebleSwap.t.sol index 9ac734205..b80f76965 100644 --- a/test/TrebleSwap.t.sol +++ b/test/TrebleSwap.t.sol @@ -52,7 +52,7 @@ contract TrebleSwapTest is BaseTest { address BRETT = 0x532f27101965dd16442E59d40670FaF5eBB142E4; address TREB; // will be set to value in DAppControl in setUp - uint256 ERR_MARGIN = 0.18e18; // 18% error margin + uint256 ERR_MARGIN = 0.22e18; // 22% error margin uint256 bundlerGasEth = 1e16; TrebleSwapDAppControl trebleSwapControl; @@ -288,9 +288,7 @@ contract TrebleSwapTest is BaseTest { beforeVars.solverTrebBalance = _balanceOf(address(TREB), winningSolver); beforeVars.burnAddressTrebBalance = _balanceOf(address(TREB), BURN); beforeVars.atlasGasSurcharge = atlas.cumulativeSurcharge(); - uint256 msgValue = (args.nativeInput ? swapInfo.inputAmount : 0) + bundlerGasEth; - if (args.nativeInput) beforeVars.userInputTokenBalance -= bundlerGasEth; - if (args.nativeOutput) beforeVars.userOutputTokenBalance -= bundlerGasEth; + uint256 msgValue = args.nativeInput ? swapInfo.inputAmount : 0; uint256 txGasUsed; uint256 estAtlasGasSurcharge = gasleft(); // Reused below during calculations @@ -306,13 +304,28 @@ contract TrebleSwapTest is BaseTest { // Check Atlas auctionWon return value assertEq(auctionWon, auctionWonExpected, "auctionWon not as expected"); + // Check msg.value is 0 unless sending ETH as the input token to be swapped + if (!args.nativeInput) assertEq(msgValue, 0, "msgValue should have been 0"); + // Check Atlas gas surcharge change - assertApproxEqRel( - atlas.cumulativeSurcharge() - beforeVars.atlasGasSurcharge, - estAtlasGasSurcharge, - ERR_MARGIN, - "Atlas gas surcharge not within estimated range" - ); + if (args.solverOps.length > 0 && auctionWonExpected) { + assertApproxEqRel( + atlas.cumulativeSurcharge() - beforeVars.atlasGasSurcharge, + estAtlasGasSurcharge, + ERR_MARGIN, + "Atlas gas surcharge not within estimated range" + ); + } else if (args.solverOps.length == 0) { + // No surcharge taken if no solvers. + assertEq( + atlas.cumulativeSurcharge(), + beforeVars.atlasGasSurcharge, + "Atlas gas surcharge changed when zero solvers" + ); + } else { + // If solver failed (solver's fault), surcharge still taken, but only on failing solverOp portion. Difficult + // to estimate what that would be so skip this check in that 1 test case. + } // Check user input token change if (args.nativeInput && auctionWonExpected) { From 392ba0e3e43497e72fd346b1ba4831f60194cdbc Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:07:20 +0200 Subject: [PATCH 14/70] fix: record accurate `solverSurcharge` figure --- src/contracts/atlas/GasAccounting.sol | 28 ++++++++++++++++++++------- test/GasAccounting.t.sol | 10 ---------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 613027eeb..5b04b288d 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -286,8 +286,19 @@ abstract contract GasAccounting is SafetyLocks { } else { // CASE: Solver failed, so we calculate what they owe. uint256 _gasUsedWithSurcharges = _gasUsed.withAtlasAndBundlerSurcharges(); - _setSolverSurcharge(solverSurcharge() + _gasUsedWithSurcharges - _gasUsed); - _assign(solverOp.from, _gasUsedWithSurcharges, _gasUsedWithSurcharges, false); + uint256 _surchargesOnly = _gasUsedWithSurcharges - _gasUsed; + + // In `_assign()`, the failing solver's bonded AtlETH balance is reduced by `_gasUsedWithSurcharges`. Any + // deficit from that operation is added to `writeoffs` and returned as `_assignDeficit` below. The portion + // that can be covered by the solver's AtlETH is added to `deposits`, to account that it has been paid. + uint256 _assignDeficit = _assign(solverOp.from, _gasUsedWithSurcharges, _gasUsedWithSurcharges, false); + + // We track the surcharges (in excess of deficit - so the actual AtlETH that can be collected) separately, + // so that in the event of no successful solvers, any `_assign()`ed surcharges can be attributed to an + // increase in Atlas' cumulative surcharge. + if (_surchargesOnly > _assignDeficit) { + _setSolverSurcharge(solverSurcharge() + (_surchargesOnly - _assignDeficit)); + } } } @@ -336,15 +347,18 @@ abstract contract GasAccounting is SafetyLocks { adjustedClaims -= _gasRemainder.withBundlerSurcharge(); if (ctx.solverSuccessful) { - // Calculate the preadjusted netAtlasGasSurcharge + // If a solver was successful, calc the full Atlas gas surcharge on the gas cost of the entire metacall, and + // add it to withdrawals so that the cost is assigned to winning solver by the end of _settle(). This will + // be offset by any gas surcharge paid by failed solvers, which would have been added to deposits or + // writeoffs in _handleSolverAccounting(). As such, the winning solver does not pay for surcharge on the gas + // used by other solvers. netAtlasGasSurcharge = _fees - _gasRemainder.getAtlasSurcharge(); - adjustedWithdrawals += netAtlasGasSurcharge; - - S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge + S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; } else { + // If no successful solvers, only collect partial surcharges from solver's fault failures (if any) netAtlasGasSurcharge = solverSurcharge(); - S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge + if (netAtlasGasSurcharge > 0) S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; return (adjustedWithdrawals, adjustedDeposits, adjustedClaims, adjustedWriteoffs, netAtlasGasSurcharge); } diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index 39f62bfb0..adc23846e 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -27,7 +27,6 @@ import { BaseTest } from "test/base/BaseTest.t.sol"; contract MockGasAccounting is TestAtlas, BaseTest { uint256 public constant MOCK_SOLVER_GAS_LIMIT = 500_000; - constructor( uint256 _escrowDuration, address _verification, @@ -1030,15 +1029,6 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq(unbonding, unbondingBefore); } - function test_settle_withFailedsolver_reverts() public { - // Setup context with initial claims and deposits - Context memory ctx = setupContext(1 ether, 1 ether, 4000 ether, 1000 ether, false); - - // Expect a revert due to insufficient total balance for a failed solver - vm.expectRevert(); - mockGasAccounting.settle(ctx); - } - function test_settle_with_deposits() public { Context memory ctx = setupContext(1 ether, 0.5 ether, 4000 ether, 1000 ether, true); // Check initial balances From 0f749dab0f65d60efae973374b7dd2a1e86174d1 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:17:17 +0200 Subject: [PATCH 15/70] fix: 2 Escrow tests - metacall no longer reverts --- test/Escrow.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index e789f0196..08bc4ff51 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -304,7 +304,7 @@ contract EscrowTest is BaseTest { .withGas(solverGasLimit) .signAndBuild(address(atlasVerification), solverOnePK); - executeSolverOperationCase(userOp, solverOps, false, false, 1 << uint256(SolverOutcome.InsufficientEscrow), true); + executeSolverOperationCase(userOp, solverOps, false, false, 1 << uint256(SolverOutcome.InsufficientEscrow), false); } function test_executeSolverOperation_validateSolverOperation_callValueTooHigh_SkipCoverage() public { @@ -323,7 +323,7 @@ contract EscrowTest is BaseTest { function test_executeSolverOperation_validateSolverOperation_userOutOfGas_SkipCoverage() public { (UserOperation memory userOp, SolverOperation[] memory solverOps) = executeSolverOperationInit(defaultCallConfig().build()); this.executeSolverOperationCase{gas: _VALIDATION_GAS_LIMIT + _SOLVER_GAS_LIMIT + 1_000_000}( - userOp, solverOps, false, false, 1 << uint256(SolverOutcome.UserOutOfGas), true + userOp, solverOps, false, false, 1 << uint256(SolverOutcome.UserOutOfGas), false ); } From 6f1f469257a20ddac9a533dd1c1267361f23c764 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:05:57 +0200 Subject: [PATCH 16/70] fix: FLOnline breaking tests for surcharge rule change --- test/FLOnline.t.sol | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/test/FLOnline.t.sol b/test/FLOnline.t.sol index 082507d48..e8520b826 100644 --- a/test/FLOnline.t.sol +++ b/test/FLOnline.t.sol @@ -51,6 +51,7 @@ contract FastLaneOnlineTest is BaseTest { bool solverFour; } + uint256 constant SURCHARGE_PER_SOLVER_IF_ALL_FAIL = 28_000e9; // 28k Gwei (avg, differs for ERC20/native in/out) uint256 constant ERR_MARGIN = 0.15e18; // 15% error margin address internal constant NATIVE_TOKEN = address(0); @@ -1279,7 +1280,6 @@ contract FastLaneOnlineTest is BaseTest { internal { bool nativeTokenIn = args.swapIntent.tokenUserSells == NATIVE_TOKEN; - bool nativeTokenOut = args.swapIntent.tokenUserBuys == NATIVE_TOKEN; bool solverWon = winningSolver != address(0); beforeVars.userTokenOutBalance = _balanceOf(args.swapIntent.tokenUserBuys, userEOA); @@ -1315,13 +1315,26 @@ contract FastLaneOnlineTest is BaseTest { // Return early if transaction expected to revert. Balance checks below would otherwise fail. if (!swapCallShouldSucceed) return; - // Check Atlas gas surcharge earned is within 15% of the estimated gas surcharge - assertApproxEqRel( - atlas.cumulativeSurcharge() - beforeVars.atlasGasSurcharge, - estAtlasGasSurcharge, - ERR_MARGIN, - "Atlas gas surcharge not within estimated range" - ); + if (solverCount == 0) { + // If zero solvers, no surcharge taken + assertEq(atlas.cumulativeSurcharge(), beforeVars.atlasGasSurcharge, "Atlas gas surcharge should not change"); + } else if (solverWon) { + // Check Atlas gas surcharge earned is within 15% of the estimated gas surcharge + assertApproxEqRel( + atlas.cumulativeSurcharge() - beforeVars.atlasGasSurcharge, + estAtlasGasSurcharge, + ERR_MARGIN, + "Atlas gas surcharge not within estimated range (solver won)" + ); + } else { + // If all solvers fail, surcharge taken only on gas cost of solverOps failed due to solver fault + assertApproxEqRel( + atlas.cumulativeSurcharge() - beforeVars.atlasGasSurcharge, + SURCHARGE_PER_SOLVER_IF_ALL_FAIL * solverCount, + ERR_MARGIN, + "Atlas gas surcharge not within estimated range (solvers failed)" + ); + } // Check user's balances changed as expected assertTrue( From c4de266110dd7c3de7db2f3aa6ab831e42310564 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:05:52 +0200 Subject: [PATCH 17/70] chore: Base L2 Gas Calculator deploy script tweaks --- script/deploy-gas-calculator.s.sol | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/script/deploy-gas-calculator.s.sol b/script/deploy-gas-calculator.s.sol index 8c52a0e71..f2fcd58e8 100644 --- a/script/deploy-gas-calculator.s.sol +++ b/script/deploy-gas-calculator.s.sol @@ -7,16 +7,25 @@ import { DeployBaseScript } from "script/base/deploy-base.s.sol"; import { BaseGasCalculator } from "src/contracts/gasCalculator/BaseGasCalculator.sol"; contract DeployGasCalculatorScript is DeployBaseScript { + // NOTE: Adjust the constructor parameters as needed here: + // - BASE_GAS_PRICE_ORACLE: The address of the gas price oracle contract + // - BASE_CALLDATA_LENGTH_OFFSET: The offset to be applied to the calldata length (can be negative or positive) + // ----------------------------------------------------------------------------------------------- + address constant BASE_GAS_PRICE_ORACLE = address(0x420000000000000000000000000000000000000F); + int256 constant BASE_CALLDATA_LENGTH_OFFSET = 0; // can be negative or positive + // ----------------------------------------------------------------------------------------------- + function run() external { console.log("\n=== DEPLOYING GasCalculator ===\n"); console.log("Deploying to chain: \t\t", _getDeployChain()); - uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); + uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); address deployer = vm.addr(deployerPrivateKey); + console.log("Deployer address: \t\t", deployer); + uint256 chainId = block.chainid; - string memory deploymentName; address deploymentAddr; vm.startBroadcast(deployerPrivateKey); @@ -24,10 +33,9 @@ contract DeployGasCalculatorScript is DeployBaseScript { if (chainId == 8453 || chainId == 84_532) { // Base or Base Sepolia BaseGasCalculator gasCalculator = new BaseGasCalculator({ - _gasPriceOracle: address(0), // Insert gas price oracle address here - _calldataLengthOffset: 0 // Insert calldata length offset here (can be negative) - }); - deploymentName = "BASE_GAS_CALCULATOR"; + _gasPriceOracle: BASE_GAS_PRICE_ORACLE, + _calldataLengthOffset: BASE_CALLDATA_LENGTH_OFFSET + }); deploymentAddr = address(gasCalculator); } else { revert("Error: Chain ID not supported"); @@ -35,11 +43,14 @@ contract DeployGasCalculatorScript is DeployBaseScript { vm.stopBroadcast(); - _writeAddressToDeploymentsJson(deploymentName, deploymentAddr); + _writeAddressToDeploymentsJson("L2_GAS_CALCULATOR", deploymentAddr); console.log("\n"); - console.log("Deployed contract: ", deploymentName); - console.log("Deployed at address: ", deploymentAddr); + console.log("-------------------------------------------------------------------------------"); + console.log("| Contract | Address |"); + console.log("-------------------------------------------------------------------------------"); + console.log("| L2_GAS_CALCULATOR (Base) | ", address(deploymentAddr), " |"); + console.log("-------------------------------------------------------------------------------"); console.log("\n"); console.log("You can find a list of contract addresses from the latest deployment in deployments.json"); } From 20ac0afeba981f926dd02b444eafc94fe13a6831 Mon Sep 17 00:00:00 2001 From: jj1980a <40311124+jj1980a@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:47:18 +0400 Subject: [PATCH 18/70] Apply suggestions from code review Co-authored-by: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> --- .../gasCalculator/BaseGasCalculator.sol | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index a0dfc09ef..b1217ec27 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -15,16 +15,17 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { uint256 internal constant _CALLDATA_LENGTH_PREMIUM = 32; uint256 internal constant _BASE_TRANSACTION_GAS_USED = 21_000; - address public immutable gasPriceOracle; + address public immutable GAS_PRICE_ORACLE; int256 public calldataLengthOffset; - constructor(address _gasPriceOracle, int256 _calldataLengthOffset) Ownable(msg.sender) { - gasPriceOracle = _gasPriceOracle; - calldataLengthOffset = _calldataLengthOffset; + constructor(address gasPriceOracle, int256 calldataLenOffset) Ownable(msg.sender) { + GAS_PRICE_ORACLE = gasPriceOracle; + calldataLengthOffset = calldataLenOffset; } /// @notice Calculate the cost of calldata in ETH on a L2 with a different fee structure than mainnet /// @param calldataLength The length of the calldata in bytes + /// @return calldataCost The cost of the calldata in ETH function getCalldataCost(uint256 calldataLength) external view override returns (uint256 calldataCost) { // `getL1FeeUpperBound` returns the upper bound of the L1 fee in wei. It expects an unsigned transaction size in // bytes, *not calldata length only*, which makes this function a rough estimate. @@ -41,12 +42,14 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { calldataLength -= 68; } - if (calldataLengthOffset < 0 && calldataLength < uint256(-calldataLengthOffset)) { + int256 _calldataLenOffset = calldataLengthOffset; + + if (_calldataLenOffset < 0 && calldataLength < uint256(-_calldataLenOffset)) { return calldataCost; } - calldataLength += uint256(calldataLengthOffset); - calldataCost += IGasPriceOracle(gasPriceOracle).getL1FeeUpperBound(calldataLength); + calldataLength += uint256(_calldataLenOffset); + calldataCost += IGasPriceOracle(GAS_PRICE_ORACLE).getL1FeeUpperBound(calldataLength); } /// @notice Gets the cost of initial gas used for a transaction with a different calldata fee than mainnet @@ -57,7 +60,7 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { /// @notice Sets the calldata length offset /// @param _calldataLengthOffset The new calldata length offset - function setCalldataLengthOffset(int256 _calldataLengthOffset) external onlyOwner { - calldataLengthOffset = _calldataLengthOffset; + function setCalldataLengthOffset(int256 calldataLenOffset) external onlyOwner { + calldataLengthOffset = calldataLenOffset; } } From 04493e7f57844924632a2dcd64b554f1935e726f Mon Sep 17 00:00:00 2001 From: jj1980a Date: Fri, 13 Sep 2024 13:48:58 +0400 Subject: [PATCH 19/70] forge fmt --- src/contracts/gasCalculator/BaseGasCalculator.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index b1217ec27..d572b8e19 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -43,7 +43,7 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { } int256 _calldataLenOffset = calldataLengthOffset; - + if (_calldataLenOffset < 0 && calldataLength < uint256(-_calldataLenOffset)) { return calldataCost; } @@ -59,7 +59,7 @@ contract BaseGasCalculator is IL2GasCalculator, Ownable { } /// @notice Sets the calldata length offset - /// @param _calldataLengthOffset The new calldata length offset + /// @param calldataLenOffset The new calldata length offset function setCalldataLengthOffset(int256 calldataLenOffset) external onlyOwner { calldataLengthOffset = calldataLenOffset; } From bc6f32a98e551921c0e86a6ba251531fc9c31e04 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Fri, 13 Sep 2024 13:50:46 +0400 Subject: [PATCH 20/70] fix deploy script --- script/deploy-gas-calculator.s.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/deploy-gas-calculator.s.sol b/script/deploy-gas-calculator.s.sol index f2fcd58e8..3866bbaf1 100644 --- a/script/deploy-gas-calculator.s.sol +++ b/script/deploy-gas-calculator.s.sol @@ -33,8 +33,8 @@ contract DeployGasCalculatorScript is DeployBaseScript { if (chainId == 8453 || chainId == 84_532) { // Base or Base Sepolia BaseGasCalculator gasCalculator = new BaseGasCalculator({ - _gasPriceOracle: BASE_GAS_PRICE_ORACLE, - _calldataLengthOffset: BASE_CALLDATA_LENGTH_OFFSET + gasPriceOracle: BASE_GAS_PRICE_ORACLE, + calldataLenOffset: BASE_CALLDATA_LENGTH_OFFSET }); deploymentAddr = address(gasCalculator); } else { From 547588bb539130e0ea957af013fbedfd569ccc10 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:33:39 +0200 Subject: [PATCH 21/70] feat: add easier way to control hook failure for tests --- test/base/DummyDAppControl.sol | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index e74653c17..e7ce04018 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -14,6 +14,13 @@ library CallConfigBuilder { } contract DummyDAppControl is DAppControl { + bool public preOpsShouldRevert; + bool public userOpShouldRevert; + bool public preSolverShouldRevert; + bool public postSolverShouldRevert; + bool public allocateValueShouldRevert; + bool public postOpsShouldRevert; + event MEVPaymentSuccess(address bidToken, uint256 bidAmount); constructor( @@ -78,7 +85,7 @@ contract DummyDAppControl is DAppControl { return; } - (bool shouldRevert) = abi.decode(data, (bool)); + bool shouldRevert = DummyDAppControl(CONTROL).allocateValueShouldRevert(); require(!shouldRevert, "_allocateValueCall revert requested"); emit MEVPaymentSuccess(bidToken, winningAmount); } @@ -97,4 +104,30 @@ contract DummyDAppControl is DAppControl { require(!shouldRevert, "userOperationCall revert requested"); return returnValue; } + + // Revert settings + + function setPreOpsShouldRevert(bool _preOpsShouldRevert) public { + preOpsShouldRevert = _preOpsShouldRevert; + } + + function setUserOpShouldRevert(bool _userOpShouldRevert) public { + userOpShouldRevert = _userOpShouldRevert; + } + + function setPreSolverShouldRevert(bool _preSolverShouldRevert) public { + preSolverShouldRevert = _preSolverShouldRevert; + } + + function setPostSolverShouldRevert(bool _postSolverShouldRevert) public { + postSolverShouldRevert = _postSolverShouldRevert; + } + + function setAllocateValueShouldRevert(bool _allocateValueShouldRevert) public { + allocateValueShouldRevert = _allocateValueShouldRevert; + } + + function setPostOpsShouldRevert(bool _postOpsShouldRevert) public { + postOpsShouldRevert = _postOpsShouldRevert; + } } From 5605e76b96c8da75b69d635b980343d8735410ed Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:34:18 +0200 Subject: [PATCH 22/70] test: add `forwardReturnData` config tests --- src/contracts/solver/SolverBase.sol | 2 +- test/Escrow.t.sol | 92 +++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/contracts/solver/SolverBase.sol b/src/contracts/solver/SolverBase.sol index 88cccac67..0ef23806a 100644 --- a/src/contracts/solver/SolverBase.sol +++ b/src/contracts/solver/SolverBase.sol @@ -42,7 +42,7 @@ contract SolverBase is ISolverContract { address bidToken, uint256 bidAmount, bytes calldata solverOpData, - bytes calldata + bytes calldata forwardedData ) external payable diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index e789f0196..705144068 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -191,6 +191,9 @@ contract EscrowTest is BaseTest { .withAllowAllocateValueFailure(false) // Do not allow the value allocation to fail .build() ); + + dAppControl.setAllocateValueShouldRevert(true); + executeHookCase(false, 1, AtlasErrors.AllocateValueFail.selector); } @@ -463,11 +466,6 @@ contract EscrowTest is BaseTest { .withBidAmount(bidAmount) .signAndBuild(address(atlasVerification), solverOnePK); - console.log("DApp control balance", address(gasSponsorControl).balance); - console.log("Solver balance", address(dummySolver).balance); - console.log("Bid amount (to trigger partial)", bidAmount); - console.log("Solver bonded amt", atlas.balanceOfBonded(solverOneEOA)); - uint256 expectedResult = 0; // Success expected executeSolverOperationCase(userOp, solverOps, true, true, expectedResult, false); } @@ -479,7 +477,6 @@ contract EscrowTest is BaseTest { uint256 solverOpValue = address(atlas).balance; assertTrue(solverOpValue > 0, "solverOpValue must be greater than 0"); - deal(address(solver), 10e18); // plenty of ETH to repay what solver owes (UserOperation memory userOp, SolverOperation[] memory solverOps) = executeSolverOperationInit(defaultCallConfig().build()); @@ -495,6 +492,67 @@ contract EscrowTest is BaseTest { assertTrue(success, "metacall should have succeeded"); } + function test_executeSolverOperation_ForwardReturnData_True() public { + // Checks that the solver CAN receive the data returned from the userOp phase + uint256 expectedDataValue = 123; + DummySolverContributor solver = new DummySolverContributor(address(atlas)); + assertEq(solver.forwardedData().length, 0, "solver forwardedData should start empty"); + deal(address(solver), 1 ether); // 1 ETH covers default bid (1) + 0.5 ETH gas cost + + (UserOperation memory userOp, SolverOperation[] memory solverOps) = executeSolverOperationInit( + defaultCallConfig() + .withTrackUserReturnData(true) + .withForwardReturnData(true) + .withRequireFulfillment(true) + .build() + ); + + userOp = validUserOperation(address(dAppControl)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, expectedDataValue)) + .signAndBuild(address(atlasVerification), userPK); + + solverOps[0] = validSolverOperation(userOp) + .withSolver(address(solver)) + .withBidAmount(defaultBidAmount) + .signAndBuild(address(atlasVerification), solverOnePK); + + uint256 result = 0; // Success + executeSolverOperationCase(userOp, solverOps, true, true, result, false); + + uint256 forwardedData = abi.decode(solver.forwardedData(), (uint256)); + assertEq(forwardedData, expectedDataValue, "solver should have received the userOp data"); + } + + function test_executeSolverOperation_ForwardReturnData_False() public { + // Checks that the solver CANNOT receive the data returned from the userOp phase + uint256 dataValue = 123; + DummySolverContributor solver = new DummySolverContributor(address(atlas)); + assertEq(solver.forwardedData().length, 0, "solver forwardedData should start empty"); + deal(address(solver), 1 ether); // 1 ETH covers default bid (1) + 0.5 ETH gas cost + + (UserOperation memory userOp, SolverOperation[] memory solverOps) = executeSolverOperationInit( + defaultCallConfig() + .withTrackUserReturnData(true) + .withForwardReturnData(false) + .withRequireFulfillment(true) + .build() + ); + + userOp = validUserOperation(address(dAppControl)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, dataValue)) + .signAndBuild(address(atlasVerification), userPK); + + solverOps[0] = validSolverOperation(userOp) + .withSolver(address(solver)) + .withBidAmount(defaultBidAmount) + .signAndBuild(address(atlasVerification), solverOnePK); + + uint256 result = 0; // Success + executeSolverOperationCase(userOp, solverOps, true, true, result, false); + assertEq(solver.forwardedData().length, 0, "solver forwardedData should still be empty"); + } + + function test_executeSolverOperation_solverOpWrapper_defaultCase() public { // Can't find a way to reach the default case (which is a good thing) vm.skip(true); @@ -547,7 +605,7 @@ contract DummySolver { } function atlasSolverCall( - address solverOpFrom, + address /* solverOpFrom */, address executionEnvironment, address, uint256 bidAmount, @@ -567,7 +625,6 @@ contract DummySolver { if (address(this).balance >= bidAmount) { SafeTransferLib.safeTransferETH(executionEnvironment, bidAmount); } - if (bidAmount == noGasPayBack) { // Don't pay gas @@ -575,10 +632,6 @@ contract DummySolver { } else if (bidAmount == partialGasPayBack) { // Only pay half of shortfall owed - expect postSolverCall hook in DAppControl to pay the rest uint256 _shortfall = IAtlas(_atlas).shortfall(); - - console.log("Solver shortfall", _shortfall); - console.log("gas price", tx.gasprice); - IAtlas(_atlas).reconcile(_shortfall / 2); return; } @@ -591,31 +644,34 @@ contract DummySolver { } contract DummySolverContributor { - address private _atlas; + address private immutable ATLAS; + bytes public forwardedData; constructor(address atlas) { - _atlas = atlas; + ATLAS = atlas; } function atlasSolverCall( - address solverOpFrom, + address /* solverOpFrom */, address executionEnvironment, address, uint256 bidAmount, bytes calldata, - bytes calldata + bytes calldata userReturnData ) external payable { + if (userReturnData.length > 0) forwardedData = userReturnData; + // Pay bid if (address(this).balance >= bidAmount) { SafeTransferLib.safeTransferETH(executionEnvironment, bidAmount); } // Pay borrowed ETH + gas used - uint256 shortfall = IAtlas(_atlas).shortfall(); - IAtlas(_atlas).reconcile{value: shortfall}(0); + uint256 shortfall = IAtlas(ATLAS).shortfall(); + IAtlas(ATLAS).reconcile{value: shortfall}(0); return; } From 4aa76469b8aa3c99f61f0f0c75308492660090d6 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:10:00 +0200 Subject: [PATCH 23/70] test: use hookShouldRevert pattern in `Escrow.t.sol` --- test/Escrow.t.sol | 36 ++++++++++++++---------- test/base/DummyDAppControl.sol | 50 ++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index 705144068..d6035cced 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -143,7 +143,7 @@ contract EscrowTest is BaseTest { .withAllowAllocateValueFailure(true) // Allow the value allocation to fail .build() ); - executeHookCase(false, block.timestamp * 2, noError); + executeHookCase(block.timestamp * 2, noError); } // Ensure metacall reverts with the proper error when the preOps hook reverts. @@ -154,7 +154,8 @@ contract EscrowTest is BaseTest { .withReuseUserOp(true) // Allow metacall to revert .build() ); - executeHookCase(true, 0, AtlasErrors.PreOpsFail.selector); + dAppControl.setPreOpsShouldRevert(true); + executeHookCase(0, AtlasErrors.PreOpsFail.selector); } // Ensure the user operation executes successfully. To ensure the operation's returned data is as expected, we @@ -168,7 +169,7 @@ contract EscrowTest is BaseTest { .withAllowAllocateValueFailure(true) // Allow the value allocation to fail .build() ); - executeHookCase(false, block.timestamp * 3, noError); + executeHookCase(block.timestamp * 3, noError); } // Ensure metacall reverts with the proper error when the user operation reverts. @@ -178,7 +179,8 @@ contract EscrowTest is BaseTest { .withReuseUserOp(true) // Allow metacall to revert .build() ); - executeHookCase(true, 0, AtlasErrors.UserOpFail.selector); + dAppControl.setUserOpShouldRevert(true); + executeHookCase(0, AtlasErrors.UserOpFail.selector); } // Ensure metacall reverts with the proper error when the allocateValue hook reverts. @@ -194,7 +196,7 @@ contract EscrowTest is BaseTest { dAppControl.setAllocateValueShouldRevert(true); - executeHookCase(false, 1, AtlasErrors.AllocateValueFail.selector); + executeHookCase(1, AtlasErrors.AllocateValueFail.selector); } // Ensure the postOps hook is successfully called. No return data is expected from the postOps hook, so we do not @@ -205,7 +207,7 @@ contract EscrowTest is BaseTest { .withRequirePostOps(true) // Execute the postOps hook .build() ); - executeHookCase(false, 0, noError); + executeHookCase(0, noError); } // Ensure metacall reverts with the proper error when the postOps hook reverts. @@ -219,7 +221,8 @@ contract EscrowTest is BaseTest { .withAllowAllocateValueFailure(true) // Allow the value allocation to fail .build() ); - executeHookCase(false, 1, AtlasErrors.PostOpsFail.selector); + dAppControl.setPostOpsShouldRevert(true); + executeHookCase(1, AtlasErrors.PostOpsFail.selector); } // Ensure the allocateValue hook is successfully called. No return data is expected from the allocateValue hook, so @@ -237,17 +240,16 @@ contract EscrowTest is BaseTest { vm.expectEmit(false, false, false, true, executionEnvironment); emit MEVPaymentSuccess(address(0), defaultBidAmount); - this.executeHookCase(false, 0, noError); + this.executeHookCase(0, noError); } - function executeHookCase(bool hookShouldRevert, uint256 expectedHookReturnValue, bytes4 expectedError) public { + function executeHookCase(uint256 expectedHookReturnValue, bytes4 expectedError) public { bool revertExpected = expectedError != noError; UserOperation memory userOp = validUserOperation(address(dAppControl)) .withData( abi.encodeWithSelector( dAppControl.userOperationCall.selector, - hookShouldRevert, expectedHookReturnValue ) ) @@ -385,7 +387,7 @@ contract EscrowTest is BaseTest { ); UserOperation memory userOp = validUserOperation(address(dAppControl)) - .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, 1)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, 1)) .signAndBuild(address(atlasVerification), userPK); SolverOperation[] memory solverOps = new SolverOperation[](1); @@ -394,6 +396,8 @@ contract EscrowTest is BaseTest { .signAndBuild(address(atlasVerification), solverOnePK); uint256 result = (1 << uint256(SolverOutcome.PreSolverFailed)); + dAppControl.setPreSolverShouldRevert(true); + executeSolverOperationCase(userOp, solverOps, false, false, result, true); } @@ -409,7 +413,7 @@ contract EscrowTest is BaseTest { ); UserOperation memory userOp = validUserOperation(address(dAppControl)) - .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, 1)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, 1)) .signAndBuild(address(atlasVerification), userPK); SolverOperation[] memory solverOps = new SolverOperation[](1); @@ -418,6 +422,8 @@ contract EscrowTest is BaseTest { .signAndBuild(address(atlasVerification), solverOnePK); uint256 result = (1 << uint256(SolverOutcome.PostSolverFailed)); + dAppControl.setPostSolverShouldRevert(true); + executeSolverOperationCase(userOp, solverOps, true, false, result, true); } @@ -508,7 +514,7 @@ contract EscrowTest is BaseTest { ); userOp = validUserOperation(address(dAppControl)) - .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, expectedDataValue)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, expectedDataValue)) .signAndBuild(address(atlasVerification), userPK); solverOps[0] = validSolverOperation(userOp) @@ -539,7 +545,7 @@ contract EscrowTest is BaseTest { ); userOp = validUserOperation(address(dAppControl)) - .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, dataValue)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, dataValue)) .signAndBuild(address(atlasVerification), userPK); solverOps[0] = validSolverOperation(userOp) @@ -565,7 +571,7 @@ contract EscrowTest is BaseTest { defaultAtlasWithCallConfig(callConfig); userOp = validUserOperation(address(dAppControl)) - .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, false, 0)) + .withData(abi.encodeWithSelector(dAppControl.userOperationCall.selector, 0)) .signAndBuild(address(atlasVerification), userPK); solverOps = new SolverOperation[](1); diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index e7ce04018..34341e813 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -21,6 +21,8 @@ contract DummyDAppControl is DAppControl { bool public allocateValueShouldRevert; bool public postOpsShouldRevert; + // TODO add storage vars to store input data for each hook, then test hooks were passed the correct data + event MEVPaymentSuccess(address bidToken, uint256 bidAmount); constructor( @@ -38,38 +40,49 @@ contract DummyDAppControl is DAppControl { function _checkUserOperation(UserOperation memory) internal pure virtual override { } function _preOpsCall(UserOperation calldata userOp) internal virtual override returns (bytes memory) { - if (userOp.data.length == 0) { - return new bytes(0); - } + bool shouldRevert = DummyDAppControl(CONTROL).preOpsShouldRevert(); + require(!shouldRevert, "_preOpsCall revert requested"); - (bool success, bytes memory data) = address(userOp.dapp).call(userOp.data); - require(success, "_preOpsCall reverted"); + if (userOp.data.length == 0) return new bytes(0); + + (, bytes memory data) = address(userOp.dapp).call(userOp.data); return data; } - function _postOpsCall(bool, bytes calldata data) internal pure virtual override { + function _postOpsCall(bool, bytes calldata data) internal view virtual override { + bool shouldRevert = DummyDAppControl(CONTROL).postOpsShouldRevert(); + require(!shouldRevert, "_postOpsCall revert requested"); if (data.length == 0) return; - (bool shouldRevert) = abi.decode(data, (bool)); - require(!shouldRevert, "_postOpsCall revert requested"); + // TODO store input data and check it was passed correctly in Escrow.t.sol + // (bool shouldRevert) = abi.decode(data, (bool)); + // require(!shouldRevert, "_postOpsCall revert requested"); } function _preSolverCall(SolverOperation calldata, bytes calldata returnData) internal view virtual override { + bool shouldRevert = DummyDAppControl(CONTROL).preSolverShouldRevert(); + require(!shouldRevert, "_preSolverCall revert requested"); + if (returnData.length == 0) { return; } - (bool shouldRevert) = abi.decode(returnData, (bool)); - require(!shouldRevert, "_preSolverCall revert requested"); + // TODO store input data and check it was passed correctly in Escrow.t.sol + // (bool shouldRevert) = abi.decode(returnData, (bool)); + // require(!shouldRevert, "_preSolverCall revert requested"); } - function _postSolverCall(SolverOperation calldata, bytes calldata returnData) internal pure virtual override { + function _postSolverCall(SolverOperation calldata, bytes calldata returnData) internal view virtual override { + bool shouldRevert = DummyDAppControl(CONTROL).postSolverShouldRevert(); + require(!shouldRevert, "_postSolverCall revert requested"); + if (returnData.length == 0) { return; } - (bool shouldRevert) = abi.decode(returnData, (bool)); - require(!shouldRevert, "_postSolverCall revert requested"); + // TODO store input data and check it was passed correctly in Escrow.t.sol + // (bool shouldRevert) = abi.decode(returnData, (bool)); + // require(!shouldRevert, "_postSolverCall revert requested"); } function _allocateValueCall( @@ -81,12 +94,10 @@ contract DummyDAppControl is DAppControl { virtual override { - if (data.length == 0) { - return; - } - bool shouldRevert = DummyDAppControl(CONTROL).allocateValueShouldRevert(); require(!shouldRevert, "_allocateValueCall revert requested"); + + // TODO store input data and check it was passed correctly in Escrow.t.sol emit MEVPaymentSuccess(bidToken, winningAmount); } @@ -100,8 +111,11 @@ contract DummyDAppControl is DAppControl { // Custom functions // **************************************** - function userOperationCall(bool shouldRevert, uint256 returnValue) public pure returns (uint256) { + function userOperationCall(uint256 returnValue) public view returns (uint256) { + bool shouldRevert = DummyDAppControl(CONTROL).userOpShouldRevert(); require(!shouldRevert, "userOperationCall revert requested"); + + // TODO store input data and check it was passed correctly in Escrow.t.sol return returnValue; } From 61093483f841104bcd768abc4944af466e62b910 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:46:00 +0200 Subject: [PATCH 24/70] chore: rel import paths in DAppControl and parents --- src/contracts/common/ExecutionBase.sol | 10 +++++----- src/contracts/dapp/ControlTemplate.sol | 8 ++++---- src/contracts/dapp/DAppControl.sol | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/contracts/common/ExecutionBase.sol b/src/contracts/common/ExecutionBase.sol index 9a27878af..eb5b34c46 100644 --- a/src/contracts/common/ExecutionBase.sol +++ b/src/contracts/common/ExecutionBase.sol @@ -3,12 +3,12 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; -import { ExecutionPhase } from "src/contracts/types/LockTypes.sol"; -import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "src/contracts/libraries/SafetyBits.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import "src/contracts/types/SolverOperation.sol"; +import { ExecutionPhase } from "../types/LockTypes.sol"; +import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "../libraries/SafetyBits.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import "../types/SolverOperation.sol"; contract Base { address public immutable ATLAS; diff --git a/src/contracts/dapp/ControlTemplate.sol b/src/contracts/dapp/ControlTemplate.sol index df402abcf..b510f7f1d 100644 --- a/src/contracts/dapp/ControlTemplate.sol +++ b/src/contracts/dapp/ControlTemplate.sol @@ -1,10 +1,10 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; abstract contract DAppControlTemplate { uint32 internal constant DEFAULT_SOLVER_GAS_LIMIT = 1_000_000; diff --git a/src/contracts/dapp/DAppControl.sol b/src/contracts/dapp/DAppControl.sol index 6cf5fa25d..03c4d977e 100644 --- a/src/contracts/dapp/DAppControl.sol +++ b/src/contracts/dapp/DAppControl.sol @@ -2,17 +2,17 @@ pragma solidity 0.8.25; import { DAppControlTemplate } from "./ControlTemplate.sol"; -import { ExecutionBase } from "src/contracts/common/ExecutionBase.sol"; -import { ExecutionPhase } from "src/contracts/types/LockTypes.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ValidCallsResult } from "src/contracts/types/ValidCalls.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; +import { ExecutionBase } from "../common/ExecutionBase.sol"; +import { ExecutionPhase } from "../types/LockTypes.sol"; +import { CallBits } from "../libraries/CallBits.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { AtlasEvents } from "../types/AtlasEvents.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { ValidCallsResult } from "../types/ValidCalls.sol"; +import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol"; /// @title DAppControl /// @author FastLane Labs From 39394d98e30e7bb78f8215551477b9a62d2ae778 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:42:42 +0200 Subject: [PATCH 25/70] chore: switch to relative imports --- src/contracts/atlas/AtlETH.sol | 4 +-- src/contracts/atlas/Atlas.sol | 22 ++++++------- src/contracts/atlas/AtlasVerification.sol | 26 +++++++-------- src/contracts/atlas/DAppIntegration.sol | 10 +++--- src/contracts/atlas/Escrow.sol | 32 +++++++++---------- src/contracts/atlas/Factory.sol | 12 +++---- src/contracts/atlas/GasAccounting.sol | 17 +++++----- src/contracts/atlas/NonceManager.sol | 2 +- src/contracts/atlas/Permit69.sol | 9 +++--- src/contracts/atlas/SafetyLocks.sol | 12 +++---- src/contracts/atlas/Storage.sol | 16 +++++----- src/contracts/common/ExecutionBase.sol | 1 + src/contracts/common/ExecutionEnvironment.sol | 18 +++++------ src/contracts/helpers/GovernanceBurner.sol | 2 +- src/contracts/helpers/Simulator.sol | 23 ++++++------- src/contracts/helpers/Sorter.sol | 24 +++++++------- src/contracts/helpers/TxBuilder.sol | 18 +++++------ src/contracts/interfaces/IAtlas.sol | 8 ++--- .../interfaces/IAtlasVerification.sol | 12 +++---- src/contracts/interfaces/IDAppControl.sol | 6 ++-- .../interfaces/IExecutionEnvironment.sol | 8 ++--- src/contracts/interfaces/ISimulator.sol | 8 ++--- src/contracts/interfaces/ISolverContract.sol | 2 +- src/contracts/libraries/CallBits.sol | 4 +-- src/contracts/libraries/CallVerification.sol | 8 ++--- src/contracts/libraries/EscrowBits.sol | 2 +- src/contracts/libraries/SafetyBits.sol | 2 +- src/contracts/solver/SolverBase.sol | 6 ++-- src/contracts/solver/SolverBaseInvertBid.sol | 6 ++-- src/contracts/solver/src/TestSolver.sol | 2 +- src/contracts/solver/src/TestSolverExPost.sol | 2 +- src/contracts/types/AtlasConstants.sol | 2 +- src/contracts/types/AtlasErrors.sol | 2 +- 33 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/contracts/atlas/AtlETH.sol b/src/contracts/atlas/AtlETH.sol index e39120fb4..4e9cb21d2 100644 --- a/src/contracts/atlas/AtlETH.sol +++ b/src/contracts/atlas/AtlETH.sol @@ -3,8 +3,8 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { SafeCast } from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol"; -import { Permit69 } from "src/contracts/atlas/Permit69.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import { Permit69 } from "./Permit69.sol"; +import "../types/EscrowTypes.sol"; /// @author FastLane Labs /// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it. diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index c17d08258..27a5cae75 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -7,17 +7,17 @@ import { LibSort } from "solady/utils/LibSort.sol"; import { Escrow } from "./Escrow.sol"; import { Factory } from "./Factory.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/ValidCalls.sol"; - -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; -import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/LockTypes.sol"; +import "../types/ConfigTypes.sol"; +import "../types/DAppOperation.sol"; +import "../types/ValidCalls.sol"; + +import { CallBits } from "../libraries/CallBits.sol"; +import { SafetyBits } from "../libraries/SafetyBits.sol"; +import { IL2GasCalculator } from "../interfaces/IL2GasCalculator.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; /// @title Atlas V1 /// @author FastLane Labs diff --git a/src/contracts/atlas/AtlasVerification.sol b/src/contracts/atlas/AtlasVerification.sol index 0d7e3ae0f..9c1b7d5cc 100644 --- a/src/contracts/atlas/AtlasVerification.sol +++ b/src/contracts/atlas/AtlasVerification.sol @@ -4,19 +4,19 @@ pragma solidity 0.8.25; import { EIP712 } from "openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol"; import { ECDSA } from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; import { SignatureChecker } from "openzeppelin-contracts/contracts/utils/cryptography/SignatureChecker.sol"; -import { DAppIntegration } from "src/contracts/atlas/DAppIntegration.sol"; -import { NonceManager } from "src/contracts/atlas/NonceManager.sol"; - -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasConstants } from "src/contracts/types/AtlasConstants.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/ValidCalls.sol"; +import { DAppIntegration } from "./DAppIntegration.sol"; +import { NonceManager } from "./NonceManager.sol"; + +import { CallBits } from "../libraries/CallBits.sol"; +import { CallVerification } from "../libraries/CallVerification.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { AtlasConstants } from "../types/AtlasConstants.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/DAppOperation.sol"; +import "../types/EscrowTypes.sol"; +import "../types/ValidCalls.sol"; /// @title AtlasVerification /// @author FastLane Labs diff --git a/src/contracts/atlas/DAppIntegration.sol b/src/contracts/atlas/DAppIntegration.sol index 4542c0a3d..1ffc0c8e5 100644 --- a/src/contracts/atlas/DAppIntegration.sol +++ b/src/contracts/atlas/DAppIntegration.sol @@ -1,11 +1,11 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { CallBits } from "../libraries/CallBits.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { AtlasEvents } from "../types/AtlasEvents.sol"; /// @title DAppIntegration /// @author FastLane Labs diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 47ce9a5ec..4e3aac68e 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -2,22 +2,22 @@ pragma solidity 0.8.25; import { AtlETH } from "./AtlETH.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISolverContract } from "src/contracts/interfaces/ISolverContract.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; - -import { SafeCall } from "src/contracts/libraries/SafeCall/SafeCall.sol"; -import { EscrowBits } from "src/contracts/libraries/EscrowBits.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; -import { AccountingMath } from "src/contracts/libraries/AccountingMath.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; +import { IExecutionEnvironment } from "../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { ISolverContract } from "../interfaces/ISolverContract.sol"; +import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; + +import { SafeCall } from "../libraries/SafeCall/SafeCall.sol"; +import { EscrowBits } from "../libraries/EscrowBits.sol"; +import { CallBits } from "../libraries/CallBits.sol"; +import { SafetyBits } from "../libraries/SafetyBits.sol"; +import { AccountingMath } from "../libraries/AccountingMath.sol"; +import { DAppConfig } from "../types/ConfigTypes.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/EscrowTypes.sol"; +import "../types/LockTypes.sol"; /// @title Escrow /// @author FastLane Labs diff --git a/src/contracts/atlas/Factory.sol b/src/contracts/atlas/Factory.sol index 76c819c76..57a5fcd2c 100644 --- a/src/contracts/atlas/Factory.sol +++ b/src/contracts/atlas/Factory.sol @@ -1,12 +1,12 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { Mimic } from "src/contracts/common/Mimic.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; +import { Mimic } from "../common/Mimic.sol"; +import { DAppConfig } from "../types/ConfigTypes.sol"; +import { UserOperation } from "../types/UserOperation.sol"; +import { AtlasEvents } from "../types/AtlasEvents.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; /// @title Factory /// @author FastLane Labs diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 63f9cdd48..c6671d499 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -3,14 +3,15 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { SafeCast } from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol"; -import { SafetyLocks } from "src/contracts/atlas/SafetyLocks.sol"; -import { EscrowBits } from "src/contracts/libraries/EscrowBits.sol"; -import { AccountingMath } from "src/contracts/libraries/AccountingMath.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; + +import { SafetyLocks } from "./SafetyLocks.sol"; +import { EscrowBits } from "../libraries/EscrowBits.sol"; +import { AccountingMath } from "../libraries/AccountingMath.sol"; +import { SolverOperation } from "../types/SolverOperation.sol"; +import { DAppConfig } from "../types/ConfigTypes.sol"; +import { IL2GasCalculator } from "../interfaces/IL2GasCalculator.sol"; +import "../types/EscrowTypes.sol"; +import "../types/LockTypes.sol"; /// @title GasAccounting /// @author FastLane Labs diff --git a/src/contracts/atlas/NonceManager.sol b/src/contracts/atlas/NonceManager.sol index c4cb745ba..19fa27956 100644 --- a/src/contracts/atlas/NonceManager.sol +++ b/src/contracts/atlas/NonceManager.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { AtlasConstants } from "src/contracts/types/AtlasConstants.sol"; +import { AtlasConstants } from "../types/AtlasConstants.sol"; contract NonceManager is AtlasConstants { // address => last used sequential nonce diff --git a/src/contracts/atlas/Permit69.sol b/src/contracts/atlas/Permit69.sol index 6d6f7d0ba..31e2a4c66 100644 --- a/src/contracts/atlas/Permit69.sol +++ b/src/contracts/atlas/Permit69.sol @@ -3,11 +3,12 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { GasAccounting } from "src/contracts/atlas/GasAccounting.sol"; -import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "src/contracts/libraries/SafetyBits.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import { GasAccounting } from "./GasAccounting.sol"; + +import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "../libraries/SafetyBits.sol"; +import "../types/LockTypes.sol"; +import "../types/EscrowTypes.sol"; // NOTE: Permit69 only works inside of the Atlas environment - specifically // inside of the custom ExecutionEnvironments that each user deploys when diff --git a/src/contracts/atlas/SafetyLocks.sol b/src/contracts/atlas/SafetyLocks.sol index 2b3d66b92..380ea749f 100644 --- a/src/contracts/atlas/SafetyLocks.sol +++ b/src/contracts/atlas/SafetyLocks.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.25; import { Storage } from "./Storage.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallBits } from "../libraries/CallBits.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/EscrowTypes.sol"; +import "../types/LockTypes.sol"; /// @title SafetyLocks /// @author FastLane Labs diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 4a20052b1..7d3e78b10 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -1,14 +1,14 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/libraries/AccountingMath.sol"; - -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasConstants } from "src/contracts/types/AtlasConstants.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; +import "../types/EscrowTypes.sol"; +import "../types/LockTypes.sol"; +import "../libraries/AccountingMath.sol"; + +import { AtlasEvents } from "../types/AtlasEvents.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { AtlasConstants } from "../types/AtlasConstants.sol"; +import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol"; /// @title Storage /// @author FastLane Labs diff --git a/src/contracts/common/ExecutionBase.sol b/src/contracts/common/ExecutionBase.sol index eb5b34c46..4bdeddec1 100644 --- a/src/contracts/common/ExecutionBase.sol +++ b/src/contracts/common/ExecutionBase.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; + import { IAtlas } from "../interfaces/IAtlas.sol"; import { ExecutionPhase } from "../types/LockTypes.sol"; diff --git a/src/contracts/common/ExecutionEnvironment.sol b/src/contracts/common/ExecutionEnvironment.sol index b818e2c22..42945ad01 100644 --- a/src/contracts/common/ExecutionEnvironment.sol +++ b/src/contracts/common/ExecutionEnvironment.sol @@ -3,17 +3,17 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { Base } from "src/contracts/common/ExecutionBase.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISolverContract } from "src/contracts/interfaces/ISolverContract.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; +import { Base } from "./ExecutionBase.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { ISolverContract } from "../interfaces/ISolverContract.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { CallBits } from "../libraries/CallBits.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/EscrowTypes.sol"; /// @title ExecutionEnvironment /// @author FastLane Labs diff --git a/src/contracts/helpers/GovernanceBurner.sol b/src/contracts/helpers/GovernanceBurner.sol index e9914dd7d..fdad5a2f0 100644 --- a/src/contracts/helpers/GovernanceBurner.sol +++ b/src/contracts/helpers/GovernanceBurner.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; /// @title GovernanceBurner /// @author FastLane Labs diff --git a/src/contracts/helpers/Simulator.sol b/src/contracts/helpers/Simulator.sol index 34d9f3f33..2385b8477 100644 --- a/src/contracts/helpers/Simulator.sol +++ b/src/contracts/helpers/Simulator.sol @@ -1,21 +1,18 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; - -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; - import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/ValidCalls.sol"; -import "src/contracts/types/EscrowTypes.sol"; - -import { Result } from "src/contracts/interfaces/ISimulator.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/LockTypes.sol"; +import "../types/DAppOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/ValidCalls.sol"; +import "../types/EscrowTypes.sol"; +import { AtlasErrors } from "../types/AtlasErrors.sol"; +import { Result } from "../interfaces/ISimulator.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; contract Simulator is AtlasErrors { address public immutable deployer; diff --git a/src/contracts/helpers/Sorter.sol b/src/contracts/helpers/Sorter.sol index face331c4..b4a0fd924 100644 --- a/src/contracts/helpers/Sorter.sol +++ b/src/contracts/helpers/Sorter.sol @@ -1,18 +1,18 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; - -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { AccountingMath } from "src/contracts/libraries/AccountingMath.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; -import { AtlasConstants } from "src/contracts/types/AtlasConstants.sol"; - -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; +import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol"; + +import { CallBits } from "../libraries/CallBits.sol"; +import { AccountingMath } from "../libraries/AccountingMath.sol"; +import { CallVerification } from "../libraries/CallVerification.sol"; +import { AtlasConstants } from "../types/AtlasConstants.sol"; + +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; contract Sorter is AtlasConstants { using CallBits for uint32; diff --git a/src/contracts/helpers/TxBuilder.sol b/src/contracts/helpers/TxBuilder.sol index 3e70fdc2e..dea57c90b 100644 --- a/src/contracts/helpers/TxBuilder.sol +++ b/src/contracts/helpers/TxBuilder.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { IAtlasVerification } from "../interfaces/IAtlasVerification.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/DAppOperation.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; +import { CallVerification } from "../libraries/CallVerification.sol"; +import { CallBits } from "../libraries/CallBits.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/interfaces/IAtlas.sol b/src/contracts/interfaces/IAtlas.sol index 65a9a3ce2..b518a0016 100644 --- a/src/contracts/interfaces/IAtlas.sol +++ b/src/contracts/interfaces/IAtlas.sol @@ -1,10 +1,10 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/DAppOperation.sol"; +import "../types/LockTypes.sol"; interface IAtlas { // Atlas.sol diff --git a/src/contracts/interfaces/IAtlasVerification.sol b/src/contracts/interfaces/IAtlasVerification.sol index cdd1eef7a..ed4f050f5 100644 --- a/src/contracts/interfaces/IAtlasVerification.sol +++ b/src/contracts/interfaces/IAtlasVerification.sol @@ -1,12 +1,12 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/ValidCalls.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/DAppOperation.sol"; +import "../types/SolverOperation.sol"; +import "../types/EscrowTypes.sol"; +import "../types/ValidCalls.sol"; interface IAtlasVerification { // AtlasVerification.sol diff --git a/src/contracts/interfaces/IDAppControl.sol b/src/contracts/interfaces/IDAppControl.sol index 25f699e85..e3be1417f 100644 --- a/src/contracts/interfaces/IDAppControl.sol +++ b/src/contracts/interfaces/IDAppControl.sol @@ -1,9 +1,9 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../types/UserOperation.sol"; +import "../types/SolverOperation.sol"; +import "../types/ConfigTypes.sol"; interface IDAppControl { function preOpsCall(UserOperation calldata userOp) external payable returns (bytes memory); diff --git a/src/contracts/interfaces/IExecutionEnvironment.sol b/src/contracts/interfaces/IExecutionEnvironment.sol index 17d7ecb55..9dcdee96a 100644 --- a/src/contracts/interfaces/IExecutionEnvironment.sol +++ b/src/contracts/interfaces/IExecutionEnvironment.sol @@ -1,10 +1,10 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/EscrowTypes.sol"; interface IExecutionEnvironment { function preOpsWrapper(UserOperation calldata userOp) external returns (bytes memory preOpsData); diff --git a/src/contracts/interfaces/ISimulator.sol b/src/contracts/interfaces/ISimulator.sol index 8a92a2ce1..f1d3bb8ce 100644 --- a/src/contracts/interfaces/ISimulator.sol +++ b/src/contracts/interfaces/ISimulator.sol @@ -1,10 +1,10 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; +import "../types/DAppOperation.sol"; enum Result { Unknown, diff --git a/src/contracts/interfaces/ISolverContract.sol b/src/contracts/interfaces/ISolverContract.sol index 047a3f779..b055a0415 100644 --- a/src/contracts/interfaces/ISolverContract.sol +++ b/src/contracts/interfaces/ISolverContract.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; +import "../types/SolverOperation.sol"; interface ISolverContract { function atlasSolverCall( diff --git a/src/contracts/libraries/CallBits.sol b/src/contracts/libraries/CallBits.sol index 62b46a465..f5c1d0a6e 100644 --- a/src/contracts/libraries/CallBits.sol +++ b/src/contracts/libraries/CallBits.sol @@ -1,9 +1,9 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; +import { IDAppControl } from "../interfaces/IDAppControl.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../types/ConfigTypes.sol"; library CallBits { uint32 internal constant _ONE = uint32(1); diff --git a/src/contracts/libraries/CallVerification.sol b/src/contracts/libraries/CallVerification.sol index 6c41ee411..ba4f4829e 100644 --- a/src/contracts/libraries/CallVerification.sol +++ b/src/contracts/libraries/CallVerification.sol @@ -1,11 +1,11 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../types/SolverOperation.sol"; +import "../types/UserOperation.sol"; +import "../types/ConfigTypes.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; +import { CallBits } from "./CallBits.sol"; library CallVerification { using CallBits for uint32; diff --git a/src/contracts/libraries/EscrowBits.sol b/src/contracts/libraries/EscrowBits.sol index 392f7bb7b..d8c19356c 100644 --- a/src/contracts/libraries/EscrowBits.sol +++ b/src/contracts/libraries/EscrowBits.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/EscrowTypes.sol"; +import "../types/EscrowTypes.sol"; library EscrowBits { // Bundler's Fault - solver doesn't owe any gas refund. SolverOp isn't executed diff --git a/src/contracts/libraries/SafetyBits.sol b/src/contracts/libraries/SafetyBits.sol index ab8231701..c9fe77717 100644 --- a/src/contracts/libraries/SafetyBits.sol +++ b/src/contracts/libraries/SafetyBits.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/LockTypes.sol"; +import "../types/LockTypes.sol"; // NOTE: No user transfers allowed during AllocateValue uint8 constant SAFE_USER_TRANSFER = uint8( diff --git a/src/contracts/solver/SolverBase.sol b/src/contracts/solver/SolverBase.sol index 88cccac67..1311fd961 100644 --- a/src/contracts/solver/SolverBase.sol +++ b/src/contracts/solver/SolverBase.sol @@ -4,10 +4,10 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISolverContract } from "src/contracts/interfaces/ISolverContract.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { ISolverContract } from "../interfaces/ISolverContract.sol"; -import "src/contracts/types/SolverOperation.sol"; +import "../types/SolverOperation.sol"; interface IWETH9 { function deposit() external payable; diff --git a/src/contracts/solver/SolverBaseInvertBid.sol b/src/contracts/solver/SolverBaseInvertBid.sol index 3924665e0..328ffc169 100644 --- a/src/contracts/solver/SolverBaseInvertBid.sol +++ b/src/contracts/solver/SolverBaseInvertBid.sol @@ -4,10 +4,10 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISolverContract } from "src/contracts/interfaces/ISolverContract.sol"; +import { IAtlas } from "../interfaces/IAtlas.sol"; +import { ISolverContract } from "../interfaces/ISolverContract.sol"; -import "src/contracts/types/SolverOperation.sol"; +import "../types/SolverOperation.sol"; interface IWETH9 { function deposit() external payable; diff --git a/src/contracts/solver/src/TestSolver.sol b/src/contracts/solver/src/TestSolver.sol index 0e9a22475..445ac3bea 100644 --- a/src/contracts/solver/src/TestSolver.sol +++ b/src/contracts/solver/src/TestSolver.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../../solver/SolverBase.sol"; // Flashbots opensource repo import { BlindBackrun } from "./BlindBackrun/BlindBackrun.sol"; diff --git a/src/contracts/solver/src/TestSolverExPost.sol b/src/contracts/solver/src/TestSolverExPost.sol index 2bf3cd0eb..0cdf88cc5 100644 --- a/src/contracts/solver/src/TestSolverExPost.sol +++ b/src/contracts/solver/src/TestSolverExPost.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../../solver/SolverBase.sol"; // Flashbots opensource repo import { BlindBackrun } from "./BlindBackrun/BlindBackrun.sol"; diff --git a/src/contracts/types/AtlasConstants.sol b/src/contracts/types/AtlasConstants.sol index da2b78397..25fa70fb7 100644 --- a/src/contracts/types/AtlasConstants.sol +++ b/src/contracts/types/AtlasConstants.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/ValidCalls.sol"; +import "./ValidCalls.sol"; // NOTE: Internal constants that are defined but not used in the logic of a smart contract, will NOT be included in the // bytecode of the smart contract when compiled. However, public constants will be included in every inheriting contract diff --git a/src/contracts/types/AtlasErrors.sol b/src/contracts/types/AtlasErrors.sol index 163a22afe..582c14e89 100644 --- a/src/contracts/types/AtlasErrors.sol +++ b/src/contracts/types/AtlasErrors.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/ValidCalls.sol"; +import "./ValidCalls.sol"; contract AtlasErrors { // Simulator From 705e15e976baad5e4cbc313e5cbd13dd7b83bb70 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:53:53 +0200 Subject: [PATCH 26/70] chore: use relative imports in BaseTest --- test/base/BaseTest.t.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index a43479298..0377d4812 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -6,11 +6,11 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { TestAtlas } from "./TestAtlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; -import { Sorter } from "src/contracts/helpers/Sorter.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; -import { GovernanceBurner } from "src/contracts/helpers/GovernanceBurner.sol"; +import { AtlasVerification } from "../../src/contracts/atlas/AtlasVerification.sol"; +import { ExecutionEnvironment } from "../../src/contracts/common/ExecutionEnvironment.sol"; +import { Sorter } from "../../src/contracts/helpers/Sorter.sol"; +import { Simulator } from "../../src/contracts/helpers/Simulator.sol"; +import { GovernanceBurner } from "../../src/contracts/helpers/GovernanceBurner.sol"; contract BaseTest is Test { struct Sig { From 5a250602e293858a8b61482814d5648e9ff25e85 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:56:41 +0200 Subject: [PATCH 27/70] chore: use relative imports in TestAtlas --- test/base/TestAtlas.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 4e325dc4c..bbcf4fe44 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/atlas/Atlas.sol"; +import "../../src/contracts/atlas/Atlas.sol"; /// @title TestAtlas /// @author FastLane Labs From ffba055fc7f2db66a33ffb84ffa73cd7b4d3a06a Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:31:29 +0200 Subject: [PATCH 28/70] test: improve DummyDAppControl, Escrow tests --- test/Escrow.t.sol | 31 +++++++++++------ test/base/DummyDAppControl.sol | 61 ++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index d6035cced..cacbf8040 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -143,7 +143,10 @@ contract EscrowTest is BaseTest { .withAllowAllocateValueFailure(true) // Allow the value allocation to fail .build() ); - executeHookCase(block.timestamp * 2, noError); + + (UserOperation memory userOp,,) = executeHookCase(block.timestamp * 2, noError); + bytes memory expectedInput = abi.encode(userOp); + assertEq(expectedInput, dAppControl.preOpsInputData(), "preOpsInputData should match expectedInput"); } // Ensure metacall reverts with the proper error when the preOps hook reverts. @@ -170,6 +173,8 @@ contract EscrowTest is BaseTest { .build() ); executeHookCase(block.timestamp * 3, noError); + bytes memory expectedInput = abi.encode(block.timestamp * 3); + assertEq(expectedInput, dAppControl.userOpInputData(), "userOpInputData should match expectedInput"); } // Ensure metacall reverts with the proper error when the user operation reverts. @@ -195,7 +200,6 @@ contract EscrowTest is BaseTest { ); dAppControl.setAllocateValueShouldRevert(true); - executeHookCase(1, AtlasErrors.AllocateValueFail.selector); } @@ -208,6 +212,8 @@ contract EscrowTest is BaseTest { .build() ); executeHookCase(0, noError); + bytes memory expectedInput = abi.encode(true, new bytes(0)); + assertEq(expectedInput, dAppControl.postOpsInputData(), "postOpsInputData should match expectedInput"); } // Ensure metacall reverts with the proper error when the postOps hook reverts. @@ -234,19 +240,22 @@ contract EscrowTest is BaseTest { .withTrackUserReturnData(true) // Track the user operation's return data .build() ); + uint256 userOpArg = 321; - vm.prank(userEOA); - address executionEnvironment = atlas.createExecutionEnvironment(userEOA, address(dAppControl)); + executeHookCase(userOpArg, noError); - vm.expectEmit(false, false, false, true, executionEnvironment); - emit MEVPaymentSuccess(address(0), defaultBidAmount); - this.executeHookCase(0, noError); + bytes memory expectedInput = abi.encode(address(0), defaultBidAmount, abi.encode(userOpArg)); + assertEq(expectedInput, dAppControl.allocateValueInputData(), "allocateValueInputData should match expectedInput"); } - function executeHookCase(uint256 expectedHookReturnValue, bytes4 expectedError) public { + function executeHookCase(uint256 expectedHookReturnValue, bytes4 expectedError) public returns( + UserOperation memory userOp, + SolverOperation[] memory solverOps, + DAppOperation memory dappOp + ) { bool revertExpected = expectedError != noError; - UserOperation memory userOp = validUserOperation(address(dAppControl)) + userOp = validUserOperation(address(dAppControl)) .withData( abi.encodeWithSelector( dAppControl.userOperationCall.selector, @@ -255,13 +264,13 @@ contract EscrowTest is BaseTest { ) .signAndBuild(address(atlasVerification), userPK); - SolverOperation[] memory solverOps = new SolverOperation[](1); + solverOps = new SolverOperation[](1); solverOps[0] = validSolverOperation(userOp) .withBidAmount(defaultBidAmount) .withData(abi.encode(expectedHookReturnValue)) .signAndBuild(address(atlasVerification), solverOnePK); - DAppOperation memory dappOp = validDAppOperation(userOp, solverOps).build(); + dappOp = validDAppOperation(userOp, solverOps).build(); if (revertExpected) { vm.expectRevert(expectedError); diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index 34341e813..42975c5cd 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -22,6 +22,12 @@ contract DummyDAppControl is DAppControl { bool public postOpsShouldRevert; // TODO add storage vars to store input data for each hook, then test hooks were passed the correct data + bytes public preOpsInputData; + bytes public userOpInputData; + bytes public preSolverInputData; + bytes public postSolverInputData; + bytes public allocateValueInputData; + bytes public postOpsInputData; event MEVPaymentSuccess(address bidToken, uint256 bidAmount); @@ -43,46 +49,34 @@ contract DummyDAppControl is DAppControl { bool shouldRevert = DummyDAppControl(CONTROL).preOpsShouldRevert(); require(!shouldRevert, "_preOpsCall revert requested"); + DummyDAppControl(CONTROL).setInputData(abi.encode(userOp), 0); + console.logBytes(abi.encode(userOp)); + if (userOp.data.length == 0) return new bytes(0); (, bytes memory data) = address(userOp.dapp).call(userOp.data); return data; } - function _postOpsCall(bool, bytes calldata data) internal view virtual override { + function _postOpsCall(bool solved, bytes calldata data) internal virtual override { bool shouldRevert = DummyDAppControl(CONTROL).postOpsShouldRevert(); require(!shouldRevert, "_postOpsCall revert requested"); - if (data.length == 0) return; - // TODO store input data and check it was passed correctly in Escrow.t.sol - // (bool shouldRevert) = abi.decode(data, (bool)); - // require(!shouldRevert, "_postOpsCall revert requested"); + DummyDAppControl(CONTROL).setInputData(abi.encode(solved, data), 5); } - function _preSolverCall(SolverOperation calldata, bytes calldata returnData) internal view virtual override { + function _preSolverCall(SolverOperation calldata solverOp, bytes calldata returnData) internal virtual override { bool shouldRevert = DummyDAppControl(CONTROL).preSolverShouldRevert(); require(!shouldRevert, "_preSolverCall revert requested"); - if (returnData.length == 0) { - return; - } - - // TODO store input data and check it was passed correctly in Escrow.t.sol - // (bool shouldRevert) = abi.decode(returnData, (bool)); - // require(!shouldRevert, "_preSolverCall revert requested"); + DummyDAppControl(CONTROL).setInputData(abi.encode(solverOp, returnData), 2); } - function _postSolverCall(SolverOperation calldata, bytes calldata returnData) internal view virtual override { + function _postSolverCall(SolverOperation calldata solverOp, bytes calldata returnData) internal virtual override { bool shouldRevert = DummyDAppControl(CONTROL).postSolverShouldRevert(); require(!shouldRevert, "_postSolverCall revert requested"); - if (returnData.length == 0) { - return; - } - - // TODO store input data and check it was passed correctly in Escrow.t.sol - // (bool shouldRevert) = abi.decode(returnData, (bool)); - // require(!shouldRevert, "_postSolverCall revert requested"); + DummyDAppControl(CONTROL).setInputData(abi.encode(solverOp, returnData), 3); } function _allocateValueCall( @@ -97,8 +91,9 @@ contract DummyDAppControl is DAppControl { bool shouldRevert = DummyDAppControl(CONTROL).allocateValueShouldRevert(); require(!shouldRevert, "_allocateValueCall revert requested"); - // TODO store input data and check it was passed correctly in Escrow.t.sol - emit MEVPaymentSuccess(bidToken, winningAmount); + DummyDAppControl(CONTROL).setInputData(abi.encode(bidToken, winningAmount, data), 4); + + // emit MEVPaymentSuccess(bidToken, winningAmount); } function getBidValue(SolverOperation calldata solverOp) public view virtual override returns (uint256) { @@ -111,11 +106,12 @@ contract DummyDAppControl is DAppControl { // Custom functions // **************************************** - function userOperationCall(uint256 returnValue) public view returns (uint256) { + function userOperationCall(uint256 returnValue) public returns (uint256) { bool shouldRevert = DummyDAppControl(CONTROL).userOpShouldRevert(); require(!shouldRevert, "userOperationCall revert requested"); - // TODO store input data and check it was passed correctly in Escrow.t.sol + DummyDAppControl(CONTROL).setInputData(abi.encode(returnValue), 1); + return returnValue; } @@ -144,4 +140,19 @@ contract DummyDAppControl is DAppControl { function setPostOpsShouldRevert(bool _postOpsShouldRevert) public { postOpsShouldRevert = _postOpsShouldRevert; } + + // Called by the EE to save input data for testing after the metacall ends + function setInputData( + bytes memory inputData, + uint256 hook // 0: preOps, 1: userOp, 2: preSolver, 3: postSolver, 4: allocateValue, 5: postOps + ) + public + { + if (hook == 0) preOpsInputData = inputData; + if (hook == 1) userOpInputData = inputData; + if (hook == 2) preSolverInputData = inputData; + if (hook == 3) postSolverInputData = inputData; + if (hook == 4) allocateValueInputData = inputData; + if (hook == 5) postOpsInputData = inputData; + } } From 9cc763f433a0cd814c31d48eb9e34a58bc382d85 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:57:02 +0200 Subject: [PATCH 29/70] chore: use relative imports in scripts --- script/base/deploy-base.s.sol | 18 +++++++++--------- script/create-oev-demo-positions.s.sol | 8 ++++---- script/deploy-atlas.s.sol | 16 ++++++++-------- script/deploy-demo-tokens.s.sol | 10 +++++----- script/deploy-exec-env.s.sol | 4 ++-- script/deploy-fl-online-control.s.sol | 8 ++++---- script/deploy-oev-demo.s.sol | 14 +++++++------- script/deploy-sorter.s.sol | 4 ++-- script/deploy-swap-intent-control.s.sol | 12 ++++++------ script/deploy-tx-builder.s.sol | 10 +++++----- script/deploy-v2-reward-control.s.sol | 8 ++++---- script/mint-demo-tokens.s.sol | 4 ++-- script/set-oev-demo-signers.s.sol | 10 +++++----- script/solver-deposit.s.sol | 4 ++-- 14 files changed, 65 insertions(+), 65 deletions(-) diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 71b5a6b16..fb28277fb 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -7,15 +7,15 @@ import "forge-std/StdJson.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { SwapIntentDAppControl } from "src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; -import { Sorter } from "src/contracts/helpers/Sorter.sol"; -import { SimpleRFQSolver } from "test/SwapIntent.t.sol"; - -import { Utilities } from "src/contracts/helpers/Utilities.sol"; +import { Atlas } from "../../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../../src/contracts/atlas/AtlasVerification.sol"; +import { SwapIntentDAppControl } from "../../src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; +import { TxBuilder } from "../../src/contracts/helpers/TxBuilder.sol"; +import { Simulator } from "../../src/contracts/helpers/Simulator.sol"; +import { Sorter } from "../../src/contracts/helpers/Sorter.sol"; +import { SimpleRFQSolver } from "../../test/SwapIntent.t.sol"; + +import { Utilities } from "../../src/contracts/helpers/Utilities.sol"; contract DeployBaseScript is Script { using stdJson for string; diff --git a/script/create-oev-demo-positions.s.sol b/script/create-oev-demo-positions.s.sol index 3c6761701..283309e84 100644 --- a/script/create-oev-demo-positions.s.sol +++ b/script/create-oev-demo-positions.s.sol @@ -6,11 +6,11 @@ import "forge-std/Test.sol"; import { DeployBaseScript } from "script/base/deploy-base.s.sol"; -import { ChainlinkDAppControl } from "src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; +import { ChainlinkDAppControl } from "../src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; +import { ChainlinkAtlasWrapper } from "../src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; -import { Token } from "src/contracts/helpers/DemoToken.sol"; -import { DemoLendingProtocol } from "src/contracts/helpers/DemoLendingProtocol.sol"; +import { Token } from "../src/contracts/helpers/DemoToken.sol"; +import { DemoLendingProtocol } from "../src/contracts/helpers/DemoLendingProtocol.sol"; // Sets up a few liquidatable positions in the Lending Protocol. ETH for gas fees distributed by Lending Gov. contract CreateOEVDemoPositionsScript is DeployBaseScript { diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 8531c62e4..789546c3d 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -4,14 +4,14 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; - -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; -import { Sorter } from "src/contracts/helpers/Sorter.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; + +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { Simulator } from "../src/contracts/helpers/Simulator.sol"; +import { Sorter } from "../src/contracts/helpers/Sorter.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; contract DeployAtlasScript is DeployBaseScript { function run() external { diff --git a/script/deploy-demo-tokens.s.sol b/script/deploy-demo-tokens.s.sol index b5517c645..54afc65fa 100644 --- a/script/deploy-demo-tokens.s.sol +++ b/script/deploy-demo-tokens.s.sol @@ -6,12 +6,12 @@ import "forge-std/Test.sol"; import { DeployBaseScript } from "script/base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { V2RewardDAppControl } from "src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; -import { IUniswapV2Router02 } from "src/contracts/examples/v2-example-router/interfaces/IUniswapV2Router.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { V2RewardDAppControl } from "../src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; +import { IUniswapV2Router02 } from "../src/contracts/examples/v2-example-router/interfaces/IUniswapV2Router.sol"; -import { Token } from "src/contracts/helpers/DemoToken.sol"; +import { Token } from "../src/contracts/helpers/DemoToken.sol"; import { WETH } from "solady/tokens/WETH.sol"; // Deploy 3 stablecoin tokens (DAI, USDA, USDB) - all 18 decimals diff --git a/script/deploy-exec-env.s.sol b/script/deploy-exec-env.s.sol index 66cbf86a2..337678dcd 100644 --- a/script/deploy-exec-env.s.sol +++ b/script/deploy-exec-env.s.sol @@ -4,9 +4,9 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; contract DeployExecEnvScript is DeployBaseScript { ExecutionEnvironment public execEnv; diff --git a/script/deploy-fl-online-control.s.sol b/script/deploy-fl-online-control.s.sol index 7ee4beeaa..3e513931a 100644 --- a/script/deploy-fl-online-control.s.sol +++ b/script/deploy-fl-online-control.s.sol @@ -4,11 +4,11 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { FastLaneOnlineOuter } from "src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { FastLaneOnlineOuter } from "../src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol"; contract DeployFLOnlineControlScript is DeployBaseScript { FastLaneOnlineOuter flOnline; diff --git a/script/deploy-oev-demo.s.sol b/script/deploy-oev-demo.s.sol index 13954c4d5..dbe42e4ee 100644 --- a/script/deploy-oev-demo.s.sol +++ b/script/deploy-oev-demo.s.sol @@ -4,15 +4,15 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { ChainlinkDAppControl } from "src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { ChainlinkDAppControl } from "../src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; +import { ChainlinkAtlasWrapper } from "../src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; -import { Token } from "src/contracts/helpers/DemoToken.sol"; -import { DemoLendingProtocol } from "src/contracts/helpers/DemoLendingProtocol.sol"; +import { Token } from "../src/contracts/helpers/DemoToken.sol"; +import { DemoLendingProtocol } from "../src/contracts/helpers/DemoLendingProtocol.sol"; contract DeployOEVDemoScript is DeployBaseScript { address public constant CHAINLINK_ETH_USD = 0x694AA1769357215DE4FAC081bf1f309aDC325306; // on Sepolia diff --git a/script/deploy-sorter.s.sol b/script/deploy-sorter.s.sol index 0440ee64a..3a6f2f1f8 100644 --- a/script/deploy-sorter.s.sol +++ b/script/deploy-sorter.s.sol @@ -4,9 +4,9 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Sorter } from "src/contracts/helpers/Sorter.sol"; +import { Sorter } from "../src/contracts/helpers/Sorter.sol"; contract DeploySorterScript is DeployBaseScript { function run() external { diff --git a/script/deploy-swap-intent-control.s.sol b/script/deploy-swap-intent-control.s.sol index 6bf1c8d78..3eb01e615 100644 --- a/script/deploy-swap-intent-control.s.sol +++ b/script/deploy-swap-intent-control.s.sol @@ -4,13 +4,13 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { SwapIntentDAppControl } from "src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { SwapIntentDAppControl } from "../src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { Simulator } from "../src/contracts/helpers/Simulator.sol"; contract DeploySwapIntentControlScript is DeployBaseScript { function run() external { diff --git a/script/deploy-tx-builder.s.sol b/script/deploy-tx-builder.s.sol index 4c648ea71..c9fb32758 100644 --- a/script/deploy-tx-builder.s.sol +++ b/script/deploy-tx-builder.s.sol @@ -4,12 +4,12 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { Simulator } from "../src/contracts/helpers/Simulator.sol"; contract DeployTxBuilderScript is DeployBaseScript { function run() external { diff --git a/script/deploy-v2-reward-control.s.sol b/script/deploy-v2-reward-control.s.sol index 263e4bee8..46db22ea6 100644 --- a/script/deploy-v2-reward-control.s.sol +++ b/script/deploy-v2-reward-control.s.sol @@ -4,11 +4,11 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { V2RewardDAppControl } from "src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { V2RewardDAppControl } from "../src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; contract DeployV2RewardControlScript is DeployBaseScript { V2RewardDAppControl v2RewardControl; diff --git a/script/mint-demo-tokens.s.sol b/script/mint-demo-tokens.s.sol index 36a6d883a..ab8ef1c4c 100644 --- a/script/mint-demo-tokens.s.sol +++ b/script/mint-demo-tokens.s.sol @@ -4,8 +4,8 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; -import { Token } from "src/contracts/helpers/DemoToken.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; +import { Token } from "../src/contracts/helpers/DemoToken.sol"; import { WETH } from "solady/tokens/WETH.sol"; contract MintDemoTokensScript is DeployBaseScript { diff --git a/script/set-oev-demo-signers.s.sol b/script/set-oev-demo-signers.s.sol index 22ccf327d..e2c8ead19 100644 --- a/script/set-oev-demo-signers.s.sol +++ b/script/set-oev-demo-signers.s.sol @@ -4,13 +4,13 @@ pragma solidity 0.8.25; import "forge-std/Script.sol"; import "forge-std/Test.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { ChainlinkDAppControl } from "src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; +import { ChainlinkDAppControl } from "../src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; +import { ChainlinkAtlasWrapper } from "../src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; -import { Token } from "src/contracts/helpers/DemoToken.sol"; -import { DemoLendingProtocol } from "src/contracts/helpers/DemoLendingProtocol.sol"; +import { Token } from "../src/contracts/helpers/DemoToken.sol"; +import { DemoLendingProtocol } from "../src/contracts/helpers/DemoLendingProtocol.sol"; // For the Chainlink OEV demo, when its difficult to find a real `transmit()` tx with a low enough ETH price. // We replace the real Sepolia Chainlink ETH/USD signers with a set of test signers, in ChainlinkDAppControl. diff --git a/script/solver-deposit.s.sol b/script/solver-deposit.s.sol index 9daa79492..01e4ecbf6 100644 --- a/script/solver-deposit.s.sol +++ b/script/solver-deposit.s.sol @@ -5,9 +5,9 @@ import "forge-std/Script.sol"; import "forge-std/Test.sol"; import "forge-std/StdJson.sol"; -import { DeployBaseScript } from "script/base/deploy-base.s.sol"; +import { DeployBaseScript } from "./base/deploy-base.s.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; // NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' From ef45b272d4c3a88a91a83b0180771e3f9d65108c Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:58:25 +0200 Subject: [PATCH 30/70] chore: use relative imports in examples --- .../examples/ex-post-mev-example/V2ExPost.sol | 14 +++++----- .../examples/fastlane-online/BaseStorage.sol | 4 +-- .../fastlane-online/FastLaneControl.sol | 20 ++++++------- .../fastlane-online/FastLaneOnlineInner.sol | 24 ++++++++-------- .../fastlane-online/FastLaneOnlineOuter.sol | 26 ++++++++--------- .../fastlane-online/IFastLaneOnline.sol | 6 ++-- .../examples/fastlane-online/OuterHelpers.sol | 28 +++++++++---------- .../fastlane-online/SolverGateway.sol | 28 +++++++++---------- src/contracts/examples/gas-filler/Filler.sol | 16 +++++------ .../GeneralizedBackrunUserBundler.sol | 18 ++++++------ .../examples/intents-example/StateIntent.sol | 8 +++--- .../intents-example/SwapIntentDAppControl.sol | 10 +++---- .../SwapIntentInvertBidDAppControl.sol | 12 ++++---- .../examples/intents-example/V4SwapIntent.sol | 12 ++++---- .../oev-example/ChainlinkAtlasWrapper.sol | 7 ++--- .../oev-example/ChainlinkDAppControl.sol | 12 ++++---- .../oev-example/ChainlinkDAppControlAlt.sol | 12 ++++---- .../trebleswap/TrebleSwapDAppControl.sol | 8 +++--- .../v2-example-router/V2RewardDAppControl.sol | 8 +++--- .../examples/v2-example/V2DAppControl.sol | 14 +++++----- .../examples/v4-example/UniV4Hook.sol | 12 ++++---- .../examples/v4-example/V4DAppControl.sol | 16 +++++------ 22 files changed, 156 insertions(+), 159 deletions(-) diff --git a/src/contracts/examples/ex-post-mev-example/V2ExPost.sol b/src/contracts/examples/ex-post-mev-example/V2ExPost.sol index 6d7bb4948..7c90b9140 100644 --- a/src/contracts/examples/ex-post-mev-example/V2ExPost.sol +++ b/src/contracts/examples/ex-post-mev-example/V2ExPost.sol @@ -6,17 +6,17 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Base Imports -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; // Uni V2 Imports import { IUniswapV2Pair } from "./interfaces/IUniswapV2Pair.sol"; diff --git a/src/contracts/examples/fastlane-online/BaseStorage.sol b/src/contracts/examples/fastlane-online/BaseStorage.sol index d552082ea..ca2514a3d 100644 --- a/src/contracts/examples/fastlane-online/BaseStorage.sol +++ b/src/contracts/examples/fastlane-online/BaseStorage.sol @@ -1,9 +1,9 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/SolverOperation.sol"; +import "../../types/SolverOperation.sol"; -import { Reputation } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { Reputation } from "./FastLaneTypes.sol"; contract BaseStorage { error FLOnline_NotUnlocked(); diff --git a/src/contracts/examples/fastlane-online/FastLaneControl.sol b/src/contracts/examples/fastlane-online/FastLaneControl.sol index 0166f2d6e..9b0388c95 100644 --- a/src/contracts/examples/fastlane-online/FastLaneControl.sol +++ b/src/contracts/examples/fastlane-online/FastLaneControl.sol @@ -6,16 +6,16 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; - -import { SwapIntent, BaselineCall } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; -import { FastLaneOnlineErrors } from "src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol"; -import { IFastLaneOnline } from "src/contracts/examples/fastlane-online/IFastLaneOnline.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; + +import { SwapIntent, BaselineCall } from "./FastLaneTypes.sol"; +import { FastLaneOnlineErrors } from "./FastLaneOnlineErrors.sol"; +import { IFastLaneOnline } from "./IFastLaneOnline.sol"; interface ISolverGateway { function getBidAmount(bytes32 solverOpHash) external view returns (uint256 bidAmount); diff --git a/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol b/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol index 08d35946d..492085440 100644 --- a/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol +++ b/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol @@ -6,22 +6,22 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { DAppOperation } from "../../types/DAppOperation.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Interface Import -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlasVerification } from "../../interfaces/IAtlasVerification.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; -import { FastLaneOnlineControl } from "src/contracts/examples/fastlane-online/FastLaneControl.sol"; -import { BaseStorage } from "src/contracts/examples/fastlane-online/BaseStorage.sol"; +import { FastLaneOnlineControl } from "./FastLaneControl.sol"; +import { BaseStorage } from "./BaseStorage.sol"; -import { SwapIntent, BaselineCall } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { SwapIntent, BaselineCall } from "./FastLaneTypes.sol"; interface IGeneralizedBackrunProxy { function getUser() external view returns (address); diff --git a/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol b/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol index bae46e1c5..b4a9efe4f 100644 --- a/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol +++ b/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol @@ -6,23 +6,23 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { DAppOperation } from "../../types/DAppOperation.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Interface Import -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlasVerification } from "../../interfaces/IAtlasVerification.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; -import { FastLaneOnlineControl } from "src/contracts/examples/fastlane-online/FastLaneControl.sol"; -import { FastLaneOnlineInner } from "src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol"; -import { SolverGateway } from "src/contracts/examples/fastlane-online/SolverGateway.sol"; +import { FastLaneOnlineControl } from "./FastLaneControl.sol"; +import { FastLaneOnlineInner } from "./FastLaneOnlineInner.sol"; +import { SolverGateway } from "./SolverGateway.sol"; -import { SwapIntent, BaselineCall } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { SwapIntent, BaselineCall } from "./FastLaneTypes.sol"; contract FastLaneOnlineOuter is SolverGateway { constructor(address atlas, address protocolGuildWallet) SolverGateway(atlas, protocolGuildWallet) { } diff --git a/src/contracts/examples/fastlane-online/IFastLaneOnline.sol b/src/contracts/examples/fastlane-online/IFastLaneOnline.sol index 412ab2935..c61c79508 100644 --- a/src/contracts/examples/fastlane-online/IFastLaneOnline.sol +++ b/src/contracts/examples/fastlane-online/IFastLaneOnline.sol @@ -1,9 +1,9 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import { SwapIntent, BaselineCall, Reputation } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import { SwapIntent, BaselineCall, Reputation } from "./FastLaneTypes.sol"; interface IFastLaneOnline { // User entrypoint diff --git a/src/contracts/examples/fastlane-online/OuterHelpers.sol b/src/contracts/examples/fastlane-online/OuterHelpers.sol index ba2b78615..4a0544d40 100644 --- a/src/contracts/examples/fastlane-online/OuterHelpers.sol +++ b/src/contracts/examples/fastlane-online/OuterHelpers.sol @@ -7,24 +7,24 @@ import { LibSort } from "solady/utils/LibSort.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { DAppOperation } from "../../types/DAppOperation.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; +import "../../types/EscrowTypes.sol"; // Interface Import -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISimulator } from "src/contracts/interfaces/ISimulator.sol"; +import { IAtlasVerification } from "../../interfaces/IAtlasVerification.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; +import { ISimulator } from "../../interfaces/ISimulator.sol"; -import { FastLaneOnlineControl } from "src/contracts/examples/fastlane-online/FastLaneControl.sol"; -import { FastLaneOnlineInner } from "src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol"; +import { FastLaneOnlineControl } from "./FastLaneControl.sol"; +import { FastLaneOnlineInner } from "./FastLaneOnlineInner.sol"; -import { SwapIntent, BaselineCall, Reputation } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { SwapIntent, BaselineCall, Reputation } from "./FastLaneTypes.sol"; contract OuterHelpers is FastLaneOnlineInner { // NOTE: Any funds collected in excess of the therapy bills required for the Cardano engineering team diff --git a/src/contracts/examples/fastlane-online/SolverGateway.sol b/src/contracts/examples/fastlane-online/SolverGateway.sol index 681e38e39..26e3ed80c 100644 --- a/src/contracts/examples/fastlane-online/SolverGateway.sol +++ b/src/contracts/examples/fastlane-online/SolverGateway.sol @@ -6,24 +6,24 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { DAppOperation } from "../../types/DAppOperation.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; +import "../../types/EscrowTypes.sol"; // Interface Import -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { ISimulator } from "src/contracts/interfaces/ISimulator.sol"; +import { IAtlasVerification } from "../../interfaces/IAtlasVerification.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; +import { ISimulator } from "../../interfaces/ISimulator.sol"; -import { FastLaneOnlineControl } from "src/contracts/examples/fastlane-online/FastLaneControl.sol"; -import { OuterHelpers } from "src/contracts/examples/fastlane-online/OuterHelpers.sol"; +import { FastLaneOnlineControl } from "./FastLaneControl.sol"; +import { OuterHelpers } from "./OuterHelpers.sol"; -import { SwapIntent, BaselineCall, Reputation } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { SwapIntent, BaselineCall, Reputation } from "./FastLaneTypes.sol"; contract SolverGateway is OuterHelpers { uint256 public constant USER_GAS_BUFFER = 350_000; diff --git a/src/contracts/examples/gas-filler/Filler.sol b/src/contracts/examples/gas-filler/Filler.sol index a0e9ee643..904c11476 100644 --- a/src/contracts/examples/gas-filler/Filler.sol +++ b/src/contracts/examples/gas-filler/Filler.sol @@ -5,18 +5,18 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; // Atlas Base Imports -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; interface IERC20 { function allowance(address owner, address spender) external view returns (uint256); diff --git a/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol b/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol index 6ae07c1d3..22aa7620c 100644 --- a/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol +++ b/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol @@ -6,17 +6,17 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { DAppOperation } from "../../types/DAppOperation.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Interface Import -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlasVerification } from "../../interfaces/IAtlasVerification.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; struct Approval { address token; diff --git a/src/contracts/examples/intents-example/StateIntent.sol b/src/contracts/examples/intents-example/StateIntent.sol index 37a2e24b8..3083ca379 100644 --- a/src/contracts/examples/intents-example/StateIntent.sol +++ b/src/contracts/examples/intents-example/StateIntent.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.25; // Atlas Base Imports -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import "src/contracts/types/LockTypes.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/examples/intents-example/SwapIntentDAppControl.sol b/src/contracts/examples/intents-example/SwapIntentDAppControl.sol index 8aabc1b1c..8250a32e0 100644 --- a/src/contracts/examples/intents-example/SwapIntentDAppControl.sol +++ b/src/contracts/examples/intents-example/SwapIntentDAppControl.sol @@ -6,11 +6,11 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; struct Condition { address antecedent; diff --git a/src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol b/src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol index 48b72c81d..3fc659dab 100644 --- a/src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol +++ b/src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol @@ -6,15 +6,15 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Base Imports -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/examples/intents-example/V4SwapIntent.sol b/src/contracts/examples/intents-example/V4SwapIntent.sol index 46c6f2775..519b5947f 100644 --- a/src/contracts/examples/intents-example/V4SwapIntent.sol +++ b/src/contracts/examples/intents-example/V4SwapIntent.sol @@ -6,15 +6,15 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Base Imports -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol b/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol index 5fb5df22c..d00f82af8 100644 --- a/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol +++ b/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol @@ -3,11 +3,8 @@ pragma solidity 0.8.25; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; import { SafeERC20, IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; -import { - IChainlinkAtlasWrapper, - AggregatorV2V3Interface -} from "src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol"; -import { IChainlinkDAppControl } from "src/contracts/examples/oev-example/IChainlinkDAppControl.sol"; +import { IChainlinkAtlasWrapper, AggregatorV2V3Interface } from "./IChainlinkAtlasWrapper.sol"; +import { IChainlinkDAppControl } from "./IChainlinkDAppControl.sol"; // A wrapper contract for a specific Chainlink price feed, used by Atlas to capture Oracle Extractable Value (OEV). // Each MEV-generating protocol needs their own wrapper for each Chainlink price feed they use. diff --git a/src/contracts/examples/oev-example/ChainlinkDAppControl.sol b/src/contracts/examples/oev-example/ChainlinkDAppControl.sol index ab190d88a..18883ed99 100644 --- a/src/contracts/examples/oev-example/ChainlinkDAppControl.sol +++ b/src/contracts/examples/oev-example/ChainlinkDAppControl.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.25; import { ECDSA } from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { ChainlinkAtlasWrapper } from "./ChainlinkAtlasWrapper.sol"; // Role enum as per Chainlink's OffchainAggregatorBilling.sol contract enum Role { diff --git a/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol b/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol index d518c4eb4..611e32bdc 100644 --- a/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol +++ b/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol @@ -1,14 +1,14 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { ChainlinkAtlasWrapper } from "./ChainlinkAtlasWrapperAlt.sol"; // Role enum as per Chainlink's OffchainAggregatorBilling.sol contract enum Role { diff --git a/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol b/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol index c0d06f083..413a54af9 100644 --- a/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol +++ b/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol @@ -4,10 +4,10 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; struct SwapTokenInfo { address inputToken; diff --git a/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol b/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol index eae49ece4..45a73d5d9 100644 --- a/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol +++ b/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol @@ -6,10 +6,10 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; // Uniswap Imports import { IUniswapV2Router01, IUniswapV2Router02 } from "./interfaces/IUniswapV2Router.sol"; diff --git a/src/contracts/examples/v2-example/V2DAppControl.sol b/src/contracts/examples/v2-example/V2DAppControl.sol index 9eef3516a..de6e2f9f6 100644 --- a/src/contracts/examples/v2-example/V2DAppControl.sol +++ b/src/contracts/examples/v2-example/V2DAppControl.sol @@ -5,17 +5,17 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; // Atlas Base Imports -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/UserOperation.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; // Uni V2 Imports import { IUniswapV2Pair } from "./interfaces/IUniswapV2Pair.sol"; diff --git a/src/contracts/examples/v4-example/UniV4Hook.sol b/src/contracts/examples/v4-example/UniV4Hook.sol index f6fbc1ddb..490622e5b 100644 --- a/src/contracts/examples/v4-example/UniV4Hook.sol +++ b/src/contracts/examples/v4-example/UniV4Hook.sol @@ -8,13 +8,13 @@ import { IHooks } from "./IHooks.sol"; // Atlas Imports import { V4DAppControl } from "./V4DAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/LockTypes.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/UserOperation.sol"; +import "../../types/ConfigTypes.sol"; +import "../../types/LockTypes.sol"; // NOTE: Uniswap V4 is unique in that it would not require a frontend integration. // Instead, hooks can be used to enforce that the proceeds of the MEV auctions are diff --git a/src/contracts/examples/v4-example/V4DAppControl.sol b/src/contracts/examples/v4-example/V4DAppControl.sol index 6d0e7684a..093defc0d 100644 --- a/src/contracts/examples/v4-example/V4DAppControl.sol +++ b/src/contracts/examples/v4-example/V4DAppControl.sol @@ -6,17 +6,17 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; // Atlas Base Imports -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { IAtlas } from "../../interfaces/IAtlas.sol"; +import { SafetyBits } from "../../libraries/SafetyBits.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/LockTypes.sol"; +import { CallConfig } from "../../types/ConfigTypes.sol"; +import "../../types/SolverOperation.sol"; +import "../../types/UserOperation.sol"; +import "../../types/ConfigTypes.sol"; +import "../../types/LockTypes.sol"; // Atlas DApp-Control Imports -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../dapp/DAppControl.sol"; // V4 Imports import { IPoolManager } from "./IPoolManager.sol"; From 1c476d9ec4f8e98b2199a85ddd47e78a98f4720c Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:00:36 +0200 Subject: [PATCH 31/70] chore: remove TODO --- test/base/DummyDAppControl.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index 42975c5cd..b33af3cc9 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -21,7 +21,6 @@ contract DummyDAppControl is DAppControl { bool public allocateValueShouldRevert; bool public postOpsShouldRevert; - // TODO add storage vars to store input data for each hook, then test hooks were passed the correct data bytes public preOpsInputData; bytes public userOpInputData; bytes public preSolverInputData; From 0ba846db32b8407d89508fb95d9dcd09976809b4 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:19:02 +0200 Subject: [PATCH 32/70] chore: use relative imports in tests --- test/Accounting.t.sol | 18 +++++------ test/AccountingMath.t.sol | 2 +- test/AtlETH.t.sol | 4 +-- test/Atlas.t.sol | 31 +++++++++--------- test/AtlasVerification.t.sol | 20 ++++++------ test/DAppIntegration.t.sol | 10 +++--- test/Escrow.t.sol | 22 ++++++------- test/ExPost.t.sol | 32 ++++++++----------- test/ExecutionBase.t.sol | 8 ++--- test/ExecutionEnvironment.t.sol | 24 +++++++------- test/FLOnline.t.sol | 16 +++++----- test/Factory.t.sol | 14 ++++---- test/FlashLoan.t.sol | 22 ++++++------- test/GasAccounting.t.sol | 28 ++++++++-------- test/MainTest.t.sol | 24 +++++++------- test/Mimic.t.sol | 2 +- test/NonceManager.t.sol | 14 ++++---- test/OEV.t.sol | 20 ++++++------ test/OEValt.t.sol | 18 +++++------ test/Permit69.t.sol | 20 ++++++------ test/SafetyLocks.t.sol | 10 +++--- test/Simulator.t.sol | 22 ++++++------- test/Sorter.t.sol | 4 +-- test/Storage.t.sol | 6 ++-- test/Surcharge.t.sol | 4 +-- test/SwapIntent.t.sol | 14 ++++---- test/SwapIntentInvertBid.t.sol | 20 ++++++------ test/TrebleSwap.t.sol | 14 ++++---- test/V2Helper.sol | 18 +++++------ test/V2RewardDAppControl.t.sol | 24 +++++++------- test/base/DummyDAppControl.sol | 8 ++--- test/base/GasSponsorDAppControl.sol | 12 +++---- test/base/TestUtils.sol | 12 +++---- test/base/builders/DAppOperationBuilder.sol | 16 +++++----- test/base/builders/SolverOperationBuilder.sol | 14 ++++---- test/base/builders/UserOperationBuilder.sol | 8 ++--- test/helpers/CallConfigBuilder.sol | 2 +- test/helpers/DummyDAppControlBuilder.sol | 6 ++-- test/libraries/CallBits.t.sol | 6 ++-- test/libraries/CallVerification.t.sol | 6 ++-- test/libraries/EscrowBits.t.sol | 6 ++-- test/libraries/SafetyBits.t.sol | 10 +++--- 42 files changed, 294 insertions(+), 297 deletions(-) diff --git a/test/Accounting.t.sol b/test/Accounting.t.sol index fc4fd43f7..0ca3c5042 100644 --- a/test/Accounting.t.sol +++ b/test/Accounting.t.sol @@ -6,14 +6,14 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; -import "src/contracts/types/LockTypes.sol"; +import { SafetyBits } from "../src/contracts/libraries/SafetyBits.sol"; +import "../src/contracts/types/LockTypes.sol"; import { TestUtils } from "./base/TestUtils.sol"; @@ -21,9 +21,9 @@ import { SwapIntentDAppControl, SwapIntent, Condition -} from "src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; +} from "../src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; contract AccountingTest is BaseTest { SwapIntentDAppControl public swapIntentControl; diff --git a/test/AccountingMath.t.sol b/test/AccountingMath.t.sol index a9b26d180..bc38ab121 100644 --- a/test/AccountingMath.t.sol +++ b/test/AccountingMath.t.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import "src/contracts/libraries/AccountingMath.sol"; +import "../src/contracts/libraries/AccountingMath.sol"; contract AccountingMathTest is Test { function testWithBundlerSurcharge() public { diff --git a/test/AtlETH.t.sol b/test/AtlETH.t.sol index 31ad0787d..76bc505b8 100644 --- a/test/AtlETH.t.sol +++ b/test/AtlETH.t.sol @@ -4,8 +4,8 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import {AtlasEvents} from "src/contracts/types/AtlasEvents.sol"; -import {AtlasErrors} from "src/contracts/types/AtlasErrors.sol"; +import {AtlasEvents} from "../src/contracts/types/AtlasEvents.sol"; +import {AtlasErrors} from "../src/contracts/types/AtlasErrors.sol"; contract AtlETHTest is BaseTest { diff --git a/test/Atlas.t.sol b/test/Atlas.t.sol index f64d010cf..6fdf8fa25 100644 --- a/test/Atlas.t.sol +++ b/test/Atlas.t.sol @@ -3,23 +3,24 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { UserOperationBuilder } from "test/base/builders/UserOperationBuilder.sol"; - -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; -import { Sorter } from "src/contracts/helpers/Sorter.sol"; -import { Simulator } from "src/contracts/helpers/Simulator.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/LockTypes.sol"; - import { LibSort } from "solady/utils/LibSort.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; +import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; + +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; +import { Sorter } from "../src/contracts/helpers/Sorter.sol"; +import { Simulator } from "../src/contracts/helpers/Simulator.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import "../src/contracts/types/LockTypes.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; + + // These tests focus on the functions found in the Atlas.sol file contract AtlasTest is BaseTest { diff --git a/test/AtlasVerification.t.sol b/test/AtlasVerification.t.sol index d0f09628e..c703cafc7 100644 --- a/test/AtlasVerification.t.sol +++ b/test/AtlasVerification.t.sol @@ -3,18 +3,18 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { AtlasVerification, USER_TYPEHASH_DEFAULT, USER_TYPEHASH_TRUSTED } from "src/contracts/atlas/AtlasVerification.sol"; -import { DAppConfig, CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { ValidCallsResult } from "src/contracts/types/ValidCalls.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { AtlasVerification, USER_TYPEHASH_DEFAULT, USER_TYPEHASH_TRUSTED } from "../src/contracts/atlas/AtlasVerification.sol"; +import { DAppConfig, CallConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { ValidCallsResult } from "../src/contracts/types/ValidCalls.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; import { DummyDAppControl } from "./base/DummyDAppControl.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { SolverOutcome } from "src/contracts/types/EscrowTypes.sol"; +import { CallVerification } from "../src/contracts/libraries/CallVerification.sol"; +import { CallBits } from "../src/contracts/libraries/CallBits.sol"; +import { SolverOutcome } from "../src/contracts/types/EscrowTypes.sol"; import { DummyDAppControlBuilder } from "./helpers/DummyDAppControlBuilder.sol"; import { CallConfigBuilder } from "./helpers/CallConfigBuilder.sol"; import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; diff --git a/test/DAppIntegration.t.sol b/test/DAppIntegration.t.sol index 7bbb5c08e..3a74750b4 100644 --- a/test/DAppIntegration.t.sol +++ b/test/DAppIntegration.t.sol @@ -3,11 +3,11 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; -import { DAppIntegration } from "src/contracts/atlas/DAppIntegration.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; +import { DAppIntegration } from "../src/contracts/atlas/DAppIntegration.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; import { DummyDAppControl, CallConfigBuilder } from "./base/DummyDAppControl.sol"; diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index e789f0196..ec8660c62 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -5,12 +5,12 @@ import "forge-std/Test.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import { EscrowBits } from "src/contracts/libraries/EscrowBits.sol"; +import { IAtlas } from "../src/contracts/interfaces/IAtlas.sol"; +import { IDAppControl } from "../src/contracts/interfaces/IDAppControl.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; +import { CallBits } from "../src/contracts/libraries/CallBits.sol"; +import { EscrowBits } from "../src/contracts/libraries/EscrowBits.sol"; import { DummyDAppControl } from "./base/DummyDAppControl.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; @@ -21,11 +21,11 @@ import { SolverOperationBuilder } from "./base/builders/SolverOperationBuilder.s import { DAppOperationBuilder } from "./base/builders/DAppOperationBuilder.sol"; import { GasSponsorDAppControl } from "./base/GasSponsorDAppControl.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/EscrowTypes.sol"; contract EscrowTest is BaseTest { using CallBits for CallConfig; diff --git a/test/ExPost.t.sol b/test/ExPost.t.sol index 49dc800c2..c3ff5798a 100644 --- a/test/ExPost.t.sol +++ b/test/ExPost.t.sol @@ -1,31 +1,27 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; +import "forge-std/Test.sol"; + import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; - -import { Atlas } from "src/contracts/atlas/Atlas.sol"; - -import { Result } from "src/contracts/helpers/Simulator.sol"; +import { IExecutionEnvironment } from "../src/contracts/interfaces/IExecutionEnvironment.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { Result } from "../src/contracts/helpers/Simulator.sol"; +import { V2ExPost } from "../src/contracts/examples/ex-post-mev-example/V2ExPost.sol"; +import { SolverExPost } from "../src/contracts/solver/src/TestSolverExPost.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; -import { V2ExPost } from "src/contracts/examples/ex-post-mev-example/V2ExPost.sol"; - -import { SolverExPost } from "src/contracts/solver/src/TestSolverExPost.sol"; - -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import "../src/contracts/types/ConfigTypes.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import { V2Helper } from "./V2Helper.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; - -import "forge-std/Test.sol"; contract ExPostTest is BaseTest { /// forge-config: default.gas_price = 15000000000 diff --git a/test/ExecutionBase.t.sol b/test/ExecutionBase.t.sol index 5cb1a0b11..9a9debdc7 100644 --- a/test/ExecutionBase.t.sol +++ b/test/ExecutionBase.t.sol @@ -5,12 +5,12 @@ import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { Base } from "src/contracts/common/ExecutionBase.sol"; -import { ExecutionPhase } from "src/contracts/types/LockTypes.sol"; +import { Base } from "../src/contracts/common/ExecutionBase.sol"; +import { ExecutionPhase } from "../src/contracts/types/LockTypes.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../src/contracts/libraries/SafetyBits.sol"; -import "src/contracts/libraries/SafetyBits.sol"; +import "../src/contracts/libraries/SafetyBits.sol"; contract ExecutionBaseTest is BaseTest { using SafetyBits for Context; diff --git a/test/ExecutionEnvironment.t.sol b/test/ExecutionEnvironment.t.sol index 5162118b3..aa94f361b 100644 --- a/test/ExecutionEnvironment.t.sol +++ b/test/ExecutionEnvironment.t.sol @@ -5,26 +5,26 @@ import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import { MockSafetyLocks } from "./SafetyLocks.t.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; +import { DAppControl } from "../src/contracts/dapp/DAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlas } from "../src/contracts/interfaces/IAtlas.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; +import { SafetyBits } from "../src/contracts/libraries/SafetyBits.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/EscrowTypes.sol"; -import "src/contracts/libraries/CallBits.sol"; +import "../src/contracts/libraries/CallBits.sol"; /// @notice ExecutionEnvironmentTest tests deploy ExecutionEnvironment contracts through the factory. Because all calls /// are delegated through the mimic contract, the reported coverage is at 0%, but the actual coverage is close to 100%. diff --git a/test/FLOnline.t.sol b/test/FLOnline.t.sol index 082507d48..63badd069 100644 --- a/test/FLOnline.t.sol +++ b/test/FLOnline.t.sol @@ -5,17 +5,17 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; -import { FastLaneOnlineOuter } from "src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol"; -import { FastLaneOnlineInner } from "src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol"; -import { SwapIntent, BaselineCall, Reputation } from "src/contracts/examples/fastlane-online/FastLaneTypes.sol"; -import { FastLaneOnlineErrors } from "src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol"; +import { FastLaneOnlineOuter } from "../src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol"; +import { FastLaneOnlineInner } from "../src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol"; +import { SwapIntent, BaselineCall, Reputation } from "../src/contracts/examples/fastlane-online/FastLaneTypes.sol"; +import { FastLaneOnlineErrors } from "../src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol"; -import { IUniswapV2Router02 } from "test/base/interfaces/IUniswapV2Router.sol"; +import { IUniswapV2Router02 } from "./base/interfaces/IUniswapV2Router.sol"; contract FastLaneOnlineTest is BaseTest { struct FastOnlineSwapArgs { diff --git a/test/Factory.t.sol b/test/Factory.t.sol index 814db49c3..032fde60d 100644 --- a/test/Factory.t.sol +++ b/test/Factory.t.sol @@ -3,15 +3,15 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; -import { Factory } from "src/contracts/atlas/Factory.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; +import { Factory } from "../src/contracts/atlas/Factory.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; import { DummyDAppControl, CallConfigBuilder } from "./base/DummyDAppControl.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; -import "src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/UserOperation.sol"; import "./base/TestUtils.sol"; diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index 19786c81f..a313d2abd 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -5,19 +5,19 @@ import "forge-std/Test.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import { ArbitrageTest } from "./base/ArbitrageTest.t.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import { SolverOutcome } from "src/contracts/types/EscrowTypes.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/DAppOperation.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; +import { DAppControl } from "../src/contracts/dapp/DAppControl.sol"; +import { CallConfig } from "../src/contracts/types/ConfigTypes.sol"; +import { SolverOutcome } from "../src/contracts/types/EscrowTypes.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; +import { IAtlas } from "../src/contracts/interfaces/IAtlas.sol"; import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; import { SolverOperationBuilder } from "./base/builders/SolverOperationBuilder.sol"; import { DAppOperationBuilder } from "./base/builders/DAppOperationBuilder.sol"; diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index 39f62bfb0..e520f937d 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -5,24 +5,24 @@ import "forge-std/Test.sol"; import { SafeCast } from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol"; -import { GasAccounting } from "src/contracts/atlas/GasAccounting.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { AtlasConstants } from "src/contracts/types/AtlasConstants.sol"; +import { GasAccounting } from "../src/contracts/atlas/GasAccounting.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; +import { AtlasConstants } from "../src/contracts/types/AtlasConstants.sol"; -import { EscrowBits } from "src/contracts/libraries/EscrowBits.sol"; -import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; +import { EscrowBits } from "../src/contracts/libraries/EscrowBits.sol"; +import { IL2GasCalculator } from "../src/contracts/interfaces/IL2GasCalculator.sol"; -import "src/contracts/libraries/AccountingMath.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/libraries/AccountingMath.sol"; +import "../src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/ConfigTypes.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; -import { TestAtlas } from "test/base/TestAtlas.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; +import { TestAtlas } from "./base/TestAtlas.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; contract MockGasAccounting is TestAtlas, BaseTest { uint256 public constant MOCK_SOLVER_GAS_LIMIT = 500_000; diff --git a/test/MainTest.t.sol b/test/MainTest.t.sol index 0b9716287..6883c3a85 100644 --- a/test/MainTest.t.sol +++ b/test/MainTest.t.sol @@ -4,25 +4,25 @@ pragma solidity 0.8.25; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { IExecutionEnvironment } from "../src/contracts/interfaces/IExecutionEnvironment.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { Mimic } from "src/contracts/common/Mimic.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { Mimic } from "../src/contracts/common/Mimic.sol"; -import { V2DAppControl } from "src/contracts/examples/v2-example/V2DAppControl.sol"; +import { V2DAppControl } from "../src/contracts/examples/v2-example/V2DAppControl.sol"; -import { Solver } from "src/contracts/solver/src/TestSolver.sol"; +import { Solver } from "../src/contracts/solver/src/TestSolver.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import { V2Helper } from "./V2Helper.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; import "forge-std/Test.sol"; diff --git a/test/Mimic.t.sol b/test/Mimic.t.sol index fcb1ad877..f1a2445c9 100644 --- a/test/Mimic.t.sol +++ b/test/Mimic.t.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { Mimic } from "src/contracts/common/Mimic.sol"; +import { Mimic } from "../src/contracts/common/Mimic.sol"; contract MimicTest is Test { function testMimicDelegatecall() public { diff --git a/test/NonceManager.t.sol b/test/NonceManager.t.sol index 07f2d6974..083648fd6 100644 --- a/test/NonceManager.t.sol +++ b/test/NonceManager.t.sol @@ -3,13 +3,13 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { NonceManager } from "src/contracts/atlas/NonceManager.sol"; -import { DAppConfig, CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { ValidCallsResult } from "src/contracts/types/ValidCalls.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; +import { NonceManager } from "../src/contracts/atlas/NonceManager.sol"; +import { DAppConfig, CallConfig } from "../src/contracts/types/ConfigTypes.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { DAppOperation } from "../src/contracts/types/DAppOperation.sol"; +import { ValidCallsResult } from "../src/contracts/types/ValidCalls.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; import { AtlasVerificationBase } from "./AtlasVerification.t.sol"; contract MockNonceManager is NonceManager { diff --git a/test/OEV.t.sol b/test/OEV.t.sol index 58a57fdc2..0ad596d7d 100644 --- a/test/OEV.t.sol +++ b/test/OEV.t.sol @@ -6,19 +6,19 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; import { UserOperationBuilder } from "test/base/builders/UserOperationBuilder.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; -import { ChainlinkDAppControl, Oracle, Role } from "src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; -import { ChainlinkAtlasWrapper } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; -import { AggregatorV2V3Interface } from "src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { ChainlinkDAppControl, Oracle, Role } from "../src/contracts/examples/oev-example/ChainlinkDAppControl.sol"; +import { ChainlinkAtlasWrapper } from "../src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol"; +import { AggregatorV2V3Interface } from "../src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; // Using this Chainlink update to ETHUSD feed as an example: diff --git a/test/OEValt.t.sol b/test/OEValt.t.sol index 65f418191..fc8ffa4a2 100644 --- a/test/OEValt.t.sol +++ b/test/OEValt.t.sol @@ -6,18 +6,18 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; import { UserOperationBuilder } from "test/base/builders/UserOperationBuilder.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; -import { ChainlinkDAppControl, Oracle, Role } from "src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol"; -import {ChainlinkAtlasWrapper, IChainlinkFeed } from "src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { ChainlinkDAppControl, Oracle, Role } from "../src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol"; +import {ChainlinkAtlasWrapper, IChainlinkFeed } from "../src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; // Using this Chainlink update to ETHUSD feed as an example: diff --git a/test/Permit69.t.sol b/test/Permit69.t.sol index b5b47f4c8..36adf4065 100644 --- a/test/Permit69.t.sol +++ b/test/Permit69.t.sol @@ -6,20 +6,20 @@ import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import "./base/TestUtils.sol"; -import { Permit69 } from "src/contracts/atlas/Permit69.sol"; -import { Mimic } from "src/contracts/common/Mimic.sol"; +import { Permit69 } from "../src/contracts/atlas/Permit69.sol"; +import { Mimic } from "../src/contracts/common/Mimic.sol"; -import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "src/contracts/atlas/Permit69.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "../src/contracts/atlas/Permit69.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; -import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; +import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; -import { Atlas } from "src/contracts/atlas/Atlas.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; +import { Atlas } from "../src/contracts/atlas/Atlas.sol"; +import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; contract Permit69Test is BaseTest { diff --git a/test/SafetyLocks.t.sol b/test/SafetyLocks.t.sol index 5fab4b491..43faa3edd 100644 --- a/test/SafetyLocks.t.sol +++ b/test/SafetyLocks.t.sol @@ -3,12 +3,12 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { SafetyLocks } from "src/contracts/atlas/SafetyLocks.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { SafetyLocks } from "../src/contracts/atlas/SafetyLocks.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; contract MockSafetyLocks is SafetyLocks { constructor() SafetyLocks(0, address(0), address(0), address(0), address(0)) { } diff --git a/test/Simulator.t.sol b/test/Simulator.t.sol index aef3e2360..61cae787e 100644 --- a/test/Simulator.t.sol +++ b/test/Simulator.t.sol @@ -3,16 +3,16 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { Result } from "src/contracts/helpers/Simulator.sol"; -import { DAppConfig, CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; -import { ValidCallsResult } from "src/contracts/types/ValidCalls.sol"; -import { SolverOutcome } from "src/contracts/types/EscrowTypes.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; +import { Result } from "../src/contracts/helpers/Simulator.sol"; +import { DAppConfig, CallConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; +import { ValidCallsResult } from "../src/contracts/types/ValidCalls.sol"; +import { SolverOutcome } from "../src/contracts/types/EscrowTypes.sol"; +import { CallVerification } from "../src/contracts/libraries/CallVerification.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; @@ -22,7 +22,7 @@ import { CallConfigBuilder } from "./helpers/CallConfigBuilder.sol"; import { DummyDAppControlBuilder } from "./helpers/DummyDAppControlBuilder.sol"; import { DummyDAppControl } from "./base/DummyDAppControl.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; contract SimulatorTest is BaseTest { diff --git a/test/Sorter.t.sol b/test/Sorter.t.sol index 55ea02771..7f2224504 100644 --- a/test/Sorter.t.sol +++ b/test/Sorter.t.sol @@ -9,8 +9,8 @@ import { CallConfigBuilder } from "./helpers/CallConfigBuilder.sol"; import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; import { SolverOperationBuilder } from "./base/builders/SolverOperationBuilder.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/SolverOperation.sol"; contract SorterTest is BaseTest { DummyDAppControl dAppControl; diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 536cbe697..3c2d08a35 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -3,10 +3,10 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { Storage } from "src/contracts/atlas/Storage.sol"; -import "src/contracts/types/LockTypes.sol"; +import { Storage } from "../src/contracts/atlas/Storage.sol"; +import "../src/contracts/types/LockTypes.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; contract StorageTest is BaseTest { using stdStorage for StdStorage; diff --git a/test/Surcharge.t.sol b/test/Surcharge.t.sol index 2c1516b13..53ea362fe 100644 --- a/test/Surcharge.t.sol +++ b/test/Surcharge.t.sol @@ -3,8 +3,8 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { AtlasEvents } from "src/contracts/types/AtlasEvents.sol"; -import { AtlasErrors } from "src/contracts/types/AtlasErrors.sol"; +import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; +import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; contract SurchargeTest is BaseTest { using stdStorage for StdStorage; diff --git a/test/SwapIntent.t.sol b/test/SwapIntent.t.sol index 09ccef145..37f16b513 100644 --- a/test/SwapIntent.t.sol +++ b/test/SwapIntent.t.sol @@ -6,19 +6,19 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; import { SwapIntentDAppControl, SwapIntent, Condition -} from "src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +} from "../src/contracts/examples/intents-example/SwapIntentDAppControl.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; interface IUniV2Router02 { function swapExactTokensForTokens( diff --git a/test/SwapIntentInvertBid.t.sol b/test/SwapIntentInvertBid.t.sol index 4d8e8abe3..5ab8aadf2 100644 --- a/test/SwapIntentInvertBid.t.sol +++ b/test/SwapIntentInvertBid.t.sol @@ -5,16 +5,16 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import { SwapIntent, SwapIntentInvertBidDAppControl } from "src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol"; -import { SolverBaseInvertBid } from "src/contracts/solver/SolverBaseInvertBid.sol"; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import { SwapIntent, SwapIntentInvertBidDAppControl } from "../src/contracts/examples/intents-example/SwapIntentInvertBidDAppControl.sol"; +import { SolverBaseInvertBid } from "../src/contracts/solver/SolverBaseInvertBid.sol"; +import { DAppControl } from "../src/contracts/dapp/DAppControl.sol"; +import { CallConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; contract SwapIntentTest is BaseTest { Sig public sig; diff --git a/test/TrebleSwap.t.sol b/test/TrebleSwap.t.sol index 9ac734205..ecb727f13 100644 --- a/test/TrebleSwap.t.sol +++ b/test/TrebleSwap.t.sol @@ -5,16 +5,16 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import { DAppOperation } from "src/contracts/types/DAppOperation.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import { DAppOperation } from "../src/contracts/types/DAppOperation.sol"; +import { CallVerification } from "../src/contracts/libraries/CallVerification.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; -import { TrebleSwapDAppControl } from "src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol"; +import { TrebleSwapDAppControl } from "../src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol"; contract TrebleSwapTest is BaseTest { struct SwapTokenInfo { diff --git a/test/V2Helper.sol b/test/V2Helper.sol index 34880fead..442d7f01a 100644 --- a/test/V2Helper.sol +++ b/test/V2Helper.sol @@ -1,18 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; -import { IUniswapV2Pair } from "src/contracts/examples/v2-example/interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Pair } from "../src/contracts/examples/v2-example/interfaces/IUniswapV2Pair.sol"; -import { BlindBackrun } from "src/contracts/solver/src/BlindBackrun/BlindBackrun.sol"; +import { BlindBackrun } from "../src/contracts/solver/src/BlindBackrun/BlindBackrun.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "src/contracts/types/LockTypes.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/SolverOperation.sol"; +import "../src/contracts/types/UserOperation.sol"; +import "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/EscrowTypes.sol"; +import "../src/contracts/types/LockTypes.sol"; +import "../src/contracts/types/ConfigTypes.sol"; import "forge-std/Test.sol"; diff --git a/test/V2RewardDAppControl.t.sol b/test/V2RewardDAppControl.t.sol index 62154d346..4a6776273 100644 --- a/test/V2RewardDAppControl.t.sol +++ b/test/V2RewardDAppControl.t.sol @@ -6,18 +6,18 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; -import { BaseTest } from "test/base/BaseTest.t.sol"; -import { TxBuilder } from "src/contracts/helpers/TxBuilder.sol"; -import { UserOperationBuilder } from "test/base/builders/UserOperationBuilder.sol"; - -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { DAppConfig } from "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/DAppOperation.sol"; - -import { V2RewardDAppControl } from "src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; -import { IUniswapV2Router01, IUniswapV2Router02 } from "src/contracts/examples/v2-example-router/interfaces/IUniswapV2Router.sol"; -import { SolverBase } from "src/contracts/solver/SolverBase.sol"; +import { BaseTest } from "./base/BaseTest.t.sol"; +import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; +import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; + +import { SolverOperation } from "../src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../src/contracts/types/UserOperation.sol"; +import { DAppConfig } from "../src/contracts/types/ConfigTypes.sol"; +import "../src/contracts/types/DAppOperation.sol"; + +import { V2RewardDAppControl } from "../src/contracts/examples/v2-example-router/V2RewardDAppControl.sol"; +import { IUniswapV2Router01, IUniswapV2Router02 } from "../src/contracts/examples/v2-example-router/interfaces/IUniswapV2Router.sol"; +import { SolverBase } from "../src/contracts/solver/SolverBase.sol"; contract V2RewardDAppControlTest is BaseTest { address V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index e74653c17..4425404c3 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; +import { DAppControl } from "../../src/contracts/dapp/DAppControl.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; +import "../../src/contracts/types/ConfigTypes.sol"; +import "../../src/contracts/types/UserOperation.sol"; +import "../../src/contracts/types/SolverOperation.sol"; import "forge-std/Test.sol"; diff --git a/test/base/GasSponsorDAppControl.sol b/test/base/GasSponsorDAppControl.sol index 3de66a943..c9de344cd 100644 --- a/test/base/GasSponsorDAppControl.sol +++ b/test/base/GasSponsorDAppControl.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { DAppControl } from "src/contracts/dapp/DAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnvironment.sol"; +import { DAppControl } from "../../src/contracts/dapp/DAppControl.sol"; +import { IAtlas } from "../../src/contracts/interfaces/IAtlas.sol"; +import { IExecutionEnvironment } from "../../src/contracts/interfaces/IExecutionEnvironment.sol"; -import "src/contracts/types/ConfigTypes.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; +import "../../src/contracts/types/ConfigTypes.sol"; +import "../../src/contracts/types/UserOperation.sol"; +import "../../src/contracts/types/SolverOperation.sol"; import "forge-std/Test.sol"; diff --git a/test/base/TestUtils.sol b/test/base/TestUtils.sol index 50004d1ba..4b6cae7ca 100644 --- a/test/base/TestUtils.sol +++ b/test/base/TestUtils.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { Mimic } from "src/contracts/common/Mimic.sol"; +import { IDAppControl } from "../../src/contracts/interfaces/IDAppControl.sol"; +import { Mimic } from "../../src/contracts/common/Mimic.sol"; -import "src/contracts/types/UserOperation.sol"; -import "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../../src/contracts/types/UserOperation.sol"; +import "../../src/contracts/types/SolverOperation.sol"; +import "../../src/contracts/types/ConfigTypes.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; +import { CallBits } from "../../src/contracts/libraries/CallBits.sol"; library TestUtils { using CallBits for uint32; diff --git a/test/base/builders/DAppOperationBuilder.sol b/test/base/builders/DAppOperationBuilder.sol index cf0979bba..76cb6c8f4 100644 --- a/test/base/builders/DAppOperationBuilder.sol +++ b/test/base/builders/DAppOperationBuilder.sol @@ -3,17 +3,17 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; -import "src/contracts/types/DAppOperation.sol"; +import { UserOperation } from "../../../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../../../src/contracts/types/SolverOperation.sol"; +import "../../../src/contracts/types/DAppOperation.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; +import { CallVerification } from "../../../src/contracts/libraries/CallVerification.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IDAppControl } from "../../../src/contracts/interfaces/IDAppControl.sol"; +import { IAtlasVerification } from "../../../src/contracts/interfaces/IAtlasVerification.sol"; +import { IAtlas } from "../../../src/contracts/interfaces/IAtlas.sol"; -import "src/contracts/types/ConfigTypes.sol"; +import "../../../src/contracts/types/ConfigTypes.sol"; contract DAppOperationBuilder is Test { using CallVerification for UserOperation; diff --git a/test/base/builders/SolverOperationBuilder.sol b/test/base/builders/SolverOperationBuilder.sol index 4350ae75a..9b3e9e53d 100644 --- a/test/base/builders/SolverOperationBuilder.sol +++ b/test/base/builders/SolverOperationBuilder.sol @@ -3,15 +3,15 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { SolverOperation } from "src/contracts/types/SolverOperation.sol"; +import { UserOperation } from "../../../src/contracts/types/UserOperation.sol"; +import { SolverOperation } from "../../../src/contracts/types/SolverOperation.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; +import { CallVerification } from "../../../src/contracts/libraries/CallVerification.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; -import { IDAppControl } from "src/contracts/interfaces/IDAppControl.sol"; -import { IAtlas } from "src/contracts/interfaces/IAtlas.sol"; +import { IAtlas } from "../../../src/contracts/interfaces/IAtlas.sol"; +import { IAtlasVerification } from "../../../src/contracts/interfaces/IAtlasVerification.sol"; +import { IDAppControl } from "../../../src/contracts/interfaces/IDAppControl.sol"; +import { IAtlas } from "../../../src/contracts/interfaces/IAtlas.sol"; contract SolverOperationBuilder is Test { using CallVerification for UserOperation; diff --git a/test/base/builders/UserOperationBuilder.sol b/test/base/builders/UserOperationBuilder.sol index 26e24e56b..126892e08 100644 --- a/test/base/builders/UserOperationBuilder.sol +++ b/test/base/builders/UserOperationBuilder.sol @@ -3,11 +3,11 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { UserOperation } from "src/contracts/types/UserOperation.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; +import { UserOperation } from "../../../src/contracts/types/UserOperation.sol"; +import { CallConfig } from "../../../src/contracts/types/ConfigTypes.sol"; +import { CallBits } from "../../../src/contracts/libraries/CallBits.sol"; -import { IAtlasVerification } from "src/contracts/interfaces/IAtlasVerification.sol"; +import { IAtlasVerification } from "../../../src/contracts/interfaces/IAtlasVerification.sol"; contract UserOperationBuilder is Test { using CallBits for uint32; diff --git a/test/helpers/CallConfigBuilder.sol b/test/helpers/CallConfigBuilder.sol index cf3b57da7..82800d46c 100644 --- a/test/helpers/CallConfigBuilder.sol +++ b/test/helpers/CallConfigBuilder.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; +import { CallConfig } from "../../src/contracts/types/ConfigTypes.sol"; import "forge-std/Test.sol"; diff --git a/test/helpers/DummyDAppControlBuilder.sol b/test/helpers/DummyDAppControlBuilder.sol index d9eaafd23..5ef97d908 100644 --- a/test/helpers/DummyDAppControlBuilder.sol +++ b/test/helpers/DummyDAppControlBuilder.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import { DummyDAppControl } from "test/base/DummyDAppControl.sol"; -import { CallConfig } from "src/contracts/types/ConfigTypes.sol"; -import { AtlasVerification } from "src/contracts/atlas/AtlasVerification.sol"; +import { DummyDAppControl } from "../base/DummyDAppControl.sol"; +import { CallConfig } from "../../src/contracts/types/ConfigTypes.sol"; +import { AtlasVerification } from "../../src/contracts/atlas/AtlasVerification.sol"; import "forge-std/Test.sol"; diff --git a/test/libraries/CallBits.t.sol b/test/libraries/CallBits.t.sol index ffc093cad..0c5d6f5fd 100644 --- a/test/libraries/CallBits.t.sol +++ b/test/libraries/CallBits.t.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; -import "src/contracts/types/UserOperation.sol"; -import "test/base/TestUtils.sol"; +import { CallBits } from "../../src/contracts/libraries/CallBits.sol"; +import "../../src/contracts/types/UserOperation.sol"; +import "../base/TestUtils.sol"; contract CallBitsTest is Test { using CallBits for uint32; diff --git a/test/libraries/CallVerification.t.sol b/test/libraries/CallVerification.t.sol index 665224198..a5c7aa404 100644 --- a/test/libraries/CallVerification.t.sol +++ b/test/libraries/CallVerification.t.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { CallVerification } from "src/contracts/libraries/CallVerification.sol"; -import "src/contracts/types/UserOperation.sol"; -import "test/base/TestUtils.sol"; +import { CallVerification } from "../../src/contracts/libraries/CallVerification.sol"; +import "../../src/contracts/types/UserOperation.sol"; +import "../base/TestUtils.sol"; contract CallVerificationTest is Test { using CallVerification for UserOperation; diff --git a/test/libraries/EscrowBits.t.sol b/test/libraries/EscrowBits.t.sol index c404707d1..ff5f829e1 100644 --- a/test/libraries/EscrowBits.t.sol +++ b/test/libraries/EscrowBits.t.sol @@ -3,9 +3,9 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { EscrowBits } from "src/contracts/libraries/EscrowBits.sol"; -import "src/contracts/types/EscrowTypes.sol"; -import "test/base/TestUtils.sol"; +import { EscrowBits } from "../../src/contracts/libraries/EscrowBits.sol"; +import "../../src/contracts/types/EscrowTypes.sol"; +import "../base/TestUtils.sol"; contract EscrowBitsTest is Test { using EscrowBits for uint256; diff --git a/test/libraries/SafetyBits.t.sol b/test/libraries/SafetyBits.t.sol index 52ba6c979..d9f4c06f7 100644 --- a/test/libraries/SafetyBits.t.sol +++ b/test/libraries/SafetyBits.t.sol @@ -3,13 +3,13 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; -import { SafetyBits } from "src/contracts/libraries/SafetyBits.sol"; -import "src/contracts/types/LockTypes.sol"; -import "test/base/TestUtils.sol"; +import { SafetyBits } from "../../src/contracts/libraries/SafetyBits.sol"; +import "../../src/contracts/types/LockTypes.sol"; +import "../base/TestUtils.sol"; -import { CallBits } from "src/contracts/libraries/CallBits.sol"; +import { CallBits } from "../../src/contracts/libraries/CallBits.sol"; -import { CallConfigIndex } from "src/contracts/types/ConfigTypes.sol"; +import { CallConfigIndex } from "../../src/contracts/types/ConfigTypes.sol"; contract SafetyBitsTest is Test { using SafetyBits for Context; From 8be2960a348e5cd664f217415c3e7da9eda47dc1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Sep 2024 21:21:27 -0700 Subject: [PATCH 33/70] 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 34/70] 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 c560ce5f4fd38b7e8d65d5704c9f1b589789e8b4 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Wed, 25 Sep 2024 11:05:33 +0400 Subject: [PATCH 35/70] lower calldata premium value --- lib/forge-std | 2 +- lib/solady | 2 +- src/contracts/gasCalculator/BaseGasCalculator.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index 1ce7535a5..5a802d7c1 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1ce7535a517406b9aec7ea1ea27c1b41376f712c +Subproject commit 5a802d7c10abb4bbfb3e7214c75052ef9e6a06f8 diff --git a/lib/solady b/lib/solady index f833eadd4..42af395e6 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit f833eadd4591da7e8e455eab779bf1d918486847 +Subproject commit 42af395e631fcc9d640eddf11c57c6f1ca3f9103 diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index d572b8e19..97e404a66 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -12,7 +12,7 @@ interface IGasPriceOracle { } contract BaseGasCalculator is IL2GasCalculator, Ownable { - uint256 internal constant _CALLDATA_LENGTH_PREMIUM = 32; + uint256 internal constant _CALLDATA_LENGTH_PREMIUM = 16; uint256 internal constant _BASE_TRANSACTION_GAS_USED = 21_000; address public immutable GAS_PRICE_ORACLE; From 1dd15ac3d6c0111bde494a436825acdc60188d69 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:19:35 +0200 Subject: [PATCH 36/70] refactor: set surcharge rates in constructor --- script/deploy-atlas.s.sol | 8 +- src/contracts/atlas/AtlETH.sol | 12 ++- src/contracts/atlas/Atlas.sol | 12 ++- src/contracts/atlas/Escrow.sol | 12 ++- src/contracts/atlas/GasAccounting.sol | 28 ++++-- src/contracts/atlas/Permit69.sol | 12 ++- src/contracts/atlas/SafetyLocks.sol | 12 ++- src/contracts/atlas/Storage.sol | 8 +- src/contracts/libraries/AccountingMath.sol | 33 +++++-- test/AccountingMath.t.sol | 83 +++++++++------- test/{Atlas.t.sol => BidFinding.t.sol} | 59 +---------- test/DAppIntegration.t.sol | 5 + test/Factory.t.sol | 5 + test/GasAccounting.t.sol | 18 ++-- test/Permit69.t.sol | 85 ++++++++-------- test/SafetyLocks.t.sol | 2 +- test/Storage.t.sol | 108 +++++++++++++++++---- test/base/BaseTest.t.sol | 4 + test/base/TestAtlas.sol | 13 ++- 19 files changed, 327 insertions(+), 192 deletions(-) rename test/{Atlas.t.sol => BidFinding.t.sol} (63%) diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 8531c62e4..2cc7eb957 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -14,6 +14,10 @@ import { Sorter } from "src/contracts/helpers/Sorter.sol"; import { ExecutionEnvironment } from "src/contracts/common/ExecutionEnvironment.sol"; contract DeployAtlasScript is DeployBaseScript { + uint256 ESCROW_DURATION = 64; + uint256 ATLAS_SURCHARGE_RATE = 1_000_000; // 10% + uint256 BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% + function run() external { console.log("\n=== DEPLOYING Atlas ===\n"); @@ -37,7 +41,9 @@ contract DeployAtlasScript is DeployBaseScript { ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedAtlasAddr); atlas = new Atlas({ - escrowDuration: 64, + escrowDuration: ESCROW_DURATION, + atlasSurchargeRate: ATLAS_SURCHARGE_RATE, + bundlerSurchargeRate: BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: expectedSimulatorAddr, executionTemplate: address(execEnvTemplate), diff --git a/src/contracts/atlas/AtlETH.sol b/src/contracts/atlas/AtlETH.sol index e39120fb4..d9bf8a654 100644 --- a/src/contracts/atlas/AtlETH.sol +++ b/src/contracts/atlas/AtlETH.sol @@ -11,12 +11,22 @@ import "src/contracts/types/EscrowTypes.sol"; abstract contract AtlETH is Permit69 { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - Permit69(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + Permit69( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { } /*////////////////////////////////////////////////////////////// diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index c17d08258..909e4c56e 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -28,13 +28,23 @@ contract Atlas is Escrow, Factory { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator, address executionTemplate ) - Escrow(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + Escrow( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) Factory(executionTemplate) { } diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index db81645c1..39a243f59 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -31,12 +31,22 @@ abstract contract Escrow is AtlETH { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - AtlETH(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + AtlETH( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { if (escrowDuration == 0) revert InvalidEscrowDuration(); } diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 63f9cdd48..ab1053b00 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -21,12 +21,22 @@ abstract contract GasAccounting is SafetyLocks { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - SafetyLocks(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + SafetyLocks( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { } /// @notice Sets the initial accounting values for the metacall transaction. @@ -35,10 +45,10 @@ abstract contract GasAccounting is SafetyLocks { uint256 _rawClaims = (FIXED_GAS_OFFSET + gasMarker) * tx.gasprice; // Set any withdraws or deposits - _setClaims(_rawClaims.withBundlerSurcharge()); + _setClaims(_rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE)); // Atlas surcharge is based on the raw claims value. - _setFees(_rawClaims.getAtlasSurcharge()); + _setFees(_rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE)); _setDeposits(msg.value); // Explicitly set writeoffs and withdrawals to 0 in case multiple metacalls in single tx. @@ -281,16 +291,16 @@ abstract contract GasAccounting is SafetyLocks { if (result.bundlersFault()) { // CASE: Solver is not responsible for the failure of their operation, so we blame the bundler // and reduce the total amount refunded to the bundler - _setWriteoffs(writeoffs() + _gasUsed.withAtlasAndBundlerSurcharges()); + _setWriteoffs(writeoffs() + _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE)); } else { // CASE: Solver failed, so we calculate what they owe. - uint256 _gasUsedWithSurcharges = _gasUsed.withAtlasAndBundlerSurcharges(); + uint256 _gasUsedWithSurcharges = _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); _assign(solverOp.from, _gasUsedWithSurcharges, _gasUsedWithSurcharges, false); } } function _writeOffBidFindGasCost(uint256 gasUsed) internal { - _setWriteoffs(writeoffs() + gasUsed.withAtlasAndBundlerSurcharges()); + _setWriteoffs(writeoffs() + gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE)); } /// @param ctx Context struct containing relevant context information for the Atlas auction. @@ -332,9 +342,9 @@ abstract contract GasAccounting is SafetyLocks { uint256 _gasRemainder = _gasLeft * tx.gasprice; // Calculate the preadjusted netAtlasGasSurcharge - netAtlasGasSurcharge = _fees - _gasRemainder.getAtlasSurcharge(); + netAtlasGasSurcharge = _fees - _gasRemainder.getSurcharge(ATLAS_SURCHARGE_RATE); - adjustedClaims -= _gasRemainder.withBundlerSurcharge(); + adjustedClaims -= _gasRemainder.withSurcharge(BUNDLER_SURCHARGE_RATE); adjustedWithdrawals += netAtlasGasSurcharge; S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; // Update the cumulative surcharge @@ -342,7 +352,7 @@ abstract contract GasAccounting is SafetyLocks { // gas rebate. By reducing the claims, solvers end up paying less in total. if (ctx.solverCount > 0) { // Calculate the unadjusted bundler gas surcharge - uint256 _grossBundlerGasSurcharge = adjustedClaims.withoutBundlerSurcharge(); + uint256 _grossBundlerGasSurcharge = adjustedClaims.withoutSurcharge(BUNDLER_SURCHARGE_RATE); // Calculate an estimate for how much gas should be remaining // NOTE: There is a free buffer of one SolverOperation because solverIndex starts at 0. diff --git a/src/contracts/atlas/Permit69.sol b/src/contracts/atlas/Permit69.sol index 6d6f7d0ba..44f5bc455 100644 --- a/src/contracts/atlas/Permit69.sol +++ b/src/contracts/atlas/Permit69.sol @@ -26,12 +26,22 @@ import "src/contracts/types/EscrowTypes.sol"; abstract contract Permit69 is GasAccounting { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - GasAccounting(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + GasAccounting( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { } /// @notice Verifies that the caller is an authorized Execution Environment contract. diff --git a/src/contracts/atlas/SafetyLocks.sol b/src/contracts/atlas/SafetyLocks.sol index 2b3d66b92..ad9384f36 100644 --- a/src/contracts/atlas/SafetyLocks.sol +++ b/src/contracts/atlas/SafetyLocks.sol @@ -18,12 +18,22 @@ abstract contract SafetyLocks is Storage { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - Storage(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + Storage( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { } /// @notice Sets the Atlas lock to the specified execution environment. diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 4a20052b1..251e4892b 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -18,6 +18,8 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { address public immutable SIMULATOR; address public immutable L2_GAS_CALCULATOR; uint256 public immutable ESCROW_DURATION; + uint256 public immutable ATLAS_SURCHARGE_RATE; + uint256 public immutable BUNDLER_SURCHARGE_RATE; // AtlETH public constants // These constants double as interface functions for the ERC20 standard, hence the lowercase naming convention. @@ -26,8 +28,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { uint8 public constant decimals = 18; // Gas Accounting public constants - uint256 public constant ATLAS_SURCHARGE_RATE = AccountingMath._ATLAS_SURCHARGE_RATE; - uint256 public constant BUNDLER_SURCHARGE_RATE = AccountingMath._BUNDLER_SURCHARGE_RATE; uint256 public constant SCALE = AccountingMath._SCALE; uint256 public constant FIXED_GAS_OFFSET = AccountingMath._FIXED_GAS_OFFSET; @@ -56,6 +56,8 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, @@ -67,6 +69,8 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { SIMULATOR = simulator; L2_GAS_CALCULATOR = l2GasCalculator; ESCROW_DURATION = escrowDuration; + ATLAS_SURCHARGE_RATE = atlasSurchargeRate; + BUNDLER_SURCHARGE_RATE = bundlerSurchargeRate; // Gas Accounting // Initialized with msg.value to seed flash loan liquidity diff --git a/src/contracts/libraries/AccountingMath.sol b/src/contracts/libraries/AccountingMath.sol index d30c044e1..2fd437832 100644 --- a/src/contracts/libraries/AccountingMath.sol +++ b/src/contracts/libraries/AccountingMath.sol @@ -3,27 +3,40 @@ pragma solidity 0.8.25; library AccountingMath { // Gas Accounting public constants - uint256 internal constant _ATLAS_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% - uint256 internal constant _BUNDLER_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% uint256 internal constant _SOLVER_GAS_LIMIT_BUFFER_PERCENTAGE = 500_000; // out of 10_000_000 = 5% uint256 internal constant _SCALE = 10_000_000; // 10_000_000 / 10_000_000 = 100% uint256 internal constant _FIXED_GAS_OFFSET = 85_000; - function withBundlerSurcharge(uint256 amount) internal pure returns (uint256 adjustedAmount) { - adjustedAmount = amount * (_SCALE + _BUNDLER_SURCHARGE_RATE) / _SCALE; + function withSurcharge(uint256 amount, uint256 surchargeRate) internal pure returns (uint256 adjustedAmount) { + adjustedAmount = amount * (_SCALE + surchargeRate) / _SCALE; } - function withoutBundlerSurcharge(uint256 amount) internal pure returns (uint256 unadjustedAmount) { - unadjustedAmount = amount * _SCALE / (_SCALE + _BUNDLER_SURCHARGE_RATE); + function withoutSurcharge(uint256 amount, uint256 surchargeRate) internal pure returns (uint256 unadjustedAmount) { + unadjustedAmount = amount * _SCALE / (_SCALE + surchargeRate); } - function withAtlasAndBundlerSurcharges(uint256 amount) internal pure returns (uint256 adjustedAmount) { - adjustedAmount = amount * (_SCALE + _ATLAS_SURCHARGE_RATE + _BUNDLER_SURCHARGE_RATE) / _SCALE; + function withSurcharges( + uint256 amount, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate + ) + internal + pure + returns (uint256 adjustedAmount) + { + adjustedAmount = amount * (_SCALE + atlasSurchargeRate + bundlerSurchargeRate) / _SCALE; } // gets the Atlas surcharge from an unadjusted amount - function getAtlasSurcharge(uint256 amount) internal pure returns (uint256 surcharge) { - surcharge = amount * _ATLAS_SURCHARGE_RATE / _SCALE; + function getSurcharge( + uint256 unadjustedAmount, + uint256 surchargeRate + ) + internal + pure + returns (uint256 surchargeAmount) + { + surchargeAmount = unadjustedAmount * surchargeRate / _SCALE; } function solverGasLimitScaledDown( diff --git a/test/AccountingMath.t.sol b/test/AccountingMath.t.sol index a9b26d180..69cb1263c 100644 --- a/test/AccountingMath.t.sol +++ b/test/AccountingMath.t.sol @@ -5,68 +5,83 @@ import "forge-std/Test.sol"; import "src/contracts/libraries/AccountingMath.sol"; contract AccountingMathTest is Test { + uint256 DEFAULT_ATLAS_SURCHARGE_RATE = 1_000_000; // 10% + uint256 DEFAULT_BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% + function testWithBundlerSurcharge() public { - assertEq(AccountingMath.withBundlerSurcharge(0), uint256(0)); - assertEq(AccountingMath.withBundlerSurcharge(1), uint256(1)); - assertEq(AccountingMath.withBundlerSurcharge(11), uint256(12)); - assertEq(AccountingMath.withBundlerSurcharge(100), uint256(110)); - assertEq(AccountingMath.withBundlerSurcharge(1e18), uint256(11e17)); + assertEq(AccountingMath.withSurcharge(0, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(0)); + assertEq(AccountingMath.withSurcharge(1, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(1)); + assertEq(AccountingMath.withSurcharge(11, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(12)); + assertEq(AccountingMath.withSurcharge(100, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(110)); + assertEq(AccountingMath.withSurcharge(1e18, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(11e17)); vm.expectRevert(); - AccountingMath.withBundlerSurcharge(type(uint256).max); + AccountingMath.withSurcharge(type(uint256).max, DEFAULT_BUNDLER_SURCHARGE_RATE); } function testWithoutBundlerSurcharge() public { - assertEq(AccountingMath.withoutBundlerSurcharge(0), uint256(0)); - assertEq(AccountingMath.withoutBundlerSurcharge(1), uint256(0)); - assertEq(AccountingMath.withoutBundlerSurcharge(12), uint256(10)); - assertEq(AccountingMath.withoutBundlerSurcharge(110), uint256(100)); - assertEq(AccountingMath.withoutBundlerSurcharge(11e17), uint256(1e18)); + assertEq(AccountingMath.withoutSurcharge(0, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(0)); + assertEq(AccountingMath.withoutSurcharge(1, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(0)); + assertEq(AccountingMath.withoutSurcharge(12, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(10)); + assertEq(AccountingMath.withoutSurcharge(110, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(100)); + assertEq(AccountingMath.withoutSurcharge(11e17, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(1e18)); vm.expectRevert(); - AccountingMath.withoutBundlerSurcharge(type(uint256).max); + AccountingMath.withoutSurcharge(type(uint256).max, DEFAULT_BUNDLER_SURCHARGE_RATE); } function testWithAtlasAndBundlerSurcharges() public { - assertEq(AccountingMath.withAtlasAndBundlerSurcharges(0), uint256(0)); - assertEq(AccountingMath.withAtlasAndBundlerSurcharges(1), uint256(1)); - assertEq(AccountingMath.withAtlasAndBundlerSurcharges(10), uint256(12)); - assertEq(AccountingMath.withAtlasAndBundlerSurcharges(100), uint256(120)); - assertEq(AccountingMath.withAtlasAndBundlerSurcharges(1e18), uint256(12e17)); + assertEq( + AccountingMath.withSurcharges(0, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(0) + ); + assertEq( + AccountingMath.withSurcharges(1, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(1) + ); + assertEq( + AccountingMath.withSurcharges(10, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE), uint256(12) + ); + assertEq( + AccountingMath.withSurcharges(100, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE), + uint256(120) + ); + assertEq( + AccountingMath.withSurcharges(1e18, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE), + uint256(12e17) + ); vm.expectRevert(); - AccountingMath.withAtlasAndBundlerSurcharges(type(uint256).max); + AccountingMath.withSurcharges(type(uint256).max, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE); } function testGetAtlasSurcharge() public { - assertEq(AccountingMath.getAtlasSurcharge(0), uint256(0)); - assertEq(AccountingMath.getAtlasSurcharge(10), uint256(1)); - assertEq(AccountingMath.getAtlasSurcharge(20), uint256(2)); - assertEq(AccountingMath.getAtlasSurcharge(30), uint256(3)); - assertEq(AccountingMath.getAtlasSurcharge(100), uint256(10)); - assertEq(AccountingMath.getAtlasSurcharge(1_000_000), uint256(100_000)); - assertEq(AccountingMath.getAtlasSurcharge(1e18), uint256(1e17)); + assertEq(AccountingMath.getSurcharge(0, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(0)); + assertEq(AccountingMath.getSurcharge(10, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(1)); + assertEq(AccountingMath.getSurcharge(20, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(2)); + assertEq(AccountingMath.getSurcharge(30, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(3)); + assertEq(AccountingMath.getSurcharge(100, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(10)); + assertEq(AccountingMath.getSurcharge(1_000_000, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(100_000)); + assertEq(AccountingMath.getSurcharge(1e18, DEFAULT_ATLAS_SURCHARGE_RATE), uint256(1e17)); vm.expectRevert(); - AccountingMath.getAtlasSurcharge(type(uint256).max); + AccountingMath.getSurcharge(type(uint256).max, DEFAULT_ATLAS_SURCHARGE_RATE); } function testSolverGasLimitScaledDown() public { assertEq(AccountingMath.solverGasLimitScaledDown(0, 100), uint256(0)); assertEq(AccountingMath.solverGasLimitScaledDown(50, 100), uint256(47)); // 50 * 10_000_000 / 10_500_000 assertEq(AccountingMath.solverGasLimitScaledDown(100, 200), uint256(95)); - + assertEq(AccountingMath.solverGasLimitScaledDown(200, 100), uint256(95)); assertEq(AccountingMath.solverGasLimitScaledDown(300, 200), uint256(190)); - + assertEq(AccountingMath.solverGasLimitScaledDown(100, 100), uint256(95)); assertEq(AccountingMath.solverGasLimitScaledDown(200, 200), uint256(190)); - - assertEq(AccountingMath.solverGasLimitScaledDown(1_000_000, 500_000), uint256(476_190)); // 500_000 * 10_000_000 / 10_500_000 - assertEq(AccountingMath.solverGasLimitScaledDown(1e18, 1e18), uint256(952380952380952380)); - + + assertEq(AccountingMath.solverGasLimitScaledDown(1_000_000, 500_000), uint256(476_190)); // 500_000 * 10_000_000 + // / 10_500_000 + assertEq(AccountingMath.solverGasLimitScaledDown(1e18, 1e18), uint256(952_380_952_380_952_380)); + vm.expectRevert(); assertEq(AccountingMath.solverGasLimitScaledDown(type(uint256).max, type(uint256).max), type(uint256).max); - + assertEq(AccountingMath.solverGasLimitScaledDown(1, 2), uint256(0)); // 1 * 10_000_000 / 10_500_000 assertEq(AccountingMath.solverGasLimitScaledDown(3, 3), uint256(2)); // 3 * 10_000_000 / 10_500_000 assertEq(AccountingMath.solverGasLimitScaledDown(5, 10), uint256(4)); // 5 * 10_000_000 / 10_500_000 - } } diff --git a/test/Atlas.t.sol b/test/BidFinding.t.sol similarity index 63% rename from test/Atlas.t.sol rename to test/BidFinding.t.sol index f64d010cf..fb61ab6e7 100644 --- a/test/Atlas.t.sol +++ b/test/BidFinding.t.sol @@ -20,38 +20,11 @@ import "src/contracts/types/LockTypes.sol"; import { LibSort } from "solady/utils/LibSort.sol"; -// These tests focus on the functions found in the Atlas.sol file -contract AtlasTest is BaseTest { - - function setUp_bidFindingIteration() public { - // super.setUp(); - - // vm.startPrank(payee); - // simulator = new Simulator(); - - // // Computes the addresses at which AtlasVerification will be deployed - // address expectedAtlasAddr = vm.computeCreateAddress(payee, vm.getNonce(payee) + 1); - // address expectedAtlasVerificationAddr = vm.computeCreateAddress(payee, vm.getNonce(payee) + 2); - // bytes32 salt = keccak256(abi.encodePacked(block.chainid, expectedAtlasAddr, "AtlasFactory 1.0")); - // ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment{ salt: salt }(expectedAtlasAddr); - - // atlas = new MockAtlas({ - // escrowDuration: 64, - // verification: expectedAtlasVerificationAddr, - // simulator: address(simulator), - // executionTemplate: address(execEnvTemplate), - // surchargeRecipient: payee - // }); - // atlasVerification = new AtlasVerification(address(atlas)); - // simulator.setAtlas(address(atlas)); - // sorter = new Sorter(address(atlas)); - // vm.stopPrank(); - } - +contract BidFindingTest is BaseTest { function test_bidFindingIteration_sortingOrder() public pure { // Test order of bidsAndIndices after insertionSort - // 3 items. [200, 0, 100] --> [0, 100, 200] + // 3 items. [200, 0, 100] --> [0, 100, 200] uint256[] memory bidsAndIndices = new uint256[](3); bidsAndIndices[0] = 100; bidsAndIndices[1] = 0; @@ -80,7 +53,7 @@ contract AtlasTest is BaseTest { } function test_bidFindingIteration_packBidAndIndex() public pure { - uint256 bid = 12345; + uint256 bid = 12_345; uint256 index = 2; uint256 packed = _packBidAndIndex(bid, index); @@ -113,7 +86,6 @@ contract AtlasTest is BaseTest { assertEq(unpackedIndex, index); } - // Packs bid and index into a single uint256, replicates logic used in `_bidFindingIteration()` function _packBidAndIndex(uint256 bid, uint256 index) internal pure returns (uint256) { return uint256(bid << 16 | uint16(index)); @@ -127,29 +99,4 @@ contract AtlasTest is BaseTest { // uint256 solverOpsIndex = bidsAndIndices[i] & FIRST_16_BITS_MASK; index = packed & uint256(0xFFFF); } -} - -// MockAtlas exposes Atlas' internal functions for testing -contract MockAtlas is Atlas { - constructor( - uint256 _escrowDuration, - address _verification, - address _simulator, - address _surchargeRecipient, - address _l2GasCalculator, - address _executionTemplate - ) - Atlas(_escrowDuration, _verification, _simulator, _surchargeRecipient, _l2GasCalculator, _executionTemplate) - { } - - function bidFindingIteration( - DAppConfig calldata dConfig, - UserOperation calldata userOp, - SolverOperation[] calldata solverOps, - bytes memory returnData, - Context memory ctx - ) public returns (Context memory) { - _bidFindingIteration(ctx, dConfig, userOp, solverOps, returnData); - return ctx; - } } \ No newline at end of file diff --git a/test/DAppIntegration.t.sol b/test/DAppIntegration.t.sol index 7bbb5c08e..b136b27ca 100644 --- a/test/DAppIntegration.t.sol +++ b/test/DAppIntegration.t.sol @@ -16,6 +16,9 @@ contract MockDAppIntegration is DAppIntegration { } contract DAppIntegrationTest is Test { + uint256 DEFAULT_ATLAS_SURCHARGE_RATE = 1_000_000; // 10% + uint256 DEFAULT_BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% + Atlas public atlas; MockDAppIntegration public dAppIntegration; DummyDAppControl public dAppControl; @@ -40,6 +43,8 @@ contract DAppIntegrationTest is Test { // Deploy the Atlas contract with correct parameters atlas = new Atlas({ escrowDuration: 64, + atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, + bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: address(atlasVerification), simulator: address(0), executionTemplate: address(execEnvTemplate), diff --git a/test/Factory.t.sol b/test/Factory.t.sol index 814db49c3..9da4b4980 100644 --- a/test/Factory.t.sol +++ b/test/Factory.t.sol @@ -47,6 +47,9 @@ contract MockFactory is Factory, Test { } contract FactoryTest is Test { + uint256 DEFAULT_ATLAS_SURCHARGE_RATE = 1_000_000; // 10% + uint256 DEFAULT_BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% + Atlas public atlas; AtlasVerification public atlasVerification; MockFactory public mockFactory; @@ -66,6 +69,8 @@ contract FactoryTest is Test { vm.startPrank(deployer); atlas = new Atlas({ escrowDuration: 64, + atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, + bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: address(0), executionTemplate: address(execEnvTemplate), diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index 39f62bfb0..daaea6480 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -30,13 +30,15 @@ contract MockGasAccounting is TestAtlas, BaseTest { constructor( uint256 _escrowDuration, + uint256 _atlasSurchargeRate, + uint256 _bundlerSurchargeRate, address _verification, address _simulator, address _surchargeRecipient, address _l2GasCalculator, address _executionTemplate ) - TestAtlas(_escrowDuration, _verification, _simulator, _surchargeRecipient, _l2GasCalculator, _executionTemplate) + TestAtlas(_escrowDuration, _atlasSurchargeRate, _bundlerSurchargeRate, _verification, _simulator, _surchargeRecipient, _l2GasCalculator, _executionTemplate) { } ///////////////////////////////////////////////////////// @@ -172,14 +174,6 @@ contract MockGasAccounting is TestAtlas, BaseTest { function getFixedGasOffset() external pure returns (uint256) { return AccountingMath._FIXED_GAS_OFFSET; } - - function getAtlasSurchargeRate() external pure returns (uint256) { - return AccountingMath._ATLAS_SURCHARGE_RATE; - } - - function getBundlerSurchargeRate() external pure returns (uint256) { - return AccountingMath._BUNDLER_SURCHARGE_RATE; - } } contract MockGasCalculator is IL2GasCalculator, Test { @@ -212,6 +206,8 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Initialize MockGasAccounting mockGasAccounting = new MockGasAccounting( DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, address(atlasVerification), address(simulator), deployer, @@ -973,7 +969,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { (gasWaterMark + mockGasAccounting.getSolverBaseGasUsed() - gasleft()) * tx.gasprice + gasUsedOffset; mockGasAccounting.handleSolverAccounting(solverOp, gasWaterMark, result, false); - uint256 expectedWriteoffs = initialWriteoffs + AccountingMath.withAtlasAndBundlerSurcharges(gasUsed); + uint256 expectedWriteoffs = initialWriteoffs + AccountingMath.withSurcharges(gasUsed, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE); // Verify writeoffs have increased assertApproxEqRel( mockGasAccounting.getWriteoffs(), @@ -1110,6 +1106,8 @@ contract GasAccountingTest is AtlasConstants, BaseTest { IL2GasCalculator gasCalculator = new MockGasCalculator(); MockGasAccounting mockL2GasAccounting = new MockGasAccounting( DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, address(atlasVerification), address(simulator), deployer, diff --git a/test/Permit69.t.sol b/test/Permit69.t.sol index b5b47f4c8..2262ad3b9 100644 --- a/test/Permit69.t.sol +++ b/test/Permit69.t.sol @@ -22,7 +22,6 @@ import "src/contracts/types/LockTypes.sol"; import "src/contracts/types/DAppOperation.sol"; contract Permit69Test is BaseTest { - Context ctx; address mockUser; @@ -42,10 +41,12 @@ contract Permit69Test is BaseTest { address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); bytes32 salt = keccak256(abi.encodePacked(block.chainid, expectedFactoryAddr)); ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment{ salt: salt }(expectedFactoryAddr); - + vm.startPrank(deployer); mockAtlas = new MockAtlasForPermit69Tests({ _escrowDuration: 64, + _atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, + _bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, _verification: expectedAtlasVerificationAddr, _simulator: address(0), _executionTemplate: address(execEnvTemplate), @@ -97,9 +98,7 @@ contract Permit69Test is BaseTest { vm.prank(solverOneEOA); vm.expectRevert(AtlasErrors.InvalidEnvironment.selector); - mockAtlas.transferUserERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferUserERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); } function testTransferUserERC20RevertsIfLockStateNotValid() public { @@ -115,27 +114,21 @@ contract Permit69Test is BaseTest { // Uninitialized vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferUserERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferUserERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); // AllocateValue phase = ExecutionPhase.AllocateValue; mockAtlas.setContext(ctx); mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferUserERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferUserERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); // Releasing phase = ExecutionPhase.Uninitialized; mockAtlas.setContext(ctx); mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferUserERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferUserERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); vm.stopPrank(); } @@ -157,9 +150,7 @@ contract Permit69Test is BaseTest { WETH.approve(address(mockAtlas), wethTransferred); vm.prank(mockExecutionEnvAddress); - mockAtlas.transferUserERC20( - WETH_ADDRESS, solverOneEOA, wethTransferred, mockUser, mockDAppControl - ); + mockAtlas.transferUserERC20(WETH_ADDRESS, solverOneEOA, wethTransferred, mockUser, mockDAppControl); assertEq(WETH.balanceOf(mockUser), userWethBefore - wethTransferred, "User did not lose WETH"); assertEq(WETH.balanceOf(solverOneEOA), solverWethBefore + wethTransferred, "Solver did not gain WETH"); @@ -173,9 +164,7 @@ contract Permit69Test is BaseTest { vm.prank(solverOneEOA); vm.expectRevert(AtlasErrors.InvalidEnvironment.selector); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); } function testTransferDAppERC20RevertsIfLockStateNotValid() public { @@ -189,33 +178,25 @@ contract Permit69Test is BaseTest { ExecutionPhase phase = ExecutionPhase.Uninitialized; mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); // UserOperation phase = ExecutionPhase.UserOperation; mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); // SolverOperations phase = ExecutionPhase.SolverOperation; mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); // Releasing phase = ExecutionPhase.Uninitialized; mockAtlas.setPhase(phase); vm.expectRevert(AtlasErrors.InvalidLockState.selector); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, 10e18, mockUser, mockDAppControl); vm.stopPrank(); } @@ -236,9 +217,7 @@ contract Permit69Test is BaseTest { WETH.approve(address(mockAtlas), wethTransferred); vm.prank(mockExecutionEnvAddress); - mockAtlas.transferDAppERC20( - WETH_ADDRESS, solverOneEOA, wethTransferred, mockUser, mockDAppControl - ); + mockAtlas.transferDAppERC20(WETH_ADDRESS, solverOneEOA, wethTransferred, mockUser, mockDAppControl); assertEq(WETH.balanceOf(mockDAppControl), dAppWethBefore - wethTransferred, "DApp did not lose WETH"); assertEq(WETH.balanceOf(solverOneEOA), solverWethBefore + wethTransferred, "Solver did not gain WETH"); @@ -279,7 +258,7 @@ contract Permit69Test is BaseTest { function testConstantValueOfSafeDAppTransfer() public { // FIXME: fix before merging spearbit-reaudit branch vm.skip(true); - + string memory expectedBitMapString = "0000111010100000"; // Safe phases for dApp transfers are PreOps, AllocateValue, and DAppOperation // preOpsPhaseSafe = 0000 0000 0010 0000 @@ -293,8 +272,8 @@ contract Permit69Test is BaseTest { // verificationPhaseSafe = 0000 0100 0000 0000 uint8 verificationPhaseSafe = uint8(ExecutionPhase.PostOps); - uint16 expectedSafeDAppTransferBitMap = - preOpsPhaseSafe | preSolverOpsPhaseSafe | postSolverOpsPhaseSafe | allocateValuePhaseSafe | verificationPhaseSafe; + uint16 expectedSafeDAppTransferBitMap = preOpsPhaseSafe | preSolverOpsPhaseSafe | postSolverOpsPhaseSafe + | allocateValuePhaseSafe | verificationPhaseSafe; assertEq( mockAtlas.getSafeDAppTransfer(), @@ -323,13 +302,24 @@ contract Permit69Test is BaseTest { contract MockAtlasForPermit69Tests is Atlas { constructor( uint256 _escrowDuration, + uint256 _atlasSurchargeRate, + uint256 _bundlerSurchargeRate, address _verification, address _simulator, address _surchargeRecipient, address _l2GasCalculator, address _executionTemplate ) - Atlas(_escrowDuration, _verification, _simulator, _surchargeRecipient, _l2GasCalculator, _executionTemplate) + Atlas( + _escrowDuration, + _atlasSurchargeRate, + _bundlerSurchargeRate, + _verification, + _simulator, + _surchargeRecipient, + _l2GasCalculator, + _executionTemplate + ) { } // Declared in SafetyLocks.sol in the canonical Atlas system @@ -354,10 +344,7 @@ contract MockAtlasForPermit69Tests is Atlas { _environment = _activeEnvironment; } - function setLock( - address _activeEnvironment, - uint32 callConfig - ) public { + function setLock(address _activeEnvironment, uint32 callConfig) public { _setLock({ activeEnvironment: _activeEnvironment, callConfig: callConfig, @@ -376,12 +363,20 @@ contract MockAtlasForPermit69Tests is Atlas { uint32 callConfig ) public - returns (address executionEnvironment) + returns (address executionEnvironment) { return _getOrCreateExecutionEnvironment(user, control, callConfig); } - function verifyUserControlExecutionEnv(address sender, address user, address control, uint32 callConfig) internal view returns (bool) + function verifyUserControlExecutionEnv( + address sender, + address user, + address control, + uint32 callConfig + ) + internal + view + returns (bool) { return _verifyUserControlExecutionEnv(sender, user, control, callConfig); } diff --git a/test/SafetyLocks.t.sol b/test/SafetyLocks.t.sol index 5fab4b491..0cef1f739 100644 --- a/test/SafetyLocks.t.sol +++ b/test/SafetyLocks.t.sol @@ -11,7 +11,7 @@ import "src/contracts/types/ConfigTypes.sol"; import "src/contracts/types/LockTypes.sol"; contract MockSafetyLocks is SafetyLocks { - constructor() SafetyLocks(0, address(0), address(0), address(0), address(0)) { } + constructor() SafetyLocks(0, 1000000, 1000000, address(0), address(0), address(0), address(0)) { } function initializeLock( address executionEnvironment, diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 536cbe697..a3e07beb3 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -11,8 +11,6 @@ import { BaseTest } from "test/base/BaseTest.t.sol"; contract StorageTest is BaseTest { using stdStorage for StdStorage; - uint256 constant DEFAULT_ATLAS_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% - uint256 constant DEFAULT_BUNDLER_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% uint256 constant DEFAULT_SCALE = 10_000_000; // out of 10_000_000 = 100% uint256 constant DEFAULT_FIXED_GAS_OFFSET = 85_000; @@ -32,7 +30,9 @@ contract StorageTest is BaseTest { assertEq(atlas.decimals(), 18, "decimals set incorrectly"); assertEq(atlas.ATLAS_SURCHARGE_RATE(), DEFAULT_ATLAS_SURCHARGE_RATE, "ATLAS_SURCHARGE_RATE set incorrectly"); - assertEq(atlas.BUNDLER_SURCHARGE_RATE(), DEFAULT_BUNDLER_SURCHARGE_RATE, "BUNDLER_SURCHARGE_RATE set incorrectly"); + assertEq( + atlas.BUNDLER_SURCHARGE_RATE(), DEFAULT_BUNDLER_SURCHARGE_RATE, "BUNDLER_SURCHARGE_RATE set incorrectly" + ); assertEq(atlas.SCALE(), DEFAULT_SCALE, "SCALE set incorrectly"); assertEq(atlas.FIXED_GAS_OFFSET(), DEFAULT_FIXED_GAS_OFFSET, "FIXED_GAS_OFFSET set incorrectly"); } @@ -45,7 +45,7 @@ contract StorageTest is BaseTest { vm.deal(userEOA, depositAmount); vm.prank(userEOA); - atlas.deposit{value: depositAmount}(); + atlas.deposit{ value: depositAmount }(); assertEq(atlas.totalSupply(), startTotalSupply + depositAmount, "totalSupply did not increase correctly"); } @@ -56,14 +56,20 @@ contract StorageTest is BaseTest { vm.deal(userEOA, depositAmount); vm.prank(userEOA); - atlas.depositAndBond{value: depositAmount}(depositAmount); + atlas.depositAndBond{ value: depositAmount }(depositAmount); assertEq(atlas.bondedTotalSupply(), depositAmount, "bondedTotalSupply did not increase correctly"); } function test_storage_view_accessData() public { uint256 depositAmount = 1e18; - (uint256 bonded, uint256 lastAccessedBlock, uint256 auctionWins, uint256 auctionFails, uint256 totalGasValueUsed) = atlas.accessData(userEOA); + ( + uint256 bonded, + uint256 lastAccessedBlock, + uint256 auctionWins, + uint256 auctionFails, + uint256 totalGasValueUsed + ) = atlas.accessData(userEOA); assertEq(bonded, 0, "user bonded should start as 0"); assertEq(lastAccessedBlock, 0, "user lastAccessedBlock should start as 0"); @@ -73,7 +79,7 @@ contract StorageTest is BaseTest { vm.deal(userEOA, depositAmount); vm.prank(userEOA); - atlas.depositAndBond{value: depositAmount}(depositAmount); + atlas.depositAndBond{ value: depositAmount }(depositAmount); (bonded, lastAccessedBlock, auctionWins, auctionFails, totalGasValueUsed) = atlas.accessData(userEOA); @@ -96,7 +102,15 @@ contract StorageTest is BaseTest { } function test_storage_view_solverOpHashes() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); bytes32 testHash = keccak256(abi.encodePacked("test")); assertEq(mockStorage.solverOpHashes(testHash), false, "solverOpHashes[testHash] not false"); mockStorage.setSolverOpHash(testHash); @@ -104,7 +118,15 @@ contract StorageTest is BaseTest { } function test_storage_view_cumulativeSurcharge() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); assertEq(mockStorage.cumulativeSurcharge(), 0, "cumulativeSurcharge not 0"); mockStorage.setCumulativeSurcharge(100); assertEq(mockStorage.cumulativeSurcharge(), 100, "cumulativeSurcharge not 100"); @@ -157,7 +179,15 @@ contract StorageTest is BaseTest { function test_storage_transient_solverLockData() public { // MockStorage just used here to access AtlasConstants - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); (address currentSolver, bool calledBack, bool fulfilled) = atlas.solverLockData(); assertEq(currentSolver, address(0), "currentSolver should start at 0"); @@ -180,7 +210,8 @@ contract StorageTest is BaseTest { assertEq(calledBack, true, "calledBack should still be true"); assertEq(fulfilled, true, "fulfilled should be true"); - testSolverLock = mockStorage.SOLVER_CALLED_BACK_MASK() | mockStorage.SOLVER_FULFILLED_MASK() | uint256(uint160(userEOA)); + testSolverLock = + mockStorage.SOLVER_CALLED_BACK_MASK() | mockStorage.SOLVER_FULFILLED_MASK() | uint256(uint160(userEOA)); atlas.setSolverLock(testSolverLock); (currentSolver, calledBack, fulfilled) = atlas.solverLockData(); @@ -247,7 +278,15 @@ contract StorageTest is BaseTest { } function test_storage_transient_solverTo() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); assertEq(mockStorage.solverTo(), address(0), "solverTo should start at 0"); mockStorage.setSolverTo(userEOA); @@ -258,7 +297,15 @@ contract StorageTest is BaseTest { } function test_storage_transient_activeEnvironment() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); assertEq(mockStorage.activeEnvironment(), address(0), "activeEnvironment should start at 0"); mockStorage.setLock(address(1), 0, 0); @@ -269,7 +316,15 @@ contract StorageTest is BaseTest { } function test_storage_transient_activeCallConfig() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); assertEq(mockStorage.activeCallConfig(), 0, "activeCallConfig should start at 0"); mockStorage.setLock(address(0), 1, 0); @@ -280,7 +335,15 @@ contract StorageTest is BaseTest { } function test_storage_transient_phase() public { - MockStorage mockStorage = new MockStorage(DEFAULT_ESCROW_DURATION, address(0), address(0), address(0), address(0)); + MockStorage mockStorage = new MockStorage( + DEFAULT_ESCROW_DURATION, + DEFAULT_ATLAS_SURCHARGE_RATE, + DEFAULT_BUNDLER_SURCHARGE_RATE, + address(0), + address(0), + address(0), + address(0) + ); assertEq(mockStorage.phase(), 0, "phase should start at 0"); mockStorage.setLock(address(0), 0, 1); @@ -293,19 +356,28 @@ contract StorageTest is BaseTest { // To test solverOpHashes() and cumulativeSurcharge() view function contract MockStorage is Storage { - // For solverLockData test uint256 public constant SOLVER_CALLED_BACK_MASK = _SOLVER_CALLED_BACK_MASK; uint256 public constant SOLVER_FULFILLED_MASK = _SOLVER_FULFILLED_MASK; constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator ) - Storage(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator) + Storage( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator + ) { } function setSolverOpHash(bytes32 opHash) public { @@ -376,4 +448,4 @@ contract MockStorage is Storage { function getDeposits() external view returns (uint256) { return deposits(); } -} \ No newline at end of file +} diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index a43479298..f4b40272e 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -51,6 +51,8 @@ contract BaseTest is Test { IERC20 DAI = IERC20(DAI_ADDRESS); uint256 DEFAULT_ESCROW_DURATION = 64; + uint256 DEFAULT_ATLAS_SURCHARGE_RATE = 1_000_000; // 10% + uint256 DEFAULT_BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% uint256 MAINNET_FORK_BLOCK = 17_441_786; function setUp() public virtual { @@ -80,6 +82,8 @@ contract BaseTest is Test { atlas = new TestAtlas({ escrowDuration: DEFAULT_ESCROW_DURATION, + atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, + bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: address(simulator), executionTemplate: address(execEnvTemplate), diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 4e325dc4c..27c3da92e 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -9,13 +9,24 @@ import "src/contracts/atlas/Atlas.sol"; contract TestAtlas is Atlas { constructor( uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, address verification, address simulator, address initialSurchargeRecipient, address l2GasCalculator, address executionTemplate ) - Atlas(escrowDuration, verification, simulator, initialSurchargeRecipient, l2GasCalculator, executionTemplate) + Atlas( + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, + initialSurchargeRecipient, + l2GasCalculator, + executionTemplate + ) { } // Public functions to expose internal transient helpers for testing From 6541891453284f99f2cd9ab83e22aa5db852ba5f Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 15 Oct 2024 07:34:36 +0200 Subject: [PATCH 37/70] 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 5a802d7c1..ee000c6c2 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 5a802d7c10abb4bbfb3e7214c75052ef9e6a06f8 +Subproject commit ee000c6c27859065d7b3da6047345607c1d94a0d diff --git a/lib/solady b/lib/solady index 42af395e6..855e2e834 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 42af395e631fcc9d640eddf11c57c6f1ca3f9103 +Subproject commit 855e2e834a9d791002586a5c9071b1f4c0796bd1 From 8a4d49a8f74f1cf806670c8d529686e978524138 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 15 Oct 2024 07:34:56 +0200 Subject: [PATCH 38/70] test: add userOp gas limit enforced test --- test/Escrow.t.sol | 33 +++++++++++++++++++++++++++++++++ test/base/DummyDAppControl.sol | 9 +++++++++ 2 files changed, 42 insertions(+) diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index cacbf8040..f1b5c4531 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -188,6 +188,39 @@ contract EscrowTest is BaseTest { executeHookCase(0, AtlasErrors.UserOpFail.selector); } + function test_executeUserOperation_enforcesUserOpGasLimit() public { + uint256 userGasLim = 123_456; // default is 1 million in other tests in this file + + // First do metacall with default userOp gas limit (1 million) + defaultAtlasWithCallConfig(defaultCallConfig().build()); + executeHookCase(1, noError); + assertGt(dAppControl.userOpGasLeft(), userGasLim, "userOpGasLeft should be > userGasLim"); + + // Now do metacall with way lower gas limit (123_456) + vm.roll(block.number + 1); + UserOperation memory userOp = validUserOperation(address(dAppControl)) + .withData( + abi.encodeWithSelector( + dAppControl.userOperationCall.selector, + 1 + ) + ).withGas(userGasLim) + .signAndBuild(address(atlasVerification), userPK); + deal(address(dummySolver), defaultBidAmount); + SolverOperation[] memory solverOps = new SolverOperation[](1); + solverOps[0] = validSolverOperation(userOp) + .withBidAmount(defaultBidAmount) + .withData(abi.encode(1)) + .signAndBuild(address(atlasVerification), solverOnePK); + DAppOperation memory dappOp = validDAppOperation(userOp, solverOps).build(); + + vm.prank(userEOA); + bool auctionWon = atlas.metacall(userOp, solverOps, dappOp); + + assertLe(dAppControl.userOpGasLeft(), userGasLim, "userOpGasLeft should be <= userGasLim"); + assertTrue(auctionWon, "2nd auction should have been won"); + } + // Ensure metacall reverts with the proper error when the allocateValue hook reverts. function test_executeAllocateValueCall_failure_SkipCoverage() public { defaultAtlasWithCallConfig( diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index b33af3cc9..83a2bd92a 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -28,6 +28,8 @@ contract DummyDAppControl is DAppControl { bytes public allocateValueInputData; bytes public postOpsInputData; + uint256 public userOpGasLeft; + event MEVPaymentSuccess(address bidToken, uint256 bidAmount); constructor( @@ -106,6 +108,8 @@ contract DummyDAppControl is DAppControl { // **************************************** function userOperationCall(uint256 returnValue) public returns (uint256) { + DummyDAppControl(CONTROL).setUserOpGasLeft(); + bool shouldRevert = DummyDAppControl(CONTROL).userOpShouldRevert(); require(!shouldRevert, "userOperationCall revert requested"); @@ -154,4 +158,9 @@ contract DummyDAppControl is DAppControl { if (hook == 4) allocateValueInputData = inputData; if (hook == 5) postOpsInputData = inputData; } + + // Called by the EE to save gas left for testing at start of userOperationCall + function setUserOpGasLeft() public { + userOpGasLeft = gasleft(); + } } 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 39/70] 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 40/70] 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 From a9b4cbf76e228bf624501fa454ba8d9f180ba8eb Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:07:42 +0200 Subject: [PATCH 41/70] feat: add `maxBundlerRefund()` helper --- src/contracts/libraries/AccountingMath.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/contracts/libraries/AccountingMath.sol b/src/contracts/libraries/AccountingMath.sol index 7f501cc8f..e43e804a8 100644 --- a/src/contracts/libraries/AccountingMath.sol +++ b/src/contracts/libraries/AccountingMath.sol @@ -5,6 +5,7 @@ library AccountingMath { // Gas Accounting public constants uint256 internal constant _ATLAS_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% uint256 internal constant _BUNDLER_SURCHARGE_RATE = 1_000_000; // out of 10_000_000 = 10% + uint256 internal constant _MAX_BUNDLER_REFUND_RATE = 8_000_000; // out of 10_000_000 = 80% uint256 internal constant _SOLVER_GAS_LIMIT_BUFFER_PERCENTAGE = 500_000; // out of 10_000_000 = 5% uint256 internal constant _SCALE = 10_000_000; // 10_000_000 / 10_000_000 = 100% uint256 internal constant _FIXED_GAS_OFFSET = 85_000; @@ -30,6 +31,12 @@ library AccountingMath { atlasSurcharge = totalSurcharge * _ATLAS_SURCHARGE_RATE / (_ATLAS_SURCHARGE_RATE + _BUNDLER_SURCHARGE_RATE); } + // NOTE: This max should only be applied when there are no winning solvers. + // Set to 80% of the metacall gas cost, because the remaining 20% can be collected through storage refunds. + function maxBundlerRefund(uint256 metacallGasCost) internal pure returns (uint256 maxRefund) { + maxRefund = metacallGasCost * _MAX_BUNDLER_REFUND_RATE / _SCALE; + } + function solverGasLimitScaledDown( uint256 solverOpGasLimit, uint256 dConfigGasLimit From 74cf073c159cb200979bf5b7ec251821c5a81288 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:08:59 +0200 Subject: [PATCH 42/70] feat: apply max bundler refund if no winning solvers --- src/contracts/atlas/GasAccounting.sol | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 35773bef2..7629e3346 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -359,8 +359,16 @@ abstract contract GasAccounting is SafetyLocks { // If no successful solvers, only collect partial surcharges from solver's fault failures (if any) uint256 _solverSurcharge = solverSurcharge(); if (_solverSurcharge > 0) { - // NOTE: This only works when BUNDLER_SURCHARGE > ATLAS_SURCHARGE. netAtlasGasSurcharge = _solverSurcharge.getAtlasPortionFromTotalSurcharge(); + + // When no winning solvers, bundler max refund is 80% of metacall gas cost. The remaining 20% can be + // collected through storage refunds. Any excess bundler surcharge is instead taken as Atlas surcharge. + uint256 _bundlerSurcharge = _solverSurcharge - netAtlasGasSurcharge; + uint256 _maxBundlerRefund = adjustedClaims.withoutBundlerSurcharge().maxBundlerRefund(); + if (_bundlerSurcharge > _maxBundlerRefund) { + netAtlasGasSurcharge += _bundlerSurcharge - _maxBundlerRefund; + } + adjustedWithdrawals += netAtlasGasSurcharge; S_cumulativeSurcharge = _surcharge + netAtlasGasSurcharge; } From 23eeb37aad87968d5f4029644790a1951b2fe7cf Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:42:22 +0200 Subject: [PATCH 43/70] test: fix FLO tests for surcharge rule changes --- test/FLOnline.t.sol | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/FLOnline.t.sol b/test/FLOnline.t.sol index e8520b826..d1a606d14 100644 --- a/test/FLOnline.t.sol +++ b/test/FLOnline.t.sol @@ -51,8 +51,9 @@ contract FastLaneOnlineTest is BaseTest { bool solverFour; } - uint256 constant SURCHARGE_PER_SOLVER_IF_ALL_FAIL = 28_000e9; // 28k Gwei (avg, differs for ERC20/native in/out) - uint256 constant ERR_MARGIN = 0.15e18; // 15% error margin + // Only Atlas surcharge kept if all fail, bundler surcharge paid to bundler + uint256 constant SURCHARGE_PER_SOLVER_IF_ALL_FAIL = 14_000e9; // 14k Gwei (avg, differs for ERC20/native in/out) + uint256 constant ERR_MARGIN = 0.22e18; // 22% error margin address internal constant NATIVE_TOKEN = address(0); address protocolGuildWallet = 0x25941dC771bB64514Fc8abBce970307Fb9d477e9; @@ -61,7 +62,6 @@ contract FastLaneOnlineTest is BaseTest { uint256 goodSolverBidETH = 1.2 ether; // more than baseline swap amountOut if tokenOut is WETH/ETH uint256 goodSolverBidDAI = 3100e18; // more than baseline swap amountOut if tokenOut is DAI - uint256 defaultMsgValue = 1e16; // 0.01 ETH for bundler gas, treated as donation uint256 defaultGasLimit = 2_000_000; uint256 defaultGasPrice; uint256 defaultDeadlineBlock; @@ -1291,9 +1291,6 @@ contract FastLaneOnlineTest is BaseTest { beforeVars.solverTwoRep = flOnline.solverReputation(solverTwoEOA); beforeVars.solverThreeRep = flOnline.solverReputation(solverThreeEOA); - // adjust userTokenInBalance if native token - exclude gas treated as donation - if (nativeTokenIn) beforeVars.userTokenInBalance -= defaultMsgValue; - uint256 txGasUsed; uint256 estAtlasGasSurcharge = gasleft(); // Reused below during calculations @@ -1459,10 +1456,9 @@ contract FastLaneOnlineTest is BaseTest { newArgs.deadline = defaultDeadlineBlock; newArgs.gas = defaultGasLimit; newArgs.maxFeePerGas = defaultGasPrice; - newArgs.msgValue = defaultMsgValue; // Add amountUserSells of ETH to the msg.value of the fastOnlineSwap call - if (nativeTokenIn) newArgs.msgValue += swapIntent.amountUserSells; + if (nativeTokenIn) newArgs.msgValue = swapIntent.amountUserSells; } function _buildBaselineCall( From 771f801631f91055662ff050632ef5a8381ddf07 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:50:57 +0200 Subject: [PATCH 44/70] chore: clearer syntax for AccountingMath calc --- src/contracts/atlas/GasAccounting.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index d138ba30f..22f807f37 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -369,9 +369,10 @@ abstract contract GasAccounting is SafetyLocks { // If no successful solvers, only collect partial surcharges from solver's fault failures (if any) uint256 _solverSurcharge = solverSurcharge(); if (_solverSurcharge > 0) { - netAtlasGasSurcharge = _solverSurcharge.getPortionFromTotalSurcharge( - ATLAS_SURCHARGE_RATE, ATLAS_SURCHARGE_RATE + BUNDLER_SURCHARGE_RATE - ); + netAtlasGasSurcharge = _solverSurcharge.getPortionFromTotalSurcharge({ + targetSurchargeRate: ATLAS_SURCHARGE_RATE, + totalSurchargeRate: ATLAS_SURCHARGE_RATE + BUNDLER_SURCHARGE_RATE + }); // When no winning solvers, bundler max refund is 80% of metacall gas cost. The remaining 20% can be // collected through storage refunds. Any excess bundler surcharge is instead taken as Atlas surcharge. From 09a2ef3e95c7787086a93f7c821c979ac66e414b Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:02:59 +0200 Subject: [PATCH 45/70] chore: update libs --- lib/solady | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solady b/lib/solady index 855e2e834..973b785be 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 855e2e834a9d791002586a5c9071b1f4c0796bd1 +Subproject commit 973b785beefcb66934844155ccf2639ce10e980c From a4f3571f9b78a3e205afea74f4d37f72e8ebd03c Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:56:39 +0200 Subject: [PATCH 46/70] chore: adjust gas check logs --- test/ExPost.t.sol | 7 ------- test/TrebleSwap.t.sol | 7 +++++-- test/V2Helper.sol | 6 ------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/test/ExPost.t.sol b/test/ExPost.t.sol index c3ff5798a..1fce2d00b 100644 --- a/test/ExPost.t.sol +++ b/test/ExPost.t.sol @@ -139,11 +139,6 @@ contract ExPostTest is BaseTest { address executionEnvironment = atlas.createExecutionEnvironment(userEOA, userOp.control); vm.label(address(executionEnvironment), "EXECUTION ENV"); - console.log("userEOA", userEOA); - console.log("atlas", address(atlas)); - console.log("v2 ExPost Control", address(v2ExPost)); - console.log("executionEnvironment", executionEnvironment); - // User must approve Atlas IERC20(TOKEN_ZERO).approve(address(atlas), type(uint256).max); IERC20(TOKEN_ONE).approve(address(atlas), type(uint256).max); @@ -362,8 +357,6 @@ contract ExPostTest is BaseTest { (bool success,) = address(atlas).call(abi.encodeWithSelector(atlas.metacall.selector, userOp, solverOps, dAppOp)); console.log("Metacall Gas Cost:", gasLeftBefore - gasleft()); - if (success) console.log("success!"); - else console.log("failure"); assertTrue(success); vm.stopPrank(); } diff --git a/test/TrebleSwap.t.sol b/test/TrebleSwap.t.sol index 5cae397c5..79eac047f 100644 --- a/test/TrebleSwap.t.sol +++ b/test/TrebleSwap.t.sol @@ -117,7 +117,7 @@ contract TrebleSwapTest is BaseTest { _doMetacallAndChecks({ winningSolver: address(0) }); } - function testTrebleSwap_Metacall_Erc20ToErc20_OneSolver() public { + function testTrebleSwap_Metacall_Erc20ToErc20_OneSolver_GasCheck() public { // Tx: https://basescan.org/tx/0x0ef4a9c24bbede2b39e12f5e5417733fa8183f372e41ee099c2c7523064c1b55 // Swaps 197.2 USDC for at least 198,080,836.0295 WUF @@ -199,7 +199,7 @@ contract TrebleSwapTest is BaseTest { _doMetacallAndChecks({ winningSolver: address(0) }); } - function testTrebleSwap_Metacall_EthToErc20_OneSolver() public { + function testTrebleSwap_Metacall_EthToErc20_OneSolver_GasCheck() public { // Tx: https://basescan.org/tx/0xe138def4155bea056936038b9374546a366828ab8bf1233056f9e2fe4c6af999 // Swaps 0.123011147164483512 ETH for at least 307.405807527716546728 DAI @@ -301,6 +301,9 @@ contract TrebleSwapTest is BaseTest { txGasUsed = estAtlasGasSurcharge - gasleft(); estAtlasGasSurcharge = txGasUsed * tx.gasprice * atlas.ATLAS_SURCHARGE_RATE() / atlas.SCALE(); + // For benchmarking + console.log("Metacall gas cost: ", txGasUsed); + // Check Atlas auctionWon return value assertEq(auctionWon, auctionWonExpected, "auctionWon not as expected"); diff --git a/test/V2Helper.sol b/test/V2Helper.sol index 442d7f01a..18088422a 100644 --- a/test/V2Helper.sol +++ b/test/V2Helper.sol @@ -59,12 +59,6 @@ contract V2Helper is Test, TxBuilder { { (uint256 token0Balance, uint256 token1Balance) = _getTradeAmtAndDirection(firstPool, secondPool, tokenIn); - console.log("-"); - console.log("sell token", tokenIn); - console.log("token0 in ", token0Balance); - console.log("token1 in ", token1Balance); - console.log("-"); - return TxBuilder.buildUserOperation( from, firstPool, maxFeePerGas, 0, block.number + 2, buildV2SwapCalldata(token0Balance, token1Balance, from) ); From 5962eee94b04908f4c12c13df08c5e451a30d676 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:08:26 +0200 Subject: [PATCH 47/70] feat: split logic out to FactoryLib contract --- script/deploy-atlas.s.sol | 20 +++- src/contracts/atlas/Atlas.sol | 5 +- src/contracts/atlas/Factory.sol | 112 ++++------------------ src/contracts/atlas/FactoryLib.sol | 145 +++++++++++++++++++++++++++++ test/DAppIntegration.t.sol | 7 +- test/Factory.t.sol | 55 +++++++---- test/Permit69.t.sol | 64 +++++++------ test/base/BaseTest.t.sol | 8 +- test/base/TestAtlas.sol | 4 +- 9 files changed, 265 insertions(+), 155 deletions(-) create mode 100644 src/contracts/atlas/FactoryLib.sol diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 95c8f335c..d53a6162f 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -6,6 +6,7 @@ import "forge-std/Test.sol"; import { DeployBaseScript } from "./base/deploy-base.s.sol"; +import { FactoryLib } from "../src/contracts/atlas/FactoryLib.sol"; import { Atlas } from "../src/contracts/atlas/Atlas.sol"; import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; @@ -27,9 +28,9 @@ contract DeployAtlasScript is DeployBaseScript { address deployer = vm.addr(deployerPrivateKey); // Computes the addresses at which AtlasVerification will be deployed - address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); - address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); - address expectedSimulatorAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); + address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); + address expectedSimulatorAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 4); address prevSimAddr = _getAddressFromDeploymentsJson("SIMULATOR"); uint256 prevSimBalance = (prevSimAddr == address(0)) ? 0 : prevSimAddr.balance; @@ -40,13 +41,14 @@ contract DeployAtlasScript is DeployBaseScript { vm.startBroadcast(deployerPrivateKey); ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedAtlasAddr); + FactoryLib factoryLib = new FactoryLib(address(execEnvTemplate)); atlas = new Atlas({ escrowDuration: ESCROW_DURATION, atlasSurchargeRate: ATLAS_SURCHARGE_RATE, bundlerSurchargeRate: BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: expectedSimulatorAddr, - executionTemplate: address(execEnvTemplate), + factoryLib: address(factoryLib), initialSurchargeRecipient: deployer, l2GasCalculator: address(0) }); @@ -110,6 +112,16 @@ contract DeployAtlasScript is DeployBaseScript { console.log("ERROR: Sorter deployment address is 0x0"); error = true; } + // Check FactoryLib address set correctly in Atlas + if (address(factoryLib) != atlas.FACTORY_LIB()) { + console.log("ERROR: FactoryLib address not set correctly in Atlas"); + error = true; + } + // Check ExecutionEnvironment address set correctly in FactoryLib + if (address(execEnvTemplate) != factoryLib.EXECUTION_ENV_TEMPLATE()) { + console.log("ERROR: ExecutionEnvironment address not set correctly in FactoryLib"); + error = true; + } // Check ESCROW_DURATION was not set to 0 if (atlas.ESCROW_DURATION() == 0) { console.log("ERROR: ESCROW_DURATION was set to 0"); diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index 5765c084a..dd3bc2fd5 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -34,7 +34,7 @@ contract Atlas is Escrow, Factory { address simulator, address initialSurchargeRecipient, address l2GasCalculator, - address executionTemplate + address factoryLib ) Escrow( escrowDuration, @@ -45,7 +45,7 @@ contract Atlas is Escrow, Factory { initialSurchargeRecipient, l2GasCalculator ) - Factory(executionTemplate) + Factory(factoryLib) { } /// @notice metacall is the entrypoint function for the Atlas transactions. @@ -371,7 +371,6 @@ contract Atlas is Escrow, Factory { uint32 callConfig ) internal - view override returns (bool) { diff --git a/src/contracts/atlas/Factory.sol b/src/contracts/atlas/Factory.sol index 57a5fcd2c..faf5cf92f 100644 --- a/src/contracts/atlas/Factory.sol +++ b/src/contracts/atlas/Factory.sol @@ -1,29 +1,19 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.25; +import { FactoryLib } from "./FactoryLib.sol"; + import { IDAppControl } from "../interfaces/IDAppControl.sol"; -import { Mimic } from "../common/Mimic.sol"; import { DAppConfig } from "../types/ConfigTypes.sol"; import { UserOperation } from "../types/UserOperation.sol"; -import { AtlasEvents } from "../types/AtlasEvents.sol"; import { AtlasErrors } from "../types/AtlasErrors.sol"; -/// @title Factory -/// @author FastLane Labs -/// @notice Provides functionality for creating and managing execution environments for DApps within the Atlas Protocol. -/// @dev This contract uses deterministic deployment to generate and manage Execution Environment instances based on -/// predefined templates. abstract contract Factory { - address public immutable EXECUTION_ENV_TEMPLATE; + address public immutable FACTORY_LIB; bytes32 internal immutable _FACTORY_BASE_SALT; - /// @notice Initializes a new Factory contract instance by setting the immutable salt for deterministic deployment - /// of Execution Environments and storing the execution template address. - /// @dev The Execution Environment Template must be separately deployed using the same calculated salt. - /// @param executionTemplate Address of the pre-deployed execution template contract for creating Execution - /// Environment instances. - constructor(address executionTemplate) { - EXECUTION_ENV_TEMPLATE = executionTemplate; + constructor(address factoryLib) { + FACTORY_LIB = factoryLib; _FACTORY_BASE_SALT = keccak256(abi.encodePacked(block.chainid, address(this))); } @@ -57,7 +47,6 @@ abstract contract Factory { address control ) external - view returns (address executionEnvironment, uint32 callConfig, bool exists) { callConfig = IDAppControl(control).CALL_CONFIG(); @@ -100,25 +89,13 @@ abstract contract Factory { internal returns (address executionEnvironment) { - bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); bytes32 _salt = _computeSalt(user, control, callConfig); - executionEnvironment = address( - uint160( - uint256( - keccak256( - abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(abi.encodePacked(_creationCode))) - ) - ) - ) + bytes memory returnData = _delegatecallFactoryLib( + abi.encodeCall(FactoryLib.getOrCreateExecutionEnvironment, (user, control, callConfig, _salt)) ); - if (executionEnvironment.code.length == 0) { - assembly { - executionEnvironment := create2(0, add(_creationCode, 32), mload(_creationCode), _salt) - } - emit AtlasEvents.ExecutionEnvironmentCreated(user, executionEnvironment); - } + return abi.decode(returnData, (address)); } /// @notice Generates the address of a user's execution environment affected by deprecated callConfig changes in the @@ -135,79 +112,28 @@ abstract contract Factory { uint32 callConfig ) internal - view returns (address executionEnvironment) { - bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); bytes32 _salt = _computeSalt(user, control, callConfig); - executionEnvironment = address( - uint160( - uint256( - keccak256( - abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(abi.encodePacked(_creationCode))) - ) - ) - ) + bytes memory returnData = _delegatecallFactoryLib( + abi.encodeCall(FactoryLib.getExecutionEnvironmentCustom, (user, control, callConfig, _salt)) ); + + return abi.decode(returnData, (address)); } function _computeSalt(address user, address control, uint32 callConfig) internal view returns (bytes32) { return keccak256(abi.encodePacked(_FACTORY_BASE_SALT, user, control, callConfig)); } - /// @notice Generates the creation code for the execution environment contract. - /// @param control The address of the DAppControl contract associated with the execution environment. - /// @param callConfig The configuration flags defining the behavior of the execution environment. - /// @param user The address of the user for whom the execution environment is being created, contributing to the - /// uniqueness of the creation code. - /// @return creationCode The bytecode representing the creation code of the execution environment contract. - function _getMimicCreationCode( - address user, - address control, - uint32 callConfig - ) - internal - view - returns (bytes memory creationCode) - { - address _executionLib = EXECUTION_ENV_TEMPLATE; - // NOTE: Changing compiler settings or solidity versions can break this. - creationCode = type(Mimic).creationCode; - - assembly { - // Insert the ExecutionEnvironment "Lib" address, into the AAAA placeholder in the creation code. - mstore( - add(creationCode, 79), - or( - and(mload(add(creationCode, 79)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, _executionLib) - ) - ) - - // Insert the user address into the BBBB placeholder in the creation code. - mstore( - add(creationCode, 111), - or( - and(mload(add(creationCode, 111)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, user) - ) - ) - - // Insert the control address into the CCCC placeholder in the creation code. - mstore( - add(creationCode, 132), - or( - and(mload(add(creationCode, 132)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, control) - ) - ) - - // Insert the callConfig into the 2222 placeholder in the creation code. - mstore( - add(creationCode, 153), - or(and(mload(add(creationCode, 153)), not(shl(224, 0xFFFFFFFF))), shl(224, callConfig)) - ) + function _delegatecallFactoryLib(bytes memory data) internal returns (bytes memory) { + (bool _success, bytes memory _result) = FACTORY_LIB.delegatecall(data); + if (!_success) { + assembly { + revert(add(_result, 32), mload(_result)) + } } + return _result; } } diff --git a/src/contracts/atlas/FactoryLib.sol b/src/contracts/atlas/FactoryLib.sol new file mode 100644 index 000000000..4bcc81799 --- /dev/null +++ b/src/contracts/atlas/FactoryLib.sol @@ -0,0 +1,145 @@ +//SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.25; + +import { Mimic } from "../common/Mimic.sol"; +import { AtlasEvents } from "../types/AtlasEvents.sol"; + +// NOTE: Do not call these functions directly. This contract should only ever be delegatecalled by the Atlas contract. + +contract FactoryLib { + address public immutable EXECUTION_ENV_TEMPLATE; + + /// @notice Initializes a new Factory contract instance by setting the immutable salt for deterministic deployment + /// of Execution Environments and storing the execution template address. + /// @dev The Execution Environment Template must be separately deployed using the same calculated salt. + /// @param executionTemplate Address of the pre-deployed execution template contract for creating Execution + /// Environment instances. + constructor(address executionTemplate) { + EXECUTION_ENV_TEMPLATE = executionTemplate; + } + + /// @notice Deploys a new execution environment or retrieves the address of an existing one based on the DApp + /// control, user, and configuration. + /// @dev Uses the `create2` opcode for deterministic deployment, allowing the calculation of the execution + /// environment's address before deployment. The deployment uses a combination of the DAppControl address, user + /// address, call configuration, and a unique salt to ensure the uniqueness and predictability of the environment's + /// address. + /// @param user The address of the user for whom the execution environment is being set. + /// @param control The address of the DAppControl contract providing the operational context. + /// @param callConfig CallConfig settings of the DAppControl contract. + /// @return executionEnvironment The address of the newly created or already existing execution environment. + function getOrCreateExecutionEnvironment( + address user, + address control, + uint32 callConfig, + bytes32 salt + ) + public + returns (address executionEnvironment) + { + bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); + + executionEnvironment = address( + uint160( + uint256( + keccak256( + abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) + ) + ) + ) + ); + + if (executionEnvironment.code.length == 0) { + assembly { + executionEnvironment := create2(0, add(_creationCode, 32), mload(_creationCode), salt) + } + emit AtlasEvents.ExecutionEnvironmentCreated(user, executionEnvironment); + } + } + + /// @notice Generates the address of a user's execution environment affected by deprecated callConfig changes in the + /// DAppControl. + /// @dev Calculates the deterministic address of the execution environment based on the user, control, + /// callConfig, and controlCodeHash, ensuring consistency across changes in callConfig. + /// @param user The address of the user for whom the execution environment's address is being generated. + /// @param control The address of the DAppControl contract associated with the execution environment. + /// @param callConfig The configuration flags defining the behavior of the execution environment. + /// @return executionEnvironment The address of the user's execution environment. + function getExecutionEnvironmentCustom( + address user, + address control, + uint32 callConfig, + bytes32 salt + ) + public + view + returns (address executionEnvironment) + { + bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); + + executionEnvironment = address( + uint160( + uint256( + keccak256( + abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) + ) + ) + ) + ); + } + + /// @notice Generates the creation code for the execution environment contract. + /// @param control The address of the DAppControl contract associated with the execution environment. + /// @param callConfig The configuration flags defining the behavior of the execution environment. + /// @param user The address of the user for whom the execution environment is being created, contributing to the + /// uniqueness of the creation code. + /// @return creationCode The bytecode representing the creation code of the execution environment contract. + function _getMimicCreationCode( + address user, + address control, + uint32 callConfig + ) + internal + view + returns (bytes memory creationCode) + { + address _executionLib = EXECUTION_ENV_TEMPLATE; + // NOTE: Changing compiler settings or solidity versions can break this. + creationCode = type(Mimic).creationCode; + + assembly { + // Insert the ExecutionEnvironment "Lib" address, into the AAAA placeholder in the creation code. + mstore( + add(creationCode, 79), + or( + and(mload(add(creationCode, 79)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, _executionLib) + ) + ) + + // Insert the user address into the BBBB placeholder in the creation code. + mstore( + add(creationCode, 111), + or( + and(mload(add(creationCode, 111)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, user) + ) + ) + + // Insert the control address into the CCCC placeholder in the creation code. + mstore( + add(creationCode, 132), + or( + and(mload(add(creationCode, 132)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, control) + ) + ) + + // Insert the callConfig into the 2222 placeholder in the creation code. + mstore( + add(creationCode, 153), + or(and(mload(add(creationCode, 153)), not(shl(224, 0xFFFFFFFF))), shl(224, callConfig)) + ) + } + } +} diff --git a/test/DAppIntegration.t.sol b/test/DAppIntegration.t.sol index 6f64b0bab..38d93b4cf 100644 --- a/test/DAppIntegration.t.sol +++ b/test/DAppIntegration.t.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.25; import "forge-std/Test.sol"; +import { FactoryLib } from "../src/contracts/atlas/FactoryLib.sol"; import { Atlas } from "../src/contracts/atlas/Atlas.sol"; import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; import { DAppIntegration } from "../src/contracts/atlas/DAppIntegration.sol"; @@ -23,6 +24,7 @@ contract DAppIntegrationTest is Test { MockDAppIntegration public dAppIntegration; DummyDAppControl public dAppControl; AtlasVerification atlasVerification; + FactoryLib factoryLib; address atlasDeployer = makeAddr("atlas deployer"); address governance = makeAddr("governance"); @@ -33,12 +35,13 @@ contract DAppIntegrationTest is Test { vm.startPrank(atlasDeployer); // Compute expected addresses for Atlas - address expectedAtlasAddr = vm.computeCreateAddress(atlasDeployer, vm.getNonce(atlasDeployer) + 2); + address expectedAtlasAddr = vm.computeCreateAddress(atlasDeployer, vm.getNonce(atlasDeployer) + 3); ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedAtlasAddr); // Deploy the AtlasVerification contract atlasVerification = new AtlasVerification(expectedAtlasAddr); + factoryLib = new FactoryLib(address(execEnvTemplate)); // Deploy the Atlas contract with correct parameters atlas = new Atlas({ @@ -47,7 +50,7 @@ contract DAppIntegrationTest is Test { bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: address(atlasVerification), simulator: address(0), - executionTemplate: address(execEnvTemplate), + factoryLib: address(factoryLib), initialSurchargeRecipient: atlasDeployer, l2GasCalculator: address(0) }); diff --git a/test/Factory.t.sol b/test/Factory.t.sol index 1552ae90e..598e7268c 100644 --- a/test/Factory.t.sol +++ b/test/Factory.t.sol @@ -6,6 +6,7 @@ import "forge-std/Test.sol"; import { Atlas } from "../src/contracts/atlas/Atlas.sol"; import { AtlasVerification } from "../src/contracts/atlas/AtlasVerification.sol"; import { Factory } from "../src/contracts/atlas/Factory.sol"; +import { FactoryLib } from "../src/contracts/atlas/FactoryLib.sol"; import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironment.sol"; import { DummyDAppControl, CallConfigBuilder } from "./base/DummyDAppControl.sol"; import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; @@ -15,8 +16,8 @@ import "../src/contracts/types/UserOperation.sol"; import "./base/TestUtils.sol"; -contract MockFactory is Factory, Test { - constructor(address _executionTemplate) Factory(_executionTemplate) { } +contract MockFactory is Factory { + constructor(address factoryLib) Factory(factoryLib) { } function getOrCreateExecutionEnvironment(UserOperation calldata userOp) external @@ -32,6 +33,10 @@ contract MockFactory is Factory, Test { function baseSalt() external view returns (bytes32) { return _FACTORY_BASE_SALT; } +} + +contract MockFactoryLib is FactoryLib { + constructor(address executionTemplate) FactoryLib(executionTemplate) { } function getMimicCreationCode( address user, @@ -40,10 +45,10 @@ contract MockFactory is Factory, Test { ) external view - returns (bytes memory creationCode) { - require(EXECUTION_ENV_TEMPLATE != address(0), "TEST: Execution environment template not set"); - return _getMimicCreationCode(user, control, callConfig); - } + returns (bytes memory) + { + return _getMimicCreationCode(user, control, callConfig); + } } contract FactoryTest is Test { @@ -53,6 +58,7 @@ contract FactoryTest is Test { Atlas public atlas; AtlasVerification public atlasVerification; MockFactory public mockFactory; + MockFactoryLib public factoryLib; DummyDAppControl public dAppControl; address public user; @@ -60,42 +66,51 @@ contract FactoryTest is Test { function setUp() public { user = address(999); address deployer = address(333); - address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 0); - address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); - address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); - bytes32 salt = keccak256(abi.encodePacked(block.chainid, expectedFactoryAddr)); - ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment{ salt: salt }(expectedFactoryAddr); - + + address expectedFactoryLibAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer)); + address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); + address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); + vm.startPrank(deployer); + ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedFactoryAddr); + + factoryLib = new MockFactoryLib(address(execEnvTemplate)); + assertEq(address(factoryLib), expectedFactoryLibAddr, "FactoryLib address mismatch"); + atlas = new Atlas({ escrowDuration: 64, atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: address(0), - executionTemplate: address(execEnvTemplate), + factoryLib: address(factoryLib), initialSurchargeRecipient: deployer, l2GasCalculator: address(0) }); assertEq(address(atlas), expectedAtlasAddr, "Atlas address mismatch"); + atlasVerification = new AtlasVerification(address(atlas)); assertEq(address(atlasVerification), expectedAtlasVerificationAddr, "AtlasVerification address mismatch"); - mockFactory = new MockFactory({ _executionTemplate: address(execEnvTemplate) }); + + mockFactory = new MockFactory({ factoryLib: address(factoryLib) }); assertEq(address(mockFactory), expectedFactoryAddr, "Factory address mismatch"); + dAppControl = new DummyDAppControl(expectedAtlasAddr, deployer, CallConfigBuilder.allFalseCallConfig()); vm.stopPrank(); } function test_createExecutionEnvironment() public { uint32 callConfig = dAppControl.CALL_CONFIG(); - bytes memory creationCode = mockFactory.getMimicCreationCode(user, address(dAppControl), callConfig); + // NOTE: getMimicCreationCode is now in FactoryLib + bytes memory creationCode = factoryLib.getMimicCreationCode(user, address(dAppControl), callConfig); address expectedExecutionEnvironment = address( uint160( uint256( keccak256( abi.encodePacked( bytes1(0xff), - address(mockFactory), + address(factoryLib), mockFactory.computeSalt(user, address(dAppControl), callConfig), keccak256(abi.encodePacked(creationCode)) ) @@ -152,7 +167,7 @@ contract FactoryTest is Test { assertEq(predictedEE, actualEE, "Predicted and actual EE addrs should match 2"); (predictedEE,, exists) = mockFactory.getExecutionEnvironment(user, address(dAppControl)); - + assertTrue(exists, "Execution environment should exist - exist should return true"); assertFalse(predictedEE.code.length == 0, "Execution environment should exist - code at addr"); assertEq(predictedEE, actualEE, "Predicted and actual EE addrs should match 2"); @@ -167,6 +182,10 @@ contract FactoryTest is Test { uint32 _callConfig = 789; bytes32 expectedComputeSalt = keccak256(abi.encodePacked(baseSalt, _user, _control, _callConfig)); - assertEq(expectedComputeSalt, mockFactory.computeSalt(_user, _control, _callConfig), "user salt not computed correctly - depends on base salt"); + assertEq( + expectedComputeSalt, + mockFactory.computeSalt(_user, _control, _callConfig), + "user salt not computed correctly - depends on base salt" + ); } } diff --git a/test/Permit69.t.sol b/test/Permit69.t.sol index af195d3e6..34525c60e 100644 --- a/test/Permit69.t.sol +++ b/test/Permit69.t.sol @@ -8,6 +8,7 @@ import "./base/TestUtils.sol"; import { Permit69 } from "../src/contracts/atlas/Permit69.sol"; import { Mimic } from "../src/contracts/common/Mimic.sol"; +import { FactoryLib } from "../src/contracts/atlas/FactoryLib.sol"; import { SAFE_USER_TRANSFER, SAFE_DAPP_TRANSFER } from "../src/contracts/atlas/Permit69.sol"; import { AtlasEvents } from "../src/contracts/types/AtlasEvents.sol"; @@ -35,27 +36,31 @@ contract Permit69Test is BaseTest { BaseTest.setUp(); mockUser = address(0x13371337); - address deployer = address(333); - address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 0); - address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); - address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); - bytes32 salt = keccak256(abi.encodePacked(block.chainid, expectedFactoryAddr)); - ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment{ salt: salt }(expectedFactoryAddr); + + address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); vm.startPrank(deployer); + ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedAtlasAddr); + FactoryLib factoryLib = new FactoryLib(address(execEnvTemplate)); + mockAtlas = new MockAtlasForPermit69Tests({ - _escrowDuration: 64, - _atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, - _bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, - _verification: expectedAtlasVerificationAddr, - _simulator: address(0), - _executionTemplate: address(execEnvTemplate), + escrowDuration: 64, + atlasSurchargeRate: DEFAULT_ATLAS_SURCHARGE_RATE, + bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, + verification: expectedAtlasVerificationAddr, + simulator: address(0), + factoryLib: address(factoryLib), _surchargeRecipient: deployer, - _l2GasCalculator: address(0) + l2GasCalculator: address(0) }); + vm.stopPrank(); + + console.log("Mock Atlas address: ", address(mockAtlas)); + console.log("Predicted atlas address: ", expectedAtlasAddr); + assertEq(address(mockAtlas), expectedAtlasAddr, "Atlas address mismatch"); - vm.stopPrank(); mockDAppControl = address(0x123321); mockCallConfig = 0; @@ -301,24 +306,24 @@ contract Permit69Test is BaseTest { // Mock Atlas with standard implementations of Permit69's virtual functions contract MockAtlasForPermit69Tests is Atlas { constructor( - uint256 _escrowDuration, - uint256 _atlasSurchargeRate, - uint256 _bundlerSurchargeRate, - address _verification, - address _simulator, + uint256 escrowDuration, + uint256 atlasSurchargeRate, + uint256 bundlerSurchargeRate, + address verification, + address simulator, address _surchargeRecipient, - address _l2GasCalculator, - address _executionTemplate + address l2GasCalculator, + address factoryLib ) Atlas( - _escrowDuration, - _atlasSurchargeRate, - _bundlerSurchargeRate, - _verification, - _simulator, + escrowDuration, + atlasSurchargeRate, + bundlerSurchargeRate, + verification, + simulator, _surchargeRecipient, - _l2GasCalculator, - _executionTemplate + l2GasCalculator, + factoryLib ) { } @@ -375,14 +380,13 @@ contract MockAtlasForPermit69Tests is Atlas { uint32 callConfig ) internal - view returns (bool) { return _verifyUserControlExecutionEnv(sender, user, control, callConfig); } // Exposing above overridden function for testing and Permit69 coverage - function verifyCallerIsExecutionEnv(address user, address control, uint32 callConfig) public view returns (bool) { + function verifyCallerIsExecutionEnv(address user, address control, uint32 callConfig) public returns (bool) { if (!_verifyUserControlExecutionEnv(msg.sender, user, control, callConfig)) { revert AtlasErrors.InvalidEnvironment(); } diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index 07c0fcf02..f001698c1 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -5,6 +5,7 @@ import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; +import { FactoryLib } from "../../src/contracts/atlas/FactoryLib.sol"; import { TestAtlas } from "./TestAtlas.sol"; import { AtlasVerification } from "../../src/contracts/atlas/AtlasVerification.sol"; import { ExecutionEnvironment } from "../../src/contracts/common/ExecutionEnvironment.sol"; @@ -76,9 +77,10 @@ contract BaseTest is Test { simulator = new Simulator(); // Computes the addresses at which AtlasVerification will be deployed - address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); - address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedAtlasAddr); + FactoryLib factoryLib = new FactoryLib(address(execEnvTemplate)); atlas = new TestAtlas({ escrowDuration: DEFAULT_ESCROW_DURATION, @@ -86,7 +88,7 @@ contract BaseTest is Test { bundlerSurchargeRate: DEFAULT_BUNDLER_SURCHARGE_RATE, verification: expectedAtlasVerificationAddr, simulator: address(simulator), - executionTemplate: address(execEnvTemplate), + factoryLib: address(factoryLib), initialSurchargeRecipient: deployer, l2GasCalculator: address(0) }); diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 8d9fe9bb2..6d2513eeb 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -15,7 +15,7 @@ contract TestAtlas is Atlas { address simulator, address initialSurchargeRecipient, address l2GasCalculator, - address executionTemplate + address factoryLib ) Atlas( escrowDuration, @@ -25,7 +25,7 @@ contract TestAtlas is Atlas { simulator, initialSurchargeRecipient, l2GasCalculator, - executionTemplate + factoryLib ) { } From 1307e308a4fdc9207798f74954ee7880a2d1581d Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:05:55 +0200 Subject: [PATCH 48/70] feat: bump to solc 0.8.28 for `transient` keyword --- foundry.toml | 2 +- script/base/deploy-base.s.sol | 2 +- script/create-oev-demo-positions.s.sol | 2 +- script/deploy-atlas.s.sol | 2 +- script/deploy-demo-tokens.s.sol | 2 +- script/deploy-exec-env.s.sol | 2 +- script/deploy-fl-online-control.s.sol | 2 +- script/deploy-gas-calculator.s.sol | 2 +- script/deploy-oev-demo.s.sol | 2 +- script/deploy-solver.s.sol | 2 +- script/deploy-sorter.s.sol | 2 +- script/deploy-swap-intent-control.s.sol | 2 +- script/deploy-tx-builder.s.sol | 2 +- script/deploy-v2-reward-control.s.sol | 2 +- script/log-balances.s.sol | 2 +- script/mint-demo-tokens.s.sol | 2 +- script/set-oev-demo-signers.s.sol | 2 +- script/solver-deposit.s.sol | 2 +- src/contracts/atlas/AtlETH.sol | 2 +- src/contracts/atlas/Atlas.sol | 2 +- src/contracts/atlas/AtlasVerification.sol | 2 +- src/contracts/atlas/DAppIntegration.sol | 2 +- src/contracts/atlas/Escrow.sol | 2 +- src/contracts/atlas/Factory.sol | 2 +- src/contracts/atlas/FactoryLib.sol | 145 ++++++++++++++++++ src/contracts/atlas/GasAccounting.sol | 8 +- src/contracts/atlas/NonceManager.sol | 2 +- src/contracts/atlas/Permit69.sol | 2 +- src/contracts/atlas/SafetyLocks.sol | 2 +- src/contracts/atlas/Storage.sol | 12 +- src/contracts/common/ExecutionBase.sol | 2 +- src/contracts/common/ExecutionEnvironment.sol | 2 +- src/contracts/common/Mimic.sol | 2 +- src/contracts/dapp/ControlTemplate.sol | 2 +- src/contracts/dapp/DAppControl.sol | 2 +- .../examples/ex-post-mev-example/V2ExPost.sol | 2 +- .../examples/fastlane-online/BaseStorage.sol | 2 +- .../fastlane-online/FastLaneControl.sol | 2 +- .../fastlane-online/FastLaneOnlineErrors.sol | 2 +- .../fastlane-online/FastLaneOnlineInner.sol | 2 +- .../fastlane-online/FastLaneOnlineOuter.sol | 2 +- .../fastlane-online/FastLaneTypes.sol | 2 +- .../fastlane-online/IFastLaneOnline.sol | 2 +- .../examples/fastlane-online/OuterHelpers.sol | 2 +- .../fastlane-online/SolverGateway.sol | 2 +- src/contracts/examples/gas-filler/Filler.sol | 2 +- .../GeneralizedBackrunUserBundler.sol | 2 +- .../examples/intents-example/StateIntent.sol | 2 +- .../intents-example/SwapIntentDAppControl.sol | 2 +- .../oev-example/ChainlinkAtlasWrapper.sol | 2 +- .../oev-example/ChainlinkAtlasWrapperAlt.sol | 2 +- .../oev-example/ChainlinkDAppControl.sol | 2 +- .../oev-example/ChainlinkDAppControlAlt.sol | 2 +- .../oev-example/IChainlinkAtlasWrapper.sol | 2 +- .../oev-example/IChainlinkDAppControl.sol | 2 +- .../trebleswap/TrebleSwapDAppControl.sol | 2 +- .../v2-example-router/V2RewardDAppControl.sol | 2 +- .../examples/v2-example/V2DAppControl.sol | 2 +- src/contracts/examples/v4-example/IHooks.sol | 2 +- .../examples/v4-example/IPoolManager.sol | 2 +- .../examples/v4-example/UniV4Hook.sol | 2 +- .../examples/v4-example/V4DAppControl.sol | 2 +- .../gasCalculator/BaseGasCalculator.sol | 2 +- src/contracts/helpers/DemoLendingProtocol.sol | 2 +- src/contracts/helpers/DemoToken.sol | 2 +- src/contracts/helpers/DemoWETH.sol | 2 +- src/contracts/helpers/GovernanceBurner.sol | 2 +- src/contracts/helpers/Simulator.sol | 2 +- src/contracts/helpers/Sorter.sol | 2 +- src/contracts/helpers/TxBuilder.sol | 2 +- src/contracts/helpers/Utilities.sol | 2 +- src/contracts/interfaces/IAtlas.sol | 2 +- .../interfaces/IAtlasVerification.sol | 2 +- src/contracts/interfaces/IDAppControl.sol | 2 +- .../interfaces/IExecutionEnvironment.sol | 2 +- src/contracts/interfaces/IL2GasCalculator.sol | 2 +- src/contracts/interfaces/ISimulator.sol | 2 +- src/contracts/interfaces/ISolverContract.sol | 2 +- src/contracts/libraries/AccountingMath.sol | 2 +- src/contracts/libraries/CallBits.sol | 2 +- src/contracts/libraries/CallVerification.sol | 2 +- src/contracts/libraries/EscrowBits.sol | 2 +- src/contracts/libraries/SafeCall/SafeCall.sol | 2 +- src/contracts/libraries/SafetyBits.sol | 2 +- src/contracts/solver/SolverBase.sol | 2 +- src/contracts/solver/SolverBaseInvertBid.sol | 2 +- src/contracts/solver/src/TestSolver.sol | 2 +- src/contracts/solver/src/TestSolverExPost.sol | 2 +- src/contracts/types/AtlasConstants.sol | 2 +- src/contracts/types/AtlasErrors.sol | 2 +- src/contracts/types/AtlasEvents.sol | 2 +- src/contracts/types/ConfigTypes.sol | 2 +- src/contracts/types/DAppOperation.sol | 2 +- src/contracts/types/EscrowTypes.sol | 2 +- src/contracts/types/LockTypes.sol | 2 +- src/contracts/types/SolverOperation.sol | 2 +- src/contracts/types/UserOperation.sol | 2 +- src/contracts/types/ValidCalls.sol | 2 +- test/Accounting.t.sol | 2 +- test/AccountingMath.t.sol | 2 +- test/AtlETH.t.sol | 2 +- test/AtlasVerification.t.sol | 2 +- test/BidFinding.t.sol | 2 +- test/DAppIntegration.t.sol | 2 +- test/Escrow.t.sol | 2 +- test/ExPost.t.sol | 2 +- test/ExecutionBase.t.sol | 2 +- test/ExecutionEnvironment.t.sol | 2 +- test/FLOnline.t.sol | 2 +- test/Factory.t.sol | 2 +- test/FlashLoan.t.sol | 2 +- test/GasAccounting.t.sol | 8 +- test/MainTest.t.sol | 2 +- test/Mimic.t.sol | 2 +- test/NonceManager.t.sol | 2 +- test/OEV.t.sol | 2 +- test/OEValt.t.sol | 2 +- test/Permit69.t.sol | 2 +- test/SafetyLocks.t.sol | 12 +- test/Simulator.t.sol | 2 +- test/Sorter.t.sol | 2 +- test/Storage.t.sol | 14 +- test/Surcharge.t.sol | 2 +- test/SwapIntent.t.sol | 2 +- test/SwapIntentInvertBid.t.sol | 2 +- test/TrebleSwap.t.sol | 2 +- test/V2Helper.sol | 2 +- test/V2RewardDAppControl.t.sol | 2 +- test/base/ArbitrageTest.t.sol | 2 +- test/base/BaseTest.t.sol | 2 +- test/base/DummyDAppControl.sol | 2 +- test/base/GasSponsorDAppControl.sol | 2 +- test/base/TestAtlas.sol | 10 +- test/base/TestUtils.sol | 2 +- test/base/builders/DAppOperationBuilder.sol | 2 +- test/base/builders/SolverOperationBuilder.sol | 2 +- test/base/builders/UserOperationBuilder.sol | 2 +- test/base/interfaces/IUniswapV2Router.sol | 2 +- test/helpers/CallConfigBuilder.sol | 2 +- test/helpers/DummyDAppControlBuilder.sol | 2 +- test/libraries/CallBits.t.sol | 2 +- test/libraries/CallVerification.t.sol | 2 +- test/libraries/EscrowBits.t.sol | 2 +- test/libraries/SafetyBits.t.sol | 2 +- 144 files changed, 304 insertions(+), 179 deletions(-) create mode 100644 src/contracts/atlas/FactoryLib.sol diff --git a/foundry.toml b/foundry.toml index fdbb6ebe5..217b928a2 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,7 +5,7 @@ block_gas_limit = 300000000 gas_limit = 3000000000 gas_price = 1500000000 - solc_version = "0.8.25" + solc_version = "0.8.28" evm_version = "cancun" isolate = false gas_reports = ["Atlas", "AtlasVerification", "Simulator", "Sorter", "ExecutionEnvironment"] diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index fb28277fb..0b5059d45 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/create-oev-demo-positions.s.sol b/script/create-oev-demo-positions.s.sol index 283309e84..be10a6bcf 100644 --- a/script/create-oev-demo-positions.s.sol +++ b/script/create-oev-demo-positions.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index 95c8f335c..866d20f1d 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-demo-tokens.s.sol b/script/deploy-demo-tokens.s.sol index 54afc65fa..3d24baca4 100644 --- a/script/deploy-demo-tokens.s.sol +++ b/script/deploy-demo-tokens.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-exec-env.s.sol b/script/deploy-exec-env.s.sol index 337678dcd..d603a180a 100644 --- a/script/deploy-exec-env.s.sol +++ b/script/deploy-exec-env.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-fl-online-control.s.sol b/script/deploy-fl-online-control.s.sol index 3e513931a..ac9d9998a 100644 --- a/script/deploy-fl-online-control.s.sol +++ b/script/deploy-fl-online-control.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-gas-calculator.s.sol b/script/deploy-gas-calculator.s.sol index 3866bbaf1..68b9d0f01 100644 --- a/script/deploy-gas-calculator.s.sol +++ b/script/deploy-gas-calculator.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/script/deploy-oev-demo.s.sol b/script/deploy-oev-demo.s.sol index dbe42e4ee..d48fd33ba 100644 --- a/script/deploy-oev-demo.s.sol +++ b/script/deploy-oev-demo.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-solver.s.sol b/script/deploy-solver.s.sol index 499e6b733..12ef6c13e 100644 --- a/script/deploy-solver.s.sol +++ b/script/deploy-solver.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-sorter.s.sol b/script/deploy-sorter.s.sol index 3a6f2f1f8..9d9c44c48 100644 --- a/script/deploy-sorter.s.sol +++ b/script/deploy-sorter.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-swap-intent-control.s.sol b/script/deploy-swap-intent-control.s.sol index 3eb01e615..9e3b01eff 100644 --- a/script/deploy-swap-intent-control.s.sol +++ b/script/deploy-swap-intent-control.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-tx-builder.s.sol b/script/deploy-tx-builder.s.sol index c9fb32758..fe6a977a0 100644 --- a/script/deploy-tx-builder.s.sol +++ b/script/deploy-tx-builder.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/deploy-v2-reward-control.s.sol b/script/deploy-v2-reward-control.s.sol index 46db22ea6..2f6b348eb 100644 --- a/script/deploy-v2-reward-control.s.sol +++ b/script/deploy-v2-reward-control.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/log-balances.s.sol b/script/log-balances.s.sol index a8de086b7..edbe43314 100644 --- a/script/log-balances.s.sol +++ b/script/log-balances.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/mint-demo-tokens.s.sol b/script/mint-demo-tokens.s.sol index ab8ef1c4c..b7c814c7e 100644 --- a/script/mint-demo-tokens.s.sol +++ b/script/mint-demo-tokens.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/set-oev-demo-signers.s.sol b/script/set-oev-demo-signers.s.sol index e2c8ead19..b88b19038 100644 --- a/script/set-oev-demo-signers.s.sol +++ b/script/set-oev-demo-signers.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/script/solver-deposit.s.sol b/script/solver-deposit.s.sol index 01e4ecbf6..57e10b008 100644 --- a/script/solver-deposit.s.sol +++ b/script/solver-deposit.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/atlas/AtlETH.sol b/src/contracts/atlas/AtlETH.sol index 2bfcdd214..60bfb9eeb 100644 --- a/src/contracts/atlas/AtlETH.sol +++ b/src/contracts/atlas/AtlETH.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { SafeCast } from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol"; diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index 5765c084a..6091d0b32 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { LibSort } from "solady/utils/LibSort.sol"; diff --git a/src/contracts/atlas/AtlasVerification.sol b/src/contracts/atlas/AtlasVerification.sol index 9c1b7d5cc..2bf28d6d4 100644 --- a/src/contracts/atlas/AtlasVerification.sol +++ b/src/contracts/atlas/AtlasVerification.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { EIP712 } from "openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol"; import { ECDSA } from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; diff --git a/src/contracts/atlas/DAppIntegration.sol b/src/contracts/atlas/DAppIntegration.sol index 1ffc0c8e5..447a1c863 100644 --- a/src/contracts/atlas/DAppIntegration.sol +++ b/src/contracts/atlas/DAppIntegration.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../interfaces/IDAppControl.sol"; import { IAtlas } from "../interfaces/IAtlas.sol"; diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 713fe336c..2d68b88f6 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { AtlETH } from "./AtlETH.sol"; import { IExecutionEnvironment } from "../interfaces/IExecutionEnvironment.sol"; diff --git a/src/contracts/atlas/Factory.sol b/src/contracts/atlas/Factory.sol index 57a5fcd2c..181563e2c 100644 --- a/src/contracts/atlas/Factory.sol +++ b/src/contracts/atlas/Factory.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../interfaces/IDAppControl.sol"; import { Mimic } from "../common/Mimic.sol"; diff --git a/src/contracts/atlas/FactoryLib.sol b/src/contracts/atlas/FactoryLib.sol new file mode 100644 index 000000000..9ca878bbc --- /dev/null +++ b/src/contracts/atlas/FactoryLib.sol @@ -0,0 +1,145 @@ +//SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.28; + +import { Mimic } from "../common/Mimic.sol"; +import { AtlasEvents } from "../types/AtlasEvents.sol"; + +// NOTE: Do not call these functions directly. This contract should only ever be delegatecalled by the Atlas contract. + +contract FactoryLib { + address public immutable EXECUTION_ENV_TEMPLATE; + + /// @notice Initializes a new Factory contract instance by setting the immutable salt for deterministic deployment + /// of Execution Environments and storing the execution template address. + /// @dev The Execution Environment Template must be separately deployed using the same calculated salt. + /// @param executionTemplate Address of the pre-deployed execution template contract for creating Execution + /// Environment instances. + constructor(address executionTemplate) { + EXECUTION_ENV_TEMPLATE = executionTemplate; + } + + /// @notice Deploys a new execution environment or retrieves the address of an existing one based on the DApp + /// control, user, and configuration. + /// @dev Uses the `create2` opcode for deterministic deployment, allowing the calculation of the execution + /// environment's address before deployment. The deployment uses a combination of the DAppControl address, user + /// address, call configuration, and a unique salt to ensure the uniqueness and predictability of the environment's + /// address. + /// @param user The address of the user for whom the execution environment is being set. + /// @param control The address of the DAppControl contract providing the operational context. + /// @param callConfig CallConfig settings of the DAppControl contract. + /// @return executionEnvironment The address of the newly created or already existing execution environment. + function getOrCreateExecutionEnvironment( + address user, + address control, + uint32 callConfig, + bytes32 salt + ) + public + returns (address executionEnvironment) + { + bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); + + executionEnvironment = address( + uint160( + uint256( + keccak256( + abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) + ) + ) + ) + ); + + if (executionEnvironment.code.length == 0) { + assembly { + executionEnvironment := create2(0, add(_creationCode, 32), mload(_creationCode), salt) + } + emit AtlasEvents.ExecutionEnvironmentCreated(user, executionEnvironment); + } + } + + /// @notice Generates the address of a user's execution environment affected by deprecated callConfig changes in the + /// DAppControl. + /// @dev Calculates the deterministic address of the execution environment based on the user, control, + /// callConfig, and controlCodeHash, ensuring consistency across changes in callConfig. + /// @param user The address of the user for whom the execution environment's address is being generated. + /// @param control The address of the DAppControl contract associated with the execution environment. + /// @param callConfig The configuration flags defining the behavior of the execution environment. + /// @return executionEnvironment The address of the user's execution environment. + function getExecutionEnvironmentCustom( + address user, + address control, + uint32 callConfig, + bytes32 salt + ) + public + view + returns (address executionEnvironment) + { + bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); + + executionEnvironment = address( + uint160( + uint256( + keccak256( + abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) + ) + ) + ) + ); + } + + /// @notice Generates the creation code for the execution environment contract. + /// @param control The address of the DAppControl contract associated with the execution environment. + /// @param callConfig The configuration flags defining the behavior of the execution environment. + /// @param user The address of the user for whom the execution environment is being created, contributing to the + /// uniqueness of the creation code. + /// @return creationCode The bytecode representing the creation code of the execution environment contract. + function _getMimicCreationCode( + address user, + address control, + uint32 callConfig + ) + internal + view + returns (bytes memory creationCode) + { + address _executionLib = EXECUTION_ENV_TEMPLATE; + // NOTE: Changing compiler settings or solidity versions can break this. + creationCode = type(Mimic).creationCode; + + assembly { + // Insert the ExecutionEnvironment "Lib" address, into the AAAA placeholder in the creation code. + mstore( + add(creationCode, 79), + or( + and(mload(add(creationCode, 79)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, _executionLib) + ) + ) + + // Insert the user address into the BBBB placeholder in the creation code. + mstore( + add(creationCode, 111), + or( + and(mload(add(creationCode, 111)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, user) + ) + ) + + // Insert the control address into the CCCC placeholder in the creation code. + mstore( + add(creationCode, 132), + or( + and(mload(add(creationCode, 132)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), + shl(96, control) + ) + ) + + // Insert the callConfig into the 2222 placeholder in the creation code. + mstore( + add(creationCode, 153), + or(and(mload(add(creationCode, 153)), not(shl(224, 0xFFFFFFFF))), shl(224, callConfig)) + ) + } + } +} diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index ce79b62af..474e6442c 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { SafeCast } from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol"; @@ -46,7 +46,7 @@ abstract contract GasAccounting is SafetyLocks { uint256 _rawClaims = (FIXED_GAS_OFFSET + gasMarker) * tx.gasprice; // Set any withdraws or deposits - _setClaims(_rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE)); + claims = _rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE); // Atlas surcharge is based on the raw claims value. _setFees(_rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE)); @@ -105,7 +105,7 @@ abstract contract GasAccounting is SafetyLocks { } function _deficit() internal view returns (uint256) { - return claims() + withdrawals() + fees() - writeoffs(); + return claims + withdrawals() + fees() - writeoffs(); } /// @notice Allows a solver to settle any outstanding ETH owed, either to repay gas used by their solverOp or to @@ -346,7 +346,7 @@ abstract contract GasAccounting is SafetyLocks { adjustedWithdrawals = withdrawals(); adjustedDeposits = deposits(); - adjustedClaims = claims(); + adjustedClaims = claims; adjustedWriteoffs = writeoffs(); uint256 _fees = fees(); diff --git a/src/contracts/atlas/NonceManager.sol b/src/contracts/atlas/NonceManager.sol index 19fa27956..3f1b9a38c 100644 --- a/src/contracts/atlas/NonceManager.sol +++ b/src/contracts/atlas/NonceManager.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { AtlasConstants } from "../types/AtlasConstants.sol"; diff --git a/src/contracts/atlas/Permit69.sol b/src/contracts/atlas/Permit69.sol index 84ba2e599..096d7630c 100644 --- a/src/contracts/atlas/Permit69.sol +++ b/src/contracts/atlas/Permit69.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/atlas/SafetyLocks.sol b/src/contracts/atlas/SafetyLocks.sol index 6d7ec03f2..87f274eea 100644 --- a/src/contracts/atlas/SafetyLocks.sol +++ b/src/contracts/atlas/SafetyLocks.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { Storage } from "./Storage.sol"; import { CallBits } from "../libraries/CallBits.sol"; diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 0359dc2f9..2d2120554 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/EscrowTypes.sol"; import "../types/LockTypes.sol"; @@ -36,7 +36,7 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { bytes32 private constant _T_SOLVER_LOCK_SLOT = keccak256("ATLAS_SOLVER_LOCK"); bytes32 private constant _T_SOLVER_TO_SLOT = keccak256("ATLAS_SOLVER_TO"); - bytes32 private constant _T_CLAIMS_SLOT = keccak256("ATLAS_CLAIMS"); + uint256 public transient claims; bytes32 private constant _T_FEES_SLOT = keccak256("ATLAS_FEES"); bytes32 private constant _T_WRITEOFFS_SLOT = keccak256("ATLAS_WRITEOFFS"); bytes32 private constant _T_WITHDRAWALS_SLOT = keccak256("ATLAS_WITHDRAWALS"); @@ -155,10 +155,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { // Transient Internal Getters // // ---------------------------------------------------- // - function claims() internal view returns (uint256) { - return uint256(_tload(_T_CLAIMS_SLOT)); - } - function fees() internal view returns (uint256) { return uint256(_tload(_T_FEES_SLOT)); } @@ -252,10 +248,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { _tstore(_T_SOLVER_TO_SLOT, bytes32(uint256(uint160(newSolverTo)))); } - function _setClaims(uint256 newClaims) internal { - _tstore(_T_CLAIMS_SLOT, bytes32(newClaims)); - } - function _setFees(uint256 newFees) internal { _tstore(_T_FEES_SLOT, bytes32(newFees)); } diff --git a/src/contracts/common/ExecutionBase.sol b/src/contracts/common/ExecutionBase.sol index 4bdeddec1..a1383ae9e 100644 --- a/src/contracts/common/ExecutionBase.sol +++ b/src/contracts/common/ExecutionBase.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/common/ExecutionEnvironment.sol b/src/contracts/common/ExecutionEnvironment.sol index 42945ad01..84fb2fc03 100644 --- a/src/contracts/common/ExecutionEnvironment.sol +++ b/src/contracts/common/ExecutionEnvironment.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/common/Mimic.sol b/src/contracts/common/Mimic.sol index a88446bc9..ad7f4a718 100644 --- a/src/contracts/common/Mimic.sol +++ b/src/contracts/common/Mimic.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; contract Mimic { /* diff --git a/src/contracts/dapp/ControlTemplate.sol b/src/contracts/dapp/ControlTemplate.sol index b510f7f1d..3663f915e 100644 --- a/src/contracts/dapp/ControlTemplate.sol +++ b/src/contracts/dapp/ControlTemplate.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; import "../types/UserOperation.sol"; diff --git a/src/contracts/dapp/DAppControl.sol b/src/contracts/dapp/DAppControl.sol index 03c4d977e..8340bd7f4 100644 --- a/src/contracts/dapp/DAppControl.sol +++ b/src/contracts/dapp/DAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { DAppControlTemplate } from "./ControlTemplate.sol"; import { ExecutionBase } from "../common/ExecutionBase.sol"; diff --git a/src/contracts/examples/ex-post-mev-example/V2ExPost.sol b/src/contracts/examples/ex-post-mev-example/V2ExPost.sol index 7c90b9140..66b71792a 100644 --- a/src/contracts/examples/ex-post-mev-example/V2ExPost.sol +++ b/src/contracts/examples/ex-post-mev-example/V2ExPost.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/fastlane-online/BaseStorage.sol b/src/contracts/examples/fastlane-online/BaseStorage.sol index ca2514a3d..457b564a5 100644 --- a/src/contracts/examples/fastlane-online/BaseStorage.sol +++ b/src/contracts/examples/fastlane-online/BaseStorage.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../../types/SolverOperation.sol"; diff --git a/src/contracts/examples/fastlane-online/FastLaneControl.sol b/src/contracts/examples/fastlane-online/FastLaneControl.sol index 9b0388c95..183e6c350 100644 --- a/src/contracts/examples/fastlane-online/FastLaneControl.sol +++ b/src/contracts/examples/fastlane-online/FastLaneControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol b/src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol index 603cdff3a..436bb994a 100644 --- a/src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol +++ b/src/contracts/examples/fastlane-online/FastLaneOnlineErrors.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; contract FastLaneOnlineErrors { // FastLaneControl.sol diff --git a/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol b/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol index 492085440..b49f1f55d 100644 --- a/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol +++ b/src/contracts/examples/fastlane-online/FastLaneOnlineInner.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol b/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol index b4a9efe4f..fb4f10f65 100644 --- a/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol +++ b/src/contracts/examples/fastlane-online/FastLaneOnlineOuter.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/fastlane-online/FastLaneTypes.sol b/src/contracts/examples/fastlane-online/FastLaneTypes.sol index 13e4270f8..786e6a7e3 100644 --- a/src/contracts/examples/fastlane-online/FastLaneTypes.sol +++ b/src/contracts/examples/fastlane-online/FastLaneTypes.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // External representation of the swap intent struct SwapIntent { diff --git a/src/contracts/examples/fastlane-online/IFastLaneOnline.sol b/src/contracts/examples/fastlane-online/IFastLaneOnline.sol index c61c79508..df5d056d5 100644 --- a/src/contracts/examples/fastlane-online/IFastLaneOnline.sol +++ b/src/contracts/examples/fastlane-online/IFastLaneOnline.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../../types/UserOperation.sol"; import "../../types/SolverOperation.sol"; diff --git a/src/contracts/examples/fastlane-online/OuterHelpers.sol b/src/contracts/examples/fastlane-online/OuterHelpers.sol index 4a0544d40..976674c2f 100644 --- a/src/contracts/examples/fastlane-online/OuterHelpers.sol +++ b/src/contracts/examples/fastlane-online/OuterHelpers.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/fastlane-online/SolverGateway.sol b/src/contracts/examples/fastlane-online/SolverGateway.sol index 26e3ed80c..0e106b7b1 100644 --- a/src/contracts/examples/fastlane-online/SolverGateway.sol +++ b/src/contracts/examples/fastlane-online/SolverGateway.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/gas-filler/Filler.sol b/src/contracts/examples/gas-filler/Filler.sol index 904c11476..29f042c33 100644 --- a/src/contracts/examples/gas-filler/Filler.sol +++ b/src/contracts/examples/gas-filler/Filler.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol b/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol index 22aa7620c..643fe0bea 100644 --- a/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol +++ b/src/contracts/examples/generalized-backrun/GeneralizedBackrunUserBundler.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/intents-example/StateIntent.sol b/src/contracts/examples/intents-example/StateIntent.sol index 3083ca379..bc3984d81 100644 --- a/src/contracts/examples/intents-example/StateIntent.sol +++ b/src/contracts/examples/intents-example/StateIntent.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Atlas Base Imports import { IExecutionEnvironment } from "../../interfaces/IExecutionEnvironment.sol"; diff --git a/src/contracts/examples/intents-example/SwapIntentDAppControl.sol b/src/contracts/examples/intents-example/SwapIntentDAppControl.sol index 8250a32e0..fd98fd9fa 100644 --- a/src/contracts/examples/intents-example/SwapIntentDAppControl.sol +++ b/src/contracts/examples/intents-example/SwapIntentDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol b/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol index d00f82af8..daf3d5dd7 100644 --- a/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol +++ b/src/contracts/examples/oev-example/ChainlinkAtlasWrapper.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; import { SafeERC20, IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; diff --git a/src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol b/src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol index 47cefee0d..ed3842065 100644 --- a/src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol +++ b/src/contracts/examples/oev-example/ChainlinkAtlasWrapperAlt.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; import { SafeERC20, IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; diff --git a/src/contracts/examples/oev-example/ChainlinkDAppControl.sol b/src/contracts/examples/oev-example/ChainlinkDAppControl.sol index 18883ed99..fc6d7ef2b 100644 --- a/src/contracts/examples/oev-example/ChainlinkDAppControl.sol +++ b/src/contracts/examples/oev-example/ChainlinkDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { ECDSA } from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol"; import { CallConfig } from "../../types/ConfigTypes.sol"; diff --git a/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol b/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol index 611e32bdc..53b699ad5 100644 --- a/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol +++ b/src/contracts/examples/oev-example/ChainlinkDAppControlAlt.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { CallConfig } from "../../types/ConfigTypes.sol"; import "../../types/UserOperation.sol"; diff --git a/src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol b/src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol index a45b6e7b8..01fa7d141 100644 --- a/src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol +++ b/src/contracts/examples/oev-example/IChainlinkAtlasWrapper.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IChainlinkDAppControl } from "./IChainlinkDAppControl.sol"; diff --git a/src/contracts/examples/oev-example/IChainlinkDAppControl.sol b/src/contracts/examples/oev-example/IChainlinkDAppControl.sol index 3c0ff8944..663a77518 100644 --- a/src/contracts/examples/oev-example/IChainlinkDAppControl.sol +++ b/src/contracts/examples/oev-example/IChainlinkDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; interface IChainlinkDAppControl { function verifyTransmitSigners( diff --git a/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol b/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol index 413a54af9..865b3c2ba 100644 --- a/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol +++ b/src/contracts/examples/trebleswap/TrebleSwapDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol b/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol index 45a73d5d9..667e27b65 100644 --- a/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol +++ b/src/contracts/examples/v2-example-router/V2RewardDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/v2-example/V2DAppControl.sol b/src/contracts/examples/v2-example/V2DAppControl.sol index de6e2f9f6..591c68648 100644 --- a/src/contracts/examples/v2-example/V2DAppControl.sol +++ b/src/contracts/examples/v2-example/V2DAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/examples/v4-example/IHooks.sol b/src/contracts/examples/v4-example/IHooks.sol index 3f4fa5caf..03d33c679 100644 --- a/src/contracts/examples/v4-example/IHooks.sol +++ b/src/contracts/examples/v4-example/IHooks.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IPoolManager } from "./IPoolManager.sol"; diff --git a/src/contracts/examples/v4-example/IPoolManager.sol b/src/contracts/examples/v4-example/IPoolManager.sol index a2e49b34e..e9e022eba 100644 --- a/src/contracts/examples/v4-example/IPoolManager.sol +++ b/src/contracts/examples/v4-example/IPoolManager.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IHooks } from "./IHooks.sol"; diff --git a/src/contracts/examples/v4-example/UniV4Hook.sol b/src/contracts/examples/v4-example/UniV4Hook.sol index 490622e5b..7922c3745 100644 --- a/src/contracts/examples/v4-example/UniV4Hook.sol +++ b/src/contracts/examples/v4-example/UniV4Hook.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // V4 Imports import { IPoolManager } from "./IPoolManager.sol"; diff --git a/src/contracts/examples/v4-example/V4DAppControl.sol b/src/contracts/examples/v4-example/V4DAppControl.sol index 093defc0d..3eb4d198f 100644 --- a/src/contracts/examples/v4-example/V4DAppControl.sol +++ b/src/contracts/examples/v4-example/V4DAppControl.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Base Imports import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index 97e404a66..ff9b73208 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; diff --git a/src/contracts/helpers/DemoLendingProtocol.sol b/src/contracts/helpers/DemoLendingProtocol.sol index ebe66343b..3a6ba24f3 100644 --- a/src/contracts/helpers/DemoLendingProtocol.sol +++ b/src/contracts/helpers/DemoLendingProtocol.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeERC20, IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; diff --git a/src/contracts/helpers/DemoToken.sol b/src/contracts/helpers/DemoToken.sol index c2e7a93d6..375783aa6 100644 --- a/src/contracts/helpers/DemoToken.sol +++ b/src/contracts/helpers/DemoToken.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { ERC20 } from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; diff --git a/src/contracts/helpers/DemoWETH.sol b/src/contracts/helpers/DemoWETH.sol index 3824bd5ea..2b9c0f15d 100644 --- a/src/contracts/helpers/DemoWETH.sol +++ b/src/contracts/helpers/DemoWETH.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { WETH } from "solady/tokens/WETH.sol"; import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; diff --git a/src/contracts/helpers/GovernanceBurner.sol b/src/contracts/helpers/GovernanceBurner.sol index fdad5a2f0..325784c09 100644 --- a/src/contracts/helpers/GovernanceBurner.sol +++ b/src/contracts/helpers/GovernanceBurner.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../interfaces/IDAppControl.sol"; diff --git a/src/contracts/helpers/Simulator.sol b/src/contracts/helpers/Simulator.sol index 2385b8477..5ac2653d7 100644 --- a/src/contracts/helpers/Simulator.sol +++ b/src/contracts/helpers/Simulator.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; diff --git a/src/contracts/helpers/Sorter.sol b/src/contracts/helpers/Sorter.sol index b4a0fd924..43b0a9df2 100644 --- a/src/contracts/helpers/Sorter.sol +++ b/src/contracts/helpers/Sorter.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IAtlas } from "../interfaces/IAtlas.sol"; import { IDAppControl } from "../interfaces/IDAppControl.sol"; diff --git a/src/contracts/helpers/TxBuilder.sol b/src/contracts/helpers/TxBuilder.sol index dea57c90b..2d95b81fb 100644 --- a/src/contracts/helpers/TxBuilder.sol +++ b/src/contracts/helpers/TxBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../interfaces/IDAppControl.sol"; import { IAtlas } from "../interfaces/IAtlas.sol"; diff --git a/src/contracts/helpers/Utilities.sol b/src/contracts/helpers/Utilities.sol index a04978ff7..01cb6adca 100644 --- a/src/contracts/helpers/Utilities.sol +++ b/src/contracts/helpers/Utilities.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Script.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/interfaces/IAtlas.sol b/src/contracts/interfaces/IAtlas.sol index b518a0016..d66ce2adb 100644 --- a/src/contracts/interfaces/IAtlas.sol +++ b/src/contracts/interfaces/IAtlas.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; import "../types/UserOperation.sol"; diff --git a/src/contracts/interfaces/IAtlasVerification.sol b/src/contracts/interfaces/IAtlasVerification.sol index ed4f050f5..f8af0fa31 100644 --- a/src/contracts/interfaces/IAtlasVerification.sol +++ b/src/contracts/interfaces/IAtlasVerification.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/UserOperation.sol"; import "../types/ConfigTypes.sol"; diff --git a/src/contracts/interfaces/IDAppControl.sol b/src/contracts/interfaces/IDAppControl.sol index e3be1417f..20625d463 100644 --- a/src/contracts/interfaces/IDAppControl.sol +++ b/src/contracts/interfaces/IDAppControl.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/UserOperation.sol"; import "../types/SolverOperation.sol"; diff --git a/src/contracts/interfaces/IExecutionEnvironment.sol b/src/contracts/interfaces/IExecutionEnvironment.sol index 9dcdee96a..af0c7e040 100644 --- a/src/contracts/interfaces/IExecutionEnvironment.sol +++ b/src/contracts/interfaces/IExecutionEnvironment.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; import "../types/UserOperation.sol"; diff --git a/src/contracts/interfaces/IL2GasCalculator.sol b/src/contracts/interfaces/IL2GasCalculator.sol index 387aab8e8..41fd7c364 100644 --- a/src/contracts/interfaces/IL2GasCalculator.sol +++ b/src/contracts/interfaces/IL2GasCalculator.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; interface IL2GasCalculator { /// @notice Calculate the cost of calldata in ETH on a L2 with a different fee structure than mainnet diff --git a/src/contracts/interfaces/ISimulator.sol b/src/contracts/interfaces/ISimulator.sol index f1d3bb8ce..ae2148744 100644 --- a/src/contracts/interfaces/ISimulator.sol +++ b/src/contracts/interfaces/ISimulator.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; import "../types/UserOperation.sol"; diff --git a/src/contracts/interfaces/ISolverContract.sol b/src/contracts/interfaces/ISolverContract.sol index b055a0415..e0a87a968 100644 --- a/src/contracts/interfaces/ISolverContract.sol +++ b/src/contracts/interfaces/ISolverContract.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; diff --git a/src/contracts/libraries/AccountingMath.sol b/src/contracts/libraries/AccountingMath.sol index 5706f1ddf..43a941c47 100644 --- a/src/contracts/libraries/AccountingMath.sol +++ b/src/contracts/libraries/AccountingMath.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; library AccountingMath { uint256 internal constant _MAX_BUNDLER_REFUND_RATE = 8_000_000; // out of 10_000_000 = 80% diff --git a/src/contracts/libraries/CallBits.sol b/src/contracts/libraries/CallBits.sol index f5c1d0a6e..53abaa446 100644 --- a/src/contracts/libraries/CallBits.sol +++ b/src/contracts/libraries/CallBits.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../interfaces/IDAppControl.sol"; diff --git a/src/contracts/libraries/CallVerification.sol b/src/contracts/libraries/CallVerification.sol index ba4f4829e..4eab4c580 100644 --- a/src/contracts/libraries/CallVerification.sol +++ b/src/contracts/libraries/CallVerification.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/SolverOperation.sol"; import "../types/UserOperation.sol"; diff --git a/src/contracts/libraries/EscrowBits.sol b/src/contracts/libraries/EscrowBits.sol index d8c19356c..aa5eb28f6 100644 --- a/src/contracts/libraries/EscrowBits.sol +++ b/src/contracts/libraries/EscrowBits.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/EscrowTypes.sol"; diff --git a/src/contracts/libraries/SafeCall/SafeCall.sol b/src/contracts/libraries/SafeCall/SafeCall.sol index db83111d1..02ca156fc 100644 --- a/src/contracts/libraries/SafeCall/SafeCall.sol +++ b/src/contracts/libraries/SafeCall/SafeCall.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; /// @title SafeCall /// @author FastLane Labs diff --git a/src/contracts/libraries/SafetyBits.sol b/src/contracts/libraries/SafetyBits.sol index c9fe77717..e912807e9 100644 --- a/src/contracts/libraries/SafetyBits.sol +++ b/src/contracts/libraries/SafetyBits.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../types/LockTypes.sol"; diff --git a/src/contracts/solver/SolverBase.sol b/src/contracts/solver/SolverBase.sol index ca57036cd..ea9553bc1 100644 --- a/src/contracts/solver/SolverBase.sol +++ b/src/contracts/solver/SolverBase.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/solver/SolverBaseInvertBid.sol b/src/contracts/solver/SolverBaseInvertBid.sol index 328ffc169..8963df9f7 100644 --- a/src/contracts/solver/SolverBaseInvertBid.sol +++ b/src/contracts/solver/SolverBaseInvertBid.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/solver/src/TestSolver.sol b/src/contracts/solver/src/TestSolver.sol index 445ac3bea..5f5441a5a 100644 --- a/src/contracts/solver/src/TestSolver.sol +++ b/src/contracts/solver/src/TestSolver.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SolverBase } from "../../solver/SolverBase.sol"; diff --git a/src/contracts/solver/src/TestSolverExPost.sol b/src/contracts/solver/src/TestSolverExPost.sol index 0cdf88cc5..74dbbbe9e 100644 --- a/src/contracts/solver/src/TestSolverExPost.sol +++ b/src/contracts/solver/src/TestSolverExPost.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/src/contracts/types/AtlasConstants.sol b/src/contracts/types/AtlasConstants.sol index 25fa70fb7..dbe575056 100644 --- a/src/contracts/types/AtlasConstants.sol +++ b/src/contracts/types/AtlasConstants.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "./ValidCalls.sol"; diff --git a/src/contracts/types/AtlasErrors.sol b/src/contracts/types/AtlasErrors.sol index 582c14e89..606f7239f 100644 --- a/src/contracts/types/AtlasErrors.sol +++ b/src/contracts/types/AtlasErrors.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "./ValidCalls.sol"; diff --git a/src/contracts/types/AtlasEvents.sol b/src/contracts/types/AtlasEvents.sol index d53e93e9b..8bd9383d7 100644 --- a/src/contracts/types/AtlasEvents.sol +++ b/src/contracts/types/AtlasEvents.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; contract AtlasEvents { // Metacall diff --git a/src/contracts/types/ConfigTypes.sol b/src/contracts/types/ConfigTypes.sol index 39605bce9..f68e327b5 100644 --- a/src/contracts/types/ConfigTypes.sol +++ b/src/contracts/types/ConfigTypes.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; struct DAppConfig { address to; // Address of the DAppControl contract diff --git a/src/contracts/types/DAppOperation.sol b/src/contracts/types/DAppOperation.sol index 897563d16..82a3b1d1c 100644 --- a/src/contracts/types/DAppOperation.sol +++ b/src/contracts/types/DAppOperation.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; bytes32 constant DAPP_TYPEHASH = keccak256( "DAppOperation(address from,address to,uint256 nonce,uint256 deadline,address control,address bundler,bytes32 userOpHash,bytes32 callChainHash)" diff --git a/src/contracts/types/EscrowTypes.sol b/src/contracts/types/EscrowTypes.sol index 7568cb582..c5e8f393c 100644 --- a/src/contracts/types/EscrowTypes.sol +++ b/src/contracts/types/EscrowTypes.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // bonded = total - unbonding struct EscrowAccountBalance { diff --git a/src/contracts/types/LockTypes.sol b/src/contracts/types/LockTypes.sol index f5831ff6d..938b7199b 100644 --- a/src/contracts/types/LockTypes.sol +++ b/src/contracts/types/LockTypes.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; struct Context { bytes32 userOpHash; // not packed diff --git a/src/contracts/types/SolverOperation.sol b/src/contracts/types/SolverOperation.sol index ffd9392e6..d58c73952 100644 --- a/src/contracts/types/SolverOperation.sol +++ b/src/contracts/types/SolverOperation.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; bytes32 constant SOLVER_TYPEHASH = keccak256( "SolverOperation(address from,address to,uint256 value,uint256 gas,uint256 maxFeePerGas,uint256 deadline,address solver,address control,bytes32 userOpHash,address bidToken,uint256 bidAmount,bytes data)" diff --git a/src/contracts/types/UserOperation.sol b/src/contracts/types/UserOperation.sol index de80f5c20..3a6d06600 100644 --- a/src/contracts/types/UserOperation.sol +++ b/src/contracts/types/UserOperation.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; // Default UserOperation typehash bytes32 constant USER_TYPEHASH_DEFAULT = keccak256( diff --git a/src/contracts/types/ValidCalls.sol b/src/contracts/types/ValidCalls.sol index 43a996434..0831a98a2 100644 --- a/src/contracts/types/ValidCalls.sol +++ b/src/contracts/types/ValidCalls.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; /// @title ValidCallsResult /// @notice Enum for ValidCallsResult diff --git a/test/Accounting.t.sol b/test/Accounting.t.sol index 0ca3c5042..1006d6047 100644 --- a/test/Accounting.t.sol +++ b/test/Accounting.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/AccountingMath.t.sol b/test/AccountingMath.t.sol index 2db24f74a..1a380ca6c 100644 --- a/test/AccountingMath.t.sol +++ b/test/AccountingMath.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import "../src/contracts/libraries/AccountingMath.sol"; diff --git a/test/AtlETH.t.sol b/test/AtlETH.t.sol index 76bc505b8..9c8a8aee6 100644 --- a/test/AtlETH.t.sol +++ b/test/AtlETH.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/AtlasVerification.t.sol b/test/AtlasVerification.t.sol index c703cafc7..093098e1c 100644 --- a/test/AtlasVerification.t.sol +++ b/test/AtlasVerification.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/BidFinding.t.sol b/test/BidFinding.t.sol index c30d339e5..c31e30bc7 100644 --- a/test/BidFinding.t.sol +++ b/test/BidFinding.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { LibSort } from "solady/utils/LibSort.sol"; diff --git a/test/DAppIntegration.t.sol b/test/DAppIntegration.t.sol index 6f64b0bab..33b6533bb 100644 --- a/test/DAppIntegration.t.sol +++ b/test/DAppIntegration.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index f31c292d6..cbde8b2e1 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/ExPost.t.sol b/test/ExPost.t.sol index 1fce2d00b..78f5add99 100644 --- a/test/ExPost.t.sol +++ b/test/ExPost.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/ExecutionBase.t.sol b/test/ExecutionBase.t.sol index 9a9debdc7..b30d6d542 100644 --- a/test/ExecutionBase.t.sol +++ b/test/ExecutionBase.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/ExecutionEnvironment.t.sol b/test/ExecutionEnvironment.t.sol index aa94f361b..e7bac6f64 100644 --- a/test/ExecutionEnvironment.t.sol +++ b/test/ExecutionEnvironment.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; diff --git a/test/FLOnline.t.sol b/test/FLOnline.t.sol index 4f43cf480..c8f9ab6e9 100644 --- a/test/FLOnline.t.sol +++ b/test/FLOnline.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/test/Factory.t.sol b/test/Factory.t.sol index 1552ae90e..80235982b 100644 --- a/test/Factory.t.sol +++ b/test/Factory.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index a313d2abd..578741fd2 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index 6c7cbcbc6..eb312230b 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; @@ -661,7 +661,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { vm.prank(executionEnvironment); mockGasAccounting.contribute{ value: 10 ether }(); - assertEq(mockGasAccounting.getClaims(), 10 ether, "Claims should be set to 10 ether"); + assertEq(mockGasAccounting.claims(), 10 ether, "Claims should be set to 10 ether"); assertEq(address(mockGasAccounting).balance, 10 ether, "mockGasAccounting should have 10 ether"); } @@ -1040,7 +1040,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { (uint256 claimsPaidToBundler, uint256 netGasSurcharge) = mockGasAccounting.settle(ctx); // Check final balances and perform assertions - uint256 finalClaims = mockGasAccounting.getClaims(); + uint256 finalClaims = mockGasAccounting.claims(); uint256 finalBonded = mockGasAccounting.balanceOfBonded(solverOneEOA); uint256 finalUnbonding = mockGasAccounting.balanceOfUnbonding(solverOneEOA); { @@ -1086,7 +1086,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertTrue(claimsPaidToBundler > 0, "Claims paid to bundler should be non-zero"); assertTrue(netGasSurcharge > 0, "Net gas surcharge should be non-zero"); assertLe( - mockGasAccounting.getClaims(), + mockGasAccounting.claims(), 3 ether, "Final claims should be less than or equal to initial claims plus deposits" ); diff --git a/test/MainTest.t.sol b/test/MainTest.t.sol index 6883c3a85..788b8ab9b 100644 --- a/test/MainTest.t.sol +++ b/test/MainTest.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/test/Mimic.t.sol b/test/Mimic.t.sol index f1a2445c9..c676dc6a7 100644 --- a/test/Mimic.t.sol +++ b/test/Mimic.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { Mimic } from "../src/contracts/common/Mimic.sol"; diff --git a/test/NonceManager.t.sol b/test/NonceManager.t.sol index 083648fd6..76b60b175 100644 --- a/test/NonceManager.t.sol +++ b/test/NonceManager.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/OEV.t.sol b/test/OEV.t.sol index 0ad596d7d..267d966e4 100644 --- a/test/OEV.t.sol +++ b/test/OEV.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/OEValt.t.sol b/test/OEValt.t.sol index fc8ffa4a2..a836e5c1d 100644 --- a/test/OEValt.t.sol +++ b/test/OEValt.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/Permit69.t.sol b/test/Permit69.t.sol index af195d3e6..0d95172f5 100644 --- a/test/Permit69.t.sol +++ b/test/Permit69.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/SafetyLocks.t.sol b/test/SafetyLocks.t.sol index 80df01533..57347165b 100644 --- a/test/SafetyLocks.t.sol +++ b/test/SafetyLocks.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; @@ -57,7 +57,7 @@ contract MockSafetyLocks is SafetyLocks { } function setClaims(uint256 _claims) external { - _setClaims(_claims); + claims = _claims; } function setWithdrawals(uint256 _withdrawals) external { @@ -90,10 +90,6 @@ contract MockSafetyLocks is SafetyLocks { // View functions - function getClaims() external view returns (uint256) { - return claims(); - } - function getFees() external view returns (uint256) { return fees(); } @@ -158,7 +154,7 @@ contract SafetyLocksTest is Test { safetyLocks.setClaims(newClaims); - uint256 claims = safetyLocks.getClaims(); + uint256 claims = safetyLocks.claims(); assertEq(claims, newClaims); } @@ -245,7 +241,7 @@ contract SafetyLocksTest is Test { safetyLocks.setSolverLock(0x456); (address activeEnv, uint32 callConfig, uint8 phase) = safetyLocks.lock(); - uint256 claims = safetyLocks.getClaims(); + uint256 claims = safetyLocks.claims(); uint256 withdrawals = safetyLocks.getWithdrawals(); uint256 deposits = safetyLocks.getDeposits(); uint256 fees = safetyLocks.getFees(); diff --git a/test/Simulator.t.sol b/test/Simulator.t.sol index 61cae787e..1a842a92c 100644 --- a/test/Simulator.t.sol +++ b/test/Simulator.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/Sorter.t.sol b/test/Sorter.t.sol index 7f2224504..d24d52dd0 100644 --- a/test/Sorter.t.sol +++ b/test/Sorter.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { BaseTest } from "./base/BaseTest.t.sol"; diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 242c04dc2..154d70f21 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; @@ -228,13 +228,13 @@ contract StorageTest is BaseTest { } function test_storage_transient_claims() public { - assertEq(atlas.getClaims(), 0, "claims should start at 0"); + assertEq(atlas.claims(), 0, "claims should start at 0"); atlas.setClaims(100); - assertEq(atlas.getClaims(), 100, "claims should be 100"); + assertEq(atlas.claims(), 100, "claims should be 100"); atlas.clearTransientStorage(); - assertEq(atlas.getClaims(), 0, "claims should be 0 again"); + assertEq(atlas.claims(), 0, "claims should be 0 again"); } function test_storage_transient_fees() public { @@ -420,7 +420,7 @@ contract MockStorage is Storage { _setLock(address(0), 0, 0); _setSolverLock(0); _setSolverTo(address(0)); - _setClaims(0); + claims = 0; _setFees(0); _setWriteoffs(0); _setWithdrawals(0); @@ -429,10 +429,6 @@ contract MockStorage is Storage { // View functions - function getClaims() external view returns (uint256) { - return claims(); - } - function getFees() external view returns (uint256) { return fees(); } diff --git a/test/Surcharge.t.sol b/test/Surcharge.t.sol index 53ea362fe..7ee7b2749 100644 --- a/test/Surcharge.t.sol +++ b/test/Surcharge.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { BaseTest } from "./base/BaseTest.t.sol"; diff --git a/test/SwapIntent.t.sol b/test/SwapIntent.t.sol index 37f16b513..5ae6b8ce2 100644 --- a/test/SwapIntent.t.sol +++ b/test/SwapIntent.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/SwapIntentInvertBid.t.sol b/test/SwapIntentInvertBid.t.sol index 5ab8aadf2..4af3f86fd 100644 --- a/test/SwapIntentInvertBid.t.sol +++ b/test/SwapIntentInvertBid.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; diff --git a/test/TrebleSwap.t.sol b/test/TrebleSwap.t.sol index 79eac047f..e118e588b 100644 --- a/test/TrebleSwap.t.sol +++ b/test/TrebleSwap.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/V2Helper.sol b/test/V2Helper.sol index 18088422a..ed14f6c75 100644 --- a/test/V2Helper.sol +++ b/test/V2Helper.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { TxBuilder } from "../src/contracts/helpers/TxBuilder.sol"; diff --git a/test/V2RewardDAppControl.t.sol b/test/V2RewardDAppControl.t.sol index 4a6776273..d20e697ef 100644 --- a/test/V2RewardDAppControl.t.sol +++ b/test/V2RewardDAppControl.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/ArbitrageTest.t.sol b/test/base/ArbitrageTest.t.sol index eda8080e9..2d7234a8b 100644 --- a/test/base/ArbitrageTest.t.sol +++ b/test/base/ArbitrageTest.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol index 07c0fcf02..ebec10978 100644 --- a/test/base/BaseTest.t.sol +++ b/test/base/BaseTest.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index 99def7930..8d5dbc439 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { DAppControl } from "../../src/contracts/dapp/DAppControl.sol"; diff --git a/test/base/GasSponsorDAppControl.sol b/test/base/GasSponsorDAppControl.sol index c9de344cd..d6d676fbb 100644 --- a/test/base/GasSponsorDAppControl.sol +++ b/test/base/GasSponsorDAppControl.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { DAppControl } from "../../src/contracts/dapp/DAppControl.sol"; import { IAtlas } from "../../src/contracts/interfaces/IAtlas.sol"; diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 8d9fe9bb2..828ea6762 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "../../src/contracts/atlas/Atlas.sol"; @@ -35,7 +35,7 @@ contract TestAtlas is Atlas { _setLock(address(0), 0, 0); _setSolverLock(0); _setSolverTo(address(0)); - _setClaims(0); + claims = 0; _setFees(0); _setWriteoffs(0); _setWithdrawals(0); @@ -59,7 +59,7 @@ contract TestAtlas is Atlas { } function setClaims(uint256 newClaims) public { - _setClaims(newClaims); + claims = newClaims; } function setFees(uint256 newFees) public { @@ -80,10 +80,6 @@ contract TestAtlas is Atlas { // View functions - function getClaims() external view returns (uint256) { - return claims(); - } - function getFees() external view returns (uint256) { return fees(); } diff --git a/test/base/TestUtils.sol b/test/base/TestUtils.sol index 4b6cae7ca..a3e942694 100644 --- a/test/base/TestUtils.sol +++ b/test/base/TestUtils.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { IDAppControl } from "../../src/contracts/interfaces/IDAppControl.sol"; import { Mimic } from "../../src/contracts/common/Mimic.sol"; diff --git a/test/base/builders/DAppOperationBuilder.sol b/test/base/builders/DAppOperationBuilder.sol index 76cb6c8f4..4d45d6f94 100644 --- a/test/base/builders/DAppOperationBuilder.sol +++ b/test/base/builders/DAppOperationBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/builders/SolverOperationBuilder.sol b/test/base/builders/SolverOperationBuilder.sol index 9b3e9e53d..4130bb452 100644 --- a/test/base/builders/SolverOperationBuilder.sol +++ b/test/base/builders/SolverOperationBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/builders/UserOperationBuilder.sol b/test/base/builders/UserOperationBuilder.sol index 126892e08..791642190 100644 --- a/test/base/builders/UserOperationBuilder.sol +++ b/test/base/builders/UserOperationBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/base/interfaces/IUniswapV2Router.sol b/test/base/interfaces/IUniswapV2Router.sol index aa198cf3c..3d45d23c2 100644 --- a/test/base/interfaces/IUniswapV2Router.sol +++ b/test/base/interfaces/IUniswapV2Router.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; interface IUniswapV2Router01 { function factory() external pure returns (address); diff --git a/test/helpers/CallConfigBuilder.sol b/test/helpers/CallConfigBuilder.sol index 82800d46c..97dbc2a94 100644 --- a/test/helpers/CallConfigBuilder.sol +++ b/test/helpers/CallConfigBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { CallConfig } from "../../src/contracts/types/ConfigTypes.sol"; diff --git a/test/helpers/DummyDAppControlBuilder.sol b/test/helpers/DummyDAppControlBuilder.sol index 5ef97d908..b86cf0037 100644 --- a/test/helpers/DummyDAppControlBuilder.sol +++ b/test/helpers/DummyDAppControlBuilder.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { DummyDAppControl } from "../base/DummyDAppControl.sol"; import { CallConfig } from "../../src/contracts/types/ConfigTypes.sol"; diff --git a/test/libraries/CallBits.t.sol b/test/libraries/CallBits.t.sol index 0c5d6f5fd..7d217a22e 100644 --- a/test/libraries/CallBits.t.sol +++ b/test/libraries/CallBits.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/libraries/CallVerification.t.sol b/test/libraries/CallVerification.t.sol index a5c7aa404..1861ee266 100644 --- a/test/libraries/CallVerification.t.sol +++ b/test/libraries/CallVerification.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/libraries/EscrowBits.t.sol b/test/libraries/EscrowBits.t.sol index ff5f829e1..254cef218 100644 --- a/test/libraries/EscrowBits.t.sol +++ b/test/libraries/EscrowBits.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; diff --git a/test/libraries/SafetyBits.t.sol b/test/libraries/SafetyBits.t.sol index d9f4c06f7..1ec221353 100644 --- a/test/libraries/SafetyBits.t.sol +++ b/test/libraries/SafetyBits.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.28; import "forge-std/Test.sol"; From c37e7a82fa88b2ebaefdd4948e75a91768e1f18d Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:54:40 +0200 Subject: [PATCH 49/70] rm: FactoryLib file from different PR --- src/contracts/atlas/FactoryLib.sol | 145 ----------------------------- 1 file changed, 145 deletions(-) delete mode 100644 src/contracts/atlas/FactoryLib.sol diff --git a/src/contracts/atlas/FactoryLib.sol b/src/contracts/atlas/FactoryLib.sol deleted file mode 100644 index 9ca878bbc..000000000 --- a/src/contracts/atlas/FactoryLib.sol +++ /dev/null @@ -1,145 +0,0 @@ -//SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.28; - -import { Mimic } from "../common/Mimic.sol"; -import { AtlasEvents } from "../types/AtlasEvents.sol"; - -// NOTE: Do not call these functions directly. This contract should only ever be delegatecalled by the Atlas contract. - -contract FactoryLib { - address public immutable EXECUTION_ENV_TEMPLATE; - - /// @notice Initializes a new Factory contract instance by setting the immutable salt for deterministic deployment - /// of Execution Environments and storing the execution template address. - /// @dev The Execution Environment Template must be separately deployed using the same calculated salt. - /// @param executionTemplate Address of the pre-deployed execution template contract for creating Execution - /// Environment instances. - constructor(address executionTemplate) { - EXECUTION_ENV_TEMPLATE = executionTemplate; - } - - /// @notice Deploys a new execution environment or retrieves the address of an existing one based on the DApp - /// control, user, and configuration. - /// @dev Uses the `create2` opcode for deterministic deployment, allowing the calculation of the execution - /// environment's address before deployment. The deployment uses a combination of the DAppControl address, user - /// address, call configuration, and a unique salt to ensure the uniqueness and predictability of the environment's - /// address. - /// @param user The address of the user for whom the execution environment is being set. - /// @param control The address of the DAppControl contract providing the operational context. - /// @param callConfig CallConfig settings of the DAppControl contract. - /// @return executionEnvironment The address of the newly created or already existing execution environment. - function getOrCreateExecutionEnvironment( - address user, - address control, - uint32 callConfig, - bytes32 salt - ) - public - returns (address executionEnvironment) - { - bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); - - executionEnvironment = address( - uint160( - uint256( - keccak256( - abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) - ) - ) - ) - ); - - if (executionEnvironment.code.length == 0) { - assembly { - executionEnvironment := create2(0, add(_creationCode, 32), mload(_creationCode), salt) - } - emit AtlasEvents.ExecutionEnvironmentCreated(user, executionEnvironment); - } - } - - /// @notice Generates the address of a user's execution environment affected by deprecated callConfig changes in the - /// DAppControl. - /// @dev Calculates the deterministic address of the execution environment based on the user, control, - /// callConfig, and controlCodeHash, ensuring consistency across changes in callConfig. - /// @param user The address of the user for whom the execution environment's address is being generated. - /// @param control The address of the DAppControl contract associated with the execution environment. - /// @param callConfig The configuration flags defining the behavior of the execution environment. - /// @return executionEnvironment The address of the user's execution environment. - function getExecutionEnvironmentCustom( - address user, - address control, - uint32 callConfig, - bytes32 salt - ) - public - view - returns (address executionEnvironment) - { - bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); - - executionEnvironment = address( - uint160( - uint256( - keccak256( - abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(abi.encodePacked(_creationCode))) - ) - ) - ) - ); - } - - /// @notice Generates the creation code for the execution environment contract. - /// @param control The address of the DAppControl contract associated with the execution environment. - /// @param callConfig The configuration flags defining the behavior of the execution environment. - /// @param user The address of the user for whom the execution environment is being created, contributing to the - /// uniqueness of the creation code. - /// @return creationCode The bytecode representing the creation code of the execution environment contract. - function _getMimicCreationCode( - address user, - address control, - uint32 callConfig - ) - internal - view - returns (bytes memory creationCode) - { - address _executionLib = EXECUTION_ENV_TEMPLATE; - // NOTE: Changing compiler settings or solidity versions can break this. - creationCode = type(Mimic).creationCode; - - assembly { - // Insert the ExecutionEnvironment "Lib" address, into the AAAA placeholder in the creation code. - mstore( - add(creationCode, 79), - or( - and(mload(add(creationCode, 79)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, _executionLib) - ) - ) - - // Insert the user address into the BBBB placeholder in the creation code. - mstore( - add(creationCode, 111), - or( - and(mload(add(creationCode, 111)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, user) - ) - ) - - // Insert the control address into the CCCC placeholder in the creation code. - mstore( - add(creationCode, 132), - or( - and(mload(add(creationCode, 132)), not(shl(96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))), - shl(96, control) - ) - ) - - // Insert the callConfig into the 2222 placeholder in the creation code. - mstore( - add(creationCode, 153), - or(and(mload(add(creationCode, 153)), not(shl(224, 0xFFFFFFFF))), shl(224, callConfig)) - ) - } - } -} From fdcdba516a44e583a3b99383630b3019a7062262 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:55:36 +0200 Subject: [PATCH 50/70] refactor: `transient` keyword for Accounting vars --- src/contracts/atlas/GasAccounting.sol | 48 +++++++++++----------- src/contracts/atlas/Storage.sol | 52 +++--------------------- test/GasAccounting.t.sol | 58 +++++++++++++-------------- test/SafetyLocks.t.sol | 50 ++++++++--------------- test/Storage.t.sol | 51 ++++++++--------------- test/base/TestAtlas.sol | 35 +++++----------- 6 files changed, 100 insertions(+), 194 deletions(-) diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 474e6442c..2c734d7e4 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -49,13 +49,13 @@ abstract contract GasAccounting is SafetyLocks { claims = _rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE); // Atlas surcharge is based on the raw claims value. - _setFees(_rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE)); - _setDeposits(msg.value); - _setSolverSurcharge(0); + fees = _rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE); + deposits = msg.value; - // Explicitly set writeoffs and withdrawals to 0 in case multiple metacalls in single tx. - _setWriteoffs(0); - _setWithdrawals(0); + // Explicitly set other transient vars to 0 in case multiple metacalls in single tx. + writeoffs = 0; + withdrawals = 0; + solverSurcharge = 0; // Explicitly clear solverLock and solverTo in case multiple metacalls in single tx. _setSolverLock(0); @@ -100,12 +100,12 @@ abstract contract GasAccounting is SafetyLocks { /// @return uint256 The current shortfall amount, or 0 if there is no shortfall. function shortfall() external view returns (uint256) { uint256 _currentDeficit = _deficit(); - uint256 _deposits = deposits(); + uint256 _deposits = deposits; return (_currentDeficit > _deposits) ? (_currentDeficit - _deposits) : 0; } function _deficit() internal view returns (uint256) { - return claims + withdrawals() + fees() - writeoffs(); + return claims + withdrawals + fees - writeoffs; } /// @notice Allows a solver to settle any outstanding ETH owed, either to repay gas used by their solverOp or to @@ -137,12 +137,12 @@ abstract contract GasAccounting is SafetyLocks { if (maxApprovedGasSpend > _bondedBalance) maxApprovedGasSpend = _bondedBalance; uint256 _deductions = _deficit(); - uint256 _additions = deposits() + msg.value; + uint256 _additions = deposits + msg.value; // Add msg.value to solver's deposits // NOTE: Surplus deposits are credited back to the Solver during settlement. // NOTE: This function is called inside the solver try/catch and will be undone if solver fails. - if (msg.value > 0) _setDeposits(_additions); + if (msg.value > 0) deposits = _additions; // CASE: Callback verified but insufficient balance if (_deductions > _additions + maxApprovedGasSpend) { @@ -165,7 +165,7 @@ abstract contract GasAccounting is SafetyLocks { /// @notice Internal function to handle ETH contribution, increasing deposits if a non-zero value is sent. function _contribute() internal { - if (msg.value != 0) _setDeposits(deposits() + msg.value); + if (msg.value != 0) deposits += msg.value; } /// @notice Borrows ETH from the contract, transferring the specified amount to the caller if available. @@ -178,7 +178,7 @@ abstract contract GasAccounting is SafetyLocks { if (amount == 0) return true; if (address(this).balance < amount) return false; - _setWithdrawals(withdrawals() + amount); + withdrawals += amount; return true; } @@ -221,7 +221,7 @@ abstract contract GasAccounting is SafetyLocks { s_balanceOf[owner].unbonding = 0; _aData.bonded = 0; - _setWriteoffs(writeoffs() + deficit); + writeoffs += deficit; amount -= deficit; // Set amount equal to total to accurately track the changing bondedTotalSupply } else { // The unbonding balance is sufficient to cover the remaining amount owed. Draw everything from the @@ -242,7 +242,7 @@ abstract contract GasAccounting is SafetyLocks { S_accessData[owner] = _aData; S_bondedTotalSupply -= amount; - _setDeposits(deposits() + amount); + deposits += amount; } /// @notice Increases the owner's bonded balance by the specified amount. @@ -264,7 +264,7 @@ abstract contract GasAccounting is SafetyLocks { // Persist changes in the _aData memory struct back to storage S_accessData[owner] = _aData; - _setWithdrawals(withdrawals() + amount); + withdrawals += amount; } /// @notice Accounts for the gas cost of a failed SolverOperation, either by increasing writeoffs (if the bundler is @@ -293,7 +293,7 @@ abstract contract GasAccounting is SafetyLocks { if (result.bundlersFault()) { // CASE: Solver is not responsible for the failure of their operation, so we blame the bundler // and reduce the total amount refunded to the bundler - _setWriteoffs(writeoffs() + _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE)); + writeoffs += _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); } else { // CASE: Solver failed, so we calculate what they owe. uint256 _gasUsedWithSurcharges = _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); @@ -308,13 +308,13 @@ abstract contract GasAccounting is SafetyLocks { // so that in the event of no successful solvers, any `_assign()`ed surcharges can be attributed to an // increase in Atlas' cumulative surcharge. if (_surchargesOnly > _assignDeficit) { - _setSolverSurcharge(solverSurcharge() + (_surchargesOnly - _assignDeficit)); + solverSurcharge += (_surchargesOnly - _assignDeficit); } } } function _writeOffBidFindGasCost(uint256 gasUsed) internal { - _setWriteoffs(writeoffs() + gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE)); + writeoffs += gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); } /// @param ctx Context struct containing relevant context information for the Atlas auction. @@ -344,11 +344,11 @@ abstract contract GasAccounting is SafetyLocks { { uint256 _surcharge = S_cumulativeSurcharge; - adjustedWithdrawals = withdrawals(); - adjustedDeposits = deposits(); + adjustedWithdrawals = withdrawals; + adjustedDeposits = deposits; adjustedClaims = claims; - adjustedWriteoffs = writeoffs(); - uint256 _fees = fees(); + adjustedWriteoffs = writeoffs; + uint256 _fees = fees; uint256 _gasLeft = gasleft(); // Hold this constant for the calculations @@ -368,7 +368,7 @@ 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) - uint256 _solverSurcharge = solverSurcharge(); + uint256 _solverSurcharge = solverSurcharge; if (_solverSurcharge > 0) { netAtlasGasSurcharge = _solverSurcharge.getPortionFromTotalSurcharge({ targetSurchargeRate: ATLAS_SURCHARGE_RATE, @@ -533,6 +533,6 @@ abstract contract GasAccounting is SafetyLocks { /// correct. /// @return True if the balance is reconciled, false otherwise. function _isBalanceReconciled() internal view returns (bool) { - return deposits() >= _deficit(); + return deposits >= _deficit(); } } diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 2d2120554..326d1f23d 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -37,11 +37,11 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { bytes32 private constant _T_SOLVER_TO_SLOT = keccak256("ATLAS_SOLVER_TO"); uint256 public transient claims; - bytes32 private constant _T_FEES_SLOT = keccak256("ATLAS_FEES"); - bytes32 private constant _T_WRITEOFFS_SLOT = keccak256("ATLAS_WRITEOFFS"); - bytes32 private constant _T_WITHDRAWALS_SLOT = keccak256("ATLAS_WITHDRAWALS"); - bytes32 private constant _T_DEPOSITS_SLOT = keccak256("ATLAS_DEPOSITS"); - bytes32 private constant _T_SOLVER_SURCHARGE_SLOT = keccak256("ATLAS_SOLVER_SURCHARGE"); + uint256 public transient fees; + uint256 public transient writeoffs; + uint256 public transient withdrawals; + uint256 public transient deposits; + uint256 public transient solverSurcharge; // total surcharge collected from failed solverOps due to solver fault. // AtlETH storage uint256 internal S_totalSupply; @@ -155,26 +155,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { // Transient Internal Getters // // ---------------------------------------------------- // - function fees() internal view returns (uint256) { - return uint256(_tload(_T_FEES_SLOT)); - } - - function writeoffs() internal view returns (uint256) { - return uint256(_tload(_T_WRITEOFFS_SLOT)); - } - - function withdrawals() internal view returns (uint256) { - return uint256(_tload(_T_WITHDRAWALS_SLOT)); - } - - function deposits() internal view returns (uint256) { - return uint256(_tload(_T_DEPOSITS_SLOT)); - } - - function solverSurcharge() internal view returns (uint256) { - return uint256(_tload(_T_SOLVER_SURCHARGE_SLOT)); - } - function _lock() internal view returns (address activeEnvironment, uint32 callConfig, uint8 phase) { bytes32 _lockData = _tload(_T_LOCK_SLOT); activeEnvironment = address(uint160(uint256(_lockData >> 40))); @@ -248,28 +228,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { _tstore(_T_SOLVER_TO_SLOT, bytes32(uint256(uint160(newSolverTo)))); } - function _setFees(uint256 newFees) internal { - _tstore(_T_FEES_SLOT, bytes32(newFees)); - } - - function _setWriteoffs(uint256 newWriteoffs) internal { - _tstore(_T_WRITEOFFS_SLOT, bytes32(newWriteoffs)); - } - - function _setWithdrawals(uint256 newWithdrawals) internal { - _tstore(_T_WITHDRAWALS_SLOT, bytes32(newWithdrawals)); - } - - function _setDeposits(uint256 newDeposits) internal { - _tstore(_T_DEPOSITS_SLOT, bytes32(newDeposits)); - } - - // NOTE: Only captures surcharges for failed solver Ops where - // solver is at fault - function _setSolverSurcharge(uint256 newSurcharge) internal { - _tstore(_T_SOLVER_SURCHARGE_SLOT, bytes32(newSurcharge)); - } - // ------------------------------------------------------ // // Transient Storage Helpers // // ------------------------------------------------------ // diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index eb312230b..47c7b6177 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -315,7 +315,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Verify the balances after contribution assertEq(address(mockGasAccounting).balance, contributeValue); - assertEq(mockGasAccounting.getDeposits(), contributeValue); + assertEq(mockGasAccounting.deposits(), contributeValue); } function test_multipleContributes() public { @@ -334,7 +334,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Verify the balances after the first contribution assertEq(address(mockGasAccounting).balance, firstContributeValue); - assertEq(mockGasAccounting.getDeposits(), firstContributeValue); + assertEq(mockGasAccounting.deposits(), firstContributeValue); // Perform the second valid contribute call vm.prank(executionEnvironment); @@ -342,7 +342,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Verify the balances after the second contribution assertEq(address(mockGasAccounting).balance, totalContributeValue); - assertEq(mockGasAccounting.getDeposits(), totalContributeValue); + assertEq(mockGasAccounting.deposits(), totalContributeValue); } function test_contribute_withZeroValue() public { @@ -358,7 +358,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Verify the balances after the contribution is zero assertEq(address(mockGasAccounting).balance, contributeValue); - assertEq(mockGasAccounting.getDeposits(), contributeValue); + assertEq(mockGasAccounting.deposits(), contributeValue); } function test_borrow_preOpsPhase() public { @@ -373,7 +373,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq( solverOneEOA.balance, borrowedAmount, "Execution environment balance should be equal to borrowed amount" ); - assertEq(borrowedAmount, mockGasAccounting.getWithdrawals(), "Withdrawals should be equal to borrowed amount"); + assertEq(borrowedAmount, mockGasAccounting.withdrawals(), "Withdrawals should be equal to borrowed amount"); } function test_borrow_userOperationPhase() public { @@ -390,7 +390,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { borrowedAmount, "Execution environment balance should be equal to borrowed amount" ); - assertEq(borrowedAmount, mockGasAccounting.getWithdrawals(), "Withdrawals should be equal to borrowed amount"); + assertEq(borrowedAmount, mockGasAccounting.withdrawals(), "Withdrawals should be equal to borrowed amount"); } function test_borrow_preSolverPhase() public { @@ -407,7 +407,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { borrowedAmount, "Execution environment balance should be equal to borrowed amount" ); - assertEq(borrowedAmount, mockGasAccounting.getWithdrawals(), "Withdrawals should be equal to borrowed amount"); + assertEq(borrowedAmount, mockGasAccounting.withdrawals(), "Withdrawals should be equal to borrowed amount"); } function test_borrow_solverOperationPhase() public { @@ -423,12 +423,12 @@ contract GasAccountingTest is AtlasConstants, BaseTest { borrowedAmount, "Execution environment balance should be equal to borrowed amount" ); - assertEq(borrowedAmount, mockGasAccounting.getWithdrawals(), "Withdrawals should be equal to borrowed amount"); + assertEq(borrowedAmount, mockGasAccounting.withdrawals(), "Withdrawals should be equal to borrowed amount"); } function test_borrow_postSolverPhase_reverts() public { uint256 borrowedAmount = 1e18; - uint256 withdrawalsBefore = mockGasAccounting.getWithdrawals(); + uint256 withdrawalsBefore = mockGasAccounting.withdrawals(); fundContract(borrowedAmount); mockGasAccounting.setLock(executionEnvironment, 0, uint8(ExecutionPhase.PostSolver)); @@ -437,12 +437,12 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.borrow(borrowedAmount); assertEq(executionEnvironment.balance, 0, "Execution environment balance should remain zero"); - assertEq(withdrawalsBefore, mockGasAccounting.getWithdrawals(), "Withdrawals should remain unchanged"); + assertEq(withdrawalsBefore, mockGasAccounting.withdrawals(), "Withdrawals should remain unchanged"); } function test_borrow_allocateValuePhase_reverts() public { uint256 borrowedAmount = 1e18; - uint256 withdrawalsBefore = mockGasAccounting.getWithdrawals(); + uint256 withdrawalsBefore = mockGasAccounting.withdrawals(); fundContract(borrowedAmount); mockGasAccounting.setLock(executionEnvironment, 0, uint8(ExecutionPhase.AllocateValue)); @@ -451,12 +451,12 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.borrow(borrowedAmount); assertEq(executionEnvironment.balance, 0, "Execution environment balance should remain zero"); - assertEq(withdrawalsBefore, mockGasAccounting.getWithdrawals(), "Withdrawals should remain unchanged"); + assertEq(withdrawalsBefore, mockGasAccounting.withdrawals(), "Withdrawals should remain unchanged"); } function test_borrow_postOpsPhase_reverts() public { uint256 borrowedAmount = 1e18; - uint256 withdrawalsBefore = mockGasAccounting.getWithdrawals(); + uint256 withdrawalsBefore = mockGasAccounting.withdrawals(); fundContract(borrowedAmount); mockGasAccounting.setLock(executionEnvironment, 0, uint8(ExecutionPhase.PostOps)); @@ -465,7 +465,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.borrow(borrowedAmount); assertEq(executionEnvironment.balance, 0, "Execution environment balance should remain zero"); - assertEq(withdrawalsBefore, mockGasAccounting.getWithdrawals(), "Withdrawals should remain unchanged"); + assertEq(withdrawalsBefore, mockGasAccounting.withdrawals(), "Withdrawals should remain unchanged"); } function test_multipleBorrows() public { @@ -529,7 +529,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { "Final contract balance should be initial balance minus total borrowed amount" ); assertEq( - totalBorrowAmount, mockGasAccounting.getWithdrawals(), "Withdrawals should equal total borrowed amount" + totalBorrowAmount, mockGasAccounting.withdrawals(), "Withdrawals should equal total borrowed amount" ); } @@ -735,7 +735,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq(currentSolver, solverOneEOA, "Current solver should match execution environment"); // Verify that deposits did not increase - assertEq(mockGasAccounting.getDeposits(), initialClaims, "Deposits should remain unchanged"); + assertEq(mockGasAccounting.deposits(), initialClaims, "Deposits should remain unchanged"); } function test_reconcileWithETH() public { @@ -762,7 +762,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq(currentSolver, solverOneEOA, "Current solver should match execution environment"); // Verify that deposits increased by the reconciled amount - assertEq(mockGasAccounting.getDeposits(), initialClaims, "Deposits should match the amount sent as msg.value"); + assertEq(mockGasAccounting.deposits(), initialClaims, "Deposits should match the amount sent as msg.value"); } function test_assign_zeroAmount() public { @@ -784,7 +784,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Get initial values uint256 bondedTotalSupplyBefore = mockGasAccounting.bondedTotalSupply(); - uint256 depositsBefore = mockGasAccounting.getDeposits(); + uint256 depositsBefore = mockGasAccounting.deposits(); uint256 deficit = mockGasAccounting.assign(solverOp.from, assignedAmount, assignedAmount, true); assertEq(deficit, 0, "Deficit should be 0"); @@ -793,7 +793,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq(lastAccessedBlock, uint32(block.number)); uint256 bondedTotalSupplyAfter = mockGasAccounting.bondedTotalSupply(); - uint256 depositsAfter = mockGasAccounting.getDeposits(); + uint256 depositsAfter = mockGasAccounting.deposits(); assertEq(bondedTotalSupplyAfter, bondedTotalSupplyBefore - assignedAmount); assertEq(depositsAfter, depositsBefore + assignedAmount); @@ -809,7 +809,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.increaseBondedBalance(solverOp.from, bondedAmount); // Set bonded balance to 500 uint256 bondedTotalSupplyBefore = mockGasAccounting.bondedTotalSupply(); - uint256 depositsBefore = mockGasAccounting.getDeposits(); + uint256 depositsBefore = mockGasAccounting.deposits(); // Call the assign function and capture the deficit uint256 deficit = mockGasAccounting.assign(solverOp.from, assignedAmount, assignedAmount, true); @@ -825,7 +825,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { bondedTotalSupplyBefore - assignedAmount, "Bonded total supply mismatch" ); - assertEq(mockGasAccounting.getDeposits(), depositsBefore + assignedAmount, "Deposits mismatch"); + assertEq(mockGasAccounting.deposits(), depositsBefore + assignedAmount, "Deposits mismatch"); // Retrieve and check the updated balances (uint112 bonded, uint112 unbonding) = mockGasAccounting._balanceOf(solverOp.from); @@ -843,13 +843,13 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.increaseBondedBalance(solverOp.from, bondedAmount); uint256 bondedTotalSupplyBefore = mockGasAccounting.bondedTotalSupply(); - uint256 depositsBefore = mockGasAccounting.getDeposits(); + uint256 depositsBefore = mockGasAccounting.deposits(); uint256 deficit = mockGasAccounting.assign(solverOp.from, assignedAmount, assignedAmount, true); assertEq(deficit, assignedAmount - (unbondingAmount + bondedAmount)); (, uint32 lastAccessedBlock,,,) = mockGasAccounting.accessData(solverOp.from); assertEq(lastAccessedBlock, uint32(block.number)); assertEq(mockGasAccounting.bondedTotalSupply(), bondedTotalSupplyBefore - (unbondingAmount + bondedAmount)); - assertEq(mockGasAccounting.getDeposits(), depositsBefore + (unbondingAmount + bondedAmount)); + assertEq(mockGasAccounting.deposits(), depositsBefore + (unbondingAmount + bondedAmount)); (uint112 bonded, uint112 unbonding) = mockGasAccounting._balanceOf(solverOp.from); assertEq(unbonding, 0); assertEq(bonded, 0); @@ -912,14 +912,14 @@ contract GasAccountingTest is AtlasConstants, BaseTest { mockGasAccounting.increaseBondedBalance(solverOp.from, bondedAmount); uint256 bondedTotalSupplyBefore = mockGasAccounting.bondedTotalSupply(); - uint256 depositsBefore = mockGasAccounting.getDeposits(); + uint256 depositsBefore = mockGasAccounting.deposits(); (uint112 unbondingBefore,) = mockGasAccounting._balanceOf(solverOp.from); vm.expectRevert(AtlasErrors.ValueTooLarge.selector); mockGasAccounting.assign(solverOp.from, assignedAmount, assignedAmount, true); // Check assign reverted with overflow, and accounting values did not change assertEq(mockGasAccounting.bondedTotalSupply(), bondedTotalSupplyBefore); - assertEq(mockGasAccounting.getDeposits(), depositsBefore); + assertEq(mockGasAccounting.deposits(), depositsBefore); (uint112 unbonding,) = mockGasAccounting._balanceOf(solverOp.from); assertEq(unbonding, unbondingBefore); } @@ -929,7 +929,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { uint256 lastAccessedBlock; uint256 bondedTotalSupplyBefore = mockGasAccounting.bondedTotalSupply(); - uint256 withdrawalsBefore = mockGasAccounting.getWithdrawals(); + uint256 withdrawalsBefore = mockGasAccounting.withdrawals(); (uint112 bondedBefore,,,,) = mockGasAccounting.accessData(solverOp.from); (, lastAccessedBlock,,,) = mockGasAccounting.accessData(solverOp.from); assertEq(lastAccessedBlock, 0); @@ -942,7 +942,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { assertEq(lastAccessedBlock, uint32(block.number)); assertEq(mockGasAccounting.bondedTotalSupply(), bondedTotalSupplyBefore + creditedAmount); assertEq(bondedAfter, bondedBefore + uint112(creditedAmount)); - assertEq(mockGasAccounting.getWithdrawals(), withdrawalsBefore + creditedAmount); + assertEq(mockGasAccounting.withdrawals(), withdrawalsBefore + creditedAmount); // Testing uint112 boundary values for casting from uint256 to uint112 in _credit() uint256 overflowAmount = uint256(type(uint112).max) + 1; @@ -954,7 +954,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { // Setup solverOp.data = ""; uint256 gasWaterMark = gasleft() + 5000; - uint256 initialWriteoffs = mockGasAccounting.getWriteoffs(); + uint256 initialWriteoffs = mockGasAccounting.writeoffs(); // Simulate solver not responsible for failure uint256 result = EscrowBits._NO_REFUND; @@ -971,7 +971,7 @@ contract GasAccountingTest is AtlasConstants, BaseTest { uint256 expectedWriteoffs = initialWriteoffs + AccountingMath.withSurcharges(gasUsed, DEFAULT_ATLAS_SURCHARGE_RATE, DEFAULT_BUNDLER_SURCHARGE_RATE); // Verify writeoffs have increased assertApproxEqRel( - mockGasAccounting.getWriteoffs(), + mockGasAccounting.writeoffs(), expectedWriteoffs, 1e15, // 0.1% margin for error "Writeoffs should be approximately equal to expected value" diff --git a/test/SafetyLocks.t.sol b/test/SafetyLocks.t.sol index 57347165b..de65cbbc9 100644 --- a/test/SafetyLocks.t.sol +++ b/test/SafetyLocks.t.sol @@ -60,20 +60,20 @@ contract MockSafetyLocks is SafetyLocks { claims = _claims; } - function setWithdrawals(uint256 _withdrawals) external { - _setWithdrawals(_withdrawals); + function setFees(uint256 newFees) public { + fees = newFees; } - function setDeposits(uint256 _deposits) external { - _setDeposits(_deposits); + function setWriteoffs(uint256 newWriteoffs) public { + writeoffs = newWriteoffs; } - function setFees(uint256 _fees) external { - _setFees(_fees); + function setWithdrawals(uint256 newWithdrawals) public { + withdrawals = newWithdrawals; } - function setWriteoffs(uint256 _writeoffs) external { - _setWriteoffs(_writeoffs); + function setDeposits(uint256 newDeposits) public { + deposits = newDeposits; } function setSolverLock(uint256 newSolverLock) external { @@ -87,24 +87,6 @@ contract MockSafetyLocks is SafetyLocks { function solverTo() external view returns (address) { return _solverTo(); } - - // View functions - - function getFees() external view returns (uint256) { - return fees(); - } - - function getWriteoffs() external view returns (uint256) { - return writeoffs(); - } - - function getWithdrawals() external view returns (uint256) { - return withdrawals(); - } - - function getDeposits() external view returns (uint256) { - return deposits(); - } } contract SafetyLocksTest is Test { @@ -163,7 +145,7 @@ contract SafetyLocksTest is Test { safetyLocks.setWithdrawals(newWithdrawals); - uint256 withdrawals = safetyLocks.getWithdrawals(); + uint256 withdrawals = safetyLocks.withdrawals(); assertEq(withdrawals, newWithdrawals); } @@ -172,7 +154,7 @@ contract SafetyLocksTest is Test { safetyLocks.setDeposits(newDeposits); - uint256 deposits = safetyLocks.getDeposits(); + uint256 deposits = safetyLocks.deposits(); assertEq(deposits, newDeposits); } @@ -181,7 +163,7 @@ contract SafetyLocksTest is Test { safetyLocks.setFees(newFees); - uint256 fees = safetyLocks.getFees(); + uint256 fees = safetyLocks.fees(); assertEq(fees, newFees); } @@ -190,7 +172,7 @@ contract SafetyLocksTest is Test { safetyLocks.setWriteoffs(newWriteoffs); - uint256 writeoffs = safetyLocks.getWriteoffs(); + uint256 writeoffs = safetyLocks.writeoffs(); assertEq(writeoffs, newWriteoffs); } @@ -242,10 +224,10 @@ contract SafetyLocksTest is Test { (address activeEnv, uint32 callConfig, uint8 phase) = safetyLocks.lock(); uint256 claims = safetyLocks.claims(); - uint256 withdrawals = safetyLocks.getWithdrawals(); - uint256 deposits = safetyLocks.getDeposits(); - uint256 fees = safetyLocks.getFees(); - uint256 writeoffs = safetyLocks.getWriteoffs(); + uint256 withdrawals = safetyLocks.withdrawals(); + uint256 deposits = safetyLocks.deposits(); + uint256 fees = safetyLocks.fees(); + uint256 writeoffs = safetyLocks.writeoffs(); (address solverTo,,) = safetyLocks.solverLockData(); assertEq(safetyLocks.isUnlocked(), false); diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 154d70f21..eaca89d1c 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -238,43 +238,43 @@ contract StorageTest is BaseTest { } function test_storage_transient_fees() public { - assertEq(atlas.getFees(), 0, "fees should start at 0"); + assertEq(atlas.fees(), 0, "fees should start at 0"); atlas.setFees(100); - assertEq(atlas.getFees(), 100, "fees should be 100"); + assertEq(atlas.fees(), 100, "fees should be 100"); atlas.clearTransientStorage(); - assertEq(atlas.getFees(), 0, "fees should be 0 again"); + assertEq(atlas.fees(), 0, "fees should be 0 again"); } function test_storage_transient_writeoffs() public { - assertEq(atlas.getWriteoffs(), 0, "writeoffs should start at 0"); + assertEq(atlas.writeoffs(), 0, "writeoffs should start at 0"); atlas.setWriteoffs(100); - assertEq(atlas.getWriteoffs(), 100, "writeoffs should be 100"); + assertEq(atlas.writeoffs(), 100, "writeoffs should be 100"); atlas.clearTransientStorage(); - assertEq(atlas.getWriteoffs(), 0, "writeoffs should be 0 again"); + assertEq(atlas.writeoffs(), 0, "writeoffs should be 0 again"); } function test_storage_transient_withdrawals() public { - assertEq(atlas.getWithdrawals(), 0, "withdrawals should start at 0"); + assertEq(atlas.withdrawals(), 0, "withdrawals should start at 0"); atlas.setWithdrawals(100); - assertEq(atlas.getWithdrawals(), 100, "withdrawals should be 100"); + assertEq(atlas.withdrawals(), 100, "withdrawals should be 100"); atlas.clearTransientStorage(); - assertEq(atlas.getWithdrawals(), 0, "withdrawals should be 0 again"); + assertEq(atlas.withdrawals(), 0, "withdrawals should be 0 again"); } function test_storage_transient_deposits() public { - assertEq(atlas.getDeposits(), 0, "deposits should start at 0"); + assertEq(atlas.deposits(), 0, "deposits should start at 0"); atlas.setDeposits(100); - assertEq(atlas.getDeposits(), 100, "deposits should be 100"); + assertEq(atlas.deposits(), 100, "deposits should be 100"); atlas.clearTransientStorage(); - assertEq(atlas.getDeposits(), 0, "deposits should be 0 again"); + assertEq(atlas.deposits(), 0, "deposits should be 0 again"); } function test_storage_transient_solverTo() public { @@ -421,27 +421,10 @@ contract MockStorage is Storage { _setSolverLock(0); _setSolverTo(address(0)); claims = 0; - _setFees(0); - _setWriteoffs(0); - _setWithdrawals(0); - _setDeposits(0); - } - - // View functions - - function getFees() external view returns (uint256) { - return fees(); - } - - function getWriteoffs() external view returns (uint256) { - return writeoffs(); - } - - function getWithdrawals() external view returns (uint256) { - return withdrawals(); - } - - function getDeposits() external view returns (uint256) { - return deposits(); + fees = 0; + writeoffs = 0; + withdrawals = 0; + deposits = 0; + solverSurcharge = 0; } } diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 828ea6762..679eb476c 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -36,10 +36,11 @@ contract TestAtlas is Atlas { _setSolverLock(0); _setSolverTo(address(0)); claims = 0; - _setFees(0); - _setWriteoffs(0); - _setWithdrawals(0); - _setDeposits(0); + fees = 0; + writeoffs = 0; + withdrawals = 0; + deposits = 0; + solverSurcharge = 0; } function setLock(address activeEnvironment, uint32 callConfig, uint8 phase) public { @@ -63,36 +64,18 @@ contract TestAtlas is Atlas { } function setFees(uint256 newFees) public { - _setFees(newFees); + fees = newFees; } function setWriteoffs(uint256 newWriteoffs) public { - _setWriteoffs(newWriteoffs); + writeoffs = newWriteoffs; } function setWithdrawals(uint256 newWithdrawals) public { - _setWithdrawals(newWithdrawals); + withdrawals = newWithdrawals; } function setDeposits(uint256 newDeposits) public { - _setDeposits(newDeposits); - } - - // View functions - - function getFees() external view returns (uint256) { - return fees(); - } - - function getWriteoffs() external view returns (uint256) { - return writeoffs(); - } - - function getWithdrawals() external view returns (uint256) { - return withdrawals(); - } - - function getDeposits() external view returns (uint256) { - return deposits(); + deposits = newDeposits; } } From 0950125cfd03e6ce8ed9040f8159162c7a3e3eed Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:41:38 +0200 Subject: [PATCH 51/70] refactor: make transient vars internal + `t_` prefixed --- src/contracts/atlas/Escrow.sol | 4 +- src/contracts/atlas/GasAccounting.sol | 62 +++++++++++++-------------- src/contracts/atlas/Storage.sol | 31 +++++--------- test/GasAccounting.t.sol | 2 +- test/SafetyLocks.t.sol | 44 ++++++++++++++----- test/Storage.t.sol | 20 ++++----- test/base/TestAtlas.sol | 52 +++++++++++++++------- 7 files changed, 123 insertions(+), 92 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 2d68b88f6..3bcd5da45 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -573,8 +573,8 @@ abstract contract Escrow is AtlETH { bool _success; // Set the solver lock and solver address at the beginning to ensure reliability - _setSolverLock(uint256(uint160(solverOp.from))); - _setSolverTo(solverOp.solver); + t_solverLock = uint256(uint160(solverOp.from)); + t_solverTo = solverOp.solver; // ------------------------------------- // // Pre-Solver Call // diff --git a/src/contracts/atlas/GasAccounting.sol b/src/contracts/atlas/GasAccounting.sol index 2c734d7e4..43e0c7ece 100644 --- a/src/contracts/atlas/GasAccounting.sol +++ b/src/contracts/atlas/GasAccounting.sol @@ -46,20 +46,18 @@ abstract contract GasAccounting is SafetyLocks { uint256 _rawClaims = (FIXED_GAS_OFFSET + gasMarker) * tx.gasprice; // Set any withdraws or deposits - claims = _rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE); + t_claims = _rawClaims.withSurcharge(BUNDLER_SURCHARGE_RATE); // Atlas surcharge is based on the raw claims value. - fees = _rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE); - deposits = msg.value; + t_fees = _rawClaims.getSurcharge(ATLAS_SURCHARGE_RATE); + t_deposits = msg.value; // Explicitly set other transient vars to 0 in case multiple metacalls in single tx. - writeoffs = 0; - withdrawals = 0; - solverSurcharge = 0; - - // Explicitly clear solverLock and solverTo in case multiple metacalls in single tx. - _setSolverLock(0); - _setSolverTo(address(0)); + t_writeoffs = 0; + t_withdrawals = 0; + t_solverSurcharge = 0; + t_solverLock = 0; + t_solverTo = address(0); // The Lock slot is cleared at the end of the metacall, so no need to zero again here. } @@ -100,12 +98,12 @@ abstract contract GasAccounting is SafetyLocks { /// @return uint256 The current shortfall amount, or 0 if there is no shortfall. function shortfall() external view returns (uint256) { uint256 _currentDeficit = _deficit(); - uint256 _deposits = deposits; + uint256 _deposits = t_deposits; return (_currentDeficit > _deposits) ? (_currentDeficit - _deposits) : 0; } function _deficit() internal view returns (uint256) { - return claims + withdrawals + fees - writeoffs; + return t_claims + t_withdrawals + t_fees - t_writeoffs; } /// @notice Allows a solver to settle any outstanding ETH owed, either to repay gas used by their solverOp or to @@ -128,7 +126,7 @@ abstract contract GasAccounting is SafetyLocks { // calls directly to the solver contract in this phase, the solver should be careful to not call malicious // contracts which may call reconcile() on their behalf, with an excessive maxApprovedGasSpend. if (_phase() != uint8(ExecutionPhase.SolverOperation)) revert WrongPhase(); - if (msg.sender != _solverTo()) revert InvalidAccess(); + if (msg.sender != t_solverTo) revert InvalidAccess(); (address _currentSolver, bool _calledBack, bool _fulfilled) = _solverLockData(); uint256 _bondedBalance = uint256(S_accessData[_currentSolver].bonded); @@ -137,12 +135,12 @@ abstract contract GasAccounting is SafetyLocks { if (maxApprovedGasSpend > _bondedBalance) maxApprovedGasSpend = _bondedBalance; uint256 _deductions = _deficit(); - uint256 _additions = deposits + msg.value; + uint256 _additions = t_deposits + msg.value; // Add msg.value to solver's deposits // NOTE: Surplus deposits are credited back to the Solver during settlement. // NOTE: This function is called inside the solver try/catch and will be undone if solver fails. - if (msg.value > 0) deposits = _additions; + if (msg.value > 0) t_deposits = _additions; // CASE: Callback verified but insufficient balance if (_deductions > _additions + maxApprovedGasSpend) { @@ -151,21 +149,21 @@ abstract contract GasAccounting is SafetyLocks { // but it does treat any msg.value as a deposit and allows for either the solver to call back with a // higher maxApprovedGasSpend or to have their deficit covered by a contribute during the postSolverOp // hook. - _setSolverLock(uint256(uint160(_currentSolver)) | _SOLVER_CALLED_BACK_MASK); + t_solverLock = (uint256(uint160(_currentSolver)) | _SOLVER_CALLED_BACK_MASK); } return _deductions - _additions; } // CASE: Callback verified and solver duty fulfilled if (!_fulfilled) { - _setSolverLock(uint256(uint160(_currentSolver)) | _SOLVER_CALLED_BACK_MASK | _SOLVER_FULFILLED_MASK); + t_solverLock = (uint256(uint160(_currentSolver)) | _SOLVER_CALLED_BACK_MASK | _SOLVER_FULFILLED_MASK); } return 0; } /// @notice Internal function to handle ETH contribution, increasing deposits if a non-zero value is sent. function _contribute() internal { - if (msg.value != 0) deposits += msg.value; + if (msg.value != 0) t_deposits += msg.value; } /// @notice Borrows ETH from the contract, transferring the specified amount to the caller if available. @@ -178,7 +176,7 @@ abstract contract GasAccounting is SafetyLocks { if (amount == 0) return true; if (address(this).balance < amount) return false; - withdrawals += amount; + t_withdrawals += amount; return true; } @@ -221,7 +219,7 @@ abstract contract GasAccounting is SafetyLocks { s_balanceOf[owner].unbonding = 0; _aData.bonded = 0; - writeoffs += deficit; + t_writeoffs += deficit; amount -= deficit; // Set amount equal to total to accurately track the changing bondedTotalSupply } else { // The unbonding balance is sufficient to cover the remaining amount owed. Draw everything from the @@ -242,7 +240,7 @@ abstract contract GasAccounting is SafetyLocks { S_accessData[owner] = _aData; S_bondedTotalSupply -= amount; - deposits += amount; + t_deposits += amount; } /// @notice Increases the owner's bonded balance by the specified amount. @@ -264,7 +262,7 @@ abstract contract GasAccounting is SafetyLocks { // Persist changes in the _aData memory struct back to storage S_accessData[owner] = _aData; - withdrawals += amount; + t_withdrawals += amount; } /// @notice Accounts for the gas cost of a failed SolverOperation, either by increasing writeoffs (if the bundler is @@ -293,7 +291,7 @@ abstract contract GasAccounting is SafetyLocks { if (result.bundlersFault()) { // CASE: Solver is not responsible for the failure of their operation, so we blame the bundler // and reduce the total amount refunded to the bundler - writeoffs += _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); + t_writeoffs += _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); } else { // CASE: Solver failed, so we calculate what they owe. uint256 _gasUsedWithSurcharges = _gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); @@ -308,13 +306,13 @@ abstract contract GasAccounting is SafetyLocks { // so that in the event of no successful solvers, any `_assign()`ed surcharges can be attributed to an // increase in Atlas' cumulative surcharge. if (_surchargesOnly > _assignDeficit) { - solverSurcharge += (_surchargesOnly - _assignDeficit); + t_solverSurcharge += (_surchargesOnly - _assignDeficit); } } } function _writeOffBidFindGasCost(uint256 gasUsed) internal { - writeoffs += gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); + t_writeoffs += gasUsed.withSurcharges(ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE); } /// @param ctx Context struct containing relevant context information for the Atlas auction. @@ -344,11 +342,11 @@ abstract contract GasAccounting is SafetyLocks { { uint256 _surcharge = S_cumulativeSurcharge; - adjustedWithdrawals = withdrawals; - adjustedDeposits = deposits; - adjustedClaims = claims; - adjustedWriteoffs = writeoffs; - uint256 _fees = fees; + adjustedWithdrawals = t_withdrawals; + adjustedDeposits = t_deposits; + adjustedClaims = t_claims; + adjustedWriteoffs = t_writeoffs; + uint256 _fees = t_fees; uint256 _gasLeft = gasleft(); // Hold this constant for the calculations @@ -368,7 +366,7 @@ 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) - uint256 _solverSurcharge = solverSurcharge; + uint256 _solverSurcharge = t_solverSurcharge; if (_solverSurcharge > 0) { netAtlasGasSurcharge = _solverSurcharge.getPortionFromTotalSurcharge({ targetSurchargeRate: ATLAS_SURCHARGE_RATE, @@ -533,6 +531,6 @@ abstract contract GasAccounting is SafetyLocks { /// correct. /// @return True if the balance is reconciled, false otherwise. function _isBalanceReconciled() internal view returns (bool) { - return deposits >= _deficit(); + return t_deposits >= _deficit(); } } diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index 326d1f23d..d74838c60 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -33,15 +33,16 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { // Transient storage slots bytes32 private constant _T_LOCK_SLOT = keccak256("ATLAS_LOCK"); - bytes32 private constant _T_SOLVER_LOCK_SLOT = keccak256("ATLAS_SOLVER_LOCK"); - bytes32 private constant _T_SOLVER_TO_SLOT = keccak256("ATLAS_SOLVER_TO"); + + uint256 internal transient t_solverLock; + address internal transient t_solverTo; // current solverOp.solver contract address - uint256 public transient claims; - uint256 public transient fees; - uint256 public transient writeoffs; - uint256 public transient withdrawals; - uint256 public transient deposits; - uint256 public transient solverSurcharge; // total surcharge collected from failed solverOps due to solver fault. + uint256 internal transient t_claims; + uint256 internal transient t_fees; + uint256 internal transient t_writeoffs; + uint256 internal transient t_withdrawals; + uint256 internal transient t_deposits; + uint256 internal transient t_solverSurcharge; // total surcharge collected from failed solverOps due to solver fault. // AtlETH storage uint256 internal S_totalSupply; @@ -182,16 +183,12 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { /// @return calledBack Boolean indicating whether the solver has called back via `reconcile`. /// @return fulfilled Boolean indicating whether the solver's outstanding debt has been repaid via `reconcile`. function _solverLockData() internal view returns (address currentSolver, bool calledBack, bool fulfilled) { - uint256 _solverLock = uint256(_tload(_T_SOLVER_LOCK_SLOT)); + uint256 _solverLock = t_solverLock; currentSolver = address(uint160(_solverLock)); calledBack = _solverLock & _SOLVER_CALLED_BACK_MASK != 0; fulfilled = _solverLock & _SOLVER_FULFILLED_MASK != 0; } - function _solverTo() internal view returns (address) { - return address(uint160(uint256(_tload(_T_SOLVER_TO_SLOT)))); - } - function _isUnlocked() internal view returns (bool) { return _tload(_T_LOCK_SLOT) == bytes32(_UNLOCKED); } @@ -220,14 +217,6 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { _tstore(_T_LOCK_SLOT, (_tload(_T_LOCK_SLOT) & _LOCK_PHASE_MASK) | bytes32(uint256(newPhase))); } - function _setSolverLock(uint256 newSolverLock) internal { - _tstore(_T_SOLVER_LOCK_SLOT, bytes32(newSolverLock)); - } - - function _setSolverTo(address newSolverTo) internal { - _tstore(_T_SOLVER_TO_SLOT, bytes32(uint256(uint160(newSolverTo)))); - } - // ------------------------------------------------------ // // Transient Storage Helpers // // ------------------------------------------------------ // diff --git a/test/GasAccounting.t.sol b/test/GasAccounting.t.sol index 47c7b6177..430471dcf 100644 --- a/test/GasAccounting.t.sol +++ b/test/GasAccounting.t.sol @@ -116,7 +116,7 @@ contract MockGasAccounting is TestAtlas, BaseTest { } function setSolverLock(address _solverFrom) external { - _setSolverLock(uint256(uint160(_solverFrom))); + t_solverLock = (uint256(uint160(_solverFrom))); } function _balanceOf(address account) external view returns (uint112, uint112) { diff --git a/test/SafetyLocks.t.sol b/test/SafetyLocks.t.sol index de65cbbc9..c4d1bd4fc 100644 --- a/test/SafetyLocks.t.sol +++ b/test/SafetyLocks.t.sol @@ -56,36 +56,58 @@ contract MockSafetyLocks is SafetyLocks { _setLockPhase(newPhase); } - function setClaims(uint256 _claims) external { - claims = _claims; + function setSolverLock(uint256 newSolverLock) public { + t_solverLock = newSolverLock; + } + + function setSolverTo(address newSolverTo) public { + t_solverTo = newSolverTo; + } + + function setClaims(uint256 newClaims) public { + t_claims = newClaims; } function setFees(uint256 newFees) public { - fees = newFees; + t_fees = newFees; } function setWriteoffs(uint256 newWriteoffs) public { - writeoffs = newWriteoffs; + t_writeoffs = newWriteoffs; } function setWithdrawals(uint256 newWithdrawals) public { - withdrawals = newWithdrawals; + t_withdrawals = newWithdrawals; } function setDeposits(uint256 newDeposits) public { - deposits = newDeposits; + t_deposits = newDeposits; + } + + // Transient Var View Functions + + function claims() external view returns (uint256) { + return t_claims; + } + + function fees() external view returns (uint256) { + return t_fees; + } + + function writeoffs() external view returns (uint256) { + return t_writeoffs; } - function setSolverLock(uint256 newSolverLock) external { - _setSolverLock(newSolverLock); + function withdrawals() external view returns (uint256) { + return t_withdrawals; } - function setSolverTo(address newSolverTo) external { - _setSolverTo(newSolverTo); + function deposits() external view returns (uint256) { + return t_deposits; } function solverTo() external view returns (address) { - return _solverTo(); + return t_solverTo; } } diff --git a/test/Storage.t.sol b/test/Storage.t.sol index eaca89d1c..7852ae2a4 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -391,11 +391,11 @@ contract MockStorage is Storage { // For internal view functions without external versions function solverTo() public view returns (address) { - return _solverTo(); + return t_solverTo; } function setSolverTo(address newSolverTo) public { - _setSolverTo(newSolverTo); + t_solverTo = newSolverTo; } function activeEnvironment() public view returns (address) { @@ -418,13 +418,13 @@ contract MockStorage is Storage { // To clear all transient storage vars function clearTransientStorage() public { _setLock(address(0), 0, 0); - _setSolverLock(0); - _setSolverTo(address(0)); - claims = 0; - fees = 0; - writeoffs = 0; - withdrawals = 0; - deposits = 0; - solverSurcharge = 0; + t_solverLock = 0; + t_solverTo = address(0); + t_claims = 0; + t_fees = 0; + t_writeoffs = 0; + t_withdrawals = 0; + t_deposits = 0; + t_solverSurcharge = 0; } } diff --git a/test/base/TestAtlas.sol b/test/base/TestAtlas.sol index 679eb476c..3ee904489 100644 --- a/test/base/TestAtlas.sol +++ b/test/base/TestAtlas.sol @@ -33,14 +33,14 @@ contract TestAtlas is Atlas { function clearTransientStorage() public { _setLock(address(0), 0, 0); - _setSolverLock(0); - _setSolverTo(address(0)); - claims = 0; - fees = 0; - writeoffs = 0; - withdrawals = 0; - deposits = 0; - solverSurcharge = 0; + t_solverLock = 0; + t_solverTo = address(0); + t_claims = 0; + t_fees = 0; + t_writeoffs = 0; + t_withdrawals = 0; + t_deposits = 0; + t_solverSurcharge = 0; } function setLock(address activeEnvironment, uint32 callConfig, uint8 phase) public { @@ -52,30 +52,52 @@ contract TestAtlas is Atlas { } function setSolverLock(uint256 newSolverLock) public { - _setSolverLock(newSolverLock); + t_solverLock = newSolverLock; } function setSolverTo(address newSolverTo) public { - _setSolverTo(newSolverTo); + t_solverTo = newSolverTo; } function setClaims(uint256 newClaims) public { - claims = newClaims; + t_claims = newClaims; } function setFees(uint256 newFees) public { - fees = newFees; + t_fees = newFees; } function setWriteoffs(uint256 newWriteoffs) public { - writeoffs = newWriteoffs; + t_writeoffs = newWriteoffs; } function setWithdrawals(uint256 newWithdrawals) public { - withdrawals = newWithdrawals; + t_withdrawals = newWithdrawals; } function setDeposits(uint256 newDeposits) public { - deposits = newDeposits; + t_deposits = newDeposits; + } + + // Transient Var View Functions + + function claims() external view returns (uint256) { + return t_claims; + } + + function fees() external view returns (uint256) { + return t_fees; + } + + function writeoffs() external view returns (uint256) { + return t_writeoffs; + } + + function withdrawals() external view returns (uint256) { + return t_withdrawals; + } + + function deposits() external view returns (uint256) { + return t_deposits; } } From a90b1adcafa63adf8d7697f2e609e414c1bd0c99 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:02:31 +0200 Subject: [PATCH 52/70] refactor: convert lock slot to `transient` syntax --- src/contracts/atlas/Storage.sol | 49 ++++++++------------------ src/contracts/types/AtlasConstants.sol | 2 +- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/contracts/atlas/Storage.sol b/src/contracts/atlas/Storage.sol index d74838c60..baca20ae2 100644 --- a/src/contracts/atlas/Storage.sol +++ b/src/contracts/atlas/Storage.sol @@ -32,17 +32,17 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { uint256 public constant FIXED_GAS_OFFSET = AccountingMath._FIXED_GAS_OFFSET; // Transient storage slots - bytes32 private constant _T_LOCK_SLOT = keccak256("ATLAS_LOCK"); - + uint256 internal transient t_lock; // contains activeAddress, callConfig, and phase uint256 internal transient t_solverLock; address internal transient t_solverTo; // current solverOp.solver contract address + // solverSurcharge = total surcharge collected from failed solverOps due to solver fault. + uint256 internal transient t_solverSurcharge; uint256 internal transient t_claims; uint256 internal transient t_fees; uint256 internal transient t_writeoffs; uint256 internal transient t_withdrawals; uint256 internal transient t_deposits; - uint256 internal transient t_solverSurcharge; // total surcharge collected from failed solverOps due to solver fault. // AtlETH storage uint256 internal S_totalSupply; @@ -157,25 +157,25 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { // ---------------------------------------------------- // function _lock() internal view returns (address activeEnvironment, uint32 callConfig, uint8 phase) { - bytes32 _lockData = _tload(_T_LOCK_SLOT); - activeEnvironment = address(uint160(uint256(_lockData >> 40))); - callConfig = uint32(uint256(_lockData >> 8)); - phase = uint8(uint256(_lockData)); + uint256 _lockData = t_lock; + activeEnvironment = address(uint160(_lockData >> 40)); + callConfig = uint32(_lockData >> 8); + phase = uint8(_lockData); } function _activeEnvironment() internal view returns (address) { // right shift 40 bits to remove the callConfig and phase, only activeEnvironment remains - return address(uint160(uint256(_tload(_T_LOCK_SLOT) >> 40))); + return address(uint160(t_lock >> 40)); } function _activeCallConfig() internal view returns (uint32) { // right shift 8 bits to remove the phase, cast to uint32 to remove the activeEnvironment - return uint32(uint256(_tload(_T_LOCK_SLOT) >> 8)); + return uint32(t_lock >> 8); } function _phase() internal view returns (uint8) { // right-most 8 bits of Lock are the phase - return uint8(uint256(_tload(_T_LOCK_SLOT))); + return uint8(t_lock); } /// @notice Returns information about the current state of the solver lock. @@ -190,7 +190,7 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { } function _isUnlocked() internal view returns (bool) { - return _tload(_T_LOCK_SLOT) == bytes32(_UNLOCKED); + return t_lock == _UNLOCKED; } // ---------------------------------------------------- // @@ -201,36 +201,15 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants { // Pack the lock slot from the right: // [ 56 bits ][ 160 bits ][ 32 bits ][ 8 bits ] // [ unused bits ][ activeEnvironment ][ callConfig ][ phase ] - _tstore( - _T_LOCK_SLOT, - bytes32(uint256(uint160(activeEnvironment))) << 40 | bytes32(uint256(callConfig)) << 8 - | bytes32(uint256(phase)) - ); + t_lock = uint256(uint160(activeEnvironment)) << 40 | uint256(callConfig) << 8 | uint256(phase); } function _releaseLock() internal { - _tstore(_T_LOCK_SLOT, bytes32(_UNLOCKED)); + t_lock = _UNLOCKED; } // Sets the Lock phase without changing the activeEnvironment or callConfig. function _setLockPhase(uint8 newPhase) internal { - _tstore(_T_LOCK_SLOT, (_tload(_T_LOCK_SLOT) & _LOCK_PHASE_MASK) | bytes32(uint256(newPhase))); - } - - // ------------------------------------------------------ // - // Transient Storage Helpers // - // ------------------------------------------------------ // - - function _tstore(bytes32 slot, bytes32 value) internal { - assembly { - tstore(slot, value) - } - } - - function _tload(bytes32 slot) internal view returns (bytes32 value) { - assembly { - value := tload(slot) - } - return value; + t_lock = (t_lock & _LOCK_PHASE_MASK) | uint256(newPhase); } } diff --git a/src/contracts/types/AtlasConstants.sol b/src/contracts/types/AtlasConstants.sol index dbe575056..79edb0c25 100644 --- a/src/contracts/types/AtlasConstants.sol +++ b/src/contracts/types/AtlasConstants.sol @@ -37,7 +37,7 @@ contract AtlasConstants { uint256 internal constant _SOLVER_FULFILLED_MASK = 1 << 162; // Used to set Lock phase without changing the activeEnvironment or callConfig. - bytes32 internal constant _LOCK_PHASE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00; + uint256 internal constant _LOCK_PHASE_MASK = uint256(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00); // ValidCalls error threshold before which the metacall reverts, and after which it returns gracefully to store // nonces as used. From a8030e2ac8dcafd77cac94da6493fa57b4c835df Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:28:35 +0200 Subject: [PATCH 53/70] chore: remove unused constants --- src/contracts/types/AtlasConstants.sol | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/contracts/types/AtlasConstants.sol b/src/contracts/types/AtlasConstants.sol index 79edb0c25..b8cf43d07 100644 --- a/src/contracts/types/AtlasConstants.sol +++ b/src/contracts/types/AtlasConstants.sol @@ -18,6 +18,7 @@ contract AtlasConstants { // Atlas constants used in `_bidFindingIteration()` uint256 internal constant _BITS_FOR_INDEX = 16; + uint256 internal constant _FIRST_16_BITS_TRUE_MASK = uint256(0xFFFF); // Escrow constants uint256 internal constant _VALIDATION_GAS_LIMIT = 500_000; @@ -47,16 +48,5 @@ contract AtlasConstants { // ATLAS VERIFICATION CONSTANTS // // ------------------------------------------------------- // - uint256 internal constant _FULL_BITMAP = _FIRST_240_BITS_TRUE_MASK; - uint256 internal constant _NONCES_PER_BITMAP = 240; uint8 internal constant _MAX_SOLVERS = type(uint8).max - 1; - - // ------------------------------------------------------- // - // SHARED CONSTANTS // - // ------------------------------------------------------- // - - uint256 internal constant _FIRST_240_BITS_TRUE_MASK = - uint256(0x0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); - uint256 internal constant _FIRST_16_BITS_TRUE_MASK = uint256(0xFFFF); - uint256 internal constant _FIRST_4_BITS_TRUE_MASK = uint256(0xF); } From a7cce597f86d5e571f78abd64abab3f5b21edc49 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 21 Oct 2024 20:57:08 +0200 Subject: [PATCH 54/70] test: fix Factory tests --- test/Factory.t.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Factory.t.sol b/test/Factory.t.sol index 598e7268c..0e770182f 100644 --- a/test/Factory.t.sol +++ b/test/Factory.t.sol @@ -67,10 +67,10 @@ contract FactoryTest is Test { user = address(999); address deployer = address(333); - address expectedFactoryLibAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer)); - address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); - address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); - address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); + address expectedFactoryLibAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 1); + address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); + address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); + address expectedFactoryAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 4); vm.startPrank(deployer); ExecutionEnvironment execEnvTemplate = new ExecutionEnvironment(expectedFactoryAddr); @@ -110,7 +110,7 @@ contract FactoryTest is Test { keccak256( abi.encodePacked( bytes1(0xff), - address(factoryLib), + address(mockFactory), mockFactory.computeSalt(user, address(dAppControl), callConfig), keccak256(abi.encodePacked(creationCode)) ) From df971642e6e6ab0e6928450a15b889342b60a178 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:07:39 +0200 Subject: [PATCH 55/70] fix: delegatecalled create2 fn must be payable --- src/contracts/atlas/FactoryLib.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/contracts/atlas/FactoryLib.sol b/src/contracts/atlas/FactoryLib.sol index 4bcc81799..0cf9495a5 100644 --- a/src/contracts/atlas/FactoryLib.sol +++ b/src/contracts/atlas/FactoryLib.sol @@ -35,6 +35,7 @@ contract FactoryLib { bytes32 salt ) public + payable returns (address executionEnvironment) { bytes memory _creationCode = _getMimicCreationCode({ user: user, control: control, callConfig: callConfig }); From 148049f573e0a30edf8a0ecf08f738a2fe1d7350 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:24:19 +0200 Subject: [PATCH 56/70] chore: bump Solidity version to `0.8.28` --- src/contracts/atlas/FactoryLib.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contracts/atlas/FactoryLib.sol b/src/contracts/atlas/FactoryLib.sol index 0cf9495a5..a6b74e3d1 100644 --- a/src/contracts/atlas/FactoryLib.sol +++ b/src/contracts/atlas/FactoryLib.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.25; +pragma solidity 0.8.28; import { Mimic } from "../common/Mimic.sol"; import { AtlasEvents } from "../types/AtlasEvents.sol"; From 776fb93f789fdc648cc836c34b6ff15427516ed1 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:25:47 +0200 Subject: [PATCH 57/70] ci: disable lint check as pre-req for test check --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8deface8..0aed06e90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: echo "✅ Passed" >> $GITHUB_STEP_SUMMARY tests: - needs: ["lint", "build"] + needs: ["build"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 47c3b17473890ea5ade9f6a30b92fd5ac55c93ed Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:33:10 +0200 Subject: [PATCH 58/70] fix: apply graceful return gas offset to userOp call --- src/contracts/atlas/Escrow.sol | 7 ++++++- src/contracts/types/AtlasConstants.sol | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 3bcd5da45..0f04581d3 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -101,7 +101,11 @@ abstract contract Escrow is AtlETH { { bool _success; bytes memory _data; - uint256 _gasLimit = userOp.gas > gasleft() ? gasleft() : userOp.gas; + + // Calculate gas limit ceiling, including gas to return gracefully even if userOp call is OOG. + uint256 _gasLimit = gasleft() * 63 / 64 - _GRACEFUL_RETURN_GAS_OFFSET; + // Use the smaller of userOp.gas and the gas limit ceiling + _gasLimit = userOp.gas < _gasLimit ? userOp.gas : _gasLimit; if (!_borrow(userOp.value)) { revert InsufficientEscrow(); @@ -121,6 +125,7 @@ abstract contract Escrow is AtlETH { return returnData; } } + // revert for failed if (ctx.isSimulation) revert UserOpSimFail(); revert UserOpFail(); diff --git a/src/contracts/types/AtlasConstants.sol b/src/contracts/types/AtlasConstants.sol index b8cf43d07..89e4f5e23 100644 --- a/src/contracts/types/AtlasConstants.sol +++ b/src/contracts/types/AtlasConstants.sol @@ -23,6 +23,7 @@ contract AtlasConstants { // Escrow constants uint256 internal constant _VALIDATION_GAS_LIMIT = 500_000; uint256 internal constant _FASTLANE_GAS_BUFFER = 125_000; // integer amount + uint256 internal constant _GRACEFUL_RETURN_GAS_OFFSET = 40_000; // Gas Accounting constants uint256 internal constant _CALLDATA_LENGTH_PREMIUM = 32; // 16 (default) * 2 @@ -38,7 +39,8 @@ contract AtlasConstants { uint256 internal constant _SOLVER_FULFILLED_MASK = 1 << 162; // Used to set Lock phase without changing the activeEnvironment or callConfig. - uint256 internal constant _LOCK_PHASE_MASK = uint256(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00); + uint256 internal constant _LOCK_PHASE_MASK = + uint256(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00); // ValidCalls error threshold before which the metacall reverts, and after which it returns gracefully to store // nonces as used. From 17340c8a2da364f780a3a9a50e1c288f717ec7c9 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:33:52 +0200 Subject: [PATCH 59/70] test: userOp out-of-gas graceful return case --- test/Escrow.t.sol | 27 +++++++++++++++++++++++++++ test/base/DummyDAppControl.sol | 8 ++++++++ 2 files changed, 35 insertions(+) diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index cbde8b2e1..f2023bbaa 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -221,6 +221,33 @@ contract EscrowTest is BaseTest { assertTrue(auctionWon, "2nd auction should have been won"); } + function test_executeUserOperation_gracefullyReturnsWhenUserOpOOG() public { + // userOp.gas should be more than ceiling calculated in _executeUserOperation() + uint256 userGasLim = 500_000; + uint256 metacallGasLim = 300_000; // will trigger use of userOp gas ceiling + + defaultAtlasWithCallConfig(defaultCallConfig().build()); + UserOperation memory userOp = validUserOperation(address(dAppControl)) + .withData( + abi.encodeWithSelector( + dAppControl.burnEntireGasLimit.selector) + ).withGas(userGasLim) + .signAndBuild(address(atlasVerification), userPK); + deal(address(dummySolver), defaultBidAmount); + SolverOperation[] memory solverOps = new SolverOperation[](1); + solverOps[0] = validSolverOperation(userOp) + .withBidAmount(defaultBidAmount) + .withData(abi.encode(1)) + .signAndBuild(address(atlasVerification), solverOnePK); + DAppOperation memory dappOp = validDAppOperation(userOp, solverOps).build(); + + // Send msg.value so it must be sent back, testing the upper bound of remaining gas for graceful return + deal(userEOA, 1 ether); + vm.prank(userEOA); + bool auctionWon = atlas.metacall{gas: metacallGasLim, value: 1 ether}(userOp, solverOps, dappOp); + assertEq(auctionWon, false, "call should not revert but auction should not be won either"); + } + // Ensure metacall reverts with the proper error when the allocateValue hook reverts. function test_executeAllocateValueCall_failure_SkipCoverage() public { defaultAtlasWithCallConfig( diff --git a/test/base/DummyDAppControl.sol b/test/base/DummyDAppControl.sol index 8d5dbc439..dfd510a0a 100644 --- a/test/base/DummyDAppControl.sol +++ b/test/base/DummyDAppControl.sol @@ -118,6 +118,14 @@ contract DummyDAppControl is DAppControl { return returnValue; } + // Used to use all gas available during a call to get OOG error. + function burnEntireGasLimit() public { + uint256 _uselessSum; + while (true) { + _uselessSum += uint256(keccak256(abi.encodePacked(_uselessSum, gasleft()))) / 1e18; + } + } + // Revert settings function setPreOpsShouldRevert(bool _preOpsShouldRevert) public { From 3a4972d973412c4e49481b0910715a8c7bf65c46 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:03:15 +0200 Subject: [PATCH 60/70] docs: version is Atlas v1.1 in natspec --- src/contracts/atlas/Atlas.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contracts/atlas/Atlas.sol b/src/contracts/atlas/Atlas.sol index 4d6e3be33..5635d17ab 100644 --- a/src/contracts/atlas/Atlas.sol +++ b/src/contracts/atlas/Atlas.sol @@ -19,7 +19,7 @@ import { SafetyBits } from "../libraries/SafetyBits.sol"; import { IL2GasCalculator } from "../interfaces/IL2GasCalculator.sol"; import { IDAppControl } from "../interfaces/IDAppControl.sol"; -/// @title Atlas V1 +/// @title Atlas V1.1 /// @author FastLane Labs /// @notice The Execution Abstraction protocol. contract Atlas is Escrow, Factory { From 17e81f27156610daa47ebaef4bdb47c1635ba20e Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:53:57 +0200 Subject: [PATCH 61/70] feat: add `bidAmount` to `SolverTxResult` event --- src/contracts/atlas/Escrow.sol | 4 ++-- src/contracts/types/AtlasEvents.sol | 7 ++++++- test/Escrow.t.sol | 14 ++++++++------ test/FlashLoan.t.sol | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 0f04581d3..9ccfbed56 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -206,7 +206,7 @@ abstract contract Escrow is AtlETH { if (_result.executionSuccessful()) { // First successful solver call that paid what it bid - emit SolverTxResult(solverOp.solver, solverOp.from, true, true, _result); + emit SolverTxResult(solverOp.solver, solverOp.from, true, true, _result, bidAmount); ctx.solverSuccessful = true; ctx.solverOutcome = uint24(_result); @@ -221,7 +221,7 @@ abstract contract Escrow is AtlETH { // Account for failed SolverOperation gas costs _handleSolverAccounting(solverOp, _gasWaterMark, _result, !prevalidated); - emit SolverTxResult(solverOp.solver, solverOp.from, _result.executedWithError(), false, _result); + emit SolverTxResult(solverOp.solver, solverOp.from, _result.executedWithError(), false, _result, bidAmount); return 0; } diff --git a/src/contracts/types/AtlasEvents.sol b/src/contracts/types/AtlasEvents.sol index 8bd9383d7..c72f316df 100644 --- a/src/contracts/types/AtlasEvents.sol +++ b/src/contracts/types/AtlasEvents.sol @@ -21,7 +21,12 @@ contract AtlasEvents { // Escrow events event SolverTxResult( - address indexed solverTo, address indexed solverFrom, bool executed, bool success, uint256 result + address indexed solverTo, + address indexed solverFrom, + bool executed, + bool success, + uint256 result, + uint256 bidAmount ); // Factory events diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index f2023bbaa..2031acc83 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -41,11 +41,6 @@ contract EscrowTest is BaseTest { uint256 private constant _SOLVER_GAS_BUFFER = 5; // out of 100 uint256 private constant _FASTLANE_GAS_BUFFER = 125_000; // integer amount - event MEVPaymentSuccess(address bidToken, uint256 bidAmount); - event SolverTxResult( - address indexed solverTo, address indexed solverFrom, bool executed, bool success, uint256 result - ); - function defaultCallConfig() public returns (CallConfigBuilder) { return new CallConfigBuilder(); } @@ -662,7 +657,14 @@ contract EscrowTest is BaseTest { DAppOperation memory dappOp = validDAppOperation(userOp, solverOps).build(); vm.expectEmit(false, false, false, true, address(atlas)); - emit SolverTxResult(solverOps[0].solver, solverOps[0].from, solverOpExecuted, solverOpSuccess, expectedResult); + emit AtlasEvents.SolverTxResult( + solverOps[0].solver, + solverOps[0].from, + solverOpExecuted, + solverOpSuccess, + expectedResult, + solverOps[0].bidAmount + ); vm.prank(userEOA); if (metacallShouldRevert) vm.expectRevert(); // Metacall should revert, the reason isn't important, we're only checking the event diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index 578741fd2..efbf54690 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -110,7 +110,7 @@ contract FlashLoanTest is BaseTest { vm.startPrank(userEOA); vm.expectEmit(true, true, true, true); uint256 result = (1 << uint256(SolverOutcome.BidNotPaid)); - emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, true, false, result); + emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, true, false, result, solverOps[0].bidAmount); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); @@ -153,7 +153,7 @@ contract FlashLoanTest is BaseTest { vm.expectEmit(true, true, true, true); result = (1 << uint256(SolverOutcome.CallValueTooHigh)); console.log("result", result); - emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, false, false, result); + emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, false, false, result, solverOps[0].bidAmount); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); @@ -213,7 +213,7 @@ contract FlashLoanTest is BaseTest { vm.startPrank(userEOA); result = 0; vm.expectEmit(true, true, true, true); - emit AtlasEvents.SolverTxResult(_solver, solverOneEOA, true, true, result); + emit AtlasEvents.SolverTxResult(_solver, solverOneEOA, true, true, result, solverOps[0].bidAmount); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); From 8a475a19a5eb83b60854e3699ae5d3b9bb2e1460 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:11:12 +0200 Subject: [PATCH 62/70] feat: add `bidToken` to `SolverTxResult` event --- src/contracts/atlas/Escrow.sol | 8 +++-- src/contracts/types/AtlasEvents.sol | 3 +- test/Escrow.t.sol | 3 +- test/FlashLoan.t.sol | 55 +++++++++++++++++------------ 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 9ccfbed56..4adfe4bb0 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -206,7 +206,9 @@ abstract contract Escrow is AtlETH { if (_result.executionSuccessful()) { // First successful solver call that paid what it bid - emit SolverTxResult(solverOp.solver, solverOp.from, true, true, _result, bidAmount); + emit SolverTxResult( + solverOp.solver, solverOp.from, true, true, _result, bidAmount, solverOp.bidToken + ); ctx.solverSuccessful = true; ctx.solverOutcome = uint24(_result); @@ -221,7 +223,9 @@ abstract contract Escrow is AtlETH { // Account for failed SolverOperation gas costs _handleSolverAccounting(solverOp, _gasWaterMark, _result, !prevalidated); - emit SolverTxResult(solverOp.solver, solverOp.from, _result.executedWithError(), false, _result, bidAmount); + emit SolverTxResult( + solverOp.solver, solverOp.from, _result.executedWithError(), false, _result, bidAmount, solverOp.bidToken + ); return 0; } diff --git a/src/contracts/types/AtlasEvents.sol b/src/contracts/types/AtlasEvents.sol index c72f316df..cc504d85f 100644 --- a/src/contracts/types/AtlasEvents.sol +++ b/src/contracts/types/AtlasEvents.sol @@ -26,7 +26,8 @@ contract AtlasEvents { bool executed, bool success, uint256 result, - uint256 bidAmount + uint256 bidAmount, + address bidToken ); // Factory events diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index 2031acc83..4ac30686d 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -663,7 +663,8 @@ contract EscrowTest is BaseTest { solverOpExecuted, solverOpSuccess, expectedResult, - solverOps[0].bidAmount + solverOps[0].bidAmount, + solverOps[0].bidToken ); vm.prank(userEOA); diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index efbf54690..064c28725 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -26,10 +26,18 @@ interface IWETH { function withdraw(uint256 wad) external; } +struct Balances{ + uint256 eth; + uint256 atlETH; + uint256 bonded; +} + contract FlashLoanTest is BaseTest { DummyDAppControlBuilder public control; Sig public sig; + Balances public userBefore; + Balances public userAfter; function setUp() public virtual override { BaseTest.setUp(); @@ -110,7 +118,9 @@ contract FlashLoanTest is BaseTest { vm.startPrank(userEOA); vm.expectEmit(true, true, true, true); uint256 result = (1 << uint256(SolverOutcome.BidNotPaid)); - emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, true, false, result, solverOps[0].bidAmount); + emit AtlasEvents.SolverTxResult( + address(solver), solverOneEOA, true, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); @@ -153,7 +163,9 @@ contract FlashLoanTest is BaseTest { vm.expectEmit(true, true, true, true); result = (1 << uint256(SolverOutcome.CallValueTooHigh)); console.log("result", result); - emit AtlasEvents.SolverTxResult(address(solver), solverOneEOA, false, false, result, solverOps[0].bidAmount); + emit AtlasEvents.SolverTxResult( + address(solver), solverOneEOA, false, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); @@ -192,15 +204,12 @@ contract FlashLoanTest is BaseTest { (sig.v, sig.r, sig.s) = vm.sign(governancePK, atlasVerification.getDAppOperationPayload(dAppOp)); dAppOp.signature = abi.encodePacked(sig.r, sig.s, sig.v); - address _solver = address(solver); - - uint256 solverStartingTotal = WETH.balanceOf(_solver); - + uint256 solverStartingTotal = WETH.balanceOf(address(solver)); uint256 atlasStartingETH = address(atlas).balance; - uint256 userStartingETH = address(userEOA).balance; - uint256 userStartingAtlETH = atlas.balanceOf(userEOA); - uint256 userStartingBonded = atlas.balanceOfBonded(userEOA); + userBefore.eth = address(userEOA).balance; + userBefore.atlETH = atlas.balanceOf(userEOA); + userBefore.bonded = atlas.balanceOfBonded(userEOA); assertEq(solverStartingTotal, 1e18, "solver incorrect starting WETH"); solverStartingTotal += (atlas.balanceOf(solverOneEOA) + atlas.balanceOfBonded(solverOneEOA)); @@ -213,7 +222,9 @@ contract FlashLoanTest is BaseTest { vm.startPrank(userEOA); result = 0; vm.expectEmit(true, true, true, true); - emit AtlasEvents.SolverTxResult(_solver, solverOneEOA, true, true, result, solverOps[0].bidAmount); + emit AtlasEvents.SolverTxResult( + address(solver), solverOneEOA, true, true, result, solverOps[0].bidAmount, solverOps[0].bidToken + ); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); @@ -222,18 +233,18 @@ contract FlashLoanTest is BaseTest { { console.log("solverStartingTotal: ", solverStartingTotal); - console.log("solverEndingTotal : ", WETH.balanceOf(_solver) + atlas.balanceOf(solverOneEOA) + atlas.balanceOfBonded(solverOneEOA)); - solverStartingTotal -= (WETH.balanceOf(_solver) + atlas.balanceOf(solverOneEOA) + atlas.balanceOfBonded(solverOneEOA)); + console.log("solverEndingTotal : ", WETH.balanceOf(address(solver)) + atlas.balanceOf(solverOneEOA) + atlas.balanceOfBonded(solverOneEOA)); + solverStartingTotal -= (WETH.balanceOf(address(solver)) + atlas.balanceOf(solverOneEOA) + atlas.balanceOfBonded(solverOneEOA)); console.log("solverDeltaTotal : ", solverStartingTotal); } - uint256 userEndingETH = address(userEOA).balance; - uint256 userEndingAtlETH = atlas.balanceOf(userEOA); - uint256 userEndingBonded = atlas.balanceOfBonded(userEOA); + userAfter.eth = address(userEOA).balance; + userAfter.atlETH = atlas.balanceOf(userEOA); + userAfter.bonded = atlas.balanceOfBonded(userEOA); { - console.log("userStartingTotal :", userStartingETH + userStartingAtlETH + userStartingBonded); - console.log("userEndingTotal :", userEndingETH + userEndingAtlETH + userEndingBonded); + console.log("userStartingTotal :", userBefore.eth + userBefore.atlETH + userBefore.bonded); + console.log("userEndingTotal :", userAfter.eth + userAfter.atlETH + userAfter.bonded); console.log("atlasStartingETH :", atlasStartingETH); console.log("atlasEndingETH :", address(atlas).balance); @@ -242,7 +253,7 @@ contract FlashLoanTest is BaseTest { netSurcharge = atlas.cumulativeSurcharge() - netSurcharge; console.log("NetCumulativeSrchrg: ", netSurcharge); - assertEq(WETH.balanceOf(_solver), 0, "solver WETH not used"); + assertEq(WETH.balanceOf(address(solver)), 0, "solver WETH not used"); assertEq(atlas.balanceOf(solverOneEOA), 0, "solver atlETH not used"); console.log("atlasStartingETH :", atlasStartingETH); console.log("atlasEnding ETH :", address(atlas).balance); @@ -250,10 +261,10 @@ contract FlashLoanTest is BaseTest { // NOTE: solverStartingTotal is the solverTotal delta, not starting. assertTrue(address(atlas).balance >= atlasStartingETH - solverStartingTotal, "atlas incorrect ending ETH"); // atlas should NEVER lose balance during a metacall - console.log("userStartingETH :", userStartingETH); - console.log("userEndingETH :", userEndingETH); - assertTrue((userEndingETH - userStartingETH) >= 1 ether, "user incorrect ending ETH"); // user bal should increase by 1e (bid) + gas refund - assertTrue((userEndingBonded - userStartingBonded) == 0, "user incorrect ending bonded AtlETH"); // user bonded bal should increase by gas refund + console.log("userStartingETH :", userBefore.eth); + console.log("userEndingETH :", userAfter.eth); + assertTrue((userAfter.eth - userBefore.eth) >= 1 ether, "user incorrect ending ETH"); // user bal should increase by 1e (bid) + gas refund + assertTrue((userAfter.bonded - userBefore.bonded) == 0, "user incorrect ending bonded AtlETH"); // user bonded bal should increase by gas refund } } From 6df621f752eab255e7ed54f719f600b5c62fbb0a Mon Sep 17 00:00:00 2001 From: jj1980a Date: Tue, 12 Nov 2024 12:33:47 +0400 Subject: [PATCH 63/70] add indexed dapp control address in solver tx result event --- lib/forge-std | 2 +- lib/solady | 2 +- src/contracts/atlas/Escrow.sol | 11 +++++++++-- src/contracts/types/AtlasEvents.sol | 1 + test/Escrow.t.sol | 1 + test/FlashLoan.t.sol | 6 +++--- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/forge-std b/lib/forge-std index 1de6eecf8..5a802d7c1 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f +Subproject commit 5a802d7c10abb4bbfb3e7214c75052ef9e6a06f8 diff --git a/lib/solady b/lib/solady index 973b785be..42af395e6 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 973b785beefcb66934844155ccf2639ce10e980c +Subproject commit 42af395e631fcc9d640eddf11c57c6f1ca3f9103 diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 4adfe4bb0..7a5003d93 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -207,7 +207,7 @@ abstract contract Escrow is AtlETH { if (_result.executionSuccessful()) { // First successful solver call that paid what it bid emit SolverTxResult( - solverOp.solver, solverOp.from, true, true, _result, bidAmount, solverOp.bidToken + solverOp.solver, solverOp.from, dConfig.to, true, true, _result, bidAmount, solverOp.bidToken ); ctx.solverSuccessful = true; @@ -224,7 +224,14 @@ abstract contract Escrow is AtlETH { _handleSolverAccounting(solverOp, _gasWaterMark, _result, !prevalidated); emit SolverTxResult( - solverOp.solver, solverOp.from, _result.executedWithError(), false, _result, bidAmount, solverOp.bidToken + solverOp.solver, + solverOp.from, + dConfig.to, + _result.executedWithError(), + false, + _result, + bidAmount, + solverOp.bidToken ); return 0; diff --git a/src/contracts/types/AtlasEvents.sol b/src/contracts/types/AtlasEvents.sol index cc504d85f..18a21c030 100644 --- a/src/contracts/types/AtlasEvents.sol +++ b/src/contracts/types/AtlasEvents.sol @@ -23,6 +23,7 @@ contract AtlasEvents { event SolverTxResult( address indexed solverTo, address indexed solverFrom, + address indexed dAppControl, bool executed, bool success, uint256 result, diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index 4ac30686d..02d451dff 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -660,6 +660,7 @@ contract EscrowTest is BaseTest { emit AtlasEvents.SolverTxResult( solverOps[0].solver, solverOps[0].from, + userOp.control, solverOpExecuted, solverOpSuccess, expectedResult, diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index 064c28725..2013848e8 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -119,7 +119,7 @@ contract FlashLoanTest is BaseTest { vm.expectEmit(true, true, true, true); uint256 result = (1 << uint256(SolverOutcome.BidNotPaid)); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, true, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), solverOneEOA, userOp.control, true, false, result, solverOps[0].bidAmount, solverOps[0].bidToken ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); @@ -164,7 +164,7 @@ contract FlashLoanTest is BaseTest { result = (1 << uint256(SolverOutcome.CallValueTooHigh)); console.log("result", result); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, false, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), solverOneEOA, userOp.control, false, false, result, solverOps[0].bidAmount, solverOps[0].bidToken ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); @@ -223,7 +223,7 @@ contract FlashLoanTest is BaseTest { result = 0; vm.expectEmit(true, true, true, true); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, true, true, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), solverOneEOA, userOp.control, true, true, result, solverOps[0].bidAmount, solverOps[0].bidToken ); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); From 617e8e6ad613f9a0fce5b6e8f33b4a13435767ad Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:46:10 +0200 Subject: [PATCH 64/70] fix: rearrange event item order - solves stack too deep --- src/contracts/atlas/Escrow.sol | 8 ++++---- src/contracts/types/AtlasEvents.sol | 6 +++--- test/Escrow.t.sol | 6 +++--- test/FlashLoan.t.sol | 27 ++++++++++++++++++++++++--- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/contracts/atlas/Escrow.sol b/src/contracts/atlas/Escrow.sol index 7a5003d93..ec4b0666a 100644 --- a/src/contracts/atlas/Escrow.sol +++ b/src/contracts/atlas/Escrow.sol @@ -207,7 +207,7 @@ abstract contract Escrow is AtlETH { if (_result.executionSuccessful()) { // First successful solver call that paid what it bid emit SolverTxResult( - solverOp.solver, solverOp.from, dConfig.to, true, true, _result, bidAmount, solverOp.bidToken + solverOp.solver, solverOp.from, dConfig.to, solverOp.bidToken, bidAmount, true, true, _result ); ctx.solverSuccessful = true; @@ -227,11 +227,11 @@ abstract contract Escrow is AtlETH { solverOp.solver, solverOp.from, dConfig.to, + solverOp.bidToken, + bidAmount, _result.executedWithError(), false, - _result, - bidAmount, - solverOp.bidToken + _result ); return 0; diff --git a/src/contracts/types/AtlasEvents.sol b/src/contracts/types/AtlasEvents.sol index 18a21c030..54093db8e 100644 --- a/src/contracts/types/AtlasEvents.sol +++ b/src/contracts/types/AtlasEvents.sol @@ -24,11 +24,11 @@ contract AtlasEvents { address indexed solverTo, address indexed solverFrom, address indexed dAppControl, + address bidToken, + uint256 bidAmount, bool executed, bool success, - uint256 result, - uint256 bidAmount, - address bidToken + uint256 result ); // Factory events diff --git a/test/Escrow.t.sol b/test/Escrow.t.sol index 02d451dff..2eb667754 100644 --- a/test/Escrow.t.sol +++ b/test/Escrow.t.sol @@ -661,11 +661,11 @@ contract EscrowTest is BaseTest { solverOps[0].solver, solverOps[0].from, userOp.control, + solverOps[0].bidToken, + solverOps[0].bidAmount, solverOpExecuted, solverOpSuccess, - expectedResult, - solverOps[0].bidAmount, - solverOps[0].bidToken + expectedResult ); vm.prank(userEOA); diff --git a/test/FlashLoan.t.sol b/test/FlashLoan.t.sol index 2013848e8..bc7716521 100644 --- a/test/FlashLoan.t.sol +++ b/test/FlashLoan.t.sol @@ -119,7 +119,14 @@ contract FlashLoanTest is BaseTest { vm.expectEmit(true, true, true, true); uint256 result = (1 << uint256(SolverOutcome.BidNotPaid)); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, userOp.control, true, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), + solverOneEOA, + userOp.control, + solverOps[0].bidToken, + solverOps[0].bidAmount, + true, + false, + result ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); @@ -164,7 +171,14 @@ contract FlashLoanTest is BaseTest { result = (1 << uint256(SolverOutcome.CallValueTooHigh)); console.log("result", result); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, userOp.control, false, false, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), + solverOneEOA, + userOp.control, + solverOps[0].bidToken, + solverOps[0].bidAmount, + false, + false, + result ); vm.expectRevert(); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); @@ -223,7 +237,14 @@ contract FlashLoanTest is BaseTest { result = 0; vm.expectEmit(true, true, true, true); emit AtlasEvents.SolverTxResult( - address(solver), solverOneEOA, userOp.control, true, true, result, solverOps[0].bidAmount, solverOps[0].bidToken + address(solver), + solverOneEOA, + userOp.control, + solverOps[0].bidToken, + solverOps[0].bidAmount, + true, + true, + result ); atlas.metacall({ userOp: userOp, solverOps: solverOps, dAppOp: dAppOp }); vm.stopPrank(); From 4807453749ccb3d613bc037a1ee8890cf7d92f98 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:24:00 +0200 Subject: [PATCH 65/70] feat: add surcharge settings to deploy script --- script/base/deploy-base.s.sol | 13 +++++++++++++ script/deploy-atlas.s.sol | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/script/base/deploy-base.s.sol b/script/base/deploy-base.s.sol index 0b5059d45..ca7a4b748 100644 --- a/script/base/deploy-base.s.sol +++ b/script/base/deploy-base.s.sol @@ -70,6 +70,19 @@ contract DeployBaseScript is Script { } } + function _getSurchargeRates() internal view returns (uint256 atlasSurchargeRate, uint256 bundlerSurchargeRate) { + uint256 chainId = block.chainid; + if (chainId == 137 || chainId == 80_002) { + // POLYGON and AMOY + atlasSurchargeRate = 5_000_000; // 50% + bundlerSurchargeRate = 5_000_000; // 50% + } else { + // Default - for all other chains + atlasSurchargeRate = 1_000_000; // 10% + bundlerSurchargeRate = 1_000_000; // 10% + } + } + // NOTE: When handling JSON with StdJson, prefix keys with '.' e.g. '.ATLAS' // These 2 functions abstract away the '.' thing though. // Pass in a key like 'ATLAS', and the current chain will be detected via `block.chainid` in `_getDeployChain()` diff --git a/script/deploy-atlas.s.sol b/script/deploy-atlas.s.sol index b60e37e1b..da8f07b95 100644 --- a/script/deploy-atlas.s.sol +++ b/script/deploy-atlas.s.sol @@ -16,8 +16,8 @@ import { ExecutionEnvironment } from "../src/contracts/common/ExecutionEnvironme contract DeployAtlasScript is DeployBaseScript { uint256 ESCROW_DURATION = 64; - uint256 ATLAS_SURCHARGE_RATE = 1_000_000; // 10% - uint256 BUNDLER_SURCHARGE_RATE = 1_000_000; // 10% + uint256 ATLAS_SURCHARGE_RATE; // Set below + uint256 BUNDLER_SURCHARGE_RATE; // Set below function run() external { console.log("\n=== DEPLOYING Atlas ===\n"); @@ -27,6 +27,8 @@ contract DeployAtlasScript is DeployBaseScript { uint256 deployerPrivateKey = vm.envUint("GOV_PRIVATE_KEY"); address deployer = vm.addr(deployerPrivateKey); + (ATLAS_SURCHARGE_RATE, BUNDLER_SURCHARGE_RATE) = _getSurchargeRates(); + // Computes the addresses at which AtlasVerification will be deployed address expectedAtlasAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 2); address expectedAtlasVerificationAddr = vm.computeCreateAddress(deployer, vm.getNonce(deployer) + 3); From 60a70b3e7d886677ef7a0759cee4a87a818334c0 Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:50:18 +0200 Subject: [PATCH 66/70] chore: deploy Atlas v1.1 on Polygon --- deployments.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deployments.json b/deployments.json index 005f6f6f9..a11867c80 100644 --- a/deployments.json +++ b/deployments.json @@ -18,10 +18,10 @@ "FL_ONLINE_DAPP_CONTROL": "0xf0E388C7DFfE14a61280a4E5b84d77be3d2875e3" }, "POLYGON": { - "ATLAS": "0x912AceADa1b9c9B378894D0610C5684167710FDD", - "ATLAS_VERIFICATION": "0x2fBF38a38D753E4ce398000CCC552Efa50702e1e", - "SIMULATOR": "0x1244E4B8D93D2A72692Bf3600f7f5a494e24895a", - "SORTER": "0xFac7bf300E7eb17A2eD0Be67b60f5FeDd2E28E90", + "ATLAS": "0xB363f4D32DdB0b43622eA07Ae9145726941272B4", + "ATLAS_VERIFICATION": "0x621c6970fD9F124230feE35117d318069056819a", + "SIMULATOR": "0x82A3460920582968688FD887F21c5F3155A3BBd4", + "SORTER": "0xf8Bd19064A77297A691a29d9a40dF76F32fc86ad", "FL_ONLINE_DAPP_CONTROL": "0x498aC70345AD6b161eEf4AFBEA8F010401cfa780" }, "BSC": { @@ -54,4 +54,4 @@ "SORTER": "", "FL_ONLINE_DAPP_CONTROL": "" } -} +} \ No newline at end of file From 3d372be5424b44c6c668d030bbe7a38eb5490982 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Wed, 13 Nov 2024 14:00:11 +0400 Subject: [PATCH 67/70] add base sepolia deployment adresses --- deployments.json | 9 ++++++++- package.json | 4 +++- src/contracts/gasCalculator/BaseGasCalculator.sol | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/deployments.json b/deployments.json index a11867c80..f4c55feee 100644 --- a/deployments.json +++ b/deployments.json @@ -53,5 +53,12 @@ "SIMULATOR": "", "SORTER": "", "FL_ONLINE_DAPP_CONTROL": "" + }, + "BASE SEPOLIA": { + "ATLAS": "0xa55051bd82eFeA1dD487875C84fE9c016859659B", + "ATLAS_VERIFICATION": "0xf0E388C7DFfE14a61280a4E5b84d77be3d2875e3", + "SIMULATOR": "0xD72D821dA82964c0546a5501347a3959808E072f", + "SORTER": "0xAb665f032e6A20Ef7D43FfD4E92a2f4fd6d5771e", + "L2_GAS_CALCULATOR": "0x3b7B38362bB7E2F000Cd2432343F3483F785F435" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 670a89b44..01e5657e6 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "deploy-atlas-bsc": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BSC_RPC_URL} --legacy --broadcast --etherscan-api-key ${BSCSCAN_API_KEY} --verify --delay 30", "deploy-atlas-bsc-testnet": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BSC_TESTNET_RPC_URL} --legacy --broadcast --etherscan-api-key ${BSCSCAN_API_KEY} --verify --delay 30", + + "deploy-atlas-base-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BASE_SEPOLIA_RPC_URL} --legacy --broadcast --etherscan-api-key ${BASESCAN_API_KEY} --verify --delay 30", "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --legacy --gas-estimate-multiplier 150 --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify --delay 30", "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast", @@ -60,7 +62,7 @@ "solver-deposit": "source .env && forge script script/solver-deposit.s.sol:SolverAtlasDepositScript --fork-url http://localhost:8545 --broadcast --non-interactive", "setup-demo": "npm run deploy-atlas-swap-intent-tx-builder && npm run deploy-solver && npm run solver-deposit", - "deploy-gas-calculator-base": "source .env && forge script script/deploy-gas-calculator.s.sol:DeployGasCalculatorScript --rpc-url ${BASE_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", + "deploy-gas-calculator-base": "source .env && forge script script/deploy-gas-calculator.s.sol:DeployGasCalculatorScript --rpc-url ${BASE_RPC_URL} --broadcast --etherscan-api-key ${BASESCAN_API_KEY} --verify", "atlas-addr": "echo 'ATLAS:' && jq -r '.ATLAS' deployments.json", "swap-intent-addr": "echo 'SWAP INTENT DAPP CONTROL:' && jq -r '.SWAP_INTENT_DAPP_CONTROL' deployments.json", diff --git a/src/contracts/gasCalculator/BaseGasCalculator.sol b/src/contracts/gasCalculator/BaseGasCalculator.sol index ff9b73208..af36c65b0 100644 --- a/src/contracts/gasCalculator/BaseGasCalculator.sol +++ b/src/contracts/gasCalculator/BaseGasCalculator.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; -import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol"; import { IL2GasCalculator } from "src/contracts/interfaces/IL2GasCalculator.sol"; /// @notice Implementation: From c27bd763ed27443463541103d4024e4378e52566 Mon Sep 17 00:00:00 2001 From: Amitabh Anand Date: Wed, 13 Nov 2024 16:15:39 +0530 Subject: [PATCH 68/70] feat: base deployment --- .env.example | 3 ++- deployments.json | 7 +++++++ package.json | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index bfab354ce..96c390fce 100644 --- a/.env.example +++ b/.env.example @@ -27,4 +27,5 @@ BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/XXXXXXXX ETHERSCAN_API_KEY=XXXXXXXX POLYGONSCAN_API_KEY=XXXXXXXX -BSCSCAN_API_KEY=XXXXXXXX \ No newline at end of file +BSCSCAN_API_KEY=XXXXXXXX +BASESCAN_API_KEY=XXXXXXXX \ No newline at end of file diff --git a/deployments.json b/deployments.json index a11867c80..96fc9f766 100644 --- a/deployments.json +++ b/deployments.json @@ -53,5 +53,12 @@ "SIMULATOR": "", "SORTER": "", "FL_ONLINE_DAPP_CONTROL": "" + }, + "BASE": { + "ATLAS": "0x3efbaBE0ee916A4677D281c417E895a3e7411Ac2", + "ATLAS_VERIFICATION": "0x16839b7Bb46136B204Bcb7eA71c9226952c02b34", + "SIMULATOR": "0xa55051bd82eFeA1dD487875C84fE9c016859659B", + "SORTER": "0xD72D821dA82964c0546a5501347a3959808E072f", + "L2_GAS_CALCULATOR": "0xf9436C4b1353D5B411AD5bb65B9826f34737BbC7" } } \ No newline at end of file diff --git a/package.json b/package.json index 670a89b44..fc1726815 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "deploy-atlas-sepolia": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${SEPOLIA_RPC_URL} --legacy --gas-estimate-multiplier 150 --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify --delay 30", "deploy-atlas-local": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --fork-url http://localhost:8545 --broadcast", + "deploy-atlas-base": "source .env && forge script script/deploy-atlas.s.sol:DeployAtlasScript --rpc-url ${BASE_RPC_URL} --legacy --broadcast --etherscan-api-key ${BASESCAN_API_KEY} --verify --delay 30", + "deploy-swap-intent-sepolia": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", "deploy-swap-intent-local": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --fork-url http://localhost:8545 --broadcast", From 6af7d57ba7b3d7e94ab66de2bf5856f608a67aee Mon Sep 17 00:00:00 2001 From: jj1980a Date: Thu, 14 Nov 2024 12:50:30 +0400 Subject: [PATCH 69/70] univ3 pools creation script --- package.json | 1 + script/deploy-demo-tokens-v3.s.sol | 203 +++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 script/deploy-demo-tokens-v3.s.sol diff --git a/package.json b/package.json index a6e1ab604..41278c9a2 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "deploy-swap-intent-local": "source .env && forge script script/deploy-swap-intent-control.s.sol:DeploySwapIntentControlScript --fork-url http://localhost:8545 --broadcast", "deploy-demo-tokens-sepolia": "source .env && forge script script/deploy-demo-tokens.s.sol:DeployDemoTokensScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", + "deploy-demo-tokens-base-sepolia": "source .env && forge script script/deploy-demo-tokens-v3.s.sol:DeployDemoTokensScript --rpc-url ${BASE_SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${BASESCAN_API_KEY} --verify", "mint-demo-tokens-sepolia": "source .env && forge script script/mint-demo-tokens.s.sol:MintDemoTokensScript --rpc-url ${SEPOLIA_RPC_URL} --broadcast --etherscan-api-key ${ETHERSCAN_API_KEY} --verify", diff --git a/script/deploy-demo-tokens-v3.s.sol b/script/deploy-demo-tokens-v3.s.sol new file mode 100644 index 000000000..30c7c9540 --- /dev/null +++ b/script/deploy-demo-tokens-v3.s.sol @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.28; + +import "forge-std/Script.sol"; +import "forge-std/Test.sol"; + +import { DeployBaseScript } from "script/base/deploy-base.s.sol"; + +import { Token } from "../src/contracts/helpers/DemoToken.sol"; +import { WETH } from "solady/tokens/WETH.sol"; + +// Deploy 3 stablecoin tokens (DAI, USDA, USDB) - all 18 decimals +// Use WETH recognized by Uniswap V3 Router on the target chain +// Make WETH/Stable pools on Uniswap V3 for each stablecoin +// Add liquidity to each pool: 900 Stablecoin / 0.00001 WETH + +contract DeployDemoTokensScript is DeployBaseScript { + // on Base Sepolia + address public constant UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER = 0x27F971cb582BF9E50F397e4d29a5C7A34f11faA2; + + uint256 public constant WETH_AMOUNT = 0.00001 ether; + uint256 public constant STABLE_AMOUNT = 900 ether; + + uint256 public constant ETH_GAS_BUFFER = 0.01 ether; //TODO update + uint256 public constant ETH_NEEDED = ETH_GAS_BUFFER + (WETH_AMOUNT * 3); + + Token dai; + Token usda; + Token usdb; + + address payable public constant WETH_ADDRESS = payable(0x4200000000000000000000000000000000000006); + WETH9 weth = WETH9(WETH_ADDRESS); + + function run() external { + console.log("\n=== DEPLOYING DEMO TOKENS ===\n"); + + uint256 deployerPrivateKey = vm.envUint("DAPP_GOV_PRIVATE_KEY"); + address deployer = vm.addr(deployerPrivateKey); + + console.log("Deployer address: \t\t\t\t", deployer); + + if (deployer.balance < ETH_NEEDED) { + console.log("\n"); + console.log("NOT ENOUGH ETH IN DEPLOYER WALLET!"); + console.log("Wallet balance: \t\t\t\t", deployer.balance); + console.log("ETH needed: \t\t\t\t\t", ETH_NEEDED); + return; + } + + vm.startBroadcast(deployerPrivateKey); + + // Deploy 3 stablecoins + console.log("Deploying tokens...\n"); + dai = new Token("DAI Stablecoin", "DAI", 18); + usda = new Token("USDA Stablecoin", "USDA", 18); + usdb = new Token("USDB Stablecoin", "USDB", 18); + + address token0; + address token1; + uint160 sqrtPriceX96 = 1.0001e18; + uint24 fee = 100; + + // Create WETH/Stablecoin pools on Uniswap V3 + console.log("Creating Uniswap V3 Pools...\n"); + + token0 = address(dai) < address(weth) ? address(dai) : address(weth); + token1 = address(dai) < address(weth) ? address(weth) : address(dai); + address daiWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + token0 = address(usda) < address(weth) ? address(usda) : address(weth); + token1 = address(usda) < address(weth) ? address(weth) : address(usda); + address usdaWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + token0 = address(usdb) < address(weth) ? address(usdb) : address(weth); + token1 = address(usdb) < address(weth) ? address(weth) : address(usdb); + address usdbWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + token0 = address(dai) < address(usda) ? address(dai) : address(usda); + token1 = address(dai) < address(usda) ? address(usda) : address(dai); + address daiUsdaPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + token0 = address(dai) < address(usdb) ? address(dai) : address(usdb); + token1 = address(dai) < address(usdb) ? address(usdb) : address(dai); + address daiUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + token0 = address(usda) < address(usdb) ? address(usda) : address(usdb); + token1 = address(usda) < address(usdb) ? address(usdb) : address(usda); + address usdaUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + + // Add liquidity to stablecoin/weth pools: 900 Stablecoin / 0.3 WETH = $3000 per WETH + console.log("Adding liquidity to STABLE/WETH pools...\n"); + mintApproveAndAddLiquidity(dai, Token(address(weth)), STABLE_AMOUNT, WETH_AMOUNT, deployer); + mintApproveAndAddLiquidity(usda, Token(address(weth)), STABLE_AMOUNT, WETH_AMOUNT, deployer); + mintApproveAndAddLiquidity(usdb, Token(address(weth)), STABLE_AMOUNT, WETH_AMOUNT, deployer); + + // Add liquidity to stablecoin/stablecoin pools: 900 Stablecoin / 900 Stablecoin = $1 per Stablecoin + console.log("Adding liquidity to STABLE/STABLE pools...\n"); + mintApproveAndAddLiquidity(dai, usda, STABLE_AMOUNT, STABLE_AMOUNT, deployer); + mintApproveAndAddLiquidity(dai, usdb, STABLE_AMOUNT, STABLE_AMOUNT, deployer); + mintApproveAndAddLiquidity(usda, usdb, STABLE_AMOUNT, STABLE_AMOUNT, deployer); + + vm.stopBroadcast(); + + console.log("\n"); + console.log("WETH Token used: \t\t", address(weth)); + console.log("\n"); + console.log("DAI deployed at: \t\t", address(dai)); + console.log("USDA deployed at: \t\t", address(usda)); + console.log("USDB deployed at: \t\t", address(usdb)); + console.log("\n"); + console.log("DAI/WETH Pool: \t\t", daiWethPool); + console.log("USDA/WETH Pool: \t\t", usdaWethPool); + console.log("USDB/WETH Pool: \t\t", usdbWethPool); + console.log("DAI/USDA Pool: \t\t", daiUsdaPool); + console.log("DAI/USDB Pool: \t\t", daiUsdbPool); + console.log("USDA/USDB Pool: \t\t", usdaUsdbPool); + console.log("\n"); + } + + function mintApproveAndAddLiquidity( + Token tokenA, + Token tokenB, + uint256 amountA, + uint256 amountB, + address deployer + ) + public + { + // Deposit ETH if token is WETH, or mint tokens if not WETH + if (address(tokenA) == address(weth)) { + WETH9(WETH_ADDRESS).deposit{ value: amountA }(); + } else { + tokenA.mint(deployer, amountA); + } + + if (address(tokenB) == address(weth)) { + WETH9(WETH_ADDRESS).deposit{ value: amountB }(); + } else { + tokenB.mint(deployer, amountB); + } + + // Then approve both tokens and add liquidity on Uniswap + tokenA.approve(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER, amountA); + tokenB.approve(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER, amountB); + IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER).mint( + IUniswapV3NonfungiblePositionManager.MintParams({ + token0: address(tokenA) < address(tokenB) ? address(tokenA) : address(tokenB), + token1: address(tokenA) < address(tokenB) ? address(tokenB) : address(tokenA), + fee: 100, + tickLower: -887_271, + tickUpper: 887_271, + amount0Desired: address(tokenA) < address(tokenB) ? amountA : amountB, + amount1Desired: address(tokenA) < address(tokenB) ? amountB : amountA, + amount0Min: 1, + amount1Min: 1, + recipient: deployer, + deadline: block.timestamp + 1000 + }) + ); + } +} + +interface IUniswapV3NonfungiblePositionManager { + function createAndInitializePoolIfNecessary( + address token0, + address token1, + uint24 fee, + uint160 sqrtPriceX96 + ) + external + payable + returns (address pool); + + struct MintParams { + address token0; + address token1; + uint24 fee; + int24 tickLower; + int24 tickUpper; + uint256 amount0Desired; + uint256 amount1Desired; + uint256 amount0Min; + uint256 amount1Min; + address recipient; + uint256 deadline; + } + + function mint(MintParams calldata params) + external + payable + returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); +} + +// Foundry not compiling if WETH imported directly from solady/tokens/WETH.sol for some reason. +contract WETH9 is WETH { + constructor() WETH() { } +} From b1d23f11003307d8670536485c02d984b7c4c6ac Mon Sep 17 00:00:00 2001 From: jj1980a Date: Thu, 14 Nov 2024 13:42:28 +0400 Subject: [PATCH 70/70] adjust initial pool price --- script/deploy-demo-tokens-v3.s.sol | 102 +++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/script/deploy-demo-tokens-v3.s.sol b/script/deploy-demo-tokens-v3.s.sol index 30c7c9540..c471e5208 100644 --- a/script/deploy-demo-tokens-v3.s.sol +++ b/script/deploy-demo-tokens-v3.s.sol @@ -9,6 +9,8 @@ import { DeployBaseScript } from "script/base/deploy-base.s.sol"; import { Token } from "../src/contracts/helpers/DemoToken.sol"; import { WETH } from "solady/tokens/WETH.sol"; +import { stdMath } from "forge-std/StdMath.sol"; + // Deploy 3 stablecoin tokens (DAI, USDA, USDB) - all 18 decimals // Use WETH recognized by Uniswap V3 Router on the target chain // Make WETH/Stable pools on Uniswap V3 for each stablecoin @@ -55,43 +57,76 @@ contract DeployDemoTokensScript is DeployBaseScript { usda = new Token("USDA Stablecoin", "USDA", 18); usdb = new Token("USDB Stablecoin", "USDB", 18); - address token0; - address token1; - uint160 sqrtPriceX96 = 1.0001e18; + address daiWethPool; + address usdaWethPool; + address usdbWethPool; + address daiUsdaPool; + address daiUsdbPool; + address usdaUsdbPool; uint24 fee = 100; // Create WETH/Stablecoin pools on Uniswap V3 console.log("Creating Uniswap V3 Pools...\n"); - token0 = address(dai) < address(weth) ? address(dai) : address(weth); - token1 = address(dai) < address(weth) ? address(weth) : address(dai); - address daiWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(dai) < address(weth) ? address(dai) : address(weth); + address token1 = address(dai) < address(weth) ? address(weth) : address(dai); + uint256 amount0 = address(dai) < address(weth) ? STABLE_AMOUNT : WETH_AMOUNT; + uint256 amount1 = address(dai) < address(weth) ? WETH_AMOUNT : STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + daiWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } - token0 = address(usda) < address(weth) ? address(usda) : address(weth); - token1 = address(usda) < address(weth) ? address(weth) : address(usda); - address usdaWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(usda) < address(weth) ? address(usda) : address(weth); + address token1 = address(usda) < address(weth) ? address(weth) : address(usda); + uint256 amount0 = address(usda) < address(weth) ? STABLE_AMOUNT : WETH_AMOUNT; + uint256 amount1 = address(usda) < address(weth) ? WETH_AMOUNT : STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + usdaWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } - token0 = address(usdb) < address(weth) ? address(usdb) : address(weth); - token1 = address(usdb) < address(weth) ? address(weth) : address(usdb); - address usdbWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(usdb) < address(weth) ? address(usdb) : address(weth); + address token1 = address(usdb) < address(weth) ? address(weth) : address(usdb); + uint256 amount0 = address(usdb) < address(weth) ? STABLE_AMOUNT : WETH_AMOUNT; + uint256 amount1 = address(usdb) < address(weth) ? WETH_AMOUNT : STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + usdbWethPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } - token0 = address(dai) < address(usda) ? address(dai) : address(usda); - token1 = address(dai) < address(usda) ? address(usda) : address(dai); - address daiUsdaPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(dai) < address(usda) ? address(dai) : address(usda); + address token1 = address(dai) < address(usda) ? address(usda) : address(dai); + uint256 amount0 = STABLE_AMOUNT; + uint256 amount1 = STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + daiUsdaPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } - token0 = address(dai) < address(usdb) ? address(dai) : address(usdb); - token1 = address(dai) < address(usdb) ? address(usdb) : address(dai); - address daiUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(dai) < address(usdb) ? address(dai) : address(usdb); + address token1 = address(dai) < address(usdb) ? address(usdb) : address(dai); + uint256 amount0 = STABLE_AMOUNT; + uint256 amount1 = STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + daiUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } - token0 = address(usda) < address(usdb) ? address(usda) : address(usdb); - token1 = address(usda) < address(usdb) ? address(usdb) : address(usda); - address usdaUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) - .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + { + address token0 = address(usda) < address(usdb) ? address(usda) : address(usdb); + address token1 = address(usda) < address(usdb) ? address(usdb) : address(usda); + uint256 amount0 = STABLE_AMOUNT; + uint256 amount1 = STABLE_AMOUNT; + uint160 sqrtPriceX96 = uint160((sqrt((amount1 * 1e18) / amount0) * 2 ** 96) / 1e9); + usdaUsdbPool = IUniswapV3NonfungiblePositionManager(UNISWAP_V3_NONFUNGIBLE_POSITION_MANAGER) + .createAndInitializePoolIfNecessary(token0, token1, fee, sqrtPriceX96); + } // Add liquidity to stablecoin/weth pools: 900 Stablecoin / 0.3 WETH = $3000 per WETH console.log("Adding liquidity to STABLE/WETH pools...\n"); @@ -164,6 +199,19 @@ contract DeployDemoTokensScript is DeployBaseScript { }) ); } + + function sqrt(uint256 y) internal pure returns (uint256 z) { + if (y > 3) { + z = y; + uint256 x = y / 2 + 1; + while (x < z) { + z = x; + x = (y / x + x) / 2; + } + } else if (y != 0) { + z = 1; + } + } } interface IUniswapV3NonfungiblePositionManager {