Skip to content

Commit

Permalink
updated initialization since its requires a locker now
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Nov 28, 2023
1 parent d991235 commit eb0558f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/pages/initialize/HookDataInit.solsnippet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IPoolManager manager = IPoolManager(0x01);
PoolInitializeTest initializeRouter = PoolInitializeTest(0x01);

address hook = address(0x80); // prefix indicates the hook only has a beforeInitialize() function
address token0 = address(0x11);
Expand All @@ -19,4 +19,4 @@ PoolKey memory pool = PoolKey({
tickSpacing: tickSpacing,
hooks: IHooks(hook)
});
manager.initialize(pool, startingPrice, hookData);
initializeRouter.initialize(pool, startingPrice, hookData);
4 changes: 2 additions & 2 deletions src/pages/initialize/Hookless.solsnippet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IPoolManager manager = IPoolManager(0x01);
PoolInitializeTest initializeRouter = PoolInitializeTest(0x01);

address token0 = address(0x11);
address token1 = address(0x22);
Expand All @@ -18,4 +18,4 @@ PoolKey memory pool = PoolKey({
tickSpacing: tickSpacing,
hooks: IHooks(address(0x0)) // !!! Hookless pool is address(0x0)
});
manager.initialize(pool, startingPrice, hookData);
initializeRouter.initialize(pool, startingPrice, hookData);
7 changes: 4 additions & 3 deletions src/pages/initialize/PoolInitialize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
pragma solidity ^0.8.20;

import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {PoolInitializeTest} from "@uniswap/v4-core/contracts/test/PoolInitializeTest.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {CurrencyLibrary, Currency} from "@uniswap/v4-core/contracts/types/Currency.sol";

