Contract con_pyusd_v2


Contract Code


  
1 # v2_Final Python USD - Experimental Risky Lamden Fully Decentralized Stable Coin
2 # Check collateralization TAU to PYUSD by using get_current_backing_ratio()
3 # !!If its 1 everything is fine and > 1 its amazing and overcollateralized!!
4 # You can exchange TAU to PYUSD and PYUSD to TAU at any point at the same ratio that LUSD-TAU is at using tau_to_pyusd() or pyusd_to_tau()
5 # Dont forget to approve TAU to con_pyusd or tau_to_pyusd() exchange function doesnt work or just use the Swap dApp UI
6 # Difference to LUSD is that PYUSD is collateralized by TAU on this chain instead of USDT
7 # 2% protocol fee only on tau_to_pyusd() or pyusd_to_tau() - no extra fee on rocketswap but limited liq on rocketswap
8 # Stablecoin Swap available at https://ipfs.io/ipfs/QmduzBgnsz2VftqmUaFDpWFW9Mw4ks8z6n5GEzMTG62hRB !!!
9
10 import currency as tau
11 import con_rocketswap_official_v1_1 as rocketswap
12
13 balances = Hash(default_value=0)
14 metadata = Hash()
15
16 prices = ForeignHash(foreign_contract='con_rocketswap_official_v1_1', foreign_name='prices')
17
18 dev_tax = Variable()
19 liquidity_tax = Variable()
20
21 dev_address = Variable()
22 total_supply = Variable()
23
24
25 @construct
26 def seed():
27 metadata['token_name'] = "Python USD"
28 metadata['token_symbol'] = "PYUSD"
29 metadata['operator'] = ctx.caller
30
31 balances[ctx.caller] = 0
32
33 dev_tax.set(1)
34 dev_address.set('6a9004cbc570592c21879e5ee319c754b9b7bf0278878b1cc21ac87eed0ee38d')
35 liquidity_tax.set(1)
36
37 total_supply.set(0)
38
39 @export
40 def change_metadata(key: str, value: Any):
41 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
42 metadata[key] = value
43
44 @export
45 def transfer(amount: float, to: str):
46 assert amount > 0, 'Cannot send negative balances!'
47 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
48 balances[ctx.caller] -= amount
49 balances[to] += amount
50
51 @export
52 def approve(amount: float, to: str):
53 assert amount > 0, 'Cannot send negative balances!'
54 balances[ctx.caller, to] += amount
55
56 @export
57 def transfer_from(amount: float, to: str, main_account: str):
58 assert amount > 0, 'Cannot send negative balances!'
59 assert balances[main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
60 .format(balances[main_account, ctx.caller], amount)
61 assert balances[main_account] >= amount, 'Not enough coins to send!'
62 balances[main_account, ctx.caller] -= amount
63 balances[main_account] -= amount
64 balances[to] += amount
65
66 @export
67 def tau_to_pyusd(amount: float):
68 tau.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
69 tax_amount = ((amount / prices["con_lusd_lst001"]) / 100 * (dev_tax.get() + liquidity_tax.get()))
70 balances[ctx.caller] += ((amount / prices["con_lusd_lst001"]) - tax_amount)
71 balances[dev_address.get()] += tax_amount / 2
72 balances[ctx.this] += tax_amount / 2
73 total_supply.set(total_supply.get() + (amount / prices["con_lusd_lst001"]))
74 if(tax_amount/2 > 5):
75 add_liquidity()
76
77 @export
78 def pyusd_to_tau(amount: float):
79 tax_amount = (amount / 100 * (dev_tax.get() + liquidity_tax.get()))
80 final_amount = amount - tax_amount
81 balances[ctx.caller] -= amount
82 balances[dev_address.get()] += tax_amount / 2
83 balances[ctx.this] += tax_amount / 2
84 total_supply.set(total_supply.get() - final_amount)
85 tau.transfer(amount=final_amount*prices["con_lusd_lst001"], to=ctx.caller)
86 if(tax_amount/2 > 5):
87 add_liquidity()
88
89 @export
90 def get_current_backing_ratio():
91 # > 1 = Good
92 return ((tau.balance_of(ctx.this) * circulating_supply())/ prices["con_lusd_lst001"])
93
94
95 def add_liquidity():
96 token_amount = balances[ctx.this] / 2
97 approve(amount=token_amount, to="con_rocketswap_official_v1_1")
98 tau_amount = rocketswap.sell(contract="con_pyusd_v2", token_amount=token_amount)
99 tau.approve(amount=tau_amount, to="con_rocketswap_official_v1_1")
100 rocketswap.add_liquidity(contract="con_pyusd_v2", currency_amount=tau_amount)
101
102 @export
103 def circulating_supply():
104 return (total_supply.get() - balances[ctx.this])
105
106 @export
107 def total_supply():
108 return (total_supply.get())
109

Byte Code

e30000000000000000000000000600000040000000733c010000640064016c005a01640064016c025a03650464006402640364048d035a0565046402640564068d025a066507640764086402640864098d045a0865096402640a64068d025a0a65096402640b64068d025a0b65096402640c64068d025a0c65096402640d64068d025a0d640e640f84005a0e650f640283016510651164109c0264116412840483015a12650f640283016513651064139c0264146415840483015a14650f640283016513651064139c0264166417840483015a15650f6402830165136510651064189c036419641a840483015a16650f640283016513641b9c01641c641d840483015a17650f640283016513641b9c01641e641f840483015a18650f6402830164206421840083015a196422642384005a1a650f6402830164246425840083015a1b650f640283016426640d840083015a1c640153002927e9000000004eda0c636f6e5f70797573645f7632da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272050000007206000000da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da067072696365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572050000007206000000da076465765f746178da0d6c69717569646974795f746178da0b6465765f61646472657373da0c746f74616c5f737570706c7963000000000000000000000000030000004300000073500000006401740064023c006403740064043c0074016a02740064053c006406740374016a023c0074046a0564078301010074066a0564088301010074076a0564078301010074086a056406830101006400530029094e7a0a507974686f6e20555344da0a746f6b656e5f6e616d65da055059555344da0c746f6b656e5f73796d626f6cda086f70657261746f727201000000e901000000da40366139303034636263353730353932633231383739653565653331396337353462396237626630323738383738623163633231616338376565643065653338642909da0a5f5f6d65746164617461da03637478da0663616c6c6572da0a5f5f62616c616e636573da095f5f6465765f746178da03736574da0d5f5f6465765f61646472657373da0f5f5f6c69717569646974795f746178da0e5f5f746f74616c5f737570706c79a900721f000000721f000000da00da045f5f5f5f0d00000073120000000001080108010a010a010a01040106010a0172210000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e72130000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721700000072180000007216000000da0e417373657274696f6e4572726f72290272220000007223000000721f000000721f0000007220000000da0f6368616e67655f6d6574616461746119000000730600000000021001060172250000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e642129047224000000721900000072170000007218000000290272260000007227000000721f000000721f0000007220000000da087472616e7366657220000000730800000000021001160112017228000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047224000000721900000072170000007218000000290272260000007227000000721f000000721f0000007220000000da07617070726f7665280000007304000000000210017229000000290372260000007227000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000738a0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e642129057224000000721900000072170000007218000000da06666f726d6174290372260000007227000000722a000000721f000000721f0000007220000000da0d7472616e736665725f66726f6d2e0000007310000000000210010c010c011401140116011001722c0000002901722600000063010000000000000002000000060000004300000073b000000074006a017c0074026a0374026a0464018d0301007c007405640219001b0064031b0074066a07830074086a078300170014007d01740974026a04050019007c007405640219001b007c011800370003003c007409740a6a078300050019007c0164041b00370003003c00740974026a03050019007c0164041b00370003003c00740b6a0c740b6a0783007c007405640219001b001700830101007c0164041b0064056b0472ac740d830001006400530029064e290372260000007227000000722a000000da0f636f6e5f6c7573645f6c7374303031e964000000e902000000e905000000290eda03746175722c0000007217000000da04746869737218000000da085f5f707269636573721a000000da03676574721d0000007219000000721c000000721e000000721b000000da0f5f5f6164645f6c697175696469747929027226000000da0a7461785f616d6f756e74721f000000721f0000007220000000da0c7461755f746f5f70797573643a00000073140000000002140114010c011e01180116010e010c010c01723700000063010000000000000003000000050000004300000073a00000007c0064011b0074006a01830074026a018300170014007d017c007c0118007d02740374046a05050019007c00380003003c00740374066a018300050019007c0164021b00370003003c00740374046a07050019007c0164021b00370003003c0074086a0974086a0183007c02180083010100740a6a0b7c02740c64031900140074046a0564048d0201007c0164021b0064056b04729c740d830001006400530029064e722e000000722f000000722d0000002902722600000072270000007230000000290e721a0000007234000000721d000000721900000072170000007218000000721c0000007232000000721e000000721b0000007231000000722800000072330000007235000000290372260000007236000000da0c66696e616c5f616d6f756e74721f000000721f0000007220000000da0c70797573645f746f5f746175480000007312000000000218010801120118011601120118020c017239000000630000000000000000000000000300000043000000731a00000074006a0174026a0383017404830014007405640119001b00530029024e722d00000029067231000000da0a62616c616e63655f6f6672170000007232000000da1263697263756c6174696e675f737570706c797233000000721f000000721f000000721f0000007220000000da196765745f63757272656e745f6261636b696e675f726174696f56000000730400000000021201723c0000006300000000000000000200000004000000430000007348000000740074016a02190064011b007d0074037c00640264038d02010074046a0564047c0064058d027d0174066a037c01640264038d02010074046a0764047c0164068d0201006400530029074e722f0000007208000000290272260000007227000000720200000029027205000000da0c746f6b656e5f616d6f756e7429027205000000da0f63757272656e63795f616d6f756e7429087219000000721700000072320000007229000000da0a726f636b657473776170da0473656c6c7231000000da0d6164645f6c69717569646974792902723d000000da0a7461755f616d6f756e74721f000000721f000000722000000072350000005c000000730e00000000010e010c01060108010e0106017235000000630000000000000000000000000300000043000000731200000074006a018300740274036a0419001800530029014e2905721e0000007234000000721900000072170000007232000000721f000000721f000000721f0000007220000000723b0000006600000073020000000002723b000000630000000000000000000000000100000043000000730800000074006a018300530029014e2902721e0000007234000000721f000000721f000000721f0000007220000000720f0000006b00000073020000000002291dda0863757272656e637972310000007208000000723f000000da044861736872190000007216000000da0b466f726569676e486173687233000000da085661726961626c65721a000000721d000000721c000000721e0000007221000000da085f5f6578706f7274da03737472da03416e797225000000da05666c6f617472280000007229000000722c00000072370000007239000000723c0000007235000000723b000000720f000000721f000000721f000000721f0000007220000000da083c6d6f64756c653e010000007334000000080108010e010c0104010c010c010c010c010c03080c0601120606011207060112050601140b0601100d0601100d1006080a1005