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

Update NBA contracts & txs to Cadence 1.0 #248

Merged
merged 59 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
30006da
first version of cadence 1.0
bshahid331 Feb 21, 2024
1743167
Add minter entitlement and inherity NFT public interface in TopShot p…
bshahid331 Mar 20, 2024
52cadab
update go version
bshahid331 Mar 20, 2024
4ed8b2e
Swith view and access positions
bshahid331 Apr 3, 2024
3d8761e
Adjust smart contracts for cadence 1.0
bshahid331 Apr 4, 2024
269f08b
fix contracts test
bshahid331 Apr 3, 2024
255fec3
nft v1.0.0 upgrade (#252)
rrrkren May 7, 2024
523ab99
sharded collection conforming to NFT provider and deposit
rrrkren May 7, 2024
1c1dd7c
remove contract initialized
fkenji Aug 7, 2024
2bb483d
update fastbreakv1
judezhu Aug 7, 2024
74c96bf
Merge pull request #254 from dapperlabs/judez/stage-fastbreak
judezhu Aug 7, 2024
2129799
Bump golang.org/x/net from 0.19.0 to 0.23.0 in /lib/go/test (#250)
dependabot[bot] Apr 19, 2024
dbf8487
upgrade flow sdk
judezhu Aug 6, 2024
a21834d
fix minted event
judezhu Aug 6, 2024
269a9a7
updated go mod
judezhu Aug 7, 2024
bd43d59
Merge pull request #253 from dapperlabs/judez/NBA-2865-upgrade-flow-sdk
judezhu Aug 7, 2024
5c56240
Fix tests on Cadence 1.0 (#255)
fkenji Aug 7, 2024
09f93a5
remove contract initialized
fkenji Aug 7, 2024
672af35
fix get length
fkenji Aug 7, 2024
6b04ffb
remove unneeded entitlement
fkenji Aug 7, 2024
5c912bc
emit standard events
fkenji Aug 8, 2024
0fe9518
deprecate public interface
fkenji Aug 8, 2024
7800460
Merge branch 'master' into feature/cadence-1.0
fkenji Aug 8, 2024
81680be
Re-add public interfaces now due to usage in tests; remove un-needed …
fkenji Aug 8, 2024
e412417
update assets
fkenji Aug 8, 2024
1d54f42
remove Withdraw / Deposit events from Fastbreak in lieu of standard N…
fkenji Aug 8, 2024
0108409
update readme
fkenji Aug 8, 2024
0d6b4b4
Remove custom Withdraw / Deposit events being emitted
fkenji Aug 8, 2024
f3e14bd
update assets
fkenji Aug 8, 2024
0c3db89
fix tests
judezhu Aug 8, 2024
5455f72
fix more tests
judezhu Aug 12, 2024
08687dd
remove unused code
judezhu Aug 12, 2024
209b9f6
added events validateion
judezhu Aug 12, 2024
9920f49
updated all event type check
judezhu Aug 12, 2024
043f9c8
Merge pull request #258 from dapperlabs/judez/add-events-validation
judezhu Aug 12, 2024
a28c918
Merge pull request #257 from dapperlabs/judez/fixing-event-tests
judezhu Aug 12, 2024
beab2ce
fix fields
judezhu Aug 12, 2024
a0b4bd8
fixed id
judezhu Aug 12, 2024
7ac2be3
fix unlock event
judezhu Aug 13, 2024
2ddccc5
fixed moment minted
judezhu Aug 13, 2024
0f9969b
Merge pull request #259 from dapperlabs/judez/fix-moment-locked
judezhu Aug 13, 2024
f32c479
added new name
judezhu Aug 17, 2024
b39c50b
Merge pull request #261 from dapperlabs/judez/add-new-destroy-event
judezhu Aug 17, 2024
d83d8e8
add script to setup capabilities on minter account from locker account
fkenji Aug 20, 2024
aa451bb
Embed transactions / scripts (#260)
fkenji Aug 20, 2024
d25c15e
update assets
fkenji Aug 20, 2024
3b3ab32
update commit
fkenji Aug 20, 2024
741ce81
fix script
judezhu Aug 26, 2024
df8459c
run make test
judezhu Aug 26, 2024
836b430
Merge pull request #262 from dapperlabs/judez/fix-nba-check-collectio…
judezhu Aug 27, 2024
da3f48d
fix marketplace txes
judezhu Aug 28, 2024
34f2890
revert hardcoded address
judezhu Aug 28, 2024
ff0b5ee
fix addresses
judezhu Aug 28, 2024
ae4afa8
updated assets
judezhu Aug 28, 2024
89727e0
fix tx
judezhu Aug 29, 2024
78398ac
updated assets
judezhu Aug 29, 2024
339032e
fix script
judezhu Aug 29, 2024
19d37ae
Merge pull request #263 from dapperlabs/judez/fix-marketplace-txes
judezhu Aug 29, 2024
b42875f
save cap on storage (#264)
fkenji Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading