Skip to main content

Router

Overview

The Router contract contains logic to facilitate multi-hop swaps for Cosmos native & CW20 tokens.

InstantiateMsg

Initializes the Router contract with the Astroport factory contract address.

json
router.rs
Copy

_3
{
_3
"astroport_factory": "terra..."
_3
}

ExecuteMsg

receive

CW20 receive msg.

json
router.rs
Copy

_7
{
_7
"receive": {
_7
"sender": "terra...",
_7
"amount": "123",
_7
"msg": "<base64_encoded_json_string>"
_7
}
_7
}

ParamsTypeDescription
receiveCw20ReceiveMsgCW20 receive message

execute_swap_operations

Performs multi-hop swap operations for native Cosmos & CW20 tokens. Swaps execute one-by-one and the last swap will return the ask token. This function is public (can be called by anyone).

json
router.rs
Copy

_29
{
_29
"execute_swap_operations": {
_29
"operations": [
_29
{
_29
"native_swap": {
_29
"offer_denom": "...",
_29
"ask_denom": "..."
_29
}
_29
},
_29
{
_29
"astro_swap": {
_29
"offer_asset_info": {
_29
"native_token": {
_29
"denom": "..."
_29
}
_29
},
_29
"ask_asset_info": {
_29
"token": {
_29
"contract_addr": "..."
_29
}
_29
}
_29
}
_29
}
_29
],
_29
"minimum_receive": "123",
_29
"to": "...",
_29
"max_spread": "0.05"
_29
}
_29
}

ParamsTypeDescription
operationsVec<SwapOperation>A vector of swap operations
minimum_receiveOption<Uint128>The minimum amount of tokens to get from a swap
toOption<String>Addess receving tokens (if different from sender)
max_spreadOption<Decimal>Max spread

SwapOperation

router.rs
Copy

_11
#[cw_serde]
_11
pub enum SwapOperation {
_11
NativeSwap {
_11
offer_denom: String,
_11
ask_denom: String,
_11
},
_11
AstroSwap {
_11
offer_asset_info: AssetInfo,
_11
ask_asset_info: AssetInfo,
_11
},
_11
}

VariantsDescription
NativeSwapNative swap
AstroSwapASTRO swap

execute_swap_operation

Executes a single swap operation. This message is for internal use.

astro_swap.json
native_swap.json
router.rs
Copy

_21
{
_21
"execute_swap_operation": {
_21
"operation": {
_21
"astro_swap": {
_21
"offer_asset_info": {
_21
"native_token": {
_21
"denom": "..."
_21
}
_21
},
_21
"ask_asset_info": {
_21
"token": {
_21
"contract_addr": "..."
_21
}
_21
}
_21
}
_21
},
_21
"to": "...",
_21
"max_spread": "0.05",
_21
"single": false
_21
}
_21
}

ParamsTypeDescription
operation<SwapOperation>Native or Astro swap operation
toOption<String>Addess receving tokens (if different from sender)
max_spreadOption<Decimal>Max spread
singleboolDefines whether this swap is single or part of a multi hop route

assert_minimum_receive

Checks that an amount of ask tokens exceeds minimum_receive. This message is for internal use.

json
router.rs
Copy

_10
{
_10
"asset_info": {
_10
"token": {
_10
"contract_addr": "..."
_10
}
_10
},
_10
"prev_balance": "123",
_10
"minimum_receive": "123",
_10
"receiver": "..."
_10
}

ParamsTypeDescription
asset_infoAssetInfoInformation about an asset stored in an AssetInfo struct
prev_balanceUint128Previous balance
minimum_receiveUint128The minimum amount of tokens to get from a swap
receiverStringAddess receving tokens

QueryMsg

config

Queries the general configuration for the router contract.

json
router.rs
Copy

_3
{
_3
"config": {}
_3
}

ConfigResponse

This structure describes a custom struct to return a query response containing the base contract configuration.

json
router.rs
Copy

_3
{
_3
"astroport_factory": "terra..."
_3
}

ParamsTypeDescription
astroport_factoryStringThe Astroport factory contract address

simulate_swap_operations

Simulates multi-hop swap operations.

json
router.rs
Copy

_27
{
_27
"simulate_swap_operations": {
_27
"offer_amount": "123",
_27
"operations": [
_27
{
_27
"native_swap": {
_27
"offer_denom": "...",
_27
"ask_denom": "..."
_27
}
_27
},
_27
{
_27
"astro_swap": {
_27
"offer_asset_info": {
_27
"native_token": {
_27
"denom": "..."
_27
}
_27
},
_27
"ask_asset_info": {
_27
"token": {
_27
"contract_addr": "..."
_27
}
_27
}
_27
}
_27
}
_27
]
_27
}
_27
}

ParamsTypeDescription
offer_amountUint128The amount of tokens to swap
operationsVec<SwapOperation>The swap operations to perform, each swap involving a specific pool

SimulateSwapOperationsResponse

This structure describes a custom struct to return a query response containing the end amount of a swap simulation.

json
router.rs
Copy

_3
{
_3
"amount": "123"
_3
}

ParamsTypeDescription
amountUint128The amount of tokens received in a swap simulation