Dummy Mail
Dummy Mail

Reputation: 83

How opensea auction smart contract work without storing the ether

Trying to understand how opensea "Make the bid" work. Whenever any interested buyer wants to buy an NFT, they have to create an offer,in which they basically sign a message(commitment)(which is not costing gas fees). I didn't understand how this thing works behind the scene. If, let say, i made an offer for 3 days and i won the bid or seller accepted the bid, and i don't have required ether(the bid amount) at that moment, then what will happen?

Auction smart contract basically take bidder amount as stake, and when auction end, if user doen't won the auction, transfer staked ether back, but in both the above process staking ether+paying transaction fees, these extra overhead is there.

Opensea doesn't follow staking of bidding amount and hence save user from paying transaction fees + staking ether. But they ask user to sign for confirmation of bid. Can anyone explain whats technically happening?

I have gone through below links also but this doesn't answer how opensea is working.

Link 1 : https://ethereum.stackexchange.com/questions/102660/creating-an-auction-smart-contract-without-storing-the-ether

Link 2: https://ethereum.stackexchange.com/questions/110749/auction-data-on-chain-or-off-chain

In link 2, they mention "Commitments are created by signing "messages". These are off-chain transactions. However, cancelling transactions requires posting on-chain." But how is it actually working?

Upvotes: 5

Views: 1466

Answers (2)

Lawwee
Lawwee

Reputation: 1

This is what is being done;

When a user bids on an NFT, they are approving the contract they are interacting with to transfer their Ether on their behalf (approve from the ERC-20 token standard). This is why they need to sign a transaction/commitment.

As this happens, the contract also stores the details of the bid which includes the bid price, so when a user wins a bid, the contract would already have approval to transfer the bid price to the NFT holder, then do so accordingly. This is in line with why and how opensea gets unlimited approval to transfer the user/buyer's ERC-20 based token, which I believe is also a reason why Opensea makes use of WETH and not ETH.

If the user does not have the required ether, there would have to be an extra functionality that allows the NFT holder to pick the second highest bidder, or cancel the auction as a whole. Reason being, contracts are automated with certain conditions in place, if the conditions are not meant, then the transaction fails. With this nature, the extra functionality is the best way to go (my opinion).

As for the commitments, commitments are done off-chain the primary network (for faster processing and lesser fees most likely), so the commitment message being signed is on an L2 solution (could be blockchain or application), which would still be rolled up or merged to the primary network, so the primary network is able to have details of the transaction. Since there is no further flow after cancelling the transaction, then it makes sense to have that directly on-chain the primary network.

Upvotes: 0

0xSanson
0xSanson

Reputation: 857

I'll explain how the newest version of Opensea works, called Seaport (docs).

If, let say, i made an offer for 3 days and i won the bid or seller accepted the bid, and i don't have required ether(the bid amount) at that moment, then what will happen?

Simply your offer won't be fulfillable. Opensea's UI should filter unfulfillable offers so they don't get accepted. If an offer is accepted by mistake, nothing bad happens, the transaction simply fails and no token is transferred.

The job of the smart contract is not to store offers, but to verify that an offer is valid and to transfer the tokens accordingly.

It may be a surprise, but the only data stored on the contract are the following mappings

// Track status of each order (validated, cancelled, and fraction filled).
mapping(bytes32 => OrderStatus) private _orderStatus;

// Only orders signed using an offerer's current counter are fulfillable.
mapping(address => uint256) private _counters;

The first mapping ensures that an order can't be fulfilled multiple times or if it was cancelled. (The order is recognized by its bytes32 hash).

The second mapping saves a counter for every offerer. Every offer has a counter parameter that should match _counters[offerer], otherwise it's invalid. This is a smart way to cancel all your existing offers, because you have a "cancel all" function simply increment your _counters.

This should have answered why to cancel orders you need to have a on-chain transaction. Because nothing guarantees that an offer is forgotten by everyone off-chain.

Opensea doesn't follow staking of bidding amount and hence save user from paying transaction fees + staking ether. But they ask user to sign for confirmation of bid. Can anyone explain whats technically happening?

The "confirmation of bid" is a wallet signature (EIP-712) necessary to make the process trustless. No one will be able to steal tokens by forging offers. The only trusting assumption is that Opensea won't hide an offer from a buyer/seller.

Upvotes: 1

Related Questions