GC Deep Dive — SpicySwap

Genius Contracts
6 min readJun 2, 2021

Welcome to the newest AMM decentralized exchange, built on Tezos

Hello friends, we’re exited to fully unveil our upcoming Tezos-native AMM DEX, named SpicySwap. Our new automated DEX is inspired by the Uniswap V2 general framework, but the base contract has been rewritten from the ground up to be compatible with Tezos’ smart contract language Michelson. The basic features of this DEX will be token-token swaps between arbitrary FA2 tokens, and the ability to provide liquidity in arbitrary swap pools. We’ve released a SpicySwap playground for initial testing of the base swap contracts (requires Florencenet wallet). Let’s get into the features.

Features

FA2 Token-Token Swaps

As the FA2 standard is becoming widely accepted in the Tezos DeFi ecosystem, we’ve decided to adopt it as our only supported token standard. We’ve also chosen to avoid supporting native Tezos (XTZ) due to the overhead that comes with delegation. Making our base pool contract simpler and easier to audit will give liquidity providers the protection they need, while still allowing new and complex DeFi interactions to take place. The aim of any AMM DEX should be to protect liquidity providers at all costs.

As with token-token DEXs on Ethereum, SpicySwap is going to need general “anchor tokens” that will generally be the easiest to trade against. A sample list could include: a wrapped XTZ token, a stable-coin linked to real world currency, or other crypto assets such as Bitcoin or ETH (in wrapped form). We’re excited to have community discourse on preferred anchor tokens.

Granada Gas Savings

After double-digit tests and refactor loops, I finally got the contract to a place where I thought the gas was reasonable. A few more gas optimizations are being held secret for now, and will be implemented before release to decrease gas costs even more.

Furthermore, the recently released “Granada” protocol proposal will be a huge win for SpicySwap.

The gas cost of serialization and deserialization of Micheline (a JSON representation of Michelson) is divided by 10 thanks to an optimization of the data-encoding library.

After all of the testing, it was pretty obvious that the most expensive action in our contract was the (de)serialization of Micheline. Taking that down by a factor of ten will do wonders for SpicySwap’s gas costs. We will be looking to upgrade our testnet to Granada and start analyzing gas costs very soon.

Flash Swaps/Loans

Using the Uniswap V2 architecture as inspiration, SpicySwap will allow for Flash Swaps and Flash Loans. This is enabled by implementing their optimistic transfer architecture; you can read more about that in the UniswapV2 Whitepaper.

Flash Swaps allow a user to include an arbitrary contract call that is executed in the middle of their swap. As long as the money is paid back and the invariant (plus fees) is preserved when checking at the end of the swap, the transaction will go through. This can remove collateral barriers across the DeFi ecosystem, and open up complex DeFi interactions at a much larger scale.

As flash swaps and loans are new to Tezos, this will take a community effort to test dApps and make sure there are no side effects or vulnerabilities exposed when high amounts of liquidity are borrowed and used across protocols.

Price Oracle

Initially I was going to push this idea down the line, but the gas savings in Granada will make this a reasonable possibility at release. We can use each pair as a decentralized price oracle by accumulating a time-weighted average price. This price will be manipulation-resistant and will open up even more complex DeFi interactions, as contracts would be able to easily call and receive a time-weighted price that they can trust.

Audit

This is a serious project, and will require serious testing. We plan to undergo and publish a full audit report on our contracts, UI, and UX. Any findings shall be fixed before release, and once audited we will start open-sourcing our contracts over time.

Fees

This is an especially important topic in the context of AMM DEXs, because fees are the cornerstone incentive for liquidity providers. Liquidity providers will earn a flat 0.2% fee on every trade.

Furthermore, we will be introducing a new protocol token for SpicySwap called Spice ($SPI). This token will be used to farm fees from any arbitrary pair. The protocol-level fee will be 1/2 of the liquidity providers fee, resulting in an overall fee structure of 0.2% to LP, 0.1% to $SPI Farmers for a total of 0.3%. These fee rates will be governed by $sDAO.

