Protocols
AirSwap trading technology is fully decentralized, powered by smart contracts that enable counterparty discovery and atomic swaps. AirSwap protocols communicate prices off-chain and settle on-chain. Peers take the form of individuals trading manually or software trading in an automated way, in which case market makers run servers that implement the following protocols.
For information on finding counter-parties, see Discovery.
Discovery
AirSwap Discovery protocol is used to determine the trading protocols and tokens supported by peers.
getProtocols
getProtocols
Peers may call getProtocols
to determine protocols supported by a peer. Protocols are identified by interfaceId
and configuration params include the chainId
, swapContractAddress
, and walletAddress
that the peer intends to use.
setProtocols
setProtocols
When connected via WebSocket, the server may send a setProtocols
notification to the client to indicate the protocols it supports. Protocols are identified by interfaceId
and configuration params include the chainId
, swapContractAddress
, and walletAddress
the server intends to use.
getTokens
getTokens
Peers may call getTokens
to determine tokens supported by another peer, whether connected via HTTPS or WebSocket. The return value is an array of tokens identified by the token contract address.
setTokens
setTokens
When connected via WebSocket, the server may send a setTokens
notification to indicate the tokens it supports.
RequestForQuoteERC20
AirSwap RequestForQuoteERC20 is a client-server protocol used by market makers running servers from which clients request ERC20 orders via HTTP or WebSocket. In RFQ, the server is the signer (i.e. signerAmount
, signerToken
) and the client is the sender (i.e. senderAmount
, senderToken
).
getSignerSideOrderERC20
getSignerSideOrderERC20
Given a senderAmount
the server returns a signed OrderERC20 including the signerAmount
. The client is selling to the server. Client may optionally request a minimum expiry in seconds. Returns an order.
getSenderSideOrderERC20
getSenderSideOrderERC20
Given a signerAmount
the server returns a signed OrderERC20 with a senderAmount
. The client is buying from the server. Client may optionally request a minimum expiry in seconds. Returns an order.
getPricingERC20
getPricingERC20
Client may request soft pricing for a list of token pairs. Client may optionally request a minimum expiry in seconds to be factored into pricing. Returns current formula or levels for each pair.
Client may also request pricing for all available pairs.
Example
To find counterparties, see Discovery. With server URLs in hand, clients may call getSignerSideOrderERC20
or getSenderSideOrderERC20
as JSON-RPC requests on servers that support RequestForQuoteERC20.
Client Request
Requests can also be made using curl or wget for debugging.
Server Response
See the signatures page for details on signing an OrderERC20.
Client Settlement
With an OrderERC20 in hand, the client sends an Ethereum transaction to the SwapERC20 contract. The swapLight
function is gas efficient, whereas the swap
function provides protocol fee rebates to staked AST holders. Either function can settle a correctly signed OrderERC20. A successful swap emits a SwapERC20
event.
The server or client may subscribe to a filter for a SwapERC20
event with the order nonce
to track fills.
LastLookERC20
AirSwap LastLookERC20 is used by servers to stream quotes to clients. Clients periodically send signed OrderERC20s to the server, which then has the "last look" and option to send it to the EVM for settlement. In last-look, the client is the signer (e.g. signerAmount
, signerToken
) and the server is the sender (e.g. senderAmount
, senderToken
).
subscribePricingERC20
subscribePricingERC20
Client subscribes to pricing updates for a list of token pairs. Returns current formula or levels for each pair.
Client may also subscribe to pricing updates for all available pairs. Returns current formula or levels for each pair.
unsubscribePricingERC20
unsubscribePricingERC20
Client unsubscribes from pricing updates for a list of token pairs. Returns a boolean.
Client may also unsubscribe from all subscriptions. Returns a boolean.
setPricingERC20
setPricingERC20
Server updates pricing for one or more token pairs. Returns a boolean.
considerOrderERC20
considerOrderERC20
Client provides a priced OrderERC20 to the server. Returns boolean true
if accepted by the server.
Example
To find counterparties, see Discovery. With WebSocket server URLs in hand (i.e. the URL schema is wss
), clients connect to each and calls methods as JSON-RPC over WebSocket.
WebSocket
Upon connection, the server calls setProtocols
on the client.
The client may then subscribe to pricing updates.
The server then continuously updates the client with new pricing.
The client may send an OrderERC20 to the server to consider a swap.
With an OrderERC20 in hand, the server sends an Ethereum transaction to the SwapERC20 contract. The swapLight
function is gas efficient, whereas the swap
function provides protocol fee rebates to staked AST holders. Either function can settle a correctly signed OrderERC20. A successful swap emits a SwapERC20
event.
The client may subscribe to a filter for a SwapERC20
event with the nonce
they provided to the server to track fills.
Indexing
AirSwap Indexing is used by peers to store and fetch orders on other peers.
addOrder
addOrder
Peers may call addOrder
to add an order to another peer.
getOrders
getOrders
Peers may call getOrders
to query for orders indexed by another peer.
getTags
getTags
Peers may call getTags
to get all available tags for a token.
Where OrderFilter
, Indexes
, and Direction
can be found here.
IndexingERC20
AirSwap Indexing is used by peers to store and fetch ERC20 orders on other peers.
addOrderERC20
addOrderERC20
Peers may call addOrderERC20
to add an order to another peer.
getOrdersERC20
getOrdersERC20
Peers may call getOrdersERC20
to query for orders indexed by another peer.
Where OrderFilter
, Indexes
, and Direction
can be found here.
getTags
getTags
Peers may call getTags
to get all available tags for a token.
Pricing Formats
Server pricing can be communicated either by levels or a formula. All input and output values for pricing are in base units rather than atomic units. When generating orders, all values must be converted to atomic units.
Levels
A server may provide "levels" to determine its pricing for various tokens and amounts. Each level is a tuple of amount and price at that level. Amounts and minimums are all in baseToken
. Each level indicates price “up to” the specified amount and therefore the last level is the maximum.
Examples
Client wants to swap 1000
USDT into WETH. Client looks up baseToken USDT and quoteToken WETH and uses the bid
levels above. The first 100
would be multiplied by 0.00053
and second 900
would be multiplied by 0.00061
for a total of 0.602
WETH.
Client wants to swap 1
WETH into USDT. Client looks up baseToken WETH and quoteToken USDT and uses the bid
levels above. The first 0.5
would be multiplied by 2000
and second 0.5
would be multiplied by 2010
for a total of 2005
USDT.
Client wants to swap WETH into 1000
USDT. Client looks up baseToken USDT and quoteToken WETH and uses the ask
levels above. The first 100
would be multiplied by 0.00055
and second 900
would be multiplied by 0.00067
for a total of 0.658
WETH.
Client wants to swap USDT into 1
WETH. Client looks up baseToken WETH and quoteToken USDT and uses the ask
levels above. The first 0.5
would be multiplied by 2001
and second 0.5
would be multiplied by 2015
for a total WETH amount of 2008
USDT.
Formula
The server can specify formulas to use for pricing. Each formula is an expression with operations including addition, subtraction, multiplication, and division, where x
is provided by the client.
Examples
Client wants to swap 1000
USDT into WETH. Client looks up baseToken USDT and quoteToken WETH and uses the bid
levels above. 1000
is multiplied by 0.00053
for a total of 0.53
WETH.
Client wants to swap 1
WETH into USDT. Client looks up baseToken WETH and quoteToken USDT and uses the bid
levels above. 1
is multiplied by 2000
for a total of 2000
WETH.
Client wants to swap WETH into 1000
USDT. Client looks up baseToken USDT and quoteToken WETH and uses the ask
levels above. 1000
is multiplied by 0.00055
for a total of 0.55
WETH.
Client wants to swap USDT into 1
WETH. Client looks up baseToken WETH and quoteToken USDT and uses the ask
levels above. 1
is multiplied by 2001
for a total of 2001
WETH.
Last updated