Contract con_reflecttau_v2


Contract Code


  
1 import currency as tau
2
3 I = importlib
4
5 action_interface = [I.Func('execute', args=('payload', 'caller'))]
6
7 metadata = Hash()
8 balances = Hash(default_value=0.0)
9
10 contract = Variable()
11 total_supply = Variable()
12 swap_end_date = Variable()
13 burn_address = Variable()
14
15 @construct
16 def init(name: str):
17 balances[ctx.caller] = 0
18
19 metadata['action_reflection'] = 'con_reflecttau_v2_reflection'
20 metadata['action_liquidity'] = 'con_reflecttau_v2_liquidity'
21 metadata['action_treasury'] = 'con_reflecttau_v2_treasury'
22 metadata['action_buyback'] = 'con_reflecttau_v2_buyback'
23 metadata['action_dev'] = 'con_reflecttau_v2_developer'
24
25 metadata['token_name'] = "ReflectTAU.io"
26 metadata['token_symbol'] = "RTAU"
27
28 metadata['operators'] = [
29 'a5565739151e6f8d3fbb03ab605a31cc285e36a717a95002a60e6e4d4e4fa411',
30 '025169da812b5db222e0ce57fbc2b5f949a59ac10a1a65a77fa4ab67c492fbad',
31 '6351a80d32cbb3c173e490b093a95b15bcf4f6190251863669202d7fe2257af3'
32 ]
33
34 contract.set(name)
35 total_supply.set(0.0)
36 burn_address.set('reflecttau_burn_address')
37 swap_end_date.set(now + datetime.timedelta(days=180))
38
39 @export
40 def change_metadata(key: str, value: Any):
41 assert_signer_is_operator()
42
43 """
44 If we are setting an action core contract, make sure that the
45 value is an existing contract and follows the agreed on interface
46 """
47 if key.startswith('action_'):
48 con = I.import_module(value)
49
50 error = 'Action contract does not follow the correct interface!'
51 assert I.enforce_interface(con, action_interface), error
52
53 """
54 Save key and value for an operator. This entry symbolizes
55 the agreement of ctx.caller to set the metadata.
56 """
57 metadata[key, ctx.caller] = value
58
59 agreed = True
60
61 # Check if all operators agree on setting same value for key
62 for op in metadata['operators']:
63 if metadata[key, op] != metadata[key, ctx.caller]:
64 agreed = False
65 break
66
67 if agreed:
68 # Since all operators agree, set new value for key
69 metadata[key] = value
70
71 """
72 Since agreement was met and the value set,
73 let's set the agreement for each operator to a
74 different value so that one-time agreements
75 can't be used more than once by some operator
76 """
77 for op in metadata['operators']:
78 metadata[key, op] = hashlib.sha256(str(now))
79
80 return f'{key} = {value}'
81
82 @export
83 def assert_operators_agree(agreement: str, one_time: bool=True):
84 """
85 Operators can agree to specific action core executions.
86 The agreements will then be checked in the action core
87 contract before they execute.
88
89 The agreement keys need to have the following form:
90 <action_contract>#<function>#<arg_1>#<arg_2>#...
91
92 The value needs to be: "agreed"
93
94 If it is a 'one_time' agreement, it will be set to an
95 empty string after checking, to not allow execution
96 again without new agreement from all operators.
97 """
98 assert metadata[agreement] == 'agreed', 'No agreement met!'
99
100 if one_time:
101 metadata[agreement] = ''
102
103 @export
104 def balance_of(address: str):
105 return balances[address]
106
107 @export
108 def allowance(owner: str, spender: str):
109 return balances[owner, spender]
110
111 @export
112 def get_metadata(key: str):
113 return metadata[key]
114
115 @export
116 def contract():
117 return contract.get()
118
119 @export
120 def burn_address():
121 return burn_address.get()
122
123 @export
124 def transfer(amount: float, to: str):
125 assert amount > 0, 'Cannot send negative balances!'
126 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
127
128 """
129 1. Set balance of sender to 'balance - amount'
130
131 2. Set balance of reflection contract to 'fees
132 calculated by reflection contract'
133
134 3. Set balance of receiver to 'balance + amount - fees'
135 """
136
137 balances[ctx.caller] -= amount
138 balances[metadata['action_reflection']] += call('action_reflection', {'function': 'calc_taxes', 'amount': amount, 'to': to})
139 balances[to] += call('action_reflection', {'function': 'transfer', 'amount': amount, 'to': to})
140
141 @export
142 def approve(amount: float, to: str):
143 assert amount > 0, 'Cannot send negative balances!'
144 balances[ctx.caller, to] += amount
145
146 @export
147 def transfer_from(amount: float, to: str, main_account: str):
148 assert amount > 0, 'Cannot send negative balances!'
149 assert balances[main_account, ctx.caller] >= amount, f'You approved {balances[main_account, ctx.caller]} but need {amount}'
150 assert balances[main_account] >= amount, 'Not enough coins to send! '
151
152 """
153 1. Reduce allowances of sender by amount
154
155 2. Set balance of sender to 'balance - amount'
156
157 3. Set balance of reflection contract to 'fees
158 calculated by reflection contract'
159
160 4. Set balance of receiver to 'balance + amount - fees'
161 """
162
163 balances[main_account, ctx.caller] -= amount
164 balances[main_account] -= amount
165 balances[metadata['action_reflection']] += call('action_reflection', {'function': 'calc_taxes', 'amount': amount, 'to': to})
166 balances[to] += call('action_reflection', {'function': 'transfer_from', 'amount': amount, 'to': to, 'main_account': main_account})
167
168 def call(action: str, payload: dict):
169 # Call action core contract functions from within this contract
170 assert metadata[action] is not None, 'Invalid action!'
171 return I.import_module(metadata[action]).execute(payload, ctx.caller)
172
173 @export
174 def external_call(action: str, payload: dict):
175 assert_signer_is_operator()
176
177 """
178 Call action core contract functions externally.
179 To mark that it was an external call, the key
180 'external' will be added to the payload. Action
181 core contracts can check for that key and know
182 if a call came from the main token contract or
183 from outside.
184 """
185
186 if not payload:
187 payload = {}
188
189 payload['external'] = True
190 return call(action, payload)
191
192 @export
193 def swap_basic(basic_amount: float):
194 assert now < swap_end_date.get(), 'Swap period ended'
195 assert basic_amount > 0, 'Cannot swap negative balances!'
196
197 I.import_module('con_doug_lst001').transfer_from(
198 main_account=ctx.caller,
199 amount=basic_amount,
200 to=burn_address.get())
201
202 swap_amount = basic_amount * 0.07613035192
203 total_supply.set(total_supply.get() + swap_amount)
204 balances[ctx.caller] += swap_amount
205
206 call('action_reflection', {'function': 'manage_holders_index', 'address': ctx.caller, 'amount': swap_amount})
207
208 @export
209 def swap_rtau(rtau_amount: float):
210 assert now < swap_end_date.get(), 'Swap period ended'
211 assert rtau_amount > 0, 'Cannot swap negative balances!'
212
213 I.import_module('con_reflecttau').transfer_from(
214 main_account=ctx.caller,
215 amount=rtau_amount,
216 to=burn_address.get())
217
218 swap_amount = rtau_amount * 0.002386964808
219 total_supply.set(total_supply.get() + swap_amount)
220 balances[ctx.caller] += swap_amount
221
222 call('action_reflection', {'function': 'manage_holders_index', 'address': ctx.caller, 'amount': swap_amount})
223
224 @export
225 def time_until_swap_end():
226 return swap_end_date.get() - now
227
228 @export
229 def circulating_supply():
230 return total_supply.get() - balances[burn_address.get()]
231
232 @export
233 def total_supply():
234 return total_supply.get()
235
236 @export
237 def assert_signer_is_operator():
238 assert ctx.signer in metadata['operators'], 'Only executable by operators!'
239

