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

Fee accrual as 1155 balance #289

Closed
wants to merge 1 commit into from

Conversation

kevin-fruitful
Copy link

@kevin-fruitful kevin-fruitful commented Jun 30, 2023

Related Issue

Referencing issue #203

Description of changes

Removed the 2 mappings protocolFeesAccrued and hookFeesAccrued.
swap and modifyPosition now mint ERC1155 currencies to the protocolFeeController and a pool's hook contract.

collectProtocolFees and collectHookFees now burn ERC1155 currencies.

Respective tests have been updated. Implemented onERC1155Received and onERC1155BatchReceived for ProtocolFeeControllerTest and MockHooks test contracts.

Additional thoughts

Change _balances from private to internal such that the variable can be read directly instead of going through balanceOf.

@kevin-fruitful kevin-fruitful changed the title refactor: fee accrual as 1155 balance Fee accrual as 1155 balance Jun 30, 2023
protocolFeesAccrued[currency] -= amountCollected;
amountCollected = (amount == 0) ? balanceOf(address(protocolFeeController), currency.toId()) : amount;

_burn(address(protocolFeeController), currency.toId(), amountCollected);
Copy link

@hiroshitashir hiroshitashir Jul 5, 2023

Choose a reason for hiding this comment

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

I'm not an official reviewer so I could be wrong. I just want someone more knowledgeable to take a look.

I wonder if we want to call _burn when msg.sender == address(protocolFeeController) since it's calling currency.transfer below.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review!

In this singleton design, all ERC20s are held by the Pool Manager contract. Individual pool balances of ERC20s (aka currencies) are being accounted for within this Pool Manager contract.

This internal call burn() is decreasing the ERC1155 balance (or "internal" balance) of the protocol fee controller's fee token (some ERC20). Then, currency.transfer is transferring (ERC20.transfer()) the fee token rom the pool manager to the (external) protocol fee controller.

Let me know if that makes sense or if I'm misunderstanding something! Thanks!

recipient = (recipient == address(0)) ? hookAddress : recipient;

hookFeesAccrued[hookAddress][currency] -= amountCollected;
_burn(hookAddress, currency.toId(), amountCollected);

Choose a reason for hiding this comment

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

Same here.

@NoahZinsmeister
Copy link
Contributor

thanks for the PR @kevin-fruitful (and @hiroshitash for the review)!

i'm inclined to leave this on ice for a while, not because it's bad, but because a) the state of 1155 tokens in the pool manager is a bit up in the air (see #294), and b) using 1155 balances would probably complicate designs where custom hooks are custodying funds as 1155 balances

keeping the PR open as a reference though, and it might make sense to merge depending on where we land with 1155!

@NoahZinsmeister NoahZinsmeister added the blocked Waiting a dependency label Jul 6, 2023
@hensha256
Copy link
Contributor

Hi! Going to close this PR now for a few reasons

  1. we have removed hook fees accruing in the contract and instead they are achieved in other methods (Remove hook fees and protocol fee on withdrawal #432)
  2. we now use 6909s instead of 1155s (6909 fixed #446)
  3. we tried to accrue protocol fees as 6909s (Accumulate protocol fees as 6909s  #449) but closed this as it made swap costs increase dramatically due to the event emitted when minting a 6909

Thanks again for your submission

@hensha256 hensha256 closed this Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting a dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants