MarketplaceSEALED
█╳◇╳^░○█^~○#╲^*$▓#◇*▒▒█▒○░■?○*○#□◆!░▪&□?@○╱$◆╲?▪▒╳□!%~▫╳?◆▓!◇╳○~
Transaction ID
Execution Fee
0.00002874 FLOWTransaction Summary
MarketplaceCalled FlowToken, FungibleToken, NonFungibleToken +7 more
Script Arguments
0removalListingResourceIDUInt64
227598908679399
1saleItemIDUInt64
1914022
2saleItemPriceUFix64
8.0
3customIDString?
RARIBLE
4commissionAmountUFix64
0.0
5expiryUInt64
1759271094
6marketplacesAddress[Address]
Cadence Script
1import FlowToken from 0x1654653399040a61
2import FungibleToken from 0xf233dcee88fe0abe
3import NonFungibleToken from 0x1d7e57aa55817448
4import MetadataViews from 0x1d7e57aa55817448
5import NFTStorefrontV2 from 0x4eb8a10cb9f87357
6
7 import HWGarageCard from 0xd0bcefdf1e67ea85
8 import HWGaragePack from 0xd0bcefdf1e67ea85
9 import HWGarageCardV2 from 0xd0bcefdf1e67ea85
10 import HWGaragePackV2 from 0xd0bcefdf1e67ea85
11 import HWGarageTokenV2 from 0xd0bcefdf1e67ea85
12
13
14transaction(removalListingResourceID: UInt64, saleItemID: UInt64, saleItemPrice: UFix64, customID: String?, commissionAmount: UFix64, expiry: UInt64, marketplacesAddress: [Address]) {
15 let tokenReceiver: Capability<&{FungibleToken.Receiver}>
16 let HWGarageCardV2Provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>
17 let storefront: auth(NFTStorefrontV2.CreateListing, NFTStorefrontV2.RemoveListing) &NFTStorefrontV2.Storefront
18 var saleCuts: [NFTStorefrontV2.SaleCut]
19 var marketplacesCapability: [Capability<&{FungibleToken.Receiver}>]
20
21 prepare(acct: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, Storage) &Account) {
22
23
24
25
26 // HWGaragePack
27 let packCollectionData: MetadataViews.NFTCollectionData = HWGaragePack.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
28 ?? panic("ViewResolver does not resolve NFTCollectionData view")
29
30 // exit if packCollection exists
31 if acct.storage.borrow<&HWGaragePack.Collection>(from: packCollectionData.storagePath) == nil {
32 // create a new empty packCollection for HWGaragePack
33 let packCollection: @{NonFungibleToken.Collection} <- HWGaragePack.createEmptyCollection(nftType: Type<@HWGaragePack.NFT>())
34
35 // save HWGaragePack packCollection to the account
36 acct.storage.save(<-packCollection, to: packCollectionData.storagePath)
37
38 // create a public capability for the HWGaragePack packCollection
39 acct.capabilities.unpublish(packCollectionData.publicPath) // remove any current pubCap
40 let packCollectionCap: Capability<&HWGaragePack.Collection> = acct.capabilities.storage.issue<&HWGaragePack.Collection>(packCollectionData.storagePath)
41 acct.capabilities.publish(packCollectionCap, at: packCollectionData.publicPath)
42 }
43
44 // HWGarageCard
45 let cardCollectionData: MetadataViews.NFTCollectionData = HWGarageCard.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
46 ?? panic("ViewResolver does not resolve NFTCollectionData view")
47
48 // exit if cardCollection exists
49 if acct.storage.borrow<&HWGarageCard.Collection>(from: cardCollectionData.storagePath) == nil {
50 // create a new empty cardCollection for HWGarageCard
51 let cardCollection: @{NonFungibleToken.Collection} <- HWGarageCard.createEmptyCollection(nftType: Type<@HWGarageCard.NFT>())
52
53 // save HWGarageCard cardCollection to the account
54 acct.storage.save(<-cardCollection, to: cardCollectionData.storagePath)
55
56 // create a public capability for the HWGarageCard cardCollection
57 acct.capabilities.unpublish(cardCollectionData.publicPath) // remove any current pubCap
58 let cardCollectionCap: Capability<&HWGarageCard.Collection> = acct.capabilities.storage.issue<&HWGarageCard.Collection>(cardCollectionData.storagePath)
59 acct.capabilities.publish(cardCollectionCap, at: cardCollectionData.publicPath)
60 }
61
62 // HWGarageTokenV2
63 let tokenCollectionDataV2: MetadataViews.NFTCollectionData = HWGarageTokenV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
64 ?? panic("ViewResolver does not resolve NFTCollectionData view")
65
66 if acct.storage.borrow<&HWGarageTokenV2.Collection>(from: tokenCollectionDataV2.storagePath) == nil {
67 // create a new empty tokenCollection for HWGarageTokenV2
68 let tokenCollection: @{NonFungibleToken.Collection} <- HWGarageTokenV2.createEmptyCollection(nftType: Type<@HWGarageTokenV2.NFT>())
69
70 // save HWGarageTokenV2 tokenCollection to the account
71 acct.storage.save(<-tokenCollection, to: tokenCollectionDataV2.storagePath)
72
73 // create a public capability for the HWGarageTokenV2 tokenCollection
74 acct.capabilities.unpublish(tokenCollectionDataV2.publicPath) // remove any current pubCap
75 let tokenCollectionCap = acct.capabilities.storage.issue<&HWGarageTokenV2.Collection>(tokenCollectionDataV2.storagePath)
76 acct.capabilities.publish(tokenCollectionCap, at: tokenCollectionDataV2.publicPath)
77 }
78
79 // HWGarageCardV2
80 let cardCollectionDataV2: MetadataViews.NFTCollectionData = HWGarageCardV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
81 ?? panic("ViewResolver does not resolve NFTCollectionData view")
82
83 // exit if cardCollection exists
84 if acct.storage.borrow<&HWGarageCardV2.Collection>(from: cardCollectionDataV2.storagePath) == nil {
85 // create a new empty cardCollection for HWGarageCardV2
86 let cardCollection: @{NonFungibleToken.Collection} <- HWGarageCardV2.createEmptyCollection(nftType: Type<@HWGarageCardV2.NFT>())
87
88 // save HWGarageCardV2 cardCollection to the account
89 acct.storage.save(<-cardCollection, to: cardCollectionDataV2.storagePath)
90
91 // create a public capability for the HWGarageCardV2 cardCollection
92 acct.capabilities.unpublish(cardCollectionDataV2.publicPath) // remove any current pubCap
93 let cardCollectionCap = acct.capabilities.storage.issue<&HWGarageCardV2.Collection>(cardCollectionDataV2.storagePath)
94 acct.capabilities.publish(cardCollectionCap, at: cardCollectionDataV2.publicPath)
95 }
96
97 // HWGaragePackV2
98 let garagePackCollectionDataV2: MetadataViews.NFTCollectionData = HWGaragePackV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
99 ?? panic("ViewResolver does not resolve NFTCollectionData view")
100
101 // exit if packCollection exists
102 if acct.storage.borrow<&HWGaragePackV2.Collection>(from: garagePackCollectionDataV2.storagePath) == nil {
103 // create a new empty packCollection for HWGaragePackV2
104 let packCollection: @{NonFungibleToken.Collection} <- HWGaragePackV2.createEmptyCollection(nftType: Type<@HWGaragePackV2.NFT>())
105
106 // save HWGaragePackV2 packCollection to the account
107 acct.storage.save(<-packCollection, to: garagePackCollectionDataV2.storagePath)
108
109 // create a public capability for the HWGaragePackV2 packCollection
110 acct.capabilities.unpublish(garagePackCollectionDataV2.publicPath) // remove any current pubCap
111 let packCollectionCap = acct.capabilities.storage.issue<&HWGaragePackV2.Collection>(garagePackCollectionDataV2.storagePath)
112 acct.capabilities.publish(packCollectionCap, at: garagePackCollectionDataV2.publicPath)
113 }
114
115
116
117 if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
118
119 // Create a new empty Storefront
120 let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
121
122 // save it to the account
123 acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
124
125 // create a public capability for the Storefront
126 let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
127 NFTStorefrontV2.StorefrontStoragePath
128 )
129 acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
130 }
131
132
133
134 self.saleCuts = []
135 self.marketplacesCapability = []
136
137 let collectionData = HWGarageCardV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
138 ?? panic("ViewResolver does not resolve NFTCollectionData view")
139
140 // Receiver for the sale cut.
141 self.tokenReceiver = acct.capabilities.get<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
142 assert(self.tokenReceiver.borrow() != nil, message: "Missing or mis-typed FT receiver")
143
144 self.HWGarageCardV2Provider = acct.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(
145 collectionData.storagePath
146 )
147 assert(self.HWGarageCardV2Provider.check(), message: "Missing or mis-typed HWGaragePackV2 provider")
148
149 let collection = acct.capabilities.borrow<&{NonFungibleToken.Collection}>(collectionData.publicPath)
150 ?? panic("Could not borrow a reference to the signer's collection")
151
152 var totalRoyaltyCut = 0.0
153 let effectiveSaleItemPrice = saleItemPrice - commissionAmount
154 let nft = collection.borrowNFT(saleItemID)!
155 // Check whether the NFT implements the MetadataResolver or not.
156 if nft.getViews().contains(Type<MetadataViews.Royalties>()) {
157 let royaltiesRef = nft.resolveView(Type<MetadataViews.Royalties>())?? panic("Unable to retrieve the royalties")
158 let royalties = (royaltiesRef as! MetadataViews.Royalties).getRoyalties()
159 for royalty in royalties {
160 // TODO - Verify the type of the vault and it should exists
161 let royaltyValue = royalty.cut * saleItemPrice
162 self.saleCuts.append(NFTStorefrontV2.SaleCut(receiver: royalty.receiver, amount: royaltyValue))
163 totalRoyaltyCut = totalRoyaltyCut + royaltyValue
164 }
165 }
166 // Append the cut for the seller.
167 self.saleCuts.append(
168 NFTStorefrontV2.SaleCut(
169 receiver: self.tokenReceiver,
170 amount: effectiveSaleItemPrice - totalRoyaltyCut
171 )
172 )
173 assert(self.HWGarageCardV2Provider.borrow() != nil, message: "Missing or mis-typed Collection provider")
174
175 self.storefront = acct.storage.borrow<auth(NFTStorefrontV2.CreateListing, NFTStorefrontV2.RemoveListing) &NFTStorefrontV2.Storefront>(
176 from: NFTStorefrontV2.StorefrontStoragePath
177 ) ?? panic("Missing or mis-typed NFTStorefront Storefront")
178
179 for marketplace in marketplacesAddress {
180 // Here we are making a fair assumption that all given addresses would have
181 // the capability to receive the `ExampleToken`
182 self.marketplacesCapability.append(
183 getAccount(marketplace).capabilities.get<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
184 )
185 }
186 }
187
188 execute {
189 var existingListingIDs = self.storefront.getExistingListingIDs(
190 nftType: Type<@HWGarageCardV2.NFT>(),
191 nftID: saleItemID
192 )
193 // remove existing listings
194 for listingID in existingListingIDs {
195 self.storefront.removeListing(listingResourceID: listingID)
196 }
197 // Create listing
198 self.storefront.createListing(
199 nftProviderCapability: self.HWGarageCardV2Provider,
200 nftType: Type<@HWGarageCardV2.NFT>(),
201 nftID: saleItemID,
202 salePaymentVaultType: Type<@FlowToken.Vault>(),
203 saleCuts: self.saleCuts,
204 marketplacesCapability: self.marketplacesCapability.length == 0 ? nil : self.marketplacesCapability,
205 customID: customID,
206 commissionAmount: commissionAmount,
207 expiry: expiry
208 )
209 }
210}