Skip to content

Commit

Permalink
Merge branch 'main' into add-v2-adapter-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoda authored Feb 20, 2025
2 parents 879d1ab + fdb5d3e commit 54c168e
Show file tree
Hide file tree
Showing 21 changed files with 1,176 additions and 160 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release
on:
# manual trigger
workflow_dispatch:

jobs:
deploy:
name: release
runs-on:
group: npm-deploy
environment:
name: release
permissions:
id-token: write
contents: write
steps:
- name: Load secret
uses: 1password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0
with:
# Export loaded secrets as environment variables
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
# You may need to change this to your vault name and secret name
# Refer to it by calling env.NPM_TOKEN
# This token is also limited by IP to ONLY work on the runner
NPM_TOKEN: op://npm-deploy/npm-runner-token/secret

- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744

- name: Setup Node
uses: actions/[email protected]
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
scope: "@uniswap"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- name: Install dependencies
run: |
git submodule update --init --recursive
- name: Compile
run: forge build

- name: Release
env:
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm set "//registry.npmjs.org/:_authToken" ${{ env.NPM_TOKEN }}
npm publish --provenance --access public
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main
schedule:
# random HH:MM to avoid a load spike on GitHub Actions at 00:00
- cron: '35 11 * * *'
- cron: "35 11 * * *"
jobs:
semgrep:
name: semgrep/ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- name: Run tests
run: forge test --isolate -vvv
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# if you add a file here, add it to `.npmignore` too
cache/
foundry-out/
.vscode/
broadcast/*/*/dry-run/*.json
broadcast/*/*/run-[0-9]*.json
broadcast/*/*/run-[0-9]*.json
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache/
.vscode/
broadcast/*/*/dry-run/*.json
broadcast/*/*/run-[0-9]*.json
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@uniswap/v4-periphery",
"version": "1.0.1",
"description": "🦄 Peripheral smart contracts for interacting with Uniswap v4",
"repository": {
"type": "git",
"url": "git+https://github.com/Uniswap/v4-periphery.git"
},
"license": "MIT",
"bugs": {
"url": "https://uniswap.org/bug-bounty"
},
"homepage": "https://github.com/Uniswap/v4-periphery#readme",
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"uniswap",
"periphery",
"v4"
]
}
39 changes: 39 additions & 0 deletions script/DeployHook.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {HookMiner} from "../src/utils/HookMiner.sol";

/// @dev Replace import with your own hook
import {MockCounterHook} from "../test/mocks/MockCounterHook.sol";

/// @notice Mines the address and deploys the Counter.sol Hook contract
contract DeployHookScript is Script {
address constant CREATE2_DEPLOYER = address(0x4e59b44847b379578588920cA78FbF26c0B4956C);

/// @dev Replace with the desired PoolManager on its corresponding chain
IPoolManager constant POOLMANAGER = IPoolManager(address(0xE03A1074c86CFeDd5C142C4F04F1a1536e203543));

function setUp() public {}

function run() public {
// hook contracts must have specific flags encoded in the address
uint160 flags = uint160(
Hooks.BEFORE_SWAP_FLAG | Hooks.AFTER_SWAP_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG
| Hooks.BEFORE_REMOVE_LIQUIDITY_FLAG
);

bytes memory constructorArgs = abi.encode(POOLMANAGER);

// Mine a salt that will produce a hook address with the correct flags
(address hookAddress, bytes32 salt) =
HookMiner.find(CREATE2_DEPLOYER, flags, type(MockCounterHook).creationCode, constructorArgs);

// Deploy the hook using CREATE2
vm.broadcast();
MockCounterHook counter = new MockCounterHook{salt: salt}(IPoolManager(POOLMANAGER));
require(address(counter) == hookAddress, "CounterScript: hook address mismatch");
}
}
9 changes: 9 additions & 0 deletions src/base/ImmutableState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ contract ImmutableState is IImmutableState {
/// @inheritdoc IImmutableState
IPoolManager public immutable poolManager;

/// @notice Thrown when the caller is not PoolManager
error NotPoolManager();

/// @notice Only allow calls from the PoolManager contract
modifier onlyPoolManager() {
if (msg.sender != address(poolManager)) revert NotPoolManager();
_;
}

constructor(IPoolManager _poolManager) {
poolManager = _poolManager;
}
Expand Down
9 changes: 0 additions & 9 deletions src/base/SafeCallback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ import {ImmutableState} from "./ImmutableState.sol";
/// @title Safe Callback
/// @notice A contract that only allows the Uniswap v4 PoolManager to call the unlockCallback
abstract contract SafeCallback is ImmutableState, IUnlockCallback {
/// @notice Thrown when calling unlockCallback where the caller is not PoolManager
error NotPoolManager();

constructor(IPoolManager _poolManager) ImmutableState(_poolManager) {}

/// @notice Only allow calls from the PoolManager contract
modifier onlyPoolManager() {
if (msg.sender != address(poolManager)) revert NotPoolManager();
_;
}

/// @inheritdoc IUnlockCallback
/// @dev We force the onlyPoolManager modifier by exposing a virtual function after the onlyPoolManager check.
function unlockCallback(bytes calldata data) external onlyPoolManager returns (bytes memory) {
Expand Down
146 changes: 0 additions & 146 deletions src/base/hooks/BaseHook.sol

This file was deleted.

Loading

0 comments on commit 54c168e

Please sign in to comment.