Contract con_uber_lootbox


Contract Code


  
1 # 100% Fair Randomness
2 random.seed()
3
4 I = importlib
5 import currency
6
7
8 operator = Variable()
9 rocketswap_contract = Variable()
10 trt_contract = Variable()
11 box_contents = Variable()
12 price = Variable()
13
14
15 @construct
16 def seed():
17 operator.set(ctx.caller)
18 rocketswap_contract.set("con_rocketswap_official_v1_1")
19 trt_contract.set("con_trt")
20 box_contents.set([])
21 price.set(1000)
22
23 token = I.import_module("con_trt").approve(amount=99999999999999999, to="con_rocketswap_official_v1_1")
24
25
26 @export
27 def set_operator(new_op: str):
28 assert ctx.caller == operator.get(), "You are not the operator"
29 operator.set(new_op)
30
31
32 @export
33 def set_rocketswap_contract(contract: str):
34 assert ctx.caller == operator.get(), "You are not the operator"
35 rocketswap_contract.set(contract)
36 I.import_module(trt_contract.get()).approve(amount=99999999999999999, to=contract)
37
38
39 @export
40 def set_trt_contract(contract: str):
41 assert ctx.caller == operator.get(), "You are not the operator"
42 trt_contract.set(contract)
43 I.import_module(contract.get()).approve(amount=99999999999999999, to=rocketswap_contract.get())
44
45
46 @export
47 def set_price(new_price: float):
48 assert ctx.caller == operator.get(), "You are not the operator"
49 price.set(new_price)
50
51
52 @export
53 def deposit_nft(collection_contract: str, name: str):
54 assert ctx.caller == operator.get(), "You are not the operator"
55 collection = I.import_module(collection_contract)
56 collection.transfer_from(name=name, amount=1, to=ctx.this, main_account=ctx.caller)
57 nfts = box_contents.get()
58 nfts.append({"collection":collection_contract, "name":name})
59 box_contents.set(nfts)
60
61
62 @export
63 def emergency_withdraw_nft(collection_contract: str, name: str):
64 assert ctx.caller == operator.get(), "You are not the operator"
65 collection = I.import_module(collection_contract)
66 collection.transfer(name=name, amount=1, to=ctx.caller)
67 nfts = box_contents.get()
68 nfts.remove({"collection":collection_contract, "name":name})
69 box_contents.set(nfts)
70
71
72 @export
73 def play():
74 assert len(box_contents.get()) > 0, "There are no nfts available right now"
75
76 token = I.import_module(trt_contract.get())
77 token.transfer_from(amount=price.get(), to=ctx.this, main_account=ctx.caller)
78
79 rocketswap = I.import_module(rocketswap_contract.get())
80 tau = rocketswap.sell(contract=trt_contract.get(), token_amount=price.get())
81 currency.transfer(amount=tau, to=operator.get())
82
83 nfts = box_contents.get()
84 your_number = random.randint(0, len(nfts)-1)
85 your_winning = nfts[your_number]
86
87 collection = I.import_module(your_winning['collection'])
88 collection.transfer(name=your_winning['name'], amount=1, to=ctx.caller)
89
90 nfts.pop(your_number)
91 box_contents.set(nfts)
92
93 return f"You won {your_winning['name']} from collection {your_winning['collection']}"

Byte Code

