Contract con_pusd_v1_1


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 owner1_metadata_change = metadata[key, owner1]
54 owner2_metadata_change = metadata[key, owner2]
55
56
57 if owner1_metadata_change == owner2_metadata_change:
58 metadata[key] = value
59
60 metadata[key, owner1] = ''
61 metadata[key, owner2] = ''
62
63 assert_owner()
64
65 @export
66 def transfer(amount: float, to: str):
67 assert amount > 0, 'Cannot send negative balances!'
68 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
69
70 balances[ctx.caller] -= amount
71 balances[to] += amount
72
73 @export
74 def approve(amount: float, to: str):
75 assert amount > 0, 'Cannot send negative balances!'
76
77 allowances[ctx.caller, to] += amount
78
79 @export
80 def transfer_from(amount: float, to: str, main_account: str):
81 assert amount > 0, 'Cannot send negative balances!'
82 assert allowances[main_account, ctx.caller] >= amount, f'You approved {allowances[main_account, ctx.caller]} but need {amount}'
83 assert balances[main_account] >= amount, 'Not enough coins to send!'
84
85 allowances[main_account, ctx.caller] -= amount
86 balances[main_account] -= amount
87 balances[to] += amount
88
89 @export
90 def tau_to_pusd(tau_amount: float):
91 assert tau_amount > 0, 'Cannot send negative balances!'
92 assert dapp_state.get() == 'active', 'The dapp is currently paused'
93
94 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
95
96 price_change = abs(((prices[metadata['lusd']])-last_price.get())/last_price.get())*100
97
98 if (price_change >= metadata['anti_manipulation_threshold']):
99 dapp_state.set('inactive')
100 else:
101 dev_amount = tau_amount / 100 * metadata['dev_tax']
102 mnt_amount = tau_amount / 100 * metadata['mnt_tax']
103
104 tau.transfer_from(amount=tau_amount, to=ctx.this, main_account=ctx.caller)
105 tau.transfer(amount=dev_amount, to=metadata['dev_addr'])
106
107 pusd_amount = ((tau_amount - dev_amount - mnt_amount) / prices[metadata['lusd']])
108
109 balances[ctx.caller] += pusd_amount
110 total_supply.set(total_supply.get() + pusd_amount)
111 last_price.set(prices[metadata['lusd']])
112
113 @export
114 def pusd_to_tau(pusd_amount: float):
115 assert pusd_amount > 0, 'Cannot send negative balances!'
116 assert dapp_state.get() == 'active', 'The dapp is currently paused'
117
118 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
119
120 price_change = abs(((prices[metadata['lusd']])-last_price.get())/last_price.get())*100
121
122 if (price_change >= metadata['anti_manipulation_threshold']):
123 dapp_state.set('inactive')
124 else:
125 liq_amount = pusd_amount / 100 * metadata['liq_tax']
126 tau_amount = (pusd_amount - liq_amount) * prices[metadata['lusd']]
127
128 tau.transfer(amount=tau_amount, to=ctx.caller)
129
130 balances[ctx.this] += liq_amount
131 balances[ctx.caller] -= pusd_amount
132
133 total_supply.set(total_supply.get() - pusd_amount)
134 last_price.set(prices[metadata['lusd']])
135 if liq_amount >= 10:
136 add_liquidity(liq_amount)
137
138 def add_liquidity(pusd_amount: float):
139 approve(amount=pusd_amount, to=metadata['dex'])
140 tau_amount = I.import_module(metadata['dex']).sell(contract=ctx.this, token_amount=pusd_amount / 2)
141
142 tau.approve(amount=tau_amount, to=metadata['dex'])
143 I.import_module(metadata['dex']).add_liquidity(contract=ctx.this, currency_amount=pusd_amount)
144
145 @export
146 def unpause_dapp():
147 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
148 last_price.set(prices[metadata['lusd']])
149 dapp_state.set('active')
150 assert_owner()
151
152 @export
153 def get_current_backing_ratio(): # > 1 = Good
154 prices = ForeignHash(foreign_contract=metadata['dex'], foreign_name='prices')
155 return ((tau.balance_of(ctx.this) * (1 / prices[metadata['lusd']])) / circulating_supply())
156
157 @export
158 def migrate_tau(contract: str, amount: float):
159 approved_action('migrate_tau', contract, amount)
160
161 tau.transfer(amount=amount, to=contract, main_account=ctx.this)
162 assert_owner()
163
164 @export
165 def migrate_pusd(contract: str, amount: float):
166 assert amount > 0, 'Cannot send negative balances!'
167 assert balances[ctx.this] >= amount, 'Not enough coins to send!'
168
169 approved_action('migrate_pusd', contract, amount)
170
171 balances[ctx.this] -= amount
172 balances[contract] += amount
173 assert_owner()
174
175 @export
176 def migrate_lp(contract: str, amount: float):
177 approved_action('migrate_lp', contract, amount)
178
179 dex = I.import_module(metadata['dex'])
180 dex.approve_liquidity(ctx.this, contract, amount)
181 dex.transfer_liquidity(ctx.this, contract, amount)
182 assert_owner()
183
184 def approved_action(action: str, contract: str, amount: float):
185 owner1 = metadata['operators'][0]
186 owner2 = metadata['operators'][1]
187
188 owner1_action = metadata[action, owner1]
189 owner2_action = metadata[action, owner2]
190
191 assert owner1_action == f'{contract},{amount}', f'Wrong metadata for {owner1}'
192 assert owner2_action == f'{contract},{amount}', f'Wrong metadata for {owner2}'
193
194 @export
195 def circulating_supply():
196 return f'{total_supply.get() - balances[ctx.this]}'
197
198 @export
199 def total_supply():
200 return f'{total_supply.get()}'
201
202 def assert_owner():
203 assert ctx.caller in metadata['operators'], 'Only executable by operators!'

