@flowtyio/flow-contracts 0.0.17 → 0.0.18

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.
@@ -0,0 +1,392 @@
1
+ import "NonFungibleToken"
2
+ import "FungibleToken"
3
+ import "MetadataViews"
4
+
5
+ pub contract FindViews {
6
+
7
+ pub struct OnChainFile : MetadataViews.File{
8
+ pub let content: String
9
+ pub let mediaType: String
10
+ pub let protocol: String
11
+
12
+ init(content:String, mediaType: String) {
13
+ self.content=content
14
+ self.protocol="onChain"
15
+ self.mediaType=mediaType
16
+ }
17
+
18
+ pub fun uri(): String {
19
+ return "data:".concat(self.mediaType).concat(",").concat(self.content)
20
+ }
21
+ }
22
+
23
+ pub struct SharedMedia : MetadataViews.File {
24
+ pub let mediaType: String
25
+ pub let pointer: ViewReadPointer
26
+ pub let protocol: String
27
+
28
+ init(pointer: ViewReadPointer, mediaType: String) {
29
+ self.pointer=pointer
30
+ self.mediaType=mediaType
31
+ self.protocol="shared"
32
+
33
+ if pointer.resolveView(Type<OnChainFile>()) == nil {
34
+ panic("Cannot create shared media if the pointer does not contain StringMedia")
35
+ }
36
+ }
37
+
38
+ pub fun uri(): String {
39
+ let media = self.pointer.resolveView(Type<OnChainFile>())
40
+ if media == nil {
41
+ return ""
42
+ }
43
+ return (media as! OnChainFile).uri()
44
+ }
45
+ }
46
+
47
+ pub resource interface VaultViews {
48
+ pub var balance: UFix64
49
+
50
+ pub fun getViews() : [Type]
51
+ pub fun resolveView(_ view: Type): AnyStruct?
52
+ }
53
+
54
+ pub struct FTVaultData {
55
+ pub let tokenAlias: String
56
+ pub let storagePath: StoragePath
57
+ pub let receiverPath: PublicPath
58
+ pub let balancePath: PublicPath
59
+ pub let providerPath: PrivatePath
60
+ pub let vaultType: Type
61
+ pub let receiverType: Type
62
+ pub let balanceType: Type
63
+ pub let providerType: Type
64
+ pub let createEmptyVault: ((): @FungibleToken.Vault)
65
+
66
+ init(
67
+ tokenAlias: String,
68
+ storagePath: StoragePath,
69
+ receiverPath: PublicPath,
70
+ balancePath: PublicPath,
71
+ providerPath: PrivatePath,
72
+ vaultType: Type,
73
+ receiverType: Type,
74
+ balanceType: Type,
75
+ providerType: Type,
76
+ createEmptyVault: ((): @FungibleToken.Vault)
77
+ ) {
78
+ pre {
79
+ receiverType.isSubtype(of: Type<&{FungibleToken.Receiver}>()): "Receiver type must include FungibleToken.Receiver interfaces."
80
+ balanceType.isSubtype(of: Type<&{FungibleToken.Balance}>()): "Balance type must include FungibleToken.Balance interfaces."
81
+ providerType.isSubtype(of: Type<&{FungibleToken.Provider}>()): "Provider type must include FungibleToken.Provider interface."
82
+ }
83
+ self.tokenAlias=tokenAlias
84
+ self.storagePath=storagePath
85
+ self.receiverPath=receiverPath
86
+ self.balancePath=balancePath
87
+ self.providerPath = providerPath
88
+ self.vaultType=vaultType
89
+ self.receiverType=receiverType
90
+ self.balanceType=balanceType
91
+ self.providerType = providerType
92
+ self.createEmptyVault=createEmptyVault
93
+ }
94
+ }
95
+
96
+ // This is an example taken from Versus
97
+ pub struct CreativeWork {
98
+ pub let artist: String
99
+ pub let name: String
100
+ pub let description: String
101
+ pub let type: String
102
+
103
+ init(artist: String, name: String, description: String, type: String) {
104
+ self.artist=artist
105
+ self.name=name
106
+ self.description=description
107
+ self.type=type
108
+ }
109
+ }
110
+
111
+
112
+ /// A basic pointer that can resolve data and get owner/id/uuid and gype
113
+ pub struct interface Pointer {
114
+ pub let id: UInt64
115
+ pub fun resolveView(_ type: Type) : AnyStruct?
116
+ pub fun getUUID() :UInt64
117
+ pub fun getViews() : [Type]
118
+ pub fun owner() : Address
119
+ pub fun valid() : Bool
120
+ pub fun getItemType() : Type
121
+ pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver}
122
+
123
+ //There are just convenience functions for shared views in the standard
124
+ pub fun getRoyalty() : MetadataViews.Royalties
125
+ pub fun getTotalRoyaltiesCut() : UFix64
126
+
127
+ //Requred views
128
+ pub fun getDisplay() : MetadataViews.Display
129
+ pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData
130
+
131
+ pub fun checkSoulBound() : Bool
132
+
133
+ }
134
+
135
+ //An interface to say that this pointer can withdraw
136
+ pub struct interface AuthPointer {
137
+ pub fun withdraw() : @AnyResource
138
+ }
139
+
140
+ pub struct ViewReadPointer : Pointer {
141
+ access(self) let cap: Capability<&{MetadataViews.ResolverCollection}>
142
+ pub let id: UInt64
143
+ pub let uuid: UInt64
144
+ pub let itemType: Type
145
+
146
+ init(cap: Capability<&{MetadataViews.ResolverCollection}>, id: UInt64) {
147
+ self.cap=cap
148
+ self.id=id
149
+
150
+ if !self.cap.check() {
151
+ panic("The capability is not valid.")
152
+ }
153
+ let viewResolver=self.cap.borrow()!.borrowViewResolver(id: self.id)
154
+ let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
155
+ let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
156
+ self.uuid=viewResolver.uuid
157
+ self.itemType=viewResolver.getType()
158
+ }
159
+
160
+ pub fun resolveView(_ type: Type) : AnyStruct? {
161
+ return self.getViewResolver().resolveView(type)
162
+ }
163
+
164
+ pub fun getUUID() :UInt64{
165
+ return self.uuid
166
+ }
167
+
168
+ pub fun getViews() : [Type]{
169
+ return self.getViewResolver().getViews()
170
+ }
171
+
172
+ pub fun owner() : Address {
173
+ return self.cap.address
174
+ }
175
+
176
+ pub fun getTotalRoyaltiesCut() :UFix64 {
177
+ var total=0.0
178
+ for royalty in self.getRoyalty().getRoyalties() {
179
+ total = total + royalty.cut
180
+ }
181
+ return total
182
+ }
183
+
184
+ pub fun getRoyalty() : MetadataViews.Royalties {
185
+ if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
186
+ return v
187
+ }
188
+ return MetadataViews.Royalties([])
189
+ }
190
+
191
+ pub fun valid() : Bool {
192
+ if !self.cap.check() || !self.cap.borrow()!.getIDs().contains(self.id) {
193
+ return false
194
+ }
195
+ return true
196
+ }
197
+
198
+ pub fun getItemType() : Type {
199
+ return self.itemType
200
+ }
201
+
202
+ pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver} {
203
+ return self.cap.borrow()?.borrowViewResolver(id: self.id) ?? panic("The capability of view pointer is not linked.")
204
+ }
205
+
206
+ pub fun getDisplay() : MetadataViews.Display {
207
+ if let v = MetadataViews.getDisplay(self.getViewResolver()) {
208
+ return v
209
+ }
210
+ panic("MetadataViews Display View is not implemented on this NFT.")
211
+ }
212
+
213
+ pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
214
+ if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
215
+ return v
216
+ }
217
+ panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
218
+ }
219
+
220
+ pub fun checkSoulBound() : Bool {
221
+ return FindViews.checkSoulBound(self.getViewResolver())
222
+ }
223
+ }
224
+
225
+
226
+ pub fun getNounce(_ viewResolver: &{MetadataViews.Resolver}) : UInt64 {
227
+ if let nounce = viewResolver.resolveView(Type<FindViews.Nounce>()) {
228
+ if let v = nounce as? FindViews.Nounce {
229
+ return v.nounce
230
+ }
231
+ }
232
+ return 0
233
+ }
234
+
235
+
236
+ pub struct AuthNFTPointer : Pointer, AuthPointer{
237
+ access(self) let cap: Capability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
238
+ pub let id: UInt64
239
+ pub let nounce: UInt64
240
+ pub let uuid: UInt64
241
+ pub let itemType: Type
242
+
243
+ init(cap: Capability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>, id: UInt64) {
244
+ self.cap=cap
245
+ self.id=id
246
+
247
+ if !self.cap.check() {
248
+ panic("The capability is not valid.")
249
+ }
250
+
251
+ let viewResolver=self.cap.borrow()!.borrowViewResolver(id: self.id)
252
+ let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
253
+ let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
254
+ self.nounce=FindViews.getNounce(viewResolver)
255
+ self.uuid=viewResolver.uuid
256
+ self.itemType=viewResolver.getType()
257
+ }
258
+
259
+ pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver} {
260
+ return self.cap.borrow()?.borrowViewResolver(id: self.id) ?? panic("The capability of view pointer is not linked.")
261
+ }
262
+
263
+ pub fun resolveView(_ type: Type) : AnyStruct? {
264
+ return self.getViewResolver().resolveView(type)
265
+ }
266
+
267
+ pub fun getUUID() :UInt64{
268
+ return self.uuid
269
+ }
270
+
271
+ pub fun getViews() : [Type]{
272
+ return self.getViewResolver().getViews()
273
+ }
274
+
275
+ pub fun valid() : Bool {
276
+ if !self.cap.check() || !self.cap.borrow()!.getIDs().contains(self.id) {
277
+ return false
278
+ }
279
+
280
+ let viewResolver=self.getViewResolver()
281
+
282
+ if let nounce = viewResolver.resolveView(Type<FindViews.Nounce>()) {
283
+ if let v = nounce as? FindViews.Nounce {
284
+ return v.nounce==self.nounce
285
+ }
286
+ }
287
+ return true
288
+ }
289
+
290
+ pub fun getTotalRoyaltiesCut() :UFix64 {
291
+ var total=0.0
292
+ for royalty in self.getRoyalty().getRoyalties() {
293
+ total = total + royalty.cut
294
+ }
295
+ return total
296
+ }
297
+
298
+ pub fun getRoyalty() : MetadataViews.Royalties {
299
+ if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
300
+ return v
301
+ }
302
+ return MetadataViews.Royalties([])
303
+ }
304
+
305
+ pub fun getDisplay() : MetadataViews.Display {
306
+ if let v = MetadataViews.getDisplay(self.getViewResolver()) {
307
+ return v
308
+ }
309
+ panic("MetadataViews Display View is not implemented on this NFT.")
310
+ }
311
+
312
+ pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
313
+ if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
314
+ return v
315
+ }
316
+ panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
317
+ }
318
+
319
+ pub fun withdraw() :@NonFungibleToken.NFT {
320
+ if !self.cap.check() {
321
+ panic("The pointer capability is invalid.")
322
+ }
323
+ return <- self.cap.borrow()!.withdraw(withdrawID: self.id)
324
+ }
325
+
326
+ pub fun deposit(_ nft: @NonFungibleToken.NFT){
327
+ if !self.cap.check(){
328
+ panic("The pointer capablity is invalid.")
329
+ }
330
+ self.cap.borrow()!.deposit(token: <- nft)
331
+ }
332
+
333
+ pub fun owner() : Address {
334
+ return self.cap.address
335
+ }
336
+
337
+ pub fun getItemType() : Type {
338
+ return self.itemType
339
+ }
340
+
341
+ pub fun checkSoulBound() : Bool {
342
+ return FindViews.checkSoulBound(self.getViewResolver())
343
+ }
344
+ }
345
+
346
+ pub fun createViewReadPointer(address:Address, path:PublicPath, id:UInt64) : ViewReadPointer {
347
+ let cap= getAccount(address).getCapability<&{MetadataViews.ResolverCollection}>(path)
348
+ let pointer= FindViews.ViewReadPointer(cap: cap, id: id)
349
+ return pointer
350
+ }
351
+
352
+ pub struct Nounce {
353
+ pub let nounce: UInt64
354
+
355
+ init(_ nounce: UInt64) {
356
+ self.nounce=nounce
357
+ }
358
+ }
359
+
360
+ pub struct SoulBound {
361
+
362
+ pub let message: String
363
+
364
+ init(_ message:String) {
365
+ self.message=message
366
+
367
+ }
368
+ }
369
+
370
+ pub fun checkSoulBound(_ viewResolver: &{MetadataViews.Resolver}) : Bool {
371
+ if let soulBound = viewResolver.resolveView(Type<FindViews.SoulBound>()) {
372
+ if let v = soulBound as? FindViews.SoulBound {
373
+ return true
374
+ }
375
+ }
376
+ return false
377
+ }
378
+
379
+ pub fun getDapperAddress(): Address {
380
+ switch FindViews.account.address.toString() {
381
+ case "0x097bafa4e0b48eef":
382
+ //mainnet
383
+ return 0xead892083b3e2c6c
384
+ case "0x35717efbbce11c74":
385
+ //testnet
386
+ return 0x82ec283f88a62e65
387
+ default:
388
+ //emulator
389
+ return 0x01cf0e2f2f715450
390
+ }
391
+ }
392
+ }
package/flow.json CHANGED
@@ -307,6 +307,22 @@
307
307
  "testnet": "0x31ad40c07a2a9788",
308
308
  "mainnet": "0xa340dc0a4ec828ab"
309
309
  }
310
+ },
311
+ "FindViews": {
312
+ "source": "./contracts/find/FindViews.cdc",
313
+ "aliases": {
314
+ "emulator": "0xf8d6e0586b0a20c7",
315
+ "mainnet": "0x097bafa4e0b48eef",
316
+ "testnet": "0x35717efbbce11c74"
317
+ }
318
+ },
319
+ "FLOAT": {
320
+ "source": "./contracts/emerald-city/FLOAT.cdc",
321
+ "aliases": {
322
+ "emulator": "0xf8d6e0586b0a20c7",
323
+ "mainnet": "0x2d4c3caffbeab845",
324
+ "testnet": "0x4d47bf3ce5e4393f"
325
+ }
310
326
  }
311
327
  },
312
328
  "deployments": {
@@ -333,7 +349,9 @@
333
349
  "StringUtils",
334
350
  "AddressUtils",
335
351
  "ScopedNFTProviders",
336
- "ScopedFTProviders"
352
+ "ScopedFTProviders",
353
+ "FindViews",
354
+ "FLOAT"
337
355
  ],
338
356
  "emulator-ft": [
339
357
  "FungibleToken",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",