Been farming across several protocols lately - primarily focusing on a mix of stablecoin pairs on Curve and some riskier, but higher-APY, impermanent loss (IL) prone pairs on smaller LPs. The biggest headache isn't the APY fluctuations or even the smart contract risk (though that's always in the back of my mind), it's the manual rebalancing.
Every few days, I find myself spending a significant chunk of time calculating optimal rebalancing points, swapping tokens, and reapplying liquidity. It's time-consuming and prone to errors, especially when gas fees spike.
I'm trying to build a more automated workflow. My current idea involves a simple script that:
- Monitors the IL for specific pairs (e.g., using a price oracle or direct pool data).
- Tracks the current APY for re-depositing rewards.
- Calculates the threshold for rebalancing (e.g., if IL exceeds X% or if rewards accumulated reach Y% of the initial deposit).
- Potentially executes swaps and LP re-additions via a multi-chain compatible tool or a specific DEX router if gas is manageable.
Has anyone here built or used something similar? I'm thinking of starting with a Python script and maybe integrating with tools like Brownie or Hardhat for contract interaction. The main challenge is managing the cross-chain aspect without incurring prohibitive gas costs for every small rebalance. Maybe focusing on rebalancing within a single L1 or L2 at a time is more practical?
What are your thoughts on automating this? Any pitfalls I should be aware of, or existing tools that do this effectively without requiring deep coding knowledge?