Contract con_portal


Contract Code


  
1 I = importlib
2
3 multisig = Hash(default_value='')
4 metadata = Hash(default_value='')
5 balances = Hash(default_value=0)
6 allowances = Hash(default_value=0)
7
8 @construct
9 def seed():
10 metadata['total_supply'] = 142_487_438
11 metadata['token_name'] = "Portal"
12 metadata['token_symbol'] = "XPTL"
13 metadata['v_token_con'] = "con_v_portal"
14 metadata['v_lp_con'] = "con_v_portal_lp"
15 metadata['swap_end_date'] = now + datetime.timedelta(days=30)
16
17 metadata['operator'] = [
18 'fcefe7743fa70c97ae2d5290fd673070da4b0293da095f0ae8aceccf5e62b6a1',
19 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
20 '889f923fb54a79deb11ee2850010488992222c92351d3024ea3a737b78fab0eb'
21 ]
22
23 balances[ctx.submission_name] = metadata['total_supply']
24
25 @export
26 def transfer(amount: float, to: str):
27 assert amount > 0, 'Cannot send negative balances!'
28 assert balances[ctx.caller] >= amount, 'Not enough tokens to send!'
29
30 balances[ctx.caller] -= amount
31 balances[to] += amount
32
33 @export
34 def approve(amount: float, to: str):
35 assert amount > 0, 'Cannot send negative balances!'
36 allowances[ctx.caller, to] += amount
37
38 @export
39 def transfer_from(amount: float, to: str, main_account: str):
40 approved = allowances[main_account, ctx.caller]
41
42 assert amount > 0, 'Cannot send negative balances!'
43 assert approved >= amount, f'You approved {approved} but need {amount}'
44 assert balances[main_account] >= amount, 'Not enough tokens to send!'
45
46 allowances[main_account, ctx.caller] -= amount
47 balances[main_account] -= amount
48 balances[to] += amount
49
50 @export
51 def balance_of(address: str):
52 return balances[address]
53
54 @export
55 def time_until_swap_end():
56 return metadata['swap_end_date'] - now
57
58 @export
59 def total_supply():
60 return int(metadata['total_supply'])
61
62 @export
63 def set_multisig(topic: str, data: Any):
64 multisig[ctx.caller, topic] = data
65 assert_caller_is_owner()
66
67 def multisig_agrees(topic: str, data: Any):
68 yes = 0
69
70 if multisig[metadata['operator'][0], topic] == data: yes += 1
71 if multisig[metadata['operator'][1], topic] == data: yes += 1
72 if multisig[metadata['operator'][2], topic] == data: yes += 1
73
74 if yes > 1:
75 multisig[metadata['operator'][0], topic] = 0
76 multisig[metadata['operator'][1], topic] = 0
77 multisig[metadata['operator'][2], topic] = 0
78
79 return True
80
81 return False
82
83 @export
84 def change_metadata(key: str, value: Any):
85 assert multisig_agrees(f'metadata-{key}', value), 'Not enough votes!'
86 assert_caller_is_owner()
87
88 metadata[key] = value
89
90 if key == 'token_name':
91 I.import_module(metadata['v_token_con']).change_token_name(value)
92 I.import_module(metadata['v_lp_con']).change_token_name(value)
93 elif key == 'token_symbol':
94 I.import_module(metadata['v_token_con']).change_token_symbol(value)
95 I.import_module(metadata['v_lp_con']).change_token_symbol(value)
96
97
98 @export
99 def swap_neb(amount: float):
100 assert amount > 0, 'Cannot swap negative balances!'
101
102 if now > metadata['swap_end_date']:
103 assert multisig_agrees(f'swap-{ctx.signer}', amount), 'Swap period ended'
104
105 I.import_module('con_nebula').transfer_from(
106 amount=amount,
107 to='NEBULA_BURN_ADDRESS',
108 main_account=ctx.caller
109 )
110
111 swap_amount = amount * 0.1
112 balances[ctx.caller] += swap_amount
113 metadata['total_supply'] += swap_amount
114
115 @export
116 def withdraw(token_contract: str, amount: float):
117 assert multisig_agrees(f'withdraw-{token_contract}', amount), 'Not enough votes!'
118 assert_caller_is_owner()
119
120 if token_contract == ctx.this:
121 assert amount > 0, 'Cannot send negative balances!'
122 assert balances[token_contract] >= amount, 'Not enough tokens to send!'
123 balances[token_contract] -= amount
124 balances[ctx.caller] += amount
125 else:
126 I.import_module(token_contract).transfer(amount, ctx.caller)
127
128 def assert_caller_is_owner():
129 assert ctx.caller in metadata['operator'], 'Only executable by operators!'
130

