Contract con_gold_flip


Contract Code


  
1 random.seed()
2 I = importlib
3
4 owner = Variable()
5 burn_rate = Variable()
6 min_amount = Variable()
7 max_amount = Variable()
8 burn_address = Variable()
9
10 @construct
11 def init():
12 # Owner of this contract
13 owner.set(ctx.caller)
14 # Burn rate for lost flips in %
15 burn_rate.set(10)
16 # Min amount of tokens to bet
17 min_amount.set(2500000)
18 # Max amount of tokens to bet
19 max_amount.set(10000000)
20 # Burn tokens by sending to this address
21 burn_address.set("0000000000000BURN0000000000000")
22
23 @export
24 def flip(amount: float, token_contract: str):
25 error = "Amount must be equal to or greater than " + str(min_amount.get())
26 assert amount >= min_amount.get(), error
27
28 error = "Amount must be equal to or less than " + str(max_amount.get())
29 assert amount <= max_amount.get(), error
30
31 # Transfer tokens from user to contract
32 I.import_module(token_contract).transfer_from(
33 amount=amount,
34 to=ctx.this,
35 main_account=ctx.caller)
36
37 # Randomly decide if user won or lost
38 if random.choice([True, False]):
39 # Transfer tokens from contract to user
40 I.import_module(token_contract).transfer(
41 amount=amount*2,
42 to=ctx.caller)
43
44 return "You WON"
45
46 else:
47 # Burn percent of bet amount
48 I.import_module(token_contract).transfer(
49 amount=amount/100*burn_rate.get(),
50 to=burn_address.get())
51
52 return "You LOST"
53
54 @export
55 def adjust_burn(percent: float):
56 error = "Only owner can adjust burn rate"
57 assert ctx.caller == owner.get(), error
58
59 error = "Wrong burn rate value"
60 assert (percent >= 0 and percent <= 100), error
61
62 burn_rate.set(percent)
63
64 @export
65 def adjust_min(amount: int):
66 error = "Only owner can adjust min amount"
67 assert ctx.caller == owner.get(), error
68
69 min_amount.set(amount)
70
71 @export
72 def adjust_max(amount: int):
73 error = "Only owner can adjust max amount"
74 assert ctx.caller == owner.get(), error
75
76 max_amount.set(amount)
77
78 @export
79 def pay_in(amount: float, token_contract: str):
80 error = "Negative amount is not allowed"
81 assert amount > 0, error
82
83 # Transfer tokens from user to contract
84 I.import_module(token_contract).transfer_from(
85 amount=amount,
86 to=ctx.this,
87 main_account=ctx.caller)
88
89 @export
90 def pay_out(amount: float, token_contract: str):
91 error = "Negative amount is not allowed"
92 assert amount > 0, error
93
94 error = "Only owner can payout tokens"
95 assert ctx.caller == owner.get(), error
96
97 # Transfer tokens from contract to owner
98 I.import_module(token_contract).transfer(
99 amount=amount,
100 to=ctx.caller)

Byte Code

e3000000000000000000000000040000004000000073de00000065006a018300010065025a0365046400640164028d025a0565046400640364028d025a0665046400640464028d025a0765046400640564028d025a0865046400640664028d025a096407640884005a0a650b64008301650c650d64099c02640a640b840483015a0e650b64008301650c640c9c01640d640e840483015a0f650b640083016510640f9c0164106411840483015a11650b640083016510640f9c0164126413840483015a12650b64008301650c650d64099c0264146415840483015a13650b64008301650c650d64099c0264166417840483015a14641853002919da0d636f6e5f676f6c645f666c6970da056f776e65722902da08636f6e7472616374da046e616d65da096275726e5f72617465da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74da0c6275726e5f61646472657373630000000000000000000000000200000043000000733800000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0164038301010074076a016404830101006400530029054ee90a00000069a02526006980969800da1e303030303030303030303030304255524e303030303030303030303030302908da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0b5f5f6275726e5f72617465da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74da0e5f5f6275726e5f61646472657373a90072130000007213000000da00da045f5f5f5f0a000000730a00000000010c010a010a010a0172150000002902da06616d6f756e74da0e746f6b656e5f636f6e747261637463020000000000000003000000050000004300000073ba0000006401740074016a028300830117007d027c0074016a0283006b05732474037c02830182016402740074046a028300830117007d027c0074046a0283006b01734874037c028301820174056a067c0183016a077c0074086a0974086a0a64038d030100740b6a0c6404640567028301728e74056a067c0183016a0d7c006406140074086a0a64078d0201006408530074056a067c0183016a0d7c0064091b00740e6a0283001400740f6a02830064078d020100640a530064005300290b4e7a28416d6f756e74206d75737420626520657175616c20746f206f722067726561746572207468616e207a25416d6f756e74206d75737420626520657175616c20746f206f72206c657373207468616e2029037216000000da02746fda0c6d61696e5f6163636f756e745446e9020000002902721600000072180000007a07596f7520574f4ee9640000007a08596f75204c4f53542910da037374727210000000da03676574da0e417373657274696f6e4572726f727211000000da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6d720d000000da0474686973720e000000da0672616e646f6dda0663686f696365da087472616e73666572720f0000007212000000290372160000007217000000da056572726f72721300000072130000007214000000da04666c69701200000073180000000002100214011001140110010a010e011a0204021001140172270000002901da0770657263656e74630100000000000000020000000200000043000000734400000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05722e7c0064046b01733674047c018301820174056a067c00830101006400530029054e7a1f4f6e6c79206f776e65722063616e2061646a757374206275726e20726174657a1557726f6e67206275726e20726174652076616c7565e900000000721b0000002907720d000000720e000000720b000000721d000000721e000000720f000000720c000000290272280000007226000000721300000072130000007214000000da0b61646a7573745f6275726e25000000730a00000000020401160104011801722a00000029017216000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a204f6e6c79206f776e65722063616e2061646a757374206d696e20616d6f756e742907720d000000720e000000720b000000721d000000721e0000007210000000720c000000290272160000007226000000721300000072130000007214000000da0a61646a7573745f6d696e2e0000007306000000000204011601722b000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a204f6e6c79206f776e65722063616e2061646a757374206d617820616d6f756e742907720d000000720e000000720b000000721d000000721e0000007211000000720c000000290272160000007226000000721300000072130000007214000000da0a61646a7573745f6d6178350000007306000000000204011601722c000000630200000000000000030000000500000043000000733200000064017d027c0064026b04731474007c028301820174016a027c0183016a037c0074046a0574046a0664038d0301006400530029044e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f776564722900000029037216000000721800000072190000002907721e000000721f00000072200000007221000000720d0000007222000000720e0000002903721600000072170000007226000000721300000072130000007214000000da067061795f696e3c00000073080000000002040110011001722d000000630200000000000000030000000400000043000000734800000064017d027c0064026b04731474007c028301820164037d0274016a0274036a0483006b02732e74007c028301820174056a067c0183016a077c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472290000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902721600000072180000002908721e000000720d000000720e000000720b000000721d000000721f000000722000000072250000002903721600000072170000007226000000721300000072130000007214000000da077061795f6f757444000000730a00000000020401100104011601722e0000004e29157223000000da0473656564da09696d706f72746c6962721f000000da085661726961626c65720b000000720f0000007210000000721100000072120000007215000000da085f5f6578706f7274da05666c6f6174721c0000007227000000722a000000da03696e74722b000000722c000000722d000000722e0000007213000000721300000072130000007214000000da083c6d6f64756c653e010000007326000000080104010c010c010c010c010c03080806011212060110080601100606011006060112070601