-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: Solvers clean #116
Changes from 5 commits
f0b5ebc
a19b93c
34249eb
3d98aa4
2a8ceec
46cbea6
793697c
ec990d7
a24019a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,19 @@ import { | |
encodeFeeUpdate, | ||
encodeControllerUpdate | ||
} from "./ConstantSumUtils.sol"; | ||
import { | ||
computeAllocationGivenX, | ||
computeAllocationGivenY | ||
} from "src/lib/StrategyLib.sol"; | ||
import { | ||
ONE, | ||
computeInitialPoolData, | ||
FixedPointMathLib, | ||
computeSwapDeltaLiquidity | ||
} from "./ConstantSumMath.sol"; | ||
import { PairSolver } from "src/PairSolver.sol"; | ||
|
||
contract ConstantSumSolver { | ||
contract ConstantSumSolver is PairSolver { | ||
error NotEnoughLiquidity(); | ||
|
||
using FixedPointMathLib for uint256; | ||
|
@@ -46,6 +51,7 @@ contract ConstantSumSolver { | |
uint256 deltaLiquidity; | ||
} | ||
|
||
/// @notice used by kit | ||
function simulateSwap( | ||
uint256 poolId, | ||
bool swapXIn, | ||
|
@@ -91,6 +97,7 @@ contract ConstantSumSolver { | |
return (valid, state.amountOut, swapData); | ||
} | ||
|
||
/// @notice used by kit | ||
function preparePriceUpdate(uint256 newPrice) | ||
public | ||
pure | ||
|
@@ -99,6 +106,7 @@ contract ConstantSumSolver { | |
return encodePriceUpdate(newPrice); | ||
} | ||
|
||
/// @notice used by kit | ||
function prepareSwapFeeUpdate(uint256 newSwapFee) | ||
public | ||
pure | ||
|
@@ -107,11 +115,50 @@ contract ConstantSumSolver { | |
return encodeFeeUpdate(newSwapFee); | ||
} | ||
|
||
/// @notice used by kit | ||
function prepareControllerUpdate(address newController) | ||
public | ||
pure | ||
returns (bytes memory) | ||
{ | ||
return encodeControllerUpdate(newController); | ||
} | ||
|
||
function getReservesAndLiquidity(uint256 poolId) | ||
public | ||
view | ||
override | ||
returns (uint256, uint256, uint256) | ||
{ | ||
Pool memory pool = IDFMM(IStrategy(strategy).dfmm()).pools(poolId); | ||
return (pool.reserves[0], pool.reserves[1], pool.totalLiquidity); | ||
} | ||
|
||
function getPoolParams(uint256 poolId) | ||
public | ||
view | ||
returns (ConstantSumParams memory) | ||
{ | ||
return abi.decode( | ||
IStrategy(strategy).getPoolParams(poolId), (ConstantSumParams) | ||
); | ||
} | ||
|
||
// 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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} |
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.
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.
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'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.
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.
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.