Contract con_launchpad_5


Contract Code


  
1 # Launchpad v0.5 with MOBGOV features but without MOB features
2 # Token Creator creates a token and puts amount of token up for sale.
3 # He will need to set a token contract, start, end time, hardcap, tokens for sale and maximum buy.
4 # People can invest TAU
5 # If end time reached and softcap reached - Make tokens available to claim
6 # If hardcap reached - Make tokens available to claim
7 # If endtime reached and softcap not reached - Refund TAU, Refund Tokens to Creator
8 #
9 #
10
11 I = importlib
12 random.seed() # To generate somewhat unique token sale id
13
14 token_sales = Hash(default_value=0)
15 investments = Hash(default_value=0)
16
17 sales = Variable() # IDs of all sales for listing on website
18
19 end_fee = Variable() # Only if sale is successful then fee of raised money
20 operator = Variable() # I can help when the sale is over but is not getting finalized
21 dev_fees = Variable()
22 mobgov_contract = Variable()
23
24 @construct
25 def seed():
26 end_fee.set(5)
27 operator.set(
28 "ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89")
29 sales.set("None")
30 mobgov_contract.set("con_mintorburn_gov")
31
32 @export
33 def create_sale(start_date_day: int, start_date_month: int, start_date_year: int, start_date_hour: int, start_date_minute: int, softcap: float, hardcap: float, max_buy: float, tokens_for_sale: float, token_contract: str, end_date_day: int, end_date_month: int, end_date_year: int, end_date_hour: int, end_date_minute: int):
34 token_sale_id = str(random.randint(0, 100000000))
35 assert token_sale_id not in sales.get().split(','), "Try again"
36 assert tokens_for_sale > 0, "The token amount needs to be over 0"
37 assert datetime.datetime(start_date_year, start_date_month, start_date_day, start_date_hour, start_date_minute) > now, "The start needs to be in the future"
38 assert datetime.datetime(end_date_year, end_date_month, end_date_day, end_date_hour, end_date_minute) > now, "The end needs to be in the future"
39 assert datetime.datetime(end_date_year, end_date_month, end_date_day, end_date_hour, end_date_minute) > datetime.datetime(start_date_year, start_date_month, start_date_day, start_date_hour, start_date_minute), "The end cannot be before the start"
40 I.import_module(token_contract).transfer_from(
41 main_account=ctx.caller,
42 amount=tokens_for_sale,
43 to=ctx.this)
44 token_sales[token_sale_id] = {"start_date": datetime.datetime(start_date_year, start_date_month, start_date_day, start_date_hour, start_date_minute), "end_date": datetime.datetime(
45 end_date_year, end_date_month, end_date_day, end_date_hour, end_date_minute), "softcap": softcap, "hardcap": hardcap, "max_buy": max_buy, "raised": decimal('0'), "tokens_for_sale": tokens_for_sale, "token_contract": token_contract, "seller": ctx.caller, "finalized": False, "success": False}
46 sales.set(sales.get() + "," + token_sale_id)
47
48 @export
49 def finalize(token_sale_id: str):
50 token_sale = token_sales[token_sale_id]
51 assert token_sale["finalized"] == False, "This sale is already finalized"
52 assert token_sale["end_date"] <= now, "The sale can only be finalized when the end date is reached"
53 assert token_sale["seller"] == ctx.caller or ctx.caller == operator.get(), "The sale can only be finalized by the seller"
54 if(token_sale["raised"] >= token_sale["softcap"]):
55 token_sale["success"] = True
56 I.import_module("currency").transfer(
57 amount=token_sale["raised"] - (token_sale["raised"] / 100 * end_fee.get()),
58 to=ctx.caller)
59 dev_fees.set(dev_fees.get() + (token_sale["raised"] / 100 * end_fee.get()))
60 if(token_sale["raised"] < token_sale["hardcap"]): # Refund the leftover tokens
61 I.import_module(token_sale["token_contract"]).transfer(
62 amount= (token_sale["hardcap"] / token_sale["tokens_for_sale"]) * (token_sale["hardcap"] - token_sale["raised"]),
63 to=ctx.caller)
64 else:
65 token_sale["success"] = False
66 I.import_module(token_sale["token_contract"]).transfer(
67 amount=token_sale["tokens_for_sale"],
68 to=ctx.caller)
69 token_sale["finalized"] = True
70 token_sales[token_sale_id] = token_sale
71
72 @export
73 def buy(token_sale_id: str, amount_to_invest: float):
74 mobgov_holders = ForeignHash(foreign_contract=mobgov_contract.get(), foreign_name='balances')
75 mobgov_advantage = 1
76 mobgov_early = False
77 if(mobgov_holders[ctx.caller] >= 100):
78 mobgov_advantage = 1.2
79 elif(mobgov_holders[ctx.caller] >= 1000):
80 mobgov_advantage = 1.5
81 mobgov_early = True
82 elif(mobgov_holders[ctx.caller] >= 5000):
83 mobgov_advantage = 2
84 mobgov_early = True
85 token_sale = token_sales[token_sale_id]
86 assert token_sale["finalized"] == False, "This sale is already finalized"
87 assert token_sale["end_date"] > now, "The end date is already reached"
88 assert token_sale["raised"] + amount_to_invest <= token_sale["hardcap"], "This buy would exceed the sale hardcap"
89 assert investments[token_sale_id, ctx.caller] + amount_to_invest <= token_sale["max_buy"] * mobgov_advantage, "You are not allowed to buy that much"
90 assert amount_to_invest > 0, "The buy amount needs to be over 0"
91 assert token_sale["start_date"] < now or mobgov_early == True and token_sale["start_date"] < (now - datetime.datetime(hour=1)), "The sale didnt start yet"
92
93 I.import_module("currency").transfer_from(
94 main_account=ctx.caller,
95 amount=amount_to_invest,
96 to=ctx.this)
97 token_sale["raised"] += amount_to_invest
98 investments[token_sale_id, ctx.caller] += amount_to_invest
99 token_sales[token_sale_id] = token_sale
100
101 @export
102 def claim(token_sale_id: str):
103 token_sale = token_sales[token_sale_id]
104 assert token_sale["finalized"] == True, "This sale needs to be finalized first"
105 if(token_sale["success"] == True):
106 I.import_module(token_sale["token_contract"]).transfer(
107 amount=token_sale["hardcap"] / token_sale["tokens_for_sale"] * investments[token_sale_id, ctx.caller],
108 to=ctx.caller)
109 investments[token_sale_id, ctx.caller] = 0
110 elif(token_sale["success"] == False):
111 I.import_module("currency").transfer(
112 amount=investments[token_sale_id, ctx.caller],
113 to=ctx.caller)
114 investments[token_sale_id, ctx.caller] = 0
115
116
117 @export
118 def admin_fee_claim(amount: float):
119 assert ctx.caller == operator.get(), "You are not the operator"
120 I.import_module("currency").transfer(
121 amount=amount,
122 to=ctx.caller)
123 dev_fees.set(dev_fees.get() - amount)
124
125 @export
126 def admin_set_mobgov_contract(contract: str):
127 assert ctx.caller == operator.get(), "You are not the operator"
128 mobgov_contract.set(contract)
129
130 @export
131 def admin_set_end_fee(fee: float):
132 assert ctx.caller == operator.get(), "You are not the operator"
133 end_fee.set(fee)
134

