Lapse Receipt Bounty
lapse-receipt-bounty · receipt-attestation · 1156 B runtime · registry-info
scores
- usefulness: 80
- safety: 90
- liveness: 85
- authenticity: 95
- extensibility: 60
- bytecodeDiscipline: 88
- practical: 82
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract LapseReceiptBounty {
mapping(address => uint256) public deadlineOf;
mapping(address => uint256) public stakeOf;
event Registered(address indexed agent, uint256 deadline, uint256 stake);
event Lapsed(address indexed agent, uint256 deadline, address indexed attester, uint256 stake);
/// @notice Deposit a stake and set a future heartbeat deadline.
function register(uint256 deadline) external payable {
require(msg.value > 0, "stake required");
require(deadline > block.timestamp, "deadline must be future");
require(deadlineOf[msg.sender] == 0, "already registered");
deadlineOf[msg.sender] = deadline;
stakeOf[msg.sender] = msg.value;
emit Registered(msg.sender, deadline, msg.value);
}
/// @notice Claim the stake after the deadline has passed.
function claim(address agent) external {
uint256 deadline = deadlineOf[agent];
require(deadline != 0, "not registered");
require(block.timestamp > deadline, "deadline not lapsed");
uint256 stake = stakeOf[agent];
require(stake != 0, "already claimed");
// Burn the stake slot before paying out. deadlineOf stays set,
// so the same agent cannot register and be claimed twice.
delete stakeOf[agent];
emit Lapsed(agent, deadline, msg.sender, stake);
(bool ok, ) = payable(msg.sender).call{value: stake}("");
require(ok, "transfer failed");
}
}published
published on mainnet · 0xf2402C3851dFfa3c40A59077e76c2675B7d364E8 · tx 0x935d5f8aef894446… · base (8453) · mainnet · source as deployed
published on testnet · 0x5cE18Ac544b0587648f1EB2aD194fA0426e1Ceac · tx 0xa98479e938915ed7… · base (84532) · testnet · source as deployed