Skip to main content
Version: 2.0.0

Protocols

The main goal of the protocol class is allowing anyone to implement protocols through a standardized format for a handful of categories:

  • Dex
  • Lending
  • Custom

Each Protocol can implement one or multiple of these (AAVE for example can be both a Lending and Dex because it offers products in both categories).

The protocols are standardized so that they can easily be reused by others. Ideally through the library system.

Implementations

Dex is a Decentralized Exchange. More info about implementing a DEX class can be found here.

Lending is a lending protocol that allows borrowing and supplying tokens on chain. More info about implementing a Lending class can be found here.

Custom can be anything you want it to be and doesn't have to follow a standardized format. This is available in case you want to expose functions that don't fit the standardized format. Please note that when these functions are implemented by an agent or environment it won't be easily exchanged with a different Protocol because the standardization has been let go. More information about implementing a Custom class can be found here.

Contracts

The may to talk to on-chain contracts is through protocols (although you can make contracts available directly in an environment too). More information about contracts can be found here.

Class implementation

Each of the 3 options currently available (Dex, Lending or Custom) have to be a separate file. dex.py, lending.py or custom.py which have to implement the respective protocol type.

Library file

The library file for the protocol supports a few extra parameters besides the standard ones, see a full example of a library file for an agent below:

name: "Aave V3"
version: "1.0.0"
type: "protocol"
author: "Almanak Blockchain Labs"
description: "Uniswap V3 protocol"
license: "MIT"

supported_chains:
- engine: 'evm'
chainId: '1'
dependencies:
contracts:
- abi: "file://abi/aave_pool.json"
address: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"
alias: "aave_pool"
- engine: 'evm'
chainId: '2'
dependencies:
contracts:
- abi: "file://abi/aave_pool.json"
address: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"
alias: "aave_pool"
settings:
uniswap_v3_usdc_pool: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

Please note that only 1 almanak-library.yaml file is required per protocol, each protocol can implement 1 or all 3 types of protocol.

As you can see the main part that we add is the supported_chains, which is simply an array of objects that you can use to configure dependencies and only allow the agent to work on certain chains because it has unique features to them.

  • engine is the Chain Engine as configured for the environment.
  • chainId is the chain id as configured for the environment.
  • dependencies allow you to set certain dependencies on an environment level, these have to be library items or contracts which have to be local files that are available in the same or subdirectory of the almanak-library.yaml.
  • settings are like any other settings but can overwrite them on an environment level. Useful for contract addresses that are different per chain