Skip to content

feat(templates): add raydium-hello-world community template - #449

Open
cxalem wants to merge 8 commits into
solana-foundation:mainfrom
cxalem:feat/raydium-hello-world
Open

feat(templates): add raydium-hello-world community template#449
cxalem wants to merge 8 commits into
solana-foundation:mainfrom
cxalem:feat/raydium-hello-world

Conversation

@cxalem

@cxalem cxalem commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

What

New community template: raydium-hello-world — a Next.js + wallet-adapter + @raydium-io/raydium-sdk-v2 starter that swaps on a Raydium CPMM pool, devnet-first. Sibling to drift-hello-world in the protocol-intro series.

What it teaches:

  • Raydium SDK init in a browser dApp: wallet PublicKey + signAllTransactions — no secret keys anywhere
  • CPMM pool anatomy: reserves from RPC via cpmm.getPoolInfoFromRpc, price derived locally
  • Per-keystroke local quoting with CurveCalculator (the on-chain constant-product math, zero RPC per keypress)
  • Building, signing, and confirming a V0 swap transaction on devnet (incl. SOL wrapping)

Follows the kit-family design guidelines: Solana-branded grid background, neutral tokens, Inter + Geist Mono, next-themes dark mode, sonner toasts, shadcn primitives.

Deliberate decisions

  • Devnet-pinned, no ClusterSelect — the default pool only exists on devnet; a cluster switcher would break the core flow. Pool is env-overridable (NEXT_PUBLIC_POOL_ID) and the in-app error state teaches recovery when a devnet pool dies (they do).
  • .env.example committed via a !.env.example gitignore exception (placeholders only) — it documents the four optional env vars; the template runs with zero config.
  • SDK pinned exact (0.2.60-alpha) — it's an alpha line; caret ranges would break fresh scaffolds on breaking alphas.
  • Quote and amount travel as an atomic pair, and the quote object is cloned before cpmm.swap because the SDK applies the slippage discount by mutating the object passed in (retries would otherwise compound the discount).
  • Generated catalog files intentionally not committed — they auto-commit on merge per generate-metadata.yml.

Review

Pre-push review ran through a dual-review agent pipeline (two independent reviewers + an external Codex pass auditing the decision log); all blocking findings fixed: quote/amount pairing, swapResult clone, .env.example shipping, README accuracy, full-signature copy affordance, wallet errors surfaced as toasts.

Test plan

  • tsc --noEmit, template eslint, next build, repo lint (structure + prettier), pnpm generate + validate: all pass locally under pnpm 10.5.2
  • Build-only swap transaction verified against the live devnet pool
  • Draft until: end-to-end wallet swap re-verified on the final code + Raydium-branded og-image replaces the neutral placeholder; screenshots to be added then

cxalem and others added 3 commits August 3, 2026 19:34
App shell, wallet connection (devnet-first), and component structure
for a Raydium CPMM swap starter. SDK integration marked as TODO(raydium)
in use-pool.ts, lib/raydium.ts and swap-card.tsx. README documents the
devnet pool-discovery endpoint and faucet guidance.
Bring the template in line with the kit-family design spec: Solana-branded
GridBackground (brand colors in the grid only), Inter + Geist Mono, the
neutral token set with cream/border-low, shadcn ui primitives, next-themes
dark mode with toggle, sonner toasts, wallet-adapter button restyled to
neutral, and explorer/ellipsify utils. Cluster is intentionally pinned to
devnet, so no ClusterSelect.
Pool fetch from RPC, local CurveCalculator quoting, wallet-signed
devnet swap. Applies triple-review findings: quote/amount atomic
pairing, swapResult cloned before cpmm.swap (SDK mutates it in
place), env.example shipped via gitignore exception, README trued
up to the implementation, copy-full-signature affordance, wallet
errors surfaced as toasts. Reverts accidental pnpm allowBuilds
scaffold in pnpm-workspace.yaml.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cxalem
cxalem marked this pull request as ready for review August 3, 2026 17:40
@cxalem
cxalem requested a review from catmcgee as a code owner August 3, 2026 17:40
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds a devnet-first Raydium CPMM swap template using Next.js, wallet-adapter, and Raydium SDK v2.

  • Adds browser-side pool loading, local constant-product quoting, wallet signing, and transaction confirmation.
  • Invalidates quotes by both input amount and pool-bundle identity.
  • Clears pool state synchronously during refreshes and sequence-guards overlapping loads.
  • Adds template configuration, documentation, styling, and dependency metadata.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
