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 two fields:blockhain
- blockhain of the asset,address
- address of assets, wallets in 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
String. The protocol of swap settlement. Now it supports onlyStonFiV1
= 0,DeDust
= 1Number
Integer number.
API Methods
Every method name contains version of API. Now it is v1beta4
.
Method asset.query
asset.query
Allows you to get a list of available assets. Sample:
The response consists: Object assets
that consist a blockchain specific asset list. Each asset info consists:
address
Address
Address of an asset
tags
Array(String)
Tags of asset
symbol
String
Symbol of an asset
name
String
Name of an asset
image_url
String
Asset's image url
decimals
Number
The number of decimals the asset uses - e.g. 8, means to divide the asset amount by 100000000 to get its user representation. If not specified, 9 is used by default.
metadata
Object
Custom medata of the asset
Sample:
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
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
extra_data_json
String
The extra data specified by protocol of swap in JSON format
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
extra_data_json
String
The extra data specified by protocol of swap in JSON format
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_data_json
String
The extra data specified by protocol of swap in JSON format
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
ID of the quote
trader_wallet_address
Address
The address of trader's wallet that initiated transaction
Sample:
The channel will start receiving records about the current status of the transfer. The following statuses are available for the SWAP
method:
awaiting_transfer
Waiting for the trader to initiate the trade.
transferring
Initial transaction found, waiting for transfer of funds to complete.
outgoing_tx_hash
- Hash of transaction that initiated the trade.
filling_trade
Awaiting trade to fill. For SWAP
: awaiting swap transactions in the pools.
outgoing_tx_hash
- Hash of transaction that initiated the trade.
routes
- Info about partial filling of the trade. Array of RouteStatus
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 RouterStatus
consists:
steps
- Array of StepStatus
objects
Object StepStatus
consists:
chunks
- Array of ChunkStatus
objects
Object 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 was transferred from trader wallet
expected_ask_units
Amount
The expected amount of ask asset will be transferred to trader wallet
actual_ask_units
Amount
The actual amount of ask asset was transferred to trader wallet
result
Number
Result of the chunk:
- 0
- Processing
- 1
- Filled
- 2
- Aborted
result_details_json
String
The extra data in JSON format
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
max_slippage_bps
Number
Max price slippage in basis points (0.01%)
quote
Quote
The valid quote received from quote
subscription
Sample:
The response consists:
Object transaction
that consist a blockchain specific transaction object, for TON
it is:
messages
Array(Message)
Array of transfer messages
Object Message
is:
target_address
- String. Represents the address of the recipient wallet. This address is where the transfer will be directed.send_amount
- Number. Specifies the amount of gas required to complete the transfer. This value determines the computational resources allocated for the transaction.payload
- String. Contains the hex-encoded data to be sent along with the transfer. This payload can include transaction details or other relevant information in a hexadecimal format.
Last updated