Skip to content

Commit ff22f3b

Browse files
update
1 parent b09e0c0 commit ff22f3b

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ forge coverage
4646

4747
## Private Deployment
4848

49-
- EulerSwapFactory: 0xB6cFe9b23d18A034cE925Ee84b97D20a52Db1940
50-
- EulerSwapPeriphery: 0x7fc1edF54d86DfAA90F1069E81D4B520A2A44d2B
49+
- EulerSwapFactory: 0x04C54FF83e4BC428FD1eDA2f41cdBd583A2e9cF8
50+
- EulerSwapPeriphery: 0x64A8410D7D2ecF3Aaf32b6C3932e4586f3C42ecE
5151

5252
## Safety
5353

script/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ After filling the `.env` file, make sure to run: `source .env` in your terminal.
2323

2424
## Exact in swap
2525

26-
- Fill the `SwapExactIn_input.json` file with the needed inputs.
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`
2728
- Run `forge script ./script/SwapExactIn.s.sol --rpc-url network_name --broadcast --slow`
2829

script/SwapExactIn.s.sol

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
pragma solidity ^0.8.0;
33

44
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";
5+
import {IERC20, SafeERC20, EulerSwap} from "../src/EulerSwap.sol";
6+
import {SwapUtil} from "./util/SwapUtil.sol";
97

108
contract SwapExactIn is ScriptUtil {
9+
using SafeERC20 for IERC20;
10+
1111
function run() public {
1212
// load wallet
1313
uint256 swapperKey = vm.envUint("WALLET_PRIVATE_KEY");
@@ -17,24 +17,17 @@ contract SwapExactIn is ScriptUtil {
1717
string memory inputScriptFileName = "SwapExactIn_input.json";
1818
string memory json = _getJsonFile(inputScriptFileName);
1919

20+
SwapUtil swapUtil = SwapUtil(vm.parseJsonAddress(json, ".swapUtil")); // Do not change address of this one unless u manually deploy new one
2021
EulerSwap pool = EulerSwap(vm.parseJsonAddress(json, ".pool"));
21-
EulerSwapPeriphery periphery = EulerSwapPeriphery(vm.parseJsonAddress(json, ".periphery"));
22-
2322
address tokenIn = vm.parseJsonAddress(json, ".tokenIn");
2423
address tokenOut = vm.parseJsonAddress(json, ".tokenOut");
2524
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);
3025

3126
vm.startBroadcast(swapperAddress);
3227

33-
IERC20(tokenIn).transfer(address(pool), amountIn);
34-
35-
(isAsset0In) ? pool.swap(0, expectedAmountOut, swapperAddress, "") : pool.swap(expectedAmountOut, 0, swapperAddress, "");
28+
IERC20(tokenIn).forceApprove(address(swapUtil), amountIn);
3629

37-
require(IERC20(tokenOut).balanceOf(swapperAddress) > swapperBalanceBefore, "noo");
30+
swapUtil.executeSwap(address(pool), tokenIn, tokenOut, amountIn, true);
3831

3932
vm.stopBroadcast();
4033
}

script/json/DeployPool_input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"factory": "0xB6cFe9b23d18A034cE925Ee84b97D20a52Db1940",
2+
"factory": "0x04C54FF83e4BC428FD1eDA2f41cdBd583A2e9cF8",
33
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
44
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
55
"swapAccount": "0x603765f9e9B8E3CBACbdf7A6e963B7EAD77AE86f",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"pool": "0xdFFC67B59708a1c108E4121cabB9AF5A4DB28C17"
2+
"pool": "0x67c30405250e395f31d661274352da404e624682"
33
}

script/json/SwapExactIn_input.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"pool": "0xdFFC67B59708a1c108E4121cabB9AF5A4DB28C17",
3-
"periphery": "0x7fc1edF54d86DfAA90F1069E81D4B520A2A44d2B",
2+
"pool": "0x67C30405250e395f31d661274352dA404e624682",
3+
"swapUtil": "0xcdd2d349eeD309a0016C9A17f01bF1670913708b",
44
"tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
55
"tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
6-
"amountIn": 20e6
6+
"amountIn": 9e6
77
}

script/util/SwapUtil.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import {IEulerSwapPeriphery} from "../../src/interfaces/IEulerSwapPeriphery.sol";
5+
import {IERC20, IEulerSwap, SafeERC20} from "../../src/EulerSwap.sol";
6+
7+
// This is not meant to be run in production, just for testing purposes
8+
contract SwapUtil {
9+
using SafeERC20 for IERC20;
10+
11+
IEulerSwapPeriphery public immutable periphery;
12+
13+
constructor(address peripheryAddr) {
14+
periphery = IEulerSwapPeriphery(peripheryAddr);
15+
}
16+
17+
function executeSwap(address pool, address tokenIn, address tokenOut, uint256 amount, bool isExactIn) external {
18+
bool isAsset0In = tokenIn < tokenOut;
19+
20+
(uint256 amountIn, uint256 amountOut) = (isExactIn)
21+
? (amount, periphery.quoteExactInput(address(pool), tokenIn, tokenOut, amount))
22+
: (periphery.quoteExactOutput(address(pool), tokenIn, tokenOut, amount), amount);
23+
24+
IERC20(tokenIn).safeTransferFrom(msg.sender, address(pool), amountIn);
25+
26+
(isAsset0In)
27+
? IEulerSwap(pool).swap(0, amountOut, msg.sender, "")
28+
: IEulerSwap(pool).swap(amountOut, 0, msg.sender, "");
29+
}
30+
}

0 commit comments

Comments
 (0)