Contract con_neb_vault_lp_002


Contract Code

1 I = importlib
2
3 staking = Hash(default_value=0)
4 locking = Hash(default_value=0)
5 levels = Hash(default_value=0)
6 con = Hash(default_value='')
7
8 active = Variable()
9
10 OPERATORS = [
11 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
12 'e787ed5907742fa8d50b3ca2701ab8e03ec749ced806a15cdab800a127d7f863'
13 ]
14
15 @construct
16 def seed():
17 con['neb'] = 'con_nebula'
18 con['key'] = 'con_neb_key001'
19 con['prx'] = 'con_neb_vault_proxy_001'
20 con['dex'] = 'con_rocketswap_official_v1_1'
21
22 levels[1] = {'level': 1, 'lp': 0, 'key': 0, 'emission': 0.375}
23 levels[2] = {'level': 2, 'lp': 18.75, 'key': 0, 'emission': 0.75}
24 levels[3] = {'level': 3, 'lp': 0, 'key': 1, 'emission': 1}
25 levels[4] = {'level': 4, 'lp': 37.5, 'key': 0, 'emission': 1.5}
26 levels[5] = {'level': 5, 'lp': 75, 'key': 0, 'emission': 3}
27 levels[6] = {'level': 6, 'lp': 150, 'key': 0, 'emission': 4}
28
29 active.set(True)
30
31 @export
32 def get_level(address: str):
33 lp_stake = staking[address, 'lp']
34 key_stake = staking[address, 'key']
35
36 return get_level_from_amount(lp_stake, key_stake)
37
38 @export
39 def get_level_from_amount(lp_amount: float, key_amount: int):
40 for i in range(10, 0, -1):
41 if levels[i] == 0:
42 continue
43
44 level = levels[i]
45 if (lp_amount >= level['lp']) and (key_amount >= level['key']):
46 return level
47
48 return levels[1]
49
50 @export
51 def show_level(address: str):
52 l = get_level(address)
53 return f'Level: {l["level"]}, LP: {l["lp"]}, KEY: {l["key"]}, Emission: {l["emission"]}'
54
55 @export
56 def stake(neb_lp_amount: float = 0, neb_key_amount: int = 0):
57 assert_active()
58
59 if neb_lp_amount > 0:
60 staking['lp'] += neb_lp_amount
61 staking[ctx.caller, 'lp'] += neb_lp_amount
62
63 I.import_module(con['dex']).transfer_liquidity_from(
64 contract=con['neb'],
65 to=ctx.this,
66 main_account=ctx.caller,
67 amount=neb_lp_amount)
68
69 if neb_key_amount > 0:
70 staking['key'] += neb_key_amount
71 staking[ctx.caller, 'key'] += neb_key_amount
72
73 I.import_module(con['key']).transfer_from(
74 main_account=ctx.caller,
75 amount=neb_key_amount,
76 to=ctx.this)
77
78 @export
79 def unstake(neb_lp_amount: float = 0, neb_key_amount: int = 0):
80 assert_active()
81
82 staked_lp = staking[ctx.caller, 'lp']
83 staked_key = staking[ctx.caller, 'key']
84
85 current_level = get_level_from_amount(staked_lp, staked_key)['level']
86 highest_level = 1
87
88 if isinstance(locking[ctx.caller], list):
89 for lock_contract in locking[ctx.caller]:
90 locked_level = locking[ctx.caller, lock_contract, 'level']
91
92 if locked_level > highest_level:
93 highest_level = locked_level
94
95 locked_lp = levels[highest_level]['lp']
96 locked_key = levels[highest_level]['key']
97
98 lp_available = staked_lp - locked_lp
99 key_available = staked_key - locked_key
100
101 assert lp_available >= neb_lp_amount, f'Only {lp_available} NEB LP available to unstake'
102 assert key_available >= neb_key_amount, f'Only {key_available} NEB KEY available to unstake'
103
104 if neb_lp_amount > 0:
105 I.import_module(con['dex']).transfer_liquidity(
106 contract=con['neb'],
107 to=ctx.caller,
108 amount=neb_lp_amount)
109
110 if neb_key_amount > 0:
111 I.import_module(con['key']).transfer(
112 amount=neb_key_amount,
113 to=ctx.caller)
114
115 staking[ctx.caller, 'lp'] -= neb_lp_amount
116 staking[ctx.caller, 'key'] -= neb_key_amount
117
118 staking['lp'] -= neb_lp_amount
119 staking['key'] -= neb_key_amount
120
121 @export
122 def lock():
123 trusted = ForeignVariable(foreign_contract=con['prx'], foreign_name='contracts')
124 assert ctx.caller in trusted.get(), f'Unknown contract {ctx.caller}'
125
126 if not isinstance(locking[ctx.signer], list):
127 locking[ctx.signer] = []
128
129 lock_list = locking[ctx.signer]
130
131 if not ctx.caller in lock_list:
132 lock_list.append(ctx.caller)
133
134 locking[ctx.signer] = lock_list
135
136 level = get_level(ctx.signer)
137
138 locking[ctx.signer, ctx.caller, 'level'] = level['level']
139
140 return level
141
142 @export
143 def unlock():
144 trusted = ForeignVariable(foreign_contract=con['prx'], foreign_name='contracts')
145 assert ctx.caller in trusted.get(), f'Unknown contract {ctx.caller}'
146
147 lock_list = locking[ctx.signer]
148
149 if ctx.caller in lock_list:
150 lock_list.remove(ctx.caller)
151
152 locking[ctx.signer] = lock_list
153 locking.clear(ctx.signer, ctx.caller)
154
155 @export
156 def set_contract(key: str, value: str):
157 con[key] = value
158 assert_owner()
159
160 @export
161 def set_levels(level: int, data: dict):
162 levels[level] = data
163 assert_owner()
164
165 @export
166 def emergency_withdraw_token(contract_name: str, amount: float):
167 I.import_module(contract_name).transfer(amount, ctx.caller)
168 assert_owner()
169
170 @export
171 def emergency_withdraw_lp(contract_name: str, amount: float):
172 I.import_module(con['dex']).transfer_liquidity(contract_name, ctx.caller, amount)
173 assert_owner()
174
175 @export
176 def enable_vault():
177 active.set(True)
178 assert_owner()
179
180 @export
181 def disable_vault():
182 active.set(False)
183 assert_owner()
184
185 def assert_active():
186 assert active.get() == True, 'Vault inactive!'
187
188 def assert_owner():
189 assert ctx.caller in OPERATORS, 'Only executable by operators!'
190

