Contract con_neb_key_tst12


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 amount.is_integer(), '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 amount.is_integer(), '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 amount.is_integer(), 'Amount must be an Integer!'
74
75 balances[main_account, ctx.caller] -= amount
76 balances[main_account] -= amount
77 balances[to] += amount
78
79 @export
80 def stake():
81 assert active.get() == True, 'Contract inactive!'
82 assert staking[ctx.caller] == '', 'Address is already staking!'
83 assert now < (stake_start_date.get() + datetime.timedelta(minutes=stake_start_period.get())), 'Staking start period ended!'
84
85 neb.transfer_from(amount=stake_amount.get(), to=ctx.this, main_account=ctx.caller)
86
87 staking[ctx.caller] = str(now)
88
89 @export
90 def unstake():
91 assert active.get() == True, 'Contract inactive!'
92 assert staking[ctx.caller] != '', 'Address is not staking!'
93
94 total_stake_time = stake_start_period.get() + stake_period.get()
95
96 if now < (stake_start_date.get() + datetime.timedelta(minutes=total_stake_time)):
97 # Calculate early unstake tax and payout amount
98 tax = int(stake_amount.get() / 100 * stake_tax.get())
99 payout = stake_amount.get() - tax
100
101 # Pay NEB back to user (minus tax for early unstake)
102 neb.transfer(amount=payout, to=ctx.caller)
103
104 # Retrieve vault contract
105 vault = ForeignVariable(foreign_contract='con_nebula', foreign_name='vault_contract')
106
107 # If no vault contract set, use internal vault
108 if not vault.get():
109 vault = Variable()
110 vault.set('INTERNAL_NEB_VAULT')
111
112 # Pay tax to vault
113 neb.transfer(amount=tax, to=vault.get())
114
115 # Reset staking date
116 staking[ctx.caller] = ''
117
118 return 'Unstaked early. No KEY token minted. Payed back {} NEB'.format(int(payout))
119
120 else:
121 # Pay NEB back to user
122 neb.transfer(amount=stake_amount.get(), to=ctx.caller)
123
124 # Mint KEY token for user
125 balances[ctx.caller] += 1
126
127 # Add newly minted KEY to total supply
128 total_supply.set(total_supply.get() + 1)
129
130 # Reset staking date
131 staking[ctx.caller] = ''
132
133 return 'Unstaked and minted 1 KEY token. Payed back {} NEB'.format(int(stake_amount.get()))
134
135 @export
136 def start():
137 assert_owner()
138 staking.clear()
139 stake_start_date.set(now)
140
141 @export
142 def set_stake_start_period(minutes: int):
143 assert_owner()
144 stake_start_period.set(minutes)
145
146 @export
147 def set_stake_period(minutes: int):
148 assert_owner()
149 stake_period.set(minutes)
150
151 @export
152 def set_stake_amount(amount: float):
153 assert_owner()
154 assert amount > 0, 'Cannot set negative amount!'
155 stake_amount.set(amount)
156
157 @export
158 def set_stake_tax(percent: float):
159 assert_owner()
160 assert percent > 0 and percent < 100, 'Wrong tax value!'
161 stake_tax.set(percent)
162
163 @export
164 def time_until_unstake():
165 assert staking[ctx.caller] != '', 'Address is not staking!'
166 total_stake_time = stake_start_period.get() + stake_period.get()
167 return (stake_start_date.get() - now) + datetime.timedelta(minutes=total_stake_time)
168
169 @export
170 def enable():
171 assert_owner()
172 active.set(True)
173
174 @export
175 def disable():
176 assert_owner()
177 active.set(False)
178
179 @export
180 def emergency_withdraw(amount: float):
181 assert_owner()
182 neb.transfer(amount, ctx.caller)
183
184 @export
185 def total_supply():
186 return int(total_supply.get())
187
188 def assert_owner():
189 assert ctx.caller in OPERATORS, 'Only executable by operators!'
190

Byte Code

