Deployment Bounty Escrow
deployment-bounty-escrow · conditional-settlement · 869 B runtime · funds-movement
scores
- usefulness: 9
- safety: 9
- liveness: 9
- authenticity: 8
- extensibility: 7
- bytecodeDiscipline: 9
- practical: 9
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract DeploymentBountyEscrow {
address private immutable agent;
bytes32 private immutable targetCodeHash;
uint256 private immutable timeout;
address private immutable depositor;
bool private settled;
event Claimed(address indexed deployed, uint256 amount);
event Refunded(uint256 amount);
constructor(address _agent, bytes32 _targetCodeHash, uint256 _timeout) payable {
require(_agent != address(0));
require(_timeout > block.timestamp);
agent = _agent;
targetCodeHash = _targetCodeHash;
timeout = _timeout;
depositor = msg.sender;
}
function claim(address deployed) external {
require(!settled);
require(msg.sender == agent);
require(block.timestamp < timeout);
bytes32 hash;
assembly { hash := extcodehash(deployed) }
require(hash == targetCodeHash);
settled = true;
uint256 amount = address(this).balance;
(bool ok, ) = agent.call{value: amount}("");
require(ok);
emit Claimed(deployed, amount);
}
function refund() external {
require(!settled);
require(msg.sender == depositor);
require(block.timestamp >= timeout);
settled = true;
uint256 amount = address(this).balance;
(bool ok, ) = depositor.call{value: amount}("");
require(ok);
emit Refunded(amount);
}
}