Skip to content

Commit 6e645a8

Browse files
update
1 parent f65395f commit 6e645a8

File tree

7 files changed

+96
-7
lines changed

7 files changed

+96
-7
lines changed

.gitignore

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

1212
# Dotenv file
1313
.env

script/DeployPool.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract DeployPool is ScriptUtil {
3838
string memory object;
3939
object = vm.serializeAddress("factory", "deployedPool", pool);
4040

41-
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/", outputScriptFileName));
41+
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/json/out/", outputScriptFileName));
4242

4343
vm.stopBroadcast();
4444
}

script/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ After filling the `.env` file, make sure to run: `source .env` in your terminal.
1616
- Fill the `DeployPool_input.json` file with the needed inputs.
1717
- Run `forge script ./script/DeployPool.s.sol --rpc-url network_name --broadcast --slow`
1818

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+
24+
## Exact in swap
25+
26+
- Fill the `SwapExactIn_input.json` file with the needed inputs.
27+
- Run `forge script ./script/SwapExactIn.s.sol --rpc-url network_name --broadcast --slow`
28+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 {EulerSwap, IEVC} from "../src/EulerSwap.sol";
6+
7+
import "forge-std/console2.sol";
8+
9+
/// @title Script to deploy new pool.
10+
contract SetOperatorAndActivatePool is ScriptUtil {
11+
function run() public {
12+
// load wallet
13+
uint256 deployerKey = vm.envUint("WALLET_PRIVATE_KEY");
14+
address deployerAddress = vm.rememberKey(deployerKey);
15+
16+
// load JSON file
17+
string memory inputScriptFileName = "SetOperatorAndActivatePool_input.json";
18+
string memory json = _getJsonFile(inputScriptFileName);
19+
20+
EulerSwap pool = EulerSwap(vm.parseJsonAddress(json, ".pool"));
21+
IEVC evc = IEVC(pool.EVC());
22+
23+
vm.startBroadcast(deployerAddress);
24+
25+
evc.setAccountOperator(deployerAddress, address(pool), true);
26+
27+
pool.activate();
28+
29+
vm.stopBroadcast();
30+
}
31+
}

script/SwapExactIn.s.sol

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 {IERC20, EulerSwap} from "../src/EulerSwap.sol";
6+
import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
7+
8+
import "forge-std/console2.sol";
9+
10+
contract SwapExactIn is ScriptUtil {
11+
function run() public {
12+
// load wallet
13+
uint256 swapperKey = vm.envUint("WALLET_PRIVATE_KEY");
14+
address swapperAddress = vm.rememberKey(swapperKey);
15+
16+
// load JSON file
17+
string memory inputScriptFileName = "SwapExactIn_input.json";
18+
string memory json = _getJsonFile(inputScriptFileName);
19+
20+
EulerSwap pool = EulerSwap(vm.parseJsonAddress(json, ".pool"));
21+
EulerSwapPeriphery periphery = EulerSwapPeriphery(vm.parseJsonAddress(json, ".periphery"));
22+
23+
address tokenIn = vm.parseJsonAddress(json, ".tokenIn");
24+
address tokenOut = vm.parseJsonAddress(json, ".tokenOut");
25+
uint256 amountIn = vm.parseJsonUint(json, ".amountIn");
26+
bool isAsset0In = tokenIn < tokenOut;
27+
28+
uint256 expectedAmountOut = periphery.quoteExactInput(address(pool), tokenIn, tokenOut, amountIn);
29+
uint256 swapperBalanceBefore = IERC20(tokenOut).balanceOf(swapperAddress);
30+
31+
vm.startBroadcast(swapperAddress);
32+
33+
IERC20(tokenIn).transfer(address(pool), amountIn);
34+
35+
(isAsset0In) ? pool.swap(0, expectedAmountOut, swapperAddress, "") : pool.swap(expectedAmountOut, 0, swapperAddress, "");
36+
37+
require(IERC20(tokenOut).balanceOf(swapperAddress) > swapperBalanceBefore, "noo");
38+
39+
vm.stopBroadcast();
40+
}
41+
}

script/json/DeployPool_input.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"factory": "0xB6cFe9b23d18A034cE925Ee84b97D20a52Db1940",
33
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
44
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
5-
"swapAccount": "0x0C9a3dd6b8F28529d72d7f9cE918D493519EE383",
5+
"swapAccount": "0x603765f9e9B8E3CBACbdf7A6e963B7EAD77AE86f",
66
"fee": 0,
77
"priceX": 1e18,
88
"priceY": 1e18,
9-
"concentrationX": 0.4e18,
10-
"concentrationY": 0.85e18,
11-
"debtLimit0": "1000000000",
12-
"debtLimit1": "1000000000"
9+
"concentrationX": 0.97e18,
10+
"concentrationY": 0.97e18,
11+
"debtLimit0": 2000e6,
12+
"debtLimit1": 2000e6
1313
}

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+
"pool": "0xdFFC67B59708a1c108E4121cabB9AF5A4DB28C17",
3+
"periphery": "0x7fc1edF54d86DfAA90F1069E81D4B520A2A44d2B",
4+
"tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
5+
"tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
6+
"amountIn": 20e6
7+
}

0 commit comments

Comments
 (0)