Contract con_ttest_contract


Contract Code


  
1 I = importlib
2
3 import currency as tau
4
5 balances = Hash(default_value=0)
6 metadata = Hash()
7
8 tax = Variable()
9 total_supply = Variable()
10 swap_enabled = Variable()
11
12 SWAP_FACTOR = 100
13 RSWP_CONTRACT = 'con_rocketswap_official_v1_1'
14 BURN_ADDRESS = 'internal_burn_address'
15
16 @construct
17 def seed():
18 balances[ctx.caller] = 0
19
20 metadata['token_name'] = "TTest"
21 metadata['token_symbol'] = "TTest"
22 metadata['owner'] = ctx.caller
23
24 tax.set(2)
25
26 swap_enabled.set(True)
27 total_supply.set(0)
28
29 @export
30 def change_metadata(key: str, value: Any):
31 assert_owner(); metadata[key] = value
32
33 @export
34 def transfer(amount: float, to: str):
35 assert amount > 0, 'Cannot send negative balances!'
36 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
37
38 balances[ctx.caller] -= amount
39 balances[to] += amount
40
41 if ctx.caller == RSWP_CONTRACT or to == RSWP_CONTRACT:
42 pay_tax(amount)
43
44 @export
45 def approve(amount: float, to: str):
46 assert amount > 0, 'Cannot send negative balances!'
47 balances[ctx.caller, to] += amount
48
49 @export
50 def transfer_from(amount: float, to: str, main_account: str):
51 assert amount > 0, 'Cannot send negative balances!'
52 assert balances[main_account, ctx.caller] >= amount, f'You approved {balances[main_account, ctx.caller]} but need {amount}'
53 assert balances[main_account] >= amount, 'Not enough coins to send!'
54
55 balances[main_account, ctx.caller] -= amount
56 balances[main_account] -= amount
57 balances[to] += amount
58
59 if ctx.caller == RSWP_CONTRACT or to == RSWP_CONTRACT:
60 pay_tax(amount)
61
62 def pay_tax(amount: float):
63 tax_amount = int(amount / 100 * tax.get())
64
65 if tax_amount > 0:
66 price = ForeignHash(
67 foreign_contract=RSWP_CONTRACT,
68 foreign_name='prices')[ctx.this]
69
70 tau.transfer_from(
71 main_account=ctx.signer,
72 amount=amount * price,
73 to=ctx.this)
74
75 difference = ((int(balances[ctx.signer] - tax_amount)) * -1) + 1
76
77 error = f'Not enough coins to pay for {metadata["token_symbol"]} tax. Missing {difference} {metadata["token_symbol"]}'
78 assert balances[ctx.signer] >= tax_amount, error
79
80 balances[ctx.this] += tax_amount
81 balances[ctx.signer] -= tax_amount
82
83 @export
84 def swap_doug(doug_amount: float):
85 assert swap_enabled.get() == True, 'Swapping DOUG for TTest currently disabled'
86 assert doug_amount > 0, 'Cannot swap negative balances!'
87
88 I.import_module('con_doug_lst001').transfer_from(
89 main_account=ctx.caller,
90 amount=doug_amount,
91 to=BURN_ADDRESS)
92
93 swap_amount = doug_amount * SWAP_FACTOR
94 total_supply.set(total_supply.get() + swap_amount)
95 balances[ctx.caller] += swap_amount
96
97 @export
98 def set_tax(tax_in_percent: float):
99 assert_owner(); tax.set(tax_in_percent)
100
101 @export
102 def swap_enabled(enabled: bool):
103 assert_owner(); swap_enabled.set(enabled)
104
105 @export
106 def withdraw_token(contract: str, amount: float):
107 assert_owner(); I.import_module(contract).transfer(amount, ctx.caller)
108
109 @export
110 def withdraw_lp(contract: str, amount: float):
111 assert_owner(); I.import_module(RSWP_CONTRACT).transfer_liquidity(contract, ctx.caller, amount)
112
113 @export
114 def burn(amount: float):
115 assert amount > 0, 'Cannot burn negative amount!'
116 assert balances[ctx.caller] >= amount, 'Not enough coins to burn!'
117
118 balances[BURN_ADDRESS] += amount
119 balances[ctx.caller] -= amount
120
121 @export
122 def circulating_supply():
123 return int(total_supply.get() - balances[BURN_ADDRESS])
124
125 @export
126 def total_supply():
127 return int(total_supply.get())
128
129 def assert_owner():
130 assert ctx.caller == metadata['owner'], 'Only executable by owner!'
131

