Skip to content

Commit c35641d

Browse files
committed
WIP-searcher-guide-refactor
1 parent 2bda439 commit c35641d

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ Searchers can connect to the server via WebSocket to reduce latency and subscrib
4646
```bash copy
4747
{
4848
"id": "1",
49-
"method": "subscribe",
49+
"method": "subscribe", // Name of the server method to invoke
5050
"params": {
5151
"chain_ids": ["op_sepolia"]
5252
}
5353
}
5454
```
55+
56+
Consult [`Websocket API reference`](./websocket-api-reference.mdx) for a complete list of methods and parameters.
5557
</Tabs.Tab>
5658
</Tabs>
5759

@@ -100,6 +102,8 @@ Searchers can submit bids through an HTTP POST call to the `/v1/bids` endpoint.
100102
"amount": "10",
101103
}
102104
```
105+
106+
TODO: Explain the fields here.
103107
</Tabs.Tab>
104108
<Tabs.Tab>
105109

@@ -125,14 +129,54 @@ A successful response to a bid submission has the following schema:
125129

126130
```bash copy
127131
{
128-
"id": "1", // websocket request id
132+
"id": "1", // Websocket request id
129133
"status": "success",
130134
"result": {
131-
"id": "beedbeed-b346-4fa1-8fab-2541a9e1872d", //bid id
135+
"id": "beedbeed-b346-4fa1-8fab-2541a9e1872d", // Bid id
132136
"status": "OK"
133137
}
134138
}
135139
```
140+
141+
Consult [`Websocket API reference`](./websocket-api-reference.mdx) for more details.
136142
</Tabs.Tab>
137143
</Tabs>
138-
</Steps>
144+
</Steps>
145+
146+
147+
Searchers are **recommended** to source opportunities via the opportunity endpoints and construct transactions intended for the `OpportunityAdapter`.
148+
However, searchers can use custom contracts to execute transactions if they prefer.
149+
If searchers use custom contracts, they can still use the Express Relay server to source opportunities and craft bids based on the opportunity details.
150+
151+
Check the following example of a custom contract that executes liquidation transactions:
152+
153+
```solidity copy
154+
...
155+
function callLiquidation(Opportunity memory opp){
156+
for (uint i=0; i<opp.sell_tokens.length; i++) {
157+
let token = opp.sell_tokens[i];
158+
IERC20(token.contract).approve(opp.contract, token.amount);
159+
}
160+
161+
uint256[] before = new uint256[](opp.buy_tokens.length);
162+
for (uint j=0; j<opp.buy_tokens.length; j++) {
163+
let token = opp.buy_tokens[j];
164+
before = IERC20(token.contract).balanceOf(address(this));
165+
}
166+
167+
opp.target_contract.call{value: opp.target_call_value}(opp.target_calldata);
168+
169+
uint256[] after = new uint256[](opp.buy_tokens.length);
170+
for (uint j=0; j<opp.buy_tokens.length; j++) {
171+
let token = opp.buy_tokens[j];
172+
after = IERC20(token.target_contract).balanceOf(address(this));
173+
174+
assert(after[j] == before[j] + token.amount);
175+
}
176+
}
177+
...
178+
```
179+
180+
<Callout type="info" emoji="ℹ️">
181+
Make sure to approve the `opp.contract` for the necessary amount of `sell_tokens`.
182+
</Callout>

0 commit comments

Comments
 (0)