@flowtyio/flow-contracts 0.1.0-beta.2 → 0.1.0-beta.20

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.
Files changed (44) hide show
  1. package/contracts/Burner.cdc +44 -0
  2. package/contracts/FlowStorageFees.cdc +15 -15
  3. package/contracts/FlowToken.cdc +29 -78
  4. package/contracts/FungibleToken.cdc +80 -53
  5. package/contracts/FungibleTokenMetadataViews.cdc +13 -25
  6. package/contracts/MetadataViews.cdc +107 -50
  7. package/contracts/NonFungibleToken.cdc +110 -60
  8. package/contracts/TokenForwarding.cdc +19 -11
  9. package/contracts/ViewResolver.cdc +20 -16
  10. package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
  11. package/contracts/dapper/FlowUtilityToken.cdc +107 -40
  12. package/contracts/dapper/TopShot.cdc +323 -259
  13. package/contracts/dapper/TopShotLocking.cdc +41 -15
  14. package/contracts/dapper/offers/DapperOffersV2.cdc +36 -40
  15. package/contracts/dapper/offers/OffersV2.cdc +52 -51
  16. package/contracts/dapper/offers/Resolver.cdc +13 -12
  17. package/contracts/emerald-city/FLOAT.cdc +259 -254
  18. package/contracts/example/ExampleNFT.cdc +419 -0
  19. package/contracts/example/ExampleToken.cdc +302 -0
  20. package/contracts/find/FindViews.cdc +357 -353
  21. package/contracts/flow-utils/AddressUtils.cdc +20 -23
  22. package/contracts/flow-utils/ArrayUtils.cdc +10 -11
  23. package/contracts/flow-utils/ScopedFTProviders.cdc +27 -19
  24. package/contracts/flow-utils/ScopedNFTProviders.cdc +31 -26
  25. package/contracts/flow-utils/StringUtils.cdc +24 -37
  26. package/contracts/hybrid-custody/CapabilityDelegator.cdc +29 -26
  27. package/contracts/hybrid-custody/CapabilityFactory.cdc +21 -18
  28. package/contracts/hybrid-custody/CapabilityFilter.cdc +42 -24
  29. package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
  30. package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
  31. package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
  32. package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
  33. package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
  34. package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
  35. package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +45 -0
  36. package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
  37. package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
  38. package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +16 -4
  39. package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
  40. package/contracts/lost-and-found/LostAndFound.cdc +14 -14
  41. package/contracts/nft-catalog/NFTCatalog.cdc +60 -64
  42. package/contracts/nft-catalog/NFTCatalogAdmin.cdc +28 -27
  43. package/flow.json +38 -1
  44. package/package.json +1 -1
@@ -4,21 +4,21 @@ import "ViewResolver"
4
4
 
5
5
  /// This contract implements the metadata standard proposed
6
6
  /// in FLIP-1087.
7
- ///
7
+ ///
8
8
  /// Ref: https://github.com/onflow/flips/blob/main/application/20220811-fungible-tokens-metadata.md
9
- ///
9
+ ///
10
10
  /// Structs and resources can implement one or more
11
11
  /// metadata types, called views. Each view type represents
12
12
  /// a different kind of metadata.
13
13
  ///
