Contract con_collider_001


Contract Code


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

Byte Code

e3000000000000000000000000040000004000000073e2000000640064016c005a01640064016c025a0365046a058300010065066402640364048d025a0765066402640564048d025a0865066402640664048d025a096407640884005a0a650b64028301650c64099c01640a640b840483015a0d650b64028301650c64099c01640c640d840483015a0e650b64028301650c64099c01640e640f840483015a0f650b64028301650c64099c0164106411840483015a10650b64028301650c64099c0164126413840483015a11650b64028301650c64099c0164146415840483015a12650b64028301650c64099c0164166417840483015a13640153002918e9000000004eda10636f6e5f636f6c6c696465725f303031da056f776e65722902da08636f6e7472616374da046e616d65da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74630000000000000000000000000200000043000000732400000074006a0174026a038301010074046a0164018301010074056a016402830101006400530029034ee90f000000e9320000002906da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74a90072100000007210000000da00da045f5f5f5f09000000730600000000010c010a0172120000002901da06616d6f756e7463010000000000000006000000060000004300000073dc0000006401740074016a028300830117007d017c0074016a0283006b05732474037c01830182016402740074046a028300830117007d017c0074046a0283006b01734874037c018301820174056a067c0074076a0874076a0964038d030100740a640464056406640764088d047d027c02640919007d037c007c031b007d04740b6a0c74076a08640a8d017d05640b7d017c057c046b05739e74037c0183018201740d6a0e640c640d6702830172cc740b6a0f7c0474076a09640e8d020100640f74007c0483011700641017005300641174007c008301170064121700530029134e7a0e4d696e20616d6f756e74206973207a0e4d617820616d6f756e742069732029037213000000da02746fda0c6d61696e5f6163636f756e74da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da067072696365737202000000da0b727377705f7072696365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000da15636f6e5f636f6c6c696465725f636f6e74726163742901da076163636f756e747a2b4c48432062616c616e636520746f6f206c6f7720746f2070617920666f7220706f737369626c652077696e54462902721300000072140000007a08596f7520776f6e207a04204c48437a09596f75206c6f7374207a04205441552910da03737472720e000000da03676574da0e417373657274696f6e4572726f72720f000000da03746175da0d7472616e736665725f66726f6d720c000000da0474686973720d000000da0b466f726569676e48617368da036c6863da0a62616c616e63655f6f66da0672616e646f6dda0663686f696365da087472616e7366657229067213000000da056572726f72da0d5f5f727377705f707269636573da096c68635f7072696365da0a6c68635f616d6f756e74da0b6c68635f62616c616e6365721000000072100000007211000000da07636f6c6c6964650f0000007322000000000210011401100114011401020104010a01080108010e01040110010e0110011001722e000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903721300000072140000007215000000290572200000007221000000720c0000007222000000720d00000029017213000000721000000072100000007211000000da0b6465706f7369745f7461752400000073020000000002722f000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a1f4f6e6c7920746865206f776e65722063616e207769746864726177205441552902721300000072140000002907720a000000721e000000720c000000720d000000721f00000072200000007228000000290272130000007229000000721000000072100000007211000000da0c77697468647261775f7461752900000073060000000002040116017230000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903721300000072140000007215000000290572240000007221000000720c0000007222000000720d00000029017213000000721000000072100000007211000000da0b6465706f7369745f6c686330000000730200000000027231000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a1f4f6e6c7920746865206f776e65722063616e207769746864726177204c48432902721300000072140000002907720a000000721e000000720c000000720d000000721f00000072240000007228000000290272130000007229000000721000000072100000007211000000da0c77697468647261775f6c68633500000073060000000002040116017232000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a234f6e6c7920746865206f776e65722063616e2061646a757374204d494e2076616c75652907720a000000721e000000720c000000720d000000721f000000720e000000720b000000290272130000007229000000721000000072100000007211000000da077365745f6d696e3c00000073060000000002040116017233000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a234f6e6c7920746865206f776e65722063616e2061646a757374204d41582076616c75652907720a000000721e000000720c000000720d000000721f000000720f000000720b000000290272130000007229000000721000000072100000007211000000da077365745f6d617843000000730600000000020401160172340000002914da0863757272656e63797220000000721b00000072240000007226000000da0473656564da085661726961626c65720a000000720e000000720f0000007212000000da085f5f6578706f7274da05666c6f6174722e000000722f000000723000000072310000007232000000723300000072340000007210000000721000000072100000007211000000da083c6d6f64756c653e0100000073280000000801080108010c010c010c0308060601101406011004060110060601100406011006060110060601