Repository navigation
feat(swap): build Coinbase SwapV2 and request swap_version 2 - #1104
Merged
Merged
Conversation
Add the SwapV2 instruction (15 accounts, no whitelist) and use it for the server-mediated USDF->USDC withdraw and stateless USDC->USDF sweep. Both requests set swapVersion from SwapV2.version, the same constant the instruction type owns, so the request and the locally built transaction flip together. The external-wallet deposit path keeps the v1 Swap.
0.9.0 carries swap_version on both CoinbaseStableSwapper initiate params.
bmc08gt
marked this pull request as ready for review
October 22, 2026 17:26
The client-built USDC to USDF deposit swap now emits CoinbaseStableSwapper swap_v2 (15 accounts, no whitelist) instead of the legacy swap, matching the server-mediated paths. Test vectors updated; the deposit transaction bytes are builder-derived.
SwapV2 has no whitelist account, so deriveSwapAccounts no longer derives or returns it. deriveWhitelistAddress() stays for the v1 Swap golden test and the no-whitelist assertion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server-mediated stablecoin swaps now build CoinbaseStableSwapper
SwapV2and sendswapVersion = 2. This matches code-payments/ocp-server#278, where the server builds whichever instruction the request names and the client rebuilds and signs the same transaction.The
ocp-client-protocolpin andPackage.resolvedare at 0.9.0 (cae3c52), which carriesswap_version.What changed
CoinbaseStableSwapperProgram.SwapV2is new. It uses discriminator[43, 4, 237, 11, 26, 201, 30, 98]and the v1swapargs. Its 15 accounts are v1's 16 with the whitelist (index 12) removed.SwapV2.versionfeeds both the request field and the local builder, so the two cannot disagree.stablecoinProtoandbuildUsdfToUsdcSwapInstructions.SwapService+StatelessSwapandbuildStatelessSwapInstructions.WalletConnection→buildUsdcToUsdfSwapInstructions) buildsSwapV2too, without a version switch. The user signs it and the server never sees it, so there is noswap_versionto match.CoinbaseStableSwapperProgram.Swapand the whitelist derivation are removed. Every swap the app builds isSwapV2.Tests
CoinbaseStableSwapperSwapV2Testsasserts the exact bytes and account list from the server'sinstructions_swap_v2_test.go. Android asserts the same vector. The tests also check that both requests carryswapVersion == 2and that the stateless builder emitsSwapV2.SwapInstructionBuilderUsdfToUsdcTestsandSwapInstructionBuilderUsdcToUsdfTestsnow expect 15 accounts and the v2 discriminator.CoinbaseStableSwapperDepositTransactionTestspins the full encoded deposit transaction. ItsSwapV2bytes passsimulateTransactionon mainnet (Swapped 5000000 tokens, 34752 compute units), so mainnet CoinbaseStableSwapper acceptsswap_v2on the deposit path.Before merging
swap_versionand buildsSwap, so the signedSwapV2transaction wouldn't match.swapVersionis also inside the proto the proof signs over. That needs a confirmation from the server side that this is accepted.Linked: Android code-payments/code-android-app#1817