Smart Contract

Admin

A.097bafa4e0b48eef.Admin

Deployed

2d ago
Feb 26, 2026, 03:12:51 AM UTC

Dependents

1 imports
1import FungibleToken from 0xf233dcee88fe0abe
2import FlowToken from 0x1654653399040a61
3import NonFungibleToken from 0x1d7e57aa55817448
4import MetadataViews from 0x1d7e57aa55817448
5import Profile from 0x097bafa4e0b48eef
6import FIND from 0x097bafa4e0b48eef
7import Debug from 0x097bafa4e0b48eef
8import Clock from 0x097bafa4e0b48eef
9import FTRegistry from 0x097bafa4e0b48eef
10import FindForge from 0x097bafa4e0b48eef
11import FindForgeOrder from 0x097bafa4e0b48eef
12import FindPack from 0x097bafa4e0b48eef
13import NFTCatalog from 0x49a7cda3a1eecc29
14import FINDNFTCatalogAdmin from 0x097bafa4e0b48eef
15import FindViews from 0x097bafa4e0b48eef
16import NameVoucher from 0x097bafa4e0b48eef
17import ViewResolver from 0x1d7e57aa55817448
18
19access(all) contract Admin {
20    // Entitlements
21    access(all) entitlement Owner
22
23    //store the proxy for the admin
24    access(all) let AdminProxyPublicPath: PublicPath
25    access(all) let AdminProxyStoragePath: StoragePath
26
27    /// ===================================================================================
28    // Admin things
29    /// ===================================================================================
30
31    //Admin client to use for capability receiver pattern
32    access(all) fun createAdminProxyClient() : @AdminProxy {
33        return <- create AdminProxy()
34    }
35
36    //interface to use for capability receiver pattern
37    access(all) resource interface AdminProxyClient {
38        access(all) fun addCapability(_ cap: Capability<&FIND.Network>)
39    }
40
41    //admin proxy with capability receiver
42    access(all) resource AdminProxy: AdminProxyClient {
43
44        access(self) var capability: Capability<&FIND.Network>?
45
46        access(all) fun addCapability(_ cap: Capability<&FIND.Network>) {
47            pre {
48                cap.check() : "Invalid server capablity"
49                self.capability == nil : "Server already set"
50            }
51            self.capability = cap
52        }
53
54        access(Owner) fun addPublicForgeType(name: String, forgeType : Type) {
55            pre {
56                self.capability != nil: "Cannot create FIND, capability is not set"
57            }
58
59            FindForge.addPublicForgeType(forgeType: forgeType)
60        }
61
62        access(Owner) fun addPrivateForgeType(name: String, forgeType : Type) {
63            pre {
64                self.capability != nil: "Cannot create FIND, capability is not set"
65            }
66
67            FindForge.addPrivateForgeType(name: name, forgeType: forgeType)
68        }
69
70        access(Owner) fun removeForgeType(_ type : Type) {
71            pre {
72                self.capability != nil: "Cannot create FIND, capability is not set"
73            }
74
75            FindForge.removeForgeType(type: type)
76        }
77
78        access(Owner) fun addForgeContractData(lease: String, forgeType: Type , data: AnyStruct) {
79            pre {
80                self.capability != nil: "Cannot create FIND, capability is not set"
81            }
82
83            FindForge.adminAddContractData(lease: lease, forgeType: forgeType , data: data)
84        }
85
86        access(Owner) fun addForgeMintType(_ mintType: String) {
87            pre {
88                self.capability != nil: "Cannot create FIND, capability is not set"
89            }
90
91            FindForgeOrder.addMintType(mintType)
92        }
93
94        access(Owner) fun orderForge(leaseName: String, mintType: String, minterCut: UFix64?, collectionDisplay: MetadataViews.NFTCollectionDisplay) {
95            pre {
96                self.capability != nil: "Cannot create FIND, capability is not set"
97            }
98
99            FindForge.adminOrderForge(leaseName: leaseName, mintType: mintType, minterCut: minterCut, collectionDisplay: collectionDisplay)
100        }
101
102        access(Owner) fun cancelForgeOrder(leaseName: String, mintType: String){
103            pre {
104                self.capability != nil: "Cannot create FIND, capability is not set"
105            }
106            FindForge.cancelForgeOrder(leaseName: leaseName, mintType: mintType)
107        }
108
109        access(Owner) fun fulfillForgeOrder(contractName: String, forgeType: Type) : MetadataViews.NFTCollectionDisplay {
110            pre {
111                self.capability != nil: "Cannot create FIND, capability is not set"
112            }
113
114            return FindForge.fulfillForgeOrder(contractName, forgeType: forgeType)
115        }
116
117        /// Set the wallet used for the network
118        /// @param _ The FT receiver to send the money to
119        access(Owner) fun setWallet(_ wallet: Capability<&{FungibleToken.Receiver}>) {
120            pre {
121                self.capability != nil: "Cannot create FIND, capability is not set"
122            }
123
124            let walletRef = self.capability!.borrow() ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(self.capability!.address.toString()))
125            walletRef.setWallet(wallet)
126        }
127
128        /// Enable or disable public registration
129        access(Owner) fun setPublicEnabled(_ enabled: Bool) {
130            pre {
131                self.capability != nil: "Cannot create FIND, capability is not set"
132            }
133
134            let walletRef = self.capability!.borrow() ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(self.capability!.address.toString()))
135            walletRef.setPublicEnabled(enabled)
136        }
137
138        access(Owner) fun setAddonPrice(name: String, price: UFix64) {
139            pre {
140                self.capability != nil: "Cannot create FIND, capability is not set"
141            }
142
143            let walletRef = self.capability!.borrow() ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(self.capability!.address.toString()))
144            walletRef.setAddonPrice(name: name, price: price)
145        }
146
147        access(Owner) fun setPrice(defaultPrice: UFix64, additional : {Int: UFix64}) {
148            pre {
149                self.capability != nil: "Cannot create FIND, capability is not set"
150            }
151
152            let walletRef = self.capability!.borrow() ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(self.capability!.address.toString()))
153            walletRef.setPrice(defaultPrice: defaultPrice, additionalPrices: additional)
154        }
155
156        access(Owner) fun register(name: String, profile: Capability<&{Profile.Public}>, leases: Capability<&{FIND.LeaseCollectionPublic}>){
157            pre {
158                self.capability != nil: "Cannot create FIND, capability is not set"
159            }
160
161            if !FIND.validateFindName(name) {
162                panic("A FIND name has to be lower-cased alphanumeric or dashes and between 3 and 16 characters")
163            } 
164
165            let walletRef = self.capability!.borrow() ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(self.capability!.address.toString()))
166            walletRef.internal_register(name:name, profile: profile, leases: leases)
167        }
168
169        access(Owner) fun addAddon(name:String, addon:String){
170            pre {
171                self.capability != nil: "Cannot create FIND, capability is not set"
172            }
173
174            if !FIND.validateFindName(name) {
175                panic("A FIND name has to be lower-cased alphanumeric or dashes and between 3 and 16 characters")
176            }
177
178            let user = FIND.lookupAddress(name) ?? panic("Cannot find lease owner. Lease : ".concat(name))
179            let ref = getAccount(user).capabilities.get<&{FIND.LeaseCollectionPublic}>(FIND.LeasePublicPath)!.borrow() ?? panic("Cannot borrow reference to lease collection of user : ".concat(name))
180            ref.adminAddAddon(name:name, addon:addon)
181        }
182
183        access(Owner) fun adminSetMinterPlatform(name: String, forgeType: Type, minterCut: UFix64?, description: String, externalURL: String, squareImage: String, bannerImage: String, socials: {String : String}) {
184            pre {
185                self.capability != nil: "Cannot create FIND, capability is not set"
186            }
187
188            if !FIND.validateFindName(name) {
189                panic("A FIND name has to be lower-cased alphanumeric or dashes and between 3 and 16 characters")
190            }
191
192            FindForge.adminSetMinterPlatform(leaseName: name, forgeType: forgeType, minterCut: minterCut, description: description, externalURL: externalURL, squareImage: squareImage, bannerImage: bannerImage, socials: socials)
193        }
194
195        access(Owner) fun mintForge(name: String, forgeType: Type , data: AnyStruct, receiver: &{NonFungibleToken.Receiver}) {
196            pre {
197                self.capability != nil: "Cannot create FIND, capability is not set"
198            }
199
200            FindForge.mintAdmin(leaseName: name, forgeType: forgeType, data: data, receiver: receiver)
201        }
202
203        access(Owner) fun advanceClock(_ time: UFix64) {
204            pre {
205                self.capability != nil: "Cannot create FIND, capability is not set"
206            }
207            Debug.enable(true)
208            Clock.enable()
209            Clock.tick(time)
210        }
211
212
213        access(Owner) fun debug(_ value: Bool) {
214            pre {
215                self.capability != nil: "Cannot create FIND, capability is not set"
216            }
217            Debug.enable(value)
218        }
219
220        /*
221        access(all) fun setViewConverters(from: Type, converters: [{Dandy.ViewConverter}]) {
222            pre {
223                self.capability != nil: "Cannot create FIND, capability is not set"
224            }
225
226            Dandy.setViewConverters(from: from, converters: converters)
227        }
228        */
229
230        /// ===================================================================================
231        // Fungible Token Registry
232        /// ===================================================================================
233
234        // Registry FungibleToken Information
235        access(Owner) fun setFTInfo(alias: String, type: Type, tag: [String], icon: String?, receiverPath: PublicPath, balancePath: PublicPath, vaultPath: StoragePath) {
236            pre {
237                self.capability != nil: "Cannot create FIND, capability is not set"
238            }
239            FTRegistry.setFTInfo(alias: alias, type: type, tag: tag, icon: icon, receiverPath: receiverPath, balancePath: balancePath, vaultPath:vaultPath)
240
241        }
242
243        // Remove FungibleToken Information by type identifier
244        access(Owner) fun removeFTInfoByTypeIdentifier(_ typeIdentifier: String) {
245            pre {
246                self.capability != nil: "Cannot create FIND, capability is not set"
247            }
248            FTRegistry.removeFTInfoByTypeIdentifier(typeIdentifier)
249        }
250
251
252        // Remove FungibleToken Information by alias
253        access(Owner) fun removeFTInfoByAlias(_ alias: String) {
254            pre {
255                self.capability != nil: "Cannot create FIND, capability is not set"
256            }
257            FTRegistry.removeFTInfoByAlias(alias)
258        }
259
260        /// ===================================================================================
261        // Find Pack
262        /// ===================================================================================
263
264        access(Owner) fun getAuthPointer(pathIdentifier: String, id: UInt64) : FindViews.AuthNFTPointer {
265            pre {
266                self.capability != nil: "Cannot create Admin, capability is not set"
267            }
268
269            let storagePath = StoragePath(identifier: pathIdentifier)!
270            let account=Admin.account
271            let providerIdentifier = pathIdentifier.concat("Provider")
272            let providerStoragePath = StoragePath(identifier: providerIdentifier)!
273
274            //if this stores anything but this it will panic, why does it not return nil?
275            var existingProvider= account.storage.copy<Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection, NonFungibleToken.Provider, ViewResolver.ResolverCollection}>>(from: providerStoragePath) 
276            if existingProvider==nil {
277                existingProvider=account.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection, NonFungibleToken.Provider, ViewResolver.ResolverCollection}>(storagePath)
278                //we save it to storage to memoize it
279                account.storage.save(existingProvider!, to: providerStoragePath)
280                log("create new cap")
281            }
282            var providerCap = existingProvider!
283
284
285            return FindViews.AuthNFTPointer(cap: providerCap, id: id)
286        }
287
288        access(Owner) fun mintFindPack(packTypeName: String, typeId:UInt64,hash: String) {
289            pre {
290                self.capability != nil: "Cannot create Admin, capability is not set"
291            }
292            let pathIdentifier = FindPack.getPacksCollectionPath(packTypeName: packTypeName, packTypeId: typeId)
293            let path = PublicPath(identifier: pathIdentifier)!
294            let receiver = Admin.account.capabilities.borrow<&{NonFungibleToken.Receiver, ViewResolver.ResolverCollection}>(path) ?? panic("Cannot borrow reference to receiver. receiver address: ".concat(path.toString()))
295            let mintPackData = FindPack.MintPackData(packTypeName: packTypeName, typeId: typeId, hash: hash, verifierRef: FindForge.borrowVerifier())
296            FindForge.adminMint(lease: packTypeName, forgeType: Type<@FindPack.Forge>() , data: mintPackData, receiver: receiver)
297        }
298
299        access(Owner) fun fulfillFindPack(packId:UInt64, types:[Type], rewardIds: [UInt64], salt:String) {
300            pre {
301                self.capability != nil: "Cannot create Admin, capability is not set"
302            }
303            FindPack.fulfill(packId:packId, types:types, rewardIds:rewardIds, salt:salt)
304        }
305
306        access(Owner) fun requeueFindPack(packId:UInt64) {
307            pre {
308                self.capability != nil: "Cannot create Admin, capability is not set"
309            }
310
311            let cap= Admin.account.storage.borrow<auth(FindPack.Owner) &FindPack.Collection>(from: FindPack.DLQCollectionStoragePath)!
312            cap.requeue(packId: packId)
313        }
314
315        access(Owner) fun getFindRoyaltyCap() : Capability<&{FungibleToken.Receiver}> {
316            pre {
317                self.capability != nil: "Cannot create Admin, capability is not set"
318            }
319
320            return Admin.account.capabilities.get<&{FungibleToken.Receiver}>(Profile.publicReceiverPath)!
321        }
322
323        /// ===================================================================================
324        // FINDNFTCatalog
325        /// ===================================================================================
326
327        access(Owner) fun addCatalogEntry(collectionIdentifier : String, metadata : NFTCatalog.NFTCatalogMetadata) {
328            pre {
329                self.capability != nil: "Cannot create Admin, capability is not set"
330            }
331
332            let FINDCatalogAdmin = Admin.account.storage.borrow<&FINDNFTCatalogAdmin.Admin>(from: FINDNFTCatalogAdmin.AdminStoragePath) ?? panic("Cannot borrow reference to Find NFT Catalog admin resource")
333            FINDCatalogAdmin.addCatalogEntry(collectionIdentifier : collectionIdentifier, metadata : metadata)
334        }
335
336        access(Owner) fun removeCatalogEntry(collectionIdentifier : String) {
337            pre {
338                self.capability != nil: "Cannot create Admin, capability is not set"
339            }
340
341            let FINDCatalogAdmin = Admin.account.storage.borrow<&FINDNFTCatalogAdmin.Admin>(from: FINDNFTCatalogAdmin.AdminStoragePath) ?? panic("Cannot borrow reference to Find NFT Catalog admin resource")
342            FINDCatalogAdmin.removeCatalogEntry(collectionIdentifier : collectionIdentifier)
343        }
344
345        access(Owner) fun getSwitchboardReceiverPublic() : Capability<&{FungibleToken.Receiver}> {
346            // we hard code it here instead, to avoid importing just for path
347            return Admin.account.capabilities.get<&{FungibleToken.Receiver}>(/public/GenericFTReceiver)!
348        }
349
350        /// ===================================================================================
351        // Name Voucher
352        /// ===================================================================================
353
354        access(Owner) fun mintNameVoucher(receiver : &{NonFungibleToken.Receiver}, minCharLength : UInt64) : UInt64  {
355            pre {
356                self.capability != nil: "Cannot create Admin, capability is not set"
357            }
358
359            return NameVoucher.mintNFT(recipient: receiver, minCharLength: minCharLength)
360        }
361
362        access(Owner) fun mintNameVoucherToFind(minCharLength : UInt64) : UInt64 {
363            pre {
364                self.capability != nil: "Cannot create Admin, capability is not set"
365            }
366
367            let receiver = Admin.account.storage.borrow<&NameVoucher.Collection>(from: NameVoucher.CollectionStoragePath)!
368            return NameVoucher.mintNFT(recipient: receiver, minCharLength: minCharLength)
369        }
370
371        init() {
372            self.capability = nil
373        }
374    }
375
376    init() {
377        self.AdminProxyPublicPath= /public/findAdminProxy
378        self.AdminProxyStoragePath=/storage/findAdminProxy
379    }
380}
381
382