Contract con_node_test5_distribute


Contract Code


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

Byte Code

e3000000000000000000000000050000004000000073ce000000640064016c005a01640064016c025a03650464006402640364048d035a0565066402640564068d025a0765066402640764068d025a0865066402640864068d025a0965066402640964068d025a0a65066402640a64068d025a0b640b640c84005a0c650d64028301650e650e650f640d9c03640e640f840483015a10650d64028301650e64109c0164116412840483015a11650d6402830164136414840083015a12650d6402830164156416840083015a13650d6402830164176418840083015a146419641a84005a1564015300291be9000000004eda19636f6e5f6e6f64655f74657374355f64697374726962757465da09696e766573746f72732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da08656e645f64617465290272050000007206000000da10746f74616c5f7461755f616d6f756e74da11746f74616c5f6e6f64655f616d6f756e74da0e6d696e5f7461755f616d6f756e74da086f70657261746f72630000000000000000000000000200000043000000731000000074006a0174026a03830101006400530029014e2904da0a5f5f6f70657261746f72da03736574da03637478da0663616c6c6572a90072100000007210000000da00da045f5f5f5f0f0000007302000000000172120000002903da0d74696d655f696e5f686f757273da076d696e5f746175da0b6e6f64655f616d6f756e74630300000000000000030000000500000043000000734800000074008300010074016a02740374046a057c0064018d0117008301010074066a027c028301010074076a027c018301010074086a097c02740a6a0b740a6a0c64028d0301006400530029034e2901da05686f7572732903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74290dda1b5f5f6173736572745f63616c6c65725f69735f6f70657261746f72da0a5f5f656e645f64617465720d000000da036e6f77da086461746574696d65da0974696d6564656c7461da135f5f746f74616c5f6e6f64655f616d6f756e74da105f5f6d696e5f7461755f616d6f756e74da046e6f6465da0d7472616e736665725f66726f6d720e000000da0474686973720f0000002903721300000072140000007215000000721000000072100000007211000000da05736574757013000000730a0000000002060116010a010a0172240000002901da0a616d6f756e745f74617563010000000000000001000000040000004300000073620000007c0074006a0183006b0573207402640174006a0183009b0064029d0383018201740374046a0183006b007334740264038301820174056a0674056a0183007c00170083010100740774086a09050019007c00370003003c00740774086a091900530029044e7a1c596f75206e65656420746f20696e76657374206174206c65617374207a04205441557a1a496e766573746d656e742074696d656672616d6520656e646564290a7220000000da03676574da0e417373657274696f6e4572726f72721c000000721b000000da125f5f746f74616c5f7461755f616d6f756e74720d000000da0b5f5f696e766573746f7273720e000000720f00000029017225000000721000000072100000007211000000da06696e766573741d000000730c00000000020e011201140112011201722a000000630000000000000000000000000200000043000000730c00000074006a01830074021800530029014e2903721b0000007226000000721c0000007210000000721000000072100000007211000000da0e74696d655f756e74696c5f656e642700000073020000000002722b000000630000000000000000020000000400000043000000736e00000074006a01830074026b00731e7403640174006a0183009b009d0283018201740474056a06190064026b0473347403640383018201740474056a06190074076a0183001b00640414007d0074086a01830064041b007c0014007d0174096a0a7c0174056a0664058d0201006400530029064e7a2a496e766573746d656e742074696d65206e6f74206f766572207965742120456e6420646174652069732072010000007a1e596f7520646f206e6f74206f776e20616e79204e4f444520746f6b656e73e964000000290272170000007218000000290b721b0000007226000000721c00000072270000007229000000720e000000720f0000007228000000721f0000007221000000da087472616e736665722902da117461755f70657263656e745f6f776e6564da0a6e6f64655f6f776e6564721000000072100000007211000000da1377697468647261775f6e6f64655f746f6b656e2c000000730c0000000002060118011602160110017230000000630000000000000000000000000400000043000000732200000074008300010074016a0274016a0374046a05830174046a0664018d0201006400530029024e2902721700000072180000002907721a000000da03746175722d000000da0a62616c616e63655f6f66720e0000007223000000720f0000007210000000721000000072100000007211000000da0c77697468647261775f746175370000007304000000000206017233000000630000000000000000000000000200000043000000731600000074006a0174026a0383006b027312740482016400530029014e2905720e000000720f000000720c000000722600000072270000007210000000721000000072100000007211000000721a0000003d00000073020000000001721a0000002916da0e636f6e5f6e6f64655f74657374347221000000da0863757272656e63797231000000da04486173687229000000da085661726961626c65721b0000007228000000721f0000007220000000720c0000007212000000da085f5f6578706f7274da03696e74da05666c6f61747224000000722a000000722b00000072300000007233000000721a0000007210000000721000000072100000007211000000da083c6d6f64756c653e01000000732800000008010801060108010c010401080104010801040108010c03080406011409060110091005100b1006