-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rETH #31
Open
julienmartinlevrai
wants to merge
32
commits into
master
Choose a base branch
from
reth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
rETH #31
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
264eae7
Support wsteth complex path, fix other tests
talbaneth e8c403a
fix typo - pooXlFee => poolXFee
talbaneth bab3e02
chore: copy WstETH callee into rETH callee
julienmartinlevrai e614913
feat: support rETH operations
julienmartinlevrai 3da7767
fix: remove outdated tests
julienmartinlevrai 697079e
test: add test file for rETH callee
julienmartinlevrai ca512e9
test: replace WstETH for rETH in baseline
julienmartinlevrai cdbbfe4
fix: reduce profit for SteCRV
julienmartinlevrai 2f594b2
test: use forge caching
julienmartinlevrai 5a79a16
feat: add rETH callee to Makefile flatten
julienmartinlevrai bbfedd6
chore: add block age to test file
julienmartinlevrai d660ad3
test: deploy Clipper
julienmartinlevrai b6081ff
test: deploy rETH join adapter
julienmartinlevrai ba044ee
test: rely join in vat
julienmartinlevrai e5574ee
fix: rETH balanceOf storage slot
julienmartinlevrai 94b83c7
test: init ilk in vat
julienmartinlevrai 1c6c064
feat: init ilk in spotter and jug
julienmartinlevrai 3cd9762
test: warp after ilk init in jug
julienmartinlevrai 910903a
test: file dog.hole for new ilk
julienmartinlevrai e9a5776
test: file ilk’s chop in dog
julienmartinlevrai 76d94f0
test: clipper permissions
julienmartinlevrai 8b6ae22
test: add abacus for new ilk
julienmartinlevrai d7bbe7e
test: fix curve pool address
julienmartinlevrai 4790bc8
feat: 2x Curve swap
julienmartinlevrai 4854df4
test: rely rETH clipper in dog
julienmartinlevrai c0e1056
test: file clipper params
julienmartinlevrai 3f30750
chore: use test-forge.sh
julienmartinlevrai 157fe46
fix: pass curve pools as constructor params
julienmartinlevrai 3728627
refactor: remove nbsp chars
julienmartinlevrai 17c783b
refactor: make code more similar to WstETH
julienmartinlevrai bca2ab6
ttake 1K reth intead of 3K in est_bigAmtWithComplexPath
talbaneth d505189
Add reth deployment data
talbaneth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/out | ||
/cache | ||
block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
// SPDX-FileCopyrightText: © 2022 Dai Foundation <www.daifoundation.org> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
pragma solidity >=0.6.12; | ||
pragma experimental ABIEncoderV2; | ||
|
||
interface GemJoinLike { | ||
function dec() external view returns (uint256); | ||
function gem() external view returns (address); | ||
function exit(address, uint256) external; | ||
} | ||
|
||
interface DaiJoinLike { | ||
function dai() external view returns (TokenLike); | ||
function join(address, uint256) external; | ||
} | ||
|
||
interface TokenLike { | ||
function approve(address, uint256) external; | ||
function transfer(address, uint256) external; | ||
function balanceOf(address) external view returns (uint256); | ||
function symbol() external view returns (string memory); | ||
} | ||
|
||
interface CharterManagerLike { | ||
function exit(address crop, address usr, uint256 val) external; | ||
} | ||
|
||
interface WstEthLike is TokenLike { | ||
function unwrap(uint256 _wstEthAmount) external returns (uint256); | ||
function stETH() external view returns (address); | ||
} | ||
|
||
interface CurvePoolLike { | ||
function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) | ||
external returns (uint256 dy); | ||
function coins(uint256 id) external view returns (address); | ||
} | ||
|
||
interface WethLike is TokenLike { | ||
function deposit() external payable; | ||
} | ||
|
||
interface UniV3RouterLike { | ||
|
||
struct ExactInputParams { | ||
bytes path; | ||
address recipient; | ||
uint256 deadline; | ||
uint256 amountIn; | ||
uint256 amountOutMinimum; | ||
} | ||
|
||
function exactInput(UniV3RouterLike.ExactInputParams calldata params) | ||
external payable returns (uint256 amountOut); | ||
} | ||
|
||
contract rETHCurveUniv3Callee { | ||
|
||
CurvePoolLike public immutable rocketToLido; | ||
CurvePoolLike public immutable lidoToETH; | ||
UniV3RouterLike public immutable uniV3Router; | ||
DaiJoinLike public immutable daiJoin; | ||
TokenLike public immutable dai; | ||
address public immutable weth; | ||
|
||
uint256 public constant RAY = 10 ** 27; | ||
|
||
function _add(uint x, uint y) internal pure returns (uint z) { | ||
require((z = x + y) >= x, "ds-math-add-overflow"); | ||
} | ||
function _sub(uint x, uint y) internal pure returns (uint z) { | ||
require((z = x - y) <= x, "ds-math-sub-underflow"); | ||
} | ||
function _divup(uint256 x, uint256 y) internal pure returns (uint256 z) { | ||
z = _add(x, _sub(y, 1)) / y; | ||
} | ||
|
||
constructor( | ||
address rocketToLido_, | ||
address lidoToETH_, | ||
address uniV3Router_, | ||
address daiJoin_, | ||
address weth_ | ||
) public { | ||
rocketToLido = CurvePoolLike(rocketToLido_); | ||
lidoToETH = CurvePoolLike(lidoToETH_); | ||
uniV3Router = UniV3RouterLike(uniV3Router_); | ||
daiJoin = DaiJoinLike(daiJoin_); | ||
TokenLike dai_ = DaiJoinLike(daiJoin_).dai(); | ||
dai = dai_; | ||
weth = weth_; | ||
|
||
dai_.approve(daiJoin_, type(uint256).max); | ||
} | ||
|
||
receive() external payable {} | ||
|
||
function _fromWad(address gemJoin, uint256 wad) internal view returns (uint256 amt) { | ||
amt = wad / 10 ** (_sub(18, GemJoinLike(gemJoin).dec())); | ||
} | ||
|
||
function clipperCall( | ||
address sender, // Clipper caller, pays back the loan | ||
uint256 owe, // Dai amount to pay back [rad] | ||
uint256 slice, // Gem amount received [wad] | ||
bytes calldata data // Extra data, see below | ||
) external { | ||
( | ||
address to, // address to send remaining DAI to | ||
address gemJoin, // gemJoin adapter address | ||
uint256 minProfit, // minimum profit in DAI to make [wad] | ||
bytes memory path, // uniswap v3 path | ||
address charterManager // pass address(0) if no manager | ||
) = abi.decode(data, (address, address, uint256, bytes, address)); | ||
|
||
address gem = GemJoinLike(gemJoin).gem(); // RocketPool rETH | ||
|
||
// Convert slice to token precision | ||
slice = _fromWad(gemJoin, slice); | ||
|
||
// Exit gem to token | ||
if(charterManager != address(0)) { | ||
CharterManagerLike(charterManager).exit(gemJoin, address(this), slice); | ||
} else { | ||
GemJoinLike(gemJoin).exit(address(this), slice); | ||
} | ||
|
||
// rETH -> wstETH | ||
TokenLike(gem).approve(address(rocketToLido), slice); | ||
slice = rocketToLido.exchange({ | ||
i: 0, // send token id 1 (RocketPool rETH) | ||
j: 1, // receive token id 0 (wstETH) | ||
dx: slice, // send `slice` amount of rETH | ||
min_dy: 0 // accept any amount of ETH (`minProfit` is checked below) | ||
}); | ||
gem = rocketToLido.coins(1); | ||
|
||
// wstETH -> stETH | ||
slice = WstEthLike(gem).unwrap(slice); | ||
gem = WstEthLike(gem).stETH(); | ||
|
||
// stETH -> ETH | ||
TokenLike(gem).approve(address(lidoToETH), slice); | ||
slice = lidoToETH.exchange({ | ||
i: 1, // send token id 1 (stETH) | ||
j: 0, // receive token id 0 (ETH) | ||
dx: slice, // send `slice` amount of stETH | ||
min_dy: 0 // accept any amount of ETH (`minProfit` is checked below) | ||
}); | ||
|
||
// ETH -> wETH | ||
gem = weth; | ||
WethLike(gem).deposit{ | ||
value: slice | ||
}(); | ||
|
||
// Approve uniV3 to take gem | ||
WethLike(gem).approve(address(uniV3Router), slice); | ||
|
||
// Calculate amount of DAI to Join (as erc20 WAD value) | ||
uint256 daiToJoin = _divup(owe, RAY); | ||
|
||
// Do operation and get dai amount bought (checking the profit is achieved) | ||
UniV3RouterLike.ExactInputParams memory params = UniV3RouterLike.ExactInputParams({ | ||
path: path, | ||
recipient: address(this), | ||
deadline: block.timestamp, | ||
amountIn: slice, | ||
amountOutMinimum: _add(daiToJoin, minProfit) | ||
}); | ||
uniV3Router.exactInput(params); | ||
|
||
// Although Uniswap will accept all gems, this check is a sanity check, just in case | ||
// Transfer any lingering gem to specified address | ||
if (WethLike(gem).balanceOf(address(this)) > 0) { | ||
WethLike(gem).transfer(to, WethLike(gem).balanceOf(address(this))); | ||
} | ||
|
||
// Convert DAI bought to internal vat value of the msg.sender of Clipper.take | ||
daiJoin.join(sender, daiToJoin); | ||
|
||
// Transfer remaining DAI to specified address | ||
dai.transfer(to, dai.balanceOf(address(this))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that we have these tests replaced in a pending PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did a really great job of replacing these tests.