2.30 Important Protocols
Last updated
Last updated
There are many protocols currently living in the EVM. The protocols presented here are few of the most important protocols that an auditor must be familiar with.
WETH
Protocols often work with one or many ERC20
tokens, be it either their own or of other protocols. They also work with the Ether that is sent to their smart contracts via msg.value
. Instead of having two separate sets of logic and two separate sets of control flow within their contracts (one to deal with Ether, the other to deal with ERC20
tokens), it would be very convenient if we could have a single logic, a single control flow to deal with both Ether and ERC20
tokens.
The WETH
concept provides this capability: it allows smart contracts to convert Ether that's been sent to their contracts to its ERC20
equivalent which is known as WETH. This conversion is a process called wrapping, while the other direction of converting the ERC20
equivalent of WETH back to Ether is called unwrapping.
This is made possible by sending the Ether to a WETH
contract which converts it into its ERC20
equivalent at a ratio. There are multiple versions of WETH contracts the most popular right now, is the which holds anywhere between 6.5 to 7 million Ether as of this point.
There are also some improvements being done: there is WETH10
that is more Gas efficient than the version 9. This version also supports flash loans as per the EIP3156
standard. So this WETH concept is something that we often come across in smart contact applications.
Uniswap is an automated market making protocol on Ethereum. That's powered by what is known as a constant product formula:
where and are token balances of two different tokens and is their constant product.
Uniswap allows liquidity providers to create pools of token pairs, and whenever anyone provides liquidity to either of the two tokens of the token pair, new tokens known as LP tokens liquidity provided tokens are minted and sent back to the liquidity provider. This represents their share of the liquidity in the tokens.
Uniswap is the most popular protocol on Ethereum currently for swapping between tokens belonging to a token pair, and a big part of that is because of the simplicity of the constant product formula as determined by the curve .
Uniswap also provides support for on-chain Oracles. A price Oracle is a tool that allows smart contracts to determine the price information about a given asset on the blockchain. In the case of Uniswap V2, every token pair measures the price of further tokens at the beginning of each block.
So, in effect this is measuring the price at the end of the previous block that is maintained within a cumulative price variable that's weighted by the amount of time this price has existed for the token pair. This particular variable can be used by different contracts on the Ethereum blockchain to track what is known as "time weighted average prices" (TWAPs) across any particular time interval.
Uniswap recently introduced their version 3 of the protocol, which is considered as a big improvement over their version 2. This improvement is specifically around the concept of concentrated liquidity. What this means is it allows liquidity providers to provide liquidity for the token pair, across custom price ranges instead of across the entire constant product curve.
This brings about a big improvement to their capital efficiency. This version of the protocol also introduces flexible fees across different values as shown here.
Finally, for Oracle support, version V3 introduces advanced TWAP support where the cumulative sum instead of being maintained and trapped in one variable is now done so in an array. This allows smart contracts to query the TWAP on demand for any period within the last 9 days.
Chainlink is perhaps the most widely used Oracle and source of price feeds for smart contracts on Ethereum. Price data and even other kinds of data are taken from multiple off-chain data providers and they are put on-chain to create these feeds by the decentralized Oracles on the chainlink network.
Chainlink has mechanisms for aggregating this data across the various data providers and itself provides an extensive set of APIs for working with these Oracles and price feeds.