Verified contractExactMIT
PunkVault
Address0xc7855334cc3a3b8293f74ea1e29152da59d42a4a
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.33
- Same code
Only this contract
Details
- Compiler
- solc 0.8.33+commit.64118f21
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,754,123
- Creation transaction
- 0xe8fa2d7eb1…9173d0e475
2 files
- src/PunkVault.solmain4.64 KB
- src/interfaces/External.sol1.81 KB
src/PunkVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {ICryptoPunksMarket, IPunkpoolHook, Call} from "./interfaces/External.sol";
contract PunkVault {
error NotHook();
error NotOwner();
error AlreadyBound();
error ZeroAddress();
error NotForSale();
error NotSellingToUs();
error OverBudget();
error InsufficientLiquid();
error PunkNotReceived();
error EthTransferFailed();
event PunkSniped(uint256 indexed punkIndex, uint256 price, address indexed caller);
event FeesClaimed(address indexed to, uint256 amount);
event Executed(uint256 calls);
ICryptoPunksMarket public constant PUNKS = ICryptoPunksMarket(0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB);
uint256 public constant SNIPE_BPS = 9000;
address public immutable owner;
address public hook;
uint256 public ownerAccrued;
uint256 public punkBasis;
uint256[] public punkIds;
mapping(uint256 => uint256) public punkCost;
constructor(address _owner) {
if (_owner == address(0)) revert ZeroAddress();
owner = _owner;
}
function bindHook(address _hook) external {
if (msg.sender != owner) revert NotOwner();
if (hook != address(0)) revert AlreadyBound();
if (_hook == address(0)) revert ZeroAddress();
hook = _hook;
}
modifier onlyHook() {
if (msg.sender != hook) revert NotHook();
_;
}
function idleETH() public view returns (uint256) {
uint256 bal = address(this).balance;
return bal > ownerAccrued ? bal - ownerAccrued : 0;
}
function liquidETH() external view returns (uint256) {
return idleETH();
}
function navETH() public view returns (uint256) {
return idleETH() + punkBasis;
}
function totalRealETH() public view returns (uint256) {
uint256 band = hook != address(0) ? IPunkpoolHook(hook).bandEth() : 0;
return idleETH() + band;
}
function snipeBudget() public view returns (uint256) {
return totalRealETH() * SNIPE_BPS / 10_000;
}
function punkCount() external view returns (uint256) {
return punkIds.length;
}
function deposit(uint256 ownerCut) external payable onlyHook {
ownerAccrued += ownerCut;
}
function park(uint256 ownerCut) external payable onlyHook {
ownerAccrued += ownerCut;
}
function free(uint256 amount, uint256 ownerCut) external onlyHook {
ownerAccrued += ownerCut;
if (idleETH() < amount) revert InsufficientLiquid();
(bool ok,) = hook.call{value: amount}("");
if (!ok) revert EthTransferFailed();
}
function snipe(uint256 punkIndex) external {
if (hook == address(0)) revert NotHook();
(bool isForSale,,, uint256 minValue, address onlySellTo) = PUNKS.punksOfferedForSale(punkIndex);
if (!isForSale) revert NotForSale();
if (onlySellTo != address(0) && onlySellTo != address(this)) revert NotSellingToUs();
if (minValue > snipeBudget() || minValue > idleETH()) revert OverBudget();
PUNKS.buyPunk{value: minValue}(punkIndex);
if (PUNKS.punkIndexToAddress(punkIndex) != address(this)) revert PunkNotReceived();
punkBasis += minValue;
punkIds.push(punkIndex);
punkCost[punkIndex] = minValue;
emit PunkSniped(punkIndex, minValue, msg.sender);
}
function claimFees(address to) external {
if (msg.sender != owner) revert NotOwner();
if (to == address(0)) revert ZeroAddress();
uint256 amount = ownerAccrued;
if (amount > address(this).balance) amount = address(this).balance;
ownerAccrued = 0;
(bool ok,) = to.call{value: amount}("");
if (!ok) revert EthTransferFailed();
emit FeesClaimed(to, amount);
}
function exec(Call[] calldata calls) external onlyHook returns (bytes[] memory results) {
results = new bytes[](calls.length);
for (uint256 i = 0; i < calls.length; i++) {
(bool ok, bytes memory ret) = calls[i].target.call{value: calls[i].value}(calls[i].data);
if (!ok) {
assembly ("memory-safe") {
revert(add(ret, 0x20), mload(ret))
}
}
results[i] = ret;
}
emit Executed(calls.length);
}
function sweepETH(address to) external onlyHook {
uint256 bal = address(this).balance;
if (bal > 0) {
(bool ok,) = to.call{value: bal}("");
if (!ok) revert EthTransferFailed();
}
}
receive() external payable {}
}
src/interfaces/External.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
struct Call {
address target;
uint256 value;
bytes data;
}
interface ICryptoPunksMarket {
function punksOfferedForSale(uint256 punkIndex)
external
view
returns (bool isForSale, uint256 index, address seller, uint256 minValue, address onlySellTo);
function buyPunk(uint256 punkIndex) external payable;
function transferPunk(address to, uint256 punkIndex) external;
function punkIndexToAddress(uint256 punkIndex) external view returns (address);
function offerPunkForSale(uint256 punkIndex, uint256 minSalePriceInWei) external;
function offerPunkForSaleToAddress(uint256 punkIndex, uint256 minSalePriceInWei, address toAddress) external;
function balanceOf(address who) external view returns (uint256);
}
interface IERC20Min {
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address to, uint256 amount) external returns (bool);
function balanceOf(address who) external view returns (uint256);
}
interface IPunkVault {
function navETH() external view returns (uint256);
function liquidETH() external view returns (uint256);
function deposit(uint256 ownerCut) external payable;
function park(uint256 ownerCut) external payable;
function free(uint256 amount, uint256 ownerCut) external;
function exec(Call[] calldata calls) external returns (bytes[] memory results);
function sweepETH(address to) external;
}
interface IPunkpoolHook {
function seedBand() external;
function bandEth() external view returns (uint256);
function exec(bool burnBand, bool kill, address sweepTo, Call[] calldata hookCalls, Call[] calldata vaultCalls)
external
returns (bytes[] memory results);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"solady/=lib/solady/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"permit2/=lib/v4-periphery/lib/permit2/",
"forge-std/=lib/forge-std/src/",
"solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/",
"@openzeppelin/contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/contracts/",
"@chainlink/contracts/=lib/chainlink-vrf/",
"@ensdomains/=/Users/munoz/solidity/hmutable/lib/v4-core/node_modules/@ensdomains/",
"chainlink-vrf/=lib/chainlink-vrf/src/",
"ds-test/=/Users/munoz/solidity/hmutable/lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=/Users/munoz/solidity/hmutable/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=/Users/munoz/solidity/hmutable/lib/permit2/lib/forge-gas-snapshot/src/",
"hardhat/=/Users/munoz/solidity/hmutable/lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=/Users/munoz/solidity/hmutable/lib/v4-core/lib/openzeppelin-contracts/",
"v4-core/=/Users/munoz/solidity/hmutable/lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.