API Documentation Terra 2.0

The TFM DEX aggregator API can be found under the following URL:
The API consists of the following endpoints:

/route

Parameter name
Type
Description
token0
string
Contract address of the token to sell, e.g. USDC
token1
string
Contract address of the token to buy, e.g. uluna
amount
integer
Amount of the token to sell, set in minimal divisible units, e.g. 13.45 Luna set as 13450000
exchange
string
Optional parameter to limit the search of the best route within a given exchange. For example, input of "astroport" will only search on Astroport, while "astroport, terraswap" will search on both Astroport and Terraswap. The default setting is to search on all the DEX's if no value is passed.
use_split
bool
indicates if volume splitting should be applied

List of available exchanges:

astroport
terraswap
phoenix

Example:

api-terra2.tfm.com/route?amount=10000000000&token1=uluna&token0=terra1nsuqsk6kh58ulczatwev87ttq2z6r3pusulg9r24mfj2fvtzd4uq3exn26&exchanges=terraswap,astroport&use_split=true
Return structure:
{
"alternatives": {},
"input_amount": 111.0,
"price_impact": 0.003054968298016103,
"return_amount": 5.288686,
"routes": [
{
"input_amount": 111.0,
"operations": [
{
"ask_token": "uluna",
"contract_addr": "terra179a20595ssz3zxmg46t9jpwyq5vfhuvyelj5qnthq6dcah9tdu0sxpt0tm",
"exchange": "astroport",
"offer_token": "terra1uv8ltv32tuq4qf6xspytpv058p0pef64s5xdncfywjexv22lfjzs7mul8s"
},
{
"ask_token": "ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4",
"contract_addr": "terra190alph3r79rm2ypefamglwk53ln2qr3ud09sa3mnxexxf0p8xv3qzume3r",
"exchange": "phoenix",
"offer_token": "uluna"
}
],
"price_impact": 0.003054968298016103,
"return_amount": 5.288686
}
]
}
The response structure is defined by the following components:
  1. 1.
    input_amount: the amount to swap
  2. 2.
    return_amount: the amount returned by the swap simulation
  3. 3.
    routes/operations: array that indicates the swap operations to be taken
  4. 4.
    ask_token: the output token
  5. 5.
    offer_token: the input token
  6. 6.
    exchange: the exchange where the swap is being performed
  7. 7.
    price_impact: the price impact on the swap operation
The deployed smart contract that handles the swap is:

/swap

Parameter name
Type
Description
token0
string
Contract address of the token to sell, e.g. USDC
token1
string
Contract address of the token to buy, e.g. uluna
amount
integer
Amount of the token to sell, set in minimal divisible units, e.g. 13.45 Luna set as 13450000
exchange
string
Optional parameter to limit the search of the best route within a given exchange. For example, input of "astroport" will only search on Astroport, while "astroport, terraswap" will search on both Astroport and Terraswap. The default setting is to search on all the DEX's if no value is passed.
slippage
decimal
The slippage for the trade. Value between 0 and 1. For example, for a 15% slippage, we can enter 0.15
use_split
bool
Indicates if volume splitting should be applied

Example:

api-terra2.tfm.com/swap?amount=10000000000&token1=uluna&token0=terra1nsuqsk6kh58ulczatwev87ttq2z6r3pusulg9r24mfj2fvtzd4uq3exn26&slipage=0.05&exchanges=terraswap&use_split=true
Return structure:
{
"type": "wasm/MsgExecuteContract",
"value": {
"coins": [
{
"amount": "111000000",
"denom": "ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4"
}
],
"contract": "REPLACE_ROUTER",
"execute_msg": {
"execute_swap_operations": {
"expect_amount": "2286213624",
"max_spread": "0.50",
"minimum_receive": "2263351487",
"offer_amount": "111000000",
"routes": [
{
"offer_amount": "111000000",
"operations": [
{
"t_f_m_swap": {
"ask_asset_info": {
"native_token": {
"denom": "uluna"
}
},
"factory_name": "astroport",
"offer_asset_info": {
"native_token": {
"denom": "ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4"
}
},
"pair_contract": "terra1fd68ah02gr2y8ze7tm9te7m70zlmc7vjyyhs6xlhsdmqqcjud4dql4wpxr"
}
},
{
"t_f_m_swap": {
"ask_asset_info": {
"token": {
"contract_addr": "terra1uv8ltv32tuq4qf6xspytpv058p0pef64s5xdncfywjexv22lfjzs7mul8s"
}
},
"factory_name": "astroport",
"offer_asset_info": {
"native_token": {
"denom": "uluna"
}
},
"pair_contract": "terra179a20595ssz3zxmg46t9jpwyq5vfhuvyelj5qnthq6dcah9tdu0sxpt0tm"
}
}
]
}
]
}
},
"sender": "REPLACE_SENDER"
}
}
Returns the WASM message to be executed.
The "REPLACE_SENDER" has to be replaced with the address of the sender.
The "REPLACE_ROUTER" has to be replaced with terra19hz374h6ruwtzrnm8ytkae782uv79h9yt9tuytgvt94t26c4793qnfg7vn

/tokens

Returns the list of all supported tokens on the aggregator
Return structure:
[{"contract_addr":"terra1ecgazyd0waaj3g7l9cmy5gulhxkps2gmxu9ghducvuypjq68mq2s5lvsct","decimals":6,"id":0,"name":"Eris Amplified LUNA","symbol":"ampLUNA"},
{"contract_addr":"terra14xsm2wzvu7xaf567r693vgfkhmvfs08l68h4tjj5wjgyn5ky8e2qvzyanh","decimals":6,"id":0,"name":"Stader LunaX Token","symbol":"LunaX"},
{"contract_addr":"uluna","decimals":6,"id":0,"name":"LUNA","symbol":"LUNA"},{"contract_addr":"ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4","decimals":6,"id":0,"name":"uusdc","symbol":"axlUSDC"},
...