Lattice Exchange: the next evolution of DEX swaps

Fireflight
3 min readSep 14, 2022

This article covers some of the current flaws & limitations in ERC20 swaps and how Lattice Exchange solves these. Don’t miss the Hypergraph Hour on September 21st where an updated whitepaper will be revealed. Lattice will be so much more than just a DEX!

Let’s first go through the limitations & inefficiencies in EVM DEXes like security risks, fees, front running bots,..

Spend approval:

Why do you first need to approve your token before executing a swap on a DEX? This is due to a limitation in ERC20 smart contracts. It’s not possible to call a function in a DEX smart contract while also sending funds to that DEX smart contract in a single transaction.

To overcome this problem, the DEX smart contract needs “spend” approval to the token in your wallet, so the contract can call the “transferFrom()” function of your ERC20 token and send the funds to the smart contract on your behalf, where it performs the swap and credits you the amount of the swapped token.

This is not only inefficient & costly but also opens up a security risk, as you are giving the smart contract permission to spend funds on your behalf. If you give approval to a malicious smart contract, they can drain funds in your wallet (a hardware wallet will not save you here).

Be careful with these approvals and frequently remove the allowances of DAPPS you aren’t using anymore. Most EVM block explorers have a “Token Approval” page, where you can check the approvals you gave for DAPPS and revoke them. Example: https://etherscan.io/tokenapprovalchecker

Fees & slippage

Each interaction on ethereum (or any EVM chain) has a cost. A traditional DEX swap has 2 smart contract calls:

  1. Token approval: this is a fairly cheap transaction
  2. Smart contract swap: this is a complex smart contract and can become very expensive

The higher you set your transaction fee, the faster your transaction will get executed. A lot of bots exploit this and are front-running your swaps.

They detect active swap transactions that have a fairly low fee & high slippage, buy a large amount of your target token to increase that token price (so you buy higher) and set a high fee so their transaction is processed first.

After your swap is processed (which you now have bought at a higher price due to the frontrunning bot), they sell and take profits from the short-term price increase of that token. Not much can be done about this due to the way smart contracts & gas fees work.

Lattice Exchange

So how is Lattice Exchange solving these issues? By using state channels on the hypergraph instead of smart contracts to perform the swaps. State channels are more flexible since they are built on JVM (java virtual machine) which is one of the most popular program runtimes out there, so they don’t have the limitations we see on EVM.

Lattice can build a global cross-chain liquidity pool based on the L0 standard, which is the token standard inside the hypergraph, and perform the swaps using state channels. This is very scalable, fast and feeless for the end users, so there are no opportunities here for front running bots.

Because the hypergraph is focused on interoperability, Lattice will be able to perform cross-chain swaps and execute ERC20 token swaps at a much cheaper fee and without granting token spend approvals. You would send your ERC20 token to the state channel and then the state channel takes care of the swap. This is a massive cost saver, since you now only need to pay the ERC20 transfer fee and that’s it (saving about 80% of the gas costs compared to uniswap)!

The crypto space moves at a fast pace and we see lots of innovations on swap protocols happening. Being built on the feeless environment of the hypergraph and having access to a global liquidity pool that is interoperable with all networks will certainly have a competitive advantage though.. And I haven’t even talked about any of the other features that Lattice will provide (let’s save that for another day).

--

--