@flowtyio/flow-contracts 0.1.0-beta.29 → 0.1.0-beta.30
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.
|
@@ -9,6 +9,7 @@ https://github.com/Flowtyio/fungible-token-router
|
|
|
9
9
|
|
|
10
10
|
import "FungibleToken"
|
|
11
11
|
import "FungibleTokenMetadataViews"
|
|
12
|
+
import "FlowToken"
|
|
12
13
|
|
|
13
14
|
access(all) contract FungibleTokenRouter {
|
|
14
15
|
access(all) let StoragePath: StoragePath
|
|
@@ -44,18 +45,32 @@ access(all) contract FungibleTokenRouter {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
access(all) fun deposit(from: @{FungibleToken.Vault}) {
|
|
47
|
-
let tokenType = from.getType()
|
|
48
|
-
let destination = self.addressOverrides[tokenType] ?? self.defaultAddress
|
|
48
|
+
let tokenType = from.getType()
|
|
49
|
+
let destination = self.addressOverrides[tokenType.identifier] ?? self.defaultAddress
|
|
50
|
+
|
|
51
|
+
var vaultDataOpt: FungibleTokenMetadataViews.FTVaultData? = nil
|
|
52
|
+
|
|
53
|
+
if tokenType == Type<@FlowToken.Vault>() {
|
|
54
|
+
vaultDataOpt = FungibleTokenMetadataViews.FTVaultData(
|
|
55
|
+
storagePath: /storage/flowTokenVault,
|
|
56
|
+
receiverPath: /public/flowTokenReceiver,
|
|
57
|
+
metadataPath: /public/flowTokenReceiver,
|
|
58
|
+
receiverLinkedType: Type<&FlowToken.Vault>(),
|
|
59
|
+
metadataLinkedType: Type<&FlowToken.Vault>(),
|
|
60
|
+
createEmptyVaultFunction: fun(): @{FungibleToken.Vault} {
|
|
61
|
+
return <- FlowToken.createEmptyVault(vaultType: tokenType)
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
} else if let md = from.resolveView(Type<FungibleTokenMetadataViews.FTVaultData>()) {
|
|
65
|
+
vaultDataOpt = md as! FungibleTokenMetadataViews.FTVaultData
|
|
66
|
+
}
|
|
49
67
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
assert(receiver.check(), message: "no receiver found at path: ".concat(vaultData.receiverPath.toString()))
|
|
68
|
+
let vaultData = vaultDataOpt ?? panic("vault data could not be retrieved")
|
|
69
|
+
let receiver = getAccount(destination).capabilities.get<&{FungibleToken.Receiver}>(vaultData.receiverPath)
|
|
70
|
+
assert(receiver.check(), message: "no receiver found at path: ".concat(vaultData.receiverPath.toString()))
|
|
55
71
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
72
|
+
emit TokensRouted(tokenType: tokenType.identifier, amount: from.balance, to: destination)
|
|
73
|
+
receiver.borrow()!.deposit(from: <-from)
|
|
59
74
|
|
|
60
75
|
panic("Could not find FungibleTokenMetadataViews.FTVaultData on depositing tokens")
|
|
61
76
|
}
|