-
Notifications
You must be signed in to change notification settings - Fork 308
feat(developer-hub): add how to guides for express relay #3020
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
Changes from 2 commits
c492af4
da2fd14
3c0297d
7763d6d
6058e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| --- | ||
| title: "Integrate as a Protocol" | ||
| description: >- | ||
| Learn how frontends can integrate Express Relay to empower token swapping with better pricing and MEV recapture. | ||
| --- | ||
|
|
||
| # How to Integrate Express Relay Swaps | ||
|
|
||
| This guide will explain how frontends can integrate Express Relay to empower swapping. | ||
|
|
||
| <div className="steps-container mt-8"> | ||
| <div className="step"> | ||
| <div className="step-header"> | ||
| <div className="step-number">1</div> | ||
| <h3>Install the Express Relay SDK</h3> | ||
| </div> | ||
| <div className="step-content"> | ||
| <p>Pyth provides a <a href="https://www.npmjs.com/package/@pythnetwork/express-relay-js" target="_blank" rel="noopener noreferrer">Typescript SDK</a> to help developers integrate Express Relay into their frontends.</p> | ||
|
|
||
| <p>You can install the SDK via npm or yarn. You can invoke the SDK client as below:</p> | ||
|
|
||
| ```typescript | ||
| import { Client } from "@pythnetwork/express-relay-js"; | ||
|
|
||
| const client = new Client( | ||
| { baseUrl: "https://per-mainnet.dourolabs.app" }, | ||
| undefined // Default WebSocket options | ||
| ); | ||
| ``` | ||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
| <div className="step"> | ||
| <div className="step-header"> | ||
| <div className="step-number">2</div> | ||
| <h3>Request a Quote</h3> | ||
| </div> | ||
| <div className="step-content"> | ||
| <p>You can request a quote by calling the <a href="https://github.com/pyth-network/per/blob/281de989db887aaf568fed39315a76acc16548fa/sdk/js/src/index.ts#L501-L506" target="_blank" rel="noopener noreferrer"><strong>getQuote</strong></a> SDK method.</p> | ||
|
|
||
| <p>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:</p> | ||
|
|
||
| ```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); | ||
| ``` | ||
|
|
||
| <p><strong>quote</strong> contains the full details, including the amount the searcher is quoting and the transaction that the user needs to sign. It also contains an <strong>expirationTime</strong>; after this time, the transaction will no longer succeed on chain, so you should request a new quote a few seconds before the <strong>expirationTime</strong>.</p> | ||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
| <div className="step"> | ||
| <div className="step-header"> | ||
| <div className="step-number">3</div> | ||
| <h3>Submit User Signature to the Express Relay Server</h3> | ||
| </div> | ||
| <div className="step-content"> | ||
| <p>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.</p> | ||
|
|
||
| <p>Below is an example showing how the frontend can submit the signed quote transaction to the server using the <a href="https://github.com/pyth-network/per/blob/358eedc1f9072cdfc3418fba309697580f2474f9/sdk/js/src/index.ts#L537-L542" target="_blank" rel="noopener noreferrer"><strong>submitQuote</strong></a> method. The response from the <strong>getQuote</strong> method includes a field called <strong>referenceId</strong>, which the frontend should use in its submission of the user signature.</p> | ||
|
|
||
| ```typescript | ||
| const submitQuote = { | ||
| chainId: "solana", | ||
| referenceId: quote.referenceId, | ||
| userSignature: signature, | ||
| }; | ||
|
|
||
| const txSubmitted = await client.submitQuote(submitQuote); | ||
| ``` | ||
|
|
||
| <p><strong>submitQuote</strong> returns the fully signed transaction that the server submitted to the RPC node.</p> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| You may find these additional resources helpful for integrating Express Relay as a frontend. | ||
|
|
||
| ### Contract Addresses | ||
|
|
||
| The [Contract Addresses](./contract-addresses) page lists the relevant addresses for Express Relay integration. | ||
|
|
||
| ### Error Codes | ||
|
|
||
| The [Error Codes](./errors) 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| --- | ||
| title: "Integrate as a Searcher" | ||
| description: >- | ||
| Integrate once and access all existing and future opportunities across integrated DeFi protocols through Express Relay's bidding system. | ||
| --- | ||
|
|
||
| import { IntegrationCard } from "../../../src/components/IntegrationCard"; | ||
|
|
||
| # How to Integrate Express Relay as a Searcher | ||
|
|
||
| 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. | ||
|
|
||
| Express Relay exposes different endpoints for interaction, which can be used directly via HTTP, WebSocket, or one of the SDKs for convenience. | ||
|
|
||
| ## What is a Searcher? | ||
|
|
||
| Searchers are sophisticated actors who monitor blockchain networks for profitable opportunities such as arbitrage, liquidations, and MEV extraction. With Express Relay, searchers can: | ||
|
|
||
| - **Access unified opportunities** across multiple integrated DeFi protocols | ||
| - **Compete in fair auctions** for the right to fulfill user transactions | ||
| - **Capture value** while providing better execution for users | ||
|
|
||
| ## Integration Methods | ||
|
|
||
| Express Relay provides multiple ways for searchers to integrate: | ||
|
|
||
| - **Direct API integration** using HTTP and WebSocket endpoints | ||
| - **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 | ||
| - **Real-time subscriptions** for opportunity monitoring | ||
|
|
||
| ## Integration Process | ||
|
|
||
| Searchers can integrate with Express Relay in three key steps: | ||
|
|
||
| ### Step 1: Subscribe to New Opportunities | ||
|
|
||
| Monitor opportunities across integrated DeFi protocols in real-time using Express Relay's WebSocket or HTTP endpoints. Opportunities include: | ||
|
|
||
| - **Market orders** from integrated protocols requiring immediate execution | ||
| - **Limit orders** on supported order book systems | ||
| - **Liquidation opportunities** from lending and borrowing protocols | ||
| - **Arbitrage opportunities** across different decentralized exchanges | ||
|
|
||
| ### Step 2: Construct and Submit Your Bid | ||
|
|
||
| Analyze opportunities and construct competitive bids based on: | ||
|
|
||
| - **Your execution strategy** and available capital | ||
| - **Gas costs** and transaction efficiency considerations | ||
| - **Expected profit margins** and risk assessment | ||
| - **Competition** from other searchers in the auction | ||
|
|
||
| Submit bids to Express Relay's auction system where the highest bidder wins the right to fulfill the opportunity. | ||
|
|
||
| ### Step 3: Execute Won Opportunities | ||
|
|
||
| If your bid wins the auction, execute the opportunity by: | ||
|
|
||
| - **Fulfilling the user's transaction** according to the opportunity parameters | ||
| - **Capturing the bid amount** as compensation for providing the service | ||
| - **Ensuring proper execution** to maintain reputation in the system | ||
|
|
||
| ## Supported Chains | ||
|
|
||
| Searchers can currently integrate with Express Relay on **Solana Virtual Machine (SVM)** chains, with support for additional chains coming soon. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Ready to integrate as a searcher? Start with our detailed integration guides: | ||
|
|
||
| <div className="mt-8"> | ||
| <IntegrationCard | ||
| href="./integrate-as-searcher/svm" | ||
| colorScheme="blue" | ||
| title="Integrate with Express Relay on SVM Chains" | ||
| description="Complete guide for integrating Express Relay on Solana Virtual Machine chains with code examples and best practices" | ||
| icon={ | ||
| <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"> | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth={2} | ||
| d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" | ||
| /> | ||
| </svg> | ||
| } | ||
| /> | ||
| </div> | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| Explore these resources to enhance your searcher integration: | ||
|
|
||
| ### API Documentation | ||
|
|
||
| - **[WebSocket API Reference](./websocket-api-reference)** - Real-time opportunity streaming | ||
| - **[HTTP API Reference](./http-api-reference)** - REST endpoints for opportunities and bidding | ||
|
|
||
| ### Technical Resources | ||
|
|
||
| - **[Contract Addresses](./contract-addresses)** - Smart contract addresses across supported chains | ||
| - **[Error Codes](./errors)** - Complete list of error codes and troubleshooting guide | ||
|
|
||
| ### Understanding Express Relay | ||
|
|
||
| - **[How Express Relay Works](./how-express-relay-works)** - Deep dive into the auction mechanism and architecture |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| --- | ||
| title: "Integrate as a Searcher" | ||
| description: >- | ||
| Integrate once and access all existing and future opportunities across integrated DeFi protocols through Express Relay's bidding system. | ||
| --- | ||
|
|
||
| import { IntegrationCard } from "../../../../src/components/IntegrationCard"; | ||
|
|
||
| # How to Integrate Express Relay as a Searcher | ||
|
|
||
| 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. | ||
|
|
||
| Express Relay exposes different endpoints for interaction, which can be used directly via HTTP, WebSocket, or one of the SDKs for convenience. | ||
|
|
||
| ## What is a Searcher? | ||
|
|
||
| Searchers are sophisticated actors who monitor blockchain networks for profitable opportunities such as arbitrage, liquidations, and MEV extraction. With Express Relay, searchers can: | ||
|
|
||
| - **Access unified opportunities** across multiple integrated DeFi protocols | ||
| - **Compete in fair auctions** for the right to fulfill user transactions | ||
| - **Capture value** while providing better execution for users | ||
|
|
||
| ## Integration Methods | ||
|
|
||
| Express Relay provides multiple ways for searchers to integrate: | ||
|
|
||
| - **Direct API integration** using HTTP and WebSocket endpoints | ||
| - **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 | ||
| - **Real-time subscriptions** for opportunity monitoring | ||
|
|
||
| ## Integration Process | ||
|
|
||
| Searchers can integrate with Express Relay in three key steps: | ||
|
|
||
| ### Step 1: Subscribe to New Opportunities | ||
|
|
||
| Monitor opportunities across integrated DeFi protocols in real-time using Express Relay's WebSocket or HTTP endpoints. Opportunities include: | ||
|
|
||
| - **Market orders** from integrated protocols requiring immediate execution | ||
| - **Limit orders** on supported order book systems | ||
| - **Liquidation opportunities** from lending and borrowing protocols | ||
| - **Arbitrage opportunities** across different decentralized exchanges | ||
|
|
||
| ### Step 2: Construct and Submit Your Bid | ||
|
|
||
| Analyze opportunities and construct competitive bids based on: | ||
|
|
||
| - **Your execution strategy** and available capital | ||
| - **Gas costs** and transaction efficiency considerations | ||
| - **Expected profit margins** and risk assessment | ||
| - **Competition** from other searchers in the auction | ||
|
|
||
| Submit bids to Express Relay's auction system where the highest bidder wins the right to fulfill the opportunity. | ||
|
|
||
| ### Step 3: Execute Won Opportunities | ||
|
|
||
| If your bid wins the auction, execute the opportunity by: | ||
|
|
||
| - **Fulfilling the user's transaction** according to the opportunity parameters | ||
| - **Capturing the bid amount** as compensation for providing the service | ||
| - **Ensuring proper execution** to maintain reputation in the system | ||
|
|
||
| ## Supported Chains | ||
|
|
||
| Searchers can currently integrate with Express Relay on **Solana Virtual Machine (SVM)** chains, with support for additional chains coming soon. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Ready to integrate as a searcher? Start with our detailed integration guides: | ||
|
|
||
| <div className="mt-8"> | ||
| <IntegrationCard | ||
| href="./svm" | ||
| colorScheme="blue" | ||
| title="Integrate with Express Relay on SVM Chains" | ||
| description="Complete guide for integrating Express Relay on Solana Virtual Machine chains with code examples and best practices" | ||
| icon={ | ||
| <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"> | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth={2} | ||
| d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" | ||
| /> | ||
| </svg> | ||
|
||
| } | ||
| /> | ||
| </div> | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| Explore these resources to enhance your searcher integration: | ||
|
|
||
| ### API Documentation | ||
|
|
||
| - **[WebSocket API Reference](./websocket-api-reference)** - Real-time opportunity streaming | ||
| - **[HTTP API Reference](./http-api-reference)** - REST endpoints for opportunities and bidding | ||
|
|
||
| ### Technical Resources | ||
|
|
||
| - **[Contract Addresses](./contract-addresses)** - Smart contract addresses across supported chains | ||
| - **[Error Codes](./errors)** - Complete list of error codes and troubleshooting guide | ||
|
|
||
| ### Understanding Express Relay | ||
|
|
||
| - **[How Express Relay Works](./how-express-relay-works)** - Deep dive into the auction mechanism and architecture | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "title": "Integrate as a Searcher", | ||
| "pages": ["svm"] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we wanna import the component where we are using