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

feat: Solvers clean #116

Closed
wants to merge 9 commits into from
Closed

feat: Solvers clean #116

wants to merge 9 commits into from

Conversation

0xJepsen
Copy link
Contributor

@0xJepsen 0xJepsen commented Apr 2, 2024

Closes #115

I'm sure this can be cleaner but this does what I want.

@0xJepsen 0xJepsen changed the base branch from main to fix/spearbit-audit April 2, 2024 16:53
@kinrezC kinrezC marked this pull request as ready for review April 2, 2024 18:26
@kinrezC kinrezC requested review from clemlak, kinrezC, Autoparallel and Alexangelj and removed request for clemlak and kinrezC April 2, 2024 18:26
kinrezC
kinrezC previously approved these changes Apr 2, 2024
Copy link
Contributor

@Alexangelj Alexangelj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so new pair solver does the job for computing allocate/deallocate amounts? thats good

There's some issues with imports, formatting, styling, and natspec

Clement needs to review and sign off. Solvers are kind of not in scope of the audit because they are used as lens contracts, but they still should be as clean as the rest of the codebase

@Alexangelj
Copy link
Contributor

I also feel like this should be a PR outside of the audit fixes. I imagine we will continue to edit the solvers as we need, so these will continue to be "unaudited", but i'll leave this up to @clemlak to decide on what to do

@0xJepsen
Copy link
Contributor Author

0xJepsen commented Apr 2, 2024

Sure yeah review all you need.

@Alexangelj Alexangelj added 💡 feature New features 🚧 DO NOT MERGE 🚧 Do not merge 🛠️ kit Anything related to the DFMM kit labels Apr 2, 2024
@clemlak
Copy link
Contributor

clemlak commented Apr 3, 2024

I agree with Alex, maybe we should merge this into another branch later because the fix/spearbit-audit branch might be used by the auditors to check the fixes.

Comment on lines +57 to +59
function computePrice(ConstantSumParams memory params) pure returns (uint256) {
return params.price;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this one is needed? I understand that it might be for consistency regarding the other strategies but I think this one could just be an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really but makes the api the same between them all. I think general is better than bespoke so i advocate for keeping it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this, but if it lives in the ConstantSumMath.sol and it's not invoked anywhere in e.g. solver, or strategy it doesn't really do anything, so I'm not sure what to do with this at the moment.

Comment on lines 147 to 163
// These are same for allocation and deallocation
// delta y is 0
function PrepareAllocationDeltaGivenDeltaX(
uint256 poolId,
uint256 deltaX
) public view returns (bytes memory) {
ConstantSumParams memory params = getPoolParams(poolId);
uint256 deltaL = deltaX.mulWadDown(params.price);
return abi.encode(deltaX, 0, deltaL);
}

function PrepareAllocationDeltaGivenDeltaY(
// uint256 poolId,
uint256 deltaY
) public pure returns (bytes memory) {
return abi.encode(0, deltaY, deltaY);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NatSpec could be improved and the name of the functions should use camel case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed some of the natspec but i am unsure if i am most familiar with the conventions you would like to adhere to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of a PairSolver.

Comment on lines 84 to 115
function encodeAllocationDeltasGivenDeltaX(
uint256 deltaX,
uint256 reserveX,
uint256 reserveY,
uint256 liquidity
) pure returns (bytes memory) {
uint256 deltaY = computeDeltaYGivenDeltaX(deltaX, reserveX, reserveY);
uint256 deltaL = computeDeltaLGivenDeltaX(deltaX, liquidity, reserveX);
return abi.encode(deltaX, deltaY, deltaL);
}

function encodeAllocationDeltasGivenDeltaY(
uint256 deltaY,
uint256 reserveX,
uint256 reserveY,
uint256 liquidity
) pure returns (bytes memory) {
uint256 deltaX = computeDeltaXGivenDeltaY(deltaY, reserveX, reserveY);
uint256 deltaL = computeDeltaLGivenDeltaY(deltaY, liquidity, reserveY);
return abi.encode(deltaX, deltaY, deltaL);
}

function encodeAllocationDeltasGivenDeltaL(
uint256 deltaL,
uint256 reserveX,
uint256 reserveY,
uint256 liquidity
) pure returns (bytes memory) {
uint256 deltaX = computeDeltaXGivenDeltaL(deltaL, reserveX, liquidity);
uint256 deltaY = computeDeltaYGivenDeltaL(deltaL, reserveY, liquidity);
return abi.encode(deltaX, deltaY, deltaL);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if these functions should stay here, maybe we can have them in the PairStrategy contract directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would moving them change the api at all? If not i think moving them is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should for sure go in PairStrategy, clement is right

@@ -91,7 +90,7 @@ contract LogNormalSwapTest is LogNormalSetUp {

console2.log(invariant);

uint256 amountOut = preReserves[0] - rx;
uint256 amountOut = rX - rx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to rename these variables, that's not super explicit haha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed could be good.

Base automatically changed from fix/spearbit-audit to main April 3, 2024 14:54
@clemlak clemlak dismissed kinrezC’s stale review April 3, 2024 14:54

The base branch was changed.

@0xJepsen 0xJepsen removed the 🚧 DO NOT MERGE 🚧 Do not merge label Apr 5, 2024
@0xJepsen 0xJepsen requested a review from clemlak April 8, 2024 14:30
@0xJepsen 0xJepsen requested a review from Alexangelj April 8, 2024 14:30
Comment on lines +14 to +20
/**
* @title Pair strategy base contract for DFMM.
* @notice This abstract contract defines the basic behavior of
* a two-token strategy for DFMM. It is meant to be inherited by
* a concrete strategy implementation.
* @author Primitive
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong natspec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to change it? Not sure what the "right" natspec is. I don't really have any opinions on solidity but all the kits work uses this. I'm more of the opinion on RERO then high modernism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's time to finish our style guide 👀

@0xJepsen 0xJepsen mentioned this pull request Apr 8, 2024
@0xJepsen
Copy link
Contributor Author

Closed in favor of #130

@0xJepsen 0xJepsen closed this Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 feature New features 🛠️ kit Anything related to the DFMM kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify allocate and deallocate flow for solvers
4 participants