Smart Contract

FantastecSwapDataProperties

A.4bbff461fa8f6192.FantastecSwapDataProperties

Deployed

14h ago
Feb 28, 2026, 02:27:40 AM UTC

Dependents

0 imports
1/**
2# Contract: FantastecSwapDataProperties
3# Description:
4
5The purpose of this contract is to define the metadata objects that are properties of cards and collections
6(as defined in the fantastecSwapDataV2 contract)
7*/
8
9access(all) contract FantastecSwapDataProperties {
10  access(all) entitlement Add
11    
12  access(contract) var arrayTypes: [String]
13
14  access(all) struct interface MetadataElement {
15    access(all) let id: UInt64
16  }
17
18  access(all) struct ProductCollectionChance {
19    access(all) let collectionId : UInt64
20    access(all) let chance: UFix64
21    init (
22      _ collectionId: UInt64,
23      _ chance: UFix64
24    ) {
25      self.collectionId = collectionId
26      self.chance = chance
27    }
28  }
29
30  access(all) struct ProductContent: MetadataElement {
31    access(all) let id: UInt64;
32    access(all) let content: [ProductCollectionChance];
33    init (
34      _ id: UInt64
35    ){
36      self.id = id;
37      self.content = [];
38    }
39    access(Add) fun add(_ collectionId: UInt64, _ chance: UFix64){
40      let productCollectionChance = ProductCollectionChance(collectionId, chance)
41      self.content.append(productCollectionChance)
42    }
43  }
44
45  access(all) struct Media: MetadataElement {
46    access(all) let id: UInt64;
47    access(all) let url: String;
48    access(all) let type: String;
49    access(all) let mediaType: String;
50    access(all) let ipfsCid: String;
51    access(all) let hash: String;
52
53    init(
54      _ id: UInt64,
55      _ url: String,
56      _ type: String,
57      _ mediaType: String,
58      _ ipfsCid: String,
59      _ hash: String,
60    ){
61      self.id = id;
62      self.url = url;
63      self.type = type;
64      self.mediaType = mediaType;
65      self.ipfsCid = ipfsCid;
66      self.hash = hash;
67    }
68  }
69
70  access(all) struct Social: MetadataElement {
71    access(all) let id: UInt64;
72    access(all) let url: String;
73    access(all) let type: String;
74
75    init(
76      _ id: UInt64,
77      _ url: String,
78      _ type: String,
79    ){
80      self.id = id;
81      self.url = url;
82      self.type = type;
83    }
84  }
85
86  access(all) struct Partner: MetadataElement {
87    access(all) let id: UInt64;
88    access(all) let name: String;
89
90    init(
91      _ id: UInt64,
92      _ name: String,
93    ){
94      self.id = id;
95      self.name = name;
96    }
97  }
98
99  access(all) struct Team: MetadataElement {
100    access(all) let id: UInt64;
101    access(all) let name: String;
102    access(all) let gender: String;
103
104    init(
105      _ id: UInt64,
106      _ name: String,
107      _ gender: String,
108    ){
109      self.id = id;
110      self.name = name;
111      self.gender = gender;
112    }
113  }
114
115  access(all) struct Sport: MetadataElement {
116    access(all) let id: UInt64;
117    access(all) let name: String;
118
119    init(
120      _ id: UInt64,
121      _ name: String,
122    ){
123      self.id = id;
124      self.name = name;
125    }
126  }
127
128  access(all) struct Sku: MetadataElement {
129    access(all) let id: UInt64;
130    access(all) let name: String;
131
132    init(
133      _ id: UInt64,
134      _ name: String,
135    ){
136      self.id = id;
137      self.name = name;
138    }
139  }
140
141  access(all) struct Season: MetadataElement {
142    access(all) let id: UInt64;
143    access(all) let name: String;
144    access(all) let startDate: String;
145    access(all) let endDate: String;
146
147    init(
148      _ id: UInt64,
149      _ name: String,
150      _ startDate: String,
151      _ endDate: String,
152    ){
153      self.id = id;
154      self.name = name;
155      self.startDate = startDate;
156      self.endDate = endDate;
157    }
158  }
159
160  access(all) struct Level: MetadataElement {
161    access(all) let id: UInt64;
162    access(all) let name: String;
163    access(all) let scarcity: String;
164
165    init(
166      _ id: UInt64,
167      _ name: String,
168      _ scarcity: String,
169    ){
170      self.id = id;
171      self.name = name;
172      self.scarcity = scarcity;
173    }
174  }
175
176  access(all) struct Player: MetadataElement {
177    access(all) let id: UInt64;
178    access(all) let name: String;
179    access(all) let gender: String;
180    access(all) let position: String?;
181    access(all) let shirtNumber: String?;
182    init(
183      _ id: UInt64,
184      _ name: String,
185      _ gender: String,
186      _ position: String?,
187      _ shirtNumber: String?,
188    ){
189      self.id = id;
190      self.name = name;
191      self.gender = gender;
192      self.position = position;
193      self.shirtNumber = shirtNumber;
194    }
195  }
196
197  access(all) struct Royalty: MetadataElement {
198    access(all) let id: UInt64;
199    access(all) let address: Address;
200    access(all) let percentage: UFix64;
201    init(
202      _ id: UInt64,
203      _ address: Address,
204      _ percentage: UFix64,
205    ){
206      pre {
207        percentage <= 100.0: "percentage cannot be higher than 100"
208      }
209      self.id = id;
210      self.address = address;
211      self.percentage = percentage;
212    }
213  }
214
215  access(all) struct License: MetadataElement {
216    access(all) let id: UInt64;
217    access(all) let name: String;
218    access(all) let url: String;
219    access(all) let dateAwarded: String;
220    init(
221      _ id: UInt64,
222      _ name: String,
223      _ url: String,
224      _ dateAwarded: String,
225    ){
226      self.id = id;
227      self.name = name;
228      self.url = url;
229      self.dateAwarded = dateAwarded;
230    }
231  }
232
233  access(all) struct CardId: MetadataElement {
234    access(all) let id: UInt64;
235    init(
236      _ id: UInt64,
237    ){
238      self.id = id;
239    }
240  }
241
242  access(all) struct MintVolume: MetadataElement {
243    access(all) let id: UInt64;
244    access(all) let value: UInt64;
245    init(
246      _ id: UInt64,
247      _ value: UInt64,
248    ){
249      self.id = id;
250      self.value = value;
251    }
252  }
253
254  access(all) struct RedeemInfo: MetadataElement {
255    access(all) let id: UInt64;
256    access(all) let retailerName: String;
257    access(all) let retailerPinHash: String;
258    access(all) let retailerAddress: Address;
259    access(all) let validFrom: UFix64?;
260    access(all) let validTo: UFix64?;
261    init(
262      _ id: UInt64,
263      _ retailerName: String,
264      _ retailerPinHash: String,
265      _ retailerAddress: Address,
266      _ validFrom: UFix64?,
267      _ validTo: UFix64?,
268    ){
269      self.id = id;
270      self.retailerName = retailerName;
271      self.retailerPinHash = retailerPinHash;
272      self.retailerAddress = retailerAddress;
273      self.validFrom = validFrom;
274      self.validTo = validTo;
275    }
276  }
277
278  access(all) struct RedeemInfoV2: MetadataElement {
279    access(all) let id: UInt64;
280    access(all) let retailerName: String;
281    access(all) let retailerPinHash: String;
282    access(all) let retailerAddress: Address;
283    access(all) let validFrom: UFix64?;
284    access(all) let validTo: UFix64?;
285    access(all) let type: String;
286    access(all) let t_and_cs: String;
287    access(all) let description: String;
288
289    init(
290      _ id: UInt64,
291      _ retailerName: String,
292      _ retailerPinHash: String,
293      _ retailerAddress: Address,
294      _ validFrom: UFix64?,
295      _ validTo: UFix64?,
296      _ type: String,
297      _ t_and_cs: String,
298      _ description: String,
299    ){
300      self.id = id;
301      self.retailerName = retailerName;
302      self.retailerPinHash = retailerPinHash;
303      self.retailerAddress = retailerAddress;
304      self.validFrom = validFrom;
305      self.validTo = validTo;
306      self.type = type;
307      self.t_and_cs = t_and_cs;
308      self.description = description;
309    }
310  }
311
312  access(all) struct NewsFeed: MetadataElement {
313    access(all) let id: UInt64
314    access(all) let title: String
315    access(all) let publishedDate: UFix64
316    access(all) let buttonUrl: String
317    access(all) let buttonText: String
318    init(
319      _ id: UInt64,
320      _ title: String,
321      _ publishedDate: UFix64,
322      _ buttonUrl: String,
323      _ buttonText: String,      
324    ){
325      self.id = id
326      self.title = title
327      self.publishedDate = publishedDate
328      self.buttonUrl = buttonUrl
329      self.buttonText = buttonText
330    }
331  }
332
333  access(all) struct BlockedUsers: MetadataElement {
334    access(all) let id: UInt64;
335    access(all) let blockedAddresses: [Address];
336    init(
337      _ id: UInt64,
338      _ blockedAddresses: [Address]
339    ){
340      self.id = id;
341      self.blockedAddresses = blockedAddresses;
342    }
343  }
344
345  access(all) fun IsArrayMetadataType(_ type: String): Bool {
346    return self.arrayTypes.contains(type);
347  }
348
349  access(all) fun parseUInt64(_ string: String?): UInt64? {
350    if (string == nil) {
351      return nil
352    }
353    return UInt64.fromString(string!)
354  }
355
356  access(all) fun parseUFix64(_ string: String?): UFix64? {
357    if (string == nil) {
358      return nil
359    }
360    return UFix64.fromString(string!)
361  }
362
363  access(all) fun parseAddress(_ string: String?): Address? {
364    if (string == nil) {
365      return nil
366    }
367    var addressString = string!
368    if (addressString.slice(from: 0, upTo: 2) == "0x") {
369      addressString = addressString.slice(from: 2, upTo: addressString.length)
370    }
371    let bytes = addressString.decodeHex()
372    let numberOfBytes: UInt64 = UInt64(bytes.length)
373    var i: UInt64 = 0
374    var addressAsInt: UInt64 = 0
375    var multiplier: UInt64 = 1
376    while i < numberOfBytes {
377      let index: UInt64 = numberOfBytes - 1 - i
378      let intPart = UInt64(bytes[index]) * multiplier
379      addressAsInt = addressAsInt + intPart
380      i = i + 1
381      multiplier = multiplier.saturatingMultiply(256)
382    }
383    let address = Address(addressAsInt)
384    return address
385  }
386
387  access(all) fun addToMetadata(
388    _ type: String,
389    _ metadataArray: [{MetadataElement}],
390    _ metadata: {MetadataElement},
391  ): [{MetadataElement}] {
392    if (self.IsArrayMetadataType(type)) {
393      var updatedMetadataArray = self.removeMetadataElementById(metadataArray, metadata.id)
394      updatedMetadataArray.append(metadata)
395      return updatedMetadataArray
396    } else {
397      if metadataArray.length > 0 {
398        metadataArray.removeFirst()
399      }
400      metadataArray.append(metadata)
401      return metadataArray
402    }
403  }
404
405  access(all) fun removeFromMetadata(
406    _ type: String,
407    _ metadataArray: [{MetadataElement}],
408    _ id: UInt64?,
409  ): [{MetadataElement}] {
410    if (self.IsArrayMetadataType(type)) {
411      let updatedMetadataArray = self.removeMetadataElementById(metadataArray, id!)
412      return updatedMetadataArray
413    } else {
414      let metadataExists = metadataArray.length > 0
415      if (metadataExists) {
416        metadataArray.removeFirst()
417      }
418      return metadataArray
419    }
420  }
421
422  access(all) fun removeMetadataElementById(
423    _ array: [{MetadataElement}],
424    _ id: UInt64,
425  ): [{MetadataElement}] {
426    if (array == nil) {
427      return []
428    }
429    var indexToRemove: Int = -1
430    for index, element in array {
431      if (element.id == id) {
432        indexToRemove = index
433        break
434      }
435    }
436    if (indexToRemove > -1) {
437      array.remove(at: indexToRemove)
438    }
439    return array
440  }  
441
442  init() {
443    self.arrayTypes = ["media", "socials", "royalties", "licenses", "cardIds"]
444  }
445}