Contract con_gamma_phi_house_v2


Contract Code


  
1 # con_gamma_phi_house_v2
2 import currency as tau
3 import con_phi_lst001 as phi
4
5 tau_balances = ForeignHash(foreign_contract='currency', foreign_name='balances')
6 phi_balances = ForeignHash(foreign_contract='con_phi_lst001', foreign_name='balances')
7
8 owner = Variable()
9
10 min_bet = Variable()
11 max_bet = Variable()
12
13 wheel_multipliers = Variable()
14
15 random.seed()
16
17 @construct
18 def seed():
19 min_bet.set(1)
20 max_bet.set(1000)
21 wheel_multipliers.set([10, 1, 0, 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 3, 0, 0])
22 owner.set(ctx.caller)
23
24 @export
25 def flip_phi(amount: float, odds: float = 0.5):
26 assert odds >= 0.001, 'Odds must be >= 0.001'
27 assert odds <= 0.999, 'Odds must be <= 0.999'
28 assert phi_balances[ctx.caller] >= amount, 'Insufficient funds!'
29 assert amount >= min_bet.get(), f'Must bet at least {min_bet.get()}'
30 assert amount <= max_bet.get(), f'Cannot bet more than {max_bet.get()}'
31 payout = amount / odds
32 assert payout - amount < phi_balances[ctx.this], f'Not enough money in the bank :('
33 phi.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
34 r = random.randint(0, 999)
35 if r < odds * 1000:
36 phi.transfer(amount=payout, to=ctx.caller)
37
38 @export
39 def spin_wheel(amount: float):
40 assert phi_balances[ctx.caller] >= amount, 'Insufficient funds!'
41 assert amount >= min_bet.get(), f'Must bet at least {min_bet.get()}'
42 assert amount <= max_bet.get(), f'Cannot bet more than {max_bet.get()}'
43 multipliers = wheel_multipliers.get()
44 max_payout = amount * max(multipliers)
45 assert max_payout - amount < phi_balances[ctx.this], f'Not enough money in the bank :('
46 phi.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
47 num = len(multipliers)
48 lucky_spin = random.randint(0, num-1)
49 multiplier = multipliers[lucky_spin]
50 if multiplier > 0:
51 phi.transfer(amount=multiplier * amount, to=ctx.caller)
52 return lucky_spin
53
54 @export
55 def roll_dice(amount: float):
56 assert phi_balances[ctx.caller] >= amount, 'Insufficient funds!'
57 assert amount >= min_bet.get(), f'Must bet at least {min_bet.get()}'
58 assert amount <= max_bet.get(), f'Cannot bet more than {max_bet.get()}'
59
60 n_dice = 5
61
62 multi_5_kind = 185.14285714285717
63 multi_4_kind = multi_5_kind * (6.0/150.0)
64 multi_full_house = multi_5_kind * (6.0/300.0)
65 multi_3_kind = multi_5_kind * (6.0/1200.0)
66 multi_2_pair = multi_5_kind * (6.0/1800.0)
67 multi_2_kind = multi_5_kind * (6.0/3600.0)
68 multi_straight = multi_5_kind * (6.0/720.0)
69
70
71 max_payout = amount * multi_5_kind
72
73 assert max_payout - amount < phi_balances[ctx.this], f'Not enough money in the bank :('
74
75 phi.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
76
77 rolls = []
78
79 for i in range(n_dice):
80 rolls.append(random.randint(1, 6))
81
82 unique = set(rolls)
83
84 n_unique = len(unique)
85
86 count_map = {x: rolls.count(x) for x in unique}
87 counts = list(count_map.values())
88
89 if n_unique == n_dice:
90 # Straight
91 multiplier = multi_straight
92 elif n_unique == 1:
93 # 5 of a kind
94 multiplier = multi_5_kind
95 elif n_unique == 2:
96 # Check
97 if max(counts) == 4:
98 # 4 of a kind
99 multiplier = multi_4_kind
100 else:
101 # Full house
102 multiplier = multi_full_house
103 elif n_unique == 3:
104 if max(counts) == 3:
105 # 3 of a kind
106 multiplier = multi_3_kind
107 else:
108 # 2 pair
109 multiplier = multi_2_pair
110 else:
111 # single pair
112 multiplier = multi_2_kind
113
114 if multiplier > 0:
115 phi.transfer(amount=multiplier * amount, to=ctx.caller)
116
117 return rolls
118
119 @export
120 def set_wheel_multipliers(multipliers: list):
121 error = "Only the owner can adjust the min amount"
122 assert owner.get() == ctx.caller, error
123 wheel_multipliers.set(multipliers)
124
125 @export
126 def set_min(amount: int):
127 error = "Only the owner can adjust the min amount"
128 assert owner.get() == ctx.caller, error
129 min_bet.set(amount)
130
131 @export
132 def set_max(amount: int):
133 error = "Only the owner can adjust the max amount"
134 assert owner.get() == ctx.caller, error
135 max_bet.set(amount)
136
137
138 @export
139 def change_ownership(new_owner: str):
140 assert ctx.caller == owner.get(), 'Only the owner can change ownership!'
141
142 owner.set(new_owner)
143
144 @export
145 def pay_out(amount: float):
146 error = "Negative amount is not allowed"
147 assert amount > 0, error
148
149 error = "Only owner can payout tokens"
150 assert ctx.caller == owner.get(), error
151
152 # Transfer tokens from contract to owner
153 phi.transfer(
154 amount=amount,
155 to=ctx.caller)

