-
Notifications
You must be signed in to change notification settings - Fork 54
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
BAL Hookathon - Volatility Fee Hook #87
base: main
Are you sure you want to change the base?
Conversation
Someone is attempting to deploy a commit to the Matt Pereira's projects Team on Vercel. A member of the Team first needs to authorize it. |
// Constructor | ||
// Add Trusted Roter and Allowed Factory for the Hook at Deployment | ||
constructor(IVault vault,address allowedFactory, address router) VaultGuard(vault) Ownable(msg.sender) { | ||
_trustedRouter = router; |
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.
It looks like _trustedRouter
is unused, any reason why it was included here?
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 took the boilerplate code from ExampleHooks
and must have missed it since my linter wasn’t on. It’s not particularly useful in its current state, but it could add an extra layer of security if implemented in onComputeDynamicSwapFeePercentage
, similar to how it’s used in veBALFeeDiscountHook.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.
Hey there, daniel from Balancer here! Overall, the hook code is well written and easy to understand. Great work @t-phoenix!
- As you noted, you use a constant product rather than the pool's math. It'd be better to port
WeightedMath.sol
orStableMath.sol
since you have an allowed factory, you can scope it to a single invariant. - You're applying fees based on a single swap, whereas I'd expect a volatility fee needs to account for a period of time to be effective. To illustrate the point, an informed user would just split a large swap into several smaller swaps to bypass the volatility hook implementation you've presented.
Hey @danielmkm,
I might be missing or overlooking at things, please feel free to connect. I all am here for learning. |
🪝Volatility Fee Hook
A dynamic Swap Fee hook based on volatiltiy of the pool. The Hook calculates utilization ratio based on Amount of Token Out and Balance of Token Out in the pool, and charges higher fee when the utilization ratio increases.
🔑Key Advantages
⭐️Volatility Fee Hook v1
was developed simply to discretely distinguish fee ranges:
Technicals:
Developers can update the fee charge ranges in
function _calculateSwapFee
.packages/foundry/contracts/hooks/VolatiltiyFeeHook.sol
packages/foundry/test/VolatilityFeeHook.t.sol
✨Volatility Fee Hook V2
v2 is developed on a continuous exponential curve for charging Swap Fee.
The core equation behind charging these swap fee is:
feeMultiplier = 1 + (utilization Ratio^2 * 99)
multiplying by 99 ensures that at max utilization the fee multiplier reaches 100x
packages/foundry/contracts/hooks/VolatiltiyFeeHookV2.sol
packages/foundry/scripts/08_DeployVolatiltiyFeePool.s.sol