Contract con_gamma_phi_sales_v1


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 purchase_round_1(amount_tau: float):
26 assert amount_tau > 0, 'Cannot purchase negative amounts!'
27 purchaser = ctx.caller
28
29 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
30
31 amount = amount_tau / round_1_price.get()
32
33 assert round_1_quantity.get() > amount, 'Not enough remaining in round 1'
34
35 round_1_quantity.set(round_1_quantity.get() - amount)
36
37 tau.transfer_from(amount_tau, ctx.this, purchaser)
38 phi.transfer(amount, purchaser)
39
40
41 @export
42 def purchase_round_2(amount_tau: float):
43 assert amount_tau > 0, 'Cannot purchase negative amounts!'
44 purchaser = ctx.caller
45
46 assert tau_balances[purchaser] >= amount_tau, 'Not enough tau!'
47
48 amount = amount_tau / round_2_price.get()
49
50 assert round_2_quantity.get() > amount, 'Not enough remaining in round 1'
51
52 round_2_quantity.set(round_2_quantity.get() - amount)
53
54 tau.transfer_from(amount_tau, ctx.this, purchaser)
55 phi.transfer(amount, purchaser)
56
57
58 @export
59 def pay_out(amount: float):
60 error = "Negative amount is not allowed"
61 assert amount > 0, error
62
63 error = "Only owner can payout tokens"
64 assert ctx.caller == owner.get(), error
65
66 # Transfer tokens from contract to owner
67 phi.transfer(
68 amount=amount,
69 to=ctx.caller)

Byte Code

e3000000000000000000000000060000004000000073aa000000640064016c005a01640064016c025a036504640264036404640564068d045a0565066404640764088d025a0765066404640964088d025a0865066404640a64088d025a0965066404640b64088d025a0a65066404640c64088d025a0b640d640e84005a0c650d64048301650e640f9c0164106411840483015a0f650d64048301650e640f9c0164126413840483015a10650d64048301650e64149c0164156416840483015a11640153002917e9000000004eda0863757272656e6379da0862616c616e636573da16636f6e5f67616d6d615f7068695f73616c65735f7631da0c7461755f62616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da056f776e6572290272080000007209000000da0d726f756e645f315f7072696365da10726f756e645f315f7175616e74697479da0d726f756e645f325f7072696365da10726f756e645f325f7175616e74697479630000000000000000000000000300000043000000734000000074006a017402640183018301010074036a0164028301010074046a017402640383018301010074056a0164028301010074066a0174076a08830101006400530029044e7a05302e3030326900e1f5057a05302e3030342909da0f5f5f726f756e645f315f7072696365da03736574da07646563696d616cda125f5f726f756e645f315f7175616e74697479da0f5f5f726f756e645f325f7072696365da125f5f726f756e645f325f7175616e74697479da075f5f6f776e6572da03637478da0663616c6c6572a90072180000007218000000da00da045f5f5f5f10000000730a00000000010e010a010e010a01721a0000002901da0a616d6f756e745f746175630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290dda0e417373657274696f6e4572726f7272160000007217000000da0e5f5f7461755f62616c616e636573720f000000da0367657472120000007210000000da03746175da0d7472616e736665725f66726f6dda0474686973da03706869da087472616e736665722903721b000000da09707572636861736572da06616d6f756e74721800000072180000007219000000da1070757263686173655f726f756e645f3118000000731000000000021001060114010c011401120110017226000000630100000000000000030000000400000043000000737c0000007c0064016b047310740064028301820174016a027d0174037c0119007c006b05732a74006403830182017c0074046a0583001b007d0274066a0583007c026b04734a740064048301820174066a0774066a0583007c0218008301010074086a097c0074016a0a7c0183030100740b6a0c7c027c01830201006400530029054e72010000007a2143616e6e6f74207075726368617365206e6567617469766520616d6f756e7473217a0f4e6f7420656e6f75676820746175217a1f4e6f7420656e6f7567682072656d61696e696e6720696e20726f756e642031290d721c00000072160000007217000000721d0000007213000000721e00000072140000007210000000721f00000072200000007221000000722200000072230000002903721b00000072240000007225000000721800000072180000007219000000da1070757263686173655f726f756e645f3224000000731000000000021001060114010c01140112011001722700000029017225000000630100000000000000020000000400000043000000734200000064017d017c0064026b04731474007c018301820164037d0174016a0274036a0483006b02732e74007c018301820174056a067c0074016a0264048d0201006400530029054e7a1e4e6567617469766520616d6f756e74206973206e6f7420616c6c6f77656472010000007a1c4f6e6c79206f776e65722063616e207061796f757420746f6b656e7329027225000000da02746f2907721c000000721600000072170000007215000000721e0000007222000000722300000029027225000000da056572726f72721800000072180000007219000000da077061795f6f757430000000730a00000000020401100104011601722a00000029127202000000721f000000da07636f6e5f7068697222000000da0b466f726569676e48617368721d000000da085661726961626c657215000000720f000000721200000072130000007214000000721a000000da085f5f6578706f7274da05666c6f617472260000007227000000722a0000007218000000721800000072180000007219000000da083c6d6f64756c653e0100000073260000000801080104010c010c010401080104010801040108010401080308080601100b0601100b0601