Contract con_ape_test004


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(1500)
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 if time_delta <= datetime.timedelta(days=30):
53 payout = data[ctx.caller] / 100 * 30
54 elif time_delta <= datetime.timedelta(days=90):
55 payout = data[ctx.caller] / 100 * 50
56 elif time_delta <= datetime.timedelta(days=120):
57 payout = data[ctx.caller] / 100 * 70
58 else:
59 payout = data[ctx.caller] / 100 * 80
60
61 neb = importlib.import_module(neb_contract.get())
62
63 # Pay back user
64 neb.transfer(amount=int(payout), to=ctx.caller)
65
66 # Amount of NEB going to the vault
67 amount_delta = data[ctx.caller] - payout
68
69 vault = ForeignVariable(foreign_contract=neb_contract.get(), foreign_name=vault_variable.get())
70
71 if not vault.get():
72 vault = Variable(INTERNAL_VAULT)
73
74 # Send delta amount to vault
75 neb.transfer(amount=int(amount_delta), to=vault.get())
76
77 data[ctx.caller] = 0
78
79 return 'Payed out {} NEB from {} NEB'.format(int(payout), total_amount)
80
81 @export
82 def enable():
83 assert_owner()
84 active.set(True)
85
86 @export
87 def disable():
88 assert_owner()
89 active.set(False)
90
91 @export
92 def set_tau_amount(amount: int):
93 assert_owner()
94 assert amount >= 0, 'Amount of TAU can not be negative'
95
96 tau_amount.set(amount)
97
98 @export
99 def set_price_interface(contract: str, variable: str):
100 assert_owner()
101 price_contract.set(contract)
102 price_variable.set(variable)
103
104 @export
105 def set_vault_interface(contract: str, variable: str):
106 assert_owner()
107 neb_contract.set(contract)
108 vault_variable.set(variable)
109
110 def assert_owner():
111 assert ctx.caller in OPERATORS, 'Only executable by operators!'
112

Byte Code

