Contract con_gamma_phi_sales_v2


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 round_1_price.set(price)
27
28
29 @export
30 def set_round_2_price(price: float):
31 round_2_price.set(price)
32
33
34 @export
35 def set_round_1_quantity(quantity: int):
36 round_1_quantity.set(quantity)
37
38
39 @export
40 def set_round_2_quantity(quantity: int):
41 round_2_quantity.set(quantity)
42
43
44 @export
45 def purchase_round_1(amount_tau: float):
46 assert amount_tau > 0, 'Cannot purchase negative amounts!'
47 purchaser = ctx.caller
48
49 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
50
51 amount = amount_tau / round_1_price.get()
52
53 assert round_1_quantity.get() > amount, 'Not enough remaining in round 1'
54
55 round_1_quantity.set(round_1_quantity.get() - amount)
56
57 tau.transfer_from(amount_tau, ctx.this, purchaser)
58 phi.transfer(amount, purchaser)
59
60
61 @export
62 def purchase_round_2(amount_tau: float):
63 assert amount_tau > 0, 'Cannot purchase negative amounts!'
64 purchaser = ctx.caller
65
66 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
67
68 amount = amount_tau / round_2_price.get()
69
70 assert round_2_quantity.get() > amount, 'Not enough remaining in round 1'
71
72 round_2_quantity.set(round_2_quantity.get() - amount)
73
74 tau.transfer_from(amount_tau, ctx.this, purchaser)
75 phi.transfer(amount, purchaser)
76
77 @export
78 def pay_out_phi(amount: float):
79 error = "Negative amount is not allowed"
80 assert amount > 0, error
81
82 error = "Only owner can payout tokens"
83 assert ctx.caller == owner.get(), error
84
85 # Transfer tokens from contract to owner
86 phi.transfer(
87 amount=amount,
88 to=ctx.caller)
89
90 @export
91 def pay_out_tau(amount: float):
92 error = "Negative amount is not allowed"
93 assert amount > 0, error
94
95 error = "Only owner can payout tokens"
96 assert ctx.caller == owner.get(), error
97
98 # Transfer tokens from contract to owner
99 tau.transfer(
100 amount=amount,
101 to=ctx.caller)

Byte Code

e300000000000000000000000006000000400000007318010000640064016c005a01640064016c025a036504640264036404640564068d045a0565066404640764088d025a0765066404640964088d025a0865066404640a64088d025a0965066404640b64088d025a0a65066404640c64088d025a0b640d640e84005a0c650d64048301650e640f9c0164106411840483015a0f650d64048301650e640f9c0164126413840483015a10650d64048301651164149c0164156416840483015a12650d64048301651164149c0164176418840483015a13650d64048301650e64199c01641a641b840483015a14650d64048301650e64199c01641c641d840483015a15650d64048301650e641e9c01641f6420840483015a16650d64048301650e641e9c0164216422840483015a17640153002923e9000000004eda0863757272656e6379da0862616c616e636573da16636f6e5f67616d6d615f7068695f73616c65735f7632da0c7461755f62616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da056f776e6572290272080000007209000000da0d726f756e645f315f7072696365da10726f756e645f315f7175616e74697479da0d726f756e645f325f7072696365da10726f756e645f325f7175616e74697479630000000000000000000000000300000043000000734000000074006a017402640183018301010074036a0164028301010074046a017402640383018301010074056a0164028301010074066a0174076a08830101006400530029044e7a05302e3030326900e1f5057a05302e3030342909da0f5f5f726f756e645f315f7072696365da03736574da07646563696d616cda125f5f726f756e645f315f7175616e74697479da0f5f5f726f756e645f325f7072696365da125f5f726f756e645f325f7175616e74697479da075f5f6f776e6572da03637478da0663616c6c6572a90072180000007218000000da00da045f5f5f5f10000000730a00000000010e010a010e010a01721a0000002901da057072696365630100000000000000010000000200000043000000730e00000074006a017c00830101006400530029014e2902720f00000072100000002901721b000000721800000072180000007219000000da117365745f726f756e645f315f70726963651800000073020000000002721c000000630100000000000000010000000200000043000000730e00000074006a017c00830101006400530029014e2902721300000072100000002901721b000000721800000072180000007219000000da117365745f726f756e645f325f70726963651d00000073020000000002721d0000002901da087175616e74697479630100000000000000010000000200000043000000730e00000074006a017c00830101006400530029014e2902721200000072100000002901721e000000721800000072180000007219000000da147365745f726f756e645f315f7175616e746974792200000073020000000002721f000000630100000000000000010000000200000043000000730e00000074006a017c00830101006400530029014e2902721400000072100000002901721e000000721800000072180000007219000000da147365745f726f756e645f325f7175616e74697479270000007302000000000272200000002901da0a616d6f756e745f746175630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290dda0e417373657274696f6e4572726f7272160000007217000000da0e5f5f7461755f62616c616e636573720f000000da0367657472120000007210000000da03746175da0d7472616e736665725f66726f6dda0474686973da03706869da087472616e7366657229037221000000da09707572636861736572da06616d6f756e74721800000072180000007219000000da1070757263686173655f726f756e645f312c000000731000000000021001060114010c01140112011001722c000000630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290d722200000072160000007217000000722300000072130000007224000000721400000072100000007225000000722600000072270000007228000000722900000029037221000000722a000000722b000000721800000072180000007219000000da1070757263686173655f726f756e645f3238000000731000000000021001060114010c01140112011001722d0000002901722b000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902722b000000da02746f290772220000007216000000721700000072150000007224000000722800000072290000002902722b000000da056572726f72721800000072180000007219000000da0b7061795f6f75745f70686944000000730a000000000204011001040116017230000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e732902722b000000722e000000290772220000007216000000721700000072150000007224000000722500000072290000002902722b000000722f000000721800000072180000007219000000da0b7061795f6f75745f7461754d000000730a000000000204011001040116017231000000291872020000007225000000da07636f6e5f7068697228000000da0b466f726569676e486173687223000000da085661726961626c657215000000720f000000721200000072130000007214000000721a000000da085f5f6578706f7274da05666c6f6174721c000000721d000000da03696e74721f0000007220000000722c000000722d000000723000000072310000007218000000721800000072180000007219000000da083c6d6f64756c653e01000000733a0000000801080104010c010c01040108010401080104010801040108030808060110040601100406011004060110040601100b0601100b060110080601