@flowtyio/flow-contracts 0.1.0-beta.23 → 0.1.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,8 @@ import "OffersV2"
2
2
  import "FungibleToken"
3
3
  import "NonFungibleToken"
4
4
  import "Resolver"
5
+ import "ViewResolver"
6
+
5
7
 
6
8
  // DapperOffersV2
7
9
  //
@@ -12,6 +14,9 @@ import "Resolver"
12
14
  // get details on Offers contained within it.
13
15
  //
14
16
  access(all) contract DapperOffersV2 {
17
+
18
+ access(all) entitlement Manager
19
+ access(all) entitlement ProxyManager
15
20
  // DapperOffersV2
16
21
  // This contract has been deployed.
17
22
  // Event consumers can now expect events from this contract.
@@ -51,7 +56,7 @@ access(all) contract DapperOffersV2 {
51
56
  //
52
57
  access(all) fun addProxyCapability(
53
58
  account: Address,
54
- cap: Capability<&{DapperOffersV2.DapperOfferProxyManager}>
59
+ cap: Capability<auth(ProxyManager) &DapperOffer>
55
60
  )
56
61
  }
57
62
 
@@ -62,8 +67,8 @@ access(all) contract DapperOffersV2 {
62
67
  // createOffer
63
68
  // Allows the DapperOffer owner to create Offers.
64
69
  //
65
- access(all) fun createOffer(
66
- vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
70
+ access(Manager) fun createOffer(
71
+ vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
67
72
  nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
68
73
  nftType: Type,
69
74
  amount: UFix64,
@@ -76,7 +81,7 @@ access(all) contract DapperOffersV2 {
76
81
  // removeOffer
77
82
  // Allows the DapperOffer owner to remove offers
78
83
  //
79
- access(all) fun removeOffer(offerId: UInt64)
84
+ access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
80
85
  }
81
86
 
82
87
  // DapperOfferProxyManager
@@ -86,11 +91,11 @@ access(all) contract DapperOffersV2 {
86
91
  // removeOffer
87
92
  // Allows the DapperOffer owner to remove offers
88
93
  //
89
- access(all) fun removeOffer(offerId: UInt64)
94
+ access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
90
95
  // removeOfferFromProxy
91
96
  // Allows the DapperOffer proxy owner to remove offers
92
97
  //
93
- access(all) fun removeOfferFromProxy(account: Address, offerId: UInt64)
98
+ access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64)
94
99
  }
95
100
 
96
101
 
@@ -98,18 +103,18 @@ access(all) contract DapperOffersV2 {
98
103
  // A resource that allows its owner to manage a list of Offers, and anyone to interact with them
99
104
  // in order to query their details and accept the Offers for NFTs that they represent.
100
105
  //
101
- access(all) resource DapperOffer : DapperOfferManager, DapperOfferPublic, DapperOfferProxyManager {
106
+ access(all) resource DapperOffer :DapperOfferManager, DapperOfferPublic, DapperOfferProxyManager {
102
107
  // The dictionary of Address to DapperOfferProxyManager capabilities.
103
- access(self) var removeOfferCapability: {Address:Capability<&{DapperOffersV2.DapperOfferProxyManager}>}
108
+ access(self) var removeOfferCapability: {Address:Capability<auth(ProxyManager) &DapperOffer>}
104
109
  // The dictionary of Offer uuids to Offer resources.
105
110
  access(self) var offers: @{UInt64:OffersV2.Offer}
106
111
 
107
112
  // addProxyCapability
108
113
  // Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
109
114
  //
110
- access(all) fun addProxyCapability(account: Address, cap: Capability<&{DapperOffersV2.DapperOfferProxyManager}>) {
115
+ access(all) fun addProxyCapability(account: Address, cap: Capability<auth(ProxyManager) &DapperOffer>) {
111
116
  pre {
112
- cap.borrow() != nil: "Invalid admin capability"
117
+ cap != nil: "Invalid admin capability"
113
118
  }
114
119
  self.removeOfferCapability[account] = cap
115
120
  }
@@ -117,23 +122,23 @@ access(all) contract DapperOffersV2 {
117
122
  // removeOfferFromProxy
118
123
  // Allows the DapperOffer proxy owner to remove offers
119
124
  //
120
- access(all) fun removeOfferFromProxy(account: Address, offerId: UInt64) {
125
+ access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64) {
121
126
  pre {
122
127
  self.removeOfferCapability[account] != nil:
123
128
  "Cannot remove offers until the token admin has deposited the account registration capability"
124
129
  }
125
130
 
126
- let adminRef = self.removeOfferCapability[account]!.borrow()!
131
+ let adminRef = self.removeOfferCapability[account]!
127
132
 
128
- adminRef.removeOffer(offerId: offerId)
133
+ adminRef.borrow()!.removeOffer(offerId: offerId)
129
134
  }
130
135
 
131
136
 
132
137
  // createOffer
133
138
  // Allows the DapperOffer owner to create Offers.
134
139
  //
135
- access(all) fun createOffer(
136
- vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
140
+ access(Manager) fun createOffer(
141
+ vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
137
142
  nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
138
143
  nftType: Type,
139
144
  amount: UFix64,
@@ -165,22 +170,28 @@ access(all) contract DapperOffersV2 {
165
170
  // removeOffer
166
171
  // Remove an Offer that has not yet been accepted from the collection and destroy it.
167
172
  //
168
- access(all) fun removeOffer(offerId: UInt64) {
169
- destroy self.offers.remove(key: offerId) ?? panic("missing offer")
173
+ access(Manager | ProxyManager) fun removeOffer(offerId: UInt64) {
174
+ let offer <- self.offers.remove(key: offerId) ?? panic("missing offer")
175
+ // offer.customDestroy()
176
+ destroy offer
170
177
  }
171
178
 
172
179
  // getOfferIds
173
180
  // Returns an array of the Offer resource IDs that are in the collection
174
181
  //
175
- access(all) fun getOfferIds(): [UInt64] {
182
+ access(all) view fun getOfferIds(): [UInt64] {
176
183
  return self.offers.keys
177
184
  }
178
185
 
179
186
  // borrowOffer
180
187
  // Returns a read-only view of the Offer for the given OfferID if it is contained by this collection.
181
188
  //
182
- access(all) fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}? {
183
- return &self.offers[offerId]
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
+ }
184
195
  }
185
196
 
186
197
  // cleanup
@@ -206,13 +217,9 @@ access(all) contract DapperOffersV2 {
206
217
  emit DapperOfferInitialized(DapperOfferResourceId: self.uuid)
207
218
  }
208
219
 
209
- // destructor
210
- //
211
- // destroy() {
212
- // destroy self.offers
213
- // // Let event consumers know that this storefront exists.
214
- // emit DapperOfferDestroyed(DapperOfferResourceId: self.uuid)
215
- // }
220
+ access(all) event ResourceDestroyed(
221
+ id: UInt64 = self.uuid
222
+ )
216
223
  }
217
224
 
218
225
  // createDapperOffer
@@ -231,4 +238,4 @@ access(all) contract DapperOffersV2 {
231
238
 
232
239
  emit DapperOffersInitialized()
233
240
  }
234
- }
241
+ }
@@ -2,10 +2,10 @@ import "FungibleToken"
2
2
  import "NonFungibleToken"
3
3
  import "DapperUtilityCoin"
4
4
  import "MetadataViews"
5
- import "Resolver"
6
5
  import "ViewResolver"
6
+ import "Resolver"
7
7
 
8
- // OffersV2
8
+ /// OffersV2
9
9
  //
10
10
  // Contract holds the Offer resource and a public method to create them.
11
11
  //
@@ -141,6 +141,10 @@ access(all) contract OffersV2 {
141
141
 
142
142
 
143
143
  access(all) resource Offer: OfferPublic {
144
+
145
+ access(all) event ResourceDestroyed(purchased: Bool = self.details.purchased, offerId: UInt64 = self.details.offerId)
146
+
147
+
144
148
  // The OfferDetails struct of the Offer
145
149
  access(self) let details: OfferDetails
146
150
  // The vault which will handle the payment if the Offer is accepted.
@@ -151,7 +155,7 @@ access(all) contract OffersV2 {
151
155
  access(contract) let resolverCapability: Capability<&{Resolver.ResolverPublic}>
152
156
 
153
157
  init(
154
- vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
158
+ vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
155
159
  nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
156
160
  nftType: Type,
157
161
  amount: UFix64,
@@ -252,8 +256,8 @@ access(all) contract OffersV2 {
252
256
 
253
257
  // If a DUC vault is being used for payment we must assert that no DUC is leaking from the transactions.
254
258
  let isDucVault = self.vaultRefCapability.isInstance(
255
- Type<Capability<&{FungibleToken.Provider, FungibleToken.Balance}>>()
256
- )
259
+ Type<Capability<&DapperUtilityCoin.Vault>>()
260
+ ) // todo: check if this is correct
257
261
 
258
262
  if isDucVault {
259
263
  assert(self.vaultRefCapability.borrow()!.balance == initalDucSupply, message: "DUC is leaking")
@@ -279,14 +283,14 @@ access(all) contract OffersV2 {
279
283
  // getDetails
280
284
  // Return Offer details
281
285
  //
282
- access(all) fun getDetails(): OfferDetails {
286
+ access(all) view fun getDetails(): OfferDetails {
283
287
  return self.details
284
288
  }
285
289
 
286
290
  // getRoyaltyInfo
287
291
  // Return royalty details
288
292
  //
289
- access(all) fun getRoyaltyInfo(): {Address:UFix64} {
293
+ access(all) view fun getRoyaltyInfo(): {Address:UFix64} {
290
294
  let royaltyInfo: {Address:UFix64} = {}
291
295
 
292
296
  for royalty in self.details.royalties {
@@ -294,31 +298,11 @@ access(all) contract OffersV2 {
294
298
  }
295
299
  return royaltyInfo;
296
300
  }
297
-
298
- // destroy() {
299
- // if !self.details.purchased {
300
- // emit OfferCompleted(
301
- // purchased: self.details.purchased,
302
- // acceptingAddress: nil,
303
- // offerAddress: self.nftReceiverCapability.address,
304
- // offerId: self.details.offerId,
305
- // nftType: self.details.nftType,
306
- // offerAmount: self.details.offerAmount,
307
- // royalties: self.getRoyaltyInfo(),
308
- // offerType: self.details.offerParamsString["_type"] ?? "unknown",
309
- // offerParamsString: self.details.offerParamsString,
310
- // offerParamsUFix64: self.details.offerParamsUFix64,
311
- // offerParamsUInt64: self.details.offerParamsUInt64,
312
- // paymentVaultType: self.details.paymentVaultType,
313
- // nftId: nil,
314
- // )
315
- // }
316
- // }
317
301
  }
318
302
 
319
303
  // makeOffer
320
304
  access(all) fun makeOffer(
321
- vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
305
+ vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
322
306
  nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
323
307
  nftType: Type,
324
308
  amount: UFix64,
@@ -341,5 +325,4 @@ access(all) contract OffersV2 {
341
325
  )
342
326
  return <-newOfferResource
343
327
  }
344
- }
345
-
328
+ }
@@ -1,8 +1,14 @@
1
1
  import "NonFungibleToken"
2
2
  import "MetadataViews"
3
- import "ViewResolver"
4
3
  import "TopShot"
4
+ import "ViewResolver"
5
5
 
6
+ // Resolver
7
+ //
8
+ // Contract holds the Offer exchange resolution rules.
9
+ //
10
+ // When an Offer is created a ResolverType is included. The ResolverType is also
11
+ // passed into checkOfferResolver() from the Offers contract on exchange validation
6
12
  access(all) contract Resolver {
7
13
  // Current list of supported resolution rules.
8
14
  access(all) enum ResolverType: UInt8 {
@@ -35,7 +41,7 @@ access(all) contract Resolver {
35
41
  if offerParamsString["resolver"] == ResolverType.NFT.rawValue.toString() {
36
42
  assert(item.id.toString() == offerParamsString["nftId"], message: "item NFT does not have specified ID")
37
43
  return true
38
- } else if offerParamsString["resolver"] == ResolverType.TopShotEdition.rawValue.toString() {
44
+ } else if offerParamsString["resolver"] == ResolverType.TopShotEdition.rawValue.toString() {
39
45
  // // Get the Top Shot specific metadata for this NFT
40
46
  let view = item.resolveView(Type<TopShot.TopShotMomentMetadataView>())!
41
47
  let metadata = view as! TopShot.TopShotMomentMetadataView
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.0-beta.23",
3
+ "version": "0.1.0-beta.24",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",