Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Add src and tests #1

wants to merge 7 commits into from

Conversation

nourharidy
Copy link
Member

No description provided.

Copy link

@08xmt 08xmt left a 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.

src/Auction.sol Outdated Show resolved Hide resolved
Comment on lines +28 to +56
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);
}
Copy link

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.

Copy link
Member Author

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.

@wavey0x
Copy link

wavey0x commented Dec 23, 2023

lgtm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants