@flowtyio/flow-contracts 0.1.0-beta.16 → 0.1.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/NonFungibleToken.cdc +17 -10
- package/contracts/dapper/TopShot.cdc +8 -8
- package/contracts/dapper/offers/OffersV2.cdc +3 -3
- package/contracts/dapper/offers/Resolver.cdc +2 -2
- package/contracts/example/ExampleNFT.cdc +2 -2
- package/contracts/flow-utils/ScopedNFTProviders.cdc +4 -4
- package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +5 -8
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +7 -10
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +2 -2
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +2 -2
- package/package.json +1 -1
|
@@ -49,9 +49,6 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
49
49
|
/// An entitlement for allowing updates and update events for an NFT
|
|
50
50
|
access(all) entitlement Update
|
|
51
51
|
|
|
52
|
-
/// entitlement for owner that grants Withdraw and Update
|
|
53
|
-
access(all) entitlement Owner
|
|
54
|
-
|
|
55
52
|
/// Event that contracts should emit when the metadata of an NFT is updated
|
|
56
53
|
/// It can only be emitted by calling the `emitNFTUpdated` function
|
|
57
54
|
/// with an `Updatable` entitled reference to the NFT that was updated
|
|
@@ -63,7 +60,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
63
60
|
/// and query the updated metadata from the owners' collections.
|
|
64
61
|
///
|
|
65
62
|
access(all) event Updated(type: String, id: UInt64, uuid: UInt64, owner: Address?)
|
|
66
|
-
access(
|
|
63
|
+
access(all) view fun emitNFTUpdated(_ nftRef: auth(Update) &{NonFungibleToken.NFT})
|
|
67
64
|
{
|
|
68
65
|
emit Updated(type: nftRef.getType().identifier, id: nftRef.id, uuid: nftRef.uuid, owner: nftRef.owner?.address)
|
|
69
66
|
}
|
|
@@ -85,9 +82,6 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
85
82
|
///
|
|
86
83
|
access(all) event Deposited(type: String, id: UInt64, uuid: UInt64, to: Address?, collectionUUID: UInt64)
|
|
87
84
|
|
|
88
|
-
/// Included for backwards-compatibility
|
|
89
|
-
access(all) resource interface INFT: NFT {}
|
|
90
|
-
|
|
91
85
|
/// Interface that the NFTs must conform to
|
|
92
86
|
///
|
|
93
87
|
access(all) resource interface NFT: ViewResolver.Resolver {
|
|
@@ -105,6 +99,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
105
99
|
access(all) fun createEmptyCollection(): @{Collection} {
|
|
106
100
|
post {
|
|
107
101
|
result.getLength() == 0: "The created collection must be empty!"
|
|
102
|
+
result.isSupportedNFTType(type: self.getType()): "The created collection must support this NFT type"
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
105
|
|
|
@@ -141,7 +136,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
141
136
|
/// withdraw removes an NFT from the collection and moves it to the caller
|
|
142
137
|
/// It does not specify whether the ID is UUID or not
|
|
143
138
|
/// @param withdrawID: The id of the NFT to withdraw from the collection
|
|
144
|
-
access(Withdraw
|
|
139
|
+
access(Withdraw) fun withdraw(withdrawID: UInt64): @{NFT} {
|
|
145
140
|
post {
|
|
146
141
|
result.id == withdrawID: "The ID of the withdrawn token must be the same as the requested ID"
|
|
147
142
|
emit Withdrawn(type: result.getType().identifier, id: result.id, uuid: result.uuid, from: self.owner?.address, providerUUID: self.uuid)
|
|
@@ -174,6 +169,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
174
169
|
access(all) fun deposit(token: @{NFT})
|
|
175
170
|
access(all) view fun getLength(): Int
|
|
176
171
|
access(all) view fun getIDs(): [UInt64]
|
|
172
|
+
access(all) fun forEachID(_ f: fun (UInt64): Bool): Void
|
|
177
173
|
access(all) view fun borrowNFT(_ id: UInt64): &{NFT}?
|
|
178
174
|
}
|
|
179
175
|
|
|
@@ -182,6 +178,8 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
182
178
|
///
|
|
183
179
|
access(all) resource interface Collection: Provider, Receiver, CollectionPublic, ViewResolver.ResolverCollection {
|
|
184
180
|
|
|
181
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
182
|
+
|
|
185
183
|
/// deposit takes a NFT as an argument and stores it in the collection
|
|
186
184
|
/// @param token: The NFT to deposit into the collection
|
|
187
185
|
access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
|
|
@@ -196,7 +194,16 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
196
194
|
|
|
197
195
|
/// Gets the amount of NFTs stored in the collection
|
|
198
196
|
/// @return An integer indicating the size of the collection
|
|
199
|
-
access(all) view fun getLength(): Int
|
|
197
|
+
access(all) view fun getLength(): Int {
|
|
198
|
+
return self.ownedNFTs.length
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// Allows a given function to iterate through the list
|
|
202
|
+
/// of owned NFT IDs in a collection without first
|
|
203
|
+
/// having to load the entire list into memory
|
|
204
|
+
access(all) fun forEachID(_ f: fun (UInt64): Bool): Void {
|
|
205
|
+
self.ownedNFTs.forEachKey(f)
|
|
206
|
+
}
|
|
200
207
|
|
|
201
208
|
/// Borrows a reference to an NFT stored in the collection
|
|
202
209
|
/// If the NFT with the specified ID is not in the collection,
|
|
@@ -231,4 +238,4 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
231
238
|
result.getIDs().length == 0: "The created collection must be empty!"
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
|
-
}
|
|
241
|
+
}
|
|
@@ -1060,7 +1060,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1060
1060
|
access(all) resource Collection: MomentCollectionPublic, NonFungibleToken.Collection {
|
|
1061
1061
|
// Dictionary of Moment conforming tokens
|
|
1062
1062
|
// NFT is a resource type with a UInt64 ID field
|
|
1063
|
-
access(
|
|
1063
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
1064
1064
|
|
|
1065
1065
|
init() {
|
|
1066
1066
|
self.ownedNFTs <- {}
|
|
@@ -1098,7 +1098,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1098
1098
|
// that is to be removed from the Collection
|
|
1099
1099
|
//
|
|
1100
1100
|
// returns: @NonFungibleToken.NFT the token that was withdrawn
|
|
1101
|
-
access(NonFungibleToken.Withdraw
|
|
1101
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
1102
1102
|
|
|
1103
1103
|
// Borrow nft and check if locked
|
|
1104
1104
|
let nft = self.borrowNFT(withdrawID)
|
|
@@ -1124,7 +1124,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1124
1124
|
// Returns: @NonFungibleToken.Collection: A collection that contains
|
|
1125
1125
|
// the withdrawn moments
|
|
1126
1126
|
//
|
|
1127
|
-
access(NonFungibleToken.Withdraw
|
|
1127
|
+
access(NonFungibleToken.Withdraw) fun batchWithdraw(ids: [UInt64]): @{NonFungibleToken.Collection} {
|
|
1128
1128
|
// Create a new empty Collection
|
|
1129
1129
|
var batchCollection <- create Collection()
|
|
1130
1130
|
|
|
@@ -1181,7 +1181,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1181
1181
|
|
|
1182
1182
|
// lock takes a token id and a duration in seconds and locks
|
|
1183
1183
|
// the moment for that duration
|
|
1184
|
-
access(NonFungibleToken.Update
|
|
1184
|
+
access(NonFungibleToken.Update) fun lock(id: UInt64, duration: UFix64) {
|
|
1185
1185
|
// Remove the nft from the Collection
|
|
1186
1186
|
let token <- self.ownedNFTs.remove(key: id)
|
|
1187
1187
|
?? panic("Cannot lock: Moment does not exist in the collection")
|
|
@@ -1195,7 +1195,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1195
1195
|
|
|
1196
1196
|
// batchLock takes an array of token ids and a duration in seconds
|
|
1197
1197
|
// it iterates through the ids and locks each for the specified duration
|
|
1198
|
-
access(NonFungibleToken.Update
|
|
1198
|
+
access(NonFungibleToken.Update) fun batchLock(ids: [UInt64], duration: UFix64) {
|
|
1199
1199
|
// Iterate through the ids and lock them
|
|
1200
1200
|
for id in ids {
|
|
1201
1201
|
self.lock(id: id, duration: duration)
|
|
@@ -1204,7 +1204,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1204
1204
|
|
|
1205
1205
|
// unlock takes a token id and attempts to unlock it
|
|
1206
1206
|
// TopShotLocking.unlockNFT contains business logic around unlock eligibility
|
|
1207
|
-
access(NonFungibleToken.Update
|
|
1207
|
+
access(NonFungibleToken.Update) fun unlock(id: UInt64) {
|
|
1208
1208
|
// Remove the nft from the Collection
|
|
1209
1209
|
let token <- self.ownedNFTs.remove(key: id)
|
|
1210
1210
|
?? panic("Cannot lock: Moment does not exist in the collection")
|
|
@@ -1218,7 +1218,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1218
1218
|
|
|
1219
1219
|
// batchUnlock takes an array of token ids
|
|
1220
1220
|
// it iterates through the ids and unlocks each if they are eligible
|
|
1221
|
-
access(NonFungibleToken.Update
|
|
1221
|
+
access(NonFungibleToken.Update) fun batchUnlock(ids: [UInt64]) {
|
|
1222
1222
|
// Iterate through the ids and unlocks them
|
|
1223
1223
|
for id in ids {
|
|
1224
1224
|
self.unlock(id: id)
|
|
@@ -1230,7 +1230,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1230
1230
|
//
|
|
1231
1231
|
// Parameters: ids: An array of NFT IDs
|
|
1232
1232
|
// to be destroyed from the Collection
|
|
1233
|
-
access(NonFungibleToken.Update
|
|
1233
|
+
access(NonFungibleToken.Update) fun destroyMoments(ids: [UInt64]) {
|
|
1234
1234
|
let topShotLockingAdmin = TopShot.account.storage.borrow<&TopShotLocking.Admin>(from: TopShotLocking.AdminStoragePath())
|
|
1235
1235
|
?? panic("No TopShotLocking admin resource in storage")
|
|
1236
1236
|
|
|
@@ -130,7 +130,7 @@ access(all) contract OffersV2 {
|
|
|
130
130
|
// This will accept the offer if provided with the NFT id that matches the Offer
|
|
131
131
|
//
|
|
132
132
|
access(all) fun accept(
|
|
133
|
-
item: @{NonFungibleToken.
|
|
133
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
134
134
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
135
135
|
): Void
|
|
136
136
|
// getDetails
|
|
@@ -210,7 +210,7 @@ access(all) contract OffersV2 {
|
|
|
210
210
|
// - Provided with a NFT matching the NFT Type within the Offer details.
|
|
211
211
|
//
|
|
212
212
|
access(all) fun accept(
|
|
213
|
-
item: @{NonFungibleToken.
|
|
213
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
214
214
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
215
215
|
): Void {
|
|
216
216
|
|
|
@@ -221,7 +221,7 @@ access(all) contract OffersV2 {
|
|
|
221
221
|
|
|
222
222
|
let resolverCapability = self.resolverCapability.borrow() ?? panic("could not borrow resolver")
|
|
223
223
|
let resolverResult = resolverCapability.checkOfferResolver(
|
|
224
|
-
item: &item as &{NonFungibleToken.
|
|
224
|
+
item: &item as &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
225
225
|
offerParamsString: self.details.offerParamsString,
|
|
226
226
|
offerParamsUInt64: self.details.offerParamsUInt64,
|
|
227
227
|
offerParamsUFix64: self.details.offerParamsUFix64,
|
|
@@ -15,7 +15,7 @@ access(all) contract Resolver {
|
|
|
15
15
|
// which is used within the Resolver resource for offer acceptance validation
|
|
16
16
|
access(all) resource interface ResolverPublic {
|
|
17
17
|
access(all) fun checkOfferResolver(
|
|
18
|
-
item: &{NonFungibleToken.
|
|
18
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
19
19
|
offerParamsString: {String:String},
|
|
20
20
|
offerParamsUInt64: {String:UInt64},
|
|
21
21
|
offerParamsUFix64: {String:UFix64}): Bool
|
|
@@ -28,7 +28,7 @@ access(all) contract Resolver {
|
|
|
28
28
|
// Holds the validation rules for resolver each type of supported ResolverType
|
|
29
29
|
// Function returns TRUE if the provided nft item passes the criteria for exchange
|
|
30
30
|
access(all) fun checkOfferResolver(
|
|
31
|
-
item: &{NonFungibleToken.
|
|
31
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
32
32
|
offerParamsString: {String:String},
|
|
33
33
|
offerParamsUInt64: {String:UInt64},
|
|
34
34
|
offerParamsUFix64: {String:UFix64}): Bool {
|
|
@@ -164,7 +164,7 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
164
164
|
|
|
165
165
|
// dictionary of NFT conforming tokens
|
|
166
166
|
// NFT is a resource type with an `UInt64` ID field
|
|
167
|
-
access(
|
|
167
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
168
168
|
|
|
169
169
|
init () {
|
|
170
170
|
self.ownedNFTs <- {}
|
|
@@ -206,7 +206,7 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
// withdraw removes an NFT from the collection and moves it to the caller
|
|
209
|
-
access(NonFungibleToken.Withdraw
|
|
209
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
210
210
|
let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
|
|
211
211
|
|
|
212
212
|
emit Withdraw(id: token.id, from: self.owner?.address)
|
|
@@ -78,7 +78,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
78
78
|
//
|
|
79
79
|
// Wrapper around an NFT Provider that is restricted to specific ids.
|
|
80
80
|
access(all) resource ScopedNFTProvider: NonFungibleToken.Provider {
|
|
81
|
-
access(self) let provider: Capability<auth(NonFungibleToken.Withdraw
|
|
81
|
+
access(self) let provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
|
|
82
82
|
access(self) let filters: [{NFTFilter}]
|
|
83
83
|
|
|
84
84
|
// block timestamp that this provider can no longer be used after
|
|
@@ -91,7 +91,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
91
91
|
return false
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw
|
|
94
|
+
access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>, filters: [{NFTFilter}], expiration: UFix64?) {
|
|
95
95
|
self.provider = provider
|
|
96
96
|
self.expiration = expiration
|
|
97
97
|
self.filters = filters
|
|
@@ -125,7 +125,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
125
125
|
return self.provider.check()
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
access(NonFungibleToken.Withdraw
|
|
128
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
129
129
|
pre {
|
|
130
130
|
!self.isExpired(): "provider has expired"
|
|
131
131
|
}
|
|
@@ -157,7 +157,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
access(all) fun createScopedNFTProvider(
|
|
160
|
-
provider: Capability<auth(NonFungibleToken.Withdraw
|
|
160
|
+
provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>,
|
|
161
161
|
filters: [{NFTFilter}],
|
|
162
162
|
expiration: UFix64?
|
|
163
163
|
): @ScopedNFTProvider {
|
|
@@ -34,15 +34,12 @@ access(all) contract FTVaultFactory {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return cap
|
|
37
|
+
let cap = acct.capabilities.get<&{FungibleToken.Vault}>(path)
|
|
38
|
+
if !cap.check() {
|
|
39
|
+
return nil
|
|
43
40
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
41
|
+
|
|
42
|
+
return cap
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
}
|
|
@@ -5,11 +5,11 @@ access(all) contract NFTProviderAndCollectionFactory {
|
|
|
5
5
|
access(all) struct WithdrawFactory: CapabilityFactory.Factory {
|
|
6
6
|
access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
|
|
7
7
|
if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
|
|
8
|
-
if !con.capability.check<auth(NonFungibleToken.Withdraw
|
|
8
|
+
if !con.capability.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>() {
|
|
9
9
|
return nil
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return con.capability as! Capability<auth(NonFungibleToken.Withdraw
|
|
12
|
+
return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
return nil
|
|
@@ -34,15 +34,12 @@ access(all) contract NFTProviderAndCollectionFactory {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return cap
|
|
37
|
+
let cap = acct.capabilities.get<&{NonFungibleToken.Collection}>(path)
|
|
38
|
+
if !cap.check() {
|
|
39
|
+
return nil
|
|
43
40
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
41
|
+
|
|
42
|
+
return cap
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
}
|
|
@@ -5,11 +5,11 @@ access(all) contract NFTProviderAndCollectionFactory {
|
|
|
5
5
|
access(all) struct Factory: CapabilityFactory.Factory {
|
|
6
6
|
access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
|
|
7
7
|
if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
|
|
8
|
-
if !con.capability.check<auth(NonFungibleToken.Withdraw
|
|
8
|
+
if !con.capability.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>() {
|
|
9
9
|
return nil
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return con.capability as! Capability<auth(NonFungibleToken.Withdraw
|
|
12
|
+
return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
return nil
|
|
@@ -5,11 +5,11 @@ access(all) contract NFTProviderFactory {
|
|
|
5
5
|
access(all) struct Factory: CapabilityFactory.Factory {
|
|
6
6
|
access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
|
|
7
7
|
if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
|
|
8
|
-
if !con.capability.check<auth(NonFungibleToken.Withdraw
|
|
8
|
+
if !con.capability.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>() {
|
|
9
9
|
return nil
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return con.capability as! Capability<auth(NonFungibleToken.Withdraw
|
|
12
|
+
return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
return nil
|