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

FEATURE: V2 NonFungibleToken Standard #126

Merged
merged 128 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 104 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
a1a099d
first work on new standard
joshuahannan Jul 20, 2022
d418112
first draft of v2 NFT standard
joshuahannan Sep 9, 2022
6c03134
add type parameter to createEmptyCollection
joshuahannan Sep 9, 2022
cca2732
merge from master
joshuahannan Sep 12, 2022
926e46e
PR comments
joshuahannan Sep 12, 2022
f59902e
PR comments
joshuahannan Sep 27, 2022
e1bb168
make test
joshuahannan Sep 27, 2022
052d03a
move everything into the interface
joshuahannan Oct 5, 2022
ebdbb60
use getID and proper transfer
joshuahannan Oct 18, 2022
b7bc90b
use views in events, return optionals, and dont hardcode
joshuahannan Dec 6, 2022
3b8189e
add createEmptyCollection
joshuahannan Dec 16, 2022
340850c
isAcceptedType
joshuahannan Feb 1, 2023
7161f65
mar13 update
joshuahannan Mar 13, 2023
dc3a6f8
PR comments
joshuahannan Mar 23, 2023
bd8478f
separate nft views, add uuid, event args, resolver, and get contracts…
joshuahannan Apr 12, 2023
8f515ed
use events in interfaces
joshuahannan May 2, 2023
5a6b13e
integrate stable cadence changes
joshuahannan Jul 18, 2023
0d498ec
comment out events
joshuahannan Jul 18, 2023
4a745a6
modify view functions
joshuahannan Jul 18, 2023
98f7669
remove deposit impl
joshuahannan Jul 18, 2023
31bc26c
remove view from dictToTraits
joshuahannan Jul 18, 2023
ec3eda1
remove view modifier from resolveView
joshuahannan Jul 19, 2023
3f1e70b
remove restricted types
joshuahannan Jul 26, 2023
10f298c
remove AnyStruct
joshuahannan Jul 26, 2023
e12c049
update dependencies and fix example NFT
joshuahannan Aug 11, 2023
bc46319
fix import cadence issue and remove view
joshuahannan Aug 11, 2023
4387871
comment out default method conflicts
joshuahannan Aug 18, 2023
620416c
comment out usedUUID
joshuahannan Aug 18, 2023
523f9fa
comment out CollectionPublic
joshuahannan Aug 18, 2023
3945512
generate assets
joshuahannan Aug 18, 2023
f3c95ef
remove CollectionPublic from metadata views
joshuahannan Aug 18, 2023
719b931
add get length
joshuahannan Sep 6, 2023
ac62857
fixed missing auth for provider type
bjartek Sep 6, 2023
21640aa
Merge branch 'master' into standard-v2-updates
sisyphusSmiling Oct 20, 2023
1a261c0
update NFTForwarding for Cadence 1.0
sisyphusSmiling Oct 20, 2023
d9ef40e
update NFTForwarding transactions for new implementation
sisyphusSmiling Oct 20, 2023
2d9a34c
bump ci flow cli version to Cadence 1.0 pre-release
sisyphusSmiling Oct 23, 2023
8014190
fix ExampleNFT-v2 account storage access bug
sisyphusSmiling Oct 24, 2023
4311a6c
update FungibleToken Cadence 1.0 implementation
sisyphusSmiling Oct 24, 2023
262c73f
update flow.json with v2 contract implementations
sisyphusSmiling Oct 24, 2023
d872c31
update txns & scripts for Cadence 1.0 + supporting ExampleNFT-v2 Cade…
sisyphusSmiling Oct 24, 2023
c6330af
update Makefile & go tests
sisyphusSmiling Oct 24, 2023
ef9b4d7
update NFT-v2 to emit events from interface pre/post conditions
sisyphusSmiling Oct 24, 2023
359da96
update ExampleNFT-v2 Cadence tests & go assets
sisyphusSmiling Oct 24, 2023
0649cdf
update ExampleNFT-v2 providerPath
sisyphusSmiling Oct 24, 2023
b959c5b
update go tests and supporting txns
sisyphusSmiling Oct 24, 2023
92526d4
update go assets
sisyphusSmiling Oct 24, 2023
42b00b3
fix test cases to correspond with new contract implementations
sisyphusSmiling Oct 24, 2023
0f2bb28
add metadata trait test validation to go suite
sisyphusSmiling Oct 24, 2023
6958b19
update flow.json with emulator aliases
sisyphusSmiling Oct 24, 2023
cf9a423
fix NFTForwarding.Forwarder conformance to .Receiver & rename events
sisyphusSmiling Oct 24, 2023
c7aa593
add NFTForwarding Cadence tests & fix txn bugs
sisyphusSmiling Oct 24, 2023
cb3b555
complete NFTForwarding cadence tests + supporting txns & scripts
sisyphusSmiling Oct 24, 2023
f42de59
update .gitignore to include coverage.json
sisyphusSmiling Oct 24, 2023
88a73f1
fix contract.go placeholder variable name
sisyphusSmiling Oct 26, 2023
3c50d77
update NFT.transfer() pre-conditions on recevier.check() & .getIDs().…
sisyphusSmiling Nov 6, 2023
60eb711
update instances of Collection.getIDs().length with .getLength()
sisyphusSmiling Nov 6, 2023
8531ac6
add comments to test_helpers methods
sisyphusSmiling Nov 7, 2023
4347b53
update go assets
sisyphusSmiling Nov 7, 2023
86ca92b
re-add .transfer() pre-condition on .getIDs().contains(id)
sisyphusSmiling Nov 7, 2023
3f3d5a7
update go assets
sisyphusSmiling Nov 7, 2023
683df24
Merge pull request #194 from onflow/standard-v2-updates
sisyphusSmiling Nov 7, 2023
2b6dfd6
remove transfer, withdraw methods, and default implementations
joshuahannan Nov 14, 2023
825022e
add universal collection and other small changes
joshuahannan Nov 20, 2023
b11e79f
Merge remote-tracking branch 'origin/master' into standard-v2
joshuahannan Nov 20, 2023
7020df2
added updated event
bjartek Dec 1, 2023
408c68c
Update contracts/NonFungibleToken-v2.cdc
bjartek Dec 1, 2023
01c7114
add sub NFT, remove borrowNFTSafe
joshuahannan Dec 4, 2023
a3aebb3
Merge remote-tracking branch 'origin/standard-v2' into standard-v2
joshuahannan Dec 4, 2023
eb1dd95
change updated to use entitled reference
joshuahannan Dec 4, 2023
24d5952
remove custom destructors
joshuahannan Dec 12, 2023
456a980
remove resource destructor
turbolent Dec 13, 2023
ecf0b5b
generate
turbolent Dec 13, 2023
aebb56b
default destroy event, event args, id field, remove getID, go test up…
joshuahannan Jan 10, 2024
c0ff8f7
remove path functions, add view function, update view resolver names
joshuahannan Jan 11, 2024
30ef48a
add getIDs
joshuahannan Jan 11, 2024
2c9be03
remove view, add getIDs
joshuahannan Jan 12, 2024
b73ac84
add subNFTs method, update forwarder events
joshuahannan Jan 16, 2024
ded9217
add support for multiple type definitions
joshuahannan Jan 22, 2024
3c2b2d2
remove get NFT types, update basic NFT and UniversalCollection, and u…
joshuahannan Jan 22, 2024
bcf55c5
Update Cadence version
SupunS Jan 20, 2024
0a43997
add event emission functions
joshuahannan Jan 24, 2024
d896d25
revert event emission functions
joshuahannan Jan 24, 2024
4973179
update sdk and cadence deps
joshuahannan Jan 25, 2024
56b6daf
update to SDK v1.0.0-M1
turbolent Jan 25, 2024
2118663
update to SDK v1.0.0-M1
turbolent Jan 25, 2024
d2b571f
remove event functions, make update access contract, fix some tests
joshuahannan Jan 25, 2024
58c75f2
update transactions get get Go tests passing
joshuahannan Jan 31, 2024
fdeb8ee
sync with master
joshuahannan Jan 31, 2024
912407f
add collection public interface back and remove some go tests
joshuahannan Feb 1, 2024
ebdb001
use receiver and collection in public linked type
joshuahannan Feb 1, 2024
e8c999a
use correct public linked types and get most tests passing
joshuahannan Feb 5, 2024
322e5f5
add updated FT
joshuahannan Feb 5, 2024
86ee8c3
remove burner
joshuahannan Feb 5, 2024
e3b2202
add generic setup and transfer transactions
joshuahannan Feb 9, 2024
48f42d9
update generic transfer transactions and add tests
joshuahannan Feb 13, 2024
1bf01d6
change address arguments to strings
joshuahannan Feb 14, 2024
cd2c42e
use withhexprefix
joshuahannan Feb 14, 2024
938a91c
use latest import syntax update readme and use correct borrow syntax
joshuahannan Mar 5, 2024
9026973
update ci to use flow-c1
joshuahannan Mar 5, 2024
bd7ca70
add info about old branch to README
joshuahannan Mar 6, 2024
e135b94
update previewnet address
joshuahannan Mar 8, 2024
024d61f
update view resolver comments
joshuahannan Mar 11, 2024
3a595a3
remove basic NFT and UniversalCollection
joshuahannan Mar 11, 2024
058d82e
Make ExampleNFT compatible for contract update
SupunS Mar 21, 2024
d72353a
Add back the type assertion for the deposited token
SupunS Mar 22, 2024
c949828
Make the collection path backward compatible
SupunS Mar 25, 2024
e69a42c
remove docs, INFT, and update paths
joshuahannan Mar 26, 2024
c01c72c
make ci
joshuahannan Mar 26, 2024
1b8384e
Cleanup redundant paths
SupunS Mar 28, 2024
067c816
re-add royalties to mint and address PR comments
joshuahannan Apr 1, 2024
87ea0d0
fix FungibleToken import address
joshuahannan Apr 1, 2024
7cbc99e
add pre-conditions to createEmpty and update dependencies
joshuahannan Apr 2, 2024
74687e7
make emitNFTUpdated access all
joshuahannan Apr 2, 2024
808e6db
reorg transactions and scripts
joshuahannan Apr 3, 2024
f122847
fix import placeholders
joshuahannan Apr 9, 2024
cd08f8b
add correct getLength impl
joshuahannan Apr 10, 2024
17a6587
add NFT storage requirement and forEachID function
joshuahannan Apr 11, 2024
8d4f496
add def impl for getLength and fix iterator test
joshuahannan Apr 11, 2024
68c66a2
update iterate script and test access(all)
joshuahannan Apr 11, 2024
a0d5ecc
update comments
joshuahannan Apr 11, 2024
39036ac
use capabilities borrow
joshuahannan Apr 15, 2024
4a6f42d
make ownedNFTs access(all)
joshuahannan Apr 24, 2024
fa1f400
remove Owner entitlement
joshuahannan Apr 29, 2024
40c3de7
merge evm view from master
joshuahannan Apr 29, 2024
c640157
Update ExampleNFT v2 with EVMBridgedMetadata view from master (#215)
sisyphusSmiling May 2, 2024
c614396
resolve conflicts
joshuahannan May 2, 2024
f741cb5
update to latest CLI and emulator and fix txs and tests to not use op…
joshuahannan May 6, 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.19'
go-version: '1.20'
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.5.0
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
- name: Flow CLI Version
run: flow version
run: flow-c1 version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Run tests
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
node_modules
node_modules
coverage.json
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
test:
$(MAKE) generate -C lib/go
$(MAKE) test -C lib/go
flow test --cover --covercode="contracts" tests/test_*.cdc
flow-c1 test --cover --covercode="contracts" tests/test_*.cdc

.PHONY: ci
ci:
$(MAKE) ci -C lib/go
flow test --cover --covercode="contracts" tests/test_*.cdc
flow-c1 test --cover --covercode="contracts" tests/test_*.cdc
132 changes: 42 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

This standard defines the minimum functionality required to
implement a safe, secure, and easy-to-use non-fungible token
contract on the [Flow blockchain](https://flow.com/
contract on the [Flow blockchain](https://flow.com/)

The version of the contracts in the `master` branch is the
Cadence 1.0 version of the contracts and is not the same
as the ones that are currently deployed to testnet and mainnet.
See the `cadence-0.42` branch for the currently deployed versions.

## What is Cadence?

Expand All @@ -26,18 +31,21 @@ There is no need to deploy them yourself.

Note: With the emulator, you must use the -contracts flag to deploy these contracts.

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x631e88ae7f1d7c20` |
| Mainnet | `0x1d7e57aa55817448` |
| Network | Contract Address |
| ------------------| -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| PreviewNet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x631e88ae7f1d7c20` |
| Mainnet | `0x1d7e57aa55817448` |

## Core Types

Contracts that implement the `NonFungibleToken` interface are required to implement two resource interfaces:
Contracts that implement the `NonFungibleToken` interface are expected
to utilize two resource interfaces:

- `NFT` - A resource that describes the structure of a single NFT.
- `Collection` - A resource that can hold multiple NFTs of the same type and defines ways
- `NFT` - A resource interface that describes the structure of a single NFT.
- `Collection` - A resource interface that describes an object
that can hold multiple NFTs of the same type and defines ways
to deposit, withdraw, and query information about the stored NFTs.

Users typically store one collection per NFT type, saved at a well-known location in their account storage.
Expand All @@ -47,69 +55,32 @@ Contracts that implement the `NonFungibleToken` interface are required to implem
## Core Features

The `NonFungibleToken` contract defines the following set of functionality
that must be included in each implementation:
that should be included in each implementation:

### Create a new NFT collection

Create a new collection using the `Token.createEmptyCollection()` function.
Create a new collection using the `Token.createEmptyCollection(nftType: Type)` function.

This function MUST return an empty collection that contains no NFTs.

Users typically save new collections to a contract-defined location in their account
and link the `NonFungibleToken.CollectionPublic` interface as a public capability.

```cadence
let collection <- ExampleNFT.createEmptyCollection()

account.save(<-collection, to: ExampleNFT.CollectionStoragePath)

// create a public capability for the collection
account.link<&{NonFungibleToken.CollectionPublic}>(
ExampleNFT.CollectionPublicPath,
target: ExampleNFT.CollectionStoragePath
)
```
and public a capability to their collection.

### Withdraw an NFT

Withdraw an `NFT` from a `Collection` using the [`withdraw()`](contracts/ExampleNFT.cdc#L36-L42) function.
This function emits the [`Withdraw`](contracts/ExampleNFT.cdc#L12) event.

```cadence
let collectionRef = account.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath)
?? panic("Could not borrow a reference to the owner's collection")

// withdraw the NFT from the owner's collection
let nft <- collectionRef.withdraw(withdrawID: 42)
```
Withdraw an `NFT` from a `Collection` using the [`withdraw()`](contracts/ExampleNFT.cdc#L160) function.
This function emits the [`NonFungibleToken.Withdrawn`](contracts/NonFungibleToken.cdc#L78) event automatically.

### Deposit an NFT

Deposit an `NFT` into a `Collection` using the [`deposit()`](contracts/ExampleNFT.cdc#L46-L57) function.
This function emits the [`Deposit`](contracts/ExampleNFT.cdc#L13) event.

This function is available on the `NonFungibleToken.CollectionPublic` interface,
which accounts publish as public capability.
This capability allows anybody to deposit an NFT into a collection
without accessing the entire collection.

```cadence
let nft: ExampleNFT.NFT

// ...

let collection = account.getCapability(ExampleNFT.CollectionPublicPath)
.borrow<&{NonFungibleToken.CollectionPublic}>()
?? panic("Could not borrow a reference to the receiver's collection")

collection.deposit(token: <-nft)
```
Deposit an `NFT` into a `Collection` using the [`deposit()`](contracts/ExampleNFT.cdc#L169-L176) function.
This function emits the [`NonFungibleToken.Deposited`](contracts/NonFungibleToken.cdc#L86) event automatically.

#### ⚠️ Important

In order to comply with the deposit function in the interface,
an implementation MUST take a `@NonFungibleToken.NFT` resource as an argument.
This means that anyone can send a resource object that conforms to `@NonFungibleToken.NFT` to a deposit function.
an implementation MUST take a `@{NonFungibleToken.NFT}` resource as an argument.
This means that anyone can send a resource object that conforms to `{NonFungibleToken.NFT}` to a deposit function.
In an implementation, you MUST cast the `token` as your specific token type before depositing it or you will
deposit another token type into your collection. For example:

Expand All @@ -120,18 +91,17 @@ let token <- token as! @ExampleNFT.NFT

### List NFTs in an account

Return a list of NFTs in a `Collection` using the [`getIDs`](contracts/ExampleNFT.cdc#L59-L62) function.
Return a list of NFTs in a `Collection` using the [`getIDs`](contracts/ExampleNFT.cdc#L179) function.

This function is available on the `NonFungibleToken.CollectionPublic` interface,
which accounts publish as public capability.
### Return the NFT type that a collection can accept in a deposit

```cadence
let collection = account.getCapability(ExampleNFT.CollectionPublicPath)
.borrow<&{NonFungibleToken.CollectionPublic}>()
?? panic("Could not borrow a reference to the receiver's collection")
Return types of NFTs that a `Collection` can accept in a deposit
using the [`getSupportedNFTTypes`](contracts/ExampleNFT.cdc#L143-L157) functions.

let ids = collection.getIDs()
```
### Get Available SubNFTs, if any

Some NFTs can own other NFTs, the standard provides a [function](contracts/NonFungibleToken.cdc#L111-L131) that
projects can optionally implement to return information the owned NFTs.

## NFT Metadata

Expand All @@ -157,29 +127,6 @@ including the name, description, image and owner.

**Source: [get_nft_metadata.cdc](scripts/get_nft_metadata.cdc)**

```cadence
// Get the regular public capability
let collection = account.getCapability(ExampleNFT.CollectionPublicPath)
.borrow<&{ExampleNFT.ExampleNFTCollectionPublic}>()
?? panic("Could not borrow a reference to the collection")

// Borrow a reference to the NFT as usual
let nft = collection.borrowExampleNFT(id: 42)
?? panic("Could not borrow a reference to the NFT")

// Call the resolveView method
// Provide the type of the view that you want to resolve
// View types are defined in the MetadataViews contract
// You can see if an NFT supports a specific view type by using the `getViews()` method
if let view = nft.resolveView(Type<MetadataViews.Display>()) {
let display = view as! MetadataViews.Display

log(display.name)
log(display.description)
log(display.thumbnail)
}
```

### How to implement metadata

The [example NFT contract](contracts/ExampleNFT.cdc) shows a basic example
Expand Down Expand Up @@ -245,13 +192,18 @@ but without most of the downsides.
## How to test the standard

If you want to test out these contracts, we recommend either testing them
with the [Flow Playground](https://play.onflow.org)
with the [Flow Playground](https://play.flow.com)
or with the [Visual Studio Code Extension](https://github.com/onflow/flow/blob/master/docs/vscode-extension.md#cadence-visual-studio-code-extension).

The steps to follow are:

1. Deploy `NonFungibleToken.cdc`
2. Deploy `ExampleNFT.cdc`, importing `NonFungibleToken` from the address you deployed it to.
1. Deploy `ViewResolver.cdc`
joshuahannan marked this conversation as resolved.
Show resolved Hide resolved
2. Deploy `NonFungibleToken.cdc`, importing `ViewResolver`.
3. Deploy `ExampleNFT.cdc`, importing `NonFungibleToken`.

If you are not making any modifications to the standard contracts,
they are already deployed to the addresses listed above and you can just import
from those directly instead of deploying them yourself.

Then you can experiment with some of the other transactions and scripts in `transactions/`
or even write your own. You'll need to replace some of the import address placeholders with addresses that you deploy to, as well as some of the transaction arguments.
Expand Down
Loading
Loading