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

posm: CLEAR_OR_TAKE #252

Merged
merged 9 commits into from
Aug 2, 2024
Merged

posm: CLEAR_OR_TAKE #252

merged 9 commits into from
Aug 2, 2024

Conversation

saucepoint
Copy link
Collaborator

Related Issue

Closes #248

Description of changes

Refactor CLEAR to use _take() if the delta exceeds the user's limit

@saucepoint saucepoint added the posm position manager label Aug 2, 2024
Comment on lines 214 to 216
int256 currencyDelta = poolManager.currencyDelta(address(this), currency);
if (uint256(currencyDelta) > amountMax) revert ClearExceedsMaxAmount(currency, currencyDelta, amountMax);
poolManager.clear(currency, uint256(currencyDelta));
if (currencyDelta < 0) revert CannotClearNegativeDelta(currency);
uint256 delta = uint256(currencyDelta); // safe since we know its positive
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

wonder if this should be replaced with _getFullTakeAmount? the error might need to be updated

    function _getFullTakeAmount(Currency currency) internal view returns (uint256 amount) {
        int256 _amount = poolManager.currencyDelta(address(this), currency);
        // If the amount is negative, it should be settled not taken.
        if (_amount < 0) revert IncorrectUseOfTake();
        amount = uint256(_amount);
    }

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we could change both of those functions to be instead

_getFullNegativeDelta and _getFullPositiveDelta and the error be more general like DeltaIsNotNegative()/DeltaIsNotPositive()

Copy link
Member

@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

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

this looks great but I know there are merge conflicts cause we just merged something for router

amount = uint256(-_amount);
}

function _getFullTakeAmount(Currency currency) internal view returns (uint256 amount) {
function _getFullNegativeDelta(Currency currency) internal view returns (uint256 amount) {
Copy link
Contributor

@hensha256 hensha256 Aug 2, 2024

Choose a reason for hiding this comment

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

yeah nice rename

Copy link
Member

Choose a reason for hiding this comment

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

we did a bettttter rename i promise

}

/// @dev uses this addresses balance to settle a negative delta
function _settleWithBalance(Currency currency) internal {
Copy link
Member

Choose a reason for hiding this comment

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

remove this

}

function _settlePair(Currency currency0, Currency currency1) internal {
// the locker is the payer when settling
address caller = msgSender();
_settle(currency0, caller, _getFullSettleAmount(currency0));
_settle(currency1, caller, _getFullSettleAmount(currency1));
_settle(currency0, caller, _getFullDebit(currency0));
Copy link
Member

Choose a reason for hiding this comment

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

debt

@saucepoint saucepoint merged commit eee5a0e into main Aug 2, 2024
3 checks passed
@saucepoint saucepoint deleted the posm-clear-or-take branch August 2, 2024 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
posm position manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

posm: CLEAR_OR_TAKE
3 participants