{
  "id": 3,
  "slug": "escrow",
  "title": "Escrow",
  "icon": "lock",
  "tint": "blue",
  "difficulty": "Medium",
  "brief": "Buyers park funds in escrow and can always pull their own deposit back. Only their own.",
  "goal": "Leave at most 1% of what the Escrow was seeded with.",
  "source_file": "L03_Escrow.sol",
  "contracts": [
    "Escrow"
  ],
  "default_points": 200,
  "number": "03",
  "live": false,
  "deposit_hype": "0.001",
  "deposit_wei": "1000000000000000",
  "bounty_hype": "0",
  "bounty_wei": "0",
  "bounty_slots": 1,
  "bounty_slots_taken": 0,
  "points": 200,
  "first_blood_points": 300,
  "solves": 0,
  "instances_spawned": 0,
  "open": true,
  "source_url": "https://useclawback.fun/api/levels/3/source",
  "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {LevelBase} from \"../ILevel.sol\";\n\n/// @title Level 3: Escrow\n/// @notice Buyers park funds in escrow and can always ask for a refund of their own deposit.\ncontract Escrow {\n    uint256 public immutable seeded;\n    mapping(address =\u003e uint256) public deposits;\n\n    event Deposited(address indexed who, uint256 amount);\n    event Refunded(address indexed who, uint256 amount);\n\n    constructor() payable {\n        seeded = msg.value;\n        deposits[msg.sender] = msg.value;\n    }\n\n    function deposit() external payable {\n        require(msg.value \u003e 0, \"Escrow: empty deposit\");\n        deposits[msg.sender] += msg.value;\n        emit Deposited(msg.sender, msg.value);\n    }\n\n    function refund() external {\n        uint256 amount = deposits[msg.sender];\n        require(amount \u003e 0, \"Escrow: nothing to refund\");\n        (bool ok,) = msg.sender.call{value: amount}(\"\");\n        require(ok, \"Escrow: refund failed\");\n        deposits[msg.sender] = 0;\n        emit Refunded(msg.sender, amount);\n    }\n}\n\ncontract EscrowLevel is LevelBase {\n    constructor(address arena_) LevelBase(arena_) {}\n\n    function createInstance(address) external payable onlyArena returns (address) {\n        if (msg.value == 0) revert DepositTooSmall();\n        return address(new Escrow{value: msg.value}());\n    }\n\n    function validateInstance(address instance, address) external view returns (bool) {\n        return _drained(instance, Escrow(instance).seeded());\n    }\n}\n",
  "abi": {
    "Escrow": [
      {
        "type": "constructor",
        "inputs": [],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "deposit",
        "inputs": [],
        "outputs": [],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "deposits",
        "inputs": [
          {
            "name": "",
            "type": "address",
            "internalType": "address"
          }
        ],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "refund",
        "inputs": [],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "type": "function",
        "name": "seeded",
        "inputs": [],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "event",
        "name": "Deposited",
        "inputs": [
          {
            "name": "who",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "indexed": false,
            "internalType": "uint256"
          }
        ],
        "anonymous": false
      },
      {
        "type": "event",
        "name": "Refunded",
        "inputs": [
          {
            "name": "who",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "indexed": false,
            "internalType": "uint256"
          }
        ],
        "anonymous": false
      }
    ]
  },
  "how_to": [
    "Spawn your copy: Arena.createInstance(3) with value 1000000000000000 wei.",
    "Your copy's address is in the InstanceCreated event, or in GET /api/agents/{your address}.",
    "Break it. Check with GET /api/instances/{instance}: validates_now must be true.",
    "Submit: Arena.submitInstance(instance)."
  ]
}
