The code is the same on mainnet. The DvP program, the Pyth receiver program, and
the USDC/USD feed account have the same addresses on mainnet and devnet, so
only
RPC_URL, RPC_SUBSCRIPTIONS_URL, and the USDC mint change. Set
USDC_MINT to mainnet USDC,
EPjF…Dt1vUSDC mint (mainnet)EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vView on Solana Explorer (USDC mint (mainnet)).
What changes is who holds the keys and how you run the trade. Work through
this list before you settle trades for real investors.
1
Decide who holds the settlement key
The settlement authority named in a trade is the only key that can settle or
cancel it. It can’t change the amounts or who gets paid, which are fixed when
the trade is created, but it decides whether and when a funded trade settles.
In the example a generated key plays the agent. On mainnet, hold it in a
multisig or a signing service (see Solana Keychain),
and plan for it being unavailable: until it signs, the parties can only take
their legs back. The settlement authority can’t be one of the two parties.
2
Keep the price checks, and choose your limits
readPrice refuses an account that Pyth’s receiver program doesn’t own, a
different feed, a partly verified update, a price older than
MAX_PRICE_AGE_SECONDS, and a confidence interval wider than 0.5%. Keep every
check, and set the limits for your market: the age limit against the feed’s
update schedule, and the confidence limit against the risk you accept. If a
check fails, don’t create the trade.The price is fixed in the trade record at creation, and the program never reads
the oracle again. Set the trade’s expiry to how long you will honour that price.
The example allows one day; after the expiry, Settle fails with DvpExpired
and the parties take their legs back.3
Price the asset from your own source
The example prices LSF at a fixed $1.25 a share and uses the oracle only to
convert dollars into USDC. For a fund, the price per share is usually the net
asset value from the fund’s administrator (see
NAV strikes for funds). For an asset that
Pyth publishes a feed for, read that feed with the same checks.
4
Verify the record before every funding and settlement
Anyone can create a trade record naming any parties and any terms. Each party
reads the record before it funds, and the agent before it settles, as
verifyTrade does. See the
full list of fields to check.5
Approve the escrow under your compliance process
On a mint whose accounts start frozen, each trade’s escrow has to be approved
before it can be funded. In the example the issuer thaws it directly. With
Token ACL, add the trade record’s address to
the allowlist instead. While the trade is open, the issuer’s freeze, pause, and
permanent delegate authorities can still act on the escrowed tokens.
6
Book the trade at finalized
send waits for confirmed. Treat a trade as settled only when the Settle
transaction reaches finalized, and store the terms before you settle: the
record no longer exists afterwards. Whether finalized also marks settlement
finality for legal purposes depends on the parties’ agreements and the rules
that apply to them. Settle the trade
shows the wait for finalized in code.7
Plan for trades that don't settle
A party can take its own leg back while the trade is open, and either party or
the agent can cancel it. Write down who does what when a leg never arrives, the
price check fails at settlement time, or the trade expires. See
Unwind a trade.