14
14
  access(all) contract FungibleTokenMetadataViews {
15
15
 
16
- /// FTView wraps FTDisplay and FTVaultData, and is used to give a complete
17
- /// picture of a Fungible Token. Most Fungible Token contracts should
16
+ /// FTView wraps FTDisplay and FTVaultData, and is used to give a complete
17
+ /// picture of a Fungible Token. Most Fungible Token contracts should
18
18
  /// implement this view.
19
19
  ///
20
20
  access(all) struct FTView {
21
- access(all) let ftDisplay: FTDisplay?
21
+ access(all) let ftDisplay: FTDisplay?
22
22
  access(all) let ftVaultData: FTVaultData?
23
23
  view init(
24
24
  ftDisplay: FTDisplay?,
@@ -45,8 +45,8 @@ access(all) contract FungibleTokenMetadataViews {
45
45
  )
46
46
  }
47
47
 
48
- /// View to expose the information needed to showcase this FT.
49
- /// This can be used by applications to give an overview and
48
+ /// View to expose the information needed to showcase this FT.
49
+ /// This can be used by applications to give an overview and
50
50
  /// graphics of the FT.
51
51
  ///
52
52
  access(all) struct FTDisplay {
@@ -94,7 +94,7 @@ access(all) contract FungibleTokenMetadataViews {
94
94
  }
95
95
 
96
96
  /// Helper to get FTDisplay in a way that will return a typed optional.
97
- ///
97
+ ///
98
98
  /// @param viewResolver: A reference to the resolver resource
99
99
  /// @return An optional FTDisplay struct
100
100
  ///
@@ -108,7 +108,7 @@ access(all) contract FungibleTokenMetadataViews {
108
108
  }
109
109
 
110
110
  /// View to expose the information needed store and interact with a FT vault.
111
- /// This can be used by applications to setup a FT vault with proper
111
+ /// This can be used by applications to setup a FT vault with proper
112
112
  /// storage and public capabilities.
113
113
  ///
114
114
  access(all) struct FTVaultData {
@@ -121,22 +121,14 @@ access(all) contract FungibleTokenMetadataViews {
121
121
  /// Public path which must be linked to expose the balance and resolver public capabilities.
122
122
  access(all) let metadataPath: PublicPath
123
123
 
124
- /// Private path which should be linked to expose the provider capability to withdraw funds
125
- /// from the vault.
126
- access(all) let providerPath: PrivatePath
127
-
128
- /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
124
+ /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
129
125
  /// the `FungibleToken.Receiver` interface.
130
126
  access(all) let receiverLinkedType: Type
131
127
 
132
- /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
128
+ /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
133
129
  /// the `ViewResolver.Resolver` interfaces.
134
130
  access(all) let metadataLinkedType: Type
135
131
 
136
- /// Type that should be linked at the aforementioned private path. This
137
- /// is normally a restricted type with at a minimum the `FungibleToken.Provider` interface.
138
- access(all) let providerLinkedType: Type
139
-
140
132
  /// Function that allows creation of an empty FT vault that is intended
141
133
  /// to store the funds.
142
134
  access(all) let createEmptyVault: fun(): @{FungibleToken.Vault}
@@ -145,24 +137,19 @@ access(all) contract FungibleTokenMetadataViews {
145
137
  storagePath: StoragePath,
146
138
  receiverPath: PublicPath,
147
139
  metadataPath: PublicPath,
148
- providerPath: PrivatePath,
149
140
  receiverLinkedType: Type,
150
141
  metadataLinkedType: Type,
151
- providerLinkedType: Type,
152
142
  createEmptyVaultFunction: fun(): @{FungibleToken.Vault}
153
143
  ) {
154
144
  pre {
155
145
  receiverLinkedType.isSubtype(of: Type<&{FungibleToken.Receiver}>()): "Receiver public type must include FungibleToken.Receiver."
156
- metadataLinkedType.isSubtype(of: Type<&{ViewResolver.Resolver}>()): "Metadata public type must include ViewResolver.Resolver interfaces."
157
- providerLinkedType.isSubtype(of: Type<&{FungibleToken.Provider}>()): "Provider type must include FungibleToken.Provider interface."
146
+ metadataLinkedType.isSubtype(of: Type<&{FungibleToken.Vault}>()): "Metadata linked type must be a fungible token vault"
158
147
  }
159
148
  self.storagePath = storagePath
160
149
  self.receiverPath = receiverPath
161
150
  self.metadataPath = metadataPath
162
- self.providerPath = providerPath
163
151
  self.receiverLinkedType = receiverLinkedType
164
152
  self.metadataLinkedType = metadataLinkedType
165
- self.providerLinkedType = providerLinkedType
166
153
  self.createEmptyVault = createEmptyVaultFunction
167
154
  }
168
155
  }
@@ -190,3 +177,4 @@ access(all) contract FungibleTokenMetadataViews {
190
177
  }
191
178
  }
192
179
  }
180
+
@@ -126,15 +126,39 @@ access(all) contract MetadataViews {
126
126
  }
127
127
  }
128
128
 
129
- /// View to represent a file with an correspoiding mediaType.
130
- ///
129
+ /// A struct to represent a generic URI. May be used to represent the URI of
130
+ /// the NFT where the type of URI is not able to be determined (i.e. HTTP,
131
+ /// IPFS, etc.)
132
+ ///
133
+ access(all) struct URI: File {
134
+ /// The base URI prefix, if any. Not needed for all URIs, but helpful
135
+ /// for some use cases For example, updating a whole NFT collection's
136
+ /// image host easily
137
+ ///
138
+ access(all) let baseURI: String?
139
+ /// The URI string value
140
+ /// NOTE: this is set on init as a concatenation of the baseURI and the
141
+ /// value if baseURI != nil
142
+ ///
143
+ access(self) let value: String
144
+
145
+ access(all) view fun uri(): String {
146
+ return self.value
147
+ }
148
+
149
+ init(baseURI: String?, value: String) {
150
+ self.baseURI = baseURI
151
+ self.value = baseURI != nil ? baseURI!.concat(value) : value
152
+ }
153
+ }
154
+
131
155
  access(all) struct Media {
132
156
 
133
157
  /// File for the media
134
158
  ///
135
159
  access(all) let file: {File}
136
160
 
137
- /// media-type comes on the form of type/subtype as described here
161
+ /// media-type comes on the form of type/subtype as described here
138
162
  /// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
139
163
  ///
140
164
  access(all) let mediaType: String
@@ -185,7 +209,7 @@ access(all) contract MetadataViews {
185
209
  /// Helper to get License in a typesafe way
186
210
  ///
187
211
  /// @param viewResolver: A reference to the resolver resource
188
- /// @return A optional License struct
212
+ /// @return An optional License struct
189
213
  ///
190
214
  access(all) fun getLicense(_ viewResolver: &{ViewResolver.Resolver}) : License? {
191
215
  if let view = viewResolver.resolveView(Type<License>()) {
@@ -197,7 +221,7 @@ access(all) contract MetadataViews {
197
221
  }
198
222
 
199
223
  /// View to expose a URL to this item on an external site.
200
- /// This can be used by applications like .find and Blocto to direct users
224
+ /// This can be used by applications like .find and Blocto to direct users
201
225
  /// to the original link for an NFT or a project page that describes the NFT collection.
202
226
  /// eg https://www.my-nft-project.com/overview-of-nft-collection
203
227
  ///
@@ -212,7 +236,7 @@ access(all) contract MetadataViews {
212
236
  /// Helper to get ExternalURL in a typesafe way
213
237
  ///
214
238
  /// @param viewResolver: A reference to the resolver resource
215
- /// @return A optional ExternalURL struct
239
+ /// @return An optional ExternalURL struct
216
240
  ///
217
241
  access(all) fun getExternalURL(_ viewResolver: &{ViewResolver.Resolver}) : ExternalURL? {
218
242
  if let view = viewResolver.resolveView(Type<ExternalURL>()) {
@@ -223,27 +247,27 @@ access(all) contract MetadataViews {
223
247
  return nil
224
248
  }
225
249
 
226
- /// View that defines the composable royalty standard that gives marketplaces a
250
+ /// View that defines the composable royalty standard that gives marketplaces a
227
251
  /// unified interface to support NFT royalties.
228
252
  ///
229
253
  access(all) struct Royalty {
230
254
 
231
255
  /// Generic FungibleToken Receiver for the beneficiary of the royalty
232
256
  /// Can get the concrete type of the receiver with receiver.getType()
233
- /// Recommendation - Users should create a new link for a FlowToken
234
- /// receiver for this using `getRoyaltyReceiverPublicPath()`, and not
235
- /// use the default FlowToken receiver. This will allow users to update
257
+ /// Recommendation - Users should create a new link for a FlowToken
258
+ /// receiver for this using `getRoyaltyReceiverPublicPath()`, and not
259
+ /// use the default FlowToken receiver. This will allow users to update
236
260
  /// the capability in the future to use a more generic capability
237
261
  access(all) let receiver: Capability<&{FungibleToken.Receiver}>
238
262
 
239
- /// Multiplier used to calculate the amount of sale value transferred to
240
- /// royalty receiver. Note - It should be between 0.0 and 1.0
241
- /// Ex - If the sale value is x and multiplier is 0.56 then the royalty
263
+ /// Multiplier used to calculate the amount of sale value transferred to
264
+ /// royalty receiver. Note - It should be between 0.0 and 1.0
265
+ /// Ex - If the sale value is x and multiplier is 0.56 then the royalty
242
266
  /// value would be 0.56 * x.
243
267
  /// Generally percentage get represented in terms of basis points
244
- /// in solidity based smart contracts while cadence offers `UFix64`
245
- /// that already supports the basis points use case because its
246
- /// operations are entirely deterministic integer operations and support
268
+ /// in solidity based smart contracts while cadence offers `UFix64`
269
+ /// that already supports the basis points use case because its
270
+ /// operations are entirely deterministic integer operations and support
247
271
  /// up to 8 points of precision.
248
272
  access(all) let cut: UFix64
249
273
 
@@ -263,7 +287,7 @@ access(all) contract MetadataViews {
263
287
  }
264
288
 
265
289
  /// Wrapper view for multiple Royalty views.
266
- /// Marketplaces can query this `Royalties` struct from NFTs
290
+ /// Marketplaces can query this `Royalties` struct from NFTs
267
291
  /// and are expected to pay royalties based on these specifications.
268
292
  ///
269
293
  access(all) struct Royalties {
@@ -353,9 +377,9 @@ access(all) contract MetadataViews {
353
377
  view init(_ traits: [Trait]) {
354
378
  self.traits = traits
355
379
  }
356
-
380
+
357
381
  /// Adds a single Trait to the Traits view
358
- ///
382
+ ///
359
383
  /// @param Trait: The trait struct to be added
360
384
  ///
361
385
  access(all) fun addTrait(_ t: Trait) {
@@ -377,8 +401,8 @@ access(all) contract MetadataViews {
377
401
  return nil
378
402
  }
379
403
 
380
- /// Helper function to easily convert a dictionary to traits. For NFT
381
- /// collections that do not need either of the optional values of a Trait,
404
+ /// Helper function to easily convert a dictionary to traits. For NFT
405
+ /// collections that do not need either of the optional values of a Trait,
382
406
  /// this method should suffice to give them an array of valid traits.
383
407
  ///
384
408
  /// @param dict: The dictionary to be converted to Traits
@@ -494,7 +518,7 @@ access(all) contract MetadataViews {
494
518
  }
495
519
 
496
520
  /// View to expose rarity information for a single rarity
497
- /// Note that a rarity needs to have either score or description but it can
521
+ /// Note that a rarity needs to have either score or description but it can
498
522
  /// have both
499
523
  ///
500
524
  access(all) struct Rarity {
@@ -534,8 +558,8 @@ access(all) contract MetadataViews {
534
558
  return nil
535
559
  }
536
560
 
537
- /// NFTView wraps all Core views along `id` and `uuid` fields, and is used
538
- /// to give a complete picture of an NFT. Most NFTs should implement this
561
+ /// NFTView wraps all Core views along `id` and `uuid` fields, and is used
562
+ /// to give a complete picture of an NFT. Most NFTs should implement this
539
563
  /// view.
540
564
  ///
541
565
  access(all) struct NFTView {
@@ -569,7 +593,7 @@ access(all) contract MetadataViews {
569
593
  }
570
594
  }
571
595
 
572
- /// Helper to get an NFT view
596
+ /// Helper to get an NFT view
573
597
  ///
574
598
  /// @param id: The NFT id
575
599
  /// @param viewResolver: A reference to the resolver resource
@@ -594,7 +618,7 @@ access(all) contract MetadataViews {
594
618
  }
595
619
 
596
620
  /// View to expose the information needed store and retrieve an NFT.
597
- /// This can be used by applications to setup a NFT collection with proper
621
+ /// This can be used by applications to setup a NFT collection with proper
598
622
  /// storage and public capabilities.
599
623
  ///
600
624
  access(all) struct NFTCollectionData {
@@ -605,24 +629,13 @@ access(all) contract MetadataViews {
605
629
  /// including standard NFT interfaces and metadataviews interfaces
606
630
  access(all) let publicPath: PublicPath
607
631
 
608
- /// Private path which should be linked to expose the provider
609
- /// capability to withdraw NFTs from the collection holding NFTs
610
- access(all) let providerPath: PrivatePath
611
-
612
- /// Public collection type that is expected to provide sufficient read-only access to standard
613
- /// functions (deposit + getIDs + borrowNFT). For new
614
- /// collections, this may be set to be equal to the type specified in `publicLinkedType`.
632
+ /// The concrete type of the collection that is exposed to the public
633
+ /// now that entitlements exist, it no longer needs to be restricted to a specific interface
615
634
  access(all) let publicCollection: Type
616
635
 
617
- /// Type that should be linked at the aforementioned public path. This is normally a
618
- /// restricted type with many interfaces. Notably the
619
- /// `NFT.Receiver`, and `ViewResolver.ResolverCollection` interfaces are required.
636
+ /// Type that should be linked at the aforementioned public path
620
637
  access(all) let publicLinkedType: Type
621
638
 
622
- /// Type that should be linked at the aforementioned private path. This is normally
623
- /// a restricted type with at a minimum the `NFT.Provider` interface
624
- access(all) let providerLinkedType: Type
625
-
626
639
  /// Function that allows creation of an empty NFT collection that is intended to store
627
640
  /// this NFT.
628
641
  access(all) let createEmptyCollection: fun(): @{NonFungibleToken.Collection}
@@ -630,22 +643,17 @@ access(all) contract MetadataViews {
630
643
  view init(
631
644
  storagePath: StoragePath,
632
645
  publicPath: PublicPath,
633
- providerPath: PrivatePath,
634
646
  publicCollection: Type,
635
647
  publicLinkedType: Type,
636
- providerLinkedType: Type,
637
648
  createEmptyCollectionFunction: fun(): @{NonFungibleToken.Collection}
638
649
  ) {
639
650
  pre {
640
- publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Receiver, ViewResolver.ResolverCollection}>()): "Public type must include NonFungibleToken.Receiver and ViewResolver.ResolverCollection interfaces."
641
- providerLinkedType.isSubtype(of: Type<&{NonFungibleToken.Provider, ViewResolver.ResolverCollection}>()): "Provider type must include NonFungibleToken.Provider and ViewResolver.ResolverCollection interface."
651
+ publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Collection}>()): "Public type must be a subtype of NonFungibleToken.Collection interface."
642
652
  }
643
653
  self.storagePath=storagePath
644
654
  self.publicPath=publicPath
645
- self.providerPath = providerPath
646
655
  self.publicCollection=publicCollection
647
656
  self.publicLinkedType=publicLinkedType
648
- self.providerLinkedType = providerLinkedType
649
657
  self.createEmptyCollection=createEmptyCollectionFunction
650
658
  }
651
659
  }
@@ -665,7 +673,7 @@ access(all) contract MetadataViews {
665
673
  }
666
674
 
667
675
  /// View to expose the information needed to showcase this NFT's
668
- /// collection. This can be used by applications to give an overview and
676
+ /// collection. This can be used by applications to give an overview and
669
677
  /// graphics of the NFT collection this NFT belongs to.
670
678
  ///
671
679
  access(all) struct NFTCollectionDisplay {
@@ -681,7 +689,7 @@ access(all) contract MetadataViews {
681
689
  // Square-sized image to represent this collection.
682
690
  access(all) let squareImage: MetadataViews.Media
683
691
 
684
- // Banner-sized image for this collection, recommended to have a size near 1200x630.
692
+ // Banner-sized image for this collection, recommended to have a size near 1400x350.
685
693
  access(all) let bannerImage: MetadataViews.Media
686
694
 
687
695
  // Social links to reach this collection's social homepages.
@@ -705,7 +713,7 @@ access(all) contract MetadataViews {
705
713
  }
706
714
  }
707
715
 
708
- /// Helper to get NFTCollectionDisplay in a way that will return a typed
716
+ /// Helper to get NFTCollectionDisplay in a way that will return a typed
709
717
  /// Optional
710
718
  ///
711
719
  /// @param viewResolver: A reference to the resolver resource
@@ -719,4 +727,53 @@ access(all) contract MetadataViews {
719
727
  }
720
728
  return nil
721
729
  }
722
- }
730
+ /// This view may be used by Cadence-native projects to define their
731
+ /// contract- and token-level metadata according to EVM-compatible formats.
732
+ /// Several ERC standards (e.g. ERC20, ERC721, etc.) expose name and symbol
733
+ /// values to define assets as well as contract- & token-level metadata view
734
+ /// `tokenURI(uint256)` and `contractURI()` methods. This view enables
735
+ /// Cadence projects to define in their own contracts how they would like
736
+ /// their metadata to be defined when bridged to EVM.
737
+ ///
738
+ access(all) struct EVMBridgedMetadata {
739
+
740
+ /// The name of the asset
741
+ ///
742
+ access(all) let name: String
743
+
744
+ /// The symbol of the asset
745
+ ///
746
+ access(all) let symbol: String
747
+
748
+ /// The URI of the asset - this can either be contract-level or
749
+ /// token-level URI depending on where the metadata is resolved. It
750
+ /// is recommended to reference EVM metadata standards for how to best
751
+ /// prepare your view's formatted value.
752
+ ///
753
+ /// For example, while you may choose to take advantage of onchain
754
+ /// metadata, as is the case for most Cadence NFTs, you may also choose
755
+ /// to represent your asset's metadata in IPFS and assign this value as
756
+ /// an IPFSFile struct pointing to that IPFS file. Alternatively, you
757
+ /// may serialize your NFT's metadata and assign it as a JSON string
758
+ /// data URL representating the NFT's onchain metadata at the time this
759
+ /// view is resolved.
760
+ ///
761
+ access(all) let uri: {File}
762
+
763
+ init(name: String, symbol: String, uri: {File}) {
764
+ self.name = name
765
+ self.symbol = symbol
766
+ self.uri = uri
767
+ }
768
+ }
769
+
770
+ access(all) fun getEVMBridgedMetadata(_ viewResolver: &{ViewResolver.Resolver}) : EVMBridgedMetadata? {
771
+ if let view = viewResolver.resolveView(Type<EVMBridgedMetadata>()) {
772
+ if let v = view as? EVMBridgedMetadata {
773
+ return v
774
+ }
775
+ }
776
+ return nil
777
+ }
778
+
779
+ }