-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implement VIPs for MakerPSM -- PRO-115 #46
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1b345c2
Implement VIPs for MakerPSM
duncancmt 6d7744f
Contract too large; optimize bips math to avoid use of unnecessary Fu…
duncancmt 7389208
natspec
duncancmt f23067c
Merge branch 'list_of_amms' into makerpsm
duncancmt 2f47544
Announce support for MakerPSM in compatibility matrix
duncancmt e52c6fd
Contract too large
duncancmt 78d753b
Contract too large
duncancmt da5934c
Contract too large
duncancmt 0e0ea00
Drop support for ZeroEx (protocol v4) through a VIP; limit orders are…
duncancmt 64f40a2
Add OTC partial fill test
duncancmt bc6230c
Update gas table
duncancmt 85a0eba
Add test for UniV2 multihop
duncancmt d560718
Golf UniV2 multihop
duncancmt 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 @@ | ||
136655 | ||
136638 |
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 @@ | ||
160506 | ||
160489 |
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 @@ | ||
153015 | ||
142580 |
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 @@ | ||
189118 |
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 @@ | ||
212990 |
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 @@ | ||
195056 |
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 @@ | ||
145780 | ||
172912 |
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 @@ | ||
174977 | ||
202822 |
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 @@ | ||
160683 | ||
188244 |
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 @@ | ||
180742 |
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 @@ | ||
212708 |
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 @@ | ||
197858 |
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,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.21; | ||
|
||
import {ERC20} from "solmate/src/tokens/ERC20.sol"; | ||
|
||
import {SafeTransferLib} from "../utils/SafeTransferLib.sol"; | ||
import {UnsafeMath} from "../utils/UnsafeMath.sol"; | ||
|
||
interface IPSM { | ||
/// @dev Get the fee for selling DAI to USDC in PSM | ||
/// @return tout toll out [wad] | ||
function tout() external view returns (uint256); | ||
|
||
/// @dev Get the address of the underlying vault powering PSM | ||
/// @return address of gemJoin contract | ||
function gemJoin() external view returns (address); | ||
|
||
/// @dev Sell USDC for DAI | ||
/// @param usr The address of the account trading USDC for DAI. | ||
/// @param gemAmt The amount of USDC to sell in USDC base units | ||
function sellGem(address usr, uint256 gemAmt) external; | ||
|
||
/// @dev Buy USDC for DAI | ||
/// @param usr The address of the account trading DAI for USDC | ||
/// @param gemAmt The amount of USDC to buy in USDC base units | ||
function buyGem(address usr, uint256 gemAmt) external; | ||
} | ||
|
||
abstract contract MakerPSM { | ||
using UnsafeMath for uint256; | ||
using SafeTransferLib for ERC20; | ||
|
||
// Maker units https://github.com/makerdao/dss/blob/master/DEVELOPING.md | ||
// wad: fixed point decimal with 18 decimals (for basic quantities, e.g. balances) | ||
uint256 internal constant WAD = 10 ** 18; | ||
|
||
ERC20 internal immutable DAI; | ||
|
||
constructor(address dai) { | ||
DAI = ERC20(dai); | ||
} | ||
|
||
function makerPsmSellGem(address recipient, uint256 bips, IPSM psm, ERC20 gemToken) internal { | ||
// phantom overflow can't happen here because PSM prohibits gemToken with decimals > 18 | ||
uint256 sellAmount = (gemToken.balanceOf(address(this)) * bips).unsafeDiv(10_000); | ||
gemToken.safeApproveIfBelow(psm.gemJoin(), sellAmount); | ||
psm.sellGem(recipient, sellAmount); | ||
} | ||
|
||
function makerPsmBuyGem(address recipient, uint256 bips, IPSM psm, ERC20 gemToken) internal { | ||
// phantom overflow can't happen here because DAI has decimals = 18 | ||
uint256 sellAmount = (DAI.balanceOf(address(this)) * bips).unsafeDiv(10_000); | ||
unchecked { | ||
uint256 feeDivisor = psm.tout() + WAD; // eg. 1.001 * 10 ** 18 with 0.1% fee [tout is in wad]; | ||
// overflow can't happen at all because DAI is reasonable and PSM prohibits gemToken with decimals > 18 | ||
uint256 buyAmount = (sellAmount * 10 ** uint256(gemToken.decimals())).unsafeDiv(feeDivisor); | ||
|
||
DAI.safeApproveIfBelow(address(psm), sellAmount); | ||
psm.buyGem(recipient, buyAmount); | ||
} | ||
} | ||
} |
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.
previous versions of this comparison weren't accurate because they failed to actually transfer the buy token to the taker. this PR rectifies that oversight in the unit test, massively increasing the gas consumed