@flowtyio/flow-contracts 0.1.0-beta.14 → 0.1.0-beta.16

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.
@@ -78,7 +78,7 @@ access(all) contract ScopedNFTProviders {
78
78
  //
79
79
  // Wrapper around an NFT Provider that is restricted to specific ids.
80
80
  access(all) resource ScopedNFTProvider: NonFungibleToken.Provider {
81
- access(self) let provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>
81
+ access(self) let provider: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
82
82
  access(self) let filters: [{NFTFilter}]
83
83
 
84
84
  // block timestamp that this provider can no longer be used after
@@ -91,7 +91,7 @@ access(all) contract ScopedNFTProviders {
91
91
  return false
92
92
  }
93
93
 
94
- access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>, filters: [{NFTFilter}], expiration: UFix64?) {
94
+ access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>, filters: [{NFTFilter}], expiration: UFix64?) {
95
95
  self.provider = provider
96
96
  self.expiration = expiration
97
97
  self.filters = filters
@@ -102,7 +102,11 @@ access(all) contract ScopedNFTProviders {
102
102
  return false
103
103
  }
104
104
 
105
- let nft = self.provider.borrow()!.borrowNFT(id)
105
+ if !self.provider.check() {
106
+ return false
107
+ }
108
+
109
+ let nft: &{NonFungibleToken.NFT}? = self.provider.borrow()!.borrowNFT(id)
106
110
  if nft == nil {
107
111
  return false
108
112
  }
@@ -153,11 +157,10 @@ access(all) contract ScopedNFTProviders {
153
157
  }
154
158
 
155
159
  access(all) fun createScopedNFTProvider(
156
- provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>,
160
+ provider: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>,
157
161
  filters: [{NFTFilter}],
158
162
  expiration: UFix64?
159
163
  ): @ScopedNFTProvider {
160
164
  return <- create ScopedNFTProvider(provider: provider, filters: filters, expiration: expiration)
161
165
  }
162
- }
163
-
166
+ }
@@ -15,6 +15,9 @@ access(all) contract CapabilityDelegator {
15
15
  access(all) let PublicPath: PublicPath
16
16
 
17
17
  access(all) entitlement Get
18
+ access(all) entitlement Owner
19
+ access(all) entitlement Add
20
+ access(all) entitlement Delete
18
21
 
19
22
  /* --- Events --- */
20
23
  //
@@ -123,7 +126,7 @@ access(all) contract CapabilityDelegator {
123
126
  /// @param cap: Capability to add
124
127
  /// @param isPublic: Whether the Capability should be public or private
125
128
  ///
126
- access(Mutate | Insert) fun addCapability(cap: Capability, isPublic: Bool) {
129
+ access(Owner | Add) fun addCapability(cap: Capability, isPublic: Bool) {
127
130
  pre {
128
131
  cap.check<&AnyResource>(): "Invalid Capability provided"
129
132
  }
@@ -139,7 +142,7 @@ access(all) contract CapabilityDelegator {
139
142
  ///
140
143
  /// @param cap: Capability to remove
141
144
  ///
142
- access(Mutate | Remove) fun removeCapability(cap: Capability) {
145
+ access(Owner | Delete) fun removeCapability(cap: Capability) {
143
146
  if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
144
147
  emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
145
148
  }
@@ -17,6 +17,10 @@ access(all) contract CapabilityFactory {
17
17
 
18
18
  access(all) let StoragePath: StoragePath
19
19
  access(all) let PublicPath: PublicPath
20
+
21
+ access(all) entitlement Owner
22
+ access(all) entitlement Add
23
+ access(all) entitlement Delete
20
24
 
21
25
  /// Factory structures a common interface for Capability retrieval from a given account at a specified path
22
26
  ///
@@ -60,7 +64,7 @@ access(all) contract CapabilityFactory {
60
64
  /// @param t: Type of Capability the Factory retrieves
61
65
  /// @param f: Factory to add
62
66
  ///
63
- access(Mutate | Insert) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
67
+ access(Owner | Add) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
64
68
  pre {
65
69
  !self.factories.containsKey(t): "Factory of given type already exists"
66
70
  }
@@ -72,7 +76,7 @@ access(all) contract CapabilityFactory {
72
76
  /// @param t: Type of Capability the Factory retrieves
73
77
  /// @param f: Factory to replace existing Factory
74
78
  ///
75
- access(Mutate | Insert) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
79
+ access(Owner | Add) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
76
80
  self.factories[t] = f
77
81
  }
78
82
 
@@ -80,7 +84,7 @@ access(all) contract CapabilityFactory {
80
84
  ///
81
85
  /// @param t: Type the Factory is indexed on
82
86
  ///
83
- access(Mutate | Remove) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
87
+ access(Owner | Delete) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
84
88
  return self.factories.remove(key: t)
85
89
  }
86
90
 
@@ -13,6 +13,10 @@ access(all) contract CapabilityFilter {
13
13
  access(all) let StoragePath: StoragePath
14
14
  access(all) let PublicPath: PublicPath
15
15
 
16
+ access(all) entitlement Owner
17
+ access(all) entitlement Add
18
+ access(all) entitlement Delete
19
+
16
20
  /* --- Events --- */
17
21
  //
18
22
  access(all) event FilterUpdated(id: UInt64, filterType: Type, type: Type, active: Bool)
@@ -38,7 +42,7 @@ access(all) contract CapabilityFilter {
38
42
  ///
39
43
  /// @param type: The type to add to the denied types mapping
40
44
  ///
41
- access(Mutate | Insert) fun addType(_ type: Type) {
45
+ access(Owner | Add) fun addType(_ type: Type) {
42
46
  self.deniedTypes.insert(key: type, true)
43
47
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
44
48
  }
@@ -47,7 +51,7 @@ access(all) contract CapabilityFilter {
47
51
  ///
48
52
  /// @param type: The type to remove from the denied types mapping
49
53
  ///
50
- access(Mutate | Remove) fun removeType(_ type: Type) {
54
+ access(Owner | Delete) fun removeType(_ type: Type) {
51
55
  if let removed = self.deniedTypes.remove(key: type) {
52
56
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
53
57
  }
@@ -55,7 +59,7 @@ access(all) contract CapabilityFilter {
55
59
 
56
60
  /// Removes all types from the mapping of denied types
57
61
  ///
58
- access(Mutate | Remove) fun removeAllTypes() {
62
+ access(Owner | Delete) fun removeAllTypes() {
59
63
  for type in self.deniedTypes.keys {
60
64
  self.removeType(type)
61
65
  }
@@ -105,7 +109,7 @@ access(all) contract CapabilityFilter {
105
109
  ///
106
110
  /// @param type: The type to add to the allowed types mapping
107
111
  ///
108
- access(Mutate | Insert) fun addType(_ type: Type) {
112
+ access(Owner | Add) fun addType(_ type: Type) {
109
113
  self.allowedTypes.insert(key: type, true)
110
114
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
111
115
  }
@@ -114,7 +118,7 @@ access(all) contract CapabilityFilter {
114
118
  ///
115
119
  /// @param type: The type to remove from the denied types mapping
116
120
  ///
117
- access(Mutate | Remove) fun removeType(_ type: Type) {
121
+ access(Owner | Delete) fun removeType(_ type: Type) {
118
122
  if let removed = self.allowedTypes.remove(key: type) {
119
123
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
120
124
  }
@@ -122,7 +126,7 @@ access(all) contract CapabilityFilter {
122
126
 
123
127
  /// Removes all types from the mapping of denied types
124
128
  ///
125
- access(Mutate | Remove) fun removeAllTypes() {
129
+ access(Owner | Delete) fun removeAllTypes() {
126
130
  for type in self.allowedTypes.keys {
127
131
  self.removeType(type)
128
132
  }
@@ -234,13 +234,13 @@ access(all) contract HybridCustody {
234
234
  /// Entry point for a parent to obtain, maintain and access Capabilities or perform other actions on child accounts
235
235
  ///
236
236
  access(all) resource interface ManagerPrivate {
237
- access(Manage | Insert) fun addAccount(cap: Capability<auth(Child) &{AccountPrivate, AccountPublic, ViewResolver.Resolver}>)
237
+ access(Manage) fun addAccount(cap: Capability<auth(Child) &{AccountPrivate, AccountPublic, ViewResolver.Resolver}>)
238
238
  access(Manage) fun borrowAccount(addr: Address): auth(Child) &{AccountPrivate, AccountPublic, ViewResolver.Resolver}?
239
- access(Manage | Remove) fun removeChild(addr: Address)
240
- access(Manage | Insert) fun addOwnedAccount(cap: Capability<auth(Owner) &{OwnedAccountPrivate, OwnedAccountPublic, ViewResolver.Resolver}>)
239
+ access(Manage) fun removeChild(addr: Address)
240
+ access(Manage) fun addOwnedAccount(cap: Capability<auth(Owner) &{OwnedAccountPrivate, OwnedAccountPublic, ViewResolver.Resolver}>)
241
241
  access(Manage) fun borrowOwnedAccount(addr: Address): auth(Owner) &{OwnedAccountPrivate, OwnedAccountPublic, ViewResolver.Resolver}?
242
- access(Manage | Remove) fun removeOwned(addr: Address)
243
- access(Manage | Mutate) fun setManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?, childAddress: Address) {
242
+ access(Manage) fun removeOwned(addr: Address)
243
+ access(Manage) fun setManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?, childAddress: Address) {
244
244
  pre {
245
245
  cap == nil || cap!.check(): "Invalid Manager Capability Filter"
246
246
  }
@@ -282,7 +282,7 @@ access(all) contract HybridCustody {
282
282
 
283
283
  /// Sets the Display on the ChildAccount. If nil, the display is removed.
284
284
  ///
285
- access(Manage | Mutate) fun setChildAccountDisplay(address: Address, _ d: MetadataViews.Display?) {
285
+ access(Manage) fun setChildAccountDisplay(address: Address, _ d: MetadataViews.Display?) {
286
286
  pre {
287
287
  self.childAccounts[address] != nil: "There is no child account with this address"
288
288
  }
@@ -316,7 +316,7 @@ access(all) contract HybridCustody {
316
316
 
317
317
  /// Sets the default Filter Capability for this Manager. Does not propagate to child accounts.
318
318
  ///
319
- access(Manage | Mutate) fun setDefaultManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?) {
319
+ access(Manage) fun setDefaultManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?) {
320
320
  pre {
321
321
  cap == nil || cap!.check(): "supplied capability must be nil or check must pass"
322
322
  }
@@ -326,7 +326,7 @@ access(all) contract HybridCustody {
326
326
 
327
327
  /// Sets the Filter Capability for this Manager, propagating to the specified child account
328
328
  ///
329
- access(Manage | Mutate) fun setManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?, childAddress: Address) {
329
+ access(Manage) fun setManagerCapabilityFilter(cap: Capability<&{CapabilityFilter.Filter}>?, childAddress: Address) {
330
330
  let acct = self.borrowAccount(addr: childAddress)
331
331
  ?? panic("child account not found")
332
332
 
@@ -1100,9 +1100,9 @@ access(all) contract HybridCustody {
1100
1100
 
1101
1101
  /// Retrieves a reference to the ChildAccount associated with the given parent account if one exists.
1102
1102
  ///
1103
- access(Owner) fun borrowChildAccount(parent: Address): auth(Capabilities) &ChildAccount? {
1103
+ access(Owner) fun borrowChildAccount(parent: Address): auth(Child) &ChildAccount? {
1104
1104
  let identifier = HybridCustody.getChildAccountIdentifier(parent)
1105
- return self.borrowAccount().storage.borrow<auth(Capabilities) &ChildAccount>(from: StoragePath(identifier: identifier)!)
1105
+ return self.borrowAccount().storage.borrow<auth(Child) &ChildAccount>(from: StoragePath(identifier: identifier)!)
1106
1106
  }
1107
1107
 
1108
1108
  /// Sets the CapabilityFactory Manager for the specified parent in the associated ChildAccount.
@@ -1124,9 +1124,9 @@ access(all) contract HybridCustody {
1124
1124
 
1125
1125
  /// Retrieves a reference to the Delegator associated with the given parent account if one exists.
1126
1126
  ///
1127
- access(Owner) fun borrowCapabilityDelegatorForParent(parent: Address): auth(Mutate) &CapabilityDelegator.Delegator? {
1127
+ access(Owner) fun borrowCapabilityDelegatorForParent(parent: Address): auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator? {
1128
1128
  let identifier = HybridCustody.getCapabilityDelegatorIdentifier(parent)
1129
- return self.borrowAccount().storage.borrow<auth(Mutate) &CapabilityDelegator.Delegator>(from: StoragePath(identifier: identifier)!)
1129
+ return self.borrowAccount().storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: StoragePath(identifier: identifier)!)
1130
1130
  }
1131
1131
 
1132
1132
  /// Adds the provided Capability to the Delegator associated with the given parent account.
@@ -5,11 +5,11 @@ access(all) contract FTAllFactory {
5
5
  access(all) struct Factory: CapabilityFactory.Factory {
6
6
  access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
7
7
  if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
8
- if !con.capability.check<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance, FungibleToken.Receiver}>() {
8
+ if !con.capability.check<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance}>() {
9
9
  return nil
10
10
  }
11
11
 
12
- return con.capability as! Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance, FungibleToken.Receiver}>
12
+ return con.capability as! Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance}>
13
13
  }
14
14
 
15
15
  return nil
@@ -0,0 +1,48 @@
1
+ import "CapabilityFactory"
2
+ import "FungibleToken"
3
+
4
+ access(all) contract FTVaultFactory {
5
+ access(all) struct WithdrawFactory: CapabilityFactory.Factory {
6
+ access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
7
+ if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
8
+ if !con.capability.check<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>() {
9
+ return nil
10
+ }
11
+
12
+ return con.capability as! Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>
13
+ }
14
+
15
+ return nil
16
+ }
17
+
18
+ access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
19
+ return nil
20
+ }
21
+ }
22
+
23
+ access(all) struct Factory: CapabilityFactory.Factory {
24
+ access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
25
+ if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
26
+ if !con.capability.check<&{FungibleToken.Vault}>() {
27
+ return nil
28
+ }
29
+
30
+ return con.capability as! Capability<&{FungibleToken.Vault}>
31
+ }
32
+
33
+ return nil
34
+ }
35
+
36
+ access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
37
+ if let cap = acct.capabilities.get<&{FungibleToken.Vault}>(path) {
38
+ if !cap.check() {
39
+ return nil
40
+ }
41
+
42
+ return cap
43
+ }
44
+
45
+ return nil
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,48 @@
1
+ import "CapabilityFactory"
2
+ import "NonFungibleToken"
3
+
4
+ access(all) contract NFTProviderAndCollectionFactory {
5
+ access(all) struct WithdrawFactory: CapabilityFactory.Factory {
6
+ access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
7
+ if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
8
+ if !con.capability.check<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Collection}>() {
9
+ return nil
10
+ }
11
+
12
+ return con.capability as! Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Collection}>
13
+ }
14
+
15
+ return nil
16
+ }
17
+
18
+ access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
19
+ return nil
20
+ }
21
+ }
22
+
23
+ access(all) struct Factory: CapabilityFactory.Factory {
24
+ access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
25
+ if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
26
+ if !con.capability.check<&{NonFungibleToken.Collection}>() {
27
+ return nil
28
+ }
29
+
30
+ return con.capability as! Capability<&{NonFungibleToken.Collection}>
31
+ }
32
+
33
+ return nil
34
+ }
35
+
36
+ access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability? {
37
+ if let cap = acct.capabilities.get<&{NonFungibleToken.Collection}>(path) {
38
+ if !cap.check() {
39
+ return nil
40
+ }
41
+
42
+ return cap
43
+ }
44
+
45
+ return nil
46
+ }
47
+ }
48
+ }
@@ -5,11 +5,11 @@ access(all) contract NFTProviderAndCollectionFactory {
5
5
  access(all) struct Factory: CapabilityFactory.Factory {
6
6
  access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
7
7
  if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
8
- if !con.capability.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>() {
8
+ if !con.capability.check<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>() {
9
9
  return nil
10
10
  }
11
11
 
12
- return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
12
+ return con.capability as! Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
13
13
  }
14
14
 
15
15
  return nil
@@ -5,11 +5,11 @@ access(all) contract NFTProviderFactory {
5
5
  access(all) struct Factory: CapabilityFactory.Factory {
6
6
  access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? {
7
7
  if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) {
8
- if !con.capability.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>() {
8
+ if !con.capability.check<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>() {
9
9
  return nil
10
10
  }
11
11
 
12
- return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>
12
+ return con.capability as! Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>
13
13
  }
14
14
 
15
15
  return nil
package/flow.json CHANGED
@@ -33,8 +33,8 @@
33
33
  "source": "./contracts/Burner.cdc",
34
34
  "aliases": {
35
35
  "emulator": "0xf8d6e0586b0a20c7",
36
- "testnet": "0x631e88ae7f1d7c20",
37
- "mainnet": "0x1d7e57aa55817448"
36
+ "testnet": "0x9a0766d93b6608b7",
37
+ "mainnet": "0xf233dcee88fe0abe"
38
38
  }
39
39
  },
40
40
  "MetadataViews": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.0-beta.14",
3
+ "version": "0.1.0-beta.16",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",