-
Notifications
You must be signed in to change notification settings - Fork 4
/
CurveEthPoolAdapter.sol
54 lines (46 loc) · 1.55 KB
/
CurveEthPoolAdapter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-3
pragma solidity ^0.8.15;
import "src/interfaces/IPoolAdapter.sol";
import "src/interfaces/curve/ICurveMetaSwap.sol";
import "src/interfaces/curve/ICurveStableSwap.sol";
import "src/libraries/TokenUtils.sol";
import "src/interfaces/IWETH9.sol";
contract CurveEthPoolAdapter is IPoolAdapter {
address public immutable override pool;
mapping(address => int128) public tokenIds;
bool public isMetapool;
address public immutable weth;
constructor(address _pool, address[] memory _tokens, address _weth) {
weth = _weth;
pool = _pool;
for (uint256 i; i < _tokens.length; i++) {
tokenIds[_tokens[i]] = int128(int256(i));
}
}
/// @inheritdoc IPoolAdapter
function getDy(
address inputToken,
address outputToken,
uint256 inputAmount
) external view override returns (uint256) {
return ICurveStableSwap(pool).get_dy(tokenIds[inputToken], tokenIds[outputToken], inputAmount);
}
/// @inheritdoc IPoolAdapter
function melt(
address inputToken,
address outputToken,
uint256 inputAmount,
uint256 minimumAmountOut
) external override returns (uint256) {
IWETH9(weth).withdraw(inputAmount);
return
ICurveStableSwap(pool).exchange{ value: inputAmount }(
tokenIds[inputToken],
tokenIds[outputToken],
inputAmount,
minimumAmountOut,
msg.sender
);
}
receive() external payable {}
}