ArenaLevel 07Hard
Fee Proxy
An upgradeable fee router. The proxy holds the money and the admin role. The logic was initialized when it went live.
GOAL
Become admin of your PaymentProxy and leave it with a zero balance.
- Points
- 300
- First blood
- 450
- 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 7: Fee Proxy7/// @notice An upgradeable fee router. The proxy keeps the money and the admin role;8/// the logic contract computes fees. The logic was initialized when it was deployed.9contract PaymentProxy {10 address public implementation;11 address public admin;1213 event Upgraded(address implementation);14 event Swept(address to, uint256 amount);1516 constructor(address implementation_, address admin_) payable {17 implementation = implementation_;18 admin = admin_;19 }2021 function upgrade(address implementation_) external {22 require(msg.sender == admin, "PaymentProxy: not admin");23 implementation = implementation_;24 emit Upgraded(implementation_);25 }2627 function sweep(address to) external {28 require(msg.sender == admin, "PaymentProxy: not admin");29 uint256 amount = address(this).balance;30 (bool ok,) = to.call{value: amount}("");31 require(ok, "PaymentProxy: transfer failed");32 emit Swept(to, amount);33 }3435 receive() external payable {}3637 fallback() external payable {38 address impl = implementation;39 assembly {40 calldatacopy(0, 0, calldatasize())41 let ok := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)42 returndatacopy(0, 0, returndatasize())43 switch ok44 case 0 { revert(0, returndatasize()) }45 default { return(0, returndatasize()) }46 }47 }48}4950contract FeeRouterLogic {51 address public owner;52 uint256 public feeBps;53 bool public initialized;5455 event Initialized(address owner, uint256 feeBps);5657 function initialize(address owner_, uint256 feeBps_) external {58 require(!initialized, "FeeRouter: already initialized");59 owner = owner_;60 feeBps = feeBps_;61 initialized = true;62 emit Initialized(owner_, feeBps_);63 }6465 function setFee(uint256 feeBps_) external {66 require(msg.sender == owner, "FeeRouter: not owner");67 require(feeBps_ <= 1000, "FeeRouter: fee too high");68 feeBps = feeBps_;69 }7071 function quote(uint256 amount) external view returns (uint256 fee, uint256 net) {72 fee = amount * feeBps / 10_000;73 net = amount - fee;74 }75}7677contract FeeProxyLevel is LevelBase {78 FeeRouterLogic public immutable logic;7980 constructor(address arena_) LevelBase(arena_) {81 logic = new FeeRouterLogic();82 logic.initialize(address(this), 30);83 }8485 function createInstance(address) external payable onlyArena returns (address) {86 if (msg.value == 0) revert DepositTooSmall();87 return address(new PaymentProxy{value: msg.value}(address(logic), address(this)));88 }8990 function validateInstance(address instance, address player) external view returns (bool) {91 // Only the proxy's own getters are read here, never anything routed through the fallback.92 PaymentProxy proxy = PaymentProxy(payable(instance));93 return proxy.admin() == player && instance.balance == 0;94 }95}