# Building an Adapter
## Introduction
Set Protocol V2 uses a module system to add functionality to Sets. While modules generally specify the general action to be done (such as trading for TradeModule or governance for GovernanceModule), adapters tell the module how exactly to perform that action. For example, while the TradeModule allows Set managers to execute trades, it is adapters such as UniswapV2ExchangeAdapter and SynthetixExchangeAdapter that empower it to make trades on any particular exchange
## Steps to building a new adapter
In this section, we will follow an example of writing an exchange adapter for Uniswap V2 to be used by the TradeModule
### Step 1: Research the integrating protocol
Since we are going to be writing an adapter that uses Uniswap, we first want to understand Uniswap's architecture. Some cursory research on Uniswap will reveal that it uses a smart contract called `Router`, to execute trades. In order to use this contract, you must first have the correct token approval, and then you can call `swapExactTokensForTokens` to perform a swap.
### Step 2: Understanding the module's interface requirements
Each module has an accompanying interface that all adapters for it must adhere to. For the TradeModule, the interface is called `IExchangeAdapter.sol`. This interface requires two different functions be implemented, `getSpender` and `getTradeCalldata`. Before you can write an adapter, you must understand what these functions do, and have an idea of how to implement them for your usecase. Nearly all adapters have some function named `getSomethingCalldata`. This function generally returns a tuple containing `(callee, etherAmount, functionCallData)`. This function uses `abi.encodeWithSignature` to create this `functionCallData` return value, which is the encoded function call that the module must execute in order to perform the action (in this case making a trade).
### Step 3: Write the adapter
Adapter are written in the set-protocol-v2 GitHub repository under `contracts/protocol/integration` folder. The adapter should be written a single contract which adheres to the correct interface.
### Step 4: Write tests
All functions in your adapter must be fully tested. These tests should be placed under `test/protocol/integration`. It is most important to thoroughly test the getCalldata function of the adapter to insure that it properly encodes the function calldata.
### Step 5: Open a PR
The final step of writing an adapter is opening a PR in the set-protocol-v2 repository to get your code added to our codebase. Before you open a PR, ensure that your contract contains javadoc comments, and that every function has an associated test. In the description of your PR, specify what module the adapter is for, what protocol it integrates with, and provide a brief description of what it will be used for.