Byte Code

e3000000000000000000000000050000004000000073f0010000640064016c005a0165025a0365036a046402643f64058d0267015a0565066406640764088d025a0765066508640983016406640a640b8d035a09650a6406640c64088d025a0b650a6406640d64088d025a0c650a6406640e64088d025a0d650a6406640f64088d025a0e650f64109c016411641284045a10651164068301650f651264139c0264146415840483015a136511640683016440650f651464179c0264186419840583015a15651164068301650f641a9c01641b641c840483015a16651164068301650f650f641d9c02641e641f840483015a17651164068301650f64209c0164216422840483015a186511640683016423640c840083015a196511640683016424640f840083015a1a651164068301651b650f64259c0264266427840483015a1c651164068301651b650f64259c0264286429840483015a1d651164068301651b650f650f642a9c03642b642c840483015a1e650f651f642d9c02642e642f84045a20651164068301650f651f642d9c0264306431840483015a21651164068301651b64329c0164336434840483015a22651164068301651b64359c0164366437840483015a2365116406830164386439840083015a24651164068301643a643b840083015a25651164068301643c640d840083015a26651164068301643d643e840083015a27640153002941e9000000004eda0765786563757465da077061796c6f6164da0663616c6c65722901da0461726773da11636f6e5f7265666c6563747461755f7632da086d657461646174612902da08636f6e7472616374da046e616d657a03302e30da0862616c616e6365732903da0d64656661756c745f76616c7565720800000072090000007208000000da0c746f74616c5f737570706c79da0d737761705f656e645f64617465da0c6275726e5f6164647265737329017209000000630100000000000000010000000500000043000000738c0000006401740074016a023c006402740364033c006404740364053c006406740364073c006408740364093c00640a7403640b3c00640c7403640d3c00640e7403640f3c006410641164126703740364133c0074046a057c008301010074066a057407641483018301010074086a0564158301010074096a05740a740b6a0c641664178d011700830101006400530029184e7201000000da1c636f6e5f7265666c6563747461755f76325f7265666c656374696f6eda11616374696f6e5f7265666c656374696f6eda1b636f6e5f7265666c6563747461755f76325f6c6971756964697479da10616374696f6e5f6c6971756964697479da1a636f6e5f7265666c6563747461755f76325f7472656173757279da0f616374696f6e5f7472656173757279da19636f6e5f7265666c6563747461755f76325f6275796261636bda0e616374696f6e5f6275796261636bda1b636f6e5f7265666c6563747461755f76325f646576656c6f706572da0a616374696f6e5f6465767a0d5265666c6563745441552e696fda0a746f6b656e5f6e616d65da0452544155da0c746f6b656e5f73796d626f6cda4061353536353733393135316536663864336662623033616236303561333163633238356533366137313761393530303261363065366534643465346661343131da4030323531363964613831326235646232323265306365353766626332623566393439613539616331306131613635613737666134616236376334393266626164da4036333531613830643332636262336331373365343930623039336139356231356263663466363139303235313836333636393230326437666532323537616633da096f70657261746f72737a03302e30da177265666c6563747461755f6275726e5f61646472657373e9b40000002901da0464617973290dda0a5f5f62616c616e636573da036374787204000000da0a5f5f6d65746164617461da0a5f5f636f6e7472616374da03736574da0e5f5f746f74616c5f737570706c79da07646563696d616cda0e5f5f6275726e5f61646472657373da0f5f5f737761705f656e645f64617465da036e6f77da086461746574696d65da0974696d6564656c746129017209000000a900722f000000da00da045f5f5f5f0d000000731e00000000010a010801080108010801080108010802020102010a010a010e010a0172310000002902da036b6579da0576616c756563020000000000000006000000050000004300000073bc0000007400830001007c006a0164018301723274026a037c0183017d0264027d0374026a047c0274058302733274067c03830182017c0174077c0074086a0966023c0064037d04783074076404190044005d247d0574077c007c056602190074077c0074086a09660219006b03724e64057d045000714e57007c0472b87c0174077c003c00782674076404190044005d1a7d05740a6a0b740c740d8301830174077c007c0566023c00718c57007c009b0064067c019b009d0353006400530029074eda07616374696f6e5f7a36416374696f6e20636f6e747261637420646f6573206e6f7420666f6c6c6f772074686520636f727265637420696e746572666163652154721f000000467a03203d20290eda196173736572745f7369676e65725f69735f6f70657261746f72da0a73746172747377697468da0149da0d696d706f72745f6d6f64756c65da11656e666f7263655f696e74657266616365da10616374696f6e5f696e74657266616365da0e417373657274696f6e4572726f72722500000072240000007204000000da07686173686c6962da06736861323536da03737472722c000000290672320000007233000000da03636f6eda056572726f72da06616772656564da026f70722f000000722f0000007230000000da0f6368616e67655f6d65746164617461200000007320000000000206050a010a01040114050e0104010e011a0104010601040108070e011a017243000000542902da0961677265656d656e74da086f6e655f74696d65630200000000000000020000000300000043000000732400000074007c00190064016b02731474016402830182017c017220640374007c003c0064045300290561d80100000a202020204f70657261746f72732063616e20616772656520746f20737065636966696320616374696f6e20636f726520657865637574696f6e732e0a202020205468652061677265656d656e74732077696c6c207468656e20626520636865636b656420696e2074686520616374696f6e20636f72650a20202020636f6e7472616374206265666f7265207468657920657865637574652e0a0a202020205468652061677265656d656e74206b657973206e65656420746f20686176652074686520666f6c6c6f77696e6720666f726d3a0a202020203c616374696f6e5f636f6e74726163743e233c66756e6374696f6e3e233c6172675f313e233c6172675f323e232e2e2e0a0a202020205468652076616c7565206e6565647320746f2062653a2022616772656564220a0a202020204966206974206973206120276f6e655f74696d65272061677265656d656e742c2069742077696c6c2062652073657420746f20616e0a20202020656d70747920737472696e6720616674657220636865636b696e672c20746f206e6f7420616c6c6f7720657865637574696f6e0a20202020616761696e20776974686f7574206e65772061677265656d656e742066726f6d20616c6c206f70657261746f72732e0a2020202072410000007a114e6f2061677265656d656e74206d65742172300000004e29027225000000723b000000290272440000007245000000722f000000722f0000007230000000da166173736572745f6f70657261746f72735f616772656542000000730600000000101401040172460000002901da0761646472657373630100000000000000010000000200000043000000730800000074007c001900530029014e2901722300000029017247000000722f000000722f0000007230000000da0a62616c616e63655f6f66570000007302000000000272480000002902da056f776e6572da077370656e646572630200000000000000020000000300000043000000730c00000074007c007c0166021900530029014e2901722300000029027249000000724a000000722f000000722f0000007230000000da09616c6c6f77616e63655c00000073020000000002724b00000029017232000000630100000000000000010000000200000043000000730800000074007c001900530029014e2901722500000029017232000000722f000000722f0000007230000000da0c6765745f6d657461646174616100000073020000000002724c000000630000000000000000000000000100000043000000730800000074006a018300530029014e29027226000000da03676574722f000000722f000000722f000000723000000072080000006600000073020000000002630000000000000000000000000100000043000000730800000074006a018300530029014e2902722a000000724d000000722f000000722f000000722f0000007230000000720e0000006b000000730200000000022902da06616d6f756e74da02746f630200000000000000020000000900000043000000737c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c007401740464041900050019007405640464057c007c0164069c038302370003003c0074017c01050019007405640464077c007c0164069c038302370003003c006400530029084e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217210000000da0a63616c635f74617865732903da0866756e6374696f6e724e000000724f000000da087472616e736665722906723b0000007223000000722400000072040000007225000000da065f5f63616c6c2902724e000000724f000000722f000000722f0000007230000000725200000070000000730e0000000002100116091201100112010e017252000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573212904723b0000007223000000722400000072040000002902724e000000724f000000722f000000722f0000007230000000da07617070726f76658300000073040000000002100172540000002903724e000000724f000000da0c6d61696e5f6163636f756e74630300000000000000030000000a0000004300000073c00000007c0064016b047310740064028301820174017c0274026a03660219007c006b0573407400640374017c0274026a03660219009b0064047c009b009d048301820174017c0219007c006b057354740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c007401740464061900050019007405640664077c007c0164089c038302370003003c0074017c01050019007405640664097c007c017c02640a9c048302370003003c0064005300290b4e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a1a4e6f7420656e6f75676820636f696e7320746f2073656e6421207210000000725000000029037251000000724e000000724f000000da0d7472616e736665725f66726f6d29047251000000724e000000724f00000072550000002906723b000000722300000072240000007204000000722500000072530000002903724e000000724f0000007255000000722f000000722f00000072300000007256000000890000007316000000000210010c012401140b16011001100112010c01060172560000002902da06616374696f6e7203000000630200000000000000020000000300000043000000732c00000074007c00190064006b097314740164018301820174026a0374007c00190083016a047c0174056a068302530029024e7a0f496e76616c696420616374696f6e2129077225000000723b00000072370000007238000000720200000072240000007204000000290272570000007203000000722f000000722f00000072300000007253000000a2000000730400000000011401725300000063020000000000000002000000030000004300000073200000007400830001007c01730e69007d0164017c0164023c0074017c007c018302530029034e54da0865787465726e616c290272350000007253000000290272570000007203000000722f000000722f0000007230000000da0d65787465726e616c5f63616c6ca7000000730a0000000002060904010401080172590000002901da0c62617369635f616d6f756e746301000000000000000200000006000000430000007388000000740074016a0283006b00731474036401830182017c0064026b047324740364038301820174046a05640483016a0674076a087c0074096a02830064058d0301007c00740a6406830114007d01740b6a0c740b6a0283007c01170083010100740d74076a08050019007c01370003003c00740e6407640874076a087c0164099c038302010064005300290a4e7a115377617020706572696f6420656e64656472010000007a1e43616e6e6f742073776170206e656761746976652062616c616e63657321da0f636f6e5f646f75675f6c737430303129037255000000724e000000724f0000007a0d302e30373631333033353139327210000000da146d616e6167655f686f6c646572735f696e646578290372510000007247000000724e000000290f722c000000722b000000724d000000723b00000072370000007238000000725600000072240000007204000000722a000000722900000072280000007227000000722300000072530000002902725a000000da0b737761705f616d6f756e74722f000000722f0000007230000000da0a737761705f6261736963b800000073120000000002140110010e010e010c01120112010601725e0000002901da0b727461755f616d6f756e746301000000000000000200000006000000430000007388000000740074016a0283006b00731474036401830182017c0064026b047324740364038301820174046a05640483016a0674076a087c0074096a02830064058d0301007c00740a6406830114007d01740b6a0c740b6a0283007c01170083010100740d74076a08050019007c01370003003c00740e6407640874076a087c0164099c038302010064005300290a4e7a115377617020706572696f6420656e64656472010000007a1e43616e6e6f742073776170206e656761746976652062616c616e63657321da0e636f6e5f7265666c65637474617529037255000000724e000000724f0000007a0e302e3030323338363936343830387210000000725c000000290372510000007247000000724e000000290f722c000000722b000000724d000000723b00000072370000007238000000725600000072240000007204000000722a000000722900000072280000007227000000722300000072530000002902725f000000725d000000722f000000722f0000007230000000da09737761705f72746175c500000073120000000002140110010e010e010c011201120106017261000000630000000000000000000000000200000043000000730c00000074006a01830074021800530029014e2903722b000000724d000000722c000000722f000000722f000000722f0000007230000000da1374696d655f756e74696c5f737761705f656e64d2000000730200000000027262000000630000000000000000000000000300000043000000731400000074006a018300740274036a01830019001800530029014e29047228000000724d0000007223000000722a000000722f000000722f000000722f0000007230000000da1263697263756c6174696e675f737570706c79d7000000730200000000027263000000630000000000000000000000000100000043000000730800000074006a018300530029014e29027228000000724d000000722f000000722f000000722f0000007230000000720c000000dc00000073020000000002630000000000000000000000000300000043000000731a00000074006a017402640119006b06731674036402830182016400530029034e721f0000007a1d4f6e6c792065786563757461626c65206279206f70657261746f72732129047224000000da067369676e65727225000000723b000000722f000000722f000000722f00000072300000007235000000e100000073040000000002100172350000002902720300000072040000002901542928da0863757272656e6379da03746175da09696d706f72746c69627237000000da0446756e63723a000000da0448617368722500000072290000007223000000da085661726961626c6572260000007228000000722b000000722a000000723e0000007231000000da085f5f6578706f7274da03416e797243000000da04626f6f6c72460000007248000000724b000000724c0000007208000000720e000000da05666c6f6174725200000072540000007256000000da046469637472530000007259000000725e000000726100000072620000007263000000720c0000007235000000722f000000722f000000722f0000007230000000da083c6d6f64756c653e01000000734e0000000801040110010c0108010a010c010c010c010c030e130601122106011414060110040601120406011004100510050601121206011205060114181005060112100601100c0601100c100510051005