Smart Contract
VioletVerse
A.f5f7db710acb59d3.VioletVerse
1import FungibleToken from 0xf233dcee88fe0abe
2
3// Token contract of Violet Verse Token (VV)
4pub contract VioletVerse: FungibleToken {
5
6 // Total supply of Flow tokens in existence
7 pub var totalSupply: UFix64
8
9 // Total Launch Users
10 pub var launchUsers: UFix64
11
12 // Defines token vault storage path
13 pub let TokenStoragePath: StoragePath
14
15 // Defines token vault public balance path
16 pub let TokenPublicBalancePath: PublicPath
17
18 // Defines token vault public receiver path
19 pub let TokenPublicReceiverPath: PublicPath
20
21 // Event that is emitted when the contract is created
22 pub event TokensInitialized(initialSupply: UFix64)
23
24 // Event that is emitted when tokens are withdrawn from a Vault
25 pub event TokensWithdrawn(amount: UFix64, from: Address?)
26
27 // Event that is emitted when tokens are deposited to a Vault
28 pub event TokensDeposited(amount: UFix64, to: Address?)
29
30 // Event that is emitted when tokens are destroyed
31 pub event TokensBurned(amount: UFix64)
32
33 // Vault
34 //
35 // Each user stores an instance of only the Vault in their storage
36 // The functions in the Vault and governed by the pre and post conditions
37 // in FungibleToken when they are called.
38 // The checks happen at runtime whenever a function is called.
39 //
40 // Resources can only be created in the context of the contract that they
41 // are defined in, so there is no way for a malicious user to create Vaults
42 // out of thin air.
43 //
44 pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance {
45
46 // holds the balance of a users tokens
47 pub var balance: UFix64
48
49 // initialize the balance at resource creation time
50 init(balance: UFix64) {
51 self.balance = balance
52 }
53
54 // withdraw
55 //
56 // Function that takes an integer amount as an argument
57 // and withdraws that amount from the Vault.
58 // It creates a new temporary Vault that is used to hold
59 // the money that is being transferred. It returns the newly
60 // created Vault to the context that called so it can be deposited
61 // elsewhere.
62 //
63 pub fun withdraw(amount: UFix64): @FungibleToken.Vault {
64 self.balance = self.balance - amount
65 emit TokensWithdrawn(amount: amount, from: self.owner?.address)
66 return <-create Vault(balance: amount)
67 }
68
69 // deposit
70 //
71 // Function that takes a Vault object as an argument and adds
72 // its balance to the balance of the owners Vault.
73 // It is allowed to destroy the sent Vault because the Vault
74 // was a temporary holder of the tokens. The Vault's balance has
75 // been consumed and therefore can be destroyed.
76 pub fun deposit(from: @FungibleToken.Vault) {
77 let vault <- from as! @VioletVerse.Vault
78 self.balance = self.balance + vault.balance
79 emit TokensDeposited(amount: vault.balance, to: self.owner?.address)
80 vault.balance = 0.0
81 destroy vault
82 }
83
84 destroy() {
85 VioletVerse.totalSupply = VioletVerse.totalSupply - self.balance
86 if (self.balance > 0.0) {
87 // Emit an event that shows that the token was burned
88 emit TokensBurned(amount: self.balance)
89 }
90 }
91 }
92
93 // createEmptyVault
94 //
95 // Function that creates a new Vault with a balance of zero
96 // and returns it to the calling context. A user must call this function
97 // and store the returned Vault in their storage in order to allow their
98 // account to be able to receive deposits of this token type.
99 //
100 pub fun createEmptyVault(): @FungibleToken.Vault {
101 if (VioletVerse.launchUsers == 0.0) {
102 return <-create Vault(balance: 0.0)
103 } else {
104 VioletVerse.launchUsers = VioletVerse.launchUsers - 1.0
105 return <-create Vault(balance: 777.00)
106 }
107 }
108
109 pub fun createVioletVault(): @FungibleToken.Vault {
110 if (VioletVerse.launchUsers == 0.0) {
111 return <-create Vault(balance: 0.0)
112 } else {
113 VioletVerse.launchUsers = VioletVerse.launchUsers - 1.0
114 VioletVerse.totalSupply = VioletVerse.totalSupply + 777.00
115 return <-create Vault(balance: 777.00)
116 }
117 }
118
119
120 init() {
121 // Total supply of VV is 100M
122 self.totalSupply = 99_611_500.0
123 self.launchUsers = 500.0
124
125 self.TokenStoragePath = /storage/violetVerseVault
126 self.TokenPublicReceiverPath = /public/violetVerseReceiver
127 self.TokenPublicBalancePath = /public/violetVerseBalance
128
129 // Create the Vault with the total supply of tokens and save it in storage
130 let vault <- create Vault(balance: self.totalSupply)
131 self.account.save(<-vault, to: self.TokenStoragePath)
132
133 // Create a public capability to the stored Vault that only exposes
134 // the `deposit` method through the `Receiver` interface
135 self.account.link<&VioletVerse.Vault{FungibleToken.Receiver}>(
136 self.TokenPublicReceiverPath,
137 target: self.TokenStoragePath
138 )
139
140 // Create a public capability to the stored Vault that only exposes
141 // the `balance` field through the `Balance` interface
142 self.account.link<&VioletVerse.Vault{FungibleToken.Balance}>(
143 self.TokenPublicBalancePath,
144 target: self.TokenStoragePath
145 )
146
147 // Emit an event that shows that the contract was initialized
148 emit TokensInitialized(initialSupply: self.totalSupply)
149 }
150}
151