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:
Name | Type | Description |
---|---|---|
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:
Name | Type | Description |
---|---|---|
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:
|
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:
Name | Type | Description |
---|---|---|
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:
Name | Type | Description |
---|---|---|
routes | Array(SwapRoute) | Array of Swap routes |
Object SwapRoute
:
Name | Type | Description |
---|---|---|
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
:
Name | Type | Description |
---|---|---|
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
:
Name | Type | Description |
---|---|---|
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:
Name | Type | Description |
---|---|---|
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:
Name | Description | Fields |
---|---|---|
awaiting_transfer | Waiting for the trader to initiate the trade. | |
transferring | Initial transaction found, waiting for transfer of funds to complete. |
|
filling_trade | Awaiting trade to fill. For |
|
trade_settled | The trade has completed (fully or partially filled or fully aborted) |
|
Object RouterStatus
consists:
steps
- Array of StepStatus
objects
Object StepStatus
consists:
chunks
- Array of ChunkStatus
objects
Object ChunkStatus
:
Name | Type | Description |
---|---|---|
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:
- |
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:
Name | Type | Description |
---|---|---|
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 |
Sample:
The response consists:
Object transaction
that consist a blockchain specific transaction object, for TON
it is:
Name | Type | Description |
---|---|---|
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