Contract con_gold_ticket_003


Contract Code

1 import currency as tau
2 import con_gold_contract as gold
3
4 random.seed()
5
6 # Owner of this contract
7 owner = Variable()
8 # Percent of total pool that goes to dev fund
9 dev_share = Variable()
10 # Percent of total pool that goes to endogen
11 endo_share = Variable()
12 # Amount of TAU needed to participate
13 tau_amount = Variable()
14 # Max users that can participate in one draw
15 max_entries = Variable()
16 # How often can one user participate in one draw
17 user_tickets = Variable()
18 # Total TAU amount of current run
19 tau_balance = Variable()
20 # Total GOLD amount of current run
21 gold_balance = Variable()
22 # Overall amount of TAU for Endogen
23 endo_tau = Variable()
24 # Overall amount of TAU for devs
25 dev_tau = Variable()
26 # List of players for current run
27 user_list = Variable()
28 # Last won amount of TAU
29 last_won_tau = Variable()
30 # Last won amount of GOLD
31 last_won_gold = Variable()
32 # Total won amount of TAU
33 total_won_tau = Variable()
34 # Total won amount of GOLD
35 total_won_gold = Variable()
36 # Last amount of burned GOLD
37 last_burned_gold = Variable()
38 # Total amount of burned GOLD
39 total_burned_gold = Variable()
40
41
42 @construct
43 def init():
44 owner.set(ctx.caller)
45 dev_share.set(9)
46 endo_share.set(1)
47 tau_amount.set(1)
48 max_entries.set(3)
49 user_tickets.set(2)
50 tau_balance.set(0)
51 gold_balance.set(0)
52 endo_tau.set(0)
53 dev_tau.set(0)
54 user_list.set([])
55 last_won_tau.set(0)
56 last_won_gold.set(0)
57 total_won_tau.set(0)
58 total_won_gold.set(0)
59 last_burned_gold.set(0)
60 total_burned_gold.set(0)
61
62 @export
63 def buy_ticket():
64 error = "Max users reached. Waiting for winner to be drawn."
65 assert len(user_list.get()) < max_entries.get(), error
66
67 tickets = {i:user_list.get().count(i) for i in user_list.get()}
68
69 if ctx.caller in tickets:
70 error = "Max amount of tickets per user reached"
71 assert tickets[ctx.caller] < user_tickets.get(), error
72
73 # Transfer TAU from user to contract
74 tau.transfer_from(
75 amount=tau_amount.get(),
76 to=ctx.this,
77 main_account=ctx.caller)
78
79 tau_balance.set(tau_balance.get() + tau_amount.get())
80
81 gold_price = ForeignHash(
82 foreign_contract='con_rocketswap_official_v1_1',
83 foreign_name='prices')
84
85 gold_amount = tau_amount.get() / gold_price["con_gold_contract"]
86
87 # Transfer GOLD from user to contract
88 gold.transfer_from(
89 amount=gold_amount,
90 to=ctx.this,
91 main_account=ctx.caller)
92
93 gold_balance.set(gold_balance.get() + gold_amount)
94
95 users = user_list.get()
96 users.append(ctx.caller)
97 user_list.set(users)
98
99 @export
100 def draw_winner():
101 allowed = [
102 "ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d",
103 "aed1eb42d24ccaff3a6264bc07da12170208bbba37b773603b90309ee3fd8b3d",
104 "a85b07902b938a37b0501ddd29d1725f99c8daeec6f5f4b4b45b3d801ede599f"
105 ]
106
107 error = "Only owner can draw a winner"
108 assert ctx.caller in allowed, error
109
110 # Determine winner address
111 winner = random.choice(user_list.get())
112
113 dev_amount_tau = tau_balance.get() / 100 * dev_share.get()
114 dev_tau.set(dev_tau.get() + dev_amount_tau)
115
116 endo_amount_tau = tau_balance.get() / 100 * endo_share.get()
117 endo_tau.set(endo_tau.get() + endo_amount_tau)
118
119 last_burned_gold.set(gold_balance.get() / 100 * (dev_share.get() + endo_share.get()))
120 total_burned_gold.set(total_burned_gold.get() + last_burned_gold.get())
121
122 last_won_tau.set(tau_balance.get() - dev_amount_tau - endo_amount_tau)
123 last_won_gold.set(gold_balance.get() - last_burned_gold.get())
124
125 total_won_tau.set(total_won_tau.get() + last_won_tau.get())
126 total_won_gold.set(total_won_gold.get() + last_won_gold.get())
127
128 # Transfer TAU from contract to winner
129 tau.transfer(
130 amount=last_won_tau.get(),
131 to=winner)
132
133 # Transfer GOLD from contract to winner
134 gold.transfer(
135 amount=last_won_gold.get(),
136 to=winner)
137
138 # Transfer GOLD from contract to burning address
139 gold.transfer(
140 amount=last_burned_gold.get(),
141 to="0000000000000BURN0000000000000")
142
143 # Prepare for next run
144 tau_balance.set(0)
145 gold_balance.set(0)
146 user_list.set([])
147
148 return winner
149
150 @export
151 def set_dev_share(percent: float):
152 error = "Only owner can adjust developer share"
153 assert ctx.caller == owner.get(), error
154
155 error = "Share can't be less than 0 or more than 100"
156 assert (percent >= 0 and percent <=100), error
157
158 dev_share.set(percent)
159
160 @export
161 def set_endo_share(percent: float):
162 error = "Only owner can adjust Endogens share"
163 assert ctx.caller == owner.get(), error
164
165 error = "Share can't be less than 0 or more than 100"
166 assert (percent >= 0 and percent <=100), error
167
168 endo_share.set(percent)
169
170 @export
171 def set_tau_amount(amount: int):
172 error = "Only owner can adjust TAU amount"
173 assert ctx.caller == owner.get(), error
174
175 error = "Amount of TAU can't be negative"
176 assert amount >= 0, error
177
178 tau_amount.set(amount)
179
180 @export
181 def set_max_entries(count: int):
182 error = "Only owner can adjust max entries"
183 assert ctx.caller == owner.get(), error
184
185 error = "Max number of entries must be more than 1"
186 assert count > 1, error
187
188 max_entries.set(count)
189
190 @export
191 def set_user_tickets(tickets: int):
192 error = "Only owner can adjust number of user tickets"
193 assert ctx.caller == owner.get(), error
194
195 error = "Max tickets per user must be more than 0"
196 assert tickets >= 1, error
197
198 user_tickets.set(tickets)
199
200 @export
201 def endo_payout():
202 error = "Payout only available for owner"
203 assert ctx.caller == owner.get(), error
204
205 # Transfer TAU from contract to Endogen
206 tau.transfer(
207 amount=endo_tau,
208 to=ctx.caller)
209
210 endo_tau.set(0)
211
212 @export
213 def dev_payout():
214 address = "96dae3b6213fb80eac7c6f4fa0fd26f34022741c56773107b20199cb43f5ed62"
215
216 error = "Payout only available for owner"
217 assert ctx.caller == address, error
218
219 # Transfer TAU from contract to Lamden devs
220 tau.transfer(
221 amount=dev_tau,
222 to=ctx.caller)
223
224 dev_tau.set(0)
225

