Wyvern Protocol in Opensea NFT Marketplace
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.
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.
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.
What is Project Wyvern Protocol?
as far as I know OpenSea uses Project Wyvern Exchange for bidding, offering, buying and selling. But I can’t understand how it is works. Does anyone knows what is it? If anybody can explain it in very basic level (I don’t need to so much detailed), I’ll be appreciate!
asked Oct 5, 2021 at 18:02
Fatih Furkan Fatih Furkan
945 4 4 silver badges 18 18 bronze badges
1 Answer 1
Their documentation is at their website https://wyvernprotocol.com/.
In order to understand the fundamentals of Wyvern Protocol you’ll need a deep understanding of blockchain and smart contracts. If you have smart contract development experience then you’ll gain the best understanding by looking at their tests in their github repo.
The basics of the protocol are straightforward, two users agree to a trade. The trade is comprised of User A offering digital assets and User B offering digital assets.
Both Users agree to the exact same conditions for the trade and the wyvern protocol makes it happen.
An example would be: User A has two ERC1155 tokens they want to trade to User B for 1.5 wEth. User B has 1.5 wEth they want to trade for two ERC1155 tokens.
The trade itself agreement is all digitally managed on the blockchain using abi
Powering decentralized crypto commerce
Trade any kind of digital asset — from rare virtual kittens to ENS names, land rights, or even smart contracts themselves.
Trade digital assets on an open protocol
Wyvern Protocol powers the peer-to-peer exchange of digital assets.

Exchange anything
Trade any kind of nonfungible asset — from rare virtual kittens to ENS names, land rights, or even smart contracts.

Exchange anywhere
Wyvern can be deployed on any EVM-based blockchain, allowing developers to power their asset exchange.

Fully open-source
The Wyvern Protocol codebase is open source, permissively licensed, and third-party audited.
Automate your crypto-commerce
Pick whichever method of sale you prefer: fixed price, Dutch auction, or something more exotic. Interface with the Exchange through a website, a mobile application, or a custom script.
Auction any kind of item
Buy & sell in any configuration
Trade mixed set of assets

Plug into a growing liquidity pool for the decentralized web
With more marketplaces leveraging the protocol and more orders created everyday, the Wyvern ecosystem is growing rapidly. Time to plug your app in.
Leverage existing orderooks
. or deploy your own
Join others & start building
Trusted by leading marketplaces

Wyvern is an incredibly generic protocol, which makes it flexible enough to support a diverse set of trading functionality — from bartering, bundle sales, to auctions.
Wyvern on the OpenSea


A wyvern is a mythical two-legged dragon with a barbed tail. It is also the name of the protocol OpenSea uses to facilitate the decentralized exchange of NFTs. This article will give you an overview of all the steps buyers and sellers go through to transact on OpenSea and its technology.

At a very high level, the process looks like this:
Seller

Buyer

Components
A lot is going on here. Let’s break down each component.
WyvernProxyRegistry
The first time a seller lists on OpenSea, the WyvernProxyRegistry creates a smart contract called OwnableDelegateProxy . The seller owns this contract, and its address is stored in the proxy registry. The code for the WyvernProxyRegistry is here.
This is the «Initialize your wallet» step:

The transaction looks like this:

OwnableDelegateProxy
One OwnableDelegateProxy is created for each seller. The Wyvern exchange contract uses this new contract to take action on the seller’s behalf. A proxy contract can call methods on other contracts without storing any information about those contracts.
This process is called proxy delegation. How this works is beyond the scope of this article, but you can learn more about it here.
NFT Contract
This is the contract for the NFT collection the seller is trying to list. The first time the seller lists any item in that collection, they give their OwnableDelegateProxy contract approval to transfer tokens.
This is the «Approve this item for sale» step:

The transaction looks like this:

OpenSea Centralized Order Book
OpenSea asks the seller to sign a message containing all the details of their listing, including the sale price and expiration date. This message is called the sell order. The signature’s purpose is to validate that the seller requested the order and that nobody modified it. OpenSea stores all sell orders and signatures in a centralized database called an order book.
These sell orders are available via the OpenSea API. This allows marketplace aggregators like Genie to show valid listings on OpenSea. Even though the orders are stored off-chain, marketplaces can fulfill any valid orders on-chain. This is why it is free to list items but costs gas to cancel them. All orders are valid until they are canceled on-chain or expire.
The sell order is created and signed in the «Confirm listing» step:

The transaction looks like this:

Wyvern Exchange Contract
This contract is responsible for executing orders. You can see the code for this contract here. The buyer calls the atmoicMatch_ method with enough ETH to fulfill the order. The automicMatch_ method takes the sell order, sell order signature, buy order, and buy order signature. It checks to see if sell and buy orders match and are still valid. It will then send fees to OpenSea, send payment to the seller, and use the seller’s OwnableDelegateProxy contract to transfer NFTs from the seller to the buyer.
Once this is done, the buy and sell orders are marked as finalized in the contract.
The transaction looks like this for the buyer:

This is the final step in the process. If all goes well, the buyer has the NFT, and the seller has the payment.
Conclusion
There’s a lot more to the Wyvern Protocol than I’ve covered here, but I hope this article has given you a better understanding of each step. If you want to dig deeper, I’ve included some resources below.

Resources
- Wyvern Protocol
- Proxy Delegate from Solidity Patterns
- OpenSea: Wyvern Exchange Contract v2
- Project Wyvern Proxy Registry
- OpenSea API Reference
- @javamonnn’s Breakdown of The Wyvern Exchange Contract
On May 25, 2022 OpenSea announced plans to switch from Wyvern to a new protocol called Seaport.