Contract con_colider_006


Contract Code


  
1 import currency as tau
2 import con_collider_contract as lhc
3 import con_rocketswap_official_v1_1 as rswp
4
5 random.seed()
6
7 owner = Variable()
8 min_amount = Variable()
9 max_amount = Variable()
10
11
12 @construct
13 def init():
14 owner.set(ctx.caller)
15 min_amount.set(15)
16 max_amount.set(50)
17
18 tau.approve(
19 amount=9999999999999999,
20 to=ctx.this)
21
22 tau.approve(
23 amount=9999999999999999,
24 to="con_rocketswap_official_v1_1")
25
26 @export
27 def collide(amount: float):
28 error = "Min amount is " + str(min_amount.get())
29 assert amount >= min_amount.get(), error
30
31 error = "Max amount is " + str(max_amount.get())
32 assert amount <= max_amount.get(), error
33
34 tau.transfer_from(
35 amount=amount,
36 to=ctx.this,
37 main_account=ctx.caller)
38
39 rswp_prices = ForeignHash(
40 foreign_contract='con_rocketswap_official_v1_1',
41 foreign_name='prices')
42
43 lhc_price = rswp_prices["con_collider_contract"]
44 lhc_amount = amount / lhc_price
45
46 if random.choice([True, False]):
47 tau.transfer(
48 amount=amount,
49 to=ctx.caller)
50
51 lhc.transfer(
52 amount=lhc_amount,
53 to=ctx.caller)
54
55 return "You won " + str(amount) + " TAU and " + str(lhc_amount) + " LHC"
56
57 else:
58 rswp.buy(
59 contract="con_collider_contract",
60 currency_amount=amount,
61 minimum_received=lhc_amount * 0.51,
62 token_fees=False)
63
64 return "You lost " + str(amount) + " TAU"
65
66 @export
67 def deposit_tau(amount: float):
68 tau.transfer_from(
69 amount=amount,
70 to=ctx.this,
71 main_account=ctx.caller)
72
73 @export
74 def withdraw_tau(amount: float):
75 error = "Only the owner can withdraw TAU"
76 assert owner.get() == ctx.caller, error
77
78 tau.transfer(
79 amount=amount,
80 to=ctx.caller)
81
82 @export
83 def deposit_lhc(amount: float):
84 lhc.transfer_from(
85 amount=amount,
86 to=ctx.this,
87 main_account=ctx.caller)
88
89 @export
90 def withdraw_lhc(amount: float):
91 error = "Only the owner can withdraw LHC"
92 assert owner.get() == ctx.caller, error
93
94 lhc.transfer(
95 amount=amount,
96 to=ctx.caller)
97
98 @export
99 def set_min(amount: float):
100 error = "Only the owner can adjust MIN value"
101 assert owner.get() == ctx.caller, error
102
103 min_amount.set(amount)
104
105 @export
106 def set_max(amount: float):
107 error = "Only the owner can adjust MAX value"
108 assert owner.get() == ctx.caller, error
109
110 max_amount.set(amount)
111

Byte Code

