{
  "id": 1,
  "slug": "tab",
  "title": "Tab",
  "icon": "receipt",
  "tint": "green",
  "difficulty": "Easy",
  "brief": "A prepaid tab. Customers top up, move credit to friends and cash out. Credit moves were recently made gas-optimized.",
  "goal": "Leave at most 1% of what the Tab was seeded with.",
  "source_file": "L01_Tab.sol",
  "contracts": [
    "Tab"
  ],
  "default_points": 100,
  "number": "01",
  "live": false,
  "deposit_hype": "0.001",
  "deposit_wei": "1000000000000000",
  "bounty_hype": "0",
  "bounty_wei": "0",
  "bounty_slots": 1,
  "bounty_slots_taken": 0,
  "points": 100,
  "first_blood_points": 150,
  "solves": 0,
  "instances_spawned": 0,
  "open": true,
  "source_url": "https://useclawback.fun/api/levels/1/source",
  "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {LevelBase} from \"../ILevel.sol\";\n\n/// @title Level 1: Tab\n/// @notice A prepaid tab. Customers top up, move credit to friends and cash out.\n///         Credit moves were made gas-optimized.\ncontract Tab {\n    uint256 public immutable seeded;\n    mapping(address =\u003e uint256) public credit;\n\n    event ToppedUp(address indexed who, uint256 amount);\n    event Moved(address indexed from, address indexed to, uint256 amount);\n    event CashedOut(address indexed who, uint256 amount);\n\n    constructor(address house) payable {\n        seeded = msg.value;\n        credit[house] = msg.value;\n    }\n\n    function topUp() external payable {\n        credit[msg.sender] += msg.value;\n        emit ToppedUp(msg.sender, msg.value);\n    }\n\n    function move(address to, uint256 amount) external {\n        unchecked {\n            credit[msg.sender] -= amount;\n            credit[to] += amount;\n        }\n        emit Moved(msg.sender, to, amount);\n    }\n\n    function cashOut(uint256 amount) external {\n        require(credit[msg.sender] \u003e= amount, \"Tab: not enough credit\");\n        credit[msg.sender] -= amount;\n        (bool ok,) = msg.sender.call{value: amount}(\"\");\n        require(ok, \"Tab: transfer failed\");\n        emit CashedOut(msg.sender, amount);\n    }\n}\n\ncontract TabLevel 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 Tab{value: msg.value}(address(this)));\n    }\n\n    function validateInstance(address instance, address) external view returns (bool) {\n        return _drained(instance, Tab(instance).seeded());\n    }\n}\n",
  "abi": {
    "Tab": [
      {
        "type": "constructor",
        "inputs": [
          {
            "name": "house",
            "type": "address",
            "internalType": "address"
          }
        ],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "cashOut",
        "inputs": [
          {
            "name": "amount",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "type": "function",
        "name": "credit",
        "inputs": [
          {
            "name": "",
            "type": "address",
            "internalType": "address"
          }
        ],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "move",
        "inputs": [
          {
            "name": "to",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "type": "function",
        "name": "seeded",
        "inputs": [],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "topUp",
        "inputs": [],
        "outputs": [],
        "stateMutability": "payable"
      },
      {
        "type": "event",
        "name": "CashedOut",
        "inputs": [
          {
            "name": "who",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "indexed": false,
            "internalType": "uint256"
          }
        ],
        "anonymous": false
      },
      {
        "type": "event",
        "name": "Moved",
        "inputs": [
          {
            "name": "from",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "to",
            "type": "address",
            "indexed": true,
            "internalType": "address"
          },
          {
            "name": "amount",
            "type": "uint256",
            "indexed": false,
            "internalType": "uint256"
          }
        ],
        "anonymous": false
      },
      {
        "type": "event",
        "name": "ToppedUp",
        "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(1) 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)."
  ]
}
