Contract con_mint


Contract Code


  
1 tokenName = 'mintedTAU'
2 import currency
3 __S = Hash(default_value=0, contract='con_mint', name='S')
4 __approved = Hash(default_value=0, contract='con_mint', name='approved')
5 __liquidityTokenBalance = Hash(default_value=0, contract='con_mint', name=
6 'liquidityTokenBalance')
7 __lastBlockMined = Hash(default_value=0, contract='con_mint', name=
8 'lastBlockMined')
9 totalMined = block_num
10 totalLiquidityTokens = 100
11
12
13 @__export('con_mint')
14 def mine():
15 assert block_num > __lastBlockMined + 100
16 miner = ctx.caller
17 amount = (block_num - totalMined) / 100
18 totalMined += amount
19 __S[miner] += amount
20
21
22 @__export('con_mint')
23 def approve(amount: float, to: str):
24 assert amount > 0, 'Cannot approve negative balance'
25 sender = ctx.caller
26 __approved[sender, to] += amount
27
28
29 @__export('con_mint')
30 def transfer_from(amount: float, to: str, fromAddress: str):
31 assert amount > 0, 'Cannot send negative balance'
32 sender = ctx.caller
33 assert __approved[fromAddress, sender
34 ] >= amount, 'Transfer amount exceeds approved balance'
35 assert __S[fromAddress
36 ] >= amount, 'Transfer amount exceeds available balance'
37 __approved[fromAddress, sender] -= amount
38 __S[fromAddress] -= amount
39 __S[to] += amount
40
41
42 @__export('con_mint')
43 def transfer(amount: int, receiver: str):
44 assert amount > 0, 'Cannot send negative balance'
45 sender = ctx.caller
46 balance = __S[sender]
47 assert balance >= amount, 'Transfer amount exceeds available balance'
48 __S[sender] -= amount
49 __S[receiver] += amount
50
51
52 @__export('con_mint')
53 def tradeTAUForToken(amount: int, fromAddress: str):
54 assert amount > 0, 'Cannot send negative balance'
55 currency.transfer_from(amount, ctx.this, fromAddress)
56 inputReserve = currency.balance_of(ctx.this)
57 outputReserve = __S[ctx.this]
58 assert input_reserve > 0 and output_reserve > 0
59 numerator = amount * outputReserve
60 denominator = inputReserve * 1000 + amount
61 amount = numerator / denominator
62 __S[ctx.this] -= amount
63 __S[fromAddress] += amount
64
65
66 @__export('con_mint')
67 def tradeTokenForTAU(amount: int, fromAddress: str):
68 assert amount > 0, 'Cannot send negative balance'
69 assert __S[fromAddress] >= amount
70 inputReserve = __S[ctx.this]
71 outputReserve = currency.balance_of(ctx.this)
72 assert input_reserve > 0 and output_reserve > 0
73 numerator = amount * outputReserve
74 denominator = inputReserve * 1000 + amount
75 amount = numerator / denominator
76 __S[fromAddress] -= amount
77 __S[ctx.this] += amount
78 currency.transfer(amount, fromAddress)
79
80
81 @__export('con_mint')
82 def addLiquidity(amountInTAU: int):
83 assert amountInTAU > 0, 'Cannot add negative liquidity'
84 assert __S[ctx.caller] >= amountInTau * __S[ctx.this
85 ] / currency.balance_of(ctx.this)
86 tokenReserve = __S[ctx.this]
87 TAUReserve = currency.balance_of(ctx.this)
88 currency.transfer_from(amountInTau, ctx.this, ctx.caller)
89 __S[ctx.caller] -= amountInTau * __S[ctx.this] / currency.balance_of(ctx
90 .this)
91 assert __S[ctx.caller] >= 0
92 tokenWorthInTAU = TAUReserve / totalLiquidityTokens
93 tokenAmount = amountInTAU / tokenWorthInTAU
94 __liquidityTokenBalance[ctx.caller] += tokenAmount
95 totalLiquidityTokens += tokenAmount
96 return tokenAmount
97
98
99 @__export('con_mint')
100 def removeLiquidity(amount: int):
101 assert amountInTAU > 0, 'Cannot add negative liquidity'
102 assert totalLiquidityTokens > 0
103 assert __liquidityTokenBalance > 0
104 __liquidityTokenBalance[ctx.caller] -= amount
105 totalLiquidityTokens -= amount
106 send(msg.sender, eth_amount)
107 percentOfPool = amount / totalLiquidityTokens
108 tokenPayout = __S[ctx.this] * percentOfPool
109 TAUPayout = currency.balance_of(ctx.this) * percentOfPool
110 currency.transfer(TAUPayout, ctx.caller)
111 __S[ctx.this] -= tokenPayout
112 __S[ctx.caller] += tokenPayout
113 return TAUPayout, tokenPayout
114
115
116 @__export('con_mint')
117 def transferLiquidityToken(amount: int, receiver: str):
118 assert amount > 0, 'Cannot send negative balance'
119 sender = ctx.caller
120 balance = __liquidityTokenBalance[sender]
121 assert balance >= amount, 'Transfer amount exceeds available balance'
122 __liquidityTokenBalance[sender] -= amount
123 __liquidityTokenBalance[receiver] += amount
124
125
126 @__export('con_mint')
127 def allowance(owner: str, spender: str):
128 return __approved[owner, spender]
129
130
131 @__export('con_mint')
132 def liquidityRatio():
133 tokenReserve = __S[ctx.this]
134 TAUReserve = currency.balance_of(ctx.this)
135 return TAUReserve / tokenReserve
136

