Skip to content

Commit 10ae9ba

Browse files
committed
refactor: change immutable MINIMUM_DEPOSIT to MAXIMUM_DEPOSIT
1 parent d0022a1 commit 10ae9ba

3 files changed

Lines changed: 26 additions & 25 deletions

File tree

contracts/contracts/core/GasTankDepositor.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Errors} from "../utils/Errors.sol";
88
/// @dev This contract implicitly trusts the RPC_SERVICE address.
99
contract GasTankDepositor {
1010
address public immutable RPC_SERVICE;
11-
uint256 public immutable MINIMUM_DEPOSIT;
11+
uint256 public immutable MAXIMUM_DEPOSIT;
1212

1313
event FundsRecovered(address indexed owner, uint256 indexed amount);
1414
event GasTankFunded(address indexed smartAccount, address indexed caller, uint256 indexed amount);
@@ -21,7 +21,7 @@ contract GasTankDepositor {
2121
error NotRPCService(address caller);
2222
error InsufficientFunds(uint256 currentBalance, uint256 requiredBalance);
2323
error NotThisEOA(address msgSender, address thisAddress);
24-
error MinimumDepositNotMet(uint256 amountToTransfer, uint256 minimumDeposit);
24+
error MaximumDepositNotMet(uint256 amountToTransfer, uint256 maximumDeposit);
2525

2626
modifier onlyThisEOA() {
2727
require(msg.sender == address(this), NotThisEOA(msg.sender, address(this)));
@@ -33,11 +33,13 @@ contract GasTankDepositor {
3333
_;
3434
}
3535

36-
constructor(address rpcService, uint256 _minDeposit) {
36+
/// @dev Writes the variables into the contract bytecode.
37+
/// @dev No storage is used in this contract.
38+
constructor(address rpcService, uint256 _maxDeposit) {
3739
require(rpcService != address(0), RPCServiceNotSet(rpcService));
38-
require(_minDeposit > 0, MinimumDepositNotMet(0, _minDeposit));
40+
require(_maxDeposit > 0, MaximumDepositNotMet(0, _maxDeposit));
3941
RPC_SERVICE = rpcService;
40-
MINIMUM_DEPOSIT = _minDeposit;
42+
MAXIMUM_DEPOSIT = _maxDeposit;
4143
}
4244

4345
receive() external payable { /* ETH transfers allowed. */ }
@@ -60,14 +62,13 @@ contract GasTankDepositor {
6062
/// @param _amount The amount to fund the gas tank with.
6163
/// @dev Only the EOA can call this function.
6264
function fundGasTank(uint256 _amount) external onlyThisEOA {
63-
require(_amount >= MINIMUM_DEPOSIT, MinimumDepositNotMet(_amount, MINIMUM_DEPOSIT));
6465
_fundGasTank(_amount);
6566
}
6667

67-
/// @notice Transfers the minimum deposit amount of ETH from the EOA's balance to the Gas RPC Service.
68+
/// @notice Transfers the maximum deposit amount of ETH from the EOA's balance to the Gas RPC Service.
6869
/// @dev Only the RPC Service can call this function.
6970
function fundGasTank() external onlyRPCService {
70-
_fundGasTank(MINIMUM_DEPOSIT);
71+
_fundGasTank(MAXIMUM_DEPOSIT);
7172
}
7273

7374
/// @dev `fundGasTank` Internal function to fund the gas tank.

contracts/doc/GasTankDepositor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ The contract facilitates a custodial gas tank system where:
3030

3131
2. **Initial Funding**:
3232
- User calls `fundGasTank(uint256 _amount)` with their desired initial deposit
33-
- Amount must be >= `MINIMUM_DEPOSIT`
33+
- Amount must be >= `MAXIMUM_DEPOSIT`
3434
- ETH is transferred from user's EOA to the RPC service EOA
3535
- RPC service updates off-chain ledger to reflect the deposit
3636

3737
3. **Automatic Top-Ups**:
3838
- When a user's off-chain ledger balance drops below threshold, RPC service calls `fundGasTank()`
39-
- This always transfers exactly `MINIMUM_DEPOSIT` amount
39+
- This always transfers exactly `MAXIMUM_DEPOSIT` amount
4040
- Transfer occurs directly from user's EOA balance (if sufficient funds available)
4141
- No user interaction required - fully automated
4242
- No need for `maxTransferAllowance` as RPC is restricted to minimum amount only

contracts/test/core/GasTankDepositorTest.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract GasTankDepositorTest is Test {
88
uint256 public constant ALICE_PK = uint256(0xA11CE);
99
uint256 public constant BOB_PK = uint256(0xB0B);
1010
uint256 public constant RPC_SERVICE_PK = uint256(0x1234567890);
11-
uint256 public constant MINIMUM_DEPOSIT = 0.01 ether;
11+
uint256 public constant MAXIMUM_DEPOSIT = 0.01 ether;
1212
address public constant ZERO_ADDRESS = address(0);
1313
bytes32 public constant EMPTY_CODEHASH = keccak256("");
1414

@@ -22,7 +22,7 @@ contract GasTankDepositorTest is Test {
2222
vm.deal(alice, 10 ether);
2323
vm.deal(bob, 10 ether);
2424
vm.deal(rpcService, 10 ether);
25-
_gasTankDepositorImpl = new GasTankDepositor(rpcService, MINIMUM_DEPOSIT);
25+
_gasTankDepositorImpl = new GasTankDepositor(rpcService, MAXIMUM_DEPOSIT);
2626
}
2727

2828
//=======================TESTS=======================
@@ -108,16 +108,16 @@ contract GasTankDepositorTest is Test {
108108

109109
//=======================TESTS FOR FUNDING THE GAS TANK=======================
110110

111-
function testRpcServiceFundsMinimumDeposit() public {
111+
function testRpcServiceFundsMaximumDeposit() public {
112112
_delegate();
113113

114114
uint256 rpcBalanceBefore = rpcService.balance;
115-
_expectGasTankFunded(rpcService, MINIMUM_DEPOSIT);
115+
_expectGasTankFunded(rpcService, MAXIMUM_DEPOSIT);
116116

117117
vm.prank(rpcService);
118118
GasTankDepositor(payable(alice)).fundGasTank();
119119

120-
assertEq(rpcService.balance, rpcBalanceBefore + MINIMUM_DEPOSIT, "rpc balance not increased");
120+
assertEq(rpcService.balance, rpcBalanceBefore + MAXIMUM_DEPOSIT, "rpc balance not increased");
121121
}
122122

123123
function testRpcServiceFundRevertsWhenCallerNotRpcService() public {
@@ -129,12 +129,12 @@ contract GasTankDepositorTest is Test {
129129
}
130130

131131
function testRpcServiceFundRevertsWhenInsufficientBalance() public {
132-
vm.deal(alice, MINIMUM_DEPOSIT - 1);
132+
vm.deal(alice, MAXIMUM_DEPOSIT - 1);
133133
_delegate();
134134

135135
vm.prank(rpcService);
136136
vm.expectRevert(
137-
abi.encodeWithSelector(GasTankDepositor.InsufficientFunds.selector, MINIMUM_DEPOSIT - 1, MINIMUM_DEPOSIT)
137+
abi.encodeWithSelector(GasTankDepositor.InsufficientFunds.selector, MAXIMUM_DEPOSIT - 1, MAXIMUM_DEPOSIT)
138138
);
139139
GasTankDepositor(payable(alice)).fundGasTank();
140140
}
@@ -152,34 +152,34 @@ contract GasTankDepositorTest is Test {
152152
assertEq(rpcService.balance, rpcBalanceBefore + amount, "rpc balance not increased");
153153
}
154154

155-
function testEOAFundRevertsBelowMinimumDeposit() public {
155+
function testEOAFundRevertsBelowMaximumDeposit() public {
156156
_delegate();
157-
uint256 belowMinimumDeposit = MINIMUM_DEPOSIT - 1 wei;
157+
uint256 belowMaximumDeposit = MAXIMUM_DEPOSIT - 1 wei;
158158

159159
vm.prank(alice);
160160
vm.expectRevert(
161-
abi.encodeWithSelector(GasTankDepositor.MinimumDepositNotMet.selector, belowMinimumDeposit, MINIMUM_DEPOSIT)
161+
abi.encodeWithSelector(GasTankDepositor.MaximumDepositNotMet.selector, belowMaximumDeposit, MAXIMUM_DEPOSIT)
162162
);
163-
GasTankDepositor(payable(alice)).fundGasTank(belowMinimumDeposit);
163+
GasTankDepositor(payable(alice)).fundGasTank(belowMaximumDeposit);
164164
}
165165

166166
function testEOAFundRevertsWhenCallerNotEOA() public {
167167
_delegate();
168168

169169
vm.prank(rpcService);
170170
vm.expectRevert(abi.encodeWithSelector(GasTankDepositor.NotThisEOA.selector, rpcService, alice));
171-
GasTankDepositor(payable(alice)).fundGasTank(MINIMUM_DEPOSIT);
171+
GasTankDepositor(payable(alice)).fundGasTank(MAXIMUM_DEPOSIT);
172172
}
173173

174174
function testEOAFundRevertsWhenInsufficientBalance() public {
175-
vm.deal(alice, MINIMUM_DEPOSIT - 1);
175+
vm.deal(alice, MAXIMUM_DEPOSIT - 1);
176176
_delegate();
177177

178178
vm.prank(alice);
179179
vm.expectRevert(
180-
abi.encodeWithSelector(GasTankDepositor.InsufficientFunds.selector, MINIMUM_DEPOSIT - 1, MINIMUM_DEPOSIT)
180+
abi.encodeWithSelector(GasTankDepositor.InsufficientFunds.selector, MAXIMUM_DEPOSIT - 1, MAXIMUM_DEPOSIT)
181181
);
182-
GasTankDepositor(payable(alice)).fundGasTank(MINIMUM_DEPOSIT);
182+
GasTankDepositor(payable(alice)).fundGasTank(MAXIMUM_DEPOSIT);
183183
}
184184

185185
//=======================HELPERS=======================

0 commit comments

Comments
 (0)