Contract con_dice003


Contract Code


  
1 import currency as tau
2 import con_degen as degen
3
4 random.seed()
5
6 owner = Variable()
7 min_amount = Variable()
8 max_amount = Variable()
9 multiplier = Variable()
10 degen_payout = Variable()
11 degen_balance = Variable()
12
13 @construct
14 def init():
15 owner.set(ctx.caller)
16 min_amount.set(10)
17 max_amount.set(100)
18 multiplier.set(5)
19 degen_payout.set(0.5)
20 degen_balance.set(0)
21
22 @export
23 def roll(guess: int, amount: float):
24 error = "Not a valid dice number"
25 assert (guess >= 1 and guess <= 6), error
26
27 error = "Min bet amount is " + str(min_amount.get())
28 assert amount >= min_amount.get(), error
29
30 error = "Max bet amount is " + str(max_amount.get())
31 assert amount <= max_amount.get(), error
32
33 balance = tau.balance_of(account=ctx.this)
34
35 error = "Contract balance too low to pay for possible win"
36 assert balance >= amount * multiplier.get(), error
37
38 tau.transfer_from(
39 amount=amount,
40 to=ctx.this,
41 main_account=ctx.caller)
42
43 result = random.randint(1, 6)
44
45 if result == guess:
46 tau.transfer(
47 amount=amount * multiplier.get(),
48 to=ctx.caller)
49 else:
50 degen_amount = degen_payout.get() * amount
51
52 if degen_balance.get() >= degen_amount:
53 degen.transfer(
54 amount=degen_amount,
55 to=ctx.caller)
56
57 degen_balance.set(degen_balance.get() - degen_amount)
58
59 return result
60
61 @export
62 def deposit_tau(amount: float):
63 tau.transfer_from(
64 amount=amount,
65 to=ctx.this,
66 main_account=ctx.caller)
67
68 @export
69 def withdraw_tau(amount: float):
70 error = "Only the owner can request a payout"
71 assert owner.get() == ctx.caller, error
72
73 tau.transfer(
74 amount=amount,
75 to=ctx.caller)
76
77 @export
78 def deposit_degen(amount: float):
79 degen.transfer_from(
80 amount=amount,
81 to=ctx.this,
82 main_account=ctx.caller)
83
84 degen_balance.set(degen_balance.get() + amount)
85
86 @export
87 def withdraw_degen(amount: float):
88 error = "Only the owner can withdraw DEGEN tokens"
89 assert owner.get() == ctx.caller, error
90
91 degen.transfer(
92 amount=amount,
93 to=ctx.caller)
94
95 degen_balance.set(degen_balance.get() - amount)
96
97 @export
98 def set_min(amount: int):
99 error = "Only the owner can adjust the min amount"
100 assert owner.get() == ctx.caller, error
101
102 min_amount.set(amount)
103
104 @export
105 def set_max(amount: int):
106 error = "Only the owner can adjust the max amount"
107 assert owner.get() == ctx.caller, error
108
109 max_amount.set(amount)
110
111 @export
112 def set_loss_payout(amount: float):
113 error = "Only the owner can adjust the loss payout"
114 assert owner.get() == ctx.caller, error
115
116 degen_payout.set(amount)
117

Byte Code

