@flowtyio/flow-contracts 0.1.0-beta.6 → 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.
- package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
- package/contracts/dapper/FlowUtilityToken.cdc +107 -40
- package/contracts/flow-utils/AddressUtils.cdc +1 -1
- package/contracts/flow-utils/ArrayUtils.cdc +50 -102
- package/contracts/flow-utils/ScopedFTProviders.cdc +24 -19
- package/contracts/flow-utils/ScopedNFTProviders.cdc +4 -3
- package/contracts/flow-utils/StringUtils.cdc +1 -1
- package/contracts/lost-and-found/LostAndFound.cdc +8 -8
- package/package.json +1 -1
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import "FungibleToken"
|
|
2
|
+
import "MetadataViews"
|
|
3
|
+
import "FungibleTokenMetadataViews"
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
access(all) contract DapperUtilityCoin: FungibleToken {
|
|
4
6
|
|
|
5
7
|
// Total supply of DapperUtilityCoins in existence
|
|
6
|
-
|
|
8
|
+
access(all) var totalSupply: UFix64
|
|
7
9
|
|
|
8
10
|
// Event that is emitted when the contract is created
|
|
9
|
-
|
|
11
|
+
access(all) event TokensInitialized(initialSupply: UFix64)
|
|
10
12
|
|
|
11
13
|
// Event that is emitted when tokens are withdrawn from a Vault
|
|
12
|
-
|
|
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
|
-
|
|
17
|
+
access(all) event TokensDeposited(amount: UFix64, to: Address?)
|
|
16
18
|
|
|
17
19
|
// Event that is emitted when new tokens are minted
|
|
18
|
-
|
|
20
|
+
access(all) event TokensMinted(amount: UFix64)
|
|
19
21
|
|
|
20
22
|
// Event that is emitted when tokens are destroyed
|
|
21
|
-
|
|
23
|
+
access(all) event TokensBurned(amount: UFix64)
|
|
22
24
|
|
|
23
25
|
// Event that is emitted when a new minter resource is created
|
|
24
|
-
|
|
26
|
+
access(all) event MinterCreated(allowedAmount: UFix64)
|
|
25
27
|
|
|
26
28
|
// Event that is emitted when a new burner resource is created
|
|
27
|
-
|
|
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
|
-
|
|
43
|
+
access(all) resource Vault: FungibleToken.Vault {
|
|
42
44
|
|
|
43
45
|
// holds the balance of a users tokens
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
119
|
+
access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
|
|
94
120
|
return <-create Vault(balance: 0.0)
|
|
95
121
|
}
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
access(all) resource Administrator {
|
|
98
124
|
// createNewMinter
|
|
99
125
|
//
|
|
100
126
|
// Function that creates and returns a new minter resource
|
|
101
127
|
//
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
+
access(all) resource Minter {
|
|
122
148
|
|
|
123
149
|
// the amount of tokens that the minter is allowed to mint
|
|
124
|
-
|
|
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
|
-
|
|
157
|
+
access(all) fun mintTokens(amount: UFix64): @DapperUtilityCoin.Vault {
|
|
132
158
|
pre {
|
|
133
|
-
amount >
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
self.account.
|
|
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
|
-
|
|
5
|
+
access(all) contract FlowUtilityToken: FungibleToken {
|
|
4
6
|
|
|
5
|
-
// Total supply of
|
|
6
|
-
|
|
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
|
-
|
|
11
|
+
access(all) event TokensInitialized(initialSupply: UFix64)
|
|
10
12
|
|
|
11
13
|
// Event that is emitted when tokens are withdrawn from a Vault
|
|
12
|
-
|
|
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
|
-
|
|
17
|
+
access(all) event TokensDeposited(amount: UFix64, to: Address?)
|
|
16
18
|
|
|
17
19
|
// Event that is emitted when new tokens are minted
|
|
18
|
-
|
|
20
|
+
access(all) event TokensMinted(amount: UFix64)
|
|
19
21
|
|
|
20
22
|
// Event that is emitted when tokens are destroyed
|
|
21
|
-
|
|
23
|
+
access(all) event TokensBurned(amount: UFix64)
|
|
22
24
|
|
|
23
25
|
// Event that is emitted when a new minter resource is created
|
|
24
|
-
|
|
26
|
+
access(all) event MinterCreated(allowedAmount: UFix64)
|
|
25
27
|
|
|
26
28
|
// Event that is emitted when a new burner resource is created
|
|
27
|
-
|
|
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
|
-
|
|
43
|
+
access(all) resource Vault: FungibleToken.Vault {
|
|
42
44
|
|
|
43
45
|
// holds the balance of a users tokens
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
119
|
+
access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
|
|
94
120
|
return <-create Vault(balance: 0.0)
|
|
95
121
|
}
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
access(all) resource Administrator {
|
|
98
124
|
// createNewMinter
|
|
99
125
|
//
|
|
100
126
|
// Function that creates and returns a new minter resource
|
|
101
127
|
//
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
+
access(all) resource Minter {
|
|
122
148
|
|
|
123
149
|
// the amount of tokens that the minter is allowed to mint
|
|
124
|
-
|
|
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
|
-
|
|
157
|
+
access(all) fun mintTokens(amount: UFix64): @FlowUtilityToken.Vault {
|
|
132
158
|
pre {
|
|
133
|
-
amount >
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
self.account.
|
|
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)
|
|
@@ -1,120 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// ScopedProviders are meant to solve the issue of unbounded access FungibleToken vaults
|
|
10
|
-
// when a provider is called for.
|
|
11
|
-
access(all) contract ScopedFTProviders {
|
|
12
|
-
access(all) struct interface FTFilter {
|
|
13
|
-
access(all) fun canWithdrawAmount(_ amount: UFix64): Bool
|
|
14
|
-
access(FungibleToken.Withdraw) fun markAmountWithdrawn(_ amount: UFix64)
|
|
15
|
-
access(all) fun getDetails(): {String: AnyStruct}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
access(all) struct AllowanceFilter: FTFilter {
|
|
19
|
-
access(self) let allowance: UFix64
|
|
20
|
-
access(self) var allowanceUsed: UFix64
|
|
21
|
-
|
|
22
|
-
init(_ allowance: UFix64) {
|
|
23
|
-
self.allowance = allowance
|
|
24
|
-
self.allowanceUsed = 0.0
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
access(all) fun canWithdrawAmount(_ amount: UFix64): Bool {
|
|
28
|
-
return amount + self.allowanceUsed <= self.allowance
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
access(FungibleToken.Withdraw) fun markAmountWithdrawn(_ amount: UFix64) {
|
|
32
|
-
self.allowanceUsed = self.allowanceUsed + amount
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
access(all) fun getDetails(): {String: AnyStruct} {
|
|
36
|
-
return {
|
|
37
|
-
"allowance": self.allowance,
|
|
38
|
-
"allowanceUsed": self.allowanceUsed
|
|
39
|
-
}
|
|
1
|
+
// Copied from https://github.com/bluesign/flow-utils/blob/dnz/cadence/contracts/ArrayUtils.cdc with minor adjustments
|
|
2
|
+
|
|
3
|
+
access(all) contract ArrayUtils {
|
|
4
|
+
access(all) fun rangeFunc(_ start: Int, _ end: Int, _ f: fun (Int): Void) {
|
|
5
|
+
var current = start
|
|
6
|
+
while current < end {
|
|
7
|
+
f(current)
|
|
8
|
+
current = current + 1
|
|
40
9
|
}
|
|
41
10
|
}
|
|
42
11
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// block timestamp that this provider can no longer be used after
|
|
52
|
-
access(self) let expiration: UFix64?
|
|
12
|
+
access(all) fun range(_ start: Int, _ end: Int): [Int] {
|
|
13
|
+
var res: [Int] = []
|
|
14
|
+
self.rangeFunc(start, end, fun (i: Int) {
|
|
15
|
+
res.append(i)
|
|
16
|
+
})
|
|
17
|
+
return res
|
|
18
|
+
}
|
|
53
19
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
20
|
+
access(all) fun reverse(_ array: [Int]): [Int] {
|
|
21
|
+
var res: [Int] = []
|
|
22
|
+
var i: Int = array.length - 1
|
|
23
|
+
while i >= 0 {
|
|
24
|
+
res.append(array[i])
|
|
25
|
+
i = i - 1
|
|
58
26
|
}
|
|
27
|
+
return res
|
|
28
|
+
}
|
|
59
29
|
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
access(all) fun transform(_ array: auth(Mutate) &[AnyStruct], _ f : fun (&AnyStruct, auth(Mutate) &[AnyStruct], Int)){
|
|
31
|
+
for i in self.range(0, array.length){
|
|
32
|
+
f(array[i], array, i)
|
|
62
33
|
}
|
|
34
|
+
}
|
|
63
35
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
36
|
+
access(all) fun iterate(_ array: [AnyStruct], _ f : fun (AnyStruct): Bool) {
|
|
37
|
+
for item in array{
|
|
38
|
+
if !f(item){
|
|
39
|
+
break
|
|
67
40
|
}
|
|
68
|
-
return false
|
|
69
41
|
}
|
|
42
|
+
}
|
|
70
43
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for filter in self.filters {
|
|
77
|
-
if !filter.canWithdrawAmount(amount) {
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return true
|
|
44
|
+
access(all) fun map(_ array: [AnyStruct], _ f : fun (AnyStruct): AnyStruct) : [AnyStruct] {
|
|
45
|
+
var res : [AnyStruct] = []
|
|
46
|
+
for item in array{
|
|
47
|
+
res.append(f(item))
|
|
83
48
|
}
|
|
49
|
+
return res
|
|
50
|
+
}
|
|
84
51
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var i = 0
|
|
91
|
-
while i < self.filters.length {
|
|
92
|
-
if !self.filters[i].canWithdrawAmount(amount) {
|
|
93
|
-
panic(StringUtils.join(["cannot withdraw tokens. filter of type", self.filters[i].getType().identifier, "failed."], " "))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
self.filters[i].markAmountWithdrawn(amount)
|
|
97
|
-
i = i + 1
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return <-self.provider.borrow()!.withdraw(amount: amount)
|
|
52
|
+
access(all) fun mapStrings(_ array: [String], _ f: fun (String) : String) : [String] {
|
|
53
|
+
var res : [String] = []
|
|
54
|
+
for item in array{
|
|
55
|
+
res.append(f(item))
|
|
101
56
|
}
|
|
57
|
+
return res
|
|
58
|
+
}
|
|
102
59
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return details
|
|
60
|
+
access(all) fun reduce(_ array: [AnyStruct], _ initial: AnyStruct, _ f : fun (AnyStruct, AnyStruct): AnyStruct) : AnyStruct{
|
|
61
|
+
var res: AnyStruct = f(initial, array[0])
|
|
62
|
+
for i in self.range(1, array.length){
|
|
63
|
+
res = f(res, array[i])
|
|
110
64
|
}
|
|
65
|
+
return res
|
|
111
66
|
}
|
|
112
67
|
|
|
113
|
-
|
|
114
|
-
provider: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>,
|
|
115
|
-
filters: [{FTFilter}],
|
|
116
|
-
expiration: UFix64?
|
|
117
|
-
): @ScopedFTProvider {
|
|
118
|
-
return <- create ScopedFTProvider(provider: provider, filters: filters, expiration: expiration)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
68
|
+
}
|
|
@@ -8,14 +8,14 @@ import "StringUtils"
|
|
|
8
8
|
//
|
|
9
9
|
// ScopedProviders are meant to solve the issue of unbounded access FungibleToken vaults
|
|
10
10
|
// when a provider is called for.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
access(all) contract ScopedFTProviders {
|
|
12
|
+
access(all) struct interface FTFilter {
|
|
13
|
+
access(all) view fun canWithdrawAmount(_ amount: UFix64): Bool
|
|
14
|
+
access(FungibleToken.Withdraw) fun markAmountWithdrawn(_ amount: UFix64)
|
|
15
|
+
access(all) fun getDetails(): {String: AnyStruct}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
access(all) struct AllowanceFilter: FTFilter {
|
|
19
19
|
access(self) let allowance: UFix64
|
|
20
20
|
access(self) var allowanceUsed: UFix64
|
|
21
21
|
|
|
@@ -24,15 +24,15 @@ pub contract ScopedFTProviders {
|
|
|
24
24
|
self.allowanceUsed = 0.0
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
access(all) view fun canWithdrawAmount(_ amount: UFix64): Bool {
|
|
28
28
|
return amount + self.allowanceUsed <= self.allowance
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
access(FungibleToken.Withdraw) fun markAmountWithdrawn(_ amount: UFix64) {
|
|
32
32
|
self.allowanceUsed = self.allowanceUsed + amount
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
access(all) fun getDetails(): {String: AnyStruct} {
|
|
36
36
|
return {
|
|
37
37
|
"allowance": self.allowance,
|
|
38
38
|
"allowanceUsed": self.allowanceUsed
|
|
@@ -44,31 +44,31 @@ pub contract ScopedFTProviders {
|
|
|
44
44
|
//
|
|
45
45
|
// A ScopedFTProvider is a wrapped FungibleTokenProvider with
|
|
46
46
|
// filters that can be defined by anyone using the ScopedFTProvider.
|
|
47
|
-
|
|
48
|
-
access(self) let provider: Capability
|
|
47
|
+
access(all) resource ScopedFTProvider: FungibleToken.Provider {
|
|
48
|
+
access(self) let provider: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>
|
|
49
49
|
access(self) var filters: [{FTFilter}]
|
|
50
50
|
|
|
51
51
|
// block timestamp that this provider can no longer be used after
|
|
52
52
|
access(self) let expiration: UFix64?
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
access(all) init(provider: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>, filters: [{FTFilter}], expiration: UFix64?) {
|
|
55
55
|
self.provider = provider
|
|
56
56
|
self.filters = filters
|
|
57
57
|
self.expiration = expiration
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
access(all) fun check(): Bool {
|
|
61
61
|
return self.provider.check()
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
access(all) view fun isExpired(): Bool {
|
|
65
65
|
if let expiration = self.expiration {
|
|
66
66
|
return getCurrentBlock().timestamp >= expiration
|
|
67
67
|
}
|
|
68
68
|
return false
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
access(all) view fun canWithdraw(_ amount: UFix64): Bool {
|
|
72
72
|
if self.isExpired() {
|
|
73
73
|
return false
|
|
74
74
|
}
|
|
@@ -82,7 +82,11 @@ pub contract ScopedFTProviders {
|
|
|
82
82
|
return true
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
|
|
86
|
+
return self.canWithdraw(amount)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
access(FungibleToken.Withdraw | FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
|
|
86
90
|
pre {
|
|
87
91
|
!self.isExpired(): "provider has expired"
|
|
88
92
|
}
|
|
@@ -100,7 +104,7 @@ pub contract ScopedFTProviders {
|
|
|
100
104
|
return <-self.provider.borrow()!.withdraw(amount: amount)
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
access(all) fun getDetails(): [{String: AnyStruct}] {
|
|
104
108
|
let details: [{String: AnyStruct}] = []
|
|
105
109
|
for filter in self.filters {
|
|
106
110
|
details.append(filter.getDetails())
|
|
@@ -110,11 +114,12 @@ pub contract ScopedFTProviders {
|
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
provider: Capability
|
|
117
|
+
access(all) fun createScopedFTProvider(
|
|
118
|
+
provider: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>,
|
|
115
119
|
filters: [{FTFilter}],
|
|
116
120
|
expiration: UFix64?
|
|
117
121
|
): @ScopedFTProvider {
|
|
118
122
|
return <- create ScopedFTProvider(provider: provider, filters: filters, expiration: expiration)
|
|
119
123
|
}
|
|
120
124
|
}
|
|
125
|
+
|
|
@@ -32,11 +32,11 @@ access(all) contract ScopedNFTProviders {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
access(all) fun canWithdraw(_ nft: &{NonFungibleToken.NFT}): Bool {
|
|
35
|
-
return self.ids[nft.
|
|
35
|
+
return self.ids[nft.id] != nil && self.ids[nft.id] == true
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
access(NonFungibleToken.Withdraw) fun markWithdrawn(_ nft: &{NonFungibleToken.NFT}) {
|
|
39
|
-
self.ids[nft.
|
|
39
|
+
self.ids[nft.id] = false
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
access(all) fun getDetails(): {String: AnyStruct} {
|
|
@@ -121,7 +121,7 @@ access(all) contract ScopedNFTProviders {
|
|
|
121
121
|
return self.provider.check()
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
124
|
+
access(NonFungibleToken.Withdraw | NonFungibleToken.Owner) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
125
125
|
pre {
|
|
126
126
|
!self.isExpired(): "provider has expired"
|
|
127
127
|
}
|
|
@@ -160,3 +160,4 @@ access(all) contract ScopedNFTProviders {
|
|
|
160
160
|
return <- create ScopedNFTProvider(provider: provider, filters: filters, expiration: expiration)
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
+
|
|
@@ -125,7 +125,7 @@ access(all) contract LostAndFound {
|
|
|
125
125
|
if self.type.isSubtype(of: Type<@{NonFungibleToken.NFT}>()) {
|
|
126
126
|
let ref = (&self.item as &AnyResource?)!
|
|
127
127
|
let nft = ref as! &{NonFungibleToken.NFT}
|
|
128
|
-
return nft.
|
|
128
|
+
return nft.id
|
|
129
129
|
}
|
|
130
130
|
return nil
|
|
131
131
|
}
|
|
@@ -135,7 +135,7 @@ access(all) contract LostAndFound {
|
|
|
135
135
|
if self.type.isSubtype(of: Type<@{FungibleToken.Vault}>()) {
|
|
136
136
|
let ref = (&self.item as &AnyResource?)!
|
|
137
137
|
let ft = ref as! &{FungibleToken.Vault}
|
|
138
|
-
return ft.
|
|
138
|
+
return ft.balance
|
|
139
139
|
}
|
|
140
140
|
return nil
|
|
141
141
|
}
|
|
@@ -391,8 +391,8 @@ access(all) contract LostAndFound {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
access(contract) fun getFlowProvider(): auth(FungibleToken.
|
|
395
|
-
return self.account.storage.borrow<auth(FungibleToken.
|
|
394
|
+
access(contract) fun getFlowProvider(): auth(FungibleToken.Withdraw) &FlowToken.Vault {
|
|
395
|
+
return self.account.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)!
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
// ShelfManager is a light-weight wrapper to get our shelves into storage.
|
|
@@ -422,7 +422,7 @@ access(all) contract LostAndFound {
|
|
|
422
422
|
item: @AnyResource,
|
|
423
423
|
memo: String?,
|
|
424
424
|
display: MetadataViews.Display?,
|
|
425
|
-
storagePayment: auth(FungibleToken.
|
|
425
|
+
storagePayment: auth(FungibleToken.Withdraw) &{FungibleToken.Vault},
|
|
426
426
|
flowTokenRepayment: Capability<&FlowToken.Vault>?
|
|
427
427
|
) : UInt64 {
|
|
428
428
|
pre {
|
|
@@ -598,7 +598,7 @@ access(all) contract LostAndFound {
|
|
|
598
598
|
init(_ flowTokenRepayment: Capability<&FlowToken.Vault>, lowBalanceThreshold: UFix64?) {
|
|
599
599
|
self.flowTokenRepayment = flowTokenRepayment
|
|
600
600
|
|
|
601
|
-
let vault <- FlowToken.createEmptyVault()
|
|
601
|
+
let vault <- FlowToken.createEmptyVault(vaultType: Type<@FlowToken.Vault>())
|
|
602
602
|
self.flowTokenVault <- vault
|
|
603
603
|
self.lowBalanceThreshold = lowBalanceThreshold
|
|
604
604
|
}
|
|
@@ -713,7 +713,7 @@ access(all) contract LostAndFound {
|
|
|
713
713
|
item: @AnyResource,
|
|
714
714
|
memo: String?,
|
|
715
715
|
display: MetadataViews.Display?,
|
|
716
|
-
storagePayment: auth(FungibleToken.
|
|
716
|
+
storagePayment: auth(FungibleToken.Withdraw) &{FungibleToken.Vault},
|
|
717
717
|
flowTokenRepayment: Capability<&FlowToken.Vault>?
|
|
718
718
|
) : UInt64 {
|
|
719
719
|
pre {
|
|
@@ -730,7 +730,7 @@ access(all) contract LostAndFound {
|
|
|
730
730
|
cap: Capability,
|
|
731
731
|
memo: String?,
|
|
732
732
|
display: MetadataViews.Display?,
|
|
733
|
-
storagePayment: auth(FungibleToken.
|
|
733
|
+
storagePayment: auth(FungibleToken.Withdraw) &{FungibleToken.Vault},
|
|
734
734
|
flowTokenRepayment: Capability<&FlowToken.Vault>
|
|
735
735
|
) {
|
|
736
736
|
if cap.check<&{NonFungibleToken.Collection}>() {
|