42 | | - | |
---|
43 | | - | func p () = makeString(["%s", "factory"], a) |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func q () = makeString(["%s", "managerPublicKey"], a) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func r () = makeString(["%s", "lpAssetId"], a) |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | func s () = makeString(["%s", "proxyTreasury"], a) |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func t () = makeString(["%s", "mainTreasury"], a) |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | func u () = makeString(["%s", "businessTreasury"], a) |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func v () = makeString(["%s", "businessTreasuryPart"], a) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func w (j) = makeString(["%s%s", "invested", i(j)], a) |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func x (j) = makeString(["%s%s", "donated", i(j)], a) |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | func y (z) = makeString(["%s%s", "available", toString(z)], a) |
---|
71 | | - | |
---|
72 | | - | |
---|
73 | | - | func A (z) = makeString(["%s%s", "claimed", toString(z)], a) |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | func B () = makeString(["%s", "currentPeriod"], a) |
---|
77 | | - | |
---|
78 | | - | |
---|
79 | | - | func C (D) = makeString(["%s%d", "price", toString(D)], a) |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | func E (D) = makeString(["%s%d", "startHeight", toString(D)], a) |
---|
83 | | - | |
---|
84 | | - | |
---|
85 | | - | func F (D) = makeString(["%s%d", "powerManagerBonus", toString(D)], a) |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | func G () = "%s__periodLength" |
---|
89 | | - | |
---|
90 | | - | |
---|
91 | | - | func H () = "%s__investPeriodLength" |
---|
92 | | - | |
---|
93 | | - | |
---|
94 | | - | func I () = "%s__blockProcessingReward" |
---|
95 | | - | |
---|
96 | | - | |
---|
97 | | - | func J () = "%s__nextBlockToProcess" |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | func K (L) = makeString(["%s%d", "blockProcessed", toString(L)], a) |
---|
101 | | - | |
---|
102 | | - | |
---|
103 | | - | func M () = "%s__withdrawal" |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | func N (z,O) = makeString(["%s%s%s", "withdrawal", toString(z), toBase58String(O)], a) |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | func P (Q,R,S,T) = { |
---|
110 | | - | let U = { |
---|
111 | | - | let k = T |
---|
112 | | - | if ($isInstanceOf(k, "ByteVector")) |
---|
113 | | - | then { |
---|
114 | | - | let l = k |
---|
115 | | - | toBase58String(l) |
---|
116 | | - | } |
---|
117 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
118 | | - | then "SOON" |
---|
119 | | - | else throw("Match error") |
---|
120 | | - | } |
---|
121 | | - | makeString(["%s%d%d%s", Q, toString(R), toString(S), U], a) |
---|
122 | | - | } |
---|
123 | | - | |
---|
124 | | - | |
---|
125 | | - | func V (z,O) = makeString(["%s%s%s", "withdrawalHistory", toString(z), toBase58String(O)], a) |
---|
126 | | - | |
---|
127 | | - | |
---|
128 | | - | func W (D) = makeString(["%s%d", "periodReward", toString(D)], a) |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | func X (D) = makeString(["%s%d", "periodRewardAmount", toString(D)], a) |
---|
132 | | - | |
---|
133 | | - | |
---|
134 | | - | func Y (g) = { |
---|
135 | | - | let Z = split(g, a) |
---|
136 | | - | if ((size(Z) == 5)) |
---|
137 | | - | then { |
---|
138 | | - | let Q = Z[1] |
---|
139 | | - | let R = valueOrErrorMessage(parseInt(Z[2]), f("invalid lpAssetAmount")) |
---|
140 | | - | let S = valueOrErrorMessage(parseInt(Z[3]), f("invalid targetPeriod")) |
---|
141 | | - | let T = Z[4] |
---|
142 | | - | $Tuple4(Q, R, S, T) |
---|
143 | | - | } |
---|
144 | | - | else h("invalid withdrawal request value") |
---|
145 | | - | } |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | let aa = { |
---|
149 | | - | let k = getString(this, p()) |
---|
150 | | - | if ($isInstanceOf(k, "String")) |
---|
151 | | - | then { |
---|
152 | | - | let g = k |
---|
153 | | - | addressFromString(g) |
---|
154 | | - | } |
---|
155 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
156 | | - | then unit |
---|
157 | | - | else throw("Match error") |
---|
158 | | - | } |
---|
159 | | - | |
---|
160 | | - | let ab = valueOrErrorMessage(aa, f("invalid factory address")) |
---|
161 | | - | |
---|
162 | | - | let ac = { |
---|
163 | | - | let k = aa |
---|
164 | | - | if ($isInstanceOf(k, "Address")) |
---|
165 | | - | then { |
---|
166 | | - | let ad = k |
---|
167 | | - | let ae = getString(ad, r()) |
---|
168 | | - | if ($isInstanceOf(ae, "String")) |
---|
169 | | - | then { |
---|
170 | | - | let g = ae |
---|
171 | | - | fromBase58String(g) |
---|
172 | | - | } |
---|
173 | | - | else if ($isInstanceOf(ae, "Unit")) |
---|
174 | | - | then unit |
---|
175 | | - | else throw("Match error") |
---|
176 | | - | } |
---|
177 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
178 | | - | then unit |
---|
179 | | - | else throw("Match error") |
---|
180 | | - | } |
---|
181 | | - | |
---|
182 | | - | let af = valueOrErrorMessage(ac, f("invalid lpAssetId")) |
---|
183 | | - | |
---|
184 | | - | let ag = { |
---|
185 | | - | let k = aa |
---|
186 | | - | if ($isInstanceOf(k, "Address")) |
---|
187 | | - | then { |
---|
188 | | - | let ad = k |
---|
189 | | - | let ae = getString(ad, s()) |
---|
190 | | - | if ($isInstanceOf(ae, "String")) |
---|
191 | | - | then { |
---|
192 | | - | let g = ae |
---|
193 | | - | addressFromString(g) |
---|
194 | | - | } |
---|
195 | | - | else if ($isInstanceOf(ae, "Unit")) |
---|
196 | | - | then unit |
---|
197 | | - | else throw("Match error") |
---|
198 | | - | } |
---|
199 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
200 | | - | then unit |
---|
201 | | - | else throw("Match error") |
---|
202 | | - | } |
---|
203 | | - | |
---|
204 | | - | let ah = valueOrErrorMessage(ag, f("invalid proxy treasury address")) |
---|
205 | | - | |
---|
206 | | - | let ai = { |
---|
207 | | - | let k = aa |
---|
208 | | - | if ($isInstanceOf(k, "Address")) |
---|
209 | | - | then { |
---|
210 | | - | let ad = k |
---|
211 | | - | let ae = getString(ad, t()) |
---|
212 | | - | if ($isInstanceOf(ae, "String")) |
---|
213 | | - | then { |
---|
214 | | - | let g = ae |
---|
215 | | - | addressFromString(g) |
---|
216 | | - | } |
---|
217 | | - | else if ($isInstanceOf(ae, "Unit")) |
---|
218 | | - | then unit |
---|
219 | | - | else throw("Match error") |
---|
220 | | - | } |
---|
221 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
222 | | - | then unit |
---|
223 | | - | else throw("Match error") |
---|
224 | | - | } |
---|
225 | | - | |
---|
226 | | - | let aj = { |
---|
227 | | - | let k = aa |
---|
228 | | - | if ($isInstanceOf(k, "Address")) |
---|
229 | | - | then { |
---|
230 | | - | let ad = k |
---|
231 | | - | let ae = getString(ad, u()) |
---|
232 | | - | if ($isInstanceOf(ae, "String")) |
---|
233 | | - | then { |
---|
234 | | - | let g = ae |
---|
235 | | - | addressFromString(g) |
---|
236 | | - | } |
---|
237 | | - | else if ($isInstanceOf(ae, "Unit")) |
---|
238 | | - | then unit |
---|
239 | | - | else throw("Match error") |
---|
240 | | - | } |
---|
241 | | - | else if ($isInstanceOf(k, "Unit")) |
---|
242 | | - | then unit |
---|
243 | | - | else throw("Match error") |
---|
244 | | - | } |
---|
245 | | - | |
---|
246 | | - | let ak = valueOrErrorMessage(ai, f("invalid main treasury address")) |
---|
247 | | - | |
---|
248 | | - | let al = valueOrErrorMessage(aj, f("invalid business treasury address")) |
---|
249 | | - | |
---|
250 | | - | func am () = { |
---|
251 | | - | let k = aa |
---|
252 | | - | if ($isInstanceOf(k, "Address")) |
---|
253 | | - | then { |
---|
254 | | - | let an = k |
---|
255 | | - | let ae = getString(an, q()) |
---|
256 | | - | if ($isInstanceOf(ae, "String")) |
---|
257 | | - | then { |
---|
258 | | - | let ao = ae |
---|
259 | | - | fromBase58String(ao) |
---|
260 | | - | } |
---|
261 | | - | else unit |
---|
262 | | - | } |
---|
263 | | - | else unit |
---|
264 | | - | } |
---|
265 | | - | |
---|
266 | | - | |
---|
267 | | - | func ap (aq,ar) = if ((aq.caller == ar)) |
---|
268 | | - | then true |
---|
269 | | - | else h("permission denied") |
---|
270 | | - | |
---|
271 | | - | |
---|
272 | | - | func as (aq) = ap(aq, ab) |
---|
273 | | - | |
---|
274 | | - | |
---|
275 | | - | func at (au,av) = { |
---|
276 | | - | let g = size(au) |
---|
277 | | - | let aw = au[0] |
---|
278 | | - | let ax = aw._1 |
---|
279 | | - | let ay = aw._2 |
---|
280 | | - | let az = au[1] |
---|
281 | | - | let aA = az._1 |
---|
282 | | - | let aB = az._2 |
---|
283 | | - | let aC = au[2] |
---|
284 | | - | let aD = aC._1 |
---|
285 | | - | let aE = aC._2 |
---|
286 | | - | if (if ((g > 0)) |
---|
287 | | - | then (ax == av) |
---|
288 | | - | else false) |
---|
289 | | - | then ay |
---|
290 | | - | else if (if ((g > 1)) |
---|
291 | | - | then (aA == av) |
---|
292 | | - | else false) |
---|
293 | | - | then aB |
---|
294 | | - | else if (if ((g > 2)) |
---|
295 | | - | then (aD == av) |
---|
296 | | - | else false) |
---|
297 | | - | then aE |
---|
298 | | - | else unit |
---|
299 | | - | } |
---|
300 | | - | |
---|
301 | | - | |
---|
302 | | - | func aF (aG,aH,aI) = { |
---|
303 | | - | let aJ = valueOrElse(getInteger(ab, x(unit)), 0) |
---|
304 | | - | let aK = valueOrElse(getInteger(ab, w(unit)), 0) |
---|
305 | | - | let aL = (aJ + aK) |
---|
306 | | - | let aM = (aG - aL) |
---|
307 | | - | let aN = if (if ((aM >= aH)) |
---|
308 | | - | then true |
---|
309 | | - | else (aH == 0)) |
---|
310 | | - | then aH |
---|
311 | | - | else h("power bonus is more than profit") |
---|
312 | | - | let aO = (aM - aN) |
---|
313 | | - | let aP = if ((aL > 0)) |
---|
314 | | - | then fraction(aJ, c, aL) |
---|
315 | | - | else 0 |
---|
316 | | - | let aQ = fraction(aO, aP, c) |
---|
317 | | - | let aR = (aO - aQ) |
---|
318 | | - | let aS = n(aI) |
---|
319 | | - | let aT = fraction(aR, if ((0 > aI)) |
---|
320 | | - | then aS |
---|
321 | | - | else 0, c) |
---|
322 | | - | let aU = fraction(aQ, if ((aI > 0)) |
---|
323 | | - | then aS |
---|
324 | | - | else 0, c) |
---|
325 | | - | let aV = ((aQ - aU) + aT) |
---|
326 | | - | let aW = ((aR - aT) + aU) |
---|
327 | | - | let aX = (aJ + aV) |
---|
328 | | - | let aY = (aK + aW) |
---|
329 | | - | let aZ = min([0, aX]) |
---|
330 | | - | let ba = min([0, aY]) |
---|
331 | | - | let bb = (max([0, aX]) + ba) |
---|
332 | | - | let bc = (max([0, aY]) + aZ) |
---|
333 | | - | let bd = valueOrErrorMessage(assetInfo(af), f("invalid lpAsset info")).quantity |
---|
334 | | - | let be = fraction(bc, c, bd) |
---|
335 | | - | let bf = if ((be != 0)) |
---|
336 | | - | then true |
---|
337 | | - | else h("LP price cannot be 0") |
---|
338 | | - | if ((bf == bf)) |
---|
339 | | - | then { |
---|
340 | | - | let bg = valueOrElse(getInteger(ab, M()), 0) |
---|
341 | | - | let bh = max([0, fraction(bg, be, c)]) |
---|
342 | | - | let bi = (bc - bh) |
---|
343 | | - | let bj = (bd - bg) |
---|
344 | | - | $Tuple6(bh, bi, bb, be, bg, bj) |
---|
345 | | - | } |
---|
| 36 | + | @Callable(r) |
---|
| 37 | + | func a () = { |
---|
| 38 | + | let h = b() |
---|
| 39 | + | if ((h == h)) |
---|
| 40 | + | then nil |
---|
349 | | - | |
---|
350 | | - | func bk (bl,O) = { |
---|
351 | | - | let z = Address(bl) |
---|
352 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
353 | | - | let bn = valueOrErrorMessage(getString(ab, N(z, O)), f("invalid withdrawal request")) |
---|
354 | | - | let bo = Y(bn) |
---|
355 | | - | let Q = bo._1 |
---|
356 | | - | let R = bo._2 |
---|
357 | | - | let S = bo._3 |
---|
358 | | - | let T = bo._4 |
---|
359 | | - | if ((S > bm)) |
---|
360 | | - | then h("invalid withdrawal request period") |
---|
361 | | - | else { |
---|
362 | | - | let bp = valueOrErrorMessage(getInteger(ab, C(S)), f("invalid price")) |
---|
363 | | - | let bq = if ((bp > 0)) |
---|
364 | | - | then fraction(R, bp, c) |
---|
365 | | - | else 0 |
---|
366 | | - | let br = getStringValue(ab, W(bm)) |
---|
367 | | - | let bs = getStringValue(ab, X(bm)) |
---|
368 | | - | $Tuple6(z, R, S, bq, br, bs) |
---|
369 | | - | } |
---|
370 | | - | } |
---|
371 | | - | |
---|
372 | | - | |
---|
373 | | - | func bt (bl,O) = { |
---|
374 | | - | let bu = bk(bl, O) |
---|
375 | | - | let z = bu._1 |
---|
376 | | - | let R = bu._2 |
---|
377 | | - | let S = bu._3 |
---|
378 | | - | let bq = bu._4 |
---|
379 | | - | let br = bu._5 |
---|
380 | | - | let bs = bu._6 |
---|
381 | | - | let bv = makeString(removeByIndex(split_51C(br, a), 0), ":") |
---|
382 | | - | let bw = makeString(removeByIndex(split_51C(bs, a), 0), ":") |
---|
383 | | - | makeString(["%d%s%s", toString(bq), bv, bw], a) |
---|
384 | | - | } |
---|
385 | | - | |
---|
386 | | - | |
---|
387 | | - | @Callable(aq) |
---|
388 | | - | func claimLP (bl) = { |
---|
389 | | - | let bx = as(aq) |
---|
390 | | - | if ((bx == bx)) |
---|
391 | | - | then { |
---|
392 | | - | let z = Address(bl) |
---|
393 | | - | let by = valueOrElse(getInteger(ab, y(z)), 0) |
---|
394 | | - | let bz = valueOrElse(getInteger(ab, A(z)), 0) |
---|
395 | | - | let bA = if ((by > 0)) |
---|
396 | | - | then [invoke(ab, "transferAsset", [bl, by, af], nil), invoke(ab, "integerEntry", [y(z), 0], nil), invoke(ab, "integerEntry", [A(z), (bz + by)], nil)] |
---|
397 | | - | else h("nothing to claim") |
---|
398 | | - | $Tuple2(nil, bA) |
---|
399 | | - | } |
---|
400 | | - | else throw("Strict value is not equal to itself.") |
---|
401 | | - | } |
---|
402 | | - | |
---|
403 | | - | |
---|
404 | | - | |
---|
405 | | - | @Callable(aq) |
---|
406 | | - | func finalize (bl,aG,aH,aI) = { |
---|
407 | | - | let bx = as(aq) |
---|
408 | | - | if ((bx == bx)) |
---|
409 | | - | then { |
---|
410 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
411 | | - | let bB = valueOrErrorMessage(getInteger(ab, G()), f("invalid period length")) |
---|
412 | | - | let bC = valueOrErrorMessage(getInteger(ab, E(bm)), f("invalid start height")) |
---|
413 | | - | let bD = valueOrErrorMessage(getInteger(ab, C(bm)), f("invalid price")) |
---|
414 | | - | let bE = valueOrErrorMessage(getInteger(ab, J()), f("invalid next block to process")) |
---|
415 | | - | let bF = ((bC + bB) - 1) |
---|
416 | | - | let bG = [if ((aq.originCaller == ak)) |
---|
417 | | - | then true |
---|
418 | | - | else h("permission denied"), if ((bE > bF)) |
---|
419 | | - | then true |
---|
420 | | - | else h("unprocessed blocks"), if ((aG >= 0)) |
---|
421 | | - | then true |
---|
422 | | - | else h("invalid new treasury volume"), if ((aH >= 0)) |
---|
423 | | - | then true |
---|
424 | | - | else h("invalid PWR managers bonus"), if (if ((aI >= -(c))) |
---|
425 | | - | then (c >= aI) |
---|
426 | | - | else false) |
---|
427 | | - | then true |
---|
428 | | - | else h("invalid treasury volume diff allocation coefficient")] |
---|
429 | | - | if ((bG == bG)) |
---|
430 | | - | then { |
---|
431 | | - | let bH = aF(aG, aH, aI) |
---|
432 | | - | let bh = bH._1 |
---|
433 | | - | let bi = bH._2 |
---|
434 | | - | let bb = bH._3 |
---|
435 | | - | let be = bH._4 |
---|
436 | | - | let bg = bH._5 |
---|
437 | | - | let bj = bH._6 |
---|
438 | | - | let bI = (bm + 1) |
---|
439 | | - | func bJ (bK,bL) = { |
---|
440 | | - | let bM = bK |
---|
441 | | - | let bN = bM._1 |
---|
442 | | - | let bO = bM._2 |
---|
443 | | - | let bs = bM._3 |
---|
444 | | - | let bP = bL.amount |
---|
445 | | - | let bQ = bL.assetId |
---|
446 | | - | let bR = ("%s" + makeString([bO, i(bQ)], a)) |
---|
447 | | - | let bS = ("%d" + makeString([bs, toString(bP)], a)) |
---|
448 | | - | let bT = ScriptTransfer(ab, bP, bQ) |
---|
449 | | - | $Tuple3((bN :+ bT), bR, bS) |
---|
450 | | - | } |
---|
451 | | - | |
---|
452 | | - | let bU = { |
---|
453 | | - | let bV = aq.payments |
---|
454 | | - | let bW = size(bV) |
---|
455 | | - | let bX = $Tuple3(nil, "", "") |
---|
456 | | - | func bY (bZ,ca) = if ((ca >= bW)) |
---|
457 | | - | then bZ |
---|
458 | | - | else bJ(bZ, bV[ca]) |
---|
459 | | - | |
---|
460 | | - | func cb (bZ,ca) = if ((ca >= bW)) |
---|
461 | | - | then bZ |
---|
462 | | - | else throw("List size exceeds 10") |
---|
463 | | - | |
---|
464 | | - | cb(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bX, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
465 | | - | } |
---|
466 | | - | let bN = bU._1 |
---|
467 | | - | let cc = bU._2 |
---|
468 | | - | let cd = bU._3 |
---|
469 | | - | let bA = [invoke(ab, "integerEntry", [F(bm), aH], nil), invoke(ab, "integerEntry", [B(), bI], nil), invoke(ab, "integerEntry", [C(bI), be], nil), invoke(ab, "integerEntry", [E(bI), (bF + 1)], nil), invoke(ab, "burn", [bg], nil), invoke(ab, "integerEntry", [M(), 0], nil), invoke(ab, "integerEntry", [w(unit), bi], nil), invoke(ab, "integerEntry", [x(unit), bb], nil), invoke(ab, "stringEntry", [W(bI), cc], nil), invoke(ab, "stringEntry", [X(bI), cd], nil)] |
---|
470 | | - | $Tuple2(bN, bA) |
---|
471 | | - | } |
---|
472 | | - | else throw("Strict value is not equal to itself.") |
---|
473 | | - | } |
---|
474 | | - | else throw("Strict value is not equal to itself.") |
---|
475 | | - | } |
---|
476 | | - | |
---|
477 | | - | |
---|
478 | | - | |
---|
479 | | - | @Callable(aq) |
---|
480 | | - | func finalizeREADONLY (aG,aH,aI) = { |
---|
481 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
482 | | - | let bB = valueOrErrorMessage(getInteger(ab, G()), f("invalid period length")) |
---|
483 | | - | let bC = valueOrErrorMessage(getInteger(ab, E(bm)), f("invalid start height")) |
---|
484 | | - | let bD = valueOrErrorMessage(getInteger(ab, C(bm)), f("invalid price")) |
---|
485 | | - | let bE = valueOrErrorMessage(getInteger(ab, J()), f("invalid next block to process")) |
---|
486 | | - | let bF = ((bC + bB) - 1) |
---|
487 | | - | let bG = [if ((bE > bF)) |
---|
488 | | - | then true |
---|
489 | | - | else h("unprocessed blocks"), if ((aG >= 0)) |
---|
490 | | - | then true |
---|
491 | | - | else h("invalid new treasury volume"), if ((aH >= 0)) |
---|
492 | | - | then true |
---|
493 | | - | else h("invalid PWR managers bonus"), if (if ((aI >= -(c))) |
---|
494 | | - | then (c >= aI) |
---|
495 | | - | else false) |
---|
496 | | - | then true |
---|
497 | | - | else h("invalid treasury volume diff allocation coefficient")] |
---|
498 | | - | if ((bG == bG)) |
---|
499 | | - | then $Tuple2(nil, aF(aG, aH, aI)) |
---|
500 | | - | else throw("Strict value is not equal to itself.") |
---|
501 | | - | } |
---|
502 | | - | |
---|
503 | | - | |
---|
504 | | - | |
---|
505 | | - | @Callable(aq) |
---|
506 | | - | func invest (bl) = { |
---|
507 | | - | let bx = as(aq) |
---|
508 | | - | if ((bx == bx)) |
---|
509 | | - | then { |
---|
510 | | - | let z = Address(bl) |
---|
511 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
512 | | - | let bC = valueOrErrorMessage(getInteger(ab, E(bm)), f("invalid start height")) |
---|
513 | | - | let ce = getIntegerValue(ab, H()) |
---|
514 | | - | let cf = if (((bC + ce) > height)) |
---|
515 | | - | then true |
---|
516 | | - | else h("too late to invest in this period") |
---|
517 | | - | if ((cf == cf)) |
---|
518 | | - | then { |
---|
519 | | - | let bD = valueOrErrorMessage(getInteger(ab, C(bm)), f("invalid price")) |
---|
520 | | - | let bL = if ((size(aq.payments) == 1)) |
---|
521 | | - | then aq.payments[0] |
---|
522 | | - | else h("invalid payments") |
---|
523 | | - | let cg = if (if ((bL.assetId == unit)) |
---|
524 | | - | then (bL.amount > 0) |
---|
525 | | - | else false) |
---|
526 | | - | then $Tuple2(bL.amount, bL.assetId) |
---|
527 | | - | else h("invalid payment amount") |
---|
528 | | - | let bP = cg._1 |
---|
529 | | - | let bQ = cg._2 |
---|
530 | | - | let ch = valueOrElse(getInteger(ab, v()), 0) |
---|
531 | | - | let ci = fraction(bP, (c - ch), c) |
---|
532 | | - | let R = if ((bD > 0)) |
---|
533 | | - | then fraction(ci, c, bD) |
---|
534 | | - | else 0 |
---|
535 | | - | let cj = valueOrElse(getInteger(ab, w(unit)), 0) |
---|
536 | | - | let bK = [ScriptTransfer(ak, ci, bQ), ScriptTransfer(al, ch, bQ)] |
---|
537 | | - | let bA = [invoke(ab, "integerEntry", [w(unit), (cj + ci)], nil), invoke(ab, "reissue", [R], nil), invoke(ab, "transferAsset", [bl, R, af], nil)] |
---|
538 | | - | $Tuple2(bK, bA) |
---|
539 | | - | } |
---|
540 | | - | else throw("Strict value is not equal to itself.") |
---|
541 | | - | } |
---|
542 | | - | else throw("Strict value is not equal to itself.") |
---|
543 | | - | } |
---|
544 | | - | |
---|
545 | | - | |
---|
546 | | - | |
---|
547 | | - | @Callable(aq) |
---|
548 | | - | func withdraw (bl) = { |
---|
549 | | - | let bx = as(aq) |
---|
550 | | - | if ((bx == bx)) |
---|
551 | | - | then { |
---|
552 | | - | let z = Address(bl) |
---|
553 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
554 | | - | let bL = if ((size(aq.payments) == 1)) |
---|
555 | | - | then aq.payments[0] |
---|
556 | | - | else h(f("invalid payments")) |
---|
557 | | - | let bQ = if ((bL.assetId == af)) |
---|
558 | | - | then af |
---|
559 | | - | else h("invalid payment asset") |
---|
560 | | - | let bP = if ((bL.amount > 0)) |
---|
561 | | - | then bL.amount |
---|
562 | | - | else h("invalid payment amount") |
---|
563 | | - | let ck = valueOrElse(getInteger(ab, M()), 0) |
---|
564 | | - | let bK = [ScriptTransfer(ab, bP, bQ)] |
---|
565 | | - | let bA = [invoke(ab, "integerEntry", [M(), (ck + bP)], nil), invoke(ab, "stringEntry", [N(z, aq.transactionId), P(d, bP, (bm + 1), unit)], nil)] |
---|
566 | | - | if ((bA == bA)) |
---|
567 | | - | then $Tuple2(bK, bA) |
---|
568 | | - | else throw("Strict value is not equal to itself.") |
---|
569 | | - | } |
---|
570 | | - | else throw("Strict value is not equal to itself.") |
---|
571 | | - | } |
---|
572 | | - | |
---|
573 | | - | |
---|
574 | | - | |
---|
575 | | - | @Callable(aq) |
---|
576 | | - | func cancelWithdraw (bl,O) = { |
---|
577 | | - | let bx = as(aq) |
---|
578 | | - | if ((bx == bx)) |
---|
579 | | - | then { |
---|
580 | | - | let z = Address(bl) |
---|
581 | | - | let bn = valueOrErrorMessage(getString(ab, N(z, O)), f("invalid withdrawal request")) |
---|
582 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
583 | | - | let cl = Y(bn) |
---|
584 | | - | let Q = cl._1 |
---|
585 | | - | let R = cl._2 |
---|
586 | | - | let S = cl._3 |
---|
587 | | - | let T = cl._4 |
---|
588 | | - | let bG = [if ((Q == d)) |
---|
589 | | - | then true |
---|
590 | | - | else h("invalid withdrawal request status"), if ((S > bm)) |
---|
591 | | - | then true |
---|
592 | | - | else h("invalid withdrawal request period")] |
---|
593 | | - | if ((bG == bG)) |
---|
594 | | - | then { |
---|
595 | | - | let ck = valueOrErrorMessage(getInteger(ab, M()), f("invalid total withdrawal amount")) |
---|
596 | | - | let bA = [invoke(ab, "integerEntry", [M(), if ((ck >= R)) |
---|
597 | | - | then (ck - R) |
---|
598 | | - | else h("invalid withdrawal amount")], nil), invoke(ab, "deleteEntry", [N(z, O)], nil), invoke(ab, "transferAsset", [bl, R, af], nil)] |
---|
599 | | - | if ((bA == bA)) |
---|
600 | | - | then $Tuple2(nil, bA) |
---|
601 | | - | else throw("Strict value is not equal to itself.") |
---|
602 | | - | } |
---|
603 | | - | else throw("Strict value is not equal to itself.") |
---|
604 | | - | } |
---|
605 | | - | else throw("Strict value is not equal to itself.") |
---|
606 | | - | } |
---|
607 | | - | |
---|
608 | | - | |
---|
609 | | - | |
---|
610 | | - | @Callable(aq) |
---|
611 | | - | func claimCollateral (bl,O) = { |
---|
612 | | - | let bx = as(aq) |
---|
613 | | - | if ((bx == bx)) |
---|
614 | | - | then { |
---|
615 | | - | let cm = bk(bl, fromBase58String(O)) |
---|
616 | | - | let z = cm._1 |
---|
617 | | - | let R = cm._2 |
---|
618 | | - | let S = cm._3 |
---|
619 | | - | let bq = cm._4 |
---|
620 | | - | let br = cm._5 |
---|
621 | | - | let bs = cm._6 |
---|
622 | | - | let cn = removeByIndex(split_51C(br, a), 0) |
---|
623 | | - | let co = removeByIndex(split_51C(bs, a), 0) |
---|
624 | | - | let bA = [invoke(ab, "deleteEntry", [N(z, fromBase58String(O))], nil), invoke(ab, "integerEntry", [V(z, fromBase58String(O)), R], nil), invoke(ab, "transferAssets", [bl, cn, co], nil)] |
---|
625 | | - | $Tuple2(nil, bA) |
---|
626 | | - | } |
---|
627 | | - | else throw("Strict value is not equal to itself.") |
---|
628 | | - | } |
---|
629 | | - | |
---|
630 | | - | |
---|
631 | | - | |
---|
632 | | - | @Callable(aq) |
---|
633 | | - | func claimCollateralBulk (bl,cp) = { |
---|
634 | | - | let bx = as(aq) |
---|
635 | | - | if ((bx == bx)) |
---|
636 | | - | then { |
---|
637 | | - | func bJ (cq,O) = { |
---|
638 | | - | let cr = bk(bl, fromBase58String(O)) |
---|
639 | | - | let z = cr._1 |
---|
640 | | - | let R = cr._2 |
---|
641 | | - | let S = cr._3 |
---|
642 | | - | let bq = cr._4 |
---|
643 | | - | let br = cr._5 |
---|
644 | | - | let bs = cr._6 |
---|
645 | | - | let cn = removeByIndex(split_51C(br, a), 0) |
---|
646 | | - | let co = removeByIndex(split_51C(bs, a), 0) |
---|
647 | | - | let cs = [invoke(ab, "deleteEntry", [N(z, fromBase58String(O))], nil), invoke(ab, "integerEntry", [V(z, fromBase58String(O)), R], nil), invoke(ab, "transferAssets", [bl, cn, co], nil)] |
---|
648 | | - | (cq ++ cs) |
---|
649 | | - | } |
---|
650 | | - | |
---|
651 | | - | let ct = { |
---|
652 | | - | let bV = cp |
---|
653 | | - | let bW = size(bV) |
---|
654 | | - | let bX = nil |
---|
655 | | - | func bY (bZ,ca) = if ((ca >= bW)) |
---|
656 | | - | then bZ |
---|
657 | | - | else bJ(bZ, bV[ca]) |
---|
658 | | - | |
---|
659 | | - | func cb (bZ,ca) = if ((ca >= bW)) |
---|
660 | | - | then bZ |
---|
661 | | - | else throw("List size exceeds 10") |
---|
662 | | - | |
---|
663 | | - | cb(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bX, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
664 | | - | } |
---|
665 | | - | $Tuple2(nil, ct) |
---|
666 | | - | } |
---|
667 | | - | else throw("Strict value is not equal to itself.") |
---|
668 | | - | } |
---|
669 | | - | |
---|
670 | | - | |
---|
671 | | - | |
---|
672 | | - | @Callable(aq) |
---|
673 | | - | func claimCollateralREADONLY (bl,O) = { |
---|
674 | | - | let cu = bt(bl, fromBase58String(O)) |
---|
675 | | - | $Tuple2(nil, cu) |
---|
676 | | - | } |
---|
677 | | - | |
---|
678 | | - | |
---|
679 | | - | |
---|
680 | | - | @Callable(aq) |
---|
681 | | - | func claimCollateralBulkREADONLY (bl,cp) = { |
---|
682 | | - | func cv (cq,O) = { |
---|
683 | | - | let cu = bt(bl, fromBase58String(O)) |
---|
684 | | - | (cq :+ cu) |
---|
685 | | - | } |
---|
686 | | - | |
---|
687 | | - | let cw = { |
---|
688 | | - | let bV = cp |
---|
689 | | - | let bW = size(bV) |
---|
690 | | - | let bX = nil |
---|
691 | | - | func bY (bZ,ca) = if ((ca >= bW)) |
---|
692 | | - | then bZ |
---|
693 | | - | else cv(bZ, bV[ca]) |
---|
694 | | - | |
---|
695 | | - | func cb (bZ,ca) = if ((ca >= bW)) |
---|
696 | | - | then bZ |
---|
697 | | - | else throw("List size exceeds 10") |
---|
698 | | - | |
---|
699 | | - | cb(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bX, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
700 | | - | } |
---|
701 | | - | $Tuple2(nil, cw) |
---|
702 | | - | } |
---|
703 | | - | |
---|
704 | | - | |
---|
705 | | - | |
---|
706 | | - | @Callable(aq) |
---|
707 | | - | func processBlocks (bl) = { |
---|
708 | | - | let bx = as(aq) |
---|
709 | | - | if ((bx == bx)) |
---|
710 | | - | then { |
---|
711 | | - | let z = Address(bl) |
---|
712 | | - | let bm = valueOrErrorMessage(getInteger(ab, B()), f("invalid period")) |
---|
713 | | - | let bB = valueOrErrorMessage(getInteger(ab, G()), f("invalid period length")) |
---|
714 | | - | let bC = valueOrErrorMessage(getInteger(ab, E(bm)), f("invalid start height")) |
---|
715 | | - | let bD = valueOrErrorMessage(getInteger(ab, C(bm)), f("invalid price")) |
---|
716 | | - | let bE = valueOrErrorMessage(getInteger(ab, J()), f("invalid next block to process")) |
---|
717 | | - | let bF = ((bC + bB) - 1) |
---|
718 | | - | let cx = 40 |
---|
719 | | - | let cy = if (if (if ((height >= bE)) |
---|
720 | | - | then if ((bE >= bC)) |
---|
721 | | - | then true |
---|
722 | | - | else (bm == 0) |
---|
723 | | - | else false) |
---|
724 | | - | then (bF >= bE) |
---|
725 | | - | else false) |
---|
726 | | - | then min([((bF - bE) + 1), cx]) |
---|
727 | | - | else h(f("invalid target block")) |
---|
728 | | - | let cz = valueOrErrorMessage(getInteger(ab, I()), f("invalid block processing reward")) |
---|
729 | | - | let cA = (cz / cy) |
---|
730 | | - | let cB = (cz - (cA * cy)) |
---|
731 | | - | func cC (cD,cE) = if ((cE >= cy)) |
---|
732 | | - | then cD |
---|
733 | | - | else { |
---|
734 | | - | let cF = (bE + cE) |
---|
735 | | - | let cG = valueOrErrorMessage(blockInfoByHeight(cF), f("invalid block info")) |
---|
736 | | - | let cH = valueOrErrorMessage(at(cG.rewards, ah), f(("invalid treasury reward for height " + toString(cF)))) |
---|
737 | | - | let cI = cG.generator |
---|
738 | | - | let by = valueOrElse(getInteger(ab, y(cI)), 0) |
---|
739 | | - | let cJ = if ((cE == (cy - 1))) |
---|
740 | | - | then (cA + cB) |
---|
741 | | - | else cA |
---|
742 | | - | let R = if ((bD > 0)) |
---|
743 | | - | then fraction((cH - cJ), c, bD) |
---|
744 | | - | else 0 |
---|
745 | | - | let cK = [invoke(ab, "stringEntry", [K(cF), makeString([toBase58String(aq.transactionId), toString(bm), toString(cI), toBase58String(bl), toString(cH), toString(cJ), toString(R)], a)], nil), invoke(ab, "integerEntry", [y(cI), (by + R)], nil)] |
---|
746 | | - | if ((cK == cK)) |
---|
747 | | - | then { |
---|
748 | | - | let cL = cD |
---|
749 | | - | let cM = cL._1 |
---|
750 | | - | let cN = cL._2 |
---|
751 | | - | $Tuple2((cM + R), (cN + cH)) |
---|
752 | | - | } |
---|
753 | | - | else throw("Strict value is not equal to itself.") |
---|
754 | | - | } |
---|
755 | | - | |
---|
756 | | - | let cO = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39] |
---|
757 | | - | let cP = { |
---|
758 | | - | let bV = cO |
---|
759 | | - | let bW = size(bV) |
---|
760 | | - | let bX = $Tuple2(0, 0) |
---|
761 | | - | func bY (bZ,ca) = if ((ca >= bW)) |
---|
762 | | - | then bZ |
---|
763 | | - | else cC(bZ, bV[ca]) |
---|
764 | | - | |
---|
765 | | - | func cb (bZ,ca) = if ((ca >= bW)) |
---|
766 | | - | then bZ |
---|
767 | | - | else throw("List size exceeds 40") |
---|
768 | | - | |
---|
769 | | - | cb(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bY(bX, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40) |
---|
770 | | - | } |
---|
771 | | - | if ((cP == cP)) |
---|
772 | | - | then { |
---|
773 | | - | let cQ = cP._2 |
---|
774 | | - | let cR = cP._1 |
---|
775 | | - | let cS = valueOrElse(getInteger(ab, v()), 0) |
---|
776 | | - | let cT = fraction(cQ, cS, c) |
---|
777 | | - | let cU = ((cQ - cT) - cz) |
---|
778 | | - | let cj = valueOrElse(getInteger(ab, w(unit)), 0) |
---|
779 | | - | let bK = [invoke(ab, "reissue", [cR], nil), invoke(ab, "integerEntry", [J(), (bE + cy)], nil), invoke(ab, "transferFromProxyTreasury", [ak.bytes, cU], nil), invoke(ab, "transferFromProxyTreasury", [bl, cz], nil), invoke(ab, "transferFromProxyTreasury", [al.bytes, cT], nil), invoke(ab, "integerEntry", [w(unit), (cj + cU)], nil)] |
---|
780 | | - | if ((bK == bK)) |
---|
781 | | - | then $Tuple2(nil, unit) |
---|
782 | | - | else throw("Strict value is not equal to itself.") |
---|
783 | | - | } |
---|
784 | | - | else throw("Strict value is not equal to itself.") |
---|
785 | | - | } |
---|
786 | | - | else throw("Strict value is not equal to itself.") |
---|
787 | | - | } |
---|
788 | | - | |
---|
789 | | - | |
---|
790 | | - | @Verifier(cV) |
---|
791 | | - | func cW () = { |
---|
792 | | - | let cX = { |
---|
793 | | - | let k = am() |
---|
794 | | - | if ($isInstanceOf(k, "ByteVector")) |
---|
795 | | - | then { |
---|
796 | | - | let ao = k |
---|
797 | | - | ao |
---|
798 | | - | } |
---|
799 | | - | else cV.senderPublicKey |
---|
800 | | - | } |
---|
801 | | - | sigVerify(cV.bodyBytes, cV.proofs[0], cX) |
---|
802 | | - | } |
---|