MarketplaceSEALED

#○▓○░╱$?◇░▪!&#▓▪●!^╱^#□◆▪▒▫~▒■▓●■^$■&▒╱◇▒?**▓○▪$█╳╱○█▒*╲%&□╳▒◆!■

Transaction ID

Timestamp

Aug 20, 2024, 02:44:28 AM UTC
1y ago

Block Height

84,920,048

Computation

0

Proposerseq:0 key:0

Authorizers

1

Transaction Summary

Marketplace

Called FlowToken, FungibleToken, NonFungibleToken +7 more

Script Arguments

0saleItemIDUInt64
1727891
1saleItemPriceUFix64
0.75
2customIDString?
RARIBLE
3commissionAmountUFix64
0.0375
4expiryUInt64
1732074262
5marketplacesAddress[Address]

Cadence Script

1import FlowToken from 0x1654653399040a61
2import FungibleToken from 0xf233dcee88fe0abe
3import NonFungibleToken from 0x1d7e57aa55817448
4import MetadataViews from 0x1d7e57aa55817448
5import NFTStorefrontV2 from 0x4eb8a10cb9f87357
6import HWGarageCard from 0xd0bcefdf1e67ea85
7import HWGaragePack from 0xd0bcefdf1e67ea85
8import HWGarageCardV2 from 0xd0bcefdf1e67ea85
9import HWGaragePackV2 from 0xd0bcefdf1e67ea85
10import HWGarageTokenV2 from 0xd0bcefdf1e67ea85
11
12transaction(saleItemID: UInt64, saleItemPrice: UFix64, customID: String?, commissionAmount: UFix64, expiry: UInt64, marketplacesAddress: [Address]) {
13    let fiatReceiver: Capability<&AnyResource{FungibleToken.Receiver}>
14    let HWGarageCardV2Provider: Capability<&AnyResource{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
15    let storefront: &NFTStorefrontV2.Storefront
16    var saleCuts: [NFTStorefrontV2.SaleCut]
17    var marketplacesCapability: [Capability<&AnyResource{FungibleToken.Receiver}>]
18
19    prepare(acct: AuthAccount) {
20
21
22
23      if acct.borrow<&HWGarageCard.Collection>(from: HWGarageCard.CollectionStoragePath) == nil {
24			    let collection <- HWGarageCard.createEmptyCollection()
25					acct.save(<-collection, to: HWGarageCard.CollectionStoragePath)
26			}
27			if acct.getCapability<&HWGarageCard.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCard.HWGarageCardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCard.CollectionPublicPath).borrow() == nil {
28					acct.link<&HWGarageCard.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCard.HWGarageCardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCard.CollectionPublicPath, target: HWGarageCard.CollectionStoragePath)
29			}
30
31			if acct.borrow<&HWGarageCardV2.Collection>(from: HWGarageCardV2.CollectionStoragePath) == nil {
32					let collection <- HWGarageCardV2.createEmptyCollection()
33					acct.save(<-collection, to: HWGarageCardV2.CollectionStoragePath)
34			}
35			if acct.getCapability<&HWGarageCardV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCardV2.CardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCardV2.CollectionPublicPath).borrow() == nil {
36					acct.link<&HWGarageCardV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCardV2.CardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCardV2.CollectionPublicPath, target: HWGarageCardV2.CollectionStoragePath)
37			}
38
39			if acct.borrow<&HWGaragePack.Collection>(from: HWGaragePack.CollectionStoragePath) == nil {
40					let collection <- HWGaragePack.createEmptyCollection()
41					acct.save(<-collection, to: HWGaragePack.CollectionStoragePath)
42			}
43			if acct.getCapability<&HWGaragePack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePack.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePack.CollectionPublicPath).borrow() == nil {
44					acct.link<&HWGaragePack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePack.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePack.CollectionPublicPath, target: HWGaragePack.CollectionStoragePath)
45			}
46
47			if acct.borrow<&HWGaragePackV2.Collection>(from: HWGaragePackV2.CollectionStoragePath) == nil {
48					let collection <- HWGaragePackV2.createEmptyCollection()
49					acct.save(<-collection, to: HWGaragePackV2.CollectionStoragePath)
50			}
51			if acct.getCapability<&HWGaragePackV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePackV2.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePackV2.CollectionPublicPath).borrow() == nil {
52					acct.link<&HWGaragePackV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePackV2.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePackV2.CollectionPublicPath, target: HWGaragePackV2.CollectionStoragePath)
53			}
54
55			if acct.borrow<&HWGarageTokenV2.Collection>(from: HWGarageTokenV2.CollectionStoragePath) == nil {
56					let collection <- HWGarageTokenV2.createEmptyCollection()
57					acct.save(<-collection, to: HWGarageTokenV2.CollectionStoragePath)
58			}
59			if acct.getCapability<&HWGarageTokenV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageTokenV2.TokenCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageTokenV2.CollectionPublicPath).borrow() == nil {
60					acct.link<&HWGarageTokenV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageTokenV2.TokenCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageTokenV2.CollectionPublicPath, target: HWGarageTokenV2.CollectionStoragePath)
61			}
62
63
64			if acct.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
65					let collection <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
66					acct.save(<-collection, to: NFTStorefrontV2.StorefrontStoragePath)
67			}
68			if acct.getCapability<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath).borrow() == nil {
69					acct.link<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath, target: NFTStorefrontV2.StorefrontStoragePath)
70			}
71
72
73        self.saleCuts = []
74        self.marketplacesCapability = []
75
76        // We need a provider capability, but one is not provided by default so we create one if needed.
77        let HWGarageCardV2ProviderPrivatePath = /private/HWGarageCardV2Collection
78
79        // Receiver for the sale cut.
80        self.fiatReceiver = acct.getCapability<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
81        assert(self.fiatReceiver.borrow() != nil, message: "Missing or mis-typed FT receiver")
82
83        // Check if the Provider capability exists or not if then create a new link for the same.
84        if !acct.getCapability<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(HWGarageCardV2ProviderPrivatePath).check() {
85            acct.link<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(HWGarageCardV2ProviderPrivatePath, target: HWGarageCardV2.CollectionStoragePath)
86        }
87
88        self.HWGarageCardV2Provider = acct.getCapability<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(HWGarageCardV2ProviderPrivatePath)
89        let collection = acct
90            .getCapability(HWGarageCardV2.CollectionPublicPath)
91            .borrow<&{HWGarageCardV2.CardCollectionPublic}>()
92            ?? panic("Could not borrow a reference to the collection")
93        var totalRoyaltyCut = 0.0
94        let effectiveSaleItemPrice = saleItemPrice - commissionAmount
95        // eslint-disable-next-line
96        let nft = collection.borrowCard(id: saleItemID)!
97        // Check whether the NFT implements the MetadataResolver or not.
98        if nft.getViews().contains(Type<MetadataViews.Royalties>()) {
99            let royaltiesRef = nft.resolveView(Type<MetadataViews.Royalties>())?? panic("Unable to retrieve the royalties")
100            let royalties = (royaltiesRef as! MetadataViews.Royalties).getRoyalties()
101            for royalty in royalties {
102                // TODO - Verify the type of the vault and it should exists
103                let royaltyValue = royalty.cut * saleItemPrice
104                self.saleCuts.append(NFTStorefrontV2.SaleCut(receiver: royalty.receiver, amount: royaltyValue))
105                totalRoyaltyCut = totalRoyaltyCut + royaltyValue
106            }
107        }
108        // Append the cut for the seller.
109        self.saleCuts.append(NFTStorefrontV2.SaleCut(
110            receiver: self.fiatReceiver,
111            amount: effectiveSaleItemPrice - totalRoyaltyCut
112        ))
113        assert(self.HWGarageCardV2Provider.borrow() != nil, message: "Missing or mis-typed HWGarageCardV2.Collection provider")
114
115        self.storefront = acct.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath)
116            ?? panic("Missing or mis-typed NFTStorefront Storefront")
117
118        for marketplace in marketplacesAddress {
119            // Here we are making a fair assumption that all given addresses would have
120            // the capability to receive the
121            self.marketplacesCapability.append(getAccount(marketplace).getCapability<&{FungibleToken.Receiver}>(/public/flowTokenReceiver))
122        }
123    }
124
125    execute {
126        // Create listing
127        self.storefront.createListing(
128            nftProviderCapability: self.HWGarageCardV2Provider,
129            nftType: Type<@HWGarageCardV2.NFT>(),
130            nftID: saleItemID,
131            salePaymentVaultType: Type<@FlowToken.Vault>(),
132            saleCuts: self.saleCuts,
133            marketplacesCapability: self.marketplacesCapability.length == 0 ? nil : self.marketplacesCapability,
134            customID: customID,
135            commissionAmount: commissionAmount,
136            expiry: expiry
137        )
138    }
139}