Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 15 additions & 148 deletions content/uniswap-hooks/api/base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ description: "Smart contract base utilities and implementations"

<div style={{marginTop: "4em"}} className="w-full flex flex-row items-center justify-between">

## `BaseAsyncSwap`
## `BaseAsyncSwap`

<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/uniswap-hooks/blob/v1.1.0/src/base/BaseAsyncSwap.sol">
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v1.2.1/src/base/BaseAsyncSwap.sol">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
</a>

</div>

```solidity
import "uniswap-hooks/src/base/BaseAsyncSwap.sol";
import "@openzeppelin/src/base/BaseAsyncSwap.sol";
```

Base implementation for async swaps, which skip the v3-like swap implementation of the `PoolManager`
Expand Down Expand Up @@ -51,7 +51,6 @@ _Available since v0.1.0_
<div className="bg-secondary p-4 rounded-md mb-6">
<h3 style={{ marginTop: "0"}}>Functions</h3>
<div className="font-mono">
- [constructor(_poolManager)](#BaseAsyncSwap-constructor-contract-IPoolManager-)
- [_beforeSwap(sender, key, params, )](#BaseAsyncSwap-_beforeSwap-address-struct-PoolKey-struct-SwapParams-bytes-)
- [_calculateSwapFee(key, specifiedAmount)](#BaseAsyncSwap-_calculateSwapFee-struct-PoolKey-uint256-)
- [getHookPermissions()](#BaseAsyncSwap-getHookPermissions--)
Expand Down Expand Up @@ -100,31 +99,12 @@ _Available since v0.1.0_
<div className="font-mono">
#### IHookEvents [!toc]
#### BaseHook [!toc]
- [NotSelf()](#BaseHook-NotSelf--)
- [InvalidPool()](#BaseHook-InvalidPool--)
- [HookNotImplemented()](#BaseHook-HookNotImplemented--)
- [NotPoolManager()](#BaseHook-NotPoolManager--)
#### IHooks [!toc]
</div>
</div>

<a id="BaseAsyncSwap-constructor-contract-IPoolManager-"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">constructor(contract IPoolManager _poolManager)</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseAsyncSwap-constructor-contract-IPoolManager-">#</a>
</div>
</div>
<div className="px-4">

Set the `PoolManager` address.

</div>
</div>

<a id="BaseAsyncSwap-_beforeSwap-address-struct-PoolKey-struct-SwapParams-bytes-"></a>

<div className="border rounded-md mb-4">
Expand Down Expand Up @@ -181,16 +161,16 @@ Set the hook permissions, specifically `beforeSwap` and `beforeSwapReturnDelta`.

<div style={{marginTop: "4em"}} className="w-full flex flex-row items-center justify-between">

## `BaseCustomAccounting`
## `BaseCustomAccounting`

<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/uniswap-hooks/blob/v1.1.0/src/base/BaseCustomAccounting.sol">
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v1.2.1/src/base/BaseCustomAccounting.sol">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
</a>

</div>

```solidity
import "uniswap-hooks/src/base/BaseCustomAccounting.sol";
import "@openzeppelin/src/base/BaseCustomAccounting.sol";
```

Base implementation for custom accounting and hook-owned liquidity.
Expand Down Expand Up @@ -226,7 +206,6 @@ _Available since v0.1.0_
<div className="bg-secondary p-4 rounded-md mb-6">
<h3 style={{ marginTop: "0"}}>Functions</h3>
<div className="font-mono">
- [constructor(_poolManager)](#BaseCustomAccounting-constructor-contract-IPoolManager-)
- [poolKey()](#BaseCustomAccounting-poolKey--)
- [addLiquidity(params)](#BaseCustomAccounting-addLiquidity-struct-BaseCustomAccounting-AddLiquidityParams-)
- [removeLiquidity(params)](#BaseCustomAccounting-removeLiquidity-struct-BaseCustomAccounting-RemoveLiquidityParams-)
Expand Down Expand Up @@ -293,8 +272,6 @@ _Available since v0.1.0_
#### IUnlockCallback [!toc]
#### IHookEvents [!toc]
#### BaseHook [!toc]
- [NotSelf()](#BaseHook-NotSelf--)
- [InvalidPool()](#BaseHook-InvalidPool--)
- [HookNotImplemented()](#BaseHook-HookNotImplemented--)
- [NotPoolManager()](#BaseHook-NotPoolManager--)
#### IHooks [!toc]
Expand All @@ -319,23 +296,6 @@ Ensure the deadline of a liquidity modification request is not expired.
</div>
</div>

<a id="BaseCustomAccounting-constructor-contract-IPoolManager-"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">constructor(contract IPoolManager _poolManager)</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseCustomAccounting-constructor-contract-IPoolManager-">#</a>
</div>
</div>
<div className="px-4">

Set the pool `PoolManager` address.

</div>
</div>

<a id="BaseCustomAccounting-poolKey--"></a>

<div className="border rounded-md mb-4">
Expand Down Expand Up @@ -688,16 +648,16 @@ Hook was already initialized.

<div style={{marginTop: "4em"}} className="w-full flex flex-row items-center justify-between">

## `BaseCustomCurve`
## `BaseCustomCurve`

<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/uniswap-hooks/blob/v1.1.0/src/base/BaseCustomCurve.sol">
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v1.2.1/src/base/BaseCustomCurve.sol">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
</a>

</div>

```solidity
import "uniswap-hooks/src/base/BaseCustomCurve.sol";
import "@openzeppelin/src/base/BaseCustomCurve.sol";
```

Base implementation for custom curves, inheriting from [`BaseCustomAccounting`](#BaseCustomAccounting).
Expand All @@ -723,7 +683,6 @@ _Available since v0.1.0_
<div className="bg-secondary p-4 rounded-md mb-6">
<h3 style={{ marginTop: "0"}}>Functions</h3>
<div className="font-mono">
- [constructor(_poolManager)](#BaseCustomCurve-constructor-contract-IPoolManager-)
- [_getAddLiquidity(, params)](#BaseCustomCurve-_getAddLiquidity-uint160-struct-BaseCustomAccounting-AddLiquidityParams-)
- [_getRemoveLiquidity(params)](#BaseCustomCurve-_getRemoveLiquidity-struct-BaseCustomAccounting-RemoveLiquidityParams-)
- [_beforeSwap(sender, key, params, )](#BaseCustomCurve-_beforeSwap-address-struct-PoolKey-struct-SwapParams-bytes-)
Expand Down Expand Up @@ -797,31 +756,12 @@ _Available since v0.1.0_
#### IUnlockCallback [!toc]
#### IHookEvents [!toc]
#### BaseHook [!toc]
- [NotSelf()](#BaseHook-NotSelf--)
- [InvalidPool()](#BaseHook-InvalidPool--)
- [HookNotImplemented()](#BaseHook-HookNotImplemented--)
- [NotPoolManager()](#BaseHook-NotPoolManager--)
#### IHooks [!toc]
</div>
</div>

<a id="BaseCustomCurve-constructor-contract-IPoolManager-"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">constructor(contract IPoolManager _poolManager)</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseCustomCurve-constructor-contract-IPoolManager-">#</a>
</div>
</div>
<div className="px-4">

Set the pool `PoolManager` address.

</div>
</div>

<a id="BaseCustomCurve-_getAddLiquidity-uint160-struct-BaseCustomAccounting-AddLiquidityParams-"></a>

<div className="border rounded-md mb-4">
Expand Down Expand Up @@ -862,7 +802,7 @@ for a remove liquidity request.

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">_beforeSwap(address sender, struct PoolKey key, struct SwapParams params, bytes) → bytes4, BeforeSwapDelta, uint24</p>
<p className="font-bold text-sm font-mono">_beforeSwap(address sender, struct PoolKey key, struct SwapParams params, bytes) → bytes4, BeforeSwapDelta returnDelta, uint24</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseCustomCurve-_beforeSwap-address-struct-PoolKey-struct-SwapParams-bytes-">#</a>
Expand Down Expand Up @@ -1007,16 +947,16 @@ Set the hook permissions, specifically `beforeInitialize`, `beforeAddLiquidity`,

<div style={{marginTop: "4em"}} className="w-full flex flex-row items-center justify-between">

## `BaseHook`
## `BaseHook`

<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/uniswap-hooks/blob/v1.1.0/src/base/BaseHook.sol">
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v1.2.1/src/base/BaseHook.sol">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
</a>

</div>

```solidity
import "uniswap-hooks/src/base/BaseHook.sol";
import "@openzeppelin/src/base/BaseHook.sol";
```

Base hook implementation.
Expand All @@ -1041,8 +981,6 @@ _Available since v0.1.0_
<h3 style={{ marginTop: "0"}}>Modifiers</h3>
<div className="font-mono">
- [onlyPoolManager()](#BaseHook-onlyPoolManager--)
- [onlySelf()](#BaseHook-onlySelf--)
- [onlyValidPools(hooks)](#BaseHook-onlyValidPools-contract-IHooks-)
</div>
</div>

Expand Down Expand Up @@ -1080,8 +1018,6 @@ _Available since v0.1.0_
<div className="bg-secondary p-4 rounded-md mb-6">
<h3 style={{ marginTop: "0"}}>Errors</h3>
<div className="font-mono">
- [NotSelf()](#BaseHook-NotSelf--)
- [InvalidPool()](#BaseHook-InvalidPool--)
- [HookNotImplemented()](#BaseHook-HookNotImplemented--)
- [NotPoolManager()](#BaseHook-NotPoolManager--)
#### IHooks [!toc]
Expand All @@ -1104,42 +1040,6 @@ _Available since v0.1.0_
</div>
</div>

<a id="BaseHook-onlySelf--"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">onlySelf()</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseHook-onlySelf--">#</a>
</div>
</div>

<div className="px-4">

Restrict the function to only be callable by the hook itself.

</div>
</div>

<a id="BaseHook-onlyValidPools-contract-IHooks-"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">onlyValidPools(contract IHooks hooks)</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">internal</p>
<a className="peer" data-card href="BaseHook-onlyValidPools-contract-IHooks-">#</a>
</div>
</div>

<div className="px-4">

Restrict the function to only be called for a valid pool.

</div>
</div>

<a id="BaseHook-constructor-contract-IPoolManager-"></a>

<div className="border rounded-md mb-4">
Expand All @@ -1152,7 +1052,7 @@ Restrict the function to only be called for a valid pool.
</div>
<div className="px-4">

Set the pool manager and check that the hook address matches the expected permissions and flags.
Check that the hook address matches the expected permissions and flags.

</div>
</div>
Expand Down Expand Up @@ -1538,40 +1438,6 @@ flag must be set to true in the `getHookPermissions` function.
</div>
</div>

<a id="BaseHook-NotSelf--"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">NotSelf()</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">error</p>
<a className="peer" data-card href="BaseHook-NotSelf--">#</a>
</div>
</div>
<div className="px-4">

The hook is not the caller.

</div>
</div>

<a id="BaseHook-InvalidPool--"></a>

<div className="border rounded-md mb-4">
<div className="bg-secondary flex w-full justify-between px-4">
<p className="font-bold text-sm font-mono">InvalidPool()</p>
<div className="flex flex-row items-center gap-2">
<p className="font-light text-sm">error</p>
<a className="peer" data-card href="BaseHook-InvalidPool--">#</a>
</div>
</div>
<div className="px-4">

The pool is not authorized to use this hook.

</div>
</div>

<a id="BaseHook-HookNotImplemented--"></a>

<div className="border rounded-md mb-4">
Expand Down Expand Up @@ -1603,3 +1469,4 @@ The hook function is not implemented.

</div>
</div>

Loading
Loading