@flowtyio/flow-contracts 0.1.1 → 0.1.3

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.
@@ -42,6 +42,7 @@ access(all) contract DropTypes {
42
42
 
43
43
  access(all) let blockTimestamp: UInt64
44
44
  access(all) let blockHeight: UInt64
45
+ access(all) let royaltyRate: UFix64
45
46
 
46
47
  init(
47
48
  id: UInt64,
@@ -53,7 +54,8 @@ access(all) contract DropTypes {
53
54
  commissionRate: UFix64,
54
55
  nftType: Type,
55
56
  address: Address?,
56
- phases: [PhaseSummary]
57
+ phases: [PhaseSummary],
58
+ royaltyRate: UFix64
57
59
  ) {
58
60
  self.id = id
59
61
  self.display = Display(display)
@@ -75,6 +77,7 @@ access(all) contract DropTypes {
75
77
  let b = getCurrentBlock()
76
78
  self.blockHeight = b.height
77
79
  self.blockTimestamp = UInt64(b.timestamp)
80
+ self.royaltyRate = royaltyRate
78
81
  }
79
82
  }
80
83
 
@@ -109,6 +112,7 @@ access(all) contract DropTypes {
109
112
 
110
113
  access(all) let address: Address?
111
114
  access(all) let remainingForAddress: Int?
115
+ access(all) let maxPerMint: Int?
112
116
 
113
117
  access(all) let quote: Quote?
114
118
 
@@ -147,6 +151,8 @@ access(all) contract DropTypes {
147
151
  self.remainingForAddress = nil
148
152
  }
149
153
 
154
+ self.maxPerMint = d.addressVerifier.getMaxPerMint(addr: self.address, totalMinted: totalMinted ?? 0, data: {} as {String: AnyStruct})
155
+
150
156
  if paymentIdentifier != nil && quantity != nil {
151
157
  let price = d.pricer.getPrice(num: quantity!, paymentTokenType: CompositeType(paymentIdentifier!)!, minter: minter)
152
158
 
@@ -199,6 +205,14 @@ access(all) contract DropTypes {
199
205
  phaseSummaries.append(summary)
200
206
  }
201
207
 
208
+ var royaltyRate = 0.0
209
+ if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type<MetadataViews.Royalties>()) {
210
+ let royalties = tmpRoyalties as! MetadataViews.Royalties
211
+ for r in royalties.getRoyalties() {
212
+ royaltyRate = royaltyRate + r.cut
213
+ }
214
+ }
215
+
202
216
  let dropSummary = DropSummary(
203
217
  id: drop!.uuid,
204
218
  display: dropDetails.display,
@@ -209,7 +223,8 @@ access(all) contract DropTypes {
209
223
  commissionRate: dropDetails.commissionRate,
210
224
  nftType: CompositeType(dropDetails.nftType)!,
211
225
  address: minter,
212
- phases: phaseSummaries
226
+ phases: phaseSummaries,
227
+ royaltyRate: royaltyRate
213
228
  )
214
229
 
215
230
  return dropSummary
@@ -263,6 +278,14 @@ access(all) contract DropTypes {
263
278
  continue
264
279
  }
265
280
 
281
+ var royaltyRate = 0.0
282
+ if let tmpRoyalties = resolver!.resolveContractView(resourceType: nftType, viewType: Type<MetadataViews.Royalties>()) {
283
+ let royalties = tmpRoyalties as! MetadataViews.Royalties
284
+ for r in royalties.getRoyalties() {
285
+ royaltyRate = royaltyRate + r.cut
286
+ }
287
+ }
288
+
266
289
  summaries.append(DropSummary(
267
290
  id: drop!.uuid,
268
291
  display: dropDetails.display,
@@ -273,7 +296,8 @@ access(all) contract DropTypes {
273
296
  commissionRate: dropDetails.commissionRate,
274
297
  nftType: CompositeType(dropDetails.nftType)!,
275
298
  address: minter,
276
- phases: phaseSummaries
299
+ phases: phaseSummaries,
300
+ royaltyRate: royaltyRate
277
301
  ))
278
302
  }
279
303
 
@@ -14,6 +14,10 @@ access(all) contract FlowtyAddressVerifiers {
14
14
  return num <= self.maxPerMint
15
15
  }
16
16
 
17
+ access(all) view fun getMaxPerMint(addr: Address?, totalMinted: Int, data: {String: AnyStruct}): Int? {
18
+ return self.maxPerMint
19
+ }
20
+
17
21
  access(Mutate) fun setMaxPerMint(_ value: Int) {
18
22
  self.maxPerMint = value
19
23
  }
@@ -49,6 +53,10 @@ access(all) contract FlowtyAddressVerifiers {
49
53
  return nil
50
54
  }
51
55
 
56
+ access(all) view fun getMaxPerMint(addr: Address?, totalMinted: Int, data: {String: AnyStruct}): Int? {
57
+ return addr != nil ? self.remainingForAddress(addr: addr!, totalMinted: totalMinted) : nil
58
+ }
59
+
52
60
  access(Mutate) fun setAddress(addr: Address, value: Int) {
53
61
  self.allowedAddresses[addr] = value
54
62
  }
@@ -327,6 +327,10 @@ access(all) contract FlowtyDrops {
327
327
  access(all) fun remainingForAddress(addr: Address, totalMinted: Int): Int? {
328
328
  return nil
329
329
  }
330
+
331
+ access(all) view fun getMaxPerMint(addr: Address?, totalMinted: Int, data: {String: AnyStruct}): Int? {
332
+ return nil
333
+ }
330
334
  }
331
335
 
332
336
  access(all) struct interface Pricer {
@@ -52,6 +52,9 @@ access(all) contract OpenEditionInitializer: ContractInitializer {
52
52
  container.addDrop(<- drop)
53
53
  }
54
54
 
55
- return NFTMetadata.initialize(acct: contractAcct, collectionInfo: collectionInfo, nftType: nftType)
55
+ let caps = NFTMetadata.initialize(acct: contractAcct, collectionInfo: collectionInfo, nftType: nftType)
56
+ caps.ownerCap.borrow()!.addMetadata(id: 0, data: data)
57
+
58
+ return caps
56
59
  }
57
60
  }
@@ -23,7 +23,7 @@ access(all) contract interface BaseCollection: ViewResolver {
23
23
  token.getType() == self.nftType: "unexpected nft type being deposited"
24
24
  }
25
25
 
26
- destroy self.ownedNFTs.insert(key: token.uuid, <-token)
26
+ destroy self.ownedNFTs.insert(key: token.id, <-token)
27
27
  }
28
28
 
29
29
  access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
@@ -80,18 +80,29 @@ access(all) contract interface BaseCollection: ViewResolver {
80
80
  return <- c.createEmptyCollection(nftType: rt)
81
81
  }
82
82
  )
83
- case Type<MetadataViews.NFTCollectionDisplay>():
84
- let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])!
85
- let tmp = c.MetadataCap.borrow()
86
- if tmp == nil {
87
- return nil
88
- }
89
-
90
- return tmp!.collectionInfo.getDisplay()
91
83
  case Type<FlowtyDrops.DropResolver>():
