Skip to content

Commit 9624a51

Browse files
update
1 parent a510a92 commit 9624a51

13 files changed

+131
-118
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ forge doc --serve --port 4000
5353
- EulerSwapFactory: 0x04C54FF83e4BC428FD1eDA2f41cdBd583A2e9cF8
5454
- EulerSwapPeriphery: 0x64A8410D7D2ecF3Aaf32b6C3932e4586f3C42ecE
5555

56+
------
57+
58+
- EulerSwapFactory: 0xF75548aF02f1928CbE9015985D4Fcbf96d728544
59+
- EulerSwapPeriphery: 0x813D74E832b3d9E9451d8f0E871E877edf2a5A5f
60+
- USDT-USDT pool: 0x2bFED8dBEb8e6226a15300AC77eE9130E52410fE
61+
62+
5663
## Safety
5764

5865
This software is experimental and is provided "as is" and "as available".

foundry.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ optimizer_runs = 10000
88
gas_reports = ["*"]
99
fs_permissions = [{ access = "read-write", path = "./"}]
1010

11-
[doc]
12-
out = "foundry-docs/"
13-
title = "EulerSwap Contracts Documentation"
14-
1511
[rpc_endpoints]
1612
mainnet = "${MAINNET_RPC_URL}"
1713
base = "${BASE_RPC_URL}"

script/DeployPool.s.sol

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,68 @@
22
pragma solidity ^0.8.0;
33

44
import {ScriptUtil} from "./ScriptUtil.s.sol";
5-
import {IEulerSwapFactory, EulerSwapFactory} from "../src/EulerSwapFactory.sol";
5+
import {IEulerSwapFactory, IEulerSwap, EulerSwapFactory} from "../src/EulerSwapFactory.sol";
6+
import {IEVC, IEulerSwap} from "../src/EulerSwap.sol";
67

