-
Notifications
You must be signed in to change notification settings - Fork 17
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
Yield fees (Step 2) #210
Yield fees (Step 2) #210
Conversation
# Conflicts: # pkg/vault/contracts/Vault.sol
# Conflicts: # pkg/interfaces/contracts/vault/IVault.sol # pkg/pool-weighted/contracts/WeightedPool8020Factory.sol # pkg/pool-weighted/contracts/WeightedPoolFactory.sol # pkg/pool-weighted/test/foundry/WeightedPool.t.sol # pkg/vault/contracts/test/PoolFactoryMock.sol # pkg/vault/contracts/test/VaultMock.sol
# Conflicts: # pkg/vault/contracts/Vault.sol
Yield fees (Step 2)
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
# Conflicts: # pkg/vault/.forge-snapshots/vaultProtocolSwapFeeGivenIn.snap # pkg/vault/contracts/VaultExtension.sol # pkg/vault/test/Vault.test.ts
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.
Nice job with the tests.
I'll add a few more; just one more comment for now.
# Conflicts: # pkg/vault/.forge-snapshots/routerRemoveLiquidityNative.snap # pkg/vault/.forge-snapshots/routerRemoveLiquidityWETH.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquidityProportional.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquiditySingleTokenExactIn.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquiditySingleTokenExactOut.snap
# Conflicts: # pkg/vault/.forge-snapshots/routerAddLiquidityNative.snap # pkg/vault/.forge-snapshots/routerAddLiquidityWETH.snap # pkg/vault/.forge-snapshots/routerRemoveLiquidityNative.snap # pkg/vault/.forge-snapshots/routerRemoveLiquidityWETH.snap # pkg/vault/.forge-snapshots/routerSwapExactInNative.snap # pkg/vault/.forge-snapshots/routerSwapExactInWETH.snap # pkg/vault/.forge-snapshots/vaultAddLiquiditySingleTokenExactOut.snap # pkg/vault/.forge-snapshots/vaultAddLiquidityUnbalanced.snap # pkg/vault/.forge-snapshots/vaultProtocolSwapFeeGivenIn.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquidityProportional.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquiditySingleTokenExactIn.snap # pkg/vault/.forge-snapshots/vaultRemoveLiquiditySingleTokenExactOut.snap # pkg/vault/.forge-snapshots/vaultSwapExactIn.snap # pkg/vault/.forge-snapshots/vaultSwapFeeGivenIn.snap
TokenType tokenType = poolData.tokenConfig[i].tokenType; | ||
|
||
// Do not charge yield fees until the pool is initialized. | ||
// ERC4626 tokens always pay yield fees; WITH_RATE tokens pay unless exempt. |
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.
The flag yieldFeeExempt
is essentially ignored for ERC4626 in this case. This is not really clear in how we define the TokenConfig
currently and will cause some confusion.
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.
I've updated the TokenConfig documentation. I believe it's true that ERC4646 tokens charge yield fees by definition, and cannot be marked exempt. In the buffer PR #250, it explicitly checks for this (vs silently failing). This was something in the old "internal buffer" PR that didn't get copied over to the external pool one, so good catch.
# Conflicts: # pkg/vault/contracts/Vault.sol # pkg/vault/contracts/VaultExtension.sol
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.
Great job @EndymionJkb . Thank you for adding tests @jubeira 🙏
Description
Introduce yield fee computation in
computePoolData
(formerlygetPoolData
).There are some tricky reentrancy issues. I believe
computePoolData
has to update the balances (otherwise, the "before" call on a swap would be inaccurate), which means it needs to be reentrant.This is fine except for
initialize
(probably should be initializePool, come to think of it, so that people don't think the Vault is being initialized...), which is already reentrant. So I made a non-reentrantinitialize
(with no external calls), and a reentrant_initialize
with the callback, similar to swap/_swap, addLiquidity/_addLiquidity, etc.Generalized the protocol fee handling (since we now have both swap and yield fees, which are collected together), and added events to enable fine-grained tracking by pool (and also validation through a simple invariant).
Deferring "boosted" pool handling, buffers, etc. And deferring optimizing pool balance storage (see separate PR for the infrastructure for that), since those are huge things by themselves.
Type of change
Checklist:
main
, or there's a description of how to mergeIssue Resolution
Closes #171