Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimbursements #449

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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 "forge-std/Test.sol";

/// @title Atlas V1
/// @author FastLane Labs
/// @notice The Execution Abstraction protocol.
Expand Down Expand Up @@ -146,6 +148,8 @@ contract Atlas is Escrow, Factory {
_returnData = _executePreOpsCall(ctx, dConfig, userOp);
}

console.log(ctx.reimbursements[0].reimburser);

// UserOp Call
_returnData = _executeUserOperation(ctx, dConfig, userOp, _returnData);

Expand Down
28 changes: 27 additions & 1 deletion src/contracts/atlas/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import "src/contracts/types/UserOperation.sol";
import "src/contracts/types/EscrowTypes.sol";
import "src/contracts/types/LockTypes.sol";

import "forge-std/Test.sol";

/// @title Escrow
/// @author FastLane Labs
/// @notice This Escrow component of Atlas handles execution of stages by calling corresponding functions on the
Expand Down Expand Up @@ -55,12 +57,35 @@ abstract contract Escrow is AtlETH {
withLockPhase(ExecutionPhase.PreOps)
returns (bytes memory)
{
uint256 gasBefore = gasleft();

(bool _success, bytes memory _data) = ctx.executionEnvironment.call(
abi.encodePacked(
abi.encodeCall(IExecutionEnvironment.preOpsWrapper, userOp), ctx.setAndPack(ExecutionPhase.PreOps)
)
);

uint256 gasUsed = gasBefore - gasleft();

Reimbursement memory newReimbursement = Reimbursement({
gasUsed: gasUsed,
reimburser: 0x1234567890123456789012345678901234567890
});

// Create a new memory array with an additional slot
Reimbursement[] memory updatedReimbursements = new Reimbursement[](ctx.reimbursements.length + 1);

// Copy existing elements
for (uint i = 0; i < ctx.reimbursements.length; i++) {
updatedReimbursements[i] = ctx.reimbursements[i];
}

// Add the new reimbursement at the end
updatedReimbursements[ctx.reimbursements.length] = newReimbursement;

// Update the context with the new array
ctx.reimbursements = updatedReimbursements;

if (_success) {
if (dConfig.callConfig.needsPreOpsReturnData()) {
return abi.decode(_data, (bytes));
Expand All @@ -70,7 +95,8 @@ abstract contract Escrow is AtlETH {
}

if (ctx.isSimulation) revert PreOpsSimFail();
revert PreOpsFail();
// revert PreOpsFail();
return new bytes(0);
}

/// @notice Executes the user operation logic defined in the Execution Environment.
Expand Down
5 changes: 4 additions & 1 deletion src/contracts/atlas/SafetyLocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ abstract contract SafetyLocks is Storage {
pure
returns (Context memory)
{
Reimbursement[] memory reimbursements;

return Context({
executionEnvironment: executionEnvironment,
userOpHash: userOpHash,
Expand All @@ -76,7 +78,8 @@ abstract contract SafetyLocks is Storage {
solverOutcome: 0,
bidFind: false,
isSimulation: isSimulation,
callDepth: 0
callDepth: 0,
reimbursements: reimbursements
});
}
}
6 changes: 6 additions & 0 deletions src/contracts/types/LockTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ struct Context {
bool bidFind;
bool isSimulation;
address bundler;
Reimbursement[] reimbursements; // array of reimbursements
}

struct Reimbursement {
uint256 gasUsed;
address reimburser;
}

enum ExecutionPhase {
Expand Down
4 changes: 3 additions & 1 deletion test/ExecutionBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ contract ExecutionBaseTest is BaseTest {
pure
returns (bytes memory firstSet, Context memory _ctx)
{
Reimbursement[] memory reimbursements;
_ctx = Context({
executionEnvironment: address(123),
userOpHash: bytes32(uint256(456)),
Expand All @@ -85,7 +86,8 @@ contract ExecutionBaseTest is BaseTest {
solverOutcome: 2,
bidFind: true,
isSimulation: false,
callDepth: 1
callDepth: 1,
reimbursements: reimbursements
});

firstSet = abi.encodePacked(
Expand Down
4 changes: 3 additions & 1 deletion test/GasAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ contract MockGasAccounting is TestAtlas, BaseTest {
view
returns (Context memory ctx)
{
Reimbursement[] memory reimbursements;
ctx = Context({
executionEnvironment: _activeEnvironment(),
userOpHash: bytes32(0),
Expand All @@ -106,7 +107,8 @@ contract MockGasAccounting is TestAtlas, BaseTest {
solverOutcome: 0,
bidFind: false,
isSimulation: false,
callDepth: 0
callDepth: 0,
reimbursements: reimbursements
});
}

Expand Down
4 changes: 3 additions & 1 deletion test/Permit69.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ contract Permit69Test is BaseTest {
callConfig: mockCallConfig
});

Reimbursement[] memory reimbursements;
ctx = Context({
executionEnvironment: mockExecutionEnvAddress,
userOpHash: bytes32(0),
Expand All @@ -77,7 +78,8 @@ contract Permit69Test is BaseTest {
solverOutcome: 0,
bidFind: false,
isSimulation: false,
callDepth: 0
callDepth: 0,
reimbursements: reimbursements
});

mockAtlas.setLock(mockExecutionEnvAddress, mockCallConfig);
Expand Down
4 changes: 3 additions & 1 deletion test/libraries/SafetyBits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract SafetyBitsTest is Test {
pure
returns (Context memory)
{
Reimbursement[] memory reimbursements;
return Context({
executionEnvironment: executionEnvironment,
userOpHash: userOpHash,
Expand All @@ -48,7 +49,8 @@ contract SafetyBitsTest is Test {
solverOutcome: 0,
bidFind: false,
isSimulation: isSimulation,
callDepth: 0
callDepth: 0,
reimbursements: reimbursements
});
}

Expand Down
Loading