MarketplaceSEALED

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

Transaction ID

Timestamp

Sep 03, 2024, 01:47:38 AM UTC
1y ago

Block Height

85,883,163

Computation

0

Execution Fee

0.00001402 FLOW

Transaction Summary

Marketplace

Called FlowToken, FungibleToken, NonFungibleToken +7 more

Script Arguments

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