Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move] NFT marketplace #921

Merged
merged 9 commits into from
Mar 21, 2022
Merged

[move] NFT marketplace #921

merged 9 commits into from
Mar 21, 2022

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Mar 18, 2022

Drafting a rough template of an NFT marketplace which makes use of shared objects and a Bag.

Two changes in Sui which I'm not sure about:

  1. Found a quick fix to enable remove_nested_object, @lxfind if you have a chance, please check my solution to TestScenario::get_inventory() should support retrieving objects owned by objects #673.
  2. Added a store ability to the Bag.

Crossroads

To continue with the topic raised on our last Sui/Move call, we could keep transfer_..._unsafe a friend-only thing if we allowed to store Bag, so that people would have built-in approach to storing large (or large enough) amounts of data.

Alternatively, if we expose this API to public, then I can remove store capability from a Bag and implement bag-like functionality in Marketplace.

I was also looking into storing ChildRef to a bag in a Marketplace object (could possibly lead to Solidity-like discovery-objects) but haven't found any API to make use of ChildRef, so got nowhere.

@damirka damirka added the move label Mar 18, 2022
@damirka damirka requested review from lxfind, awelc and sblackshear March 18, 2022 13:13
@damirka damirka self-assigned this Mar 18, 2022
/// Remove listing and get an NFT back. Only owner can do that.
public fun delist<T: store, C>(
market: &mut Marketplace,
listing: Listing<T, C>,
Copy link
Collaborator

@sblackshear sblackshear Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to understand how we are able to authenticate listing here. It is owned by Bag, but Bag is wrapped in Marketplace instead of being owned by Marketplace.

Let's assume these have the following object ID's
Marketplace: 0xA
Bag: 0xB
Listing: 0xC
Nft: 0xD

, I would expect the tx ownership chain to be

[Shared] -> 0xA -> 0xB -> 0xC -> 0xD

But the 0xA -> 0xB link can't exist if the Bag is wrapped in the marketplace instead of owned by it.

I actually don't know why this works in the tests--there might be a bug in TestScenario::remove_nested_object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, in the implementation of remove_nested_object, there is no check on the ownership of the parent object, it just checks whether the child is owned by the parent.

@sblackshear
Copy link
Collaborator

Alternatively, if we expose this API to public, then I can remove store capability from a Bag and implement bag-like functionality in Marketplace.

I think this is probably the way to go, but I also want to understand why the approach of giving Bag store works at all (i.e., is it because of a bug, or because my expectations are wrong)?

@@ -164,7 +164,9 @@ fn get_inventory_for(
// TODO: We should also be able to include objects indirectly owned by the
// requested address through owning other objects.
// https://github.com/MystenLabs/sui/issues/673
if (obj.owner == Owner::AddressOwner(sui_addr) || obj.owner.is_shared())
if (obj.owner == Owner::AddressOwner(sui_addr)
|| obj.owner == Owner::ObjectOwner(sui_addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is a great first step, but it's not sufficient.
To properly remove a child object, we still need to know the address of the signer, and check that the parent object is actually owned by the signer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the best approach to this? Passing TxContext to the get_inventory() method to determine signer and check privileges? I'm new to the backend part of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we likely need to have another version of remove_unique_object that supports two signer addresses, one being the object ID of the parent object, one being the actual sender's address, for this to authenticate properly.

/// Remove listing and get an NFT back. Only owner can do that.
public fun delist<T: store, C>(
market: &mut Marketplace,
listing: Listing<T, C>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, in the implementation of remove_nested_object, there is no check on the ownership of the parent object, it just checks whether the child is owned by the parent.

damirka added 3 commits March 21, 2022 14:46
- made KITTY a ticker-like struct
- arbitrary T with key+store instead of NFT
- use GAS as a coin
@damirka damirka marked this pull request as ready for review March 21, 2022 11:54
@damirka damirka changed the title [WIP, move] NFT marketplace [move] NFT marketplace Mar 21, 2022
@damirka damirka merged commit d4ecd15 into main Mar 21, 2022
@damirka damirka deleted the ds/nft-marketplace branch March 21, 2022 15:50
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants