@flowtyio/flow-contracts 0.1.0-beta.2 → 0.1.0-beta.21
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/Burner.cdc +44 -0
- package/contracts/FlowStorageFees.cdc +15 -15
- package/contracts/FlowToken.cdc +29 -78
- package/contracts/FungibleToken.cdc +80 -53
- package/contracts/FungibleTokenMetadataViews.cdc +13 -25
- package/contracts/MetadataViews.cdc +107 -50
- package/contracts/NonFungibleToken.cdc +110 -60
- package/contracts/TokenForwarding.cdc +19 -11
- package/contracts/ViewResolver.cdc +20 -16
- package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
- package/contracts/dapper/FlowUtilityToken.cdc +107 -40
- package/contracts/dapper/TopShot.cdc +323 -259
- package/contracts/dapper/TopShotLocking.cdc +41 -15
- package/contracts/dapper/offers/DapperOffersV2.cdc +36 -40
- package/contracts/dapper/offers/OffersV2.cdc +52 -51
- package/contracts/dapper/offers/Resolver.cdc +13 -12
- package/contracts/emerald-city/FLOAT.cdc +259 -254
- package/contracts/example/ExampleNFT.cdc +419 -0
- package/contracts/example/ExampleToken.cdc +302 -0
- package/contracts/find/FindViews.cdc +357 -353
- package/contracts/flow-utils/AddressUtils.cdc +20 -23
- package/contracts/flow-utils/ArrayUtils.cdc +10 -11
- package/contracts/flow-utils/ScopedFTProviders.cdc +27 -19
- package/contracts/flow-utils/ScopedNFTProviders.cdc +31 -26
- package/contracts/flow-utils/StringUtils.cdc +24 -37
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +29 -26
- package/contracts/hybrid-custody/CapabilityFactory.cdc +21 -18
- package/contracts/hybrid-custody/CapabilityFilter.cdc +42 -24
- package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
- 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/FTVaultFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- 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/contracts/lost-and-found/LostAndFound.cdc +14 -14
- package/contracts/nft-catalog/NFTCatalog.cdc +60 -64
- package/contracts/nft-catalog/NFTCatalogAdmin.cdc +28 -27
- package/flow.json +38 -1
- package/package.json +1 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import "FungibleToken"
|
|
2
|
+
import "FungibleTokenMetadataViews"
|
|
3
|
+
import "MetadataViews"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// THIS CONTRACT IS FOR TESTING PURPOSES ONLY!
|
|
7
|
+
access(all) contract ExampleToken {
|
|
8
|
+
|
|
9
|
+
/// Total supply of ExampleTokens in existence
|
|
10
|
+
access(all) var totalSupply: UFix64
|
|
11
|
+
|
|
12
|
+
/// TokensInitialized
|
|
13
|
+
///
|
|
14
|
+
/// The event that is emitted when the contract is created
|
|
15
|
+
access(all) event TokensInitialized(initialSupply: UFix64)
|
|
16
|
+
|
|
17
|
+
/// TokensWithdrawn
|
|
18
|
+
///
|
|
19
|
+
/// The event that is emitted when tokens are withdrawn from a Vault
|
|
20
|
+
access(all) event TokensWithdrawn(amount: UFix64, from: Address?)
|
|
21
|
+
|
|
22
|
+
/// TokensDeposited
|
|
23
|
+
///
|
|
24
|
+
/// The event that is emitted when tokens are deposited to a Vault
|
|
25
|
+
access(all) event TokensDeposited(amount: UFix64, to: Address?)
|
|
26
|
+
|
|
27
|
+
/// TokensMinted
|
|
28
|
+
///
|
|
29
|
+
/// The event that is emitted when new tokens are minted
|
|
30
|
+
access(all) event TokensMinted(amount: UFix64)
|
|
31
|
+
|
|
32
|
+
/// TokensBurned
|
|
33
|
+
///
|
|
34
|
+
/// The event that is emitted when tokens are destroyed
|
|
35
|
+
access(all) event TokensBurned(amount: UFix64)
|
|
36
|
+
|
|
37
|
+
/// MinterCreated
|
|
38
|
+
///
|
|
39
|
+
/// The event that is emitted when a new minter resource is created
|
|
40
|
+
access(all) event MinterCreated(allowedAmount: UFix64)
|
|
41
|
+
|
|
42
|
+
/// BurnerCreated
|
|
43
|
+
///
|
|
44
|
+
/// The event that is emitted when a new burner resource is created
|
|
45
|
+
access(all) event BurnerCreated()
|
|
46
|
+
|
|
47
|
+
/// Vault
|
|
48
|
+
///
|
|
49
|
+
/// Each user stores an instance of only the Vault in their storage
|
|
50
|
+
/// The functions in the Vault and governed by the pre and post conditions
|
|
51
|
+
/// in FungibleToken when they are called.
|
|
52
|
+
/// The checks happen at runtime whenever a function is called.
|
|
53
|
+
///
|
|
54
|
+
/// Resources can only be created in the context of the contract that they
|
|
55
|
+
/// are defined in, so there is no way for a malicious user to create Vaults
|
|
56
|
+
/// out of thin air. A special Minter resource needs to be defined to mint
|
|
57
|
+
/// new tokens.
|
|
58
|
+
///
|
|
59
|
+
access(all) resource Vault: FungibleToken.Vault {
|
|
60
|
+
|
|
61
|
+
/// The total balance of this vault
|
|
62
|
+
access(all) var balance: UFix64
|
|
63
|
+
|
|
64
|
+
// initialize the balance at resource creation time
|
|
65
|
+
init(balance: UFix64) {
|
|
66
|
+
self.balance = balance
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
access(all) view fun getBalance(): UFix64 {
|
|
70
|
+
return self.balance
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
access(all) view fun getDefaultStoragePath(): StoragePath? {
|
|
74
|
+
return /storage/exampleTokenVault
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
access(all) view fun getDefaultPublicPath(): PublicPath? {
|
|
78
|
+
return /public/exampleTokenPublic
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
access(all) view fun getDefaultReceiverPath(): PublicPath? {
|
|
82
|
+
return /public/exampleTokenPublic
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
|
|
86
|
+
return self.balance >= amount
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// Same as getViews above, but on a specific NFT instead of a contract
|
|
90
|
+
access(all) view fun getViews(): [Type] {
|
|
91
|
+
return ExampleToken.getContractViews(resourceType: nil)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// Same as resolveView above, but on a specific NFT instead of a contract
|
|
95
|
+
access(all) fun resolveView(_ view: Type): AnyStruct? {
|
|
96
|
+
return ExampleToken.resolveContractView(resourceType: nil, viewType: view)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// withdraw
|
|
100
|
+
///
|
|
101
|
+
/// Function that takes an amount as an argument
|
|
102
|
+
/// and withdraws that amount from the Vault.
|
|
103
|
+
///
|
|
104
|
+
/// It creates a new temporary Vault that is used to hold
|
|
105
|
+
/// the money that is being transferred. It returns the newly
|
|
106
|
+
/// created Vault to the context that called so it can be deposited
|
|
107
|
+
/// elsewhere.
|
|
108
|
+
///
|
|
109
|
+
access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
|
|
110
|
+
self.balance = self.balance - amount
|
|
111
|
+
emit TokensWithdrawn(amount: amount, from: self.owner?.address)
|
|
112
|
+
return <-create Vault(balance: amount)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
|
|
116
|
+
return {
|
|
117
|
+
Type<@ExampleToken.Vault>(): true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
access(all) view fun isSupportedVaultType(type: Type): Bool {
|
|
122
|
+
return type == Type<@ExampleToken.Vault>()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// deposit
|
|
126
|
+
///
|
|
127
|
+
/// Function that takes a Vault object as an argument and adds
|
|
128
|
+
/// its balance to the balance of the owners Vault.
|
|
129
|
+
///
|
|
130
|
+
/// It is allowed to destroy the sent Vault because the Vault
|
|
131
|
+
/// was a temporary holder of the tokens. The Vault's balance has
|
|
132
|
+
/// been consumed and therefore can be destroyed.
|
|
133
|
+
///
|
|
134
|
+
access(all) fun deposit(from: @{FungibleToken.Vault}) {
|
|
135
|
+
let vault <- from as! @ExampleToken.Vault
|
|
136
|
+
self.balance = self.balance + vault.balance
|
|
137
|
+
emit TokensDeposited(amount: vault.balance, to: self.owner?.address)
|
|
138
|
+
vault.balance = 0.0
|
|
139
|
+
destroy vault
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
access(all) fun createEmptyVault(): @Vault {
|
|
143
|
+
return <- ExampleToken.createEmptyVault()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// createEmptyVault
|
|
148
|
+
///
|
|
149
|
+
/// Function that creates a new Vault with a balance of zero
|
|
150
|
+
/// and returns it to the calling context. A user must call this function
|
|
151
|
+
/// and store the returned Vault in their storage in order to allow their
|
|
152
|
+
/// account to be able to receive deposits of this token type.
|
|
153
|
+
///
|
|
154
|
+
access(all) fun createEmptyVault(): @Vault {
|
|
155
|
+
return <-create Vault(balance: 0.0)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
access(all) resource Administrator {
|
|
159
|
+
|
|
160
|
+
/// createNewMinter
|
|
161
|
+
///
|
|
162
|
+
/// Function that creates and returns a new minter resource
|
|
163
|
+
///
|
|
164
|
+
access(all) fun createNewMinter(allowedAmount: UFix64): @Minter {
|
|
165
|
+
emit MinterCreated(allowedAmount: allowedAmount)
|
|
166
|
+
return <-create Minter(allowedAmount: allowedAmount)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/// createNewBurner
|
|
170
|
+
///
|
|
171
|
+
/// Function that creates and returns a new burner resource
|
|
172
|
+
///
|
|
173
|
+
access(all) fun createNewBurner(): @Burner {
|
|
174
|
+
emit BurnerCreated()
|
|
175
|
+
return <-create Burner()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Minter
|
|
180
|
+
///
|
|
181
|
+
/// Resource object that token admin accounts can hold to mint new tokens.
|
|
182
|
+
///
|
|
183
|
+
access(all) resource Minter {
|
|
184
|
+
|
|
185
|
+
/// The amount of tokens that the minter is allowed to mint
|
|
186
|
+
access(all) var allowedAmount: UFix64
|
|
187
|
+
|
|
188
|
+
/// mintTokens
|
|
189
|
+
///
|
|
190
|
+
/// Function that mints new tokens, adds them to the total supply,
|
|
191
|
+
/// and returns them to the calling context.
|
|
192
|
+
///
|
|
193
|
+
access(all) fun mintTokens(amount: UFix64): @ExampleToken.Vault {
|
|
194
|
+
pre {
|
|
195
|
+
amount > 0.0: "Amount minted must be greater than zero"
|
|
196
|
+
amount <= self.allowedAmount: "Amount minted must be less than the allowed amount"
|
|
197
|
+
}
|
|
198
|
+
ExampleToken.totalSupply = ExampleToken.totalSupply + amount
|
|
199
|
+
self.allowedAmount = self.allowedAmount - amount
|
|
200
|
+
emit TokensMinted(amount: amount)
|
|
201
|
+
return <-create Vault(balance: amount)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
init(allowedAmount: UFix64) {
|
|
205
|
+
self.allowedAmount = allowedAmount
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// Burner
|
|
210
|
+
///
|
|
211
|
+
/// Resource object that token admin accounts can hold to burn tokens.
|
|
212
|
+
///
|
|
213
|
+
access(all) resource Burner {
|
|
214
|
+
|
|
215
|
+
/// burnTokens
|
|
216
|
+
///
|
|
217
|
+
/// Function that destroys a Vault instance, effectively burning the tokens.
|
|
218
|
+
///
|
|
219
|
+
/// Note: the burned tokens are automatically subtracted from the
|
|
220
|
+
/// total supply in the Vault destructor.
|
|
221
|
+
///
|
|
222
|
+
access(all) fun burnTokens(from: @{FungibleToken.Vault}) {
|
|
223
|
+
let vault <- from as! @ExampleToken.Vault
|
|
224
|
+
let amount = vault.balance
|
|
225
|
+
destroy vault
|
|
226
|
+
emit TokensBurned(amount: amount)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
access(all) view fun getContractViews(resourceType: Type?): [Type] {
|
|
231
|
+
return [Type<FungibleTokenMetadataViews.FTView>(),
|
|
232
|
+
Type<FungibleTokenMetadataViews.FTDisplay>(),
|
|
233
|
+
Type<FungibleTokenMetadataViews.FTVaultData>(),
|
|
234
|
+
Type<FungibleTokenMetadataViews.TotalSupply>()]
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
|
|
238
|
+
switch viewType {
|
|
239
|
+
case Type<FungibleTokenMetadataViews.FTView>():
|
|
240
|
+
return FungibleTokenMetadataViews.FTView(
|
|
241
|
+
ftDisplay: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTDisplay>()) as! FungibleTokenMetadataViews.FTDisplay?,
|
|
242
|
+
ftVaultData: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
|
|
243
|
+
)
|
|
244
|
+
case Type<FungibleTokenMetadataViews.FTDisplay>():
|
|
245
|
+
let media = MetadataViews.Media(
|
|
246
|
+
file: MetadataViews.HTTPFile(
|
|
247
|
+
url: "https://example.com"
|
|
248
|
+
),
|
|
249
|
+
mediaType: "image/svg+xml"
|
|
250
|
+
)
|
|
251
|
+
let medias = MetadataViews.Medias([media])
|
|
252
|
+
return FungibleTokenMetadataViews.FTDisplay(
|
|
253
|
+
name: "Example Token",
|
|
254
|
+
symbol: "EXAMPLE",
|
|
255
|
+
description: "",
|
|
256
|
+
externalURL: MetadataViews.ExternalURL("https://flow.com"),
|
|
257
|
+
logos: medias,
|
|
258
|
+
socials: {
|
|
259
|
+
"twitter": MetadataViews.ExternalURL("https://twitter.com/flow_blockchain")
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
case Type<FungibleTokenMetadataViews.FTVaultData>():
|
|
263
|
+
let vaultRef = ExampleToken.account.storage.borrow<auth(FungibleToken.Withdraw) &ExampleToken.Vault>(from: /storage/exampleTokenVault)
|
|
264
|
+
?? panic("Could not borrow reference to the contract's Vault!")
|
|
265
|
+
return FungibleTokenMetadataViews.FTVaultData(
|
|
266
|
+
storagePath: /storage/exampleTokenVault,
|
|
267
|
+
receiverPath: /public/exampleTokenReceiver,
|
|
268
|
+
metadataPath: /public/exampleTokenBalance,
|
|
269
|
+
receiverLinkedType: Type<&{FungibleToken.Receiver, FungibleToken.Vault}>(),
|
|
270
|
+
metadataLinkedType: Type<&{FungibleToken.Balance, FungibleToken.Vault}>(),
|
|
271
|
+
createEmptyVaultFunction: (fun (): @{FungibleToken.Vault} {
|
|
272
|
+
return <-vaultRef.createEmptyVault()
|
|
273
|
+
})
|
|
274
|
+
)
|
|
275
|
+
case Type<FungibleTokenMetadataViews.TotalSupply>():
|
|
276
|
+
return FungibleTokenMetadataViews.TotalSupply(totalSupply: ExampleToken.totalSupply)
|
|
277
|
+
}
|
|
278
|
+
return nil
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
init() {
|
|
282
|
+
self.totalSupply = 1000.0
|
|
283
|
+
|
|
284
|
+
// Create the Vault with the total supply of tokens and save it in storage
|
|
285
|
+
//
|
|
286
|
+
let vault <- create Vault(balance: self.totalSupply)
|
|
287
|
+
self.account.storage.save(<-vault, to: /storage/exampleTokenVault)
|
|
288
|
+
|
|
289
|
+
// Create a public capability to the stored Vault that only exposes
|
|
290
|
+
// the `deposit` method through the `Receiver` interface
|
|
291
|
+
//
|
|
292
|
+
let publicCap = self.account.capabilities.storage.issue<&ExampleToken.Vault>(/storage/exampleTokenVault)
|
|
293
|
+
self.account.capabilities.publish(publicCap, at: /public/exampleTokenPublic)
|
|
294
|
+
|
|
295
|
+
let admin <- create Administrator()
|
|
296
|
+
self.account.storage.save(<-admin, to: /storage/exampleTokenAdmin)
|
|
297
|
+
|
|
298
|
+
// Emit an event that shows that the contract was initialized
|
|
299
|
+
//
|
|
300
|
+
emit TokensInitialized(initialSupply: self.totalSupply)
|
|
301
|
+
}
|
|
302
|
+
}
|