@flowtyio/flow-contracts 0.1.0-beta.3 → 0.1.0-beta.31

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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/contracts/Burner.cdc +44 -0
  3. package/contracts/FlowStorageFees.cdc +15 -15
  4. package/contracts/FlowToken.cdc +29 -78
  5. package/contracts/FungibleToken.cdc +80 -53
  6. package/contracts/FungibleTokenMetadataViews.cdc +13 -25
  7. package/contracts/FungibleTokenSwitchboard.cdc +360 -0
  8. package/contracts/MetadataViews.cdc +107 -50
  9. package/contracts/NonFungibleToken.cdc +110 -60
  10. package/contracts/TokenForwarding.cdc +19 -11
  11. package/contracts/ViewResolver.cdc +20 -16
  12. package/contracts/capability-cache/CapabilityCache.cdc +97 -0
  13. package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
  14. package/contracts/dapper/FlowUtilityToken.cdc +107 -40
  15. package/contracts/dapper/TopShot.cdc +323 -259
  16. package/contracts/dapper/TopShotLocking.cdc +41 -15
  17. package/contracts/dapper/offers/DapperOffersV2.cdc +46 -43
  18. package/contracts/dapper/offers/OffersV2.cdc +40 -56
  19. package/contracts/dapper/offers/Resolver.cdc +20 -13
  20. package/contracts/emerald-city/FLOAT.cdc +259 -254
  21. package/contracts/example/ExampleNFT.cdc +18 -21
  22. package/contracts/example/ExampleToken.cdc +68 -1
  23. package/contracts/find/FindViews.cdc +357 -353
  24. package/contracts/flow-utils/AddressUtils.cdc +20 -23
  25. package/contracts/flow-utils/ArrayUtils.cdc +10 -11
  26. package/contracts/flow-utils/ScopedFTProviders.cdc +27 -19
  27. package/contracts/flow-utils/ScopedNFTProviders.cdc +31 -26
  28. package/contracts/flow-utils/StringUtils.cdc +24 -37
  29. package/contracts/flowty-drops/ContractManager.cdc +47 -0
  30. package/contracts/flowty-drops/DropFactory.cdc +75 -0
  31. package/contracts/flowty-drops/DropTypes.cdc +278 -0
  32. package/contracts/flowty-drops/FlowtyAddressVerifiers.cdc +64 -0
  33. package/contracts/flowty-drops/FlowtyDrops.cdc +431 -0
  34. package/contracts/flowty-drops/FlowtyPricers.cdc +48 -0
  35. package/contracts/flowty-drops/FlowtySwitchers.cdc +113 -0
  36. package/contracts/flowty-drops/initializers/ContractBorrower.cdc +14 -0
  37. package/contracts/flowty-drops/initializers/ContractInitializer.cdc +7 -0
  38. package/contracts/flowty-drops/initializers/OpenEditionInitializer.cdc +58 -0
  39. package/contracts/flowty-drops/nft/BaseCollection.cdc +97 -0
  40. package/contracts/flowty-drops/nft/BaseNFT.cdc +107 -0
  41. package/contracts/flowty-drops/nft/ContractFactory.cdc +13 -0
  42. package/contracts/flowty-drops/nft/ContractFactoryTemplate.cdc +48 -0
  43. package/contracts/flowty-drops/nft/NFTMetadata.cdc +119 -0
  44. package/contracts/flowty-drops/nft/OpenEditionNFT.cdc +41 -0
  45. package/contracts/flowty-drops/nft/OpenEditionTemplate.cdc +52 -0
  46. package/contracts/flowty-drops/nft/UniversalCollection.cdc +23 -0
  47. package/contracts/fungible-token-router/FungibleTokenRouter.cdc +103 -0
  48. package/contracts/hybrid-custody/CapabilityDelegator.cdc +28 -26
  49. package/contracts/hybrid-custody/CapabilityFactory.cdc +20 -18
  50. package/contracts/hybrid-custody/CapabilityFilter.cdc +41 -24
  51. package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
  52. package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
  53. package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
  54. package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
  55. package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
  56. package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
  57. package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +46 -0
  58. package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
  59. package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
  60. package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +22 -0
  61. package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
  62. package/contracts/lost-and-found/LostAndFound.cdc +29 -25
  63. package/contracts/nft-catalog/NFTCatalog.cdc +60 -64
  64. package/contracts/nft-catalog/NFTCatalogAdmin.cdc +28 -27
  65. package/flow.json +189 -5
  66. package/package.json +1 -1
  67. package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +0 -10
