Swap grpc
This guide describes how to use the Omniston swap functionality over the gRPC API from a trader's perspective. It parallels Swap overview (WebSocket) but shows the gRPC specifics.
Key Differences from WebSocket API
Protocol Field For the gRPC API, the
protocol
field in each swap chunk must be a string:"StonFiV1"
,"StonFiV2"
, or"DeDust"
. In contrast, the WebSocket API uses numeric codes1
,2
, or3
.
Extra Version Currently, only
extraVersion = 1
is supported.Steps vs. Chunks
Each SwapStep moves from one asset to another (e.g., TON → USDC).
Each step can have multiple SwapChunk objects, but on TON you typically see exactly one chunk per step.
Method Names In the gRPC API, traders use similar calls to
requestForQuote
,buildTransfer
,trackTrade
, etc., but these are exposed via protobuf messages, not JSON-RPC. The underlying fields are the same.
Typical Flow (Traders)
A typical gRPC-based swap flow from a trader's viewpoint is:
Send a Quote Request Using
Omniston.requestForQuote
(or the corresponding gRPC call), providing:offerAssetAddress
,askAssetAddress
The desired
amount
(eitherofferUnits
oraskUnits
)Optional
referrerAddress
andreferrerFeeBps
settlementMethods
=[SETTLEMENT_METHOD_SWAP]
if you want a swapsettlementParams
such asmaxPriceSlippageBps
ormaxOutgoingMessages
(for TON)
You receive an Observable (RxJS style in the SDK) or a stream of
QuoteResponseEvent
messages over gRPC. The server may update your quote repeatedly if a more favorable price arrives.Build the Transfer When you have a valid
Quote
, callOmniston.buildTransfer
with:The
quote
you acceptedYour
sourceAddress
(onofferBlockchain
)Your
destinationAddress
(onaskBlockchain
) The API returns an object with blockchain-specific transaction data (for TON, a list of messages).
Sign/Send the Transaction
On TON, you typically pass these messages to your wallet (e.g., TonConnect, Tonkeeper, etc.).
Wait for the transaction to be mined.
Track the Trade You can then call
Omniston.trackTrade
to receive streaming updates about the trade status. This includes whether the trade was filled, partially filled, or aborted.
Important Data Types
Blockchain
A numeric code following SLIP-044. For TON, this is607
.Address
An object:Protocol
Must be one of:"StonFiV1"
"StonFiV2"
"DeDust"
SettlementMethod
For now, typically[0]
for swap in numerical form, or (in your SDK)SettlementMethod.SETTLEMENT_METHOD_SWAP
.SwapStep
andSwapChunk
Each step is a transition from
offerAssetAddress
toaskAssetAddress
.For TON: typically exactly one chunk per step.
A chunk includes:
Quote
The server provides aquoteId
,offerUnits
,askUnits
,quoteTimestamp
,tradeStartDeadline
, etc. Includesparams
with settlement info for the chosen method (SwapSettlementParams
).
Rejected Quotes
If you pass extraVersion != 1
(e.g., 3), the quote or the route gets rejected with a message like:
Make sure to use extraVersion = 1
.
Next Steps
For a complete, low-level definition of the gRPC service (resolver side, plus the underlying messages), see Resolver Integration Guide. For Node.js or TypeScript usage, see omniston-nodejs.md or the omniston-react.md for React apps. Both rely on the same underlying gRPC/WS backend.
If you have any questions or issues, please reach out in our STON.fi Discord.
Last updated