feat(buy-sol) PR 4: accept sponsored orders that buy native SOL - #4990
squadgazzz wants to merge 6 commits into
Conversation
|
Reminder: Please consider backward compatibility when modifying the API specification.
Caused by: |
|
Claude finished @squadgazzz's task in 3m 43s —— View job PR Review: accept sponsored orders that buy native SOL
Verdict: LGTM — the change is correct, well-scoped, and well-tested. One minor, non-blocking note posted inline. What I checked
Note
One thing I could not verify from this branch alone: that the rent-minimum and no-partial-fill thresholds here exactly match the autopilot rules from #4989 (not yet merged in). Worth a quick cross-check so an order can't pass placement but get filtered by the auction, or vice-versa. |
| /// Whether an order trades a token for itself. Native SOL counts as wSOL, so | ||
| /// selling wSOL for native SOL is a same-token trade. | ||
| fn same_token(sell: &Pubkey, buy: &Pubkey) -> bool { | ||
| sell == buy || (*sell == native_mint::ID && *buy == ENCODED_NATIVE_SOL_TRANSFER) |
There was a problem hiding this comment.
Minor / non-blocking: same_token is intentionally asymmetric — it treats sell == wSOL && buy == native as the same token, but not the reverse (sell == native && buy == wSOL). For create_order this is fine since intent.sell is always a real TokenAsset mint. For the quote path, though, a request with sellToken = 11111111111111111111111111111111 (native) and buyToken = wSOL would slip past this check and be forwarded to the quoter instead of returning SameBuyAndSellToken. It'll almost certainly just resolve to NoLiquidity (selling native SOL isn't a supported order shape), so this is low impact — just flagging that the helper's name suggests a symmetric relation that it doesn't provide. If native-SOL is strictly buy-only, a one-line comment saying so would make the asymmetry deliberate.
There was a problem hiding this comment.
seems like a good case for covering in unit tests
Description
The orderbook rejects every sponsored order that buys native SOL. #4986 lets the driver settle these orders and #4989 lets them into the auction, so placement can accept them.
A native buy has no buy token account. The payout goes to the owner's wallet and creates it when it's missing, so the mandatory account creation step doesn't apply, and the orderbook rejects a creation step on such an order. FE-674 has to build the creation transaction without it.
Placement also applies the autopilot's native buy rules, so an order that can't settle fails right away instead of waiting out its blockhash in the cut. A buy under 890,880 lamports (the rent-exempt minimum of an empty account), a partially fillable one, or one paying an account the System Program doesn't own gets
InvalidNativeBuy. Without a creation step nothing proves the wallet can receive, so placement looks it up once through the sponsoring RPC. A failed lookup answers 500, like the blockhash check next to it. Selling wSOL for native SOL getsSameBuyAndSellToken, like WETH for ETH on EVM, and the quote endpoint answers that pair the same way instead ofNoLiquidity. A quote whose native payout comes out under the floor getsInvalidNativeBuyas well, since placement would reject the order it prices.Merges after #4989, which checks the wallets of pending sponsored native buys.
Changes
POST /api/v1/ordersaccepts native SOL buys, without a buy account creation stepInvalidNativeBuyInvalidNativeBuyHow to test
New API and DB tests.
Related issues
BE-332