This repository contains the implementation of two smart contracts: Debt Allocator and Accountant, designed to solve the slippage issue during Yearn V3 Vault rebalancing. The solution not only removes slippage risks for users but also incentivizes rebalancers, ensuring no cost for user and decentralized vault management. Inside this contract deposit function with slippage protection is added from ERC4626 router. If user wants to be protected from slippage when depositing he should use this function and when he wants to be protected from slippage he should user withdraw or redeem function from YearnV3 vault that already has slippage protection.
Yearn V3 Vaults allocate funds to various strategies, each with a target allocation percentage. However, during rebalancing (depositing or withdrawing funds into strategies), slippage may occur, causing potential loss of funds. This project introduces a two-contract solution:
- Debt Allocator: Handles strategy rebalancing while transferring slippage loss to the rebalancer (caller).
- Accountant: Collects fees from the vault and rewards rebalancers proportionally based on their contribution to rebalancing throughout the epoch(month).
Rebalancer is not incentivized to rebalance strategy with big slippage since he is paying for it and rewards will probably not be that big. Mechanism is meant to incentivize rebalancers to rebalance effectively so they can maximize their profit while users do not feel slippage and loss of funds.
- Ensures each strategy in the Yearn V3 Vault maintains its target allocation percentages (e.g., 20%, 30%, 50%).
- Calculates the target debt each time rebalance is done on specific strategy
- Transfers all slippage loss to the rebalancer (caller) instead of vault users.
- Tracks rebalancing activity per user on a epoch/monthly basis.
- If rebalancers rebalance strategy in non optimal manner with big slippage users will not lose their assets because rebalancer will pay for loss
- Collects fees from the Yearn V3 Vault during the epoch/month.
- Distributes accumulated fees to rebalancers proportionally based on their rebalancing contributions.
- Incentivizes rebalancers to minimize slippage and maximize efficiency:
- Higher slippage results in direct loss to the caller.
- Effective rebalancers are rewarded with a greater share of the fees.
-
Rebalancing Process:
- A rebalancer (user) calls the
updateDebt()
function on the Debt Allocator contract. - The contract calculates the required target debt to align strategies with their target allocations.
- Slippage incurred during the rebalancing is deducted from the caller's funds.
- A counter tracks how many times the rebalancer has contributed during the epoch/month.
- A rebalancer (user) calls the
-
Fee Distribution:
- At the end of the month, the Accountant contract allows rebalancers to claim their rewards.
- Rewards are distributed proportionally based on the number of rebalances performed by each rebalancer.
- If a rebalancer performs 10 rebalances out of a total of 100 for the month, they receive 10% of the accumulated fees.
Please note that the given code is coded within couple of hours and is not production or audit ready. Code serves as a proof of concept of idea and is implemented quickly. Code and idea do no work at all market conditions and this is not any MVP! Also have in mind that a lot of things in this set of contracts can be done in more optimal way and that the code is not absolutely optimized. All tests are unit tests with mocked external call.