14 | | - | let f = d |
---|
15 | | - | throw("expected int5&boolean") |
---|
16 | | - | } |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | let g = "admin" |
---|
21 | | - | |
---|
22 | | - | let h = "config" |
---|
23 | | - | |
---|
24 | | - | let i = "reserves" |
---|
25 | | - | |
---|
26 | | - | let j = "aTokenId" |
---|
27 | | - | |
---|
28 | | - | let k = "assetId" |
---|
29 | | - | |
---|
30 | | - | let l = addressFromStringValue(getStringValue(this, g)) |
---|
31 | | - | |
---|
32 | | - | let m = addressFromStringValue(getStringValue(this, h)) |
---|
33 | | - | |
---|
34 | | - | let n = valueOrErrorMessage(getString(this, i), "no reserves registered") |
---|
35 | | - | |
---|
36 | | - | let o = split(n, "|") |
---|
37 | | - | |
---|
38 | | - | func p (q) = valueOrErrorMessage(getString(q, k), "no assetId in reserve") |
---|
39 | | - | |
---|
40 | | - | |
---|
41 | | - | func r (q) = valueOrErrorMessage(getInteger(m, (p(q) + "_CollateralFactor")), "no CollateralFactor in config") |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | func s (q) = valueOrErrorMessage(getInteger(m, (p(q) + "_LiquidationThreshold")), "no LiquidationThreshold in config") |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | func t (u) = valueOrErrorMessage(getInteger(m, (u + "_LiquidationPenalty")), "no LiquidationPenalty in config") |
---|
48 | | - | |
---|
49 | | - | |
---|
50 | | - | let v = valueOrErrorMessage(getInteger(m, "account_health_threshold"), "no account_health_threshold") |
---|
51 | | - | |
---|
52 | | - | let w = valueOrErrorMessage(getInteger(m, "account_health_overlap"), "no account_health_overlap") |
---|
53 | | - | |
---|
54 | | - | let x = valueOrErrorMessage(getInteger(m, "collapse_penalty"), "no collapse_penalty") |
---|
55 | | - | |
---|
56 | | - | let y = valueOrElse(getString(m, "liquidators"), "") |
---|
57 | | - | |
---|
58 | | - | func z (A) = if (contains(n, A)) |
---|
59 | | - | then true |
---|
60 | | - | else throw(("unknown reserve:" + A)) |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | func B (q,C) = b(invoke(q, "userBalance", [C], nil)) |
---|
64 | | - | |
---|
65 | | - | |
---|
66 | | - | func D (E,c) = { |
---|
67 | | - | func F (G,A) = { |
---|
68 | | - | let d = G |
---|
69 | | - | if ($isInstanceOf(d, "Address")) |
---|
70 | | - | then { |
---|
71 | | - | let H = d |
---|
72 | | - | H |
---|
73 | | - | } |
---|
74 | | - | else { |
---|
75 | | - | let q = valueOrErrorMessage(addressFromString(A), "reserve bad address") |
---|
76 | | - | if ((valueOrErrorMessage(getString(q, E), ("reserve has no " + E)) == c)) |
---|
77 | | - | then q |
---|
78 | | - | else unit |
---|
79 | | - | } |
---|
80 | | - | } |
---|
81 | | - | |
---|
82 | | - | let d = { |
---|
83 | | - | let I = o |
---|
84 | | - | let J = size(I) |
---|
85 | | - | let K = unit |
---|
86 | | - | func L (M,N) = if ((N >= J)) |
---|
87 | | - | then M |
---|
88 | | - | else F(M, I[N]) |
---|
89 | | - | |
---|
90 | | - | func O (M,N) = if ((N >= J)) |
---|
91 | | - | then M |
---|
92 | | - | else throw("List size exceeds 6") |
---|
93 | | - | |
---|
94 | | - | O(L(L(L(L(L(L(K, 0), 1), 2), 3), 4), 5), 6) |
---|
95 | | - | } |
---|
96 | | - | if ($isInstanceOf(d, "Address")) |
---|
97 | | - | then { |
---|
98 | | - | let H = d |
---|
99 | | - | H |
---|
100 | | - | } |
---|
101 | | - | else throw(("unknown " + E)) |
---|
102 | | - | } |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | func P (c,Q,R) = { |
---|
106 | | - | let S = fraction(c, Q, R) |
---|
107 | | - | let T = 3037000499 |
---|
108 | | - | let U = ((((S % T) * (R % T)) % T) == (((c % T) * (Q % T)) % T)) |
---|
109 | | - | if (U) |
---|
110 | | - | then S |
---|
111 | | - | else (S + 1) |
---|
112 | | - | } |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | func V (C) = { |
---|
116 | | - | func F (W,A) = { |
---|
117 | | - | let X = W |
---|
118 | | - | let Y = X._1 |
---|
119 | | - | let Z = X._2 |
---|
120 | | - | let q = valueOrErrorMessage(addressFromString(A), "reserve bad address") |
---|
121 | | - | let aa = r(q) |
---|
122 | | - | let ab = s(q) |
---|
123 | | - | let ac = B(q, C) |
---|
124 | | - | let ad = ac._1 |
---|
125 | | - | let ae = ac._2 |
---|
126 | | - | let af = ac._3 |
---|
127 | | - | let ag = ac._4 |
---|
128 | | - | let ah = ac._5 |
---|
129 | | - | let ai = ac._6 |
---|
130 | | - | let aj = if (ai) |
---|
131 | | - | then af |
---|
132 | | - | else 0 |
---|
133 | | - | let ak = min([ah, aj]) |
---|
134 | | - | let al = P(ak, w, a) |
---|
135 | | - | if ((ah > aj)) |
---|
136 | | - | then $Tuple2(Y, ((Z + fraction((ah - aj), a, ab)) + al)) |
---|
137 | | - | else $Tuple2((Y + fraction((aj - ah), aa, a)), (Z + al)) |
---|
138 | | - | } |
---|
139 | | - | |
---|
140 | | - | let I = o |
---|
141 | | - | let J = size(I) |
---|
142 | | - | let K = $Tuple2(0, 0) |
---|
143 | | - | func L (M,N) = if ((N >= J)) |
---|
144 | | - | then M |
---|
145 | | - | else F(M, I[N]) |
---|
146 | | - | |
---|
147 | | - | func O (M,N) = if ((N >= J)) |
---|
148 | | - | then M |
---|
149 | | - | else throw("List size exceeds 6") |
---|
150 | | - | |
---|
151 | | - | O(L(L(L(L(L(L(K, 0), 1), 2), 3), 4), 5), 6) |
---|
152 | | - | } |
---|
153 | | - | |
---|
154 | | - | |
---|
155 | | - | func am (C,an) = { |
---|
156 | | - | let ao = V(C) |
---|
157 | | - | let ap = ao._1 |
---|
158 | | - | let aq = ao._2 |
---|
159 | | - | let ar = (((ap - aq) * a) / ap) |
---|
160 | | - | if (if ((ap == 0)) |
---|
161 | | - | then (aq == 0) |
---|
162 | | - | else false) |
---|
163 | | - | then nil |
---|
164 | | - | else if (if ((ap == 0)) |
---|
165 | | - | then (aq > 0) |
---|
166 | | - | else false) |
---|
167 | | - | then throw(((an + " too much: breaching liquidation threshold(bp=0, bpu=") + toString(aq))) |
---|
168 | | - | else if ((v > ar)) |
---|
169 | | - | then throw((((((((an + " too much: breaching liquidation threshold(bp=") + toString(ap)) + ", bpu=") + toString(aq)) + ", health=") + toString(ar)) + ")")) |
---|
170 | | - | else nil |
---|
171 | | - | } |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | @Callable(as) |
---|
175 | | - | func withdraw (u,at) = { |
---|
176 | | - | let C = toString(as.caller) |
---|
177 | | - | let au = D(k, u) |
---|
178 | | - | let av = invoke(au, "withdrawFor", [C, at], nil) |
---|
179 | | - | if ((av == av)) |
---|
180 | | - | then am(C, "withdrawing") |
---|
181 | | - | else throw("Strict value is not equal to itself.") |
---|
182 | | - | } |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | |
---|
186 | | - | @Callable(as) |
---|
187 | | - | func withdraw2 (q,at) = { |
---|
188 | | - | let aw = z(q) |
---|
189 | | - | if ((aw == aw)) |
---|
190 | | - | then { |
---|
191 | | - | let C = toString(as.caller) |
---|
192 | | - | let au = addressFromStringValue(q) |
---|
193 | | - | let av = invoke(au, "withdrawFor", [C, at], nil) |
---|
194 | | - | if ((av == av)) |
---|
195 | | - | then am(C, "withdrawing2") |
---|
| 14 | + | let f = reentrantInvoke(addressFromStringValue(d), "usdn_100", nil, nil) |
---|
| 15 | + | if ((f == f)) |
---|
| 16 | + | then throw("success") |
---|