@flowtyio/flow-contracts 0.0.18 → 0.1.0-beta.10
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 +37 -39
- package/contracts/FlowToken.cdc +77 -89
- package/contracts/FungibleToken.cdc +121 -130
- package/contracts/FungibleTokenMetadataViews.cdc +38 -41
- package/contracts/MetadataViews.cdc +356 -390
- package/contracts/NonFungibleToken.cdc +149 -117
- package/contracts/TokenForwarding.cdc +19 -11
- package/contracts/ViewResolver.cdc +41 -8
- package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
- package/contracts/dapper/FlowUtilityToken.cdc +107 -40
- package/contracts/example/ExampleNFT.cdc +419 -0
- package/contracts/example/ExampleToken.cdc +302 -0
- package/contracts/flow-utils/AddressUtils.cdc +20 -23
- package/contracts/flow-utils/ArrayUtils.cdc +10 -11
- package/contracts/flow-utils/ScopedFTProviders.cdc +24 -19
- package/contracts/flow-utils/ScopedNFTProviders.cdc +27 -26
- package/contracts/flow-utils/StringUtils.cdc +24 -37
- package/contracts/lost-and-found/FeeEstimator.cdc +14 -22
- package/contracts/lost-and-found/LostAndFound.cdc +180 -172
- package/contracts/lost-and-found/LostAndFoundHelper.cdc +12 -12
- package/contracts/nft-catalog/NFTCatalog.cdc +60 -64
- package/contracts/nft-catalog/NFTCatalogAdmin.cdc +28 -27
- package/flow.json +27 -1
- package/package.json +1 -1
|
@@ -11,14 +11,14 @@ import "StringUtils"
|
|
|
11
11
|
//
|
|
12
12
|
// By using a scoped provider, only a subset of assets can be taken if the provider leaks
|
|
13
13
|
// instead of the entire nft collection.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
access(all) contract ScopedNFTProviders {
|
|
15
|
+
access(all) struct interface NFTFilter {
|
|
16
|
+
access(all) fun canWithdraw(_ nft: &{NonFungibleToken.NFT}): Bool
|
|
17
|
+
access(NonFungibleToken.Withdraw) fun markWithdrawn(_ nft: &{NonFungibleToken.NFT})
|
|
18
|
+
access(all) fun getDetails(): {String: AnyStruct}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
access(all) struct NFTIDFilter: NFTFilter {
|
|
22
22
|
// the ids that are allowed to be withdrawn.
|
|
23
23
|
// If ids[num] is false, the id cannot be withdrawn anymore
|
|
24
24
|
access(self) let ids: {UInt64: Bool}
|
|
@@ -31,22 +31,22 @@ pub contract ScopedNFTProviders {
|
|
|
31
31
|
self.ids = d
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
access(all) fun canWithdraw(_ nft: &{NonFungibleToken.NFT}): Bool {
|
|
35
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
39
|
self.ids[nft.id] = false
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
access(all) fun getDetails(): {String: AnyStruct} {
|
|
43
43
|
return {
|
|
44
44
|
"ids": self.ids
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
access(all) struct UUIDFilter: NFTFilter {
|
|
50
50
|
// the ids that are allowed to be withdrawn.
|
|
51
51
|
// If ids[num] is false, the id cannot be withdrawn anymore
|
|
52
52
|
access(self) let uuids: {UInt64: Bool}
|
|
@@ -59,15 +59,15 @@ pub contract ScopedNFTProviders {
|
|
|
59
59
|
self.uuids = d
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
access(all) fun canWithdraw(_ nft: &{NonFungibleToken.NFT}): Bool {
|
|
63
63
|
return self.uuids[nft.uuid] != nil && self.uuids[nft.uuid]! == true
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
access(NonFungibleToken.Withdraw) fun markWithdrawn(_ nft: &{NonFungibleToken.NFT}) {
|
|
67
67
|
self.uuids[nft.uuid] = false
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
access(all) fun getDetails(): {String: AnyStruct} {
|
|
71
71
|
return {
|
|
72
72
|
"uuids": self.uuids
|
|
73
73
|
}
|
|
@@ -77,39 +77,39 @@ pub contract ScopedNFTProviders {
|
|
|
77
77
|
// ScopedNFTProvider
|
|
78
78
|
//
|
|
79
79
|
// Wrapper around an NFT Provider that is restricted to specific ids.
|
|
80
|
-
|
|
81
|
-
access(self) let provider: Capability
|
|
80
|
+
access(all) resource ScopedNFTProvider: NonFungibleToken.Provider {
|
|
81
|
+
access(self) let provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>
|
|
82
82
|
access(self) let filters: [{NFTFilter}]
|
|
83
83
|
|
|
84
84
|
// block timestamp that this provider can no longer be used after
|
|
85
85
|
access(self) let expiration: UFix64?
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
access(all) view fun isExpired(): Bool {
|
|
88
88
|
if let expiration = self.expiration {
|
|
89
89
|
return getCurrentBlock().timestamp >= expiration
|
|
90
90
|
}
|
|
91
91
|
return false
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
access(all) init(provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>, filters: [{NFTFilter}], expiration: UFix64?) {
|
|
95
95
|
self.provider = provider
|
|
96
96
|
self.expiration = expiration
|
|
97
97
|
self.filters = filters
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
access(all) fun canWithdraw(_ id: UInt64): Bool {
|
|
101
101
|
if self.isExpired() {
|
|
102
102
|
return false
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
let nft = self.provider.borrow()!.borrowNFT(id
|
|
105
|
+
let nft = self.provider.borrow()!.borrowNFT(id)
|
|
106
106
|
if nft == nil {
|
|
107
107
|
return false
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
var i = 0
|
|
111
111
|
while i < self.filters.length {
|
|
112
|
-
if !self.filters[i].canWithdraw(nft) {
|
|
112
|
+
if !self.filters[i].canWithdraw(nft!) {
|
|
113
113
|
return false
|
|
114
114
|
}
|
|
115
115
|
i = i + 1
|
|
@@ -117,17 +117,17 @@ pub contract ScopedNFTProviders {
|
|
|
117
117
|
return true
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
access(all) fun check(): Bool {
|
|
121
121
|
return self.provider.check()
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
access(NonFungibleToken.Withdraw | NonFungibleToken.Owner) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
125
125
|
pre {
|
|
126
126
|
!self.isExpired(): "provider has expired"
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
let nft <- self.provider.borrow()!.withdraw(withdrawID: withdrawID)
|
|
130
|
-
let ref = &nft as &NonFungibleToken.NFT
|
|
130
|
+
let ref = &nft as &{NonFungibleToken.NFT}
|
|
131
131
|
|
|
132
132
|
var i = 0
|
|
133
133
|
while i < self.filters.length {
|
|
@@ -142,7 +142,7 @@ pub contract ScopedNFTProviders {
|
|
|
142
142
|
return <-nft
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
access(all) fun getDetails(): [{String: AnyStruct}] {
|
|
146
146
|
let details: [{String: AnyStruct}] = []
|
|
147
147
|
for f in self.filters {
|
|
148
148
|
details.append(f.getDetails())
|
|
@@ -152,11 +152,12 @@ pub contract ScopedNFTProviders {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
provider: Capability
|
|
155
|
+
access(all) fun createScopedNFTProvider(
|
|
156
|
+
provider: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>,
|
|
157
157
|
filters: [{NFTFilter}],
|
|
158
158
|
expiration: UFix64?
|
|
159
159
|
): @ScopedNFTProvider {
|
|
160
160
|
return <- create ScopedNFTProvider(provider: provider, filters: filters, expiration: expiration)
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
+
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "ArrayUtils"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
access(all) contract StringUtils {
|
|
4
|
+
|
|
5
|
+
access(all) fun format(_ s: String, _ args: {String:String}): String{
|
|
6
|
+
var formatted = s
|
|
7
|
+
for key in args.keys{
|
|
8
|
+
formatted = StringUtils.replaceAll(formatted, "{".concat(key).concat("}"), args[key]!)
|
|
9
|
+
}
|
|
10
|
+
return formatted
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
access(all) fun explode(_ s: String): [String]{
|
|
14
14
|
var chars : [String] = []
|
|
15
15
|
for i in ArrayUtils.range(0, s.length){
|
|
16
16
|
chars.append(s[i].toString())
|
|
@@ -18,7 +18,7 @@ pub contract StringUtils {
|
|
|
18
18
|
return chars
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
access(all) fun trimLeft(_ s: String): String{
|
|
22
22
|
for i in ArrayUtils.range(0, s.length){
|
|
23
23
|
if s[i] != " "{
|
|
24
24
|
return s.slice(from: i, upTo: s.length)
|
|
@@ -27,23 +27,23 @@ pub contract StringUtils {
|
|
|
27
27
|
return ""
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
access(all) fun trim(_ s: String): String{
|
|
31
31
|
return self.trimLeft(s)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
return
|
|
34
|
+
access(all) fun replaceAll(_ s: String, _ search: String, _ replace: String): String{
|
|
35
|
+
return s.replaceAll(of: search, with: replace)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
access(all) fun hasPrefix(_ s: String, _ prefix: String) : Bool{
|
|
39
39
|
return s.length >= prefix.length && s.slice(from:0, upTo: prefix.length)==prefix
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
access(all) fun hasSuffix(_ s: String, _ suffix: String) : Bool{
|
|
43
43
|
return s.length >= suffix.length && s.slice(from:s.length-suffix.length, upTo: s.length)==suffix
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
access(all) fun index(_ s : String, _ substr : String, _ startIndex: Int): Int?{
|
|
47
47
|
for i in ArrayUtils.range(startIndex,s.length-substr.length+1){
|
|
48
48
|
if s[i]==substr[0] && s.slice(from:i, upTo:i+substr.length) == substr{
|
|
49
49
|
return i
|
|
@@ -52,7 +52,7 @@ pub contract StringUtils {
|
|
|
52
52
|
return nil
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
access(all) fun count(_ s: String, _ substr: String): Int{
|
|
56
56
|
var pos = [self.index(s, substr, 0)]
|
|
57
57
|
while pos[0]!=nil {
|
|
58
58
|
pos.insert(at:0, self.index(s, substr, pos[0]!+pos.length*substr.length+1))
|
|
@@ -60,38 +60,25 @@ pub contract StringUtils {
|
|
|
60
60
|
return pos.length-1
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
access(all) fun contains(_ s: String, _ substr: String): Bool {
|
|
64
64
|
if let index = self.index(s, substr, 0) {
|
|
65
65
|
return true
|
|
66
66
|
}
|
|
67
67
|
return false
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
access(all) fun substringUntil(_ s: String, _ until: String, _ startIndex: Int): String{
|
|
71
71
|
if let index = self.index( s, until, startIndex){
|
|
72
72
|
return s.slice(from:startIndex, upTo: index)
|
|
73
73
|
}
|
|
74
74
|
return s.slice(from:startIndex, upTo:s.length)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var p = 0
|
|
80
|
-
while p<=s.length{
|
|
81
|
-
var preDelimiter = self.substringUntil(s, delimiter, p)
|
|
82
|
-
segments.append(preDelimiter)
|
|
83
|
-
p = p + preDelimiter.length + delimiter.length
|
|
84
|
-
}
|
|
85
|
-
return segments
|
|
77
|
+
access(all) fun split(_ s: String, _ delimiter: String): [String] {
|
|
78
|
+
return s.split(separator: delimiter)
|
|
86
79
|
}
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for s in strs {
|
|
91
|
-
joinedStr = joinedStr.concat(s).concat(separator)
|
|
92
|
-
}
|
|
93
|
-
return joinedStr.slice(from: 0, upTo: joinedStr.length - separator.length)
|
|
81
|
+
access(all) fun join(_ strs: [String], _ separator: String): String {
|
|
82
|
+
return String.join(strs, separator: separator)
|
|
94
83
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
84
|
+
}
|
|
@@ -11,49 +11,41 @@ import "FlowToken"
|
|
|
11
11
|
|
|
12
12
|
Consumers of this contract would then need to pop the resource out of the DepositEstimate resource to get it back
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
access(all) contract FeeEstimator {
|
|
15
|
+
access(all) resource DepositEstimate {
|
|
16
|
+
access(all) var item: @AnyResource?
|
|
17
|
+
access(all) var storageFee: UFix64
|
|
18
18
|
|
|
19
19
|
init(item: @AnyResource, storageFee: UFix64) {
|
|
20
20
|
self.item <- item
|
|
21
21
|
self.storageFee = storageFee
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
return <-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
destroy() {
|
|
30
|
-
pre {
|
|
31
|
-
self.item == nil: "cannot destroy with non-null item"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
destroy self.item
|
|
24
|
+
access(all) fun withdraw(): @AnyResource {
|
|
25
|
+
let r <- self.item <- nil
|
|
26
|
+
return <-r!
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
access(all) fun hasStorageCapacity(_ addr: Address, _ storageFee: UFix64): Bool {
|
|
39
31
|
return FlowStorageFees.defaultTokenAvailableBalance(addr) > storageFee
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
|
|
34
|
+
access(all) fun estimateDeposit(
|
|
43
35
|
item: @AnyResource,
|
|
44
36
|
): @DepositEstimate {
|
|
45
|
-
let storageUsedBefore = FeeEstimator.account.
|
|
46
|
-
FeeEstimator.account.save(<-item, to: /storage/temp)
|
|
47
|
-
let storageUsedAfter = FeeEstimator.account.
|
|
37
|
+
let storageUsedBefore = FeeEstimator.account.storage.used
|
|
38
|
+
FeeEstimator.account.storage.save(<-item, to: /storage/temp)
|
|
39
|
+
let storageUsedAfter = FeeEstimator.account.storage.used
|
|
48
40
|
|
|
49
41
|
let storageDiff = storageUsedAfter - storageUsedBefore
|
|
50
42
|
let storageFee = FeeEstimator.storageUsedToFlowAmount(storageDiff)
|
|
51
|
-
let loadedItem <- FeeEstimator.account.load<@AnyResource>(from: /storage/temp)!
|
|
43
|
+
let loadedItem <- FeeEstimator.account.storage.load<@AnyResource>(from: /storage/temp)!
|
|
52
44
|
let estimate <- create DepositEstimate(item: <-loadedItem, storageFee: storageFee)
|
|
53
45
|
return <- estimate
|
|
54
46
|
}
|
|
55
47
|
|
|
56
|
-
|
|
48
|
+
access(all) fun storageUsedToFlowAmount(_ storageUsed: UInt64): UFix64 {
|
|
57
49
|
let storageMB = FlowStorageFees.convertUInt64StorageBytesToUFix64Megabytes(storageUsed)
|
|
58
50
|
return FlowStorageFees.storageCapacityToFlow(storageMB)
|
|
59
51
|
}
|