Skip to content

[NEEDS DESIGN] Add auto compounding to farms #3

Description

@pxbee

As a Honeycomb farms user, I'd like to be able to click a button and compound my harvested COMB rewards, so that I don't need to swap, LP and stake it all manually.


Automatically harvest xComb, sell half of it, pair it and restake.

Similar functionality in solidity:
1Hive/unipool#6

Javascript example:

if (xcombBal.gt(ethers.utils.parseEther("0.25"))) {
            let toTrade = xcombBal.div(2).add(ethers.utils.parseEther("0.02"));
            const wxdai = await honeyswap.WETH();
            xcombIsToken0 = (await pool.token0() == xcomb.address);
            let [r0, r1, _] = await pool.getReserves();
            let xcReserve = xcombIsToken0 ? r0 : r1;
            let xdReserve = xcombIsToken0 ? r1 : r0;
            
            let expectedAmt = xdReserve.mul(toTrade).div(xcReserve);
            
            console.log("Selling half (", ethers.utils.formatEther(toTrade), ") to ", ethers.utils.formatEther(expectedAmt), " xdai.");
            
            const initialBal = await signer.getBalance();
            
            let swapResult = await honeyswap.swapExactTokensForETH(toTrade, expectedAmt.mul(995).div(1000), [xcomb.address, wxdai], farmerAddress, Date.now() + 2*60, {gasPrice: gasPrice});
            swapResult = await swapResult.wait();
            
            console.log(`Got ${ethers.utils.formatEther((await signer.getBalance()).sub(initialBal))} xdai.`)
            
            xcombBal = await xcomb.balanceOf(farmerAddress);
            
            let wxdaiToAdd = xdReserve.mul(xcombBal).div(xcReserve);
            
            console.log(`Adding ${ethers.utils.formatEther(xcombBal)} xcomb / ${ethers.utils.formatEther(wxdaiToAdd)} xdai...`);
            let liqResult = await honeyswap.addLiquidityETH(
                xcomb.address, xcombBal, xcombBal.mul(99).div(100), wxdaiToAdd.mul(99).div(100), farmerAddress, Date.now() + 2*60, 
                {value: wxdaiToAdd, gasPrice: gasPrice});
            await liqResult.wait();
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions