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();
}
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: