Contract con_gamma_phi_sales_v3


Contract Code


  
1 import currency as tau
2 import con_phi as phi
3
4 tau_balances = ForeignHash(foreign_contract='currency', foreign_name='balances')
5
6 owner = Variable()
7
8 round_1_price = Variable()
9 round_1_quantity = Variable()
10
11 round_2_price = Variable()
12 round_2_quantity = Variable()
13
14
15 @construct
16 def seed():
17 round_1_price.set(0.002)
18 round_1_quantity.set(100_000_000)
19 round_2_price.set(0.004)
20 round_2_quantity.set(100_000_000)
21 owner.set(ctx.caller)
22
23
24 @export
25 def set_round_1_price(price: float):
26 error = "Only owner can update this"
27 assert ctx.caller == owner.get(), error
28
29 round_1_price.set(price)
30
31
32 @export
33 def set_round_2_price(price: float):
34 error = "Only owner can update this"
35 assert ctx.caller == owner.get(), error
36
37 round_2_price.set(price)
38
39
40 @export
41 def set_round_1_quantity(quantity: int):
42 error = "Only owner can update this"
43 assert ctx.caller == owner.get(), error
44
45 round_1_quantity.set(quantity)
46
47
48 @export
49 def set_round_2_quantity(quantity: int):
50 error = "Only owner can update this"
51 assert ctx.caller == owner.get(), error
52
53 round_2_quantity.set(quantity)
54
55
56 @export
57 def purchase_round_1(amount_tau: float):
58 assert amount_tau > 0, 'Cannot purchase negative amounts!'
59 purchaser = ctx.caller
60
61 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
62
63 amount = amount_tau / round_1_price.get()
64
65 assert round_1_quantity.get() > amount, 'Not enough remaining in round 1'
66
67 round_1_quantity.set(round_1_quantity.get() - amount)
68
69 tau.transfer_from(amount_tau, ctx.this, purchaser)
70 phi.transfer(amount, purchaser)
71
72
73 @export
74 def purchase_round_2(amount_tau: float):
75 assert amount_tau > 0, 'Cannot purchase negative amounts!'
76 purchaser = ctx.caller
77
78 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
79
80 amount = amount_tau / round_2_price.get()
81
82 assert round_2_quantity.get() > amount, 'Not enough remaining in round 1'
83
84 round_2_quantity.set(round_2_quantity.get() - amount)
85
86 tau.transfer_from(amount_tau, ctx.this, purchaser)
87 phi.transfer(amount, purchaser)
88
89 @export
90 def pay_out_phi(amount: float):
91 error = "Negative amount is not allowed"
92 assert amount > 0, error
93
94 error = "Only owner can payout tokens"
95 assert ctx.caller == owner.get(), error
96
97 # Transfer tokens from contract to owner
98 phi.transfer(
99 amount=amount,
100 to=ctx.caller)
101
102 @export
103 def pay_out_tau(amount: float):
104 error = "Negative amount is not allowed"
105 assert amount > 0, error
106
107 error = "Only owner can payout tokens"
108 assert ctx.caller == owner.get(), error
109
110 # Transfer tokens from contract to owner
111 tau.transfer(
112 amount=amount,
113 to=ctx.caller)

Byte Code