Byte Code

e30000000000000000000000000500000040000000738201000065005a01640064016c025a03650464006402640364048d035a0565046402640564068d025a0665076402640764068d025a0865076402640864068d025a0965076402640964068d025a0a640a5a0b640b5a0c640c5a0d640d640e84005a0e650f6402830165106511640f9c0264106411840483015a12650f640283016513651064129c0264136414840483015a14650f640283016513651064129c0264156416840483015a15650f6402830165136510651064179c0364186419840483015a166513641a9c01641b641c84045a17650f640283016513641d9c01641e641f840483015a18650f64028301651364209c0164216422840483015a19650f64028301651a64239c0164246409840483015a1b650f640283016510651364259c0264266427840483015a1c650f640283016510651364259c0264286429840483015a1d650f640283016513641a9c01642a642b840483015a1e650f64028301642c642d840083015a1f650f64028301642e6408840083015a20642f643084005a21640153002931e9000000004eda12636f6e5f74746573745f636f6e7472616374da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272050000007206000000da03746178da0c746f74616c5f737570706c79da0c737761705f656e61626c6564e964000000da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da15696e7465726e616c5f6275726e5f6164647265737363000000000000000000000000030000004300000073460000006401740074016a023c006402740364033c006402740364043c0074016a02740364053c0074046a0564068301010074066a0564078301010074076a056401830101006400530029084e7201000000da055454657374da0a746f6b656e5f6e616d65da0c746f6b656e5f73796d626f6cda056f776e6572e902000000542908da0a5f5f62616c616e636573da03637478da0663616c6c6572da0a5f5f6d65746164617461da055f5f746178da03736574da0e5f5f737761705f656e61626c6564da0e5f5f746f74616c5f737570706c79a900721b000000721b000000da00da045f5f5f5f0e000000730e00000000010a01080108010a010a010a01721d0000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e657272160000002902721e000000721f000000721b000000721b000000721c000000da0f6368616e67655f6d657461646174611800000073040000000002060172210000002902da06616d6f756e74da02746f63020000000000000002000000040000004300000073660000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c0074026a0374046b02735a7c0174046b02726274057c00830101006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64212906da0e417373657274696f6e4572726f72721300000072140000007215000000da0d525357505f434f4e5452414354da095f5f7061795f746178290272220000007223000000721b000000721b000000721c000000da087472616e736665721e000000730c0000000002100116011201100112017227000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047224000000721300000072140000007215000000290272220000007223000000721b000000721b000000721c000000da07617070726f7665280000007304000000000210017228000000290372220000007223000000da0c6d61696e5f6163636f756e7463030000000000000003000000050000004300000073a80000007c0064016b047310740064028301820174017c0274026a03660219007c006b0573407400640374017c0274026a03660219009b0064047c009b009d048301820174017c0219007c006b057354740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c0074026a0374046b02739c7c0174046b0272a474057c00830101006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a194e6f7420656e6f75676820636f696e7320746f2073656e642129067224000000721300000072140000007215000000722500000072260000002903722200000072230000007229000000721b000000721b000000721c000000da0d7472616e736665725f66726f6d2e0000007312000000000210010c01240114011601100110011201722a0000002901722200000063010000000000000005000000070000004300000073bc00000074007c0064011b0074016a028300140083017d017c0164026b0472b874037404640364048d0274056a0619007d0274076a0874056a097c007c02140074056a0664058d0301007400740a74056a0919007c0118008301640b1400640617007d036407740b640819009b0064097c039b00640a740b640819009b009d067d04740a74056a0919007c016b057394740c7c0483018201740a74056a06050019007c01370003003c00740a74056a09050019007c01380003003c0064005300290c4e720b0000007201000000da067072696365732902da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d652903722900000072220000007223000000e9010000007a1c4e6f7420656e6f75676820636f696e7320746f2070617920666f722072100000007a0e207461782e204d697373696e6720fa0120e9ffffffff290dda03696e747217000000da03676574da0b466f726569676e4861736872250000007214000000da0474686973da03746175722a000000da067369676e657272130000007216000000722400000029057222000000da0a7461785f616d6f756e74da057072696365da0a646966666572656e6365da056572726f72721b000000721b000000721c00000072260000003b000000731600000000011401080104010e010e010a011a021e021601120172260000002901da0b646f75675f616d6f756e74630100000000000000020000000500000043000000736c00000074006a01830064016b02731474026402830182017c0064036b047324740264048301820174036a04640583016a0574066a077c00740864068d0301007c00740914007d01740a6a0b740a6a0183007c01170083010100740c74066a07050019007c01370003003c006400530029074e547a2a5377617070696e6720444f554720666f722054546573742063757272656e746c792064697361626c656472010000007a1e43616e6e6f742073776170206e656761746976652062616c616e63657321da0f636f6e5f646f75675f6c73743030312903722900000072220000007223000000290d721900000072320000007224000000da0149da0d696d706f72745f6d6f64756c65722a00000072140000007215000000da0c4255524e5f41444452455353da0b535741505f464143544f52721a000000721800000072130000002902723b000000da0b737761705f616d6f756e74721b000000721b000000721c000000da09737761705f646f75674b0000007310000000000206010e0110010e010a010801120172420000002901da0e7461785f696e5f70657263656e74630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e290372200000007217000000721800000029017243000000721b000000721b000000721c000000da077365745f7461785700000073040000000002060172440000002901da07656e61626c6564630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e290372200000007219000000721800000029017245000000721b000000721b000000721c000000720a0000005d000000730400000000020601290272050000007222000000630200000000000000020000000300000043000000731e00000074008300010074016a027c0083016a037c0174046a05830201006400530029014e29067220000000723d000000723e000000722700000072140000007215000000290272050000007222000000721b000000721b000000721c000000da0e77697468647261775f746f6b656e630000007304000000000206017246000000630200000000000000020000000400000043000000732000000074008300010074016a02740383016a047c0074056a067c01830301006400530029014e29077220000000723d000000723e0000007225000000da127472616e736665725f6c697175696469747972140000007215000000290272050000007222000000721b000000721b000000721c000000da0b77697468647261775f6c706900000073060000000002060110017248000000630100000000000000010000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b057326740064038301820174017404050019007c00370003003c00740174026a03050019007c00380003003c006400530029044e72010000007a1c43616e6e6f74206275726e206e6567617469766520616d6f756e74217a194e6f7420656e6f75676820636f696e7320746f206275726e2129057224000000721300000072140000007215000000723f00000029017222000000721b000000721b000000721c000000da046275726e700000007308000000000210011601100172490000006300000000000000000000000004000000430000007314000000740074016a02830074037404190018008301530029014e29057231000000721a00000072320000007213000000723f000000721b000000721b000000721b000000721c000000da1263697263756c6174696e675f737570706c797800000073020000000002724a000000630000000000000000000000000200000043000000730c000000740074016a0283008301530029014e29037231000000721a0000007232000000721b000000721b000000721b000000721c00000072090000007d00000073020000000002630000000000000000000000000300000043000000731a00000074006a017402640119006b02731674036402830182016400530029034e72110000007a194f6e6c792065786563757461626c65206279206f776e65722129047214000000721500000072160000007224000000721b000000721b000000721b000000721c0000007220000000820000007302000000000172200000002922da09696d706f72746c6962723d000000da0863757272656e63797235000000da044861736872130000007216000000da085661726961626c657217000000721a000000721900000072400000007225000000723f000000721d000000da085f5f6578706f7274da03737472da03416e797221000000da05666c6f617472270000007228000000722a000000722600000072420000007244000000da04626f6f6c720a000000724600000072480000007249000000724a00000072090000007220000000721b000000721b000000721b000000721c000000da083c6d6f64756c653e01000000734600000004010801060108010c010c010c010c01040104010403080a0601120506011209060112050601140c0e100601100b060110050601100506011205060112060601100710051005