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

NFTStorefront v1 & v2 Cadence 1.0 Refactor #89

Merged
merged 49 commits into from
May 21, 2024

Conversation

sisyphusSmiling
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling commented Sep 26, 2023

Closes: #87

This PR targets the existing stable-cadence branch, so includes some updates from main. The idea is to use stable-cadence as the working Stable Cadence branch moving forward.

Dependencies pulled from respective repo's stable-cadence branches:

  • ViewResolver
  • FungibleToken
  • NonFungibleToken
  • MultipleNFT
  • ExampleNFT

The changes against NFTStorefront and accompanying transactions & scripts have been made to conform to Cadence 1.0 language updates.

Note: It looks like the test suite is running the current version of Cadence as tests are not passing.

TODO:

  • Merge stable-cadence branch to this one? Picked up from up from Stable Cadence Feature Branch #74, so merge might be best way forward.
  • Update dependency repos
    • flow-ft transactions & scripts on stable cadence feature branch
    • flow-nft transactions & scripts on stable cadence feature branch
  • Get test cases to pass

poiati and others added 23 commits December 22, 2022 23:47
* update go lib

* ci: update emulator version

the version specified wasn't released
Basic cleanups to set stage for more coming
* add functionality of ghost listing

* add testing for the function

* fix flow.json

* minor fix

* Typos hunter

* change function name

---------

Co-authored-by: Álvaro Lillo Igualada <[email protected]>
* add documentation related to the ghost listing

* Update docs/documentation.md

Co-authored-by: Joshua Hannan <[email protected]>

* Update scripts/has_listing_become_ghosted.cdc

Co-authored-by: Joshua Hannan <[email protected]>

* Update scripts/has_listing_become_ghosted.cdc

Co-authored-by: Joshua Hannan <[email protected]>

* Update scripts/has_listing_become_ghosted.cdc

Co-authored-by: Joshua Hannan <[email protected]>

* Update docs/documentation.md

Co-authored-by: j pimmel <[email protected]>

* add a recomendation to use cleanup ghost listing

* Update docs/documentation.md

Co-authored-by: j pimmel <[email protected]>

* Update docs/documentation.md

Co-authored-by: j pimmel <[email protected]>

* Update docs/documentation.md

Co-authored-by: j pimmel <[email protected]>

* minor fixes

---------

Co-authored-by: Joshua Hannan <[email protected]>
Co-authored-by: j pimmel <[email protected]>
* update the core contracts

* fix test cases

* minor fix
@sisyphusSmiling sisyphusSmiling requested a review from a team September 26, 2023 23:44
@sisyphusSmiling sisyphusSmiling self-assigned this Sep 26, 2023
@sisyphusSmiling sisyphusSmiling changed the title Stable cadence refactor NFTStorefront Cadence 1.0 Refactor Sep 26, 2023
Copy link
Member

@joshuahannan joshuahannan left a comment

Choose a reason for hiding this comment

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

Looks like v2 still needs some work, so I can come back to this review once you have the tests passing

contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
contracts/utility/NFTCatalog.cdc Outdated Show resolved Hide resolved
@sisyphusSmiling sisyphusSmiling changed the title NFTStorefront Cadence 1.0 Refactor NFTStorefront v1 & v2 Cadence 1.0 Refactor Sep 29, 2023
@sisyphusSmiling
Copy link
Contributor Author

Progress on this PR is blocked until flow-ft and flow-nft repos have fully functional stable cadence branches, especially the former.
It appears the transactions from flow-ft are utilized in the test suite and since flow-ft transactions aren't up to Cadence 1.0 in the stable cadence feature branch, they're failing in the NFTStorefront test suite.
Relevant discord discussion: https://discord.com/channels/613813861610684416/621847426201944074/1157425948405280858

Copy link
Member

@joshuahannan joshuahannan left a comment

Choose a reason for hiding this comment

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

Looks pretty good! Just a few small comments about style and stuff. I only have reviewed the contract changes so far but I can get to the transactions and stuff later after you've addressed my initial comments.

Remember to update to all the latest versions of the emulator, cadence, and CLI so that we can be sure that we're testing with the most up to date versions. I left some comments where that would apply for CI and the Go tests, but I'm not sure where the dependencies are imported for the JS tests. You might need to update those too

.github/workflows/ci.yml Outdated Show resolved Hide resolved
contracts/NFTStorefront.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefront.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefront.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
docs/documentation.md Show resolved Hide resolved
docs/documentation.md Outdated Show resolved Hide resolved
docs/documentation.md Outdated Show resolved Hide resolved
lib/go/test/go.mod Outdated Show resolved Hide resolved
…v1. And update some documentation for cadence 1.0.
@aishairzay
Copy link
Contributor

@joshuahannan thanks for the comments, newest update should address all of them.

I also removed the go testing entirely which makes the version issue not a problem. The previous go testing was very simple testing targeted only towards storefrontv1, and so I've replaced it with new cadence testing for storefrontv1.

@aishairzay aishairzay marked this pull request as ready for review April 3, 2024 19:36
@highskore
Copy link

I'm using the stable cadence version of NFTStorefront and borrowNFT is always reverting for me here:
assert(ref.isInstance(self.getDetails().nftType), message: "token has wrong type"), but creating the listing works fine, it would revert on create if type was actually invalid right?

Commenting this line makes it work obviously

@aishairzay
Copy link
Contributor

