-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add src and tests #1
base: main
Are you sure you want to change the base?
Conversation
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.
LGTM, have two minor comments but nothing major.
function getDbrOut(uint dolaIn) public view returns (uint dbrOut) { | ||
require(dolaIn > 0, "dolaIn must be positive"); | ||
(uint dolaReserve, uint dbrReserve) = auction.getCurrentReserves(); | ||
uint numerator = dolaIn * dbrReserve; | ||
uint denominator = dolaReserve + dolaIn; | ||
dbrOut = numerator / denominator; | ||
} | ||
|
||
function getDolaIn(uint dbrOut) public view returns (uint dolaIn) { | ||
require(dbrOut > 0, "dbrOut must be positive"); | ||
(uint dolaReserve, uint dbrReserve) = auction.getCurrentReserves(); | ||
uint numerator = dbrOut * dolaReserve; | ||
uint denominator = dbrReserve - dbrOut; | ||
dolaIn = (numerator / denominator) + 1; | ||
} | ||
|
||
function swapExactDolaForDbr(uint dolaIn, uint dbrOutMin) external returns (uint dbrOut) { | ||
dbrOut = getDbrOut(dolaIn); | ||
require(dbrOut >= dbrOutMin, "dbrOut must be greater than dbrOutMin"); | ||
dola.transferFrom(msg.sender, address(this), dolaIn); | ||
auction.buyDBR(dolaIn, dbrOut, msg.sender); | ||
} | ||
|
||
function swapDolaForExactDbr(uint dbrOut, uint dolaInMax) external returns (uint dolaIn) { | ||
dolaIn = getDolaIn(dbrOut); | ||
require(dolaIn <= dolaInMax, "dolaIn must be less than dolaInMax"); | ||
dola.transferFrom(msg.sender, address(this), dolaIn); | ||
auction.buyDBR(dolaIn, dbrOut, msg.sender); | ||
} |
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.
Would be more gas efficient to have this functionality in the auction itself, to avoid the double transfer, but ultimately not a big deal, as MEV bots can always do the math themselves.
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.
It would. But also it would prevent us from upgrading the Helper functions in the future. imo we're likely going to create some universal DBR helper in the future that incorporates this virtual market, sDOLA's virtual market and other markets such as TriDBR in a single Router.
lgtm. |
No description provided.