AlcorDocs

Swap route

The best route to swap one token for another, ready to sign: through the AMM pools, or the AMM and the order books together.

The route service finds the best way to swap one token for another and answers with the transfers to send, so a swap needs no pool math on the client. It runs on each chain's host and stays as it is: it is not part of the deprecated API. For new integrations use Swap route v3.

Swap route

The best way to swap one token for another through the AMM pools, ready to be sent as transfers to swap.alcor.

GET https://wax.alcor.exchange/api/v2/swapRouter/getRoute

Parameters

NameTypeRequiredDescription
trade_typestringyesEXACT_INPUT: amount is what you send. EXACT_OUTPUT: amount is what you receive
inputstringyesToken id you send
outputstringyesToken id you receive
amountstringyesAmount in token units, e.g. 1.5. No more decimals than the token has
slippagenumbernoTolerance in percent. Default 0.3
receiverstringnoAccount written into the memos. Default is the literal <receiver>, to replace before signing
maxHopsnumbernoMost pools per route. Default and maximum 3
v2anynoAny non-empty value splits the trade across up to 5 routes. Without it, one route
includePoolDetailsbooleannotrue adds pools: fee and tokens of every pool used

Example

curl "https://wax.alcor.exchange/api/v2/swapRouter/getRoute?trade_type=EXACT_INPUT&input=wax-eosio.token&output=tlm-alien.worlds&amount=10&slippage=0.3&receiver=alcordexfund&maxHops=2"
{
  "route": [12501, 12406],
  "memo": "swapexactin#12501,12406#alcordexfund#39.7961 TLM@alien.worlds#0",
  "swaps": [
    {
      "input": "10.00000000 WAX",
      "route": [12501, 12406],
      "output": "39.9155 TLM",
      "percent": 100,
      "memo": "swapexactin#12501,12406#alcordexfund#39.7961 TLM@alien.worlds#0",
      "maxSent": "10.00000000",
      "minReceived": "39.7961"
    }
  ],
  "input": "10.00000000",
  "output": "39.9155",
  "minReceived": "39.7961",
  "maxSent": "10.00000000",
  "priceImpact": "0.31",
  "executionPrice": { "numerator": "399155", "denominator": "1000000000" }
}

Response fields

NameTypeDescription
swapsarrayOne transfer per split, see below
inputstringTotal amount sent
outputstringTotal amount expected
minReceivedstringExact input: the least the trade may return, after slippage
maxSentstringExact output: the most the trade may take, after slippage
priceImpactstringPercent below the pools' spot prices
executionPriceobjectRaw output per raw input, as a fraction
route, memoarray, stringPools and memo of the first swap only. Kept for old clients; use swaps
poolsobjectOnly with includePoolDetails=true: pool id to fee, tokenA, tokenB

Each swap

NameTypeDescription
inputstringAsset to transfer
outputstringAsset this swap is expected to return
percentnumberShare of the trade
routearrayPool ids the swap goes through
memostringMemo for the transfer
minReceived, maxSentstringThis swap's bounds

To swap, put one transfer of the input token per element of swaps into a single transaction: to: "swap.alcor", quantity: swap.input, memo: swap.memo with <receiver> replaced by the user's account.

Errors are plain text: HTTP 403 with Invalid request, Invalid amount, Invalid slippage or Invalid input/output, and HTTP 404 with No trading route available. Try again in a few moments.

Swap route v3

Routes through the AMM pools and the spot order books together. Answers with the transfers to send and, given the user's account, the actions ready to sign. Use it for new integrations.

GET https://wax.alcor.exchange/api/v3/swapRouter/getRoute

Parameters

NameTypeRequiredDescription
tradeTypestringyesexactIn: amount is what you send. exactOut: amount is what you receive (AMM only)
inputstringyesToken id you send
outputstringyesToken id you receive
amountstringyesAmount in token units, e.g. 1.5
slippagenumbernoTolerance in percent. Default 0.3
accountstringnoThe user's account: receiver of every swap and signer of actions. Without it the memos carry <account> and there are no actions
permissionstringnoPermission for actions. Default active
maxHopsnumbernoPools per AMM route, 1 to 3. Default 3
orderbookbooleannofalse keeps the trade on the AMM. Default true

Example

curl "https://wax.alcor.exchange/api/v3/swapRouter/getRoute?tradeType=exactIn&input=wax-eosio.token&output=tlm-alien.worlds&amount=10&slippage=0.3&account=alcordexfund"
{
  "tradeType": "exactIn",
  "input": { "id": "wax-eosio.token", "symbol": "WAX", "contract": "eosio.token", "decimals": 8, "amount": "10.00000000" },
  "output": { "id": "tlm-alien.worlds", "symbol": "TLM", "contract": "alien.worlds", "decimals": 4, "amount": "39.9242" },
  "minReceived": "39.8047",
  "maxSent": "10.00000000",
  "priceImpact": "0.3",
  "routes": [
    {
      "percent": 61,
      "input": "6.10000000",
      "output": "24.3483",
      "hops": [
        { "venue": "amm", "pool": 12501, "input": "wax-eosio.token", "output": "usdt-wrap.alcor", "fee": "0.01" },
        { "venue": "amm", "pool": 12406, "input": "usdt-wrap.alcor", "output": "tlm-alien.worlds", "fee": "0.3" }
      ]
    }
  ],
  "transfers": [
    {
      "tokenContract": "eosio.token",
      "to": "swap.alcor",
      "quantity": "6.10000000 WAX",
      "memo": "swapexactin#12501,12406#alcordexfund#24.2754 TLM@alien.worlds#0"
    }
  ],
  "actions": [
    {
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{ "actor": "alcordexfund", "permission": "active" }],
      "data": {
        "from": "alcordexfund",
        "to": "swap.alcor",
        "quantity": "6.10000000 WAX",
        "memo": "swapexactin#12501,12406#alcordexfund#24.2754 TLM@alien.worlds#0"
      }
    }
  ]
}

Response fields

NameTypeDescription
tradeTypestringAs requested
input, outputobjectToken metadata and the total amount sent or expected
minReceivedstringExact input: the least the trade may return
maxSentstringExact output: the most the trade may take
priceImpactstringPercent below the venues' spot prices
routesarrayPaths the input takes: percent, input, output and hops. Each hop has venue (amm or orderbook), pool or market, input and output token ids, fee in percent
transfersarrayWhat to send, in order: tokenContract, to, quantity, memo
actionsarrayOnly with account: the transfers as actions, ready to sign

Sign actions as they are, in order, in one transaction. An AMM leg is a transfer to swap.alcor. An order book leg is a transfer to the DEX contract with the memo <minimum> SYM@contract|min: a market order that reverts the whole transaction if it pays less than the minimum.

Errors are JSON, {"error": "<message>"}: HTTP 400 for a bad parameter (Invalid tradeType, Unknown token, Invalid amount, Invalid slippage, Invalid maxHops, Invalid orderbook, Input and output are the same token), HTTP 404 for No route.

On this page