Module 4 - Structure of an Adapter
Step By Step Instructions
Every Adapter Contract must import RouterIntentEoaAdapterWithoutDataProvider
and EoaExecutorWithoutDataProvider
from the @routerprotocol/intents-core
Package.
Import the Required Contracts
Ensure you Import both RouterIntentEoaAdapterWithoutDataProvider
and EoaExecutorWithoutDataProvider
from the @routerprotocol/intents-core
Packages into your Contract file. These Contracts are essential for enabling your Adapter to Interact with the Router Protocol’s Intent System.
Extend the Required Contracts
Your Adapter Contract must extend RouterIntentEoaAdapterWithoutDataProvider
to Inherit the necessary Functionalities for Working with the Router Protocol’s Intent System. Additionally, your Contract Should Implement EoaExecutorWithoutDataProvider
if execution functionalities without a Data Provider are Required.
Example
Below is an Example of how to Implement a Stader Adapter Contract that extends the required Base Contracts -
To Implement the Core Logic of any Adapter Contract in the Router Protocol Ecosystem, every Adapter Contract must Define an execute
function. This function Contains the Primary Business Logic for the Specific Adapter, such as Staking incase of Liquid Staking Adapter or adding Liquidity in a Pool incase of Dex Aapters.
Structure of the execute
Function
The execute
function is where the Core Action for each Adapter is Implemented. Depending on the Adapter’s Purpose, the Logic within this function will vary. Below is a Breakdown of how the execute
function is Generally Structured, in Stader Adapter as an example -
Example: execute
Function in Stader Adapter
The execute
function in the Stader Adapter is Designed to handle Staking Logic. It takes Input Data, Parses it, and executes the Staking Action by Calling the appropriate functions. Below is the example Code and Explanation -