Byte Code

e3000000000000000000000000050000004000000073a4010000640064016c005a0165025a03650464006402640364048d035a05650464006402640564048d035a06650464066402640764048d035a0765086402640864098d025a0965086402640a64098d025a0a65086402640b64098d025a0b640c640d84005a0c650d64028301650e650f640e9c02640f6410840483015a10650d640283016511650e64119c0264126413840483015a12650d640283016511650e64119c0264146415840483015a13650d640283016511650e650e64169c0364176418840483015a14650d64028301651164199c01641a641b840483015a15650d640283016511641c9c01641d641e840483015a166511641c9c01641f642084045a17650d6402830164216422840083015a18650d6402830164236424840083015a19650d64028301650e651164259c0264266427840483015a1a650d64028301650e651164259c0264286429840483015a1b650d64028301650e651164259c02642a642b840483015a1c650e650e6511642c9c03642d642e84045a1d650d64028301642f6430840083015a1e650d6402830164316408840083015a1f6432643384005a20640153002934e9000000004eda0d636f6e5f707573645f76315f31da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0a616c6c6f77616e636573da00da086d65746164617461da0c746f74616c5f737570706c79290272050000007206000000da0a646170705f7374617465da0a6c6173745f707269636563000000000000000001000000060000004300000073920000006401740064023c006403740064043c006405740064063c006407740064083c0064097400640a3c00640b7400640c3c00640b7400640d3c00640e7400640f3c006410740064113c00641264136702740064143c00740174006406190064156416641564178d047d0074026a0364188301010074046a0364198301010074056a037c0074006408190019008301010064005300291a4e7a0a507974686f6e20555344da0a746f6b656e5f6e616d65da0450555344da0c746f6b656e5f73796d626f6cda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da03646578da0f636f6e5f6c7573645f6c7374303031da046c757364da4062353631303930663739303536396465386363653866363134656263643265386337356532333031613032376533363135396237333462333930643339373532da086465765f61646472e901000000da076465765f746178da076d6e745f746178e902000000da076c69715f746178e907000000da1b616e74695f6d616e6970756c6174696f6e5f7468726573686f6c64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4036613930303463626335373035393263323138373965356565333139633735346239623762663032373838373862316363323161633837656564306565333864da096f70657261746f7273da0670726963657372020000002904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720500000072060000007201000000da066163746976652906da0a5f5f6d65746164617461da0b466f726569676e48617368da0e5f5f746f74616c5f737570706c79da03736574da0c5f5f646170705f7374617465da0c5f5f6c6173745f70726963652901da085f5f707269636573a900722b0000007208000000da045f5f5f5f0c0000007320000000000108010801080108020801080108010801080202010a0108010c010a010a01722c0000002902da036b6579da0576616c756563020000000000000006000000040000004300000073900000007c006a00830064016b03731474016402830182017c01732074016403830182017c0174027c0074036a0466023c00740264011900640419007d02740264011900640519007d0374027c007c02660219007d0474027c007c03660219007d057c047c056b0272867c0174027c003c00640674027c007c0266023c00640674027c007c0366023c007405830001006400530029074e721f0000007a1543616e206e6f74206368616e6765206f776e6572737a22506172616d65746572202276616c7565222063616e206e6f7420626520656d7074797201000000721600000072080000002906da056c6f776572da0e417373657274696f6e4572726f727224000000da03637478da0663616c6c6572da0e5f5f6173736572745f6f776e65722906722d000000722e000000da066f776e657231da066f776e657232da166f776e6572315f6d657461646174615f6368616e6765da166f776e6572325f6d657461646174615f6368616e6765722b000000722b0000007208000000da0f6368616e67655f6d65746164617461210000007318000000000214010c010e010c010c010c010c01080108010c010c0172380000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e642129047230000000da0a5f5f62616c616e6365737231000000723200000029027239000000723a000000722b000000722b0000007208000000da087472616e736665723100000073080000000002100116011201723c000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047230000000da0c5f5f616c6c6f77616e6365737231000000723200000029027239000000723a000000722b000000722b0000007208000000da07617070726f766539000000730400000000021001723e00000029037239000000723a000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000738e0000007c0064016b047310740064028301820174017c0274026a03660219007c006b0573407400640374017c0274026a03660219009b0064047c009b009d048301820174047c0219007c006b057354740064058301820174017c0274026a036602050019007c00380003003c0074047c02050019007c00380003003c0074047c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a194e6f7420656e6f75676820636f696e7320746f2073656e642129057230000000723d00000072310000007232000000723b00000029037239000000723a000000723f000000722b000000722b0000007208000000da0d7472616e736665725f66726f6d3f000000730e000000000210010c01240114011601100172400000002901da0a7461755f616d6f756e74630100000000000000060000000600000043000000730c0100007c0064016b047310740064028301820174016a02830064036b0273247400640483018201740374046405190064066407640664088d047d0174057c01740464091900190074066a028300180074066a0283001b008301640a14007d027c027404640b19006b05727474016a07640c830101006e947c00640a1b007404640d190014007d037c00640a1b007404640e190014007d0474086a097c00740a6a0b740a6a0c640f8d03010074086a0d7c0374046410190064118d0201007c007c0318007c0418007c0174046409190019001b007d05740e740a6a0c050019007c05370003003c00740f6a07740f6a0283007c0517008301010074066a077c017404640919001900830101006400530029124e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732172230000007a1c54686520646170702069732063757272656e746c7920706175736564721100000072200000007202000000290472210000007222000000720500000072060000007213000000e964000000721c000000da08696e6163746976657217000000721800000029037239000000723a000000723f000000721500000029027239000000723a000000291072300000007228000000da0367657472250000007224000000da0361627372290000007227000000da0374617572400000007231000000da04746869737232000000723c000000723b000000722600000029067241000000722a000000da0c70726963655f6368616e6765da0a6465765f616d6f756e74da0a6d6e745f616d6f756e74da0b707573645f616d6f756e74722b000000722b0000007208000000da0b7461755f746f5f707573644a000000732200000000021001140108010c01140110010c010c0210011001140212010c010c0112011201724c0000002901724b00000063010000000000000005000000060000004300000073060100007c0064016b047310740064028301820174016a02830064036b0273247400640483018201740374046405190064066407640664088d047d0174057c01740464091900190074066a028300180074066a0283001b008301640a14007d027c027404640b19006b05727474016a07640c830101006e8e7c00640a1b007404640d190014007d037c007c0318007c01740464091900190014007d0474086a097c04740a6a0b640e8d020100740c740a6a0d050019007c03370003003c00740c740a6a0b050019007c00380003003c00740e6a07740e6a0283007c0018008301010074066a077c017404640919001900830101007c03640f6b0590017202740f7c03830101006400530029104e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732172230000007a1c54686520646170702069732063757272656e746c79207061757365647211000000722000000072020000002904722100000072220000007205000000720600000072130000007242000000721c0000007243000000721a00000029027239000000723a000000e90a0000002910723000000072280000007244000000722500000072240000007245000000722900000072270000007246000000723c00000072310000007232000000723b00000072470000007226000000da0f5f5f6164645f6c69717569646974792905724b000000722a0000007248000000da0a6c69715f616d6f756e747241000000722b000000722b0000007208000000da0b707573645f746f5f74617561000000732200000000021001140108010c01140110010c010c0210011401100112011201120112010a017250000000630100000000000000020000000400000043000000735e00000074007c0074016401190064028d02010074026a0374016401190083016a0474056a067c0064031b0064048d027d0174076a007c0174016401190064028d02010074026a0374016401190083016a0874056a067c0064058d0201006400530029064e721100000029027239000000723a000000721900000029027205000000da0c746f6b656e5f616d6f756e7429027205000000da0f63757272656e63795f616d6f756e742909723e0000007224000000da0149da0d696d706f72745f6d6f64756c65da0473656c6c723100000072470000007246000000da0d6164645f6c69717569646974792902724b0000007241000000722b000000722b0000007208000000724e00000077000000730c0000000001100112010c0112011201724e000000630000000000000000010000000600000043000000733a000000740074016401190064026403640264048d047d0074026a037c0074016405190019008301010074046a036406830101007405830001006400530029074e721100000072200000007202000000290472210000007222000000720500000072060000007213000000722300000029067225000000722400000072290000007227000000722800000072330000002901722a000000722b000000722b0000007208000000da0c756e70617573655f6461707080000000730a000000000208010c0112010a0172570000006300000000000000000100000006000000430000007336000000740074016401190064026403640264048d047d0074026a0374046a05830164057c0074016406190019001b001400740683001b00530029074e72110000007220000000720200000029047221000000722200000072050000007206000000721600000072130000002907722500000072240000007246000000da0a62616c616e63655f6f6672310000007247000000da1263697263756c6174696e675f737570706c792901722a000000722b000000722b0000007208000000da196765745f63757272656e745f6261636b696e675f726174696f890000007306000000000208010c02725a0000002902720500000072390000006302000000000000000200000005000000430000007328000000740064017c007c018303010074016a027c017c0074036a0464028d0301007405830001006400530029034eda0b6d6967726174655f74617529037239000000723a000000723f0000002906da115f5f617070726f7665645f616374696f6e7246000000723c000000723100000072470000007233000000290272050000007239000000722b000000722b0000007208000000725b00000091000000730600000000020c011201725b000000630200000000000000020000000400000043000000735e0000007c0164016b0473107400640283018201740174026a0319007c016b0573267400640383018201740464047c007c0183030100740174026a03050019007c01380003003c0074017c00050019007c01370003003c007405830001006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e6421da0c6d6967726174655f7075736429067230000000723b00000072310000007247000000725c0000007233000000290272050000007239000000722b000000722b0000007208000000725d00000098000000730c0000000002100116010c0112011001725d0000006302000000000000000300000004000000430000007344000000740064017c007c018303010074016a0274036402190083017d027c026a0474056a067c007c01830301007c026a0774056a067c007c01830301007408830001006400530029034eda0a6d6967726174655f6c7072110000002909725c000000725300000072540000007224000000da11617070726f76655f6c697175696469747972310000007247000000da127472616e736665725f6c697175696469747972330000002903720500000072390000007211000000722b000000722b0000007208000000725e000000a2000000730a00000000020c010e0110011001725e0000002903da06616374696f6e720500000072390000006303000000000000000700000004000000430000007374000000740064011900640219007d03740064011900640319007d0474007c007c03660219007d0574007c007c04660219007d067c057c019b0064047c029b009d036b027350740164057c039b009d02830182017c067c019b0064047c029b009d036b027370740164057c049b009d02830182016400530029064e721f00000072010000007216000000fa012c7a1357726f6e67206d6574616461746120666f7220290272240000007230000000290772610000007205000000723900000072340000007235000000da0d6f776e6572315f616374696f6eda0d6f776e6572325f616374696f6e722b000000722b0000007208000000725c000000ab000000730c00000000010c010c010c010c012001725c000000630000000000000000000000000300000043000000731400000074006a018300740274036a04190018009b00530029014e290572260000007244000000723b00000072310000007247000000722b000000722b000000722b00000072080000007259000000b4000000730200000000027259000000630000000000000000000000000100000043000000730a00000074006a0183009b00530029014e290272260000007244000000722b000000722b000000722b0000007208000000720a000000b900000073020000000002630000000000000000000000000300000043000000731a00000074006a017402640119006b06731674036402830182016400530029034e721f0000007a1d4f6e6c792065786563757461626c65206279206f70657261746f72732129047231000000723200000072240000007230000000722b000000722b000000722b00000072080000007233000000be00000073040000000001100172330000002921da0863757272656e63797246000000da09696d706f72746c69627253000000da0448617368723b000000723d0000007224000000da085661726961626c65722600000072280000007229000000722c000000da085f5f6578706f7274da03737472da03416e797238000000da05666c6f6174723c000000723e0000007240000000724c0000007250000000724e0000007257000000725a000000725b000000725d000000725e000000725c0000007259000000720a0000007233000000722b000000722b000000722b0000007208000000da083c6d6f64756c653e010000007344000000080104010e01060108010e010c010c010c0308150601120f06011207060112050601140a06011016060110150e0910091008060112060601120906011208120910051005