Add bonding curve swap, bucket fetch, and registration flags#109
Add bonding curve swap, bucket fetch, and registration flags#109MarkSackerberg merged 5 commits intomainfrom
Conversation
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)
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughUpdated the Genesis CLI to support bonding-curve bucket operations and swaps, with new flags for launch registration ( Changes
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
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
package.jsonsrc/commands/genesis/bucket/fetch.tssrc/commands/genesis/index.tssrc/commands/genesis/launch/create.tssrc/commands/genesis/launch/register.tssrc/commands/genesis/swap.tstest/commands/genesis/genesis.swap.test.ts
- 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
Summary
genesis swapcommand for buying/selling on bonding curves with--buyAmount/--sellAmount, auto-wrapping SOL to WSOL when neededgenesis swap --infofor curve status, price quotes, and fee breakdown without transactinggenesis bucket fetchnow auto-detects bucket type (no--typerequired), shows all buckets at an index when multiple exist, and supports--type bonding-curve--creatorWalletand--twitterVerificationTokenflags ongenesis launch createandgenesis launch registerTest plan