Smart Contract
FindMarketAdmin
A.097bafa4e0b48eef.FindMarketAdmin
1import FungibleToken from 0xf233dcee88fe0abe
2import MetadataViews from 0x1d7e57aa55817448
3import FIND from 0x097bafa4e0b48eef
4import FindMarket from 0x097bafa4e0b48eef
5import FindMarketCutStruct from 0x097bafa4e0b48eef
6
7access(all) contract FindMarketAdmin {
8 // Entitlements
9 access(all) entitlement Owner
10
11 //store the proxy for the admin
12 access(all) let AdminProxyPublicPath: PublicPath
13 access(all) let AdminProxyStoragePath: StoragePath
14
15 /// ===================================================================================
16 // Admin things
17 /// ===================================================================================
18
19 //Admin client to use for capability receiver pattern
20 access(all) fun createAdminProxyClient() : @AdminProxy {
21 return <- create AdminProxy()
22 }
23
24 //interface to use for capability receiver pattern
25 access(all) resource interface AdminProxyClient {
26 access(all) fun addCapability(_ cap: Capability<&FIND.Network>)
27 }
28
29 //admin proxy with capability receiver
30 access(all) resource AdminProxy: AdminProxyClient {
31
32 access(self) var capability: Capability<&FIND.Network>?
33
34 access(all) fun addCapability(_ cap: Capability<&FIND.Network>) {
35 pre {
36 cap.check() : "Invalid server capablity"
37 self.capability == nil : "Server already set"
38 }
39 self.capability = cap
40 }
41
42 access(Owner) fun createFindMarket(name: String, address:Address, findCutSaleItem: FindMarket.TenantSaleItem?) : Capability<&FindMarket.Tenant> {
43 pre {
44 self.capability != nil: "Cannot create FIND, capability is not set"
45 }
46
47 return FindMarket.createFindMarket(name:name, address:address, findCutSaleItem: findCutSaleItem)
48 }
49
50 access(Owner) fun removeFindMarketTenant(tenant: Address) {
51 pre {
52 self.capability != nil: "Cannot create FIND, capability is not set"
53 }
54
55 FindMarket.removeFindMarketTenant(tenant: tenant)
56 }
57
58 access(Owner) fun getFindMarketClient(): &FindMarket.TenantClient{
59 pre {
60 self.capability != nil: "Cannot create FIND, capability is not set"
61 }
62
63 let path = FindMarket.TenantClientStoragePath
64 return FindMarketAdmin.account.storage.borrow<auth(FindMarket.TenantClientOwner) &FindMarket.TenantClient>(from: path) ?? panic("Cannot borrow Find market tenant client Reference.")
65 }
66
67 /// ===================================================================================
68 // Find Market Options
69 /// ===================================================================================
70 access(Owner) fun addSaleItemType(_ type: Type) {
71 pre {
72 self.capability != nil: "Cannot create FIND, capability is not set"
73 }
74 FindMarket.addSaleItemType(type)
75 }
76
77 access(Owner) fun addMarketBidType(_ type: Type) {
78 pre {
79 self.capability != nil: "Cannot create FIND, capability is not set"
80 }
81 FindMarket.addMarketBidType(type)
82 }
83
84 access(Owner) fun addSaleItemCollectionType(_ type: Type) {
85 pre {
86 self.capability != nil: "Cannot create FIND, capability is not set"
87 }
88 FindMarket.addSaleItemCollectionType(type)
89 }
90
91 access(Owner) fun addMarketBidCollectionType(_ type: Type) {
92 pre {
93 self.capability != nil: "Cannot create FIND, capability is not set"
94 }
95 FindMarket.addMarketBidCollectionType(type)
96 }
97
98 access(Owner) fun removeSaleItemType(_ type: Type) {
99 pre {
100 self.capability != nil: "Cannot create FIND, capability is not set"
101 }
102 FindMarket.removeSaleItemType(type)
103 }
104
105 access(Owner) fun removeMarketBidType(_ type: Type) {
106 pre {
107 self.capability != nil: "Cannot create FIND, capability is not set"
108 }
109 FindMarket.removeMarketBidType(type)
110 }
111
112 access(Owner) fun removeSaleItemCollectionType(_ type: Type) {
113 pre {
114 self.capability != nil: "Cannot create FIND, capability is not set"
115 }
116 FindMarket.removeSaleItemCollectionType(type)
117 }
118
119 access(Owner) fun removeMarketBidCollectionType(_ type: Type) {
120 pre {
121 self.capability != nil: "Cannot create FIND, capability is not set"
122 }
123 FindMarket.removeMarketBidCollectionType(type)
124 }
125
126 /// ===================================================================================
127 // Tenant Rules Management
128 /// ===================================================================================
129 access(Owner) fun getTenantRef(_ tenant: Address) : &FindMarket.Tenant {
130 pre {
131 self.capability != nil: "Cannot create FIND, capability is not set"
132 }
133 let string = FindMarket.getTenantPathForAddress(tenant)
134 let pp = PublicPath(identifier: string) ?? panic("Cannot generate storage path from string : ".concat(string))
135 let cap = FindMarketAdmin.account.capabilities.borrow<&FindMarket.Tenant>(pp) ?? panic("Cannot borrow tenant reference from path. Path : ".concat(pp.toString()) )
136 return cap
137 }
138
139 access(Owner) fun addFindBlockItem(tenant: Address, item: FindMarket.TenantSaleItem) {
140 pre {
141 self.capability != nil: "Cannot create FIND, capability is not set"
142 }
143 let tenant = self.getTenantRef(tenant)
144 tenant.addSaleItem(item, type: "find")
145 }
146
147 access(Owner) fun removeFindBlockItem(tenant: Address, name: String) {
148 pre {
149 self.capability != nil: "Cannot create FIND, capability is not set"
150 }
151 let tenant = self.getTenantRef(tenant)
152 tenant.removeSaleItem(name, type: "find")
153 }
154
155 access(Owner) fun setFindCut(tenant: Address, saleItem: FindMarket.TenantSaleItem) {
156 pre {
157 self.capability != nil: "Cannot create FIND, capability is not set"
158 }
159 let tenant = self.getTenantRef(tenant)
160 tenant.addSaleItem(saleItem, type: "cut")
161 }
162
163 access(Owner) fun setExtraCut(tenant: Address, types: [Type], category: String, cuts: FindMarketCutStruct.Cuts) {
164 pre {
165 self.capability != nil: "Cannot create FIND, capability is not set"
166 }
167 let tenant = self.getTenantRef(tenant)
168 tenant.setExtraCut(types: types, category: category, cuts: cuts)
169 }
170
171 access(Owner) fun setMarketOption(tenant: Address, saleItem: FindMarket.TenantSaleItem) {
172 pre {
173 self.capability != nil: "Cannot create FIND, capability is not set"
174 }
175 let tenant = self.getTenantRef(tenant)
176 tenant.addSaleItem(saleItem, type: "tenant")
177 //Emit Event here
178 }
179
180 access(Owner) fun removeMarketOption(tenant: Address, name: String) {
181 pre {
182 self.capability != nil: "Cannot create FIND, capability is not set"
183 }
184 let tenant = self.getTenantRef(tenant)
185 tenant.removeSaleItem(name, type: "tenant")
186 }
187
188 access(Owner) fun enableMarketOption(tenant: Address, name: String) {
189 pre {
190 self.capability != nil: "Cannot create FIND, capability is not set"
191 }
192 let tenant = self.getTenantRef(tenant)
193 tenant.alterMarketOption(name: name, status: "active")
194 }
195
196 access(Owner) fun deprecateMarketOption(tenant: Address, name: String) {
197 pre {
198 self.capability != nil: "Cannot create FIND, capability is not set"
199 }
200 let tenant = self.getTenantRef(tenant)
201 tenant.alterMarketOption(name: name, status: "deprecated")
202 }
203
204 access(Owner) fun stopMarketOption(tenant: Address, name: String) {
205 pre {
206 self.capability != nil: "Cannot create FIND, capability is not set"
207 }
208 let tenant = self.getTenantRef(tenant)
209 tenant.alterMarketOption(name: name, status: "stopped")
210 }
211
212 access(Owner) fun setupSwitchboardCut(tenant: Address) {
213 pre {
214 self.capability != nil: "Cannot create FIND, capability is not set"
215 }
216 let tenant = self.getTenantRef(tenant)
217 tenant.setupSwitchboardCut()
218 }
219
220 /// ===================================================================================
221 // Royalty Residual
222 /// ===================================================================================
223
224 access(Owner) fun setResidualAddress(_ address: Address) {
225 pre {
226 self.capability != nil: "Cannot create FIND, capability is not set"
227 }
228 FindMarket.setResidualAddress(address)
229 }
230
231 access(all) fun getSwitchboardReceiverPublic() : Capability<&{FungibleToken.Receiver}> {
232 // we hard code it here instead, to avoid importing just for path
233 return FindMarketAdmin.account.capabilities.get<&{FungibleToken.Receiver}>(/public/GenericFTReceiver)!
234 }
235
236 init() {
237 self.capability = nil
238 }
239
240 }
241
242 init() {
243 self.AdminProxyPublicPath= /public/findMarketAdminProxy
244 self.AdminProxyStoragePath=/storage/findMarketAdminProxy
245 }
246
247}
248
249