Skip to content

Commit 0a5fb35

Browse files
authored
Merge pull request #65 from euler-xyz/update-scripts
Update scripts
2 parents 510ccf3 + 6e4bb6d commit 0a5fb35

10 files changed

+55
-31
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ forge doc --serve --port 4000
5959
- EulerSwapPeriphery: 0x813D74E832b3d9E9451d8f0E871E877edf2a5A5f
6060
- USDT-USDT pool: 0x2bFED8dBEb8e6226a15300AC77eE9130E52410fE
6161

62+
------ with Uniswap hook contracts (latest)
63+
64+
- EulerSwap implementation: 0x0B8CD42911551882638f4C762A66570e1fAc624f
65+
- EulerSwapFactory: 0x52177559e6430396b9A7E2176Ef33b4e4052D125
66+
- EulerSwapPeriphery: 0x9F27Bc363DB128cdC349CA54671E6Fbe2bE194D0
67+
- USDT-USDT pool: 0x13f627635CD96a2A75c2efBDba979172cAb2E888
6268

6369
## Safety
6470

script.old/json/SwapExactIn_input.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

script.old/DeployPool.s.sol renamed to script/DeployPool.s.sol

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pragma solidity ^0.8.0;
44
import {ScriptUtil} from "./ScriptUtil.s.sol";
55
import {IEulerSwapFactory, IEulerSwap, EulerSwapFactory} from "../src/EulerSwapFactory.sol";
66
import {IEVC, IEulerSwap} from "../src/EulerSwap.sol";
7+
import {HookMiner} from "../test/utils/HookMiner.sol";
8+
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
9+
import {MetaProxyDeployer} from "../src/utils/MetaProxyDeployer.sol";
710

811
/// @title Script to deploy new pool.
912
contract DeployPool is ScriptUtil {
@@ -23,21 +26,32 @@ contract DeployPool is ScriptUtil {
2326
eulerAccount: eulerAccount,
2427
equilibriumReserve0: uint112(vm.parseJsonUint(json, ".equilibriumReserve0")),
2528
equilibriumReserve1: uint112(vm.parseJsonUint(json, ".equilibriumReserve1")),
26-
currReserve0: uint112(vm.parseJsonUint(json, ".currReserve0")),
27-
currReserve1: uint112(vm.parseJsonUint(json, ".currReserve1")),
28-
fee: vm.parseJsonUint(json, ".fee")
29-
});
30-
IEulerSwap.CurveParams memory curveParams = IEulerSwap.CurveParams({
3129
priceX: vm.parseJsonUint(json, ".priceX"),
3230
priceY: vm.parseJsonUint(json, ".priceY"),
3331
concentrationX: vm.parseJsonUint(json, ".concentrationX"),
34-
concentrationY: vm.parseJsonUint(json, ".concentrationY")
32+
concentrationY: vm.parseJsonUint(json, ".concentrationY"),
33+
fee: vm.parseJsonUint(json, ".fee"),
34+
protocolFee: vm.parseJsonUint(json, ".protocolFee"),
35+
protocolFeeRecipient: vm.parseJsonAddress(json, ".protocolFeeRecipient")
36+
});
37+
IEulerSwap.InitialState memory initialState = IEulerSwap.InitialState({
38+
currReserve0: uint112(vm.parseJsonUint(json, ".currReserve0")),
39+
currReserve1: uint112(vm.parseJsonUint(json, ".currReserve1"))
3540
});
36-
bytes32 salt = bytes32(uint256(vm.parseJsonUint(json, ".salt")));
41+
address eulerSwapImpl = vm.parseJsonAddress(json, ".eulerSwapImplementation");
3742

38-
IEVC evc = IEVC(factory.EVC());
39-
address predictedPoolAddress = factory.computePoolAddress(poolParams, curveParams, salt);
43+
bytes memory creationCode = MetaProxyDeployer.creationCodeMetaProxy(eulerSwapImpl, abi.encode(poolParams));
44+
(address predictedPoolAddress, bytes32 salt) = HookMiner.find(
45+
address(address(factory)),
46+
eulerAccount,
47+
uint160(
48+
Hooks.BEFORE_INITIALIZE_FLAG | Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG
49+
| Hooks.BEFORE_ADD_LIQUIDITY_FLAG
50+
),
51+
creationCode
52+
);
4053

54+
IEVC evc = IEVC(factory.EVC());
4155
IEVC.BatchItem[] memory items = new IEVC.BatchItem[](2);
4256

