Contract con_ape_test002


Contract Code

1 data = Hash(default_value=0)
2
3 active = Variable()
4 tau_amount = Variable()
5
6 price_contract = Variable()
7 price_variable = Variable()
8
9 neb_contract = Variable()
10 vault_variable = Variable()
11
12 INTERNAL_VAULT = 'INTERNAL_NEB_VAULT'
13 BURN_ADDRESS = 'NEBULA_BURN_ADDRESS'
14
15 OPERATORS = [
16 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
17 'e787ed5907742fa8d50b3ca2701ab8e03ec749ced806a15cdab800a127d7f863'
18 ]
19
20 @construct
21 def init():
22 active.set(False)
23 tau_amount.set(1)
24
25 price_contract.set('con_rocketswap_official_v1_1')
26 price_variable.set('prices')
27
28 neb_contract.set('con_nebula')
29 vault_variable.set('vault_contract')
30
31 @export
32 def subscribe():
33 assert active.get() == True, 'Contract disabled'
34
35 neb_price = ForeignHash(foreign_contract=price_contract.get(), foreign_name=price_variable.get())
36 neb_amount = int(tau_amount.get() / neb_price[neb_contract.get()])
37
38 neb = importlib.import_module(neb_contract.get())
39 neb.transfer_from(amount=neb_amount, to=ctx.this, main_account=ctx.caller)
40
41 data[ctx.caller] += neb_amount
42 data[ctx.caller, 'start'] = now
43
44 @export
45 def unsubscribe():
46 assert data[ctx.caller] > 0, 'You are not subscribed!'
47
48 total_amount = int(data[ctx.caller])
49
50 time_delta = now - data[ctx.caller, 'start']
51
52 # TODO: Set to 'days'
53 if time_delta <= datetime.timedelta(days=30):
54 payout = data[ctx.caller] / 100 * 30
55 elif time_delta <= datetime.timedelta(days=90):
56 payout = data[ctx.caller] / 100 * 50
57 elif time_delta <= datetime.timedelta(days=120):
58 payout = data[ctx.caller] / 100 * 70
59 else:
60 payout = data[ctx.caller] / 100 * 80
61
62 neb = importlib.import_module(neb_contract.get())
63
64 # Pay back user
65 neb.transfer(amount=int(payout), to=ctx.caller)
66
67 # Amount of NEB going to the vault
68 amount_delta = data[ctx.caller] - payout
69
70 vault = ForeignVariable(foreign_contract=neb_contract.get(), foreign_name=vault_variable.get())
71
72 if not vault:
73 vault = INTERNAL_VAULT
74
75 # Send delta amount to vault
76 neb.transfer(amount=int(amount_delta), to=vault)
77
78 data[ctx.caller] = 0
79
80 return 'Payed out {} NEB from {} NEB'.format(int(payout), total_amount)
81
82 @export
83 def enable():
84 assert_owner()
85 active.set(True)
86
87 @export
88 def disable():
89 assert_owner()
90 active.set(False)
91
92 @export
93 def set_tau_amount(amount: int):
94 assert_owner()
95 assert amount >= 0, 'Amount of TAU can not be negative'
96
97 tau_amount.set(amount)
98
99 @export
100 def set_price_interface(contract: str, function: str):
101 assert_owner()
102 price_contract.set(contract)
103 price_variable.set(function)
104
105 def assert_owner():
106 assert ctx.caller in OPERATORS, 'Only executable by operators!'
107

Byte Code