I'm using the stable cadence version of NFTStorefront and borrowNFT is always reverting for me here: assert(ref.isInstance(self.getDetails().nftType), message: "token has wrong type"), but creating the listing works fine, it would revert on create if type was actually invalid right?

Commenting this line makes it work obviously

Taking a look at this - In create listing we're using the following code: assert(nft!.getType() == self.details.nftType, message: "token is not of specified type") which differs from the ref.isInstance(self.getDetails().nftType that's in borrowNFT. I'm not entirely sure why one would work and the other wouldn't, so looking into that.

@highskore
Copy link

I'm using the stable cadence version of NFTStorefront and borrowNFT is always reverting for me here: assert(ref.isInstance(self.getDetails().nftType), message: "token has wrong type"), but creating the listing works fine, it would revert on create if type was actually invalid right?
Commenting this line makes it work obviously

Taking a look at this - In create listing we're using the following code: assert(nft!.getType() == self.details.nftType, message: "token is not of specified type") which differs from the ref.isInstance(self.getDetails().nftType that's in borrowNFT. I'm not entirely sure why one would work and the other wouldn't, so looking into that.

I think a test covering borrowNFT would be sufficient

@aishairzay
Copy link
Contributor

I'm using the stable cadence version of NFTStorefront and borrowNFT is always reverting for me here: assert(ref.isInstance(self.getDetails().nftType), message: "token has wrong type"), but creating the listing works fine, it would revert on create if type was actually invalid right?
Commenting this line makes it work obviously

Taking a look at this - In create listing we're using the following code: assert(nft!.getType() == self.details.nftType, message: "token is not of specified type") which differs from the ref.isInstance(self.getDetails().nftType that's in borrowNFT. I'm not entirely sure why one would work and the other wouldn't, so looking into that.

I think a test covering borrowNFT would be sufficient

Thanks for bringing this up.

I added a new script and test case to cover borrowNFT now, also updated the previewnet build to reflect the fix needed to properly check the nft type. If you run into any more issues please keep them coming here!

Copy link
Member

@joshuahannan joshuahannan left a comment

Choose a reason for hiding this comment

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

Left a couple more comments. Basically just entitlement naming and some view functions. I'd really like to get all of these deployed on previewnet and staged on testnet soon. Right now it only looks like V2 is staged. Community members have been bugging us about it. Let me know when you think you'll be able to get to these and do the staging/deployments.

contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
@joshuahannan
Copy link
Member

joshuahannan commented May 1, 2024

I updated all the dependencies, addressed all my previous comments on this PR, and got the cadence tests passing. NFTStorefront is staged on testnet, but NFTStorefrontV2 is not staged on testnet because we are still looking for the key information for the account.

Missing key information for previewnet also

Any more reviews here would be much appreciated

Copy link
Contributor Author

@sisyphusSmiling sisyphusSmiling left a comment

Choose a reason for hiding this comment

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

I left comments, but nothing that can't be addressed in a follow up - no reason to block. I can't leave an approval since I originally submitted the PR, but LGTM ✅

contracts/NFTStorefront.cdc Show resolved Hide resolved
contracts/NFTStorefront.cdc Show resolved Hide resolved
contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
contracts/NFTStorefrontV2.cdc Outdated Show resolved Hide resolved
flow.json Outdated Show resolved Hide resolved
/// Buyer of the listing (,i.e. underling NFT) would authorize and sign the
/// transaction and if purchase happens then transacted NFT would store in
/// buyer's collection.

transaction(listingResourceID: UInt64, storefrontAddress: Address, commissionRecipient: Address?) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're moving to a generalized interface for NFT & FT transactions, it'd be worth making this transaction compatible with any standard asset instead of the statically declared ExampleToken & ExampleNFT IMO

// withdraw the NFT from the owner's collection
let nft <- self.collectionRef.withdraw(withdrawID: id)

destroy nft
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be nice to see Burner.burn used here

Comment on lines +47 to +64
// // Create the royalty details
// var count = 0
// var royalties: [MetadataViews.Royalty] = []
// while royaltyBeneficiaries.length > count {
// let beneficiary = royaltyBeneficiaries[count]
// let beneficiaryCapability = getAccount(beneficiary).capabilities.get<&{FungibleToken.Receiver}>(
// MetadataViews.getRoyaltyReceiverPublicPath()
// ) ?? panic("Beneficiary does not have Receiver configured at RoyaltyReceiverPublicPath")

// royalties.append(
// MetadataViews.Royalty(
// receiver: beneficiaryCapability,
// cut: cuts[count],
// description: royaltyDescriptions[count]
// )
// )
// count = count + 1
// }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this can be uncommented

Comment on lines +20 to +27
transaction(
saleItemID: UInt64,
saleItemPrice: UFix64,
customID: String?,
commissionAmount: UFix64,
expiry: UInt64,
marketplacesAddress: [Address]
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment as above about generalizing the transaction interface for use with any NFT & FT

@joshuahannan
Copy link
Member

@sisyphusSmiling I addressed your comments about the contracts and pushed my changes. I created an issue for the transaction changes that I am going to come back to later

@joshuahannan joshuahannan merged commit a303f4a into stable-cadence May 21, 2024
@joshuahannan joshuahannan deleted the stable-cadence-refactor branch May 21, 2024 21:45
@joshuahannan joshuahannan restored the stable-cadence-refactor branch May 21, 2024 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

8 participants