4357
items[0] = IEVC.BatchItem({
@@ -50,7 +64,7 @@ contract DeployPool is ScriptUtil {
5064
onBehalfOfAccount: eulerAccount,
5165
targetContract: address(factory),
5266
value: 0,
53-
data: abi.encodeCall(EulerSwapFactory.deployPool, (poolParams, curveParams, salt))
67+
data: abi.encodeCall(EulerSwapFactory.deployPool, (poolParams, initialState, salt))
5468
});
5569

5670
vm.startBroadcast(eulerAccount);

script.old/DeployProtocol.s.sol renamed to script/DeployProtocol.s.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {ScriptUtil} from "./ScriptUtil.s.sol";
55
import {EulerSwapFactory} from "../src/EulerSwapFactory.sol";
66
import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
77
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
8+
import {EulerSwap} from "../src/EulerSwap.sol";
89

910
/// @title Script to deploy EulerSwapFactory & EulerSwapPeriphery.
1011
contract DeployProtocol is ScriptUtil {
@@ -19,13 +20,14 @@ contract DeployProtocol is ScriptUtil {
1920

2021
address evc = vm.parseJsonAddress(json, ".evc");
2122
address poolManager = vm.parseJsonAddress(json, ".poolManager");
22-
address factory = vm.parseJsonAddress(json, ".factory");
23+
address evkFactory = vm.parseJsonAddress(json, ".evkFactory");
24+
address feeOwner = vm.parseJsonAddress(json, ".feeOwner");
2325

2426
vm.startBroadcast(deployerAddress);
2527

26-
new EulerSwapFactory(IPoolManager(poolManager), evc, factory);
28+
address eulerSwapImpl = address(new EulerSwap(evc, poolManager));
29+
new EulerSwapFactory(evc, evkFactory, eulerSwapImpl, feeOwner);
2730
new EulerSwapPeriphery();
28-
2931
vm.stopBroadcast();
3032
}
3133
}
File renamed without changes.
File renamed without changes.

script.old/SwapExactIn.s.sol renamed to script/SwapExactIn.s.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
88

99
import {ScriptUtil} from "./ScriptUtil.s.sol";
1010

11-
1211
contract SwapExactIn is ScriptUtil {
1312
using SafeERC20 for IERC20;
1413

@@ -26,13 +25,14 @@ contract SwapExactIn is ScriptUtil {
2625
address tokenIn = vm.parseJsonAddress(json, ".tokenIn");
2726
address tokenOut = vm.parseJsonAddress(json, ".tokenOut");
2827
uint256 amountIn = vm.parseJsonUint(json, ".amountIn");
29-
uint256 amountOutMin = vm.parseJsonUint(json, ".amountOutMin");
28+
29+
uint256 amountOutMin = periphery.quoteExactInput(address(pool), tokenIn, tokenOut, amountIn);
3030

3131
vm.startBroadcast(swapperAddress);
3232

3333
IERC20(tokenIn).forceApprove(address(periphery), amountIn);
3434

35-
periphery.swapExactIn(address(pool), tokenIn, tokenOut, amountIn, amountOutMin);
35+
periphery.swapExactIn(address(pool), tokenIn, tokenOut, amountIn, swapperAddress, amountOutMin, 0);
3636

3737
vm.stopBroadcast();
3838
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"factory": "0xF75548aF02f1928CbE9015985D4Fcbf96d728544",
3-
"salt": "1",
2+
"factory": "0x52177559e6430396b9A7E2176Ef33b4e4052D125",
3+
"eulerSwapImplementation": "0x0B8CD42911551882638f4C762A66570e1fAc624f",
44
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
55
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
66
"equilibriumReserve0": 2000e6,
77
"equilibriumReserve1": 2000e6,
8-
"currReserve0": 2000e6,
9-
"currReserve1": 2000e6,
10-
"fee": 0,
118
"priceX": 1e18,
129
"priceY": 1e18,
1310
"concentrationX": 0.97e18,
14-
"concentrationY": 0.97e18
11+
"concentrationY": 0.97e18,
12+
"fee": 0,
13+
"protocolFee": 0,
14+
"protocolFeeRecipient": "0x0000000000000000000000000000000000000000",
15+
"currReserve0": 2000e6,
16+
"currReserve1": 2000e6
1517
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"evc": "0x0C9a3dd6b8F28529d72d7f9cE918D493519EE383",
33
"poolManager": "0x000000000004444c5dc75cB358380D2e3dE08A90",
4-
"factory": "0xF75548aF02f1928CbE9015985D4Fcbf96d728544"
4+
"evkFactory": "0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e",
5+
"feeOwner": "0x603765f9e9B8E3CBACbdf7A6e963B7EAD77AE86f"
56
}

script/json/SwapExactIn_input.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"periphery": "0x9F27Bc363DB128cdC349CA54671E6Fbe2bE194D0",
3+
"pool": "0x13f627635CD96a2A75c2efBDba979172cAb2E888",
4+
"tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
5+
"tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
6+
"amountIn": 4e6
7+
}

0 commit comments

Comments
 (0)