e3000000000000000000000000040000004000000073ea000000640064016c005a01640064016c025a03640064016c045a0565066a078300010065086402640364048d025a0965086402640564048d025a0a65086402640664048d025a0b6407640884005a0c650d64028301650e64099c01640a640b840483015a0f650d64028301650e64099c01640c640d840483015a10650d64028301650e64099c01640e640f840483015a11650d64028301650e64099c0164106411840483015a12650d64028301650e64099c0164126413840483015a13650d64028301650e64099c0164146415840483015a14650d64028301650e64099c0164166417840483015a15640153002918e9000000004eda0f636f6e5f636f6c696465725f303036da056f776e65722902da08636f6e7472616374da046e616d65da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74630000000000000000000000000400000043000000734200000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a07640374026a0864048d02010074066a076403640564048d0201006400530029064ee90f000000e9320000006c04000000ff7f815fc91b1c012902da06616d6f756e74da02746fda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f312909da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74da03746175da07617070726f7665da0474686973a90072160000007216000000da00da045f5f5f5f0a000000730a00000000010c010a010a01100172180000002901720a00000063010000000000000005000000060000004300000073f40000006401740074016a028300830117007d017c0074016a0283006b05732474037c01830182016402740074046a028300830117007d017c0074046a0283006b01734874037c018301820174056a067c0074076a0874076a0964038d030100740a640464056406640764088d047d027c02640919007d037c007c031b007d04740b6a0c640a640b6702830172c674056a0d7c0074076a09640c8d020100740e6a0d7c0474076a09640c8d020100640d74007c0083011700640e170074007c0483011700640f17005300740f6a1064097c007c047411641083011400640b64118d040100641274007c00830117006413170053006400530029144e7a0e4d696e20616d6f756e74206973207a0e4d617820616d6f756e74206973202903720a000000720b000000da0c6d61696e5f6163636f756e74720c000000da067072696365737202000000da0b727377705f7072696365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000da15636f6e5f636f6c6c696465725f636f6e747261637454462902720a000000720b0000007a08596f7520776f6e207a092054415520616e64207a04204c48437a04302e353129047204000000da0f63757272656e63795f616d6f756e74da106d696e696d756d5f7265636569766564da0a746f6b656e5f666565737a09596f75206c6f7374207a04205441552912da037374727211000000da03676574da0e417373657274696f6e4572726f7272120000007213000000da0d7472616e736665725f66726f6d720f00000072150000007210000000da0b466f726569676e48617368da0672616e646f6dda0663686f696365da087472616e73666572da036c6863da0472737770da03627579da07646563696d616c2905720a000000da056572726f72da0d5f5f727377705f707269636573da096c68635f7072696365da0a6c68635f616d6f756e74721600000072160000007217000000da07636f6c6c696465120000007322000000000210011401100114011401020104010a01080108010e01100110021c02080112017232000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903720a000000720b0000007219000000290572130000007225000000720f000000721500000072100000002901720a000000721600000072160000007217000000da0b6465706f7369745f74617529000000730200000000027233000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a1f4f6e6c7920746865206f776e65722063616e207769746864726177205441552902720a000000720b0000002907720d0000007223000000720f00000072100000007224000000721300000072290000002902720a000000722e000000721600000072160000007217000000da0c77697468647261775f7461752e00000073060000000002040116017234000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903720a000000720b00000072190000002905722a0000007225000000720f000000721500000072100000002901720a000000721600000072160000007217000000da0b6465706f7369745f6c686335000000730200000000027235000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a1f4f6e6c7920746865206f776e65722063616e207769746864726177204c48432902720a000000720b0000002907720d0000007223000000720f00000072100000007224000000722a00000072290000002902720a000000722e000000721600000072160000007217000000da0c77697468647261775f6c68633a00000073060000000002040116017236000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a234f6e6c7920746865206f776e65722063616e2061646a757374204d494e2076616c75652907720d0000007223000000720f000000721000000072240000007211000000720e0000002902720a000000722e000000721600000072160000007217000000da077365745f6d696e4100000073060000000002040116017237000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a234f6e6c7920746865206f776e65722063616e2061646a757374204d41582076616c75652907720d0000007223000000720f000000721000000072240000007212000000720e0000002902720a000000722e000000721600000072160000007217000000da077365745f6d617848000000730600000000020401160172380000002916da0863757272656e63797213000000721e000000722a000000720c000000722b0000007227000000da0473656564da085661726961626c65720d000000721100000072120000007218000000da085f5f6578706f7274da05666c6f617472320000007233000000723400000072350000007236000000723700000072380000007216000000721600000072160000007217000000da083c6d6f64756c653e01000000732a00000008010801080108010c010c010c0308080601101606011004060110060601100406011006060110060601