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 : use actions router, remove return vals #214

Merged
merged 16 commits into from
Jul 30, 2024
Merged

Conversation

snreynolds
Copy link
Member

Related Issue

Which issue does this pull request resolve?

Description of changes

@snreynolds snreynolds marked this pull request as ready for review July 27, 2024 16:57
@saucepoint saucepoint added the posm position manager label Jul 27, 2024
saucepoint
saucepoint previously approved these changes Jul 27, 2024
Copy link
Collaborator

@saucepoint saucepoint left a comment

Choose a reason for hiding this comment

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

quite surprised we're saving a few thousand gas per call 😎

src/PositionManager.sol Show resolved Hide resolved
@snreynolds snreynolds changed the title posm : Use actions router posm : use actions router, remove return vals Jul 29, 2024
Comment on lines +76 to +86
if (action == Actions.INCREASE_LIQUIDITY) {
_increase(params);
} else if (action == Actions.DECREASE_LIQUIDITY) {
_decrease(params);
} else if (action == Actions.MINT_POSITION) {
_mint(params);
} else if (action == Actions.CLOSE_CURRENCY) {
_close(params);
} else if (action == Actions.BURN_POSITION) {
// Will automatically decrease liquidity to 0 if the position is not already empty.
_burn(params);
Copy link
Collaborator

Choose a reason for hiding this comment

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

dont need to change it now, and its more a discussion bit --

I think decoding the parameters before making the internal calls makes the internal function signatures much more readable (and easier to reference)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this makes gas go down quite a bit though bc we're just passing calldata

}

function _modifyLiquidity(PositionConfig memory config, int256 liquidityChange, bytes32 salt, bytes memory hookData)
internal
returns (BalanceDelta liquidityDelta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we still need to return liquidityDelta because of slippage checks inside the internal functions

unless slippage should be on the CLOSE command 🤔

Comment on lines 138 to 140
function snapLastDelta() internal view returns (BalanceDelta delta) {
delta = hook.deltas(hook.getDeltasLength() - 1); // just want the most recetly written to delta
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: imo a better name is getLastDelta

Copy link
Collaborator

Choose a reason for hiding this comment

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

also I think this (and HookSavesDelta hook;) belongs in PosmTestSetup.sol

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agreed snap we use for gas snapshots - definitely prefer getLastDelta

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yes good catch, originally had it in LiquidityOperations cause I was referencing it but will change

Comment on lines 138 to 140
function snapLastDelta() internal view returns (BalanceDelta delta) {
delta = hook.deltas(hook.getDeltasLength() - 1); // just want the most recetly written to delta
}
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agreed snap we use for gas snapshots - definitely prefer getLastDelta

plan.actions = actions;
plan.params = params;

return plan;
}

function finalize(Plan memory plan, PoolKey memory poolKey) internal pure returns (bytes memory) {
Copy link
Contributor

Choose a reason for hiding this comment

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

imo this should now be called finalizeModifyLiquidity or something? To differentiate between what finalizeSwap and finalize are

test/position-managers/PositionManager.t.sol Outdated Show resolved Hide resolved
test/position-managers/PositionManager.t.sol Outdated Show resolved Hide resolved
test/shared/PosmTestSetup.sol Outdated Show resolved Hide resolved
test/position-managers/NativeToken.t.sol Outdated Show resolved Hide resolved
if (positionConfigs[tokenId] != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);

// Note: the tokenId is used as the salt.
BalanceDelta delta = _modifyLiquidity(config, -(liquidity.toInt256()), bytes32(tokenId), hookData);
return abi.encode(delta);
BalanceDelta liquidityDelta = _modifyLiquidity(config, -(liquidity.toInt256()), bytes32(tokenId), hookData);
Copy link
Contributor

Choose a reason for hiding this comment

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

this liquidityDelta is unused in all these functions? whats it for?

Copy link
Member Author

Choose a reason for hiding this comment

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

its for slippage checks - sauce is working on that

@@ -29,7 +31,8 @@ contract PositionManager is
Multicall,
SafeCallback,
Copy link
Contributor

Choose a reason for hiding this comment

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

can remove SafeCallback from this list now - thats inherited by BaseActionsRouter

@snreynolds snreynolds merged commit a96a8f6 into main Jul 30, 2024
3 checks passed
@snreynolds snreynolds deleted the use-actions-router branch July 30, 2024 17:32
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.

3 participants