# NEPRISWAP

NEPRIswap will be a [Uniswap](https://uniswap.org/)-inspired automated market marker (AMM) protocol implemented with smart contracts. NEPRI TFA will rely on NEPRIswap to establish nYUSD trading pairs for tAssets and for the NEPT token. This will enable a decentralized on-chain exchange for the various assets involved in NEPRIDAO and NEPRI TFA Protocol.

## Mechanism <a href="#mechanism" id="mechanism"></a>

### Liquidity Pools <a href="#liquidity-pools" id="liquidity-pools"></a>

NEPRIswap will create automated markets for pairs of tokens (or native NEPRI tokens like nYUSD, VRTBs, RTLs, ETs) 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.&#x20;

### Constant Product <a href="#constant-product" id="constant-product"></a>

NEPRIswap pools make prices based on a **constant product invariant.**

$$
XY=k
$$

The product of the number of tokens on each side of the pool should remain constant across trading operations (buying / selling). For NEPRI TFA-related pools, nYUSD is on one side and tAsset/NEPT tokens are on the other.

### Pricing <a href="#pricing" id="pricing"></a>

In order to preserve the constant product invariant, NEPRIswap will make prices that ensure the product of resultant balances of the pool is as close as possible to the product calculated prior to the trade. With X being the current balance of the pool's source asset and Y being that of the target asset:

$$
XY=k=(X+A
*{\text{in}}
​
)(Y−B*{\text{out}}

​
)
$$

To determine the proper value of $$Bout​$$ given the trader's offered asset $$A\_{in}  :$$​&#x20;

$$
B
out
​
\=  \frac{XA
in
​	}{Y + A
in}
$$

​NEPRIswap will be able to execute trades with only the current balances of the pool and the number of incoming tokens. The market price will be encoded as the number of the pool's target tokens divided by the source asset (also called the pool ratio). The spread between the executed and the expected trade is:

$$
\text{spread} = \max\bigg(\frac{YA\_{\text{in}}}{X+A\_{\text{in}}} - \frac{YA\_{\text{in}}}{X}, 0\bigg)
$$

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 $$\frac{Y}{X}​.$$&#x20;

## LP Commission <a href="#lp-commission" id="lp-commission"></a>

In order to compensate liquidity providers, NEPRIswap will charge 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 NEPRI TFA, each liquidity pool for tAssets/NEPT has a fixed LP commission fee of 0.3%. This fee is levied on the trader and is received as tAssets/NEPT or nYUSD, depending on the direction of the trade.

{% hint style="info" %}
Additionally, if the traded asset is a native token such as nYUSD, the NEPRIDAO will incur a tax on the transfer (not controlled by NEPRI TFA Protocol).
{% endhint %}

$$
\text{received} = B\_{\text{out}}(1- \text{fee}\_{\text{LP}} ) - \text{tax}
$$
