Skip to content

Commit cb7c049

Browse files
committed
refactor: update comments and minimum deposit logic
1 parent ca7b091 commit cb7c049

2 files changed

Lines changed: 46 additions & 76 deletions

File tree

contracts/contracts/core/GasTankManager.sol

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,43 @@ import {GasTankManagerStorage} from "./GasTankManagerStorage.sol";
88
import {Errors} from "../utils/Errors.sol";
99

1010
/// @title GasTankManager
11-
/// @notice Coordinates on-demand ETH bridging so EOA gas tank balances stay funded for mev-commit transactions.
12-
/// @dev The RPC provider manages EOA gas tank balances on the Mev Commit chain.
11+
/// @notice Coordinates on-demand ETH Transfers to the RPC Service for EOA custodial gas tanks.
1312
/// @dev Flow overview:
14-
/// - EOA (L1)
15-
/// - Authorizes and sets this contract as a delegate against its own EOA address. (ERC-7702)
16-
/// - Calls `sendMinimumDeposit` to send the initial ETH funds to their gas tank on the Mev Commit chain.
17-
/// - Provider (mev-commit)
18-
/// - Triggers a top-up via `topUpGasTank` when the gas tank balance cannot cover the next mev-commit transaction. This transfer amount is always the difference
19-
/// between the `minDeposit` and the current balance of this contract. The provider is the only one who can trigger a top-up.
20-
/// - These funds are then transferred to the EOA gas tank on the Mev Commit chain.
21-
/// - When a mev-commit transaction is made, the provider deducts the amount needed from the EOA's gas tank.
13+
/// - EOA (Prerequisites for use)
14+
/// - Authorizes and sets this contract as a delegate against its own EOA address. (ERC-7702 compliant)
15+
/// - Sends the initial minimum deposit via `initializeGasTank` to the RPC Service.
16+
/// - RPC Service
17+
/// - Triggers `topUpGasTank`, transferring the `minDeposit` when the gas tank requires funding.
18+
/// - These funds are then transferred to the RPC Service's custodial gas tank.
2219
contract GasTankManager is IGasTankManager, GasTankManagerStorage, Ownable2StepUpgradeable, UUPSUpgradeable {
2320
/// @notice Restricts calls to those triggered internally via `onlyThisEOA`.
2421
modifier onlyThisEOA() {
2522
require(msg.sender == address(this), NotThisEOA(msg.sender, address(this)));
2623
_;
2724
}
2825

26+
modifier isValidCaller() {
27+
require(msg.sender == address(this) || msg.sender == owner(), NotValidCaller(msg.sender));
28+
_;
29+
}
30+
2931
/// @notice Locks the implementation upon deployment.
30-
/// @dev See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#initializing-the-implementation-contract
3132
/// @custom:oz-upgrades-unsafe-allow constructor
3233
constructor() {
3334
_disableInitializers();
3435
}
3536

36-
/// @notice Accepts direct ETH deposits and forwards them to the provider.
37-
receive() external payable {
38-
_sendFundsToProvider(msg.value);
39-
}
37+
/// @notice Accepts direct ETH deposits.
38+
receive() external payable {}
4039

4140
/// @notice Reverts on any call data to keep the interface surface narrow.
4241
fallback() external payable {
4342
revert Errors.InvalidFallback();
4443
}
4544

46-
/// @notice Initializes ownership and baseline deposit requirement.
47-
/// @param _owner EOA managed by the RPC provider.
48-
/// @param _minDeposit Initial deposit requirement in wei.
45+
/// @notice Initializes ownership and the minimum deposit requirement.
46+
/// @param _owner EOA managed by the RPC Service.
47+
/// @param _minDeposit Minimum deposit requirement.
4948
function initialize(address _owner, uint256 _minDeposit) external initializer {
5049
minDeposit = _minDeposit;
5150
__Ownable_init(_owner);
@@ -59,55 +58,34 @@ contract GasTankManager is IGasTankManager, GasTankManagerStorage, Ownable2StepU
5958
}
6059

6160
/// @inheritdoc IGasTankManager
62-
function topUpGasTank(uint256 _gasTankBalance) external onlyOwner {
63-
uint256 minDeposit_ = minDeposit;
64-
uint256 available = address(this).balance;
65-
uint256 needed = minDeposit_ - _gasTankBalance;
66-
67-
_validateTopUp(_gasTankBalance, available, needed, minDeposit_);
68-
69-
_sendFundsToProvider(needed);
70-
emit GasTankToppedUp(needed);
61+
function topUpGasTank() external onlyOwner {
62+
_sendFundsToProvider(minDeposit);
7163
}
7264

7365
/// @inheritdoc IGasTankManager
74-
function fundGasTank() external payable {
75-
_sendFundsToProvider(msg.value);
66+
function initializeGasTank() external onlyThisEOA {
67+
_sendFundsToProvider(minDeposit);
7668
}
7769

7870
/// @inheritdoc IGasTankManager
79-
function sendMinimumDeposit() external payable onlyThisEOA {
80-
require(msg.value >= minDeposit, InsufficientFundsSent(msg.value, minDeposit));
81-
_sendFundsToProvider(minDeposit);
71+
function fundGasTank() external payable isValidCaller {
72+
_sendFundsToProvider(msg.value);
8273
}
8374

84-
/// @notice Restricts upgradeability to the owner.
85-
/// @dev See https://docs.openzeppelin.com/upgrades-plugins/foundry/api/upgrades
8675
/// solhint-disable-next-line no-empty-blocks
8776
function _authorizeUpgrade(address) internal override onlyOwner {}
8877

89-
/// @notice Forwards ETH to the configured provider address.
90-
/// @dev Reverts when the provider rejects the transfer.
91-
/// @param _amount Amount of wei to transfer.
78+
/// @notice Forwards ETH to the rpcService.
79+
/// @param _amount Gas tank top-up amount.
9280
function _sendFundsToProvider(uint256 _amount) internal {
93-
address provider = owner();
94-
require(provider != address(0), ProviderNotSet(provider));
81+
address rpcService = owner();
9582

96-
(bool success,) = provider.call{value: _amount}("");
97-
require(success, GasTankTopUpFailed(provider, _amount));
98-
}
83+
require(rpcService != address(0), ProviderNotSet(rpcService));
84+
require(_amount > 0, InvalidAmount());
85+
86+
(bool success,) = rpcService.call{value: _amount}("");
87+
require(success, GasTankTopUpFailed(rpcService, _amount));
9988

100-
/// @notice Validates the proposed refill before forwarding funds.
101-
/// @dev Applies guardrails to protect configured thresholds.
102-
/// @param _gasTankBalance Current gas tank balance.
103-
/// @param _available Current contract (EOA) balance.
104-
/// @param _needed Amount required to reach the `minDeposit`.
105-
/// @param _minDeposit Minimum deposit requirement in wei.
106-
function _validateTopUp(uint256 _gasTankBalance, uint256 _available, uint256 _needed, uint256 _minDeposit)
107-
internal
108-
view
109-
{
110-
require(_gasTankBalance < _minDeposit, GasTankBalanceIsSufficient(_gasTankBalance, _minDeposit));
111-
require(_available > _needed, InsufficientEOABalance(address(this), _available, _needed));
89+
emit GasTankToppedUp(address(this), msg.sender, _amount);
11290
}
11391
}

contracts/contracts/interfaces/IGasTankManager.sol

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ interface IGasTankManager {
1010
event MinimumDepositSet(uint256 indexed minDeposit);
1111

1212
/// @dev Event to log successful gas tank top up.
13-
event GasTankToppedUp(uint256 indexed transferAmount);
13+
event GasTankToppedUp(address indexed smartAccount, address indexed caller, uint256 indexed amount);
1414

1515
/// @notice Raised when a call expected from the contract itself is not.
1616
/// @param msgSender Address that invoked the call.
1717
/// @param thisAddress Address of the contract guard.
1818
error NotThisEOA(address msgSender, address thisAddress);
1919

20-
/// @notice Raised when the contract balance cannot satisfy a refill.
21-
/// @param eoaAddress L1 EOA address.
22-
/// @param available Wei currently available on the L1 EOA address.
23-
/// @param needed Wei required to meet the minimum deposit requirement.
24-
error InsufficientEOABalance(address eoaAddress, uint256 available, uint256 needed);
20+
/// @notice Raised when an invalid caller is detected.
21+
/// @param caller Address that invoked the call.
22+
error NotValidCaller(address caller);
23+
24+
/// @notice Raised when an invalid amount is detected.
25+
error InvalidAmount();
2526

2627
/// @notice Raised when forwarding funds to the provider reverts.
2728
/// @param rpcProvider Destination address for the transfer.
@@ -33,11 +34,6 @@ interface IGasTankManager {
3334
/// @param minDeposit Minimum deposit requirement.
3435
error GasTankBalanceIsSufficient(uint256 currentBalance, uint256 minDeposit);
3536

36-
/// @notice Raised when the initial minimum deposit is not sufficient.
37-
/// @param sentAmount Amount of wei sent.
38-
/// @param requiredAmount Amount of wei required.
39-
error InsufficientFundsSent(uint256 sentAmount, uint256 requiredAmount);
40-
4137
/// @notice Raised when the provider address is not set.
4238
/// @param provider Provider address.
4339
error ProviderNotSet(address provider);
@@ -47,18 +43,14 @@ interface IGasTankManager {
4743
/// @dev Only the owner can call this function.
4844
function setMinimumDeposit(uint256 minDeposit) external;
4945

50-
/// @notice Requests a top-up when the gas tank's balance is below the minimum deposit requirement.
51-
/// @param gasTankBalance Balance that the provider currently holds on the gas tank.
52-
/// @dev Only the owner can call this function.
53-
/// @dev Reverts if the current gas tank balance is greater than or equal to the minimum deposit requirement.
54-
/// @dev Reverts if the contract balance is less than the amount needed to reach the minimum deposit requirement.
55-
/// @dev Always transfer the difference between the minimum deposit requirement and the current gas tank balance.
56-
function topUpGasTank(uint256 gasTankBalance) external;
46+
/// @notice RPC requested top-up of the gas tank.
47+
/// @dev Always transfers the minimum deposit requirement.
48+
function topUpGasTank() external;
5749

58-
/// @notice Allows anyone to contribute funds. Forwards them to the provider immediately.
50+
/// @notice Allows anyone to fund the gas tank.
5951
function fundGasTank() external payable;
6052

61-
/// @notice Sets the initial minimum deposit requirement. Forwards them to the provider immediately.
62-
/// @dev Reverts if the amount sent is less than the baseline deposit.
63-
function sendMinimumDeposit() external payable;
53+
/// @notice Initializes the gas tank with the minimum deposit.
54+
/// @dev Only the EOA can call this function.
55+
function initializeGasTank() external;
6456
}

0 commit comments

Comments
 (0)