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

Replaces next reserves by deltas in swap functions #42

Merged
109 commits merged into from
Mar 13, 2024
Merged

Conversation

clemlak
Copy link
Contributor

@clemlak clemlak commented Mar 1, 2024

This PR refactors the swap functions of DFMM and strategy contracts to use deltas instead of reserves.

@clemlak clemlak self-assigned this Mar 1, 2024
@clemlak clemlak added 🧹 improvement Code improvements or cleanup 📃 contracts Anything related to the DFMM contracts (or strategies) labels Mar 1, 2024
@clemlak clemlak added this to the ❄️ Contracts Freeze milestone Mar 1, 2024
clemlak added 27 commits March 7, 2024 13:32
Comment on lines +93 to +97
int256 a = Gaussian.ppf(int256(rX.divWadDown(L)));
int256 b =
Gaussian.ppf(int256(rY.divWadDown(L.mulWadDown(params.mean))));
return a + b + int256(params.width);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This will make it too difficult to do the arb loop since invalid inputs will cause reverts instead of return values, why was it changed? If rx / L is truncated to 0 it will cause ppf to revert.

Comment on lines +162 to 181
function _computeDeltaXGivenDeltaL(
uint256 deltaLiquidity,
IDFMM.Pool calldata pool,
bytes memory
) internal pure override returns (uint256) {
return pool.reserveX.mulWadDown(
deltaLiquidity.divWadDown(pool.totalLiquidity)
);
}

function _computeDeltaYGivenDeltaL(
uint256 deltaLiquidity,
IDFMM.Pool calldata pool,
bytes memory
) internal pure override returns (uint256) {
return pool.reserveY.mulWadDown(
deltaLiquidity.divWadDown(pool.totalLiquidity)
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These functions use the same rounding direction for both allocate and deallocate, which means we can take advantage of the rounding direction and potentially take more out than we put in

@clemlak clemlak closed this pull request by merging all changes into main in 704df34 Mar 13, 2024
@clemlak clemlak deleted the feat/delta-params-swap branch March 13, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📃 contracts Anything related to the DFMM contracts (or strategies) 🧹 improvement Code improvements or cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants