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

Custom swap accounting with NoOps #299

Closed
wants to merge 21 commits into from
Closed

Conversation

emmaguo13
Copy link
Contributor

@emmaguo13 emmaguo13 commented Jul 6, 2023

Inspired by NoOp design from #291. @thogard785's commit is merged with this PR

Copy link
Contributor

@NoahZinsmeister NoahZinsmeister left a comment

Choose a reason for hiding this comment

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

i wonder if it's worth allowing pools to use a returned hooksDelta even in non-NO_OP cases...one reason is i think it's awkward if initialize can NO_OP (for example, sqrtPriceX96 remains 0 in this case, which i think means the pool is borked unless it exclusively uses no-ops going forward, which is fine for some pools but maybe not for others, and feels like a bit of a footgun). so, i think we should consider disallowing no-op on initialize, but the delta logic could still be useful for hooks to levy an initial fee or incentivize the creator or something?

i also don't really think we should allow calling after* hooks when NO_OP is used

finally i think a version of _accountNoOp that applies fees would be valuable to see. for the sake of clarity it might make sense to write that as a stacked PR on top of this one

.gitmodules Outdated Show resolved Hide resolved
contracts/PoolManager.sol Outdated Show resolved Hide resolved
contracts/PoolManager.sol Outdated Show resolved Hide resolved
contracts/PoolManager.sol Outdated Show resolved Hide resolved
contracts/types/BalanceDelta.sol Outdated Show resolved Hide resolved
contracts/types/BalanceDelta.sol Outdated Show resolved Hide resolved
@emmaguo13
Copy link
Contributor Author

NoOping on initialize will prevent the pool with that hook from being included in our pools mapping, so I think it should be removed.

@@ -108,6 +108,25 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, ERC1155, IERC1155Rec
return pools[id].positions.get(owner, tickLower, tickUpper);
}

function _accountNoOp(PoolKey memory key, BalanceDelta hookDelta) internal {
// NOTE: we are in the lock state of the user, not the hook, unless the hook is the user
_accountDelta(key.currency0, hookDelta.amount0());
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not just use _accountPoolBalanceDelta for the whole hookDelta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in most current commit, but it increases gas for modifyPosition by 56 and swap by 17

contracts/PoolManager.sol Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
contracts/PoolManager.sol Outdated Show resolved Hide resolved
@snreynolds
Copy link
Member

Closing in favor of this NoOp impl #324

@snreynolds snreynolds closed this Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants