tx · 9XbMTyPLt5fDyAAJKWfgvEwsGt5hfeRo6ZJyxN98cJX8

3Mz1td457M34EA7wU1swt2DBQDZEDpsMtgE:  -0.00500000 Waves

2022.08.29 19:21 [2205975] smart account 3Mz1td457M34EA7wU1swt2DBQDZEDpsMtgE > SELF 0.00000000 Waves

{ "type": 13, "id": "9XbMTyPLt5fDyAAJKWfgvEwsGt5hfeRo6ZJyxN98cJX8", "fee": 500000, "feeAssetId": null, "timestamp": 1661790122655, "version": 2, "chainId": 84, "sender": "3Mz1td457M34EA7wU1swt2DBQDZEDpsMtgE", "senderPublicKey": "DKoVYQRirYnan4ojiUkT12oE6XmpyNoht3ZcecUpgLsf", "proofs": [ "42mRuMYySEftmW4mLnuXy6uWWTwSzFCvK7J19zXtT6E4wmBYh8DHdtZKdH7tLEFJ2w4t6n8eTfCn3izZaYXnuWLt" ], "script": null, "height": 2205975, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: H5tixCueY28hRMFvxKbcyfS8TVKS588AKVuHdFoF88ZY Next: 3ePt1D3XZNax2NH1dGhkYXoxRz6DpMs4rrNR4YczzPwS Full:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let a = "k_ora_key"
5-
6-let b = "k_ora_block_key"
7-
8-let c = "k_ora"
9-
10-let d = "k_balance"
11-
12-let e = "k_positionSize"
13-
14-let f = "k_positionMargin"
15-
16-let g = "k_positionOpenNotional"
17-
18-let h = "k_positionFraction"
19-
20-let i = "k_initialized"
21-
22-let j = "k_paused"
23-
24-let k = "k_fee"
25-
26-let l = "k_fundingPeriod"
27-
28-let m = "k_initMarginRatio"
29-
30-let n = "k_mmr"
31-
32-let o = "k_liquidationFeeRatio"
33-
34-let p = "k_partLiquidationRatio"
35-
36-let q = "k_spreadLimit"
37-
38-let r = "k_maxPriceImpact"
39-
40-let s = "k_maxPriceSpread"
41-
42-let t = "k_lastDataStr"
43-
44-let u = "k_lastMinuteId"
45-
46-let v = "k_twapDataLastCumulativePrice"
47-
48-let w = "k_twapDataLastPrice"
49-
50-let x = "k_twapDataPreviousMinuteId"
51-
52-let y = "k_latestLongPremiumFraction"
53-
54-let z = "k_latestShortPremiumFraction"
55-
56-let A = "k_nextFundingBlockMinTimestamp"
57-
58-let B = "k_longFundingRate"
59-
60-let C = "k_shortFundingRate"
61-
62-let D = "k_qtAstR"
63-
64-let E = "k_bsAstR"
65-
66-let F = "k_totalPositionSize"
67-
68-let G = "k_totalLongPositionSize"
69-
70-let H = "k_totalShortPositionSize"
71-
72-let I = "k_cumulativeNotional"
73-
74-let J = "k_openInterestNotional"
75-
76-let K = "k_coordinatorAddress"
77-
78-let L = "k_insurance_address"
79-
80-let M = "k_admin_address"
81-
82-let N = "k_admin_public_key"
83-
84-let O = "k_quote_asset"
85-
86-let P = "k_quote_staking"
87-
88-let Q = "k_staking_address"
89-
90-let R = "k_miner_address"
91-
92-func S () = valueOrErrorMessage(addressFromString(getStringValue(this, K)), "Coordinator not set")
93-
94-
95-func T () = addressFromString(getStringValue(S(), M))
96-
97-
98-func U () = fromBase58String(getStringValue(S(), N))
99-
100-
101-func V () = fromBase58String(getStringValue(S(), O))
102-
103-
104-func W () = valueOrErrorMessage(addressFromString(getStringValue(S(), P)), "Quote asset staking not set")
105-
106-
107-func X () = valueOrErrorMessage(addressFromString(getStringValue(S(), Q)), "Insurance not set")
108-
109-
110-func Y () = valueOrErrorMessage(addressFromString(getStringValue(S(), L)), "Insurance not set")
111-
112-
113-func Z () = valueOrErrorMessage(addressFromString(getStringValue(S(), R)), "Insurance not set")
114-
115-
116-let aa = 1
117-
118-let ab = 2
119-
120-let ac = 15
121-
122-let ad = 15
123-
124-let ae = 1000
125-
126-let af = (1 * (((((10 * 10) * 10) * 10) * 10) * 10))
127-
128-let ag = (86400 * af)
129-
130-let ah = 100
131-
132-let ai = 1
133-
134-let aj = 2
135-
136-func ak (al) = (toString(al) + ",")
137-
138-
139-func am (al,an) = fraction(al, af, an, HALFEVEN)
140-
141-
142-func ao (al,an) = fraction(al, an, af, HALFEVEN)
143-
144-
145-func ap (al) = if ((al > 0))
146- then al
147- else -(al)
148-
149-
150-func aq (al,an) = if ((al >= an))
151- then al
152- else an
153-
154-
155-func ar (as,at) = ((as + "_") + at)
156-
157-
158-func au (av) = {
159- func aw (ax,ay) = ((ax + ay) + ",")
160-
161- let az = {
162- let aA = av
163- let aB = size(aA)
164- let aC = ""
165- func aD (aE,aF) = if ((aF >= aB))
166- then aE
167- else aw(aE, aA[aF])
168-
169- func aG (aE,aF) = if ((aF >= aB))
170- then aE
171- else throw("List size exceeds 20")
172-
173- aG(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aC, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20)
174- }
175- let aH = dropRight(az, 1)
176- let aI = if ((take(aH, 1) == ","))
177- then drop(aH, 1)
178- else aH
179- aI
180- }
181-
182-
183-func aJ (aK) = split(aK, ",")
184-
185-
186-func aL (av,aM,aN) = if ((size(av) > aM))
187- then (removeByIndex(av, 0) :+ aN)
188- else (av :+ aN)
189-
190-
191-func aO (aP) = valueOrErrorMessage(getInteger(this, aP), ("no value for " + aP))
192-
193-
194-func aQ () = aO(d)
195-
196-
197-func aR () = aO(k)
198-
199-
200-func aS () = aO(m)
201-
202-
203-func aT () = aO(D)
204-
205-
206-func aU () = aO(E)
207-
208-
209-func aV () = aO(F)
210-
211-
212-func aW () = aO(I)
213-
214-
215-func aX () = aO(J)
216-
217-
218-func aY () = aO(A)
219-
220-
221-func aZ () = aO(l)
222-
223-
224-func ba () = (aZ() * af)
225-
226-
227-func bb () = (aZ() * ae)
228-
229-
230-func bc () = aO(n)
231-
232-
233-func bd () = aO(o)
234-
235-
236-func be () = aO(p)
237-
238-
239-func bf () = aO(q)
240-
241-
242-func bg () = aO(r)
243-
244-
245-func bh () = aO(s)
246-
247-
248-func bi () = aO(y)
249-
250-
251-func bj () = aO(z)
252-
253-
254-func bk () = aO(H)
255-
256-
257-func bl () = aO(G)
258-
259-
260-func bm (bn,bo,bp) = {
261- let bq = (bn - bo)
262- if (if (bp)
263- then (0 > bq)
264- else false)
265- then throw("Invalid margin")
266- else if (if (!(bp))
267- then (bq >= 0)
268- else false)
269- then throw("Invalid margin")
270- else true
271- }
272-
273-
274-func br (bs) = if ((bs == 0))
275- then throw("Should not be called with _positionSize == 0")
276- else if ((bs > 0))
277- then bi()
278- else bj()
279-
280-
281-func bt (bu) = {
282- let bv = getInteger(this, ar(e, bu))
283- let bw = bv
284- if ($isInstanceOf(bw, "Int"))
285- then {
286- let bx = bw
287- $Tuple4(bx, getIntegerValue(this, ar(f, bu)), getIntegerValue(this, ar(g, bu)), getIntegerValue(this, ar(h, bu)))
288- }
289- else $Tuple4(0, 0, 0, 0)
290- }
291-
292-
293-func by (bu) = if ((bt(bu)._1 == 0))
294- then throw("No open position")
295- else true
296-
297-
298-func bz () = valueOrElse(getBoolean(this, i), false)
299-
300-
301-func bA () = valueOrElse(getBoolean(this, j), false)
302-
303-
304-func bB (bC,bD,bE) = if (bC)
305- then {
306- let bF = (aU() - bE)
307- if ((0 >= bF))
308- then throw("Tx lead to base asset reserve <= 0, revert")
309- else $Tuple4((aT() + bD), bF, (aV() + bE), (aW() + bD))
310- }
311- else {
312- let bG = (aT() - bD)
313- if ((0 >= bG))
314- then throw("Tx lead to base quote reserve <= 0, revert")
315- else $Tuple4(bG, (aU() + bE), (aV() - bE), (aW() - bD))
316- }
317-
318-
319-func bH (bC,bD) = {
320- let bI = aT()
321- let bJ = aU()
322- let aP = ao(bI, bJ)
323- let bK = if (bC)
324- then (bI + bD)
325- else (bI - bD)
326- let bL = am(aP, bK)
327- let bM = ap((bL - bJ))
328- let bN = if (bC)
329- then bM
330- else -(bM)
331- let bO = bB(bC, bD, bM)
332- let bP = bO._1
333- let bQ = bO._2
334- let bR = bO._3
335- let bS = bO._4
336- let bT = am(bI, bJ)
337- let bU = am(bD, bM)
338- let bV = ap((bT - bU))
339- let bW = (af - am(bT, (bT + bV)))
340- let bX = bg()
341- if ((bW > bX))
342- then throw(((((((((((((("Price impact " + toString(bW)) + " > max price impact ") + toString(bX)) + " before quote asset: ") + toString(bI)) + " before base asset: ") + toString(bJ)) + " quote asset amount to exchange: ") + toString(bD)) + " price before: ") + toString(bT)) + " marketPrice: ") + toString(bU)))
343- else $Tuple5(bN, bP, bQ, bR, bS)
344- }
345-
346-
347-func bY (bZ,ca,cb,cc) = {
348- let cd = if ((bZ != 0))
349- then {
350- let ce = br(bZ)
351- ao((ce - cb), bZ)
352- }
353- else 0
354- let cf = ((cc - cd) + ca)
355- let cg = if ((0 > cf))
356- then $Tuple2(0, ap(cf))
357- else $Tuple2(ap(cf), 0)
358- let ch = cg._1
359- let ci = cg._2
360- $Tuple3(ch, ci, cd)
361- }
362-
363-
364-func cj (bC,bE,ck,cl,cm) = {
365- let bT = am(cl, cm)
366- if ((bE == 0))
367- then throw("Invalid base asset amount")
368- else {
369- let aP = ao(cl, cm)
370- let cn = if (bC)
371- then (cm + bE)
372- else (cm - bE)
373- let co = am(aP, cn)
374- let cp = ap((co - cl))
375- let bX = bg()
376- let cq = bB(!(bC), cp, bE)
377- let bP = cq._1
378- let bQ = cq._2
379- let bR = cq._3
380- let bS = cq._4
381- let bU = am(cp, bE)
382- let bV = ap((bT - bU))
383- let bW = (af - am(bT, (bT + bV)))
384- if (if ((bW > bX))
385- then ck
386- else false)
387- then throw(((((((((((((("Price impact " + toString(bW)) + " > max price impact ") + toString(bX)) + " before quote asset: ") + toString(cl)) + " before base asset: ") + toString(cm)) + " base asset amount to exchange: ") + toString(bE)) + " price before: ") + toString(bT)) + " market price: ") + toString(bU)))
388- else $Tuple8(cp, bP, bQ, bR, bS, (bl() - (if (bC)
389- then ap(bE)
390- else 0)), (bk() - (if (!(bC))
391- then ap(bE)
392- else 0)), bW)
393- }
394- }
395-
396-
397-func cr (bC,bE,ck) = cj(bC, bE, ck, aT(), aU())
398-
399-
400-func cs () = {
401- let ct = valueOrErrorMessage(addressFromString(getStringValue(this, c)), "")
402- let cu = getStringValue(this, a)
403- let cv = getStringValue(this, b)
404- let cw = valueOrErrorMessage(getInteger(ct, cu), ((("Can not get oracle price. Oracle: " + toString(ct)) + " key: ") + cu))
405- cw
406- }
407-
408-
409-func cx (cl,cm) = {
410- let cy = cs()
411- let cz = am(cl, cm)
412- let cA = am((cy + cz), (2 * af))
413- let cB = am(ap((cy - cz)), cA)
414- if ((cB > bh()))
415- then throw(((("Price spread " + toString(cB)) + " > max price spread ") + toString(bh())))
416- else true
417- }
418-
419-
420-func cC () = {
421- let cl = aT()
422- let cm = aU()
423- am(cl, cm)
424- }
425-
426-
427-func cD () = {
428- let cy = cs()
429- let cE = cC()
430- (am(ap((cy - cE)), cy) > bf())
431- }
432-
433-
434-func cF (bs,cG,cl,cm) = {
435- let cH = ap(bs)
436- let cI = (0 > bs)
437- let cJ = if ((cG == ai))
438- then {
439- let cK = cj(!(cI), cH, false, cl, cm)
440- let cL = cK._1
441- let cM = cK._2
442- let cN = cK._3
443- let cO = cK._4
444- cL
445- }
446- else ao(cH, cs())
447- cJ
448- }
449-
450-
451-func cP (bu,cG) = {
452- let cQ = bt(bu)
453- let bx = cQ._1
454- let cR = cQ._2
455- let cS = cQ._3
456- let cT = cQ._4
457- if ((bx == 0))
458- then throw("Invalid position size")
459- else {
460- let cI = (0 > bx)
461- let cJ = cF(bx, cG, aT(), aU())
462- let cU = if (cI)
463- then (cS - cJ)
464- else (cJ - cS)
465- $Tuple2(cJ, cU)
466- }
467- }
468-
469-
470-func cV (cW,cX,cY) = am((cW - cX), cY)
471-
472-
473-func cZ (bu,cG) = {
474- let da = bt(bu)
475- let bx = da._1
476- let cR = da._2
477- let db = da._3
478- let cT = da._4
479- let dc = cP(bu, cG)
480- let cJ = dc._1
481- let cU = dc._2
482- let dd = bY(bx, cR, cT, cU)
483- let ch = dd._1
484- let ci = dd._2
485- cV(ch, ci, cJ)
486- }
487-
488-
489-func de (bu) = cZ(bu, ai)
490-
491-
492-func df (bu,bs) = {
493- let dg = aq(be(), (af - am(de(bu), bc())))
494- let dh = ao(ap(bs), dg)
495- let di = cr((bs > 0), dh, false)
496- let dj = di._1
497- let bW = di._8
498- if ((bg() > bW))
499- then dj
500- else {
501- let dk = ao(ap(bs), be())
502- let dl = cr((bs > 0), dk, false)._1
503- dl
504- }
505- }
506-
507-
508-func dm (bu,ck) = {
509- let dn = bt(bu)
510- let bx = dn._1
511- let cR = dn._2
512- let cS = dn._3
513- let cT = dn._4
514- let cU = cP(bu, ai)._2
515- let do = bY(bx, cR, cT, cU)
516- let ch = do._1
517- let ci = do._2
518- let dk = -(bx)
519- let dp = cU
520- let dq = -(ch)
521- let dr = cr((bx > 0), ap(bx), ck)
522- let dl = dr._1
523- let bK = dr._2
524- let bL = dr._3
525- let ds = dr._4
526- let dt = dr._5
527- let du = dr._6
528- let dv = dr._7
529- let dw = (aX() - cS)
530- $Tuple12(dk, ci, dp, dq, bK, bL, ds, dt, dw, dl, du, dv)
531- }
532-
533-
534-func dx () = {
535- let dy = ((lastBlock.timestamp / 1000) / 60)
536- let dz = (dy - ac)
537- let dA = valueOrElse(getString(this, t), "")
538- let dB = split(dA, ",")
539- func dC (ax,dD) = if ((dz >= parseIntValue(dD)))
540- then (ax :+ parseIntValue(dD))
541- else ax
542-
543- let dE = {
544- let aA = dB
545- let aB = size(aA)
546- let aC = nil
547- func aD (aE,aF) = if ((aF >= aB))
548- then aE
549- else dC(aE, aA[aF])
550-
551- func aG (aE,aF) = if ((aF >= aB))
552- then aE
553- else throw("List size exceeds 20")
554-
555- aG(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aD(aC, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20)
556- }
557- let dF = if ((size(dE) > 0))
558- then max(dE)
559- else parseIntValue(dB[0])
560- let dG = valueOrElse(getInteger(this, u), 0)
561- let dH = valueOrElse(getInteger(this, ((v + "_") + toString(dG))), 0)
562- let dI = valueOrElse(getInteger(this, ((w + "_") + toString(dG))), 0)
563- let dJ = (dH + ((dy - dG) * dI))
564- let dK = valueOrElse(getInteger(this, ((v + "_") + toString(dF))), 0)
565- let dL = valueOrElse(getInteger(this, ((w + "_") + toString(dF))), 0)
566- let dM = (dK + ((dz - dF) * dL))
567- ((dJ - dM) / ac)
568- }
569-
570-
571-func dN (dO,dP,dQ,dR,dS,dT,dU,dV,dW) = [IntegerEntry(m, dO), IntegerEntry(n, dP), IntegerEntry(o, dQ), IntegerEntry(l, dR), IntegerEntry(k, dS), IntegerEntry(q, dT), IntegerEntry(r, dU), IntegerEntry(p, dV), IntegerEntry(s, dW)]
572-
573-
574-func dX (dY,dZ,ea,eb,ec) = [IntegerEntry(A, dY), IntegerEntry(y, dZ), IntegerEntry(z, ea), IntegerEntry(B, eb), IntegerEntry(C, ec)]
575-
576-
577-func ed (at,ee,ef,eg,ce) = [IntegerEntry(ar(e, at), ee), IntegerEntry(ar(f, at), ef), IntegerEntry(ar(g, at), eg), IntegerEntry(ar(h, at), ce)]
578-
579-
580-func eh (ei) = {
581- let dy = ((lastBlock.timestamp / 1000) / 60)
582- let ej = valueOrElse(getInteger(this, u), 0)
583- if ((ej > dy))
584- then throw("TWAP out-of-order")
585- else {
586- let dG = if ((ej == 0))
587- then dy
588- else ej
589- if ((dy > ej))
590- then {
591- let ek = valueOrElse(getInteger(this, ((v + "_") + toString(ej))), 0)
592- let el = valueOrElse(getInteger(this, ((w + "_") + toString(ej))), ei)
593- let em = (ek + ((dy - dG) * el))
594- let dB = aL(aJ(valueOrElse(getString(this, t), "")), ac, toString(dy))
595-[IntegerEntry(ar(v, toString(dy)), em), IntegerEntry(ar(w, toString(dy)), ei), IntegerEntry(ar(x, toString(dy)), ej), IntegerEntry(u, dy), StringEntry(t, au(dB))]
596- }
597- else {
598- let en = valueOrElse(getInteger(this, ar(x, toString(dy))), 0)
599- let ek = valueOrElse(getInteger(this, ar(v, toString(en))), 0)
600- let el = valueOrElse(getInteger(this, ar(w, toString(en))), ei)
601- let em = (ek + ((dy - en) * el))
602-[IntegerEntry(ar(v, toString(dy)), em), IntegerEntry(ar(w, toString(dy)), ei)]
603- }
604- }
605- }
606-
607-
608-func eo (bI,bJ) = [IntegerEntry(D, bI), IntegerEntry(E, bJ)]
609-
610-
611-func ep (bI,bJ,eq,er,es,et,eu) = if (((et - eu) != eq))
612- then throw(((((("Invalid AMM state data: " + toString(et)) + " + ") + toString(eu)) + " != ") + toString(eq)))
613- else ((eo(bI, bJ) ++ [IntegerEntry(F, eq), IntegerEntry(I, er), IntegerEntry(J, es), IntegerEntry(G, et), IntegerEntry(H, eu)]) ++ eh(am(bI, bJ)))
614-
615-
616-func ev (at) = [DeleteEntry(ar(e, at)), DeleteEntry(ar(f, at)), DeleteEntry(ar(g, at)), DeleteEntry(ar(h, at))]
617-
618-
619-func ew (at,ex) = {
620- let ey = assetBalance(this, V())
621- if ((ex > ey))
622- then throw(((("Unable to withdraw " + toString(ex)) + " from contract balance ") + toString(ey)))
623- else [ScriptTransfer(at, ex, V())]
624- }
625-
626-
627-func ez (eA) = if ((0 > eA))
628- then throw("Balance")
629- else [IntegerEntry(d, eA)]
630-
631-
632-func eB (eA) = [ScriptTransfer(X(), eA, V())]
633-
634-
635-@Callable(eA)
636-func pause () = if ((eA.caller != T()))
637- then throw("Invalid togglePause params")
638- else [BooleanEntry(j, true)]
639-
640-
641-
642-@Callable(eA)
643-func unpause () = if ((eA.caller != T()))
644- then throw("Invalid togglePause params")
645- else [BooleanEntry(j, false)]
646-
647-
648-
649-@Callable(eA)
650-func addLiquidity (bD) = if (if ((eA.caller != T()))
651- then true
652- else (0 >= bD))
653- then throw("Invalid addLiquidity params")
654- else {
655- let bI = aT()
656- let bJ = aU()
657- let ei = am(bI, bJ)
658- let eC = am(bD, ei)
659- let eD = (bI + bD)
660- let eE = (bJ + eC)
661- eo(eD, eE)
662- }
663-
664-
665-
666-@Callable(eA)
667-func removeLiquidity (bD) = if (if ((eA.caller != T()))
668- then true
669- else (0 >= bD))
670- then throw("Invalid removeLiquidity params")
671- else {
672- let bI = aT()
673- let bJ = aU()
674- let ei = am(bI, bJ)
675- let eF = am(bD, ei)
676- let eD = (bI - bD)
677- let eE = (bJ - eF)
678- eo(eD, eE)
679- }
680-
681-
682-
683-@Callable(eA)
684-func changeSettings (dO,dP,dQ,dR,dS,dT,dU,dV,dW) = if ((eA.caller != T()))
685- then throw("Invalid changeSettings params")
686- else dN(dO, dP, dQ, dR, dS, dT, dU, dV, dW)
687-
688-
689-
690-@Callable(eA)
691-func initialize (bI,bJ,dR,dO,dP,dQ,dS,eG,eH,eI,dT,dU,dV,dW) = if (if (if (if (if (if (if (if (if (if (if (if ((0 >= bI))
692- then true
693- else (0 >= bJ))
694- then true
695- else (0 >= dR))
696- then true
697- else (0 >= dO))
698- then true
699- else (0 >= dP))
700- then true
701- else (0 >= dQ))
702- then true
703- else (0 >= dS))
704- then true
705- else (0 >= dT))
706- then true
707- else (0 >= dU))
708- then true
709- else (0 >= dV))
710- then true
711- else (0 >= dW))
712- then true
713- else bz())
714- then throw("Invalid initialize parameters")
715- else ((((ep(bI, bJ, 0, 0, 0, 0, 0) ++ dN(dO, dP, dQ, dR, dS, dT, dU, dV, dW)) ++ dX((lastBlock.timestamp + dR), 0, 0, 0, 0)) ++ ez(0)) ++ [BooleanEntry(i, true), StringEntry(c, eG), StringEntry(a, eH), StringEntry(K, eI)])
716-
717-
718-
719-@Callable(eA)
720-func setInitMarginRatio (dO) = if (if ((0 >= dO))
721- then true
722- else !(bz()))
723- then throw("Invalid setInitMarginRatio parameters")
724- else dN(dO, bc(), bd(), aZ(), aR(), bf(), bg(), be(), bh())
725-
726-
727-
728-@Callable(eA)
729-func decreasePosition (ex,eJ,eK) = if (if (if (if (if ((0 >= ex))
730- then true
731- else !(bz()))
732- then true
733- else !(bm(am(af, eJ), aS(), true)))
734- then true
735- else !(by(toString(eA.caller))))
736- then true
737- else bA())
738- then throw("Invalid decreasePosition parameters")
739- else {
740- let eL = bt(toString(eA.caller))
741- let eM = eL._1
742- let eN = eL._2
743- let eO = eL._3
744- let eP = eL._4
745- let eQ = if ((eM > 0))
746- then ab
747- else aa
748- let eR = (eQ == aa)
749- let eS = ao(ex, eJ)
750- let eT = cP(toString(eA.caller), ai)
751- let eU = eT._1
752- let cU = eT._2
753- let eV = if ((eU > eS))
754- then {
755- let eW = bH(eR, eS)
756- let dk = eW._1
757- let bK = eW._2
758- let bL = eW._3
759- let ds = eW._4
760- let dt = eW._5
761- let eX = ap(dk)
762- if (if ((eK != 0))
763- then (eK > eX)
764- else false)
765- then throw(((("Too little base asset exchanged, got " + toString(eX)) + " expected ") + toString(eK)))
766- else {
767- let dp = am(ao(cU, eX), ap(eM))
768- let eY = bY(eM, eN, eP, dp)
769- let ch = eY._1
770- let ci = eY._2
771- let cd = eY._3
772- let dl = eS
773- let eZ = (cU - dp)
774- let fa = if ((eM > 0))
775- then ((eU - dl) - eZ)
776- else ((eZ + eU) - dl)
777- let fb = (eM + dk)
778- $Tuple11(fb, ch, ap(fa), br(fb), bL, bK, ds, dt, (aX() - eS), (bl() - (if ((fb > 0))
779- then ap(dk)
780- else 0)), (bk() - (if ((0 > fb))
781- then ap(dk)
782- else 0)))
783- }
784- }
785- else throw("Close position first")
786- let fb = eV._1
787- let fc = eV._2
788- let fd = eV._3
789- let fe = eV._4
790- let bL = eV._5
791- let bK = eV._6
792- let ds = eV._7
793- let dt = eV._8
794- let dw = eV._9
795- let du = eV._10
796- let dv = eV._11
797- let ff = invoke(Z(), "notifyNotional", [toString(eA.caller), fd], nil)
798- if ((ff == ff))
799- then (ed(toString(eA.caller), fb, fc, fd, fe) ++ ep(bK, bL, ds, dt, dw, du, dv))
800- else throw("Strict value is not equal to itself.")
801- }
802-
803-
804-
805-@Callable(eA)
806-func increasePosition (eQ,eJ,eK) = {
807- let fg = eA.payments[0].amount
808- if (if (if (if (if (if (if ((eQ != aa))
809- then (eQ != ab)
810- else false)
811- then true
812- else (0 >= fg))
813- then true
814- else !(bz()))
815- then true
816- else (eA.payments[0].assetId != V()))
817- then true
818- else !(bm(am(af, eJ), aS(), true)))
819- then true
820- else bA())
821- then throw("Invalid increasePosition parameters")
822- else {
823- let fh = ao(fg, aR())
824- let ex = (fg - fh)
825- let fi = bt(toString(eA.caller))
826- let eM = fi._1
827- let eN = fi._2
828- let eO = fi._3
829- let eP = fi._4
830- let fj = (eM == 0)
831- let fk = if ((eM > 0))
832- then (eQ == aa)
833- else (eQ == ab)
834- let fl = if (!(fj))
835- then fk
836- else false
837- let eR = (eQ == aa)
838- let fm = if (if (fj)
839- then true
840- else fl)
841- then {
842- let eS = ao(ex, eJ)
843- let fn = bH(eR, eS)
844- let bN = fn._1
845- let bK = fn._2
846- let bL = fn._3
847- let ds = fn._4
848- let dt = fn._5
849- if (if ((eK != 0))
850- then (eK > ap(bN))
851- else false)
852- then throw(((("Limit error: " + toString(ap(bN))) + " < ") + toString(eK)))
853- else {
854- let fb = (eM + bN)
855- let fo = am(eS, eJ)
856- let fp = bY(eM, eN, eP, fo)
857- let ch = fp._1
858- let cM = fp._2
859- let cN = fp._3
860- if (!(cx(bK, bL)))
861- then throw("Over max spread limit")
862- else $Tuple11(fb, ch, (eO + eS), br(fb), bL, bK, ds, dt, (aX() + eS), (bl() + (if ((fb > 0))
863- then ap(bN)
864- else 0)), (bk() + (if ((0 > fb))
865- then ap(bN)
866- else 0)))
867- }
868- }
869- else {
870- let eS = ao(ex, eJ)
871- let fq = cP(toString(eA.caller), ai)
872- let eU = fq._1
873- let cU = fq._2
874- if ((eU > eS))
875- then throw("Use decreasePosition to decrease position size")
876- else throw("Close position first")
877- }
878- let fb = fm._1
879- let fc = fm._2
880- let fd = fm._3
881- let fe = fm._4
882- let bL = fm._5
883- let bK = fm._6
884- let ds = fm._7
885- let dt = fm._8
886- let dw = fm._9
887- let du = fm._10
888- let dv = fm._11
889- let fr = (fh / 2)
890- let fs = (fh - fr)
891- let ft = invoke(W(), "lockNeutrinoSP", [toString(X()), ah], [AttachedPayment(V(), ex)])
892- if ((ft == ft))
893- then {
894- let fu = invoke(Y(), "deposit", nil, [AttachedPayment(V(), fs)])
895- if ((fu == fu))
896- then {
897- let fv = invoke(Z(), "notifyFees", [toString(eA.caller), fh], nil)
898- if ((fv == fv))
899- then {
900- let ff = invoke(Z(), "notifyNotional", [toString(eA.caller), fd], nil)
901- if ((ff == ff))
902- then (((ed(toString(eA.caller), fb, fc, fd, fe) ++ ep(bK, bL, ds, dt, dw, du, dv)) ++ eB(fr)) ++ ez((aQ() + ex)))
903- else throw("Strict value is not equal to itself.")
904- }
905- else throw("Strict value is not equal to itself.")
906- }
907- else throw("Strict value is not equal to itself.")
908- }
909- else throw("Strict value is not equal to itself.")
910- }
911- }
912-
913-
914-
915-@Callable(eA)
916-func addMargin () = {
917- let fg = eA.payments[0].amount
918- if (if (if (if ((eA.payments[0].assetId != V()))
919- then true
920- else !(by(toString(eA.caller))))
921- then true
922- else !(bz()))
923- then true
924- else bA())
925- then throw("Invalid addMargin parameters")
926- else {
927- let fh = ao(fg, aR())
928- let ex = (fg - fh)
929- let fw = bt(toString(eA.caller))
930- let eM = fw._1
931- let eN = fw._2
932- let eO = fw._3
933- let eP = fw._4
934- let fr = (fh / 2)
935- let fs = (fh - fr)
936- let ft = invoke(W(), "lockNeutrinoSP", [toString(X()), ah], [AttachedPayment(V(), ex)])
937- if ((ft == ft))
938- then {
939- let fu = invoke(Y(), "deposit", nil, [AttachedPayment(V(), fs)])
940- if ((fu == fu))
941- then {
942- let fv = invoke(Z(), "notifyFees", [toString(eA.caller), fh], nil)
943- if ((fv == fv))
944- then ((ed(toString(eA.caller), eM, (eN + ex), eO, eP) ++ eB(fr)) ++ ez((aQ() + ex)))
945- else throw("Strict value is not equal to itself.")
946- }
947- else throw("Strict value is not equal to itself.")
948- }
949- else throw("Strict value is not equal to itself.")
950- }
951- }
952-
953-
954-
955-@Callable(eA)
956-func removeMargin (ex) = if (if (if (if ((0 >= ex))
957- then true
958- else !(by(toString(eA.caller))))
959- then true
960- else !(bz()))
961- then true
962- else bA())
963- then throw("Invalid removeMargin parameters")
964- else {
965- let fx = bt(toString(eA.caller))
966- let eM = fx._1
967- let eN = fx._2
968- let eO = fx._3
969- let eP = fx._4
970- let fy = -(ex)
971- let fz = bY(eM, eN, eP, fy)
972- let ch = fz._1
973- let ci = fz._2
974- if ((ci != 0))
975- then throw("Invalid removed margin amount")
976- else {
977- let fA = cV(ch, ci, eO)
978- if (!(bm(fA, aS(), true)))
979- then throw(((("Too much margin removed: " + toString(fA)) + " < ") + toString(aS())))
980- else {
981- let fB = invoke(W(), "unlockNeutrino", [ex, toBase58String(V())], nil)
982- if ((fB == fB))
983- then ((ed(toString(eA.caller), eM, ch, eO, br(eM)) ++ ew(eA.caller, ex)) ++ ez((aQ() - ex)))
984- else throw("Strict value is not equal to itself.")
985- }
986- }
987- }
988-
989-
990-
991-@Callable(eA)
992-func closePosition () = if (if (if (!(by(toString(eA.caller))))
993- then true
994- else !(bz()))
995- then true
996- else bA())
997- then throw("Invalid closePosition parameters")
998- else {
999- let fC = dm(toString(eA.caller), true)
1000- let cM = fC._1
1001- let fD = fC._2
1002- let dp = fC._3
1003- let dq = fC._4
1004- let bK = fC._5
1005- let bL = fC._6
1006- let ds = fC._7
1007- let dt = fC._8
1008- let dw = fC._9
1009- let cN = fC._10
1010- let du = fC._11
1011- let dv = fC._12
1012- if ((fD > 0))
1013- then throw("Unable to close position with bad debt")
1014- else {
1015- let fE = ap(dq)
1016- let fF = (aQ() - fE)
1017- let fG = if ((0 > fF))
1018- then $Tuple2(0, ap(fF))
1019- else $Tuple2(fF, 0)
1020- let fH = fG._1
1021- let fI = fG._2
1022- let fJ = if ((fI > 0))
1023- then {
1024- let fK = invoke(Y(), "withdraw", [fI], nil)
1025- if ((fK == fK))
1026- then nil
1027- else throw("Strict value is not equal to itself.")
1028- }
1029- else nil
1030- if ((fJ == fJ))
1031- then {
1032- let fB = invoke(W(), "unlockNeutrino", [(fE - fI), toBase58String(V())], nil)
1033- if ((fB == fB))
1034- then {
1035- let ff = invoke(Z(), "notifyNotional", [toString(eA.caller), 0], nil)
1036- if ((ff == ff))
1037- then (((ev(toString(eA.caller)) ++ ep(bK, bL, ds, dt, dw, du, dv)) ++ ew(eA.caller, fE)) ++ ez(fH))
1038- else throw("Strict value is not equal to itself.")
1039- }
1040- else throw("Strict value is not equal to itself.")
1041- }
1042- else throw("Strict value is not equal to itself.")
1043- }
1044- }
1045-
1046-
1047-
1048-@Callable(eA)
1049-func liquidate (bu) = {
1050- let fL = cZ(bu, ai)
1051- let fA = if (cD())
1052- then {
1053- let fM = cZ(bu, aj)
1054- aq(fL, fM)
1055- }
1056- else fL
1057- if (if (if (if (!(bm(fA, bc(), false)))
1058- then true
1059- else !(by(bu)))
1060- then true
1061- else !(bz()))
1062- then true
1063- else bA())
1064- then throw("Unable to liquidate")
1065- else if (if (if ((fL > bd()))
1066- then (be() > 0)
1067- else false)
1068- then (af > be())
1069- else false)
1070- then {
1071- let fN = bt(bu)
1072- let eM = fN._1
1073- let eN = fN._2
1074- let eO = fN._3
1075- let eP = fN._4
1076- let eQ = if ((eM > 0))
1077- then ab
1078- else aa
1079- let eR = (eQ == aa)
1080- let dl = df(bu, eM)
1081- let fO = cP(bu, ai)
1082- let eU = fO._1
1083- let cU = fO._2
1084- let fP = bH(eR, dl)
1085- let dk = fP._1
1086- let bK = fP._2
1087- let bL = fP._3
1088- let ds = fP._4
1089- let dt = fP._5
1090- let dp = am(ao(cU, ap(dk)), ap(eM))
1091- let fQ = bY(eM, eN, eP, dp)
1092- let ch = fQ._1
1093- let ci = fQ._2
1094- let cd = fQ._3
1095- let eZ = (cU - dp)
1096- let fa = if ((eM > 0))
1097- then ((eU - dl) - eZ)
1098- else ((eZ + eU) - dl)
1099- let fR = ao(dl, bd())
1100- let fS = (fR / 2)
1101- let fs = (fR - fS)
1102- let fT = (ch - fR)
1103- let fb = (eM + dk)
1104- let fd = ap(fa)
1105- let fU = br(fb)
1106- let dw = (aX() - dl)
1107- let fF = (aQ() - fR)
1108- let fV = if ((0 > fF))
1109- then $Tuple2(0, ap(fF))
1110- else $Tuple2(fF, 0)
1111- let fW = fV._1
1112- let fX = fV._2
1113- let fJ = if ((fX > 0))
1114- then {
1115- let fK = invoke(Y(), "withdraw", [fX], nil)
1116- if ((fK == fK))
1117- then nil
1118- else throw("Strict value is not equal to itself.")
1119- }
1120- else nil
1121- if ((fJ == fJ))
1122- then {
1123- let fB = invoke(W(), "unlockNeutrino", [(fR - fX), toBase58String(V())], nil)
1124- if ((fB == fB))
1125- then {
1126- let fu = invoke(Y(), "deposit", nil, [AttachedPayment(V(), fs)])
1127- if ((fu == fu))
1128- then {
1129- let ff = invoke(Z(), "notifyNotional", [bu, fd], nil)
1130- if ((ff == ff))
1131- then (((ed(bu, fb, fT, fd, fU) ++ ep(bK, bL, ds, dt, dw, (bl() - (if ((fb > 0))
1132- then ap(dk)
1133- else 0)), (bk() - (if ((0 > fb))
1134- then ap(dk)
1135- else 0)))) ++ ew(eA.caller, fS)) ++ ez(fW))
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- else {
1145- let fY = dm(bu, false)
1146- let cM = fY._1
1147- let ci = fY._2
1148- let cN = fY._3
1149- let cO = fY._4
1150- let bK = fY._5
1151- let bL = fY._6
1152- let ds = fY._7
1153- let dt = fY._8
1154- let dw = fY._9
1155- let dl = fY._10
1156- let du = fY._11
1157- let dv = fY._12
1158- let fR = ao(dl, bd())
1159- let fS = (fR / 2)
1160- let fs = (fR - fS)
1161- let fF = (aQ() - fR)
1162- let fZ = if ((0 > fF))
1163- then $Tuple2(0, ap(fF))
1164- else $Tuple2(fF, 0)
1165- let fW = fZ._1
1166- let fX = fZ._2
1167- let fJ = if ((fX > 0))
1168- then {
1169- let fK = invoke(Y(), "withdraw", [fX], nil)
1170- if ((fK == fK))
1171- then nil
1172- else throw("Strict value is not equal to itself.")
1173- }
1174- else nil
1175- if ((fJ == fJ))
1176- then {
1177- let fB = invoke(W(), "unlockNeutrino", [(fR - fX), toBase58String(V())], nil)
1178- if ((fB == fB))
1179- then {
1180- let fu = invoke(Y(), "deposit", nil, [AttachedPayment(V(), fs)])
1181- if ((fu == fu))
1182- then {
1183- let ff = invoke(Z(), "notifyNotional", [bu, 0], nil)
1184- if ((ff == ff))
1185- then (((ev(bu) ++ ep(bK, bL, ds, dt, dw, du, dv)) ++ ew(eA.caller, fS)) ++ ez(fW))
1186- else throw("Strict value is not equal to itself.")
1187- }
1188- else throw("Strict value is not equal to itself.")
1189- }
1190- else throw("Strict value is not equal to itself.")
1191- }
1192- else throw("Strict value is not equal to itself.")
1193- }
1194- }
1195-
1196-
1197-
1198-@Callable(eA)
1199-func payFunding () = {
1200- let ga = aY()
1201- if (if (if ((ga > lastBlock.timestamp))
1202- then true
1203- else !(bz()))
1204- then true
1205- else bA())
1206- then throw(((("Invalid funding block timestamp: " + toString(lastBlock.timestamp)) + " < ") + toString(ga)))
1207- else {
1208- let gb = cs()
1209- let gc = dx()
1210- let gd = (gc - gb)
1211- let ge = if (if ((bk() == 0))
1212- then true
1213- else (bl() == 0))
1214- then $Tuple2(0, 0)
1215- else if ((0 > gd))
1216- then {
1217- let gf = am(ao(gd, ba()), ag)
1218- let gg = am(ao(gf, bk()), bl())
1219- $Tuple2(gf, gg)
1220- }
1221- else {
1222- let gg = am(ao(gd, ba()), ag)
1223- let gf = am(ao(gg, bl()), bk())
1224- $Tuple2(gf, gg)
1225- }
1226- let gf = ge._1
1227- let gg = ge._2
1228- dX((ga + bb()), (bi() + gg), (bj() + gf), am(gg, gb), am(gf, gb))
1229- }
1230- }
1231-
1232-
1233-
1234-@Callable(eA)
1235-func v_get (bu) = {
1236- let gh = dm(bu, false)
1237- let cM = gh._1
1238- let cN = gh._2
1239- let cO = gh._3
1240- let gi = gh._4
1241- throw((((ak(cN) + ak(cO)) + ak(gi)) + ak(de(bu))))
1242- }
1243-
1244-
1245-
1246-@Callable(eA)
1247-func view_calcRemainMarginWithFundingPayment (bu) = {
1248- let gj = bt(bu)
1249- let bx = gj._1
1250- let cR = gj._2
1251- let db = gj._3
1252- let cT = gj._4
1253- let gk = cP(bu, ai)
1254- let cJ = gk._1
1255- let cU = gk._2
1256- let gl = bY(bx, cR, cT, cU)
1257- let ch = gl._1
1258- let ci = gl._2
1259- let cd = gl._3
1260- throw((((((ak(ch) + ak(cd)) + ak(de(bu))) + ak(cU)) + ak(ci)) + ak(cJ)))
1261- }
1262-
1263-
1264-
1265-@Callable(eA)
1266-func forceMoveAsset (bu,ex) = if (if ((addressFromPublicKey(U()) != eA.caller))
1267- then true
1268- else (0 > ex))
1269- then throw("Invalid forceMoveAsset parameters")
1270- else {
1271- let fB = invoke(W(), "unlockNeutrino", [ex, toBase58String(V())], nil)
1272- if ((fB == fB))
1273- then (ew(addressFromStringValue(bu), ex) ++ ez((aQ() - ex)))
1274- else throw("Strict value is not equal to itself.")
1275- }
1276-
1277-
1278-@Verifier(gm)
1279-func gn () = sigVerify(gm.bodyBytes, gm.proofs[0], U())
1280-
1+# no script

github/deemru/w8io/169f3d6 
57.48 ms