community/raydium-hello-world/src/hooks/use-swap.ts Keys quote state to the exact amount and pool bundle, preventing the previously reported stale quotes from remaining visible or executable.
community/raydium-hello-world/src/hooks/use-pool.ts Clears stale pool data at refresh start and prevents overlapping requests from committing out-of-order results.
community/raydium-hello-world/src/components/swap/swap-card.tsx Enables execution only when a current quote and bundle exist and keeps the button disabled while a swap is active.
community/raydium-hello-world/src/lib/raydium.ts Implements SDK initialization, local CPMM quoting, amount conversion, and transaction execution for the template.
community/raydium-hello-world/package.json Defines the new template metadata, scripts, and pinned Raydium and wallet-adapter dependencies.

Sequence Diagram

sequenceDiagram
  participant U as User
  participant UI as Swap UI
  participant P as usePool
  participant S as useSwap
  participant R as Raydium/Solana
  P->>R: Load pool and reserves
  R-->>P: Pool bundle
  P-->>S: Current bundle
  U->>UI: Enter amount
  UI->>S: Current amount
  S->>S: Compute local quote
  S-->>UI: Quote keyed by amount and bundle
  U->>UI: Confirm swap
  UI->>S: Execute current quote
  S->>R: Build, sign, submit, confirm
  R-->>S: Transaction signature
  S->>P: Refresh pool
  P-->>UI: Clear bundle and disable Swap
  P->>R: Reload reserves
Loading

Reviews (5): Last reviewed commit: "fix(templates): invalidate pool data syn..." | Re-trigger Greptile

Comment thread community/raydium-hello-world/src/hooks/use-swap.ts
cxalem and others added 2 commits August 3, 2026 19:57
A quote now records the exact input string it was computed for and is
only visible (and executable) while it matches the current input. This
closes the window where a stale quote stayed on screen with Swap
enabled during async recomputation and could execute an amount
different from the one displayed. Addresses the Greptile P1 finding.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread community/raydium-hello-world/src/hooks/use-swap.ts Outdated
A quote is now valid only for the exact (amount, bundle) pair it was
computed from. The amount-only check left a window after pool refresh
(guaranteed after every confirmed swap) where old-reserve math stayed
executable against the new bundle. Addresses the second Greptile P1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread community/raydium-hello-world/src/components/swap/swap-card.tsx
Closes the bug class behind the three staleness findings: any value
derived from async state must be bound to the inputs that produced it
and invalidated the moment those inputs are known-stale. refresh() now
clears the bundle synchronously (killing quotes and the Swap button
until fresh reserves land — including right after our own swap) and a
sequence guard prevents overlapping refreshes landing out of order.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@SrMessiSOL

Copy link
Copy Markdown
Collaborator

I reviewed the PR, including the existing Greptile threads and the latest fixes. The stale-quote issues look addressed, and I confirmed the branch merges cleanly into current main.

I would not approve yet only because the required checks are still failing (generate and Validate Template Metadata). Once those are rerun and green, this looks close to approval.

One small non-blocking wording suggestion: .env.example correctly says NEXT_PUBLIC_* values are browser-exposed, but the RPC example shows a Helius API-key URL. It may be safer to clarify that this should only be a public/throwaway devnet RPC endpoint, not a private or paid key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants