This endpoint performs an atomic exchange of one asset for another through a specified liquidity pool. The swap is executed immediately and settlement is handled by the TEE system.
Two methods to protect against price movement:
amount_out: Absolute minimum output requiredEach swap incurs fees that are split between:
Requires a valid JWT bearer token. The token’s public key must match
the user_public_key in the request.
user_public_key - Public key of the swapperpool_id - LP public key of the poolasset_in_address - Asset being providedasset_out_address - Asset being receivedamount_in - Amount to swapmin_amount_out - Minimum acceptable outputmax_slippage_bps - Optional slippage toleranceasset_in_spark_transfer_id - Transfer proofnonce - Unique value for replay protectionsignature - Request signature200 OK with swap details if successful400 Bad Request if validation fails or insufficient liquidity401 Unauthorized if authentication fails500 Internal Server Error if swap execution failsBearer authentication header of the form Bearer <token>, where <token> is your auth token.
Swap execution details including assets, amounts, and authentication
Request body for executing a swap on an AMM pool.
Swaps allow users to exchange one asset for another through a liquidity pool. The swap is executed atomically and the result is returned immediately.
Public key of the user executing the swap. Must match the authenticated user's public key.
"02abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567"
LP public key of the pool to swap through. The pool must be active and have sufficient liquidity.
"03aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899"
Public key of the asset being provided by the user. Must be one of the two assets in the selected pool.
"03bitcoinassetpubkey0000000000000000000000000000000000000000000000"
Public key of the asset the user wants to receive. Must be the other asset in the selected pool.
"03usdstablecoinpubkey111111111111111111111111111111111111111111111"
Amount of input asset to swap, in its smallest unit. Must be positive and within the pool's liquidity capacity.
x >= 0100000000
Optional maximum slippage tolerance in basis points (BPS).
If set, can override min_amount_out. 1 BPS = 0.01%, so 50 BPS = 0.5%.
x >= 050
Optional mininimum amount out If set to none, 0
x >= 0100000000
Spark network transfer ID proving the deposit of input asset. Must be a valid, confirmed transfer to the pool's address.
"spark-transfer-uuid-or-hash-for-asset-in"
Unique nonce for replay protection.
Each swap must use a unique nonce that hasn't been used before.
"unique-swap-nonce-123"
Total integrator fee the user accepts to pay.
x >= 0100
Integrator public key.
"03aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899"
Hex-encoded secp256k1 signature of the request.
Must be signed by the private key corresponding to user_public_key.
"3045022100a7e5d4f8b2c9a1e6f0d5b8c4a9e7f2d1c8b5a4e9f0d6c5b3a2e1d0c9b8a7f02201f2e3d4c5b6a7980e9f0a1b2c3d4e5f67889a0b1c2d3e4f5a6b7c8d9e0f1a2b3"
Swap executed successfully
Clean response for a successfully executed swap operation
User-friendly request ID for tracking
"01HJZKFABCDEFGHJKLMNPQRSTVW"
Whether the swap was accepted or rejected
true
Settlement service request ID for correlation
"018D5E56-9D80-7890-A1B2-C3D4E5F6G7H8"
Amount received from the swap (populated if accepted)
x >= 0"495000"
Fee paid for the swap (populated if accepted)
x >= 0"5000"
Execution price as a string (populated if accepted)
"0.00495000"
Asset received by the user (populated if accepted)
"03usdstablecoinpubkey111111111111111111111111111111111111111111111"
Asset sent by the user (populated if accepted)
"03bitcoinassetpubkey0000000000000000000000000000000000000000000000"
Spark transfer ID for receiving asset (populated if accepted)
"spark-transfer-out-123"
User-friendly error message (populated if rejected)
"Insufficient liquidity in pool"
Refunded asset (populated if rejected)
"03bitcoinassetpubkey0000000000000000000000000000000000000000000000"
Refunded amount (populated if rejected)
x >= 0"100000000"
Spark transfer ID for refund (populated if rejected)
"spark-transfer-refund-456"