MetalSwap Blog

MetalSwap <> Chainlink Paper 3 - Anti MEV Strategy

Written by MetalSwap | Aug 5, 2024 4:08:00 PM



In this third part of our three-articles series, we'll discover how Chainlink’s technology has come in handy as a problem solver from a DAO perspective - this time we're going to explore how MEVs activity can be avoided. MetalSwap’s DAO, by its side, leveraged Chainlink's different services to overcome those challenges faced by its governance. If you missed the part 1 - about governance token liquidity enhancement, or the part 2 - about bridges and DAO costs easing, here are the links ;)

To address the challenges that the DeFi environment brings with it over time, MetalSwap implemented continuously better technical solutions, as well as integrating external services like Chainlink’s to enable conditional execution of smart contract functions and particular features. 

As a DeFi building protocol, together with Chainlink's technologies, MetalSwap is enhancing its DAO operations, its DEX liquidity, and mitigating risks associated with liquidations and MEV. 

Those challenges are not only MetalSwap’s topics: they represent the common hurdles that any DAO or DeFi builder encounters, while innovating within the ecosystem, making this exploration relevant and insightful for all participants in the DeFi space.

Challenge #3 - Liquidations and MEV

The term MEV stands for Miner Extractable Value, lately referred to as Maximum Extractable Value or Maximal Extractable Value. It refers to the profit that a miner (or later, a validator) can make due to its ability to arbitrarily include, reorder or exclude transactions within the blocks it produces on a smart contract-enabled blockchain network.

After Ethereum's Mege, the mechanism for activating MEVs changed and most of the DAOs experienced new types of attack on consensus or dApp mechanisms through this exploit came to its latest evolution.

For this reason, the topic of EVMs has been increasingly and extensively discussed - explored by various DAOs and industry players, including research by famous players like Coinmarketcap and Binance Academy.

Some websites have sprung up precisely to index the activities of the most famous EVMs, with Live data to reveal crypto earning strategies of bots and expose hidden risks of DeFi on Ethereum and BSC, for example eigenphi.io

Many researchers are paying attention to MEV activities and spread news about the topic:


Blockworks Thread

The subject of EVMs has also ended up in American courts, such is the extent of some attacks.

During Naple’s Spaghetti ETH live event in march 2023, MetalSwap’s contributors conducted a bootcamp where showed how the MEV has become a significant concern for many DAOs, and how it affects MetalSwap’s dApp, managing to infiltrate the liquidation mechanism of a position. 

This is clearly a challenge raised up for a high number of different dApps,
In the context of liquidations, the original design mechanism was the following: MetalSwap incentivised the creation and owning of “decentralized liquidators” that are going to compete between each other to close the positions as soon as possible.

Although the system worked as intended initially, at some point between enough profitability and cheap blockchain fees, EVMs started to exploit it.
Let’s see briefly how:


The deep-dive about the Liquidation and MEV topic is readable on MetalSwap’s official blog, follows a brief extract:

“The presence of the MEV adds some steps to the liquidation process seen above. When the original liquidator calls the profitable transaction with the liquidateSwap OR executeSwap method, the MEV sees it in the Mempool before it goes on the blockchain. The transaction is then copied from there and pasted from another account with higher transaction fees to anticipate the original transaction. The original transaction fails because the MEV transaction arrives just before the blockchain, and the MEV takes the profit.

Although this does not yet pose a problem from the user's point of view, it becomes unprofitable for the liquidator to monitor the changes in the Active Swap and spread the original settlement transaction. This scenario could pose a serious problem for the management of MetalSwap’s Active Swaps. The MEV excludes the incentive for liquidators to work for MetalSwap. Without the incentive, the liquidation is not able to facilitate decentralisation.”

One potential solution to this problem could be to hash the Liquidator's address and SwapID using the keccak256 hashing algorithm, and then call the liquidateSwap or executeSwap methods on the Smart Contract. In this way, only the liquidation transaction that comes with that hash is accepted. This approach makes it very difficult for the MEV to recreate the transaction using the copy/paste strategy we discussed above. As a result, the Position is correctly closed, and the Liquidator can profitably execute their role.

While this solution may properly work, the MetalSwap team wondered if it was possible to make it so that the liquidation system could be simultaneously managed in a different - or better cheaper way, using some other kind of automation. In this way perhaps both solutions could coexist, for a more efficient system that doesn’t rely on only one way to trigger liquidations, or for the possibility to have the choice of the implementation of the solution that fits better with a particular blockchain environment.

Now, let’s explore how MetalSwap achieved this using a brand-new DeFi tool:

Solution #3 - Chainlink Automation Service avoiding MEVs

Chainlink Automation enables conditional execution of your smart contracts functions through a hyper-reliable and decentralized automation platform that uses the same external network of node operators that secures billions in value. Building on Chainlink Automation will help you get to market faster so you don't have to deal with the setup cost, ongoing maintenance, and risks associated with a centralized automation stack.”


https://docs.chain.link/chainlink-automation/introduction

A new possibility may come integrating the Chainlink Automation services while leaving the execution method public - but removing the settlement fee.

The settlement fee will be lowered and used instead to replenish the Chainlink automation smart contract by converting swap assets to LINK tokens.

So, let’s introduce a middleware into the flow:

It calls the checkUpkeep function on Active Swaps until it returns true, at which point it calls the performUpkeep() function, which in turn calls the liquidateSwap OR executeSwap method on the Smart Contract. The transaction then goes directly from the middleware to the mempool.

This transaction does not assign settlement fees to a liquidator, so a MEV will not pick it up. With the Chainlink Automation's transaction accepted, the Active Swap is now closed, and the platform management works as intended.
An interesting aspect of this flow is that the settlement fees are converted into LINK tokens and used to refinance the Chainlink Automation liquidation service.

Integrating the Chainlink Automation services while leaving the execution method public, the settlement fee will be lowered and used instead to replenish the Chainlink automation smart contract by converting swap assets to LINK tokens.

Chainlink Automation presents a solution to MetalSwap’s dApp issue. It enables conditional execution of smart contract functions through a hyper-reliable and decentralized automation platform. This means that MetalSwap’s liquidations can be Automated in a way that is secure, reliable, and resistant to MEV.

This is how MetalSwap solved three different common DAO challenges thanks to ChainLink’s tools, upgrading the team's knowledge about the ever-evolving world of DeFi and cooking new tools that may become useful to the whole ecosystem.

Delving into Chainlink’s services like CCIP and Automation is a giant step towards understanding and shaping the transformative journey of DeFi. Staying informed and engaged is essential for anyone looking to be part of this exciting new chapter.
Embrace the change, explore the ways, and be part of the unfolding future.



- The DeFi Foundation

 

✎ What is MetalSwap?

MetalSwap is a decentralized platform that allows Hedging Contract on financial markets with the aim of providing coverage to those who work with Digital Asset and an investment opportunity for those who contribute to increase the shared liquidity of the project. Allowing the protection for an increasing number of operators.

With Hedging Contract we enable hedge swap transactions through the use of Smart Contracts, AMM style.

It's great to Hedge the Risk of Price volatility with MetalSwap dApp !