Skip to content

Commit fd27008

Browse files
committed
feat: add refund
1 parent e0fddce commit fd27008

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

contracts/l2.sol

+21
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,25 @@ contract L2 is SignatureChecker {
189189

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

test/safe.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,21 @@ it("Handles a fraud proofs", 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)