DeFi Agents: Automated DeFi Liquidity Management

Jun 29, 2021

Fetch.ai’s first decentralized finance application will help millions of users to automate various tasks in DeFi.

The future of decentralized finance (DeFi) is intelligent automation. Fetch.ai is spearheading that effort by bringing AI-powered solutions to the DeFi space.

Today, we are introducing the first version of the DeFi Agents app. It enables users to automatically withdraw liquidity from any Uniswap V2 or PancakeSwap V2 pool based on a predefined condition — spot price. The DeFi Agents app can effectively limit impermanent loss to acceptable levels and enable effective protection from violent price movements, including the infamous “rug pulls”.

In this blog post we will walk you through the steps of:

  1. Connecting your MetaMask wallet to the DeFi Agents app
  2. Creating an agent
  3. Creating a trigger for the agent

We will be using the DeFi Agents app on the Ethereum mainnet. The UI and agent set up process are identical on Ethereum and Binance Smart Chain (BSC). You can also watch a short walkthrough on YouTube.

The DeFi Agents app is available at: https://defi-agents.fetch.ai

We plan to expand the functionality of DeFi Agents in the coming months to support other DeFi apps and more advanced triggers.

Connecting via MetaMask

To connect with the DeFi Agents app, you will need a MetaMask wallet.

IMPORTANT: To remain active, DeFi Agents require FET tokens. Upon accessing the app, users will be rewarded with 5 FET. These are not actual FET tokens and cannot be withdrawn or used anywhere else apart from the DeFi Agents app. If you want to keep your Agents running for a longer time-period, please acquire additional FET tokens and top-up your DeFi Agents app on Ethereum. Your FET app balance is available on both Ethereum and Binance Smart Chain, but can only be topped up on Ethereum with FET ERC-20 tokens.

You will also need some ETH (or BNB if you are using the app on BSC) for the payment of gas fees during the setup process. Agents also need ETH in order to execute the liquidity withdrawal transaction when the pre-determined trigger price has been reached. Therefore, we recommend having at least 0.1 ETH in your MetaMask wallets. In the case of BSC, we recommend having at least 0.01 BNB.

Finally, since the DeFi agents app helps you withdraw Uniswap V2 (or PancakeSwap V2) liquidity, you need to have Uni V2 (or PancakeSwap V2) liquidity provider (LP) tokens in your MetaMask. The agent will use them to get your liquidity out of the Uniswap pool when the conditions you predefined have been met.

Once you have FET, ETH, and Uni V2 LP tokens in your MetaMask:

  1. Go to https://defi-agents.fetch.ai/
  2. Click on the “Access DeFi Agents” button
  3. Your MetaMask wallet will prompt you to sign a transaction.
  4. Click “Sign”. This action does not cost any ETH.
  5. You will be redirected to the DeFi Agents app Dashboard.

First-time Login Dashboard

The DeFi Agents dashboard helps you set up your first Agent. This is done in three steps:

  1. Linking you MetaMask wallet (this was done at “log in”)
  2. Adding an Agent
  3. Creating a trigger for the Agent

Adding a DeFi Agent

1a) From the Dashboard — Click on “Add Agent”

or

1b) From the Menu — Click on “Agents” and then on “+ New Agent” on the right side of the screen

A pop-up window will appear. It will display the currently connected MetaMask wallet address.

2. There is currently only one type of agent available — the Stop Loss one. You can also create up to 5 agents. Click on “Create” to proceed.

Your new Agent ID will be an automatically generated combination of human-readable words. You can edit the Agent name.

Creating a Trigger

1a) From the Dashboard — Click on “Add Trigger”

or

1b) From the Menu — Click on “Triggers” and then on “+ New Trigger” on the right side of the screen.

Once again, you will see a pop-up window. Click next.

2) Select one of the agents you have created.

3) Once an Agent is selected, you will have to provide the address of the Uniswap V2 (or PancakeSwap V2) liquidity pool.

One way to identify the Ethereum address of the pool is to copy your MetaMask wallet address and paste it in https://etherscan.io/. Then in the drop-down menu, find the Uni-V2 token and click on it. You can use https://www.bscscan.com/ for Binance Smart Chain in the exact same way.

You will be redirected to the Uni V2 LP token contract. Copy the contact address.

4) Paste the pool address in the “Select Pool” field. Your LP token balance in MetaMask will be detected and you will be able to click “Next”.

5) In the next screen you will be able to set the price that will trigger the Agent into action to withdrawal your liquidity from the pool. You can set the price for either MTLX/WETH or WETH/MTLX by clicking on the “MTLX/WETH” box on the right.

Set your trigger price in accordance with the current Spot Price. The trigger must be a lower value than the current spot price for that pair.

6) Once you have set the trigger price, you need to determine how much gas you are willing to pay for this trigger to be executed. You can select from Slow, Medium, and Fast, or enter a custom gas limit.

NOTE: The Gas Price you select will determine the amount of ETH or BNB you will have to deposit with your agent so it can execute the liquidity withdrawal if the trigger price is reached.

The gas fees are not determined by Fetch.ai.

Once you choose the Gas Price and click “Next”, you will see the application begin the process of setting up your trigger. You will need to approve several MetaMask transactions.

If during the process you lack sufficient ETH or BNB, this is the error screen you will receive and you will be unable to set your trigger.

Dashboard (after Agent creation)

After agent creation, the DeFi Agent dashboard changes to display the user’s MetaMask wallet FET balance and the FET tokens available in the application.

If users want to keep their Agents active, they will need to top up the app with FET tokens on the Ethereum network (ERC-20). This could be done from the dashboard. Once the user deposits FET in the DeFi Agent application, they will be able to see an estimate of the remaining time until service expiry and the monthly FET usage.

The dashboard also displays information on the number of agents, Uniswap or PancakeSwap pool pairs, and triggers that are currently created.

Account View

The account page enables users to see a history of FET payments done automatically on the part of the app from the FET amount that the user topped up. It also displays usage information and estimated service expiry date.

Switching Between Ethereum and Binance Smart Chain

To change the network, use the switch at the upper right corner of the page.

Any agents created on Ethereum and Binance Smart Chain will be viewable on the Agents page.

Future Features

More types of triggers will be added in the future. Some of them will include:

  • APY monitor — Withdraw liquidity if APY is less than X
  • Sentiment — Withdraw liquidity if token sentiment (LunarCrush for example) goes below X
  • Best Pool — Move liquidity to an identical pool (in terms of pairs) if the APY is higher there. Limit this to one liquidity transfer per week/month/quarter.
  • ETH Fees — Withdraw liquidity if the ETH fees are becoming too high in a pre-set period of time
  • Stop-loss (Uniswap v3) — Move liquidity to the new active range if the current range is no longer generating fees
  • Portfolio management (Uniswap v3) — Define a weighting for a sector (e.g. oracles, AI, NFTs) and implement an ETF-like strategy (market-weighted balancer pool)
  • Private Uniswap v3 strategy — Hide the strategy behind the agent
  • ETH fund management V1 — Deposit funds in a contract and use it to automatically top-up one-or-more active addresses
  • ETH fund management V2 — Allow agents to swap ERC-20s for ETH if funds drop below a certain level

We are also considering integration with Zapper.

Spread the Word!

Help us spread the word about DeFi Agents and help DeFi users manage their liquidity better!

  1. Reshare this tweet: https://twitter.com/Fetch_ai/status/1409870222601883656
  2. Add these tags: #DeFiAgents @Fetch.ai #DeFi

We will distribute 1000 FET to 20 random users!

If you have questions or experience any issues, please get in touch with the Fetch.ai team in Telegram or Discord.