MarketplaceSEALED
╱◇^@╱▓▪◆╲^╲%~□╳□!▪#◇□!░%&#□*^○◆%▪◆▫░▒*#□▫^^▓□░╳●*▫▪○░▒@&&~□█●░%~
Transaction ID
Transaction Summary
MarketplaceCalled FungibleToken, NonFungibleToken, MetadataViews +5 more
Script Arguments
Cadence Script
1import FungibleToken from 0xf233dcee88fe0abe
2import NonFungibleToken from 0x1d7e57aa55817448
3import MetadataViews from 0x1d7e57aa55817448
4import TokenForwarding from 0xe544175ee0461c4b
5import DapperUtilityCoin from 0xead892083b3e2c6c
6import PackNFT from 0x0b2a3299cc857e29
7import IPackNFT from 0x18ddf0823a55a0ee
8import NFTStorefrontV2 from 0x4eb8a10cb9f87357
9
10/// Transaction that lists packNFTs for sale in Storefront.
11transaction() {
12 var ftReceiver: Capability<&AnyResource{FungibleToken.Receiver}>
13 let nftProvider: Capability<&AnyResource{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
14 let storefront: &NFTStorefrontV2.Storefront
15
16 // we only ever want to use DapperUtilityCoin
17 let universalDucReceiver: Address
18
19 let collectionRef: &PackNFT.Collection{NonFungibleToken.CollectionPublic}
20
21 prepare(user: AuthAccount) {
22 // we only ever want to use DapperUtilityCoin
23 self.universalDucReceiver = 0xead892083b3e2c6c
24
25 let PrivateCollectionPath = /private/TopShotPackNFTCollectionProviderForNFTStorefront
26
27 // ************************* Handling of DUC Recevier *************************** //
28 // Fetch the capability of the universal DUC receiver
29 let recipient = getAccount(self.universalDucReceiver).getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
30 assert(recipient.borrow() != nil, message: "Missing or mis-typed Fungible Token receiver for the DUC recipient")
31
32 // Check whether the receiver has the capability to receive the DUC
33 self.ftReceiver = user.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
34 if self.ftReceiver.borrow() == nil || !self.ftReceiver.borrow()!.isInstance(Type<@TokenForwarding.Forwarder>()) {
35 user.unlink(/public/dapperUtilityCoinReceiver)
36 // Create the forwarder and save it to the account that is doing the forwarding
37 let vault <- TokenForwarding.createNewForwarder(recipient: recipient)
38 user.save(<-vault, to: /storage/ducTokenForwarder)
39 // Link the new forwarding receiver capability
40 user.link<&{FungibleToken.Receiver}>(
41 /public/dapperUtilityCoinReceiver,
42 target: /storage/ducTokenForwarder
43 )
44 self.ftReceiver = user.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
45 }
46
47 // *************************** Seller account interactions *************************** //
48 // This checks for the public capability
49 if !user.getCapability<&PackNFT.Collection{IPackNFT.IPackNFTCollectionPublic}>(PackNFT.CollectionPublicPath)!.check() {
50 user.unlink(PackNFT.CollectionPublicPath)
51 user.link<&PackNFT.Collection{IPackNFT.IPackNFTCollectionPublic, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(PackNFT.CollectionPublicPath, target: PackNFT.CollectionStoragePath)
52 }
53
54 // Check if the Provider capability exists or not if ''no'' then create a new link for the same.
55 if !user.getCapability<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(PrivateCollectionPath)!.check() {
56 user.unlink(PrivateCollectionPath)
57 user.link<&PackNFT.Collection{IPackNFT.IPackNFTCollectionPublic, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, NonFungibleToken.Provider, MetadataViews.ResolverCollection}>(PrivateCollectionPath, target: PackNFT.CollectionStoragePath)
58 }
59
60 self.nftProvider = user.getCapability<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(PrivateCollectionPath)!
61
62 assert(self.nftProvider.borrow() != nil, message: "Missing or mis-typed PackNFT.Collection provider")
63
64 self.collectionRef = user
65 .getCapability<&PackNFT.Collection{NonFungibleToken.CollectionPublic}>(PackNFT.CollectionPublicPath).borrow()
66 ?? panic("Could not borrow a reference to the collection")
67
68 if user.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
69 // Create a new empty Storefront
70 let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
71 // save it to the account
72 user.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
73 // create a public capability for the Storefront
74 user.link<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath, target: NFTStorefrontV2.StorefrontStoragePath)
75 }
76 self.storefront = user.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath)!
77 }
78
79 execute {
80 let packNFTIDs = [196812582378637]
81 let saleItemPrices = [4.00000000]
82 for index, packNftID in packNFTIDs {
83 var totalRoyaltyCut = 0.0
84 let effectiveSaleItemPrice = UFix64(saleItemPrices[index])
85 var saleCuts: [NFTStorefrontV2.SaleCut] = []
86
87 let nft: &NonFungibleToken.NFT = self.collectionRef.borrowNFT(id: UInt64(packNftID))!
88
89 // Check whether the NFT implements the MetadataResolver or not.
90 if nft.getViews().contains(Type<MetadataViews.Royalties>()) {
91 let royaltiesRef = nft.resolveView(Type<MetadataViews.Royalties>()) ?? panic("Unable to retrieve the royalties")
92
93 let royalties = (royaltiesRef as! MetadataViews.Royalties).getRoyalties()
94
95 for royalty in royalties {
96 let royaltyReceiver = royalty.receiver
97
98 saleCuts.append(NFTStorefrontV2.SaleCut(receiver: royalty.receiver, amount: royalty.cut * effectiveSaleItemPrice))
99
100 totalRoyaltyCut = totalRoyaltyCut + royalty.cut * effectiveSaleItemPrice
101 }
102 }
103
104 // Append the cut for the seller.
105 saleCuts.append(NFTStorefrontV2.SaleCut(
106 receiver: self.ftReceiver,
107 amount: effectiveSaleItemPrice - totalRoyaltyCut
108 ))
109
110 // create listing
111 self.storefront.createListing(
112 nftProviderCapability: self.nftProvider,
113 nftType: Type<@PackNFT.NFT>(),
114 nftID: UInt64(packNftID),
115 salePaymentVaultType: Type<@DapperUtilityCoin.Vault>(),
116 saleCuts: saleCuts,
117 marketplacesCapability: nil,
118 customID: "DAPPER_MARKETPLACE",
119 commissionAmount: 0.0,
120 expiry: 32503708800 // year 3000
121 )
122 }
123 }
124}