Smart Contract
FindUserStatus
A.097bafa4e0b48eef.FindUserStatus
1import FIND from 0x097bafa4e0b48eef
2import NFTStorefront from 0x4eb8a10cb9f87357
3import NFTStorefrontV2 from 0x4eb8a10cb9f87357
4import Flowty from 0x5c57f79c6694797f
5import FlowtyRentals from 0x5c57f79c6694797f
6import FlowToken from 0x1654653399040a61
7import FlovatarMarketplace from 0x921ea449dffec68a
8import Flovatar from 0x921ea449dffec68a
9import FlovatarComponent from 0x921ea449dffec68a
10
11pub contract FindUserStatus {
12
13 pub struct StoreFrontCut {
14 pub let amount:UFix64
15 pub let address: Address
16 pub let findName:String?
17 pub let tags: {String : String}
18 pub let scalars: {String : UFix64}
19 pub let extra: {String : AnyStruct}
20
21 init(amount:UFix64, address:Address){
22 self.amount=amount
23 self.address=address
24 self.findName= FIND.reverseLookup(address)
25 self.tags={}
26 self.scalars={}
27 self.extra={}
28 }
29 }
30
31
32 pub struct StorefrontListing {
33 pub var listingId: UInt64
34 // if purchased is true -> don't show it
35 //pub var purchased: Bool
36 pub let nftIdentifier: String
37 pub let nftId: UInt64
38 pub let ftTypeIdentifier: String
39 pub let amount: UFix64
40 pub let cuts: [StoreFrontCut]
41 pub var customID: String?
42 pub let commissionAmount: UFix64?
43 pub let listingValidUntil: UInt64?
44 pub let tags: {String : String}
45 pub let scalars: {String : UFix64}
46 pub let extra: {String : AnyStruct}
47
48 init(storefrontID: UInt64, nftType: String, nftID: UInt64, salePaymentVaultType: String, salePrice: UFix64, saleCuts: [StoreFrontCut], customID: String?, commissionAmount: UFix64?, expiry: UInt64?) {
49 self.listingId = storefrontID
50 self.nftIdentifier = nftType
51 self.nftId = nftID
52 self.ftTypeIdentifier = salePaymentVaultType
53 self.amount = salePrice
54 self.cuts = saleCuts
55 self.customID = customID
56 self.commissionAmount = commissionAmount
57 self.listingValidUntil = expiry
58 self.tags={}
59 self.scalars={}
60 self.extra={}
61 }
62 }
63
64 pub struct FlowtyListing {
65 pub var listingId: UInt64
66 pub var funded: Bool
67 pub let nftIdentifier: String
68 pub let nftId: UInt64
69 pub let amount: UFix64
70 pub let interestRate: UFix64
71 pub var term: UFix64
72 pub let paymentVaultType: String
73
74 pub let paymentCuts: [StoreFrontCut]
75 pub var listedTime: UFix64
76 pub var royaltyRate: UFix64
77 pub var listingValidUntil: UFix64
78 pub var repaymentAmount: UFix64
79
80 pub let tags: {String : String}
81 pub let scalars: {String : UFix64}
82 pub let extra: {String : AnyStruct}
83
84 init(flowtyStorefrontID: UInt64, funded: Bool, nftType: String, nftID: UInt64, amount: UFix64, interestRate: UFix64, term: UFix64, paymentVaultType: String,paymentCuts: [StoreFrontCut], listedTime: UFix64, royaltyRate: UFix64, expiresAfter: UFix64, repaymentAmount: UFix64) {
85 self.listingId = flowtyStorefrontID
86 self.funded = funded
87 self.nftIdentifier = nftType
88 self.nftId = nftID
89 self.amount = amount
90 self.interestRate = interestRate
91 self.term = term
92 self.paymentVaultType = paymentVaultType
93 self.paymentCuts = paymentCuts
94 self.listedTime = listedTime
95 self.royaltyRate = royaltyRate
96 self.listingValidUntil = expiresAfter + listedTime
97 self.repaymentAmount = repaymentAmount
98 self.tags={}
99 self.scalars={}
100 self.extra={}
101 }
102 }
103
104 pub struct FlowtyRental {
105 pub var listingId: UInt64
106 pub var rented: Bool
107 pub let nftIdentifier: String
108 pub let nftId: UInt64
109 pub let amount: UFix64
110 pub let deposit: UFix64
111 pub var term: UFix64
112 pub let paymentVaultType: String
113 pub let reenableOnReturn: Bool
114
115 pub let paymentCuts: [StoreFrontCut]
116 pub var listedTime: UFix64
117 pub var royaltyRate: UFix64
118 pub var listingValidUntil: UFix64
119 pub var repaymentAmount: UFix64
120 pub var renter: Address?
121 pub var renterName: String?
122
123 pub let tags: {String : String}
124 pub let scalars: {String : UFix64}
125 pub let extra: {String : AnyStruct}
126
127 init(flowtyStorefrontID: UInt64, rented: Bool, nftType: String, nftID: UInt64, amount: UFix64, deposit: UFix64, term: UFix64, paymentVaultType: String, reenableOnReturn:Bool, paymentCuts: [StoreFrontCut], listedTime: UFix64, royaltyRate: UFix64, expiresAfter: UFix64, repaymentAmount: UFix64, renter: Address?) {
128 self.listingId = flowtyStorefrontID
129 self.rented = rented
130 self.nftIdentifier = nftType
131 self.nftId = nftID
132 self.deposit = deposit
133 self.amount = amount
134 self.term = term
135 self.paymentVaultType = paymentVaultType
136 self.reenableOnReturn = reenableOnReturn
137 self.paymentCuts = paymentCuts
138 self.listedTime = listedTime
139 self.royaltyRate = royaltyRate
140 self.listingValidUntil = expiresAfter + listedTime
141 self.repaymentAmount = repaymentAmount
142 self.renter = renter
143 self.renterName = nil
144 if renter != nil {
145 self.renterName = FIND.reverseLookup(renter!)
146 }
147 self.tags={}
148 self.scalars={}
149 self.extra={}
150 }
151 }
152
153 pub struct FlovatarListing {
154 pub var listingId: UInt64
155 pub let nftIdentifier: String
156 pub let nftId: UInt64
157 pub let ftTypeIdentifier: String
158 pub let amount: UFix64
159 pub let cuts: [StoreFrontCut]
160 pub let accessoryId: UInt64?
161 pub let hatId: UInt64?
162 pub let eyeglassesId: UInt64?
163 pub let backgroundId: UInt64?
164 pub let mint: UInt64
165 pub let series: UInt32
166 pub let creatorAddress: Address
167 pub let components: {String: UInt64}
168 pub let rareCount: UInt8
169 pub let epicCount: UInt8
170 pub let legendaryCount: UInt8
171 pub let tags: {String : String}
172 pub let scalars: {String : UFix64}
173 pub let extra: {String : AnyStruct}
174
175 init(storefrontID: UInt64, nftType: String, nftID: UInt64, salePaymentVaultType: String, salePrice: UFix64, saleCuts: [StoreFrontCut], flovatarMetadata: FlovatarMarketplace.FlovatarSaleData) {
176 self.listingId = storefrontID
177 self.nftIdentifier = nftType
178 self.nftId = nftID
179 self.ftTypeIdentifier = salePaymentVaultType
180 self.amount = salePrice
181 self.cuts = saleCuts
182 let f = flovatarMetadata
183 self.accessoryId = f.accessoryId
184 self.hatId = f.hatId
185 self.eyeglassesId = f.eyeglassesId
186 self.backgroundId = f.backgroundId
187 let d = f.metadata
188 self.mint = d.mint
189 self.series = d.series
190 self.creatorAddress = d.creatorAddress
191 self.components = d.getComponents()
192 self.rareCount = d.rareCount
193 self.epicCount = d.epicCount
194 self.legendaryCount = d.legendaryCount
195 self.tags={}
196 self.scalars={}
197 self.extra={}
198 }
199 }
200
201 pub struct FlovatarComponentListing {
202 pub var listingId: UInt64
203 pub let nftIdentifier: String
204 pub let nftId: UInt64
205 pub let ftTypeIdentifier: String
206 pub let amount: UFix64
207 pub let cuts: [StoreFrontCut]
208 pub let mint: UInt64
209 pub let templateId: UInt64
210 pub let name: String
211 pub let description: String
212 pub let category: String
213 pub let rarity: String
214 pub let color: String
215 pub let tags: {String : String}
216 pub let scalars: {String : UFix64}
217 pub let extra: {String : AnyStruct}
218
219 init(storefrontID: UInt64, nftType: String, nftID: UInt64, salePaymentVaultType: String, salePrice: UFix64, saleCuts: [StoreFrontCut], flovatarComponentMetadata: FlovatarMarketplace.FlovatarComponentSaleData) {
220 self.listingId = storefrontID
221 self.nftIdentifier = nftType
222 self.nftId = nftID
223 self.ftTypeIdentifier = salePaymentVaultType
224 self.amount = salePrice
225 self.cuts = saleCuts
226 let f = flovatarComponentMetadata.metadata
227 self.mint = f.mint
228 self.templateId = f.templateId
229 self.name = f.name
230 self.description = f.description
231 self.category = f.category
232 self.rarity = f.rarity
233 self.color = f.color
234 self.tags={}
235 self.scalars={}
236 self.extra={}
237 }
238 }
239
240 pub fun getStorefrontListing(user: Address, id: UInt64, type: Type) : StorefrontListing? {
241
242 var listingsV1 : StorefrontListing? = nil
243 let account = getAccount(user)
244 let storefrontCap = account.getCapability<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(NFTStorefront.StorefrontPublicPath)
245
246 if storefrontCap.check() {
247 let storefrontRef=storefrontCap.borrow()!
248 for listingId in storefrontRef.getListingIDs() {
249 let listing = storefrontRef.borrowListing(listingResourceID: listingId)!
250 let d = listing.getDetails()
251 if d.nftID!=id || d.nftType != type {
252 continue
253 }
254 if d.purchased {
255 continue
256 }
257 let saleCuts : [StoreFrontCut] = []
258 for cut in d.saleCuts {
259 saleCuts.append(
260 StoreFrontCut(
261 amount: cut.amount,
262 address: cut.receiver.address
263 )
264 )
265 }
266 listingsV1 = StorefrontListing(storefrontID: d.storefrontID, nftType: d.nftType.identifier, nftID: d.nftID, salePaymentVaultType: d.salePaymentVaultType.identifier, salePrice: d.salePrice, saleCuts: saleCuts, customID: nil, commissionAmount: nil, expiry: nil)
267 return listingsV1
268
269 }
270 }
271 return nil
272 }
273
274
275 pub fun getStorefrontV2Listing(user: Address, id: UInt64, type: Type) : StorefrontListing? {
276 var listingsV2 : StorefrontListing? = nil
277 let account = getAccount(user)
278 let storefrontV2Cap = account.getCapability<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath)
279
280 if storefrontV2Cap.check() {
281 let storefrontRef=storefrontV2Cap.borrow()!
282 for listingId in storefrontRef.getListingIDs() {
283 let listing = storefrontRef.borrowListing(listingResourceID: listingId)!
284 let d = listing.getDetails()
285 if d.nftID!=id || d.nftType != type {
286 continue
287 }
288 if d.purchased {
289 continue
290 }
291 let saleCuts : [StoreFrontCut] = []
292 for cut in d.saleCuts {
293 saleCuts.append(
294 StoreFrontCut(
295 amount: cut.amount,
296 address: cut.receiver.address
297 )
298 )
299 }
300 listingsV2 = StorefrontListing(storefrontID: d.storefrontID, nftType: d.nftType.identifier, nftID: d.nftID, salePaymentVaultType: d.salePaymentVaultType.identifier, salePrice: d.salePrice, saleCuts: saleCuts, customID: d.customID, commissionAmount: d.commissionAmount, expiry: d.expiry)
301 return listingsV2
302 }
303 }
304 return nil
305 }
306
307 pub fun getFlowtyListing(user: Address, id: UInt64, type: Type) : FlowtyListing? {
308 var flowty : FlowtyListing? = nil
309 let account = getAccount(user)
310 let flowtyCap = account.getCapability<&Flowty.FlowtyStorefront{Flowty.FlowtyStorefrontPublic}>(Flowty.FlowtyStorefrontPublicPath)
311
312 if flowtyCap.check() {
313 let storefrontRef=flowtyCap.borrow()!
314 for listingId in storefrontRef.getListingIDs() {
315 let listing = storefrontRef.borrowListing(listingResourceID: listingId)!
316 let d = listing.getDetails()
317 if d.nftID!=id || d.nftType != type {
318 continue
319 }
320 if d.funded {
321 continue
322 }
323 let saleCuts : [StoreFrontCut] = []
324 for cut in d.getPaymentCuts() {
325 saleCuts.append(
326 StoreFrontCut(
327 amount: cut.amount,
328 address: cut.receiver.address
329 )
330 )
331 }
332 flowty = FlowtyListing(flowtyStorefrontID: d.flowtyStorefrontID, funded: d.funded, nftType: d.nftType.identifier, nftID: d.nftID, amount: d.amount, interestRate: d.interestRate, term: d.term, paymentVaultType: d.paymentVaultType.identifier ,paymentCuts: saleCuts, listedTime: d.listedTime, royaltyRate: d.royaltyRate, expiresAfter: d.expiresAfter, repaymentAmount: d.getTotalPayment())
333 return flowty
334 }
335 }
336 return nil
337 }
338
339 pub fun getFlowtyRentals(user: Address, id: UInt64, type: Type) : FlowtyRental? {
340
341 var flowtyRental : FlowtyRental? = nil
342 let account = getAccount(user)
343 let flowtyRentalCap = account.getCapability<&FlowtyRentals.FlowtyRentalsStorefront{FlowtyRentals.FlowtyRentalsStorefrontPublic}>(FlowtyRentals.FlowtyRentalsStorefrontPublicPath)
344
345 if flowtyRentalCap.check() {
346 let storefrontRef=flowtyRentalCap.borrow()!
347 for listingId in storefrontRef.getListingIDs() {
348 let listing = storefrontRef.borrowListing(listingResourceID: listingId)!
349 let d = listing.getDetails()
350 if d.nftID!=id || d.nftType != type {
351 continue
352 }
353 if d.rented {
354 continue
355 }
356 let saleCuts : [StoreFrontCut] = []
357 let cut = d.getPaymentCut()
358 saleCuts.append(
359 StoreFrontCut(
360 amount: cut.amount,
361 address: cut.receiver.address
362 )
363 )
364
365 flowtyRental = FlowtyRental(flowtyStorefrontID: d.flowtyStorefrontID, rented: d.rented, nftType: d.nftType.identifier, nftID: d.nftID, amount: d.amount, deposit: d.deposit, term: d.term, paymentVaultType: d.paymentVaultType.identifier, reenableOnReturn: d.reenableOnReturn, paymentCuts: saleCuts, listedTime: d.listedTime, royaltyRate: d.royaltyRate, expiresAfter: d.expiresAfter, repaymentAmount: d.getTotalPayment(), renter: d.renter)
366 return flowtyRental
367 }
368 }
369 return nil
370 }
371
372 pub fun getFlovatarListing(user: Address, id: UInt64, type: Type) : FlovatarListing? {
373 let nftType = Type<@Flovatar.NFT>()
374 if type != nftType {
375 return nil
376 }
377 let flovatar = FlovatarMarketplace.getFlovatarSale(address: user, id: id)
378 if flovatar == nil {
379 return nil
380 }
381 let f = flovatar!
382 let saleCuts : [StoreFrontCut] = []
383 let creatorCut = Flovatar.getRoyaltyCut()
384 let marketCut = Flovatar.getMarketplaceCut()
385 saleCuts.appendAll([
386 StoreFrontCut(
387 amount: creatorCut,
388 address: f.metadata.creatorAddress
389 ),
390 StoreFrontCut(
391 amount: marketCut,
392 address: FlovatarMarketplace.marketplaceWallet.address
393 )
394 ])
395 return FlovatarListing(storefrontID: f.id, nftType: nftType.identifier, nftID: f.id, salePaymentVaultType: Type<@FlowToken.Vault>().identifier, salePrice: f.price, saleCuts: saleCuts, flovatarMetadata: f)
396 }
397
398 pub fun getFlovatarComponentListing(user: Address, id: UInt64, type: Type) : FlovatarComponentListing? {
399 let nftType = Type<@FlovatarComponent.NFT>()
400 if type != nftType {
401 return nil
402 }
403 let flovatar = FlovatarMarketplace.getFlovatarComponentSale(address: user, id: id)
404 if flovatar == nil {
405 return nil
406 }
407 let f = flovatar!
408 let saleCuts : [StoreFrontCut] = []
409 let creatorCut = Flovatar.getRoyaltyCut()
410 let marketCut = Flovatar.getMarketplaceCut()
411 saleCuts.appendAll([
412 StoreFrontCut(
413 amount: marketCut,
414 address: FlovatarMarketplace.marketplaceWallet.address
415 )
416 ])
417 return FlovatarComponentListing(storefrontID: f.id, nftType: nftType.identifier, nftID: f.id, salePaymentVaultType: Type<@FlowToken.Vault>().identifier, salePrice: f.price, saleCuts: saleCuts, flovatarComponentMetadata: f)
418 }
419}
420