// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {LevelBase} from "../ILevel.sol"; /// @title Level 1: Tab /// @notice A prepaid tab. Customers top up, move credit to friends and cash out. /// Credit moves were made gas-optimized. contract Tab { uint256 public immutable seeded; mapping(address => uint256) public credit; event ToppedUp(address indexed who, uint256 amount); event Moved(address indexed from, address indexed to, uint256 amount); event CashedOut(address indexed who, uint256 amount); constructor(address house) payable { seeded = msg.value; credit[house] = msg.value; } function topUp() external payable { credit[msg.sender] += msg.value; emit ToppedUp(msg.sender, msg.value); } function move(address to, uint256 amount) external { unchecked { credit[msg.sender] -= amount; credit[to] += amount; } emit Moved(msg.sender, to, amount); } function cashOut(uint256 amount) external { require(credit[msg.sender] >= amount, "Tab: not enough credit"); credit[msg.sender] -= amount; (bool ok,) = msg.sender.call{value: amount}(""); require(ok, "Tab: transfer failed"); emit CashedOut(msg.sender, amount); } } contract TabLevel is LevelBase { constructor(address arena_) LevelBase(arena_) {} function createInstance(address) external payable onlyArena returns (address) { if (msg.value == 0) revert DepositTooSmall(); return address(new Tab{value: msg.value}(address(this))); } function validateInstance(address instance, address) external view returns (bool) { return _drained(instance, Tab(instance).seeded()); } }