Swap overview
Swap settlement method
Settlement of the trade by direct swap using third-party contracts.
Actors
Trader
A protocol user who performs the token exchange.
Resolver
Service providing a token exchange rate, also known as Market Maker
.
WebSocket API
Data types used:
Blockchain
Number. Blockchain code as defined by SLIP-044. (https://github.com/satoshilabs/slips/blob/master/slip-0044.md) ForTON
, it is607
.Address
Object. It consists of two fields:blockchain
- blockchain of the asset,address
- address of assets, wallets in the specifiedBlockchain
.
For example:
Amount
String. Amount of assets in units.SettlementMethod
Number. The method of trade settlement. Value of enum of settlement methods. Currently, supports onlySwap
settlement method, which is0
.Protocol
Number. The protocol of swap settlement. Currently, it supports:StonFiV1
= 1: STON.fi DEX v1 protocolStonFiV2
= 2: STON.fi DEX v2 protocolDeDust
= 3: DeDust DEX protocol
Number
Integer number.RequestSettlementParams
Object. Additional parameters for the quote request (RFQ):max_price_slippage_bps
: Maximum price slippage, in basis points (0.01%). For example, 100 = 1% slippage.max_outgoing_messages
: Maximum number of outgoing messages supported by the wallet. For TON blockchain, this defaults to 4 if omitted.
Note: These parameters are general RFQ settings and may be used across different settlement methods. They are not specific to any particular settlement method.
SwapSettlementParams
Object. Settlement parameters specific to the swap settlement method. This type is used in the Quote'sparams
field when the settlement method is swap. Contains:routes
: Array ofSwapRoute
objects that define the possible paths for the swap.
Each
SwapRoute
consists of:steps
: Array ofSwapStep
objects describing each step in the swap routegas_budget
: String indicating the gas budget to complete the transfer
Each
SwapStep
contains:offer_asset_address
: Address object for the asset being offeredask_asset_address
: Address object for the asset being requestedchunks
: Array ofSwapChunk
objects breaking down the swap into smaller operations
Each
SwapChunk
represents a single swap operation:protocol
: Protocol used for this swap operation (e.g., "1")offer_amount
: Amount of the offered assetask_amount
: Expected amount of the asked assetextra_version
: Version of the extra data formatextra
: Protocol-specific data as a base64-encoded byte array
quote_id
String. A 32-byte identifier of the quote.
API Methods
Every method name contains version of API. Now it is v1beta6
.
Subscription method quote
quote
Allows you to create a new request for quote (RFQ
).
Accepts the following parameters as input:
offer_asset_address
Address
Blockchain-specific address of offer asset.
ask_asset_address
Address
Blockchain-specific address of ask asset.
amount
Amount
Either the amount of offer asset or ask asset:
offer_units
- The amount of offer asset the trader wants to pay, including all fees.
ask_units
- The amount of ask asset the trader wants to get after all fees.
referrer_address
Address
The address of referrer that will receive the fees or empty string if referrer is not specified.
referrer_fee_bps
Number
The amount of fees required by the referrer in basis points (1/10000 or 0.01%)
settlement_methods
Array(SettlementMethod)
Supported methods of swap settlement. The protocol limits settlement methods in quotes to specified methods. Different combinations of offer & ask chains might support different methods.
Sample:
After the request (RFQ
), the channel will start receiving quote_updated
events from resolvers, which consist of a quote
. A Quote
in the channel is updated if a more profitable deal for the trader comes in. The Quote
includes the following fields:
quote_id
String
ID of the quote generated by the platform (32 bytes)
resolver_id
String
ID of the Resolver
resolver_name
String
Name of the Resolver
offer_asset_address
Address
Blockchain-specific address of offer asset.
ask_asset_address
Address
Blockchain-specific address of ask asset.
offer_units
Amount
The amount of offer asset the trader must pay, including all fees.
ask_units
Amount
The amount of ask asset the trader will get after all fees.
referrer_address
Address
The address of referrer that will receive the fees or empty string if referrer is not specified.
referrer_fee_bps
Number
The amount of fees that the referrer will get (in units of offer_asset_address).
protocol_fee_units
Number
The amount of fees charged by the protocol (in units of offer_asset_address).
quote_timestamp
Number
The timestamp (UTC seconds) of Quote sent by resolver.
trade_start_deadline
Number
Max timestamp (UTC seconds) of start of the trade. The start of the trade is defined as the reception of offer asset by the corresponding smart contract. The resolver may still settle the trades started after this deadline has passed at own discretion.
params
Object
Additional parameters specific to settlement method. Details see below
For Swap
settlement method the params
is:
routes
Array(SwapRoute)
Array of Swap routes
Object SwapRoute
:
steps
Array(SwapStep)
Array of Swap steps
gas_budget
Amount
The amount of gas budget to complete transfer
Object SwapStep
:
offer_asset_address
Address
Blockchain-specific address of offer asset.
ask_asset_address
Address
Blockchain-specific address of ask asset.
chunks
Array(SwapChunk)
Array of swap chunks
Object SwapChunk
:
protocol
Protocol
Protocol of this swap operation
offer_amount
Amount
The amount of offer asset the trader must pay, including all fees.
ask_amount
Amount
The expected amount of ask asset the trader will get after all fees.
extra_version
Number
Version of the extra data format
extra
bytes
Bytes array used by the underlying protocol to coordinate the swap. In JSON form, it is typically base64-encoded. It is not JSON.
For more details on how to populate or interpret the extra
field for these protocols, see the (Swap Extra doc).
Sample:
Subscription method trade.track
trade.track
Method that allows you to track the status of a token exchange.
Accepts the following parameters as input:
quote_id
String
(32 bytes) ID of the quote
trader_wallet_address
Address
The address of trader's wallet that initiated transaction
outgoing_tx_hash
String
Hash of the transaction that initiated the trade
Sample:
The channel will start receiving records about the current status of the transfer. The following statuses are available:
awaiting_transfer
Waiting for the trader to initiate the trade.
transferring
Initial transaction found, waiting for transfer of funds to complete.
swapping
(SWAP method only) Awaiting swap transactions in the pools.
routes
- Info about partial filling of the trade. Array ofRouteStatus
.
awaiting_fill
(ESCROW / HTLC only) Waiting for the trade to be filled.
claim_available
(HTLC only) Resolver's deposit is claimable.
refund_available
(ESCROW / HTLC) Deposit timeout has expired, need to refund it.
receiving_funds
The transaction with incoming funds found, waiting for it to mine.
routes
- Info about partial filling of the trade.
trade_settled
The trade has completed (fully or partially filled or fully aborted)
result
- Result of the trade:
- 0
- Unknown
- 1
- fully filled
- 2
- partially filled
- 3
- aborted
routes
- Info about partial filling of the trade. Array of RouteStatus
Object Descriptions
RouteStatus
steps
- Array ofStepStatus
objects.
StepStatus
chunks
- Array ofChunkStatus
objects.
ChunkStatus
target_address
Address
Address of the contract that processes this chunk. Generally, this address receives offer tokens. More specifically, it might be the address of a protocol or liquidity pool.
offer_units
Amount
The amount of offer asset transferred from trader wallet
expected_ask_units
Amount
The expected amount of ask asset to be transferred to trader wallet
actual_ask_units
Amount
The actual amount of ask asset transferred to trader wallet
result
Number
Result of the chunk:
- 0
- Processing
- 1
- Filled
- 2
- Aborted
protocol
Protocol
Protocol of this swap operation
tx_hash
String
Hash of the transaction that executed this chunk
Samples:
Method transaction.build_transfer
transaction.build_transfer
A request to generate unsigned transfer to initiate the trade.
Accepts the following parameters as input:
source_address
Address
The address on offer_blockchain that will send initial transaction to start the trade
destination_address
Address
The address on ask_blockchain that will receive result of the trade
quote
Quote
The valid quote received from quote
subscription
Sample:
The response contains a ton
object with the blockchain-specific transaction data:
ton
Object
Contains TON-specific transaction data
ton.messages
Array(Message)
Array of messages to be sent
Each Message
object contains:
target_address
String
The address of the recipient
send_amount
String
Amount in nanotons to send as attached value
payload
String
Hex-encoded or base64-encoded transaction data
Last updated