Abstract
Following the upgrading of the Pyth Express Relay program on Solana (OP-PIP54) to introduce swapping, this proposal aims to upgrade the Pyth Express Relay Program to introduce an improved and more configurable swap instruction. It also introduces a secondary relayer field to minimize downtime in case of transitions between relayers.
Rationale
The swapping mechanism introduced in OP-PIP54 has powered over $25M in swap volume since its launch on April 2. Currently, the swap instruction has a fixed fee rate set in the Express Relay metadata account; however, efficient swap fees will likely differ by token pair as is the case across TradFi, CeFi, and DeFi: stable and liquid pairs will have lower fees than very volatile and illiquid pairs since there will be a greater supply of liquidity providers for the former. For the most liquid pairs, stable fee rates might even be below 1 bp, which is not possible in the current fee model.
Moreover, the current instruction assumes the existence of several token accounts, which necessitates their creation prior to swapping if they don’t currently exist. This creation involves paying the rent for the token accounts, which implicitly worsens the quote provided by the Express Relay searchers. Currently, as the fees are 0, the Express Relay fee receiver should not receive any tokens, and thus the token accounts don’t need to be created.
We are proposing to improve the swap instruction on the Express Relay program by creating a V2 swap instruction which addresses the aforementioned issues.
Description
The updates to the program include:
- Relaxing ATA constraints on fee receiver’s token accounts, to only check their existence if the fees are positive.
- Adding a new instruction (
swap_v2
) where swap fee is determined by the input. - Adding parts per million (PPM) precision to
swap_v2
fees. - Adding a secondary relayer for 0-downtime transitions between relayers.
With regard to the last change, in case of future updates to the relayer entity or the hot wallet used as the relayer’s signing wallet, we wish to avoid any downtime caused by delay between updating the relayer signer pubkey on the program and beginning to sign transactions with that wallet on the server. Adding a secondary relayer signer to allow either relayer signer to sign would allow a smoother transition between relayers.
With respect to making the swap platform fee determined by the input, this serves to address the issue of a single static fee rate being applied to all trading pairs and contexts. Previously, the referral fee was provided as an input argument while the platform fee was inferred from the static data in the Express Relay metadata account. Now both fees are dynamically provided, to enable ease of setting dynamic fees intelligently.
Implementation Plan
- Proposal id: 4fckPJqwoLe84Kt96MrWNwTKGxpiyTDPTSFGjJAYjmg9
- Extend the Pyth Express Relay Program with a
swap_v2
instruction and aset_secondary_relayer
instruction (and addsecondary_relayer
field to the Express Relay metadata account):- PR #451 added a
swap_v2
instruction which has the platform fee as an input argument, rather than inferring it from the Express Relay metadata account. It also relaxed the ATA initialization constraints to only check the existence of certain token accounts when there are actually fees to be received. Finally, it added the secondary relayer field and an instruction to set the secondary relayer. - PR #460 added some tests associated with the changes above.
- PR #462 fixed some checks around the ATA constraint relaxation to ensure that the fee receiver’s token accounts are the canonical ATAs.
- PR #472 converts the
swap_v2
instruction’s fees to be in parts per million (PPM) rather than basis points (BPs).
- PR #451 added a
- Verification steps (Skip to step 12 if you don’t want to build the program locally):
- Make sure you have git, rust and Docker installed.
- git: install
git
from here - rust: install
rust
from here - Docker: install Docker from here
- Install the
solana
cli:sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
- Install the
solana-verify
cli :cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 121568e
- clone the per repo by running the following command:
git clonehttps://github.com/pyth-network/per
- change your directory to
per/contracts/svm
by doingcd per/contracts/svm
- checkout commit
a6d360b
by doinggit checkout a6d360b9418fa2636ea69a634cb083fcfbccefe1
- Build the program by running
solana-verify build
- Check the hash of the artifact
sha256sum target/deploy/express_relay.so
- Alternatively you can check the hash in this Github workflow that builds the program in “Print Hash”.
- check the hash of the deployed buffer
solana program -u m dump 4dfyBNQs6sGxFpCb5XRx8AajEq1UviXAor9ygZqRjE2b temp_file && sha256sum temp_file && rm temp_file
. - Make sure the hash from step 11 (or 12) and 13 match
- Make sure the upgrade authority of the buffer
4dfyBNQs6sGxFpCb5XRx8AajEq1UviXAor9ygZqRjE2b
is the Pythian Council6oXTdojyfDS8m5VtTaYB9xRCxpKGSvKJFndLUPV3V3wT