Skip to content

Commit bc60b80

Browse files
committed
WIP-Searcher-guide
1 parent cf27a2e commit bc60b80

File tree

3 files changed

+87
-11
lines changed

3 files changed

+87
-11
lines changed

pages/express-relay/integrate-as-protocol.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Callout, Tabs, Steps } from 'nextra/components'
22

33
# How to Integrate Express Relay as a Protocol
44

5-
Defi Protocols can **permissionlessly** integrate with Express Relay to recapture MEV and access a network of searchers.
5+
Defi protocols can **permissionlessly** integrate with Express Relay to recapture MEV and access a network of searchers.
66

77
Integrating with Express Relay involves two main steps:
88

9-
- Update your defi Protocol's contract to **permission** Express Relay transactions.
9+
- Update your defi protocol's contract to **permission** Express Relay transactions.
1010
- Write a script to **expose** liquidation opportunities to Searchers for auction.
1111

1212
## Update your defi Protocol's Contract
@@ -163,7 +163,7 @@ contract EasyLend is IExpressRelayFeeReceiver {
163163

164164
## Expose Liquidation Opportunities to Searchers
165165

166-
Your defi Protocol should fetch vaults and positions eligible for liquidation and expose them to Express Relay for auction.
166+
Your defi protocol should fetch vaults and positions eligible for liquidation and expose them to Express Relay for auction.
167167

168168
The Express Relay auction server provides a **POST** method, `/v1/opportunities`, which accepts a JSON payload containing the details of the liquidation opportunity.
169169

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,86 @@
1+
import { Callout, Tabs, Steps } from 'nextra/components'
2+
13
# How to Integrate Express Relay as a Searcher
24

3-
By integrating with Express Relay, searchers are able to access opportunities from various DeFi protocols via a simple and unified interface.
4-
Opportunities and searcher bids are communicated via the Express Relay server.
5-
The server exposes different endpoints for interaction which can be used directly via HTTP and WebSocket or via one of the SDKS for convenience.
5+
Express Relay gives one place stop for on-chain opportunities. Searchers can access opportunities from various DeFi protocols via a simple and unified interface.
6+
7+
Searchers **bid** on opportunities exposed by the Express Relay server.
8+
The server exposes different endpoints for interaction, which can be used directly via HTTP, WebSocket, or one of the SDKS for convenience.
9+
10+
11+
(TODO:)
12+
Searchers can integrate with the Express Relay server in two ways:
13+
- [Integrate with the auction server](./integrate-as-searcher/auction-server)
14+
- [Integrate with the opportunity adapter](./integrate-as-searcher/opportunity-adapter)
15+
16+
17+
18+
19+
## Integrate with the auction server
20+
21+
Defi protocols integrated with Express Relay expose liquidation opportunities via the auction server.
22+
Searchers can access these opportunities by querying the server directly or subscribing to WebSocket updates.
23+
24+
To integrate with the auction server, follow these steps:
25+
1. Fetch opportunities from the auction server.
26+
1. Submit bids on opportunities to the auction server.
27+
28+
<Steps>
29+
30+
### Fetch opportunities from the auction server
31+
32+
Searchers can request via HTTP or subscribe to WebSocket updates to fetch opportunities from the auction server.
33+
34+
<Tabs items={['HTTP', 'Websocket']}>
35+
36+
<Tabs.Tab>
37+
Searchers can request opportunities through an HTTP GET call to the `/v1/opportunities` endpoint.
38+
39+
```bash copy
40+
curl -X 'GET' \
41+
'https://per-staging.dourolabs.app/v1/opportunities?chain_id=op_sepolia&mode=live&permission_key=0xdeadbeef&from_time=2024-05-23T21%3A26%3A57.329954Z'
42+
```
43+
</Tabs.Tab>
44+
<Tabs.Tab>
45+
Searchers can connect to the server via WebSocket to reduce latency and subscribe to various events. The WebSocket endpoint relies at `/v1/ws`(e.g `wss://pyth-express-relay-mainnet.asymmetric.re/v1/ws`)
46+
47+
```bash copy
48+
{
49+
"id": "1",
50+
"method": "subscribe",
51+
"params": {
52+
"chain_ids": ["op_sepolia"]
53+
}
54+
}
55+
```
56+
</Tabs.Tab>
57+
</Tabs>
58+
59+
The server responds with opportunities in the following format:
660

7-
The integration consists of 2 main steps:
61+
```json copy
62+
{
63+
"target_calldata": "0xdeadbeef", // Calldata to perform liquidation
64+
"chain_id": "op_sepolia",
65+
"target_contract": "0xcA11bde05977b3631167028862bE2a173976CA11", // Protocol contract address to call for liquidation
66+
"permission_key": "0xcafebabe", // Unique identifier for the liquidation opportunity
67+
"target_call_value": "1", // Value(in Wei) to send with to the Protocol contract.
68+
"buy_tokens": [ // Tokens to buy (Collateral)
69+
{
70+
"amount": "1000",
71+
"token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
72+
}
73+
],
74+
"sell_tokens": [ // Tokens to sell (Oustadaing Debt)
75+
{
76+
"amount": "900",
77+
"token": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
78+
}
79+
],
80+
"version": "v1" // Opportunity format version
81+
}
82+
```
83+
</Steps>
884

9-
- Integrate your searcher service with the [auction server](./integrate-as-searcher/auction-server)
10-
- \[Optional\] Use [OpportunityAdapter](./integrate-as-searcher/opportunity-adapter) and setup a wallet with the necessary tokens and approvals
1185

12-
You can also find a list of relevant contract addresses [here](./contract-addresses).
86+
### Submit bids on opportunities to the auction server.

pages/express-relay/integrate-as-searcher/opportunity-adapter.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Integrate with opportunity adapter
22

3-
The `OpportunityAdapter` is a utility contract that can be used for easier integration with express relay while maintaining maximum security. In this integration, searchers use the `Permit2` contract for safe asset management (`ERC20` tokens and Wrapped ETH) and the adapter contract to transfer bids, execute the opportunity, and ensure the assets are transferred correctly. Using the `OpportunityAdapter` means that a searcher does not need to deploy their own custom contract for inventory management and routing to the protocol contracts where liquidation takes place.
3+
The `OpportunityAdapter` is a utility contract that can be used for easier integration with express relay while maintaining maximum security.
4+
In this integration, searchers use the `Permit2` contract for safe asset management (`ERC20` tokens and Wrapped ETH) and the adapter contract to transfer bids, execute the opportunity, and ensure the assets are transferred correctly.
5+
Using the `OpportunityAdapter` means that a searcher does not need to deploy their own custom contract for inventory management and routing to the protocol contracts where liquidation takes place.
46

57
After [integrating with the auction server](./auction-server), you can integrate with the `OpportunityAdapter` framework via the following steps:
68
1. Hold your assets in your wallet. You will need to own all assets you expect to provide as `sell_tokens` to different opportunities. You will also need to approve `WETH`, as the `OpportunityAdapter` will pay your bids by deducting the bid amounts from your wallet's `WETH` balance.

0 commit comments

Comments
 (0)