92
84
  return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath))
93
85
  }
94
86
 
87
+ // These views require the {BaseCollection} interface
88
+ if let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2]) {
89
+ let tmp = c.MetadataCap.borrow()
90
+ if tmp == nil {
91
+ return nil
92
+ }
93
+
94
+ switch viewType {
95
+ case Type<MetadataViews.NFTCollectionDisplay>():
96
+ return tmp!.collectionInfo.getDisplay()
97
+ case Type<MetadataViews.Royalties>():
98
+ let keys = tmp!.metadata.keys
99
+ if keys.length == 0 || keys.length > 1 {
100
+ return nil
101
+ }
102
+ return tmp!.borrowMetadata(id: keys[0])!.getRoyalties()
103
+ }
104
+ }
105
+
95
106
  return nil
96
107
  }
97
108
  }
@@ -42,7 +42,7 @@ access(all) contract interface BaseNFT: ViewResolver {
42
42
 
43
43
  access(all) fun resolveView(_ view: Type): AnyStruct? {
44
44
  if view == Type<MetadataViews.Serial>() {
45
- return self.id
45
+ return MetadataViews.Serial(self.id)
46
46
  }
47
47
 
48
48
  let rt = self.getType()
@@ -75,25 +75,27 @@ access(all) contract interface BaseNFT: ViewResolver {
75
75
  }
76
76
  )
77
77
  case Type<MetadataViews.NFTCollectionDisplay>():
78
- return md.collectionInfo.collectionDisplay
78
+ return md.collectionInfo.getDisplay()
79
79
  }
