2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let managementAddress = base58'3My61WhRb1HXJdhjbwkGx66hQQyQN8XZ31d' |
---|
5 | | - | |
---|
6 | | - | let coldVault = extract(addressFromString("3MxuiJsRszpfZBJLHioGA3mhwdvMNtfjyCA")) |
---|
7 | | - | |
---|
8 | | - | let token = base58'G4TXfW45zGD3SQBq1vuhM9iw1zun3w32WquiYHkJUuMa' |
---|
9 | | - | |
---|
10 | | - | let tokenRate = 1000 |
---|
11 | | - | |
---|
12 | | - | let tokenDecimalsOffset = pow(10, 0, 8, 0, 0, Up()) |
---|
13 | | - | |
---|
14 | | - | let hardCapTokens = 1000000000000 |
---|
15 | | - | |
---|
16 | | - | let minInvestmentWaves = 10 |
---|
17 | | - | |
---|
18 | | - | let maxInvestmentWaves = 10000000000000000 |
---|
19 | | - | |
---|
20 | | - | let startTime = 1563271860 |
---|
21 | | - | |
---|
22 | | - | let endTime = 1609395060 |
---|
23 | | - | |
---|
24 | | - | let wavesDecimals = pow(10, 0, 8, 0, 0, Up()) |
---|
25 | | - | |
---|
26 | | - | func onlyManager (callerBytes) = { |
---|
27 | | - | let caller = toBase58String(callerBytes) |
---|
28 | | - | let managementAddressString = toBase58String(managementAddress) |
---|
29 | | - | if ((caller != managementAddressString)) |
---|
30 | | - | then false |
---|
31 | | - | else true |
---|
32 | | - | } |
---|
33 | | - | |
---|
34 | | - | |
---|
35 | | - | func getStartTime () = { |
---|
36 | | - | let dataStartTime = getInteger(this, "startTime") |
---|
37 | | - | match dataStartTime { |
---|
38 | | - | case changedStartTime: Int => |
---|
39 | | - | changedStartTime |
---|
40 | | - | case notChanged: Unit => |
---|
41 | | - | startTime |
---|
42 | | - | case _ => |
---|
43 | | - | throw() |
---|
44 | | - | } |
---|
45 | | - | } |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func getEndTime () = { |
---|
49 | | - | let dataEndTime = getInteger(this, "endTime") |
---|
50 | | - | match dataEndTime { |
---|
51 | | - | case changedEndTime: Int => |
---|
52 | | - | changedEndTime |
---|
53 | | - | case notChanged: Unit => |
---|
54 | | - | endTime |
---|
55 | | - | case _ => |
---|
56 | | - | throw() |
---|
57 | | - | } |
---|
58 | | - | } |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func hasStarted () = { |
---|
62 | | - | let dataStartTime = getInteger(this, "startTime") |
---|
63 | | - | let stoStartTime = getStartTime() |
---|
64 | | - | let blockInfo = value(blockInfoByHeight(height)) |
---|
65 | | - | let timeNow = blockInfo.timestamp |
---|
66 | | - | if ((timeNow > stoStartTime)) |
---|
67 | | - | then true |
---|
68 | | - | else false |
---|
69 | | - | } |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func hasEnded () = { |
---|
73 | | - | let dataEndTime = getInteger(this, "endTime") |
---|
74 | | - | let stoEndTime = getEndTime() |
---|
75 | | - | let blockInfo = value(blockInfoByHeight(height)) |
---|
76 | | - | let timeNow = blockInfo.timestamp |
---|
77 | | - | if ((timeNow > stoEndTime)) |
---|
78 | | - | then true |
---|
79 | | - | else false |
---|
80 | | - | } |
---|
81 | | - | |
---|
82 | | - | |
---|
83 | | - | func hasFinished () = { |
---|
84 | | - | let isFinalized = getBoolean(this, "finalized") |
---|
85 | | - | match isFinalized { |
---|
86 | | - | case dataFinalized: Boolean => |
---|
87 | | - | dataFinalized |
---|
88 | | - | case notFinalized: Unit => |
---|
89 | | - | false |
---|
90 | | - | case _ => |
---|
91 | | - | throw() |
---|
92 | | - | } |
---|
93 | | - | } |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func getWavesRaised () = { |
---|
97 | | - | let wavesRaised = getInteger(this, "wavesRaised") |
---|
98 | | - | match wavesRaised { |
---|
99 | | - | case waves: Int => |
---|
100 | | - | waves |
---|
101 | | - | case emptyState: Unit => |
---|
102 | | - | 0 |
---|
103 | | - | case _ => |
---|
104 | | - | throw() |
---|
105 | | - | } |
---|
106 | | - | } |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | func checkInvestorInPage (address,page) = { |
---|
110 | | - | let whitelistPageKey = ("whitelistedInvestors-" + toString(page)) |
---|
111 | | - | let whitelistPage = getString(this, whitelistPageKey) |
---|
112 | | - | match whitelistPage { |
---|
113 | | - | case pageString: String => |
---|
114 | | - | let addressPosition = indexOf(pageString, address) |
---|
115 | | - | match addressPosition { |
---|
116 | | - | case pos: Int => |
---|
117 | | - | true |
---|
118 | | - | case empty: Unit => |
---|
119 | | - | false |
---|
120 | | - | case _ => |
---|
121 | | - | throw() |
---|
122 | | - | } |
---|
123 | | - | case emptyPage: Unit => |
---|
124 | | - | false |
---|
125 | | - | case _ => |
---|
126 | | - | throw() |
---|
127 | | - | } |
---|
128 | | - | } |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | func checkInvestorInAllPages (address) = if (checkInvestorInPage(address, 0)) |
---|
132 | | - | then true |
---|
133 | | - | else if (checkInvestorInPage(address, 1)) |
---|
134 | | - | then true |
---|
135 | | - | else if (checkInvestorInPage(address, 2)) |
---|
136 | | - | then true |
---|
137 | | - | else if (checkInvestorInPage(address, 3)) |
---|
138 | | - | then true |
---|
139 | | - | else if (checkInvestorInPage(address, 4)) |
---|
140 | | - | then true |
---|
141 | | - | else if (checkInvestorInPage(address, 5)) |
---|
142 | | - | then true |
---|
143 | | - | else if (checkInvestorInPage(address, 6)) |
---|
144 | | - | then true |
---|
145 | | - | else if (checkInvestorInPage(address, 7)) |
---|
146 | | - | then true |
---|
147 | | - | else if (checkInvestorInPage(address, 8)) |
---|
148 | | - | then true |
---|
149 | | - | else if (checkInvestorInPage(address, 9)) |
---|
150 | | - | then true |
---|
151 | | - | else false |
---|
152 | | - | |
---|
153 | | - | |
---|
154 | | - | func getMinInvestment () = { |
---|
155 | | - | let dataMinInvestment = getInteger(this, "minInvestment") |
---|
156 | | - | match dataMinInvestment { |
---|
157 | | - | case changedMinInvestment: Int => |
---|
158 | | - | changedMinInvestment |
---|
159 | | - | case notChanged: Unit => |
---|
160 | | - | minInvestmentWaves |
---|
161 | | - | case _ => |
---|
162 | | - | throw() |
---|
163 | | - | } |
---|
164 | | - | } |
---|
165 | | - | |
---|
166 | | - | |
---|
167 | | - | func getMaxInvestment () = { |
---|
168 | | - | let dataMaxInvestment = getInteger(this, "maxInvestment") |
---|
169 | | - | match dataMaxInvestment { |
---|
170 | | - | case changedMaxInvestment: Int => |
---|
171 | | - | changedMaxInvestment |
---|
172 | | - | case notChanged: Unit => |
---|
173 | | - | maxInvestmentWaves |
---|
174 | | - | case _ => |
---|
175 | | - | throw() |
---|
176 | | - | } |
---|
177 | | - | } |
---|
178 | | - | |
---|
179 | | - | |
---|
180 | | - | @Callable(i) |
---|
181 | | - | func buyTokens () = { |
---|
182 | | - | let investorAddress = toBase58String(i.caller.bytes) |
---|
183 | | - | if (!(checkInvestorInAllPages(investorAddress))) |
---|
184 | | - | then throw("Only for whitelisted") |
---|
185 | | - | else { |
---|
186 | | - | let sendedAmount = extract(i.payment).amount |
---|
187 | | - | if ((0 >= sendedAmount)) |
---|
188 | | - | then throw("Cannot accept zero value payments") |
---|
189 | | - | else if ((getMinInvestment() > sendedAmount)) |
---|
190 | | - | then throw("Attached payment is below minimal price") |
---|
191 | | - | else if ((sendedAmount > getMaxInvestment())) |
---|
192 | | - | then throw("Attached payment is above maximum price") |
---|
193 | | - | else if (!(hasStarted())) |
---|
194 | | - | then throw("STO time is not started yet") |
---|
195 | | - | else if (hasEnded()) |
---|
196 | | - | then throw("STO time is already ended") |
---|
197 | | - | else if (hasFinished()) |
---|
198 | | - | then throw("STO is finalized") |
---|
199 | | - | else { |
---|
200 | | - | let wavesRaised = getWavesRaised() |
---|
201 | | - | let wavesOffset = (wavesDecimals / tokenDecimalsOffset) |
---|
202 | | - | let hardCapWaves = ((hardCapTokens / tokenRate) * wavesOffset) |
---|
203 | | - | let updatedWavesRaised = (wavesRaised + sendedAmount) |
---|
204 | | - | if ((updatedWavesRaised > hardCapWaves)) |
---|
205 | | - | then throw("Attached payment overflows hardcap") |
---|
206 | | - | else { |
---|
207 | | - | let tokenAmountRaw = (sendedAmount * tokenRate) |
---|
208 | | - | if ((wavesOffset > tokenAmountRaw)) |
---|
209 | | - | then throw("Attached payment is too low to buy unit of token") |
---|
210 | | - | else { |
---|
211 | | - | let tokenAmount = (tokenAmountRaw / wavesOffset) |
---|
212 | | - | ScriptResult(WriteSet([DataEntry("wavesRaised", updatedWavesRaised)]), TransferSet([ScriptTransfer(coldVault, sendedAmount, unit), ScriptTransfer(i.caller, tokenAmount, token)])) |
---|
213 | | - | } |
---|
214 | | - | } |
---|
215 | | - | } |
---|
216 | | - | } |
---|
217 | | - | } |
---|
218 | | - | |
---|
219 | | - | |
---|
220 | | - | |
---|
221 | | - | @Callable(i) |
---|
222 | | - | func finalize () = if (!(onlyManager(i.caller.bytes))) |
---|
223 | | - | then throw("Only for administration") |
---|
224 | | - | else if (hasFinished()) |
---|
225 | | - | then throw("Already finalized") |
---|
226 | | - | else if (hasEnded()) |
---|
227 | | - | then WriteSet([DataEntry("finalized", true)]) |
---|
228 | | - | else throw("STO not finished yet") |
---|
229 | | - | |
---|
230 | | - | |
---|
231 | | - | |
---|
232 | | - | @Callable(i) |
---|
233 | | - | func setStartTime (newStartTime) = if (!(onlyManager(i.caller.bytes))) |
---|
234 | | - | then throw("Only for administration") |
---|
235 | | - | else { |
---|
236 | | - | let currentEndTime = getEndTime() |
---|
237 | | - | if ((newStartTime > currentEndTime)) |
---|
238 | | - | then throw("Start date must be lower than end date") |
---|
239 | | - | else WriteSet([DataEntry("startTime", newStartTime)]) |
---|
240 | | - | } |
---|
241 | | - | |
---|
242 | | - | |
---|
243 | | - | |
---|
244 | | - | @Callable(i) |
---|
245 | | - | func setEndTime (newEndTime) = if (!(onlyManager(i.caller.bytes))) |
---|
246 | | - | then throw("Only for administration") |
---|
247 | | - | else { |
---|
248 | | - | let currentStartTime = getStartTime() |
---|
249 | | - | if ((newEndTime > currentStartTime)) |
---|
250 | | - | then throw("End date must be higher than start date") |
---|
251 | | - | else WriteSet([DataEntry("endTime", newEndTime)]) |
---|
252 | | - | } |
---|
253 | | - | |
---|
254 | | - | |
---|
255 | | - | |
---|
256 | | - | @Callable(i) |
---|
257 | | - | func setStartAndEndTimes (newStartTime,newEndTime) = if (!(onlyManager(i.caller.bytes))) |
---|
258 | | - | then throw("Only for administration") |
---|
259 | | - | else { |
---|
260 | | - | let blockInfo = value(blockInfoByHeight(height)) |
---|
261 | | - | let timeNow = blockInfo.timestamp |
---|
262 | | - | if ((timeNow >= newEndTime)) |
---|
263 | | - | then throw("Cannot set time to past") |
---|
264 | | - | else WriteSet([DataEntry("startTime", newStartTime), DataEntry("endTime", newEndTime)]) |
---|
265 | | - | } |
---|
266 | | - | |
---|
267 | | - | |
---|
268 | | - | |
---|
269 | | - | @Callable(i) |
---|
270 | | - | func setMinInvestment (newValue) = if (!(onlyManager(i.caller.bytes))) |
---|
271 | | - | then throw("Only for administration") |
---|
272 | | - | else WriteSet([DataEntry("minInvestment", newValue)]) |
---|
273 | | - | |
---|
274 | | - | |
---|
275 | | - | |
---|
276 | | - | @Callable(i) |
---|
277 | | - | func setMaxInvestment (newValue) = if (!(onlyManager(i.caller.bytes))) |
---|
278 | | - | then throw("Only for administration") |
---|
279 | | - | else WriteSet([DataEntry("maxInvestment", newValue)]) |
---|
280 | | - | |
---|
281 | | - | |
---|
282 | | - | |
---|
283 | | - | @Callable(i) |
---|
284 | | - | func setWhitelistAddresses (investors) = if (!(onlyManager(i.caller.bytes))) |
---|
285 | | - | then throw("Only for administration") |
---|
286 | | - | else { |
---|
287 | | - | let splittedWhitelist = split(investors, ",") |
---|
288 | | - | let newWhitelistSize = size(splittedWhitelist) |
---|
289 | | - | let whitelistDataPrefix = "whitelistedInvestors" |
---|
290 | | - | let totalInvestorsKey = "totalInvestors" |
---|
291 | | - | let currentPageNumKey = "currentWhitelistPage" |
---|
292 | | - | let currentPageSizeKey = "currentWhitelistPageSize" |
---|
293 | | - | let currentWhitelistSize = getInteger(this, totalInvestorsKey) |
---|
294 | | - | match currentWhitelistSize { |
---|
295 | | - | case currentInvestorsSize: Int => |
---|
296 | | - | let currentPageNum = getIntegerValue(this, currentPageNumKey) |
---|
297 | | - | let currentPageSize = getIntegerValue(this, currentPageSizeKey) |
---|
298 | | - | let currentWhitelistKey = ((whitelistDataPrefix + "-") + toString(currentPageNum)) |
---|
299 | | - | let currentWhitelistData = getStringValue(this, currentWhitelistKey) |
---|
300 | | - | let remainingPageSize = (100 - currentPageSize) |
---|
301 | | - | if (if ((remainingPageSize >= newWhitelistSize)) |
---|
302 | | - | then (remainingPageSize > 0) |
---|
303 | | - | else false) |
---|
304 | | - | then { |
---|
305 | | - | let updatedCurrentPageList = ((currentWhitelistData + ",") + investors) |
---|
306 | | - | let updatedPageSize = (currentPageSize + newWhitelistSize) |
---|
307 | | - | let newInvestorsSize = (currentInvestorsSize + newWhitelistSize) |
---|
308 | | - | WriteSet([DataEntry(totalInvestorsKey, newInvestorsSize), DataEntry(currentPageSizeKey, updatedPageSize), DataEntry(currentWhitelistKey, updatedCurrentPageList)]) |
---|
309 | | - | } |
---|
310 | | - | else { |
---|
311 | | - | let newPageNum = (currentPageNum + 1) |
---|
312 | | - | let newInvestorsSize = (currentInvestorsSize + newWhitelistSize) |
---|
313 | | - | let newPageSize = newWhitelistSize |
---|
314 | | - | let newWhitelistKey = ((whitelistDataPrefix + "-") + toString(newPageNum)) |
---|
315 | | - | WriteSet([DataEntry(totalInvestorsKey, newInvestorsSize), DataEntry(currentPageNumKey, newPageNum), DataEntry(currentPageSizeKey, newPageSize), DataEntry(newWhitelistKey, investors)]) |
---|
316 | | - | } |
---|
317 | | - | case emptyWhitelist: Unit => |
---|
318 | | - | let initPageNum = 0 |
---|
319 | | - | let firstPageKey = ((whitelistDataPrefix + "-") + toString(initPageNum)) |
---|
320 | | - | WriteSet([DataEntry(totalInvestorsKey, newWhitelistSize), DataEntry(currentPageNumKey, initPageNum), DataEntry(currentPageSizeKey, newWhitelistSize), DataEntry(firstPageKey, investors)]) |
---|
321 | | - | case _ => |
---|
322 | | - | throw() |
---|
323 | | - | } |
---|
324 | | - | } |
---|
325 | | - | |
---|
326 | | - | |
---|
327 | | - | @Verifier(tx) |
---|
328 | | - | func verify () = true |
---|
329 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|