-
Notifications
You must be signed in to change notification settings - Fork 512
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
posm: CLEAR_OR_TAKE #252
Conversation
src/PositionManager.sol
Outdated
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 |
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.
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);
}
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.
Yeah we could change both of those functions to be instead
_getFullNegativeDelta and _getFullPositiveDelta and the error be more general like DeltaIsNotNegative()/DeltaIsNotPositive()
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.
this looks great but I know there are merge conflicts cause we just merged something for router
src/base/DeltaResolver.sol
Outdated
amount = uint256(-_amount); | ||
} | ||
|
||
function _getFullTakeAmount(Currency currency) internal view returns (uint256 amount) { | ||
function _getFullNegativeDelta(Currency currency) internal view returns (uint256 amount) { |
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.
yeah nice rename
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.
we did a bettttter rename i promise
src/PositionManager.sol
Outdated
} | ||
|
||
/// @dev uses this addresses balance to settle a negative delta | ||
function _settleWithBalance(Currency currency) internal { |
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.
remove this
src/PositionManager.sol
Outdated
} | ||
|
||
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)); |
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.
debt
Related Issue
Closes #248
Description of changes
Refactor CLEAR to use
_take()
if the delta exceeds the user's limit