Interactive adapters
InteractiveAdapter
The current version of code for interactive adapters is placed in interactive-updates
branch.
To create new token adapter, one has to implement InteractiveAdapter interface. It inherits ProtocolAdapter, so one has to implement it, too.
InteractiveAdapters should implement 2 main functions: deposit()
and withdraw()
.
InteractiveAdapters should not have any storage variables used within deposit and withdraw functions. Use internal constant
or immutable constant
.
tokenAmounts
— tokens that will be used in the action (e.g. DAI in case of deposit to Compound).
Add require()
if length of tokenAmounts
should be fixed. Use the abbreviation of the contract name to use in revert()
/require()
errors (later referred to as ABBR_OF_NAME).
Usually, tokenAmounts
are decomposed in token
and amount
like that:
Use getAbsoluteAmountDeposit()
in deposit()
function and getAbsoluteAmountWithdraw()
in withdraw()
function.
If tokens are required to be approved, use the following function:
Get additional data (e.g. user address or the desired derivative address) required for the interaction from bytes data
using abi.decode
like that:
Interact with the protocol using try-catch syntax:
Fill in tokensToBeWithdrawn
array. It should consist of tokens returning to the user (e.g. cDAI in case of deposit to Compound).
Remove names of unused arguments.
Use npx prettier ./contracts/**/*.sol --write
to fix linter issues.
Add tests for interactions it test/
directory, use Uniswap, Weth, and other required adapters.
Last updated