Contract con_neb_key_tst09


Contract Code

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

Byte Code

e3000000000000000000000000050000004000000073e0010000640064016c005a01650264026403640464058d035a03650264006403640664058d035a0465026403640764088d025a0565066403640964088d025a0765066403640a64088d025a0865066403640b64088d025a0965066403640c64088d025a0a65066403640d64088d025a0b65066403640e64088d025a0c65066403640f64088d025a0d6410641167025a0e6412641384005a0f6510640383016511651264149c0264156416840483015a136510640383016514651164179c0264186419840483015a156510640383016514651164179c02641a641b840483015a16651064038301651465116511641c9c03641d641e840483015a17651064038301641f6420840083015a1865106403830164216422840083015a1965106403830164236424840083015a1a651064038301651b64259c0164266427840483015a1c651064038301651b64259c0164286429840483015a1d6510640383016514642a9c01642b642c840483015a1e6510640383016514642d9c01642e642f840483015a1f65106403830164306431840083015a2065106403830164326433840083015a2165106403830164346435840083015a226510640383016514642a9c0164366437840483015a236510640383016438640a840083015a246439643a84005a2564015300293be9000000004eda00da11636f6e5f6e65625f6b65795f7473743039da077374616b696e672903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d65746164617461290272060000007207000000da06616374697665da0c746f74616c5f737570706c79da097374616b655f746178da0c7374616b655f616d6f756e74da107374616b655f73746172745f64617465da127374616b655f73746172745f706572696f64da0c7374616b655f706572696f64da4061653764313464366439623834343366383831626136323434373237623639623638313031306537383264346665343832646266623062366163613032643564da406537383765643539303737343266613864353062336361323730316162386530336563373439636564383036613135636461623830306131323764376638363363000000000000000000000000030000004300000073640000006401740064023c006403740064043c0074016a02740064053c0074036a0464068301010074056a0464078301010074066a0474078301010074086a0464088301010074096a04640983010100740a6a04640a83010100740b6a04640b8301010064005300290c4e7a0b4e6562756c6120544b4559da0a746f6b656e5f6e616d65da04544b4559da0c746f6b656e5f73796d626f6cda086f70657261746f72e901000000e90a000000e904000000e915000000547201000000290cda0a5f5f6d65746164617461da03637478da0663616c6c6572da0b5f5f7374616b655f746178da03736574da0e5f5f7374616b655f616d6f756e74da125f5f7374616b655f73746172745f64617465da036e6f77da145f5f7374616b655f73746172745f706572696f64da0e5f5f7374616b655f706572696f64da085f5f616374697665da0e5f5f746f74616c5f737570706c79a900722700000072270000007202000000da045f5f5f5f1400000073140000000001080108010a010a010a010a010a010a010a0172280000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e6572721b00000029027229000000722a000000722700000072270000007202000000da0f6368616e67655f6d6574616461746121000000730400000000020601722c0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000735e0000007c0064016b0473107400640283018201740174026a0319007c006b057326740064038301820174047c007405830273387400640483018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212906da0e417373657274696f6e4572726f72da0a5f5f62616c616e636573721c000000721d000000da0a6973696e7374616e6365da03696e742902722d000000722e000000722700000072270000007202000000da087472616e7366657227000000730a000000000210011601120112017233000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573212904722f0000007230000000721c000000721d0000002902722d000000722e000000722700000072270000007202000000da07617070726f76653000000073040000000002100172340000002903722d000000722e000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000739c0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174057c00740683027362740064058301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029064e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e64217a1a416d6f756e74206d75737420626520616e20496e7465676572212907722f0000007230000000721c000000721d000000da06666f726d6174723100000072320000002903722d000000722e0000007235000000722700000072270000007202000000da0d7472616e736665725f66726f6d360000007312000000000210010c010c01140114011201160110017237000000630000000000000000000000000500000043000000737800000074006a01830064016b0273147402640283018201740374046a05190064036b02732a7402640483018201740674076a01830074086a09740a6a01830064058d0117006b00734e7402640683018201740b6a0c740d6a01830074046a0e74046a0564078d030100740f74068301740374046a053c006400530029084e547a12436f6e747261637420696e6163746976652172020000007a1b4164647265737320697320616c7265616479207374616b696e67212901da076d696e757465737a1b5374616b696e6720737461727420706572696f6420656e646564212903722d000000722e000000723500000029107225000000da03676574722f000000da095f5f7374616b696e67721c000000721d00000072220000007221000000da086461746574696d65da0974696d6564656c74617223000000da036e656272370000007220000000da0474686973da037374727227000000722700000072270000007202000000da057374616b6543000000730e0000000002140116010c0118010e010a017240000000630000000000000000040000000600000043000000733601000074006a01830064016b0273147402640283018201740374046a05190064036b03732a740264048301820174066a01830074076a01830017007d00740874096a018300740a6a0b7c0064058d0117006b0072de740c740d6a01830064061b00740e6a018300140083017d01740d6a0183007c0118007d02740f6a107c0274046a0564078d020100741164086409640a640b640c8d047d037c036a01830073b47412640a640b640d8d027d037c036a13640e83010100740f6a107c017c036a01830064078d0201006403740374046a053c00640f6a14740c7c02830183015300740f6a10740d6a01830074046a0564078d020100741574046a05050019006410370003003c0074166a1374166a01830064101700830101006403740374046a053c0064116a14740c740d6a0183008301830153006400530029124e547a12436f6e747261637420696e6163746976652172020000007a1741646472657373206973206e6f74207374616b696e672129017238000000e9640000002902722d000000722e000000da0a636f6e5f6e6562756c61da0e7661756c745f636f6e74726163747203000000da057661756c742904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572060000007207000000290272060000007207000000da12494e5445524e414c5f4e45425f5641554c547a36556e7374616b6564206561726c792e204e6f204b455920746f6b656e206d696e7465642e205061796564206261636b207b7d204e454272170000007a32556e7374616b656420616e64206d696e7465642031204b455920746f6b656e2e205061796564206261636b207b7d204e4542291772250000007239000000722f000000723a000000721c000000721d0000007223000000722400000072220000007221000000723b000000723c00000072320000007220000000721e000000723d0000007233000000da0f466f726569676e5661726961626c65da085661726961626c65721f0000007236000000723000000072260000002904da10746f74616c5f7374616b655f74696d65da03746178da067061796f7574da075f5f7661756c74722700000072270000007202000000da07756e7374616b654e000000733000000000021401160110010c010c0118010c01100104010401080108010c010a0112010a0104010a021401120112010a010601724e000000630000000000000000000000000200000043000000731c00000074008300010074016a028300010074036a047405830101006400530029014e2906722b000000723a000000da05636c6561727221000000721f00000072220000007227000000722700000072270000007202000000da0573746172746b0000007306000000000206010801725000000029017238000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007223000000721f00000029017238000000722700000072270000007202000000da167365745f7374616b655f73746172745f706572696f64720000007304000000000206017251000000630100000000000000010000000200000043000000731400000074008300010074016a027c00830101006400530029014e2903722b0000007224000000721f00000029017238000000722700000072270000007202000000da107365745f7374616b655f706572696f647800000073040000000002060172520000002901722d00000063010000000000000001000000020000004300000073240000007400830001007c0064016b047316740164028301820174026a037c00830101006400530029034e72010000007a1b43616e6e6f7420736574206e6567617469766520616d6f756e74212904722b000000722f0000007220000000721f0000002901722d000000722700000072270000007202000000da107365745f7374616b655f616d6f756e747e000000730600000000020601100172530000002901da0770657263656e74630100000000000000010000000200000043000000732c0000007400830001007c0064016b0472167c0064026b00731e740164038301820174026a037c00830101006400530029044e720100000072410000007a1057726f6e67207461782076616c7565212904722b000000722f000000721e000000721f00000029017254000000722700000072270000007202000000da0d7365745f7374616b655f7461788500000073060000000002060118017255000000630000000000000000010000000400000043000000733e000000740074016a02190064016b037316740364028301820174046a05830074066a05830017007d0074076a0583007408180074096a0a7c0064038d011700530029044e72020000007a1741646472657373206973206e6f74207374616b696e672129017238000000290b723a000000721c000000721d000000722f00000072230000007239000000722400000072210000007222000000723b000000723c0000002901724a000000722700000072270000007202000000da1274696d655f756e74696c5f756e7374616b658c00000073080000000002160110010e017256000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e542903722b0000007225000000721f0000007227000000722700000072270000007202000000da06656e61626c65940000007304000000000206017257000000630000000000000000000000000200000043000000731400000074008300010074016a026401830101006400530029024e462903722b0000007225000000721f0000007227000000722700000072270000007202000000da0764697361626c659a0000007304000000000206017258000000630100000000000000010000000300000043000000731800000074008300010074016a027c0074036a04830201006400530029014e2905722b000000723d0000007233000000721c000000721d0000002901722d000000722700000072270000007202000000da12656d657267656e63795f7769746864726177a00000007304000000000206017259000000630000000000000000000000000200000043000000730c000000740074016a0283008301530029014e29037232000000722600000072390000007227000000722700000072270000007202000000720b000000a600000073020000000002630000000000000000000000000200000043000000731600000074006a0174026b06731274036401830182016400530029024e7a1d4f6e6c792065786563757461626c65206279206f70657261746f7273212904721c000000721d000000da094f50455241544f5253722f0000007227000000722700000072270000007202000000722b000000ab00000073020000000001722b00000029267242000000723d000000da0448617368723a0000007230000000721b000000724900000072250000007226000000721e0000007220000000722100000072230000007224000000725a0000007228000000da085f5f6578706f7274723f000000da03416e79722c000000da05666c6f61747233000000723400000072370000007240000000724e0000007250000000723200000072510000007252000000725300000072550000007256000000725700000072580000007259000000720b000000722b0000007227000000722700000072270000007202000000da083c6d6f64756c653e01000000735400000008010e02060108010c010c010c010c010c0104010801040108010c0102010603080d0601120506011208060112050601140c100b101d100706011005060110050601100606011006100810061006060110051005