@flowtyio/flow-contracts 0.1.5 → 0.1.6

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.
@@ -1,10 +1,8 @@
1
1
  import "FungibleToken"
2
- import "FungibleTokenMetadataViews"
3
2
  import "MetadataViews"
3
+ import "FungibleTokenMetadataViews"
4
4
 
5
-
6
- // THIS CONTRACT IS FOR TESTING PURPOSES ONLY!
7
- access(all) contract ExampleToken {
5
+ access(all) contract ExampleToken: FungibleToken {
8
6
 
9
7
  /// Total supply of ExampleTokens in existence
10
8
  access(all) var totalSupply: UFix64
@@ -66,32 +64,36 @@ access(all) contract ExampleToken {
66
64
  self.balance = balance
67
65
  }
68
66
 
69
- access(all) view fun getBalance(): UFix64 {
70
- return self.balance
71
- }
72
-
73
- access(all) view fun getDefaultStoragePath(): StoragePath? {
74
- return /storage/exampleTokenVault
67
+ access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
68
+ return amount <= self.balance
75
69
  }
76
70
 
77
- access(all) view fun getDefaultPublicPath(): PublicPath? {
78
- return /public/exampleTokenPublic
71
+ access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
72
+ return {self.getType(): true}
79
73
  }
80
74
 
81
- access(all) view fun getDefaultReceiverPath(): PublicPath? {
82
- return /public/exampleTokenPublic
75
+ access(all) view fun isSupportedVaultType(type: Type): Bool {
76
+ if (type == self.getType()) { return true } else { return false }
83
77
  }
84
78
 
85
- access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
86
- return self.balance >= amount
79
+ access(all) fun createEmptyVault(): @{FungibleToken.Vault} {
80
+ return <-create Vault(balance: 0.0)
87
81
  }
88
82
 
89
- /// Same as getViews above, but on a specific NFT instead of a contract
90
- access(all) view fun getViews(): [Type] {
83
+ /// Get all the Metadata Views implemented by ExampleToken
84
+ ///
85
+ /// @return An array of Types defining the implemented views. This value will be used by
86
+ /// developers to know which parameter to pass to the resolveView() method.
87
+ ///
88
+ access(all) view fun getViews(): [Type]{
91
89
  return ExampleToken.getContractViews(resourceType: nil)
92
90
  }
93
91
 
94
- /// Same as resolveView above, but on a specific NFT instead of a contract
92
+ /// Get a Metadata View from ExampleToken
93
+ ///
94
+ /// @param view: The Type of the desired view.
95
+ /// @return A structure representing the requested view.
96
+ ///
95
97
  access(all) fun resolveView(_ view: Type): AnyStruct? {
96
98
  return ExampleToken.resolveContractView(resourceType: nil, viewType: view)
97
99
  }
@@ -112,16 +114,6 @@ access(all) contract ExampleToken {
112
114
  return <-create Vault(balance: amount)
113
115
  }
114
116
 
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
117
  /// deposit
126
118
  ///
127
119
  /// Function that takes a Vault object as an argument and adds
@@ -139,8 +131,8 @@ access(all) contract ExampleToken {
139
131
  destroy vault
140
132
  }
141
133
 
142
- access(all) fun createEmptyVault(): @Vault {
143
- return <- ExampleToken.createEmptyVault()
134
+ access(contract) fun burnCallback() {
135
+ ExampleToken.totalSupply = ExampleToken.totalSupply - self.balance
144
136
  }
145
137
  }
146
138
 
@@ -151,7 +143,7 @@ access(all) contract ExampleToken {
151
143
  /// and store the returned Vault in their storage in order to allow their
152
144
  /// account to be able to receive deposits of this token type.
153
145
  ///
154
- access(all) fun createEmptyVault(): @Vault {
146
+ access(all) fun createEmptyVault(vaultType: Type): @Vault {
155
147
  return <-create Vault(balance: 0.0)
156
148
  }
157
149
 
@@ -227,6 +219,7 @@ access(all) contract ExampleToken {
227
219
  }
228
220
  }
229
221
 
222
+ /// Gets a list of the metadata views that this contract supports
230
223
  access(all) view fun getContractViews(resourceType: Type?): [Type] {
231
224
  return [Type<FungibleTokenMetadataViews.FTView>(),
232
225
  Type<FungibleTokenMetadataViews.FTDisplay>(),
@@ -234,6 +227,21 @@ access(all) contract ExampleToken {
234
227
  Type<FungibleTokenMetadataViews.TotalSupply>()]
235
228
  }
236
229
 
230
+ access(all) fun mintTokens(amount: UFix64): @{FungibleToken.Vault} {
231
+ let admin = self.account.storage.borrow<&Administrator>(from: /storage/exampleTokenAdmin)!
232
+ let minter <- admin.createNewMinter(allowedAmount: amount)
233
+
234
+ let tokens <- minter.mintTokens(amount: amount)
235
+ destroy minter
236
+
237
+ return <- tokens
238
+ }
239
+
240
+ /// Get a Metadata View from ExampleToken
241
+ ///
242
+ /// @param view: The Type of the desired view.
243
+ /// @return A structure representing the requested view.
244
+ ///
237
245
  access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
238
246
  switch viewType {
239
247
  case Type<FungibleTokenMetadataViews.FTView>():
@@ -244,15 +252,15 @@ access(all) contract ExampleToken {
244
252
  case Type<FungibleTokenMetadataViews.FTDisplay>():
245
253
  let media = MetadataViews.Media(
246
254
  file: MetadataViews.HTTPFile(
247
- url: "https://example.com"
255
+ url: "example.com"
248
256
  ),
249
257
  mediaType: "image/svg+xml"
250
258
  )
251
259
  let medias = MetadataViews.Medias([media])
252
260
  return FungibleTokenMetadataViews.FTDisplay(
253
- name: "Example Token",
261
+ name: "EXAMPLE Token",
254
262
  symbol: "EXAMPLE",
255
- description: "",
263
+ description: "This is an example token",
256
264
  externalURL: MetadataViews.ExternalURL("https://flow.com"),
257
265
  logos: medias,
258
266
  socials: {
@@ -286,11 +294,10 @@ access(all) contract ExampleToken {
286
294
  let vault <- create Vault(balance: self.totalSupply)
287
295
  self.account.storage.save(<-vault, to: /storage/exampleTokenVault)
288
296
 
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)
297
+ let cap = self.account.capabilities.storage.issue<&{FungibleToken.Vault}>(/storage/exampleTokenVault)
298
+ self.account.capabilities.publish(cap, at: /public/exampleTokenReceiver)
299
+ self.account.capabilities.publish(cap, at: /public/exampleTokenBalance)
300
+
294
301
 
295
302
  let admin <- create Administrator()
296
303
  self.account.storage.save(<-admin, to: /storage/exampleTokenAdmin)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",