Skip to content

Commit d92aa32

Browse files
authored
Merge pull request #102 from euler-xyz/deploy-pool-script-updates
Deploy pool script updates
2 parents 5aae167 + b759c6e commit d92aa32

File tree

7 files changed

+75
-21
lines changed

7 files changed

+75
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ out/
77
/broadcast/*/31337/
88
/broadcast/**/dry-run/
99
broadcast/
10+
script/json/DeployPool_output.json
1011
script/json/out/
1112

1213
# Dotenv file

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Uniswap4 Hook Compatible:
6464
- EulerSwapFactory: `0x45b146BC07c9985589B52df651310e75C6BE066A`
6565
- EulerSwapPeriphery: `0xdAAF468d84DD8945521Ea40297ce6c5EEfc7003a`
6666

67+
## Getting Started
68+
69+
The `script` folder contains scripts for deploying pools, as well as executing test trades on them. See the dedicated [README](./script/README.md)
6770

6871
## Safety
6972

script/DeployPool.s.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ contract DeployPool is ScriptUtil {
2020
string memory json = _getJsonFile(inputScriptFileName);
2121

2222
EulerSwapFactory factory = EulerSwapFactory(vm.parseJsonAddress(json, ".factory"));
23+
24+
address pool = factory.poolByEulerAccount(eulerAccount);
25+
require(pool == address(0), "EulerSwap pool is already installed for this account. Run the uninstall script first.");
26+
2327
IEulerSwap.Params memory poolParams = IEulerSwap.Params({
2428
vault0: vm.parseJsonAddress(json, ".vault0"),
2529
vault1: vm.parseJsonAddress(json, ".vault1"),
@@ -31,16 +35,15 @@ contract DeployPool is ScriptUtil {
3135
concentrationX: vm.parseJsonUint(json, ".concentrationX"),
3236
concentrationY: vm.parseJsonUint(json, ".concentrationY"),
3337
fee: vm.parseJsonUint(json, ".fee"),
34-
protocolFee: vm.parseJsonUint(json, ".protocolFee"),
35-
protocolFeeRecipient: vm.parseJsonAddress(json, ".protocolFeeRecipient")
38+
protocolFee: factory.protocolFee(),
39+
protocolFeeRecipient: factory.protocolFeeRecipient()
3640
});
3741
IEulerSwap.InitialState memory initialState = IEulerSwap.InitialState({
3842
currReserve0: uint112(vm.parseJsonUint(json, ".currReserve0")),
3943
currReserve1: uint112(vm.parseJsonUint(json, ".currReserve1"))
4044
});
41-
address eulerSwapImpl = vm.parseJsonAddress(json, ".eulerSwapImplementation");
4245

43-
bytes memory creationCode = MetaProxyDeployer.creationCodeMetaProxy(eulerSwapImpl, abi.encode(poolParams));
46+
bytes memory creationCode = MetaProxyDeployer.creationCodeMetaProxy(factory.eulerSwapImpl(), abi.encode(poolParams));
4447
(address predictedPoolAddress, bytes32 salt) = HookMiner.find(
4548
address(address(factory)),
4649
uint160(
@@ -70,13 +73,13 @@ contract DeployPool is ScriptUtil {
7073
evc.batch(items);
7174
vm.stopBroadcast();
7275

73-
address pool = factory.poolByEulerAccount(eulerAccount);
76+
pool = factory.poolByEulerAccount(eulerAccount);
7477

7578
string memory outputScriptFileName = "DeployPool_output.json";
7679

7780
string memory object;
7881
object = vm.serializeAddress("factory", "deployedPool", pool);
7982

80-
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/out/", outputScriptFileName));
83+
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/", outputScriptFileName));
8184
}
8285
}

script/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ Before running the scripts, please make sure to fill the `.env` file following t
66

77
After filling the `.env` file, make sure to run: `source .env` in your terminal.
88

9-
## Deploy protocol
10-
11-
- Fill the `DeployProtocol_input.json` file with the needed inputs.
12-
- Run `forge script ./script/DeployProtocol.s.sol --rpc-url network_name --broadcast --slow`
13-
149
## Deploy new pool
15-
1610
- Fill the `DeployPool_input.json` file with the needed inputs.
17-
- In pool deployment, the `eulerAccount` address is the deployer address, so we derive the address from the attached private key in the `.env` file.
18-
- Run `forge script ./script/DeployPool.s.sol --rpc-url network_name --broadcast --slow`
11+
- The `eulerAccount` will be derived from the private key provided in `.env`. The account's position on Euler should be already set up.
12+
- Run `forge script ./script/DeployPool.s.sol --rpc-url network_name --broadcast --slow`, replacing `network_name` to match `_RPC_URL` environment variable (e.g. if running through `MAINNET_RPC_URL` replace `network_name` with `mainnet`)
13+
- The deployed pool address will be recorded in `./scripts/json/DeployPool_output.json` file
1914

2015
## Exact in swap
2116

2217
- Fill the `SwapExactIn_input.json` file with the needed inputs.
23-
- Run `forge script ./script/SwapExactIn.s.sol --rpc-url network_name --broadcast --slow`
18+
- Run `forge script ./script/SwapExactIn.s.sol --rpc-url network_name --broadcast --slow`, replacing `network_name` to match `_RPC_URL` environment variable (e.g. if running through `MAINNET_RPC_URL` replace `network_name` with `mainnet`)
2419

20+
## Uninstall pool
21+
22+
- Fill the `UninstallPool_input.json` file with the factory address.
23+
- Run `forge script ./script/UninstallPool.s.sol --rpc-url network_name --broadcast --slow`, replacing `network_name` to match `_RPC_URL` environment variable (e.g. if running through `MAINNET_RPC_URL` replace `network_name` with `mainnet`)
24+
25+
## Deploy protocol
26+
27+
- Fill the `DeployProtocol_input.json` file with the needed inputs.
28+
- Run `forge script ./script/DeployProtocol.s.sol --rpc-url network_name --broadcast --slow`, replacing `network_name` to match `_RPC_URL` environment variable (e.g. if running through `MAINNET_RPC_URL` replace `network_name` with `mainnet`)

script/UninstallPool.s.sol

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import {ScriptUtil} from "./ScriptUtil.s.sol";
5+
import {IEulerSwapFactory, IEulerSwap, EulerSwapFactory} from "../src/EulerSwapFactory.sol";
6+
import {IEVC, IEulerSwap} from "../src/EulerSwap.sol";
7+
8+
/// @title Script to uninstall a pool from an account.
9+
contract UninstallPool is ScriptUtil {
10+
function run() public {
11+
// load wallet
12+
uint256 eulerAccountKey = vm.envUint("WALLET_PRIVATE_KEY");
13+
address eulerAccount = vm.rememberKey(eulerAccountKey);
14+
15+
// load JSON file
16+
string memory inputScriptFileName = "UninstallPool_input.json";
17+
string memory json = _getJsonFile(inputScriptFileName);
18+
19+
EulerSwapFactory factory = EulerSwapFactory(vm.parseJsonAddress(json, ".factory"));
20+
21+
IEVC evc = IEVC(factory.EVC());
22+
IEVC.BatchItem[] memory items = new IEVC.BatchItem[](2);
23+
24+
address pool = factory.poolByEulerAccount(eulerAccount);
25+
26+
items[0] = IEVC.BatchItem({
27+
onBehalfOfAccount: address(0),
28+
targetContract: address(evc),
29+
value: 0,
30+
data: abi.encodeCall(evc.setAccountOperator, (eulerAccount, pool, false))
31+
});
32+
items[1] = IEVC.BatchItem({
33+
onBehalfOfAccount: eulerAccount,
34+
targetContract: address(factory),
35+
value: 0,
36+
data: abi.encodeCall(EulerSwapFactory.uninstallPool, ())
37+
});
38+
39+
vm.startBroadcast(eulerAccount);
40+
evc.batch(items);
41+
vm.stopBroadcast();
42+
}
43+
}

script/json/DeployPool_input.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"factory": "0x52177559e6430396b9A7E2176Ef33b4e4052D125",
3-
"eulerSwapImplementation": "0x0B8CD42911551882638f4C762A66570e1fAc624f",
2+
"factory": "0xb013be1D0D380C13B58e889f412895970A2Cf228",
43
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
54
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
65
"equilibriumReserve0": 2000e6,
@@ -9,9 +8,7 @@
98
"priceY": 1e18,
109
"concentrationX": 0.97e18,
1110
"concentrationY": 0.97e18,
12-
"fee": 0,
13-
"protocolFee": 0,
14-
"protocolFeeRecipient": "0x0000000000000000000000000000000000000000",
1511
"currReserve0": 2000e6,
16-
"currReserve1": 2000e6
12+
"currReserve1": 2000e6,
13+
"fee": 0.01e18
1714
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"factory": "0xb013be1D0D380C13B58e889f412895970A2Cf228"
3+
}

0 commit comments

Comments
 (0)