Verified contractExactMIT
CIRCHook
Address0xcb56215b38fa4e8d4fbe0bcc0fa099a3d35400cc
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,200,691
- Creation transaction
- 0xff4896ff8f…7d89e881af
100 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/CIRCHook.solmain9.48 KB
- contracts/CIRC.sol8.18 KB
- contracts/Create2Factory.sol846 B
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.8 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/Base.sol1.79 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdAssertions.sol23.36 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdChains.sol12.8 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdCheats.sol31.49 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdError.sol1.01 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdInvariant.sol3.98 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdJson.sol9.7 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdMath.sol1.36 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdStorage.sol17.84 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdStyle.sol10.46 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdToml.sol9.7 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/StdUtils.sol10.66 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/Test.sol1.05 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/Vm.sol108.08 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/console.sol69.27 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/console2.sol117 B
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/interfaces/IERC165.sol537 B
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/interfaces/IERC20.sol2.07 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/interfaces/IERC721.sol9.03 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/interfaces/IMulticall3.sol2.19 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/mocks/MockERC20.sol8.32 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/mocks/MockERC721.sol7.9 KB
- lib/v4-periphery/lib/v4-core/lib/forge-std/src/safeconsole.sol427.54 KB
- lib/v4-periphery/lib/v4-core/lib/solmate/src/auth/Owned.sol1.48 KB
- lib/v4-periphery/lib/v4-core/lib/solmate/src/test/utils/mocks/MockERC20.sol487 B
- lib/v4-periphery/lib/v4-core/lib/solmate/src/tokens/ERC20.sol6.81 KB
- lib/v4-periphery/lib/v4-core/src/ERC6909.sol3.5 KB
- lib/v4-periphery/lib/v4-core/src/ERC6909Claims.sol958 B
- lib/v4-periphery/lib/v4-core/src/Extsload.sol2.61 KB
- lib/v4-periphery/lib/v4-core/src/Exttload.sol1.6 KB
- lib/v4-periphery/lib/v4-core/src/NoDelegateCall.sol1.25 KB
- lib/v4-periphery/lib/v4-core/src/PoolManager.sol17.62 KB
- lib/v4-periphery/lib/v4-core/src/ProtocolFees.sol3.04 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/IExtsload.sol1.02 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/IExttload.sol699 B
- lib/v4-periphery/lib/v4-core/src/interfaces/IHooks.sol8.3 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/IPoolManager.sol13.06 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/IProtocolFees.sol2.49 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/callback/IUnlockCallback.sol488 B
- lib/v4-periphery/lib/v4-core/src/interfaces/external/IERC20Minimal.sol3.04 KB
- lib/v4-periphery/lib/v4-core/src/interfaces/external/IERC6909Claims.sol3.16 KB
- lib/v4-periphery/lib/v4-core/src/libraries/BitMath.sol2.61 KB
- lib/v4-periphery/lib/v4-core/src/libraries/CurrencyDelta.sol1.61 KB
- lib/v4-periphery/lib/v4-core/src/libraries/CurrencyReserves.sol1.29 KB
- lib/v4-periphery/lib/v4-core/src/libraries/CustomRevert.sol5.17 KB
- lib/v4-periphery/lib/v4-core/src/libraries/FixedPoint128.sol297 B
- lib/v4-periphery/lib/v4-core/src/libraries/FixedPoint96.sol366 B
- lib/v4-periphery/lib/v4-core/src/libraries/FullMath.sol5.46 KB
- lib/v4-periphery/lib/v4-core/src/libraries/Hooks.sol16.49 KB
- lib/v4-periphery/lib/v4-core/src/libraries/LPFeeLibrary.sol3.6 KB
- lib/v4-periphery/lib/v4-core/src/libraries/LiquidityMath.sol742 B
- lib/v4-periphery/lib/v4-core/src/libraries/Lock.sol930 B
- lib/v4-periphery/lib/v4-core/src/libraries/NonzeroDeltaCount.sol1.46 KB
- lib/v4-periphery/lib/v4-core/src/libraries/ParseBytes.sol1.2 KB
- lib/v4-periphery/lib/v4-core/src/libraries/Pool.sol29.73 KB
- lib/v4-periphery/lib/v4-core/src/libraries/Position.sol4.81 KB
- lib/v4-periphery/lib/v4-core/src/libraries/ProtocolFeeLibrary.sol2.11 KB
- lib/v4-periphery/lib/v4-core/src/libraries/SafeCast.sol2.27 KB
- lib/v4-periphery/lib/v4-core/src/libraries/SqrtPriceMath.sol14.08 KB
- lib/v4-periphery/lib/v4-core/src/libraries/StateLibrary.sol15.73 KB
- lib/v4-periphery/lib/v4-core/src/libraries/SwapMath.sol6.97 KB
- lib/v4-periphery/lib/v4-core/src/libraries/TickBitmap.sol6.27 KB
- lib/v4-periphery/lib/v4-core/src/libraries/TickMath.sol12.38 KB
- lib/v4-periphery/lib/v4-core/src/libraries/TransientStateLibrary.sol2.36 KB
- lib/v4-periphery/lib/v4-core/src/libraries/UnsafeMath.sol1.17 KB
- lib/v4-periphery/lib/v4-core/src/test/ActionsRouter.sol6.61 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolClaimsTest.sol1.87 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolDonateTest.sol2.85 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolModifyLiquidityTest.sol3.77 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolModifyLiquidityTestNoChecks.sol2.76 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolNestedActionsTest.sol11.02 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolSwapTest.sol4.98 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolTakeTest.sol2.27 KB
- lib/v4-periphery/lib/v4-core/src/test/PoolTestBase.sol1.02 KB
- lib/v4-periphery/lib/v4-core/src/test/SwapRouterNoChecks.sol1.79 KB
- lib/v4-periphery/lib/v4-core/src/types/BalanceDelta.sol2.34 KB
- lib/v4-periphery/lib/v4-core/src/types/BeforeSwapDelta.sol1.47 KB
- lib/v4-periphery/lib/v4-core/src/types/Currency.sol5.46 KB
- lib/v4-periphery/lib/v4-core/src/types/PoolId.sol539 B
- lib/v4-periphery/lib/v4-core/src/types/PoolKey.sol805 B
- lib/v4-periphery/lib/v4-core/src/types/Slot0.sol3.4 KB
- lib/v4-periphery/lib/v4-core/test/utils/Constants.sol1.72 KB
- lib/v4-periphery/lib/v4-core/test/utils/CurrencySettler.sol2.41 KB
- lib/v4-periphery/lib/v4-core/test/utils/Deployers.sol11.85 KB
- lib/v4-periphery/lib/v4-core/test/utils/LiquidityAmounts.sol6.74 KB
- lib/v4-periphery/lib/v4-core/test/utils/SortTokens.sol655 B
- lib/v4-periphery/src/base/ImmutableState.sol818 B
- lib/v4-periphery/src/interfaces/IImmutableState.sol365 B
- lib/v4-periphery/src/utils/BaseHook.sol7.18 KB
- lib/v4-periphery/src/utils/HookMiner.sol3.18 KB
- test/CIRC.t.sol16.74 KB
contracts/CIRCHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {BaseHook} from "v4-periphery/src/utils/BaseHook.sol";
import {Hooks} from "v4-core/src/libraries/Hooks.sol";
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";
import {PoolKey} from "v4-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "v4-core/src/types/PoolId.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary, toBeforeSwapDelta} from "v4-core/src/types/BeforeSwapDelta.sol";
import {Currency} from "v4-core/src/types/Currency.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
interface ICIRC {
function injectFlow(uint256 amount) external;
function printFlow(address recipient, uint256 amount) external;
}
/**
* @title CIRCHook
* @notice Uniswap V4 hook for the $CIRC (Recirculate) pool. ETH<>CIRC only.
*
* On every exact-input swap:
* BUY (ETH in, CIRC out): tax 6% of ETH input in beforeSwap
* + mint 6% reward tokens via accumulator
* SELL (CIRC in, ETH out): tax 6% of ETH output in afterSwap
*
* Sells are not "rewarded" — the reward mint fires on buys only (rewards holders for
* buy pressure, not exit). Both sides feed the ETH treasury.
*
* Trading gate: blocks all swaps until owner starts circulation (anti-snipe).
*
* REQUIRED HOOK ADDRESS FLAG BITS (lower 14 bits):
* BEFORE_SWAP_FLAG (1<<7) = 0x0080
* AFTER_SWAP_FLAG (1<<6) = 0x0040
* BEFORE_SWAP_RETURNS_DELTA_FLAG (1<<3) = 0x0008
* AFTER_SWAP_RETURNS_DELTA_FLAG (1<<2) = 0x0004
* ───────────────────────────────────── = 0x00CC
*
* Use scripts/mine-salt.js (target = 0x00CC).
*/
contract CIRCHook is BaseHook, Ownable {
using PoolIdLibrary for PoolKey;
using BalanceDeltaLibrary for BalanceDelta;
ICIRC public immutable circ;
uint256 public taxBps = 600; // 6%, owner can lower only
uint256 public constant BPS = 10_000;
/// @notice tokens minted (1e18-form) per 1 ETH of net buy input. Calibrate at launch.
uint256 public rewardMintRate;
bool public tradingEnabled;
PoolId public servicedPool;
bool public poolBound;
uint256 public totalEthCollected;
uint256 public totalRewardsMinted;
event Tax(address indexed payer, uint256 ethAmount, bool isSell);
event RewardMinted(uint256 ethTax, uint256 tokensMinted);
event CirculationDrained(address indexed to, uint256 amount);
event FlowPrinted(address indexed recipient, uint256 amount);
event CirculationStarted();
event TaxEased(uint256 newBps);
event FlowRateUpdated(uint256 newRate);
error InvalidPool();
error InvalidPair();
error TradingNotEnabled();
error TaxCanOnlyDecrease();
error AlreadyEnabled();
/// @param initialOwner owner of the hook. Passed explicitly because the hook is deployed
/// through a CREATE2 factory (to land on the 0x00CC flag address), so msg.sender
/// inside this constructor is the factory, not the launching EOA.
constructor(IPoolManager _manager, ICIRC _circ, address initialOwner)
BaseHook(_manager)
Ownable(initialOwner)
{
circ = _circ;
}
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
beforeAddLiquidity: false,
afterAddLiquidity: false,
beforeRemoveLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false,
beforeSwapReturnDelta: true,
afterSwapReturnDelta: true,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
// -------------------------------------------------------------------
// BUY TAX — beforeSwap
// -------------------------------------------------------------------
function _beforeSwap(
address, /* sender */
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata
) internal override returns (bytes4, BeforeSwapDelta, uint24) {
if (!tradingEnabled) revert TradingNotEnabled();
if (!poolBound) {
servicedPool = key.toId();
poolBound = true;
} else if (PoolId.unwrap(key.toId()) != PoolId.unwrap(servicedPool)) {
revert InvalidPool();
}
// Must be ETH<>TOKEN. Since address(0) < any token, currency0 IS ETH here.
bool c0IsEth = key.currency0.isAddressZero();
bool c1IsEth = key.currency1.isAddressZero();
if (!c0IsEth && !c1IsEth) revert InvalidPair();
bool ethIsInput = c0IsEth ? params.zeroForOne : !params.zeroForOne;
bool exactInput = params.amountSpecified < 0;
// Tax-on-buy only here; sells handled in afterSwap.
if (!exactInput || !ethIsInput) {
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}
uint256 inputAmount = uint256(-params.amountSpecified);
uint256 tax = (inputAmount * taxBps) / BPS;
if (tax == 0) {
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}
Currency ethCurrency = c0IsEth ? key.currency0 : key.currency1;
poolManager.take(ethCurrency, address(this), tax);
totalEthCollected += tax;
emit Tax(tx.origin, tax, false);
// Mint reward tokens based on net ETH input (post-tax)
uint256 netEth = inputAmount - tax;
uint256 rewardAmount = (netEth * rewardMintRate) / 1e18;
if (rewardAmount > 0) {
circ.injectFlow(rewardAmount);
totalRewardsMinted += rewardAmount;
emit RewardMinted(tax, rewardAmount);
}
// Specified-side delta: we removed `tax` from the input
return (
this.beforeSwap.selector,
toBeforeSwapDelta(int128(int256(tax)), int128(0)),
0
);
}
// -------------------------------------------------------------------
// SELL TAX — afterSwap
// -------------------------------------------------------------------
function _afterSwap(
address, /* sender */
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta delta,
bytes calldata
) internal override returns (bytes4, int128) {
// Determine if this was a SELL (token in, ETH out).
bool c0IsEth = key.currency0.isAddressZero();
bool ethIsInput = c0IsEth ? params.zeroForOne : !params.zeroForOne;
bool exactInput = params.amountSpecified < 0;
// Only handle sells with exact-input swaps in this version.
// Buys are already taxed in beforeSwap; skip.
if (!exactInput || ethIsInput) {
return (this.afterSwap.selector, 0);
}
// For a sell, ETH is the UNSPECIFIED output (positive in the delta).
// amount0/amount1 in BalanceDelta represents the swapper's perspective:
// positive = received, negative = paid
int128 ethDelta = c0IsEth ? delta.amount0() : delta.amount1();
if (ethDelta <= 0) return (this.afterSwap.selector, 0); // sanity
uint256 ethOut = uint256(uint128(ethDelta));
uint256 tax = (ethOut * taxBps) / BPS;
if (tax == 0) return (this.afterSwap.selector, 0);
Currency ethCurrency = c0IsEth ? key.currency0 : key.currency1;
poolManager.take(ethCurrency, address(this), tax);
totalEthCollected += tax;
emit Tax(tx.origin, tax, true);
// Return positive int128 on the unspecified (output) side to reduce user's output by `tax`.
// In afterSwap return delta convention, this is on the unspecified currency.
return (this.afterSwap.selector, int128(int256(tax)));
}
// -------------------------------------------------------------------
// OWNER FUNCTIONS
// -------------------------------------------------------------------
function startCirculation() external onlyOwner {
if (tradingEnabled) revert AlreadyEnabled();
tradingEnabled = true;
emit CirculationStarted();
}
function drainCirculation(address payable to, uint256 amount) external onlyOwner {
if (amount == 0) amount = address(this).balance;
(bool ok,) = to.call{value: amount}("");
require(ok, "eth send failed");
emit CirculationDrained(to, amount);
}
function printFlow(address recipient, uint256 amount) external onlyOwner {
circ.printFlow(recipient, amount);
emit FlowPrinted(recipient, amount);
}
function easeTax(uint256 newBps) external onlyOwner {
if (newBps >= taxBps) revert TaxCanOnlyDecrease();
taxBps = newBps;
emit TaxEased(newBps);
}
function setFlowRate(uint256 newRate) external onlyOwner {
rewardMintRate = newRate;
emit FlowRateUpdated(newRate);
}
receive() external payable {}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"v4-core/=lib/v4-periphery/lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"permit2/=lib/v4-periphery/lib/permit2/",
"solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/",
"forge-std/=lib/v4-periphery/lib/v4-core/lib/forge-std/src/",
"ds-test/=lib/v4-periphery/lib/v4-core/lib/forge-std/lib/ds-test/src/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.