Skip to content

Adding new adapters

Igor Sobolev edited this page Mar 24, 2020 · 5 revisions

How to add your protocol to DeFi SDK

Once a protocol is added to AdapterRegistry contract, it will immediately appear in all the interfaces that use DeFi SDK (including Zerion). In order to add protocol to to DeFi SDK one has to implement the following contracts.

ProtocolAdapter

To create new protocol adapter, one has to implement ProtocolAdapter interface. adapterType(), tokenType(), and getBalance() functions MUST be implemented.

NOTE: only internal constant state variables MUST be used, i.e. adapter MUST be stateless. Only internal functions SHOULD be used, as all the other functions will not be accessible by AdapterRegistry contract.


adapterType() returns (string)

The function has no arguments and MUST return type of the adapter:

  • "Asset" in case the adapter returns the amount of account's tokens held on the protocol;
  • "Debt" in case the adapter returns the amount of account's debt to the protocol.

tokenType() returns (string)

The function has no arguments and MUST return type of the token used by the adapter:

  • "ERC20" is the default type;
  • "AToken", "CToken", "YToken", "Uniswap pool token", "Curve pool token", "PoolTogether pool" are the currently supported ones.

getBalance(address token, address account) returns (uint256)

The function has two arguments of address type: the first one is token address and the second one is account address. The function MUST return balance of given asset held on the protocol for the given account for "Asset" adapter type. The function MUST return the amount of tokens owed to the protocol by the given user for "Debt" adapter type.

TokenAdapter

To create new token adapter, one has to implement TokenAdapter interface.


getMetadata(address token) external view returns (TokenMetadata memory)

The function has the only argument – token address. The function MUST return the ERC20-style token metadata, namely:

  • token: address of the token contract;
  • name: string with token name;
  • symbol: string with token symbol;
  • decimals: uint8 number with token decimals.

getComponents(address token) external view returns (Component[] memory)

The function has the only argument – token address. The function MUST return all the underlying tokens info:

  • token : address of the underlying token contract;
  • tokenType : string with underlying token type;
  • rate : uint256 with price per base token share (1e18).

After the adapters are deployed and tested, one can contact Zerion team in order to add the adapters to AdapterRegistry contract.