Farms Swap Exchange Overview

Farms Swap is the World’s First exchange protocol build on Binance Smart Chain that allows users to trustlessly swap BEP-20 tokens. Rather using the traditional order book model, FARMS SWAP pools tokens into smart contracts and users trade against these liquidity pools. Anyone can swap tokens, add tokens to a pool to earn fees, or list a token on Farms Swap


When viewing FarmsSwap’s website, it is important to keep in mind that it is much more than just the interface. Farms Swap standardizes how BEP20s are exchanged with a set of smart contracts. Anyone can build an interface that connects to these contracts and instantly be able to start exchanging with everyone else that is using FarmsSwap.

There are two different types of contracts that make up FarmsSwap. The first is known as an Exchange contract. Exchange contracts hold a pool of a specific token and BNB that users can swap against. The second kind of contract is the Factory contract which is in charge of creating new Exchange contracts and registering the BEP20 token address to its Exchange contract address.

There are no listing fees to add a token on FarmsSwap, instead anyone can call a function on the Factory contract to register a new token. When BUSD was added to Farmsswap. Someone first called the createExchange function in the Factory contract with BUSD’s contract address. Then the Factory contract checks it’s registry to see if an Exchange contract has been created for that token address. If no Exchange address is listed, the factory contract deploys an Exchange contract and records the Exchange address in its registry.

Liquidity Pools

FarmsSwap is unique in that it doesn’t use an order book to derive the price of an asset. In a centralized exchange, such as Coinbase Pro, the price of an asset listed on the exchange is determined by where the highest price someone is willing to pay and the lowest price someone is willing to sell meet. that the highest bid price for BTC on Coinbase Pro at that point was $48301.36 and the lowest asking price was $48301.37.

Instead Farmsswap uses the Exchange contracts to pool both BNB and a specific BEP20. When trading BNB for a token, BNB is sent to the contract’s pool and the token is given back to the user. As a result, the user doesn’t need to wait for a counterparty in order to exchange or worry about specifying a price. Since anyone can list a token and users don’t need to worry about matching with someone else, it is very easy to avoid any bootstrapping issue when first launching a token.

The amount that is returned from swapping is based on an automated market maker formula. The graph below helps illustrate how the formula works. Essentially, the amount that is returned to you is based on the ratio of BNB to token in the pool. No matter the size of a swap, the user is guaranteed to have their trade execute because the more of an asset that you add to one side of the pool, the further along the cake token it pushes you for the other asset. Meaning the larger the order relative to the pool, the worst rate you will receive as the ratio moves along the curve.

But if users are only just sending cryptocurrency, how does the ratio of BNB to token remain priced correctly relative to external markets? The answer is the pools maintain a ratio relative to the price of the rest of the market through people arbitraging the pool. Imagine that the BUSD:BNB pool is expressed in terms of a scale and when the scale is balanced the pool is appropriately priced relative to the market price of a centralized exchange. Let’s say that the current price for BNB in USD on a centralized exchange is $150 and the ratio in the Farmsswap BUSD:BNB pool returns 150 BUSD for 1 BNB. As a result, our scale is balanced because the pool matches the current market price on the centralized exchange.

Now let’s assume that there is a movement in the market that pushes the price of BNB to $100 on the centralized exchange. Due to the price movement, we can now see that our scale is off balance relative to the market price because people can now swap 1 BNB for 150 BUSD on Farmsswap when the market price on a centralized exchange is $100 for 1 BNB.

In response, someone can now put BNB into the pool, draw out BUSD, then sell the BUSD back for BNB on the centralized exchange for profit, and then repeat. They can do this until the pool has balanced out and reflects the current market price on a different exchange.

As a result, third party arbitrages play a large role in maintaining the correct ratio of token to BNB in Farmsswap pools.

Swapping BEP20 ⇄ BEP20

When interacting with a single Exchange contract, a user is able to swap between BNB and a specific BEP20 token. However, Farmsswap does allow users to directly swap an BEP20 to another BEP20 in a single transaction. The user has BUSD and would like to receive MKR. As a result, the user calls the tokenToTokenSwap function which adds BUSD to the BUSD pool and kicks BNB to the MKR pool and returns MKR to the address that initially sent the transaction.

Liquidity Providers

When an Exchange contract is first created for a token, both the token and BNB pools are empty. The first person that deposits into the contract is the one that determines the ratio between the token and BNB. If they deposit a ratio that is different from what the current market rate is, then an arbitrage opportunity is available. When liquidity providers are adding to an established pool, they should add a proportional amount of token and BNB to the pool. If they don’t, the liquidity they added is at risk of being arbitraged as well.

In addition, larger liquidity pools are beneficial to users because they allow for larger swaps to happen without skewing the token to BNB ratio too far along the curve. Farmsswap incentivises users to add liquidity to pools by rewarding liquidity providers with fees that are collected by the protocol. A 0.3% fee is taken for swapping between BNB and a token and roughly 0.6% is token for token to tokens swaps.

Lastly, special BEP20 tokens known as liquidity tokens are minted to the provider’s address in proportion to how much liquidity they contributed to the pool. The tokens are burned when the user wants to receive the liquidity they contributed plus the fees that we accumulated while their liquidity was locked.