Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Conversation

@porkbrain
Copy link
Contributor

@porkbrain porkbrain commented Sep 29, 2022

  • Sui v0.9.0

Orderbook

Orderbook implementation where bids are fungible tokens and asks are NFTs.
A bid is a request to buy one NFT from a specific collection.
An ask is one NFT with a min price condition.

Ask is an object which is associated with a single NFT.
When Ask is created, we transfer the ownership of the NFT to this
new object.
When an Ask is matched with a bid, we transfer the ownership of the
ask object to the bid owner (buyer).
The buyer can then claim the NFT via claim_nft endpoint.

One can:

  • create a new orderbook between a given collection and a BID token (witness
    pattern protected)
  • collect fees (witness pattern protected)
  • set publicly accessible actions to be witness protected
  • open a new BID
  • cancel an existing BID they own
  • offer an NFT if a collection matches OB collection
  • cancel an existing NFT offer
  • instantly buy a specific NFT

Witness protected actions

The contract which creates the orderbook can restrict specific actions to be
called only with a witness pattern and not via the entry point function.
This means others can build contracts on top of the orderbook with their own
custom logic based on their requirements or they can just use the entry point
functions that cover other use cases.

If a method is protected, clients will need to call a standard endpoint in the
witness-owning smart contract instead of the relevant endpoint in the orderbook.
Another way to think about this from a marketplace or wallet POV:
if I see that an action is protected, I can decide to either call the downstream
implementation in the collection smart contract, or simply disable that specific
action.

An example of this would be an NFT which has an expiry date like a name service
which requires an additional check before an ask can be placed on the orderbook.
Marketplaces can choose to support this additional logic or simply use the
standard orderbook and enable bids but asks would be disabled until they decide
to support the additional checks.

The setting is stored on the orderbook object:

struct WitnessProtectedActions has store {
    buy_nft: bool,
    cancel_ask: bool,
    cancel_bid: bool,
    create_ask: bool,
    create_bid: bool,
}

This means that the additional complexity is (i) opt-in by the collection and
(ii) reserved only to the particular action which warrants that complexity.

To reiterate, a marketplace can list NFTs from collections that have all
actions unprotected, ie. no special logic. Or they can just disable that
particular action that is disabled in the UI.

Additionally, if we created a standard interface for custom implementations of
the disabled actions, then the added opt-in complexity could be abstracted away
from the clients by our SDK.

TBD: Can this be misused by removing the option to cancel an ask/bid?

Changelog

[0.4.0] - 2022-09-29

Changed

  • Using Movemate's implementation of critbit (sorted binary tree) instead of
    the naive implementation with two sorted arrays.
  • Renamed package to Syrup

[0.3.0] - 2022-09-27

Changed

  • The creation of an orderbook is a witness protected function. The downstream
    contract has the liberty of deciding when and how a new instance of an
    orderbook should be created.

Added

  • Draft implementation for fees. At the moment, only the permission concept is
    figured out and data model. To collect fees, the downstream collection
    contract calls witness protected collect_fees function.
  • Logic for optionally witness protecting trading entry functions.

[0.2.0] - 2022-09-21

Added

  • Endpoint to buy a specific listed NFT.
  • Getter for OB collection id.
  • Getters for ask and bid fields.

Changed

  • Using nft-protocol v0.2.0 and Sui v0.9.0

@porkbrain porkbrain requested a review from maomove September 29, 2022 13:41
@porkbrain porkbrain self-assigned this Sep 29, 2022
porkbrain and others added 4 commits September 30, 2022 02:08
Co-authored-by: Nuno Boavida <45330362+nmboavida@users.noreply.github.com>
Using crit bit tree and price levels to hold state
@porkbrain porkbrain requested review from damirka and sblackshear and removed request for damirka and maomove September 30, 2022 11:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants