Skip to content

Add bonding curve swap, bucket fetch, and registration flags#109

Merged
MarkSackerberg merged 5 commits intomainfrom
feat/genesis-swap-and-flags
Apr 9, 2026
Merged

Add bonding curve swap, bucket fetch, and registration flags#109
MarkSackerberg merged 5 commits intomainfrom
feat/genesis-swap-and-flags

Conversation

@MarkSackerberg
Copy link
Copy Markdown
Contributor

Summary

  • New genesis swap command for buying/selling on bonding curves with --buyAmount / --sellAmount, auto-wrapping SOL to WSOL when needed
  • genesis swap --info for curve status, price quotes, and fee breakdown without transacting
  • genesis bucket fetch now auto-detects bucket type (no --type required), shows all buckets at an index when multiple exist, and supports --type bonding-curve
  • --creatorWallet and --twitterVerificationToken flags on genesis launch create and genesis launch register
  • Updated genesis SDK from v0.32.1 to v0.34.0 for devnet API compatibility (new bonding curve constants)

Test plan

  • 11 new mocha tests (flag validation, error paths, bucket fetch, registration flags)
  • All 38 existing genesis tests pass
  • Manual devnet testing: bucket fetch auto-detect, swap buy/sell, swap info with quotes, launch create with registration flags, validation errors
  • Auto-wrap SOL verified on devnet (works with no WSOL ATA, partial balance, and sufficient balance)
  • Multi-bucket auto-detect verified on localnet (launchpool + presale + unlocked at same index)

The devnet API now expects updated bonding curve constants (new supply/virtual
token ratios). SDK 0.32.1 payloads were rejected with validation errors.
- New `genesis swap` command for buying/selling on bonding curves
  with --info mode for price quotes and curve status
- Add bonding curve bucket type to `genesis bucket fetch`
  with pricing, reserves, and status display
- Add --creatorWallet and --twitterVerificationToken flags
  to `genesis launch create` and `genesis launch register`
- Tests for all new features (12 new test cases)
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@MarkSackerberg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 16 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 16 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 520b9f1a-6426-4d32-b187-99bdeb7af78d

📥 Commits

Reviewing files that changed from the base of the PR and between 3cdd19b and 88c618a.

📒 Files selected for processing (5)
  • src/commands/genesis/bucket/fetch.ts
  • src/commands/genesis/launch/create.ts
  • src/commands/genesis/launch/register.ts
  • src/commands/genesis/swap.ts
  • test/commands/genesis/genesis.swap.test.ts

Walkthrough

Updated the Genesis CLI to support bonding-curve bucket operations and swaps, with new flags for launch registration (--creatorWallet, --twitterVerificationToken). Added a new genesis swap command supporting buy/sell operations, auto-detection for bucket types in fetch, and dependency upgrade to @metaplex-foundation/genesis@^0.34.0.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Upgraded @metaplex-foundation/genesis from ^0.32.1 to ^0.34.0.
Bucket Fetch Enhancement
src/commands/genesis/bucket/fetch.ts
Added bonding-curve bucket type support; made --type flag optional with auto-detection logic that probes all known bucket PDAs in parallel; extended output to display bonding-curve-specific fields (pricing, reserves, swap window, status, fees).
Launch Registration Flags
src/commands/genesis/launch/create.ts, src/commands/genesis/launch/register.ts
Added --creatorWallet and --twitterVerificationToken flags; included public-key validation for --creatorWallet and forwarded values into registration payload.
Genesis Swap Command
src/commands/genesis/swap.ts
Implemented new genesis swap command with buy/sell amount parsing, slippage handling, SOL-to-WSOL wrapping when needed, and curve status display via --info flag; fetches Genesis account/bucket PDA and executes swapBondingCurveV2 transaction.
Documentation & Examples
src/commands/genesis/index.ts
Added usage examples for genesis swap subcommand (buy operation and --info mode).
Test Coverage
test/commands/genesis/genesis.swap.test.ts
Added comprehensive test suite covering genesis swap flag validation, bonding-curve bucket fetch, and launch create/register with registration flags; validates public-key format and error handling for invalid inputs.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as Genesis Swap<br/>Command
    participant Chain as Solana Chain
    participant SDK as Metaplex SDK
    
    User->>CLI: genesis swap --buyAmount 100000000
    
    CLI->>Chain: Fetch Genesis Account
    Chain-->>CLI: Genesis Account Data
    
    CLI->>Chain: Fetch Bonding Curve Bucket PDA
    Chain-->>CLI: Bucket Data
    
    CLI->>SDK: Compute Swap Quote<br/>(getSwapResult)
    SDK-->>CLI: Quote with Input/Output
    
    CLI->>SDK: Apply Slippage<br/>(applySlippage)
    SDK-->>CLI: Min Output Amount
    
    alt SOL Wrapping Needed
        CLI->>Chain: Create Associated Token Account
        Chain-->>CLI: Token Account Created
        CLI->>Chain: Transfer SOL
        Chain-->>CLI: SOL Transferred
        CLI->>Chain: Sync Native Account
        Chain-->>CLI: Account Synced
    end
    
    CLI->>SDK: Build Swap Transaction<br/>(swapBondingCurveV2)
    SDK-->>CLI: Transaction Built
    
    CLI->>Chain: Submit Transaction
    Chain-->>CLI: Signature & Confirmation
    
    CLI-->>User: Swap Details & Explorer URL
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

