Contract con_neb_vault_lp_005


Contract Code


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

Byte Code

e30000000000000000000000000500000040000000739e01000065005a01650264006401640264038d035a03650264006401640464038d035a04650264006401640564038d035a05650264066401640764038d035a0665076401640864098d025a0865076401640a64098d025a09640b5a0a640c640d67025a0b640e640f84005a0c650d64018301650e64109c0164116412840483015a0f650d64018301650e64109c0164136414840483015a10650d6401830164356511651264159c0264166417840583015a13650d6401830164366511651264159c0264186419840583015a14650d64018301641a641b840083015a15650d64018301641c641d840083015a16650d64018301650e650e641e9c02641f6420840483015a17650d640183016512651864219c0264226423840483015a19650d64018301650e64249c0164256426840483015a1a650d64018301650e64249c0164276428840483015a1b650d64018301650e651164299c02642a642b840483015a1c650d64018301650e651164299c02642c642d840483015a1d650d64018301651e642e9c01642f640a840483015a1f6430643184005a206432643384005a21643453002937e900000000da14636f6e5f6e65625f7661756c745f6c705f303035da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da076c6f636b696e67da066c6576656c73da00da03636f6eda0774727573746564290272050000007206000000da06616374697665da4039613132353534633230393835363764323261616139623738376437336236303664326632303434613630323138366333623961663635663663353863666166da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000050000004300000073b00000006401740064023c006403740064043c006405740064063c00640764086408740164098301640a9c04740264073c00640b7401640c830164087401640d8301640a9c047402640b3c00640e640864076407640a9c047402640e3c00640f7401641083016408740164118301640a9c047402640f3c00641264136408640e640a9c04740264123c00641464156408640f640a9c04740264143c0074036a0467008301010074056a046416830101006400530029174eda0a636f6e5f6e6562756c61da036e6562da0e636f6e5f6e65625f6b6579303031da036b6579da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da03646578e90100000072010000007a05302e3337352904da056c6576656cda026c707213000000da08656d697373696f6ee9020000007a0531382e37357a04302e3735e903000000e9040000007a0433372e357a03312e35e905000000e94b000000e906000000e996000000542906da055f5f636f6eda07646563696d616cda085f5f6c6576656c73da095f5f74727573746564da03736574da085f5f616374697665a900722700000072270000007209000000da045f5f5f5f10000000731a000000000108010801080116010a01100112010a011001120112010a0172280000002901da0761646472657373630100000000000000050000000400000043000000736800000074007c006401660219007d0174007c006402660219007d0278467401640364046406830344005d367d0374027c03190064046b027238712674027c0319007d047c017c04640119006b0572267c027c04640219006b0572267c04530071265700740264051900530029074e72180000007213000000e90a00000072010000007216000000e9ffffffff2903da095f5f7374616b696e67da0572616e6765722300000029057229000000da086c705f7374616b65da096b65795f7374616b65da01697217000000722700000072270000007209000000da096765745f6c6576656c20000000731200000000020c010c0112010c0102010801180108017231000000630100000000000000020000000900000043000000733400000074007c0083017d0164017c01640219009b0064037c01640419009b0064057c01640619009b0064077c01640819009b009d08530029094e7a074c6576656c3a2072170000007a062c204c503a2072180000007a072c204b45593a2072130000007a0c2c20456d697373696f6e3a2072190000002901723100000029027229000000da016c722700000072270000007209000000da0a73686f775f6c6576656c2d00000073040000000002080272330000002902da0d6e65625f6c705f616d6f756e74da0e6e65625f6b65795f616d6f756e7463020000000000000002000000060000004300000073c80000007400830001007c0064016b05731674016402830182017c0164016b05732674016402830182017c0064016b04727874026403050019007c00370003003c00740274036a0464036602050019007c00370003003c0074056a0674076404190083016a0874076405190074036a0974036a047c0064068d0401007c0164016b0472c474026407050019007c01370003003c00740274036a0464076602050019007c01370003003c0074056a0674076407190083016a0a74036a047c0174036a0964088d0301006400530029094e72010000007a204e6567617469766520616d6f756e747320617265206e6f7420616c6c6f77656472180000007215000000721100000029047205000000da02746fda0c6d61696e5f6163636f756e74da06616d6f756e7472130000002903723700000072380000007236000000290bda0f5f5f6173736572745f616374697665da0e417373657274696f6e4572726f72722c000000da03637478da0663616c6c6572da0149da0d696d706f72745f6d6f64756c657221000000da177472616e736665725f6c69717569646974795f66726f6dda0474686973da0d7472616e736665725f66726f6d290272340000007235000000722700000072270000007209000000da057374616b6535000000731c00000000020601100110010801100116010e010e010801080110011601120172420000006302000000000000000b000000050000004300000073840100007400830001007c0064016b05731674016402830182017c0164016b0573267401640283018201740274036a046403660219007d02740274036a046404660219007d0364017d0464017d057405740674036a0419007407830272a6784a740674036a04190044005d3c7d06740674036a047c066403660319007d07740674036a047c066404660319007d087c077c046b0472967c077d047c087c056b0472667c087d05716657007c027c0418007d097c037c0518007d0a7c097c006b0573ce740164057c099b0064069d03830182017c0a7c016b0573e6740164057c0a9b0064079d03830182017c0064016b049001721074086a09740a6408190083016a0b740a6409190074036a047c00640a8d0301007c0164016b049001723474086a09740a6404190083016a0c7c0174036a04640b8d020100740274036a0464036602050019007c00380003003c00740274036a0464046602050019007c01380003003c0074026403050019007c00380003003c0074026404050019007c01380003003c0064005300290c4e72010000007a204e6567617469766520616d6f756e747320617265206e6f7420616c6c6f776564721800000072130000007a054f6e6c79207a1c204e4542204c5020617661696c61626c6520746f20756e7374616b657a1d204e4542204b455920617661696c61626c6520746f20756e7374616b65721500000072110000002903720500000072360000007238000000290272380000007236000000290d7239000000723a000000722c000000723b000000723c000000da0a6973696e7374616e6365da095f5f6c6f636b696e67da046c697374723d000000723e0000007221000000da127472616e736665725f6c6971756964697479da087472616e73666572290b72340000007235000000da097374616b65645f6c70da0a7374616b65645f6b6579da0a686967686573745f6c70da0b686967686573745f6b6579da0d6c6f636b5f636f6e7472616374da096c6f636b65645f6c70da0a6c6f636b65645f6b6579da0c6c705f617661696c61626c65da0d6b65795f617661696c61626c65722700000072270000007209000000da07756e7374616b6547000000733a00000000020601100110010e010e01040104011001100110011001080104010801080108010801180118010a01100110010a0110010a011601160110017251000000630000000000000000040000000500000043000000738e00000074006a017d0074006a027d017c0174036a0483006b067326740564017c019b009d0283018201740674077c00190074088302733c670074077c003c0074077c0019007d027c017c026b0772567c026a097c01830101007c0274077c003c00740a7c0083017d037c036402190074077c007c01640266033c007c036403190074077c007c01640366033c007c03530029044e7a11556e6b6e6f776e20636f6e74726163742072180000007213000000290b723b000000da067369676e6572723c0000007224000000da03676574723a000000724300000072440000007245000000da06617070656e6472310000002904da0c757365725f61646472657373da0e7661756c745f636f6e7472616374da096c6f636b5f6c6973747217000000722700000072270000007209000000da046c6f636b68000000731c0000000002060106010e010c010e010801080108010a0108010801120112017258000000630000000000000000010000000500000043000000737000000074006a0174026a0383006b06731e7404640174006a019b009d0283018201740574006a0619007d0074006a017c006b06723e7c006a0774006a01830101007c00740574006a063c006402740574006a0674006a01640366033c006402740574006a0674006a01640466033c006400530029054e7a11556e6b6e6f776e20636f6e7472616374207201000000721800000072130000002908723b000000723c00000072240000007253000000723a00000072440000007252000000da0672656d6f766529017257000000722700000072270000007209000000da06756e6c6f636b7a000000730e00000000021e010a010a010c010a011201725a00000029027213000000da0576616c756563020000000000000002000000030000004300000073120000007c0174007c003c007401830001006400530029014e29027221000000da0e5f5f6173736572745f6f776e657229027213000000725b000000722700000072270000007209000000da0c7365745f636f6e747261637485000000730400000000020801725d00000029027217000000da046461746163020000000000000002000000030000004300000073120000007c0174007c003c007401830001006400530029014e29027223000000725c00000029027217000000725e000000722700000072270000007209000000da0a7365745f6c6576656c738b000000730400000000020801725f0000002901da0d636f6e74726163745f6e616d65630100000000000000020000000200000043000000733a00000074006a0174026b027312740364018301820174046a0583007d017c007c016b0772367c016a067c008301010074046a077c01830101006400530029024e7a294f6e6c792076616c696461746f722063616e20616464207472757374656420636f6e747261637473212908723b000000723c000000da0956414c494441544f52723a000000722400000072530000007254000000722500000029027260000000da11747275737465645f636f6e747261637473722700000072270000007209000000da0f6164645f76616c69645f7661756c7491000000730a00000000021201080108010a017263000000630100000000000000020000000200000043000000733a00000074006a0174026b027312740364018301820174046a0583007d017c007c016b0672367c016a067c008301010074046a077c01830101006400530029024e7a2c4f6e6c792076616c696461746f722063616e2072656d6f7665207472757374656420636f6e747261637473212908723b000000723c0000007261000000723a0000007224000000725300000072590000007225000000290272600000007262000000722700000072270000007209000000da1272656d6f76655f76616c69645f7661756c749a000000730a00000000021201080108010a017264000000290272600000007238000000630200000000000000020000000300000043000000731e00000074006a017c0083016a027c0174036a04830201007405830001006400530029014e2906723d000000723e0000007247000000723b000000723c000000725c000000290272600000007238000000722700000072270000007209000000da18656d657267656e63795f77697468647261775f746f6b656ea30000007304000000000214017265000000630200000000000000020000000400000043000000732400000074006a0174026401190083016a037c0074046a057c01830301007406830001006400530029024e72150000002907723d000000723e00000072210000007246000000723b000000723c000000725c000000290272600000007238000000722700000072270000007209000000da15656d657267656e63795f77697468647261775f6c70a9000000730600000000021401060172660000002901da0969735f616374697665630100000000000000010000000200000043000000731400000074006a017c00830101007402830001006400530029014e290372260000007225000000725c00000029017267000000722700000072270000007209000000720c000000b0000000730400000000020a01630000000000000000000000000200000043000000731800000074006a01830064016b02731474026402830182016400530029034e547a0f5661756c7420696e61637469766521290372260000007253000000723a00000072270000007227000000722700000072090000007239000000b6000000730200000000017239000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904723b000000723c000000da094f50455241544f5253723a0000007227000000722700000072270000007209000000725c000000ba00000073020000000001725c0000004e2902720100000072010000002902720100000072010000002922da09696d706f72746c6962723d000000da0448617368722c000000724400000072230000007221000000da085661726961626c6572240000007226000000726100000072680000007228000000da085f5f6578706f7274da0373747272310000007233000000da05666c6f6174da03696e74724200000072510000007258000000725a000000725d000000da0464696374725f0000007263000000726400000072650000007266000000da04626f6f6c720c0000007239000000725c0000007227000000722700000072270000007209000000da083c6d6f64756c653e01000000734c000000040106010801060108010e020e010c010c0104010201060308100601100c0601100706011411060114201012100b060112050601120506011008060110080601120506011206060110050804