@flowtyio/flow-contracts 0.0.10 → 0.0.14
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/README.md +17 -11
- package/add.js +44 -4
- package/contracts/FlowStorageFees.cdc +193 -0
- package/contracts/FlowToken.cdc +274 -0
- package/contracts/FungibleTokenMetadataViews.cdc +183 -0
- package/contracts/TokenForwarding.cdc +82 -0
- package/contracts/dapper/DapperUtilityCoin.cdc +199 -0
- package/contracts/dapper/FlowUtilityToken.cdc +199 -0
- package/contracts/lost-and-found/FeeEstimator.cdc +62 -0
- package/contracts/lost-and-found/LostAndFound.cdc +758 -0
- package/contracts/lost-and-found/LostAndFoundHelper.cdc +42 -0
- package/contracts/nft-catalog/NFTCatalog.cdc +422 -0
- package/contracts/nft-catalog/NFTCatalogAdmin.cdc +175 -0
- package/flow.json +129 -13
- package/index.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "FungibleToken"
|
|
2
|
+
import "FlowStorageFees"
|
|
3
|
+
import "FlowToken"
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
FeeEstimator
|
|
7
|
+
|
|
8
|
+
Small contract that allows other contracts to estimate how much storage cost a resource might take up.
|
|
9
|
+
This is done by storing a resource in the FeeEstimator, recording the difference in available balance,
|
|
10
|
+
then returning the difference and the original item being estimated.
|
|
11
|
+
|
|
12
|
+
Consumers of this contract would then need to pop the resource out of the DepositEstimate resource to get it back
|
|
13
|
+
*/
|
|
14
|
+
pub contract FeeEstimator {
|
|
15
|
+
pub resource DepositEstimate {
|
|
16
|
+
pub var item: @AnyResource?
|
|
17
|
+
pub var storageFee: UFix64
|
|
18
|
+
|
|
19
|
+
init(item: @AnyResource, storageFee: UFix64) {
|
|
20
|
+
self.item <- item
|
|
21
|
+
self.storageFee = storageFee
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fun withdraw(): @AnyResource {
|
|
25
|
+
let resource <- self.item <- nil
|
|
26
|
+
return <-resource!
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
destroy() {
|
|
30
|
+
pre {
|
|
31
|
+
self.item == nil: "cannot destroy with non-null item"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
destroy self.item
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
pub fun hasStorageCapacity(_ addr: Address, _ storageFee: UFix64): Bool {
|
|
39
|
+
return FlowStorageFees.defaultTokenAvailableBalance(addr) > storageFee
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pub fun estimateDeposit(
|
|
43
|
+
item: @AnyResource,
|
|
44
|
+
): @DepositEstimate {
|
|
45
|
+
let storageUsedBefore = FeeEstimator.account.storageUsed
|
|
46
|
+
FeeEstimator.account.save(<-item, to: /storage/temp)
|
|
47
|
+
let storageUsedAfter = FeeEstimator.account.storageUsed
|
|
48
|
+
|
|
49
|
+
let storageDiff = storageUsedAfter - storageUsedBefore
|
|
50
|
+
let storageFee = FeeEstimator.storageUsedToFlowAmount(storageDiff)
|
|
51
|
+
let loadedItem <- FeeEstimator.account.load<@AnyResource>(from: /storage/temp)!
|
|
52
|
+
let estimate <- create DepositEstimate(item: <-loadedItem, storageFee: storageFee)
|
|
53
|
+
return <- estimate
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fun storageUsedToFlowAmount(_ storageUsed: UInt64): UFix64 {
|
|
57
|
+
let storageMB = FlowStorageFees.convertUInt64StorageBytesToUFix64Megabytes(storageUsed)
|
|
58
|
+
return FlowStorageFees.storageCapacityToFlow(storageMB)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
init() {}
|
|
62
|
+
}
|