Byte Code

e30000000000000000000000000400000040000000739e010000640064016c005a01640064016c025a0365046a058300010065066402640364048d025a0765066402640564048d025a0865066402640664048d025a0965066402640764048d025a0a65066402640864048d025a0b65066402640964048d025a0c65066402640a64048d025a0d65066402640b64048d025a0e65066402640c64048d025a0f65066402640d64048d025a1065066402640e64048d025a1165066402640f64048d025a1265066402641064048d025a1365066402641164048d025a1465066402641264048d025a1565066402641364048d025a1665066402641464048d025a176415641684005a1865196402830164176418840083015a1a6519640283016419641a840083015a1b651964028301651c641b9c01641c641d840483015a1d651964028301651c641b9c01641e641f840483015a1e651964028301651f64209c0164216422840483015a20651964028301651f64239c0164246425840483015a21651964028301651f64269c0164276428840483015a226519640283016429642a840083015a23651964028301642b642c840083015a2464015300292de9000000004eda13636f6e5f676f6c645f7469636b65745f303033da056f776e65722902da08636f6e7472616374da046e616d65da096465765f7368617265da0a656e646f5f7368617265da0a7461755f616d6f756e74da0b6d61785f656e7472696573da0c757365725f7469636b657473da0b7461755f62616c616e6365da0c676f6c645f62616c616e6365da08656e646f5f746175da076465765f746175da09757365725f6c697374da0c6c6173745f776f6e5f746175da0d6c6173745f776f6e5f676f6c64da0d746f74616c5f776f6e5f746175da0e746f74616c5f776f6e5f676f6c64da106c6173745f6275726e65645f676f6c64da11746f74616c5f6275726e65645f676f6c6463000000000000000000000000020000004300000073b000000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0164028301010074076a0164038301010074086a0164048301010074096a01640583010100740a6a01640583010100740b6a01640583010100740c6a01640583010100740d6a01670083010100740e6a01640583010100740f6a0164058301010074106a0164058301010074116a0164058301010074126a0164058301010074136a016405830101006400530029064ee909000000e901000000e903000000e90200000072010000002914da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0b5f5f6465765f7368617265da0c5f5f656e646f5f7368617265da0c5f5f7461755f616d6f756e74da0d5f5f6d61785f656e7472696573da0e5f5f757365725f7469636b657473da0d5f5f7461755f62616c616e6365da0e5f5f676f6c645f62616c616e6365da0a5f5f656e646f5f746175da095f5f6465765f746175da0b5f5f757365725f6c697374da0e5f5f6c6173745f776f6e5f746175da0f5f5f6c6173745f776f6e5f676f6c64da0f5f5f746f74616c5f776f6e5f746175da105f5f746f74616c5f776f6e5f676f6c64da125f5f6c6173745f6275726e65645f676f6c64da135f5f746f74616c5f6275726e65645f676f6c64a900722e000000722e000000da00da045f5f5f5f1c000000732200000000010c010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a01723000000063000000000000000005000000060000004300000073f000000064017d00740074016a028300830174036a0283006b00732074047c008301820164026403840074016a028300440083017d0174056a067c016b06725a64047d007c0174056a06190074076a0283006b00735a74047c008301820174086a09740a6a02830074056a0b74056a0664058d030100740c6a0d740c6a028300740a6a028300170083010100740e6406640764086409640a8d047d02740a6a0283007c02640b19001b007d03740f6a097c0374056a0b74056a0664058d03010074106a0d74106a0283007c0317008301010074016a0283007d047c046a1174056a068301010074016a0d7c048301010064005300290c4e7a324d617820757365727320726561636865642e2057616974696e6720666f722077696e6e657220746f20626520647261776e2e630100000000000000020000000400000053000000731c00000069007c005d147d0174006a0183006a027c0183017c01930271045300722e00000029037227000000da03676574da05636f756e742902da022e30da0169722e000000722e000000722f000000fa0a3c64696374636f6d703e34000000730200000006007a1e6275795f7469636b65742e3c6c6f63616c733e2e3c64696374636f6d703e7a264d617820616d6f756e74206f66207469636b65747320706572207573657220726561636865642903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da067072696365737202000000da0a676f6c645f70726963652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000da11636f6e5f676f6c645f636f6e74726163742912da036c656e722700000072310000007221000000da0e417373657274696f6e4572726f72721c000000721d0000007222000000da03746175da0d7472616e736665725f66726f6d7220000000da04746869737223000000721b000000da0b466f726569676e48617368da04676f6c647224000000da06617070656e642905da056572726f72da077469636b657473da0c5f5f676f6c645f7072696365da0b676f6c645f616d6f756e74da057573657273722e000000722e000000722f000000da0a6275795f7469636b6574300000007324000000000204011c0112010a0104011a010e010a011601020104010a0110011402120108010c01724c000000630000000000000000050000000400000043000000736201000064016402640367037d0064047d0174006a017c006b06732074027c018301820174036a0474056a06830083017d0274076a06830064051b0074086a06830014007d0374096a0a74096a0683007c0317008301010074076a06830064051b00740b6a06830014007d04740c6a0a740c6a0683007c04170083010100740d6a0a740e6a06830064051b0074086a068300740b6a0683001700140083010100740f6a0a740f6a068300740d6a06830017008301010074106a0a74076a0683007c0318007c0418008301010074116a0a740e6a068300740d6a06830018008301010074126a0a74126a06830074106a06830017008301010074136a0a74136a06830074116a06830017008301010074146a1574106a0683007c0264068d02010074166a1574116a0683007c0264068d02010074166a15740d6a068300640764068d02010074076a0a640883010100740e6a0a64088301010074056a0a6700830101007c02530029094eda4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4061656431656234326432346363616666336136323634626330376461313231373032303862626261333762373733363033623930333039656533666438623364da40613835623037393032623933386133376230353031646464323964313732356639396338646165656336663566346234623435623364383031656465353939667a1c4f6e6c79206f776e65722063616e206472617720612077696e6e6572e964000000290272360000007237000000da1e303030303030303030303030304255524e3030303030303030303030303072010000002917721c000000721d0000007240000000da0672616e646f6dda0663686f696365722700000072310000007223000000721e0000007226000000721b000000721f0000007225000000722c0000007224000000722d00000072280000007229000000722a000000722b0000007241000000da087472616e7366657272450000002905da07616c6c6f7765647247000000da0677696e6e6572da0e6465765f616d6f756e745f746175da0f656e646f5f616d6f756e745f746175722e000000722e000000722f000000da0b647261775f77696e6e65724700000073320000000003020102010601040112010e01140112011401120114010e0116021601160116011601120112010a0108010a010a010a0172590000002901da0770657263656e74630100000000000000020000000200000043000000734400000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05722e7c0064046b01733674047c018301820174056a067c00830101006400530029054e7a254f6e6c79206f776e65722063616e2061646a75737420646576656c6f7065722073686172657a2b53686172652063616e2774206265206c657373207468616e2030206f72206d6f7265207468616e20313030720100000072500000002907721c000000721d000000721a00000072310000007240000000721e000000721b0000002902725a0000007247000000722e000000722e000000722f000000da0d7365745f6465765f736861726566000000730a00000000020401160104011801725b000000630100000000000000020000000200000043000000734400000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05722e7c0064046b01733674047c018301820174056a067c00830101006400530029054e7a244f6e6c79206f776e65722063616e2061646a75737420456e646f67656e732073686172657a2b53686172652063616e2774206265206c657373207468616e2030206f72206d6f7265207468616e20313030720100000072500000002907721c000000721d000000721a00000072310000007240000000721f000000721b0000002902725a0000007247000000722e000000722e000000722f000000da0e7365745f656e646f5f73686172656f000000730a00000000020401160104011801725c00000029017236000000630100000000000000020000000200000043000000733c00000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05732e74047c018301820174056a067c00830101006400530029044e7a204f6e6c79206f776e65722063616e2061646a7573742054415520616d6f756e747a1f416d6f756e74206f66205441552063616e2774206265206e6567617469766572010000002907721c000000721d000000721a000000723100000072400000007220000000721b000000290272360000007247000000722e000000722e000000722f000000da0e7365745f7461755f616d6f756e7478000000730a00000000020401160104011001725d00000029017232000000630100000000000000020000000200000043000000733c00000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b04732e74047c018301820174056a067c00830101006400530029044e7a214f6e6c79206f776e65722063616e2061646a757374206d617820656e74726965737a294d6178206e756d626572206f6620656e7472696573206d757374206265206d6f7265207468616e203172170000002907721c000000721d000000721a000000723100000072400000007221000000721b000000290272320000007247000000722e000000722e000000722f000000da0f7365745f6d61785f656e747269657381000000730a00000000020401160104011001725e00000029017248000000630100000000000000020000000200000043000000733c00000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05732e74047c018301820174056a067c00830101006400530029044e7a2c4f6e6c79206f776e65722063616e2061646a757374206e756d626572206f662075736572207469636b6574737a284d6178207469636b657473207065722075736572206d757374206265206d6f7265207468616e203072170000002907721c000000721d000000721a000000723100000072400000007222000000721b000000290272480000007247000000722e000000722e000000722f000000da107365745f757365725f7469636b6574738a000000730a00000000020401160104011001725f000000630000000000000000010000000400000043000000733800000064017d0074006a0174026a0383006b02731a74047c008301820174056a06740774006a0164028d02010074076a086403830101006400530029044e7a1f5061796f7574206f6e6c7920617661696c61626c6520666f72206f776e657229027236000000723700000072010000002909721c000000721d000000721a00000072310000007240000000724100000072540000007225000000721b00000029017247000000722e000000722e000000722f000000da0b656e646f5f7061796f757493000000730800000000020401160110017260000000630000000000000000020000000400000043000000733800000064017d0064027d0174006a017c006b02731a74027c018301820174036a04740574006a0164038d02010074056a066404830101006400530029054eda40393664616533623632313366623830656163376336663466613066643236663334303232373431633536373733313037623230313939636234336635656436327a1f5061796f7574206f6e6c7920617661696c61626c6520666f72206f776e657229027236000000723700000072010000002907721c000000721d0000007240000000724100000072540000007226000000721b0000002902da07616464726573737247000000722e000000722e000000722f000000da0a6465765f7061796f75749b000000730a0000000003040104011201100172630000002925da0863757272656e63797241000000723e00000072450000007252000000da0473656564da085661726961626c65721a000000721e000000721f0000007220000000722100000072220000007223000000722400000072250000007226000000722700000072280000007229000000722a000000722b000000722c000000722d0000007230000000da085f5f6578706f7274724c0000007259000000da05666c6f6174725b000000725c000000da03696e74725d000000725e000000725f00000072600000007263000000722e000000722e000000722e000000722f000000da083c6d6f64756c653e01000000734a0000000801080108010c010c010c010c010c010c010c010c010c010c010c010c010c020c0204010801040108010401080308141017101f06011008060110080601100806011008060110081008