-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
<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. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is just a cut paste of the content of
swaps.mdx