Skip to content

Commit

Permalink
Merge branch 'atlas-v1.1' into userOp-gas-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSparksCode committed Oct 15, 2024
2 parents 5e05707 + 1744cef commit 9aca697
Show file tree
Hide file tree
Showing 45 changed files with 712 additions and 328 deletions.
10 changes: 3 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ 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

Change Date: The earlier of 2025-07-01 or a date specified at
fastlane-protocol-license.fastlane.finance
Change Date: 2026-07-01

Change License: GNU General Public License v2.0 or later

Expand Down
2 changes: 1 addition & 1 deletion lib/solady
Submodule solady updated 120 files
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion script/deploy-atlas.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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),
Expand Down
57 changes: 57 additions & 0 deletions script/deploy-gas-calculator.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 {
// 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("GOV_PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);

console.log("Deployer address: \t\t", deployer);

uint256 chainId = block.chainid;
address deploymentAddr;

vm.startBroadcast(deployerPrivateKey);

if (chainId == 8453 || chainId == 84_532) {
// Base or Base Sepolia
BaseGasCalculator gasCalculator = new BaseGasCalculator({
gasPriceOracle: BASE_GAS_PRICE_ORACLE,
calldataLenOffset: BASE_CALLDATA_LENGTH_OFFSET
});
deploymentAddr = address(gasCalculator);
} else {
revert("Error: Chain ID not supported");
}

vm.stopBroadcast();

_writeAddressToDeploymentsJson("L2_GAS_CALCULATOR", deploymentAddr);

console.log("\n");
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");
}
}
12 changes: 11 additions & 1 deletion src/contracts/atlas/AtlETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{ }

/*//////////////////////////////////////////////////////////////
Expand Down
15 changes: 12 additions & 3 deletions src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pragma solidity 0.8.25;
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { LibSort } from "solady/utils/LibSort.sol";

import { IDAppControl } from "../interfaces/IDAppControl.sol";

import { Escrow } from "./Escrow.sol";
import { Factory } from "./Factory.sol";

Expand All @@ -19,6 +17,7 @@ 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";

/// @title Atlas V1
/// @author FastLane Labs
Expand All @@ -29,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)
{ }

Expand Down
18 changes: 14 additions & 4 deletions src/contracts/atlas/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IExecutionEnvironment } from "src/contracts/interfaces/IExecutionEnviro
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 "../interfaces/IDAppControl.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";
Expand All @@ -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();
}
Expand Down Expand Up @@ -610,8 +620,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)
)
)
);
Expand Down
28 changes: 19 additions & 9 deletions src/contracts/atlas/GasAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -332,17 +342,17 @@ 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

// 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.
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.
Expand Down
12 changes: 11 additions & 1 deletion src/contracts/atlas/Permit69.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion src/contracts/atlas/SafetyLocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/contracts/atlas/Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -56,6 +56,8 @@ contract Storage is AtlasEvents, AtlasErrors, AtlasConstants {

constructor(
uint256 escrowDuration,
uint256 atlasSurchargeRate,
uint256 bundlerSurchargeRate,
address verification,
address simulator,
address initialSurchargeRecipient,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/dapp/ControlTemplate.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.25;

import "../types/SolverOperation.sol";
import "../types/UserOperation.sol";
import "../types/ConfigTypes.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";

abstract contract DAppControlTemplate {
Expand Down
Loading

0 comments on commit 9aca697

Please sign in to comment.