Skip to content

Commit

Permalink
Update NBA contracts & txs to Cadence 1.0 (#248)
Browse files Browse the repository at this point in the history
* first version of cadence 1.0

* Add minter entitlement and inherity NFT public interface in TopShot public interface

* update go version

* Swith view and access positions

* Adjust smart contracts for cadence 1.0

* fix contracts test

* nft v1.0.0 upgrade (#252)

* cadence 1 upgrade

* fix tests

* token updated

* sharded collection conforming to NFT provider and deposit

* remove contract initialized

* update fastbreakv1

* Bump golang.org/x/net from 0.19.0 to 0.23.0 in /lib/go/test (#250)

* Bump golang.org/x/net from 0.19.0 to 0.23.0 in /lib/go/test

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.19.0 to 0.23.0.
- [Commits](golang/net@v0.19.0...v0.23.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

* generated

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Taylor Petrychyn <[email protected]>

* upgrade flow sdk

* fix minted event

* updated go mod

* Fix tests on Cadence 1.0 (#255)

* Fix tests

* ci

* Update go version

* remove contract initialized

* fix get length

* remove unneeded entitlement

* emit standard events

* deprecate public interface

* Re-add public interfaces now due to usage in tests; remove un-needed nftUpdated event call, as it was already being called

* update assets

* remove Withdraw / Deposit events from Fastbreak in lieu of standard NFT events

* update readme

* Remove custom Withdraw / Deposit events being emitted

* update assets

* fix tests

* fix more tests

* remove unused code

* added events validateion

* updated all event type check

* fix fields

* fixed id

* fix unlock event

* fixed moment minted

* added new name

* add script to setup capabilities on minter account from locker account

* Embed transactions / scripts (#260)

* update assets

* update commit

* fix script

* run make test

* fix marketplace txes

* revert hardcoded address

* fix addresses

* updated assets

* fix tx

* updated assets

* fix script

* save cap on storage (#264)

* save cap on storage

* fix var / entitlements

* add comments and V1 Sale handling to create and start sale collection (#266)

---------

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

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Eric Ren <[email protected]>
Co-authored-by: Fabio Kenji <[email protected]>
Co-authored-by: Jude Zhu <[email protected]>
Co-authored-by: Jude Zhu <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Taylor Petrychyn <[email protected]>
Co-authored-by: Joshua Hannan <[email protected]>
  • Loading branch information
8 people authored Sep 3, 2024
1 parent 1c07759 commit 96b859a
Show file tree
Hide file tree
Showing 183 changed files with 5,928 additions and 4,072 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: '1.19'
go-version: '1.22'
- run: make ci
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
flow.json
/imports
.vscode
.vscode
.env
**/vendor/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export GOFLAGS :=-tags=no_cgo
export CGO_ENABLED := 0

.PHONY: test
test:
$(MAKE) generate -C lib/go
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ is a list of events that can be emitted, and what each event means.
You can find definitions for interpreting these events in Go by seeing
the `lib/go/events` package.

- `pub event ContractInitialized()`

This event is emitted when the `TopShot` contract is created.

#### Events for plays
- `pub event PlayCreated(id: UInt32, metadata: {String:String})`
Expand Down
402 changes: 243 additions & 159 deletions contracts/FastBreakV1.cdc

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions contracts/MarketTopShotOldVersion.cdc → contracts/Market.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,40 @@ import DapperUtilityCoin from 0xDUCADDRESS
import NonFungibleToken from 0xNFTADDRESS
import TopShot from 0xTOPSHOTADDRESS

pub contract Market {
access(all) contract Market {

access(all) entitlement Create
access(all) entitlement Update

// -----------------------------------------------------------------------
// TopShot Market contract Event definitions
// -----------------------------------------------------------------------
// emitted when a TopShot moment is listed for sale
pub event MomentListed(id: UInt64, price: UFix64, seller: Address?)
access(all) event MomentListed(id: UInt64, price: UFix64, seller: Address?)
// emitted when the price of a listed moment has changed
pub event MomentPriceChanged(id: UInt64, newPrice: UFix64, seller: Address?)
access(all) event MomentPriceChanged(id: UInt64, newPrice: UFix64, seller: Address?)
// emitted when a token is purchased from the market
pub event MomentPurchased(id: UInt64, price: UFix64, seller: Address?)
access(all) event MomentPurchased(id: UInt64, price: UFix64, seller: Address?)
// emitted when a moment has been withdrawn from the sale
pub event MomentWithdrawn(id: UInt64, owner: Address?)
access(all) event MomentWithdrawn(id: UInt64, owner: Address?)
// emitted when the cut percentage of the sale has been changed by the owner
pub event CutPercentageChanged(newPercent: UFix64, seller: Address?)
access(all) event CutPercentageChanged(newPercent: UFix64, seller: Address?)

// SalePublic
//
// The interface that a user can publish their sale as
// to allow others to access their sale
pub resource interface SalePublic {
pub var cutPercentage: UFix64
pub fun purchase(tokenID: UInt64, buyTokens: @DapperUtilityCoin.Vault): @TopShot.NFT {
access(all) resource interface SalePublic {
access(all) var cutPercentage: UFix64
access(all) fun purchase(tokenID: UInt64, buyTokens: @DapperUtilityCoin.Vault): @TopShot.NFT {
post {
result.id == tokenID: "The ID of the withdrawn token must be the same as the requested ID"
}
}
pub fun getPrice(tokenID: UInt64): UFix64?
pub fun getIDs(): [UInt64]
pub fun borrowMoment(id: UInt64): &TopShot.NFT? {
access(all) fun getPrice(tokenID: UInt64): UFix64?
access(all) fun getIDs(): [UInt64]
access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? {
// If the result isn't nil, the id of the returned reference
// should be the same as the argument to the function
post {
Expand All @@ -86,7 +89,7 @@ pub contract Market {
//
// When a token is purchased, a cut is taken from the tokens that are used to
// purchase and sent to the beneficiary, then the rest are sent to the seller
pub resource SaleCollection: SalePublic {
access(all) resource SaleCollection: SalePublic {

// A collection of the moments that the user has for sale
access(self) var forSale: @TopShot.Collection
Expand All @@ -106,7 +109,7 @@ pub contract Market {
// the percentage that is taken from every purchase for the beneficiary
// This is a literal percentage
// For example, if the percentage is 15%, cutPercentage = 0.15
pub var cutPercentage: UFix64
access(all) var cutPercentage: UFix64

init (ownerCapability: Capability, beneficiaryCapability: Capability, cutPercentage: UFix64) {
pre {
Expand All @@ -118,7 +121,7 @@ pub contract Market {
"Beneficiary's Receiver Capability is invalid!"
}

self.forSale <- TopShot.createEmptyCollection() as! @TopShot.Collection
self.forSale <- TopShot.createEmptyCollection(nftType: Type<@TopShot.NFT>()) as! @TopShot.Collection
self.ownerCapability = ownerCapability
self.beneficiaryCapability = beneficiaryCapability
self.prices = {}
Expand All @@ -127,7 +130,7 @@ pub contract Market {

// listForSale lists an NFT for sale in this sale collection
// at the specified price
pub fun listForSale(token: @TopShot.NFT, price: UFix64) {
access(Create) fun listForSale(token: @TopShot.NFT, price: UFix64) {

// get the ID of the token
let id = token.id
Expand All @@ -142,7 +145,7 @@ pub contract Market {
}

// Withdraw removes a moment that was listed for sale
pub fun withdraw(tokenID: UInt64): @TopShot.NFT {
access(NonFungibleToken.Withdraw) fun withdraw(tokenID: UInt64): @TopShot.NFT {

// remove and return the token
// will revert if the token doesn't exist
Expand All @@ -163,9 +166,9 @@ pub contract Market {

// purchase lets a user send tokens to purchase an NFT that is for sale
// the purchased NFT is returned to the transaction context that called it
pub fun purchase(tokenID: UInt64, buyTokens: @DapperUtilityCoin.Vault): @TopShot.NFT {
access(all) fun purchase(tokenID: UInt64, buyTokens: @DapperUtilityCoin.Vault): @TopShot.NFT {
pre {
self.forSale.ownedNFTs[tokenID] != nil && self.prices[tokenID] != nil:
self.forSale.borrowNFT(tokenID) != nil && self.prices[tokenID] != nil:
"No token matching this ID for sale!"
buyTokens.balance == (self.prices[tokenID] ?? UFix64(0)):
"Not enough tokens to buy the NFT!"
Expand Down Expand Up @@ -195,7 +198,7 @@ pub contract Market {
}

// changePrice changes the price of a token that is currently for sale
pub fun changePrice(tokenID: UInt64, newPrice: UFix64) {
access(Update) fun changePrice(tokenID: UInt64, newPrice: UFix64) {
pre {
self.prices[tokenID] != nil: "Cannot change the price for a token that is not for sale"
}
Expand All @@ -206,14 +209,14 @@ pub contract Market {
}

// changePercentage changes the cut percentage of the tokens that are for sale
pub fun changePercentage(_ newPercent: UFix64) {
access(Update) fun changePercentage(_ newPercent: UFix64) {
self.cutPercentage = newPercent

emit CutPercentageChanged(newPercent: newPercent, seller: self.owner?.address)
}

// changeOwnerReceiver updates the capability for the sellers fungible token Vault
pub fun changeOwnerReceiver(_ newOwnerCapability: Capability) {
access(Update) fun changeOwnerReceiver(_ newOwnerCapability: Capability) {
pre {
newOwnerCapability.borrow<&{FungibleToken.Receiver}>() != nil:
"Owner's Receiver Capability is invalid!"
Expand All @@ -222,38 +225,34 @@ pub contract Market {
}

// changeBeneficiaryReceiver updates the capability for the beneficiary of the cut of the sale
pub fun changeBeneficiaryReceiver(_ newBeneficiaryCapability: Capability) {
access(Update) fun changeBeneficiaryReceiver(_ newBeneficiaryCapability: Capability) {
pre {
newBeneficiaryCapability.borrow<&DapperUtilityCoin.Vault{FungibleToken.Receiver}>() != nil:
newBeneficiaryCapability.borrow<&DapperUtilityCoin.Vault>() != nil:
"Beneficiary's Receiver Capability is invalid!"
}
self.beneficiaryCapability = newBeneficiaryCapability
}

// getPrice returns the price of a specific token in the sale
pub fun getPrice(tokenID: UInt64): UFix64? {
access(all) view fun getPrice(tokenID: UInt64): UFix64? {
return self.prices[tokenID]
}

// getIDs returns an array of token IDs that are for sale
pub fun getIDs(): [UInt64] {
access(all) view fun getIDs(): [UInt64] {
return self.forSale.getIDs()
}

// borrowMoment Returns a borrowed reference to a Moment in the collection
// so that the caller can read data from it
pub fun borrowMoment(id: UInt64): &TopShot.NFT? {
access(all) view fun borrowMoment(id: UInt64): &TopShot.NFT? {
let ref = self.forSale.borrowMoment(id: id)
return ref
}

destroy() {
destroy self.forSale
}
}

// createCollection returns a new collection resource to the caller
pub fun createSaleCollection(ownerCapability: Capability, beneficiaryCapability: Capability, cutPercentage: UFix64): @SaleCollection {
access(all) fun createSaleCollection(ownerCapability: Capability, beneficiaryCapability: Capability, cutPercentage: UFix64): @SaleCollection {
return <- create SaleCollection(ownerCapability: ownerCapability, beneficiaryCapability: beneficiaryCapability, cutPercentage: cutPercentage)
}
}
}
Loading

0 comments on commit 96b859a

Please sign in to comment.