|
| 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 deploy new pool. |
| 9 | +contract DeployPool 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 = "DeployPool_input.json"; |
| 17 | + string memory json = _getJsonFile(inputScriptFileName); |
| 18 | + |
| 19 | + EulerSwapFactory factory = EulerSwapFactory(vm.parseJsonAddress(json, ".factory")); |
| 20 | + IEulerSwap.Params memory poolParams = IEulerSwap.Params({ |
| 21 | + vault0: vm.parseJsonAddress(json, ".vault0"), |
| 22 | + vault1: vm.parseJsonAddress(json, ".vault1"), |
| 23 | + eulerAccount: eulerAccount, |
| 24 | + equilibriumReserve0: uint112(vm.parseJsonUint(json, ".equilibriumReserve0")), |
| 25 | + 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({ |
| 31 | + priceX: vm.parseJsonUint(json, ".priceX"), |
| 32 | + priceY: vm.parseJsonUint(json, ".priceY"), |
| 33 | + concentrationX: vm.parseJsonUint(json, ".concentrationX"), |
| 34 | + concentrationY: vm.parseJsonUint(json, ".concentrationY") |
| 35 | + }); |
| 36 | + bytes32 salt = bytes32(uint256(vm.parseJsonUint(json, ".salt"))); |
| 37 | + |
| 38 | + IEVC evc = IEVC(factory.EVC()); |
| 39 | + address predictedPoolAddress = factory.computePoolAddress(poolParams, curveParams, salt); |
| 40 | + |
| 41 | + IEVC.BatchItem[] memory items = new IEVC.BatchItem[](2); |
| 42 | + |
| 43 | + items[0] = IEVC.BatchItem({ |
| 44 | + onBehalfOfAccount: address(0), |
| 45 | + targetContract: address(evc), |
| 46 | + value: 0, |
| 47 | + data: abi.encodeCall(evc.setAccountOperator, (eulerAccount, predictedPoolAddress, true)) |
| 48 | + }); |
| 49 | + items[1] = IEVC.BatchItem({ |
| 50 | + onBehalfOfAccount: eulerAccount, |
| 51 | + targetContract: address(factory), |
| 52 | + value: 0, |
| 53 | + data: abi.encodeCall(EulerSwapFactory.deployPool, (poolParams, curveParams, salt)) |
| 54 | + }); |
| 55 | + |
| 56 | + vm.startBroadcast(eulerAccount); |
| 57 | + evc.batch(items); |
| 58 | + vm.stopBroadcast(); |
| 59 | + |
| 60 | + address pool = factory.eulerAccountToPool(eulerAccount); |
| 61 | + |
| 62 | + string memory outputScriptFileName = "DeployPool_output.json"; |
| 63 | + |
| 64 | + string memory object; |
| 65 | + object = vm.serializeAddress("factory", "deployedPool", pool); |
| 66 | + |
| 67 | + vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/out/", outputScriptFileName)); |
| 68 | + } |
| 69 | +} |
0 commit comments