Cryptocurrency empowers anyone, anywhere, to participate in the financial revolution, multiplying their investments and opening up a world of new opportunities.
In our last post, we looked at how to invest in liquidity pools, and how to earn bigger rewards by staking our liquidity in yield farms. In this post, we’re going to make this idea even more powerful by building a bot that automatically compounds our earnings back into the farm. By reinvesting your earnings and rewards, you can achieve exponential growth in your investments. Compounding is a powerful tool that can turn even modest investments into substantial wealth over time. With this bot, you can take full advantage of compounding to grow your wealth and earn the rewards you deserve. So let’s dive in!
We’ll start out by dragging the ui console view command. This command will change the UBot browser into a console interface, where we can see the output of our bot’s actions.
Next, we need to set up our wallet for use with DeFi protocols. We’ll drag over the config defi wallet command, and enter our private key.
Next, we need to claim rewards from our farm. To do that, we need to find the farm we want. We’ll drag over the set command to set a variable, and name it #farm. For the value, we’ll drag over the $find farm by tokens function, and set the exchange to “PancakeSwap”, Token A to “DOGE”, and Token B to “BNB”.
NOTE: I’m using a different farm in this tutorial than I used in the last tutorial. If you want to use the same farm, you would set the tokens to “USDC” and “USDT”.
Once we have our farm, we can claim rewards using the claim farm rewards command. We’ll use the #farm variable.
As always, we should log every transaction.
Now, let’s swap some tokens. To figure out how much we got in rewards, we need to check our balance. We’ll drag over the set command to set a variable, and name it #cake amount. For the value, we’ll use the $get token balance function to get our current balance of CAKE tokens.
Next, we’ll use the swap tokens command to swap half of our CAKE tokens for BNB, and the other half for DOGE. We’ll log our result after each swap.
Now, we’re ready to add liquidity back into our pool. We’ll use the add liquidity command to provide liquidity for the DOGE-BNB pool on PancakeSwap. We’ll use our entire balance of DOGE tokens, but subtract 0.01 BNB from our native token balance to leave a small amount for gas fees.
Finally, we’ll deposit our liquidity into the farm. We’ll use the deposit to farm command, and use the #farm variable to specify which farm to deposit into. The $get liquidity pool balance function will get our current balance of liquidity tokens. We’ll log our result after the deposit.
And that’s it! Now we can automatically compound all of our earnings, and start seeing some sweet exponential returns. This is the good stuff, where smart crypto investors really start making money.
Here’s the code from this post:
ui console view
config defi wallet("YOUR_PRIVATE_KEY")
set(#farm,$find farm by tokens("PancakeSwap","DOGE","BNB"),"Local")
log("Claiming {#farm}")
claim farm rewards(#farm,#txinfo)
log object(#txinfo)
set(#cake amount,$get token balance("BinanceSmartChain","CAKE"),"Local")
log("Swapping Tokens")
swap tokens("PancakeSwap","CAKE","BNB",$divide(#cake amount,2),#txinfo)
log object(#txinfo)
swap tokens("PancakeSwap","CAKE","DOGE",$divide(#cake amount,2),#txinfo)
log object(#txinfo)
log("Adding liquidity")
add liquidity("PancakeSwap","DOGE","BNB",$get token balance("BinanceSmartChain","DOGE"),$subtract($get native token balance("BinanceSmartChain"),.01),#txinfo)
log object(#txinfo)
log("Depositing to farm")
deposit to farm(#farm,$get liquidity pool balance("PancakeSwap","DOGE","BNB"),#txinfo)
log object(#txinfo)