Byte Code

e30000000000000000000000001100000040000000732801000065005a0165026a0383000100650464006401640264038d035a05650464006401640464038d035a0665076401640564068d025a0865076401640764068d025a0965076401640864068d025a0a65076401640964068d025a0b65076401640a64068d025a0c640b640c84005a0d650e64018301650f650f650f650f650f65106510651065106511650f650f650f650f650f640d9c0f640e640f840483015a12650e64018301651164109c0164116412840483015a13650e640183016511651064139c0264146415840483015a14650e64018301651164109c0164166417840483015a15650e64018301651064189c016419641a840483015a16650e640183016511641b9c01641c641d840483015a17650e640183016510641e9c01641f6420840483015a18642153002922e900000000da0f636f6e5f6c61756e63687061645f35da0b746f6b656e5f73616c65732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0b696e766573746d656e7473da0573616c6573290272050000007206000000da07656e645f666565da086f70657261746f72da086465765f66656573da0f6d6f62676f765f636f6e7472616374630000000000000000000000000200000043000000732c00000074006a0164018301010074026a0164028301010074036a0164038301010074046a016404830101006400530029054ee905000000da4066663631353434656139346561616562356466303865643836336334613933386539313239616261366365656535663331623636383162646564653131623839da044e6f6e65da12636f6e5f6d696e746f726275726e5f676f762905da095f5f656e645f666565da03736574da0a5f5f6f70657261746f72da075f5f73616c6573da115f5f6d6f62676f765f636f6e7472616374a90072160000007216000000da00da045f5f5f5f0f000000730a00000000010a01040106010a017218000000290fda0e73746172745f646174655f646179da1073746172745f646174655f6d6f6e7468da0f73746172745f646174655f79656172da0f73746172745f646174655f686f7572da1173746172745f646174655f6d696e757465da07736f6674636170da0768617264636170da076d61785f627579da0f746f6b656e735f666f725f73616c65da0e746f6b656e5f636f6e7472616374da0c656e645f646174655f646179da0e656e645f646174655f6d6f6e7468da0d656e645f646174655f79656172da0d656e645f646174655f686f7572da0f656e645f646174655f6d696e757465630f00000000000000100000000c000000430000007318010000740074016a0264016402830283017d0f7c0f74036a0483006a05640383016b07732a74066404830182017c0864016b04733a740664058301820174076a077c027c017c007c037c04830574086b047358740664068301820174076a077c0c7c0b7c0a7c0d7c0e830574086b047376740664078301820174076a077c0c7c0b7c0a7c0d7c0e830574076a077c027c017c007c037c0483056b0473a2740664088301820174096a0a7c0983016a0b740c6a0d7c08740c6a0e64098d03010074076a077c027c017c007c037c04830574076a077c0c7c0b7c0a7c0d7c0e83057c057c067c07740f640a83017c087c09740c6a0d640b640b640c9c0b74107c0f3c0074036a1174036a048300640317007c0f17008301010064005300290d4e72010000006900e1f505fa012c7a0954727920616761696e7a2354686520746f6b656e20616d6f756e74206e6565647320746f206265206f76657220307a23546865207374617274206e6565647320746f20626520696e20746865206675747572657a2154686520656e64206e6565647320746f20626520696e20746865206675747572657a2254686520656e642063616e6e6f74206265206265666f7265207468652073746172742903da0c6d61696e5f6163636f756e74da06616d6f756e74da02746fda013046290bda0a73746172745f64617465da08656e645f64617465721e000000721f0000007220000000da0672616973656472210000007222000000da0673656c6c6572da0966696e616c697a6564da07737563636573732912da03737472da0672616e646f6dda0772616e64696e747214000000da03676574da0573706c6974da0e417373657274696f6e4572726f72da086461746574696d65da036e6f77da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda03637478da0663616c6c6572da0474686973da07646563696d616cda0d5f5f746f6b656e5f73616c6573721200000029107219000000721a000000721b000000721c000000721d000000721e000000721f00000072200000007221000000722200000072230000007224000000722500000072260000007227000000da0d746f6b656e5f73616c655f6964721600000072160000007217000000da0b6372656174655f73616c65170000007330000000000610011a011001080108010e010a0106010e010a010c01100106010e010c01040108010a010a010601080106010e01724400000029017243000000630100000000000000020000000500000043000000734201000074007c0019007d017c016401190064026b02731c74016403830182017c016404190074026b01733074016405830182017c016406190074036a046b02735474036a0474056a0683006b02735474016407830182017c01640819007c01640919006b0590017208640a7c01640b3c0074076a08640c83016a097c01640819007c0164081900640d1b00740a6a0683001400180074036a04640e8d020100740b6a0c740b6a0683007c0164081900640d1b00740a6a06830014001700830101007c01640819007c01640f19006b009001722e74076a087c016410190083016a097c01640f19007c01641119001b007c01640f19007c01640819001800140074036a04640e8d0201006e2664027c01640b3c0074076a087c016410190083016a097c016411190074036a04640e8d020100640a7c0164013c007c0174007c003c006400530029124e7231000000467a1e546869732073616c6520697320616c72656164792066696e616c697a6564722e0000007a3b5468652073616c652063616e206f6e6c792062652066696e616c697a6564207768656e2074686520656e642064617465206973207265616368656472300000007a2c5468652073616c652063616e206f6e6c792062652066696e616c697a6564206279207468652073656c6c6572722f000000721e000000547232000000da0863757272656e6379e9640000002902722a000000722b000000721f00000072220000007221000000290d72420000007238000000723a000000723e000000723f00000072130000007236000000723b000000723c000000da087472616e736665727211000000da0a5f5f6465765f66656573721200000029027243000000da0a746f6b656e5f73616c65721600000072160000007217000000da0866696e616c697a6537000000732a00000000020801140106010e011e0106011201080110011e0114010e0112010e010e011c0208010e0110010801724a00000029027243000000da10616d6f756e745f746f5f696e76657374630200000000000000060000000600000043000000736e010000740074016a02830064016402640364048d047d0264057d0364067d047c0274036a04190064076b0572347405640883017d036e327c0274036a04190064096b0572507405640a83017d03640b7d046e167c0274036a041900640c6b057266640d7d03640b7d0474067c0019007d057c05640e190064066b0273827407640f830182017c056410190074086b04739674076411830182017c05641219007c0117007c05641319006b0173b2740764148301820174097c0074036a04660219007c0117007c05641519007c0314006b0173d874076416830182017c0164176b0473e874076418830182017c056419190074086b00900173227c04640b6b029001721a7c05641919007408740a6a0a6405641a8d0118006b00900173227407641b83018201740b6a0c641c83016a0d74036a047c0174036a0e641d8d0301007c056412050019007c01370003003c0074097c0074036a046602050019007c01370003003c007c0574067c003c0064005300291e4eda0862616c616e6365737202000000da0e6d6f62676f765f686f6c646572732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572050000007206000000e9010000004672460000007a03312e3269e80300007a03312e35546988130000e90200000072310000007a1e546869732073616c6520697320616c72656164792066696e616c697a6564722e0000007a1f54686520656e64206461746520697320616c72656164792072656163686564722f000000721f0000007a26546869732062757920776f756c6420657863656564207468652073616c65206861726463617072200000007a24596f7520617265206e6f7420616c6c6f77656420746f206275792074686174206d75636872010000007a215468652062757920616d6f756e74206e6565647320746f206265206f7665722030722d0000002901da04686f75727a185468652073616c65206469646e7420737461727420796574724500000029037229000000722a000000722b000000290fda0b466f726569676e4861736872150000007236000000723e000000723f000000724100000072420000007238000000723a000000da0d5f5f696e766573746d656e74737239000000723b000000723c000000723d000000724000000029067243000000724b000000da105f5f6d6f62676f765f686f6c64657273da106d6f62676f765f616476616e74616765da0c6d6f62676f765f6561726c797249000000721600000072160000007217000000da0362757951000000733c0000000002080104010801040104010e010a010e01080106010e0104010401080114011401160106010c010a0110011001060118011c010e010c0110011601725800000063010000000000000002000000050000004300000073aa00000074007c0019007d017c016401190064026b02731c74016403830182017c016404190064026b02726c74026a037c016405190083016a047c01640619007c01640719001b0074057c0074066a0766021900140074066a0764088d020100640974057c0074066a0766023c006e3a7c0164041900640a6b0272a674026a03640b83016a0474057c0074066a076602190074066a0764088d020100640974057c0074066a0766023c0064005300290c4e7231000000547a25546869732073616c65206e6565647320746f2062652066696e616c697a656420666972737472320000007222000000721f00000072210000002902722a000000722b0000007201000000467245000000290872420000007238000000723b000000723c00000072470000007254000000723e000000723f000000290272430000007249000000721600000072160000007217000000da05636c61696d7300000073180000000002080106010e010c010e010e01180110010c010c01140172590000002901722a000000630100000000000000010000000400000043000000734200000074006a0174026a0383006b027316740464018301820174056a06640283016a077c0074006a0164038d02010074086a0974086a0383007c001800830101006400530029044e7a18596f7520617265206e6f7420746865206f70657261746f7272450000002902722a000000722b000000290a723e000000723f000000721300000072360000007238000000723b000000723c0000007247000000724800000072120000002901722a000000721600000072160000007217000000da0f61646d696e5f6665655f636c61696d830000007306000000000216011601725a00000029017205000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a18596f7520617265206e6f7420746865206f70657261746f722907723e000000723f0000007213000000723600000072380000007215000000721200000029017205000000721600000072160000007217000000da1961646d696e5f7365745f6d6f62676f765f636f6e74726163748a000000730400000000021601725b0000002901da03666565630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a18596f7520617265206e6f7420746865206f70657261746f722907723e000000723f000000721300000072360000007238000000721100000072120000002901725c000000721600000072160000007217000000da1161646d696e5f7365745f656e645f66656590000000730400000000021601725d0000004e2919da09696d706f72746c6962723b0000007234000000da0473656564da044861736872420000007254000000da085661726961626c65721400000072110000007213000000724800000072150000007218000000da085f5f6578706f7274da03696e74da05666c6f617472330000007244000000724a00000072580000007259000000725a000000725b000000725d0000007216000000721600000072160000007217000000da083c6d6f64756c653e01000000733a0000000401080106010801060108010c010c010c010c010c04080806010401080106010801121b06011019060112210601100f06011006060110050601