Skip to content

Commit 2141d3f

Browse files
ernestognwAmxx
andauthored
Rename ERC4337Utils ENTRYPOINT to ENTRYPOINT_V07 (#5472)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
1 parent 43b3319 commit 2141d3f

File tree

4 files changed

+15
-107
lines changed

4 files changed

+15
-107
lines changed

.changeset/chilly-guests-jam.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

contracts/account/utils/draft-ERC4337Utils.sol

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ library ERC4337Utils {
1717
using Packing for *;
1818

1919
/// @dev Address of the entrypoint v0.7.0
20-
IEntryPoint internal constant ENTRYPOINT = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032);
20+
IEntryPoint internal constant ENTRYPOINT_V07 = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032);
2121

2222
/// @dev For simulation purposes, validateUserOp (and validatePaymasterUserOp) return this value on success.
2323
uint256 internal constant SIG_VALIDATION_SUCCESS = 0;
@@ -163,29 +163,4 @@ library ERC4337Utils {
163163
function paymasterData(PackedUserOperation calldata self) internal pure returns (bytes calldata) {
164164
return self.paymasterAndData.length < 52 ? Calldata.emptyBytes() : self.paymasterAndData[52:];
165165
}
166-
167-
/// @dev Deposit ether into the entrypoint.
168-
function depositTo(address to, uint256 value) internal {
169-
ENTRYPOINT.depositTo{value: value}(to);
170-
}
171-
172-
/// @dev Withdraw ether from the entrypoint.
173-
function withdrawTo(address payable to, uint256 value) internal {
174-
ENTRYPOINT.withdrawTo(to, value);
175-
}
176-
177-
/// @dev Add stake to the entrypoint.
178-
function addStake(uint256 value, uint32 unstakeDelaySec) internal {
179-
ENTRYPOINT.addStake{value: value}(unstakeDelaySec);
180-
}
181-
182-
/// @dev Unlock stake on the entrypoint.
183-
function unlockStake() internal {
184-
ENTRYPOINT.unlockStake();
185-
}
186-
187-
/// @dev Withdraw unlocked stake from the entrypoint.
188-
function withdrawStake(address payable to) internal {
189-
ENTRYPOINT.withdrawStake(to);
190-
}
191166
}

test/account/utils/draft-ERC4337Utils.test.js

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

55
const { packValidationData, UserOperation } = require('../../helpers/erc4337');
66
const { MAX_UINT48 } = require('../../helpers/constants');
7-
const time = require('../../helpers/time');
87
const ADDRESS_ONE = '0x0000000000000000000000000000000000000001';
98

109
const fixture = async () => {
11-
const [authorizer, sender, factory, paymaster, other] = await ethers.getSigners();
10+
const [authorizer, sender, factory, paymaster] = await ethers.getSigners();
1211
const utils = await ethers.deployContract('$ERC4337Utils');
1312
const SIG_VALIDATION_SUCCESS = await utils.$SIG_VALIDATION_SUCCESS();
1413
const SIG_VALIDATION_FAILED = await utils.$SIG_VALIDATION_FAILED();
1514

16-
return { utils, authorizer, sender, factory, paymaster, other, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED };
15+
return { utils, authorizer, sender, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED };
1716
};
1817

1918
describe('ERC4337Utils', function () {
2019
beforeEach(async function () {
2120
Object.assign(this, await loadFixture(fixture));
2221
});
2322

23+
describe('entrypoint', function () {
24+
it('v0.7.0', async function () {
25+
await expect(this.utils.$ENTRYPOINT_V07()).to.eventually.equal(entrypoint);
26+
});
27+
});
28+
2429
describe('parseValidationData', function () {
2530
it('parses the validation data', async function () {
2631
const authorizer = this.authorizer;
@@ -285,68 +290,4 @@ describe('ERC4337Utils', function () {
285290
});
286291
});
287292
});
288-
289-
describe('stake management', function () {
290-
const unstakeDelaySec = 3600n;
291-
292-
beforeEach(async function () {
293-
await this.authorizer.sendTransaction({ to: this.utils, value: ethers.parseEther('1') });
294-
});
295-
296-
it('deposit & withdraw', async function () {
297-
await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(0n);
298-
299-
// deposit
300-
await expect(this.utils.$depositTo(this.utils, 42n)).to.changeEtherBalances(
301-
[this.utils, entrypoint],
302-
[-42n, 42n],
303-
);
304-
305-
await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(42n);
306-
307-
// withdraw
308-
await expect(this.utils.$withdrawTo(this.other, 17n)).to.changeEtherBalances(
309-
[entrypoint, this.other],
310-
[-17n, 17n],
311-
);
312-
313-
await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(25n); // 42 - 17
314-
});
315-
316-
it('stake, unlock & withdraw stake', async function () {
317-
await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]);
318-
319-
// stake
320-
await expect(this.utils.$addStake(42n, unstakeDelaySec)).to.changeEtherBalances(
321-
[this.utils, entrypoint],
322-
[-42n, 42n],
323-
);
324-
325-
await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, true, 42n, unstakeDelaySec, 0n]);
326-
327-
// unlock
328-
const unlockTx = this.utils.$unlockStake();
329-
await expect(unlockTx).to.changeEtherBalances([this.utils, entrypoint], [0n, 0n]); // no ether movement
330-
331-
const timestamp = await time.clockFromReceipt.timestamp(unlockTx);
332-
await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([
333-
0n,
334-
false,
335-
42n,
336-
unstakeDelaySec,
337-
timestamp + unstakeDelaySec,
338-
]);
339-
340-
// wait
341-
await time.increaseBy.timestamp(unstakeDelaySec);
342-
343-
// withdraw stake
344-
await expect(this.utils.$withdrawStake(this.other)).to.changeEtherBalances(
345-
[this.utils, entrypoint, this.other],
346-
[0n, -42n, 42n],
347-
);
348-
349-
await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]);
350-
});
351-
});
352293
});