Byte Code

e30000000000000000000000000600000040000000732e010000640064016c005a01640064016c025a036504640264036404640564068d045a056504640764036404640864068d045a06650764046409640a8d025a0865076404640b640a8d025a0965076404640c640a8d025a0a65076404640d640a8d025a0b650c6a0d83000100640e640f84005a0e650f6404830165106410830166016511651164119c0264126413840583015a12650f64048301651164149c0164156416840483015a13650f64048301651164149c0164176418840483015a14650f64048301651564199c01641a641b840483015a16650f64048301651764149c01641c641d840483015a18650f64048301651764149c01641e641f840483015a19650f64048301651a64209c0164216422840483015a1b650f64048301651164149c0164236424840483015a1c640153002925e9000000004eda0863757272656e6379da0862616c616e636573da16636f6e5f67616d6d615f7068695f686f7573655f7632da0c7461755f62616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da0e636f6e5f7068695f6c7374303031da0c7068695f62616c616e636573da056f776e6572290272080000007209000000da076d696e5f626574da076d61785f626574da11776865656c5f6d756c7469706c69657273630000000000000000000000001900000043000000735e00000074006a0164018301010074026a0164028301010074036a0164036401640464056404640664046404640464016404640464046405640464046404640164046401640464066404640467188301010074046a0174056a06830101006400530029074ee90100000069e8030000e90a0000007201000000e902000000e9030000002907da095f5f6d696e5f626574da03736574da095f5f6d61785f626574da135f5f776865656c5f6d756c7469706c69657273da075f5f6f776e6572da03637478da0663616c6c6572a900721b000000721b000000da00da045f5f5f5f10000000730a00000000010a010a0122011801721d0000007a03302e352902da06616d6f756e74da046f64647363020000000000000004000000050000004300000073dc0000007c017400640183016b05731474016402830182017c017400640383016b0173287401640483018201740274036a0419007c006b05733e74016405830182017c0074056a0683006b05735c7401640674056a0683009b009d02830182017c0074076a0683006b01737a7401640774076a0683009b009d02830182017c007c011b007d027c027c001800740274036a0819006b00739c740164088301820174096a0a7c0074036a0874036a0464098d030100740b6a0c640a640b83027d037c037c01640c14006b0072d874096a0d7c0274036a04640d8d02010064005300290e4e7a05302e3030317a154f646473206d757374206265203e3d20302e3030317a05302e3939397a154f646473206d757374206265203c3d20302e3939397a13496e73756666696369656e742066756e6473217a124d75737420626574206174206c65617374207a1543616e6e6f7420626574206d6f7265207468616e207a1f4e6f7420656e6f756768206d6f6e657920696e207468652062616e6b203a282903721e000000da02746fda0c6d61696e5f6163636f756e74720100000069e703000069e80300002902721e0000007220000000290eda07646563696d616cda0e417373657274696f6e4572726f72da0e5f5f7068695f62616c616e6365737219000000721a0000007214000000da036765747216000000da0474686973da03706869da0d7472616e736665725f66726f6dda0672616e646f6dda0772616e64696e74da087472616e736665722904721e000000721f000000da067061796f7574da0172721b000000721b000000721c000000da08666c69705f70686918000000731800000000021401140116011e011e0108011401060114010c010c01722e0000002901721e00000063010000000000000006000000050000004300000073d4000000740074016a0219007c006b05731674036401830182017c0074046a0583006b0573347403640274046a0583009b009d02830182017c0074066a0583006b0173527403640374066a0583009b009d028301820174076a0583007d017c0074087c01830114007d027c027c001800740074016a0919006b0073807403640483018201740a6a0b7c0074016a0974016a0264058d030100740c7c0183017d03740d6a0e64067c036407180083027d047c017c0419007d057c0564066b0472d0740a6a0f7c057c00140074016a0264088d0201007c04530029094e7a13496e73756666696369656e742066756e6473217a124d75737420626574206174206c65617374207a1543616e6e6f7420626574206d6f7265207468616e207a1f4e6f7420656e6f756768206d6f6e657920696e207468652062616e6b203a282903721e00000072200000007221000000720100000072100000002902721e0000007220000000291072240000007219000000721a00000072230000007214000000722500000072160000007217000000da036d6178722600000072270000007228000000da036c656e7229000000722a000000722b0000002906721e000000da0b6d756c7469706c69657273da0a6d61785f7061796f7574da036e756dda0a6c75636b795f7370696eda0a6d756c7469706c696572721b000000721b000000721c000000da0a7370696e5f776865656c28000000731c000000000216011e011e0108010c0114010601140108011001080108011401723600000063010000000000000010000000050000000300000073f2010000740074016a0219007c006b05731674036401830182017c0074046a0583006b0573347403640274046a0583009b009d02830182017c0074066a0583006b0173527403640374066a0583009b009d028301820164047d017407640583017d027c027407640683017407640783011b0014007d037c027407640683017407640883011b0014007d047c027407640683017407640983011b0014007d057c027407640683017407640a83011b0014007d067c027407640683017407640b83011b0014007d077c027407640683017407640c83011b0014007d087c007c0214007d097c097c001800740074016a0819006b0073f87403640d8301820174096a0a7c0074016a0874016a02640e8d030100670089007824740b7c01830144005d187d0a88006a0c740d6a0e640f64108302830101009001711a5700740f880083017d0b74107c0b83017d0c870066016411641284087c0b440083017d0d74117c0d6a12830083017d0e7c0c7c016b02900172747c087d0f6e5c7c0c640f6b02900172847c027d0f6e4c7c0c64136b02900172a874137c0e830164146b02900172a27c037d0f6e047c047d0f6e287c0c64156b02900172cc74137c0e830164156b02900172c67c057d0f6e047c067d0f6e047c077d0f7c0f64166b04900172ee74096a147c0f7c00140074016a0264178d0201008800530029184e7a13496e73756666696369656e742066756e6473217a124d75737420626574206174206c65617374207a1543616e6e6f7420626574206d6f7265207468616e20e9050000007a123138352e31343238353731343238353731377a03362e307a053135302e307a053330302e307a06313230302e307a06313830302e307a06333630302e307a053732302e307a1f4e6f7420656e6f756768206d6f6e657920696e207468652062616e6b203a282903721e000000722000000072210000007210000000e906000000630100000000000000020000000400000013000000731800000069007c005d107d0188006a007c0183017c01930271045300721b0000002901da05636f756e742902da022e30da01782901da05726f6c6c73721b000000721c000000fa0a3c64696374636f6d703e50000000730200000006007a1d726f6c6c5f646963652e3c6c6f63616c733e2e3c64696374636f6d703e7212000000e904000000721300000072010000002902721e0000007220000000291572240000007219000000721a00000072230000007214000000722500000072160000007222000000722600000072270000007228000000da0572616e6765da06617070656e647229000000722a00000072150000007230000000da046c697374da0676616c756573722f000000722b0000002910721e000000da066e5f64696365da0c6d756c74695f355f6b696e64da0c6d756c74695f345f6b696e64da106d756c74695f66756c6c5f686f757365da0c6d756c74695f335f6b696e64da0c6d756c74695f325f70616972da0c6d756c74695f325f6b696e64da0e6d756c74695f73747261696768747232000000da0169da06756e69717565da086e5f756e69717565da09636f756e745f6d6170da06636f756e74737235000000721b0000002901723c000000721c000000da09726f6c6c5f646963653a000000734c000000000216011e011e0104010801140114011401140114011401080114010601140104010e0118010801080112010c010a0106010a0106010a010e01060206010a010e010602060204010a011401725000000029017231000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d696e20616d6f756e742907721800000072250000007219000000721a00000072230000007217000000721500000029027231000000da056572726f72721b000000721b000000721c000000da157365745f776865656c5f6d756c7469706c696572736700000073060000000002040116017252000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d696e20616d6f756e742907721800000072250000007219000000721a0000007223000000721400000072150000002902721e0000007251000000721b000000721b000000721c000000da077365745f6d696e6e00000073060000000002040116017253000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d617820616d6f756e742907721800000072250000007219000000721a0000007223000000721600000072150000002902721e0000007251000000721b000000721b000000721c000000da077365745f6d617875000000730600000000020401160172540000002901da096e65775f6f776e6572630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a244f6e6c7920746865206f776e65722063616e206368616e6765206f776e6572736869702129067219000000721a000000721800000072250000007223000000721500000029017255000000721b000000721b000000721c000000da106368616e67655f6f776e6572736869707c0000007304000000000216017256000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902721e0000007220000000290772230000007219000000721a000000721800000072250000007227000000722b0000002902721e0000007251000000721b000000721b000000721c000000da077061795f6f757482000000730a000000000204011001040116017257000000291d7202000000da03746175720a0000007227000000da0b466f726569676e48617368da0e5f5f7461755f62616c616e6365737224000000da085661726961626c6572180000007214000000721600000072170000007229000000da0473656564721d000000da085f5f6578706f72747222000000da05666c6f6174722e0000007236000000725000000072410000007252000000da03696e7472530000007254000000da0373747272560000007257000000721b000000721b000000721b000000721c000000da083c6d6f64756c653e01000000733a0000000801080104010c010401040108010c010c010c01040108010803080806011a0f060110110601102c060110060601100606011006060110050601