Contract con_rtau_vault_2


Contract Code


  
1 # _ _ _ _ _ _ _ _
2 # | \ | | | | | | | | | | | | \ \ / / | | |
3 # | \| | _| | _ _| | _ | | _| |_ _ _ _ _| | \ \ / /_ _ _ _| | |_
4 # | . ` |/ _ \ '_ \| | | | |/ _` | | | \ \/ / / _ \ '| '_ \ / _` | | \ \/ / _` | | | | | |
5 # | |\ | / |_) | |_| | | (_| | | | > <| || / | | | | | (_| | | \ / (_| | |_| | | |_
6 # |_| \_|\_|_./ \,_|_|\,_| |/_/\_\\\_|_| |_| |_|\,_|_| \/ \,_|\,_|_|\|
7 #
8 # Version 1.6
9
10 I = importlib
11
12 staking = Hash(default_value=0.0)
13 payouts = Hash(default_value=0.0)
14
15 stake_con = Variable()
16 emission_con = Variable()
17
18 total_emission = Variable()
19 total_stake = Variable()
20
21 current_stake = Variable()
22 max_single_stake = Variable()
23
24 creator_addr = Variable()
25 creator_lock = Variable()
26
27 start_date = Variable()
28 start_date_end = Variable()
29 end_date = Variable()
30
31 funded = Variable()
32
33 MIN_START_TIME = 5
34 MAX_START_TIME = 10080
35
36 MIN_STAKE_TIME = 1440
37 MAX_STAKE_TIME = 10080
38
39 MIN_LOCK_TIME = 1440
40 MAX_LOCK_TIME = 518400
41
42 NEB_FEE = 2
43 NEB_FEE_DISCOUNT = 0.2
44 NEB_INSTANT_FEE = 5000
45
46 NEB_CONTRACT = 'con_nebula'
47 NEB_KEY_CONTRACT = 'con_neb_key001'
48
49 @export
50 def fund_vault(stake_contract: str, total_stake_amount: float, emission_contract: str, total_emission_amount: float,
51 minutes_till_start: int, start_period_in_minutes: int, minutes_till_end: int,
52 max_single_stake_percent: float, creator_lock_amount: float = 0.0):
53
54 assert funded.get() != True, 'Vault is already funded!'
55
56 assert isinstance(total_stake_amount, decimal), 'Type of total_stake_amount must be float'
57 assert isinstance(total_emission_amount, decimal), 'Type of total_emission_amount must be float'
58 assert isinstance(max_single_stake_percent, decimal), 'Type of max_single_stake_percent must be float'
59 assert isinstance(creator_lock_amount, decimal), 'Type of creator_lock_amount must be float'
60 assert isinstance(minutes_till_start, int), 'Type of minutes_till_start must be int'
61 assert isinstance(start_period_in_minutes, int), 'Type of start_period_in_minutes must be int'
62 assert isinstance(minutes_till_end, int), 'Type of minutes_till_end must be int'
63
64 assert total_stake_amount > 0, 'Total stake amount must be > 0'
65 assert total_emission_amount > 0, 'Total emission amount must be > 0'
66
67 assert creator_lock_amount >= 0, 'Creator lock amount must be >= 0'
68
69 assert max_single_stake_percent > 0, 'Maximum single stake percent must be > 0'
70 assert max_single_stake_percent < 100, 'Maximum single stake percent must be < 100'
71
72 assert minutes_till_start >= MIN_START_TIME, f'Minimum time from vault start to staking start: {MIN_START_TIME} minutes'
73 assert minutes_till_start <= MAX_START_TIME, f'Maximum time from vault start to staking start: {MAX_START_TIME} minutes'
74
75 assert start_period_in_minutes >= MIN_STAKE_TIME, f'Minimum time from staking start to staking end: {MIN_STAKE_TIME / 60} hours'
76 assert start_period_in_minutes <= MAX_STAKE_TIME, f'Maximum time from staking start to staking end: {MAX_STAKE_TIME / 60 / 24} days'
77
78 assert minutes_till_end >= MIN_LOCK_TIME, f'Minimum time from staking end to vault end: {MIN_LOCK_TIME / 60} hours'
79 assert minutes_till_end <= MAX_LOCK_TIME, f'Maximum time from staking end to vault end: {MAX_LOCK_TIME / 60 / 24} days'
80
81 sc = I.import_module(stake_contract)
82 ec = I.import_module(emission_contract)
83
84 stake_con.set(stake_contract)
85 emission_con.set(emission_contract)
86
87 creator_addr.set(ctx.caller)
88 creator_lock.set(creator_lock_amount)
89
90 current_stake.set(decimal(0))
91 total_stake.set(total_stake_amount)
92 total_emission.set(total_emission_amount)
93 max_single_stake.set(total_stake_amount / 100 * max_single_stake_percent)
94
95 start_date.set(now + datetime.timedelta(minutes=minutes_till_start))
96 start_date_end.set(start_date.get() + datetime.timedelta(minutes=start_period_in_minutes))
97 end_date.set(start_date_end.get() + datetime.timedelta(minutes=minutes_till_end))
98
99 neb_key_balances = ForeignHash(foreign_contract=NEB_KEY_CONTRACT, foreign_name='balances')
100
101 if neb_key_balances[ctx.caller] and neb_key_balances[ctx.caller] >= 1:
102 discount = NEB_FEE_DISCOUNT
103 else:
104 discount = 0
105
106 fee = total_emission.get() / 100 * (decimal(NEB_FEE) - decimal(discount))
107 total_amount = total_emission.get() + fee + creator_lock.get()
108
109 send_to_vault(emission_con.get(), total_amount)
110
111 treasury = ForeignVariable(foreign_contract=NEB_CONTRACT, foreign_name='vault_contract')
112 assert treasury.get(), 'Treasury contract not set!'
113
114 I.import_module(emission_con.get()).transfer(
115 to=treasury.get(),
116 amount=fee)
117
118 I.import_module(NEB_CONTRACT).transfer_from(
119 main_account=ctx.caller,
120 amount=NEB_INSTANT_FEE,
121 to='NEBULA_BURN_ADDRESS')
122
123 funded.set(True)
124
125 def send_to_vault(contract: str, amount: float):
126 I.import_module(contract).transfer_from(
127 main_account=ctx.caller,
128 amount=amount,
129 to=ctx.this)
130
131 @export
132 def stake(amount: float):
133 assert amount > 0, 'Negative amounts are not allowed'
134 assert isinstance(amount, decimal), 'amount must be a float'
135 assert now > start_date.get(), f'Staking not started yet: {start_date.get()}'
136 assert now < start_date_end.get(), f'Staking period ended: {start_date_end.get()}'
137
138 staking[ctx.caller] += amount
139 send_to_vault(stake_con.get(), amount)
140 current_stake.set(current_stake.get() + amount)
141
142 assert staking[ctx.caller] <= max_single_stake.get(), f'Max user stake exceeded: {max_single_stake.get()}'
143 assert current_stake.get() <= total_stake.get(), f'Max total stake exceeded: {total_stake.get()}'
144
145 @export
146 def unstake():
147 assert staking[ctx.caller] > 0, f'Address is not staking!'
148 assert now > end_date.get(), f'End date not reached: {end_date.get()}'
149
150 stake_percent = staking[ctx.caller] / current_stake.get() * 100
151 user_emission = total_emission.get() / 100 * stake_percent
152
153 I.import_module(emission_con.get()).transfer(amount=user_emission, to=ctx.caller)
154 I.import_module(stake_con.get()).transfer(amount=staking[ctx.caller], to=ctx.caller)
155
156 staking[ctx.caller] = decimal(0)
157 payouts[ctx.caller] = user_emission
158
159 return f'Emission: {user_emission} {emission_con.get()}'
160
161 @export
162 def payout_only_stake(amount: float):
163 assert staking[ctx.caller] > 0, f'Address is not staking!'
164 assert isinstance(amount, decimal), 'amount must be a float'
165 assert now > end_date.get(), f'End date not reached: {end_date.get()}'
166 assert amount <= staking[ctx.caller], f'Max unstake amount is {staking[ctx.caller]}'
167
168 I.import_module(stake_con.get()).transfer(amount=amount, to=ctx.caller)
169
170 current_stake.set(current_stake.get() - amount)
171
172 staking[ctx.caller] -= amount
173 payouts[ctx.caller] = decimal(0)
174
175 return f'Remaining Stake: {staking[ctx.caller]} {stake_con.get()}'
176
177 @export
178 def pay_back_locked_creator_tokens(pay_to_address: str):
179 assert now > end_date.get(), f'End date not reached: {end_date.get()}'
180 assert creator_addr.get() == ctx.caller, 'You are not the vault creator!'
181 assert creator_lock.get() > 0, 'No creator funds locked!'
182
183 I.import_module(emission_con.get()).transfer(amount=creator_lock.get(), to=pay_to_address)

