108 | | - | let Y = Address(I(t)) |
---|
109 | | - | |
---|
110 | | - | let Z = Address(I(u)) |
---|
111 | | - | |
---|
112 | | - | let aa = valueOrErrorMessage(getInteger(T, q), "Empty kBasePeriod") |
---|
113 | | - | |
---|
114 | | - | let ab = valueOrErrorMessage(getInteger(T, s), "Empty kStartHeight") |
---|
115 | | - | |
---|
116 | | - | let ac = valueOrErrorMessage(getInteger(T, r), "Empty kPeriodLength") |
---|
117 | | - | |
---|
118 | | - | let ad = ((aa + ((height - ab) / ac)) + 3) |
---|
119 | | - | |
---|
120 | | - | let ae = getBooleanValue(this, c) |
---|
121 | | - | |
---|
122 | | - | let af = getStringValue(this, d) |
---|
123 | | - | |
---|
124 | | - | let ag = getStringValue(this, e) |
---|
125 | | - | |
---|
126 | | - | let ah = if ((af == "WAVES")) |
---|
127 | | - | then unit |
---|
128 | | - | else fromBase58String(af) |
---|
129 | | - | |
---|
130 | | - | let ai = if ((ag == "WAVES")) |
---|
131 | | - | then unit |
---|
132 | | - | else fromBase58String(ag) |
---|
133 | | - | |
---|
134 | | - | let aj = { |
---|
135 | | - | let K = ah |
---|
136 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
137 | | - | then { |
---|
138 | | - | let ak = K |
---|
139 | | - | value(assetInfo(ak)).name |
---|
140 | | - | } |
---|
141 | | - | else if ($isInstanceOf(K, "Unit")) |
---|
142 | | - | then { |
---|
143 | | - | let al = K |
---|
144 | | - | "WAVES" |
---|
145 | | - | } |
---|
146 | | - | else throw("Match error") |
---|
147 | | - | } |
---|
148 | | - | |
---|
149 | | - | let am = { |
---|
150 | | - | let K = ai |
---|
151 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
152 | | - | then { |
---|
153 | | - | let ak = K |
---|
154 | | - | value(assetInfo(ak)).name |
---|
155 | | - | } |
---|
156 | | - | else if ($isInstanceOf(K, "Unit")) |
---|
157 | | - | then { |
---|
158 | | - | let al = K |
---|
159 | | - | "WAVES" |
---|
160 | | - | } |
---|
161 | | - | else throw("Match error") |
---|
162 | | - | } |
---|
163 | | - | |
---|
164 | | - | let an = getIntegerValue(this, f) |
---|
165 | | - | |
---|
166 | | - | let ao = getIntegerValue(this, g) |
---|
167 | | - | |
---|
168 | | - | let ap = fromBase58String(getStringValue(this, j)) |
---|
169 | | - | |
---|
170 | | - | let aq = getIntegerValue(this, k) |
---|
171 | | - | |
---|
172 | | - | let ar = getIntegerValue(this, l) |
---|
173 | | - | |
---|
174 | | - | let as = fraction(ar, 40, 100) |
---|
175 | | - | |
---|
176 | | - | let at = 1000000 |
---|
177 | | - | |
---|
178 | | - | let au = 1000 |
---|
179 | | - | |
---|
180 | | - | let av = 100000000 |
---|
181 | | - | |
---|
182 | | - | let aw = 1000 |
---|
183 | | - | |
---|
184 | | - | let ax = 8 |
---|
185 | | - | |
---|
186 | | - | func ay (az) = { |
---|
187 | | - | let K = az |
---|
188 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
189 | | - | then { |
---|
190 | | - | let ak = K |
---|
191 | | - | assetBalance(this, ak) |
---|
192 | | - | } |
---|
193 | | - | else if ($isInstanceOf(K, "Unit")) |
---|
194 | | - | then { |
---|
195 | | - | let al = K |
---|
196 | | - | wavesBalance(this).available |
---|
197 | | - | } |
---|
198 | | - | else throw("Match error") |
---|
199 | | - | } |
---|
200 | | - | |
---|
201 | | - | |
---|
202 | | - | func aA (az) = { |
---|
203 | | - | let aB = { |
---|
204 | | - | let K = az |
---|
205 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
206 | | - | then { |
---|
207 | | - | let aC = K |
---|
208 | | - | if ((aC == U)) |
---|
209 | | - | then getInteger(Y, ((("rpd_balance_" + toBase58String(aC)) + "_") + toString(this))) |
---|
210 | | - | else if ((aC == W)) |
---|
211 | | - | then getInteger(Z, ((("%s%s%s__stakingBalance__" + toBase58String(aC)) + "__") + toString(this))) |
---|
212 | | - | else 0 |
---|
213 | | - | } |
---|
214 | | - | else if ($isInstanceOf(K, "Unit")) |
---|
215 | | - | then valueOrElse(getInteger(this, w), 0) |
---|
216 | | - | else throw("Match error") |
---|
217 | | - | } |
---|
218 | | - | let K = aB |
---|
219 | | - | if ($isInstanceOf(K, "Int")) |
---|
220 | | - | then { |
---|
221 | | - | let aD = K |
---|
222 | | - | aD |
---|
223 | | - | } |
---|
224 | | - | else 0 |
---|
225 | | - | } |
---|
226 | | - | |
---|
227 | | - | |
---|
228 | | - | let aE = aA(ah) |
---|
229 | | - | |
---|
230 | | - | let aF = aA(ai) |
---|
231 | | - | |
---|
232 | | - | let aG = getIntegerValue(this, h) |
---|
233 | | - | |
---|
234 | | - | let aH = getIntegerValue(this, i) |
---|
235 | | - | |
---|
236 | | - | let aI = (an - aE) |
---|
237 | | - | |
---|
238 | | - | let aJ = (ao - aF) |
---|
239 | | - | |
---|
240 | | - | let aK = (ay(ah) + aE) |
---|
241 | | - | |
---|
242 | | - | let aL = (ay(ai) + aF) |
---|
243 | | - | |
---|
244 | | - | let aM = if ((aK >= an)) |
---|
245 | | - | then (aL >= ao) |
---|
246 | | - | else false |
---|
247 | | - | |
---|
248 | | - | func aN (az) = { |
---|
249 | | - | let K = az |
---|
250 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
251 | | - | then { |
---|
252 | | - | let ak = K |
---|
253 | | - | let aO = toBase58String(ak) |
---|
254 | | - | let aP = valueOrErrorMessage(assetInfo(ak), (("Asset " + aO) + " doesn't exist")) |
---|
255 | | - | $Tuple3(aO, aP.name, aP.decimals) |
---|
256 | | - | } |
---|
257 | | - | else if ($isInstanceOf(K, "Unit")) |
---|
258 | | - | then { |
---|
259 | | - | let al = K |
---|
260 | | - | $Tuple3("WAVES", "WAVES", 8) |
---|
261 | | - | } |
---|
262 | | - | else throw("Match error") |
---|
263 | | - | } |
---|
264 | | - | |
---|
265 | | - | |
---|
266 | | - | func aQ (aR) = if ((aR == "WAVES")) |
---|
267 | | - | then $Tuple3("WAVES", "WAVES", 8) |
---|
268 | | - | else { |
---|
269 | | - | let aO = aR |
---|
270 | | - | let ak = fromBase58String(aR) |
---|
271 | | - | let aP = valueOrErrorMessage(assetInfo(ak), (("Asset " + aO) + " doesn't exist")) |
---|
272 | | - | $Tuple3(aO, aP.name, aP.decimals) |
---|
273 | | - | } |
---|
274 | | - | |
---|
275 | | - | |
---|
276 | | - | func aS (aT) = [BooleanEntry(c, false), StringEntry(m, aT)] |
---|
277 | | - | |
---|
278 | | - | |
---|
279 | | - | func aU (aV,az) = if (aV) |
---|
280 | | - | then if ((az == U)) |
---|
281 | | - | then $Tuple2("lockNeutrino", Y) |
---|
282 | | - | else $Tuple2("startStaking", Z) |
---|
283 | | - | else if ((az == U)) |
---|
284 | | - | then $Tuple2("unlockNeutrino", Y) |
---|
285 | | - | else $Tuple2("stopStaking", Z) |
---|
286 | | - | |
---|
287 | | - | |
---|
288 | | - | func aW (aV,aX,az) = if (aV) |
---|
289 | | - | then { |
---|
290 | | - | let aY = aU(aV, az) |
---|
291 | | - | let aZ = aY._1 |
---|
292 | | - | let ba = aY._2 |
---|
293 | | - | $Tuple4(aZ, ba, nil, [AttachedPayment(az, aX)]) |
---|
294 | | - | } |
---|
295 | | - | else { |
---|
296 | | - | let bb = aU(aV, az) |
---|
297 | | - | let aZ = bb._1 |
---|
298 | | - | let ba = bb._2 |
---|
299 | | - | $Tuple4(aZ, ba, [aX, toBase58String(az)], nil) |
---|
300 | | - | } |
---|
301 | | - | |
---|
302 | | - | |
---|
303 | | - | func bc (bd) = { |
---|
304 | | - | let be = valueOrElse(getInteger(S, (toString(bd) + A)), 0) |
---|
305 | | - | let bf = split(getStringValue(H, z), ",") |
---|
306 | | - | let bg = split(getStringValue(H, y), ",") |
---|
307 | | - | if (if ((be >= parseIntValue(bf[0]))) |
---|
308 | | - | then (parseIntValue(bf[1]) > be) |
---|
309 | | - | else false) |
---|
310 | | - | then (at - parseIntValue(bg[0])) |
---|
311 | | - | else if (if ((be >= parseIntValue(bf[1]))) |
---|
312 | | - | then (parseIntValue(bf[2]) > be) |
---|
313 | | - | else false) |
---|
314 | | - | then (at - parseIntValue(bg[1])) |
---|
315 | | - | else if (if ((be >= parseIntValue(bf[2]))) |
---|
316 | | - | then (parseIntValue(bf[3]) > be) |
---|
317 | | - | else false) |
---|
318 | | - | then (at - parseIntValue(bg[2])) |
---|
319 | | - | else if (if ((be >= parseIntValue(bf[3]))) |
---|
320 | | - | then (parseIntValue(bf[4]) > be) |
---|
321 | | - | else false) |
---|
322 | | - | then (at - parseIntValue(bg[3])) |
---|
323 | | - | else if ((be >= parseIntValue(bf[4]))) |
---|
324 | | - | then (at - parseIntValue(bg[4])) |
---|
325 | | - | else at |
---|
326 | | - | } |
---|
327 | | - | |
---|
328 | | - | |
---|
329 | | - | func bh (bi,bj,bk,bl,bm) = { |
---|
330 | | - | let bn = fraction(bl, bi, (bi + bk)) |
---|
331 | | - | let bo = bc(bm) |
---|
332 | | - | let bp = fraction(bn, (at - fraction(ar, bo, at, CEILING)), at) |
---|
333 | | - | let bq = fraction(bn, fraction(as, bo, at, CEILING), at) |
---|
334 | | - | if ((bj > bp)) |
---|
335 | | - | then throw(((("Calculated amount to receive " + toString(bp)) + " is less than specified minimum ") + toString(bj))) |
---|
336 | | - | else $Tuple3(bn, bp, bq) |
---|
337 | | - | } |
---|
338 | | - | |
---|
339 | | - | |
---|
340 | | - | func br () = aS(((((((((((((((("Suspicious state. Actual balances: " + toString(aK)) + " ") + aj) + ", ") + toString(aL)) + " ") + am) + ". State: ") + toString(an)) + " ") + aj) + ", ") + toString(ao)) + " ") + am)) |
---|
341 | | - | |
---|
342 | | - | |
---|
343 | | - | func bs () = if (ae) |
---|
| 74 | + | func H () = if (G) |
---|
348 | | - | @Callable(aD) |
---|
349 | | - | func init (bt) = { |
---|
350 | | - | let bu = $Tuple2(aD.payments[0].amount, aD.payments[0].assetId) |
---|
351 | | - | let bv = bu._1 |
---|
352 | | - | let bw = bu._2 |
---|
353 | | - | let bx = $Tuple2(aD.payments[1].amount, aD.payments[1].assetId) |
---|
354 | | - | let by = bx._1 |
---|
355 | | - | let bz = bx._2 |
---|
356 | | - | let bA = aN(bw) |
---|
357 | | - | let bB = bA._1 |
---|
358 | | - | let bC = bA._2 |
---|
359 | | - | let bD = bA._3 |
---|
360 | | - | let bE = aN(bz) |
---|
361 | | - | let bF = bE._1 |
---|
362 | | - | let bG = bE._2 |
---|
363 | | - | let bH = bE._3 |
---|
364 | | - | if (!(containsElement([N, O, P, Q], aD.callerPublicKey))) |
---|
365 | | - | then throw("Only admin can call this function") |
---|
366 | | - | else if (isDefined(getBoolean(this, c))) |
---|
367 | | - | then throw("DApp is already active") |
---|
368 | | - | else if ((bw == bz)) |
---|
369 | | - | then throw("Assets must be different") |
---|
370 | | - | else { |
---|
371 | | - | let bI = ((("s" + take(bC, 7)) + "_") + take(bG, 7)) |
---|
372 | | - | let bJ = ((((("ShareToken of SwopFi protocol for " + bC) + " and ") + bG) + " at address ") + toString(this)) |
---|
373 | | - | let bK = ((bD + bH) / 2) |
---|
374 | | - | let bL = pow(bv, bD, 5, 1, bD, DOWN) |
---|
375 | | - | let bM = pow(by, bH, 5, 1, bH, DOWN) |
---|
376 | | - | let bN = pow(10, 0, bK, 0, 0, DOWN) |
---|
377 | | - | let bO = fraction(bL, bM, bN) |
---|
378 | | - | let bP = Issue(bI, bJ, bO, bK, true) |
---|
379 | | - | let bQ = calculateAssetId(bP) |
---|
380 | | - | let bR = if (containsElement(X, bB)) |
---|
381 | | - | then invoke(this, "stakeUnstake", [true, bv, bB], nil) |
---|
382 | | - | else 0 |
---|
383 | | - | if ((bR == bR)) |
---|
384 | | - | then { |
---|
385 | | - | let bS = if (containsElement(X, bF)) |
---|
386 | | - | then invoke(this, "stakeUnstake", [true, by, bF], nil) |
---|
387 | | - | else 0 |
---|
388 | | - | if ((bS == bS)) |
---|
389 | | - | then { |
---|
390 | | - | let bT = [StringEntry(b, a), BooleanEntry(c, true), StringEntry(d, bB), StringEntry(e, bF), IntegerEntry(f, bv), IntegerEntry(g, by), IntegerEntry(l, getIntegerValue(H, "base_fee_cpmm")), bP, StringEntry(j, toBase58String(bQ)), IntegerEntry(k, bO), ScriptTransfer(aD.caller, bO, bQ)] |
---|
391 | | - | if (bt) |
---|
392 | | - | then (bT ++ [BooleanEntry(n, bt), IntegerEntry(o, (ab + (ad * ac)))]) |
---|
393 | | - | else bT |
---|
394 | | - | } |
---|
395 | | - | else throw("Strict value is not equal to itself.") |
---|
396 | | - | } |
---|
397 | | - | else throw("Strict value is not equal to itself.") |
---|
398 | | - | } |
---|
| 79 | + | func I (J) = if ((J == C)) |
---|
| 80 | + | then unit |
---|
| 81 | + | else throw("Only global Contract can invoke this function") |
---|
| 82 | + | |
---|
| 83 | + | |
---|
| 84 | + | func K (L) = if (containsElement([w, x, y], L)) |
---|
| 85 | + | then unit |
---|
| 86 | + | else throw("Only admin can call this function") |
---|
| 87 | + | |
---|
| 88 | + | |
---|
| 89 | + | func M (N) = [BooleanEntry(a, false), StringEntry(b, N)] |
---|
| 90 | + | |
---|
| 91 | + | |
---|
| 92 | + | func O (P,Q) = if (P) |
---|
| 93 | + | then if ((Q == D)) |
---|
| 94 | + | then $Tuple2("lockNeutrino", A) |
---|
| 95 | + | else $Tuple2("startStaking", B) |
---|
| 96 | + | else if ((Q == D)) |
---|
| 97 | + | then $Tuple2("unlockNeutrino", A) |
---|
| 98 | + | else $Tuple2("stopStaking", B) |
---|
| 99 | + | |
---|
| 100 | + | |
---|
| 101 | + | func R (P,S,Q) = if (P) |
---|
| 102 | + | then { |
---|
| 103 | + | let T = O(P, Q) |
---|
| 104 | + | let U = T._1 |
---|
| 105 | + | let V = T._2 |
---|
| 106 | + | $Tuple4(U, V, nil, [AttachedPayment(Q, S)]) |
---|
| 107 | + | } |
---|
| 108 | + | else { |
---|
| 109 | + | let W = O(P, Q) |
---|
| 110 | + | let U = W._1 |
---|
| 111 | + | let V = W._2 |
---|
| 112 | + | $Tuple4(U, V, [S, toBase58String(Q)], nil) |
---|
| 113 | + | } |
---|
| 114 | + | |
---|
| 115 | + | |
---|
| 116 | + | func X (Y,Z) = { |
---|
| 117 | + | let aa = Y |
---|
| 118 | + | let ab = aa._1 |
---|
| 119 | + | let ac = aa._2 |
---|
| 120 | + | $Tuple2((ab :+ Z.amount), (ac :+ (if ((Z.assetId == unit)) |
---|
| 121 | + | then base58'' |
---|
| 122 | + | else Z.assetId))) |
---|
402 | | - | |
---|
403 | | - | @Callable(aD) |
---|
404 | | - | func initWithInitRatio (bU,bV,af,ag,bt) = { |
---|
405 | | - | let bW = aQ(af) |
---|
406 | | - | let bB = bW._1 |
---|
407 | | - | let bC = bW._2 |
---|
408 | | - | let bD = bW._3 |
---|
409 | | - | let bX = aQ(ag) |
---|
410 | | - | let bF = bX._1 |
---|
411 | | - | let bG = bX._2 |
---|
412 | | - | let bH = bX._3 |
---|
413 | | - | if (!(containsElement([N, O, P, Q], aD.callerPublicKey))) |
---|
414 | | - | then throw("Only admin can call this function") |
---|
415 | | - | else if (isDefined(getBoolean(this, c))) |
---|
416 | | - | then throw("DApp is already active") |
---|
417 | | - | else if ((af == ag)) |
---|
418 | | - | then throw("Assets must be different") |
---|
419 | | - | else { |
---|
420 | | - | let bI = ((("s" + take(bC, 7)) + "_") + take(bG, 7)) |
---|
421 | | - | let bJ = ((((("ShareToken of SwopFi protocol for " + bC) + " and ") + bG) + " at address ") + toString(this)) |
---|
422 | | - | let bK = ((bD + bH) / 2) |
---|
423 | | - | let bO = 0 |
---|
424 | | - | let bP = Issue(bI, bJ, bO, bK, true) |
---|
425 | | - | let bQ = calculateAssetId(bP) |
---|
426 | | - | let bT = [StringEntry(b, a), BooleanEntry(c, true), StringEntry(d, bB), StringEntry(e, bF), IntegerEntry(h, bU), IntegerEntry(i, bV), IntegerEntry(f, 0), IntegerEntry(g, 0), IntegerEntry(l, getIntegerValue(H, "base_fee_cpmm")), bP, StringEntry(j, toBase58String(bQ)), IntegerEntry(k, bO)] |
---|
427 | | - | if (bt) |
---|
428 | | - | then (bT ++ [BooleanEntry(n, bt), IntegerEntry(o, (ab + (ad * ac)))]) |
---|
429 | | - | else bT |
---|
430 | | - | } |
---|
| 126 | + | func ad (ae,af) = { |
---|
| 127 | + | let t = af |
---|
| 128 | + | if (if ($isInstanceOf(t, "Issue")) |
---|
| 129 | + | then true |
---|
| 130 | + | else if ($isInstanceOf(t, "Burn")) |
---|
| 131 | + | then true |
---|
| 132 | + | else if ($isInstanceOf(t, "Reissue")) |
---|
| 133 | + | then true |
---|
| 134 | + | else if ($isInstanceOf(t, "ScriptTransfer")) |
---|
| 135 | + | then true |
---|
| 136 | + | else if ($isInstanceOf(t, "BinaryEntry")) |
---|
| 137 | + | then true |
---|
| 138 | + | else if ($isInstanceOf(t, "BooleanEntry")) |
---|
| 139 | + | then true |
---|
| 140 | + | else if ($isInstanceOf(t, "StringEntry")) |
---|
| 141 | + | then true |
---|
| 142 | + | else $isInstanceOf(t, "IntegerEntry")) |
---|
| 143 | + | then { |
---|
| 144 | + | let ag = t |
---|
| 145 | + | (ae :+ ag) |
---|
| 146 | + | } |
---|
| 147 | + | else ae |
---|
442 | | - | @Callable(aD) |
---|
443 | | - | func replenishWithTwoTokens (bZ) = valueOrElse(bs(), { |
---|
444 | | - | let bw = aD.payments[0].assetId |
---|
445 | | - | let bz = aD.payments[1].assetId |
---|
446 | | - | let bv = aD.payments[0].amount |
---|
447 | | - | let by = aD.payments[1].amount |
---|
448 | | - | let ca = aN(bw) |
---|
449 | | - | let bB = ca._1 |
---|
450 | | - | let bC = ca._2 |
---|
451 | | - | let bD = ca._3 |
---|
452 | | - | let cb = aN(bz) |
---|
453 | | - | let bF = cb._1 |
---|
454 | | - | let bG = cb._2 |
---|
455 | | - | let bH = cb._3 |
---|
456 | | - | let cc = if (if ((an == 0)) |
---|
457 | | - | then (ao == 0) |
---|
458 | | - | else false) |
---|
459 | | - | then true |
---|
460 | | - | else false |
---|
461 | | - | let cd = if (cc) |
---|
462 | | - | then fraction(fraction(aG, av, bv), au, fraction(aH, av, by)) |
---|
463 | | - | else fraction(fraction(an, av, bv), au, fraction(ao, av, by)) |
---|
464 | | - | let bK = ((bD + bH) / 2) |
---|
465 | | - | let ce = if (cc) |
---|
466 | | - | then fraction(pow(bv, bD, 5, 1, bD, DOWN), pow(by, bH, 5, 1, bH, DOWN), pow(10, 0, bK, 0, 0, DOWN)) |
---|
467 | | - | else fraction(min([fraction(bv, av, an), fraction(by, av, ao)]), aq, av) |
---|
468 | | - | if (if ((0 > bZ)) |
---|
469 | | - | then true |
---|
470 | | - | else (bZ > aw)) |
---|
471 | | - | then throw(((("Slippage tolerance must be between 0 and " + toString(aw)) + " inclusively. Actual: ") + toString(bZ))) |
---|
472 | | - | else if ((size(aD.payments) != 2)) |
---|
473 | | - | then throw("Two attached assets expected") |
---|
474 | | - | else if (if ((bw != ah)) |
---|
475 | | - | then true |
---|
476 | | - | else (bz != ai)) |
---|
477 | | - | then throw(((("Incorrect assets attached. Expected: " + af) + " and ") + ag)) |
---|
478 | | - | else if (if ((((au * (aw - bZ)) / aw) > cd)) |
---|
479 | | - | then true |
---|
480 | | - | else (cd > ((au * (aw + bZ)) / aw))) |
---|
481 | | - | then throw("Incorrect assets amount: amounts must have the contract ratio") |
---|
482 | | - | else if ((ce == 0)) |
---|
483 | | - | then throw("Too small amount to replenish") |
---|
484 | | - | else if (!(aM)) |
---|
485 | | - | then ([ScriptTransfer(aD.caller, bv, bw), ScriptTransfer(aD.caller, by, bz)] ++ br()) |
---|
486 | | - | else { |
---|
487 | | - | let bR = if (containsElement(X, bB)) |
---|
488 | | - | then invoke(this, "stakeUnstake", [true, bv, bB], nil) |
---|
489 | | - | else 0 |
---|
490 | | - | if ((bR == bR)) |
---|
491 | | - | then { |
---|
492 | | - | let bS = if (containsElement(X, bF)) |
---|
493 | | - | then invoke(this, "stakeUnstake", [true, by, bF], nil) |
---|
494 | | - | else 0 |
---|
495 | | - | if ((bS == bS)) |
---|
496 | | - | then [Reissue(ap, ce, true), IntegerEntry(f, (an + bv)), IntegerEntry(g, (ao + by)), IntegerEntry(k, (aq + ce)), ScriptTransfer(aD.caller, ce, ap)] |
---|
497 | | - | else throw("Strict value is not equal to itself.") |
---|
498 | | - | } |
---|
499 | | - | else throw("Strict value is not equal to itself.") |
---|
500 | | - | } |
---|
| 187 | + | func at (ar,as) = if ((as >= ao)) |
---|
| 188 | + | then ar |
---|
| 189 | + | else throw("List size exceeds 10") |
---|
| 190 | + | |
---|
| 191 | + | at(aq(aq(aq(aq(aq(aq(aq(aq(aq(aq(ap, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
| 192 | + | } |
---|
| 193 | + | let ab = am._1 |
---|
| 194 | + | let ac = am._2 |
---|
| 195 | + | let au = { |
---|
| 196 | + | let av = reentrantInvoke(C, ak, [aj.caller.bytes, al, ab, ac], nil) |
---|
| 197 | + | if ($isInstanceOf(av, "(List[Any], List[Any])")) |
---|
| 198 | + | then av |
---|
| 199 | + | else throw(($getType(av) + " couldn't be cast to (List[Any], List[Any])")) |
---|
| 200 | + | } |
---|
| 201 | + | if ((au == au)) |
---|
| 202 | + | then { |
---|
| 203 | + | let aw = au._2 |
---|
| 204 | + | let ax = au._1 |
---|
| 205 | + | let ay = { |
---|
| 206 | + | let an = aw |
---|
| 207 | + | let ao = size(an) |
---|
| 208 | + | let ap = nil |
---|
| 209 | + | func az (ar,as) = if ((as >= ao)) |
---|
| 210 | + | then ar |
---|
| 211 | + | else ah(ar, an[as]) |
---|
| 212 | + | |
---|
| 213 | + | func aA (ar,as) = if ((as >= ao)) |
---|
| 214 | + | then ar |
---|
| 215 | + | else throw("List size exceeds 10") |
---|
| 216 | + | |
---|
| 217 | + | aA(az(az(az(az(az(az(az(az(az(az(ap, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
| 218 | + | } |
---|
| 219 | + | let aB = { |
---|
| 220 | + | let an = ax |
---|
| 221 | + | let ao = size(an) |
---|
| 222 | + | let ap = nil |
---|
| 223 | + | func aC (ar,as) = if ((as >= ao)) |
---|
| 224 | + | then ar |
---|
| 225 | + | else ad(ar, an[as]) |
---|
| 226 | + | |
---|
| 227 | + | func aD (ar,as) = if ((as >= ao)) |
---|
| 228 | + | then ar |
---|
| 229 | + | else throw("List size exceeds 15") |
---|
| 230 | + | |
---|
| 231 | + | aD(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(aC(ap, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) |
---|
| 232 | + | } |
---|
| 233 | + | $Tuple2(aB, ay) |
---|
| 234 | + | } |
---|
| 235 | + | else throw("Strict value is not equal to itself.") |
---|
505 | | - | @Callable(aD) |
---|
506 | | - | func withdraw () = valueOrElse(bs(), { |
---|
507 | | - | let cf = $Tuple2(aD.payments[0].amount, aD.payments[0].assetId) |
---|
508 | | - | let bi = cf._1 |
---|
509 | | - | let cg = cf._2 |
---|
510 | | - | let ch = fraction(bi, an, aq) |
---|
511 | | - | let ci = fraction(bi, ao, aq) |
---|
512 | | - | if ((size(aD.payments) != 1)) |
---|
513 | | - | then throw("One attached payment expected") |
---|
514 | | - | else if ((cg != ap)) |
---|
515 | | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(ap))) |
---|
516 | | - | else if (!(aM)) |
---|
517 | | - | then ([ScriptTransfer(aD.caller, bi, cg)] ++ br()) |
---|
518 | | - | else { |
---|
519 | | - | let bR = if (containsElement(X, af)) |
---|
520 | | - | then invoke(this, "stakeUnstake", [false, ch, af], nil) |
---|
521 | | - | else 0 |
---|
522 | | - | if ((bR == bR)) |
---|
523 | | - | then { |
---|
524 | | - | let bS = if (containsElement(X, ag)) |
---|
525 | | - | then invoke(this, "stakeUnstake", [false, ci, ag], nil) |
---|
526 | | - | else 0 |
---|
527 | | - | if ((bS == bS)) |
---|
528 | | - | then [IntegerEntry(f, (an - ch)), IntegerEntry(g, (ao - ci)), IntegerEntry(k, (aq - bi)), Burn(ap, bi), ScriptTransfer(aD.caller, ch, ah), ScriptTransfer(aD.caller, ci, ai)] |
---|
529 | | - | else throw("Strict value is not equal to itself.") |
---|
530 | | - | } |
---|
531 | | - | else throw("Strict value is not equal to itself.") |
---|
532 | | - | } |
---|
533 | | - | }) |
---|
| 240 | + | @Callable(aj) |
---|
| 241 | + | func shutdown () = valueOrElse(K(aj.callerPublicKey), if (!(G)) |
---|
| 242 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, b), "the cause wasn't specified"))) |
---|
| 243 | + | else M("Paused by admin")) |
---|
537 | | - | @Callable(aD) |
---|
538 | | - | func exchange (bj) = valueOrElse(bs(), { |
---|
539 | | - | let cj = $Tuple2(aD.payments[0].amount, aD.payments[0].assetId) |
---|
540 | | - | let bi = cj._1 |
---|
541 | | - | let cg = cj._2 |
---|
542 | | - | if (if ((an == 0)) |
---|
543 | | - | then true |
---|
544 | | - | else (ao == 0)) |
---|
545 | | - | then throw("Can't exchange with zero balance") |
---|
546 | | - | else if ((0 >= bj)) |
---|
547 | | - | then throw(("Minimal amount to receive must be positive. Actual: " + toString(bj))) |
---|
548 | | - | else if ((size(aD.payments) != 1)) |
---|
549 | | - | then throw("One attached payment expected") |
---|
550 | | - | else if (!(aM)) |
---|
551 | | - | then ([ScriptTransfer(aD.caller, bi, cg)] ++ br()) |
---|
552 | | - | else if ((cg == ah)) |
---|
553 | | - | then { |
---|
554 | | - | let ck = ai |
---|
555 | | - | let cl = bh(bi, bj, an, ao, aD.originCaller) |
---|
556 | | - | let bn = cl._1 |
---|
557 | | - | let bp = cl._2 |
---|
558 | | - | let bq = cl._3 |
---|
559 | | - | let cm = (an + bi) |
---|
560 | | - | let cn = ((ao - bp) - bq) |
---|
561 | | - | let bR = if (containsElement(X, af)) |
---|
562 | | - | then invoke(this, "stakeUnstake", [true, bi, af], nil) |
---|
563 | | - | else 0 |
---|
564 | | - | if ((bR == bR)) |
---|
565 | | - | then { |
---|
566 | | - | let bS = if (containsElement(X, ag)) |
---|
567 | | - | then invoke(this, "stakeUnstake", [false, (bp + bq), ag], nil) |
---|
568 | | - | else 0 |
---|
569 | | - | if ((bS == bS)) |
---|
570 | | - | then $Tuple2([IntegerEntry(f, cm), IntegerEntry(g, cn), ScriptTransfer(aD.caller, bp, ck), ScriptTransfer(R, bq, ck)], $Tuple2(bp, ck)) |
---|
571 | | - | else throw("Strict value is not equal to itself.") |
---|
572 | | - | } |
---|
573 | | - | else throw("Strict value is not equal to itself.") |
---|
574 | | - | } |
---|
575 | | - | else if ((cg == ai)) |
---|
576 | | - | then { |
---|
577 | | - | let ck = ah |
---|
578 | | - | let co = bh(bi, bj, ao, an, aD.originCaller) |
---|
579 | | - | let bn = co._1 |
---|
580 | | - | let bp = co._2 |
---|
581 | | - | let bq = co._3 |
---|
582 | | - | let cm = ((an - bp) - bq) |
---|
583 | | - | let cn = (ao + bi) |
---|
584 | | - | let bR = if (containsElement(X, af)) |
---|
585 | | - | then invoke(this, "stakeUnstake", [false, (bp + bq), af], nil) |
---|
586 | | - | else 0 |
---|
587 | | - | if ((bR == bR)) |
---|
588 | | - | then { |
---|
589 | | - | let bS = if (containsElement(X, ag)) |
---|
590 | | - | then invoke(this, "stakeUnstake", [true, bi, ag], nil) |
---|
591 | | - | else 0 |
---|
592 | | - | if ((bS == bS)) |
---|
593 | | - | then $Tuple2([IntegerEntry(f, cm), IntegerEntry(g, cn), ScriptTransfer(aD.caller, bp, ck), ScriptTransfer(R, bq, ck)], $Tuple2(bp, ck)) |
---|
594 | | - | else throw("Strict value is not equal to itself.") |
---|
595 | | - | } |
---|
596 | | - | else throw("Strict value is not equal to itself.") |
---|
597 | | - | } |
---|
598 | | - | else throw(((("Incorrect asset attached. Expected: " + af) + " or ") + ag)) |
---|
599 | | - | }) |
---|
| 247 | + | @Callable(aj) |
---|
| 248 | + | func activate () = valueOrElse(K(aj.callerPublicKey), if (G) |
---|
| 249 | + | then throw("DApp is already active") |
---|
| 250 | + | else [BooleanEntry(a, true), DeleteEntry(b)]) |
---|
603 | | - | @Callable(aD) |
---|
604 | | - | func shutdown () = if (!(ae)) |
---|
605 | | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, m), "the cause wasn't specified"))) |
---|
606 | | - | else if (!(containsElement([N, O, P], aD.callerPublicKey))) |
---|
607 | | - | then throw("Only admin can call this function") |
---|
608 | | - | else aS("Paused by admin") |
---|
| 254 | + | @Callable(aj) |
---|
| 255 | + | func stakeUnstake (P,S,aE) = valueOrElse(I(aj.caller), valueOrElse(H(), if ((aj.caller != C)) |
---|
| 256 | + | then throw("Only global Contract can invoke this function") |
---|
| 257 | + | else if ((aE == "WAVES")) |
---|
| 258 | + | then { |
---|
| 259 | + | let aF = addressFromStringValue(valueOrErrorMessage(getString(q, e), "No leasing pool in oracle")) |
---|
| 260 | + | let aG = getBinary(this, g) |
---|
| 261 | + | let aH = valueOrElse(getInteger(this, f), 0) |
---|
| 262 | + | let aI = if (P) |
---|
| 263 | + | then (aH + S) |
---|
| 264 | + | else (aH - S) |
---|
| 265 | + | let aJ = Lease(aF, aI) |
---|
| 266 | + | let aK = calculateLeaseId(aJ) |
---|
| 267 | + | let aL = [aJ, BinaryEntry(g, aK), IntegerEntry(f, aI)] |
---|
| 268 | + | let t = aG |
---|
| 269 | + | if ($isInstanceOf(t, "ByteVector")) |
---|
| 270 | + | then { |
---|
| 271 | + | let aM = t |
---|
| 272 | + | ([LeaseCancel(aM)] ++ aL) |
---|
| 273 | + | } |
---|
| 274 | + | else aL |
---|
| 275 | + | } |
---|
| 276 | + | else { |
---|
| 277 | + | let aN = R(P, S, fromBase58String(aE)) |
---|
| 278 | + | let U = aN._1 |
---|
| 279 | + | let aO = aN._2 |
---|
| 280 | + | let aP = aN._3 |
---|
| 281 | + | let aQ = aN._4 |
---|
| 282 | + | let aR = invoke(aO, U, aP, aQ) |
---|
| 283 | + | if ((aR == aR)) |
---|
| 284 | + | then nil |
---|
| 285 | + | else throw("Strict value is not equal to itself.") |
---|
| 286 | + | })) |
---|
620 | | - | |
---|
621 | | - | @Callable(aD) |
---|
622 | | - | func takeIntoAccountExtraFunds () = valueOrElse(bs(), { |
---|
623 | | - | let cp = (aK - an) |
---|
624 | | - | let cq = (aL - ao) |
---|
625 | | - | if ((aD.caller != R)) |
---|
626 | | - | then throw("Only the wallet can call this function") |
---|
627 | | - | else if (if ((0 > cp)) |
---|
628 | | - | then true |
---|
629 | | - | else (0 > cq)) |
---|
630 | | - | then aS("Enroll amount negative") |
---|
631 | | - | else if (if ((cp == 0)) |
---|
632 | | - | then (cq == 0) |
---|
633 | | - | else false) |
---|
634 | | - | then throw("No money to take") |
---|
635 | | - | else { |
---|
636 | | - | let bR = if (containsElement(X, af)) |
---|
637 | | - | then invoke(this, "stakeUnstake", [true, cp, af], nil) |
---|
638 | | - | else 0 |
---|
639 | | - | if ((bR == bR)) |
---|
640 | | - | then { |
---|
641 | | - | let bS = if (containsElement(X, ag)) |
---|
642 | | - | then invoke(this, "stakeUnstake", [true, cq, ag], nil) |
---|
643 | | - | else 0 |
---|
644 | | - | if ((bS == bS)) |
---|
645 | | - | then [IntegerEntry(f, (an + cp)), IntegerEntry(g, (ao + cq)), IntegerEntry(("last_income_" + af), cp), IntegerEntry(("last_income_" + ag), cq)] |
---|
646 | | - | else throw("Strict value is not equal to itself.") |
---|
647 | | - | } |
---|
648 | | - | else throw("Strict value is not equal to itself.") |
---|
649 | | - | } |
---|
650 | | - | }) |
---|
651 | | - | |
---|
652 | | - | |
---|
653 | | - | |
---|
654 | | - | @Callable(aD) |
---|
655 | | - | func stakeUnstake (aV,aX,cr) = if ((aD.caller != this)) |
---|
656 | | - | then throw("Only contract itself can invoke this function") |
---|
657 | | - | else if ((cr == "WAVES")) |
---|
658 | | - | then { |
---|
659 | | - | let cs = addressFromStringValue(valueOrErrorMessage(getString(H, v), "No leasing pool in oracle")) |
---|
660 | | - | let ct = getBinary(this, x) |
---|
661 | | - | let cu = valueOrElse(getInteger(this, w), 0) |
---|
662 | | - | let cv = if (aV) |
---|
663 | | - | then (cu + aX) |
---|
664 | | - | else (cu - aX) |
---|
665 | | - | let cw = Lease(cs, cv) |
---|
666 | | - | let cx = calculateLeaseId(cw) |
---|
667 | | - | let cy = [cw, BinaryEntry(x, cx), IntegerEntry(w, cv)] |
---|
668 | | - | let K = ct |
---|
669 | | - | if ($isInstanceOf(K, "ByteVector")) |
---|
670 | | - | then { |
---|
671 | | - | let cz = K |
---|
672 | | - | ([LeaseCancel(cz)] ++ cy) |
---|
673 | | - | } |
---|
674 | | - | else cy |
---|
675 | | - | } |
---|
676 | | - | else { |
---|
677 | | - | let cA = aW(aV, aX, fromBase58String(cr)) |
---|
678 | | - | let aZ = cA._1 |
---|
679 | | - | let cB = cA._2 |
---|
680 | | - | let cC = cA._3 |
---|
681 | | - | let cD = cA._4 |
---|
682 | | - | let cE = invoke(cB, aZ, cC, cD) |
---|
683 | | - | if ((cE == cE)) |
---|
684 | | - | then nil |
---|
685 | | - | else throw("Strict value is not equal to itself.") |
---|
686 | | - | } |
---|
687 | | - | |
---|
688 | | - | |
---|
689 | | - | |
---|
690 | | - | @Callable(aD) |
---|
691 | | - | func stakeAll () = valueOrElse(bs(), if (!(containsElement([N, O, P], aD.callerPublicKey))) |
---|
692 | | - | then throw("Only admin can call this function") |
---|
693 | | - | else { |
---|
694 | | - | let bR = if (containsElement(X, af)) |
---|
695 | | - | then { |
---|
696 | | - | let cF = (an - aE) |
---|
697 | | - | if ((cF > 0)) |
---|
698 | | - | then invoke(this, "stakeUnstake", [true, cF, af], nil) |
---|
699 | | - | else 0 |
---|
700 | | - | } |
---|
701 | | - | else 0 |
---|
702 | | - | if ((bR == bR)) |
---|
703 | | - | then { |
---|
704 | | - | let bS = if (containsElement(X, ag)) |
---|
705 | | - | then { |
---|
706 | | - | let cG = (ao - aF) |
---|
707 | | - | if ((cG > 0)) |
---|
708 | | - | then invoke(this, "stakeUnstake", [true, cG, ag], nil) |
---|
709 | | - | else 0 |
---|
710 | | - | } |
---|
711 | | - | else 0 |
---|
712 | | - | if ((bS == bS)) |
---|
713 | | - | then nil |
---|
714 | | - | else throw("Strict value is not equal to itself.") |
---|
715 | | - | } |
---|
716 | | - | else throw("Strict value is not equal to itself.") |
---|
717 | | - | }) |
---|
718 | | - | |
---|
719 | | - | |
---|
720 | | - | @Verifier(cH) |
---|
721 | | - | func cI () = { |
---|
722 | | - | let cJ = { |
---|
723 | | - | let cK = if (sigVerify(cH.bodyBytes, cH.proofs[0], N)) |
---|
| 297 | + | @Verifier(aT) |
---|
| 298 | + | func aU () = { |
---|
| 299 | + | let aV = { |
---|
| 300 | + | let aW = if (sigVerify(aT.bodyBytes, aT.proofs[0], w)) |
---|