Skip to content

Commit 47ea3f0

Browse files
committed
WIP-searcher-guide-refactor
1 parent fb63c4e commit 47ea3f0

File tree

2 files changed

+54
-52
lines changed

2 files changed

+54
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Express Relay provides a **POST** method, [`/v1/opportunities`](https://per-stag
177177

178178
The JSON payload should contain opportunities in the following format:
179179

180-
```json
180+
```bash copy
181181
{
182182
"target_calldata": "0xdeadbeef", // Calldata to execute the opportunity
183183
"chain_id": "op_sepolia",

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

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@ import { Callout, Tabs, Steps } from "nextra/components";
22

33
# How to Integrate Express Relay as a Searcher
44

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.
5+
Express Relay allows searchers to integrate once and access all existing and future opportunities across integrated DeFi protocols.
6+
Searchers **bid** on these opportunities exposed by Express Relay.
67

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.
8+
Express Relay exposes different endpoints for interaction, which can be used directly via HTTP, WebSocket, or one of the SDKs for convenience.
99

10-
Searchers can integrate with the Express Relay server in three steps:
10+
Searchers can integrate with Express Relay in three steps:
1111

1212
1. Subscribe to new opportunities
1313
2. Evaluate the opportunity and construct the bid
14-
3. Submit the bid to the auction server
14+
3. Submit the bid to Express Relay.
1515

1616
<Steps>
1717

18-
### Subscribing to new opportunities
18+
### Subscribe to new opportunities
1919

20-
Express Relay provides searchers with `Typescript` and `Python` SDKs to interact with the server.
21-
Searchers can also fetch available opportunities via HTTP or subscribe to them via WebSocket.
20+
Express Relay provides searchers with `Typescript` and `Python` SDKs to interact with Express Relay.
21+
Searchers can also directly fetch available opportunities via HTTP or subscribe to them via WebSocket.
2222

2323
<Tabs items={['Typescript', 'Python', 'HTTP', 'Websocket']}>
2424

2525
<Tabs.Tab>
26-
Our JavaScript SDK provides a convenient way to subscribe to opportunities:
26+
Pyth provides a `Typescript` SDK, which allows searchers to subscribe to opportunities:
2727

2828
```typescript
2929
import { Client, Opportunity } from "@pythnetwork/express-relay-evm-js";
3030

3131
const handleOpporunity = async (opportunity: Opportunity) => {
32-
// TODO: Implement your opportunity handler here
32+
// Implement your opportunity handler here
3333
};
3434

3535
const client = new Client(
@@ -42,20 +42,18 @@ await client.subscribeChains(["op_sepolia"]);
4242

4343
</Tabs.Tab>
4444
<Tabs.Tab>
45-
Our Python SDK provides a convenient way to subscribe to opportunities:
45+
Pyth provides a `Python` SDK, which allows searchers to subscribe to opportunities:
4646

4747
```python copy
4848
from express_relay.client import (
4949
ExpressRelayClient,
5050
)
5151
from express_relay.express_relay_types import Opportunity
5252

53-
5453
def opportunity_callback(opportunity: Opportunity):
55-
# TODO: Implement your opportunity handler here
54+
# Implement your opportunity handler here
5655
pass
5756

58-
5957
client = ExpressRelayClient(
6058
'server_url',
6159
None,
@@ -67,20 +65,18 @@ await client.subscribe_chains(['op_sepolia'])
6765

6866
</Tabs.Tab>
6967
<Tabs.Tab>
70-
Searchers can request opportunities through an HTTP GET call to the `/v1/opportunities` endpoint.
68+
Searchers can request opportunities through an HTTP **GET** call to the [`/v1/opportunities`](https://pyth-express-relay-mainnet.asymmetric.re/redoc#tag/opportunity/operation/get_opportunities) endpoint.
7169

7270
```bash copy
7371
curl -X 'GET' \
7472
'https://pyth-express-relay-mainnet.asymmetric.re/v1/opportunities?chain_id=op_sepolia&mode=live'
7573
```
7674

77-
Opportunities are short-lived and will be executed in a matter of seconds. So, the above endpoint can return an empty response.
78-
79-
You can fetch historical opportunities by setting the `mode` parameter to `historical`.
75+
Opportunities are short-lived and could be executed in a matter of seconds. So, the above endpoint could return an empty response.
8076

8177
</Tabs.Tab>
8278
<Tabs.Tab>
83-
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`).
79+
Searchers can connect to the server via WebSocket to reduce latency and subscribe to various events. The WebSocket endpoint lives at `/v1/ws`(e.g `wss://pyth-express-relay-mainnet.asymmetric.re/v1/ws`).
8480
Here is a sample JSON payload to subscribe to opportunities:
8581

8682
```bash copy
@@ -102,49 +98,50 @@ The server responds with opportunities in the following format:
10298

10399
```bash copy
104100
{
105-
"target_calldata": "0xdeadbeef", // Calldata to execute the opportunity
106-
"chain_id": "op_sepolia",
107-
"target_contract": "0xcA11bde05977b3631167028862bE2a173976CA11", // Protocol contract address to call for execution
108-
"permission_key": "0xcafebabe", // Permission key required for the liquidation opportunity
109-
"target_call_value": "1", // Value(in Wei) to send with to the Protocol contract.
110-
"buy_tokens": [ // Tokens to buy
101+
"target_calldata": "0xdeadbeef", // Calldata to execute the opportunity
102+
"chain_id": "op_sepolia",
103+
"target_contract": "0xcA11bde05977b3631167028862bE2a173976CA11", // Protocol contract address to call
104+
"permission_key": "0xcafebabe", // Unique identifier for the opportunity
105+
"target_call_value": "1", // Value (in Wei) to send to the protocol contract.
106+
"sell_tokens": [ // Tokens the protocol expects to receive
111107
{
112-
"amount": "1000",
113-
"token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
108+
"amount": "900",
109+
"token": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
114110
}
115111
],
116-
"sell_tokens": [ // Tokens to sell
112+
"buy_tokens": [ // Tokens the protocol will send in return
117113
{
118-
"amount": "900",
119-
"token": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
114+
"amount": "1000",
115+
"token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
120116
}
121117
],
122-
"version": "v1" // Opportunity format version
118+
"version": "v1" // Opportunity format version
123119
}
124120
```
125121

126122
### Evaluate the opportunity and construct the bid
127123

128-
Searchers should construct a bit based on the fetched opportunity details like `buy_tokens` and `sell_tokens`.
129-
The SDKs provide an easy way to construct a bid using the `OpportunityAdapter` contract.
124+
Searchers should construct a bid based on the fetched opportunity.
125+
The SDKs provide an easy way to construct a bid using the [`OpportunityAdapter`](./integrate-as-searcher/opportunity-adapter.mdx) contract.
130126
The `OpportunityAdapter` contract handles asset transfers and ensures the opportunity is executed correctly.
131127

132-
You can learn more about the `OpportunityAdapter` contract and how to prepare your assets in the [Opportunity Adapter](./integrate-as-searcher/opportunity-adapter.mdx) section.
133-
If you have already developed an in-house searcher contract, integrating using the Opportunity Adapter contract is unnecessary.
134-
You can use our lower-level APIs, which allow higher flexibility for advanced users.
135-
Please refer to the [custom contracts](./integrate-as-searcher/custom-contract.mdx) section for more details.
128+
<Callout type="warning" emoji="⚠️">
129+
Before constructing the bid, make sure your wallet has the required assets and has made the necessary approvals.
130+
Refer to the [Prepare assets for OpportunityAdapter](./integrate-as-searcher/opportunity-adapter.mdx) section for more details.
131+
</Callout>
136132

137-
Here is an example of how to construct a bid using the SDKs:
133+
134+
Here is an example of how to construct a bid using `OpportunityAdapter` via the SDKs:
138135

139136
<Tabs items={['Typescript', 'Python']}>
140137
<Tabs.Tab>
141138
```typescript copy
142139
const handleOpportunity = async (opportunity: Opportunity) => {
143140
const nonce = BigInt(Math.floor(Math.random() * 2 ** 50));
144-
const privateKey = `0x0000`; // This should be the private key of the searcher
145-
const amount = BigInt(1000); // This should be determined based on opportunity
146-
const deadline = BigInt(Math.round(Date.now() / 1000 + 60)) // bid is valid for a minute
147-
const bid = await client.signBid(opportunity, {amount, nonce, deadline},privateKey)
141+
const privateKey = `0x0000`; // Private key of the searcher
142+
const bidAmount = BigInt(1000); // The bidAmount should be determined based on opportunity
143+
const deadline = BigInt(Math.round(Date.now() / 1000 + 60)) // Bid is valid for a minute
144+
const bid = await client.signBid(opportunity, {bidAmount, nonce, deadline}, privateKey)
148145
}
149146
```
150147
</Tabs.Tab>
@@ -161,25 +158,30 @@ from express_relay.express_relay_types import Opportunity, OpportunityBidParams
161158

162159
def opportunity_callback(opportunity: Opportunity):
163160
nonce = randbits(64)
164-
deadline = datetime.utcnow().timestamp() + 60 # bid is valid for a minute
165-
amount = 1000 # This should be determined based on the opportunity
166-
private_key = '0x00000'
161+
deadline = datetime.utcnow().timestamp() + 60 # Bid is valid for a minute
162+
bid_amount = 1000 # The bid_amount should be determined based on the opportunity
163+
private_key = '0x00000' # Private key of the searcher
167164
signed_bid = sign_bid(opportunity,
168-
OpportunityBidParams(amount=amount, deadline=int(deadline), nonce=nonce),
165+
OpportunityBidParams(amount=bid_amount, deadline=int(deadline), nonce=nonce),
169166
private_key)
170167
```
171168
</Tabs.Tab>
172169
</Tabs>
173170

174-
### Submit bids on opportunities to the auction server
175171

176-
Searchers can submit the constructed bids to the auction server via the SDKs, an HTTP POST request, or a WebSocket connection.
172+
173+
174+
If you prefer to use your own custom contracts instead of the `OpportunityAdapter`, please refer to the [custom contracts](./integrate-as-searcher/custom-contract.mdx) section.
175+
176+
### Submit bids on opportunities to Express Relay
177+
178+
Searchers can submit the constructed bids to Express Relay via the SDKs, an HTTP POST request, or a WebSocket connection.
177179

178180
<Tabs items={['Typescript', 'Python', 'HTTP', 'Websocket']}>
179181

180182
<Tabs.Tab>
181183

182-
The code snippet below demonstrates how to submit a bid using the Typescript SDK:
184+
The code snippet below demonstrates how to submit a bid using the `Typescript` SDK:
183185

184186
```typescript {4} copy
185187
const handleOpporunity = async (opportunity: Opportunity) => {
@@ -192,7 +194,7 @@ const handleOpporunity = async (opportunity: Opportunity) => {
192194
</Tabs.Tab>
193195
<Tabs.Tab>
194196

195-
The code snippet below demonstrates how to submit a bid using the Python SDK:
197+
The code snippet below demonstrates how to submit a bid using the `Python` SDK:
196198

197199
```python {5} copy
198200
def opportunity_callback(opportunity: Opportunity):
@@ -203,7 +205,7 @@ def opportunity_callback(opportunity: Opportunity):
203205
```
204206
</Tabs.Tab>
205207
<Tabs.Tab>
206-
Searchers can submit bids through an HTTP POST call to the `/v1/bids` endpoint. This endpoint accepts a JSON payload containing the details of the bid.
208+
Searchers can submit bids through an HTTP POST call to the [`/v1/bids`](https://pyth-express-relay-mainnet.asymmetric.re/redoc#tag/bid/operation/bid) endpoint. This endpoint accepts a JSON payload containing the details of the bid.
207209

208210
```bash copy
209211
curl -X POST https://pyth-express-relay-mainnet.asymmetric.re/v1/bids \

0 commit comments

Comments
 (0)