Byte Code

e30000000000000000000000000c00000040000000737c01000065005a0165026503640083016401640264038d035a0465026503640083016401640464038d035a0565066401640564068d025a0765066401640764068d025a0865066401640864068d025a0965066401640964068d025a0a65066401640a64068d025a0b65066401640b64068d025a0c65066401640c64068d025a0d65066401640d64068d025a0e65066401640e64068d025a0f65066401640f64068d025a1065066401641064068d025a1165066401641164068d025a1264125a1364135a1464145a1564135a1664145a1764155a1864165a196503641783015a1a64185a1b64195a1c641a5a1d651e640183016503640083016601651f6520651f652065216521652165206520641b9c09641c641d840583015a22651f6520641e9c02641f642084045a23651e64018301652064219c0164226423840483015a24651e6401830164246425840083015a25651e64018301652064219c0164266427840483015a26651e64018301651f64289c016429642a840483015a27642b5300292c7a03302e30da10636f6e5f727461755f7661756c745f32da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da077061796f757473da097374616b655f636f6e290272040000007205000000da0c656d697373696f6e5f636f6eda0e746f74616c5f656d697373696f6eda0b746f74616c5f7374616b65da0d63757272656e745f7374616b65da106d61785f73696e676c655f7374616b65da0c63726561746f725f61646472da0c63726561746f725f6c6f636bda0a73746172745f64617465da0e73746172745f646174655f656e64da08656e645f64617465da0666756e646564e905000000696027000069a00500006900e90700e9020000007a03302e326988130000da0a636f6e5f6e6562756c61da0e636f6e5f6e65625f6b65793030312909da0e7374616b655f636f6e7472616374da12746f74616c5f7374616b655f616d6f756e74da11656d697373696f6e5f636f6e7472616374da15746f74616c5f656d697373696f6e5f616d6f756e74da126d696e757465735f74696c6c5f7374617274da1773746172745f706572696f645f696e5f6d696e75746573da106d696e757465735f74696c6c5f656e64da186d61785f73696e676c655f7374616b655f70657263656e74da1363726561746f725f6c6f636b5f616d6f756e74630900000000000000100000000600000043000000732803000074006a01830064016b037314740264028301820174037c01740483027326740264038301820174037c03740483027338740264048301820174037c0774048302734a740264058301820174037c0874048302735c740264068301820174037c0474058302736e740264078301820174037c05740583027380740264088301820174037c0674058302739274026409830182017c01640a6b0473a27402640b830182017c03640a6b0473b27402640c830182017c08640a6b0573c27402640d830182017c07640a6b0473d27402640e830182017c07640f6b0073e274026410830182017c0474066b0573fa7402641174069b0064129d03830182017c0474076b01900173147402641374079b0064129d03830182017c0574086b059001733274026414740864151b009b0064169d03830182017c0574096b019001735474026417740964151b0064181b009b0064199d03830182017c06740a6b05900173727402641a740a64151b009b0064169d03830182017c06740b6b01900173947402641b740b64151b0064181b009b0064199d0383018201740c6a0d7c0083017d09740c6a0d7c0283017d0a740e6a0f7c008301010074106a0f7c028301010074116a0f74126a138301010074146a0f7c088301010074156a0f7404640a83018301010074166a0f7c018301010074176a0f7c038301010074186a0f7c01640f1b007c0714008301010074196a0f741a741b6a1c7c04641c8d01170083010100741d6a0f74196a018300741b6a1c7c05641c8d01170083010100741e6a0f741d6a018300741b6a1c7c06641c8d01170083010100741f7420641d641e641f64208d047d0b7c0b74126a131900900272827c0b74126a13190064216b059002728274217d0c6e04640a7d0c74176a018300640f1b0074047422830174047c0c8301180014007d0d74176a0183007c0d170074146a01830017007d0e742374106a0183007c0e83020100742474256422641e642364208d047d0f7c0f6a018300900273e67402642483018201740c6a0d74106a01830083016a267c0f6a0183007c0d64258d020100740c6a0d742583016a2774126a137428642664278d03010074006a0f6401830101006400530029284e547a185661756c7420697320616c72656164792066756e646564217a2854797065206f6620746f74616c5f7374616b655f616d6f756e74206d75737420626520666c6f61747a2b54797065206f6620746f74616c5f656d697373696f6e5f616d6f756e74206d75737420626520666c6f61747a2e54797065206f66206d61785f73696e676c655f7374616b655f70657263656e74206d75737420626520666c6f61747a2954797065206f662063726561746f725f6c6f636b5f616d6f756e74206d75737420626520666c6f61747a2654797065206f66206d696e757465735f74696c6c5f7374617274206d75737420626520696e747a2b54797065206f662073746172745f706572696f645f696e5f6d696e75746573206d75737420626520696e747a2454797065206f66206d696e757465735f74696c6c5f656e64206d75737420626520696e74e9000000007a1e546f74616c207374616b6520616d6f756e74206d757374206265203e20307a21546f74616c20656d697373696f6e20616d6f756e74206d757374206265203e20307a2043726561746f72206c6f636b20616d6f756e74206d757374206265203e3d20307a284d6178696d756d2073696e676c65207374616b652070657263656e74206d757374206265203e2030e9640000007a2a4d6178696d756d2073696e676c65207374616b652070657263656e74206d757374206265203c203130307a304d696e696d756d2074696d652066726f6d207661756c7420737461727420746f207374616b696e672073746172743a207a08206d696e757465737a304d6178696d756d2074696d652066726f6d207661756c7420737461727420746f207374616b696e672073746172743a207a304d696e696d756d2074696d652066726f6d207374616b696e6720737461727420746f207374616b696e6720656e643a20e93c0000007a0620686f7572737a304d6178696d756d2074696d652066726f6d207374616b696e6720737461727420746f207374616b696e6720656e643a20e9180000007a0520646179737a2c4d696e696d756d2074696d652066726f6d207374616b696e6720656e6420746f207661756c7420656e643a207a2c4d6178696d756d2074696d652066726f6d207374616b696e6720656e6420746f207661756c7420656e643a202901da076d696e75746573da0862616c616e6365737201000000da106e65625f6b65795f62616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000e901000000da0e7661756c745f636f6e7472616374da0874726561737572797a1a547265617375727920636f6e7472616374206e6f7420736574212902da02746fda06616d6f756e74da134e4542554c415f4255524e5f414444524553532903da0c6d61696e5f6163636f756e74722d000000722c0000002929da085f5f66756e646564da03676574da0e417373657274696f6e4572726f72da0a6973696e7374616e6365da07646563696d616cda03696e74da0e4d494e5f53544152545f54494d45da0e4d41585f53544152545f54494d45da0e4d494e5f5354414b455f54494d45da0e4d41585f5354414b455f54494d45da0d4d494e5f4c4f434b5f54494d45da0d4d41585f4c4f434b5f54494d45da0149da0d696d706f72745f6d6f64756c65da0b5f5f7374616b655f636f6eda03736574da0e5f5f656d697373696f6e5f636f6eda0e5f5f63726561746f725f61646472da03637478da0663616c6c6572da0e5f5f63726561746f725f6c6f636bda0f5f5f63757272656e745f7374616b65da0d5f5f746f74616c5f7374616b65da105f5f746f74616c5f656d697373696f6eda125f5f6d61785f73696e676c655f7374616b65da0c5f5f73746172745f64617465da036e6f77da086461746574696d65da0974696d6564656c7461da105f5f73746172745f646174655f656e64da0a5f5f656e645f64617465da0b466f726569676e48617368da104e45425f4b45595f434f4e5452414354da104e45425f4645455f444953434f554e54da074e45425f464545da0f5f5f73656e645f746f5f7661756c74da0f466f726569676e5661726961626c65da0c4e45425f434f4e5452414354da087472616e73666572da0d7472616e736665725f66726f6dda0f4e45425f494e5354414e545f4645452910721700000072180000007219000000721a000000721b000000721c000000721d000000721e000000721f000000da027363da026563da125f5f6e65625f6b65795f62616c616e636573da08646973636f756e74da03666565da0c746f74616c5f616d6f756e74da0a5f5f7472656173757279a9007260000000da00da0a66756e645f7661756c74200000007376000000000614010c0106010c0106010c0106010c0106010c0106010c0106010c0106011001100110011001100118011a011e0122011e0122010a010a010a010a010c010a010e010a010a01120116010e010c010e010c010401040108011c01060204011c0114010e010401040108011201140108010e010a01726200000029027204000000722d000000630200000000000000020000000500000043000000731e00000074006a017c0083016a0274036a047c0174036a0564018d0301006400530029024e2903722f000000722d000000722c0000002906723c000000723d000000725700000072420000007243000000da047468697329027204000000722d000000726000000072600000007261000000725300000064000000730400000000010e0172530000002901722d00000063010000000000000001000000040000004300000073da0000007c0064016b047310740064028301820174017c007402830273227400640383018201740374046a0583006b0473407400640474046a0583009b009d0283018201740374066a0583006b00735e7400640574066a0583009b009d0283018201740774086a09050019007c00370003003c00740a740b6a0583007c0083020100740c6a0d740c6a0583007c00170083010100740774086a091900740e6a0583006b0173b474006406740e6a0583009b009d0283018201740c6a058300740f6a0583006b0173d674006407740f6a0583009b009d02830182016400530029084e72200000007a204e6567617469766520616d6f756e747320617265206e6f7420616c6c6f7765647a16616d6f756e74206d757374206265206120666c6f61747a195374616b696e67206e6f742073746172746564207965743a207a165374616b696e6720706572696f6420656e6465643a207a194d61782075736572207374616b652065786365656465643a207a1a4d617820746f74616c207374616b652065786365656465643a202910723200000072330000007234000000724a00000072490000007231000000724d000000da095f5f7374616b696e67724200000072430000007253000000723e0000007245000000723f000000724800000072460000002901722d000000726000000072600000007261000000da057374616b6569000000731a0000000002100112010e0110010e01100112010e011201140110011201726500000063000000000000000002000000040000004300000073c0000000740074016a02190064016b0473167403640283018201740474056a0683006b0473347403640374056a0683009b009d0283018201740074016a02190074076a0683001b00640414007d0074086a06830064041b007c0014007d0174096a0a740b6a06830083016a0c7c0174016a0264058d02010074096a0a740d6a06830083016a0c740074016a02190074016a0264058d020100740e64018301740074016a023c007c01740f74016a023c0064067c019b006407740b6a0683009b009d04530029084e72200000007a1741646472657373206973206e6f74207374616b696e67217a16456e642064617465206e6f7420726561636865643a2072210000002902722d000000722c0000007a0a456d697373696f6e3a20fa012029107264000000724200000072430000007232000000724a000000724e000000723100000072450000007247000000723c000000723d00000072400000007256000000723e0000007234000000da095f5f7061796f7574732902da0d7374616b655f70657263656e74da0d757365725f656d697373696f6e726000000072600000007261000000da07756e7374616b657a0000007316000000000216011e011601100110010a0116010a010e010a01726a00000063010000000000000001000000040000004300000073ce000000740074016a02190064016b047316740364028301820174047c007405830273287403640383018201740674076a0883006b0473467403640474076a0883009b009d02830182017c00740074016a0219006b01736874036405740074016a0219009b009d028301820174096a0a740b6a08830083016a0c7c0074016a0264068d020100740d6a0e740d6a0883007c00180083010100740074016a02050019007c00380003003c00740564018301740f74016a023c006407740074016a0219009b006408740b6a0883009b009d04530029094e72200000007a1741646472657373206973206e6f74207374616b696e67217a16616d6f756e74206d757374206265206120666c6f61747a16456e642064617465206e6f7420726561636865643a207a164d617820756e7374616b6520616d6f756e74206973202902722d000000722c0000007a1152656d61696e696e67205374616b653a2072660000002910726400000072420000007243000000723200000072330000007234000000724a000000724e0000007231000000723c000000723d000000723e00000072560000007245000000723f00000072670000002901722d000000726000000072600000007261000000da117061796f75745f6f6e6c795f7374616b658900000073140000000002160112011e01100112011a01120112010e01726b0000002901da0e7061795f746f5f616464726573736301000000000000000100000004000000430000007368000000740074016a0283006b04731e7403640174016a0283009b009d028301820174046a02830074056a066b027334740364028301820174076a02830064036b047348740364048301820174086a09740a6a02830083016a0b74076a0283007c0064058d0201006400530029064e7a16456e642064617465206e6f7420726561636865643a207a1e596f7520617265206e6f7420746865207661756c742063726561746f722172200000007a184e6f2063726561746f722066756e6473206c6f636b6564212902722d000000722c000000290c724a000000724e000000723100000072320000007241000000724200000072430000007244000000723c000000723d000000724000000072560000002901726c000000726000000072600000007261000000da1e7061795f6261636b5f6c6f636b65645f63726561746f725f746f6b656e7397000000730a00000000021e01160114011401726d0000004e2928da09696d706f72746c6962723c000000da0448617368723400000072640000007267000000da085661726961626c65723e00000072400000007247000000724600000072450000007248000000724100000072440000007249000000724d000000724e00000072300000007236000000723700000072380000007239000000723a000000723b00000072520000007251000000725800000072550000007250000000da085f5f6578706f7274da03737472da05666c6f61747235000000726200000072530000007265000000726a000000726b000000726d0000007260000000726000000072600000007261000000da083c6d6f64756c653e01000000734c00000004010a0108010a0108010c010c010c010c010c01040108010c010c010c010c010c010c01040104010401040104010401040108010401040104030605283f100506011010100f0601100d0601