Byte Code

e30000000000000000000000000500000040000000733e01000065005a01650264006401640264038d035a03650264006401640464038d035a04650264056401640664038d035a05650264056401640764038d035a066408640984005a076508640183016509650a640a9c02640b640c840483015a0b6508640183016509650a640a9c02640d640e840483015a0c6508640183016509650a650a640f9c0364106411840483015a0d650864018301650a64129c0164136414840483015a0e65086401830164156416840083015a0f65086401830164176418840083015a10650864018301650a651164199c02641a641b840483015a12650a651164199c02641c641d84045a13650864018301650a6511641e9c02641f6420840483015a14650864018301650964219c0164226423840483015a15650864018301650a650964249c0264256426840483015a166427642884005a1764295300292ada00da0a636f6e5f706f7274616cda086d756c74697369672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461e900000000da0862616c616e636573da0a616c6c6f77616e636573630000000000000000000000000400000043000000735c0000006401740064023c006403740064043c006405740064063c006407740064083c0064097400640a3c00740174026a03640b640c8d0117007400640d3c00640e640f64106703740064113c00740064021900740474056a063c006400530029124e698e2f7e08da0c746f74616c5f737570706c79da06506f7274616cda0a746f6b656e5f6e616d65da045850544cda0c746f6b656e5f73796d626f6cda0c636f6e5f765f706f7274616cda0b765f746f6b656e5f636f6eda0f636f6e5f765f706f7274616c5f6c70da08765f6c705f636f6ee91e0000002901da0464617973da0d737761705f656e645f64617465da4066636566653737343366613730633937616532643532393066643637333037306461346230323933646130393566306165386163656363663565363262366131da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4038383966393233666235346137396465623131656532383530303130343838393932323232633932333531643330323465613361373337623738666162306562da086f70657261746f722907da0a5f5f6d65746164617461da036e6f77da086461746574696d65da0974696d6564656c7461da0a5f5f62616c616e636573da03637478da0f7375626d697373696f6e5f6e616d65a900722200000072220000007201000000da045f5f5f5f0800000073140000000001080108010801080108011402020102010a0172230000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72080000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1a4e6f7420656e6f75676820746f6b656e7320746f2073656e64212904da0e417373657274696f6e4572726f72721f0000007220000000da0663616c6c6572290272240000007225000000722200000072220000007201000000da087472616e7366657216000000730800000000021001160112017228000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72080000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047226000000da0c5f5f616c6c6f77616e63657372200000007227000000290272240000007225000000722200000072220000007201000000da07617070726f76651e000000730400000000021001722a000000290372240000007225000000da0c6d61696e5f6163636f756e74630300000000000000040000000500000043000000738800000074007c0274016a02660219007d037c0064016b04731e74036402830182017c037c006b05733a740364037c039b0064047c009b009d048301820174047c0219007c006b05734e740364058301820174007c0274016a026602050019007c00380003003c0074047c02050019007c00380003003c0074047c01050019007c00370003003c006400530029064e72080000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a1a4e6f7420656e6f75676820746f6b656e7320746f2073656e642129057229000000722000000072270000007226000000721f000000290472240000007225000000722b000000da08617070726f766564722200000072220000007201000000da0d7472616e736665725f66726f6d24000000730e00000000020e0110011c01140116011001722d0000002901da0761646472657373630100000000000000010000000200000043000000730800000074007c001900530029014e2901721f0000002901722e000000722200000072220000007201000000da0a62616c616e63655f6f662f00000073020000000002722f000000630000000000000000000000000200000043000000730c00000074006401190074011800530029024e72160000002902721b000000721c0000007222000000722200000072220000007201000000da1374696d655f756e74696c5f737761705f656e6434000000730200000000027230000000630000000000000000000000000300000043000000730c00000074007401640119008301530029024e720b0000002902da03696e74721b0000007222000000722200000072220000007201000000720b0000003900000073020000000002720b0000002902da05746f706963da046461746163020000000000000002000000040000004300000073180000007c01740074016a027c0066023c007403830001006400530029014e2904da0a5f5f6d756c746973696772200000007227000000da185f5f6173736572745f63616c6c65725f69735f6f776e6572290272320000007233000000722200000072220000007201000000da0c7365745f6d756c74697369673e000000730400000000020e01723600000063020000000000000003000000040000004300000073b000000064017d027400740164021900640119007c00660219007c016b0272247c02640337007d027400740164021900640319007c00660219007c016b0272447c02640337007d027400740164021900640419007c00660219007c016b0272647c02640337007d027c0264036b0472ac64017400740164021900640119007c0066023c0064017400740164021900640319007c0066023c0064017400740164021900640419007c0066023c00640553006406530029074e7208000000721a000000e901000000e902000000544629027234000000721b000000290372320000007233000000da03796573722200000072220000007201000000da115f5f6d756c74697369675f61677265657344000000731a0000000001040118010801180108011801080108011401140114010401723a0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000738c000000740064017c009b009d027c018302731874016402830182017402830001007c0174037c003c007c0064036b02725874046a0574036404190083016a067c018301010074046a0574036405190083016a067c01830101006e307c0064066b02728874046a0574036404190083016a077c018301010074046a0574036405190083016a077c01830101006400530029074e7a096d657461646174612d7a114e6f7420656e6f75676820766f74657321720d00000072110000007213000000720f0000002908723a00000072260000007235000000721b000000da0149da0d696d706f72745f6d6f64756c65da116368616e67655f746f6b656e5f6e616d65da136368616e67655f746f6b656e5f73796d626f6c2902723b000000723c000000722200000072220000007201000000da0f6368616e67655f6d6574616461746154000000731200000000021801060108010801140116010801140172410000002901722400000063010000000000000002000000050000004300000073800000007c0064016b047310740064028301820174017402640319006b0472367403640474046a059b009d027c0083027336740064058301820174066a07640683016a087c00640774046a0964088d0301007c00740a6409830114007d01740b74046a09050019007c01370003003c007402640a050019007c01370003003c0064005300290b4e72080000007a1e43616e6e6f742073776170206e656761746976652062616c616e6365732172160000007a05737761702d7a115377617020706572696f6420656e646564da0a636f6e5f6e6562756c61da134e4542554c415f4255524e5f41444452455353290372240000007225000000722b0000007a03302e31720b000000290c7226000000721c000000721b000000723a0000007220000000da067369676e6572723d000000723e000000722d0000007227000000da07646563696d616c721f00000029027224000000da0b737761705f616d6f756e74722200000072220000007201000000da08737761705f6e6562610000007312000000000210010c01140106010c010c010c01120172470000002902da0e746f6b656e5f636f6e747261637472240000006302000000000000000200000004000000430000007388000000740064017c009b009d027c018302731874016402830182017402830001007c0074036a046b0272707c0164036b047338740164048301820174057c0019007c016b05734c740164058301820174057c00050019007c01380003003c00740574036a06050019007c01370003003c006e1474076a087c0083016a097c0174036a06830201006400530029064e7a0977697468647261772d7a114e6f7420656e6f75676820766f7465732172080000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1a4e6f7420656e6f75676820746f6b656e7320746f2073656e6421290a723a000000722600000072350000007220000000da0474686973721f0000007227000000723d000000723e0000007228000000290272480000007224000000722200000072220000007201000000da0877697468647261776e000000731400000000021201060106010a01100106010e0110011402724a000000630000000000000000000000000300000043000000731a00000074006a017402640119006b06731674036402830182016400530029034e721a0000007a1d4f6e6c792065786563757461626c65206279206f70657261746f727321290472200000007227000000721b0000007226000000722200000072220000007222000000720100000072350000007d00000073040000000001100172350000004e2918da09696d706f72746c6962723d000000da04486173687234000000721b000000721f00000072290000007223000000da085f5f6578706f7274da05666c6f6174da037374727228000000722a000000722d000000722f0000007230000000720b000000da03416e797236000000723a00000072410000007247000000724a00000072350000007222000000722200000072220000007201000000da083c6d6f64756c653e01000000733200000004010e010e010e010e03080e06011207060112050601140a06011004100510050601120510100601120c0601100c0601120e