Contract con_pusd


Contract Code


  
1 # Python USD - Lamden Fully Decentralized Stable Coin
2 # Difference to LUSD is that PUSD is collateralized by TAU on this chain instead of USDT
3 # No Slippage Stablecoin Swap available at https://pusd.to
4
5 import currency as tau
6
7 I = importlib
8
9 balances = Hash(default_value=0)
10 allowances = Hash(default_value=0)
11 metadata = Hash(default_value='')
12
13 total_supply = Variable()
14
15 dapp_state = Variable()
16 last_price = Variable()
17
18
19 @construct
20 def seed():
21 metadata['token_name'] = "Python USD"
22 metadata['token_symbol'] = "PUSD"
23 metadata['dex'] = 'con_rocketswap_official_v1_1'
24 metadata['lusd'] = 'con_lusd_lst001'
25 metadata['dev_addr'] = 'b561090f790569de8cce8f614ebcd2e8c75e2301a027e36159b734b390d39752'
26
27 metadata['dev_tax'] = 1 # Developer tax
28 metadata['mnt_tax'] = 1 # Minting tax
29 metadata['liq_tax'] = 2 # Liquidity tax
30 metadata['anti_manipulation_threshold'] = 7
31
32 metadata['operators'] = [
33 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
34 '6a9004cbc570592c21879e5ee319c754b9b7bf0278878b1cc21ac87eed0ee38d'
35 ]
36
37 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
38
39 total_supply.set(0)
40 dapp_state.set('active')
41 last_price.set(prices[metadata['lusd']])
42
43 @export
44 def change_metadata(key: str, value: Any):
45 assert key.lower() != 'operators', 'Can not change owners'
46 assert value, 'Parameter "value" can not be empty'
47
48 metadata[key][ctx.caller] = value
49
50 owner1 = metadata['operators'][0]
51 owner2 = metadata['operators'][1]
52
53 if metadata[key][owner1] == metadata[key][owner2]:
54 metadata[key] = value
55
56 metadata[key][owner1] = ''
57 metadata[key][owner2] = ''
58
59 assert_owner()
60
61 @export
62 def transfer(amount: float, to: str):
63 assert amount > 0, 'Cannot send negative balances!'
64 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
65
66 balances[ctx.caller] -= amount
67 balances[to] += amount
68
69 @export
70 def approve(amount: float, to: str):
71 assert amount > 0, 'Cannot send negative balances!'
72
73 allowances[ctx.caller, to] += amount
74
75 @export
76 def transfer_from(amount: float, to: str, main_account: str):
77 assert amount > 0, 'Cannot send negative balances!'
78 assert allowances[main_account, ctx.caller] >= amount, f'You approved {allowances[main_account, ctx.caller]} but need {amount}'
79 assert balances[main_account] >= amount, 'Not enough coins to send!'
80
81 allowances[main_account, ctx.caller] -= amount
82 balances[main_account] -= amount
83 balances[to] += amount
84
85 @export
86 def tau_to_pusd(tau_amount: float):
87 assert tau_amount > 0, 'Cannot send negative balances!'
88 assert dapp_state.get() == 'active', 'The dapp is currently paused'
89
90 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
91
92 price_change = abs(((prices[metadata['lusd']])-last_price.get())/last_price.get())*100
93
94 if (price_change >= metadata['anti_manipulation_threshold']):
95 dapp_state.set('inactive')
96 else:
97 dev_amount = tau_amount / 100 * metadata['dev_tax']
98 mnt_amount = tau_amount / 100 * metadata['mnt_tax']
99
100 tau.transfer_from(amount=tau_amount, to=ctx.this, main_account=ctx.caller)
101 tau.transfer(amount=dev_amount, to=metadata['dev_addr'])
102
103 pusd_amount = ((tau_amount - dev_amount - mnt_amount) / prices[metadata['lusd']])
104
105 balances[ctx.caller] += pusd_amount
106 total_supply.set(total_supply.get() + pusd_amount)
107 last_price.set(prices[metadata['lusd']])
108
109 @export
110 def pusd_to_tau(pusd_amount: float):
111 assert pusd_amount > 0, 'Cannot send negative balances!'
112 assert dapp_state.get() == 'active', 'The dapp is currently paused'
113
114 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
115
116 price_change = abs(((prices[metadata['lusd']])-last_price.get())/last_price.get())*100
117
118 if (price_change >= metadata['anti_manipulation_threshold']):
119 dapp_state.set('inactive')
120 else:
121 liq_amount = pusd_amount / 100 * metadata['liq_tax']
122 tau_amount = (pusd_amount - liq_amount) * prices[metadata['lusd']]
123
124 tau.transfer(amount=tau_amount, to=ctx.caller)
125
126 balances[ctx.this] += liq_amount
127 balances[ctx.caller] -= pusd_amount
128
129 total_supply.set(total_supply.get() - pusd_amount)
130 last_price.set(prices[metadata['lusd']])
131 if liq_amount >= 10:
132 add_liquidity(liq_amount)
133
134 def add_liquidity(pusd_amount: float):
135 approve(amount=pusd_amount, to=metadata['dex'])
136 tau_amount = I.import_module(metadata['dex']).sell(contract=ctx.this, token_amount=pusd_amount / 2)
137
138 tau.approve(amount=tau_amount, to=metadata['dex'])
139 I.import_module(metadata['dex']).add_liquidity(contract=ctx.this, currency_amount=pusd_amount)
140
141 @export
142 def unpause_dapp():
143 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
144 last_price.set(prices[metadata['lusd']])
145 dapp_state.set('active')
146 assert_owner()
147
148 @export
149 def get_current_backing_ratio(): # > 1 = Good
150 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
151 return ((tau.balance_of(ctx.this) * (1 / prices[metadata['lusd']])) / circulating_supply())
152
153 @export
154 def migrate_tau(contract: str, amount: float):
155 approved_action('migrate_tau', contract, amount)
156
157 tau.transfer(amount=amount, to=contract, main_account=ctx.this)
158 assert_owner()
159
160 @export
161 def migrate_pusd(contract: str, amount: float):
162 assert amount > 0, 'Cannot send negative balances!'
163 assert balances[ctx.this] >= amount, 'Not enough coins to send!'
164
165 approved_action('migrate_pusd', contract, amount)
166
167 balances[ctx.this] -= amount
168 balances[contract] += amount
169 assert_owner()
170
171 @export
172 def migrate_lp(contract: str, amount: float):
173 approved_action('migrate_lp', contract, amount)
174
175 dex = I.import_module(metadata['dex'])
176 dex.approve_liquidity(ctx.this, contract, amount)
177 dex.transfer_liquidity(ctx.this, contract, amount)
178 assert_owner()
179
180 def approved_action(action: str, contract: str, amount: float):
181 owner1 = metadata['operators'][0]
182 owner2 = metadata['operators'][1]
183
184 assert metadata[action][owner1] == f'{contract}{amount}', f'Wrong metadata for {owner1}'
185 assert metadata[action][owner2] == f'{contract}{amount}', f'Wrong metadata for {owner2}'
186
187 @export
188 def circulating_supply():
189 return f'{total_supply.get() - balances[ctx.this]}'
190
191 @export
192 def total_supply():
193 return f'{total_supply.get()}'
194
195 def assert_owner():
196 assert ctx.caller in metadata['operators'], 'Only executable by operators!'