e300000000000000000000000005000000400000007300010000650064006401640264038d035a0165026401640464058d025a0365026401640664058d025a0465026401640764058d025a0565026401640864058d025a0665026401640964058d025a0765026401640a64058d025a08640b5a09640c5a0a640d640e67025a0b640f641084005a0c650d6401830164116412840083015a0e650d6401830164136414840083015a0f650d6401830164156416840083015a10650d6401830164176418840083015a11650d64018301651264199c01641a641b840483015a13650d6401830165146514641c9c02641d641e840483015a15650d6401830165146514641c9c02641f6420840483015a166421642284005a17642353002924e900000000da0f636f6e5f6170655f74657374303034da04646174612903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da06616374697665290272050000007206000000da0a7461755f616d6f756e74da0e70726963655f636f6e7472616374da0e70726963655f7661726961626c65da0c6e65625f636f6e7472616374da0e7661756c745f7661726961626c65da12494e5445524e414c5f4e45425f5641554c54da134e4542554c415f4255524e5f41444452455353da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da4065373837656435393037373432666138643530623363613237303161623865303365633734396365643830366131356364616238303061313237643766383633630000000000000000000000000200000043000000734000000074006a0164018301010074026a0164028301010074036a0164038301010074046a0164048301010074056a0164058301010074066a016406830101006400530029074e4669dc050000da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da06707269636573da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163742907da085f5f616374697665da03736574da0c5f5f7461755f616d6f756e74da105f5f70726963655f636f6e7472616374da105f5f70726963655f7661726961626c65da0e5f5f6e65625f636f6e7472616374da105f5f7661756c745f7661726961626c65a900721c000000721c000000da00da045f5f5f5f0e000000730c00000000010a010a010a010a010a01721e000000630000000000000000030000000600000043000000738a00000074006a01830064016b0273147402640283018201740374046a01830074056a0183006403640464058d047d00740674076a0183007c0074086a01830019001b0083017d0174096a0a74086a01830083017d027c026a0b7c01740c6a0d740c6a0e64068d030100740f740c6a0e050019007c01370003003c007410740f740c6a0e640766023c006400530029084e547a11436f6e74726163742064697361626c65647202000000da096e65625f70726963652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720500000072060000002903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74da05737461727429117215000000da03676574da0e417373657274696f6e4572726f72da0b466f726569676e4861736872180000007219000000da03696e747217000000721a000000da09696d706f72746c6962da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda03637478da0474686973da0663616c6c6572da065f5f64617461da036e6f772903da0b5f5f6e65625f7072696365da0a6e65625f616d6f756e74da036e6562721c000000721c000000721d000000da097375627363726962651700000073120000000002140108010801080118010e011401120172350000006300000000000000000600000006000000430000007344010000740074016a02190064016b04731674036402830182017404740074016a02190083017d007405740074016a0264036602190018007d017c0174066a07640464058d016b01725a740074016a02190064061b00640414007d026e5a7c0174066a07640764058d016b01727e740074016a02190064061b00640814007d026e367c0174066a07640964058d016b0172a2740074016a02190064061b00640a14007d026e12740074016a02190064061b00640b14007d0274086a09740a6a0b830083017d037c036a0c74047c02830174016a02640c8d020100740074016a0219007c0218007d04740d740a6a0b8300740e6a0b8300640d640e640f8d047d057c056a0b830090017314740f7410640d640e64108d037d057c036a0c74047c0483017c056a0b8300640c8d0201006401740074016a023c0064116a1174047c0283017c008302530029124e72010000007a17596f7520617265206e6f742073756273637269626564217225000000e91e0000002901da0464617973e964000000e95a000000e932000000e978000000e946000000e9500000002902722200000072230000007202000000da057661756c74290472200000007221000000720500000072060000002902720500000072060000007a1c5061796564206f7574207b7d204e45422066726f6d207b7d204e454229127230000000722d000000722f000000722700000072290000007231000000da086461746574696d65da0974696d6564656c7461722a000000722b000000721a0000007226000000da087472616e73666572da0f466f726569676e5661726961626c65721b000000da085661726961626c65da0e494e5445524e414c5f5641554c54da06666f726d61742906da0c746f74616c5f616d6f756e74da0a74696d655f64656c7461da067061796f75747234000000da0c616d6f756e745f64656c7461da075f5f7661756c74721c000000721c000000721d000000da0b756e73756273637269626524000000732c000000000216010e01120110011401100114011001140212010e0114010e010801080108010a010601080116010a01724b000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903da0e5f5f6173736572745f6f776e657272150000007216000000721c000000721c000000721c000000721d000000da06656e61626c653f000000730400000000020601724d000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903724c00000072150000007216000000721c000000721c000000721c000000721d000000da0764697361626c6545000000730400000000020601724e0000002901722200000063010000000000000001000000020000004300000073240000007400830001007c0064016b057316740164028301820174026a037c00830101006400530029034e72010000007a21416d6f756e74206f66205441552063616e206e6f74206265206e656761746976652904724c00000072270000007217000000721600000029017222000000721c000000721c000000721d000000da0e7365745f7461755f616d6f756e744b0000007306000000000206011001724f00000029027205000000da087661726961626c65630200000000000000020000000200000043000000731e00000074008300010074016a027c008301010074036a027c01830101006400530029014e2904724c000000721800000072160000007219000000290272050000007250000000721c000000721c000000721d000000da137365745f70726963655f696e74657266616365520000007306000000000206010a017251000000630200000000000000020000000200000043000000731e00000074008300010074016a027c008301010074036a027c01830101006400530029014e2904724c000000721a0000007216000000721b000000290272050000007250000000721c000000721c000000721d000000da137365745f7661756c745f696e74657266616365590000007306000000000206010a017252000000630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904722d000000722f000000da094f50455241544f52537227000000721c000000721c000000721c000000721d000000724c0000006000000073020000000001724c0000004e2918da0448617368723000000072430000007215000000721700000072180000007219000000721a000000721b0000007244000000da0c4255524e5f414444524553537253000000721e000000da085f5f6578706f72747235000000724b000000724d000000724e0000007229000000724f000000da0373747272510000007252000000724c000000721c000000721c000000721c000000721d000000da083c6d6f64756c653e01000000732c0000000e010c010c010c010c010c010c0104010401020106030809100d101b10061006060110060601120606011206