$SPI Farming

In this section we are using “wXTZ” as a placeholder anchor token

Users will have the ability to stake $SPI/wXTZ LP tokens in any token-token pair on SpicySwap to earn protocol fees. Every pair has a built-in protocol fee farm. After staking, your share of rewards will grow as the protocol fees in the pool grow over time. This is the main use-case for the $SPI token and the reason why it exists. Additionally, there are a couple positive side-effects from farming $SPI on SpicySwap.

First, this opens up the door to both simple and complex yield farming strategies on SpicySwap. One could choose to leave their $SPI in a popular pool with stable traffic for guaranteed rewards, or one could choose to chase volume and stake $SPI in pools that were just released and have high initial traffic. These strategies can mature into concrete formulas that then could be written into an automated “fund manager” smart contract.

Second, farming $SPI will be a great way to avoid impermanent loss while still farming fees from pools. Since most $SPI/wXTZ LP tokens will be locked up in farms, the $SPI/wXTZ pool will likely be one of the most stable pools on SpicySwap. Having high stability is a great way to decrease your impermanent loss as a liquidity provider. So, one can now accrue fees from volatile assets without being exposed to the high level of impermanent loss that comes with providing liquidity.

$SPI Tokenomics

  • Total Supply (Fixed): 100,000,000 $SPI
  • Genius Contracts Fee: 2,000,000 $SPI (2%)
  • $sDAO Treasury: 18,000,000 $SPI (18%)
  • Rolling Airdrops: 20,000,000 $SPI (20%)
  • Pre-sale: 40,000,000 $SPI (40%)
  • $sDAO/[Anchor] Farm: 20,000,000 $SPI (20%)

Rolling Airdrops

This will be a series of airdrops executed at random times until our full SpicySwap release. Every 2–3 weeks an unannounced snapshot will be taken and a 5,000,000 $SPI airdrop will go out. With each snapshot, the amount of $sDAO required will go up by 5000. The same snapshot used for Pre-sale Phase 1 will also be used for the first airdrop. This means the next airdrop will require 15k $sDAO.

FYI: Snapshots count $sDAO from anywhere where they are held: your $sDAO wallet, your $sDAO staked in Quipi LP, your $sDAO staked in farms, and your unclaimed $sDAO rewards are all automatically added together for the final count.

Pre-sale

The pre-sale will happen in three phases, and is tentatively scheduled to start next Monday, June 7th.

Phase 1, 10k+ $sDAO holders only: 100 $SPI for 1 XTZ. 20M $SPI cap

Phase 2, 15k+ $sDAO holders only: 100 $SPI for 3XTZ. 10M $SPI cap

Phase 3, Public Sale: 100 $SPI for 5 XTZ. 10M $SPI cap

If there is leftover $SPI in a phase, it will roll over to the next phase. If there is leftover $SPI after the pre-sale closes, it will be sent to the $sDAO Treasury.

The snapshot for Phase 1 has already been taken this morning. The snapshot for Phase 2 will happen the day before the pre-sale release. Each $sDAO phase will last 1 day, and Phase 3 will last until Friday or until there is no more $SPI left. I’ll be putting an anti-batch measure in the contract as well.

What will the pre-sale fund?

This project will take time, and have many costs associated with it. I’m not the biggest fan of pre-sales, but in this situation it is the perfect tool to bootstrap funding and push the project forward quickly. Below is a non-exhaustive list of future costs associated with building SpicySwap:

Swap contract work, gas optimization work, router contract, audits, formal verification, UI development, UX development, advanced documentation, SDK, community management, cloud infrastructure, highly available cloud tezos node, etc. Even with this amount of work, I think the reasonable timeline will be in the Genius Contracts’ Fall Release. Thanks for reading and I hope you are as excited as I am.

Teaser: Expect a FounderJabba article on the SalsaDAO overall roadmap soon!

--

--