Skip to content

Commit bc0c040

Browse files
committed
Paymaster: handle deposit and stake based on entrypoint()
1 parent 3b1a9fa commit bc0c040

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

contracts/account/paymaster/PaymasterCore.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ abstract contract PaymasterCore is IPaymaster {
9393

9494
/// @dev Calls {IEntryPointStake-depositTo}.
9595
function deposit() public payable virtual {
96-
ERC4337Utils.depositTo(address(this), msg.value);
96+
entryPoint().depositTo{value: msg.value}(address(this));
9797
}
9898

9999
/// @dev Calls {IEntryPointStake-withdrawTo}.
100100
function withdraw(address payable to, uint256 value) public virtual onlyWithdrawer {
101-
ERC4337Utils.withdrawTo(to, value);
101+
entryPoint().withdrawTo(to, value);
102102
}
103103

104104
/// @dev Calls {IEntryPointStake-addStake}.
105105
function addStake(uint32 unstakeDelaySec) public payable virtual {
106-
ERC4337Utils.addStake(msg.value, unstakeDelaySec);
106+
entryPoint().addStake{value: msg.value}(unstakeDelaySec);
107107
}
108108

109109
/// @dev Calls {IEntryPointStake-unlockStake}.
110110
function unlockStake() public virtual onlyWithdrawer {
111-
ERC4337Utils.unlockStake();
111+
entryPoint().unlockStake();
112112
}
113113

114114
/// @dev Calls {IEntryPointStake-withdrawStake}.
115115
function withdrawStake(address payable to) public virtual onlyWithdrawer {
116-
ERC4337Utils.withdrawStake(to);
116+
entryPoint().withdrawStake(to);
117117
}
118118

119119
/// @dev Ensures the caller is the {entrypoint}.

test/account/paymaster/Paymaster.behavior.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,29 @@ function shouldBehaveLikePaymaster({ postOp } = { postOp: false }) {
135135

136136
describe('postOp', function () {
137137
it('reverts if the caller is not the entrypoint', async function () {
138-
await expect(this.paymaster.connect(this.other).postOp(0, '0x', 0, 0))
138+
await expect(this.paymaster.connect(this.other).postOp(0n, '0x', 0n, 0n))
139139
.to.be.revertedWithCustomError(this.paymaster, 'PaymasterUnauthorized')
140140
.withArgs(this.other);
141141
});
142142
});
143143

144144
describe('deposit lifecycle', function () {
145145
it('deposits and withdraws effectively', async function () {
146+
await expect(entrypoint.balanceOf(this.paymaster)).to.eventually.equal(0n);
147+
146148
await expect(this.paymaster.connect(this.other).deposit({ value })).to.changeEtherBalances(
147149
[this.other, entrypoint],
148150
[-value, value],
149151
);
150152

151-
await expect(this.paymaster.connect(this.admin).withdraw(this.receiver, value)).to.changeEtherBalances(
153+
await expect(entrypoint.balanceOf(this.paymaster)).to.eventually.equal(value);
154+
155+
await expect(this.paymaster.connect(this.admin).withdraw(this.receiver, 1n)).to.changeEtherBalances(
152156
[entrypoint, this.receiver],
153-
[-value, value],
157+
[-1n, 1n],
154158
);
159+
160+
await expect(entrypoint.balanceOf(this.paymaster)).to.eventually.equal(value - 1n);
155161
});
156162

157163
it('reverts when an unauthorized caller tries to withdraw', async function () {
@@ -163,20 +169,37 @@ function shouldBehaveLikePaymaster({ postOp } = { postOp: false }) {
163169

164170
describe('stake lifecycle', function () {
165171
it('adds and removes stake effectively', async function () {
172+
await expect(entrypoint.deposits(this.paymaster)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]);
173+
166174
// stake
167175
await expect(this.paymaster.connect(this.other).addStake(delay, { value })).to.changeEtherBalances(
168176
[this.other, entrypoint],
169177
[-value, value],
170178
);
179+
180+
await expect(entrypoint.deposits(this.paymaster)).to.eventually.deep.equal([0n, true, 42n, delay, 0n]);
181+
171182
// unlock
172-
await this.paymaster.connect(this.admin).unlockStake();
183+
const unlockTx = this.paymaster.connect(this.admin).unlockStake();
184+
185+
const timestamp = await time.clockFromReceipt.timestamp(unlockTx);
186+
await expect(entrypoint.deposits(this.paymaster)).to.eventually.deep.equal([
187+
0n,
188+
false,
189+
42n,
190+
delay,
191+
timestamp + delay,
192+
]);
193+
173194
await time.increaseBy.timestamp(delay);
174195

175196
// withdraw stake
176197
await expect(this.paymaster.connect(this.admin).withdrawStake(this.receiver)).to.changeEtherBalances(
177198
[entrypoint, this.receiver],
178199
[-value, value],
179200
);
201+
202+
await expect(entrypoint.deposits(this.paymaster)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]);
180203
});
181204

182205
it('reverts when an unauthorized caller tries to unlock stake', async function () {

0 commit comments

Comments
 (0)