Contract con_neb_vault_int_001


Contract Code

1 I = importlib
2
3 staking = Hash(default_value=0)
4
5 emission_con = Variable()
6 total_emission = Variable()
7
8 total_stake = Variable()
9 current_stake = Variable()
10
11 active = Variable()
12 funded = Variable()
13
14 start_date = Variable()
15 start_date_end = Variable()
16 end_date = Variable()
17
18 NEB_FEE = 2
19 NEB_CONTRACT = 'con_nebula'
20 LP_VAULT = 'con_neb_vault_lp_002'
21 MIN_STAKE_PERIOD = 60
22 MAX_RUNTIME = 129600
23
24 OPERATORS = [
25 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
26 'e787ed5907742fa8d50b3ca2701ab8e03ec749ced806a15cdab800a127d7f863'
27 ]
28
29 @export
30 def fund_vault(emission_contract: str, total_emission_amount: float, total_stake_amount: float,
31 minutes_till_start: int, start_period_in_minutes: int, minutes_till_end: int):
32
33 assert funded.get() != True, 'Vault is already funded!'
34 assert total_emission_amount > 0, 'total_emission_amount not valid!'
35 assert total_stake_amount > 0, 'total_stake_amount not valid!'
36 assert minutes_till_start > 0, 'minutes_till_start not valid!'
37 assert start_period_in_minutes >= MIN_STAKE_PERIOD, 'Staking needs to be open for at least 2 days!'
38 assert minutes_till_end > 0 and minutes_till_end <= MAX_RUNTIME, 'minutes_till_end not valid!'
39
40 emission_con.set(emission_contract)
41
42 current_stake.set(0)
43 total_emission.set(total_emission_amount)
44 total_stake.set(total_stake_amount)
45
46 start_date.set(now + datetime.timedelta(minutes=minutes_till_start))
47 start_date_end.set(start_date.get() + datetime.timedelta(minutes=start_period_in_minutes))
48 end_date.set(start_date_end.get() + datetime.timedelta(minutes=minutes_till_end))
49
50 single_fee = (total_emission.get() / 100 * NEB_FEE) / len(OPERATORS)
51
52 for address in OPERATORS:
53 I.import_module(emission_con.get()).transfer_from(
54 main_account=ctx.caller,
55 amount=single_fee,
56 to=address)
57
58 send_to_vault(emission_con.get(), total_emission.get())
59
60 active.set(True)
61 funded.set(True)
62
63 @export
64 def send_to_vault(contract: str, amount: float):
65 I.import_module(contract).transfer_from(
66 main_account=ctx.caller,
67 amount=amount,
68 to=ctx.this)
69
70 @export
71 def stake(neb_amount: float):
72 assert_active()
73
74 assert now > start_date.get(), f'Staking not started yet: {start_date.get()}'
75 assert now < start_date_end.get(), f'Staking period ended: {start_date_end.get()}'
76
77 staking[ctx.caller] += neb_amount
78 send_to_vault(NEB_CONTRACT, neb_amount)
79 current_stake.set(current_stake.get() + neb_amount)
80
81 level = I.import_module(LP_VAULT).lock()
82
83 max_stake = total_stake.get() / 100 * level['emission']
84
85 assert staking[ctx.caller] <= max_stake, f'Max stake exceeded: {max_stake} NEB (Level {level["level"]})'
86 assert current_stake.get() <= total_stake.get(), f'Max total stake exceeded: {total_stake.get()} NEB'
87
88 @export
89 def unstake():
90 assert_active()
91
92 assert staking[ctx.caller] != 0, f'Address is not staking!'
93 assert now > end_date.get(), f'End date not reached: {end_date.get()}'
94
95 stake_percent = staking[ctx.caller] / current_stake.get() * 100
96 user_emission = total_emission.get() / 100 * stake_percent
97
98 I.import_module(emission_con.get()).transfer(
99 amount=user_emission,
100 to=ctx.caller)
101
102 I.import_module(NEB_CONTRACT).transfer(
103 amount=staking[ctx.caller],
104 to=ctx.caller)
105
106 staking.clear(ctx.caller)
107
108 I.import_module(LP_VAULT).unlock()
109
110 return f'Emission: {user_emission} {emission_con.get()}'
111
112 @export
113 def enable_vault():
114 active.set(True)
115 assert_owner()
116
117 @export
118 def disable_vault():
119 active.set(False)
120 assert_owner()
121
122 @export
123 def emergency_withdraw(contract: str, amount: float):
124 I.import_module(contract).transfer(amount, ctx.caller)
125 assert_owner()
126
127 def assert_active():
128 assert active.get() == True, 'Vault inactive!'
129
130 def assert_owner():
131 assert ctx.caller in OPERATORS, 'Only executable by operators!'