Byte Code

e3000000000000000000000000050000004000000073a4010000640064016c005a0165025a03650464006402640364048d035a05650464006402640564048d035a06650464066402640764048d035a0765086402640864098d025a0965086402640a64098d025a0a65086402640b64098d025a0b640c640d84005a0c650d64028301650e650f640e9c02640f6410840483015a10650d640283016511650e64119c0264126413840483015a12650d640283016511650e64119c0264146415840483015a13650d640283016511650e650e64169c0364176418840483015a14650d64028301651164199c01641a641b840483015a15650d640283016511641c9c01641d641e840483015a166511641c9c01641f642084045a17650d6402830164216422840083015a18650d6402830164236424840083015a19650d64028301650e651164259c0264266427840483015a1a650d64028301650e651164259c0264286429840483015a1b650d64028301650e651164259c02642a642b840483015a1c650e650e6511642c9c03642d642e84045a1d650d64028301642f6430840083015a1e650d6402830164316408840083015a1f6432643384005a20640153002934e9000000004eda08636f6e5f70757364da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0a616c6c6f77616e636573da00da086d65746164617461da0c746f74616c5f737570706c79290272050000007206000000da0a646170705f7374617465da0a6c6173745f707269636563000000000000000001000000060000004300000073920000006401740064023c006403740064043c006405740064063c006407740064083c0064097400640a3c00640b7400640c3c00640b7400640d3c00640e7400640f3c006410740064113c00641264136702740064143c00740174006406190064156416641564178d047d0074026a0364188301010074046a0364198301010074056a037c0074006408190019008301010064005300291a4e7a0a507974686f6e20555344da0a746f6b656e5f6e616d65da0450555344da0c746f6b656e5f73796d626f6cda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da03646578da0f636f6e5f6c7573645f6c7374303031da046c757364da4062353631303930663739303536396465386363653866363134656263643265386337356532333031613032376533363135396237333462333930643339373532da086465765f61646472e901000000da076465765f746178da076d6e745f746178e902000000da076c69715f746178e907000000da1b616e74695f6d616e6970756c6174696f6e5f7468726573686f6c64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4036613930303463626335373035393263323138373965356565333139633735346239623762663032373838373862316363323161633837656564306565333864da096f70657261746f7273da0670726963657372020000002904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720500000072060000007201000000da066163746976652906da0a5f5f6d65746164617461da0b466f726569676e48617368da0e5f5f746f74616c5f737570706c79da03736574da0c5f5f646170705f7374617465da0c5f5f6c6173745f70726963652901da085f5f707269636573a900722b0000007208000000da045f5f5f5f0b0000007320000000000108010801080108020801080108010801080202010a0108010c010a010a01722c0000002902da036b6579da0576616c756563020000000000000004000000030000004300000073880000007c006a00830064016b03731474016402830182017c01732074016403830182017c0174027c00190074036a043c00740264011900640419007d02740264011900640519007d0374027c0019007c02190074027c0019007c0319006b02727e7c0174027c003c00640674027c0019007c023c00640674027c0019007c033c007405830001006400530029074e721f0000007a1543616e206e6f74206368616e6765206f776e6572737a22506172616d65746572202276616c7565222063616e206e6f7420626520656d7074797201000000721600000072080000002906da056c6f776572da0e417373657274696f6e4572726f727224000000da03637478da0663616c6c6572da0e5f5f6173736572745f6f776e65722904722d000000722e000000da066f776e657231da066f776e657232722b000000722b0000007208000000da0f6368616e67655f6d65746164617461200000007314000000000214010c010e010c010c01180108010c010c0172360000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e642129047230000000da0a5f5f62616c616e63657372310000007232000000290272370000007238000000722b000000722b0000007208000000da087472616e736665722e00000073080000000002100116011201723a000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047230000000da0c5f5f616c6c6f77616e63657372310000007232000000290272370000007238000000722b000000722b0000007208000000da07617070726f766536000000730400000000021001723c000000290372370000007238000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000738e0000007c0064016b047310740064028301820174017c0274026a03660219007c006b0573407400640374017c0274026a03660219009b0064047c009b009d048301820174047c0219007c006b057354740064058301820174017c0274026a036602050019007c00380003003c0074047c02050019007c00380003003c0074047c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a194e6f7420656e6f75676820636f696e7320746f2073656e642129057230000000723b000000723100000072320000007239000000290372370000007238000000723d000000722b000000722b0000007208000000da0d7472616e736665725f66726f6d3c000000730e000000000210010c012401140116011001723e0000002901da0a7461755f616d6f756e74630100000000000000060000000600000043000000730c0100007c0064016b047310740064028301820174016a02830064036b0273247400640483018201740374046405190064066407640664088d047d0174057c01740464091900190074066a028300180074066a0283001b008301640a14007d027c027404640b19006b05727474016a07640c830101006e947c00640a1b007404640d190014007d037c00640a1b007404640e190014007d0474086a097c00740a6a0b740a6a0c640f8d03010074086a0d7c0374046410190064118d0201007c007c0318007c0418007c0174046409190019001b007d05740e740a6a0c050019007c05370003003c00740f6a07740f6a0283007c0517008301010074066a077c017404640919001900830101006400530029124e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732172230000007a1c54686520646170702069732063757272656e746c7920706175736564721100000072200000007202000000290472210000007222000000720500000072060000007213000000e964000000721c000000da08696e61637469766572170000007218000000290372370000007238000000723d0000007215000000290272370000007238000000291072300000007228000000da0367657472250000007224000000da0361627372290000007227000000da03746175723e0000007231000000da04746869737232000000723a000000723900000072260000002906723f000000722a000000da0c70726963655f6368616e6765da0a6465765f616d6f756e74da0a6d6e745f616d6f756e74da0b707573645f616d6f756e74722b000000722b0000007208000000da0b7461755f746f5f7075736447000000732200000000021001140108010c01140110010c010c0210011001140212010c010c0112011201724a0000002901724900000063010000000000000005000000060000004300000073060100007c0064016b047310740064028301820174016a02830064036b0273247400640483018201740374046405190064066407640664088d047d0174057c01740464091900190074066a028300180074066a0283001b008301640a14007d027c027404640b19006b05727474016a07640c830101006e8e7c00640a1b007404640d190014007d037c007c0318007c01740464091900190014007d0474086a097c04740a6a0b640e8d020100740c740a6a0d050019007c03370003003c00740c740a6a0b050019007c00380003003c00740e6a07740e6a0283007c0018008301010074066a077c017404640919001900830101007c03640f6b0590017202740f7c03830101006400530029104e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732172230000007a1c54686520646170702069732063757272656e746c79207061757365647211000000722000000072020000002904722100000072220000007205000000720600000072130000007240000000721c0000007241000000721a000000290272370000007238000000e90a0000002910723000000072280000007242000000722500000072240000007243000000722900000072270000007244000000723a00000072310000007232000000723900000072450000007226000000da0f5f5f6164645f6c697175696469747929057249000000722a0000007246000000da0a6c69715f616d6f756e74723f000000722b000000722b0000007208000000da0b707573645f746f5f7461755e000000732200000000021001140108010c01140110010c010c0210011401100112011201120112010a01724e000000630100000000000000020000000400000043000000735e00000074007c0074016401190064028d02010074026a0374016401190083016a0474056a067c0064031b0064048d027d0174076a007c0174016401190064028d02010074026a0374016401190083016a0874056a067c0064058d0201006400530029064e7211000000290272370000007238000000721900000029027205000000da0c746f6b656e5f616d6f756e7429027205000000da0f63757272656e63795f616d6f756e742909723c0000007224000000da0149da0d696d706f72745f6d6f64756c65da0473656c6c723100000072450000007244000000da0d6164645f6c697175696469747929027249000000723f000000722b000000722b0000007208000000724c00000074000000730c0000000001100112010c0112011201724c000000630000000000000000010000000600000043000000733a000000740074016401190064026403640264048d047d0074026a037c0074016405190019008301010074046a036406830101007405830001006400530029074e721100000072200000007202000000290472210000007222000000720500000072060000007213000000722300000029067225000000722400000072290000007227000000722800000072330000002901722a000000722b000000722b0000007208000000da0c756e70617573655f646170707d000000730a000000000208010c0112010a0172550000006300000000000000000100000006000000430000007336000000740074016401190064026403640264048d047d0074026a0374046a05830164057c0074016406190019001b001400740683001b00530029074e72110000007220000000720200000029047221000000722200000072050000007206000000721600000072130000002907722500000072240000007244000000da0a62616c616e63655f6f6672310000007245000000da1263697263756c6174696e675f737570706c792901722a000000722b000000722b0000007208000000da196765745f63757272656e745f6261636b696e675f726174696f860000007306000000000208010c0272580000002902720500000072370000006302000000000000000200000005000000430000007328000000740064017c007c018303010074016a027c017c0074036a0464028d0301007405830001006400530029034eda0b6d6967726174655f746175290372370000007238000000723d0000002906da115f5f617070726f7665645f616374696f6e7244000000723a000000723100000072450000007233000000290272050000007237000000722b000000722b000000720800000072590000008e000000730600000000020c0112017259000000630200000000000000020000000400000043000000735e0000007c0164016b0473107400640283018201740174026a0319007c016b0573267400640383018201740464047c007c0183030100740174026a03050019007c01380003003c0074017c00050019007c01370003003c007405830001006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e6421da0c6d6967726174655f7075736429067230000000723900000072310000007245000000725a0000007233000000290272050000007237000000722b000000722b0000007208000000725b00000095000000730c0000000002100116010c0112011001725b0000006302000000000000000300000004000000430000007344000000740064017c007c018303010074016a0274036402190083017d027c026a0474056a067c007c01830301007c026a0774056a067c007c01830301007408830001006400530029034eda0a6d6967726174655f6c7072110000002909725a000000725100000072520000007224000000da11617070726f76655f6c697175696469747972310000007245000000da127472616e736665725f6c697175696469747972330000002903720500000072370000007211000000722b000000722b0000007208000000725c0000009f000000730a00000000020c010e0110011001725c0000002903da06616374696f6e720500000072370000006303000000000000000500000003000000430000007368000000740064011900640219007d03740064011900640319007d0474007c0019007c0319007c019b007c029b009d026b02733e740164047c039b009d028301820174007c0019007c0419007c019b007c029b009d026b027364740164047c049b009d02830182016400530029054e721f000000720100000072160000007a1357726f6e67206d6574616461746120666f72202902722400000072300000002905725f0000007205000000723700000072340000007235000000722b000000722b0000007208000000725a000000a8000000730c00000000010c010c010a011c010a01725a000000630000000000000000000000000300000043000000731400000074006a018300740274036a04190018009b00530029014e290572260000007242000000723900000072310000007245000000722b000000722b000000722b00000072080000007257000000b1000000730200000000027257000000630000000000000000000000000100000043000000730a00000074006a0183009b00530029014e290272260000007242000000722b000000722b000000722b0000007208000000720a000000b600000073020000000002630000000000000000000000000300000043000000731a00000074006a017402640119006b06731674036402830182016400530029034e721f0000007a1d4f6e6c792065786563757461626c65206279206f70657261746f72732129047231000000723200000072240000007230000000722b000000722b000000722b00000072080000007233000000bb00000073040000000001100172330000002921da0863757272656e63797244000000da09696d706f72746c69627251000000da04486173687239000000723b0000007224000000da085661726961626c65722600000072280000007229000000722c000000da085f5f6578706f7274da03737472da03416e797236000000da05666c6f6174723a000000723c000000723e000000724a000000724e000000724c000000725500000072580000007259000000725b000000725c000000725a0000007257000000720a0000007233000000722b000000722b000000722b0000007208000000da083c6d6f64756c653e010000007342000000080104010e010e010e010c010c010c0308150601120d06011207060112050601140a06011016060110150e0910091008060112060601120906011208120910051005