1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = 100000000 |
---|
5 | | - | |
---|
6 | | - | let b = toBigInt(100000000) |
---|
7 | | - | |
---|
8 | | - | let c = toBigInt(1000000000000000000) |
---|
9 | | - | |
---|
10 | | - | let d = toBigInt(0) |
---|
11 | | - | |
---|
12 | | - | let e = toBigInt(0) |
---|
13 | | - | |
---|
14 | | - | let f = toBigInt(1) |
---|
15 | | - | |
---|
16 | | - | let g = toBigInt(2) |
---|
17 | | - | |
---|
18 | | - | let h = toBigInt(3) |
---|
19 | | - | |
---|
20 | | - | let i = toBigInt(4) |
---|
21 | | - | |
---|
22 | | - | let j = "WAVES" |
---|
23 | | - | |
---|
24 | | - | let k = 50 |
---|
25 | | - | |
---|
26 | | - | let l = "100" |
---|
27 | | - | |
---|
28 | | - | let m = "__" |
---|
29 | | - | |
---|
30 | | - | let n = 2 |
---|
31 | | - | |
---|
32 | | - | let o = 3 |
---|
33 | | - | |
---|
34 | | - | let p = 4 |
---|
35 | | - | |
---|
36 | | - | let q = 1 |
---|
37 | | - | |
---|
38 | | - | let r = 2 |
---|
39 | | - | |
---|
40 | | - | let s = 3 |
---|
41 | | - | |
---|
42 | | - | let t = 4 |
---|
43 | | - | |
---|
44 | | - | let u = 5 |
---|
45 | | - | |
---|
46 | | - | let v = 6 |
---|
47 | | - | |
---|
48 | | - | let w = 7 |
---|
49 | | - | |
---|
50 | | - | let x = 1 |
---|
51 | | - | |
---|
52 | | - | let y = 6 |
---|
53 | | - | |
---|
54 | | - | let z = 7 |
---|
55 | | - | |
---|
56 | | - | let A = fraction(10, a, 10000) |
---|
57 | | - | |
---|
58 | | - | func B (C,D) = fraction(toBigInt(C), c, toBigInt(D)) |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func E (C,D) = fraction(C, c, D) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func F (G,H) = toInt(fraction(G, toBigInt(H), c)) |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func I (G,H,J) = toInt(fraction(G, toBigInt(H), c, J)) |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | func K (G) = if ((d > G)) |
---|
71 | | - | then -(G) |
---|
72 | | - | else G |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | func L (G) = if ((d > G)) |
---|
76 | | - | then -(G) |
---|
77 | | - | else G |
---|
78 | | - | |
---|
79 | | - | |
---|
80 | | - | func M () = "%s__factoryContract" |
---|
81 | | - | |
---|
82 | | - | |
---|
83 | | - | func N () = "%s__managerPublicKey" |
---|
84 | | - | |
---|
85 | | - | |
---|
86 | | - | func O () = "%s__pendingManagerPublicKey" |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | func P () = "%s%s__price__last" |
---|
90 | | - | |
---|
91 | | - | |
---|
92 | | - | func Q (R,S) = makeString(["%s%s%d%d__price__history", toString(R), toString(S)], m) |
---|
93 | | - | |
---|
94 | | - | |
---|
95 | | - | func T (U,V) = ((("%s%s%s__P__" + U) + "__") + V) |
---|
96 | | - | |
---|
97 | | - | |
---|
98 | | - | func W (U,V) = ((("%s%s%s__G__" + U) + "__") + V) |
---|
99 | | - | |
---|
100 | | - | |
---|
101 | | - | func X () = "%s__amountAsset" |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | func Y () = "%s__priceAsset" |
---|
105 | | - | |
---|
106 | | - | |
---|
107 | | - | func Z () = "%s__amp" |
---|
108 | | - | |
---|
109 | | - | |
---|
110 | | - | func aa (ab) = ("%s%d__amp__" + toString(ab)) |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | func ac () = "%s__changeAmpLastCall" |
---|
114 | | - | |
---|
115 | | - | |
---|
116 | | - | let ad = "%s__fee" |
---|
117 | | - | |
---|
118 | | - | let ae = valueOrElse(getInteger(this, ad), A) |
---|
119 | | - | |
---|
120 | | - | let af = makeString(["%s", "dLp"], m) |
---|
121 | | - | |
---|
122 | | - | let ag = makeString(["%s", "dLpRefreshedHeight"], m) |
---|
123 | | - | |
---|
124 | | - | let ah = makeString(["%s", "refreshDLpDelay"], m) |
---|
125 | | - | |
---|
126 | | - | let ai = 30 |
---|
127 | | - | |
---|
128 | | - | let aj = valueOrElse(getInteger(this, ah), ai) |
---|
129 | | - | |
---|
130 | | - | func ak () = "%s__factoryConfig" |
---|
131 | | - | |
---|
132 | | - | |
---|
133 | | - | func al () = "%s%s__matcher__publicKey" |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | func am (an,ao) = (((("%d%d%s__" + an) + "__") + ao) + "__config") |
---|
137 | | - | |
---|
138 | | - | |
---|
139 | | - | func ap (aq) = ("%s%s%s__mappings__baseAsset2internalId__" + aq) |
---|
140 | | - | |
---|
141 | | - | |
---|
142 | | - | func ar () = "%s__shutdown" |
---|
143 | | - | |
---|
144 | | - | |
---|
145 | | - | func as () = "%s__allowedLpStableScriptHash" |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | func at () = "%s__feeCollectorAddress" |
---|
149 | | - | |
---|
150 | | - | |
---|
151 | | - | func au (av) = ("%s%s__skipOrderValidation__" + av) |
---|
152 | | - | |
---|
153 | | - | |
---|
154 | | - | func aw (ax,ay,az,aA) = throw((((((((("order validation failed: orderValid=" + toString(ax)) + " (") + ay) + ")") + " senderValid=") + toString(az)) + " matcherValid=") + toString(aA))) |
---|
155 | | - | |
---|
156 | | - | |
---|
157 | | - | func aB (aC,aD) = valueOrErrorMessage(getString(aC, aD), makeString(["mandatory ", toString(aC), ".", aD, " not defined"], "")) |
---|
158 | | - | |
---|
159 | | - | |
---|
160 | | - | func aE (aC,aD) = valueOrErrorMessage(getInteger(aC, aD), makeString(["mandatory ", toString(aC), ".", aD, " not defined"], "")) |
---|
161 | | - | |
---|
162 | | - | |
---|
163 | | - | func aF (aG) = throw(makeString(["lp_stable.ride:", aG], " ")) |
---|
164 | | - | |
---|
165 | | - | |
---|
166 | | - | func aH (aG) = makeString(["lp_stable.ride:", aG], " ") |
---|
167 | | - | |
---|
168 | | - | |
---|
169 | | - | let aI = addressFromStringValue(aB(this, M())) |
---|
170 | | - | |
---|
171 | | - | let aJ = { |
---|
172 | | - | let aK = invoke(aI, "getInFeeREADONLY", [toString(this)], nil) |
---|
173 | | - | if ($isInstanceOf(aK, "Int")) |
---|
174 | | - | then aK |
---|
175 | | - | else throw(($getType(aK) + " couldn't be cast to Int")) |
---|
176 | | - | } |
---|
177 | | - | |
---|
178 | | - | let aL = { |
---|
179 | | - | let aK = invoke(aI, "getOutFeeREADONLY", [toString(this)], nil) |
---|
180 | | - | if ($isInstanceOf(aK, "Int")) |
---|
181 | | - | then aK |
---|
182 | | - | else throw(($getType(aK) + " couldn't be cast to Int")) |
---|
183 | | - | } |
---|
184 | | - | |
---|
185 | | - | let aM = aB(this, Z()) |
---|
186 | | - | |
---|
187 | | - | func aN () = valueOrElse(getBoolean(aI, ar()), false) |
---|
188 | | - | |
---|
189 | | - | |
---|
190 | | - | func aO () = fromBase58String(aB(aI, al())) |
---|
191 | | - | |
---|
192 | | - | |
---|
193 | | - | let aP = addressFromStringValue(aB(aI, at())) |
---|
194 | | - | |
---|
195 | | - | func aQ () = { |
---|
196 | | - | let aR = aB(this, X()) |
---|
197 | | - | let aS = aB(this, Y()) |
---|
198 | | - | let aT = aE(aI, ap(aS)) |
---|
199 | | - | let an = aE(aI, ap(aR)) |
---|
200 | | - | split(aB(aI, am(toString(an), toString(aT))), m) |
---|
201 | | - | } |
---|
202 | | - | |
---|
203 | | - | |
---|
204 | | - | func aU (aV) = if ((aV == j)) |
---|
205 | | - | then unit |
---|
206 | | - | else fromBase58String(aV) |
---|
207 | | - | |
---|
208 | | - | |
---|
209 | | - | func aW (aV) = if ((aV == unit)) |
---|
210 | | - | then j |
---|
211 | | - | else toBase58String(value(aV)) |
---|
212 | | - | |
---|
213 | | - | |
---|
214 | | - | func aX (aY) = $Tuple7(addressFromStringValue(aY[q]), parseIntValue(aY[r]), fromBase58String(aY[s]), aU(aY[t]), aU(aY[u]), parseIntValue(aY[v]), parseIntValue(aY[w])) |
---|
215 | | - | |
---|
216 | | - | |
---|
217 | | - | let aZ = aX(aQ()) |
---|
218 | | - | |
---|
219 | | - | let ba = aZ |
---|
220 | | - | |
---|
221 | | - | let bb = ba._2 |
---|
222 | | - | |
---|
223 | | - | let bc = ba._3 |
---|
224 | | - | |
---|
225 | | - | let bd = ba._4 |
---|
226 | | - | |
---|
227 | | - | let be = ba._5 |
---|
228 | | - | |
---|
229 | | - | let bf = ba._6 |
---|
230 | | - | |
---|
231 | | - | let bg = ba._7 |
---|
232 | | - | |
---|
233 | | - | func bh () = split(aB(aI, ak()), m) |
---|
234 | | - | |
---|
235 | | - | |
---|
236 | | - | let bi = bh() |
---|
237 | | - | |
---|
238 | | - | let bj = valueOrErrorMessage(addressFromString(bi[x]), "Invalid staking contract address") |
---|
239 | | - | |
---|
240 | | - | let bk = valueOrErrorMessage(addressFromString(bi[y]), "Invalid gwx contract address") |
---|
241 | | - | |
---|
242 | | - | func bl (bm,bn,bo,bp,bq,br,bs,bt,bu,bv) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(bm), toString(bn), toString(bo), toString(bp), toString(bq), toString(br), toString(bs), toString(bt), toString(bu), toString(bv)], m) |
---|
243 | | - | |
---|
244 | | - | |
---|
245 | | - | func bw (bx,by,bz,bp,bs,bt) = makeString(["%d%d%d%d%d%d", toString(bx), toString(by), toString(bz), toString(bp), toString(bs), toString(bt)], m) |
---|
246 | | - | |
---|
247 | | - | |
---|
248 | | - | func bA (bB) = if ((bB == "WAVES")) |
---|
249 | | - | then wavesBalance(this).available |
---|
250 | | - | else assetBalance(this, fromBase58String(bB)) |
---|
251 | | - | |
---|
252 | | - | |
---|
253 | | - | func bC (bD,bE) = fraction(bD, c, bE) |
---|
254 | | - | |
---|
255 | | - | |
---|
256 | | - | func bF (bD,bE,J) = fraction(bD, c, bE, J) |
---|
257 | | - | |
---|
258 | | - | |
---|
259 | | - | func bG (bH,bI,bJ,bK) = { |
---|
260 | | - | let bL = B(bJ, bH) |
---|
261 | | - | let bM = B(bK, bI) |
---|
262 | | - | bC(bM, bL) |
---|
263 | | - | } |
---|
264 | | - | |
---|
265 | | - | |
---|
266 | | - | func bN (bJ,bK,bO) = { |
---|
267 | | - | let bP = bf |
---|
268 | | - | let bQ = bg |
---|
269 | | - | let bR = bG(bP, bQ, bJ, bK) |
---|
270 | | - | let bE = B(bJ, bP) |
---|
271 | | - | let bD = B(bK, bQ) |
---|
272 | | - | let bS = B(bO, a) |
---|
273 | | - | let bT = bC(bE, bS) |
---|
274 | | - | let bU = bC(bD, bS) |
---|
275 | | - | [bR, bT, bU] |
---|
276 | | - | } |
---|
277 | | - | |
---|
278 | | - | |
---|
279 | | - | func bV (bW,ae) = { |
---|
280 | | - | let bX = if ((ae == 0)) |
---|
281 | | - | then 0 |
---|
282 | | - | else fraction(bW, ae, a) |
---|
283 | | - | $Tuple2((bW - bX), bX) |
---|
284 | | - | } |
---|
285 | | - | |
---|
286 | | - | |
---|
287 | | - | func bY (bZ) = { |
---|
288 | | - | let ca = bZ[0] |
---|
289 | | - | let cb = bZ[1] |
---|
290 | | - | let cc = (ca + cb) |
---|
291 | | - | if ((cc == e)) |
---|
292 | | - | then e |
---|
293 | | - | else { |
---|
294 | | - | let cd = parseIntValue(aM) |
---|
295 | | - | let ce = (cd * 2) |
---|
296 | | - | let cf = fraction(ca, cb, f) |
---|
297 | | - | let cg = fraction(cf, i, f) |
---|
298 | | - | let ch = fraction(toBigInt(ce), cc, f) |
---|
299 | | - | let ci = toBigInt((ce - 1)) |
---|
300 | | - | func cj (ck) = { |
---|
301 | | - | let cl = fraction(ck, ck, f) |
---|
302 | | - | let cm = fraction(cl, ck, f) |
---|
303 | | - | let cn = fraction(cm, f, cg) |
---|
304 | | - | fraction((ch + fraction(cn, g, f)), ck, (fraction(ci, ck, f) + fraction(h, cn, f))) |
---|
305 | | - | } |
---|
306 | | - | |
---|
307 | | - | func co (cp,cq) = if (cp._2) |
---|
308 | | - | then cp |
---|
309 | | - | else { |
---|
310 | | - | let ck = cp._1 |
---|
311 | | - | let cr = cj(ck) |
---|
312 | | - | let cs = (cr - value(ck)) |
---|
313 | | - | let ct = if ((e > cs)) |
---|
314 | | - | then -(cs) |
---|
315 | | - | else cs |
---|
316 | | - | if ((f >= ct)) |
---|
317 | | - | then $Tuple2(cr, true) |
---|
318 | | - | else $Tuple2(cr, false) |
---|
319 | | - | } |
---|
320 | | - | |
---|
321 | | - | let cu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] |
---|
322 | | - | let cv = { |
---|
323 | | - | let cw = cu |
---|
324 | | - | let cx = size(cw) |
---|
325 | | - | let cy = $Tuple2(cc, false) |
---|
326 | | - | func cz (cA,cB) = if ((cB >= cx)) |
---|
327 | | - | then cA |
---|
328 | | - | else co(cA, cw[cB]) |
---|
329 | | - | |
---|
330 | | - | func cC (cA,cB) = if ((cB >= cx)) |
---|
331 | | - | then cA |
---|
332 | | - | else throw("List size exceeds 17") |
---|
333 | | - | |
---|
334 | | - | cC(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cy, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) |
---|
335 | | - | } |
---|
336 | | - | let ck = cv._1 |
---|
337 | | - | let cD = cv._2 |
---|
338 | | - | if (cD) |
---|
339 | | - | then ck |
---|
340 | | - | else throw(("D calculation error, D = " + toString(ck))) |
---|
341 | | - | } |
---|
342 | | - | } |
---|
343 | | - | |
---|
344 | | - | |
---|
345 | | - | func cE (cF,cG,cH,cI) = { |
---|
346 | | - | let cJ = bc |
---|
347 | | - | let cK = toBase58String(value(bd)) |
---|
348 | | - | let cL = toBase58String(value(be)) |
---|
349 | | - | let cM = bf |
---|
350 | | - | let cN = bg |
---|
351 | | - | let cO = toString(bb) |
---|
352 | | - | let cP = valueOrErrorMessage(assetInfo(cJ), "Wrong LP id").quantity |
---|
353 | | - | if ((toBase58String(cJ) != cG)) |
---|
354 | | - | then throw("Wrong pmt asset") |
---|
355 | | - | else { |
---|
356 | | - | let cQ = bA(cK) |
---|
357 | | - | let cR = B(cQ, cM) |
---|
358 | | - | let cS = bA(cL) |
---|
359 | | - | let cT = B(cS, cN) |
---|
360 | | - | let cU = bC(cT, cR) |
---|
361 | | - | let cV = F(cU, a) |
---|
362 | | - | let cW = B(cH, a) |
---|
363 | | - | let cX = B(cP, a) |
---|
364 | | - | let cY = fraction(cR, cW, cX) |
---|
365 | | - | let cZ = fraction(cT, cW, cX) |
---|
366 | | - | let da = I(cY, cM, FLOOR) |
---|
367 | | - | let db = I(cZ, cN, FLOOR) |
---|
368 | | - | let dc = if ((cF == "")) |
---|
369 | | - | then nil |
---|
370 | | - | else [ScriptTransfer(cI, da, if ((cK == "WAVES")) |
---|
371 | | - | then unit |
---|
372 | | - | else fromBase58String(cK)), ScriptTransfer(cI, db, if ((cL == "WAVES")) |
---|
373 | | - | then unit |
---|
374 | | - | else fromBase58String(cL)), StringEntry(W(toString(cI), cF), bw(da, db, cH, cV, height, lastBlock.timestamp)), IntegerEntry(P(), cV), IntegerEntry(Q(height, lastBlock.timestamp), cV)] |
---|
375 | | - | $Tuple10(da, db, cK, cL, cQ, cS, cP, cU, cO, dc) |
---|
376 | | - | } |
---|
377 | | - | } |
---|
378 | | - | |
---|
379 | | - | |
---|
380 | | - | func dd (cF,de,df,dg,dh,di,cI,dj,dk,dl,dm,dn,do) = { |
---|
381 | | - | let cJ = bc |
---|
382 | | - | let dp = toBase58String(value(bd)) |
---|
383 | | - | let dq = toBase58String(value(be)) |
---|
384 | | - | let dr = bf |
---|
385 | | - | let ds = bg |
---|
386 | | - | let cO = toString(bb) |
---|
387 | | - | let dt = valueOrErrorMessage(assetInfo(cJ), "Wr lp as").quantity |
---|
388 | | - | let cQ = if (dj) |
---|
389 | | - | then bA(dp) |
---|
390 | | - | else if (if (dl) |
---|
391 | | - | then (do == dp) |
---|
392 | | - | else false) |
---|
393 | | - | then (bA(dp) - dn) |
---|
394 | | - | else if (dl) |
---|
395 | | - | then bA(dp) |
---|
396 | | - | else (bA(dp) - df) |
---|
397 | | - | let cS = if (dj) |
---|
398 | | - | then bA(dq) |
---|
399 | | - | else if (if (dl) |
---|
400 | | - | then (do == dq) |
---|
401 | | - | else false) |
---|
402 | | - | then (bA(dq) - dn) |
---|
403 | | - | else if (dl) |
---|
404 | | - | then bA(dq) |
---|
405 | | - | else (bA(dq) - dh) |
---|
406 | | - | let du = B(df, dr) |
---|
407 | | - | let dv = B(dh, ds) |
---|
408 | | - | let dw = bC(dv, du) |
---|
409 | | - | let cR = B(cQ, dr) |
---|
410 | | - | let cT = B(cS, ds) |
---|
411 | | - | let dx = bY([cR, cT]) |
---|
412 | | - | let dy = if ((dt == 0)) |
---|
413 | | - | then { |
---|
414 | | - | let dz = bY([(cR + du), (cT + dv)]) |
---|
415 | | - | let dA = if ((dz > dx)) |
---|
416 | | - | then true |
---|
417 | | - | else throw("D1 should be greater than D0") |
---|
418 | | - | if ((dA == dA)) |
---|
419 | | - | then { |
---|
420 | | - | let cU = d |
---|
421 | | - | let dB = d |
---|
422 | | - | let bS = dz |
---|
423 | | - | $Tuple5(F(bS, a), F(du, dr), F(dv, ds), bC((cT + dv), (cR + du)), dB) |
---|
424 | | - | } |
---|
425 | | - | else throw("Strict value is not equal to itself.") |
---|
426 | | - | } |
---|
427 | | - | else { |
---|
428 | | - | let cU = bC(cT, cR) |
---|
429 | | - | let dC = fraction(K((cU - dw)), c, cU) |
---|
430 | | - | let dB = B(de, a) |
---|
431 | | - | if (if (if (dm) |
---|
432 | | - | then (cU != d) |
---|
433 | | - | else false) |
---|
434 | | - | then (dC > dB) |
---|
435 | | - | else false) |
---|
436 | | - | then throw(((("Price slippage " + toString(dC)) + " > ") + toString(dB))) |
---|
437 | | - | else { |
---|
438 | | - | let dD = B(dt, a) |
---|
439 | | - | let dE = fraction(du, bF(cT, cR, CEILING), c, CEILING) |
---|
440 | | - | let dF = fraction(dv, c, bF(cT, cR, FLOOR), CEILING) |
---|
441 | | - | let dG = if ((dE > dv)) |
---|
442 | | - | then $Tuple2(dF, dv) |
---|
443 | | - | else $Tuple2(du, dE) |
---|
444 | | - | let dH = dG._1 |
---|
445 | | - | let dI = dG._2 |
---|
446 | | - | let dz = bY([(cR + dH), (cT + dI)]) |
---|
447 | | - | let dA = if ((dz > dx)) |
---|
448 | | - | then true |
---|
449 | | - | else throw("D1 should be greater than D0") |
---|
450 | | - | if ((dA == dA)) |
---|
451 | | - | then { |
---|
452 | | - | let bS = fraction(dD, (dz - dx), dx) |
---|
453 | | - | $Tuple5(I(bS, a, FLOOR), I(dH, dr, CEILING), I(dI, ds, CEILING), cU, dB) |
---|
454 | | - | } |
---|
455 | | - | else throw("Strict value is not equal to itself.") |
---|
456 | | - | } |
---|
457 | | - | } |
---|
458 | | - | let dJ = dy._1 |
---|
459 | | - | let dK = dy._2 |
---|
460 | | - | let dL = dy._3 |
---|
461 | | - | let cV = F(dy._4, a) |
---|
462 | | - | let dM = F(dy._5, a) |
---|
463 | | - | if ((0 >= dJ)) |
---|
464 | | - | then throw("LP <= 0") |
---|
465 | | - | else { |
---|
466 | | - | let dN = if (!(dk)) |
---|
467 | | - | then 0 |
---|
468 | | - | else dJ |
---|
469 | | - | let dO = (df - dK) |
---|
470 | | - | let dP = (dh - dL) |
---|
471 | | - | let dQ = if (if (dl) |
---|
472 | | - | then (do == dp) |
---|
473 | | - | else false) |
---|
474 | | - | then $Tuple2(dn, 0) |
---|
475 | | - | else if (if (dl) |
---|
476 | | - | then (do == dq) |
---|
477 | | - | else false) |
---|
478 | | - | then $Tuple2(0, dn) |
---|
479 | | - | else $Tuple2(dK, dL) |
---|
480 | | - | let dR = dQ._1 |
---|
481 | | - | let dS = dQ._2 |
---|
482 | | - | let dT = [IntegerEntry(P(), cV), IntegerEntry(Q(height, lastBlock.timestamp), cV), StringEntry(T(cI, cF), bl(dR, dS, dN, cV, de, dM, height, lastBlock.timestamp, dO, dP))] |
---|
483 | | - | $Tuple13(dJ, dN, cV, cQ, cS, dt, cJ, cO, dT, dO, dP, dg, di) |
---|
484 | | - | } |
---|
485 | | - | } |
---|
486 | | - | |
---|
487 | | - | |
---|
488 | | - | func dU (bZ,cq,dV) = { |
---|
489 | | - | let dW = g |
---|
490 | | - | let dX = bZ[if ((cq == 0)) |
---|
491 | | - | then 1 |
---|
492 | | - | else 0] |
---|
493 | | - | let dY = parseBigIntValue(l) |
---|
494 | | - | let cd = (parseBigIntValue(aM) * dY) |
---|
495 | | - | let cc = dX |
---|
496 | | - | let ce = (cd * dW) |
---|
497 | | - | let dZ = (((((dV * dV) / (dX * dW)) * dV) * dY) / (ce * dW)) |
---|
498 | | - | let ea = ((cc + ((dV * dY) / ce)) - dV) |
---|
499 | | - | func co (cp,eb) = { |
---|
500 | | - | let ec = cp |
---|
501 | | - | let ed = ec._1 |
---|
502 | | - | let cD = ec._2 |
---|
503 | | - | if ((cD != unit)) |
---|
504 | | - | then cp |
---|
505 | | - | else { |
---|
506 | | - | let ee = (((ed * ed) + dZ) / ((g * ed) + ea)) |
---|
507 | | - | let ef = L((ee - value(ed))) |
---|
508 | | - | if ((f >= ef)) |
---|
509 | | - | then $Tuple2(ee, eb) |
---|
510 | | - | else $Tuple2(ee, unit) |
---|
511 | | - | } |
---|
512 | | - | } |
---|
513 | | - | |
---|
514 | | - | let cu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] |
---|
515 | | - | let eg = { |
---|
516 | | - | let cw = cu |
---|
517 | | - | let cx = size(cw) |
---|
518 | | - | let cy = $Tuple2(dV, unit) |
---|
519 | | - | func cz (cA,cB) = if ((cB >= cx)) |
---|
520 | | - | then cA |
---|
521 | | - | else co(cA, cw[cB]) |
---|
522 | | - | |
---|
523 | | - | func cC (cA,cB) = if ((cB >= cx)) |
---|
524 | | - | then cA |
---|
525 | | - | else throw("List size exceeds 15") |
---|
526 | | - | |
---|
527 | | - | cC(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cy, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) |
---|
528 | | - | } |
---|
529 | | - | let ed = eg._1 |
---|
530 | | - | let cD = eg._2 |
---|
531 | | - | if ((cD != unit)) |
---|
532 | | - | then ed |
---|
533 | | - | else throw(("Y calculation error, Y = " + toString(ed))) |
---|
534 | | - | } |
---|
535 | | - | |
---|
536 | | - | |
---|
537 | | - | func eh (ei,ej,ek) = { |
---|
538 | | - | let el = fraction(bY([E(ei, toBigInt(bf)), E(ej, toBigInt(bg))]), c, ek) |
---|
539 | | - | if ((ek == e)) |
---|
540 | | - | then e |
---|
541 | | - | else el |
---|
542 | | - | } |
---|
543 | | - | |
---|
544 | | - | |
---|
545 | | - | func em (en,eo,ep) = { |
---|
546 | | - | let eq = (toBigInt(bA(aW(bd))) - en) |
---|
547 | | - | let er = (toBigInt(bA(aW(be))) - eo) |
---|
548 | | - | let es = (toBigInt(value(assetInfo(bc)).quantity) - ep) |
---|
549 | | - | let et = eh(eq, er, es) |
---|
550 | | - | et |
---|
551 | | - | } |
---|
552 | | - | |
---|
553 | | - | |
---|
554 | | - | func eu (ev,ew,ep) = { |
---|
555 | | - | let eq = (bA(aW(bd)) + ev) |
---|
556 | | - | let er = (bA(aW(be)) + ew) |
---|
557 | | - | let es = (value(assetInfo(bc)).quantity + ep) |
---|
558 | | - | let el = eh(toBigInt(eq), toBigInt(er), toBigInt(es)) |
---|
559 | | - | let ex = [IntegerEntry(ag, height), StringEntry(af, toString(el))] |
---|
560 | | - | $Tuple2(ex, el) |
---|
561 | | - | } |
---|
562 | | - | |
---|
563 | | - | |
---|
564 | | - | func ey (ez,el) = if ((el >= ez)) |
---|
565 | | - | then true |
---|
566 | | - | else aF("updated DLp lower than current DLp") |
---|
567 | | - | |
---|
568 | | - | |
---|
569 | | - | func eA (eB) = { |
---|
570 | | - | let eq = bA(aW(bd)) |
---|
571 | | - | let er = bA(aW(be)) |
---|
572 | | - | let eC = eB.amount |
---|
573 | | - | let eD = fraction(eB.amount, eB.price, a, FLOOR) |
---|
574 | | - | let eE = if ((eB.orderType == Buy)) |
---|
575 | | - | then $Tuple2(eC, -(eD)) |
---|
576 | | - | else $Tuple2(-(eC), eD) |
---|
577 | | - | let ev = eE._1 |
---|
578 | | - | let ew = eE._2 |
---|
579 | | - | if (if (if (aN()) |
---|
580 | | - | then true |
---|
581 | | - | else (bb == o)) |
---|
582 | | - | then true |
---|
583 | | - | else (bb == p)) |
---|
584 | | - | then throw("Admin blocked") |
---|
585 | | - | else if (if ((eB.assetPair.amountAsset != bd)) |
---|
586 | | - | then true |
---|
587 | | - | else (eB.assetPair.priceAsset != be)) |
---|
588 | | - | then throw("Wr assets") |
---|
589 | | - | else { |
---|
590 | | - | let eF = parseBigIntValue(valueOrElse(getString(this, af), "0")) |
---|
591 | | - | let eG = eu(ev, ew, 0) |
---|
592 | | - | let eH = eG._1 |
---|
593 | | - | let eI = eG._2 |
---|
594 | | - | let eJ = (eI >= eF) |
---|
595 | | - | let eK = makeString(["dLp=", toString(eF), " dLpNew=", toString(eI), " amountAssetBalance=", toString(eq), " priceAssetBalance=", toString(er), " amountAssetBalanceDelta=", toString(ev), " priceAssetBalanceDelta=", toString(ew), " height=", toString(height)], "") |
---|
596 | | - | $Tuple2(eJ, eK) |
---|
597 | | - | } |
---|
598 | | - | } |
---|
599 | | - | |
---|
600 | | - | |
---|
601 | | - | func eL (cq) = if ((size(cq.payments) != 1)) |
---|
602 | | - | then throw("1 pmnt exp") |
---|
603 | | - | else { |
---|
604 | | - | let eM = value(cq.payments[0]) |
---|
605 | | - | let cG = value(eM.assetId) |
---|
606 | | - | let dn = eM.amount |
---|
607 | | - | let dy = cE(toBase58String(cq.transactionId), toBase58String(cG), dn, cq.caller) |
---|
608 | | - | let da = dy._1 |
---|
609 | | - | let db = dy._2 |
---|
610 | | - | let cO = parseIntValue(dy._9) |
---|
611 | | - | let dc = dy._10 |
---|
612 | | - | if (if (aN()) |
---|
613 | | - | then true |
---|
614 | | - | else (cO == p)) |
---|
615 | | - | then throw(("Admin blocked: " + toString(cO))) |
---|
616 | | - | else $Tuple5(da, db, dn, cG, dc) |
---|
617 | | - | } |
---|
618 | | - | |
---|
619 | | - | |
---|
620 | | - | func eN (eO,V,eP,eQ,de,dk,dl,dm,dn,do) = { |
---|
621 | | - | let dy = dd(V, de, value(eP).amount, value(eP).assetId, value(eQ).amount, value(eQ).assetId, eO, (V == ""), dk, dl, dm, dn, do) |
---|
622 | | - | let cO = parseIntValue(dy._8) |
---|
623 | | - | if (if (if (aN()) |
---|
624 | | - | then true |
---|
625 | | - | else (cO == n)) |
---|
626 | | - | then true |
---|
627 | | - | else (cO == p)) |
---|
628 | | - | then throw(("Blocked:" + toString(cO))) |
---|
629 | | - | else dy |
---|
630 | | - | } |
---|
631 | | - | |
---|
632 | | - | |
---|
633 | | - | func eR (eS,cG,cI,V,eT) = { |
---|
634 | | - | let cK = toBase58String(value(bd)) |
---|
635 | | - | let cL = toBase58String(value(be)) |
---|
636 | | - | let cJ = bc |
---|
637 | | - | let dr = bf |
---|
638 | | - | let ds = bg |
---|
639 | | - | let es = toBigInt(valueOrErrorMessage(assetInfo(cJ), "invalid lp asset").quantity) |
---|
640 | | - | let eU = if ((es > e)) |
---|
641 | | - | then true |
---|
642 | | - | else throw("initial deposit requires all coins") |
---|
643 | | - | if ((eU == eU)) |
---|
644 | | - | then { |
---|
645 | | - | let cQ = bA(cK) |
---|
646 | | - | let cS = bA(cL) |
---|
647 | | - | let eV = if ((V == "")) |
---|
648 | | - | then $Tuple2(cQ, cS) |
---|
649 | | - | else if ((cG == cK)) |
---|
650 | | - | then if ((eS > cQ)) |
---|
651 | | - | then throw("invalid payment amount") |
---|
652 | | - | else $Tuple2((cQ - eS), cS) |
---|
653 | | - | else if ((cG == cL)) |
---|
654 | | - | then if ((eS > cS)) |
---|
655 | | - | then throw("invalid payment amount") |
---|
656 | | - | else $Tuple2(cQ, (cS - eS)) |
---|
657 | | - | else throw("wrong pmtAssetId") |
---|
658 | | - | let eW = eV._1 |
---|
659 | | - | let eX = eV._2 |
---|
660 | | - | let eY = if ((cG == cK)) |
---|
661 | | - | then $Tuple2(eS, 0) |
---|
662 | | - | else if ((cG == cL)) |
---|
663 | | - | then $Tuple2(0, eS) |
---|
664 | | - | else throw("invalid payment") |
---|
665 | | - | let eZ = eY._1 |
---|
666 | | - | let fa = eY._2 |
---|
667 | | - | let fb = if (eT) |
---|
668 | | - | then $Tuple3(bV(eZ, aJ)._1, bV(fa, aJ)._1, bV(eS, aJ)._2) |
---|
669 | | - | else $Tuple3(eZ, fa, 0) |
---|
670 | | - | let fc = fb._1 |
---|
671 | | - | let fd = fb._2 |
---|
672 | | - | let bX = fb._3 |
---|
673 | | - | let fe = (eW + fc) |
---|
674 | | - | let ff = (eX + fd) |
---|
675 | | - | let dx = bY([B(eW, bf), B(eX, bg)]) |
---|
676 | | - | let dz = bY([B(fe, bf), B(ff, bg)]) |
---|
677 | | - | let dA = if ((dz > dx)) |
---|
678 | | - | then true |
---|
679 | | - | else throw() |
---|
680 | | - | if ((dA == dA)) |
---|
681 | | - | then { |
---|
682 | | - | let fg = fraction(es, (dz - dx), dx, FLOOR) |
---|
683 | | - | let cV = F(bC(B(ff, ds), B(fe, dr)), a) |
---|
684 | | - | let dT = [IntegerEntry(P(), cV), IntegerEntry(Q(height, lastBlock.timestamp), cV), StringEntry(T(cI, V), bl(eZ, fa, toInt(fg), cV, 0, 0, height, lastBlock.timestamp, 0, 0))] |
---|
685 | | - | let fh = fraction(eX, a, eW) |
---|
686 | | - | let fi = fraction(eS, a, (fh + a)) |
---|
687 | | - | let fj = (eS - fi) |
---|
688 | | - | let fk = fraction(es, toBigInt(fj), toBigInt(eX)) |
---|
689 | | - | let fl = toInt(fraction((fg - fk), b, fk)) |
---|
690 | | - | $Tuple4(toInt(fg), dT, bX, fl) |
---|
691 | | - | } |
---|
692 | | - | else throw("Strict value is not equal to itself.") |
---|
693 | | - | } |
---|
694 | | - | else throw("Strict value is not equal to itself.") |
---|
695 | | - | } |
---|
696 | | - | |
---|
697 | | - | |
---|
698 | | - | func fm (fn,fo,fp,eO,fq,fr) = { |
---|
699 | | - | let cJ = toBase58String(value(bc)) |
---|
700 | | - | let cK = toBase58String(value(bd)) |
---|
701 | | - | let cL = toBase58String(value(be)) |
---|
702 | | - | let fs = bf |
---|
703 | | - | let ft = bg |
---|
704 | | - | let fu = bb |
---|
705 | | - | let cI = if ((eO == bk)) |
---|
706 | | - | then fq |
---|
707 | | - | else eO |
---|
708 | | - | let eM = value(fp[0]) |
---|
709 | | - | let cG = value(eM.assetId) |
---|
710 | | - | let dn = eM.amount |
---|
711 | | - | let et = em(e, e, e) |
---|
712 | | - | if ((et == et)) |
---|
713 | | - | then { |
---|
714 | | - | let cF = toBase58String(fr) |
---|
715 | | - | if ((cJ != toBase58String(cG))) |
---|
716 | | - | then throw("Wrong LP") |
---|
717 | | - | else { |
---|
718 | | - | let cQ = bA(cK) |
---|
719 | | - | let cS = bA(cL) |
---|
720 | | - | let fv = { |
---|
721 | | - | let aK = invoke(this, "getOneTknV2READONLY", [fn, dn], nil) |
---|
722 | | - | if ($isInstanceOf(aK, "(Int, Int)")) |
---|
723 | | - | then aK |
---|
724 | | - | else throw(($getType(aK) + " couldn't be cast to (Int, Int)")) |
---|
725 | | - | } |
---|
726 | | - | if ((fv == fv)) |
---|
727 | | - | then { |
---|
728 | | - | let bX = fv._2 |
---|
729 | | - | let fw = fv._1 |
---|
730 | | - | let fx = if (if ((fo > 0)) |
---|
731 | | - | then (fo > fw) |
---|
732 | | - | else false) |
---|
733 | | - | then aF(makeString(["amount to receive is less than ", toString(fo)], "")) |
---|
734 | | - | else fw |
---|
735 | | - | let fy = if ((fn == cK)) |
---|
736 | | - | then $Tuple4(fx, 0, ((cQ - fx) - bX), cS) |
---|
737 | | - | else if ((fn == cL)) |
---|
738 | | - | then $Tuple4(0, fx, cQ, ((cS - fx) - bX)) |
---|
739 | | - | else throw("invalid out asset id") |
---|
740 | | - | let fz = fy._1 |
---|
741 | | - | let fA = fy._2 |
---|
742 | | - | let fe = fy._3 |
---|
743 | | - | let ff = fy._4 |
---|
744 | | - | let fB = bC(B(ff, ft), B(fe, fs)) |
---|
745 | | - | let fC = F(fB, a) |
---|
746 | | - | let fD = if ((fn == "WAVES")) |
---|
747 | | - | then unit |
---|
748 | | - | else fromBase58String(fn) |
---|
749 | | - | let fE = if ((bX > 0)) |
---|
750 | | - | then [ScriptTransfer(aP, bX, fD)] |
---|
751 | | - | else nil |
---|
752 | | - | let dc = ([ScriptTransfer(cI, fx, fD), StringEntry(W(toString(cI), cF), bw(fz, fA, dn, fC, height, lastBlock.timestamp)), IntegerEntry(P(), fC), IntegerEntry(Q(height, lastBlock.timestamp), fC)] ++ fE) |
---|
753 | | - | if ((dc == dc)) |
---|
754 | | - | then { |
---|
755 | | - | let fF = invoke(aI, "burn", [dn], [AttachedPayment(cG, dn)]) |
---|
756 | | - | if ((fF == fF)) |
---|
757 | | - | then { |
---|
758 | | - | let fG = { |
---|
759 | | - | let fH = if ((this == aP)) |
---|
760 | | - | then 0 |
---|
761 | | - | else bX |
---|
762 | | - | let fI = if ((aU(fn) == bd)) |
---|
763 | | - | then true |
---|
764 | | - | else false |
---|
765 | | - | if (fI) |
---|
766 | | - | then $Tuple2(-((fw + fH)), 0) |
---|
767 | | - | else $Tuple2(0, -((fw + fH))) |
---|
768 | | - | } |
---|
769 | | - | let ev = fG._1 |
---|
770 | | - | let ew = fG._2 |
---|
771 | | - | let fJ = eu(ev, ew, 0) |
---|
772 | | - | let fK = fJ._1 |
---|
773 | | - | let el = fJ._2 |
---|
774 | | - | let fL = ey(et, el) |
---|
775 | | - | if ((fL == fL)) |
---|
776 | | - | then $Tuple2((dc ++ fK), fx) |
---|
777 | | - | else throw("Strict value is not equal to itself.") |
---|
778 | | - | } |
---|
779 | | - | else throw("Strict value is not equal to itself.") |
---|
780 | | - | } |
---|
781 | | - | else throw("Strict value is not equal to itself.") |
---|
782 | | - | } |
---|
783 | | - | else throw("Strict value is not equal to itself.") |
---|
784 | | - | } |
---|
785 | | - | } |
---|
786 | | - | else throw("Strict value is not equal to itself.") |
---|
787 | | - | } |
---|
788 | | - | |
---|
789 | | - | |
---|
790 | | - | func fM () = { |
---|
791 | | - | let fN = getString(N()) |
---|
792 | | - | if ($isInstanceOf(fN, "String")) |
---|
793 | | - | then { |
---|
794 | | - | let cc = fN |
---|
795 | | - | fromBase58String(cc) |
---|
796 | | - | } |
---|
797 | | - | else if ($isInstanceOf(fN, "Unit")) |
---|
798 | | - | then unit |
---|
799 | | - | else throw("Match error") |
---|
800 | | - | } |
---|
801 | | - | |
---|
802 | | - | |
---|
803 | | - | func fO () = { |
---|
804 | | - | let fN = getString(O()) |
---|
805 | | - | if ($isInstanceOf(fN, "String")) |
---|
806 | | - | then { |
---|
807 | | - | let cc = fN |
---|
808 | | - | fromBase58String(cc) |
---|
809 | | - | } |
---|
810 | | - | else if ($isInstanceOf(fN, "Unit")) |
---|
811 | | - | then unit |
---|
812 | | - | else throw("Match error") |
---|
813 | | - | } |
---|
814 | | - | |
---|
815 | | - | |
---|
816 | | - | let fP = throw("Permission denied") |
---|
817 | | - | |
---|
818 | | - | func fQ (cq) = { |
---|
819 | | - | let fN = fM() |
---|
820 | | - | if ($isInstanceOf(fN, "ByteVector")) |
---|
821 | | - | then { |
---|
822 | | - | let fR = fN |
---|
823 | | - | (cq.callerPublicKey == fR) |
---|
824 | | - | } |
---|
825 | | - | else if ($isInstanceOf(fN, "Unit")) |
---|
826 | | - | then (cq.caller == this) |
---|
827 | | - | else throw("Match error") |
---|
828 | | - | } |
---|
829 | | - | |
---|
830 | | - | |
---|
831 | | - | func fS (cq) = { |
---|
832 | | - | let fN = fM() |
---|
833 | | - | if ($isInstanceOf(fN, "ByteVector")) |
---|
834 | | - | then { |
---|
835 | | - | let fR = fN |
---|
836 | | - | if ((cq.callerPublicKey == fR)) |
---|
837 | | - | then true |
---|
838 | | - | else fP |
---|
839 | | - | } |
---|
840 | | - | else if ($isInstanceOf(fN, "Unit")) |
---|
841 | | - | then if ((cq.caller == this)) |
---|
842 | | - | then true |
---|
843 | | - | else fP |
---|
844 | | - | else throw("Match error") |
---|
845 | | - | } |
---|
846 | | - | |
---|
847 | | - | |
---|
848 | | - | func fT (fU,dV,fV) = { |
---|
849 | | - | let aY = aQ() |
---|
850 | | - | let cK = aY[t] |
---|
851 | | - | let cL = aY[u] |
---|
852 | | - | let dW = g |
---|
853 | | - | let dY = parseBigIntValue(l) |
---|
854 | | - | let cd = (parseBigIntValue(aM) * dY) |
---|
855 | | - | let bZ = if ((fU == false)) |
---|
856 | | - | then [(toBigInt(bA(cK)) + fV), toBigInt(bA(cL))] |
---|
857 | | - | else [(toBigInt(bA(cL)) + fV), toBigInt(bA(cK))] |
---|
858 | | - | let dX = bZ[0] |
---|
859 | | - | let cc = dX |
---|
860 | | - | let ce = (cd * dW) |
---|
861 | | - | let dZ = (((((dV * dV) / (dX * dW)) * dV) * dY) / (ce * dW)) |
---|
862 | | - | let ea = ((cc + ((dV * dY) / ce)) - dV) |
---|
863 | | - | func co (cp,eb) = { |
---|
864 | | - | let fW = cp |
---|
865 | | - | let ed = fW._1 |
---|
866 | | - | let cD = fW._2 |
---|
867 | | - | if ((cD != unit)) |
---|
868 | | - | then cp |
---|
869 | | - | else { |
---|
870 | | - | let ee = (((ed * ed) + dZ) / ((g * ed) + ea)) |
---|
871 | | - | let ef = L((ee - value(ed))) |
---|
872 | | - | if ((f >= ef)) |
---|
873 | | - | then $Tuple2(ee, eb) |
---|
874 | | - | else $Tuple2(ee, unit) |
---|
875 | | - | } |
---|
876 | | - | } |
---|
877 | | - | |
---|
878 | | - | let cu = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] |
---|
879 | | - | let fX = { |
---|
880 | | - | let cw = cu |
---|
881 | | - | let cx = size(cw) |
---|
882 | | - | let cy = $Tuple2(dV, unit) |
---|
883 | | - | func cz (cA,cB) = if ((cB >= cx)) |
---|
884 | | - | then cA |
---|
885 | | - | else co(cA, cw[cB]) |
---|
886 | | - | |
---|
887 | | - | func cC (cA,cB) = if ((cB >= cx)) |
---|
888 | | - | then cA |
---|
889 | | - | else throw("List size exceeds 15") |
---|
890 | | - | |
---|
891 | | - | cC(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cz(cy, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) |
---|
892 | | - | } |
---|
893 | | - | let ed = fX._1 |
---|
894 | | - | let cD = fX._2 |
---|
895 | | - | if ((cD != unit)) |
---|
896 | | - | then ed |
---|
897 | | - | else throw(("Y calculation error, Y = " + toString(ed))) |
---|
898 | | - | } |
---|
899 | | - | |
---|
900 | | - | |
---|
901 | | - | func fY () = valueOrElse(getBoolean(aI, au(toString(this))), false) |
---|
902 | | - | |
---|
903 | | - | |
---|
904 | | - | @Callable(cq) |
---|
905 | | - | func calculateAmountOutForSwapREADONLY (fZ,fU,ga) = { |
---|
906 | | - | let gb = if ((fU == false)) |
---|
907 | | - | then { |
---|
908 | | - | let gc = aB(this, Y()) |
---|
909 | | - | let fV = (toBigInt(bA(aB(this, X()))) + toBigInt(fZ)) |
---|
910 | | - | $Tuple2(gc, fV) |
---|
911 | | - | } |
---|
912 | | - | else { |
---|
913 | | - | let gc = aB(this, X()) |
---|
914 | | - | let fV = (toBigInt(bA(aB(this, Y()))) + toBigInt(fZ)) |
---|
915 | | - | $Tuple2(gc, fV) |
---|
916 | | - | } |
---|
917 | | - | let gc = gb._1 |
---|
918 | | - | let fV = gb._2 |
---|
919 | | - | let aY = aQ() |
---|
920 | | - | let cK = aY[t] |
---|
921 | | - | let cL = aY[u] |
---|
922 | | - | let bZ = [toBigInt(bA(cK)), toBigInt(bA(cL))] |
---|
923 | | - | let dV = bY(bZ) |
---|
924 | | - | let ed = fT(fU, dV, toBigInt(fZ)) |
---|
925 | | - | let gd = ((toBigInt(bA(gc)) - ed) - toBigInt(1)) |
---|
926 | | - | let ge = max([0, toInt(gd)]) |
---|
927 | | - | let gf = if ((fU == false)) |
---|
928 | | - | then [((toBigInt(bA(cK)) + toBigInt(fZ)) + toBigInt(ga)), (toBigInt(bA(cL)) - gd)] |
---|
929 | | - | else [(toBigInt(bA(cK)) - gd), ((toBigInt(bA(cL)) + toBigInt(fZ)) + toBigInt(ga))] |
---|
930 | | - | let gg = bY(gf) |
---|
931 | | - | let dA = if ((gg >= dV)) |
---|
932 | | - | then true |
---|
933 | | - | else throw(makeString(["new D is fewer error", toString(dV), toString(gg)], "__")) |
---|
934 | | - | if ((dA == dA)) |
---|
935 | | - | then $Tuple2(nil, ge) |
---|
936 | | - | else throw("Strict value is not equal to itself.") |
---|
937 | | - | } |
---|
938 | | - | |
---|
939 | | - | |
---|
940 | | - | |
---|
941 | | - | @Callable(cq) |
---|
942 | | - | func calculateAmountOutForSwapAndSendTokens (fZ,fU,gh,gi,ga) = { |
---|
943 | | - | let gj = { |
---|
944 | | - | let aK = invoke(aI, "getSwapContractREADONLY", nil, nil) |
---|
945 | | - | if ($isInstanceOf(aK, "String")) |
---|
946 | | - | then aK |
---|
947 | | - | else throw(($getType(aK) + " couldn't be cast to String")) |
---|
948 | | - | } |
---|
949 | | - | let gk = [if ((value(cq.payments[0]).amount >= fZ)) |
---|
950 | | - | then true |
---|
951 | | - | else aF("Wrong amount"), if ((cq.caller == addressFromStringValue(gj))) |
---|
952 | | - | then true |
---|
953 | | - | else aF("Permission denied")] |
---|
954 | | - | if ((gk == gk)) |
---|
955 | | - | then { |
---|
956 | | - | let eM = value(cq.payments[0]) |
---|
957 | | - | let gl = aW(eM.assetId) |
---|
958 | | - | let gm = if ((fU == false)) |
---|
959 | | - | then { |
---|
960 | | - | let gc = aB(this, Y()) |
---|
961 | | - | let fV = (bA(gl) - value(cq.payments[0]).amount) |
---|
962 | | - | $Tuple2(gc, fV) |
---|
963 | | - | } |
---|
964 | | - | else { |
---|
965 | | - | let gc = aB(this, X()) |
---|
966 | | - | let fV = (bA(gl) - value(cq.payments[0]).amount) |
---|
967 | | - | $Tuple2(gc, fV) |
---|
968 | | - | } |
---|
969 | | - | let gc = gm._1 |
---|
970 | | - | let fV = gm._2 |
---|
971 | | - | let aY = aQ() |
---|
972 | | - | let cK = aY[t] |
---|
973 | | - | let cL = aY[u] |
---|
974 | | - | let bZ = if ((fU == false)) |
---|
975 | | - | then [(toBigInt(bA(cK)) - toBigInt(value(cq.payments[0]).amount)), toBigInt(bA(cL))] |
---|
976 | | - | else [toBigInt(bA(cK)), (toBigInt(bA(cL)) - toBigInt(value(cq.payments[0]).amount))] |
---|
977 | | - | let dV = bY(bZ) |
---|
978 | | - | let ed = fT(fU, dV, toBigInt(0)) |
---|
979 | | - | let gd = ((toBigInt(bA(gc)) - ed) - toBigInt(1)) |
---|
980 | | - | let ge = max([0, toInt(gd)]) |
---|
981 | | - | let gn = if ((ge >= gh)) |
---|
982 | | - | then true |
---|
983 | | - | else throw("Exchange result is fewer coins than expected") |
---|
984 | | - | if ((gn == gn)) |
---|
985 | | - | then { |
---|
986 | | - | let gf = if ((fU == false)) |
---|
987 | | - | then [(toBigInt(bA(cK)) + toBigInt(ga)), (toBigInt(bA(cL)) - gd)] |
---|
988 | | - | else [(toBigInt(bA(cK)) - gd), (toBigInt(bA(cL)) + toBigInt(ga))] |
---|
989 | | - | let gg = bY(gf) |
---|
990 | | - | let dA = if ((gg >= dV)) |
---|
991 | | - | then true |
---|
992 | | - | else throw("new D is fewer error") |
---|
993 | | - | if ((dA == dA)) |
---|
994 | | - | then $Tuple2([ScriptTransfer(addressFromStringValue(gi), ge, aU(gc))], ge) |
---|
995 | | - | else throw("Strict value is not equal to itself.") |
---|
996 | | - | } |
---|
997 | | - | else throw("Strict value is not equal to itself.") |
---|
998 | | - | } |
---|
999 | | - | else throw("Strict value is not equal to itself.") |
---|
1000 | | - | } |
---|
1001 | | - | |
---|
1002 | | - | |
---|
1003 | | - | |
---|
1004 | | - | @Callable(cq) |
---|
1005 | | - | func constructor (M) = { |
---|
1006 | | - | let dZ = fS(cq) |
---|
1007 | | - | if ((dZ == dZ)) |
---|
1008 | | - | then [StringEntry(M(), M)] |
---|
1009 | | - | else throw("Strict value is not equal to itself.") |
---|
1010 | | - | } |
---|
1011 | | - | |
---|
1012 | | - | |
---|
1013 | | - | |
---|
1014 | | - | @Callable(cq) |
---|
1015 | | - | func setManager (go) = { |
---|
1016 | | - | let dZ = fS(cq) |
---|
1017 | | - | if ((dZ == dZ)) |
---|
1018 | | - | then { |
---|
1019 | | - | let gp = fromBase58String(go) |
---|
1020 | | - | if ((gp == gp)) |
---|
1021 | | - | then [StringEntry(O(), go)] |
---|
1022 | | - | else throw("Strict value is not equal to itself.") |
---|
1023 | | - | } |
---|
1024 | | - | else throw("Strict value is not equal to itself.") |
---|
1025 | | - | } |
---|
1026 | | - | |
---|
1027 | | - | |
---|
1028 | | - | |
---|
1029 | | - | @Callable(cq) |
---|
1030 | | - | func confirmManager () = { |
---|
1031 | | - | let cf = fO() |
---|
1032 | | - | let gq = if (isDefined(cf)) |
---|
1033 | | - | then true |
---|
1034 | | - | else throw("No pending manager") |
---|
1035 | | - | if ((gq == gq)) |
---|
1036 | | - | then { |
---|
1037 | | - | let gr = if ((cq.callerPublicKey == value(cf))) |
---|
1038 | | - | then true |
---|
1039 | | - | else throw("You are not pending manager") |
---|
1040 | | - | if ((gr == gr)) |
---|
1041 | | - | then [StringEntry(N(), toBase58String(value(cf))), DeleteEntry(O())] |
---|
1042 | | - | else throw("Strict value is not equal to itself.") |
---|
1043 | | - | } |
---|
1044 | | - | else throw("Strict value is not equal to itself.") |
---|
1045 | | - | } |
---|
1046 | | - | |
---|
1047 | | - | |
---|
1048 | | - | |
---|
1049 | | - | @Callable(cq) |
---|
1050 | | - | func put (gs,gt) = { |
---|
1051 | | - | let gu = bh() |
---|
1052 | | - | let gv = valueOrErrorMessage(addressFromString(gu[x]), "Wr st addr") |
---|
1053 | | - | let gw = valueOrErrorMessage(addressFromString(gu[z]), "Wr sl addr") |
---|
1054 | | - | if ((0 > gs)) |
---|
1055 | | - | then throw("Wrong slippage") |
---|
1056 | | - | else if ((size(cq.payments) != 2)) |
---|
1057 | | - | then throw("2 pmnts expd") |
---|
1058 | | - | else { |
---|
1059 | | - | let gx = toBigInt(value(cq.payments[0]).amount) |
---|
1060 | | - | let gy = toBigInt(value(cq.payments[1]).amount) |
---|
1061 | | - | let eq = (toBigInt(bA(aW(bd))) - gx) |
---|
1062 | | - | if ((eq == eq)) |
---|
1063 | | - | then { |
---|
1064 | | - | let er = (toBigInt(bA(aW(be))) - gy) |
---|
1065 | | - | if ((er == er)) |
---|
1066 | | - | then { |
---|
1067 | | - | let es = toBigInt(value(assetInfo(bc)).quantity) |
---|
1068 | | - | if ((es == es)) |
---|
1069 | | - | then { |
---|
1070 | | - | let et = em(gx, gy, toBigInt(0)) |
---|
1071 | | - | if ((et == et)) |
---|
1072 | | - | then { |
---|
1073 | | - | let gz = eN(toString(cq.caller), toBase58String(cq.transactionId), AttachedPayment(value(cq.payments[0]).assetId, value(cq.payments[0]).amount), cq.payments[1], gs, true, false, true, 0, "") |
---|
1074 | | - | let dN = gz._2 |
---|
1075 | | - | let gA = gz._7 |
---|
1076 | | - | let dc = gz._9 |
---|
1077 | | - | let dO = gz._10 |
---|
1078 | | - | let dP = gz._11 |
---|
1079 | | - | let cK = gz._12 |
---|
1080 | | - | let cL = gz._13 |
---|
1081 | | - | let dy = invoke(aI, "emit", [dN], nil) |
---|
1082 | | - | if ((dy == dy)) |
---|
1083 | | - | then { |
---|
1084 | | - | let gB = { |
---|
1085 | | - | let fN = dy |
---|
1086 | | - | if ($isInstanceOf(fN, "Address")) |
---|
1087 | | - | then { |
---|
1088 | | - | let gC = fN |
---|
1089 | | - | invoke(gC, "emit", [dN], nil) |
---|
1090 | | - | } |
---|
1091 | | - | else unit |
---|
1092 | | - | } |
---|
1093 | | - | if ((gB == gB)) |
---|
1094 | | - | then { |
---|
1095 | | - | let gD = if ((dO > 0)) |
---|
1096 | | - | then invoke(gw, "put", nil, [AttachedPayment(cK, dO)]) |
---|
1097 | | - | else nil |
---|
1098 | | - | if ((gD == gD)) |
---|
1099 | | - | then { |
---|
1100 | | - | let gE = if ((dP > 0)) |
---|
1101 | | - | then invoke(gw, "put", nil, [AttachedPayment(cL, dP)]) |
---|
1102 | | - | else nil |
---|
1103 | | - | if ((gE == gE)) |
---|
1104 | | - | then { |
---|
1105 | | - | let gF = if (gt) |
---|
1106 | | - | then { |
---|
1107 | | - | let gG = invoke(gv, "stake", nil, [AttachedPayment(gA, dN)]) |
---|
1108 | | - | if ((gG == gG)) |
---|
1109 | | - | then nil |
---|
1110 | | - | else throw("Strict value is not equal to itself.") |
---|
1111 | | - | } |
---|
1112 | | - | else [ScriptTransfer(cq.caller, dN, gA)] |
---|
1113 | | - | let gH = eu(0, 0, 0) |
---|
1114 | | - | let fK = gH._1 |
---|
1115 | | - | let el = gH._2 |
---|
1116 | | - | let gI = if ((el >= et)) |
---|
1117 | | - | then true |
---|
1118 | | - | else aF(makeString(["updated DLp lower than current DLp", toString(eq), toString(er), toString(es), toString(et), toString(el), toString(dO), toString(dP)], " ")) |
---|
1119 | | - | if ((gI == gI)) |
---|
1120 | | - | then { |
---|
1121 | | - | let gJ = value(assetInfo(bc)).quantity |
---|
1122 | | - | if ((gJ == gJ)) |
---|
1123 | | - | then ((dc ++ gF) ++ fK) |
---|
1124 | | - | else throw("Strict value is not equal to itself.") |
---|
1125 | | - | } |
---|
1126 | | - | else throw("Strict value is not equal to itself.") |
---|
1127 | | - | } |
---|
1128 | | - | else throw("Strict value is not equal to itself.") |
---|
1129 | | - | } |
---|
1130 | | - | else throw("Strict value is not equal to itself.") |
---|
1131 | | - | } |
---|
1132 | | - | else throw("Strict value is not equal to itself.") |
---|
1133 | | - | } |
---|
1134 | | - | else throw("Strict value is not equal to itself.") |
---|
1135 | | - | } |
---|
1136 | | - | else throw("Strict value is not equal to itself.") |
---|
1137 | | - | } |
---|
1138 | | - | else throw("Strict value is not equal to itself.") |
---|
1139 | | - | } |
---|
1140 | | - | else throw("Strict value is not equal to itself.") |
---|
1141 | | - | } |
---|
1142 | | - | else throw("Strict value is not equal to itself.") |
---|
1143 | | - | } |
---|
1144 | | - | } |
---|
1145 | | - | |
---|
1146 | | - | |
---|
1147 | | - | |
---|
1148 | | - | @Callable(cq) |
---|
1149 | | - | func putOneTknV2 (fo,gt) = { |
---|
1150 | | - | let gK = { |
---|
1151 | | - | let aK = invoke(aI, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) |
---|
1152 | | - | if ($isInstanceOf(aK, "Boolean")) |
---|
1153 | | - | then aK |
---|
1154 | | - | else throw(($getType(aK) + " couldn't be cast to Boolean")) |
---|
1155 | | - | } |
---|
1156 | | - | let gL = if (if (if (aN()) |
---|
1157 | | - | then true |
---|
1158 | | - | else (bb == n)) |
---|
1159 | | - | then true |
---|
1160 | | - | else (bb == p)) |
---|
1161 | | - | then true |
---|
1162 | | - | else gK |
---|
1163 | | - | let gk = [if (if (!(gL)) |
---|
1164 | | - | then true |
---|
1165 | | - | else fQ(cq)) |
---|
1166 | | - | then true |
---|
1167 | | - | else aF("put operation is blocked by admin"), if ((size(cq.payments) == 1)) |
---|
1168 | | - | then true |
---|
1169 | | - | else aF("exactly 1 payment are expected")] |
---|
1170 | | - | if ((gk == gk)) |
---|
1171 | | - | then { |
---|
1172 | | - | let cK = toBase58String(value(bd)) |
---|
1173 | | - | let cL = toBase58String(value(be)) |
---|
1174 | | - | let cJ = bc |
---|
1175 | | - | let fs = bf |
---|
1176 | | - | let ft = bg |
---|
1177 | | - | let cI = if ((cq.caller == this)) |
---|
1178 | | - | then cq.originCaller |
---|
1179 | | - | else cq.caller |
---|
1180 | | - | let eM = value(cq.payments[0]) |
---|
1181 | | - | let cG = toBase58String(value(eM.assetId)) |
---|
1182 | | - | let dn = eM.amount |
---|
1183 | | - | let et = if ((eM.assetId == bd)) |
---|
1184 | | - | then em(toBigInt(dn), toBigInt(0), toBigInt(0)) |
---|
1185 | | - | else em(toBigInt(0), toBigInt(dn), toBigInt(0)) |
---|
1186 | | - | if ((et == et)) |
---|
1187 | | - | then { |
---|
1188 | | - | let gM = eR(dn, cG, toString(cI), toBase58String(cq.transactionId), true) |
---|
1189 | | - | if ((gM == gM)) |
---|
1190 | | - | then { |
---|
1191 | | - | let bX = gM._3 |
---|
1192 | | - | let dc = gM._2 |
---|
1193 | | - | let gN = gM._1 |
---|
1194 | | - | let dN = if (if ((fo > 0)) |
---|
1195 | | - | then (fo > gN) |
---|
1196 | | - | else false) |
---|
1197 | | - | then aF(makeString(["amount to receive is less than ", toString(fo)], "")) |
---|
1198 | | - | else gN |
---|
1199 | | - | let gz = invoke(aI, "emit", [dN], nil) |
---|
1200 | | - | if ((gz == gz)) |
---|
1201 | | - | then { |
---|
1202 | | - | let gB = { |
---|
1203 | | - | let fN = gz |
---|
1204 | | - | if ($isInstanceOf(fN, "Address")) |
---|
1205 | | - | then { |
---|
1206 | | - | let gC = fN |
---|
1207 | | - | invoke(gC, "emit", [dN], nil) |
---|
1208 | | - | } |
---|
1209 | | - | else unit |
---|
1210 | | - | } |
---|
1211 | | - | if ((gB == gB)) |
---|
1212 | | - | then { |
---|
1213 | | - | let gF = if (gt) |
---|
1214 | | - | then { |
---|
1215 | | - | let gG = invoke(bj, "stakeFor", [toString(cq.caller)], [AttachedPayment(cJ, dN)]) |
---|
1216 | | - | if ((gG == gG)) |
---|
1217 | | - | then nil |
---|
1218 | | - | else throw("Strict value is not equal to itself.") |
---|
1219 | | - | } |
---|
1220 | | - | else [ScriptTransfer(cq.caller, dN, cJ)] |
---|
1221 | | - | let fE = if ((bX > 0)) |
---|
1222 | | - | then [ScriptTransfer(aP, bX, fromBase58String(cG))] |
---|
1223 | | - | else nil |
---|
1224 | | - | let gO = if ((this == aP)) |
---|
1225 | | - | then $Tuple2(0, 0) |
---|
1226 | | - | else { |
---|
1227 | | - | let gP = if ((eM.assetId == bd)) |
---|
1228 | | - | then true |
---|
1229 | | - | else false |
---|
1230 | | - | if (gP) |
---|
1231 | | - | then $Tuple2(-(bX), 0) |
---|
1232 | | - | else $Tuple2(0, -(bX)) |
---|
1233 | | - | } |
---|
1234 | | - | let ev = gO._1 |
---|
1235 | | - | let ew = gO._2 |
---|
1236 | | - | let gQ = eu(ev, ew, 0) |
---|
1237 | | - | let fK = gQ._1 |
---|
1238 | | - | let el = gQ._2 |
---|
1239 | | - | let fL = ey(et, el) |
---|
1240 | | - | if ((fL == fL)) |
---|
1241 | | - | then $Tuple2((((dc ++ gF) ++ fE) ++ fK), dN) |
---|
1242 | | - | else throw("Strict value is not equal to itself.") |
---|
1243 | | - | } |
---|
1244 | | - | else throw("Strict value is not equal to itself.") |
---|
1245 | | - | } |
---|
1246 | | - | else throw("Strict value is not equal to itself.") |
---|
1247 | | - | } |
---|
1248 | | - | else throw("Strict value is not equal to itself.") |
---|
1249 | | - | } |
---|
1250 | | - | else throw("Strict value is not equal to itself.") |
---|
1251 | | - | } |
---|
1252 | | - | else throw("Strict value is not equal to itself.") |
---|
1253 | | - | } |
---|
1254 | | - | |
---|
1255 | | - | |
---|
1256 | | - | |
---|
1257 | | - | @Callable(cq) |
---|
1258 | | - | func putForFree (gR) = if ((0 > gR)) |
---|
1259 | | - | then throw("Wrong slpg") |
---|
1260 | | - | else if ((size(cq.payments) != 2)) |
---|
1261 | | - | then throw("2 pmnts expd") |
---|
1262 | | - | else { |
---|
1263 | | - | let gS = eN(toString(cq.caller), toBase58String(cq.transactionId), AttachedPayment(value(cq.payments[0]).assetId, value(cq.payments[0]).amount), cq.payments[1], gR, false, false, true, 0, "") |
---|
1264 | | - | let dc = gS._9 |
---|
1265 | | - | let gx = toBigInt(value(cq.payments[0]).amount) |
---|
1266 | | - | let gy = toBigInt(value(cq.payments[1]).amount) |
---|
1267 | | - | let et = em(gx, gy, toBigInt(0)) |
---|
1268 | | - | if ((et == et)) |
---|
1269 | | - | then { |
---|
1270 | | - | let gT = eu(0, 0, 0) |
---|
1271 | | - | let fK = gT._1 |
---|
1272 | | - | let el = gT._2 |
---|
1273 | | - | let fL = ey(et, el) |
---|
1274 | | - | if ((fL == fL)) |
---|
1275 | | - | then (dc ++ fK) |
---|
1276 | | - | else throw("Strict value is not equal to itself.") |
---|
1277 | | - | } |
---|
1278 | | - | else throw("Strict value is not equal to itself.") |
---|
1279 | | - | } |
---|
1280 | | - | |
---|
1281 | | - | |
---|
1282 | | - | |
---|
1283 | | - | @Callable(cq) |
---|
1284 | | - | func get () = { |
---|
1285 | | - | let et = em(toBigInt(0), toBigInt(0), toBigInt(0)) |
---|
1286 | | - | if ((et == et)) |
---|
1287 | | - | then { |
---|
1288 | | - | let dy = eL(cq) |
---|
1289 | | - | let gU = dy._1 |
---|
1290 | | - | let db = dy._2 |
---|
1291 | | - | let dn = dy._3 |
---|
1292 | | - | let cG = dy._4 |
---|
1293 | | - | let dc = dy._5 |
---|
1294 | | - | let ea = invoke(aI, "burn", [dn], [AttachedPayment(cG, dn)]) |
---|
1295 | | - | if ((ea == ea)) |
---|
1296 | | - | then { |
---|
1297 | | - | let gV = eu(-(gU), -(db), 0) |
---|
1298 | | - | let fK = gV._1 |
---|
1299 | | - | let el = gV._2 |
---|
1300 | | - | let fL = ey(et, el) |
---|
1301 | | - | if ((fL == fL)) |
---|
1302 | | - | then (dc ++ fK) |
---|
1303 | | - | else throw("Strict value is not equal to itself.") |
---|
1304 | | - | } |
---|
1305 | | - | else throw("Strict value is not equal to itself.") |
---|
1306 | | - | } |
---|
1307 | | - | else throw("Strict value is not equal to itself.") |
---|
1308 | | - | } |
---|
1309 | | - | |
---|
1310 | | - | |
---|
1311 | | - | |
---|
1312 | | - | @Callable(cq) |
---|
1313 | | - | func getOneTknV2 (fn,fo) = { |
---|
1314 | | - | let gK = { |
---|
1315 | | - | let aK = invoke(aI, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) |
---|
1316 | | - | if ($isInstanceOf(aK, "Boolean")) |
---|
1317 | | - | then aK |
---|
1318 | | - | else throw(($getType(aK) + " couldn't be cast to Boolean")) |
---|
1319 | | - | } |
---|
1320 | | - | let gW = if (if (aN()) |
---|
1321 | | - | then true |
---|
1322 | | - | else (bb == p)) |
---|
1323 | | - | then true |
---|
1324 | | - | else gK |
---|
1325 | | - | let gk = [if (if (!(gW)) |
---|
1326 | | - | then true |
---|
1327 | | - | else fQ(cq)) |
---|
1328 | | - | then true |
---|
1329 | | - | else aF("get operation is blocked by admin"), if ((size(cq.payments) == 1)) |
---|
1330 | | - | then true |
---|
1331 | | - | else aF("exactly 1 payment are expected")] |
---|
1332 | | - | if ((gk == gk)) |
---|
1333 | | - | then { |
---|
1334 | | - | let gX = fm(fn, fo, cq.payments, cq.caller, cq.originCaller, cq.transactionId) |
---|
1335 | | - | let dc = gX._1 |
---|
1336 | | - | let fx = gX._2 |
---|
1337 | | - | $Tuple2(dc, fx) |
---|
1338 | | - | } |
---|
1339 | | - | else throw("Strict value is not equal to itself.") |
---|
1340 | | - | } |
---|
1341 | | - | |
---|
1342 | | - | |
---|
1343 | | - | |
---|
1344 | | - | @Callable(cq) |
---|
1345 | | - | func refreshDLp () = { |
---|
1346 | | - | let gY = valueOrElse(getInteger(ag), 0) |
---|
1347 | | - | let gZ = if (((height - gY) >= aj)) |
---|
1348 | | - | then unit |
---|
1349 | | - | else aF(makeString([toString(aj), " blocks have not passed since the previous call"], "")) |
---|
1350 | | - | if ((gZ == gZ)) |
---|
1351 | | - | then { |
---|
1352 | | - | let eF = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, af), "0")), aH("invalid dLp")) |
---|
1353 | | - | let ha = eu(0, 0, 0) |
---|
1354 | | - | let hb = ha._1 |
---|
1355 | | - | let el = ha._2 |
---|
1356 | | - | let ex = if ((eF != el)) |
---|
1357 | | - | then hb |
---|
1358 | | - | else aF("nothing to refresh") |
---|
1359 | | - | $Tuple2(ex, toString(el)) |
---|
1360 | | - | } |
---|
1361 | | - | else throw("Strict value is not equal to itself.") |
---|
1362 | | - | } |
---|
1363 | | - | |
---|
1364 | | - | |
---|
1365 | | - | |
---|
1366 | | - | @Callable(cq) |
---|
1367 | | - | func getOneTknV2READONLY (fn,hc) = { |
---|
1368 | | - | let cK = toBase58String(value(bd)) |
---|
1369 | | - | let cL = toBase58String(value(be)) |
---|
1370 | | - | let cJ = toBase58String(value(bc)) |
---|
1371 | | - | let bZ = [toBigInt(bA(cK)), toBigInt(bA(cL))] |
---|
1372 | | - | let ek = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(cJ)), "invalid lp asset").quantity) |
---|
1373 | | - | let dx = bY(bZ) |
---|
1374 | | - | let dz = (dx - fraction(toBigInt(hc), dx, ek)) |
---|
1375 | | - | let hd = if ((fn == cK)) |
---|
1376 | | - | then 0 |
---|
1377 | | - | else if ((fn == cL)) |
---|
1378 | | - | then 1 |
---|
1379 | | - | else throw("invalid out asset id") |
---|
1380 | | - | let he = dU(bZ, hd, dz) |
---|
1381 | | - | let gd = (bZ[hd] - he) |
---|
1382 | | - | let ge = max([0, toInt((gd - f))]) |
---|
1383 | | - | let hf = bV(ge, aL) |
---|
1384 | | - | let fw = hf._1 |
---|
1385 | | - | let bX = hf._2 |
---|
1386 | | - | $Tuple2(nil, $Tuple2(fw, bX)) |
---|
1387 | | - | } |
---|
1388 | | - | |
---|
1389 | | - | |
---|
1390 | | - | |
---|
1391 | | - | @Callable(cq) |
---|
1392 | | - | func getOneTknV2WithBonusREADONLY (fn,hc) = { |
---|
1393 | | - | let cK = toBase58String(value(bd)) |
---|
1394 | | - | let cL = toBase58String(value(be)) |
---|
1395 | | - | let cJ = toBase58String(value(bc)) |
---|
1396 | | - | let cQ = bA(cK) |
---|
1397 | | - | let cS = bA(cL) |
---|
1398 | | - | let hg = { |
---|
1399 | | - | let aK = invoke(this, "getOneTknV2READONLY", [fn, hc], nil) |
---|
1400 | | - | if ($isInstanceOf(aK, "(Int, Int)")) |
---|
1401 | | - | then aK |
---|
1402 | | - | else throw(($getType(aK) + " couldn't be cast to (Int, Int)")) |
---|
1403 | | - | } |
---|
1404 | | - | let fw = hg._1 |
---|
1405 | | - | let bX = hg._2 |
---|
1406 | | - | let dy = cE("", cJ, hc, this) |
---|
1407 | | - | let da = dy._1 |
---|
1408 | | - | let db = dy._2 |
---|
1409 | | - | let hh = (da + db) |
---|
1410 | | - | let fl = if ((hh == 0)) |
---|
1411 | | - | then if ((fw == 0)) |
---|
1412 | | - | then 0 |
---|
1413 | | - | else throw("bonus calculation error") |
---|
1414 | | - | else fraction((fw - hh), a, hh) |
---|
1415 | | - | $Tuple2(nil, $Tuple3(fw, bX, fl)) |
---|
1416 | | - | } |
---|
1417 | | - | |
---|
1418 | | - | |
---|
1419 | | - | |
---|
1420 | | - | @Callable(cq) |
---|
1421 | | - | func getNoLess (hi,hj) = { |
---|
1422 | | - | let dy = eL(cq) |
---|
1423 | | - | let da = dy._1 |
---|
1424 | | - | let db = dy._2 |
---|
1425 | | - | let dn = dy._3 |
---|
1426 | | - | let cG = dy._4 |
---|
1427 | | - | let dc = dy._5 |
---|
1428 | | - | if ((hi > da)) |
---|
1429 | | - | then throw(((("Failed: " + toString(da)) + " < ") + toString(hi))) |
---|
1430 | | - | else if ((hj > db)) |
---|
1431 | | - | then throw(((("Failed: " + toString(db)) + " < ") + toString(hj))) |
---|
1432 | | - | else { |
---|
1433 | | - | let et = em(toBigInt(0), toBigInt(0), toBigInt(0)) |
---|
1434 | | - | if ((et == et)) |
---|
1435 | | - | then { |
---|
1436 | | - | let hk = invoke(aI, "burn", [dn], [AttachedPayment(cG, dn)]) |
---|
1437 | | - | if ((hk == hk)) |
---|
1438 | | - | then { |
---|
1439 | | - | let hl = eu(-(da), -(db), 0) |
---|
1440 | | - | let fK = hl._1 |
---|
1441 | | - | let el = hl._2 |
---|
1442 | | - | let fL = ey(et, el) |
---|
1443 | | - | if ((fL == fL)) |
---|
1444 | | - | then (dc ++ fK) |
---|
1445 | | - | else throw("Strict value is not equal to itself.") |
---|
1446 | | - | } |
---|
1447 | | - | else throw("Strict value is not equal to itself.") |
---|
1448 | | - | } |
---|
1449 | | - | else throw("Strict value is not equal to itself.") |
---|
1450 | | - | } |
---|
1451 | | - | } |
---|
1452 | | - | |
---|
1453 | | - | |
---|
1454 | | - | |
---|
1455 | | - | @Callable(cq) |
---|
1456 | | - | func unstakeAndGet (bW) = { |
---|
1457 | | - | let hm = if ((size(cq.payments) != 0)) |
---|
1458 | | - | then throw("No pmnts expd") |
---|
1459 | | - | else true |
---|
1460 | | - | if ((hm == hm)) |
---|
1461 | | - | then { |
---|
1462 | | - | let hn = bh() |
---|
1463 | | - | let gA = bc |
---|
1464 | | - | let ho = valueOrErrorMessage(addressFromString(hn[x]), "Wr st addr") |
---|
1465 | | - | let et = em(toBigInt(0), toBigInt(0), toBigInt(0)) |
---|
1466 | | - | if ((et == et)) |
---|
1467 | | - | then { |
---|
1468 | | - | let hp = invoke(ho, "unstake", [toBase58String(gA), bW], nil) |
---|
1469 | | - | if ((hp == hp)) |
---|
1470 | | - | then { |
---|
1471 | | - | let dy = cE(toBase58String(cq.transactionId), toBase58String(gA), bW, cq.caller) |
---|
1472 | | - | let da = dy._1 |
---|
1473 | | - | let db = dy._2 |
---|
1474 | | - | let cO = parseIntValue(dy._9) |
---|
1475 | | - | let dc = dy._10 |
---|
1476 | | - | let hq = if (if (aN()) |
---|
1477 | | - | then true |
---|
1478 | | - | else (cO == p)) |
---|
1479 | | - | then throw(("Blocked: " + toString(cO))) |
---|
1480 | | - | else true |
---|
1481 | | - | if ((hq == hq)) |
---|
1482 | | - | then { |
---|
1483 | | - | let hr = invoke(aI, "burn", [bW], [AttachedPayment(gA, bW)]) |
---|
1484 | | - | if ((hr == hr)) |
---|
1485 | | - | then { |
---|
1486 | | - | let hs = eu(-(da), -(db), 0) |
---|
1487 | | - | let fK = hs._1 |
---|
1488 | | - | let el = hs._2 |
---|
1489 | | - | let fL = ey(et, el) |
---|
1490 | | - | if ((fL == fL)) |
---|
1491 | | - | then (dc ++ fK) |
---|
1492 | | - | else throw("Strict value is not equal to itself.") |
---|
1493 | | - | } |
---|
1494 | | - | else throw("Strict value is not equal to itself.") |
---|
1495 | | - | } |
---|
1496 | | - | else throw("Strict value is not equal to itself.") |
---|
1497 | | - | } |
---|
1498 | | - | else throw("Strict value is not equal to itself.") |
---|
1499 | | - | } |
---|
1500 | | - | else throw("Strict value is not equal to itself.") |
---|
1501 | | - | } |
---|
1502 | | - | else throw("Strict value is not equal to itself.") |
---|
1503 | | - | } |
---|
1504 | | - | |
---|
1505 | | - | |
---|
1506 | | - | |
---|
1507 | | - | @Callable(cq) |
---|
1508 | | - | func unstakeAndGetNoLess (ht,hu,hj) = { |
---|
1509 | | - | let gW = if (aN()) |
---|
1510 | | - | then true |
---|
1511 | | - | else (bb == p) |
---|
1512 | | - | let gk = [if (!(gW)) |
---|
1513 | | - | then true |
---|
1514 | | - | else throw("get operation is blocked by admin"), if ((size(cq.payments) == 0)) |
---|
1515 | | - | then true |
---|
1516 | | - | else throw("no payments are expected")] |
---|
1517 | | - | if ((gk == gk)) |
---|
1518 | | - | then { |
---|
1519 | | - | let et = em(toBigInt(0), toBigInt(0), toBigInt(0)) |
---|
1520 | | - | if ((et == et)) |
---|
1521 | | - | then { |
---|
1522 | | - | let hp = invoke(bj, "unstake", [toBase58String(bc), ht], nil) |
---|
1523 | | - | if ((hp == hp)) |
---|
1524 | | - | then { |
---|
1525 | | - | let hv = cE(toBase58String(cq.transactionId), toBase58String(bc), ht, cq.caller) |
---|
1526 | | - | let da = hv._1 |
---|
1527 | | - | let db = hv._2 |
---|
1528 | | - | let dc = hv._10 |
---|
1529 | | - | let hw = [if ((da >= hu)) |
---|
1530 | | - | then true |
---|
1531 | | - | else throw(makeString(["amount asset amount to receive is less than ", toString(hu)], "")), if ((db >= hj)) |
---|
1532 | | - | then true |
---|
1533 | | - | else throw(makeString(["price asset amount to receive is less than ", toString(hj)], ""))] |
---|
1534 | | - | if ((hw == hw)) |
---|
1535 | | - | then { |
---|
1536 | | - | let hk = invoke(aI, "burn", [ht], [AttachedPayment(bc, ht)]) |
---|
1537 | | - | if ((hk == hk)) |
---|
1538 | | - | then { |
---|
1539 | | - | let hx = eu(-(da), -(db), 0) |
---|
1540 | | - | let fK = hx._1 |
---|
1541 | | - | let el = hx._2 |
---|
1542 | | - | let fL = ey(et, el) |
---|
1543 | | - | if ((fL == fL)) |
---|
1544 | | - | then (dc ++ fK) |
---|
1545 | | - | else throw("Strict value is not equal to itself.") |
---|
1546 | | - | } |
---|
1547 | | - | else throw("Strict value is not equal to itself.") |
---|
1548 | | - | } |
---|
1549 | | - | else throw("Strict value is not equal to itself.") |
---|
1550 | | - | } |
---|
1551 | | - | else throw("Strict value is not equal to itself.") |
---|
1552 | | - | } |
---|
1553 | | - | else throw("Strict value is not equal to itself.") |
---|
1554 | | - | } |
---|
1555 | | - | else throw("Strict value is not equal to itself.") |
---|
1556 | | - | } |
---|
1557 | | - | |
---|
1558 | | - | |
---|
1559 | | - | |
---|
1560 | | - | @Callable(cq) |
---|
1561 | | - | func unstakeAndGetOneTknV2 (ht,fn,fo) = { |
---|
1562 | | - | let gK = { |
---|
1563 | | - | let aK = invoke(aI, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) |
---|
1564 | | - | if ($isInstanceOf(aK, "Boolean")) |
---|
1565 | | - | then aK |
---|
1566 | | - | else throw(($getType(aK) + " couldn't be cast to Boolean")) |
---|
1567 | | - | } |
---|
1568 | | - | let gW = if (if (aN()) |
---|
1569 | | - | then true |
---|
1570 | | - | else (bb == p)) |
---|
1571 | | - | then true |
---|
1572 | | - | else gK |
---|
1573 | | - | let gk = [if (if (!(gW)) |
---|
1574 | | - | then true |
---|
1575 | | - | else fQ(cq)) |
---|
1576 | | - | then true |
---|
1577 | | - | else aF("get operation is blocked by admin"), if ((size(cq.payments) == 0)) |
---|
1578 | | - | then true |
---|
1579 | | - | else aF("no payments are expected")] |
---|
1580 | | - | if ((gk == gk)) |
---|
1581 | | - | then { |
---|
1582 | | - | let hn = bh() |
---|
1583 | | - | let gA = bc |
---|
1584 | | - | let ho = valueOrErrorMessage(addressFromString(hn[x]), "Wr st addr") |
---|
1585 | | - | let cI = cq.caller |
---|
1586 | | - | let hy = this |
---|
1587 | | - | let hp = invoke(ho, "unstakeINTERNAL", [gA, ht, cI.bytes, hy.bytes], nil) |
---|
1588 | | - | if ((hp == hp)) |
---|
1589 | | - | then { |
---|
1590 | | - | let hz = fm(fn, fo, [AttachedPayment(gA, ht)], cq.caller, cq.originCaller, cq.transactionId) |
---|
1591 | | - | let dc = hz._1 |
---|
1592 | | - | let fx = hz._2 |
---|
1593 | | - | $Tuple2(dc, fx) |
---|
1594 | | - | } |
---|
1595 | | - | else throw("Strict value is not equal to itself.") |
---|
1596 | | - | } |
---|
1597 | | - | else throw("Strict value is not equal to itself.") |
---|
1598 | | - | } |
---|
1599 | | - | |
---|
1600 | | - | |
---|
1601 | | - | |
---|
1602 | | - | @Callable(cq) |
---|
1603 | | - | func putOneTknV2WithBonusREADONLY (hA,hB) = { |
---|
1604 | | - | let hC = eR(hA, hB, "", "", true) |
---|
1605 | | - | let fg = hC._1 |
---|
1606 | | - | let dc = hC._2 |
---|
1607 | | - | let bX = hC._3 |
---|
1608 | | - | let fl = hC._4 |
---|
1609 | | - | $Tuple2(nil, $Tuple3(fg, bX, fl)) |
---|
1610 | | - | } |
---|
1611 | | - | |
---|
1612 | | - | |
---|
1613 | | - | |
---|
1614 | | - | @Callable(cq) |
---|
1615 | | - | func putOneTknV2WithoutTakeFeeREADONLY (hA,hB) = { |
---|
1616 | | - | let hD = eR(hA, hB, "", "", false) |
---|
1617 | | - | let fg = hD._1 |
---|
1618 | | - | let dc = hD._2 |
---|
1619 | | - | let bX = hD._3 |
---|
1620 | | - | let fl = hD._4 |
---|
1621 | | - | $Tuple2(nil, $Tuple3(fg, bX, fl)) |
---|
1622 | | - | } |
---|
1623 | | - | |
---|
1624 | | - | |
---|
1625 | | - | |
---|
1626 | | - | @Callable(cq) |
---|
1627 | | - | func activate (hE,hF) = if ((toString(cq.caller) != toString(aI))) |
---|
1628 | | - | then throw("denied") |
---|
1629 | | - | else $Tuple2([StringEntry(X(), hE), StringEntry(Y(), hF), StringEntry(Z(), toString(k))], "success") |
---|
1630 | | - | |
---|
1631 | | - | |
---|
1632 | | - | |
---|
1633 | | - | @Callable(cq) |
---|
1634 | | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, aQ()) |
---|
1635 | | - | |
---|
1636 | | - | |
---|
1637 | | - | |
---|
1638 | | - | @Callable(cq) |
---|
1639 | | - | func getAccBalanceWrapperREADONLY (bB) = $Tuple2(nil, bA(bB)) |
---|
1640 | | - | |
---|
1641 | | - | |
---|
1642 | | - | |
---|
1643 | | - | @Callable(cq) |
---|
1644 | | - | func calcPricesWrapperREADONLY (bJ,bK,bO) = { |
---|
1645 | | - | let hG = bN(bJ, bK, bO) |
---|
1646 | | - | $Tuple2(nil, [toString(hG[0]), toString(hG[1]), toString(hG[2])]) |
---|
1647 | | - | } |
---|
1648 | | - | |
---|
1649 | | - | |
---|
1650 | | - | |
---|
1651 | | - | @Callable(cq) |
---|
1652 | | - | func fromX18WrapperREADONLY (G,hH) = $Tuple2(nil, F(parseBigIntValue(G), hH)) |
---|
1653 | | - | |
---|
1654 | | - | |
---|
1655 | | - | |
---|
1656 | | - | @Callable(cq) |
---|
1657 | | - | func toX18WrapperREADONLY (C,D) = $Tuple2(nil, toString(B(C, D))) |
---|
1658 | | - | |
---|
1659 | | - | |
---|
1660 | | - | |
---|
1661 | | - | @Callable(cq) |
---|
1662 | | - | func calcPriceBigIntWrapperREADONLY (bD,bE) = $Tuple2(nil, toString(bC(parseBigIntValue(bD), parseBigIntValue(bE)))) |
---|
1663 | | - | |
---|
1664 | | - | |
---|
1665 | | - | |
---|
1666 | | - | @Callable(cq) |
---|
1667 | | - | func estimatePutOperationWrapperREADONLY (cF,de,df,dg,dh,di,hI,dj,dk) = $Tuple2(nil, dd(cF, de, df, dg, dh, di, hI, dj, dk, true, false, 0, "")) |
---|
1668 | | - | |
---|
1669 | | - | |
---|
1670 | | - | |
---|
1671 | | - | @Callable(cq) |
---|
1672 | | - | func estimateGetOperationWrapperREADONLY (cF,hJ,cH,hI) = { |
---|
1673 | | - | let dy = cE(cF, hJ, cH, addressFromStringValue(hI)) |
---|
1674 | | - | $Tuple2(nil, $Tuple10(dy._1, dy._2, dy._3, dy._4, dy._5, dy._6, dy._7, toString(dy._8), dy._9, dy._10)) |
---|
1675 | | - | } |
---|
1676 | | - | |
---|
1677 | | - | |
---|
1678 | | - | |
---|
1679 | | - | @Callable(cq) |
---|
1680 | | - | func changeAmp () = { |
---|
1681 | | - | let hK = invoke(aI, "getChangeAmpConfigREADONLY", [toString(this)], nil) |
---|
1682 | | - | let hL = { |
---|
1683 | | - | let fN = hK |
---|
1684 | | - | if ($isInstanceOf(fN, "List[Any]")) |
---|
1685 | | - | then { |
---|
1686 | | - | let hM = fN |
---|
1687 | | - | $Tuple3({ |
---|
1688 | | - | let aK = hM[0] |
---|
1689 | | - | if ($isInstanceOf(aK, "Int")) |
---|
1690 | | - | then aK |
---|
1691 | | - | else throw(($getType(aK) + " couldn't be cast to Int")) |
---|
1692 | | - | }, { |
---|
1693 | | - | let aK = hM[1] |
---|
1694 | | - | if ($isInstanceOf(aK, "Int")) |
---|
1695 | | - | then aK |
---|
1696 | | - | else throw(($getType(aK) + " couldn't be cast to Int")) |
---|
1697 | | - | }, { |
---|
1698 | | - | let aK = hM[2] |
---|
1699 | | - | if ($isInstanceOf(aK, "Int")) |
---|
1700 | | - | then aK |
---|
1701 | | - | else throw(($getType(aK) + " couldn't be cast to Int")) |
---|
1702 | | - | }) |
---|
1703 | | - | } |
---|
1704 | | - | else aF("invalid entry type") |
---|
1705 | | - | } |
---|
1706 | | - | let hN = hL._1 |
---|
1707 | | - | let hO = hL._2 |
---|
1708 | | - | let hP = hL._3 |
---|
1709 | | - | let hQ = parseIntValue(getStringValue(Z())) |
---|
1710 | | - | let hR = (hQ + hO) |
---|
1711 | | - | let hS = if ((0 > hO)) |
---|
1712 | | - | then if ((hP > hR)) |
---|
1713 | | - | then hP |
---|
1714 | | - | else hR |
---|
1715 | | - | else if ((hR > hP)) |
---|
1716 | | - | then hP |
---|
1717 | | - | else hR |
---|
1718 | | - | let hT = valueOrElse(getInteger(ac()), 0) |
---|
1719 | | - | let hU = (hT + hN) |
---|
1720 | | - | let gk = [if ((height > hU)) |
---|
1721 | | - | then true |
---|
1722 | | - | else aF("try again in few blocks"), if ((hQ != hS)) |
---|
1723 | | - | then true |
---|
1724 | | - | else aF("already reached target")] |
---|
1725 | | - | if ((gk == gk)) |
---|
1726 | | - | then [IntegerEntry(ac(), height), StringEntry(Z(), toString(hS)), StringEntry(aa(height), toString(hS))] |
---|
1727 | | - | else throw("Strict value is not equal to itself.") |
---|
1728 | | - | } |
---|
1729 | | - | |
---|
1730 | | - | |
---|
1731 | | - | @Verifier(hV) |
---|
1732 | | - | func hW () = { |
---|
1733 | | - | let hX = { |
---|
1734 | | - | let fN = fM() |
---|
1735 | | - | if ($isInstanceOf(fN, "ByteVector")) |
---|
1736 | | - | then { |
---|
1737 | | - | let fR = fN |
---|
1738 | | - | fR |
---|
1739 | | - | } |
---|
1740 | | - | else if ($isInstanceOf(fN, "Unit")) |
---|
1741 | | - | then hV.senderPublicKey |
---|
1742 | | - | else throw("Match error") |
---|
1743 | | - | } |
---|
1744 | | - | let fN = hV |
---|
1745 | | - | if ($isInstanceOf(fN, "Order")) |
---|
1746 | | - | then { |
---|
1747 | | - | let eB = fN |
---|
1748 | | - | let hY = aO() |
---|
1749 | | - | let hZ = if (fY()) |
---|
1750 | | - | then $Tuple2(true, "") |
---|
1751 | | - | else eA(eB) |
---|
1752 | | - | let ax = hZ._1 |
---|
1753 | | - | let ay = hZ._2 |
---|
1754 | | - | let az = sigVerify(eB.bodyBytes, eB.proofs[0], eB.senderPublicKey) |
---|
1755 | | - | let aA = sigVerify(eB.bodyBytes, eB.proofs[1], hY) |
---|
1756 | | - | if (if (if (ax) |
---|
1757 | | - | then az |
---|
1758 | | - | else false) |
---|
1759 | | - | then aA |
---|
1760 | | - | else false) |
---|
1761 | | - | then true |
---|
1762 | | - | else aw(ax, ay, az, aA) |
---|
1763 | | - | } |
---|
1764 | | - | else if ($isInstanceOf(fN, "SetScriptTransaction")) |
---|
1765 | | - | then { |
---|
1766 | | - | let cc = fN |
---|
1767 | | - | if (sigVerify(hV.bodyBytes, hV.proofs[0], hX)) |
---|
1768 | | - | then true |
---|
1769 | | - | else { |
---|
1770 | | - | let ia = blake2b256(value(cc.script)) |
---|
1771 | | - | let ib = fromBase64String(value(getString(aI, as()))) |
---|
1772 | | - | let ic = scriptHash(this) |
---|
1773 | | - | if ((ib == ia)) |
---|
1774 | | - | then (ic != ia) |
---|
1775 | | - | else false |
---|
1776 | | - | } |
---|
1777 | | - | } |
---|
1778 | | - | else sigVerify(hV.bodyBytes, hV.proofs[0], hX) |
---|
1779 | | - | } |
---|
1780 | | - | |
---|
| 1 | + | # no script |
---|