e3000000000000000000000000040000004000000073f400000065006a018300010065025a03640064016c045a0465056402640364048d025a0665056402640564048d025a0765056402640664048d025a0865056402640764048d025a0965056402640864048d025a0a6409640a84005a0b650c64028301650d640b9c01640c640d840483015a0e650c64028301650d640e9c01640f6410840483015a0f650c64028301650d640e9c0164116412840483015a10650c64028301651164139c0164146415840483015a12650c64028301650d650d64169c0264176418840483015a13650c64028301650d650d64169c026419641a840483015a14650c64028301641b641c840083015a1564015300291de9000000004eda10636f6e5f756265725f6c6f6f74626f78da086f70657261746f722902da08636f6e7472616374da046e616d65da13726f636b6574737761705f636f6e7472616374da0c7472745f636f6e7472616374da0c626f785f636f6e74656e7473da057072696365630000000000000000010000000400000043000000734c00000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0167008301010074076a0164038301010074086a09640283016a0a6404640164058d027d006400530029064eda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da07636f6e5f74727469e80300006c04000000ff7f133be1151a0b2902da06616d6f756e74da02746f290bda0a5f5f6f70657261746f72da03736574da03637478da0663616c6c6572da155f5f726f636b6574737761705f636f6e7472616374da0e5f5f7472745f636f6e7472616374da0e5f5f626f785f636f6e74656e7473da075f5f7072696365da0149da0d696d706f72745f6d6f64756c65da07617070726f76652901da05746f6b656ea900721a000000da00da045f5f5f5f0c000000730e00000000010c010a010a010a010a010c01721c0000002901da066e65775f6f70630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a18596f7520617265206e6f7420746865206f70657261746f72290672100000007211000000720e000000da03676574da0e417373657274696f6e4572726f72720f0000002901721d000000721a000000721a000000721b000000da0c7365745f6f70657261746f7216000000730400000000021601722000000029017204000000630100000000000000010000000400000043000000733c00000074006a0174026a0383006b027316740464018301820174056a067c008301010074076a0874096a03830083016a0a64027c0064038d0201006400530029044e7a18596f7520617265206e6f7420746865206f70657261746f726c04000000ff7f133be1151a0b2902720c000000720d000000290b72100000007211000000720e000000721e000000721f0000007212000000720f000000721600000072170000007213000000721800000029017204000000721a000000721a000000721b000000da177365745f726f636b6574737761705f636f6e74726163741c0000007308000000000216010a0110017221000000630100000000000000010000000400000043000000734000000074006a0174026a0383006b027316740464018301820174056a067c008301010074076a087c006a03830083016a096402740a6a03830064038d0201006400530029044e7a18596f7520617265206e6f7420746865206f70657261746f726c04000000ff7f133be1151a0b2902720c000000720d000000290b72100000007211000000720e000000721e000000721f0000007213000000720f000000721600000072170000007218000000721200000029017204000000721a000000721a000000721b000000da107365745f7472745f636f6e7472616374240000007308000000000216010a01100172220000002901da096e65775f7072696365630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a18596f7520617265206e6f7420746865206f70657261746f72290772100000007211000000720e000000721e000000721f0000007215000000720f00000029017223000000721a000000721a000000721b000000da097365745f70726963652c00000073040000000002160172240000002902da13636f6c6c656374696f6e5f636f6e74726163747205000000630200000000000000040000000600000043000000735c00000074006a0174026a0383006b027316740464018301820174056a067c0083017d027c026a077c01640274006a0874006a0164038d04010074096a0383007d037c036a0a7c007c0164049c028301010074096a0b7c03830101006400530029054e7a18596f7520617265206e6f7420746865206f70657261746f72e90100000029047205000000720c000000720d000000da0c6d61696e5f6163636f756e742902da0a636f6c6c656374696f6e7205000000290c72100000007211000000720e000000721e000000721f00000072160000007217000000da0d7472616e736665725f66726f6dda04746869737214000000da06617070656e64720f0000002904722500000072050000007228000000da046e667473721a000000721a000000721b000000da0b6465706f7369745f6e667432000000730e000000000216010a010c010a0108011001722d000000630200000000000000040000000500000043000000735800000074006a0174026a0383006b027316740464018301820174056a067c0083017d027c026a077c01640274006a0164038d03010074086a0383007d037c036a097c007c0164049c028301010074086a0a7c03830101006400530029054e7a18596f7520617265206e6f7420746865206f70657261746f72722600000029037205000000720c000000720d000000290272280000007205000000290b72100000007211000000720e000000721e000000721f00000072160000007217000000da087472616e736665727214000000da0672656d6f7665720f0000002904722500000072050000007228000000722c000000721a000000721a000000721b000000da16656d657267656e63795f77697468647261775f6e66743d000000730c000000000216010a01120108011001723000000063000000000000000007000000050000004300000073e8000000740074016a028300830164016b047318740364028301820174046a0574066a02830083017d007c006a0774086a02830074096a0a74096a0b64038d03010074046a05740c6a02830083017d017c016a0d74066a02830074086a02830064048d027d02740e6a0f7c0274106a02830064058d02010074016a0283007d0374116a12640174007c0383016406180083027d047c037c0419007d0574046a057c056407190083017d067c066a0f7c0564081900640674096a0b64098d0301007c036a137c048301010074016a147c0383010100640a7c05640819009b00640b7c05640719009b009d045300290c4e72010000007a25546865726520617265206e6f206e66747320617661696c61626c65207269676874206e6f772903720c000000720d000000722700000029027204000000da0c746f6b656e5f616d6f756e742902720c000000720d00000072260000007228000000720500000029037205000000720c000000720d0000007a08596f7520776f6e207a112066726f6d20636f6c6c656374696f6e202915da036c656e7214000000721e000000721f000000721600000072170000007213000000722900000072150000007210000000722a00000072110000007212000000da0473656c6cda0863757272656e6379722e000000720e000000da0672616e646f6dda0772616e64696e74da03706f70720f00000029077219000000da0a726f636b657473776170da03746175722c000000da0b796f75725f6e756d626572da0c796f75725f77696e6e696e677228000000721a000000721a000000721b000000da04706c617947000000732000000000020a010e010e0118020e010a010c0112010801140108010e0116010a010a02723c00000029167235000000da0473656564da09696d706f72746c696272160000007234000000da085661726961626c65720e0000007212000000721300000072140000007215000000721c000000da085f5f6578706f7274da03737472722000000072210000007222000000da05666c6f61747224000000722d0000007230000000723c000000721a000000721a000000721a000000721b000000da083c6d6f64756c653e01000000732c0000000801040108010c01040108010c010c010c03080a060110050601100706011007060110050601120a06011209