Проверенный контрактТочноеMIT
DacityStrategyHook
Адрес0xdcf00afc4d3df3ff1400a5bf5872169049184088
- Баланс
0,014007 ETH
- Транзакций
0
- Компилятор
solc 0.8.28
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 457 602
- Транзакция создания
- 0xb0aa47ee91…564cc9c2d8
2 файла
- DacityStrategyHook.solглавный4,63 КБ
- V4Interfaces.sol7,83 КБ
DacityStrategyHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import { IPoolManager, PoolKey, SwapParams, Currency, BeforeSwapDelta, BeforeSwapDeltaLibrary } from "./V4Interfaces.sol";
interface IERC20Min {
function balanceOf(address) external view returns (uint256);
function transfer(address, uint256) external returns (bool);
}
/// @title Dacity Strategy tax hook (3% on every swap, paid to the deployer's vault)
/// @custom:token Dacity Strategy (DCTYSTR)
/// @custom:build 542785a52e766d9d
contract DacityStrategyHook {
using BeforeSwapDeltaLibrary for *;
IPoolManager public immutable poolManager;
address public immutable owner;
/// @notice Swap fee in basis points on the input side of every swap (3% at launch).
uint16 public taxBps;
uint16 public constant MAX_TAX_BPS = 1000; // hard cap 10%
uint16 public constant BPS_DENOM = 10_000;
bytes32 public constant BUILD = 0x542785a52e766d9d7111b3483ecbc9d4821885d02b7af4eb10c03a98bd55ecbc;
/// @notice Addresses that pay no fee (owner, the hook itself, anything the owner excludes).
mapping(address => bool) public excludedFromTax;
event TaxTaken(address indexed swapper, address currency, uint256 amount);
event TaxBpsSet(uint16 bps);
event ExcludedSet(address indexed who, bool excluded);
event Harvested(address indexed to, uint256 ethAmount, address token, uint256 tokenAmount);
error NotOwner();
error NotPM();
error TooHigh();
error ExactOutputNotSupported();
modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; }
modifier onlyPoolManager() { if (msg.sender != address(poolManager)) revert NotPM(); _; }
receive() external payable {}
constructor(IPoolManager _pm, address _owner, uint16 _taxBps) {
if (_taxBps > MAX_TAX_BPS) revert TooHigh();
poolManager = _pm;
owner = _owner;
taxBps = _taxBps;
excludedFromTax[_owner] = true;
excludedFromTax[address(this)] = true;
}
function setTax(uint16 bps) external onlyOwner { if (bps > MAX_TAX_BPS) revert TooHigh(); taxBps = bps; emit TaxBpsSet(bps); }
function setExcluded(address who, bool excluded) external onlyOwner { excludedFromTax[who] = excluded; emit ExcludedSet(who, excluded); }
/// @notice Hook permissions: beforeSwap + beforeSwapReturnDelta (address flags 0x88).
function getHookPermissions() external pure returns (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) {
return (false, false, false, false, false, false, true, false, false, false, true, false, false, false);
}
/// @notice V4 callback: skim taxBps off the input currency of each swap into this hook (the vault).
function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata) external onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {
uint16 t = taxBps;
if (t == 0 || excludedFromTax[tx.origin] || excludedFromTax[sender]) return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
// Exact-input only: the input amount is known up front, so taxBps of it is skimmed before the swap. An exact-output
// swap does not know its input yet; rather than tax the wrong side (the old code did), refuse it. Nothing that
// routes hooked pools (this page, the Universal Router buys and sells) uses exact-output.
if (params.amountSpecified >= 0) revert ExactOutputNotSupported();
Currency inputCurrency = params.zeroForOne ? key.currency0 : key.currency1;
uint256 tax = (uint256(-params.amountSpecified) * t) / BPS_DENOM;
if (tax == 0) return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
poolManager.take(inputCurrency, address(this), tax);
emit TaxTaken(tx.origin, Currency.unwrap(inputCurrency), tax);
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.toBeforeSwapDelta(int128(int256(tax)), int128(0)), 0);
}
/// @notice Sweep collected fees (native ETH + the token) to the owner.
function harvest(address token) external onlyOwner {
uint256 ethBal = address(this).balance;
if (ethBal != 0) { (bool ok, ) = owner.call{value: ethBal}(""); require(ok, "eth send failed"); }
uint256 tokBal = 0;
if (token != address(0)) { tokBal = IERC20Min(token).balanceOf(address(this)); if (tokBal != 0) IERC20Min(token).transfer(owner, tokBal); }
emit Harvested(owner, ethBal, token, tokBal);
}
}
V4Interfaces.sol
// SPDX-License-Identifier: MIT
// Minimal vendored Uniswap V4 + ancillary interfaces needed by uBIRDSHook.
// Sourced + simplified from @uniswap/v4-core v1.0.x. Only the surface
// the hook actually uses.
pragma solidity ^0.8.20;
// ───── Currency ─────────────────────────────────────────────────────────
type Currency is address;
library CurrencyLibrary {
Currency constant NATIVE = Currency.wrap(address(0));
function isAddressZero(Currency c) internal pure returns (bool) {
return Currency.unwrap(c) == address(0);
}
function transfer(Currency c, address to, uint256 amount) internal {
if (amount == 0) return;
if (Currency.unwrap(c) == address(0)) {
(bool ok, ) = to.call{value: amount}("");
require(ok, "Currency: ETH transfer failed");
} else {
// ERC-20 transfer with no return-value assumption
(bool ok, bytes memory data) = Currency.unwrap(c).call(
abi.encodeWithSelector(0xa9059cbb, to, amount)
);
require(ok && (data.length == 0 || abi.decode(data, (bool))), "Currency: ERC20 transfer failed");
}
}
}
// ───── PoolKey ──────────────────────────────────────────────────────────
struct PoolKey {
Currency currency0;
Currency currency1;
uint24 fee;
int24 tickSpacing;
address hooks;
}
// ───── BeforeSwapDelta (for delta-returning hooks) ──────────────────────
// V4 packs two int128 values (specified delta + unspecified delta) into a single int256.
// specified currency is the one the swap caller is exact-amounting.
type BeforeSwapDelta is int256;
library BeforeSwapDeltaLibrary {
BeforeSwapDelta constant ZERO_DELTA = BeforeSwapDelta.wrap(0);
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
internal pure returns (BeforeSwapDelta delta)
{
return BeforeSwapDelta.wrap(
(int256(deltaSpecified) << 128) | (int256(uint256(uint128(deltaUnspecified))))
);
}
}
// ───── SwapParams ───────────────────────────────────────────────────────
struct SwapParams {
bool zeroForOne;
int256 amountSpecified; // negative = exact-input, positive = exact-output
uint160 sqrtPriceLimitX96;
}
// ───── BalanceDelta (post-swap result) ──────────────────────────────────
type BalanceDelta is int256;
// ───── IPoolManager (subset) ────────────────────────────────────────────
interface IPoolManager {
/// @notice Take some currency out of the PoolManager, increasing the caller's debt.
function take(Currency currency, address to, uint256 amount) external;
/// @notice Settle currency debt with the PoolManager (pay it back).
function settle() external payable returns (uint256);
/// @notice Sync transient balance for a token before settle.
function sync(Currency currency) external;
/// @notice Mint claim tokens to caller against a currency credit.
function mint(address to, uint256 id, uint256 amount) external;
/// @notice Burn caller's claim tokens to settle a currency credit.
function burn(address from, uint256 id, uint256 amount) external;
}
// ───── IHooks (callback surface; only what we implement) ────────────────
interface IHooks {
function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)
external returns (bytes4);
function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
external returns (bytes4);
function beforeAddLiquidity(address sender, PoolKey calldata key,
bytes calldata hookData, bytes calldata params)
external returns (bytes4);
function afterAddLiquidity(address sender, PoolKey calldata key,
bytes calldata params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData)
external returns (bytes4, BalanceDelta);
function beforeRemoveLiquidity(address sender, PoolKey calldata key,
bytes calldata params, bytes calldata hookData)
external returns (bytes4);
function afterRemoveLiquidity(address sender, PoolKey calldata key,
bytes calldata params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData)
external returns (bytes4, BalanceDelta);
function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
external returns (bytes4, BeforeSwapDelta, uint24);
function afterSwap(address sender, PoolKey calldata key, SwapParams calldata params,
BalanceDelta delta, bytes calldata hookData)
external returns (bytes4, int128);
function beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external returns (bytes4);
function afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external returns (bytes4);
}
// ───── Hooks permission flag layout ─────────────────────────────────────
// Bit positions in the bottom 14 bits of the hook's deployed address.
// PoolManager rejects calls if the address bits don't match the methods
// actually implemented.
library HookFlags {
uint160 constant BEFORE_INITIALIZE_FLAG = 1 << 13;
uint160 constant AFTER_INITIALIZE_FLAG = 1 << 12;
uint160 constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11;
uint160 constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10;
uint160 constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9;
uint160 constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8;
uint160 constant BEFORE_SWAP_FLAG = 1 << 7;
uint160 constant AFTER_SWAP_FLAG = 1 << 6;
uint160 constant BEFORE_DONATE_FLAG = 1 << 5;
uint160 constant AFTER_DONATE_FLAG = 1 << 4;
uint160 constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3;
uint160 constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2;
uint160 constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA = 1 << 1;
uint160 constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA = 1 << 0;
}
// ───── Sudoswap V2 LSSVMPair (subset) ───────────────────────────────────
// The pool we'll buy NFTs from. Its `swapTokenForAnyNFTs` is the cheapest
// way to fetch any NFT from the pool's inventory.
interface ILSSVMPair {
function swapTokenForAnyNFTs(
uint256 numNFTs,
uint256 maxExpectedTokenInput,
address nftRecipient,
bool isRouter,
address routerCaller
) external payable returns (uint256 inputAmount);
function getBuyNFTQuote(uint256 assetId, uint256 numNFTs)
external view
returns (
uint8 error,
uint256 newSpotPrice,
uint256 newDelta,
uint256 inputAmount,
uint256 protocolFee,
uint256 royaltyAmount
);
function nft() external view returns (address);
}
Настройки компилятораПоказать
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.