Assessment reports>Astroport Pair XYK Sale Tax>Threat Model>Message: ExecuteMsg::Swap

Message: ExecuteMsg::Swap

This message can be sent by anyone and allows to perform a swap.

The parameters that a user can control are:

  • offer_asset — This is the input asset (denom and amount) the user offers. It must be a valid native asset (token asset swaps need to use the ExecuteMsg::Receive flow). The amount must match the actual amount bundled with the incoming message, and the asset must be one of the two assets in the pool.

  • belief_price — This is an optional user-controlled price used to calculate the swap spread, in turn used to enforce anti-slippage checks.

  • max_spread — This is an optional user-controlled number representing the maximum acceptable spread, for anti-slippage checks.

  • to — This is the optional address that will receive the output assets. If not provided, the output will be transferred to the message sender.

  • ask_asset_info — This field of ExecuteMsg::Swap is ignored.

The handler for the message computes the output amount that satisfies the k-invariant, accounting for commission fees and maker fees (taken from the output asset) and sales tax (taken from the input asset). All the fees are configurable for each pool. The contract checks that the effective exchange rate satisfies the anti-slippage threshold provided by the user. The message handler generates the appropriate messages to transfer the computed amounts to the required destinations. If configured to do so, the contract will also keep track of asset balances. Lastly, the contract will update the cumulative prices and return a response that includes metadata about the completed swap, including the addresses of the sender and (potentially different) receiver, input and output amounts, commission fees, maker fees, and sales tax amounts.

Zellic © 2024Back to top ↑