28 | | - | else this |
---|
29 | | - | } |
---|
30 | | - | |
---|
31 | | - | func p (b,q) = valueOrErrorMessage(getInteger(this, b), q) |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func r (b,q) = valueOrErrorMessage(getString(this, b), q) |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func s (b,q) = valueOrErrorMessage(getInteger(m, b), q) |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | func t (b,q) = valueOrErrorMessage(getString(m, b), q) |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | let u = "BULLId" |
---|
44 | | - | |
---|
45 | | - | let v = "BEARId" |
---|
46 | | - | |
---|
47 | | - | let w = "mainTokenId" |
---|
48 | | - | |
---|
49 | | - | let x = "bullCollateral" |
---|
50 | | - | |
---|
51 | | - | let y = "bearCollateral" |
---|
52 | | - | |
---|
53 | | - | let z = "bullCirculation" |
---|
54 | | - | |
---|
55 | | - | let A = "bearCirculation" |
---|
56 | | - | |
---|
57 | | - | let B = "issuePercentile" |
---|
58 | | - | |
---|
59 | | - | let C = "redeemPercentile" |
---|
60 | | - | |
---|
61 | | - | let D = "minIssue" |
---|
62 | | - | |
---|
63 | | - | let E = "minRedeem" |
---|
64 | | - | |
---|
65 | | - | let F = "minPool" |
---|
66 | | - | |
---|
67 | | - | let G = "feesAccumulated" |
---|
68 | | - | |
---|
69 | | - | let H = "issueWhiteList" |
---|
70 | | - | |
---|
71 | | - | let I = "rebalancePercentile" |
---|
72 | | - | |
---|
73 | | - | let J = "lastSettlementPriceId" |
---|
74 | | - | |
---|
75 | | - | let K = "headPointer" |
---|
76 | | - | |
---|
77 | | - | let L = "tailPointer" |
---|
78 | | - | |
---|
79 | | - | let M = "queueSize" |
---|
80 | | - | |
---|
81 | | - | let N = "poolMainTokenValue" |
---|
82 | | - | |
---|
83 | | - | let O = "poolUp" |
---|
84 | | - | |
---|
85 | | - | let P = "poolDwn" |
---|
86 | | - | |
---|
87 | | - | let Q = "poolTokenCirculation" |
---|
88 | | - | |
---|
89 | | - | let R = "poolToken" |
---|
90 | | - | |
---|
91 | | - | let S = "leverage" |
---|
92 | | - | |
---|
93 | | - | let T = "wavesPacemakerFee" |
---|
94 | | - | |
---|
95 | | - | let U = "usdnPacemakerFee" |
---|
96 | | - | |
---|
97 | | - | let V = "oraclev2" |
---|
98 | | - | |
---|
99 | | - | let W = "assetidv2" |
---|
100 | | - | |
---|
101 | | - | let X = valueOrErrorMessage(getString(this, V), "no oraclev2 key") |
---|
102 | | - | |
---|
103 | | - | let Y = valueOrErrorMessage(getString(this, W), "no assetidv2") |
---|
104 | | - | |
---|
105 | | - | let Z = valueOrElse(getInteger(m, (toString(this) + "_deviationPercentile")), 0) |
---|
106 | | - | |
---|
107 | | - | let aa = ("%s%s__idxCurrent__" + Y) |
---|
108 | | - | |
---|
109 | | - | let ab = (("%s%s%d__idx2Height__" + Y) + "__") |
---|
110 | | - | |
---|
111 | | - | let ac = (("%s%s%d__priceByHeight__" + Y) + "__") |
---|
112 | | - | |
---|
113 | | - | let ad = valueOrElse(getInteger(m, U), 0) |
---|
114 | | - | |
---|
115 | | - | let ae = valueOrElse(getInteger(m, T), 0) |
---|
116 | | - | |
---|
117 | | - | let af = p(x, "no 0") |
---|
118 | | - | |
---|
119 | | - | let ag = p(y, "no 1") |
---|
120 | | - | |
---|
121 | | - | let ah = p(z, "no 2") |
---|
122 | | - | |
---|
123 | | - | let ai = p(A, "no 3") |
---|
124 | | - | |
---|
125 | | - | let aj = r(u, "no 14") |
---|
126 | | - | |
---|
127 | | - | let ak = r(v, "no 15") |
---|
128 | | - | |
---|
129 | | - | let al = r(w, "no 16") |
---|
130 | | - | |
---|
131 | | - | let am = s(B, "no 4") |
---|
132 | | - | |
---|
133 | | - | let an = s(C, "no 5") |
---|
134 | | - | |
---|
135 | | - | let ao = s(D, "no 6") |
---|
136 | | - | |
---|
137 | | - | let ap = s(E, "no 7") |
---|
138 | | - | |
---|
139 | | - | let aq = s(F, "no 8") |
---|
140 | | - | |
---|
141 | | - | let ar = valueOrElse(getInteger(m, ((toString(this) + "_") + I)), 0) |
---|
142 | | - | |
---|
143 | | - | let as = t(H, "no 9") |
---|
144 | | - | |
---|
145 | | - | func at (f) = if ((as == "")) |
---|
146 | | - | then true |
---|
147 | | - | else isDefined(indexOf(as, toString(f))) |
---|
148 | | - | |
---|
149 | | - | |
---|
150 | | - | let au = p(N, "no") |
---|
151 | | - | |
---|
152 | | - | let av = p(O, "no 10") |
---|
153 | | - | |
---|
154 | | - | let aw = p(P, "no 11") |
---|
155 | | - | |
---|
156 | | - | let ax = r(R, "no 12") |
---|
157 | | - | |
---|
158 | | - | let ay = p(Q, "no 13") |
---|
159 | | - | |
---|
160 | | - | let az = fraction(af, av, ah) |
---|
161 | | - | |
---|
162 | | - | let aA = fraction(ag, aw, ai) |
---|
163 | | - | |
---|
164 | | - | let aB = ((au + az) + aA) |
---|
165 | | - | |
---|
166 | | - | let aC = valueOrErrorMessage(addressFromString(X), "bad oracle address") |
---|
167 | | - | |
---|
168 | | - | let aD = s("closeInterval", "no CI") |
---|
169 | | - | |
---|
170 | | - | let aE = valueOrErrorMessage(getInteger(this, J), "no last rebalance price") |
---|
171 | | - | |
---|
172 | | - | let aF = valueOrErrorMessage(getInteger(aC, aa), ((("bad oracle data at " + toString(aC)) + ": no integer at ") + aa)) |
---|
173 | | - | |
---|
174 | | - | let aG = valueOrElse(getInteger(this, S), 3) |
---|
175 | | - | |
---|
176 | | - | func aH (aI) = valueOrErrorMessage(getInteger(aC, (ab + toString(aI))), ("no data at index " + toString(aI))) |
---|
177 | | - | |
---|
178 | | - | |
---|
179 | | - | func aJ (aK) = valueOrErrorMessage(getInteger(aC, (ac + toString(aK))), ("no data for height " + toString(aK))) |
---|
180 | | - | |
---|
181 | | - | |
---|
182 | | - | func aL (aI) = aJ(aH(aI)) |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | let aM = valueOrElse(getInteger(this, M), 0) |
---|
186 | | - | |
---|
187 | | - | let aN = valueOrElse(getString(this, K), "") |
---|
188 | | - | |
---|
189 | | - | let aO = valueOrElse(getString(this, L), "") |
---|
190 | | - | |
---|
191 | | - | let aP = valueOrElse(getInteger(this, G), 0) |
---|
192 | | - | |
---|
193 | | - | let aQ = (aN == "") |
---|
194 | | - | |
---|
195 | | - | let aR = if (aQ) |
---|
196 | | - | then k |
---|
197 | | - | else { |
---|
198 | | - | let aS = split(r(aN, "settle2: bad head pointer"), "|") |
---|
199 | | - | parseIntValue(aS[3]) |
---|
200 | | - | } |
---|
201 | | - | |
---|
202 | | - | let aT = aL(aE) |
---|
203 | | - | |
---|
204 | | - | let aU = "ISSUE" |
---|
205 | | - | |
---|
206 | | - | let aV = "REDEEM" |
---|
207 | | - | |
---|
208 | | - | let aW = "POOL" |
---|
209 | | - | |
---|
210 | | - | let aX = "UNPOOL" |
---|
211 | | - | |
---|
212 | | - | let aY = "feeAddress" |
---|
213 | | - | |
---|
214 | | - | let aZ = "stakingAddress" |
---|
215 | | - | |
---|
216 | | - | let ba = "daemonPublicKey" |
---|
217 | | - | |
---|
218 | | - | let bb = valueOrErrorMessage(addressFromString(t(aY, "no feeAddress")), "bad feeAddress") |
---|
219 | | - | |
---|
220 | | - | let bc = t(aZ, "no stakingAddress") |
---|
221 | | - | |
---|
222 | | - | let bd = fromBase58String(t(ba, "no daemonPublicKey")) |
---|
223 | | - | |
---|
224 | | - | let be = valueOrErrorMessage(addressFromString("3PNikM6yp4NqcSU8guxQtmR5onr2D4e8yTJ"), "bad rpd address") |
---|
225 | | - | |
---|
226 | | - | let bf = ["2HHqV8W9DJayV5R6tBD2Sb8srphpoboDi7r1t1aPiumC", "5ZXe82RRASU7qshXM2J9JNYhqJ9GWYjjVq2gwUV5Naz9", "5WRXFSjwcTbNfKcJs8ZqXmSSWYsSVJUtMvMqZj5hH4Nc"] |
---|
227 | | - | |
---|
228 | | - | func bg (bh,g,bi,aI,bj,bk,bl) = (((((((((((((bh + "|") + toString(g)) + "|") + bi) + "|") + toString(aI)) + "|") + bj) + "|") + toString(bk)) + "|") + toString(bl)) + "|") |
---|
229 | | - | |
---|
230 | | - | |
---|
231 | | - | func bm (bn,bo) = { |
---|
232 | | - | let bp = (bn - bo) |
---|
233 | | - | if ((bp > 0)) |
---|
234 | | - | then bp |
---|
235 | | - | else (0 - bp) |
---|
| 56 | + | else if ((x == r)) |
---|
| 57 | + | then { |
---|
| 58 | + | let C = fraction(n, A, p) |
---|
| 59 | + | [IntegerEntry(i, (n - C)), IntegerEntry(k, (p - A)), ScriptTransfer(B, C, fromBase58String(s))] |
---|
| 60 | + | } |
---|
| 61 | + | else throw("bad token attached") |
---|
239 | | - | func bq () = bm((af - az), (ag - aA)) |
---|
240 | | - | |
---|
241 | | - | |
---|
242 | | - | func br (bs) = { |
---|
243 | | - | let bt = if ((av > 0)) |
---|
244 | | - | then aj |
---|
245 | | - | else ak |
---|
246 | | - | if ((bs != bt)) |
---|
247 | | - | then au |
---|
248 | | - | else (bq() + aB) |
---|
249 | | - | } |
---|
250 | | - | |
---|
251 | | - | |
---|
252 | | - | func bu (bv,bk) = if ((0 > bk)) |
---|
253 | | - | then throw("negative min payout") |
---|
254 | | - | else { |
---|
255 | | - | let bw = bv.payments[1] |
---|
256 | | - | let bx = { |
---|
257 | | - | let n = bw.assetId |
---|
258 | | - | if ($isInstanceOf(n, "ByteVector")) |
---|
259 | | - | then { |
---|
260 | | - | let by = n |
---|
261 | | - | if ((toBase58String(by) == al)) |
---|
262 | | - | then (bw.amount >= ad) |
---|
263 | | - | else false |
---|
264 | | - | } |
---|
265 | | - | else if ($isInstanceOf(n, "Unit")) |
---|
266 | | - | then { |
---|
267 | | - | let bz = n |
---|
268 | | - | (bw.amount >= ae) |
---|
269 | | - | } |
---|
270 | | - | else throw("Match error") |
---|
271 | | - | } |
---|
272 | | - | if (!(bx)) |
---|
273 | | - | then throw("incorrect pacemaker fee") |
---|
274 | | - | else true |
---|
275 | | - | } |
---|
276 | | - | |
---|
277 | | - | |
---|
278 | | - | func bA (bB,bh,g,bi,aI,bj,bk,bl) = if (!(valueOrElse(getBoolean(this, "enableEnqueue"), true))) |
---|
279 | | - | then throw("enqueue paused") |
---|
280 | | - | else { |
---|
281 | | - | let bC = d(M, (aM + 1)) |
---|
282 | | - | let bD = bg(bh, g, bi, aI, bj, bk, bl) |
---|
283 | | - | if ((aM == 0)) |
---|
284 | | - | then [a(K, bB), a(L, bB), a(bB, bD), bC] |
---|
285 | | - | else { |
---|
286 | | - | let bE = r(L, "can't get tail pointer") |
---|
287 | | - | let bF = r(bE, "can't resolve pointer") |
---|
288 | | - | let bG = (bF + bB) |
---|
289 | | - | [a(bE, bG), a(bB, bD), a(L, bB), bC] |
---|
290 | | - | } |
---|
291 | | - | } |
---|
292 | | - | |
---|
293 | | - | |
---|
294 | | - | func bH (bI,bJ,bK,bL,bM,bN,bO,bP) = { |
---|
295 | | - | func bQ (bR,bS,bT,bn,bU,bV,bW) = { |
---|
296 | | - | let bp = (bR - bS) |
---|
297 | | - | let bX = fraction(bR, bV, bT) |
---|
298 | | - | let bY = if ((bp > bX)) |
---|
299 | | - | then bV |
---|
300 | | - | else fraction(bp, bT, bR) |
---|
301 | | - | let bZ = if ((bp > bX)) |
---|
302 | | - | then bX |
---|
303 | | - | else fraction(bY, bR, bT) |
---|
304 | | - | $Tuple7((bR - bZ), bS, (bT - bY), bn, (bU + bZ), (bV - bY), bW) |
---|
305 | | - | } |
---|
306 | | - | |
---|
307 | | - | func ca (bR,bS,bT,bn,bU,bV,bW) = { |
---|
308 | | - | let bp = (bS - bR) |
---|
309 | | - | let bX = fraction(bS, bW, bn) |
---|
310 | | - | let bY = if ((bp > bX)) |
---|
311 | | - | then bW |
---|
312 | | - | else fraction(bp, bn, bS) |
---|
313 | | - | let bZ = if ((bp > bX)) |
---|
314 | | - | then bX |
---|
315 | | - | else fraction(bY, bS, bn) |
---|
316 | | - | $Tuple7(bR, (bS - bZ), bT, (bn - bY), (bU + bZ), bV, (bW - bY)) |
---|
317 | | - | } |
---|
318 | | - | |
---|
319 | | - | func cb (bR,bS,bT,bn,bU,bV,bW) = { |
---|
320 | | - | let bp = (bR - bS) |
---|
321 | | - | let cc = if ((bU > bp)) |
---|
322 | | - | then bp |
---|
323 | | - | else bU |
---|
324 | | - | let cd = fraction(cc, bn, bS) |
---|
325 | | - | $Tuple7(bR, (bS + cc), bT, (bn + cd), (bU - cc), bV, (bW + cd)) |
---|
326 | | - | } |
---|
327 | | - | |
---|
328 | | - | func ce (bR,bS,bT,bn,bU,bV,bW) = { |
---|
329 | | - | let bp = (bS - bR) |
---|
330 | | - | let cc = if ((bU > bp)) |
---|
331 | | - | then bp |
---|
332 | | - | else bU |
---|
333 | | - | let cd = fraction(cc, bT, bR) |
---|
334 | | - | $Tuple7((bR + cc), bS, (bT + cd), bn, (bU - cc), (bV + cd), bW) |
---|
335 | | - | } |
---|
336 | | - | |
---|
337 | | - | let cf = if ((bI > bJ)) |
---|
338 | | - | then { |
---|
339 | | - | let cg = bQ(bI, bJ, bK, bL, bM, bN, bO) |
---|
340 | | - | let ch = cg |
---|
341 | | - | let f = ch._1 |
---|
342 | | - | let ci = ch._2 |
---|
343 | | - | let cj = ch._3 |
---|
344 | | - | let ck = ch._4 |
---|
345 | | - | let q = ch._5 |
---|
346 | | - | let cl = ch._6 |
---|
347 | | - | let cm = ch._7 |
---|
348 | | - | if ((cl > 0)) |
---|
349 | | - | then cg |
---|
350 | | - | else if ((cl == 0)) |
---|
351 | | - | then cb(f, ci, cj, ck, q, cl, cm) |
---|
352 | | - | else throw("poolUp < 0") |
---|
353 | | - | } |
---|
354 | | - | else { |
---|
355 | | - | let cn = ca(bI, bJ, bK, bL, bM, bN, bO) |
---|
356 | | - | let co = cn |
---|
357 | | - | let f = co._1 |
---|
358 | | - | let ci = co._2 |
---|
359 | | - | let cj = co._3 |
---|
360 | | - | let ck = co._4 |
---|
361 | | - | let q = co._5 |
---|
362 | | - | let cl = co._6 |
---|
363 | | - | let cm = co._7 |
---|
364 | | - | if ((cm > 0)) |
---|
365 | | - | then cn |
---|
366 | | - | else if ((cm == 0)) |
---|
367 | | - | then ce(f, ci, cj, ck, q, cl, cm) |
---|
368 | | - | else throw("poolDwn < 0") |
---|
369 | | - | } |
---|
370 | | - | let bR = cf._1 |
---|
371 | | - | let bS = cf._2 |
---|
372 | | - | let bT = cf._3 |
---|
373 | | - | let bn = cf._4 |
---|
374 | | - | let bU = cf._5 |
---|
375 | | - | let bV = cf._6 |
---|
376 | | - | let bW = cf._7 |
---|
377 | | - | let cp = fraction(bq(), (ar * bP), ((1440 * 100) * 100)) |
---|
378 | | - | let cq = if ((bW > 0)) |
---|
379 | | - | then cp |
---|
380 | | - | else 0 |
---|
381 | | - | let cr = if ((bV > 0)) |
---|
382 | | - | then cp |
---|
383 | | - | else 0 |
---|
384 | | - | $Tuple7((bR - cq), (bS - cr), bT, bn, ((bU + cq) + cr), bV, bW) |
---|
385 | | - | } |
---|
386 | | - | |
---|
387 | | - | |
---|
388 | | - | func cs (bI,bJ,bK,bL) = { |
---|
389 | | - | let ct = bH(bI, bJ, bK, bL, au, av, aw, 0) |
---|
390 | | - | let cu = ct._1 |
---|
391 | | - | let cv = ct._2 |
---|
392 | | - | let cw = ct._3 |
---|
393 | | - | let cx = ct._4 |
---|
394 | | - | let cy = ct._5 |
---|
395 | | - | let cz = ct._6 |
---|
396 | | - | let cA = ct._7 |
---|
397 | | - | [d(x, cu), d(z, cw), d(y, cv), d(A, cx), d(N, cy), d(O, cz), d(P, cA)] |
---|
398 | | - | } |
---|
399 | | - | |
---|
400 | | - | |
---|
401 | | - | func cB () = { |
---|
402 | | - | func cC (f,cD) = if ((cD >= f)) |
---|
403 | | - | then $Tuple2(f, 0) |
---|
404 | | - | else $Tuple2(cD, (f - cD)) |
---|
405 | | - | |
---|
406 | | - | if ((aM == 0)) |
---|
407 | | - | then throw("nothing to settle") |
---|
408 | | - | else { |
---|
409 | | - | func cE (cF) = d(G, (aP + cF)) |
---|
410 | | - | |
---|
411 | | - | let cG = d(M, (aM - 1)) |
---|
412 | | - | let cH = (aN == aO) |
---|
413 | | - | let cI = a(L, "") |
---|
414 | | - | let cJ = r(aN, "bad head pointer(dequeue)") |
---|
415 | | - | let aS = split(cJ, "|") |
---|
416 | | - | let bh = aS[0] |
---|
417 | | - | let g = parseIntValue(aS[1]) |
---|
418 | | - | let bi = aS[2] |
---|
419 | | - | let aI = parseIntValue(aS[3]) |
---|
420 | | - | let bj = addressFromStringValue(aS[4]) |
---|
421 | | - | let bk = if ((8 > size(aS))) |
---|
422 | | - | then 0 |
---|
423 | | - | else parseIntValue(aS[5]) |
---|
424 | | - | let bl = if ((8 > size(aS))) |
---|
425 | | - | then k |
---|
426 | | - | else parseIntValue(aS[6]) |
---|
427 | | - | let cK = aS[(size(aS) - 1)] |
---|
428 | | - | func cL (cM) = [a(K, cK), cG, e(bj, g, fromBase58String(cM))] |
---|
429 | | - | |
---|
430 | | - | let cN = if ((aE != aI)) |
---|
431 | | - | then throw(((("corrupt state, settledPriceIndex=" + toString(aE)) + ", request price id=") + toString(aI))) |
---|
432 | | - | else if ((bh == aU)) |
---|
433 | | - | then { |
---|
434 | | - | let cO = fraction(g, am, 10000) |
---|
435 | | - | let cP = (g - cO) |
---|
436 | | - | let cQ = if ((bi == aj)) |
---|
437 | | - | then fraction(ah, cP, af) |
---|
438 | | - | else if ((bi == ak)) |
---|
439 | | - | then fraction(ai, cP, ag) |
---|
440 | | - | else throw("bad token id") |
---|
441 | | - | let cR = cC(cQ, bl) |
---|
442 | | - | let cS = cR._1 |
---|
443 | | - | let cT = cR._2 |
---|
444 | | - | let cU = if ((bi == aj)) |
---|
445 | | - | then $Tuple4(cQ, cP, 0, 0) |
---|
446 | | - | else $Tuple4(0, 0, cQ, cP) |
---|
447 | | - | let cV = cU._1 |
---|
448 | | - | let cW = cU._2 |
---|
449 | | - | let cX = cU._3 |
---|
450 | | - | let cY = cU._4 |
---|
451 | | - | if ((bk > cS)) |
---|
452 | | - | then cL(al) |
---|
453 | | - | else (cs((af + cW), (ag + cY), (ah + cV), (ai + cX)) ++ [a(K, cK), cE(cO), cG, e(bj, cS, fromBase58String(bi)), e(bb, cT, fromBase58String(bi))]) |
---|
454 | | - | } |
---|
455 | | - | else if ((bh == aV)) |
---|
456 | | - | then { |
---|
457 | | - | let cZ = g |
---|
458 | | - | let da = if ((bi == aj)) |
---|
459 | | - | then fraction(af, cZ, ah) |
---|
460 | | - | else if ((bi == ak)) |
---|
461 | | - | then fraction(ag, cZ, ai) |
---|
462 | | - | else throw("bad token id") |
---|
463 | | - | let cO = fraction(da, an, 10000) |
---|
464 | | - | let db = (da - cO) |
---|
465 | | - | let dc = cC(db, bl) |
---|
466 | | - | let dd = dc._1 |
---|
467 | | - | let de = dc._2 |
---|
468 | | - | let df = if ((bi == aj)) |
---|
469 | | - | then $Tuple4(cZ, da, 0, 0) |
---|
470 | | - | else $Tuple4(0, 0, cZ, da) |
---|
471 | | - | let dg = df._1 |
---|
472 | | - | let dh = df._2 |
---|
473 | | - | let di = df._3 |
---|
474 | | - | let dj = df._4 |
---|
475 | | - | if ((bk > dd)) |
---|
476 | | - | then cL(bi) |
---|
477 | | - | else (cs((af - dh), (ag - dj), (ah - dg), (ai - di)) ++ [a(K, cK), cE(cO), cG, e(bj, dd, fromBase58String(al)), e(bb, de, fromBase58String(al))]) |
---|
478 | | - | } |
---|
479 | | - | else if ((bh == aW)) |
---|
480 | | - | then { |
---|
481 | | - | let dk = fraction(ay, g, aB) |
---|
482 | | - | if ((bk > dk)) |
---|
483 | | - | then cL(al) |
---|
484 | | - | else [d(N, (au + g)), d(Q, (ay + dk)), a(K, cK), cG, e(bj, dk, fromBase58String(ax))] |
---|
485 | | - | } |
---|
486 | | - | else if ((bh == aX)) |
---|
487 | | - | then { |
---|
488 | | - | func dl (f) = fraction(f, g, ay) |
---|
489 | | - | |
---|
490 | | - | let dm = dl(au) |
---|
491 | | - | let dn = dl(av) |
---|
492 | | - | let do = dl(aw) |
---|
493 | | - | let dp = fraction(dn, af, ah) |
---|
494 | | - | let dq = fraction(do, ag, ai) |
---|
495 | | - | let dr = ((dm + dp) + dq) |
---|
496 | | - | if ((bk > dr)) |
---|
497 | | - | then cL(ax) |
---|
498 | | - | else [d(N, (au - dm)), d(Q, (ay - g)), d(O, (av - dn)), d(P, (aw - do)), d(z, (ah - dn)), d(A, (ai - do)), d(x, (af - dp)), d(y, (ag - dq)), a(K, cK), cG, e(bj, dr, fromBase58String(al))] |
---|
499 | | - | } |
---|
500 | | - | else throw(("bad action: " + bh)) |
---|
501 | | - | if (cH) |
---|
502 | | - | then cI :: cN |
---|
503 | | - | else cN |
---|
504 | | - | } |
---|
505 | | - | } |
---|
506 | | - | |
---|
507 | | - | |
---|
508 | | - | func ds (dt) = if (!(valueOrElse(getBoolean(this, "enableRebalance"), true))) |
---|
509 | | - | then throw("rebalance paused") |
---|
510 | | - | else if ((dt == 0)) |
---|
511 | | - | then throw("[OK] offset=0") |
---|
512 | | - | else { |
---|
513 | | - | func du (c,dv,dw,dx) = { |
---|
514 | | - | let dy = { |
---|
515 | | - | let dz = (((2 * (if ((dw > dv)) |
---|
516 | | - | then dw |
---|
517 | | - | else dv)) * dx) / 3037000499) |
---|
518 | | - | if ((10 > dz)) |
---|
519 | | - | then 10 |
---|
520 | | - | else if ((100 > dz)) |
---|
521 | | - | then 100 |
---|
522 | | - | else 1000 |
---|
523 | | - | } |
---|
524 | | - | let dA = ((if ((dw > dv)) |
---|
525 | | - | then dw |
---|
526 | | - | else dv) / dy) |
---|
527 | | - | let dB = ((if ((dv > dw)) |
---|
528 | | - | then dw |
---|
529 | | - | else dv) / dy) |
---|
530 | | - | let f = (dB * dB) |
---|
531 | | - | let ci = ((((dx * dx) * dA) * dA) - (((((2 * dx) * dx) - dx) * dA) * dB)) |
---|
532 | | - | let dC = ((dx * dx) - dx) |
---|
533 | | - | fraction(c, ((dC * f) + ci), (((dC + 1) * f) + ci)) |
---|
534 | | - | } |
---|
535 | | - | |
---|
536 | | - | let dD = (aE + dt) |
---|
537 | | - | let dE = aL(dD) |
---|
538 | | - | let dF = if ((ag > af)) |
---|
539 | | - | then af |
---|
540 | | - | else ag |
---|
541 | | - | let dG = du(dF, aT, dE, aG) |
---|
542 | | - | let dH = (dE > aT) |
---|
543 | | - | let dI = if (dH) |
---|
544 | | - | then (af + dG) |
---|
545 | | - | else (af - dG) |
---|
546 | | - | let dJ = if (dH) |
---|
547 | | - | then (ag - dG) |
---|
548 | | - | else (ag + dG) |
---|
549 | | - | let dK = bH(dI, dJ, ah, ai, au, av, aw, dt) |
---|
550 | | - | let dL = dK._1 |
---|
551 | | - | let dM = dK._2 |
---|
552 | | - | let dN = dK._3 |
---|
553 | | - | let dO = dK._4 |
---|
554 | | - | let dP = dK._5 |
---|
555 | | - | let dQ = dK._6 |
---|
556 | | - | let dR = dK._7 |
---|
557 | | - | [d(x, dL), d(y, dM), d(z, dN), d(A, dO), d(N, dP), d(O, dQ), d(P, dR), d(J, dD)] |
---|
558 | | - | } |
---|
559 | | - | |
---|
560 | | - | |
---|
561 | | - | func dS (dT,dU) = if ((dT > dU)) |
---|
562 | | - | then throw(((("price too old: minPayout " + toString(dT)) + " > avg = ") + toString(dU))) |
---|
563 | | - | else ((dU + dU) - dT) |
---|
564 | | - | |
---|
565 | | - | |
---|
566 | | - | @Callable(bv) |
---|
567 | | - | func enableEnqueue (dV) = if ((bv.caller != bb)) |
---|
568 | | - | then throw("only admin can") |
---|
569 | | - | else [BooleanEntry("enableEnqueue", dV)] |
---|
570 | | - | |
---|
571 | | - | |
---|
572 | | - | |
---|
573 | | - | @Callable(bv) |
---|
574 | | - | func enableRebalance (dV) = if ((bv.caller != bb)) |
---|
575 | | - | then throw("only admin can") |
---|
576 | | - | else [BooleanEntry("enableRebalance", dV)] |
---|
577 | | - | |
---|
578 | | - | |
---|
579 | | - | |
---|
580 | | - | @Callable(bv) |
---|
581 | | - | func withdrawFee (dW) = if ((dW > aP)) |
---|
582 | | - | then throw(("too much. available: " + toString(aP))) |
---|
583 | | - | else [d(G, (aP - dW)), e(bb, dW, fromBase58String(al))] |
---|
584 | | - | |
---|
585 | | - | |
---|
586 | | - | |
---|
587 | | - | @Callable(dX) |
---|
588 | | - | func requestRedeemSl (bk) = if (bu(dX, bk)) |
---|
589 | | - | then { |
---|
590 | | - | let g = dX.payments[0].amount |
---|
591 | | - | let bs = toBase58String(valueOrErrorMessage(dX.payments[0].assetId, "bad token att")) |
---|
592 | | - | if (if ((bs != aj)) |
---|
593 | | - | then (bs != ak) |
---|
594 | | - | else false) |
---|
595 | | - | then throw("bad token req") |
---|
596 | | - | else { |
---|
597 | | - | let dY = if ((bs == aj)) |
---|
598 | | - | then $Tuple2(af, ah) |
---|
599 | | - | else if ((bs == ak)) |
---|
600 | | - | then $Tuple2(ag, ai) |
---|
601 | | - | else throw("bad token req") |
---|
602 | | - | let dZ = dY._1 |
---|
603 | | - | let ea = dY._2 |
---|
604 | | - | let eb = fraction(g, dZ, ea) |
---|
605 | | - | let ec = if ((bk == 0)) |
---|
606 | | - | then $Tuple2(0, k) |
---|
607 | | - | else $Tuple2(bk, dS(bk, eb)) |
---|
608 | | - | let ed = ec._1 |
---|
609 | | - | let ee = ec._2 |
---|
610 | | - | if ((dX.caller == this)) |
---|
611 | | - | then throw("can't do") |
---|
612 | | - | else { |
---|
613 | | - | let ef = fraction(dZ, g, ea) |
---|
614 | | - | if ((ap > ef)) |
---|
615 | | - | then throw((("Attached payment too small. Min redeem amount is " + toString((ap / 1000000))) + " USDN")) |
---|
616 | | - | else bA(toBase58String(dX.transactionId), aV, g, bs, (aF + 1), toString(dX.caller), ed, ee) |
---|
617 | | - | } |
---|
618 | | - | } |
---|
619 | | - | } |
---|
620 | | - | else throw() |
---|
621 | | - | |
---|
622 | | - | |
---|
623 | | - | |
---|
624 | | - | @Callable(dX) |
---|
625 | | - | func requestIssueSl (bs,bk) = if (bu(dX, bk)) |
---|
626 | | - | then if (if ((bs != aj)) |
---|
627 | | - | then (bs != ak) |
---|
628 | | - | else false) |
---|
629 | | - | then throw("bad token req") |
---|
630 | | - | else if (!(at(dX.caller))) |
---|
631 | | - | then throw("only whitelisted can do") |
---|
632 | | - | else if ((dX.payments[0].assetId != fromBase58String(al))) |
---|
633 | | - | then throw("bad token att") |
---|
634 | | - | else { |
---|
635 | | - | let g = dX.payments[0].amount |
---|
636 | | - | let eg = if ((bs == aj)) |
---|
637 | | - | then $Tuple2(af, ah) |
---|
638 | | - | else if ((bs == ak)) |
---|
639 | | - | then $Tuple2(ag, ai) |
---|
640 | | - | else throw("bad token req") |
---|
641 | | - | let dZ = eg._1 |
---|
642 | | - | let ea = eg._2 |
---|
643 | | - | let eb = fraction(g, ea, dZ) |
---|
644 | | - | let eh = if ((bk == 0)) |
---|
645 | | - | then $Tuple2(0, k) |
---|
646 | | - | else $Tuple2(bk, dS(bk, eb)) |
---|
647 | | - | let ed = eh._1 |
---|
648 | | - | let ee = eh._2 |
---|
649 | | - | if ((ao > g)) |
---|
650 | | - | then throw((("Attached payment too small. Min required: " + toString((ao / 1000000))) + " USDN")) |
---|
651 | | - | else { |
---|
652 | | - | let ei = br(bs) |
---|
653 | | - | if (if ((as == "")) |
---|
654 | | - | then (dX.payments[0].amount > ei) |
---|
655 | | - | else false) |
---|
656 | | - | then throw((("trying to issue more than pool can handle. Max attachment allowed = " + toString((ei / 1000000))) + " USDN")) |
---|
657 | | - | else bA(toBase58String(dX.transactionId), aU, g, bs, (aF + 1), toString(dX.caller), ed, ee) |
---|
658 | | - | } |
---|
659 | | - | } |
---|
660 | | - | else throw() |
---|
661 | | - | |
---|
662 | | - | |
---|
663 | | - | |
---|
664 | | - | @Callable(dX) |
---|
665 | | - | func requestPool () = if (!(at(dX.caller))) |
---|
666 | | - | then throw("only whitelisted can do") |
---|
667 | | - | else { |
---|
668 | | - | let ej = dX.payments[0] |
---|
669 | | - | if ((ej.assetId != fromBase58String(al))) |
---|
670 | | - | then throw("USDN required") |
---|
671 | | - | else if ((aq > ej.amount)) |
---|
672 | | - | then throw(("pool min: " + toString(aq))) |
---|
673 | | - | else { |
---|
674 | | - | let ek = fraction(ay, ej.amount, aB) |
---|
675 | | - | bA(toBase58String(dX.transactionId), aW, dX.payments[0].amount, "", (aF + 1), toString(dX.caller), 0, k) |
---|
676 | | - | } |
---|
677 | | - | } |
---|
678 | | - | |
---|
679 | | - | |
---|
680 | | - | |
---|
681 | | - | @Callable(dX) |
---|
682 | | - | func requestUnpool () = { |
---|
683 | | - | let ej = dX.payments[0] |
---|
684 | | - | if ((ej.assetId != fromBase58String(ax))) |
---|
685 | | - | then throw("bad token att") |
---|
686 | | - | else { |
---|
687 | | - | let ek = fraction(aB, ej.amount, ay) |
---|
688 | | - | if ((aq > ek)) |
---|
689 | | - | then throw(((("unpool at least for" + toString(aq)) + " ") + al)) |
---|
690 | | - | else bA(toBase58String(dX.transactionId), aX, dX.payments[0].amount, "", (aF + 1), toString(dX.caller), 0, k) |
---|
691 | | - | } |
---|
| 65 | + | @Callable(D) |
---|
| 66 | + | func withdrawFee (E) = { |
---|
| 67 | + | let F = valueOrErrorMessage(getInteger(this, l), "no fees acc") |
---|
| 68 | + | if ((E > F)) |
---|
| 69 | + | then throw(("too much. available: " + toString(F))) |
---|
| 70 | + | else [IntegerEntry(l, (F - E)), ScriptTransfer(u, E, fromBase58String(s))] |
---|