contract PoolInitialize {
using CurrencyLibrary for Currency;

// set the pool manager address
IPoolManager manager = IPoolManager(0x01);
// set the initialize router
PoolInitializeTest initializeRouter = PoolInitializeTest(0x02);

function init(
address token0,
Expand All @@ -33,6 +34,6 @@ contract PoolInitialize {
tickSpacing: tickSpacing,
hooks: IHooks(hook)
});
manager.initialize(pool, sqrtPriceX96, hookData);
initializeRouter.initialize(pool, sqrtPriceX96, hookData);
}
}
21 changes: 11 additions & 10 deletions src/pages/initialize/index.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const keywords = [
export const codes = [
{
fileName: "HookDataInit.sol",
code: "SVBvb2xNYW5hZ2VyIG1hbmFnZXIgPSBJUG9vbE1hbmFnZXIoMHgwMSk7CgphZGRyZXNzIGhvb2sgPSBhZGRyZXNzKDB4ODApOyAvLyBwcmVmaXggaW5kaWNhdGVzIHRoZSBob29rIG9ubHkgaGFzIGEgYmVmb3JlSW5pdGlhbGl6ZSgpIGZ1bmN0aW9uCmFkZHJlc3MgdG9rZW4wID0gYWRkcmVzcygweDExKTsKYWRkcmVzcyB0b2tlbjEgPSBhZGRyZXNzKDB4MjIpOwp1aW50MjQgc3dhcEZlZSA9IDMwMDA7IC8vIDAuMzAlIGZlZSB0aWVyCmludDI0IHRpY2tTcGFjaW5nID0gNjA7CgovLyBmbG9vcihzcXJ0KDEpICogMl45NikKdWludDE2MCBzdGFydGluZ1ByaWNlID0gNzkyMjgxNjI1MTQyNjQzMzc1OTM1NDM5NTAzMzY7CgovLyBBc3N1bWUgdGhlIGN1c3RvbSBob29rIHJlcXVpcmVzIGEgdGltZXN0YW1wIHdoZW4gaW5pdGlhbGl6aW5nIGl0CmJ5dGVzIG1lbW9yeSBob29rRGF0YSA9IGFiaS5lbmNvZGUoYmxvY2sudGltZXN0YW1wKTsKClBvb2xLZXkgbWVtb3J5IHBvb2wgPSBQb29sS2V5KHsKICAgIGN1cnJlbmN5MDogQ3VycmVuY3kud3JhcCh0b2tlbjApLAogICAgY3VycmVuY3kxOiBDdXJyZW5jeS53cmFwKHRva2VuMSksC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0IHN3YXBGZWUsCiAgICAgICAgaW50MjQgdGlja1NwYWNpbmcsCiAgICAgICAgYWRkcmVzcyBob29rLAogICAgICAgIHVpbnQxNjAgc3FydFByaWNlWDk2LAogICAgICAgIGJ5dGVzIGNhbGxkYXRhIGhvb2tEYXRhCiAgICApIGV4dGVybmFsIHsKICAgICAgICAvLyBzb3J0IHlvdXIgdG9rZW5zISB2NCByZXF1aXJlcyB0b2tlbjAgPCB0b2tlbjEKICAgICAgICBpZiAodG9rZW4wID4gdG9rZW4xKSB7CiAgICAgICAgICAgICh0b2tlbjAsIHRva2VuMSkgPSAodG9rZW4xLCB0b2tlbjApOwogICAgICAgIH0KCiAgICAgICAgUG9vbEtleSBtZW1vcnkgcG9vbCA9IFBvb2xLZXkoewogICAgICAgICAgICBjdXJyZW5jeTA6IEN1cnJlbmN5LndyYXAodG9rZW4wKSwKICAgICAgICAgICAgY3VycmVuY3kxOiBDdXJyZW5jeS53cmFwKHRva2VuMSksCiAgICAgICAgICAgIGZlZTogc3dhcEZlZSwKICAgICAgICAgICAgdGlja1NwYWNpbmc6IHRpY2tTcGFjaW5nLAogICAgICAgICAgICBob29rczogSUhvb2tzKGhvb2spCiAgICAgICAgfSk7CiAgICAgICAgaW5pdGlhbGl6ZVJvdXRlci5pbml0aWFsaXplKHBvb2wsIHNxcnRQcmljZVg5NiwgaG9va0RhdGEpOwogICAgfQp9Cg==",
},
]

Expand All @@ -45,15 +45,16 @@ const html = `<ul>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.20;</span>
<span class="hljs-keyword">import</span> {<span class="hljs-title">IPoolManager</span>} <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"</span>;
<span class="hljs-keyword">import</span> {<span class="hljs-title">PoolInitializeTest</span>} <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"@uniswap/v4-core/contracts/test/PoolInitializeTest.sol"</span>;
<span class="hljs-keyword">import</span> {<span class="hljs-title">IHooks</span>} <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"@uniswap/v4-core/contracts/interfaces/IHooks.sol"</span>;
<span class="hljs-keyword">import</span> {<span class="hljs-title">PoolKey</span>} <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"@uniswap/v4-core/contracts/types/PoolKey.sol"</span>;
<span class="hljs-keyword">import</span> {<span class="hljs-title">CurrencyLibrary</span>, <span class="hljs-title">Currency</span>} <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"@uniswap/v4-core/contracts/types/Currency.sol"</span>;
<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">PoolInitialize</span> </span>{
<span class="hljs-keyword">using</span> <span class="hljs-title">CurrencyLibrary</span> <span class="hljs-title"><span class="hljs-keyword">for</span></span> <span class="hljs-title">Currency</span>;
<span class="hljs-comment">// set the pool manager address</span>
IPoolManager manager <span class="hljs-operator">=</span> IPoolManager(<span class="hljs-number">0x01</span>);
<span class="hljs-comment">// set the initialize router</span>
PoolInitializeTest initializeRouter <span class="hljs-operator">=</span> PoolInitializeTest(<span class="hljs-number">0x02</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">init</span>(<span class="hljs-params">
<span class="hljs-keyword">address</span> token0,
Expand All @@ -76,12 +77,12 @@ const html = `<ul>
tickSpacing: tickSpacing,
hooks: IHooks(hook)
});
manager.initialize(pool, sqrtPriceX96, hookData);
initializeRouter.initialize(pool, sqrtPriceX96, hookData);
}
}
</code></pre><h3>Examples of Initializing a V4 Pool</h3>
<p><em>Hooks are not mandatory, you can create a pool without a hook</em></p>
<pre><code class="language-solidity">IPoolManager manager <span class="hljs-operator">=</span> IPoolManager(<span class="hljs-number">0x01</span>);
<pre><code class="language-solidity">PoolInitializeTest initializeRouter <span class="hljs-operator">=</span> PoolInitializeTest(<span class="hljs-number">0x01</span>);
<span class="hljs-keyword">address</span> token0 <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x11</span>);
<span class="hljs-keyword">address</span> token1 <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x22</span>);
Expand All @@ -101,9 +102,9 @@ PoolKey <span class="hljs-keyword">memory</span> pool <span class="hljs-operator
tickSpacing: tickSpacing,
hooks: IHooks(<span class="hljs-keyword">address</span>(<span class="hljs-number">0x0</span>)) <span class="hljs-comment">// !!! Hookless pool is address(0x0)</span>
});
manager.initialize(pool, startingPrice, hookData);
initializeRouter.initialize(pool, startingPrice, hookData);
</code></pre><p><em>Some hooks may require initialization data, i.e. <code>block.timestamp</code></em></p>
<pre><code class="language-solidity">IPoolManager manager <span class="hljs-operator">=</span> IPoolManager(<span class="hljs-number">0x01</span>);
<pre><code class="language-solidity">PoolInitializeTest initializeRouter <span class="hljs-operator">=</span> PoolInitializeTest(<span class="hljs-number">0x01</span>);
<span class="hljs-keyword">address</span> hook <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x80</span>); <span class="hljs-comment">// prefix indicates the hook only has a beforeInitialize() function</span>
<span class="hljs-keyword">address</span> token0 <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x11</span>);
Expand All @@ -124,7 +125,7 @@ PoolKey <span class="hljs-keyword">memory</span> pool <span class="hljs-operator
tickSpacing: tickSpacing,
hooks: IHooks(hook)
});
manager.initialize(pool, startingPrice, hookData);
initializeRouter.initialize(pool, startingPrice, hookData);
</code></pre>`

export default html

0 comments on commit eb0558f

Please sign in to comment.