Byte Code

e30000000000000000000000000500000040000000734601000064005a00640164026c015a01650264016403640464058d035a03650264016403640664058d035a04650264016403640764058d035a05650264016403640864058d035a0665075a0864095a09650a64038301640a640b840083015a0b650a64038301650c650d640c9c02640d640e840483015a0e650a64038301650c650d650d640f9c0364106411840483015a0f650a640383016510650d64129c0264136414840483015a11650a640383016510650d64159c0264166417840483015a12650a640383016510650d64159c0264186419840483015a13650a640383016510641a9c01641b641c840483015a14650a640383016510641d9c01641e641f840483015a15650a640383016510650d64129c0264206421840483015a16650a64038301650d650d64229c0264236424840483015a17650a6403830164256426840083015a18640253002927da096d696e746564544155e9000000004eda08636f6e5f6d696e74da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da08617070726f766564da156c6971756964697479546f6b656e42616c616e6365da0e6c617374426c6f636b4d696e6564e964000000630000000000000000030000000400000043000000733e00000074007401640117006b0473107402820174036a047d0074007c01180064011b007d027c017c0237007d0174057c00050019007c02370003003c006400530029024e720b0000002906da09626c6f636b5f6e756dda105f5f6c617374426c6f636b4d696e6564da0e417373657274696f6e4572726f72da03637478da0663616c6c6572da035f5f532903da056d696e6572da0a746f74616c4d696e6564da06616d6f756e74a9007215000000da00da046d696e650d000000730a0000000002100106010c010801721700000029027214000000da02746f630200000000000000030000000400000043000000732e0000007c0064016b047310740064028301820174016a027d0274037c027c016602050019007c00370003003c006400530029034e72020000007a1f43616e6e6f7420617070726f7665206e656761746976652062616c616e63652904720e000000720f0000007210000000da0a5f5f617070726f766564290372140000007218000000da0673656e646572721500000072150000007216000000da07617070726f7665160000007306000000000210010601721b000000290372140000007218000000da0b66726f6d41646472657373630300000000000000040000000400000043000000737a0000007c0064016b047310740064028301820174016a027d0374037c027c03660219007c006b05732e740064038301820174047c0219007c006b057342740064048301820174037c027c036602050019007c00380003003c0074047c02050019007c00380003003c0074047c01050019007c00370003003c006400530029054e72020000007a1c43616e6e6f742073656e64206e656761746976652062616c616e63657a285472616e7366657220616d6f756e74206578636565647320617070726f7665642062616c616e63657a295472616e7366657220616d6f756e74206578636565647320617661696c61626c652062616c616e63652905720e000000720f000000721000000072190000007211000000290472140000007218000000721c000000721a000000721500000072150000007216000000da0d7472616e736665725f66726f6d1d00000073120000000002100106010a010e0106010e0114011001721d00000029027214000000da08726563656976657263020000000000000004000000040000004300000073520000007c0064016b047310740064028301820174016a027d0274037c0219007d037c037c006b05732e740064038301820174037c02050019007c00380003003c0074037c01050019007c00370003003c006400530029044e72020000007a1c43616e6e6f742073656e64206e656761746976652062616c616e63657a295472616e7366657220616d6f756e74206578636565647320617661696c61626c652062616c616e63652904720e000000720f0000007210000000721100000029047214000000721e000000721a000000da0762616c616e6365721500000072150000007216000000da087472616e736665722a000000730c000000000210010601080110011001722000000029027214000000721c000000630200000000000000060000000400000043000000738c0000007c0064016b047310740064028301820174016a027c0074036a047c018303010074016a0574036a0483017d02740674036a0419007d03740764016b047246740864016b04734a740082017c007c0314007d047c02640314007c0017007d057c047c051b007d00740674036a04050019007c00380003003c0074067c01050019007c00370003003c006400530029044e72020000007a1c43616e6e6f742073656e64206e656761746976652062616c616e636569e80300002909720e000000da0863757272656e6379721d000000720f000000da0474686973da0a62616c616e63655f6f667211000000da0d696e7075745f72657365727665da0e6f75747075745f7265736572766529067214000000721c000000da0c696e70757452657365727665da0d6f757470757452657365727665da096e756d657261746f72da0b64656e6f6d696e61746f72721500000072150000007216000000da107472616465544155466f72546f6b656e3400000073140000000002100110010c010a01140108010c0108011201722a00000063020000000000000006000000040000004300000073980000007c0064016b047310740064028301820174017c0119007c006b05732074008201740174026a0319007d0274046a0574026a0383017d03740664016b047246740764016b04734a740082017c007c0314007d047c02640314007c0017007d057c047c051b007d0074017c01050019007c00380003003c00740174026a03050019007c00370003003c0074046a087c007c01830201006400530029044e72020000007a1c43616e6e6f742073656e64206e656761746976652062616c616e636569e80300002909720e0000007211000000720f00000072220000007221000000722300000072240000007225000000722000000029067214000000721c0000007226000000722700000072280000007229000000721500000072150000007216000000da107472616465546f6b656e466f725441554200000073160000000002100110010a010c01140108010c01080110011201722b0000002901da0b616d6f756e74496e54415563010000000000000006000000060000004300000073c80000007c0064016b0473107400640283018201740174026a0319007404740174026a051900140074066a0774026a0583011b006b05733874008201740174026a0519007d0174066a0774026a0583017d0274066a08740474026a0574026a0383030100740174026a03050019007404740174026a051900140074066a0774026a0583011b00380003003c00740174026a03190064016b05739a740082017c027c031b007d047c007c041b007d05740974026a03050019007c05370003003c007c037c0537007d037c05530029034e72020000007a1d43616e6e6f7420616464206e65676174697665206c6971756964697479290a720e0000007211000000720f0000007210000000da0b616d6f756e74496e546175722200000072210000007223000000721d000000da175f5f6c6971756964697479546f6b656e42616c616e63652906722c000000da0c746f6b656e52657365727665da0a54415552657365727665da14746f74616c4c6971756964697479546f6b656e73da0f746f6b656e576f727468496e544155da0b746f6b656e416d6f756e74721500000072150000007216000000da0c6164644c697175696469747951000000731a00000000021001080120010a010c01120128021201080108011201080172340000002901721400000063010000000000000005000000040000004300000073ae000000740064016b04731074016402830182017c0164016b04731c74018201740264016b04732874018201740274036a04050019007c00380003003c007c017c0038007d01740574066a077408830201007c007c011b007d02740974036a0a19007c0214007d03740b6a0c74036a0a83017c0214007d04740b6a0d7c0474036a0483020100740974036a0a050019007c03380003003c00740974036a04050019007c03370003003c007c047c036602530029034e72020000007a1d43616e6e6f7420616464206e65676174697665206c6971756964697479290e722c000000720e000000722e000000720f0000007210000000da0473656e64da036d7367721a000000da0a6574685f616d6f756e7472110000007222000000722100000072230000007220000000290572140000007231000000da0d70657263656e744f66506f6f6cda0b746f6b656e5061796f7574da095441555061796f7574721500000072150000007216000000da0f72656d6f76654c697175696469747963000000731a000000000210010c010c01120108010c0108010e0110010e0112011201723b00000063020000000000000004000000040000004300000073520000007c0064016b047310740064028301820174016a027d0274037c0219007d037c037c006b05732e740064038301820174037c02050019007c00380003003c0074037c01050019007c00370003003c006400530029044e72020000007a1c43616e6e6f742073656e64206e656761746976652062616c616e63657a295472616e7366657220616d6f756e74206578636565647320617661696c61626c652062616c616e63652904720e000000720f0000007210000000722e00000029047214000000721e000000721a000000721f000000721500000072150000007216000000da167472616e736665724c6971756964697479546f6b656e74000000730c000000000210010601080110011001723c0000002902da056f776e6572da077370656e646572630200000000000000020000000300000043000000730c00000074007c007c0166021900530029014e290172190000002902723d000000723e000000721500000072150000007216000000da09616c6c6f77616e63657e00000073020000000002723f000000630000000000000000020000000200000043000000731e000000740074016a0219007d0074036a0474016a0283017d017c017c001b00530029014e29057211000000720f0000007222000000722100000072230000002902722f0000007230000000721500000072150000007216000000da0e6c6971756964697479526174696f83000000730600000000020a010c0172400000002919da09746f6b656e4e616d657221000000da044861736872110000007219000000722e000000720d000000720c00000072130000007231000000da085f5f6578706f72747217000000da05666c6f6174da03737472721b000000721d000000da03696e747220000000722a000000722b0000007234000000723b000000723c000000723f00000072400000007215000000721500000072150000007216000000da083c6d6f64756c653e01000000733a000000040108010e010e010601080106010801040104031009060112060601140c060112090601120d0601120e06011011060110100601120906011204