# Constant-product AMM

Terraswap and Astroport are automated market-maker (AMM) protocols implemented with smart contracts on the Terra blockchain.  An AMM enables a decentralized on-chain exchange for the various assets involved in Terra ecosystem.  For more details regarding these protocols, please refer to:

* Terraswap documentation: <https://docs.terraswap.io>.
* Astroport documentation: <https://docs.astroport.fi/astroport/astroport/astro-pools/constant-product-pools#how-constant-product-pools-work>.

The delta-neutral strategy uses constant-product AMMs offered by Terraswap and Astroport, to trade between UST and cw20 tokens, including mAsset, MIR and SPEC in the following situations:

* **mAsset -> UST (Terraswap):** When mAsset short position is opened or increased (at delta-neutral position open and reinvestment events), the minted mAsset is swapped for UST by Mirror's smart contract; at rebalance events, moving from a net long state back to the neutral state;
* **UST -> mAsset (Terraswap):** At rebalance events, moving from a net short state back to the neutral state;
* **MIR -> UST (Terraswap or Astroport):** At reinvestment events, the Aperture delta-neutral smart contract swaps MIR reward for UST via Terraswap or Astroport, whichever provides the better rate;
* **SPEC -> UST (Terraswap, or potentially Astroport in the future):** At reinvestment events, the Aperture delta-neutral smart contract swaps SPEC reward for UST via Terraswap; at this time there is no SPEC-UST liquidity pool on Astroport, but the Aperture delta-neutral contract is already implemented to check for such a pool on Astroport.  As a result, when the SPEC-UST Astroport pool is created and provides a better rate than Terraswap, SPEC swaps will automatically be routed to Astroport.

To learn about the mechanism of a constant-product AMM, please refer to <https://docs.terraswap.io/docs/introduction/mechanism/>.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aperture.finance/docs/legacy-products/terra-classic-delta-neutral-strategy-retired/constant-product-amm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