@@ -4,21 +4,21 @@ import "ViewResolver"
4
4
 
5
5
  /// This contract implements the metadata standard proposed
6
6
  /// in FLIP-1087.
7
- ///
7
+ ///
8
8
  /// Ref: https://github.com/onflow/flips/blob/main/application/20220811-fungible-tokens-metadata.md
9
- ///
9
+ ///
10
10
  /// Structs and resources can implement one or more
11
11
  /// metadata types, called views. Each view type represents
12
12
  /// a different kind of metadata.
13
13
  ///
14
14
  access(all) contract FungibleTokenMetadataViews {
15
15
 
16
- /// FTView wraps FTDisplay and FTVaultData, and is used to give a complete
17
- /// picture of a Fungible Token. Most Fungible Token contracts should
16
+ /// FTView wraps FTDisplay and FTVaultData, and is used to give a complete
17
+ /// picture of a Fungible Token. Most Fungible Token contracts should
18
18
  /// implement this view.
19
19
  ///
20
20
  access(all) struct FTView {
21
- access(all) let ftDisplay: FTDisplay?
21
+ access(all) let ftDisplay: FTDisplay?
22
22
  access(all) let ftVaultData: FTVaultData?
23
23
  view init(
24
24
  ftDisplay: FTDisplay?,
@@ -45,8 +45,8 @@ access(all) contract FungibleTokenMetadataViews {
45
45
  )
46
46
  }
47
47
 
48
- /// View to expose the information needed to showcase this FT.
49
- /// This can be used by applications to give an overview and
48
+ /// View to expose the information needed to showcase this FT.
49
+ /// This can be used by applications to give an overview and
50
50
  /// graphics of the FT.
51
51
  ///
52
52
  access(all) struct FTDisplay {
@@ -94,7 +94,7 @@ access(all) contract FungibleTokenMetadataViews {
94
94
  }
95
95
 
96
96
  /// Helper to get FTDisplay in a way that will return a typed optional.
97
- ///
97
+ ///
98
98
  /// @param viewResolver: A reference to the resolver resource
99
99
  /// @return An optional FTDisplay struct
100
100
  ///
@@ -108,7 +108,7 @@ access(all) contract FungibleTokenMetadataViews {
108
108
  }
109
109
 
110
110
  /// View to expose the information needed store and interact with a FT vault.
111
- /// This can be used by applications to setup a FT vault with proper
111
+ /// This can be used by applications to setup a FT vault with proper
112
112
  /// storage and public capabilities.
113
113
  ///
114
114
  access(all) struct FTVaultData {
@@ -121,22 +121,14 @@ access(all) contract FungibleTokenMetadataViews {
121
121
  /// Public path which must be linked to expose the balance and resolver public capabilities.
122
122
  access(all) let metadataPath: PublicPath
123
123
 
124
- /// Private path which should be linked to expose the provider capability to withdraw funds
125
- /// from the vault.
126
- access(all) let providerPath: PrivatePath
127
-
128
- /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
124
+ /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
129
125
  /// the `FungibleToken.Receiver` interface.
130
126
  access(all) let receiverLinkedType: Type
131
127
 
132
- /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
128
+ /// Type that should be linked at the `receiverPath`. This is a restricted type requiring
133
129
  /// the `ViewResolver.Resolver` interfaces.
134
130
  access(all) let metadataLinkedType: Type
135
131
 
136
- /// Type that should be linked at the aforementioned private path. This
137
- /// is normally a restricted type with at a minimum the `FungibleToken.Provider` interface.
138
- access(all) let providerLinkedType: Type
139
-
140
132
  /// Function that allows creation of an empty FT vault that is intended
141
133
  /// to store the funds.
142
134
  access(all) let createEmptyVault: fun(): @{FungibleToken.Vault}
@@ -145,24 +137,19 @@ access(all) contract FungibleTokenMetadataViews {
145
137
  storagePath: StoragePath,
146
138
  receiverPath: PublicPath,
147
139
  metadataPath: PublicPath,
148
- providerPath: PrivatePath,
149
140
  receiverLinkedType: Type,
150
141
  metadataLinkedType: Type,
151
- providerLinkedType: Type,
152
142
  createEmptyVaultFunction: fun(): @{FungibleToken.Vault}
153
143
  ) {
154
144
  pre {
155
145
  receiverLinkedType.isSubtype(of: Type<&{FungibleToken.Receiver}>()): "Receiver public type must include FungibleToken.Receiver."
156
- metadataLinkedType.isSubtype(of: Type<&{ViewResolver.Resolver}>()): "Metadata public type must include ViewResolver.Resolver interfaces."
157
- providerLinkedType.isSubtype(of: Type<&{FungibleToken.Provider}>()): "Provider type must include FungibleToken.Provider interface."
146
+ metadataLinkedType.isSubtype(of: Type<&{FungibleToken.Vault}>()): "Metadata linked type must be a fungible token vault"
158
147
  }
159
148
  self.storagePath = storagePath
160
149
  self.receiverPath = receiverPath
161
150
  self.metadataPath = metadataPath
162
- self.providerPath = providerPath
163
151
  self.receiverLinkedType = receiverLinkedType
164
152
  self.metadataLinkedType = metadataLinkedType
165
- self.providerLinkedType = providerLinkedType
166
153
  self.createEmptyVault = createEmptyVaultFunction
167
154
  }
168
155
  }
@@ -190,3 +177,4 @@ access(all) contract FungibleTokenMetadataViews {
190
177
  }
191
178
  }
192
179
  }
180
+
@@ -0,0 +1,360 @@
1
+ import "FungibleToken"
2
+
3
+ /// The contract that allows an account to receive payments in multiple fungible
4
+ /// tokens using a single `{FungibleToken.Receiver}` capability.
5
+ /// This capability should ideally be stored at the
6
+ /// `FungibleTokenSwitchboard.ReceiverPublicPath = /public/GenericFTReceiver`
7
+ /// but it can be stored anywhere.
8
+ ///
9
+ access(all) contract FungibleTokenSwitchboard {
10
+
11
+ // Storage and Public Paths
12
+ access(all) let StoragePath: StoragePath
13
+ access(all) let PublicPath: PublicPath
14
+ access(all) let ReceiverPublicPath: PublicPath
15
+
16
+ access(all) entitlement Owner
17
+
18
+ /// The event that is emitted when a new vault capability is added to a
19
+ /// switchboard resource.
20
+ ///
21
+ access(all) event VaultCapabilityAdded(type: Type, switchboardOwner: Address?,
22
+ capabilityOwner: Address?)
23
+
24
+ /// The event that is emitted when a vault capability is removed from a
25
+ /// switchboard resource.
26
+ ///
27
+ access(all) event VaultCapabilityRemoved(type: Type, switchboardOwner: Address?,
28
+ capabilityOwner: Address?)
29
+
30
+ /// The event that is emitted when a deposit can not be completed.
31
+ ///
32
+ access(all) event NotCompletedDeposit(type: Type, amount: UFix64,
33
+ switchboardOwner: Address?)
34
+
35
+ /// The interface that enforces the method to allow anyone to check on the
36
+ /// available capabilities of a switchboard resource and also exposes the
37
+ /// deposit methods to deposit funds on it.
38
+ ///
39
+ access(all) resource interface SwitchboardPublic {
40
+ access(all) view fun getVaultTypesWithAddress(): {Type: Address}
41
+ access(all) view fun getSupportedVaultTypes(): {Type: Bool}
42
+ access(all) view fun isSupportedVaultType(type: Type): Bool
43
+ access(all) fun deposit(from: @{FungibleToken.Vault})
44
+ access(all) fun safeDeposit(from: @{FungibleToken.Vault}): @{FungibleToken.Vault}?
45
+ access(all) view fun safeBorrowByType(type: Type): &{FungibleToken.Receiver}?
46
+ }
47
+
48
+ /// The resource that stores the multiple fungible token receiver
49
+ /// capabilities, allowing the owner to add and remove them and anyone to
50
+ /// deposit any fungible token among the available types.
51
+ ///
52
+ access(all) resource Switchboard: FungibleToken.Receiver, SwitchboardPublic {
53
+
54
+ /// Dictionary holding the fungible token receiver capabilities,
55
+ /// indexed by the fungible token vault type.
56
+ ///
57
+ access(contract) var receiverCapabilities: {Type: Capability<&{FungibleToken.Receiver}>}
58
+
59
+ /// Adds a new fungible token receiver capability to the switchboard
60
+ /// resource.
61
+ ///
62
+ /// @param capability: The capability to expose a certain fungible
63
+ /// token vault deposit function through `{FungibleToken.Receiver}` that
64
+ /// will be added to the switchboard.
65
+ ///
66
+ access(Owner) fun addNewVault(capability: Capability<&{FungibleToken.Receiver}>) {
67
+ // Borrow a reference to the vault pointed to by the capability we
68
+ // want to store inside the switchboard
69
+ let vaultRef = capability.borrow()
70
+ ?? panic ("Cannot borrow reference to vault from capability")
71
+ // Check if there is a previous capability for this token, if not
72
+ if (self.receiverCapabilities[vaultRef.getType()] == nil) {
73
+ // use the vault reference type as key for storing the
74
+ // capability and then
75
+ self.receiverCapabilities[vaultRef.getType()] = capability
76
+ // emit the event that indicates that a new capability has been
77
+ // added
78
+ emit VaultCapabilityAdded(type: vaultRef.getType(),
79
+ switchboardOwner: self.owner?.address,
80
+ capabilityOwner: capability.address)
81
+ } else {
82
+ // If there was already a capability for that token, panic
83
+ panic("There is already a vault in the Switchboard for this token")
84
+ }
85
+ }
86
+
87
+ /// Adds a number of new fungible token receiver capabilities by using
88
+ /// the paths where they are stored.
89
+ ///
90
+ /// @param paths: The paths where the public capabilities are stored.
91
+ /// @param address: The address of the owner of the capabilities.
92
+ ///
93
+ access(Owner) fun addNewVaultsByPath(paths: [PublicPath], address: Address) {
94
+ // Get the account where the public capabilities are stored
95
+ let owner = getAccount(address)
96
+ // For each path, get the saved capability and store it
97
+ // into the switchboard's receiver capabilities dictionary
98
+ for path in paths {
99
+ let capability = owner.capabilities.get<&{FungibleToken.Receiver}>(path)
100
+ // Borrow a reference to the vault pointed to by the capability
101
+ // we want to store inside the switchboard
102
+ // If the vault was borrowed successfully...
103
+ if let vaultRef = capability.borrow() {
104
+ // ...and if there is no previous capability added for that token
105
+ if (self.receiverCapabilities[vaultRef!.getType()] == nil) {
106
+ // Use the vault reference type as key for storing the
107
+ // capability
108
+ self.receiverCapabilities[vaultRef!.getType()] = capability
109
+ // and emit the event that indicates that a new
110
+ // capability has been added
111
+ emit VaultCapabilityAdded(type: vaultRef.getType(),
112
+ switchboardOwner: self.owner?.address,
113
+ capabilityOwner: address,
114
+ )
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ /// Adds a new fungible token receiver capability to the switchboard
121
+ /// resource specifying which `Type` of `@{FungibleToken.Vault}` can be
122
+ /// deposited to it. Use it to include in your switchboard "wrapper"
123
+ /// receivers such as a `@TokenForwarding.Forwarder`. It can also be
124
+ /// used to overwrite the type attached to a certain capability without
125
+ /// having to remove that capability first.
126
+ ///
127
+ /// @param capability: The capability to expose a certain fungible
128
+ /// token vault deposit function through `{FungibleToken.Receiver}` that
129
+ /// will be added to the switchboard.
130
+ ///
131
+ /// @param type: The type of fungible token that can be deposited to that
132
+ /// capability, rather than the `Type` from the reference borrowed from
133
+ /// said capability
134
+ ///
135
+ access(Owner) fun addNewVaultWrapper(capability: Capability<&{FungibleToken.Receiver}>,
136
+ type: Type) {
137
+ // Check if the capability is working
138
+ assert(capability.check(), message: "The passed capability is not valid")
139
+ // Use the type parameter as key for the capability
140
+ self.receiverCapabilities[type] = capability
141
+ // emit the event that indicates that a new capability has been
142
+ // added
143
+ emit VaultCapabilityAdded(
144
+ type: type,
145
+ switchboardOwner: self.owner?.address,
146
+ capabilityOwner: capability.address,
147
+ )
148
+ }
149
+
150
+ /// Adds zero or more new fungible token receiver capabilities to the
151
+ /// switchboard resource specifying which `Type`s of `@{FungibleToken.Vault}`s
152
+ /// can be deposited to it. Use it to include in your switchboard "wrapper"
153
+ /// receivers such as a `@TokenForwarding.Forwarder`. It can also be
154
+ /// used to overwrite the types attached to certain capabilities without
155
+ /// having to remove those capabilities first.
156
+ ///
157
+ /// @param paths: The paths where the public capabilities are stored.
158
+ /// @param types: The types of the fungible token to be deposited on each path.
159
+ /// @param address: The address of the owner of the capabilities.
160
+ ///
161
+ access(Owner) fun addNewVaultWrappersByPath(paths: [PublicPath], types: [Type],
162
+ address: Address) {
163
+ // Get the account where the public capabilities are stored
164
+ let owner = getAccount(address)
165
+ // For each path, get the saved capability and store it
166
+ // into the switchboard's receiver capabilities dictionary
167
+ for i, path in paths {
168
+ let capability = owner.capabilities.get<&{FungibleToken.Receiver}>(path)
169
+ // Borrow a reference to the vault pointed to by the capability
170
+ // we want to store inside the switchboard
171
+ // If the vault was borrowed successfully...
172
+ if let vaultRef = capability.borrow() {
173
+ // Use the vault reference type as key for storing the capability
174
+ self.receiverCapabilities[types[i]] = capability
175
+ // and emit the event that indicates that a new capability has been added
176
+ emit VaultCapabilityAdded(
177
+ type: types[i],
178
+ switchboardOwner: self.owner?.address,
179
+ capabilityOwner: address,
180
+ )
181
+ }
182
+ }
183
+ }
184
+
185
+ /// Removes a fungible token receiver capability from the switchboard
186
+ /// resource.
187
+ ///
188
+ /// @param capability: The capability to a fungible token vault to be
189
+ /// removed from the switchboard.
190
+ ///
191
+ access(Owner) fun removeVault(capability: Capability<&{FungibleToken.Receiver}>) {
192
+ // Borrow a reference to the vault pointed to by the capability we
193
+ // want to remove from the switchboard
194
+ let vaultRef = capability.borrow()
195
+ ?? panic ("Cannot borrow reference to vault from capability")
196
+ // Use the vault reference to find the capability to remove
197
+ self.receiverCapabilities.remove(key: vaultRef.getType())
198
+ // Emit the event that indicates that a new capability has been
199
+ // removed
200
+ emit VaultCapabilityRemoved(
201
+ type: vaultRef.getType(),
202
+ switchboardOwner: self.owner?.address,
203
+ capabilityOwner: capability.address,
204
+ )
205
+ }
206
+
207
+ /// Takes a fungible token vault and routes it to the proper fungible
208
+ /// token receiver capability for depositing it.
209
+ ///
210
+ /// @param from: The deposited fungible token vault resource.
211
+ ///
212
+ access(all) fun deposit(from: @{FungibleToken.Vault}) {
213
+ // Get the capability from the ones stored at the switchboard
214
+ let depositedVaultCapability = self.receiverCapabilities[from.getType()]
215
+ ?? panic ("The deposited vault is not available on this switchboard")
216
+
217
+ // Borrow the reference to the desired vault
218
+ let vaultRef = depositedVaultCapability.borrow()
219
+ ?? panic ("Can not borrow a reference to the the vault")
220
+
221
+ vaultRef.deposit(from: <-from)
222
+ }
223
+
224
+ /// Takes a fungible token vault and tries to route it to the proper
225
+ /// fungible token receiver capability for depositing the funds,
226
+ /// avoiding panicking if the vault is not available.
227
+ ///
228
+ /// @param vaultType: The type of the ft vault that wants to be
229
+ /// deposited.
230
+ ///
231
+ /// @return The deposited fungible token vault resource, without the
232
+ /// funds if the deposit was successful, or still containing the funds
233
+ /// if the reference to the needed vault was not found.
234
+ ///
235
+ access(all) fun safeDeposit(from: @{FungibleToken.Vault}): @{FungibleToken.Vault}? {
236
+ // Try to get the proper vault capability from the switchboard
237
+ // If the desired vault is present on the switchboard...
238
+ if let depositedVaultCapability = self.receiverCapabilities[from.getType()] {
239
+ // We try to borrow a reference to the vault from the capability
240
+ // If we can borrow a reference to the vault...
241
+ if let vaultRef = depositedVaultCapability.borrow() {
242
+ // We deposit the funds on said vault
243
+ vaultRef.deposit(from: <-from.withdraw(amount: from.balance))
244
+ }
245
+ }
246
+ // if deposit failed for some reason
247
+ if from.balance > 0.0 {
248
+ emit NotCompletedDeposit(
249
+ type: from.getType(),
250
+ amount: from.balance,
251
+ switchboardOwner: self.owner?.address,
252
+ )
253
+ return <-from
254
+ }
255
+ destroy from
256
+ return nil
257
+ }
258
+
259
+ /// Checks that the capability tied to a type is valid
260
+ ///
261
+ /// @param vaultType: The type of the ft vault whose capability needs to be checked
262
+ ///
263
+ /// @return a boolean marking the capability for a type as valid or not
264
+ access(all) view fun checkReceiverByType(type: Type): Bool {
265
+ if self.receiverCapabilities[type] == nil {
266
+ return false
267
+ }
268
+
269
+ return self.receiverCapabilities[type]!.check()
270
+ }
271
+
272
+ /// Gets the receiver assigned to a provided vault type.
273
+ /// This is necessary because without it, it is not possible to look under the hood and see if a capability
274
+ /// is of an expected type or not. This helps guard against infinitely chained TokenForwarding or other invalid
275
+ /// malicious kinds of updates that could prevent listings from being made that are valid on storefronts.
276
+ ///
277
+ /// @param vaultType: The type of the ft vault whose capability needs to be checked
278
+ ///
279
+ /// @return an optional receiver capability for consumers of the switchboard to check/validate on their own
280
+ access(all) view fun safeBorrowByType(type: Type): &{FungibleToken.Receiver}? {
281
+ if !self.checkReceiverByType(type: type) {
282
+ return nil
283
+ }
284
+
285
+ return self.receiverCapabilities[type]!.borrow()
286
+ }
287
+
288
+ /// A getter function to know which tokens a certain switchboard
289
+ /// resource is prepared to receive along with the address where
290
+ /// those tokens will be deposited.
291
+ ///
292
+ /// @return A dictionary mapping the `{FungibleToken.Receiver}`
293
+ /// type to the receiver owner's address
294
+ ///
295
+ access(all) view fun getVaultTypesWithAddress(): {Type: Address} {
296
+ let effectiveTypesWithAddress: {Type: Address} = {}
297
+ // Check if each capability is live
298
+ for vaultType in self.receiverCapabilities.keys {
299
+ if self.receiverCapabilities[vaultType]!.check() {
300
+ // and attach it to the owner's address
301
+ effectiveTypesWithAddress[vaultType] = self.receiverCapabilities[vaultType]!.address
302
+ }
303
+ }
304
+ return effectiveTypesWithAddress
305
+ }
306
+
307
+ /// A getter function that returns the token types supported by this resource,
308
+ /// which can be deposited using the 'deposit' function.
309
+ ///
310
+ /// @return Dictionary of FT types that can be deposited.
311
+ access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
312
+ let supportedVaults: {Type: Bool} = {}
313
+ for receiverType in self.receiverCapabilities.keys {
314
+ if self.receiverCapabilities[receiverType]!.check() {
315
+ if receiverType.isSubtype(of: Type<@{FungibleToken.Vault}>()) {
316
+ supportedVaults[receiverType] = true
317
+ }
318
+ if receiverType.isSubtype(of: Type<@{FungibleToken.Receiver}>()) {
319
+ let receiverRef = self.receiverCapabilities[receiverType]!.borrow()!
320
+ let subReceiverSupportedTypes = receiverRef.getSupportedVaultTypes()
321
+ for subReceiverType in subReceiverSupportedTypes.keys {
322
+ if subReceiverType.isSubtype(of: Type<@{FungibleToken.Vault}>()) {
323
+ supportedVaults[subReceiverType] = true
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ return supportedVaults
330
+ }
331
+
332
+ /// Returns whether or not the given type is accepted by the Receiver
333
+ /// A vault that can accept any type should just return true by default
334
+ access(all) view fun isSupportedVaultType(type: Type): Bool {
335
+ let supportedVaults = self.getSupportedVaultTypes()
336
+ if let supported = supportedVaults[type] {
337
+ return supported
338
+ } else { return false }
339
+ }
340
+
341
+ init() {
342
+ // Initialize the capabilities dictionary
343
+ self.receiverCapabilities = {}
344
+ }
345
+
346
+ }
347
+
348
+ /// Function that allows to create a new blank switchboard. A user must call
349
+ /// this function and store the returned resource in their storage.
350
+ ///
351
+ access(all) fun createSwitchboard(): @Switchboard {
352
+ return <-create Switchboard()
353
+ }
354
+
355
+ init() {
356
+ self.StoragePath = /storage/fungibleTokenSwitchboard
357
+ self.PublicPath = /public/fungibleTokenSwitchboardPublic
358
+ self.ReceiverPublicPath = /public/GenericFTReceiver
359
+ }
360
+ }