Byte Code

e30000000000000000000000000800000040000000734401000065005a01650264006401640264038d035a0365046401640464058d025a0565046401640664058d025a0665046401640764058d025a0765046401640864058d025a0865046401640964058d025a0965046401640a64058d025a0a65046401640b64058d025a0b65046401640c64058d025a0c65046401640d64058d025a0d640e5a0e640f5a0f64105a1064115a1164125a126413641467025a1365146401830165156516651665176517651764159c0664166417840483015a186514640183016515651664189c026419641a840483015a196514640183016516641b9c01641c641d840483015a1a651464018301641e641f840083015a1b65146401830164206421840083015a1c65146401830164226423840083015a1d6514640183016515651664189c0264246425840483015a1e6426642784005a1f6428642984005a20642a5300292be900000000da15636f6e5f6e65625f7661756c745f696e745f303031da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0c656d697373696f6e5f636f6e290272050000007206000000da0e746f74616c5f656d697373696f6eda0b746f74616c5f7374616b65da0d63757272656e745f7374616b65da06616374697665da0666756e646564da0a73746172745f64617465da0e73746172745f646174655f656e64da08656e645f64617465e902000000da0a636f6e5f6e6562756c61da14636f6e5f6e65625f7661756c745f6c705f303032e93c0000006940fa0100da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da40653738376564353930373734326661386435306233636132373031616238653033656337343963656438303661313563646162383030613132376437663836332906da11656d697373696f6e5f636f6e7472616374da15746f74616c5f656d697373696f6e5f616d6f756e74da12746f74616c5f7374616b655f616d6f756e74da126d696e757465735f74696c6c5f7374617274da1773746172745f706572696f645f696e5f6d696e75746573da106d696e757465735f74696c6c5f656e64630600000000000000080000000600000043000000734a01000074006a01830064016b03731474026402830182017c0164036b04732474026404830182017c0264036b04733474026405830182017c0364036b04734474026406830182017c0474036b05735474026407830182017c0564036b0472647c0574046b01736c740264088301820174056a067c008301010074076a0664038301010074086a067c018301010074096a067c0283010100740a6a06740b740c6a0d7c0364098d01170083010100740e6a06740a6a018300740c6a0d7c0464098d01170083010100740f6a06740e6a018300740c6a0d7c0564098d0117008301010074086a018300640a1b00741014007411741283011b007d067828741244005d207d0774136a1474056a01830083016a1574166a177c067c07640b8d03010071fc5700741874056a01830074086a0183008302010074196a0664018301010074006a0664018301010064005300290c4e547a185661756c7420697320616c72656164792066756e6465642172010000007a20746f74616c5f656d697373696f6e5f616d6f756e74206e6f742076616c6964217a1d746f74616c5f7374616b655f616d6f756e74206e6f742076616c6964217a1d6d696e757465735f74696c6c5f7374617274206e6f742076616c6964217a2d5374616b696e67206e6565647320746f206265206f70656e20666f72206174206c6561737420322064617973217a1b6d696e757465735f74696c6c5f656e64206e6f742076616c6964212901da076d696e75746573e9640000002903da0c6d61696e5f6163636f756e74da06616d6f756e74da02746f291ada085f5f66756e646564da03676574da0e417373657274696f6e4572726f72da104d494e5f5354414b455f504552494f44da0b4d41585f52554e54494d45da0e5f5f656d697373696f6e5f636f6eda03736574da0f5f5f63757272656e745f7374616b65da105f5f746f74616c5f656d697373696f6eda0d5f5f746f74616c5f7374616b65da0c5f5f73746172745f64617465da036e6f77da086461746574696d65da0974696d6564656c7461da105f5f73746172745f646174655f656e64da0a5f5f656e645f64617465da074e45425f464545da036c656eda094f50455241544f5253da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda03637478da0663616c6c6572da0d73656e645f746f5f7661756c74da085f5f61637469766529087216000000721700000072180000007219000000721a000000721b000000da0a73696e676c655f666565da0761646472657373a900723d000000da00da0a66756e645f7661756c741a000000732c00000000041401100110011001100118010a010a010a010a0116010e010c010e010c0118010a010e01120112010a01723f00000029027205000000721f000000630200000000000000020000000500000043000000731e00000074006a017c0083016a0274036a047c0174036a0564018d0301006400530029024e2903721e000000721f0000007220000000290672340000007235000000723600000072370000007238000000da047468697329027205000000721f000000723d000000723d000000723e000000723900000036000000730400000000020e0172390000002901da0a6e65625f616d6f756e7463010000000000000003000000060000004300000073e2000000740083000100740174026a0383006b0473247404640174026a0383009b009d0283018201740174056a0383006b0073427404640274056a0383009b009d0283018201740674076a08050019007c00370003003c007409740a7c0083020100740b6a0c740b6a0383007c00170083010100740d6a0e740f83016a1083007d0174116a03830064031b007c016404190014007d02740674076a0819007c026b0173ba740464057c029b0064067c01640719009b0064089d0583018201740b6a03830074116a0383006b0173de7404640974116a0383009b00640a9d038301820164005300290b4e7a195374616b696e67206e6f742073746172746564207965743a207a165374616b696e6720706572696f6420656e6465643a20721d000000da08656d697373696f6e7a144d6178207374616b652065786365656465643a207a0c204e454220284c6576656c20da056c6576656cfa01297a1a4d617820746f74616c207374616b652065786365656465643a207a04204e45422912da0f5f5f6173736572745f616374697665722c000000722b00000072220000007223000000722f000000da095f5f7374616b696e67723700000072380000007239000000da0c4e45425f434f4e54524143547228000000722700000072340000007235000000da084c505f5641554c54da046c6f636b722a000000290372410000007243000000da096d61785f7374616b65723d000000723d000000723e000000da057374616b653c000000731c000000000206010e0110010e01100112010a0112010e011401080120011201724b00000063000000000000000002000000040000004300000073c4000000740083000100740174026a03190064016b03731c7404640283018201740574066a0783006b04733a7404640374066a0783009b009d0283018201740174026a03190074086a0783001b00640414007d0074096a07830064041b007c0014007d01740a6a0b740c6a07830083016a0d7c0174026a0364058d020100740a6a0b740e83016a0d740174026a03190074026a0364058d02010074016a0f74026a0383010100740a6a0b741083016a118300010064067c019b006407740c6a0783009b009d04530029084e72010000007a1741646472657373206973206e6f74207374616b696e67217a16456e642064617465206e6f7420726561636865643a20721d0000002902721f00000072200000007a0a456d697373696f6e3a20fa0120291272450000007246000000723700000072380000007223000000722c0000007230000000722200000072280000007229000000723400000072350000007226000000da087472616e736665727247000000da05636c6561727248000000da06756e6c6f636b2902da0d7374616b655f70657263656e74da0d757365725f656d697373696f6e723d000000723d000000723e000000da07756e7374616b654e00000073180000000002060116011e011601100110010a0112010a010c010e017252000000630000000000000000000000000200000043000000731400000074006a016401830101007402830001006400530029024e542903723a0000007227000000da0e5f5f6173736572745f6f776e6572723d000000723d000000723d000000723e000000da0c656e61626c655f7661756c745e000000730400000000020a017254000000630000000000000000000000000200000043000000731400000074006a016401830101007402830001006400530029024e462903723a00000072270000007253000000723d000000723d000000723d000000723e000000da0d64697361626c655f7661756c7464000000730400000000020a017255000000630200000000000000020000000300000043000000731e00000074006a017c0083016a027c0174036a04830201007405830001006400530029014e290672340000007235000000724d00000072370000007238000000725300000029027205000000721f000000723d000000723d000000723e000000da12656d657267656e63795f77697468647261776a0000007304000000000214017256000000630000000000000000000000000200000043000000731800000074006a01830064016b02731474026402830182016400530029034e547a0f5661756c7420696e616374697665212903723a00000072220000007223000000723d000000723d000000723d000000723e000000724500000070000000730200000000017245000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f72732129047237000000723800000072330000007223000000723d000000723d000000723d000000723e0000007253000000740000007302000000000172530000004e2921da09696d706f72746c69627234000000da04486173687246000000da085661726961626c6572260000007229000000722a0000007228000000723a0000007221000000722b000000722f0000007230000000723100000072470000007248000000722400000072250000007233000000da085f5f6578706f7274da03737472da05666c6f6174da03696e74723f0000007239000000724b000000725200000072540000007255000000725600000072450000007253000000723d000000723d000000723d000000723e000000da083c6d6f64756c653e0100000073480000000401060108010c02040108010c01040108010c010c010c01040108010c01040104010401040104010201060306010401040112190601120506011011101010061006060112050804