ArenaLevel 05Medium
Batch Pay
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.
- Points
- 250
- First blood
- 375
- 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 5: Batch Pay7/// @notice A payment wallet with internal balances. Power users batch several actions in one transaction.8contract BatchPay {9 uint256 public immutable seeded;10 mapping(address => uint256) public balanceOf;1112 event Deposited(address indexed who, uint256 amount);13 event Paid(address indexed from, address indexed to, uint256 amount);14 event Withdrawn(address indexed who, uint256 amount);1516 constructor() payable {17 seeded = msg.value;18 balanceOf[msg.sender] = msg.value;19 }2021 function deposit() public payable {22 balanceOf[msg.sender] += msg.value;23 emit Deposited(msg.sender, msg.value);24 }2526 function pay(address to, uint256 amount) public {27 require(balanceOf[msg.sender] >= amount, "BatchPay: not enough balance");28 balanceOf[msg.sender] -= amount;29 balanceOf[to] += amount;30 emit Paid(msg.sender, to, amount);31 }3233 function withdraw(uint256 amount) public {34 require(balanceOf[msg.sender] >= amount, "BatchPay: not enough balance");35 balanceOf[msg.sender] -= amount;36 (bool ok,) = msg.sender.call{value: amount}("");37 require(ok, "BatchPay: transfer failed");38 emit Withdrawn(msg.sender, amount);39 }4041 /// @notice Run several of this contract's own functions in one transaction.42 function batch(bytes[] calldata calls) external payable returns (bytes[] memory results) {43 results = new bytes[](calls.length);44 for (uint256 i; i < calls.length; ++i) {45 (bool ok, bytes memory res) = address(this).delegatecall(calls[i]);46 require(ok, "BatchPay: call failed");47 results[i] = res;48 }49 }50}5152contract BatchPayLevel is LevelBase {53 constructor(address arena_) LevelBase(arena_) {}5455 function createInstance(address) external payable onlyArena returns (address) {56 if (msg.value == 0) revert DepositTooSmall();57 return address(new BatchPay{value: msg.value}());58 }5960 function validateInstance(address instance, address) external view returns (bool) {61 return _drained(instance, BatchPay(instance).seeded());62 }63}