Skip to content

Commit

Permalink
Merge branch 'size-cuts' into solc-version-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSparksCode committed Nov 9, 2023
2 parents 159d14f + 01d50db commit dfc2758
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 86 deletions.
46 changes: 46 additions & 0 deletions script/deploy-atlas.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Atlas} from "src/contracts/atlas/Atlas.sol";
import {AtlasFactory} from "src/contracts/atlas/AtlasFactory.sol";
import {AtlasVerification} from "src/contracts/atlas/AtlasVerification.sol";
import {GasAccountingLib} from "src/contracts/atlas/GasAccountingLib.sol";
import {SafetyLocksLib} from "src/contracts/atlas/SafetyLocksLib.sol";
import {SwapIntentController} from "src/contracts/examples/intents-example/SwapIntent.sol";
import {TxBuilder} from "src/contracts/helpers/TxBuilder.sol";
import {Simulator} from "src/contracts/helpers/Simulator.sol";
Expand All @@ -20,6 +21,7 @@ contract DeployAtlasScript is DeployBaseScript {
AtlasFactory public atlasFactory;
AtlasVerification public atlasVerification;
GasAccountingLib public gasAccountingLib;
SafetyLocksLib public safetyLocksLib;
Simulator public simulator;

function run() external {
Expand All @@ -40,6 +42,10 @@ contract DeployAtlasScript is DeployBaseScript {
deployer,
vm.getNonce(deployer) + 3
);
address expectedSafetyLocksLibAddr = computeCreateAddress(
deployer,
vm.getNonce(deployer) + 4
);

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

Expand All @@ -51,6 +57,7 @@ contract DeployAtlasScript is DeployBaseScript {
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator)
});
atlasFactory = new AtlasFactory(address(atlas));
Expand All @@ -59,6 +66,15 @@ contract DeployAtlasScript is DeployBaseScript {
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
safetyLocksLib = new SafetyLocksLib({
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
Expand All @@ -79,6 +95,7 @@ contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript {
AtlasFactory public atlasFactory;
AtlasVerification public atlasVerification;
GasAccountingLib public gasAccountingLib;
SafetyLocksLib public safetyLocksLib;
Simulator public simulator;
SwapIntentController public swapIntentControl;

Expand All @@ -100,6 +117,10 @@ contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript {
deployer,
vm.getNonce(deployer) + 3
);
address expectedSafetyLocksLibAddr = computeCreateAddress(
deployer,
vm.getNonce(deployer) + 4
);

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

Expand All @@ -111,6 +132,7 @@ contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript {
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator)
});
atlasFactory = new AtlasFactory(address(atlas));
Expand All @@ -119,6 +141,15 @@ contract DeployAtlasAndSwapIntentDAppControlScript is DeployBaseScript {
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
safetyLocksLib = new SafetyLocksLib({
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
Expand Down Expand Up @@ -148,6 +179,7 @@ contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScri
AtlasFactory public atlasFactory;
AtlasVerification public atlasVerification;
GasAccountingLib public gasAccountingLib;
SafetyLocksLib public safetyLocksLib;
Simulator public simulator;
SwapIntentController public swapIntentControl;
TxBuilder public txBuilder;
Expand All @@ -170,6 +202,10 @@ contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScri
deployer,
vm.getNonce(deployer) + 3
);
address expectedSafetyLocksLibAddr = computeCreateAddress(
deployer,
vm.getNonce(deployer) + 4
);

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

Expand All @@ -181,6 +217,7 @@ contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScri
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator)
});
atlasFactory = new AtlasFactory(address(atlas));
Expand All @@ -189,6 +226,15 @@ contract DeployAtlasAndSwapIntentDAppControlAndTxBuilderScript is DeployBaseScri
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_safetyLocksLib: expectedSafetyLocksLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
safetyLocksLib = new SafetyLocksLib({
_escrowDuration: 64,
_factory: expectedAtlasFactoryAddr,
_verification: expectedAtlasVerificationAddr,
_gasAccLib: expectedGasAccountingLibAddr,
_simulator: address(simulator),
_atlas: address(atlas)
});
Expand Down
11 changes: 6 additions & 5 deletions src/contracts/atlas/AtlETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ abstract contract AtlETH is Permit69 {
address _factory,
address _verification,
address _gasAccLib,
address _safetyLocksLib,
address _simulator
) Permit69(_escrowDuration, _factory, _verification, _gasAccLib, _simulator) {}
) Permit69(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) {}

