> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Go live with trade settlement

> Before you settle real trades: the mainnet values, who holds the settlement key, which price checks to keep, and when a trade counts as settled.

<div className="sol-stepper not-prose" data-path="settle-trade">
<div className="sol-stepper-nav" role="navigation" aria-label="Settle a trade · ~40 min">
<ol>
<li data-state="done"><a href="/developers/docs/defi/settle-trade/try-it"><span className="sol-stepper-n">Step 1<span className="sol-vh">, </span><span className="sol-stepper-done">Done</span><span className="sol-vh">: </span></span><span className="sol-stepper-t">Watch a trade settle</span></a></li>
<li data-state="done"><a href="/developers/docs/defi/settle-trade/browser"><span className="sol-stepper-n">Step 2<span className="sol-vh">, </span><span className="sol-stepper-done">Done</span><span className="sol-vh">: </span></span><span className="sol-stepper-t">Read the code</span></a></li>
<li data-state="done"><a href="/developers/docs/defi/settle-trade/local"><span className="sol-stepper-n">Step 3<span className="sol-vh">, </span><span className="sol-stepper-done">Done</span><span className="sol-vh">: </span></span><span className="sol-stepper-t">Run it from your machine</span></a></li>
<li data-state="current"><a href="/developers/docs/defi/settle-trade/go-live" aria-current="step"><span className="sol-stepper-n">Step 4<span className="sol-vh">: </span></span><span className="sol-stepper-t">Go live</span></a></li>
</ol>
</div>
</div>

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,
<span className="sol-address" data-address="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"><Tooltip headline="USDC mint (mainnet)" tip="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" cta="View on Solana Explorer" href="https://explorer.solana.com/address/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v">`EPjF…Dt1v`</Tooltip><span className="nojs-only"> ([USDC mint (mainnet)](https://explorer.solana.com/address/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v))</span></span>.
What changes is who holds the keys and how you run the trade. Work through
this list before you settle trades for real investors.

<Steps>
<Step title="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](/developers/docs/tools/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.
</Step>
<Step title="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.
</Step>
<Step title="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](/developers/docs/tokenization/nav-strikes)). For an asset that
Pyth publishes a feed for, read that feed with the same checks.
</Step>
<Step title="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](/developers/docs/defi/dvp-program#verification-before-funding-and-settlement).
</Step>
<Step title="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](/developers/docs/tokenization/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.
</Step>
<Step title="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](/developers/docs/defi/dvp-program/settle-the-trade)
shows the wait for `finalized` in code.
</Step>
<Step title="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](/developers/docs/defi/dvp-program/unwind-a-trade).
</Step>
</Steps>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Confirmation & finality</span> <span className="sol-concept-def">A transaction goes from processed to finalized in well under a second, and once finalized it can't be reversed.</span>](/developers/docs/core/transactions/confirmation)
</div>

## You settled a trade

You priced a trade from an oracle and settled both legs in one transaction.
From here:

<Columns cols={2}>
<Card title="DvP program reference" icon="book" href="/developers/docs/defi/dvp-program">
Roles, accounts, errors, supported tokens, and limits.
</Card>
<Card title="DvP using delegation" icon="arrow-left-right" href="/developers/docs/tokenization/dvp">
Settle through token delegation instead of escrow.
</Card>
<Card title="Issue an asset" icon="layers" href="/developers/docs/assets/issue-asset" arrow>
The restricted asset this tutorial trades.
</Card>
<Card title="All markets guides" icon="chart-line" href="/developers/docs/defi">
Exchanges, settlement, MEV protection, and transaction delivery.
</Card>
</Columns>
