Skip to content

fix(express-relay): Update endpoint and simplify nestings #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/express-relay/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

"api-reference": {
"title": "HTTP API Reference ↗",
"href": "https://pyth-express-relay-mainnet.asymmetric.re/docs",
"href": "https://per-mainnet.dourolabs.app/docs",
"newWindow": true
},
"websocket-api-reference": "Websocket API Reference",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ title: SVM
---

import { Tabs, Callout } from "nextra/components";
import AddressSvmTable from "../../../components/AddressSvmTable";
import AddressSvmTable from "../../components/AddressSvmTable";

# SVM Contract Addresses

Express Relay is currently deployed on the following SVM environments:

<Tabs items={['Prod (Solana Mainnet-Beta)', 'Testing (Solana Mainnet-Beta)']}>
<Tabs.Tab>
Auction Server endpoint: https://pyth-express-relay-mainnet.asymmetric.re/
Auction Server endpoint: https://per-mainnet.dourolabs.app/

### Prod

Expand Down
File renamed without changes.
83 changes: 80 additions & 3 deletions pages/express-relay/integrate-as-protocol.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
# How to Integrate Express Relay as a Protocol
import { Steps } from "nextra/components";

This section covers how to integrate Express Relay for your use case. Please see the relevant section below for the use case of interest.
# How to Integrate Express Relay Swaps

- [Swaps](integrate-as-protocol/swaps)
This guide will explain how frontends can integrate Express Relay to empower swapping.

Copy link
Contributor Author

@m30m m30m May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a cut paste of the content of swaps.mdx

<Steps>
### Install the Express Relay SDK