Byte Code

e30000000000000000000000000500000040000000738401000065005a01650264006401640264038d035a03650264006401640464038d035a04650264006401640564038d035a05650264066401640764038d035a0665076401640864098d025a08640a640b67025a09640c640d84005a0a650b64018301650c640e9c01640f6410840483015a0d650b64018301650e650f64119c0264126413840483015a10650b64018301650c640e9c0164146415840483015a11650b640183016433650e650f64169c0264176418840583015a12650b640183016434650e650f64169c026419641a840583015a13650b64018301641b641c840083015a14650b64018301641d641e840083015a15650b64018301650c650c641f9c0264206421840483015a16650b64018301650f651764229c0264236424840483015a18650b64018301650c650e64259c0264266427840483015a19650b64018301650c650e64259c0264286429840483015a1a650b64018301642a642b840083015a1b650b64018301642c642d840083015a1c642e642f84005a1d6430643184005a1e643253002935e900000000da14636f6e5f6e65625f7661756c745f6c705f303032da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da076c6f636b696e67da066c6576656c73da00da03636f6eda06616374697665290272050000007206000000da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000050000004300000073ae0000006401740064023c006403740064043c006405740064063c006407740064083c006409640a640a7401640b8301640c9c04740264093c00640d7401640e8301640a7401640f8301640c9c047402640d3c006410640a64096409640c9c04740264103c006411740164128301640a740164138301640c9c04740264113c0064146415640a6410640c9c04740264143c0064166417640a6411640c9c04740264163c0074036a046418830101006400530029194eda0a636f6e5f6e6562756c61da036e6562da0e636f6e5f6e65625f6b6579303031da036b6579da17636f6e5f6e65625f7661756c745f70726f78795f303031da03707278da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da03646578e90100000072010000007a05302e3337352904da056c6576656cda026c707211000000da08656d697373696f6ee9020000007a0531382e37357a04302e3735e903000000e9040000007a0433372e357a03312e35e905000000e94b000000e906000000e996000000542905da055f5f636f6eda07646563696d616cda085f5f6c6576656c73da085f5f616374697665da03736574a900722600000072260000007209000000da045f5f5f5f0e000000731a0000000001080108010801080116010a01100112010a0110011201120172270000002901da0761646472657373630100000000000000030000000300000043000000732200000074007c006401660219007d0174007c006402660219007d0274017c017c028302530029034e721800000072110000002902da095f5f7374616b696e67da156765745f6c6576656c5f66726f6d5f616d6f756e7429037228000000da086c705f7374616b65da096b65795f7374616b65722600000072260000007209000000da096765745f6c6576656c1e000000730600000000020c010c01722d0000002902da096c705f616d6f756e74da0a6b65795f616d6f756e74630200000000000000040000000400000043000000735000000078467400640164026406830344005d367d0274017c02190064026b027220710e74017c0219007d037c007c03640419006b05720e7c017c03640519006b05720e7c035300710e5700740164031900530029074ee90a0000007201000000721600000072180000007211000000e9ffffffff2902da0572616e676572230000002904722e000000722f000000da01697217000000722600000072260000007209000000722a00000025000000730e000000000212010c010201080118010801722a000000630100000000000000020000000900000043000000733400000074007c0083017d0164017c01640219009b0064037c01640419009b0064057c01640619009b0064077c01640819009b009d08530029094e7a074c6576656c3a2072170000007a062c204c503a2072180000007a072c204b45593a2072110000007a0c2c20456d697373696f6e3a2072190000002901722d00000029027228000000da016c722600000072260000007209000000da0a73686f775f6c6576656c3000000073040000000002080272350000002902da0d6e65625f6c705f616d6f756e74da0e6e65625f6b65795f616d6f756e7463020000000000000002000000060000004300000073a80000007400830001007c0064016b04725874016402050019007c00370003003c00740174026a0364026602050019007c00370003003c0074046a0574066403190083016a0774066404190074026a0874026a037c0064058d0401007c0164016b0472a474016406050019007c01370003003c00740174026a0364066602050019007c01370003003c0074046a0574066406190083016a0974026a037c0174026a0864078d0301006400530029084e720100000072180000007215000000720f00000029047205000000da02746fda0c6d61696e5f6163636f756e74da06616d6f756e74721100000029037239000000723a0000007238000000290ada0f5f5f6173736572745f6163746976657229000000da03637478da0663616c6c6572da0149da0d696d706f72745f6d6f64756c657221000000da177472616e736665725f6c69717569646974795f66726f6dda0474686973da0d7472616e736665725f66726f6d290272360000007237000000722600000072260000007209000000da057374616b65380000007318000000000206010801100116010e010e010801080110011601120172430000006302000000000000000c00000005000000430000007368010000740083000100740174026a036401660219007d02740174026a036402660219007d0374047c027c038302640319007d0464047d057405740674026a031900740783027274782e740674026a03190044005d207d06740674026a037c066403660319007d077c077c056b0472507c077d057150570074087c051900640119007d0874087c051900640219007d097c027c0818007d0a7c037c0918007d0b7c0a7c006b0573b4740964057c0a9b0064069d03830182017c0b7c016b0573cc740964057c0b9b0064079d03830182017c0064086b0472f4740a6a0b740c6409190083016a0d740c640a190074026a037c00640b8d0301007c0164086b0490017218740a6a0b740c6402190083016a0e7c0174026a03640c8d020100740174026a0364016602050019007c00380003003c00740174026a0364026602050019007c01380003003c0074016401050019007c00380003003c0074016402050019007c01380003003c0064005300290d4e72180000007211000000721700000072160000007a054f6e6c79207a1c204e4542204c5020617661696c61626c6520746f20756e7374616b657a1d204e4542204b455920617661696c61626c6520746f20756e7374616b6572010000007215000000720f000000290372050000007238000000723a0000002902723a0000007238000000290f723b0000007229000000723c000000723d000000722a000000da0a6973696e7374616e6365da095f5f6c6f636b696e67da046c6973747223000000da0e417373657274696f6e4572726f72723e000000723f0000007221000000da127472616e736665725f6c6971756964697479da087472616e73666572290c72360000007237000000da097374616b65645f6c70da0a7374616b65645f6b6579da0d63757272656e745f6c6576656cda0d686967686573745f6c6576656cda0d6c6f636b5f636f6e7472616374da0c6c6f636b65645f6c6576656cda096c6f636b65645f6c70da0a6c6f636b65645f6b6579da0c6c705f617661696c61626c65da0d6b65795f617661696c61626c65722600000072260000007209000000da07756e7374616b65480000007334000000000206010e010e010e010401100110011001080108010c010c0108010801180118010801100110010a0110010a011601160110017254000000630000000000000000030000000600000043000000739a000000740074016401190064026403640464058d047d0074026a037c006a0483006b0673327405640674026a039b009d02830182017406740774026a08190074098302734c6700740774026a083c00740774026a0819007d0174026a037c016b07726c7c016a0a74026a03830101007c01740774026a083c00740b74026a0883017d027c0264071900740774026a0874026a03640766033c007c02530029084e7213000000da09636f6e7472616374737202000000da07747275737465642904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720500000072060000007a11556e6b6e6f776e20636f6e7472616374207217000000290cda0f466f726569676e5661726961626c657221000000723c000000723d000000da03676574724700000072440000007245000000da067369676e65727246000000da06617070656e64722d0000002903da095f5f74727573746564da096c6f636b5f6c6973747217000000722600000072260000007209000000da046c6f636b660000007318000000000208010c011e0110010a010a010a010c010a010a011601725f0000006300000000000000000200000006000000430000007370000000740074016401190064026403640464058d047d0074026a037c006a0483006b0673327405640674026a039b009d0283018201740674026a0719007d0174026a037c016b0672527c016a0874026a03830101007c01740674026a073c0074066a0974026a0774026a03830201006400530029074e7213000000725500000072020000007256000000290472570000007258000000720500000072060000007a11556e6b6e6f776e20636f6e747261637420290a72590000007221000000723c000000723d000000725a00000072470000007245000000725b000000da0672656d6f7665da05636c6561722902725d000000725e000000722600000072260000007209000000da06756e6c6f636b760000007310000000000208010c011e010a010a010c010a01726200000029027211000000da0576616c756563020000000000000002000000030000004300000073120000007c0174007c003c007401830001006400530029014e29027221000000da0e5f5f6173736572745f6f776e6572290272110000007263000000722600000072260000007209000000da0c7365745f636f6e747261637482000000730400000000020801726500000029027217000000da046461746163020000000000000002000000030000004300000073120000007c0174007c003c007401830001006400530029014e290272230000007264000000290272170000007266000000722600000072260000007209000000da0a7365745f6c6576656c738800000073040000000002080172670000002902da0d636f6e74726163745f6e616d65723a000000630200000000000000020000000300000043000000731e00000074006a017c0083016a027c0174036a04830201007405830001006400530029014e2906723e000000723f0000007249000000723c000000723d000000726400000029027268000000723a000000722600000072260000007209000000da18656d657267656e63795f77697468647261775f746f6b656e8e0000007304000000000214017269000000630200000000000000020000000400000043000000732400000074006a0174026401190083016a037c0074046a057c01830301007406830001006400530029024e72150000002907723e000000723f00000072210000007248000000723c000000723d000000726400000029027268000000723a000000722600000072260000007209000000da15656d657267656e63795f77697468647261775f6c70940000007306000000000214010601726a000000630000000000000000000000000200000043000000731400000074006a016401830101007402830001006400530029024e5429037224000000722500000072640000007226000000722600000072260000007209000000da0c656e61626c655f7661756c749b000000730400000000020a01726b000000630000000000000000000000000200000043000000731400000074006a016401830101007402830001006400530029024e4629037224000000722500000072640000007226000000722600000072260000007209000000da0d64697361626c655f7661756c74a1000000730400000000020a01726c000000630000000000000000000000000200000043000000731800000074006a01830064016b02731474026402830182016400530029034e547a0f5661756c7420696e6163746976652129037224000000725a00000072470000007226000000722600000072260000007209000000723b000000a700000073020000000001723b000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904723c000000723d000000da094f50455241544f5253724700000072260000007226000000722600000072090000007264000000ab0000007302000000000172640000004e290272010000007201000000290272010000007201000000291fda09696d706f72746c6962723e000000da04486173687229000000724500000072230000007221000000da085661726961626c657224000000726d0000007227000000da085f5f6578706f7274da03737472722d000000da05666c6f6174da03696e74722a000000723500000072430000007254000000725f00000072620000007265000000da046469637472670000007269000000726a000000726b000000726c000000723b00000072640000007226000000722600000072260000007209000000da083c6d6f64756c653e010000007344000000040106010801060108010e020e010c01020106030810060110060601120a060110070601140f0601141d1010100c06011205060112050601120506011206100610060804