Skip to content

Commit 2722d35

Browse files
authored
Revert "[API-4248] Wrap and unwrap ETH"
1 parent ae2aca2 commit 2722d35

File tree

7 files changed

+11
-322
lines changed

7 files changed

+11
-322
lines changed

SwapRouter/script/Deploy.s.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ contract SwapRouterDeploy is Script {
1111
function run() external {
1212
vm.startBroadcast();
1313

14-
address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
15-
16-
SkipGoSwapRouter router = new SkipGoSwapRouter(weth);
14+
SkipGoSwapRouter router = SkipGoSwapRouter(0xa11CC0eFb1B3AcD95a2B8cd316E8c132E16048b5);
1715

1816
UniswapV2Adapter uniswapV2Adapter = new UniswapV2Adapter();
1917
UniswapV3Adapter uniswapV3Adapter = new UniswapV3Adapter();

SwapRouter/src/SkipGoSwapRouter.sol

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
55
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
66

77
import {IAdapter} from "./interfaces/IAdapter.sol";
8-
import {IWETH} from "./interfaces/IWETH.sol";
98

109
contract SkipGoSwapRouter is Ownable {
1110
enum ExchangeType {
@@ -15,8 +14,6 @@ contract SkipGoSwapRouter is Ownable {
1514

1615
mapping(ExchangeType => address) public adapters;
1716

18-
address public weth;
19-
2017
struct Hop {
2118
ExchangeType exchangeType;
2219
bytes data;
@@ -27,11 +24,7 @@ contract SkipGoSwapRouter is Ownable {
2724
uint256 feeBPS;
2825
}
2926

30-
constructor(address _weth) Ownable(msg.sender) {
31-
weth = _weth;
32-
}
33-
34-
receive() external payable {}
27+
constructor() Ownable(msg.sender) {}
3528

3629
function swapExactIn(
3730
uint256 amountIn,
@@ -41,15 +34,7 @@ contract SkipGoSwapRouter is Ownable {
4134
Hop[] calldata hops,
4235
Affiliate[] calldata affiliates
4336
) external payable returns (uint256 amountOut) {
44-
// if token in is ETH, msg.value must be equal to amountIn
45-
// if token in is not ETH, msg.value must be 0
46-
require(msg.value == (tokenIn == address(0) ? amountIn : 0), "invalid msg.value");
47-
48-
if (tokenIn == address(0)) {
49-
IWETH(weth).deposit{value: amountIn}();
50-
} else {
51-
IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
52-
}
37+
IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
5338

5439
amountOut = amountIn;
5540

@@ -76,14 +61,9 @@ contract SkipGoSwapRouter is Ownable {
7661

7762
uint256 amountPaid = _payAffiliateFees(tokenOut, amountOut, affiliates);
7863

79-
amountOut = amountOut - amountPaid;
64+
IERC20(tokenOut).transfer(msg.sender, amountOut - amountPaid);
8065

81-
if (tokenOut == address(0)) {
82-
IWETH(weth).withdraw(amountOut);
83-
payable(msg.sender).transfer(amountOut);
84-
} else {
85-
IERC20(tokenOut).transfer(msg.sender, amountOut);
86-
}
66+
amountOut = amountOut - amountPaid;
8767
}
8868

8969
function swapExactOut(
@@ -98,13 +78,7 @@ contract SkipGoSwapRouter is Ownable {
9878

9979
require(amountIn <= amountInMax, "amount in is greater than amount in max");
10080

101-
if (tokenIn == address(0)) {
102-
require(msg.value >= amountIn, "msg.value is less than amount in");
103-
IWETH(weth).deposit{value: amountIn}();
104-
} else {
105-
require(msg.value == 0, "msg.value must be 0");
106-
IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
107-
}
81+
IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
10882

10983
amountOut = amountIn;
11084

@@ -129,19 +103,7 @@ contract SkipGoSwapRouter is Ownable {
129103

130104
uint256 amountPaid = _payAffiliateFees(tokenOut, amountOut, affiliates);
131105

132-
uint256 amountOutAfterFees = amountOut - amountPaid;
133-
134-
if (tokenOut == address(0)) {
135-
IWETH(weth).withdraw(amountOutAfterFees);
136-
payable(msg.sender).transfer(amountOutAfterFees);
137-
} else {
138-
IERC20(tokenOut).transfer(msg.sender, amountOutAfterFees);
139-
}
140-
141-
// refund unused ETH
142-
if (tokenIn == address(0) && msg.value > amountIn) {
143-
payable(msg.sender).transfer(msg.value - amountIn);
144-
}
106+
IERC20(tokenOut).transfer(msg.sender, amountOut - amountPaid);
145107
}
146108

147109
function getAmountOut(uint256 amountIn, Hop[] calldata hops) public view returns (uint256 amountOut) {

SwapRouter/src/adapters/UniswapV2Adapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ contract UniswapV2Adapter {
1313
uint256 fee;
1414
}
1515

16-
function swapExactIn(uint256 amountIn, bytes calldata data) external payable returns (uint256 amountOut) {
16+
function swapExactIn(uint256 amountIn, bytes calldata data) external returns (uint256 amountOut) {
1717
UniswapV2Data memory uniswapV2Data = abi.decode(data, (UniswapV2Data));
1818

1919
(uint112 reserve0, uint112 reserve1,) = IUniswapV2Pair(uniswapV2Data.pool).getReserves();

SwapRouter/src/adapters/UniswapV3Adapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contract UniswapV3Adapter {
1515
address swapRouter;
1616
}
1717

18-
function swapExactIn(uint256 amountIn, bytes calldata data) external payable returns (uint256 amountOut) {
18+
function swapExactIn(uint256 amountIn, bytes calldata data) external returns (uint256 amountOut) {
1919
UniswapV3Data memory uniswapV3Data = abi.decode(data, (UniswapV3Data));
2020

2121
IERC20(uniswapV3Data.tokenIn).approve(uniswapV3Data.swapRouter, amountIn);

SwapRouter/src/interfaces/IWETH.sol

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

0 commit comments

Comments
 (0)