Contract con_node_test6_distribute


Contract Code


  
1 import con_node as node
2 import currency as tau
3
4 investors = Hash(default_value=0)
5
6 total_tau_amount = Variable()
7 total_node_amount = Variable()
8 min_tau_amount = Variable()
9
10 operator = Variable()
11 end_date = Variable()
12
13 setup_executed = Variable()
14
15 @construct
16 def init():
17 operator.set(ctx.caller)
18 setup_executed.set(False)
19 total_tau_amount.set(0)
20 total_node_amount.set(0)
21 min_tau_amount.set(0)
22 end_date.set(now)
23
24 @export
25 def setup(time_in_hours: int, min_tau: int, node_amount: float):
26 assert_caller_is_operator()
27
28 end_date.set(now + datetime.timedelta(hours=time_in_hours))
29 total_node_amount.set(node_amount)
30 min_tau_amount.set(min_tau)
31
32 setup_executed.set(True)
33
34 node.transfer_from(amount=node_amount, to=ctx.this, main_account=ctx.caller)
35
36 @export
37 def invest(amount_tau: int):
38 assert setup_executed.get(), 'Not set up yet. Try again later'
39 assert amount_tau >= min_tau_amount.get(), f'Min investment is {min_tau_amount.get()} TAU'
40 assert now < end_date.get(), 'Investment period ended'
41
42 total_tau_amount.set(total_tau_amount.get() + amount_tau)
43 investors[ctx.caller] += amount_tau
44
45 return investors[ctx.caller]
46
47 @export
48 def time_until_end():
49 return end_date.get() - now
50
51 @export
52 def withdraw_node_token():
53 assert now > end_date.get(), f'Investment period ended on {end_date.get()}'
54 assert investors[ctx.caller] > 0, 'You do not own any NODE tokens'
55
56 tau_percent_owned = investors[ctx.caller] / total_tau_amount.get() * 100
57 node_owned = total_node_amount.get() / 100 * tau_percent_owned
58
59 node.transfer(amount=node_owned, to=ctx.caller)
60
61 @export
62 def withdraw_tau():
63 assert_caller_is_operator()
64 tau.transfer(amount=tau.balance_of(ctx.this), to=ctx.caller)
65
66 def assert_caller_is_operator():
67 assert ctx.caller == operator.get()
68

Byte Code

e3000000000000000000000000050000004000000073da000000640064016c005a01640064016c025a03650464006402640364048d035a0565066402640564068d025a0765066402640764068d025a0865066402640864068d025a0965066402640964068d025a0a65066402640a64068d025a0b65066402640b64068d025a0c640c640d84005a0d650e64028301650f650f6510640e9c03640f6410840483015a11650e64028301650f64119c0164126413840483015a12650e6402830164146415840083015a13650e6402830164166417840083015a14650e6402830164186419840083015a15641a641b84005a1664015300291ce9000000004eda19636f6e5f6e6f64655f74657374365f64697374726962757465da09696e766573746f72732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da10746f74616c5f7461755f616d6f756e74290272050000007206000000da11746f74616c5f6e6f64655f616d6f756e74da0e6d696e5f7461755f616d6f756e74da086f70657261746f72da08656e645f64617465da0e73657475705f6578656375746564630000000000000000000000000200000043000000734200000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0164028301010074076a0164028301010074086a017409830101006400530029034e467201000000290ada0a5f5f6f70657261746f72da03736574da03637478da0663616c6c6572da105f5f73657475705f6578656375746564da125f5f746f74616c5f7461755f616d6f756e74da135f5f746f74616c5f6e6f64655f616d6f756e74da105f5f6d696e5f7461755f616d6f756e74da0a5f5f656e645f64617465da036e6f77a90072170000007217000000da00da045f5f5f5f11000000730c00000000010c010a010a010a010a0172190000002903da0d74696d655f696e5f686f757273da076d696e5f746175da0b6e6f64655f616d6f756e74630300000000000000030000000500000043000000735200000074008300010074016a02740374046a057c0064018d0117008301010074066a027c028301010074076a027c018301010074086a0264028301010074096a0a7c02740b6a0c740b6a0d64038d0301006400530029044e2901da05686f757273542903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74290eda1b5f5f6173736572745f63616c6c65725f69735f6f70657261746f727215000000720e0000007216000000da086461746574696d65da0974696d6564656c7461721300000072140000007211000000da046e6f6465da0d7472616e736665725f66726f6d720f000000da047468697372100000002903721a000000721b000000721c000000721700000072170000007218000000da0573657475701a000000730c0000000002060116010a010a010a0172270000002901da0a616d6f756e745f746175630100000000000000010000000400000043000000737200000074006a018300731074026401830182017c0074036a0183006b0573307402640274036a0183009b0064039d0383018201740474056a0183006b007344740264048301820174066a0774066a0183007c00170083010100740874096a0a050019007c00370003003c00740874096a0a1900530029054e7a1f4e6f7420736574207570207965742e2054727920616761696e206c617465727a124d696e20696e766573746d656e74206973207a04205441557a17496e766573746d656e7420706572696f6420656e646564290b7211000000da03676574da0e417373657274696f6e4572726f727214000000721600000072150000007212000000720e000000da0b5f5f696e766573746f7273720f000000721000000029017228000000721700000072170000007218000000da06696e7665737425000000730e000000000210010e011201140112011201722c000000630000000000000000000000000200000043000000730c00000074006a01830074021800530029014e29037215000000722900000072160000007217000000721700000072170000007218000000da0e74696d655f756e74696c5f656e643000000073020000000002722d000000630000000000000000020000000400000043000000736e000000740074016a0283006b04731e7403640174016a0283009b009d0283018201740474056a06190064026b0473347403640383018201740474056a06190074076a0283001b00640414007d0074086a02830064041b007c0014007d0174096a0a7c0174056a0664058d0201006400530029064e7a1b496e766573746d656e7420706572696f6420656e646564206f6e2072010000007a1e596f7520646f206e6f74206f776e20616e79204e4f444520746f6b656e73e9640000002902721e000000721f000000290b721600000072150000007229000000722a000000722b000000720f0000007210000000721200000072130000007224000000da087472616e736665722902da117461755f70657263656e745f6f776e6564da0a6e6f64655f6f776e6564721700000072170000007218000000da1377697468647261775f6e6f64655f746f6b656e35000000730c00000000020e0110011602160110017232000000630000000000000000000000000400000043000000732200000074008300010074016a0274016a0374046a05830174046a0664018d0201006400530029024e2902721e000000721f00000029077221000000da03746175722f000000da0a62616c616e63655f6f66720f000000722600000072100000007217000000721700000072170000007218000000da0c77697468647261775f746175400000007304000000000206017235000000630000000000000000000000000200000043000000731600000074006a0174026a0383006b027312740482016400530029014e2905720f0000007210000000720d0000007229000000722a00000072170000007217000000721700000072180000007221000000460000007302000000000172210000002917da08636f6e5f6e6f64657224000000da0863757272656e63797233000000da0448617368722b000000da085661726961626c65721200000072130000007214000000720d000000721500000072110000007219000000da085f5f6578706f7274da03696e74da05666c6f61747227000000722c000000722d0000007232000000723500000072210000007217000000721700000072170000007218000000da083c6d6f64756c653e01000000732c00000008010801060108010401080104010801040108010c010c010401080308090601140a0601100a1005100b1006