e300000000000000000000000006000000400000007318010000640064016c005a01640064016c025a036504640264036404640564068d045a0565066404640764088d025a0765066404640964088d025a0865066404640a64088d025a0965066404640b64088d025a0a65066404640c64088d025a0b640d640e84005a0c650d64048301650e640f9c0164106411840483015a0f650d64048301650e640f9c0164126413840483015a10650d64048301651164149c0164156416840483015a12650d64048301651164149c0164176418840483015a13650d64048301650e64199c01641a641b840483015a14650d64048301650e64199c01641c641d840483015a15650d64048301650e641e9c01641f6420840483015a16650d64048301650e641e9c0164216422840483015a17640153002923e9000000004eda0863757272656e6379da0862616c616e636573da16636f6e5f67616d6d615f7068695f73616c65735f7633da0c7461755f62616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da056f776e6572290272080000007209000000da0d726f756e645f315f7072696365da10726f756e645f315f7175616e74697479da0d726f756e645f325f7072696365da10726f756e645f325f7175616e74697479630000000000000000000000000300000043000000734000000074006a017402640183018301010074036a0164028301010074046a017402640383018301010074056a0164028301010074066a0174076a08830101006400530029044e7a05302e3030326900e1f5057a05302e3030342909da0f5f5f726f756e645f315f7072696365da03736574da07646563696d616cda125f5f726f756e645f315f7175616e74697479da0f5f5f726f756e645f325f7072696365da125f5f726f756e645f325f7175616e74697479da075f5f6f776e6572da03637478da0663616c6c6572a90072180000007218000000da00da045f5f5f5f10000000730a00000000010e010a010e010a01721a0000002901da057072696365630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a1a4f6e6c79206f776e65722063616e2075706461746520746869732907721600000072170000007215000000da03676574da0e417373657274696f6e4572726f72720f00000072100000002902721b000000da056572726f72721800000072180000007219000000da117365745f726f756e645f315f7072696365180000007306000000000204011601721f000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a1a4f6e6c79206f776e65722063616e2075706461746520746869732907721600000072170000007215000000721c000000721d000000721300000072100000002902721b000000721e000000721800000072180000007219000000da117365745f726f756e645f325f70726963651f000000730600000000020401160172200000002901da087175616e74697479630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a1a4f6e6c79206f776e65722063616e2075706461746520746869732907721600000072170000007215000000721c000000721d0000007212000000721000000029027221000000721e000000721800000072180000007219000000da147365745f726f756e645f315f7175616e746974792600000073060000000002040116017222000000630100000000000000020000000200000043000000732800000064017d0174006a0174026a0383006b02731a74047c018301820174056a067c00830101006400530029024e7a1a4f6e6c79206f776e65722063616e2075706461746520746869732907721600000072170000007215000000721c000000721d0000007214000000721000000029027221000000721e000000721800000072180000007219000000da147365745f726f756e645f325f7175616e746974792d000000730600000000020401160172230000002901da0a616d6f756e745f746175630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290d721d00000072160000007217000000da0e5f5f7461755f62616c616e636573720f000000721c00000072120000007210000000da03746175da0d7472616e736665725f66726f6dda0474686973da03706869da087472616e7366657229037224000000da09707572636861736572da06616d6f756e74721800000072180000007219000000da1070757263686173655f726f756e645f3134000000731000000000021001060114010c01140112011001722d000000630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290d721d0000007216000000721700000072250000007213000000721c000000721400000072100000007226000000722700000072280000007229000000722a00000029037224000000722b000000722c000000721800000072180000007219000000da1070757263686173655f726f756e645f3240000000731000000000021001060114010c01140112011001722e0000002901722c000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902722c000000da02746f2907721d000000721600000072170000007215000000721c0000007229000000722a0000002902722c000000721e000000721800000072180000007219000000da0b7061795f6f75745f7068694c000000730a000000000204011001040116017230000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902722c000000722f0000002907721d000000721600000072170000007215000000721c0000007226000000722a0000002902722c000000721e000000721800000072180000007219000000da0b7061795f6f75745f74617555000000730a000000000204011001040116017231000000291872020000007226000000da07636f6e5f7068697229000000da0b466f726569676e486173687225000000da085661726961626c657215000000720f000000721200000072130000007214000000721a000000da085f5f6578706f7274da05666c6f6174721f0000007220000000da03696e7472220000007223000000722d000000722e000000723000000072310000007218000000721800000072180000007219000000da083c6d6f64756c653e01000000733a0000000801080104010c010c01040108010401080104010801040108030808060110060601100606011006060110060601100b0601100b060110080601