80
80
 
81
81
  if let entry = md.borrowMetadata(id: self.metadataID) {
82
82
  switch view {
83
83
  case Type<MetadataViews.Traits>():
84
- return entry.traits
84
+ return entry.getTraits()
85
85
  case Type<MetadataViews.Editions>():
86
- return entry.editions
86
+ return entry.getEditions()
87
87
  case Type<MetadataViews.Display>():
88
88
  let num = (entry.editions?.infoList?.length ?? 0) > 0 ? entry.editions!.infoList[0].number : self.id
89
89
 
90
90
  return MetadataViews.Display(
91
91
  name: entry.name.concat(" #").concat(num.toString()),
92
92
  description: entry.description,
93
- thumbnail: NFTMetadata.UriFile(entry.thumbnail.uri())
93
+ thumbnail: entry.getThumbnail()
94
94
  )
95
95
  case Type<MetadataViews.ExternalURL>():
96
- return entry.externalURL
96
+ return entry.getExternalURL()
97
+ case Type<MetadataViews.Royalties>():
98
+ return entry.getRoyalties()
97
99
  }
98
100
  }
99
101
 
@@ -36,6 +36,26 @@ access(all) contract NFTMetadata {
36
36
 
37
37
  access(all) let data: {String: AnyStruct}
38
38
 
39
+ access(all) fun getThumbnail(): {MetadataViews.File} {
40
+ return self.thumbnail
41
+ }
42
+
43
+ access(all) fun getTraits(): MetadataViews.Traits? {
44
+ return self.traits
45
+ }
46
+
47
+ access(all) fun getEditions(): MetadataViews.Editions? {
48
+ return self.editions
49
+ }
50
+
51
+ access(all) fun getExternalURL(): MetadataViews.ExternalURL? {
52
+ return self.externalURL
53
+ }
54
+
55
+ access(all) fun getRoyalties(): MetadataViews.Royalties? {
56
+ return self.royalties
57
+ }
58
+
39
59
  init(
40
60
  name: String,
41
61
  description: String,
@@ -14,6 +14,22 @@ access(all) contract UniversalCollection {
14
14
  return <- create Collection(nftType: self.nftType)
15
15
  }
16
16
 
17
+ access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
18
+ pre {
19
+ token.getType() == self.nftType: "unexpected nft type being deposited"
20
+ }
21
+
22
+ destroy self.ownedNFTs.insert(key: token.id, <-token)
23
+ }
24
+
25
+ access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
26
+ return &self.ownedNFTs[id]
27
+ }
28
+
29
+ access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
30
+ return <- self.ownedNFTs.remove(key: withdrawID)!
31
+ }
32
+
17
33
  init (nftType: Type) {
18
34
  self.ownedNFTs <- {}
19
35
  self.nftType = nftType
package/flow.json CHANGED
@@ -487,7 +487,7 @@
487
487
  "source": "./contracts/flowty-drops/DropTypes.cdc",
488
488
  "aliases": {
489
489
  "testing": "0x0000000000000006",
490
- "testnet": "0x934da91a977f1ac4",
490
+ "testnet": "0x22f23883bf122007",
491
491
  "emulator": "0xf8d6e0586b0a20c7"
492
492
  }
493
493
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",