Suggested Reviewers

  • blockiosaurus
  • tonyboylehub
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the three main additions: bonding curve swap command, bucket fetch enhancements, and registration flags for launch create/register.
Description check ✅ Passed The description comprehensively documents new features, enhancements, SDK updates, and testing performed, directly corresponding to changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/genesis-swap-and-flags

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands/genesis/swap.ts`:
- Around line 313-330: Validate buyAmount/sellAmount strings before calling
BigInt in the info-only branch: check flags.buyAmount and flags.sellAmount are
numeric integer strings (no decimals, optional leading +/-, digits only) and
produce a clear error message if invalid, then parse to BigInt and proceed to
call getSwapResult(...) and applySlippage(...) as before; do the same validation
for the sell path (use SwapDirection.Buy/Sell, firstBuy, getSwapResult,
applySlippage, and result.buyQuote/result.sellQuote) so invalid inputs yield a
friendly validation error instead of an unhandled BigInt exception.
- Around line 165-170: The code manually parses SPL token account bytes in the
block that reads ataAccount and sets currentBalance, which is fragile; replace
the manual DataView/offset logic in the same section (where ataAccount &&
ataAccount.exists and currentBalance is assigned) by calling a robust parser
such as fetchToken from `@metaplex-foundation/mpl-toolbox` (or an equivalent SPL
token account decoder) to read the token amount and assign it to currentBalance,
ensuring proper bigint conversion and handling missing fields/errors instead of
relying on hardcoded byte offsets.
- Around line 183-186: The current call to transferSol builds the amount using
sol(Number(deficit) / 1e9) which can lose precision for large lamport values;
change it to use the lamports() helper from `@metaplex-foundation/umi` so you pass
a bigint-safe amount (e.g., lamports(deficitAsBigInt)) instead of converting to
Number. Update the import list to include lamports, and in the transfer call
replace sol(Number(deficit) / 1e9) with lamports(deficit) (ensuring deficit is a
bigint or converted safely to bigint) while keeping the same destination
(wsolAta) and context (this.context.umi) and wrapping logic (wrapTx,
transferSol).

In `@test/commands/genesis/genesis.swap.test.ts`:
- Around line 10-14: The hardcoded 5s delay in the before hook after
runCli(['toolbox', 'sol', 'airdrop', ...]) should be replaced with a
deterministic confirmation or documented; either poll the RPC/account balance
until the expected SOL amount is reflected (use the existing runCli helper or an
RPC client to check the test wallet balance in a loop with short backoff) and
proceed once confirmed, or if polling is not feasible add a short comment above
the setTimeout explaining why 5000ms is required (blockchain confirmation) and
consider reducing it to a smaller safe value—change references around the before
hook, runCli('toolbox','sol','airdrop',...), and the setTimeout to implement the
chosen approach.
- Line 6: The import statement currently brings in stripAnsi and
createGenesisAccount but stripAnsi is unused; update the import in the test file
to remove the unused symbol (leave createGenesisAccount) by editing the import
line that references stripAnsi and createGenesisAccount so only
createGenesisAccount is imported.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5cd9da61-a6d7-4f30-ab1a-42bbfdd15c65

📥 Commits

Reviewing files that changed from the base of the PR and between 349f84b and 3cdd19b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • package.json
  • src/commands/genesis/bucket/fetch.ts
  • src/commands/genesis/index.ts
  • src/commands/genesis/launch/create.ts
  • src/commands/genesis/launch/register.ts
  • src/commands/genesis/swap.ts
  • test/commands/genesis/genesis.swap.test.ts

MarkSackerberg and others added 2 commits April 9, 2026 14:03
- Use lamports() instead of sol(Number/1e9) to preserve precision
- Add BigInt validation with clear errors in --info quote mode
- Remove unused stripAnsi import in tests
Resolve ESLint errors including import/object/class member sorting,
padding lines, prefer-switch, Number.isNaN, Boolean coercion,
destructuring, and promise executor return issues.

https://claude.ai/code/session_01LNfYbSi7Vkp8c6w6T3zLu8
@MarkSackerberg MarkSackerberg merged commit 6f4f452 into main Apr 9, 2026
3 checks passed
@MarkSackerberg MarkSackerberg deleted the feat/genesis-swap-and-flags branch April 9, 2026 12:57
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.

3 participants