// SPDX-License-Identifier: MIT pragma solidity 0.8.28; /// @title BundelZap /// @notice One signature buys a basket of Robinhood Chain stock tokens. ETH in, wrapped once, then one /// Uniswap V3 `exactInput` per leg on the canonical SwapRouter02. Every swap pays the buyer directly: /// this contract never holds a stock token. One failing leg reverts the whole basket. /// @dev No owner, no admin, no upgrade, no fee. The stock allowlist and the bridge asset are fixed at /// construction; nothing can be added or removed afterwards. interface IWETH9 { function deposit() external payable; function withdraw(uint256) external; function approve(address, uint256) external returns (bool); function balanceOf(address) external view returns (uint256); } interface ISwapRouter02 { struct ExactInputParams { bytes path; address recipient; uint256 amountIn; uint256 amountOutMinimum; } function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); } contract BundelZap { struct Leg { address token; // canonical stock token the leg must end in bytes path; // WETH -fee-> token, or WETH -fee-> BRIDGE -fee-> token uint256 amountIn; // WETH spent on this leg (wei) uint256 minOut; // slippage floor in token units } ISwapRouter02 public immutable router; IWETH9 public immutable weth; address public immutable bridge; // the only allowed middle hop (USDG) uint256 public constant MAX_LEGS = 8; uint256 public fills; // receipts counter: fill #1, #2, ... mapping(address => bool) public isStock; address[] private _stocks; bool private _locked; event BasketFilled(uint256 indexed fillId, address indexed buyer, address indexed recipient, bytes32 basketTag, uint256 ethIn, uint256 legCount); event LegFilled(uint256 indexed fillId, address indexed token, uint256 amountIn, uint256 amountOut, bytes path); error Expired(); error NoLegs(); error TooManyLegs(); error ValueMismatch(); error NotAStock(address token); error BadPath(uint256 leg); error DuplicateLeg(address token); error Reentrancy(); constructor(address router_, address weth_, address bridge_, address[] memory stocks_) { router = ISwapRouter02(router_); weth = IWETH9(weth_); bridge = bridge_; for (uint256 i = 0; i < stocks_.length; i++) { if (!isStock[stocks_[i]]) { isStock[stocks_[i]] = true; _stocks.push(stocks_[i]); } } } function stocks() external view returns (address[] memory) { return _stocks; } /// @notice Buy every leg in one transaction. `msg.value` must equal the sum of the legs. /// @param recipient wallet that receives every token (zero = the caller) /// @param basketTag free 32-byte label the site uses to name the basket on its receipt function buy(Leg[] calldata legs, address recipient, uint256 deadline, bytes32 basketTag) external payable returns (uint256 fillId, uint256[] memory amountsOut) { if (_locked) revert Reentrancy(); _locked = true; if (block.timestamp > deadline) revert Expired(); uint256 n = legs.length; if (n == 0) revert NoLegs(); if (n > MAX_LEGS) revert TooManyLegs(); if (recipient == address(0)) recipient = msg.sender; uint256 total; for (uint256 i = 0; i < n; i++) { Leg calldata leg = legs[i]; if (!isStock[leg.token]) revert NotAStock(leg.token); for (uint256 j = 0; j < i; j++) if (legs[j].token == leg.token) revert DuplicateLeg(leg.token); _checkPath(leg.path, leg.token, i); total += leg.amountIn; } if (total != msg.value || total == 0) revert ValueMismatch(); weth.deposit{value: msg.value}(); weth.approve(address(router), msg.value); fillId = ++fills; amountsOut = new uint256[](n); for (uint256 i = 0; i < n; i++) { Leg calldata leg = legs[i]; amountsOut[i] = router.exactInput( ISwapRouter02.ExactInputParams({path: leg.path, recipient: recipient, amountIn: leg.amountIn, amountOutMinimum: leg.minOut}) ); emit LegFilled(fillId, leg.token, leg.amountIn, amountsOut[i], leg.path); } emit BasketFilled(fillId, msg.sender, recipient, basketTag, msg.value, n); // exactInput spends every wei of amountIn, so nothing is left; clear the approval for hygiene. weth.approve(address(router), 0); _locked = false; } /// @dev path = WETH(20) fee(3) [BRIDGE(20) fee(3)] token(20) function _checkPath(bytes calldata path, address token, uint256 i) private view { uint256 len = path.length; if (len != 43 && len != 66) revert BadPath(i); if (address(bytes20(path[0:20])) != address(weth)) revert BadPath(i); if (address(bytes20(path[len - 20:len])) != token) revert BadPath(i); if (len == 66 && address(bytes20(path[23:43])) != bridge) revert BadPath(i); } receive() external payable { revert(); } }