Architecture

DeFi SDK consists of four major components: Router, Core, , and TokenAdapterRegistry. Protocol Adapters / Interactive Adapters and Token Adapters are per-protocol contracts.

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.

Router

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.

Core

ProtocolAdapterRegistry

ProtocolAdapterRegistry is a contract that maintains a list of ProtocolAdapters and is called to fetch user's balances.

ProtocolAdapterRegistryAdapterRegistry (v2/legacy)

ProtocolAdapter

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: some of adapters (asset adapters) returns the amount of the account's tokens held on the protocol (owned by the user or staked) or the account's debt to the protocol in case the returned amount is negative. Some adapters do not return any balance and used only for tokens exchange.

ProtocolAdapter

InteractiveAdapter

InteractiveAdapter is a special contract for every protocol. It inherits from ProtocolAdapter and 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.

InteractiveAdapter

TokenAdapterRegistry

TokenAdapterRegistry is a contract that maintains a list of TokenAdapters and is called to fetch token's metadata and rates to underlying tokens. Some protocols do not use "simple" ERC20 tokens but instead have complex derivatives, for example the Compound protocol has cTokens. The TokenAdapterRegistry contract also provides information about the type of tokens.

TokenAdapterRegistry

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 and rates of underlying tokens.

TokenAdapter

Last updated