Architecture

DeFi SDK consists of three major components: Protocol Adapters, Token Adapters and Adapter Registry.

ProtocolAdapters

ProtocolAdapter is a special contract for every protocol. Its main purpose is to wrap all the protocol interactions. There are different types of protocol adapters: "Asset" adapter returns the amount of the account's tokens held on the protocol and the "Debt" adapter returns the amount of the account's debt to the protocol. Some protocols do not use "simple" ERC20 tokens but instead have complex derivatives, for example the Compound protocol has CTokens. The ProtocolAdapter contract also provides information about the type of tokens used within it.

TokenAdapters

TokenAdapter is a contract for every derivative token type (e.g cTokens, aTokens, yTokens, etc.) Its main purpose is to provide ERC20-style token metadata as well as information about the underlying ERC20 tokens (like DAI for cDAI). Namely, it provides addresses, types and rates of underlying tokens.

AdapterRegistry

AdapterRegistry is a contract that a) maintains a list of ProtocolAdapters and TokenAdapters and b) is called to fetch user balances.

InteractiveAdapters

InteractiveAdapter is a special contract for every protocol. Its main purpose is to wrap all the protocol interactions, namely “withdraw” and “deposit”. Deposit is the action when tokens are transferred to the protocol (lend tokens, add pool liquidity). Withdraw is the action when tokens are transferred from the protocol (withdraw deposit, return pool liquidity).

Technically, InteractiveAdapter is a base contract for all the interactive adapters.

Core

Core is the contract with main logic. It iterates over the array of actions and consecutively executes them. Also, it is responsible for sending the required tokens back to the user.

Router

Router is the main contract for all the interactions. It checks signatures, transfers tokens to the Core, and calls Core with the correct parameters. Most of security checks are done here. Although the Core contract can be called directly, we still recommend interacting with our system via the Router contract to make sure no funds are lost on Core or Router contracts.