@flowtyio/flow-contracts 0.1.0-beta.10 → 0.1.0-beta.12
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.
- package/contracts/flow-utils/ScopedFTProviders.cdc +4 -0
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +25 -25
- package/contracts/hybrid-custody/CapabilityFactory.cdc +18 -17
- package/contracts/hybrid-custody/CapabilityFilter.cdc +38 -22
- package/contracts/hybrid-custody/HybridCustody.cdc +305 -232
- package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
- package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
- package/package.json +1 -1
|
@@ -7,48 +7,48 @@
|
|
|
7
7
|
/// private `Delegator` can only be borrowed from the child account when you have access to the full `ChildAccount`
|
|
8
8
|
/// resource.
|
|
9
9
|
///
|
|
10
|
-
|
|
10
|
+
access(all) contract CapabilityDelegator {
|
|
11
11
|
|
|
12
12
|
/* --- Canonical Paths --- */
|
|
13
13
|
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
access(all) let StoragePath: StoragePath
|
|
15
|
+
access(all) let PrivatePath: PrivatePath
|
|
16
|
+
access(all) let PublicPath: PublicPath
|
|
17
17
|
|
|
18
18
|
/* --- Events --- */
|
|
19
19
|
//
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
access(all) event DelegatorCreated(id: UInt64)
|
|
21
|
+
access(all) event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)
|
|
22
22
|
|
|
23
23
|
/// Private interface for Capability retrieval
|
|
24
24
|
///
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
access(all) resource interface GetterPrivate {
|
|
26
|
+
access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
|
|
27
27
|
post {
|
|
28
28
|
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
access(all) view fun findFirstPrivateType(_ type: Type): Type?
|
|
32
|
+
access(Capabilities) fun getAllPrivate(): [Capability]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/// Exposes public Capability retrieval
|
|
36
36
|
///
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
access(all) resource interface GetterPublic {
|
|
38
|
+
access(all) view fun getPublicCapability(_ type: Type): Capability? {
|
|
39
39
|
post {
|
|
40
|
-
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type
|
|
40
|
+
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
access(all) view fun findFirstPublicType(_ type: Type): Type?
|
|
45
|
+
access(all) view fun getAllPublic(): [Capability]
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/// This Delegator is used to store Capabilities, partitioned by public and private access with corresponding
|
|
49
49
|
/// GetterPublic and GetterPrivate conformances.AccountCapabilityController
|
|
50
50
|
///
|
|
51
|
-
|
|
51
|
+
access(all) resource Delegator: GetterPublic, GetterPrivate {
|
|
52
52
|
access(self) let privateCapabilities: {Type: Capability}
|
|
53
53
|
access(self) let publicCapabilities: {Type: Capability}
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ pub contract CapabilityDelegator {
|
|
|
56
56
|
//
|
|
57
57
|
/// Returns the public Capability of the given Type if it exists
|
|
58
58
|
///
|
|
59
|
-
|
|
59
|
+
access(all) view fun getPublicCapability(_ type: Type): Capability? {
|
|
60
60
|
return self.publicCapabilities[type]
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -66,7 +66,7 @@ pub contract CapabilityDelegator {
|
|
|
66
66
|
/// @param type: Type of the Capability to retrieve
|
|
67
67
|
/// @return Capability of the given Type if it exists, nil otherwise
|
|
68
68
|
///
|
|
69
|
-
|
|
69
|
+
access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
|
|
70
70
|
return self.privateCapabilities[type]
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -74,7 +74,7 @@ pub contract CapabilityDelegator {
|
|
|
74
74
|
///
|
|
75
75
|
/// @return List of all public Capabilities
|
|
76
76
|
///
|
|
77
|
-
|
|
77
|
+
access(all) view fun getAllPublic(): [Capability] {
|
|
78
78
|
return self.publicCapabilities.values
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -82,7 +82,7 @@ pub contract CapabilityDelegator {
|
|
|
82
82
|
///
|
|
83
83
|
/// @return List of all private Capabilities
|
|
84
84
|
///
|
|
85
|
-
|
|
85
|
+
access(Capabilities) fun getAllPrivate(): [Capability] {
|
|
86
86
|
return self.privateCapabilities.values
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -91,7 +91,7 @@ pub contract CapabilityDelegator {
|
|
|
91
91
|
/// @param type: Type to check for subtypes
|
|
92
92
|
/// @return First public Type that is a subtype of the given Type, nil otherwise
|
|
93
93
|
///
|
|
94
|
-
|
|
94
|
+
access(all) view fun findFirstPublicType(_ type: Type): Type? {
|
|
95
95
|
for t in self.publicCapabilities.keys {
|
|
96
96
|
if t.isSubtype(of: type) {
|
|
97
97
|
return t
|
|
@@ -106,7 +106,7 @@ pub contract CapabilityDelegator {
|
|
|
106
106
|
/// @param type: Type to check for subtypes
|
|
107
107
|
/// @return First private Type that is a subtype of the given Type, nil otherwise
|
|
108
108
|
///
|
|
109
|
-
|
|
109
|
+
access(all) view fun findFirstPrivateType(_ type: Type): Type? {
|
|
110
110
|
for t in self.privateCapabilities.keys {
|
|
111
111
|
if t.isSubtype(of: type) {
|
|
112
112
|
return t
|
|
@@ -122,7 +122,7 @@ pub contract CapabilityDelegator {
|
|
|
122
122
|
/// @param cap: Capability to add
|
|
123
123
|
/// @param isPublic: Whether the Capability should be public or private
|
|
124
124
|
///
|
|
125
|
-
|
|
125
|
+
access(Mutate) fun addCapability(cap: Capability, isPublic: Bool) {
|
|
126
126
|
pre {
|
|
127
127
|
cap.check<&AnyResource>(): "Invalid Capability provided"
|
|
128
128
|
}
|
|
@@ -138,7 +138,7 @@ pub contract CapabilityDelegator {
|
|
|
138
138
|
///
|
|
139
139
|
/// @param cap: Capability to remove
|
|
140
140
|
///
|
|
141
|
-
|
|
141
|
+
access(Mutate) fun removeCapability(cap: Capability) {
|
|
142
142
|
if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
|
|
143
143
|
emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
|
|
144
144
|
}
|
|
@@ -158,7 +158,7 @@ pub contract CapabilityDelegator {
|
|
|
158
158
|
///
|
|
159
159
|
/// @return Newly created Delegator
|
|
160
160
|
///
|
|
161
|
-
|
|
161
|
+
access(all) fun createDelegator(): @Delegator {
|
|
162
162
|
let delegator <- create Delegator()
|
|
163
163
|
emit DelegatorCreated(id: delegator.uuid)
|
|
164
164
|
return <- delegator
|
|
@@ -13,37 +13,38 @@
|
|
|
13
13
|
/// Capabilities is critical to the use case of Hybrid Custody. It's advised to use Factories sparingly and only for
|
|
14
14
|
/// cases where Capabilities must be castable by the caller.
|
|
15
15
|
///
|
|
16
|
-
|
|
16
|
+
access(all) contract CapabilityFactory {
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
access(all) let StoragePath: StoragePath
|
|
19
|
+
access(all) let PrivatePath: PrivatePath
|
|
20
|
+
access(all) let PublicPath: PublicPath
|
|
21
21
|
|
|
22
22
|
/// Factory structures a common interface for Capability retrieval from a given account at a specified path
|
|
23
23
|
///
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
access(all) struct interface Factory {
|
|
25
|
+
access(Capabilities) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability?
|
|
26
|
+
access(all) view fun getPublicCapability(acct: auth(Capabilities) &Account, path: PublicPath): Capability?
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/// Getter defines an interface for retrieval of a Factory if contained within the implementing resource
|
|
29
30
|
///
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
access(all) resource interface Getter {
|
|
32
|
+
access(all) view fun getSupportedTypes(): [Type]
|
|
33
|
+
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/// Manager is a resource that contains Factories and implements the Getter interface for retrieval of contained
|
|
36
37
|
/// Factories
|
|
37
38
|
///
|
|
38
|
-
|
|
39
|
+
access(all) resource Manager: Getter {
|
|
39
40
|
/// Mapping of Factories indexed on Type of Capability they retrieve
|
|
40
|
-
|
|
41
|
+
access(all) let factories: {Type: {CapabilityFactory.Factory}}
|
|
41
42
|
|
|
42
43
|
/// Retrieves a list of Types supported by contained Factories
|
|
43
44
|
///
|
|
44
45
|
/// @return List of Types supported by the Manager
|
|
45
46
|
///
|
|
46
|
-
|
|
47
|
+
access(all) view fun getSupportedTypes(): [Type] {
|
|
47
48
|
return self.factories.keys
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -51,7 +52,7 @@ pub contract CapabilityFactory {
|
|
|
51
52
|
///
|
|
52
53
|
/// @param t: Type the Factory is indexed on
|
|
53
54
|
///
|
|
54
|
-
|
|
55
|
+
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
|
|
55
56
|
return self.factories[t]
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -60,7 +61,7 @@ pub contract CapabilityFactory {
|
|
|
60
61
|
/// @param t: Type of Capability the Factory retrieves
|
|
61
62
|
/// @param f: Factory to add
|
|
62
63
|
///
|
|
63
|
-
|
|
64
|
+
access(Mutate) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
|
|
64
65
|
pre {
|
|
65
66
|
!self.factories.containsKey(t): "Factory of given type already exists"
|
|
66
67
|
}
|
|
@@ -72,7 +73,7 @@ pub contract CapabilityFactory {
|
|
|
72
73
|
/// @param t: Type of Capability the Factory retrieves
|
|
73
74
|
/// @param f: Factory to replace existing Factory
|
|
74
75
|
///
|
|
75
|
-
|
|
76
|
+
access(Mutate) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
|
|
76
77
|
self.factories[t] = f
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -80,7 +81,7 @@ pub contract CapabilityFactory {
|
|
|
80
81
|
///
|
|
81
82
|
/// @param t: Type the Factory is indexed on
|
|
82
83
|
///
|
|
83
|
-
|
|
84
|
+
access(Mutate) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
|
|
84
85
|
return self.factories.remove(key: t)
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -92,7 +93,7 @@ pub contract CapabilityFactory {
|
|
|
92
93
|
/// Creates a Manager resource
|
|
93
94
|
///
|
|
94
95
|
/// @return Manager resource
|
|
95
|
-
|
|
96
|
+
access(all) fun createFactoryManager(): @Manager {
|
|
96
97
|
return <- create Manager()
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -6,29 +6,29 @@
|
|
|
6
6
|
/// - `AllowlistFilter` - A filter which contains a mapping of allowed Types
|
|
7
7
|
/// - `AllowAllFilter` - A passthrough, all requested capabilities are allowed
|
|
8
8
|
///
|
|
9
|
-
|
|
9
|
+
access(all) contract CapabilityFilter {
|
|
10
10
|
|
|
11
11
|
/* --- Canonical Paths --- */
|
|
12
12
|
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
access(all) let StoragePath: StoragePath
|
|
14
|
+
access(all) let PublicPath: PublicPath
|
|
15
|
+
access(all) let PrivatePath: PrivatePath
|
|
16
16
|
|
|
17
17
|
/* --- Events --- */
|
|
18
18
|
//
|
|
19
|
-
|
|
19
|
+
access(all) event FilterUpdated(id: UInt64, filterType: Type, type: Type, active: Bool)
|
|
20
20
|
|
|
21
21
|
/// `Filter` is a simple interface with methods to determine if a Capability is allowed and retrieve details about
|
|
22
22
|
/// the Filter itself
|
|
23
23
|
///
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
access(all) resource interface Filter {
|
|
25
|
+
access(all) view fun allowed(cap: Capability): Bool
|
|
26
|
+
access(all) view fun getDetails(): AnyStruct
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/// `DenylistFilter` is a `Filter` which contains a mapping of denied Types
|
|
30
30
|
///
|
|
31
|
-
|
|
31
|
+
access(all) resource DenylistFilter: Filter {
|
|
32
32
|
|
|
33
33
|
/// Represents the underlying types which should not ever be returned by a RestrictedChildAccount. The filter
|
|
34
34
|
/// will borrow a requested capability, and make sure that the type it gets back is not in the list of denied
|
|
@@ -39,7 +39,7 @@ pub contract CapabilityFilter {
|
|
|
39
39
|
///
|
|
40
40
|
/// @param type: The type to add to the denied types mapping
|
|
41
41
|
///
|
|
42
|
-
|
|
42
|
+
access(Mutate) fun addType(_ type: Type) {
|
|
43
43
|
self.deniedTypes.insert(key: type, true)
|
|
44
44
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
|
|
45
45
|
}
|
|
@@ -48,18 +48,26 @@ pub contract CapabilityFilter {
|
|
|
48
48
|
///
|
|
49
49
|
/// @param type: The type to remove from the denied types mapping
|
|
50
50
|
///
|
|
51
|
-
|
|
51
|
+
access(Mutate) fun removeType(_ type: Type) {
|
|
52
52
|
if let removed = self.deniedTypes.remove(key: type) {
|
|
53
53
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/// Removes all types from the mapping of denied types
|
|
58
|
+
///
|
|
59
|
+
access(Mutate) fun removeAllTypes() {
|
|
60
|
+
for type in self.deniedTypes.keys {
|
|
61
|
+
self.removeType(type)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
58
66
|
///
|
|
59
67
|
/// @param cap: The capability to check
|
|
60
68
|
/// @return: true if the capability is allowed, false otherwise
|
|
61
69
|
///
|
|
62
|
-
|
|
70
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
63
71
|
if let item = cap.borrow<&AnyResource>() {
|
|
64
72
|
return !self.deniedTypes.containsKey(item.getType())
|
|
65
73
|
}
|
|
@@ -72,7 +80,7 @@ pub contract CapabilityFilter {
|
|
|
72
80
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
73
81
|
/// key as well as types denied indexed on the `deniedTypes` key
|
|
74
82
|
///
|
|
75
|
-
|
|
83
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
76
84
|
return {
|
|
77
85
|
"type": self.getType(),
|
|
78
86
|
"deniedTypes": self.deniedTypes.keys
|
|
@@ -86,7 +94,7 @@ pub contract CapabilityFilter {
|
|
|
86
94
|
|
|
87
95
|
/// `AllowlistFilter` is a `Filter` which contains a mapping of allowed Types
|
|
88
96
|
///
|
|
89
|
-
|
|
97
|
+
access(all) resource AllowlistFilter: Filter {
|
|
90
98
|
// allowedTypes
|
|
91
99
|
// Represents the set of underlying types which are allowed to be
|
|
92
100
|
// returned by a RestrictedChildAccount. The filter will borrow
|
|
@@ -98,7 +106,7 @@ pub contract CapabilityFilter {
|
|
|
98
106
|
///
|
|
99
107
|
/// @param type: The type to add to the allowed types mapping
|
|
100
108
|
///
|
|
101
|
-
|
|
109
|
+
access(Mutate) fun addType(_ type: Type) {
|
|
102
110
|
self.allowedTypes.insert(key: type, true)
|
|
103
111
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
|
|
104
112
|
}
|
|
@@ -107,18 +115,26 @@ pub contract CapabilityFilter {
|
|
|
107
115
|
///
|
|
108
116
|
/// @param type: The type to remove from the denied types mapping
|
|
109
117
|
///
|
|
110
|
-
|
|
118
|
+
access(Mutate) fun removeType(_ type: Type) {
|
|
111
119
|
if let removed = self.allowedTypes.remove(key: type) {
|
|
112
120
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
|
|
113
121
|
}
|
|
114
122
|
}
|
|
123
|
+
|
|
124
|
+
/// Removes all types from the mapping of denied types
|
|
125
|
+
///
|
|
126
|
+
access(Mutate) fun removeAllTypes() {
|
|
127
|
+
for type in self.allowedTypes.keys {
|
|
128
|
+
self.removeType(type)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
115
131
|
|
|
116
132
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
117
133
|
///
|
|
118
134
|
/// @param cap: The capability to check
|
|
119
135
|
/// @return: true if the capability is allowed, false otherwise
|
|
120
136
|
///
|
|
121
|
-
|
|
137
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
122
138
|
if let item = cap.borrow<&AnyResource>() {
|
|
123
139
|
return self.allowedTypes.containsKey(item.getType())
|
|
124
140
|
}
|
|
@@ -131,7 +147,7 @@ pub contract CapabilityFilter {
|
|
|
131
147
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
132
148
|
/// key as well as types allowed indexed on the `allowedTypes` key
|
|
133
149
|
///
|
|
134
|
-
|
|
150
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
135
151
|
return {
|
|
136
152
|
"type": self.getType(),
|
|
137
153
|
"allowedTypes": self.allowedTypes.keys
|
|
@@ -145,13 +161,13 @@ pub contract CapabilityFilter {
|
|
|
145
161
|
|
|
146
162
|
/// AllowAllFilter is a passthrough, all requested capabilities are allowed
|
|
147
163
|
///
|
|
148
|
-
|
|
164
|
+
access(all) resource AllowAllFilter: Filter {
|
|
149
165
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
150
166
|
///
|
|
151
167
|
/// @param cap: The capability to check
|
|
152
168
|
/// @return: true since this filter is a passthrough
|
|
153
169
|
///
|
|
154
|
-
|
|
170
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
155
171
|
return true
|
|
156
172
|
}
|
|
157
173
|
|
|
@@ -160,7 +176,7 @@ pub contract CapabilityFilter {
|
|
|
160
176
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
161
177
|
/// key
|
|
162
178
|
///
|
|
163
|
-
|
|
179
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
164
180
|
return {
|
|
165
181
|
"type": self.getType()
|
|
166
182
|
}
|
|
@@ -172,7 +188,7 @@ pub contract CapabilityFilter {
|
|
|
172
188
|
/// @param t: The type of `Filter` to create
|
|
173
189
|
/// @return: A new instance of the given `Filter` type
|
|
174
190
|
///
|
|
175
|
-
|
|
191
|
+
access(all) fun createFilter(_ t: Type): @{Filter} {
|
|
176
192
|
post {
|
|
177
193
|
result.getType() == t
|
|
178
194
|
}
|