# Welcome!

We're glad you're here. Check out the official documentation for the premiere front running resistant, privacy first AMM DEX secured by Secret Network!

## Introduction to the Protocol

**SecretSwap is a protocol for swapping** [**SecretTokens**](broken://pages/-MaeM1BAfj4LZ5IUZ8mB) **(SNIP-20s) on Secret Network.** Given the encrypted nature of secret contracts, inputs to a transaction/contract are encrypted while they are on the mempool and cannot be front-run by any adversary. This ensures **SecretSwap protects its users and their money from front-running attacks and privacy threats**.

SecretSwap also provides access to **cross-chain liquidity** through an [Ethereum bridge](https://bridge.scrt.network/), a [Binance Smart Chain bridge](https://bridge.scrt.network/), a [Monero bridge](https://ipfs.io/ipns/k51qzi5uqu5dhovcugri8aul3itkct8lvnodtnv2y3o1saotkjsa7ao1aq0dqa/), a Plasm bridge (in development), and reduces fees relative to Ethereum.


# Overview

SecretSwap is an automated market maker ([AMM](broken://pages/-MaeEUALTkZ9OCx3IWNZ)) liquidity protocol. There is no order book, no centralized party, and no central facilitator of trade. Built by Secret Contracts, SecretSwap transactions inputs are encrypted - protecting users from front-running attacks and providing an increased level of privacy compared to traditional AMMs.

Each pool within SecretSwap is defined by a secret contract that includes a few functions to enable swapping tokens, adding liquidity and more. At its core each pool uses the function `x*y=k` to maintain a curve along which trades can occur.

The pools keep track of reserves (liquidity) and updates those reserves every single time someone trades. Because the reserves are automatically rebalanced, a SecretSwap pool can always be used to buy or sell a token without requiring a counter-party on the other side of your trade.

* **Note:** Given the requirement to publicly update pool reserves to determine the price, an observer can see a consolidated view of changes (swaps, provide / remove liquidity) in a given block. As a result, if there’s a single transaction with the pool in a given block, it is not possible to have privacy on that transaction. With more transactions per pool in a given block, SecretSwap provides additional privacy to users.

For a more in depth description, check out how SecretSwap works in this [blog post](https://scrt.network/blog/secret-markets-front-running-prevention) outlining the theory behind an AMM using secret contracts.

In order to use SecretSwap, you will need the [Keplr Wallet](https://wallet.keplr.app/) installed on your browser and at a minimum, some `SCRT` to begin swapping.


# Stakeholders

Interacting with SecretSwap, users act in one or more of the following roles:

* Traders
* Liquidity Providers
* Stakers

#### Traders

A **trader** engages in buying and selling assets through SecretSwap and benefits from price exposure via assets & the implemented [CSHBK rewards program](broken://pages/-MaeMDfsvt5GqPNhPxpc).

#### Liquidity Providers

A [**liquidity provider**](broken://pages/-MaeEgnqczpOVZmVuBCY) adds equal amounts of an sAsset and/or another required asset to the corresponding SecretSwap pool, which increases liquidity for that market. This process rewards the liquidity provider newly minted LP tokens, which represent the liquidity provider's share in the pool and also provide rewards from the pool's trading fees. LP tokens can be burned to reclaim their corresponding share from the pool. Certain LP tokens are rewarded with SEFI token.

#### Stakers

A **staker** is a user that stakes either LP Tokens or SEFI tokens in order to earn staking rewards as SEFI tokens. Governance is the process through which new sAssets will be added and protocol parameters can be altered. While governance for SecretSwap isn’t enabled at this time, this functionality will be released in the future. Only SEFI stakers will be able to participate in SecretSwap governance. SEFI staked & LP Tokens can be unstaked at any time.


# SecretTokens

Secret Tokens are the privacy tokens powered by Secret Contracts on Secret Network. Using Secret Contracts, the network achieves privacy network effects.

## SNIP-20 Tokens (a.k.a. SecretTokens)

Leveraging secret contracts, Secret Network supports the creation of privacy preserving fungible tokens, which are called Secret Tokens. Combining the programmability of ERC-20s with the privacy of Zcash or Monero, SecretTokens unlock important use cases and create new value. These tokens follow the [SNIP-20](https://github.com/SecretFoundation/SNIPs/blob/master/SNIP-20.md) specification, which is loosely based on Ethereum's [ERC-20](https://eips.ethereum.org/EIPS/eip-20) and [ERC-777](https://eips.ethereum.org/EIPS/eip-777) standards and is a superset of CosmWasm's [CW-20](https://github.com/CosmWasm/cosmwasm-plus/blob/master/packages/cw20/README.md).&#x20;

### What is encrypted?

* Balances
* Transactions (receiver, amount)
* Contract calls

Any transaction, all rolling balances and contract interactions are forever kept encrypted, ensuring both anonymity and confidentiality. Each person can still query their own (and only their own) balance, as well as send tokens to others, privately. Additionally, viewing keys can be generated to allow third parties (including other contracts) to view your balance, without actually taking control of your funds.To illustrate, [Secret Network block explorer](https://secretnodes.com/secret/chains/secret-2/contracts/secret1k0jntykt7e4g3y88ltc60czgjuqdy4c9e8fzek) only shows interactions (without specifying specific function calls) with a SNIP-20 contract and total supply (essentially TVL) of tokens, plus transfers and holdings corresponding to the viewer.

### Privacy Network Effects

Imagine a system where any operation you do, across any DeFi service (be it trading, staking, lending, providing liquidity, issuing synthetic tokens, etc.) happens with complete privacy. That’s the vision of programmable privacy and Secret Network. There is a big difference between transactional and computational privacy. Secret contracts give application developers the power of programmable privacy features, which are *composable.*

Each DeFi user actually gains more privacy with every additional service and every dollar worth of additional value locked in the ecosystem, leading to *privacy network effects*. The aggregate liquidity across all DeFi applications quantifies the level of privacy obtained (a.k.a. the anonymity set).

## SCRT vs sSCRT

The Secret Network blockchain is powered by the `SCRT` token. It can be delegated to validators to secure the network for staking rewards and it is also used to pay for network fees. This token can be purchased in centralized exchanges.

SecretSwap also supports the `sSCRT` token, which is the SNIP-20 implementation of `SCRT`. This token has all the privacy features of secret smart contracts, however it cannot be used to stake or to pay network fees. `SCRT` can be swapped for `sSCRT` via the [Keplr Wallet](https://wallet.keplr.app/) or via the main SecretSwap app.

* *Pro tip:* Always keep a few un-staked `SCRT` in your wallet for network fees.

### Viewing Keys and Compliance

Privacy by default means the users have control of who sees what! To increase their usability, Secret Tokens are designed to enable owners to share verifiable proofs with anyone. This is also critical to build a compliant financial ecosystem. [Viewing Keys](broken://pages/-MaeMJ5Yty0b0kUkK2Jo) are used to validate the identity of someone who queries a specific account. User-supplied strings are used for entropy for generation of the viewing key. Viewing keys are designed to be used by 3rd parties like auditors, wallets and explorers when users opt-in to share this information.


# Viewing Keys

Viewing Keys allow users to see balances of SecretTokens

The encrypted nature of the secret smart contracts that power [SecretTokens](broken://pages/-MaeM1BAfj4LZ5IUZ8mB) and SecretSwap means that the balances on your wallet are not visible by default, even to you. In order to see these balances, you need to create the corresponding viewing keys.

In the SecretSwap app, you can select a SecretToken from the drop-down and the app will check your wallet for a viewing key. If one is found, the app will show your balance, otherwise it will show a button showing "View Balance".

![](/files/F0I8oAwLA18lrvQFZ2Hu)

Clicking this button triggers the creation of a viewing key for that SecretToken for your wallet. [Keplr](https://keplr.app/) will prompt you to approve this creation and submit the transaction.&#x20;

![](/files/jS8YFkJjN6rCOAHfO3QW)

This transaction needs a small amount of `SCRT` for network fees. &#x20;

![](/files/VolaktUiZeEcslM1fwvD)

Once this transaction is completed, the SecretSwap app will show your balance for that SecretToken, even if zero. Each SecretToken you wish to hold in your wallet will need a viewing key created. These keys can be copied and then imported into Keplr if you switch your wallet to a different browser.

### Adding Viewing Keys directly from Keplr

Viewing Keys can also be added directly from your Keplr wallet. In order to do this, you'll first need the contract address of the token you're going to be adding. A list of contract addresses can be found [here](broken://pages/-MaeGkiHk0llLH4jrY0O) or on [secretanalytics.xyz](http://secretanalytics.xyz/secretswap). Once you have the contract address for the token you'd like to add, open your Keplr wallet and click the button consisting of three lines in the top left corner. This will open the menu and reveal the following options:

![Select the 'Add Token' option from this menu](/files/quGG5Z5nqHq0JtKd52Nj)

Clicking the 'Add Token' option from the menu will open the following dialogue box:<br>

![Click 'Submit' when populated](https://files.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-MaeBBtp7oGfe-K-vG2b%2F-Mb7n620XBobaoWu5K23%2F-Mb7qCu7yraPumzx-vDz%2FScreenshot%20from%202021-06-01%2013-30-45.png?alt=media\&token=1d79260a-c70a-4dea-84d3-efd5bb392113)

Paste the contract address in the 'Contract Address' field and Keplr wallet will auto-populate the remainder of the details. In this example, we're adding the viewing key for sWBTC. Click the 'Submit' button and you'll once again be asked to authorize gas usage.<br>

![Click 'Approve' to finalize](https://files.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-MaeBBtp7oGfe-K-vG2b%2F-Mb7n620XBobaoWu5K23%2F-Mb7qxxUOmTdAzEwKipj%2FScreenshot%20from%202021-06-01%2013-30-54.png?alt=media\&token=543bbf85-5aa4-4583-a5d5-053d05fedb02)

Once you approve the gas usage, the Viewing Key will be added to your wallet and the balance of your added asset should now be showing on SecretSwap or showing as '0' if you have none of this asset. It's that simple!


# Bridges

Bridges allow cross-chain liquidity on SecretSwap and allow Secret Network to provide privacy to the blockchain ecosystem.

SecretSwap supports cross-chain exchanges through bridges that allow you to lock tokens from one blockchain (e.g.: Ethereum) and receive SecretToken equivalents to use in SecretSwap. The [Ethereum, Monero, & Binance Smart Chain bridges ](https://bridge.scrt.network/)are currently available and others are in active development. The list of supported assets can be found [here](https://bridge.scrt.network/tokens).

{% hint style="info" %}
Keep in mind that there are minimum amounts to withdraw your SecretTokens back to the Ethereum & Binance Smart Chain blockchains due to the their respective network fees. These are listed in the [Supported Assets](https://bridge.scrt.network/tokens) page.
{% endhint %}

To use the Ethereum & BSC [bridges](https://bridge.scrt.network), you will need both the [Keplr Wallet](https://wallet.keplr.app/) and [Metamask](https://metamask.io) wallet on your browser. The bridge will then allow you to choose if you want to move tokens from Ethereum or Binance Smart Chain to Secret Network, or viceversa. You can bridge ETH, BNB, or any of the supported tokens to their SecretToken equivalent, keep in mind that the bridging transaction will incur Ethereum or Binance Smart Chain network fees. The [XMR bridge](https://ipfs.io/ipfs/QmNRrLDhKGZCSXAZcPU1cBTaLouhWnTi5kfWUzJB4nJbzA) was created by a different development team and has different processes. The tutorial for this bridge can be found [here](https://medium.com/@secretnetwork/secret-monero-bridge-tutorial-22c5eab8bcac).\
\
To choose which bridge you would like to use, simply click the drop down box and make your selection as shown in the picture below:

![](/files/Xx09OfpLhvvDjtcIOk7A)


# SEFI Token

The SEFI Token is the governance token for SecretSwap and is also used to incentivize traders and liquidity provider on SecretSwap

The `SEFI` token was distributed in a one-time genesis event in March 2021 and will continue to be distributed to SecretSwap users over four years. The token emission and the details of each class of rewards can be seen below. **`SEFI` is non-inflationary with a fixed supply of 1 billion tokens.**

10% of `SEFI` was distributed at genesis. The remaining 90% of tokens would be distributed over four years, with rewards halving year over year. Of the remaining 90% of tokens to be distributed after genesis, approximately 71% will be allocated to SecretSwap Users (LP Providers & Traders in the form of $CSHBK) as notated and broken down in the chart below. Approximately 11% is allocated for SEFI Stakers and 18% is reserved for future development, accounting for 100% of the remaining supply distribution. These parameters (e.g. weighting of rewards between LP Providers and Traders) could change in the future through governance.

|                      |  Genesis  |  Year 1  |  Year 2  |  Year 3 |  Year 4 | Total   |
| -------------------- | :-------: | :------: | :------: | :-----: | :-----: | ------- |
| **Genesis**          | **10.0%** |     -    |     -    |    -    |    -    |         |
| External Communities |    2.5%   |     -    |     -    |    -    |    -    |         |
| Existing Users       |    7.5%   |     -    |     -    |    -    |    -    |         |
| **SecretSwap Users** |     -     |  37.87%  |  18.93%  |  9.47%  |  4.73%  | **71%** |
| *LP Providers*       |     -     | *32.53%* | *16.26%* | *8.13%* | *4.08%* | *61%*   |
| *Traders (CSHBK)*    |     -     |  *5.34%* |  *2.67%* | *1.34%* | *0.65%* | *10%*   |
| **SEFI Stakers**     |     -     |   5.87%  |   2.93%  |  1.47%  |  0.73%  | **11%** |
| **Development Fund** |     -     |   9.6%   |   4.8%   |   2.4%  |   1.2%  | **18%** |

You can obtain `SEFI` tokens on SecretSwap, as well as earn them by providing liquidity on selected trading pairs, or through the [CSHBCK Token](broken://pages/-MaeMDfsvt5GqPNhPxpc) mechanism.

### Initial Function of SEFI

The SEFI token allows the Secret DeFi community to govern its protocol in a decentralized fashion. The decentralized governance functionality is now live! Some of the aspects that the community can govern include:

* Spending the development pool
* Determining pools eligible for user rewards, including changing their respective weights
* Joining other communities, for example, by enabling joint liquidity mining campaigns like [Sushiswap Onsen](https://amm.testnet.enigma.co/swap#Swap)
* SecretSwap fees and use of fees
* Adding other products into Secret Finance that receive and utilize SEFI

SEFI tokens staked in the previous pool will need to be migrated to the new pool to continue to earn rewards & participate in decentralized governance. Only SEFI tokens staked in the new pool will be eligible to participate.

For details on the tokenomics of `SEFI`, see [this blog post](https://scrt.network/blog/sefi-governance-token-for-secret-defi).


# CSHBK Token

CSHBK token has been disabled until further notice. This program will be revamped in a different format in a future implementation. CSHBK is not redeemable at this time.


# Swapping

The SecretSwap app has three sections: Swap, Provide and Withdraw. To swap tokens, click on the Swap tab and select the SecretToken you have and wish to exchange from the drop-down. If you have a viewing key in your wallet, your balance for that SecretToken will be displayed.

Next, pick the SecretToken you wish to receive from the second drop-down. The app will report your balance for this second SecretToken if you have a viewing key. If you don’t, you can click the “View” button to generate one.

Next, enter the amount of the SecretToken you have that you wish to swap. The SecretSwap app will calculate a route through the existing liquidity pools and provide you with an estimated amount of the target SecretToken you selected.<br>

![Preparing a swap.](/files/mtOMQBJhSd9OIuRvBob2)

The SecretSwap app also provides additional information about your swap:

* Price: SecretSwap will report the current exchange rate between the two SecretTokens you have selected. You can flip between the two rates by clicking on the double arrow icon on the right. For the example below, clicking the icon would show the price in sSCRT per sDAI. Clicking it again would return to showing the price in sDAI per sSCRT. The price reported is determined by the ratios in the liquidity pools involved in the trade and may differ from the overall market rate.

![](/files/uddKAyaOoLjNIxFQ5ihS)

* Route: SecretSwap features a routing engine that searches existing liquidity pools to find a path from your source token to your target token, looking to provide the best available price. This feature allows you to swap tokens even when there is no liquidity pool available for your trading pair, or the direct trading pair may have low liquidity. If you hover over the question mark, the app will show you the different routes and the price each can give.

![](/files/s30r5I26Md9I1vkh8XfK)

## Fees <a href="#fees" id="fees"></a>

There are two kinds of fees: network fees and liquidity provider fees. Network fees are required to drive the smart contracts that drive SecretSwap on Secret Network. These fees are paid in `SCRT` and you can use your Keplr wallet to adjust and pay these.

Liquidity providers also receive a fee as an incentive for providing their SecretTokens to SecretSwap for the liquidity and health of the exchange. Currently, this fee is 0.3% and is paid in the SecretToken you are providing for your exchange. This fee is shown on the information in the SecretSwap app.

![](/files/qTVIjCTziZp9nSbHRR5q)

## Price Impact <a href="#price-impact" id="price-impact"></a>

Due to the nature of the algorithm behind Automated Market Makers (AMMs), every trade impacts the amounts of tokens that are in a liquidity pool, affecting the price. The price for a trade is determined by the ratio of tokens present in a liquidity pool and may differ from the overall market rate.

Suppose you have a liquidity pool with SecretToken X and SecretToken Y at a ratio of 1 Y : 4 X. Intuitively, we would think that swapping any amount of X would always give us 1/4 of that amount in Y. However, the constant product formula behind liquidity pools behaves differently, as shown in the chart below.

![](/files/GSVXhQ5tYXYybetW2V9T)

As you can see, the larger the size of your trade, the larger the impact to the pool and the larger the difference will be in the final price you pay for your exchange. This is especially important when the size of your trade approaches the overall size of the pool, where the price impact can be quite significant, as shown below.

![](/files/fwTGjIqLPh8XkTIIRPxC)

The SecretSwap app shows you a calculation of the price impact of your trade based on the amount you have entered and the status of the liquidity pool to inform you before finalizing your swap.


# Liquidity Providing

SecretSwap is an Automated Market Maker (AMM) built on the secret smart contracts powered by the Secret Network. This technology allows the community to swap tokens without an intermediary, by pooling tokens in SecretSwap as a liquidity provider.

The algorithm behind SecretSwap's liquidity pools is called the constant product formula, `x * y = k`. Liquidity Providers (LPs) lock their tokens in a pool at a certain ratio of `x` to `y` that determines the price the pool offers to the community.

&#x20;

![Image Credit: G. R2](/files/D05BOTDuN7qyj3Qdky7U)

To provide your SecretTokens to SecretSwap for liquidity, go to the "Pool" page and use the "Provide" tab in the app. You can then pick the two tokens you wish to provide to SecretSwap as an LP. The app will show your available balance of each token, you can then enter the amount you wish to provide for one of your tokens and the app will calculate the amount of the other token that maintains the constant `k` of the pool. In cases where the liquidity pair does not exist, you get to set the ratio of the liquidity pool by the amounts of tokens you choose to provide.

![](/files/FEfWTF4TrbhHlS2VvKxE)

The app will report the current price for the pool if the pair exists, and will also report the portion of the total tokens in the pool that you are providing. This is important information because your rewards depend on your share of the pool. You can always look at the current status of the liquidity pool by clicking the "View Pair Analytics" link in the app, which will take you to [SecretAnalytics](https://secretanalytics.xyz/) to look at the total amount of tokens in the pool, the pool's volume and rewards.

You will need to approve both tokens to be used by SecretSwap using the corresponding buttons and approving the transactions in Keplr. After clicking "Provide", your tokens will be added to the liquidity pool and you will receive Liquidity Provider tokens that represent your share of the pool. In order to see your LP token balance, you will need to navigate to the "Withdraw" tab on the app and choose the liquidity pool where you added your tokens.

![](/files/FFm2UZ0pe3YNFOgDos4Y)

This tab will show the "View" icon if you don't have a viewing key for your LP tokens. You can click it to create a new viewing key and the app will display the balance of your LP tokens as well as the amount of pooled SecretTokens that you can redeem if you wish to withdraw your tokens from the pool. To withdraw, you can use the slider to select the amount and then approve the transaction in your Keplr wallet.

**Note:** The amounts of SecretTokens you can redeem for your LP tokens will change over time and will not necessarily be the same amount or ratio that you originally provided.

## Rewards

As an incentive to the community, SecretSwap has a 0.3% fee for every swap. This fee is added to the liquidity pool, giving LPs a share of these fees proportional to their share of the pool.

As a further incentive, certain trading pairs have staking rewards available. Liquidity Providers can stake their LP tokens and receive `SEFI` tokens, the [Secret Finance governance token](broken://pages/-MaeM6Aqi0CmbQHQJ_s1), as a reward. Currently, the pairs with rewards available are:

* sUSDC(ETH) - sUSDC(BSC)&#x20;
* sETH(ETH) - sETH(BSC)&#x20;
* sSCRT - sUSDT&#x20;
* sSCRT - sETH&#x20;
* sSCRT - sWBTC&#x20;
* sSCRT - SEFI&#x20;
* SEFI - sXMR&#x20;
* SEFI - sUSDC&#x20;
* sETH - sWBTC&#x20;
* sSCRT - sDAI&#x20;
* sSCRT - sBNB(BSC)&#x20;
* sSCRT - sLINK&#x20;
* sSCRT - sRSR&#x20;
* sSCRT - sOCEAN&#x20;
* sSCRT - sRUNE&#x20;
* sSCRT - sYFI&#x20;
* sSCRT - sDOT(BSC)&#x20;
* sSCRT - sMANA&#x20;
* sSCRT - sUNI

To stake your LP tokens, you can click on the "[Earn](https://app.secretswap.io/earn)" tab in the app and then select the particular LP token you would like to stake. The app will show you the balance of LP tokens in your wallet, the balance of LP tokens staked in the secret smart contract, if any, and your rewards balance. Here you can deposit your LP tokens, claim your rewards or withdraw any of your staked LP tokens.

![Rewards management for Liquidity Providers](/files/F1CdwCzImDVqxOH90gDh)

## Impermanent Loss

This is an important concept for Liquidity Providers. By providing your tokens to the liquidity pool, you are allowing your tokens to be exchanged for one another. For example, you provide 30 `sDAI` and 10 `sSCRT` to the liquidity pool and own 100% of the pool. If the market price of `sSCRT` increases to 4 `sDAI`, arbitrageurs will buy `sSCRT` until the pool's price reflects the market price. This removes `sSCRT` and adds `sDAI` to the pool until the pooled tokens are 35 `sDAI` and 8.6 `sSCRT`.

If the LP had not provided the tokens to the pool, their original 10 `sSCRT` would now be worth $40. With the pool exchanging some of the tokens, the 8.6 `sSCRT` is now worth around $34. The difference of $6 is the impermanent loss. It is referred to as impermanent because the pool tokens are in constant flow and the amounts will continue to change. Once the LP withdraws the tokens from the pool, this loss would become permanent. This risk is why incentives are provided to compensate Liquidity Providers. If you're interested in calculating impermanent loss, [click here for a compatible calculator](https://dailydefi.org/tools/impermanent-loss-calculator/).


# Tutorials

{% embed url="<https://youtu.be/b9_F14eAcKE>" %}
How to Buy SCRT in the U.S. Tutorial - Coinbase and Osmosis
{% endembed %}

{% embed url="<https://www.youtube.com/watch?feature=youtu.be&v=fTvKoshaWvM>" %}
Ethereum Bridge Video Tutorial
{% endembed %}

{% embed url="<https://www.youtube.com/watch?feature=youtu.be&v=HeoESTz4TzM>" %}
BSC Bridge Video Tutorial
{% endembed %}

{% embed url="<https://youtu.be/C0zRTaV8XgI>" %}
Monero Bridge Tutorial
{% endembed %}

{% embed url="<https://medium.com/@secretnetwork/secret-monero-bridge-tutorial-22c5eab8bcac>" %}
Written Monero Bridge Tutorial
{% endembed %}

{% embed url="<https://www.youtube.com/watch?v=beGEcIynFAw>" %}
SecretSwap Full Length Video Tutorial
{% endembed %}

{% embed url="<https://medium.com/@secretnetwork/trade-and-earn-yield-on-secretswap-bed612f1ddd2>" %}
Trade & Earn Yield Written Tutorial
{% endembed %}

{% embed url="<https://medium.com/@secretnetwork/provide-liquidity-on-secretswap-cd0dbe03cbc6>" %}
Provide Liquidity Written Tutorial
{% endembed %}

{% embed url="<https://darrenvchiu.medium.com/sefi-governance-tutorial-on-chain-private-voting-for-secretswap-11b52e4748fd>" %}
SEFI Governance Written Tutorial
{% endembed %}


# Frequently Asked Questions

## General

### What is SecretSwap?

SecretSwap is a protocol for creating liquidity and trading SNIP-20 tokens on Secret Network. Leveraging secret contracts, SecretSwap protects users against malicious front-running and privacy threats, provides access to cross-chain liquidity, and reduces fees relative to Ethereum.

### What is Front-running?

Front-running is an arbitrage strategy to make profit at someone else’s expense based on an information advantage. Front-running issue is not limited to DeFi, however the scale of the problem is amplified given the public nature of blockchains. Miners and arbitrage bots can see an order on the mempool before the order makes its way into the ledger and insert their orders with higher gas fees to be processed first. This means that the miner or the arbitrage bot can profit at the expense of a regular user. Furthermore, this arbitrage opportunity increases the gas fees of the underlying network, hurting users even more. [ Front-running problem on Ethereum DeFi costs users \~$1bn per year and millions of dollars in lost gas fees](https://explore.flashbots.net/).

### How does SecretSwap achieve front-running resistance?

SecretSwap is a protocol to swap secret contract based tokens (SNIP-20s) on Secret Network. Given the encrypted nature of secret contracts, inputs to a transaction/contract are encrypted while they are on the mempool and cannot be frontrun by any adversary. This ensures SecretSwap protects its users and their money from front-running attacks.

### How do I use SecretSwap?

First, you’ll need a Keplr wallet and some SCRT. Once completed, head over to [SecretSwap](https://bridge.scrt.network/swap) to start using the protocol to provide liquidity or swap tokens. Since SecretSwap is built on Secret Network, each transaction and interaction costs SCRT (the native coin of the network). This is called the “gas fee” and it’s paid to network validators to keep the network running.

### How does SecretSwap work?

SecretSwap is an automated market maker (AMM) liquidity protocol. There is no orderbook, no centralized party, and no central facilitator of trade. Using Secret Contracts, the mempool of potential SecretSwap transactions are kept entirely encrypted - protecting users from front-running attacks and providing an increased level of privacy compared to traditional AMMs.

Each pool within SecretSwap is defined by a secret contract that includes a few functions to enable swapping tokens, adding liquidity and more. At its core each pool uses the function `x*y=k` to maintain a curve along which trades can happen.

The pools keep track of reserves (liquidity) and updates those reserves every single time someone trades. Because the reserves are automatically rebalanced, a SecretSwap pool can always be used to buy or sell a token without requiring a counterparty on the other side of your trade.

Note: Given the requirement to publicly update pool reserves to determine the price, an observer can see a consolidated view of changes (swaps, provide / remove liquidity) in a given block. As a result, if there’s a single transaction with the pool in a given block, it is not possible to have privacy on that transaction. With more transactions per pool in a given block, SecretSwap provides additional privacy to users.

For a more in depth description, check out how SecretSwap works in this [blog post](https://scrt.network/blog/secret-markets-front-running-prevention) outlining the theory behind an AMM using secret contracts.

### How are prices determined?

Prices are determined by the amount of each secret token in a pool. The secret contract maintains a constant using the following function: `x*y=k`.

In this case `x` = secret\_token\_0, `y` = secret\_token\_1, `k` = constant. For each trade, a certain amount of secret tokens are removed from the pool in exchange for adding an amount of the other secret token. To maintain k, the balances held by the secret contract are adjusted during the execution of the trade, therefore changing the price.

### I saw a token was trading at X value, but when I traded on SecretSwap I got a much lower value?

There are 2 fees involved with a SecretSwap transaction: SecretSwap fees and Secret Network fees. SecretSwap fees are 0.3% of each swap deducted across the pairs. The fees are put back in the liquidity pool providing income for LPs of that pair. The fees can be changed in the future with decentralized governance enabled by SEFI.

Secret Network requires SCRT as gas to execute each transaction. Depending on the market price of SCRT, transaction costs can increase or decrease.

### Why does my transaction cost X?

Secret Network requires SCRT as gas to execute each transaction. Depending on the market price of SCRT transaction costs can increase or decrease

## SEFI Token

### What is SEFI?

SEFI is the governance token for SecretSwap and the Secret DeFi ecosystem. Users of SecretSwap can earn SEFI to participate in shaping the future of the first front-running resistant, privacy-first open financial system. SEFI is a SNIP-20 or Secret Token, which means all SEFI transactions and contract interactions are private.

### What is the total supply of SEFI?

Total supply of SEFI is set at 1,000,000,000. This amount is a non-inflationary fixed supply set at launch. 10% of the SEFI supply will be distributed at the genesis event to SecretSwap LPs during the soft-launch, SCRT stakers who secure Secret Network, users (depositors) of Secret Network-Ethereum bridge and UNI holders (above 400 UNI). The remaining 90% of the supply will be distributed over 4 years with a deflationary schedule. For more, see [SEFI tokenomics](https://scrt.network/blog/sefi-governance-token-for-secret-defi).

### How can I claim my SEFI?

Users will be able to claim SEFI both on Secret Network with their [Keplr Wallet](https://wallet.keplr.app/) and on Ethereum with their [Metamask](https://metamask.io/) wallet. Users can claim their SEFI airdrop on the [SecretSwap application](https://bridge.scrt.network/sefi). After you’ve claimed your SEFI, you can provide liquidity to sSCRT/SEFI pool or stake your SEFI and continue to earn SEFI after genesis.

### Who else can earn SEFI after genesis?

SecretSwap LPs and SEFI stakers will begin earning SEFI after genesis. Traders on SecretSwap will also earn SEFI, though not immediately at genesis. Currently eligible pools for LP rewards are:

* sETH - sWBTC
* sSCRT - SEFI
* sSCRT - sETH
* sSCRT - sLINK
* sSCRT - sRSR
* sSCRT - sRUNE
* sSCRT - sUSDT
* sSCRT - sWBTC

### Will you be able to stake SEFI at launch?

Yes, you can use this [link](https://bridge.scrt.network/sefi) to stake SEFI and participate in SecretSwap governance. Staking SEFI provides impermanent loss free yield. SEFI staking is done through a secret contract, using the [SecretSwap application](https://bridge.scrt.network/sefi).

### What is the difference between an LP token and SEFI?

LP tokens are crypto-assets (secretTokens)mathematical proof that represents your ownership of a pool. When Alice provides provided assets to a pool, she receives LP tokens. Hand holding LP tokens means holding the claim to getting those assets back. This is in contrast to SEFI, which is the SecretSwap governance token used for managing application layer changes. Staking LP tokens allows you to earn SEFI.

### Are rewards for SecretSwap LPs in SEFI or also in SCRT?

All SecretSwap rewards and governance are based on SEFI.

### What is the difference between SEFI and SCRT when it comes to governance?

SEFI is used as an application layer governance token specifically for SecretSwap parameters, developer fund spending, and application related changes. This is in contrast to SCRT, which is the native governance token of the Secret Network protocol layer.

### How is the price of SEFI determined at the beginning?

The price of SEFI will be determined by market forces of demand and supply.

## Support

### I accidentally transferred my tokens to a pair contract, is there anyway I can get them back?

SecretSwap token pair secret contracts are ownerless. We have no special control over the pair secret contracts’ functionality; because of this, any tokens accidentally transferred to the token contract itself are lost forever. Please be careful!

### How can I get support for SecretSwap?

You can use the official [SecretSwap Discord Server](https://discord.gg/mvc9KFvykM) or the [SecretSwap official Telegram chat](https://t.me/secretswapnet) to get support for all SecretSwap related issues.

### Will Keplr support SEFI staking?

SEFI is a SNIP-20 (secret token) and supported by Keplr like all other SNIP-20s.


# Glossary

* **AMM:** Automated Market Maker. An algorithmic system to allow for non-custodial swaps of cryptocurrencies.
* **Bridge:** An app that allows you to lock tokens from a different blockchain and receive the SecretToken equivalent to use inside Secret Network. Currently, Ethereum is supported on mainnet, Binance Smart Chain is supported on testnet and other bridges are in development.
* **Constant Product Formula:** The AMM algorithm used by SecretSwap.
* **LP tokens:** Tokens that a Liquidity Provider receives when providing tokens to a liquidity pool, representing the LP's portion of the liquidity pool.
* **LP:** Liquidity Provider. A member of the SecretSwap community that has provided tokens to the liquidity pools that drive SecretSwap.
* **Liquidity Provider Fees:** The fee incurred for each swap executed in SecretSwap, to reward Liquidity Providers. It is currently 0.3%.
* **Network Fees:** The fees that are required to execute transactions and secret smart contracts on Secret Network. These fees are paid in `SCRT` tokens.
* **Pair:** A secret smart contract that enables trading between two SNIP-20 tokens.
* **Price Impact:** The impact the size of your trade will have on the liquidity pool and therefore on the price you will ultimately pay.
* **SNIP-20:** The Secret Network standard for tokens, based on the Cosmos CW-20 standard.
* **Slippage:** See *Price Impact*.


# Create a New Pair

A pre-stored pair is used in this procedure. Token contract should be instantiated in advance.

The Factory JSON parameter for instantiation is below:

```javascript
{
  "pair_code_id": 1,
  "pair_code_hash": "<HASH>",
  "token_code_id": 2,
  "token_code_hash": "<HASH>",
  "init_hook": { // optional
    "msg": "base64_encoded_json_data",
    "contract_addr": "secret...",
    "callback_code_hash": "<HASH>"
  }
}
```


# Factory

This contract registers the relation between your token and others. It uses the pre-stored pair contract binary and instantiate it. So, you don't have to execute the pair contract additionally.

## Transaction

### Create pair

Instantiate pair from uploaded WASM binary.

```javascript
{
  "pair_code_id": 1,
  "pair_code_hash": "<HASH>",
  "token_code_id": 2,
  "token_code_hash": "<HASH>",
  "init_hook": {
    "msg": "<base64_encoded_json_string>",
    "contract_addr": "secret...",
    "code_hash": "<HASH>"
  }
}
```

## Query

## Config

```javascript
{
  "config": {}
}
```

### Pair

```javascript
{
  "pair": {
    "asset_infos": [
      {
        "token": {
          "contract_addr": "<HumanAddr>",
          "token_code_hash": "<HASH>",
          "viewing_key": "..."
        }
      },
      {
        "native_token": {
          "denom": "uscrt"
        }
      }
    ]
  }
}

```

### Pairs

```javascript
{
  "pairs": {
    "start_after": [
      //optional
      {
        "token": {
          "contract_addr": "<HumanAddr>"
        }
      },
      {
        "native_token": {
          "denom": "uscrt"
        }
      }
    ],
    "limit": 10 //optional, default=10, max=30
  }
}
```


# Query

* Command line:

```bash
  secretcli q compute query <contract-address> '<JSON-formatted message>'
```

* RESTful API:

```
<light-client-address>/wasm/contracts/<contract-address>/store?query=<JSON-formatted message>
```

## How to organize query message

You may check `<contract>/src/msg.rs` of each contract.


# Pair

## Transaction

### Provide liquidity

Send user's assets to SecretSwap contract and provide liquidity.

Assets can be both SNIP20 and native tokens. It can be distinguished with the key under `info.token` or `info.native_token`.&#x20;

```javascript
{
  "provide_liquidity": {
    "assets": [
      {
        "info": {
          "token": {
            "contract_addr": "<HumanAddr>",
            "token_code_hash": "<HASH>",
            "viewing_key": "" // empty
          }
        },
        "amount": "10"
      },
      {
        "info": {
          "native_token": {
            "denom": "uscrt"
          }
        },
        "amount": "10"
      }
    ],
    "slippage_tolerance": 0.1 // optinonal
  }
}
```

{% hint style="info" %}
For SNIP20 assets, you first have to set an allowance for the pair to spend the token.
{% endhint %}

{% hint style="info" %}
For SCRT, you have to send the SCRT amount to the `provide_liquidity` contract call.&#x20;
{% endhint %}

### Swap

Swap between the given two tokens. `offer_asset` is your source asset and `to` is your destination token contract.

```javascript
{
  "swap": {
    "offer_asset": {
      "info": {
        "native_token": {
          "denom": "uluna"
        }
      },
      "amount": "10"
    },
    "expected_return": "13", // optional
    "belief_price": 0.1, // optional
    "max_spread": 0.1, // optional
    "to": "<HumanAddr>" // optional
  }
}
```

```javascript
{
  "swap": {
    "offer_asset": {
      "info": {
        "token": {
          "contract_addr": "<HumanAddr>",
          "token_code_hash": "<HASH>",
          "viewing_key": "" // empty
        }
      },
      "amount": "10"
    },
    "expected_return": "13", // optional
    "belief_price": 0.1, // optional
    "max_spread": 0.1, // optional
    "to": "<HumanAddr>" // optional
  }
}
```

## Query

### Pool

```javascript
{
  "pool": {}
}
```

### Simulation

```javascript
{
  "simulation": {
    "offer_asset": {
      "info": {
        "token": {
          "contract_addr": "<HumanAddr>",
          "token_code_hash": "<HASH>",
          "viewing_key": "" // empty
        }
      },
      "amount": "10"
    }
  }
}
```

### Reverse Simulation

```javascript
{
  "reverse_simulation": {
    "ask_asset": {
      "info": {
        "token": {
          "contract_addr": "<HumanAddr>",
          "token_code_hash": "<HASH>",
          "viewing_key": "" // empty
        }
      },
      "amount": "10"
    }
  }
}
```


# Contract Addresses

## Mainnet

SEFI: `secret15l9cqgz5uezgydrglaak5ahfac69kmx2qpd6xt`\
sSCRT: `secret1k0jntykt7e4g3y88ltc60czgjuqdy4c9e8fzek`

### Factory

* Pair code id: 13
* Factory code id:
* Factory contract address: `secret1fjqlk09wp7yflxx7y433mkeskqdtw3yqerkcgp`

### Pairs

| Pair                   | Contract Address                                | LP Token Contract                               |
| ---------------------- | ----------------------------------------------- | ----------------------------------------------- |
| sSCRT-sAAVE            | `secret1fz6k6sxlnqwga9q67y9wly6q9hcknddn8alrtg` | `secret1k6ypx2hv28yd73c9ethamru48ke9vetqrjzu26` |
| sSCRT-sBAC             | `secret1py6j9h7mfe87h9jud0e6zyk6qyhllz4r89xpe8` | `secret138wwgfj4p7w87dwq8hnjckjhpy6kv76e6ez4me` |
| sSCRT-sBAND            | `secret1mq2f0x9qyr2fwpyuaux3tehgvk8faz9ntazehd` | `secret1n5qe4k8zf09gh8zdrydcc3jqls4ceww8wzr2kv` |
| sSCRT-sBAT             | `secret1fh9f4zquppnzp8wrhvy2pfkwyd4tadt530332a` | `secret1djl87ynczxgsm0xzcpqslcwkpuppp5tc68yywv` |
| sSCRT-sDAI             | `secret1sj65pd9fqgwyj0a9ctl4cecp62y52z5nzpq60r` | `secret17w0wjempgtt8ngn59y7cwlae02kve5jzar4xmw` |
| sSCRT-sDPI             | `secret1ldac7f6372k5nte03u9ev9c0ls7le5sp09gz8d` | `secret1jmv4h3f8rtlxsfaven4kstdaq55pr8rwty8ss5` |
| sSCRT-sENJ             | `secret14mzz277cnt8l4efnskzj4s3c04lx6njd52nfnn` | `secret1uf6kk3a6damq93w6gnjj4xyr4xdpj86kzpvrwh` |
| sSCRT-sETH             | `secret14zv2fdsfwqzxqt7s2ushp4c4jr56ysyld5zcdf` | `secret17gja535zp09t9mlzzxndqqg4gzvhg0vsklhd54` |
| sSCRT-sFATS            | `secret1fspv4fzc90g72r22djhhtf2jrxvcte3dsvp2dk` | `secret1kg8pd6ag4cx72302uflm5n8nau2m6k7q9efck3` |
| sSCRT-sLINK            | `secret1x8244a7l2fr642axef0sl5z3jw2pn75rp36hxs` | `secret1rldr66767a4gz3adkq2vgndwgnxlfqqae4fgen` |
| sSCRT-sMANA            | `secret1u9zfyh7d4mgf44f3y8fhz4e70dhjzd5e5df8hp` | `secret1gewshds6yhyry842vnxl9q6krezaatep6rxyt2` |
| sSCRT-sMKR             | `secret15kkj9gyjurvxqcv63ly96lmc7vpcsllt65f7dv` | `secret185jen8q6ss5xnja33vj7pvqz49m8frkdekvzpy` |
| sSCRT-sOCEAN           | `secret13ns5mzms67jttq5cnv76j5lgtd0xf69sv4sdpq` | `secret1kduh3vlszmg3snq36k6s8l4v8s26z47m3q9haa` |
| sSCRT-sREN             | `secret1lamq00jwpms5hzel22rjgmd0v2wn8fep6rzhmh` | `secret1m76hs58wqxasd7f6au3c7gx8at5xu2ez9kf44l` |
| sSCRT-sRSR             | `secret1g97kxc857asparfgdudzkzyq5akd74xmup52uj` | `secret102gfpp4hgvytxlxsz8hnjy7uqndmhau3jkzps8` |
| sSCRT-sRUNE            | `secret1j8vs8v729vregluuzr5n4zr77ztaleqtqcw026` | `secret1kg24nc3v4wm4vzufup8fvmvffxtm8425uwfvqd` |
| sSCRT-SCRT             | `secret1rf4uqg4d2elmvp535ayhxwnrpdykmxan0nrwtg` | `secret1xhvv5uj5fa9yxcuuk4awqw568ve7g05v7fa0vd` |
| sSCRT-SEFI             | `secret1rgky3ns9ua09rt059049yl0zqf3xjqxne7ezhp` | `secret1709qy2smh0r7jjac0qxfgjsqn7zpvgthsdz025` |
| sSCRT-sSIENNA          | `secret1rxrg8mp4qm5703ccz26lgh8hx7gpnkujrn6qcr` | `secret1l3azwns4uqglmu42hnjgfrlqc7hhqulq05cheg` |
| sSCRT-sSNX             | `secret12um5gxf2vdm6vy4q36jcxlg9mc60y6wgewwxx9` | `secret1tp25zaypu53g8av4qcr3gdrzujerxze38hm090` |
| sSCRT-sSUSHI           | `secret1m79q9hnz44xtndmlrd9p57tt6z3kjeecp7957u` | `secret15atu5s5aqhkezg44d035nufq80ltwx968vey00` |
| sSCRT-sTORN            | `secret14v3p9xq0353fvwrhkjyv4c96vrujjvzwmqyq0k` | `secret1853yqdhf2yjnaf2xerhmgsl5dt50t4grh63y3r` |
| sSCRT-sTUSD            | `secret103e3kt05rt89fayp9y7w44wj4x3k5zumy6cdyc` | `secret1hsd23gm7ces9rf24e0mryhywlcl4l5903pwrts` |
| sSCRT-sUNI             | `secret1pmt7ncuhau2g7h9snygx2tlkzqnks3uz5edgyc` | `secret1m8msletvevuj2vsl8rcvqq9esflxmmnd2lf7yd` |
| sSCRT-sUNILP-WSCRT-ETH | `secret1v82egg9xtycsaz0h3nqay0saq0dv296z4swjku` | `secret1t6vfa5wnzqgvlk7u7u6fz9dwltrn44kzr22fh6` |
| sSCRT-sUSDC            | `secret1uakhxh3qwe2k8khww709cpxlm8kmwapufmfrr0` | `secret1azgy8zx6duz2s4yhxqvghsd25gnun6hefy7ff4` |
| sSCRT-sUSDT            | `secret1gyct75dc2pf20vtj3l86k2jxg79mffyh9ljve3` | `secret1cgd6gcc4uyrxmzsmk4tpeta8auzcgwk4n5ngrx` |
| sSCRT-sWBTC            | `secret10x0k62eaal4q3t9c200qvmgftahxjqvdawn69c` | `secret1xxvqanj85m7dppplku5782cn9hl8askqd329sv` |
| sSCRT-sYFI             | `secret1zra95h6nf4kc49x59x66t7crxxl79hr5nph882` | `secret1he6rzcet6jcwryu544a5zkkadxee4sk0umu703` |

### Crosschain Contract Addresses

SEFI (BSC): `0xcd95350c69F229E72e57A44e8C05C436E65E4bEb`\
SEFI (ETH): `0x773258b03c730F84aF10dFcB1BfAa7487558B8Ac`\
WSCRT (ETH): `0x2B89bF8ba858cd2FCee1faDa378D5cd6936968Be`


