Contract con_gold_flip_001


Contract Code


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

Byte Code

e30000000000000000000000000400000040000000730c01000065006a018300010065025a0365046400640164028d025a0565046400640364028d025a0665046400640464028d025a0765046400640564028d025a0865046400640664028d025a0965046400640764028d025a0a65046400640864028d025a0b6409640a84005a0c650d64008301650e650f640b9c02640c640d840483015a10650d64008301650e640e9c01640f6410840483015a11650d64008301650e640e9c0164116412840483015a12650d64008301651364139c0164146415840483015a14650d64008301651364139c0164166417840483015a15650d64008301650e650f640b9c0264186419840483015a16650d64008301650e650f640b9c02641a641b840483015a17641c5300291dda11636f6e5f676f6c645f666c69705f303031da056f776e65722902da08636f6e7472616374da046e616d65da096275726e5f72617465da0c726573657276655f72617465da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74da0c6275726e5f61646472657373da0f726573657276655f61646472657373630000000000000000000000000300000043000000735400000074006a0174026a038301010074046a017405640183018301010074066a017405640283018301010074076a0164038301010074086a0164048301010074096a01640583010100740a6a016406830101006400530029074e7a03312e307a03312e3569a02526006980969800da1e303030303030303030303030304255524e30303030303030303030303030da4039366461653362363231336662383065616337633666346661306664323666333430323237343163353637373331303762323031393963623433663565643632290bda075f5f6f776e6572da03736574da03637478da0663616c6c6572da0b5f5f6275726e5f72617465da07646563696d616cda0e5f5f726573657276655f72617465da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74da0e5f5f6275726e5f61646472657373da115f5f726573657276655f61646472657373a90072180000007218000000da00da045f5f5f5f0d000000731000000000010c010e010e010a010a010a010401721a0000002902da06616d6f756e74da0e746f6b656e5f636f6e747261637463020000000000000003000000050000004300000073de0000006401740074016a028300830117007d027c0074016a0283006b05732474037c02830182016402740074046a028300830117007d027c0074046a0283006b01734874037c028301820174056a067c0183016a077c0074086a0974086a0a64038d030100740b6a0c6404640567028301728e74056a067c0183016a0d7c006406140074086a0a64078d0201006408530074056a067c0183016a0d7c0064091b00740e6a0283001400740f6a02830064078d02010074056a067c0183016a0d7c0064091b0074106a028300140074116a02830064078d020100640a530064005300290b4e7a28416d6f756e74206d75737420626520657175616c20746f206f722067726561746572207468616e207a25416d6f756e74206d75737420626520657175616c20746f206f72206c657373207468616e202903721b000000da02746fda0c6d61696e5f6163636f756e745446e9020000002902721b000000721d0000007a07596f7520574f4ee9640000007a08596f75204c4f53542912da037374727214000000da03676574da0e417373657274696f6e4572726f727215000000da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6d720f000000da04746869737210000000da0672616e646f6dda0663686f696365da087472616e7366657272110000007216000000721300000072170000002903721b000000721c000000da056572726f72721800000072180000007219000000da04666c697018000000731c0000000002100214011001140110010a010e011a0204021001140110011401722c0000002901da0770657263656e74630100000000000000020000000200000043000000734400000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05722e7c0064046b01733674047c018301820174056a067c00830101006400530029054e7a1f4f6e6c79206f776e65722063616e2061646a757374206275726e20726174657a1557726f6e67206275726e20726174652076616c7565e90000000072200000002907720f0000007210000000720d000000722200000072230000007211000000720e0000002902722d000000722b000000721800000072180000007219000000da1061646a7573745f6275726e5f726174652d000000730a00000000020401160104011801722f000000630100000000000000020000000200000043000000734400000064017d0174006a0174026a0383006b02731a74047c018301820164027d017c0064036b05722e7c0064046b01733674047c018301820174056a067c00830101006400530029054e7a224f6e6c79206f776e65722063616e2061646a757374207265736572766520726174657a1857726f6e67207265736572766520726174652076616c7565722e00000072200000002907720f0000007210000000720d000000722200000072230000007213000000720e0000002902722d000000722b000000721800000072180000007219000000da1361646a7573745f726573657276655f7261746536000000730a0000000002040116010401180172300000002901721b000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a204f6e6c79206f776e65722063616e2061646a757374206d696e20616d6f756e742907720f0000007210000000720d000000722200000072230000007214000000720e0000002902721b000000722b000000721800000072180000007219000000da0a61646a7573745f6d696e3f00000073060000000002040116017231000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a204f6e6c79206f776e65722063616e2061646a757374206d617820616d6f756e742907720f0000007210000000720d000000722200000072230000007215000000720e0000002902721b000000722b000000721800000072180000007219000000da0a61646a7573745f6d61784600000073060000000002040116017232000000630200000000000000030000000500000043000000733200000064017d027c0064026b04731474007c028301820174016a027c0183016a037c0074046a0574046a0664038d0301006400530029044e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f776564722e0000002903721b000000721d000000721e00000029077223000000722400000072250000007226000000720f000000722700000072100000002903721b000000721c000000722b000000721800000072180000007219000000da067061795f696e4d000000730800000000020401100110017233000000630200000000000000030000000400000043000000734800000064017d027c0064026b04731474007c028301820164037d0274016a0274036a0483006b02732e74007c028301820174056a067c0183016a077c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f776564722e0000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902721b000000721d00000029087223000000720f0000007210000000720d000000722200000072240000007225000000722a0000002903721b000000721c000000722b000000721800000072180000007219000000da077061795f6f757455000000730a0000000002040110010401160172340000004e29187228000000da0473656564da09696d706f72746c69627224000000da085661726961626c65720d000000721100000072130000007214000000721500000072160000007217000000721a000000da085f5f6578706f7274da05666c6f61747221000000722c000000722f0000007230000000da03696e7472310000007232000000723300000072340000007218000000721800000072180000007219000000da083c6d6f64756c653e010000007330000000080104010c010c010c010c010c010c0104010803080b0601121406011008060110080601100606011006060112070601