Skip to content

valory-xyz/celo-trader

Repository files navigation

Celo trader

An Olas agent that makes transactions on the Celo network.

System requirements

Alternatively, you can fetch this docker image with the relevant requirements satisfied:

NOTE: Tendermint and IPFS dependencies are missing from the image at the moment.

docker pull valory/open-autonomy-user:latest
docker container run -it valory/open-autonomy-user:latest

Run you own agent

Get the code

  1. Clone this repo:

    git clone git@github.com:valory-xyz/celo-trader.git
    
  2. Create the virtual environment:

    cd celo-trader
    poetry shell
    poetry install
    
  3. Sync packages:

    autonomy packages sync --update-packages
    

Prepare the data

  1. Prepare a keys.json file containing wallet address and the private key for each of the agents. To create this file, either generate a new one with autonomy generate-key ethereum -n 1 or export a existing one using Metamask and follow the following format:

    [
        {
            "address": "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",
            "private_key": "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
        }
    ]
    
  2. Deploy a Safe on Celo and set your agent address as one of the signers.

  3. Fund both your agent and Safe with a small amount of CELO, i.e. $0.05 each.

Run the service

  1. Make a copy of the env file:

    cp sample.env .env
    
  2. Fill in the required environment variables in .env. You'll need a Ethereum RPC even if the service runs on Celo. These variables are: ALL_PARTICIPANTS, ETHEREUM_LEDGER_RPC and SAFE_CONTRACT_ADDRESS. You can also modify MAX_TRANSFER_VALUE_WEI, which is a security measure to set the max amount of wei the agent should be able to send. This is a stopgap solution for hypothetical situations where the LLM malfunctions and specifies big transfer values.

  3. Check that Docker is running:

    docker
    
  4. Run the service:

    bash run_service.sh
    
  5. Look at the service logs (on another terminal):

    docker logs -f celotrader_abci_0
    
  6. Make a transfer request, for example to a specific address (use your own destination address):

    curl -X POST http://localhost:8000/request -H "Content-Type: application/json" -d '{"prompt":"Transfer 1 wei to 0x8D7102ce2d35a409535285252599c149FBeABB73"}'
    

Extend the agent (advanced)

To extend agents, it is useful to first understand their architecture and the development process.

After you feel comfortable with running agents and their architecture, think about a useful addition or modification for the Celo Trader. For example: modify the agent and the mech tool to perform swaps. The high level steps would be:

  1. Using the prepare_tx mech tool as template, create a new mech tool that prepares a swap transaction given a pair of tokens and the amount to swap.

  2. Configure your TOOL env so the agent uses your new tool

  3. Modify the agent's process_next_mech_response method in order to get the correct data from the new tool.

  4. Update the transaction preparation on the agent so, instead of a simple transfer, it uses the data received in the previous step to make a call to Uniswap. Here's an example on how to make a contract call. Since agents communicate with contracts through the contract_api, you will need to create a contract package (essentially a contract wrapper) for Uniswap that implements a single method to swap. Here's a contract method for reference.

The trader agent might be a good example to understand how to make transactions using an agent. There's a easy to follow quickstart for this agent that anyone can use to run the trader.