Skip to content

Commit 48bee12

Browse files
Merge pull request #3020 from pyth-network/add-express-relay-guides
feat(developer-hub): add how to guides for express relay
2 parents 05bc1c5 + 6058e98 commit 48bee12

File tree

10 files changed

+574
-75
lines changed

10 files changed

+574
-75
lines changed

apps/developer-hub/content/docs/express-relay/how-to-guides/index.mdx

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/developer-hub/content/docs/express-relay/index.mdx

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ icon: Gavel
66
full: true
77
---
88

9+
import { IntegrationCard } from "../../../src/components/IntegrationCard";
10+
import {
11+
Files,
12+
MagnifyingGlass,
13+
Question,
14+
} from "@phosphor-icons/react/dist/ssr";
15+
916
# Introduction
1017

1118
Express Relay is a priority auction which enables better orderflow mechanisms that eliminate [Maximal Extractable Value](https://www.ledger.com/academy/glossary/maximal-extractable-value-mev) (MEV).
@@ -25,23 +32,15 @@ To integrate with Express Relay, you can integrate as a protocol (to power token
2532
colorScheme="blue"
2633
title="Integrate as a Protocol"
2734
description="Power token swaps and recapture MEV with Express Relay integration"
28-
icon={
29-
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
30-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
31-
</svg>
32-
}
35+
icon={<Files size={16} />}
3336
/>
3437

3538
<IntegrationCard
3639
href="./integrate-as-searcher"
3740
colorScheme="green"
3841
title="Integrate as a Searcher"
3942
description="Access unified orderflow opportunities across DeFi protocols"
40-
icon={
41-
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
42-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
43-
</svg>
44-
}
43+
icon={<MagnifyingGlass size={16} />}
4544
/>
4645
</div>
4746

@@ -55,15 +54,6 @@ To learn more about Express Relay, refer to the following resources:
5554
colorScheme="purple"
5655
title="How Express Relay Works"
5756
description="Understand the mechanics behind Express Relay's priority auction system"
58-
icon={
59-
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
60-
<path
61-
strokeLinecap="round"
62-
strokeLinejoin="round"
63-
strokeWidth={2}
64-
d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
65-
/>
66-
</svg>
67-
}
57+
icon={<Question size={16} />}
6858
/>
6959
</div>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: "Integrate as a Protocol"
3+
description: >-
4+
Learn how frontends can integrate Express Relay to empower token swapping with better pricing and MEV recapture.
5+
---
6+
7+
# How to Integrate Express Relay Swaps
8+
9+
This guide will explain how frontends can integrate Express Relay to empower swapping.
10+
11+
## Step 1: Install the Express Relay SDK
12+
13+
Pyth provides a [Typescript SDK](https://www.npmjs.com/package/@pythnetwork/express-relay-js) to help developers integrate Express Relay into their frontends.
14+
15+
You can install the SDK via npm or yarn. You can invoke the SDK client as below:
16+
17+
```typescript
18+
import { Client } from "@pythnetwork/express-relay-js";
19+
20+
const client = new Client(
21+
{ baseUrl: "https://per-mainnet.dourolabs.app" },
22+
undefined, // Default WebSocket options
23+
);
24+
```
25+
26+
## Step 2: Request a Quote
27+
28+
You can request a quote by calling the [**getQuote**](https://github.com/pyth-network/per/blob/281de989db887aaf568fed39315a76acc16548fa/sdk/js/src/index.ts#L501-L506) SDK method.
29+
30+
The example below shows how you can construct a quote request for a USDC → WSOL swap, with 100 USDC provided as input by the user:
31+
32+
```typescript
33+
const userWallet = new PublicKey("<INPUT USER PUBKEY>");
34+
35+
const quoteRequest = {
36+
chainId: "solana",
37+
inputTokenMint: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), // USDC mint
38+
outputTokenMint: new PublicKey("So11111111111111111111111111111111111111112"), // WSOL mint
39+
specifiedTokenAmount: {
40+
side: "input",
41+
amount: 100_000_000,
42+
},
43+
userWallet,
44+
};
45+
46+
const quote = await client.getQuote(quoteRequest);
47+
```
48+
49+
**quote** contains the full details, including the amount the searcher is quoting and the transaction that the user needs to sign. It also contains an **expirationTime**; after this time, the transaction will no longer succeed on chain, so you should request a new quote a few seconds before the **expirationTime**.
50+
51+
## Step 3: Submit User Signature to the Express Relay Server
52+
53+
Once you show the quote to the user, the user should sign the transaction if they wish to engage in the swap. The frontend can pass this signature along to the Express Relay server, which will handle aggregating all the required signatures for the transaction and submitting it to the RPC node.
54+
55+
Below is an example showing how the frontend can submit the signed quote transaction to the server using the [**submitQuote**](https://github.com/pyth-network/per/blob/358eedc1f9072cdfc3418fba309697580f2474f9/sdk/js/src/index.ts#L537-L542) method. The response from the **getQuote** method includes a field called **referenceId**, which the frontend should use in its submission of the user signature.
56+
57+
```typescript
58+
const submitQuote = {
59+
chainId: "solana",
60+
referenceId: quote.referenceId,
61+
userSignature: signature,
62+
};
63+
64+
const txSubmitted = await client.submitQuote(submitQuote);
65+
```
66+
67+
**submitQuote** returns the fully signed transaction that the server submitted to the RPC node.
68+
69+
## Additional Resources
70+
71+
You may find these additional resources helpful for integrating Express Relay as a frontend.
72+
73+
### Contract Addresses
74+
75+
The [Contract Addresses](./contract-addresses) page lists the relevant addresses for Express Relay integration.
76+
77+
### Error Codes
78+
79+
The [Error Codes](./errors) page lists the error codes returned by Express Relay.
80+
81+
### API Reference
82+
83+
The [API Reference](https://per-mainnet.dourolabs.app/docs) provides detailed information on Express Relay APIs.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: "Integrate as a Searcher"
3+
description: >-
4+
Integrate once and access all existing and future opportunities across integrated DeFi protocols through Express Relay's bidding system.
5+
---
6+
7+
import { IntegrationCard } from "../../../../src/components/IntegrationCard";
8+
import { Code } from "@phosphor-icons/react/dist/ssr";
9+
10+
# How to Integrate Express Relay as a Searcher
11+
12+
Express Relay allows searchers to integrate once and access all existing and future opportunities across integrated DeFi protocols. Searchers **bid** on these opportunities exposed by Express Relay.
13+
14+
Express Relay exposes different endpoints for interaction, which can be used directly via HTTP, WebSocket, or one of the SDKs for convenience.
15+
16+
## What is a Searcher?
17+
18+
Searchers are sophisticated actors who monitor blockchain networks for profitable opportunities such as arbitrage, liquidations, and MEV extraction. With Express Relay, searchers can:
19+
20+
- **Access unified opportunities** across multiple integrated DeFi protocols
21+
- **Compete in fair auctions** for the right to fulfill user transactions
22+
- **Capture value** while providing better execution for users
23+
24+
## Integration Methods
25+
26+
Express Relay provides multiple ways for searchers to integrate:
27+
28+
- **Direct API integration** using HTTP and WebSocket endpoints
29+
- **SDK integration** with [Typescript](https://github.com/pyth-network/per/tree/main/sdk/js) and [Python](https://github.com/pyth-network/per/tree/main/sdk/python) SDKs
30+
- **Real-time subscriptions** for opportunity monitoring
31+
32+
## Integration Process
33+
34+
Searchers can integrate with Express Relay in three key steps:
35+
36+
### Step 1: Subscribe to New Opportunities
37+
38+
Monitor opportunities across integrated DeFi protocols in real-time using Express Relay's WebSocket or HTTP endpoints. Opportunities include:
39+
40+
- **Market orders** from integrated protocols requiring immediate execution
41+
- **Limit orders** on supported order book systems
42+
- **Liquidation opportunities** from lending and borrowing protocols
43+
- **Arbitrage opportunities** across different decentralized exchanges
44+
45+
### Step 2: Construct and Submit Your Bid
46+
47+
Analyze opportunities and construct competitive bids based on:
48+
49+
- **Your execution strategy** and available capital
50+
- **Gas costs** and transaction efficiency considerations
51+
- **Expected profit margins** and risk assessment
52+
- **Competition** from other searchers in the auction
53+
54+
Submit bids to Express Relay's auction system where the highest bidder wins the right to fulfill the opportunity.
55+
56+
### Step 3: Execute Won Opportunities
57+
58+
If your bid wins the auction, execute the opportunity by:
59+
60+
- **Fulfilling the user's transaction** according to the opportunity parameters
61+
- **Capturing the bid amount** as compensation for providing the service
62+
- **Ensuring proper execution** to maintain reputation in the system
63+
64+
## Supported Chains
65+
66+
Searchers can currently integrate with Express Relay on **Solana Virtual Machine (SVM)** chains, with support for additional chains coming soon.
67+
68+
## Getting Started
69+
70+
Ready to integrate as a searcher? Start with our detailed integration guides:
71+
72+
<div className="mt-8">
73+
<IntegrationCard
74+
href="./svm"
75+
colorScheme="blue"
76+
title="Integrate with Express Relay on SVM Chains"
77+
description="Complete guide for integrating Express Relay on Solana Virtual Machine chains with code examples and best practices"
78+
icon={<Code size={16} />}
79+
/>
80+
</div>
81+
82+
## Additional Resources
83+
84+
Explore these resources to enhance your searcher integration:
85+
86+
### API Documentation
87+
88+
- **[WebSocket API Reference](./websocket-api-reference)** - Real-time opportunity streaming
89+
- **[HTTP API Reference](./http-api-reference)** - REST endpoints for opportunities and bidding
90+
91+
### Technical Resources
92+
93+
- **[Contract Addresses](./contract-addresses)** - Smart contract addresses across supported chains
94+
- **[Error Codes](./errors)** - Complete list of error codes and troubleshooting guide
95+
96+
### Understanding Express Relay
97+
98+
- **[How Express Relay Works](./how-express-relay-works)** - Deep dive into the auction mechanism and architecture
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Integrate as a Searcher",
3+
"pages": ["svm"]
4+
}

0 commit comments

Comments
 (0)