Contract con_neb_key_tst13


Contract Code

1 # 888b 888 888 888 888 d8P 8888888888 Y88b d88P
2 # 8888b 888 888 888 888 d8P 888 Y88b d88P
3 # 88888b 888 888 888 888 d8P 888 Y88o88P
4 # 888Y88b 888 .d88b. 88888b. 888 888 888 8888b. 888d88K 8888888 Y888P
5 # 888 Y88b888 d8P Y8b 888 "88b 888 888 888 "88b 8888888b 888 888
6 # 888 Y88888 88888888 888 888 888 888 888 .d888888 888 Y88b 888 888
7 # 888 Y8888 Y8b. 888 d88P Y88b 888 888 888 888 888 Y88b 888 888
8 # 888 Y888 "Y8888 88888P" "Y88888 888 "Y888888 888 Y88b 8888888888 888
9
10 import con_nebula as neb
11
12 staking = Hash(default_value='')
13 balances = Hash(default_value=0)
14 metadata = Hash()
15
16 active = Variable()
17 total_supply = Variable()
18
19 stake_tax = Variable()
20 stake_amount = Variable()
21 stake_start_date = Variable()
22 stake_start_period = Variable()
23 stake_period = Variable()
24
25 OPERATORS = [
26 'ae7d14d6d9b8443f881ba6244727b69b681010e782d4fe482dbfb0b6aca02d5d',
27 'e787ed5907742fa8d50b3ca2701ab8e03ec749ced806a15cdab800a127d7f863'
28 ]
29
30 @construct
31 def seed():
32 metadata['token_name'] = "Nebula TKEY"
33 metadata['token_symbol'] = "TKEY"
34 metadata['operator'] = ctx.caller
35
36 stake_tax.set(1)
37 stake_amount.set(10)
38 stake_start_date.set(now)
39 stake_start_period.set(4)
40 stake_period.set(21)
41
42 active.set(True)
43 total_supply.set(0)
44
45 @export
46 def change_metadata(key: str, value: Any):
47 assert_owner()
48
49 metadata[key] = value
50
51 @export
52 def transfer(amount: float, to: str):
53 assert amount > 0, 'Cannot send negative balances!'
54 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
55 assert is_int(amount), 'Amount must be an Integer!'
56
57 balances[ctx.caller] -= amount
58 balances[to] += amount
59
60 @export
61 def approve(amount: float, to: str):
62 assert amount > 0, 'Cannot send negative balances!'
63 assert is_int(amount), 'Amount must be an Integer!'
64
65 balances[ctx.caller, to] += amount
66
67 @export
68 def transfer_from(amount: float, to: str, main_account: str):
69 assert amount > 0, 'Cannot send negative balances!'
70 assert balances[main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
71 .format(balances[main_account, ctx.caller], amount)
72 assert balances[main_account] >= amount, 'Not enough coins to send!'
73 assert is_int(amount), 'Amount must be an Integer!'
74
75 balances[main_account, ctx.caller] -= amount
76 balances[main_account] -= amount
77 balances[to] += amount
78
79 def is_int(amount: float):
80 int_amount = int(amount)
81 return int_amount == amount
82
83 @export
84 def stake():
85 assert active.get() == True, 'Contract inactive!'
86 assert staking[ctx.caller] == '', 'Address is already staking!'
87 assert now < (stake_start_date.get() + datetime.timedelta(minutes=stake_start_period.get())), 'Staking start period ended!'
88
89 neb.transfer_from(amount=stake_amount.get(), to=ctx.this, main_account=ctx.caller)
90
91 staking[ctx.caller] = str(now)
92
93 @export
94 def unstake():
95 assert active.get() == True, 'Contract inactive!'
96 assert staking[ctx.caller] != '', 'Address is not staking!'
97
98 total_stake_time = stake_start_period.get() + stake_period.get()
99
100 if now < (stake_start_date.get() + datetime.timedelta(minutes=total_stake_time)):
101 # Calculate early unstake tax and payout amount
102 tax = int(stake_amount.get() / 100 * stake_tax.get())
103 payout = stake_amount.get() - tax
104
105 # Pay NEB back to user (minus tax for early unstake)
106 neb.transfer(amount=payout, to=ctx.caller)
107
108 # Retrieve vault contract
109 vault = ForeignVariable(foreign_contract='con_nebula', foreign_name='vault_contract')
110
111 # If no vault contract set, use internal vault
112 if not vault.get():
113 vault = Variable()
114 vault.set('INTERNAL_NEB_VAULT')
115
116 # Pay tax to vault
117 neb.transfer(amount=tax, to=vault.get())
118
119 # Reset staking date
120 staking[ctx.caller] = ''
121
122 return 'Unstaked early. No KEY token minted. Payed back {} NEB'.format(int(payout))
123
124 else:
125 # Pay NEB back to user
126 neb.transfer(amount=stake_amount.get(), to=ctx.caller)
127
128 # Mint KEY token for user
129 balances[ctx.caller] += 1
130
131 # Add newly minted KEY to total supply
132 total_supply.set(total_supply.get() + 1)
133
134 # Reset staking date
135 staking[ctx.caller] = ''
136
137 return 'Unstaked and minted 1 KEY token. Payed back {} NEB'.format(int(stake_amount.get()))
138
139 @export
140 def start():
141 assert_owner()
142 staking.clear()
143 stake_start_date.set(now)
144
145 @export
146 def set_stake_start_period(minutes: int):
147 assert_owner()
148 stake_start_period.set(minutes)
149
150 @export
151 def set_stake_period(minutes: int):
152 assert_owner()
153 stake_period.set(minutes)
154
155 @export
156 def set_stake_amount(amount: float):
157 assert_owner()
158 assert amount > 0, 'Cannot set negative amount!'
159 stake_amount.set(amount)
160
161 @export
162 def set_stake_tax(percent: float):
163 assert_owner()
164 assert percent > 0 and percent < 100, 'Wrong tax value!'
165 stake_tax.set(percent)
166
167 @export
168 def time_until_unstake():
169 assert staking[ctx.caller] != '', 'Address is not staking!'
170 total_stake_time = stake_start_period.get() + stake_period.get()
171 return (stake_start_date.get() - now) + datetime.timedelta(minutes=total_stake_time)
172
173 @export
174 def enable():
175 assert_owner()
176 active.set(True)
177
178 @export
179 def disable():
180 assert_owner()
181 active.set(False)
182
183 @export
184 def emergency_withdraw(amount: float):
185 assert_owner()
186 neb.transfer(amount, ctx.caller)
187
188 @export
189 def total_supply():
190 return int(total_supply.get())
191
192 def assert_owner():
193 assert ctx.caller in OPERATORS, 'Only executable by operators!'
194

Byte Code

e3000000000000000000000000050000004000000073ee010000640064016c005a01650264026403640464058d035a03650264006403640664058d035a0465026403640764088d025a0565066403640964088d025a0765066403640a64088d025a0865066403640b64088d025a0965066403640c64088d025a0a65066403640d64088d025a0b65066403640e64088d025a0c65066403640f64088d025a0d6410641167025a0e6412641384005a0f6510640383016511651264149c0264156416840483015a136510640383016514651164179c0264186419840483015a156510640383016514651164179c02641a641b840483015a16651064038301651465116511641c9c03641d641e840483015a176514641f9c016420642184045a1865106403830164226423840083015a1965106403830164246425840083015a1a65106403830164266427840083015a1b651064038301651c64289c016429642a840483015a1d651064038301651c64289c01642b642c840483015a1e6510640383016514641f9c01642d642e840483015a1f6510640383016514642f9c0164306431840483015a2065106403830164326433840083015a2165106403830164346435840083015a2265106403830164366437840083015a236510640383016514641f9c0164386439840483015a24651064038301643a640a840083015a25643b643c84005a2664015300293de9000000004eda00da11636f6e5f6e65625f6b65795f7473743133da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d65746164617461290272060000007207000000da06616374697665da0c746f74616c5f737570706c79da097374616b655f746178da0c7374616b655f616d6f756e74da107374616b655f73746172745f64617465da127374616b655f73746172745f706572696f64da0c7374616b655f706572696f64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000030000004300000073640000006401740064023c006403740064043c0074016a02740064053c0074036a0464068301010074056a0464078301010074066a0474078301010074086a0464088301010074096a04640983010100740a6a04640a83010100740b6a04640b8301010064005300290c4e7a0b4e6562756c6120544b4559da0a746f6b656e5f6e616d65da04544b4559da0c746f6b656e5f73796d626f6cda086f70657261746f72e901000000e90a000000e904000000e915000000547201000000290cda0a5f5f6d65746164617461da03637478da0663616c6c6572da0b5f5f7374616b655f746178da03736574da0e5f5f7374616b655f616d6f756e74da125f5f7374616b655f73746172745f64617465da036e6f77da145f5f7374616b655f73746172745f706572696f64da0e5f5f7374616b655f706572696f64da085f5f616374697665da0e5f5f746f74616c5f737570706c79a900722700000072270000007202000000da045f5f5f5f1400000073140000000001080108010a010a010a010a010a010a010a0172280000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e6572721b00000029027229000000722a000000722700000072270000007202000000da0f6368616e67655f6d6574616461746121000000730400000000020601722c0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000735c0000007c0064016b0473107400640283018201740174026a0319007c006b057326740064038301820174047c00830173367400640483018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212905da0e417373657274696f6e4572726f72da0a5f5f62616c616e636573721c000000721d000000da085f5f69735f696e742902722d000000722e000000722700000072270000007202000000da087472616e7366657227000000730a000000000210011601100112017232000000630200000000000000020000000400000043000000733a0000007c0064016b047310740064028301820174017c00830173207400640383018201740274036a047c016602050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1a416d6f756e74206d75737420626520616e20496e7465676572212905722f00000072310000007230000000721c000000721d0000002902722d000000722e000000722700000072270000007202000000da07617070726f766530000000730600000000021001100172330000002903722d000000722e000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000739a0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174057c0083017360740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212906722f0000007230000000721c000000721d000000da06666f726d617472310000002903722d000000722e0000007234000000722700000072270000007202000000da0d7472616e736665725f66726f6d370000007312000000000210010c010c011401140110011601100172360000002901722d000000630100000000000000020000000200000043000000731000000074007c0083017d017c017c006b02530029014e2901da03696e742902722d000000da0a696e745f616d6f756e747227000000722700000072020000007231000000440000007304000000000108017231000000630000000000000000000000000500000043000000737800000074006a01830064016b0273147402640283018201740374046a05190064036b02732a7402640483018201740674076a01830074086a09740a6a01830064058d0117006b00734e7402640683018201740b6a0c740d6a01830074046a0e74046a0564078d030100740f74068301740374046a053c006400530029084e547a12436f6e747261637420696e6163746976652172020000007a1b4164647265737320697320616c7265616479207374616b696e67212901da076d696e757465737a1b5374616b696e6720737461727420706572696f6420656e646564212903722d000000722e000000723400000029107225000000da03676574722f000000da095f5f7374616b696e67721c000000721d00000072220000007221000000da086461746574696d65da0974696d6564656c74617223000000da036e656272360000007220000000da0474686973da037374727227000000722700000072270000007202000000da057374616b6549000000730e0000000002140116010c0118010e010a017241000000630000000000000000040000000600000043000000733601000074006a01830064016b0273147402640283018201740374046a05190064036b03732a740264048301820174066a01830074076a01830017007d00740874096a018300740a6a0b7c0064058d0117006b0072de740c740d6a01830064061b00740e6a018300140083017d01740d6a0183007c0118007d02740f6a107c0274046a0564078d020100741164086409640a640b640c8d047d037c036a01830073b47412640a640b640d8d027d037c036a13640e83010100740f6a107c017c036a01830064078d0201006403740374046a053c00640f6a14740c7c02830183015300740f6a10740d6a01830074046a0564078d020100741574046a05050019006410370003003c0074166a1374166a01830064101700830101006403740374046a053c0064116a14740c740d6a0183008301830153006400530029124e547a12436f6e747261637420696e6163746976652172020000007a1741646472657373206973206e6f74207374616b696e672129017239000000e9640000002902722d000000722e000000da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163747203000000da057661756c742904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572060000007207000000290272060000007207000000da12494e5445524e414c5f4e45425f5641554c547a36556e7374616b6564206561726c792e204e6f204b455920746f6b656e206d696e7465642e205061796564206261636b207b7d204e454272170000007a32556e7374616b656420616e64206d696e7465642031204b455920746f6b656e2e205061796564206261636b207b7d204e454229177225000000723a000000722f000000723b000000721c000000721d0000007223000000722400000072220000007221000000723c000000723d00000072370000007220000000721e000000723e0000007232000000da0f466f726569676e5661726961626c65da085661726961626c65721f0000007235000000723000000072260000002904da10746f74616c5f7374616b655f74696d65da03746178da067061796f7574da075f5f7661756c74722700000072270000007202000000da07756e7374616b6554000000733000000000021401160110010c010c0118010c01100104010401080108010c010a0112010a0104010a021401120112010a010601724f000000630000000000000000000000000200000043000000731c00000074008300010074016a028300010074036a047405830101006400530029014e2906722b000000723b000000da05636c6561727221000000721f00000072220000007227000000722700000072270000007202000000da057374617274710000007306000000000206010801725100000029017239000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007223000000721f00000029017239000000722700000072270000007202000000da167365745f7374616b655f73746172745f706572696f64780000007304000000000206017252000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007224000000721f00000029017239000000722700000072270000007202000000da107365745f7374616b655f706572696f647e000000730400000000020601725300000063010000000000000001000000020000004300000073240000007400830001007c0064016b047316740164028301820174026a037c00830101006400530029034e72010000007a1b43616e6e6f7420736574206e6567617469766520616d6f756e74212904722b000000722f0000007220000000721f0000002901722d000000722700000072270000007202000000da107365745f7374616b655f616d6f756e7484000000730600000000020601100172540000002901da0770657263656e74630100000000000000010000000200000043000000732c0000007400830001007c0064016b0472167c0064026b00731e740164038301820174026a037c00830101006400530029044e720100000072420000007a1057726f6e67207461782076616c7565212904722b000000722f000000721e000000721f00000029017255000000722700000072270000007202000000da0d7365745f7374616b655f7461788b00000073060000000002060118017256000000630000000000000000010000000400000043000000733e000000740074016a02190064016b037316740364028301820174046a05830074066a05830017007d0074076a0583007408180074096a0a7c0064038d011700530029044e72020000007a1741646472657373206973206e6f74207374616b696e672129017239000000290b723b000000721c000000721d000000722f0000007223000000723a000000722400000072210000007222000000723c000000723d0000002901724b000000722700000072270000007202000000da1274696d655f756e74696c5f756e7374616b659200000073080000000002160110010e017257000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903722b0000007225000000721f0000007227000000722700000072270000007202000000da06656e61626c659a0000007304000000000206017258000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903722b0000007225000000721f0000007227000000722700000072270000007202000000da0764697361626c65a00000007304000000000206017259000000630100000000000000010000000300000043000000731800000074008300010074016a027c0074036a04830201006400530029014e2905722b000000723e0000007232000000721c000000721d0000002901722d000000722700000072270000007202000000da12656d657267656e63795f7769746864726177a6000000730400000000020601725a000000630000000000000000000000000200000043000000730c000000740074016a0283008301530029014e290372370000007226000000723a0000007227000000722700000072270000007202000000720b000000ac00000073020000000002630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904721c000000721d000000da094f50455241544f5253722f0000007227000000722700000072270000007202000000722b000000b100000073020000000001722b00000029277243000000723e000000da0448617368723b0000007230000000721b000000724a00000072250000007226000000721e0000007220000000722100000072230000007224000000725b0000007228000000da085f5f6578706f72747240000000da03416e79722c000000da05666c6f617472320000007233000000723600000072310000007241000000724f000000725100000072370000007252000000725300000072540000007256000000725700000072580000007259000000725a000000720b000000722b0000007227000000722700000072270000007202000000da083c6d6f64756c653e01000000735600000008010e02060108010c010c010c010c010c0104010801040108010c0102010603080d0601120506011208060112060601140c0e05100b101d100706011005060110050601100606011006100810061006060110051005