e3000000000000000000000000050000004000000073e0010000640064016c005a01650264026403640464058d035a03650264006403640664058d035a0465026403640764088d025a0565066403640964088d025a0765066403640a64088d025a0865066403640b64088d025a0965066403640c64088d025a0a65066403640d64088d025a0b65066403640e64088d025a0c65066403640f64088d025a0d6410641167025a0e6412641384005a0f6510640383016511651264149c0264156416840483015a136510640383016514651164179c0264186419840483015a156510640383016514651164179c02641a641b840483015a16651064038301651465116511641c9c03641d641e840483015a17651064038301641f6420840083015a1865106403830164216422840083015a1965106403830164236424840083015a1a651064038301651b64259c0164266427840483015a1c651064038301651b64259c0164286429840483015a1d6510640383016514642a9c01642b642c840483015a1e6510640383016514642d9c01642e642f840483015a1f65106403830164306431840083015a2065106403830164326433840083015a2165106403830164346435840083015a226510640383016514642a9c0164366437840483015a236510640383016438640a840083015a246439643a84005a2564015300293be9000000004eda00da11636f6e5f6e65625f6b65795f7473743132da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d65746164617461290272060000007207000000da06616374697665da0c746f74616c5f737570706c79da097374616b655f746178da0c7374616b655f616d6f756e74da107374616b655f73746172745f64617465da127374616b655f73746172745f706572696f64da0c7374616b655f706572696f64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000030000004300000073640000006401740064023c006403740064043c0074016a02740064053c0074036a0464068301010074056a0464078301010074066a0474078301010074086a0464088301010074096a04640983010100740a6a04640a83010100740b6a04640b8301010064005300290c4e7a0b4e6562756c6120544b4559da0a746f6b656e5f6e616d65da04544b4559da0c746f6b656e5f73796d626f6cda086f70657261746f72e901000000e90a000000e904000000e915000000547201000000290cda0a5f5f6d65746164617461da03637478da0663616c6c6572da0b5f5f7374616b655f746178da03736574da0e5f5f7374616b655f616d6f756e74da125f5f7374616b655f73746172745f64617465da036e6f77da145f5f7374616b655f73746172745f706572696f64da0e5f5f7374616b655f706572696f64da085f5f616374697665da0e5f5f746f74616c5f737570706c79a900722700000072270000007202000000da045f5f5f5f1400000073140000000001080108010a010a010a010a010a010a010a0172280000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e6572721b00000029027229000000722a000000722700000072270000007202000000da0f6368616e67655f6d6574616461746121000000730400000000020601722c0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000735c0000007c0064016b0473107400640283018201740174026a0319007c006b05732674006403830182017c006a04830073367400640483018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212905da0e417373657274696f6e4572726f72da0a5f5f62616c616e636573721c000000721d000000da0a69735f696e74656765722902722d000000722e000000722700000072270000007202000000da087472616e7366657227000000730a000000000210011601100112017232000000630200000000000000020000000400000043000000733a0000007c0064016b04731074006402830182017c006a01830073207400640383018201740274036a047c016602050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1a416d6f756e74206d75737420626520616e20496e7465676572212905722f00000072310000007230000000721c000000721d0000002902722d000000722e000000722700000072270000007202000000da07617070726f766530000000730600000000021001100172330000002903722d000000722e000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000739a0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b05735074006404830182017c006a0583007360740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212906722f0000007230000000721c000000721d000000da06666f726d617472310000002903722d000000722e0000007234000000722700000072270000007202000000da0d7472616e736665725f66726f6d370000007312000000000210010c010c01140114011001160110017236000000630000000000000000000000000500000043000000737800000074006a01830064016b0273147402640283018201740374046a05190064036b02732a7402640483018201740674076a01830074086a09740a6a01830064058d0117006b00734e7402640683018201740b6a0c740d6a01830074046a0e74046a0564078d030100740f74068301740374046a053c006400530029084e547a12436f6e747261637420696e6163746976652172020000007a1b4164647265737320697320616c7265616479207374616b696e67212901da076d696e757465737a1b5374616b696e6720737461727420706572696f6420656e646564212903722d000000722e000000723400000029107225000000da03676574722f000000da095f5f7374616b696e67721c000000721d00000072220000007221000000da086461746574696d65da0974696d6564656c74617223000000da036e656272360000007220000000da0474686973da037374727227000000722700000072270000007202000000da057374616b6544000000730e0000000002140116010c0118010e010a01723f000000630000000000000000040000000600000043000000733601000074006a01830064016b0273147402640283018201740374046a05190064036b03732a740264048301820174066a01830074076a01830017007d00740874096a018300740a6a0b7c0064058d0117006b0072de740c740d6a01830064061b00740e6a018300140083017d01740d6a0183007c0118007d02740f6a107c0274046a0564078d020100741164086409640a640b640c8d047d037c036a01830073b47412640a640b640d8d027d037c036a13640e83010100740f6a107c017c036a01830064078d0201006403740374046a053c00640f6a14740c7c02830183015300740f6a10740d6a01830074046a0564078d020100741574046a05050019006410370003003c0074166a1374166a01830064101700830101006403740374046a053c0064116a14740c740d6a0183008301830153006400530029124e547a12436f6e747261637420696e6163746976652172020000007a1741646472657373206973206e6f74207374616b696e672129017237000000e9640000002902722d000000722e000000da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163747203000000da057661756c742904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572060000007207000000290272060000007207000000da12494e5445524e414c5f4e45425f5641554c547a36556e7374616b6564206561726c792e204e6f204b455920746f6b656e206d696e7465642e205061796564206261636b207b7d204e454272170000007a32556e7374616b656420616e64206d696e7465642031204b455920746f6b656e2e205061796564206261636b207b7d204e4542291772250000007238000000722f0000007239000000721c000000721d0000007223000000722400000072220000007221000000723a000000723b000000da03696e747220000000721e000000723c0000007232000000da0f466f726569676e5661726961626c65da085661726961626c65721f0000007235000000723000000072260000002904da10746f74616c5f7374616b655f74696d65da03746178da067061796f7574da075f5f7661756c74722700000072270000007202000000da07756e7374616b654f000000733000000000021401160110010c010c0118010c01100104010401080108010c010a0112010a0104010a021401120112010a010601724e000000630000000000000000000000000200000043000000731c00000074008300010074016a028300010074036a047405830101006400530029014e2906722b0000007239000000da05636c6561727221000000721f00000072220000007227000000722700000072270000007202000000da0573746172746c0000007306000000000206010801725000000029017237000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007223000000721f00000029017237000000722700000072270000007202000000da167365745f7374616b655f73746172745f706572696f64730000007304000000000206017251000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007224000000721f00000029017237000000722700000072270000007202000000da107365745f7374616b655f706572696f647900000073040000000002060172520000002901722d00000063010000000000000001000000020000004300000073240000007400830001007c0064016b047316740164028301820174026a037c00830101006400530029034e72010000007a1b43616e6e6f7420736574206e6567617469766520616d6f756e74212904722b000000722f0000007220000000721f0000002901722d000000722700000072270000007202000000da107365745f7374616b655f616d6f756e747f000000730600000000020601100172530000002901da0770657263656e74630100000000000000010000000200000043000000732c0000007400830001007c0064016b0472167c0064026b00731e740164038301820174026a037c00830101006400530029044e720100000072400000007a1057726f6e67207461782076616c7565212904722b000000722f000000721e000000721f00000029017254000000722700000072270000007202000000da0d7365745f7374616b655f7461788600000073060000000002060118017255000000630000000000000000010000000400000043000000733e000000740074016a02190064016b037316740364028301820174046a05830074066a05830017007d0074076a0583007408180074096a0a7c0064038d011700530029044e72020000007a1741646472657373206973206e6f74207374616b696e672129017237000000290b7239000000721c000000721d000000722f00000072230000007238000000722400000072210000007222000000723a000000723b0000002901724a000000722700000072270000007202000000da1274696d655f756e74696c5f756e7374616b658d00000073080000000002160110010e017256000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903722b0000007225000000721f0000007227000000722700000072270000007202000000da06656e61626c65950000007304000000000206017257000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903722b0000007225000000721f0000007227000000722700000072270000007202000000da0764697361626c659b0000007304000000000206017258000000630100000000000000010000000300000043000000731800000074008300010074016a027c0074036a04830201006400530029014e2905722b000000723c0000007232000000721c000000721d0000002901722d000000722700000072270000007202000000da12656d657267656e63795f7769746864726177a10000007304000000000206017259000000630000000000000000000000000200000043000000730c000000740074016a0283008301530029014e29037247000000722600000072380000007227000000722700000072270000007202000000720b000000a700000073020000000002630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904721c000000721d000000da094f50455241544f5253722f0000007227000000722700000072270000007202000000722b000000ac00000073020000000001722b00000029267241000000723c000000da044861736872390000007230000000721b000000724900000072250000007226000000721e0000007220000000722100000072230000007224000000725a0000007228000000da085f5f6578706f7274723e000000da03416e79722c000000da05666c6f6174723200000072330000007236000000723f000000724e0000007250000000724700000072510000007252000000725300000072550000007256000000725700000072580000007259000000720b000000722b0000007227000000722700000072270000007202000000da083c6d6f64756c653e01000000735400000008010e02060108010c010c010c010c010c0104010801040108010c0102010603080d0601120506011208060112060601140c100b101d100706011005060110050601100606011006100810061006060110051005