Wyvern on the OpenSea
How The OpenSea Exchange Works
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
--Update--
On May 25, 2022 OpenSea announced plans to switch from Wyvern to a new protocol called Seaport.