{
  "id": 5,
  "slug": "batch-pay",
  "title": "Batch Pay",
  "icon": "layers",
  "tint": "purple",
  "difficulty": "Medium",
  "brief": "A payment wallet with internal balances and a batch function for power users who hate paying gas twice.",
  "goal": "Leave at most 1% of what BatchPay was seeded with.",
  "source_file": "L05_BatchPay.sol",
  "contracts": [
    "BatchPay"
  ],
  "default_points": 250,
  "number": "05",
  "live": false,
  "deposit_hype": "0.001",
  "deposit_wei": "1000000000000000",
  "bounty_hype": "0",
  "bounty_wei": "0",
  "bounty_slots": 1,
  "bounty_slots_taken": 0,
  "points": 250,
  "first_blood_points": 375,
  "solves": 0,
  "instances_spawned": 0,
  "open": true,
  "source_url": "https://useclawback.fun/api/levels/5/source",
  "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {LevelBase} from \"../ILevel.sol\";\n\n/// @title Level 5: Batch Pay\n/// @notice A payment wallet with internal balances. Power users batch several actions in one transaction.\ncontract BatchPay {\n    uint256 public immutable seeded;\n    mapping(address =\u003e uint256) public balanceOf;\n\n    event Deposited(address indexed who, uint256 amount);\n    event Paid(address indexed from, address indexed to, uint256 amount);\n    event Withdrawn(address indexed who, uint256 amount);\n\n    constructor() payable {\n        seeded = msg.value;\n        balanceOf[msg.sender] = msg.value;\n    }\n\n    function deposit() public payable {\n        balanceOf[msg.sender] += msg.value;\n        emit Deposited(msg.sender, msg.value);\n    }\n\n    function pay(address to, uint256 amount) public {\n        require(balanceOf[msg.sender] \u003e= amount, \"BatchPay: not enough balance\");\n        balanceOf[msg.sender] -= amount;\n        balanceOf[to] += amount;\n        emit Paid(msg.sender, to, amount);\n    }\n\n    function withdraw(uint256 amount) public {\n        require(balanceOf[msg.sender] \u003e= amount, \"BatchPay: not enough balance\");\n        balanceOf[msg.sender] -= amount;\n        (bool ok,) = msg.sender.call{value: amount}(\"\");\n        require(ok, \"BatchPay: transfer failed\");\n        emit Withdrawn(msg.sender, amount);\n    }\n\n    /// @notice Run several of this contract's own functions in one transaction.\n    function batch(bytes[] calldata calls) external payable returns (bytes[] memory results) {\n        results = new bytes[](calls.length);\n        for (uint256 i; i \u003c calls.length; ++i) {\n            (bool ok, bytes memory res) = address(this).delegatecall(calls[i]);\n            require(ok, \"BatchPay: call failed\");\n            results[i] = res;\n        }\n    }\n}\n\ncontract BatchPayLevel 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 BatchPay{value: msg.value}());\n    }\n\n    function validateInstance(address instance, address) external view returns (bool) {\n        return _drained(instance, BatchPay(instance).seeded());\n    }\n}\n",
  "abi": {
    "BatchPay": [
      {
        "type": "constructor",
        "inputs": [],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "balanceOf",
        "inputs": [
          {
            "name": "",
            "type": "address",
            "internalType": "address"
          }
        ],
        "outputs": [
          {
            "name": "",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "stateMutability": "view"
      },
      {
        "type": "function",
        "name": "batch",
        "inputs": [
          {
            "name": "calls",
            "type": "bytes[]",
            "internalType": "bytes[]"
          }
        ],
        "outputs": [
          {
            "name": "results",
            "type": "bytes[]",
            "internalType": "bytes[]"
          }
        ],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "deposit",
        "inputs": [],
        "outputs": [],
        "stateMutability": "payable"
      },
      {
        "type": "function",
        "name": "pay",
        "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": "withdraw",
        "inputs": [
          {
            "name": "amount",
            "type": "uint256",
            "internalType": "uint256"
          }
        ],
        "outputs": [],
        "stateMutability": "nonpayable"
      },
      {
        "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": "Paid",
        "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": "Withdrawn",
        "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(5) 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)."
  ]
}
