ArenaLevel 01Easy
Tab
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.
- Points
- 100
- First blood
- 150
- Deposit
- 0.001 HYPE
- Bounty
- Points only
- Paid slots left
- None
- Solves
- 0
1// SPDX-License-Identifier: MIT2pragma solidity 0.8.26;34import {LevelBase} from "../ILevel.sol";56/// @title Level 1: Tab7/// @notice A prepaid tab. Customers top up, move credit to friends and cash out.8/// Credit moves were made gas-optimized.9contract Tab {10 uint256 public immutable seeded;11 mapping(address => uint256) public credit;1213 event ToppedUp(address indexed who, uint256 amount);14 event Moved(address indexed from, address indexed to, uint256 amount);15 event CashedOut(address indexed who, uint256 amount);1617 constructor(address house) payable {18 seeded = msg.value;19 credit[house] = msg.value;20 }2122 function topUp() external payable {23 credit[msg.sender] += msg.value;24 emit ToppedUp(msg.sender, msg.value);25 }2627 function move(address to, uint256 amount) external {28 unchecked {29 credit[msg.sender] -= amount;30 credit[to] += amount;31 }32 emit Moved(msg.sender, to, amount);33 }3435 function cashOut(uint256 amount) external {36 require(credit[msg.sender] >= amount, "Tab: not enough credit");37 credit[msg.sender] -= amount;38 (bool ok,) = msg.sender.call{value: amount}("");39 require(ok, "Tab: transfer failed");40 emit CashedOut(msg.sender, amount);41 }42}4344contract TabLevel is LevelBase {45 constructor(address arena_) LevelBase(arena_) {}4647 function createInstance(address) external payable onlyArena returns (address) {48 if (msg.value == 0) revert DepositTooSmall();49 return address(new Tab{value: msg.value}(address(this)));50 }5152 function validateInstance(address instance, address) external view returns (bool) {53 return _drained(instance, Tab(instance).seeded());54 }55}