@flowtyio/flow-contracts 0.1.0-beta.7 → 0.1.0-beta.8

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,30 +1,32 @@
1
1
  import "FungibleToken"
2
+ import "MetadataViews"
3
+ import "FungibleTokenMetadataViews"
2
4
 
3
- pub contract DapperUtilityCoin: FungibleToken {
5
+ access(all) contract DapperUtilityCoin: FungibleToken {
4
6
 
5
7
  // Total supply of DapperUtilityCoins in existence
6
- pub var totalSupply: UFix64
8
+ access(all) var totalSupply: UFix64
7
9
 
8
10
  // Event that is emitted when the contract is created
9
- pub event TokensInitialized(initialSupply: UFix64)
11
+ access(all) event TokensInitialized(initialSupply: UFix64)
10
12
 
11
13
  // Event that is emitted when tokens are withdrawn from a Vault
12
- pub event TokensWithdrawn(amount: UFix64, from: Address?)
14
+ access(all) event TokensWithdrawn(amount: UFix64, from: Address?)
13
15
 
14
16
  // Event that is emitted when tokens are deposited to a Vault
15
- pub event TokensDeposited(amount: UFix64, to: Address?)
17
+ access(all) event TokensDeposited(amount: UFix64, to: Address?)
16
18
 
17
19
  // Event that is emitted when new tokens are minted
18
- pub event TokensMinted(amount: UFix64)
20
+ access(all) event TokensMinted(amount: UFix64)
19
21
 
20
22
  // Event that is emitted when tokens are destroyed
21
- pub event TokensBurned(amount: UFix64)
23
+ access(all) event TokensBurned(amount: UFix64)
22
24
 
23
25
  // Event that is emitted when a new minter resource is created
24
- pub event MinterCreated(allowedAmount: UFix64)
26
+ access(all) event MinterCreated(allowedAmount: UFix64)
25
27
 
26
28
  // Event that is emitted when a new burner resource is created
27
- pub event BurnerCreated()
29
+ access(all) event BurnerCreated()
28
30
 
29
31
  // Vault
30
32
  //
@@ -38,10 +40,10 @@ pub contract DapperUtilityCoin: FungibleToken {
38
40
  // out of thin air. A special Minter resource needs to be defined to mint
39
41
  // new tokens.
40
42
  //
41
- pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance {
43
+ access(all) resource Vault: FungibleToken.Vault {
42
44
 
43
45
  // holds the balance of a users tokens
44
- pub var balance: UFix64
46
+ access(all) var balance: UFix64
45
47
 
46
48
  // initialize the balance at resource creation time
47
49
  init(balance: UFix64) {
@@ -57,7 +59,7 @@ pub contract DapperUtilityCoin: FungibleToken {
57
59
  // created Vault to the context that called so it can be deposited
58
60
  // elsewhere.
59
61
  //
60
- pub fun withdraw(amount: UFix64): @FungibleToken.Vault {
62
+ access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
61
63
  self.balance = self.balance - amount
62
64
  emit TokensWithdrawn(amount: amount, from: self.owner?.address)
63
65
  return <-create Vault(balance: amount)
@@ -70,7 +72,7 @@ pub contract DapperUtilityCoin: FungibleToken {
70
72
  // It is allowed to destroy the sent Vault because the Vault
71
73
  // was a temporary holder of the tokens. The Vault's balance has
72
74
  // been consumed and therefore can be destroyed.
73
- pub fun deposit(from: @FungibleToken.Vault) {
75
+ access(all) fun deposit(from: @{FungibleToken.Vault}) {
74
76
  let vault <- from as! @DapperUtilityCoin.Vault
75
77
  self.balance = self.balance + vault.balance
76
78
  emit TokensDeposited(amount: vault.balance, to: self.owner?.address)
@@ -78,9 +80,33 @@ pub contract DapperUtilityCoin: FungibleToken {
78
80
  destroy vault
79
81
  }
80
82
 
81
- destroy() {
83
+ access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
84
+ return self.balance >= amount
85
+ }
86
+
87
+ access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
88
+ return {Type<@Vault>(): true}
89
+ }
90
+
91
+ access(all) view fun isSupportedVaultType(type: Type): Bool {
92
+ return type == Type<@Vault>()
93
+ }
94
+
95
+ access(contract) fun burnCallback() {
82
96
  DapperUtilityCoin.totalSupply = DapperUtilityCoin.totalSupply - self.balance
83
97
  }
98
+
99
+ access(all) fun createEmptyVault(): @{FungibleToken.Vault} {
100
+ return <- create Vault(balance: 0.0)
101
+ }
102
+
103
+ access(all) view fun getViews(): [Type]{
104
+ return DapperUtilityCoin.getContractViews(resourceType: nil)
105
+ }
106
+
107
+ access(all) fun resolveView(_ view: Type): AnyStruct? {
108
+ return DapperUtilityCoin.resolveContractView(resourceType: nil, viewType: view)
109
+ }
84
110
  }
85
111
 
86
112
  // createEmptyVault
@@ -90,16 +116,16 @@ pub contract DapperUtilityCoin: FungibleToken {
90
116
  // and store the returned Vault in their storage in order to allow their
91
117
  // account to be able to receive deposits of this token type.
92
118
  //
93
- pub fun createEmptyVault(): @FungibleToken.Vault {
119
+ access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
94
120
  return <-create Vault(balance: 0.0)
95
121
  }
96
122
 
97
- pub resource Administrator {
123
+ access(all) resource Administrator {
98
124
  // createNewMinter
99
125
  //
100
126
  // Function that creates and returns a new minter resource
101
127
  //
102
- pub fun createNewMinter(allowedAmount: UFix64): @Minter {
128
+ access(all) fun createNewMinter(allowedAmount: UFix64): @Minter {
103
129
  emit MinterCreated(allowedAmount: allowedAmount)
104
130
  return <-create Minter(allowedAmount: allowedAmount)
105
131
  }
@@ -108,7 +134,7 @@ pub contract DapperUtilityCoin: FungibleToken {
108
134
  //
109
135
  // Function that creates and returns a new burner resource
110
136
  //
111
- pub fun createNewBurner(): @Burner {
137
+ access(all) fun createNewBurner(): @Burner {
112
138
  emit BurnerCreated()
113
139
  return <-create Burner()
114
140
  }
@@ -118,19 +144,19 @@ pub contract DapperUtilityCoin: FungibleToken {
118
144
  //
119
145
  // Resource object that token admin accounts can hold to mint new tokens.
120
146
  //
121
- pub resource Minter {
147
+ access(all) resource Minter {
122
148
 
123
149
  // the amount of tokens that the minter is allowed to mint
124
- pub var allowedAmount: UFix64
150
+ access(all) var allowedAmount: UFix64
125
151
 
126
152
  // mintTokens
127
153
  //
128
154
  // Function that mints new tokens, adds them to the total supply,
129
155
  // and returns them to the calling context.
130
156
  //
131
- pub fun mintTokens(amount: UFix64): @DapperUtilityCoin.Vault {
157
+ access(all) fun mintTokens(amount: UFix64): @DapperUtilityCoin.Vault {
132
158
  pre {
133
- amount > UFix64(0): "Amount minted must be greater than zero"
159
+ amount > 0.0: "Amount minted must be greater than zero"
134
160
  amount <= self.allowedAmount: "Amount minted must be less than the allowed amount"
135
161
  }
136
162
  DapperUtilityCoin.totalSupply = DapperUtilityCoin.totalSupply + amount
@@ -148,7 +174,7 @@ pub contract DapperUtilityCoin: FungibleToken {
148
174
  //
149
175
  // Resource object that token admin accounts can hold to burn tokens.
150
176
  //
151
- pub resource Burner {
177
+ access(all) resource Burner {
152
178
 
153
179
  // burnTokens
154
180
  //
@@ -157,7 +183,7 @@ pub contract DapperUtilityCoin: FungibleToken {
157
183
  // Note: the burned tokens are automatically subtracted from the
158
184
  // total supply in the Vault destructor.
159
185
  //
160
- pub fun burnTokens(from: @FungibleToken.Vault) {
186
+ access(all) fun burnTokens(from: @{FungibleToken.Vault}) {
161
187
  let vault <- from as! @DapperUtilityCoin.Vault
162
188
  let amount = vault.balance
163
189
  destroy vault
@@ -165,6 +191,57 @@ pub contract DapperUtilityCoin: FungibleToken {
165
191
  }
166
192
  }
167
193
 
194
+ access(all) view fun getContractViews(resourceType: Type?): [Type] {
195
+ return [Type<FungibleTokenMetadataViews.FTView>(),
196
+ Type<FungibleTokenMetadataViews.FTDisplay>(),
197
+ Type<FungibleTokenMetadataViews.FTVaultData>(),
198
+ Type<FungibleTokenMetadataViews.TotalSupply>()]
199
+ }
200
+
201
+ access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
202
+ switch viewType {
203
+ case Type<FungibleTokenMetadataViews.FTView>():
204
+ return FungibleTokenMetadataViews.FTView(
205
+ ftDisplay: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTDisplay>()) as! FungibleTokenMetadataViews.FTDisplay?,
206
+ ftVaultData: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
207
+ )
208
+ case Type<FungibleTokenMetadataViews.FTDisplay>():
209
+ let media = MetadataViews.Media(
210
+ file: MetadataViews.HTTPFile(
211
+ url: "https://meetdapper.com/"
212
+ ),
213
+ mediaType: "image/svg+xml"
214
+ )
215
+ let medias = MetadataViews.Medias([media])
216
+ return FungibleTokenMetadataViews.FTDisplay(
217
+ name: "Dapper Utility Coin",
218
+ symbol: "DUC",
219
+ description: "",
220
+ externalURL: MetadataViews.ExternalURL("https://meetdapper.com/"),
221
+ logos: medias,
222
+ socials: {
223
+ "twitter": MetadataViews.ExternalURL("https://twitter.com/hellodapper")
224
+ }
225
+ )
226
+ case Type<FungibleTokenMetadataViews.FTVaultData>():
227
+ let vaultRef = DapperUtilityCoin.account.storage.borrow<auth(FungibleToken.Withdraw) &DapperUtilityCoin.Vault>(from: /storage/dapperUtilityCoinVault)
228
+ ?? panic("Could not borrow reference to the contract's Vault!")
229
+ return FungibleTokenMetadataViews.FTVaultData(
230
+ storagePath: /storage/dapperUtilityCoinVault,
231
+ receiverPath: /public/exampleTokenReceiver,
232
+ metadataPath: /public/dapperUtilityCoinBalance,
233
+ receiverLinkedType: Type<&{FungibleToken.Receiver, FungibleToken.Vault}>(),
234
+ metadataLinkedType: Type<&{FungibleToken.Balance, FungibleToken.Vault}>(),
235
+ createEmptyVaultFunction: (fun (): @{FungibleToken.Vault} {
236
+ return <-vaultRef.createEmptyVault()
237
+ })
238
+ )
239
+ case Type<FungibleTokenMetadataViews.TotalSupply>():
240
+ return FungibleTokenMetadataViews.TotalSupply(totalSupply: DapperUtilityCoin.totalSupply)
241
+ }
242
+ return nil
243
+ }
244
+
168
245
  init() {
169
246
  // we're using a high value as the balance here to make it look like we've got a ton of money,
170
247
  // just in case some contract manually checks that our balance is sufficient to pay for stuff
@@ -172,26 +249,16 @@ pub contract DapperUtilityCoin: FungibleToken {
172
249
 
173
250
  let admin <- create Administrator()
174
251
  let minter <- admin.createNewMinter(allowedAmount: self.totalSupply)
175
- self.account.save(<-admin, to: /storage/dapperUtilityCoinAdmin)
252
+ self.account.storage.save(<-admin, to: /storage/dapperUtilityCoinAdmin)
176
253
 
177
254
  // mint tokens
178
255
  let tokenVault <- minter.mintTokens(amount: self.totalSupply)
179
- self.account.save(<-tokenVault, to: /storage/dapperUtilityCoinVault)
256
+ self.account.storage.save(<-tokenVault, to: /storage/dapperUtilityCoinVault)
180
257
  destroy minter
181
258
 
182
- // Create a public capability to the stored Vault that only exposes
183
- // the balance field through the Balance interface
184
- self.account.link<&DapperUtilityCoin.Vault{FungibleToken.Balance}>(
185
- /public/dapperUtilityCoinBalance,
186
- target: /storage/dapperUtilityCoinVault
187
- )
188
-
189
- // Create a public capability to the stored Vault that only exposes
190
- // the deposit method through the Receiver interface
191
- self.account.link<&{FungibleToken.Receiver}>(
192
- /public/dapperUtilityCoinReceiver,
193
- target: /storage/dapperUtilityCoinVault
194
- )
259
+ let cap = self.account.capabilities.storage.issue<&DapperUtilityCoin.Vault>(/storage/dapperUtilityCoinVault)
260
+ self.account.capabilities.publish(cap, at: /public/dapperUtilityCoinBalance)
261
+ self.account.capabilities.publish(cap, at: /public/dapperUtilityCoinReceiver)
195
262
 
196
263
  // Emit an event that shows that the contract was initialized
197
264
  emit TokensInitialized(initialSupply: self.totalSupply)
@@ -1,30 +1,32 @@
1
1
  import "FungibleToken"
2
+ import "MetadataViews"
3
+ import "FungibleTokenMetadataViews"
2
4
 
3
- pub contract FlowUtilityToken: FungibleToken {
5
+ access(all) contract FlowUtilityToken: FungibleToken {
4
6
 
5
- // Total supply of DapperUtilityCoins in existence
6
- pub var totalSupply: UFix64
7
+ // Total supply of FlowUtilityTokens in existence
8
+ access(all) var totalSupply: UFix64
7
9
 
8
10
  // Event that is emitted when the contract is created
9
- pub event TokensInitialized(initialSupply: UFix64)
11
+ access(all) event TokensInitialized(initialSupply: UFix64)
10
12
 
11
13
  // Event that is emitted when tokens are withdrawn from a Vault
12
- pub event TokensWithdrawn(amount: UFix64, from: Address?)
14
+ access(all) event TokensWithdrawn(amount: UFix64, from: Address?)
13
15
 
14
16
  // Event that is emitted when tokens are deposited to a Vault
15
- pub event TokensDeposited(amount: UFix64, to: Address?)
17
+ access(all) event TokensDeposited(amount: UFix64, to: Address?)
16
18
 
17
19
  // Event that is emitted when new tokens are minted
18
- pub event TokensMinted(amount: UFix64)
20
+ access(all) event TokensMinted(amount: UFix64)
19
21
 
20
22
  // Event that is emitted when tokens are destroyed
21
- pub event TokensBurned(amount: UFix64)
23
+ access(all) event TokensBurned(amount: UFix64)
22
24
 
23
25
  // Event that is emitted when a new minter resource is created
24
- pub event MinterCreated(allowedAmount: UFix64)
26
+ access(all) event MinterCreated(allowedAmount: UFix64)
25
27
 
26
28
  // Event that is emitted when a new burner resource is created
27
- pub event BurnerCreated()
29
+ access(all) event BurnerCreated()
28
30
 
29
31
  // Vault
30
32
  //
@@ -38,10 +40,10 @@ pub contract FlowUtilityToken: FungibleToken {
38
40
  // out of thin air. A special Minter resource needs to be defined to mint
39
41
  // new tokens.
40
42
  //
41
- pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance {
43
+ access(all) resource Vault: FungibleToken.Vault {
42
44
 
43
45
  // holds the balance of a users tokens
44
- pub var balance: UFix64
46
+ access(all) var balance: UFix64
45
47
 
46
48
  // initialize the balance at resource creation time
47
49
  init(balance: UFix64) {
@@ -57,7 +59,7 @@ pub contract FlowUtilityToken: FungibleToken {
57
59
  // created Vault to the context that called so it can be deposited
58
60
  // elsewhere.
59
61
  //
60
- pub fun withdraw(amount: UFix64): @FungibleToken.Vault {
62
+ access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
61
63
  self.balance = self.balance - amount
62
64
  emit TokensWithdrawn(amount: amount, from: self.owner?.address)
63
65
  return <-create Vault(balance: amount)
@@ -70,17 +72,41 @@ pub contract FlowUtilityToken: FungibleToken {
70
72
  // It is allowed to destroy the sent Vault because the Vault
71
73
  // was a temporary holder of the tokens. The Vault's balance has
72
74
  // been consumed and therefore can be destroyed.
73
- pub fun deposit(from: @FungibleToken.Vault) {
75
+ access(all) fun deposit(from: @{FungibleToken.Vault}) {
74
76
  let vault <- from as! @FlowUtilityToken.Vault
75
77
  self.balance = self.balance + vault.balance
76
78
  emit TokensDeposited(amount: vault.balance, to: self.owner?.address)
77
79
  vault.balance = 0.0
78
80
  destroy vault
79
81
  }
82
+
83
+ access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
84
+ return self.balance >= amount
85
+ }
86
+
87
+ access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
88
+ return {Type<@Vault>(): true}
89
+ }
90
+
91
+ access(all) view fun isSupportedVaultType(type: Type): Bool {
92
+ return type == Type<@Vault>()
93
+ }
80
94
 
81
- destroy() {
95
+ access(contract) fun burnCallback() {
82
96
  FlowUtilityToken.totalSupply = FlowUtilityToken.totalSupply - self.balance
83
97
  }
98
+
99
+ access(all) fun createEmptyVault(): @{FungibleToken.Vault} {
100
+ return <- create Vault(balance: 0.0)
101
+ }
102
+
103
+ access(all) view fun getViews(): [Type]{
104
+ return FlowUtilityToken.getContractViews(resourceType: nil)
105
+ }
106
+
107
+ access(all) fun resolveView(_ view: Type): AnyStruct? {
108
+ return FlowUtilityToken.resolveContractView(resourceType: nil, viewType: view)
109
+ }
84
110
  }
85
111
 
86
112
  // createEmptyVault
@@ -90,16 +116,16 @@ pub contract FlowUtilityToken: FungibleToken {
90
116
  // and store the returned Vault in their storage in order to allow their
91
117
  // account to be able to receive deposits of this token type.
92
118
  //
93
- pub fun createEmptyVault(): @FungibleToken.Vault {
119
+ access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
94
120
  return <-create Vault(balance: 0.0)
95
121
  }
96
122
 
97
- pub resource Administrator {
123
+ access(all) resource Administrator {
98
124
  // createNewMinter
99
125
  //
100
126
  // Function that creates and returns a new minter resource
101
127
  //
102
- pub fun createNewMinter(allowedAmount: UFix64): @Minter {
128
+ access(all) fun createNewMinter(allowedAmount: UFix64): @Minter {
103
129
  emit MinterCreated(allowedAmount: allowedAmount)
104
130
  return <-create Minter(allowedAmount: allowedAmount)
105
131
  }
@@ -108,7 +134,7 @@ pub contract FlowUtilityToken: FungibleToken {
108
134
  //
109
135
  // Function that creates and returns a new burner resource
110
136
  //
111
- pub fun createNewBurner(): @Burner {
137
+ access(all) fun createNewBurner(): @Burner {
112
138
  emit BurnerCreated()
113
139
  return <-create Burner()
114
140
  }
@@ -118,19 +144,19 @@ pub contract FlowUtilityToken: FungibleToken {
118
144
  //
119
145
  // Resource object that token admin accounts can hold to mint new tokens.
120
146
  //
121
- pub resource Minter {
147
+ access(all) resource Minter {
122
148
 
123
149
  // the amount of tokens that the minter is allowed to mint
124
- pub var allowedAmount: UFix64
150
+ access(all) var allowedAmount: UFix64
125
151
 
126
152
  // mintTokens
127
153
  //
128
154
  // Function that mints new tokens, adds them to the total supply,
129
155
  // and returns them to the calling context.
130
156
  //
131
- pub fun mintTokens(amount: UFix64): @FlowUtilityToken.Vault {
157
+ access(all) fun mintTokens(amount: UFix64): @FlowUtilityToken.Vault {
132
158
  pre {
133
- amount > UFix64(0): "Amount minted must be greater than zero"
159
+ amount > 0.0: "Amount minted must be greater than zero"
134
160
  amount <= self.allowedAmount: "Amount minted must be less than the allowed amount"
135
161
  }
136
162
  FlowUtilityToken.totalSupply = FlowUtilityToken.totalSupply + amount
@@ -148,7 +174,7 @@ pub contract FlowUtilityToken: FungibleToken {
148
174
  //
149
175
  // Resource object that token admin accounts can hold to burn tokens.
150
176
  //
151
- pub resource Burner {
177
+ access(all) resource Burner {
152
178
 
153
179
  // burnTokens
154
180
  //
@@ -157,7 +183,7 @@ pub contract FlowUtilityToken: FungibleToken {
157
183
  // Note: the burned tokens are automatically subtracted from the
158
184
  // total supply in the Vault destructor.
159
185
  //
160
- pub fun burnTokens(from: @FungibleToken.Vault) {
186
+ access(all) fun burnTokens(from: @{FungibleToken.Vault}) {
161
187
  let vault <- from as! @FlowUtilityToken.Vault
162
188
  let amount = vault.balance
163
189
  destroy vault
@@ -165,6 +191,57 @@ pub contract FlowUtilityToken: FungibleToken {
165
191
  }
166
192
  }
167
193
 
194
+ access(all) view fun getContractViews(resourceType: Type?): [Type] {
195
+ return [Type<FungibleTokenMetadataViews.FTView>(),
196
+ Type<FungibleTokenMetadataViews.FTDisplay>(),
197
+ Type<FungibleTokenMetadataViews.FTVaultData>(),
198
+ Type<FungibleTokenMetadataViews.TotalSupply>()]
199
+ }
200
+
201
+ access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
202
+ switch viewType {
203
+ case Type<FungibleTokenMetadataViews.FTView>():
204
+ return FungibleTokenMetadataViews.FTView(
205
+ ftDisplay: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTDisplay>()) as! FungibleTokenMetadataViews.FTDisplay?,
206
+ ftVaultData: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
207
+ )
208
+ case Type<FungibleTokenMetadataViews.FTDisplay>():
209
+ let media = MetadataViews.Media(
210
+ file: MetadataViews.HTTPFile(
211
+ url: "https://meetdapper.com/"
212
+ ),
213
+ mediaType: "image/svg+xml"
214
+ )
215
+ let medias = MetadataViews.Medias([media])
216
+ return FungibleTokenMetadataViews.FTDisplay(
217
+ name: "Dapper Utility Coin",
218
+ symbol: "DUC",
219
+ description: "",
220
+ externalURL: MetadataViews.ExternalURL("https://meetdapper.com/"),
221
+ logos: medias,
222
+ socials: {
223
+ "twitter": MetadataViews.ExternalURL("https://twitter.com/hellodapper")
224
+ }
225
+ )
226
+ case Type<FungibleTokenMetadataViews.FTVaultData>():
227
+ let vaultRef = FlowUtilityToken.account.storage.borrow<auth(FungibleToken.Withdraw) &FlowUtilityToken.Vault>(from: /storage/flowUtilityTokenVault)
228
+ ?? panic("Could not borrow reference to the contract's Vault!")
229
+ return FungibleTokenMetadataViews.FTVaultData(
230
+ storagePath: /storage/flowUtilityTokenVault,
231
+ receiverPath: /public/exampleTokenReceiver,
232
+ metadataPath: /public/flowUtilityTokenBalance,
233
+ receiverLinkedType: Type<&{FungibleToken.Receiver, FungibleToken.Vault}>(),
234
+ metadataLinkedType: Type<&{FungibleToken.Balance, FungibleToken.Vault}>(),
235
+ createEmptyVaultFunction: (fun (): @{FungibleToken.Vault} {
236
+ return <-vaultRef.createEmptyVault()
237
+ })
238
+ )
239
+ case Type<FungibleTokenMetadataViews.TotalSupply>():
240
+ return FungibleTokenMetadataViews.TotalSupply(totalSupply: FlowUtilityToken.totalSupply)
241
+ }
242
+ return nil
243
+ }
244
+
168
245
  init() {
169
246
  // we're using a high value as the balance here to make it look like we've got a ton of money,
170
247
  // just in case some contract manually checks that our balance is sufficient to pay for stuff
@@ -172,26 +249,16 @@ pub contract FlowUtilityToken: FungibleToken {
172
249
 
173
250
  let admin <- create Administrator()
174
251
  let minter <- admin.createNewMinter(allowedAmount: self.totalSupply)
175
- self.account.save(<-admin, to: /storage/flowUtilityTokenAdmin)
252
+ self.account.storage.save(<-admin, to: /storage/flowUtilityTokenAdmin)
176
253
 
177
254
  // mint tokens
178
255
  let tokenVault <- minter.mintTokens(amount: self.totalSupply)
179
- self.account.save(<-tokenVault, to: /storage/flowUtilityTokenVault)
256
+ self.account.storage.save(<-tokenVault, to: /storage/flowUtilityTokenVault)
180
257
  destroy minter
181
258
 
182
- // Create a public capability to the stored Vault that only exposes
183
- // the balance field through the Balance interface
184
- self.account.link<&FlowUtilityToken.Vault{FungibleToken.Balance}>(
185
- /public/flowUtilityTokenBalance,
186
- target: /storage/flowUtilityTokenVault
187
- )
188
-
189
- // Create a public capability to the stored Vault that only exposes
190
- // the deposit method through the Receiver interface
191
- self.account.link<&{FungibleToken.Receiver}>(
192
- /public/flowUtilityTokenReceiver,
193
- target: /storage/flowUtilityTokenVault
194
- )
259
+ let cap = self.account.capabilities.storage.issue<&FlowUtilityToken.Vault>(/storage/flowUtilityTokenVault)
260
+ self.account.capabilities.publish(cap, at: /public/flowUtilityTokenBalance)
261
+ self.account.capabilities.publish(cap, at: /public/flowUtilityTokenReceiver)
195
262
 
196
263
  // Emit an event that shows that the contract was initialized
197
264
  emit TokensInitialized(initialSupply: self.totalSupply)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.8",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",