In this section, we'll explore the IERC20
interface, a standard interface for interacting with ERC-20 tokens and the IWETH
interface, a standard interface for interacting with wrapped Ether (WETH). Understanding these interfaces is crucial as it is used in the Uniswap V3 Swap contract to handle token transfers and approvals.
You can find a "Solidity ERC20 Token Course" for beginners in LearnEth to understand the ERC20 token standard in more detail.
On line 85, we define the IERC20
interface. This interface defines a standard set of functions that ERC-20 tokens must implement. Let's examine the key functions within this interface:
On line 86, we define the totalSupply
function. This function returns the total supply of the token.
On line 88, we define the balanceOf
function. This function returns the balance of the specified address.
On line 90, we define the transfer
function. This function transfers tokens from the sender to the specified recipient.
On line 92, we define the allowance
function. This function returns the amount of tokens that the spender is allowed to spend on behalf of the owner.
On line 94, we define the approve
function. When called, this function approves a spender to spend the specified amount of tokens on behalf of the sender.
On line 96, we define the transferFrom
function. This function transfers tokens from the specified sender to the recipient. The function can only be called by the spender if the spender is allowed to spend the specified amount of tokens on behalf of the sender.
On lines 102-103, we define the Transfer
and Approval
events. These events are emitted when the transfer
and approve
functions are called, respectively.
On line 106, we define the IWETH
interface. This interface extends the IERC20
interface and defines two additional functions:
On line 107, we define the deposit
function. This function deposits ETH into the contract and returns the equivalent amount of WETH. This function is used to wrap ETH into WETH.
We need to wrap ETH into WETH because the Uniswap V3 Swap contract only supports ERC-20 tokens.
On line 109, we define the withdraw
function. This function withdraws the specified amount of WETH from the contract and returns the equivalent amount of ETH. This function is used to unwrap WETH into ETH.
In this tutorial, we explored the Uniswap V3 Swap contract. To get a full sense of how Uniswap works, try making some swaps on the Uniswap DApp and go to the Uniswap docs.