Contract con_neb_key


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

Byte Code

e3000000000000000000000000050000004000000073ee010000640064016c005a01650264026403640464058d035a03650264006403640664058d035a0465026403640764088d025a0565066403640964088d025a0765066403640a64088d025a0865066403640b64088d025a0965066403640c64088d025a0a65066403640d64088d025a0b65066403640e64088d025a0c65066403640f64088d025a0d6410641167025a0e6412641384005a0f6510640383016511651264149c0264156416840483015a136510640383016514651164179c0264186419840483015a156510640383016514651164179c02641a641b840483015a16651064038301651465116511641c9c03641d641e840483015a176514641f9c016420642184045a1865106403830164226423840083015a1965106403830164246425840083015a1a65106403830164266427840083015a1b651064038301651c64289c016429642a840483015a1d651064038301651c64289c01642b642c840483015a1e6510640383016514641f9c01642d642e840483015a1f6510640383016514642f9c0164306431840483015a2065106403830164326433840083015a2165106403830164346435840083015a2265106403830164366437840083015a236510640383016514641f9c0164386439840483015a24651064038301643a640a840083015a25643b643c84005a2664015300293de9000000004eda00da0b636f6e5f6e65625f6b6579da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d65746164617461290272060000007207000000da06616374697665da0c746f74616c5f737570706c79da097374616b655f746178da0c7374616b655f616d6f756e74da107374616b655f73746172745f64617465da127374616b655f73746172745f706572696f64da0c7374616b655f706572696f64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000030000004300000073640000006401740064023c006403740064043c0074016a02740064053c0074036a0464068301010074056a0464078301010074066a0474078301010074086a0464088301010074096a04640983010100740a6a04640a83010100740b6a04640b8301010064005300290c4e7a0a4e6562756c61204b4559da0a746f6b656e5f6e616d65da034b4559da0c746f6b656e5f73796d626f6cda086f70657261746f72e9010000006940420f00e904000000e915000000467201000000290cda0a5f5f6d65746164617461da03637478da0663616c6c6572da0b5f5f7374616b655f746178da03736574da0e5f5f7374616b655f616d6f756e74da125f5f7374616b655f73746172745f64617465da036e6f77da145f5f7374616b655f73746172745f706572696f64da0e5f5f7374616b655f706572696f64da085f5f616374697665da0e5f5f746f74616c5f737570706c79a900722600000072260000007202000000da045f5f5f5f1100000073140000000001080108010a010a010a010a010a010a010a0172270000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e6572721a000000290272280000007229000000722600000072260000007202000000da0f6368616e67655f6d657461646174611e000000730400000000020601722b0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000735c0000007c0064016b0473107400640283018201740174026a0319007c006b057326740064038301820174047c00830173367400640483018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212905da0e417373657274696f6e4572726f72da0a5f5f62616c616e636573721b000000721c000000da085f5f69735f696e742902722c000000722d000000722600000072260000007202000000da087472616e7366657224000000730a000000000210011601100112017231000000630200000000000000020000000400000043000000733a0000007c0064016b047310740064028301820174017c00830173207400640383018201740274036a047c016602050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1a416d6f756e74206d75737420626520616e20496e7465676572212905722e0000007230000000722f000000721b000000721c0000002902722c000000722d000000722600000072260000007202000000da07617070726f76652d000000730600000000021001100172320000002903722c000000722d000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000739a0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174057c0083017360740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212906722e000000722f000000721b000000721c000000da06666f726d617472300000002903722c000000722d0000007233000000722600000072260000007202000000da0d7472616e736665725f66726f6d340000007312000000000210010c010c011401140110011601100172350000002901722c000000630100000000000000020000000200000043000000731000000074007c0083017d017c017c006b02530029014e2901da03696e742902722c000000da0a696e745f616d6f756e747226000000722600000072020000007230000000410000007304000000000108017230000000630000000000000000000000000500000043000000737800000074006a01830064016b0273147402640283018201740374046a05190064036b02732a7402640483018201740674076a01830074086a09740a6a01830064058d0117006b00734e7402640683018201740b6a0c740d6a01830074046a0e74046a0564078d030100740f74068301740374046a053c006400530029084e547a12436f6e747261637420696e6163746976652172020000007a1b4164647265737320697320616c7265616479207374616b696e67212901da04646179737a1b5374616b696e6720737461727420706572696f6420656e646564212903722c000000722d000000723300000029107224000000da03676574722e000000da095f5f7374616b696e67721b000000721c00000072210000007220000000da086461746574696d65da0974696d6564656c74617222000000da036e65627235000000721f000000da0474686973da037374727226000000722600000072260000007202000000da057374616b6546000000730e0000000002140116010c0118010e010a017240000000630000000000000000040000000600000043000000733601000074006a01830064016b0273147402640283018201740374046a05190064036b03732a740264048301820174066a01830074076a01830017007d00740874096a018300740a6a0b7c0064058d0117006b0072de740c740d6a01830064061b00740e6a018300140083017d01740d6a0183007c0118007d02740f6a107c0274046a0564078d020100741164086409640a640b640c8d047d037c036a01830073b47412640a640b640d8d027d037c036a13640e83010100740f6a107c017c036a01830064078d0201006403740374046a053c00640f6a14740c7c02830183015300740f6a10740d6a01830074046a0564078d020100741574046a05050019006410370003003c0074166a1374166a01830064101700830101006403740374046a053c0064116a14740c740d6a0183008301830153006400530029124e547a12436f6e747261637420696e6163746976652172020000007a1741646472657373206973206e6f74207374616b696e672129017238000000e9640000002902722c000000722d000000da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163747203000000da057661756c742904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572060000007207000000290272060000007207000000da12494e5445524e414c5f4e45425f5641554c547a36556e7374616b6564206561726c792e204e6f204b455920746f6b656e206d696e7465642e205061796564206261636b207b7d204e454272170000007a32556e7374616b656420616e64206d696e7465642031204b455920746f6b656e2e205061796564206261636b207b7d204e4542291772240000007239000000722e000000723a000000721b000000721c0000007222000000722300000072210000007220000000723b000000723c0000007236000000721f000000721d000000723d0000007231000000da0f466f726569676e5661726961626c65da085661726961626c65721e0000007234000000722f00000072250000002904da10746f74616c5f7374616b655f74696d65da03746178da067061796f7574da075f5f7661756c74722600000072260000007202000000da07756e7374616b6551000000732e00000000021401160110010c010c0118010c01100104010c0208010c010a0112010a0104010a021401120112010a010601724e000000630000000000000000000000000200000043000000731c00000074008300010074016a028300010074036a047405830101006400530029014e2906722a000000723a000000da05636c6561727220000000721e00000072210000007226000000722600000072260000007202000000da0573746172746e0000007306000000000206010801725000000029017238000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722a0000007222000000721e00000029017238000000722600000072260000007202000000da167365745f7374616b655f73746172745f706572696f64750000007304000000000206017251000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722a0000007223000000721e00000029017238000000722600000072260000007202000000da107365745f7374616b655f706572696f647b000000730400000000020601725200000063010000000000000001000000020000004300000073240000007400830001007c0064016b047316740164028301820174026a037c00830101006400530029034e72010000007a1b43616e6e6f7420736574206e6567617469766520616d6f756e74212904722a000000722e000000721f000000721e0000002901722c000000722600000072260000007202000000da107365745f7374616b655f616d6f756e7481000000730600000000020601100172530000002901da0770657263656e74630100000000000000010000000200000043000000732c0000007400830001007c0064016b0472167c0064026b00731e740164038301820174026a037c00830101006400530029044e720100000072410000007a1057726f6e67207461782076616c7565212904722a000000722e000000721d000000721e00000029017254000000722600000072260000007202000000da0d7365745f7374616b655f7461788800000073060000000002060118017255000000630000000000000000010000000400000043000000733e000000740074016a02190064016b037316740364028301820174046a05830074066a05830017007d0074076a0583007408180074096a0a7c0064038d011700530029044e72020000007a1741646472657373206973206e6f74207374616b696e672129017238000000290b723a000000721b000000721c000000722e00000072220000007239000000722300000072200000007221000000723b000000723c0000002901724a000000722600000072260000007202000000da1274696d655f756e74696c5f756e7374616b658f00000073080000000002160110010e017256000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903722a0000007224000000721e0000007226000000722600000072260000007202000000da06656e61626c65970000007304000000000206017257000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903722a0000007224000000721e0000007226000000722600000072260000007202000000da0764697361626c659d0000007304000000000206017258000000630100000000000000010000000300000043000000731800000074008300010074016a027c0074036a04830201006400530029014e2905722a000000723d0000007231000000721b000000721c0000002901722c000000722600000072260000007202000000da12656d657267656e63795f7769746864726177a30000007304000000000206017259000000630000000000000000000000000200000043000000730c000000740074016a0283008301530029014e29037236000000722500000072390000007226000000722600000072260000007202000000720b000000a900000073020000000002630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904721b000000721c000000da094f50455241544f5253722e0000007226000000722600000072260000007202000000722a000000ae00000073020000000001722a00000029277242000000723d000000da0448617368723a000000722f000000721a000000724900000072240000007225000000721d000000721f000000722000000072220000007223000000725a0000007227000000da085f5f6578706f7274723f000000da03416e79722b000000da05666c6f617472310000007232000000723500000072300000007240000000724e0000007250000000723600000072510000007252000000725300000072550000007256000000725700000072580000007259000000720b000000722a0000007226000000722600000072260000007202000000da083c6d6f64756c653e01000000735200000008010e010e010c010c010c010c010c010c01040108010c0102010603080d0601120506011208060112060601140c0e05100b101d100706011005060110050601100606011006100810061006060110051005