Smart Contract
FIVEGCOIN
A.efc9bea2fda54f34.FIVEGCOIN
1// FIVEGCOIN.cdc 5G COIN
2//
3// This contract implements a fungible token that will be used
4// to reward hotspot operators for providing 5G network coverage.
5
6import FungibleToken from 0xf233dcee88fe0abe
7import MetadataViews from 0x1d7e57aa55817448
8import FungibleTokenMetadataViews from 0xf233dcee88fe0abe
9
10access(all) contract FIVEGCOIN: FungibleToken {
11
12 access(all) event TokensWithdrawn(amount: UFix64, from: Address?)
13 access(all) event TokensDeposited(amount: UFix64, to: Address?)
14 access(all) event TokensMinted(amount: UFix64)
15
16 access(all) let VaultStoragePath: StoragePath
17 access(all) let VaultPublicPath: PublicPath
18 access(all) let ReceiverPublicPath: PublicPath
19
20 access(all) var totalSupply: UFix64
21 access(all) resource Vault: FungibleToken.Vault {
22
23 access(all) var balance: UFix64
24
25 init(balance: UFix64) {
26 self.balance = balance
27 }
28
29 access(contract) fun burnCallback() {
30 if self.balance > 0.0 {
31 FIVEGCOIN.totalSupply = FIVEGCOIN.totalSupply - self.balance
32 }
33 self.balance = 0.0
34 }
35
36 access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
37 return {self.getType(): true}
38 }
39
40 access(all) view fun isSupportedVaultType(type: Type): Bool {
41 if (type == self.getType()) { return true } else { return false }
42 }
43
44 access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
45 return amount <= self.balance
46 }
47
48 access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
49 self.balance = self.balance - amount
50
51 if let address = self.owner?.address {
52 emit TokensWithdrawn(amount: amount, from: address)
53 } else {
54 emit TokensWithdrawn(amount: amount, from: nil)
55 }
56 return <-create Vault(balance: amount)
57 }
58
59 access(all) fun deposit(from: @{FungibleToken.Vault}) {
60 let vault <- from as! @FIVEGCOIN.Vault
61 self.balance = self.balance + vault.balance
62
63 if let address = self.owner?.address {
64 emit TokensDeposited(amount: vault.balance, to: address)
65 } else {
66 emit TokensDeposited(amount: vault.balance, to: nil)
67 }
68 vault.balance = 0.0
69 destroy vault
70 }
71
72 access(all) view fun getViews(): [Type]{
73 return []
74 }
75
76 access(all) fun resolveView(_ view: Type): AnyStruct? {
77 return nil
78 }
79
80 access(all) fun createEmptyVault(): @{FungibleToken.Vault} {
81 return <-create Vault(balance: 0.0)
82 }
83 }
84
85 access(all) fun createEmptyVault(vaultType: Type): @FIVEGCOIN.Vault {
86 return <-create Vault(balance: 0.0)
87 }
88
89 /// Gets a list of the metadata views that this contract supports
90 access(all) view fun getContractViews(resourceType: Type?): [Type] {
91 return []
92 }
93
94 access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
95 return nil
96 }
97
98 access(account) fun mintTokens(amount: UFix64): @FIVEGCOIN.Vault {
99 pre {
100 amount > 0.0: "Amount minted must be greater than zero"
101 }
102 FIVEGCOIN.totalSupply = FIVEGCOIN.totalSupply + amount
103
104 emit TokensMinted(amount: amount)
105 return <-create Vault(balance: amount)
106 }
107
108 init() {
109 self.totalSupply = 0.0
110 self.VaultStoragePath = /storage/FIVEGCOINVault_1
111 self.VaultPublicPath = /public/FIVEGCOINVault_1
112 self.ReceiverPublicPath = /public/FIVEGCOINReceiver_1
113
114 let vault <-create Vault(balance: 0.0)
115 self.account.storage.save(<-vault, to: self.VaultStoragePath)
116
117 let tokenCap = self.account.capabilities.storage.issue<&FIVEGCOIN.Vault>(self.VaultStoragePath)
118 self.account.capabilities.publish(tokenCap, at: self.ReceiverPublicPath)
119 self.account.capabilities.publish(tokenCap, at: self.VaultPublicPath)
120 }
121}
122