Skip to content

Commit 4dea020

Browse files
committed
feat: add refund
1 parent f221563 commit 4dea020

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

contracts/l2.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,25 @@ contract L2 is SignatureChecker {
190190

191191
batches[honestStartNonce].status = BatchStatus.Refunded;
192192
}
193+
194+
function refund(uint256 index) public {
195+
require(
196+
block.timestamp > tickets[index].timestamp + maxAuthDelay,
197+
"maxAuthDelay must have passed since deposit"
198+
);
199+
200+
require(
201+
nextNonceToAuthorize <= index,
202+
"The nonce must not be a part of a batch"
203+
);
204+
(Batch memory batch, ) = createBatch(nextNonceToAuthorize, index);
205+
batches[nextNonceToAuthorize] = batch;
206+
batch.status = BatchStatus.Refunded;
207+
nextNonceToAuthorize = index + 1;
208+
209+
(bool sent, ) = tickets[index].l1Recipient.call{
210+
value: tickets[index].value
211+
}("");
212+
require(sent, "Failed to send Ether");
213+
}
193214
}

test/safe.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,21 @@ it("Able to prove fraud", async () => {
192192
),
193193
);
194194
});
195+
196+
it("Able to get a ticket refunded", async () => {
197+
await deposit(0, 10);
198+
await expect(customerL2.refund(0, { gasLimit })).to.be.rejectedWith(
199+
"maxAuthDelay must have passed since deposit",
200+
);
201+
await ethers.provider.send("evm_increaseTime", [61]);
202+
await waitForTx(customerL2.refund(0, { gasLimit }));
203+
await waitForTx(customerL2.refund(1, { gasLimit }));
204+
await expect(customerL2.refund(1, { gasLimit })).to.be.rejectedWith(
205+
"The nonce must not be a part of a batch",
206+
);
207+
208+
await deposit(2, 8);
209+
await ethers.provider.send("evm_increaseTime", [61]);
210+
// Refund 3rd and 4th deposit
211+
await waitForTx(customerL2.refund(2, { gasLimit }));
212+
});

0 commit comments

Comments
 (0)