@flowtyio/flow-contracts 0.1.0-beta.15 → 0.1.0-beta.17
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/NonFungibleToken.cdc +17 -10
- package/contracts/dapper/TopShot.cdc +8 -8
- package/contracts/dapper/offers/OffersV2.cdc +3 -3
- package/contracts/dapper/offers/Resolver.cdc +2 -2
- package/contracts/example/ExampleNFT.cdc +2 -2
- package/contracts/flow-utils/ScopedNFTProviders.cdc +4 -4
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +5 -2
- package/contracts/hybrid-custody/CapabilityFactory.cdc +7 -3
- package/contracts/hybrid-custody/CapabilityFilter.cdc +10 -6
- package/contracts/hybrid-custody/HybridCustody.cdc +12 -12
- package/contracts/hybrid-custody/factories/FTAllFactory.cdc +2 -2
- package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- package/package.json +1 -1
|
@@ -49,9 +49,6 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
49
49
|
/// An entitlement for allowing updates and update events for an NFT
|
|
50
50
|
access(all) entitlement Update
|
|
51
51
|
|
|
52
|
-
/// entitlement for owner that grants Withdraw and Update
|
|
53
|
-
access(all) entitlement Owner
|
|
54
|
-
|
|
55
52
|
/// Event that contracts should emit when the metadata of an NFT is updated
|
|
56
53
|
/// It can only be emitted by calling the `emitNFTUpdated` function
|
|
57
54
|
/// with an `Updatable` entitled reference to the NFT that was updated
|
|
@@ -63,7 +60,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
63
60
|
/// and query the updated metadata from the owners' collections.
|
|
64
61
|
///
|
|
65
62
|
access(all) event Updated(type: String, id: UInt64, uuid: UInt64, owner: Address?)
|
|
66
|
-
access(
|
|
63
|
+
access(all) view fun emitNFTUpdated(_ nftRef: auth(Update) &{NonFungibleToken.NFT})
|
|
67
64
|
{
|
|
68
65
|
emit Updated(type: nftRef.getType().identifier, id: nftRef.id, uuid: nftRef.uuid, owner: nftRef.owner?.address)
|
|
69
66
|
}
|
|
@@ -85,9 +82,6 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
85
82
|
///
|
|
86
83
|
access(all) event Deposited(type: String, id: UInt64, uuid: UInt64, to: Address?, collectionUUID: UInt64)
|
|
87
84
|
|
|
88
|
-
/// Included for backwards-compatibility
|
|
89
|
-
access(all) resource interface INFT: NFT {}
|
|
90
|
-
|
|
91
85
|
/// Interface that the NFTs must conform to
|
|
92
86
|
///
|
|
93
87
|
access(all) resource interface NFT: ViewResolver.Resolver {
|
|
@@ -105,6 +99,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
105
99
|
access(all) fun createEmptyCollection(): @{Collection} {
|
|
106
100
|
post {
|
|
107
101
|
result.getLength() == 0: "The created collection must be empty!"
|
|
102
|
+
result.isSupportedNFTType(type: self.getType()): "The created collection must support this NFT type"
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
105
|
|
|
@@ -141,7 +136,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
141
136
|
/// withdraw removes an NFT from the collection and moves it to the caller
|
|
142
137
|
/// It does not specify whether the ID is UUID or not
|
|
143
138
|
/// @param withdrawID: The id of the NFT to withdraw from the collection
|
|
144
|
-
access(Withdraw
|
|
139
|
+
access(Withdraw) fun withdraw(withdrawID: UInt64): @{NFT} {
|
|
145
140
|
post {
|
|
146
141
|
result.id == withdrawID: "The ID of the withdrawn token must be the same as the requested ID"
|
|
147
142
|
emit Withdrawn(type: result.getType().identifier, id: result.id, uuid: result.uuid, from: self.owner?.address, providerUUID: self.uuid)
|
|
@@ -174,6 +169,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
174
169
|
access(all) fun deposit(token: @{NFT})
|
|
175
170
|
access(all) view fun getLength(): Int
|
|
176
171
|
access(all) view fun getIDs(): [UInt64]
|
|
172
|
+
access(all) fun forEachID(_ f: fun (UInt64): Bool): Void
|
|
177
173
|
access(all) view fun borrowNFT(_ id: UInt64): &{NFT}?
|
|
178
174
|
}
|
|
179
175
|
|
|
@@ -182,6 +178,8 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
182
178
|
///
|
|
183
179
|
access(all) resource interface Collection: Provider, Receiver, CollectionPublic, ViewResolver.ResolverCollection {
|
|
184
180
|
|
|
181
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
182
|
+
|
|
185
183
|
/// deposit takes a NFT as an argument and stores it in the collection
|
|
186
184
|
/// @param token: The NFT to deposit into the collection
|
|
187
185
|
access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
|
|
@@ -196,7 +194,16 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
196
194
|
|
|
197
195
|
/// Gets the amount of NFTs stored in the collection
|
|
198
196
|
/// @return An integer indicating the size of the collection
|
|
199
|
-
access(all) view fun getLength(): Int
|
|
197
|
+
access(all) view fun getLength(): Int {
|
|
198
|
+
return self.ownedNFTs.length
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// Allows a given function to iterate through the list
|
|
202
|
+
/// of owned NFT IDs in a collection without first
|
|
203
|
+
/// having to load the entire list into memory
|
|
204
|
+
access(all) fun forEachID(_ f: fun (UInt64): Bool): Void {
|
|
205
|
+
self.ownedNFTs.forEachKey(f)
|
|
206
|
+
}
|
|
200
207
|
|
|
201
208
|
/// Borrows a reference to an NFT stored in the collection
|
|
202
209
|
/// If the NFT with the specified ID is not in the collection,
|
|
@@ -231,4 +238,4 @@ access(all) contract interface NonFungibleToken: ViewResolver {
|
|
|
231
238
|
result.getIDs().length == 0: "The created collection must be empty!"
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
|
-
}
|
|
241
|
+
}
|
|
@@ -1060,7 +1060,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1060
1060
|
access(all) resource Collection: MomentCollectionPublic, NonFungibleToken.Collection {
|
|
1061
1061
|
// Dictionary of Moment conforming tokens
|
|
1062
1062
|
// NFT is a resource type with a UInt64 ID field
|
|
1063
|
-
access(
|
|
1063
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
1064
1064
|
|
|
1065
1065
|
init() {
|
|
1066
1066
|
self.ownedNFTs <- {}
|
|
@@ -1098,7 +1098,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1098
1098
|
// that is to be removed from the Collection
|
|
1099
1099
|
//
|
|
1100
1100
|
// returns: @NonFungibleToken.NFT the token that was withdrawn
|
|
1101
|
-
access(NonFungibleToken.Withdraw
|
|
1101
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
1102
1102
|
|
|
1103
1103
|
// Borrow nft and check if locked
|
|
1104
1104
|
let nft = self.borrowNFT(withdrawID)
|
|
@@ -1124,7 +1124,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1124
1124
|
// Returns: @NonFungibleToken.Collection: A collection that contains
|
|
1125
1125
|
// the withdrawn moments
|
|
1126
1126
|
//
|
|
1127
|
-
access(NonFungibleToken.Withdraw
|
|
1127
|
+
access(NonFungibleToken.Withdraw) fun batchWithdraw(ids: [UInt64]): @{NonFungibleToken.Collection} {
|
|
1128
1128
|
// Create a new empty Collection
|
|
1129
1129
|
var batchCollection <- create Collection()
|
|
1130
1130
|
|
|
@@ -1181,7 +1181,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1181
1181
|
|
|
1182
1182
|
// lock takes a token id and a duration in seconds and locks
|
|
1183
1183
|
// the moment for that duration
|
|
1184
|
-
access(NonFungibleToken.Update
|
|
1184
|
+
access(NonFungibleToken.Update) fun lock(id: UInt64, duration: UFix64) {
|
|
1185
1185
|
// Remove the nft from the Collection
|
|
1186
1186
|
let token <- self.ownedNFTs.remove(key: id)
|
|
1187
1187
|
?? panic("Cannot lock: Moment does not exist in the collection")
|
|
@@ -1195,7 +1195,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1195
1195
|
|
|
1196
1196
|
// batchLock takes an array of token ids and a duration in seconds
|
|
1197
1197
|
// it iterates through the ids and locks each for the specified duration
|
|
1198
|
-
access(NonFungibleToken.Update
|
|
1198
|
+
access(NonFungibleToken.Update) fun batchLock(ids: [UInt64], duration: UFix64) {
|
|
1199
1199
|
// Iterate through the ids and lock them
|
|
1200
1200
|
for id in ids {
|
|
1201
1201
|
self.lock(id: id, duration: duration)
|
|
@@ -1204,7 +1204,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1204
1204
|
|
|
1205
1205
|
// unlock takes a token id and attempts to unlock it
|
|
1206
1206
|
// TopShotLocking.unlockNFT contains business logic around unlock eligibility
|
|
1207
|
-
access(NonFungibleToken.Update
|
|
1207
|
+
access(NonFungibleToken.Update) fun unlock(id: UInt64) {
|
|
1208
1208
|
// Remove the nft from the Collection
|
|
1209
1209
|
let token <- self.ownedNFTs.remove(key: id)
|
|
1210
1210
|
?? panic("Cannot lock: Moment does not exist in the collection")
|
|
@@ -1218,7 +1218,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1218
1218
|
|
|
1219
1219
|
// batchUnlock takes an array of token ids
|
|
1220
1220
|
// it iterates through the ids and unlocks each if they are eligible
|
|
1221
|
-
access(NonFungibleToken.Update
|
|
1221
|
+
access(NonFungibleToken.Update) fun batchUnlock(ids: [UInt64]) {
|
|
1222
1222
|
// Iterate through the ids and unlocks them
|
|
1223
1223
|
for id in ids {
|
|
1224
1224
|
self.unlock(id: id)
|
|
@@ -1230,7 +1230,7 @@ access(all) contract TopShot: NonFungibleToken {
|
|
|
1230
1230
|
//
|
|
1231
1231
|
// Parameters: ids: An array of NFT IDs
|
|
1232
1232
|
// to be destroyed from the Collection
|
|
1233
|
-
access(NonFungibleToken.Update
|
|
1233
|
+
access(NonFungibleToken.Update) fun destroyMoments(ids: [UInt64]) {
|
|
1234
1234
|
let topShotLockingAdmin = TopShot.account.storage.borrow<&TopShotLocking.Admin>(from: TopShotLocking.AdminStoragePath())
|
|
1235
1235
|
?? panic("No TopShotLocking admin resource in storage")
|
|
1236
1236
|
|
|
@@ -130,7 +130,7 @@ access(all) contract OffersV2 {
|
|
|
130
130
|
// This will accept the offer if provided with the NFT id that matches the Offer
|
|
131
131
|
//
|
|
132
132
|
access(all) fun accept(
|
|
133
|
-
item: @{NonFungibleToken.
|
|
133
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
134
134
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
135
135
|
): Void
|
|
136
136
|
// getDetails
|
|
@@ -210,7 +210,7 @@ access(all) contract OffersV2 {
|
|
|
210
210
|
// - Provided with a NFT matching the NFT Type within the Offer details.
|
|
211
211
|
//
|
|
212
212
|
access(all) fun accept(
|
|
213
|
-
item: @{NonFungibleToken.
|
|
213
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
214
214
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
215
215
|
): Void {
|
|
216
216
|
|
|
@@ -221,7 +221,7 @@ access(all) contract OffersV2 {
|
|
|
221
221
|
|
|
222
222
|
let resolverCapability = self.resolverCapability.borrow() ?? panic("could not borrow resolver")
|
|
223
223
|
let resolverResult = resolverCapability.checkOfferResolver(
|
|
224
|
-
item: &item as &{NonFungibleToken.
|
|
224
|
+
item: &item as &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
225
225
|
offerParamsString: self.details.offerParamsString,
|
|
226
226
|
offerParamsUInt64: self.details.offerParamsUInt64,
|
|
227
227
|
offerParamsUFix64: self.details.offerParamsUFix64,
|
|
@@ -15,7 +15,7 @@ access(all) contract Resolver {
|
|
|
15
15
|
// which is used within the Resolver resource for offer acceptance validation
|
|
16
16
|
access(all) resource interface ResolverPublic {
|
|
17
17
|
access(all) fun checkOfferResolver(
|
|
18
|
-
item: &{NonFungibleToken.
|
|
18
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
19
19
|
offerParamsString: {String:String},
|
|
20
20
|
offerParamsUInt64: {String:UInt64},
|
|
21
21
|
offerParamsUFix64: {String:UFix64}): Bool
|
|
@@ -28,7 +28,7 @@ access(all) contract Resolver {
|
|
|
28
28
|
// Holds the validation rules for resolver each type of supported ResolverType
|
|
29
29
|
// Function returns TRUE if the provided nft item passes the criteria for exchange
|
|
30
30
|
access(all) fun checkOfferResolver(
|
|
31
|
-
item: &{NonFungibleToken.
|
|
31
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
32
32
|
offerParamsString: {String:String},
|
|
33
33
|
offerParamsUInt64: {String:UInt64},
|
|
34
34
|
offerParamsUFix64: {String:UFix64}): Bool {
|
|
@@ -164,7 +164,7 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
164
164
|
|
|
165
165
|
// dictionary of NFT conforming tokens
|
|
166
166
|
// NFT is a resource type with an `UInt64` ID field
|
|
167
|
-
access(
|
|
167
|
+
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
|
|
168
168
|
|
|
169
169
|
init () {
|
|
170
170
|
self.ownedNFTs <- {}
|
|
@@ -206,7 +206,7 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
// withdraw removes an NFT from the collection and moves it to the caller
|
|
209
|
-
access(NonFungibleToken.Withdraw
|
|
209
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
210
210
|
let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
|
|
211
211
|
|
|
212
212
|
emit Withdraw(id: token.id, from: self.owner?.address)
|
|
@@ -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
|
|
81
|
+
access(self) let provider: Capability<auth(NonFungibleToken.Withdraw) &{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
|
|
94
|
+
access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>, filters: [{NFTFilter}], expiration: UFix64?) {
|
|
95
95
|
self.provider = provider
|
|
96
96
|
self.expiration = expiration
|
|
97
97
|
self.filters = filters
|
|
@@ -125,7 +125,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
125
125
|
return self.provider.check()
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
access(NonFungibleToken.Withdraw
|
|
128
|
+
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
129
129
|
pre {
|
|
130
130
|
!self.isExpired(): "provider has expired"
|
|
131
131
|
}
|
|
@@ -157,7 +157,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
access(all) fun createScopedNFTProvider(
|
|
160
|
-
provider: Capability<auth(NonFungibleToken.Withdraw
|
|
160
|
+
provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>,
|
|
161
161
|
filters: [{NFTFilter}],
|
|
162
162
|
expiration: UFix64?
|
|
163
163
|
): @ScopedNFTProvider {
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
240
|
-
access(Manage
|
|
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
|
|
243
|
-
access(Manage
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
1103
|
+
access(Owner) fun borrowChildAccount(parent: Address): auth(Child) &ChildAccount? {
|
|
1104
1104
|
let identifier = HybridCustody.getChildAccountIdentifier(parent)
|
|
1105
|
-
return self.borrowAccount().storage.borrow<auth(
|
|
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(
|
|
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(
|
|
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.
|
|
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.
|
|
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,45 @@
|
|
|
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
|
+
let cap = acct.capabilities.get<&{FungibleToken.Vault}>(path)
|
|
38
|
+
if !cap.check() {
|
|
39
|
+
return nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return cap
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.Collection}>() {
|
|
9
|
+
return nil
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return con.capability as! Capability<auth(NonFungibleToken.Withdraw) &{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
|
+
let cap = acct.capabilities.get<&{NonFungibleToken.Collection}>(path)
|
|
38
|
+
if !cap.check() {
|
|
39
|
+
return nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return cap
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|