Contract con_neb_vault_int_017


Contract Code

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

Byte Code

e30000000000000000000000000800000040000000733a01000065005a01650264006401640264038d035a0365046401640464058d025a0565046401640664058d025a0665046401640764058d025a0765046401640864058d025a0865046401640964058d025a0965046401640a64058d025a0a65046401640b64058d025a0b65046401640c64058d025a0c65046401640d64058d025a0d640e5a0e640f5a0f64105a1064115a1164125a126413641467025a1365146401830165156516651665176517651764159c0664166417840483015a186514640183016515651664189c026419641a840483015a196514640183016516641b9c01641c641d840483015a1a651464018301641e641f840083015a1b651464018301651c64209c0164216409840483015a1d6514640183016515651664189c0264226423840483015a1e6424642584005a1f6426642784005a20642853002929e900000000da15636f6e5f6e65625f7661756c745f696e745f303137da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0c656d697373696f6e5f636f6e290272050000007206000000da0e746f74616c5f656d697373696f6eda0b746f74616c5f7374616b65da0d63757272656e745f7374616b65da06616374697665da0666756e646564da0a73746172745f64617465da0e73746172745f646174655f656e64da08656e645f64617465e902000000da0a636f6e5f6e6562756c61da14636f6e5f6e65625f7661756c745f6c705f303035e9050000006940fa0100da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da40653738376564353930373734326661386435306233636132373031616238653033656337343963656438303661313563646162383030613132376437663836332906da11656d697373696f6e5f636f6e7472616374da15746f74616c5f656d697373696f6e5f616d6f756e74da12746f74616c5f7374616b655f616d6f756e74da126d696e757465735f74696c6c5f7374617274da1773746172745f706572696f645f696e5f6d696e75746573da106d696e757465735f74696c6c5f656e64630600000000000000080000000600000043000000734a01000074006a01830064016b03731474026402830182017c0164036b04732474026404830182017c0264036b04733474026405830182017c0364036b04734474026406830182017c0474036b05735474026407830182017c0564036b0472647c0574046b01736c740264088301820174056a067c008301010074076a0664038301010074086a067c018301010074096a067c0283010100740a6a06740b740c6a0d7c0364098d01170083010100740e6a06740a6a018300740c6a0d7c0464098d01170083010100740f6a06740e6a018300740c6a0d7c0564098d0117008301010074086a018300640a1b00741014007411741283011b007d067828741244005d207d0774136a1474056a01830083016a1574166a177c067c07640b8d03010071fc5700741874056a01830074086a0183008302010074196a0664018301010074006a0664018301010064005300290c4e547a185661756c7420697320616c72656164792066756e6465642172010000007a20746f74616c5f656d697373696f6e5f616d6f756e74206e6f742076616c6964217a1d746f74616c5f7374616b655f616d6f756e74206e6f742076616c6964217a1d6d696e757465735f74696c6c5f7374617274206e6f742076616c6964217a2d5374616b696e67206e6565647320746f206265206f70656e20666f72206174206c6561737420322064617973217a1b6d696e757465735f74696c6c5f656e64206e6f742076616c6964212901da076d696e75746573e9640000002903da0c6d61696e5f6163636f756e74da06616d6f756e74da02746f291ada085f5f66756e646564da03676574da0e417373657274696f6e4572726f72da104d494e5f5354414b455f504552494f44da0b4d41585f52554e54494d45da0e5f5f656d697373696f6e5f636f6eda03736574da0f5f5f63757272656e745f7374616b65da105f5f746f74616c5f656d697373696f6eda0d5f5f746f74616c5f7374616b65da0c5f5f73746172745f64617465da036e6f77da086461746574696d65da0974696d6564656c7461da105f5f73746172745f646174655f656e64da0a5f5f656e645f64617465da074e45425f464545da036c656eda094f50455241544f5253da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda03637478da0663616c6c6572da0d73656e645f746f5f7661756c74da085f5f61637469766529087216000000721700000072180000007219000000721a000000721b000000da0a73696e676c655f666565da0761646472657373a900723d000000da00da0a66756e645f7661756c741a000000732c00000000041401100110011001100118010a010a010a010a0116010e010c010e010c0118010a010e01120112010a01723f00000029027205000000721f000000630200000000000000020000000500000043000000731e00000074006a017c0083016a0274036a047c0174036a0564018d0301006400530029024e2903721e000000721f0000007220000000290672340000007235000000723600000072370000007238000000da047468697329027205000000721f000000723d000000723d000000723e000000723900000036000000730400000000020e0172390000002901da0a6e65625f616d6f756e7463010000000000000003000000060000004300000073f20000007400830001007c0064016b0473167401640283018201740274036a0483006b0473347401640374036a0483009b009d0283018201740274056a0483006b0073527401640474056a0483009b009d0283018201740674076a08050019007c00370003003c007409740a7c0083020100740b6a0c740b6a0483007c00170083010100740d6a0e740f83016a1083007d0174116a04830064051b007c016406190014007d02740674076a0819007c026b0173ca740164077c029b0064087c01640919009b00640a9d0583018201740b6a04830074116a0483006b0173ee7401640b74116a0483009b00640c9d038301820164005300290d4e72010000007a204e6567617469766520616d6f756e747320617265206e6f7420616c6c6f7765647a195374616b696e67206e6f742073746172746564207965743a207a165374616b696e6720706572696f6420656e6465643a20721d000000da08656d697373696f6e7a144d6178207374616b652065786365656465643a207a0c204e454220284c6576656c20da056c6576656cfa01297a1a4d617820746f74616c207374616b652065786365656465643a207a04204e45422912da0f5f5f6173736572745f6163746976657223000000722c000000722b0000007222000000722f000000da095f5f7374616b696e67723700000072380000007239000000da0c4e45425f434f4e54524143547228000000722700000072340000007235000000da084c505f5641554c54da046c6f636b722a000000290372410000007243000000da096d61785f7374616b65723d000000723d000000723e000000da057374616b653c000000731e0000000002060110010e0110010e01100112010a0112010e011401080120011201724b00000063000000000000000002000000040000004300000073c2000000740083000100740174026a03190064016b03731c7404640283018201740574066a0783006b04733a7404640374066a0783009b009d0283018201740174026a03190074086a0783001b00640414007d0074096a07830064041b007c0014007d01740a6a0b740c6a07830083016a0d7c0174026a0364058d020100740a6a0b740e83016a0d740174026a03190074026a0364058d020100740a6a0b740f83016a10830001006401740174026a033c0064067c019b006407740c6a0783009b009d04530029084e72010000007a1741646472657373206973206e6f74207374616b696e67217a16456e642064617465206e6f7420726561636865643a20721d0000002902721f00000072200000007a0a456d697373696f6e3a20fa0120291172450000007246000000723700000072380000007223000000722c0000007230000000722200000072280000007229000000723400000072350000007226000000da087472616e7366657272470000007248000000da06756e6c6f636b2902da0d7374616b655f70657263656e74da0d757365725f656d697373696f6e723d000000723d000000723e000000da07756e7374616b654f00000073180000000002060116011e011601100110010a0112010a010e010a0172510000002901da0969735f616374697665630100000000000000010000000200000043000000731400000074006a017c00830101007402830001006400530029014e2903723a0000007227000000da0e5f5f6173736572745f6f776e657229017252000000723d000000723d000000723e000000720b0000005f000000730400000000020a01630200000000000000020000000300000043000000731e00000074006a017c0083016a027c0174036a04830201007405830001006400530029014e290672340000007235000000724d00000072370000007238000000725300000029027205000000721f000000723d000000723d000000723e000000da12656d657267656e63795f7769746864726177650000007304000000000214017254000000630000000000000000000000000200000043000000731800000074006a01830064016b02731474026402830182016400530029034e547a0f5661756c7420696e616374697665212903723a00000072220000007223000000723d000000723d000000723d000000723e00000072450000006b000000730200000000017245000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f72732129047237000000723800000072330000007223000000723d000000723d000000723d000000723e00000072530000006f0000007302000000000172530000004e2921da09696d706f72746c69627234000000da04486173687246000000da085661726961626c6572260000007229000000722a0000007228000000723a0000007221000000722b000000722f0000007230000000723100000072470000007248000000722400000072250000007233000000da085f5f6578706f7274da03737472da05666c6f6174da03696e74723f0000007239000000724b0000007251000000da04626f6f6c720b000000725400000072450000007253000000723d000000723d000000723d000000723e000000da083c6d6f64756c653e0100000073480000000401060108010c02040108010c01040108010c010c010c01040108010c01040104010401040104010201060306010401040112190601120506011012101006011005060112050804