Smart Contract

DapperOffersV2

A.b8ea91944fd51c43.DapperOffersV2

Valid From

86,002,358

Deployed

1d ago
Feb 24, 2026, 11:58:06 PM UTC

Dependents

748511 imports
1import OffersV2 from 0xb8ea91944fd51c43
2import FungibleToken from 0xf233dcee88fe0abe
3import NonFungibleToken from 0x1d7e57aa55817448
4import Resolver from 0xb8ea91944fd51c43
5import Burner from 0xf233dcee88fe0abe
6
7// DapperOffersV2
8//
9// Each account that wants to create offers for NFTs installs an DapperOffer
10// resource and creates individual Offers for NFTs within it.
11//
12// The DapperOffer resource contains the methods to add, remove, borrow and
13// get details on Offers contained within it.
14//
15access(all) contract DapperOffersV2 {
16
17    access(all) entitlement Manager
18    access(all) entitlement ProxyManager
19    // DapperOffersV2
20    // This contract has been deployed.
21    // Event consumers can now expect events from this contract.
22    //
23    access(all) event DapperOffersInitialized()
24
25    /// DapperOfferInitialized
26    // A DapperOffer resource has been created.
27    //
28    access(all) event DapperOfferInitialized(DapperOfferResourceId: UInt64)
29
30    // DapperOfferDestroyed
31    // A DapperOffer resource has been destroyed.
32    // Event consumers can now stop processing events from this resource.
33    //
34    access(all) event DapperOfferDestroyed(DapperOfferResourceId: UInt64)
35
36
37    // DapperOfferPublic
38    // An interface providing a useful public interface to a Offer.
39    //
40    access(all) resource interface DapperOfferPublic {
41        // getOfferIds
42        // Get a list of Offer ids created by the resource.
43        //
44        access(all) fun getOfferIds(): [UInt64]
45        // borrowOffer
46        // Borrow an Offer to either accept the Offer or get details on the Offer.
47        //
48        access(all) fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}?
49        // cleanup
50        // Remove an Offer
51        //
52        access(all) fun cleanup(offerId: UInt64)
53        // addProxyCapability
54        // Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
55        //
56        access(all) fun addProxyCapability(
57            account: Address,
58            cap: Capability<auth(ProxyManager) &DapperOffer>
59        )
60    }
61
62    // DapperOfferManager
63    // An interface providing a management interface for an DapperOffer resource.
64    //
65    access(all) resource interface DapperOfferManager {
66        // createOffer
67        // Allows the DapperOffer owner to create Offers.
68        //
69        access(Manager) fun createOffer(
70            vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
71            nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
72            nftType: Type,
73            amount: UFix64,
74            royalties: [OffersV2.Royalty],
75            offerParamsString: {String:String},
76            offerParamsUFix64: {String:UFix64},
77            offerParamsUInt64: {String:UInt64},
78            resolverCapability: Capability<&{Resolver.ResolverPublic}>,
79        ): UInt64
80        // removeOffer
81        // Allows the DapperOffer owner to remove offers
82        //
83        access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
84    }
85
86    // DapperOfferProxyManager
87    // An interface providing removeOffer on behalf of an DapperOffer owner.
88    //
89    access(all) resource interface DapperOfferProxyManager {
90        // removeOffer
91        // Allows the DapperOffer owner to remove offers
92        //
93        access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
94        // removeOfferFromProxy
95        // Allows the DapperOffer proxy owner to remove offers
96        //
97        access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64)
98    }
99
100
101    // DapperOffer
102    // A resource that allows its owner to manage a list of Offers, and anyone to interact with them
103    // in order to query their details and accept the Offers for NFTs that they represent.
104    //
105    access(all) resource DapperOffer :DapperOfferManager, DapperOfferPublic, DapperOfferProxyManager {
106        // The dictionary of Address to DapperOfferProxyManager capabilities.
107        access(self) var removeOfferCapability: {Address:Capability<auth(ProxyManager) &DapperOffer>}
108        // The dictionary of Offer uuids to Offer resources.
109        access(self) var offers: @{UInt64:OffersV2.Offer}
110
111        // addProxyCapability
112        // Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
113        //
114        access(all) fun addProxyCapability(account: Address, cap: Capability<auth(ProxyManager) &DapperOffer>) {
115            pre {
116                cap != nil: "Invalid admin capability"
117            }
118            self.removeOfferCapability[account] = cap
119        }
120
121        // removeOfferFromProxy
122        // Allows the DapperOffer proxy owner to remove offers
123        //
124        access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64) {
125            pre {
126                self.removeOfferCapability[account] != nil:
127                    "Cannot remove offers until the token admin has deposited the account registration capability"
128            }
129
130            let adminRef = self.removeOfferCapability[account]!
131
132            adminRef.borrow()!.removeOffer(offerId: offerId)
133        }
134
135
136        // createOffer
137        // Allows the DapperOffer owner to create Offers.
138        //
139        access(Manager) fun createOffer(
140            vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
141            nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
142            nftType: Type,
143            amount: UFix64,
144            royalties: [OffersV2.Royalty],
145            offerParamsString: {String:String},
146            offerParamsUFix64: {String:UFix64},
147            offerParamsUInt64: {String:UInt64},
148            resolverCapability: Capability<&{Resolver.ResolverPublic}>,
149        ): UInt64 {
150            let offer <- OffersV2.makeOffer(
151                vaultRefCapability: vaultRefCapability,
152                nftReceiverCapability: nftReceiverCapability,
153                nftType: nftType,
154                amount: amount,
155                royalties: royalties,
156                offerParamsString: offerParamsString,
157                offerParamsUFix64: offerParamsUFix64,
158                offerParamsUInt64: offerParamsUInt64,
159                resolverCapability: resolverCapability,
160            )
161
162            let offerId = offer.uuid
163            let dummy <- self.offers[offerId] <- offer
164            destroy dummy
165
166            return offerId
167        }
168
169        // removeOffer
170        // Remove an Offer that has not yet been accepted from the collection and destroy it.
171        //
172        access(Manager | ProxyManager) fun removeOffer(offerId: UInt64) {
173            let offer <- self.offers.remove(key: offerId) ?? panic("missing offer")
174            // offer.customDestroy()
175            
176            Burner.burn(<-offer)
177        }
178
179        // getOfferIds
180        // Returns an array of the Offer resource IDs that are in the collection
181        //
182        access(all) view fun getOfferIds(): [UInt64] {
183            return self.offers.keys
184        }
185
186        // borrowOffer
187        // Returns a read-only view of the Offer for the given OfferID if it is contained by this collection.
188        //
189        access(all) view fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}? {
190            if self.offers[offerId] != nil {
191                return (&self.offers[offerId] as &{OffersV2.OfferPublic}?)!
192            } else {
193                return nil
194            }
195        }
196
197        // cleanup
198        // Remove an Offer *if* it has been accepted.
199        // Anyone can call, but at present it only benefits the account owner to do so.
200        // Kind purchasers can however call it if they like.
201        //
202        access(all) fun cleanup(offerId: UInt64) {
203            pre {
204                self.offers[offerId] != nil: "could not find Offer with given id"
205            }
206            let offer <- self.offers.remove(key: offerId)!
207            assert(offer.getDetails().purchased == true, message: "Offer is not purchased, only admin can remove")
208
209            Burner.burn(<-offer)
210        }
211
212        // constructor
213        //
214        init() {
215            self.removeOfferCapability = {}
216            self.offers <- {}
217            // Let event consumers know that this storefront will no longer exist.
218            emit DapperOfferInitialized(DapperOfferResourceId: self.uuid)
219        }
220
221        access(all) event ResourceDestroyed(
222            id: UInt64 = self.uuid
223        )
224    }
225
226    // createDapperOffer
227    // Make creating an DapperOffer publicly accessible.
228    //
229    access(all) fun createDapperOffer(): @DapperOffer {
230        return <-create DapperOffer()
231    }
232
233    access(all) let DapperOffersStoragePath: StoragePath
234    access(all) let DapperOffersPublicPath: PublicPath
235
236    init () {
237        self.DapperOffersStoragePath = /storage/DapperOffersV2
238        self.DapperOffersPublicPath = /public/DapperOffersV2
239
240        emit DapperOffersInitialized()
241    }
242}
243