Pyth provides a [Typescript SDK](https://www.npmjs.com/package/@pythnetwork/express-relay-js) to help developers integrate Express Relay into their frontends.

You can install the SDK via npm or yarn. You can invoke the SDK client as below:

```typescript
import { Client } from "@pythnetwork/express-relay-js";

const client = new Client(
{ baseUrl: "https://per-mainnet.dourolabs.app" },
undefined // Default WebSocket options
);
```

### Request a Quote

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.

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:

```typescript
const userWallet = new PublicKey("<INPUT USER PUBKEY>");

const quoteRequest = {
chainId: "solana",
inputTokenMint: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), // USDC mint
outputTokenMint: new PublicKey("So11111111111111111111111111111111111111112"), // WSOL mint
specifiedTokenAmount: {
side: "input",
amount: 100_000_000,
},
userWallet,
};

const quote = await client.getQuote(quoteRequest);
```

`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`.

### Submit User Signature to the Express Relay Server

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.

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.

```typescript
const submitQuote = {
chainId: "solana",
referenceId: quote.referenceId,
userSignature: signature,
};

const txSubmitted = await client.submitQuote(submitQuote);
```

`submitQuote` returns the fully signed transaction that the server submitted to the RPC node.

</Steps>

## Additional Resources

You may find these additional resources helpful for integrating Express Relay as a frontend.

### Contract Addresses

The [SVM](./contract-addresses.mdx) Contract Addresses page lists the relevant addresses for Express Relay integration.

### Error Codes

The [SVM](./errors.mdx) Error Codes page lists the error codes returned by Express Relay.

### API Reference

The [API Reference](https://per-mainnet.dourolabs.app/docs) provides detailed information on Express Relay APIs.
3 changes: 0 additions & 3 deletions pages/express-relay/integrate-as-protocol/_meta.json

This file was deleted.

82 changes: 0 additions & 82 deletions pages/express-relay/integrate-as-protocol/swaps.mdx

This file was deleted.

16 changes: 8 additions & 8 deletions pages/express-relay/integrate-as-searcher/svm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Callout, Tabs, Steps } from "nextra/components";

# SVM Searcher Integration

SVM Express Relay searchers fulfill opportunities representing limit orders on the [Limo](https://solscan.io/account/LiMoM9rMhrdYrfzUCxQppvxCSG1FcrUK9G8uLq4A1GF) program.
SVM Express Relay searchers fulfill market order opportunities as well as limit orders on the [Limo](https://solscan.io/account/LiMoM9rMhrdYrfzUCxQppvxCSG1FcrUK9G8uLq4A1GF) program.

<Steps>

Expand All @@ -25,7 +25,7 @@ const handleOpportunity = async (opportunity: Opportunity) => {
};

const client = new Client(
{ baseUrl: "https://pyth-express-relay-mainnet.asymmetric.re" },
{ baseUrl: "https://per-mainnet.dourolabs.app" },
undefined, // Default WebSocket options
handleOpportunity
);
Expand Down Expand Up @@ -53,7 +53,7 @@ async def opportunity_callback(opportunity: Opportunity):
# Implement your opportunity handler here

client = ExpressRelayClient(
"https://pyth-express-relay-mainnet.asymmetric.re",
"https://per-mainnet.dourolabs.app",
None,
opportunity_callback,
None,
Expand All @@ -70,18 +70,18 @@ if __name__ == "__main__":

</Tabs.Tab>
<Tabs.Tab>
Searchers can request opportunities through an HTTP **GET** call to the [`/v1/opportunities`](https://pyth-express-relay-mainnet.asymmetric.re/docs#tag/opportunity/operation/get_opportunities) endpoint.
Searchers can request opportunities through an HTTP **GET** call to the [`/v1/opportunities`](https://per-mainnet.dourolabs.app/docs#tag/opportunity/operation/get_opportunities) endpoint.

```bash copy
curl -X 'GET' \
'https://pyth-express-relay-mainnet.asymmetric.re/v1/opportunities?chain_id=solana&mode=live'
'https://per-mainnet.dourolabs.app/v1/opportunities?chain_id=solana&mode=live'
```

Opportunities are short-lived and could be executed in a matter of seconds. So, the above endpoint could return an empty response.

</Tabs.Tab>
<Tabs.Tab>
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`).
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://per-mainnet.dourolabs.app/v1/ws`).
Here is a sample JSON payload to subscribe to opportunities:

```bash copy
Expand Down Expand Up @@ -289,10 +289,10 @@ def opportunity_callback(opportunity: Opportunity):

</Tabs.Tab>
<Tabs.Tab>
Searchers can submit bids through an HTTP POST call to the [`/v1/bids`](https://pyth-express-relay-mainnet.asymmetric.re/docs#tag/bid/operation/bid) endpoint. This endpoint accepts a JSON payload containing the details of the bid.
Searchers can submit bids through an HTTP POST call to the [`/v1/bids`](https://per-mainnet.dourolabs.app/docs#tag/bid/operation/bid) endpoint. This endpoint accepts a JSON payload containing the details of the bid.

```bash copy
curl -X POST https://pyth-express-relay-mainnet.asymmetric.re/v1/bids \
curl -X POST https://per-mainnet.dourolabs.app/v1/bids \
-H "Content-Type: application/json" \
-d '{
"chain_id": "solana",
Expand Down
4 changes: 2 additions & 2 deletions pages/express-relay/websocket-api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Tabs } from "nextra/components";
# WebSocket API Reference

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`).
The WebSocket endpoint lives at `/v1/ws`(e.g `wss://per-mainnet.dourolabs.app/v1/ws`).

## General format

Expand Down Expand Up @@ -60,7 +60,7 @@ After a successful subscription, you will receive new opportunities for the sele
}
```

The schema for the opportunity is similar to what’s returned in the [HTTP requests](https://pyth-express-relay-mainnet.asymmetric.re/docs#tag/opportunity/operation/get_opportunities).
The schema for the opportunity is similar to what’s returned in the [HTTP requests](https://per-mainnet.dourolabs.app/docs#tag/opportunity/operation/get_opportunities).

To unsubscribe from a list of chains, you can send the following message:

Expand Down
Loading