docs.mirror.finance Open in urlscan Pro
2606:4700:4400::6812:240f  Public Scan

URL: https://docs.mirror.finance/protocol/terraswap
Submission: On October 23 via api from GR — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

Home

Interchain Access
Security
FAQ
Protocol
Overview
Mirrored Assets (mAssets)
Mirror Token (MIR)
Terraswap
Staking Tokens (LP & sLP)
Governance

Developers
mirrorcli
Mirror.js
Mirror API
User Guide
Web App

Mirror on Ethereum

Terra Bridge
Smart Contracts
Architecture
Collector
Community
Factory
Gov
Admin Manager
Mint
Lock
TeFi Oracle
Collateral Oracle
Staking
Limit Order
External Resources
Mirror Protocol GitHub

Terraswap App

Terra Blockchain

Mirror Bug Bounty Program

Powered By GitBook
Terraswap


A short primer on Terraswap is provided here for convenience. For more details
regarding Terraswap, you can refer to its official documentation here.
Terraswap is a Uniswap-inspired automated market maker (AMM) protocol
implemented with smart contracts on the Terra blockchain. Mirror relies on
Terraswap to establish UST trading pairs for mAssets and for the MIR token. This
enables a decentralized on-chain exchange for the various assets involved in
Mirror Protocol.
MECHANISM

LIQUIDITY POOLS

Terraswap creates automated markets for pairs of tokens (or native Terra coins
like UST) called pools which enable users to exchange one asset for the other
directly on-chain. Pools maintain balances of both assets, to which users can
provide liquidity in exchange for reward-bearing LP tokens. A more detailed
explanation about LP tokens and their relationship with Mirror can be found
here.
CONSTANT PRODUCT

Terraswap pools make prices based on a constant product invariant.
XY=kXY=k \\XY=k
The product of the number of tokens on each side of the pool should remain
constant across trading operations (buying / selling). For Mirror-related pools,
TerraUSD is on one side and mAsset/MIR tokens are on the other.
PRICING

In order to preserve the constant product invariant, Terraswap will make prices
that ensure the product of resultant balances of the pool is as close as
possible to product calculated prior to the trade. With
XXX
being the current balance of the pool's source asset and and
YYY
being that of the target asset:
XY=k=(X+Ain)(Y−Bout)X Y = k =(X + A_{\text{in}})(Y - B_{\text{out}})
\\XY=k=(X+Ain )(Y−Bout )
To determine the proper value of
BoutB_{\text{out}}Bout
given the trader's offered asset
AinA_{in}Ain
:
Bout=YAinX+AinB_{\text{out}} = \frac{YA_{\text{in}}}{X+A_{\text{in}}}Bout =X+Ain
YAin
Terraswap is able to execute trades with only the current balances of the pool
and the number of incoming tokens. The market price is encoded the number of
pool's target tokens divided by the source asset (also called the pool ratio).
The spread between the executed and the expected trade is:
spread=max⁡(YAinX+Ain−YAinX,0)\text{spread} =
\max\bigg(\frac{YA_{\text{in}}}{X+A_{\text{in}}} - \frac{YA_{\text{in}}}{X},
0\bigg)spread=max(X+Ain YAin −XYAin ,0)
When a pool has large balances of tokens on both sides from liquidity providers,
the spread becomes smaller and helps the pool execute closer to its reported
price of
YX\frac{Y}{X}XY
.
LP COMMISSION

In order to compensate liquidity providers, Terraswap charges an LP Commission
on each trade. The fee returns to the pool to serve as a reward for LP token
holders and can only be withdrawn by burning LP tokens and reclaiming a portion
of the pool.
In Mirror, each liquidity pool for mAssets/MIR has a fixed LP commission fee of
0.3%. This fee is levied on the trader and is received as mAssets/MIR or UST,
depending on the direction of the trade.
Additionally, if the traded asset is a native token such as UST, the Terra
network will incur a tax on the transfer (not controlled by Mirror Protocol).
received=Bout(1−feeLP)−tax\text{received} = B_{\text{out}}(1-
\text{fee}_{\text{LP}} ) - \text{tax}received=Bout (1−feeLP )−tax

Protocol - Previous
Mirror Token (MIR)
Next - Protocol
Staking Tokens (LP & sLP)

Last modified 1yr ago
Was this page helpful?

Copy link
On this page
Mechanism
Liquidity Pools
Constant Product
Pricing
LP Commission
Cookies
Reject all
This site uses cookies to deliver its service and to analyse traffic. By
browsing this site, you accept our cookie policy.