e3000000000000000000000000050000004000000073e8000000650064006401640264038d035a0165026401640464058d025a0365026401640664058d025a0465026401640764058d025a0565026401640864058d025a0665026401640964058d025a0765026401640a64058d025a08640b5a09640c5a0a640d640e67025a0b640f641084005a0c650d6401830164116412840083015a0e650d6401830164136414840083015a0f650d6401830164156416840083015a10650d6401830164176418840083015a11650d64018301651264199c01641a641b840483015a13650d6401830165146514641c9c02641d641e840483015a15641f642084005a16642153002922e900000000da0f636f6e5f6170655f74657374303032da04646174612903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da06616374697665290272050000007206000000da0a7461755f616d6f756e74da0e70726963655f636f6e7472616374da0e70726963655f7661726961626c65da0c6e65625f636f6e7472616374da0e7661756c745f7661726961626c65da12494e5445524e414c5f4e45425f5641554c54da134e4542554c415f4255524e5f41444452455353da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4065373837656435393037373432666138643530623363613237303161623865303365633734396365643830366131356364616238303061313237643766383633630000000000000000000000000200000043000000734000000074006a0164018301010074026a0164028301010074036a0164038301010074046a0164048301010074056a0164058301010074066a016406830101006400530029074e46e901000000da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da06707269636573da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163742907da085f5f616374697665da03736574da0c5f5f7461755f616d6f756e74da105f5f70726963655f636f6e7472616374da105f5f70726963655f7661726961626c65da0e5f5f6e65625f636f6e7472616374da105f5f7661756c745f7661726961626c65a900721d000000721d000000da00da045f5f5f5f0e000000730c00000000010a010a010a010a010a01721f000000630000000000000000030000000600000043000000738a00000074006a01830064016b0273147402640283018201740374046a01830074056a0183006403640464058d047d00740674076a0183007c0074086a01830019001b0083017d0174096a0a74086a01830083017d027c026a0b7c01740c6a0d740c6a0e64068d030100740f740c6a0e050019007c01370003003c007410740f740c6a0e640766023c006400530029084e547a11436f6e74726163742064697361626c65647202000000da096e65625f70726963652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720500000072060000002903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74da05737461727429117216000000da03676574da0e417373657274696f6e4572726f72da0b466f726569676e486173687219000000721a000000da03696e747218000000721b000000da09696d706f72746c6962da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda03637478da0474686973da0663616c6c6572da065f5f64617461da036e6f772903da0b5f5f6e65625f7072696365da0a6e65625f616d6f756e74da036e6562721d000000721d000000721e000000da097375627363726962651700000073120000000002140108010801080118010e011401120172360000006300000000000000000600000006000000430000007332010000740074016a02190064016b04731674036402830182017404740074016a02190083017d007405740074016a0264036602190018007d017c0174066a07640464058d016b01725a740074016a02190064061b00640414007d026e5a7c0174066a07640764058d016b01727e740074016a02190064061b00640814007d026e367c0174066a07640964058d016b0172a2740074016a02190064061b00640a14007d026e12740074016a02190064061b00640b14007d0274086a09740a6a0b830083017d037c036a0c74047c02830174016a02640c8d020100740074016a0219007c0218007d04740d740a6a0b8300740e6a0b8300640d640e640f8d047d057c0590017306740f7d057c036a0c74047c0483017c05640c8d0201006401740074016a023c0064106a1074047c0283017c008302530029114e72010000007a17596f7520617265206e6f742073756273637269626564217226000000e91e0000002901da0464617973e964000000e95a000000e932000000e978000000e946000000e9500000002902722300000072240000007202000000da057661756c74290472210000007222000000720500000072060000007a1c5061796564206f7574207b7d204e45422066726f6d207b7d204e454229117231000000722e00000072300000007228000000722a0000007232000000da086461746574696d65da0974696d6564656c7461722b000000722c000000721b0000007227000000da087472616e73666572da0f466f726569676e5661726961626c65721c000000da0e494e5445524e414c5f5641554c54da06666f726d61742906da0c746f74616c5f616d6f756e74da0a74696d655f64656c7461da067061796f75747235000000da0c616d6f756e745f64656c7461da075f5f7661756c74721d000000721d000000721e000000da0b756e73756273637269626524000000732a000000000216010e01120110011401100114011001140212010e0114010e010801080108010601040112010a01724b000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903da0e5f5f6173736572745f6f776e657272160000007217000000721d000000721d000000721d000000721e000000da06656e61626c653e000000730400000000020601724d000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903724c00000072160000007217000000721d000000721d000000721d000000721e000000da0764697361626c6544000000730400000000020601724e0000002901722300000063010000000000000001000000020000004300000073240000007400830001007c0064016b057316740164028301820174026a037c00830101006400530029034e72010000007a21416d6f756e74206f66205441552063616e206e6f74206265206e656761746976652904724c00000072280000007218000000721700000029017223000000721d000000721d000000721e000000da0e7365745f7461755f616d6f756e744a0000007306000000000206011001724f00000029027205000000da0866756e6374696f6e630200000000000000020000000200000043000000731e00000074008300010074016a027c008301010074036a027c01830101006400530029014e2904724c00000072190000007217000000721a000000290272050000007250000000721d000000721d000000721e000000da137365745f70726963655f696e74657266616365510000007306000000000206010a017251000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904722e0000007230000000da094f50455241544f52537228000000721d000000721d000000721d000000721e000000724c0000005800000073020000000001724c0000004e2917da04486173687231000000da085661726961626c65721600000072180000007219000000721a000000721b000000721c0000007244000000da0c4255524e5f414444524553537252000000721f000000da085f5f6578706f72747236000000724b000000724d000000724e000000722a000000724f000000da037374727251000000724c000000721d000000721d000000721d000000721e000000da083c6d6f64756c653e0100000073280000000e010c010c010c010c010c010c0104010401020106030809100d101a100610060601100606011206