test/account/utils/draft-ERC7579Utils.t.sol

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ contract SampleAccount is IAccount, Ownable {
2020
using ERC4337Utils for *;
2121
using ERC7579Utils for *;
2222

23-
IEntryPoint internal constant ENTRY_POINT = IEntryPoint(payable(0x0000000071727De22E5E9d8BAf0edAc6f37da032));
24-
2523
event Log(bool duringValidation, Execution[] calls);
2624

2725
error UnsupportedCallType(CallType callType);
@@ -33,7 +31,7 @@ contract SampleAccount is IAccount, Ownable {
3331
bytes32 userOpHash,
3432
uint256 missingAccountFunds
3533
) external override returns (uint256 validationData) {
36-
require(msg.sender == address(ENTRY_POINT), "only from EP");
34+
require(msg.sender == address(ERC4337Utils.ENTRYPOINT_V07), "only from EP");
3735
// Check signature
3836
if (userOpHash.toEthSignedMessageHash().recover(userOp.signature) != owner()) {
3937
revert OwnableUnauthorizedAccount(_msgSender());
@@ -81,7 +79,7 @@ contract SampleAccount is IAccount, Ownable {
8179
}
8280

8381
function execute(Mode mode, bytes calldata executionCalldata) external payable {
84-
require(msg.sender == address(this) || msg.sender == address(ENTRY_POINT), "not auth");
82+
require(msg.sender == address(this) || msg.sender == address(ERC4337Utils.ENTRYPOINT_V07), "not auth");
8583

8684
(CallType callType, ExecType execType, , ) = mode.decodeMode();
8785

@@ -105,7 +103,6 @@ contract ERC7579UtilsTest is Test {
105103
using ERC4337Utils for *;
106104
using ERC7579Utils for *;
107105

108-
IEntryPoint private constant ENTRYPOINT = IEntryPoint(payable(0x0000000071727De22E5E9d8BAf0edAc6f37da032));
109106
address private _owner;
110107
uint256 private _ownerKey;
111108
address private _account;
@@ -166,7 +163,7 @@ contract ERC7579UtilsTest is Test {
166163
userOps[0].signature = abi.encodePacked(r, s, v);
167164

168165
vm.recordLogs();
169-
ENTRYPOINT.handleOps(userOps, payable(_beneficiary));
166+
ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary));
170167

171168
assertEq(_recipient1.balance, 1 wei);
172169
assertEq(_recipient2.balance, 1 wei);
@@ -224,7 +221,7 @@ contract ERC7579UtilsTest is Test {
224221
abi.encodeWithSelector(ERC7579Utils.ERC7579DecodingError.selector)
225222
)
226223
);
227-
ENTRYPOINT.handleOps(userOps, payable(_beneficiary));
224+
ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary));
228225

229226
_collectAndPrintLogs(false);
230227
}
@@ -282,7 +279,7 @@ contract ERC7579UtilsTest is Test {
282279
abi.encodeWithSelector(ERC7579Utils.ERC7579DecodingError.selector)
283280
)
284281
);
285-
ENTRYPOINT.handleOps(userOps, payable(_beneficiary));
282+
ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary));
286283

287284
_collectAndPrintLogs(true);
288285
}
@@ -378,7 +375,7 @@ contract ERC7579UtilsTest is Test {
378375
}
379376

380377
function hashUserOperation(PackedUserOperation calldata useroperation) public view returns (bytes32) {
381-
return useroperation.hash(address(ENTRYPOINT), block.chainid);
378+
return useroperation.hash(address(ERC4337Utils.ENTRYPOINT_V07), block.chainid);
382379
}
383380

384381
function _collectAndPrintLogs(bool includeTotalValue) internal {

0 commit comments

Comments
 (0)