Wyvern Protocol in Opensea NFT Marketplace

Victor Yeo
2 min readMar 6, 2022

--

Today we look at Wyvern protocol, and how it is used in NFT marketplace. Wyvern protocol is an decentralized exchange protocol. Opensea is an example of NFT marketplace that utilises Wyvern protocol.

To be specific, we are looking at Wyvern v3 which supersedes Wyvern v2. We will also touch on Wyvern v2 when it is necessary to do so. The http link to Wyvern git repo code is added for easy reference.

NFT marketplace featuring Wyvern protocol

Referring to the diagram above, seller and buyer can create sell order and buy order on Opensea. The orders are stored on a centralized database. When there is a match of buy order and sell order, the orders are sent to smart contracts for on chain settlement. The set of smart contracts are implemented according to Wyvern protocol.

In Wyvern protocol, the smart contract that implements the trade is Exchange smart contract. It verifies the signature is indeed signed by the order maker.

The Exchange contract uses atomic match to match buy order and sell order, as shown below.

atomic matching

The Order structure is in ExchangeCore.sol. The first order is probably order made by maker, the second order is order made by counterparty.

To illustrate the point, when buyer pays ether to buy NFT from seller, the following scenario (ERC20-NFT trade) occurs.

  • Order offers to call the transfer (or transferFrom) function on a particular NFT contract with a particular NFT identifier, asserts that the counterparty's (the buyer) call is a transfer call to the desired ERC20 contract, and asserts the desired amount of tokens. Basically it means buyer sends WETH (an ERC20 token) to the seller , in exchange for NFT token. This is on chain settlement.

Every user has a Proxy smart contract. Each item which is traded on Opensea is owned by a Proxy smart contract of a user. This Proxy smart contract is controlled by the owner or the exchange smart contract. In this way, users do not have to approve each trade on the Opensea, so that savings of gas fee can be achieved.

The Proxy contract registers AuthenticatedProxy contract. AuthenticatedProxy is used in Exchange contract to execute order on matching order, which is called from atomic matching.

In AuthenticatedProxy, the proxy function executes the call from proxy contact using call or delegate call , depending on HowToCall enum.

In Wyvern v2, there is DAO smart contract, it decides which smart contract can control the proxy smart contract of each user. But DAO smart contract is no longer in Wyvern v3 git repo.

--

--