78
/// @title Script to deploy new pool.
89
contract DeployPool is ScriptUtil {
910
function run() public {
1011
// load wallet
11-
uint256 deployerKey = vm.envUint("WALLET_PRIVATE_KEY");
12-
address deployerAddress = vm.rememberKey(deployerKey);
12+
uint256 eulerAccountKey = vm.envUint("WALLET_PRIVATE_KEY");
13+
address eulerAccount = vm.rememberKey(eulerAccountKey);
1314

1415
// load JSON file
1516
string memory inputScriptFileName = "DeployPool_input.json";
1617
string memory json = _getJsonFile(inputScriptFileName);
1718

1819
EulerSwapFactory factory = EulerSwapFactory(vm.parseJsonAddress(json, ".factory"));
19-
IEulerSwapFactory.DeployParams memory params = IEulerSwapFactory.DeployParams({
20+
IEulerSwap.Params memory poolParams = IEulerSwap.Params({
2021
vault0: vm.parseJsonAddress(json, ".vault0"),
2122
vault1: vm.parseJsonAddress(json, ".vault1"),
22-
swapAccount: vm.parseJsonAddress(json, ".swapAccount"),
23-
fee: vm.parseJsonUint(json, ".fee"),
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({
2431
priceX: vm.parseJsonUint(json, ".priceX"),
2532
priceY: vm.parseJsonUint(json, ".priceY"),
2633
concentrationX: vm.parseJsonUint(json, ".concentrationX"),
27-
concentrationY: vm.parseJsonUint(json, ".concentrationY"),
28-
debtLimit0: uint112(vm.parseJsonUint(json, ".debtLimit0")),
29-
debtLimit1: uint112(vm.parseJsonUint(json, ".debtLimit1"))
34+
concentrationY: vm.parseJsonUint(json, ".concentrationY")
3035
});
36+
bytes32 salt = bytes32(uint256(vm.parseJsonUint(json, ".salt")));
3137

32-
vm.startBroadcast(deployerAddress);
38+
IEVC evc = IEVC(factory.EVC());
39+
address predictedPoolAddress = factory.computePoolAddress(poolParams, curveParams, salt);
3340

34-
address pool = factory.deployPool(params);
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);
3561

3662
string memory outputScriptFileName = "DeployPool_output.json";
3763

3864
string memory object;
3965
object = vm.serializeAddress("factory", "deployedPool", pool);
4066

4167
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/out/", outputScriptFileName));
42-
43-
vm.stopBroadcast();
4468
}
4569
}

script/DeployProtocol.s.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ contract DeployProtocol is ScriptUtil {
2020

2121
vm.startBroadcast(deployerAddress);
2222

23-
new EulerSwapFactory();
24-
new EulerSwapPeriphery(evc);
23+
new EulerSwapFactory(evc);
24+
new EulerSwapPeriphery();
2525

2626
vm.stopBroadcast();
2727
}

script/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ After filling the `.env` file, make sure to run: `source .env` in your terminal.
1414
## Deploy new pool
1515

1616
- 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.
1718
- Run `forge script ./script/DeployPool.s.sol --rpc-url network_name --broadcast --slow`
1819

19-
## Activate new pool
20-
21-
- Fill the `SetOperatorAndActivatePool_input.json` file with the needed inputs.
22-
- Run `forge script ./script/SetOperatorAndActivatePool.s.sol --rpc-url network_name --broadcast --slow`
23-
2420
## Exact in swap
2521

26-
- Fill the `SwapExactIn_input.json` file with the needed inputs. For the `swapUtil` field, use the address of the `SwapUtil` contract deployed in the network you are using:
27-
- For mainnet, use `0xcdd2d349eeD309a0016C9A17f01bF1670913708b`
22+
- Fill the `SwapExactIn_input.json` file with the needed inputs.
2823
- Run `forge script ./script/SwapExactIn.s.sol --rpc-url network_name --broadcast --slow`
2924

script/SetOperatorAndActivatePool.s.sol

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

script/SwapExactIn.s.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ pragma solidity ^0.8.0;
33

44
import {ScriptUtil} from "./ScriptUtil.s.sol";
55
import {IERC20, SafeERC20, EulerSwap} from "../src/EulerSwap.sol";
6-
import {SwapUtil} from "./util/SwapUtil.sol";
7-
6+
import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
87
contract SwapExactIn is ScriptUtil {
98
using SafeERC20 for IERC20;
109

@@ -17,17 +16,18 @@ contract SwapExactIn is ScriptUtil {
1716
string memory inputScriptFileName = "SwapExactIn_input.json";
1817
string memory json = _getJsonFile(inputScriptFileName);
1918

20-
SwapUtil swapUtil = SwapUtil(vm.parseJsonAddress(json, ".swapUtil")); // Do not change address of this one unless u manually deploy new one
19+
EulerSwapPeriphery periphery = EulerSwapPeriphery(vm.parseJsonAddress(json, ".periphery"));
2120
EulerSwap pool = EulerSwap(vm.parseJsonAddress(json, ".pool"));
2221
address tokenIn = vm.parseJsonAddress(json, ".tokenIn");
2322
address tokenOut = vm.parseJsonAddress(json, ".tokenOut");
2423
uint256 amountIn = vm.parseJsonUint(json, ".amountIn");
24+
uint256 amountOutMin = vm.parseJsonUint(json, ".amountOutMin");
2525

2626
vm.startBroadcast(swapperAddress);
2727

28-
IERC20(tokenIn).forceApprove(address(swapUtil), amountIn);
28+
IERC20(tokenIn).forceApprove(address(periphery), amountIn);
2929

30-
swapUtil.executeSwap(address(pool), tokenIn, tokenOut, amountIn, true);
30+
periphery.swapExactIn(address(pool), tokenIn, tokenOut, amountIn, amountOutMin);
3131

3232
vm.stopBroadcast();
3333
}

script/json/DeployPool_input.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2-
"factory": "0x04C54FF83e4BC428FD1eDA2f41cdBd583A2e9cF8",
2+
"factory": "0xF75548aF02f1928CbE9015985D4Fcbf96d728544",
3+
"salt": "1",
34
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
45
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
5-
"swapAccount": "0x603765f9e9B8E3CBACbdf7A6e963B7EAD77AE86f",
6+
"equilibriumReserve0": 2000e6,
7+
"equilibriumReserve1": 2000e6,
8+
"currReserve0": 2000e6,
9+
"currReserve1": 2000e6,
610
"fee": 0,
711
"priceX": 1e18,
812
"priceY": 1e18,
913
"concentrationX": 0.97e18,
10-
"concentrationY": 0.97e18,
11-
"debtLimit0": 2000e6,
12-
"debtLimit1": 2000e6
14+
"concentrationY": 0.97e18
1315
}

script/json/SetOperatorAndActivatePool_input.json

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

script/json/SwapExactIn_input.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"pool": "0x67C30405250e395f31d661274352dA404e624682",
3-
"swapUtil": "0xcdd2d349eeD309a0016C9A17f01bF1670913708b",
2+
"periphery": "0x813D74E832b3d9E9451d8f0E871E877edf2a5A5f",
3+
"pool": "0x2bFED8dBEb8e6226a15300AC77eE9130E52410fE",
44
"tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
55
"tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
6-
"amountIn": 9e6
6+
"amountIn": 4e6,
7+
"amountOutMin": 3.9e6
78
}

0 commit comments

Comments
 (0)