e30000000000000000000000000400000040000000731e010000640064016c005a01640064016c025a0365046a058300010065066402640364048d025a0765066402640564048d025a0865066402640664048d025a0965066402640764048d025a0a65066402640864048d025a0b65066402640964048d025a0c640a640b84005a0d650e64028301650f6510640c9c02640d640e840483015a11650e640283016510640f9c0164106411840483015a12650e640283016510640f9c0164126413840483015a13650e640283016510640f9c0164146415840483015a14650e640283016510640f9c0164166417840483015a15650e64028301650f640f9c0164186419840483015a16650e64028301650f640f9c01641a641b840483015a17650e640283016510640f9c01641c641d840483015a1864015300291ee9000000004eda0b636f6e5f64696365303033da056f776e65722902da08636f6e7472616374da046e616d65da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74da0a6d756c7469706c696572da0c646567656e5f7061796f7574da0d646567656e5f62616c616e6365630000000000000000000000000300000043000000734600000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0164038301010074076a017408640483018301010074096a016405830101006400530029064ee90a000000e964000000e9050000007a03302e357201000000290ada075f5f6f776e6572da03736574da03637478da0663616c6c6572da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74da0c5f5f6d756c7469706c696572da0e5f5f646567656e5f7061796f7574da07646563696d616cda0f5f5f646567656e5f62616c616e6365a90072180000007218000000da00da045f5f5f5f0c000000730c00000000010c010a010a010a010e01721a0000002902da056775657373da06616d6f756e74630200000000000000060000000500000043000000731001000064017d027c0064026b0572147c0064036b01731c74007c02830182016404740174026a038300830117007d027c0174026a0383006b05734074007c02830182016405740174046a038300830117007d027c0174046a0383006b01736474007c028301820174056a0674076a0864068d017d0364077d027c037c0174096a03830014006b05738e74007c028301820174056a0a7c0174076a0874076a0b64088d030100740c6a0d6402640383027d047c047c006b0272d074056a0e7c0174096a038300140074076a0b64098d0201006e3c740f6a0383007c0114007d0574106a0383007c056b059001720c74116a0e7c0574076a0b64098d02010074106a1274106a0383007c051800830101007c045300290a4e7a174e6f7420612076616c69642064696365206e756d626572e901000000e9060000007a124d696e2062657420616d6f756e74206973207a124d61782062657420616d6f756e74206973202901da076163636f756e747a30436f6e74726163742062616c616e636520746f6f206c6f7720746f2070617920666f7220706f737369626c652077696e2903721c000000da02746fda0c6d61696e5f6163636f756e742902721c00000072200000002913da0e417373657274696f6e4572726f72da037374727212000000da036765747213000000da03746175da0a62616c616e63655f6f667210000000da04746869737214000000da0d7472616e736665725f66726f6d7211000000da0672616e646f6dda0772616e64696e74da087472616e7366657272150000007217000000da05646567656e720f0000002906721b000000721c000000da056572726f72da0762616c616e6365da06726573756c74da0c646567656e5f616d6f756e74721800000072180000007219000000da04726f6c6c15000000732400000000020401180110011401100114010e010401180114010c0108011a020c010e011001120172310000002901721c000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903721c000000722000000072210000002905722500000072280000007210000000722700000072110000002901721c000000721800000072180000007219000000da0b6465706f7369745f7461752c000000730200000000027232000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a234f6e6c7920746865206f776e65722063616e20726571756573742061207061796f75742902721c00000072200000002907720e00000072240000007210000000721100000072220000007225000000722b0000002902721c000000722d000000721800000072180000007219000000da0c77697468647261775f7461753100000073060000000002040116017233000000630100000000000000010000000500000043000000732a00000074006a017c0074026a0374026a0464018d03010074056a0674056a0783007c001700830101006400530029024e2903721c000000722000000072210000002908722c00000072280000007210000000722700000072110000007217000000720f00000072240000002901721c000000721800000072180000007219000000da0d6465706f7369745f646567656e380000007304000000000214017234000000630100000000000000020000000400000043000000734000000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d02010074076a0874076a0183007c001800830101006400530029034e7a284f6e6c7920746865206f776e65722063616e20776974686472617720444547454e20746f6b656e732902721c00000072200000002909720e0000007224000000721000000072110000007222000000722c000000722b0000007217000000720f0000002902721c000000722d000000721800000072180000007219000000da0e77697468647261775f646567656e3e000000730800000000020401160110017235000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d696e20616d6f756e742907720e00000072240000007210000000721100000072220000007212000000720f0000002902721c000000722d000000721800000072180000007219000000da077365745f6d696e4600000073060000000002040116017236000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d617820616d6f756e742907720e00000072240000007210000000721100000072220000007213000000720f0000002902721c000000722d000000721800000072180000007219000000da077365745f6d61784d00000073060000000002040116017237000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a294f6e6c7920746865206f776e65722063616e2061646a75737420746865206c6f7373207061796f75742907720e00000072240000007210000000721100000072220000007215000000720f0000002902721c000000722d000000721800000072180000007219000000da0f7365745f6c6f73735f7061796f757454000000730600000000020401160172380000002919da0863757272656e63797225000000da09636f6e5f646567656e722c0000007229000000da0473656564da085661726961626c65720e00000072120000007213000000721400000072150000007217000000721a000000da085f5f6578706f7274da03696e74da05666c6f6174723100000072320000007233000000723400000072350000007236000000723700000072380000007218000000721800000072180000007219000000da083c6d6f64756c653e0100000073320000000801080108010c010c010c010c010c010c030809060112160601100406011006060110050601100706011006060110060601