/*//////////////////////////////////////////////////////////////
ATLETH
Expand All @@ -42,12 +43,12 @@ abstract contract AtlETH is Permit69 {
return _escrowAccountData[account].balance;
}

function nextAccountNonce(address account) external view returns (uint256 nextNonce) {
nextNonce = uint256(_escrowAccountData[account].nonce) + 1;
function nextAccountNonce(address account) external view returns (uint256) {
return uint256(_escrowAccountData[account].nonce) + 1;
}

function accountLastActiveBlock(address account) external view returns (uint256 lastBlock) {
lastBlock = uint256(_escrowAccountData[account].lastAccessed);
function accountLastActiveBlock(address account) external view returns (uint256) {
return uint256(_escrowAccountData[account].lastAccessed);
}

// Deposit ETH and get atlETH in return.
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ contract Atlas is Escrow {
address _factory,
address _verification,
address _gasAccLib,
address _safetyLocksLib,
address _simulator
) Escrow(_escrowDuration, _factory, _verification, _gasAccLib, _simulator) {}
) Escrow(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) {}

function createExecutionEnvironment(address dAppControl) external returns (address executionEnvironment) {
executionEnvironment = IAtlasFactory(FACTORY).createExecutionEnvironment(msg.sender, dAppControl);
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/atlas/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ abstract contract Escrow is AtlETH {
address _factory,
address _verification,
address _gasAccLib,
address _safetyLocksLib,
address _simulator
) AtlETH(_escrowDuration, _factory, _verification, _gasAccLib, _simulator) {}
) AtlETH(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) {}

///////////////////////////////////////////////////
/// EXTERNAL FUNCTIONS FOR BUNDLER INTERACTION ///
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/atlas/GasAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ abstract contract GasAccounting is SafetyLocks {
address _factory,
address _verification,
address _gasAccLib,
address _safetyLocksLib,
address _simulator
) SafetyLocks(_escrowDuration, _factory, _verification, _gasAccLib, _simulator) {}
) SafetyLocks(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) {}

// ---------------------------------------
// EXTERNAL FUNCTIONS
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/atlas/GasAccountingLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ contract GasAccountingLib is Storage, FastLaneErrorsEvents {
uint256 _escrowDuration,
address _factory,
address _verification,
// address _gasAccLib,
address _safetyLocksLib,
address _simulator,
address _atlas
) Storage(_escrowDuration, _factory, _verification, address(this), _simulator) {
) Storage(_escrowDuration, _factory, _verification, address(this), _safetyLocksLib, _simulator) {
ATLAS = _atlas;
}

Expand Down
155 changes: 81 additions & 74 deletions src/contracts/atlas/SafetyLocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "../types/LockTypes.sol";

import {Storage} from "./Storage.sol";
import {FastLaneErrorsEvents} from "../types/Emissions.sol";
import {SafetyLocksLib} from "./SafetyLocksLib.sol";

import "forge-std/Test.sol";

Expand All @@ -28,85 +29,91 @@ abstract contract SafetyLocks is Storage, FastLaneErrorsEvents {
address _factory,
address _verification,
address _gasAccLib,
address _safetyLocksLib,
address _simulator
) Storage(_escrowDuration, _factory, _verification, _gasAccLib, _simulator) {}
) Storage(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) {}

function _initializeEscrowLock(UserOperation calldata userOp, address executionEnvironment, address bundler, uint256 gasLimit) internal {
_checkIfUnlocked();

uint256 activeParties;
activeParties = activeParties.markActive(Party.Bundler);
activeParties = activeParties.markActive(Party.Solver);

uint256 bundlerIndex = uint256(Party.Bundler);

// Check for proxies
// NOTE: Order is important here so that we can loop through these later without having to go backwards to find final proxy
// Builder proxy
if (block.coinbase == bundler) {
activeParties = activeParties.markActive(Party.Builder);
ledgers[uint256(Party.Builder)] = Ledger({
balance: 0,
contributed: 0,
requested: 0,
status: LedgerStatus.Proxy,
proxy: Party.Bundler
});

} else if (block.coinbase == userOp.from) {
activeParties = activeParties.markActive(Party.Builder);
ledgers[uint256(Party.Builder)] = Ledger({
balance: 0,
contributed: 0,
requested: 0,
status: LedgerStatus.Proxy,
proxy: Party.User
});
}

// Bundler proxy
if (bundler == userOp.from) {
// Bundler already marked active
ledgers[uint256(Party.Bundler)] = Ledger({
balance: 0,
contributed: 0,
requested: 0,
status: LedgerStatus.Proxy,
proxy: Party.User
});
bundlerIndex = uint256(Party.User);
}

// Initialize Ledger
int64 iGasLimit = int64(uint64(gasLimit));

if (msg.value != 0) {
int64 bundlerDeposit = int64(uint64(msg.value / tx.gasprice));
ledgers[bundlerIndex] = Ledger({
balance: 0,
contributed: bundlerDeposit,
requested: 0 - bundlerDeposit - iGasLimit,
status: LedgerStatus.Active,
proxy: Party(bundlerIndex)
});
} else {
ledgers[bundlerIndex] = Ledger({
balance: 0,
contributed: 0,
requested: 0 - iGasLimit,
status: LedgerStatus.Active,
proxy: Party(bundlerIndex)
});
}

// Initialize the Lock
lock = Lock({
activeEnvironment: executionEnvironment,
activeParties: uint16(activeParties),
startingBalance: uint64((address(this).balance - msg.value) / tx.gasprice)
});
(bool success,) = SAFETY_LOCKS_LIB.delegatecall(abi.encodeWithSelector(SafetyLocksLib.initializeEscrowLock.selector, userOp, executionEnvironment, bundler, gasLimit));
if(!success) revert SafetyLocksLibError();
}

// function _initializeEscrowLock(UserOperation calldata userOp, address executionEnvironment, address bundler, uint256 gasLimit) internal {
// _checkIfUnlocked();

// uint256 activeParties;
// activeParties = activeParties.markActive(Party.Bundler);
// activeParties = activeParties.markActive(Party.Solver);

// uint256 bundlerIndex = uint256(Party.Bundler);

// // Check for proxies
// // NOTE: Order is important here so that we can loop through these later without having to go backwards to find final proxy
// // Builder proxy
// if (block.coinbase == bundler) {
// activeParties = activeParties.markActive(Party.Builder);
// ledgers[uint256(Party.Builder)] = Ledger({
// balance: 0,
// contributed: 0,
// requested: 0,
// status: LedgerStatus.Proxy,
// proxy: Party.Bundler
// });

// } else if (block.coinbase == userOp.from) {
// activeParties = activeParties.markActive(Party.Builder);
// ledgers[uint256(Party.Builder)] = Ledger({
// balance: 0,
// contributed: 0,
// requested: 0,
// status: LedgerStatus.Proxy,
// proxy: Party.User
// });
// }

// // Bundler proxy
// if (bundler == userOp.from) {
// // Bundler already marked active
// ledgers[uint256(Party.Bundler)] = Ledger({
// balance: 0,
// contributed: 0,
// requested: 0,
// status: LedgerStatus.Proxy,
// proxy: Party.User
// });
// bundlerIndex = uint256(Party.User);
// }

// // Initialize Ledger
// int64 iGasLimit = int64(uint64(gasLimit));

// if (msg.value != 0) {
// int64 bundlerDeposit = int64(uint64(msg.value / tx.gasprice));
// ledgers[bundlerIndex] = Ledger({
// balance: 0,
// contributed: bundlerDeposit,
// requested: 0 - bundlerDeposit - iGasLimit,
// status: LedgerStatus.Active,
// proxy: Party(bundlerIndex)
// });
// } else {
// ledgers[bundlerIndex] = Ledger({
// balance: 0,
// contributed: 0,
// requested: 0 - iGasLimit,
// status: LedgerStatus.Active,
// proxy: Party(bundlerIndex)
// });
// }

// // Initialize the Lock
// lock = Lock({
// activeEnvironment: executionEnvironment,
// activeParties: uint16(activeParties),
// startingBalance: uint64((address(this).balance - msg.value) / tx.gasprice)
// });
// }

function _buildEscrowLock(
DAppConfig calldata dConfig,
address executionEnvironment,
Expand Down
Loading

0 comments on commit dfc2758

Please sign in to comment.