1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "__" |
---|
5 | | - | |
---|
6 | | - | let b = 8 |
---|
7 | | - | |
---|
8 | | - | let c = "WAVES" |
---|
9 | | - | |
---|
10 | | - | let d = 1000000000000000000 |
---|
11 | | - | |
---|
12 | | - | let e = toBigInt(d) |
---|
13 | | - | |
---|
14 | | - | func f (g) = makeString(["lp_staking_pools.ride:", g], " ") |
---|
15 | | - | |
---|
16 | | - | |
---|
17 | | - | func h (g) = throw(f(g)) |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func i (j,k) = f(makeString(["mandatory ", toString(j), ".", k, " is not defined"], "")) |
---|
21 | | - | |
---|
22 | | - | |
---|
23 | | - | func l (j,k) = valueOrErrorMessage(getString(j, k), i(j, k)) |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func m (j,k) = valueOrErrorMessage(getInteger(j, k), i(j, k)) |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | func n (o) = if ((o == c)) |
---|
30 | | - | then unit |
---|
31 | | - | else fromBase58String(o) |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func p (o) = if ((o == unit)) |
---|
35 | | - | then c |
---|
36 | | - | else toBase58String(value(o)) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func q (r) = if ((r >= 0)) |
---|
40 | | - | then r |
---|
41 | | - | else h("value should be positive") |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | func s () = makeString(["%s", "factoryContract"], a) |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | func t () = makeString(["%s", "lpStakingContract"], a) |
---|
48 | | - | |
---|
49 | | - | |
---|
50 | | - | func u () = makeString(["%s", "stakingContract"], a) |
---|
51 | | - | |
---|
52 | | - | |
---|
53 | | - | func v () = makeString(["%s", "boostingContract"], a) |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | func w () = makeString(["%s", "swapContract"], a) |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | func x () = makeString(["%s", "assetsStoreContract"], a) |
---|
60 | | - | |
---|
61 | | - | |
---|
62 | | - | func y () = makeString(["%s", "usdtAssetId"], a) |
---|
63 | | - | |
---|
64 | | - | |
---|
65 | | - | func z () = makeString(["%s", "wxAssetId"], a) |
---|
66 | | - | |
---|
67 | | - | |
---|
68 | | - | func A () = makeString(["%s", "shutdown"], a) |
---|
69 | | - | |
---|
70 | | - | |
---|
71 | | - | func B () = makeString(["%s", "minDelay"], a) |
---|
72 | | - | |
---|
73 | | - | |
---|
74 | | - | func C () = makeString(["%s", "lockFraction"], a) |
---|
75 | | - | |
---|
76 | | - | |
---|
77 | | - | func D (E) = makeString(["%s%s", p(E), "shareAssetId"], a) |
---|
78 | | - | |
---|
79 | | - | |
---|
80 | | - | func F (G) = makeString(["%s%s", p(G), "baseAssetId"], a) |
---|
81 | | - | |
---|
82 | | - | |
---|
83 | | - | func H (E) = makeString(["%s%s", p(E), "period"], a) |
---|
84 | | - | |
---|
85 | | - | |
---|
86 | | - | func I (E,J) = makeString(["%s%s%d", p(E), "periodStartHeight", toString(J)], a) |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | func K (E) = makeString(["%s%s", p(E), "baseAssetAmountToConvert"], a) |
---|
90 | | - | |
---|
91 | | - | |
---|
92 | | - | func L (E) = makeString(["%s%s", p(E), "shareAssetAmountToConvert"], a) |
---|
93 | | - | |
---|
94 | | - | |
---|
95 | | - | func M (E,N) = makeString(["%s%s%s", p(E), toString(N), "baseAssetAmountToConvert"], a) |
---|
96 | | - | |
---|
97 | | - | |
---|
98 | | - | func O (E,N) = makeString(["%s%s%s%s", p(E), toString(N), "baseAssetAmountToConvert", "period"], a) |
---|
99 | | - | |
---|
100 | | - | |
---|
101 | | - | func P (E,N) = makeString(["%s%s%s", p(E), toString(N), "shareAssetAmountToConvert"], a) |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | func Q (E,N) = makeString(["%s%s%s%s", p(E), toString(N), "shareAssetAmountToConvert", "period"], a) |
---|
105 | | - | |
---|
106 | | - | |
---|
107 | | - | func R (E,J) = makeString(["%s%s%d", p(E), "price", toString(J)], a) |
---|
108 | | - | |
---|
109 | | - | |
---|
110 | | - | func S (E) = makeString(["%s%s%s%d%d", p(E), "price", "history", toString(lastBlock.height), toString(lastBlock.timestamp)], a) |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | func T (E,J) = makeString(["%s%s%d%s", p(E), "price", toString(J), "put"], a) |
---|
114 | | - | |
---|
115 | | - | |
---|
116 | | - | func U (E) = makeString(["%s%s%s%s%d%d", p(E), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], a) |
---|
117 | | - | |
---|
118 | | - | |
---|
119 | | - | func V (E,J) = makeString(["%s%s%d%s", p(E), "price", toString(J), "get"], a) |
---|
120 | | - | |
---|
121 | | - | |
---|
122 | | - | func W (E) = makeString(["%s%s%s%s%d%d", p(E), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], a) |
---|
123 | | - | |
---|
124 | | - | |
---|
125 | | - | func X (E,Y,J,N,Z) = makeString(["%s%s%s%s", "history", Y, toString(N), toBase58String(Z), toString(height)], a) |
---|
126 | | - | |
---|
127 | | - | |
---|
128 | | - | func aa () = "%s__managerPublicKey" |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | func ab () = "%s__pendingManagerPublicKey" |
---|
132 | | - | |
---|
133 | | - | |
---|
134 | | - | func ac () = { |
---|
135 | | - | let ad = getString(aa()) |
---|
136 | | - | if ($isInstanceOf(ad, "String")) |
---|
137 | | - | then { |
---|
138 | | - | let ae = ad |
---|
139 | | - | fromBase58String(ae) |
---|
140 | | - | } |
---|
141 | | - | else if ($isInstanceOf(ad, "Unit")) |
---|
142 | | - | then unit |
---|
143 | | - | else throw("Match error") |
---|
144 | | - | } |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | func af () = { |
---|
148 | | - | let ad = getString(ab()) |
---|
149 | | - | if ($isInstanceOf(ad, "String")) |
---|
150 | | - | then { |
---|
151 | | - | let ae = ad |
---|
152 | | - | fromBase58String(ae) |
---|
153 | | - | } |
---|
154 | | - | else if ($isInstanceOf(ad, "Unit")) |
---|
155 | | - | then unit |
---|
156 | | - | else throw("Match error") |
---|
157 | | - | } |
---|
158 | | - | |
---|
159 | | - | |
---|
160 | | - | let ag = throw("Permission denied") |
---|
161 | | - | |
---|
162 | | - | func ah (ai) = if ((ai.caller == this)) |
---|
163 | | - | then true |
---|
164 | | - | else ag |
---|
165 | | - | |
---|
166 | | - | |
---|
167 | | - | func aj (ai) = { |
---|
168 | | - | let ad = ac() |
---|
169 | | - | if ($isInstanceOf(ad, "ByteVector")) |
---|
170 | | - | then { |
---|
171 | | - | let ak = ad |
---|
172 | | - | if ((ai.callerPublicKey == ak)) |
---|
173 | | - | then true |
---|
174 | | - | else ag |
---|
175 | | - | } |
---|
176 | | - | else if ($isInstanceOf(ad, "Unit")) |
---|
177 | | - | then ah(ai) |
---|
178 | | - | else throw("Match error") |
---|
179 | | - | } |
---|
180 | | - | |
---|
181 | | - | |
---|
182 | | - | let al = valueOrElse(getBoolean(A()), false) |
---|
183 | | - | |
---|
184 | | - | func am (ai) = if (if (!(al)) |
---|
185 | | - | then true |
---|
186 | | - | else aj(ai)) |
---|
187 | | - | then true |
---|
188 | | - | else throw("operation is disabled") |
---|
189 | | - | |
---|
190 | | - | |
---|
191 | | - | let an = addressFromStringValue(l(this, s())) |
---|
192 | | - | |
---|
193 | | - | let ao = addressFromStringValue(l(this, t())) |
---|
194 | | - | |
---|
195 | | - | let ap = addressFromStringValue(l(this, u())) |
---|
196 | | - | |
---|
197 | | - | let aq = addressFromStringValue(l(this, v())) |
---|
198 | | - | |
---|
199 | | - | let ar = addressFromStringValue(l(this, w())) |
---|
200 | | - | |
---|
201 | | - | let as = addressFromStringValue(l(this, x())) |
---|
202 | | - | |
---|
203 | | - | let at = n(l(this, y())) |
---|
204 | | - | |
---|
205 | | - | let au = n(l(this, z())) |
---|
206 | | - | |
---|
207 | | - | let av = 1440 |
---|
208 | | - | |
---|
209 | | - | let aw = valueOrElse(getInteger(this, B()), av) |
---|
210 | | - | |
---|
211 | | - | let ax = 100000000 |
---|
212 | | - | |
---|
213 | | - | let ay = fraction(1, ax, 2) |
---|
214 | | - | |
---|
215 | | - | let az = valueOrElse(getInteger(this, C()), ay) |
---|
216 | | - | |
---|
217 | | - | func aA (aB) = { |
---|
218 | | - | let aC = p(aB) |
---|
219 | | - | let aD = p(at) |
---|
220 | | - | let aE = { |
---|
221 | | - | let aF = invoke(an, "poolInfoREADONLY", [aC, aD], nil) |
---|
222 | | - | if ($isInstanceOf(aF, "(Address, ByteVector)")) |
---|
223 | | - | then aF |
---|
224 | | - | else unit |
---|
225 | | - | } |
---|
226 | | - | aE |
---|
227 | | - | } |
---|
228 | | - | |
---|
229 | | - | |
---|
230 | | - | func aG (aH,G) = { |
---|
231 | | - | let aI = valueOrErrorMessage(assetInfo(G), "failed to get share asset info") |
---|
232 | | - | let aJ = aI.quantity |
---|
233 | | - | let aK = q(valueOrErrorMessage({ |
---|
234 | | - | let aF = invoke(ap, "stakedByUserREADONLY", [p(aH), toString(this)], nil) |
---|
235 | | - | if ($isInstanceOf(aF, "Int")) |
---|
236 | | - | then aF |
---|
237 | | - | else unit |
---|
238 | | - | }, f("invalid stakedByUserREADONLY result"))) |
---|
239 | | - | let aL = if ((aJ == 0)) |
---|
240 | | - | then e |
---|
241 | | - | else fraction(toBigInt(aK), e, toBigInt(aJ), FLOOR) |
---|
242 | | - | aL |
---|
243 | | - | } |
---|
244 | | - | |
---|
245 | | - | |
---|
246 | | - | @Callable(ai) |
---|
247 | | - | func setManager (aM) = { |
---|
248 | | - | let aN = aj(ai) |
---|
249 | | - | if ((aN == aN)) |
---|
250 | | - | then { |
---|
251 | | - | let aO = fromBase58String(aM) |
---|
252 | | - | if ((aO == aO)) |
---|
253 | | - | then [StringEntry(ab(), aM)] |
---|
254 | | - | else throw("Strict value is not equal to itself.") |
---|
255 | | - | } |
---|
256 | | - | else throw("Strict value is not equal to itself.") |
---|
257 | | - | } |
---|
258 | | - | |
---|
259 | | - | |
---|
260 | | - | |
---|
261 | | - | @Callable(ai) |
---|
262 | | - | func confirmManager () = { |
---|
263 | | - | let aP = af() |
---|
264 | | - | let aQ = if (isDefined(aP)) |
---|
265 | | - | then true |
---|
266 | | - | else h("no pending manager") |
---|
267 | | - | if ((aQ == aQ)) |
---|
268 | | - | then { |
---|
269 | | - | let aR = if ((ai.callerPublicKey == value(aP))) |
---|
270 | | - | then true |
---|
271 | | - | else h("you are not pending manager") |
---|
272 | | - | if ((aR == aR)) |
---|
273 | | - | then [StringEntry(aa(), toBase58String(value(aP))), DeleteEntry(ab())] |
---|
274 | | - | else throw("Strict value is not equal to itself.") |
---|
275 | | - | } |
---|
276 | | - | else throw("Strict value is not equal to itself.") |
---|
277 | | - | } |
---|
278 | | - | |
---|
279 | | - | |
---|
280 | | - | |
---|
281 | | - | @Callable(ai) |
---|
282 | | - | func emit (aS,aT) = { |
---|
283 | | - | let aN = ah(ai) |
---|
284 | | - | if ((aN == aN)) |
---|
285 | | - | then { |
---|
286 | | - | let aU = true |
---|
287 | | - | $Tuple2([Reissue(aS, aT, aU)], aT) |
---|
288 | | - | } |
---|
289 | | - | else throw("Strict value is not equal to itself.") |
---|
290 | | - | } |
---|
291 | | - | |
---|
292 | | - | |
---|
293 | | - | |
---|
294 | | - | @Callable(ai) |
---|
295 | | - | func burn (aS,aT) = { |
---|
296 | | - | let aN = ah(ai) |
---|
297 | | - | if ((aN == aN)) |
---|
298 | | - | then $Tuple2([Burn(aS, aT)], aT) |
---|
299 | | - | else throw("Strict value is not equal to itself.") |
---|
300 | | - | } |
---|
301 | | - | |
---|
302 | | - | |
---|
303 | | - | |
---|
304 | | - | @Callable(ai) |
---|
305 | | - | func create (aV,aW,aX,aY,aZ) = { |
---|
306 | | - | let ba = "STAKING_LP" |
---|
307 | | - | let E = n(aV) |
---|
308 | | - | let bb = [aj(ai), if (isDefined(aA(E))) |
---|
309 | | - | then true |
---|
310 | | - | else h("invalid base asset")] |
---|
311 | | - | if ((bb == bb)) |
---|
312 | | - | then { |
---|
313 | | - | let bc = [IntegerEntry(H(E), 0)] |
---|
314 | | - | if ((aW == "")) |
---|
315 | | - | then { |
---|
316 | | - | let bd = 1 |
---|
317 | | - | let be = Issue(aX, aY, bd, b, true) |
---|
318 | | - | let bf = calculateAssetId(be) |
---|
319 | | - | let bg = Burn(bf, bd) |
---|
320 | | - | let bh = toBase58String(bf) |
---|
321 | | - | let bi = invoke(as, "createOrUpdate", [bh, aZ, false], nil) |
---|
322 | | - | if ((bi == bi)) |
---|
323 | | - | then { |
---|
324 | | - | let bj = invoke(as, "addLabel", [bh, ba], nil) |
---|
325 | | - | if ((bj == bj)) |
---|
326 | | - | then $Tuple2((bc ++ [be, bg, StringEntry(D(E), bh), StringEntry(F(bf), aV)]), bh) |
---|
327 | | - | else throw("Strict value is not equal to itself.") |
---|
328 | | - | } |
---|
329 | | - | else throw("Strict value is not equal to itself.") |
---|
330 | | - | } |
---|
331 | | - | else { |
---|
332 | | - | let G = fromBase58String(aW) |
---|
333 | | - | let aI = valueOrErrorMessage(assetInfo(G), f("invalid share asset id")) |
---|
334 | | - | let bk = if ((aI.issuer == ao)) |
---|
335 | | - | then true |
---|
336 | | - | else h("invalid share asset id issuer") |
---|
337 | | - | if ((bk == bk)) |
---|
338 | | - | then $Tuple2((bc ++ [StringEntry(D(E), aW), StringEntry(F(G), aV)]), aW) |
---|
339 | | - | else throw("Strict value is not equal to itself.") |
---|
340 | | - | } |
---|
341 | | - | } |
---|
342 | | - | else throw("Strict value is not equal to itself.") |
---|
343 | | - | } |
---|
344 | | - | |
---|
345 | | - | |
---|
346 | | - | |
---|
347 | | - | @Callable(ai) |
---|
348 | | - | func put () = { |
---|
349 | | - | let bl = if ((size(ai.payments) == 1)) |
---|
350 | | - | then ai.payments[0] |
---|
351 | | - | else h("exactly 1 payment is expected") |
---|
352 | | - | let E = bl.assetId |
---|
353 | | - | let N = ai.caller |
---|
354 | | - | let bb = [am(ai), if (isDefined(getString(D(E)))) |
---|
355 | | - | then true |
---|
356 | | - | else h("invalid asset")] |
---|
357 | | - | if ((bb == bb)) |
---|
358 | | - | then { |
---|
359 | | - | let bm = valueOrErrorMessage(aA(E), f("invalid asset")) |
---|
360 | | - | let bn = bm._1 |
---|
361 | | - | let aH = bm._2 |
---|
362 | | - | let J = value(getInteger(H(E))) |
---|
363 | | - | let bo = getInteger(O(E, N)) |
---|
364 | | - | let bp = if ((bo == unit)) |
---|
365 | | - | then unit |
---|
366 | | - | else { |
---|
367 | | - | let bq = value(bo) |
---|
368 | | - | if ((bq == J)) |
---|
369 | | - | then unit |
---|
370 | | - | else invoke(this, "claimShareAsset", [p(E), toString(N)], nil) |
---|
371 | | - | } |
---|
372 | | - | if ((bp == bp)) |
---|
373 | | - | then { |
---|
374 | | - | let br = valueOrElse(getInteger(K(E)), 0) |
---|
375 | | - | let bs = valueOrElse(getInteger(M(E, N)), 0) |
---|
376 | | - | $Tuple2([IntegerEntry(K(E), (br + bl.amount)), IntegerEntry(M(E, N), (bs + bl.amount)), IntegerEntry(O(E, N), J), IntegerEntry(X(E, "put", J, N, ai.transactionId), bl.amount)], unit) |
---|
377 | | - | } |
---|
378 | | - | else throw("Strict value is not equal to itself.") |
---|
379 | | - | } |
---|
380 | | - | else throw("Strict value is not equal to itself.") |
---|
381 | | - | } |
---|
382 | | - | |
---|
383 | | - | |
---|
384 | | - | |
---|
385 | | - | @Callable(ai) |
---|
386 | | - | func claimShareAsset (aV,bt) = { |
---|
387 | | - | let bb = [am(ai)] |
---|
388 | | - | if ((bb == bb)) |
---|
389 | | - | then { |
---|
390 | | - | let N = if ((bt == "")) |
---|
391 | | - | then ai.caller |
---|
392 | | - | else { |
---|
393 | | - | let aN = ah(ai) |
---|
394 | | - | if ((aN == aN)) |
---|
395 | | - | then valueOrErrorMessage(addressFromString(bt), f("invalid user address")) |
---|
396 | | - | else throw("Strict value is not equal to itself.") |
---|
397 | | - | } |
---|
398 | | - | if ((N == N)) |
---|
399 | | - | then { |
---|
400 | | - | let E = n(aV) |
---|
401 | | - | let G = value(n(valueOrErrorMessage(getString(D(E)), f("invalid base asset id")))) |
---|
402 | | - | if ((G == G)) |
---|
403 | | - | then { |
---|
404 | | - | let J = valueOrErrorMessage(getInteger(H(E)), f("invalid period")) |
---|
405 | | - | if ((J == J)) |
---|
406 | | - | then { |
---|
407 | | - | let bs = valueOrElse(getInteger(M(E, N)), 0) |
---|
408 | | - | let bu = if ((bs > 0)) |
---|
409 | | - | then true |
---|
410 | | - | else h("nothing to claim") |
---|
411 | | - | if ((bu == bu)) |
---|
412 | | - | then { |
---|
413 | | - | let bq = valueOrErrorMessage(getInteger(O(E, N)), f("failed to get period")) |
---|
414 | | - | let bv = if ((J > bq)) |
---|
415 | | - | then true |
---|
416 | | - | else h("invalid period") |
---|
417 | | - | if ((bv == bv)) |
---|
418 | | - | then { |
---|
419 | | - | let aL = toBigInt(valueOrErrorMessage(getBinary(T(E, bq)), f("failed to get price"))) |
---|
420 | | - | let bw = toInt(fraction(toBigInt(bs), e, aL)) |
---|
421 | | - | $Tuple2([IntegerEntry(M(E, N), 0), DeleteEntry(O(E, N)), ScriptTransfer(N, bw, G), IntegerEntry(X(E, "claimShareAsset", J, N, ai.transactionId), bw)], unit) |
---|
422 | | - | } |
---|
423 | | - | else throw("Strict value is not equal to itself.") |
---|
424 | | - | } |
---|
425 | | - | else throw("Strict value is not equal to itself.") |
---|
426 | | - | } |
---|
427 | | - | else throw("Strict value is not equal to itself.") |
---|
428 | | - | } |
---|
429 | | - | else throw("Strict value is not equal to itself.") |
---|
430 | | - | } |
---|
431 | | - | else throw("Strict value is not equal to itself.") |
---|
432 | | - | } |
---|
433 | | - | else throw("Strict value is not equal to itself.") |
---|
434 | | - | } |
---|
435 | | - | |
---|
436 | | - | |
---|
437 | | - | |
---|
438 | | - | @Callable(ai) |
---|
439 | | - | func get () = { |
---|
440 | | - | let bb = [am(ai)] |
---|
441 | | - | if ((bb == bb)) |
---|
442 | | - | then { |
---|
443 | | - | let bl = if ((size(ai.payments) == 1)) |
---|
444 | | - | then ai.payments[0] |
---|
445 | | - | else h("exactly 1 payment is expected") |
---|
446 | | - | let G = bl.assetId |
---|
447 | | - | let E = value(n(valueOrErrorMessage(getString(F(G)), f("invalid share asset id")))) |
---|
448 | | - | if ((E == E)) |
---|
449 | | - | then { |
---|
450 | | - | let N = ai.caller |
---|
451 | | - | let bx = valueOrErrorMessage(aA(E), f("invalid asset")) |
---|
452 | | - | let bn = bx._1 |
---|
453 | | - | let aH = bx._2 |
---|
454 | | - | let J = value(getInteger(H(E))) |
---|
455 | | - | let by = getInteger(Q(E, N)) |
---|
456 | | - | let bz = if ((by == unit)) |
---|
457 | | - | then unit |
---|
458 | | - | else { |
---|
459 | | - | let bA = value(by) |
---|
460 | | - | if ((bA == J)) |
---|
461 | | - | then unit |
---|
462 | | - | else invoke(this, "claimBaseAsset", [p(E), toString(N)], nil) |
---|
463 | | - | } |
---|
464 | | - | if ((bz == bz)) |
---|
465 | | - | then { |
---|
466 | | - | let bB = valueOrElse(getInteger(L(E)), 0) |
---|
467 | | - | let bC = valueOrElse(getInteger(P(E, N)), 0) |
---|
468 | | - | $Tuple2([IntegerEntry(L(E), (bB + bl.amount)), IntegerEntry(P(E, N), (bC + bl.amount)), IntegerEntry(Q(E, N), J), IntegerEntry(X(E, "get", J, N, ai.transactionId), bl.amount)], unit) |
---|
469 | | - | } |
---|
470 | | - | else throw("Strict value is not equal to itself.") |
---|
471 | | - | } |
---|
472 | | - | else throw("Strict value is not equal to itself.") |
---|
473 | | - | } |
---|
474 | | - | else throw("Strict value is not equal to itself.") |
---|
475 | | - | } |
---|
476 | | - | |
---|
477 | | - | |
---|
478 | | - | |
---|
479 | | - | @Callable(ai) |
---|
480 | | - | func claimBaseAsset (aV,bt) = { |
---|
481 | | - | let bb = [am(ai)] |
---|
482 | | - | if ((bb == bb)) |
---|
483 | | - | then { |
---|
484 | | - | let N = if ((bt == "")) |
---|
485 | | - | then ai.caller |
---|
486 | | - | else { |
---|
487 | | - | let aN = ah(ai) |
---|
488 | | - | if ((aN == aN)) |
---|
489 | | - | then valueOrErrorMessage(addressFromString(bt), f("invalid user address")) |
---|
490 | | - | else throw("Strict value is not equal to itself.") |
---|
491 | | - | } |
---|
492 | | - | if ((N == N)) |
---|
493 | | - | then { |
---|
494 | | - | let E = n(aV) |
---|
495 | | - | let G = value(n(valueOrErrorMessage(getString(D(E)), f("invalid base asset id")))) |
---|
496 | | - | if ((G == G)) |
---|
497 | | - | then { |
---|
498 | | - | let J = valueOrErrorMessage(getInteger(H(E)), f("invalid period")) |
---|
499 | | - | if ((J == J)) |
---|
500 | | - | then { |
---|
501 | | - | let bC = valueOrElse(getInteger(P(E, N)), 0) |
---|
502 | | - | let bu = if ((bC > 0)) |
---|
503 | | - | then true |
---|
504 | | - | else h("nothing to claim") |
---|
505 | | - | if ((bu == bu)) |
---|
506 | | - | then { |
---|
507 | | - | let bA = valueOrErrorMessage(getInteger(Q(E, N)), f("failed to get period")) |
---|
508 | | - | let bv = if ((J > bA)) |
---|
509 | | - | then true |
---|
510 | | - | else h("invalid period") |
---|
511 | | - | if ((bv == bv)) |
---|
512 | | - | then { |
---|
513 | | - | let aL = toBigInt(valueOrErrorMessage(getBinary(V(E, bA)), f("failed to get price"))) |
---|
514 | | - | let bD = toInt(fraction(toBigInt(bC), aL, e)) |
---|
515 | | - | $Tuple2([IntegerEntry(P(E, N), 0), DeleteEntry(Q(E, N)), ScriptTransfer(N, bD, E), IntegerEntry(X(E, "claimBaseAsset", J, N, ai.transactionId), bD)], unit) |
---|
516 | | - | } |
---|
517 | | - | else throw("Strict value is not equal to itself.") |
---|
518 | | - | } |
---|
519 | | - | else throw("Strict value is not equal to itself.") |
---|
520 | | - | } |
---|
521 | | - | else throw("Strict value is not equal to itself.") |
---|
522 | | - | } |
---|
523 | | - | else throw("Strict value is not equal to itself.") |
---|
524 | | - | } |
---|
525 | | - | else throw("Strict value is not equal to itself.") |
---|
526 | | - | } |
---|
527 | | - | else throw("Strict value is not equal to itself.") |
---|
528 | | - | } |
---|
529 | | - | |
---|
530 | | - | |
---|
531 | | - | |
---|
532 | | - | @Callable(ai) |
---|
533 | | - | func finalize (aV) = { |
---|
534 | | - | let bb = [am(ai)] |
---|
535 | | - | if ((bb == bb)) |
---|
536 | | - | then { |
---|
537 | | - | let E = n(aV) |
---|
538 | | - | let G = value(n(valueOrErrorMessage(getString(D(E)), f("invalid base asset id")))) |
---|
539 | | - | if ((G == G)) |
---|
540 | | - | then { |
---|
541 | | - | let aI = valueOrErrorMessage(assetInfo(G), f("invalid share asset id")) |
---|
542 | | - | let J = valueOrErrorMessage(getInteger(H(E)), f("invalid period")) |
---|
543 | | - | if ((J == J)) |
---|
544 | | - | then { |
---|
545 | | - | let bE = getInteger(I(E, J)) |
---|
546 | | - | let bF = if ((bE == unit)) |
---|
547 | | - | then unit |
---|
548 | | - | else { |
---|
549 | | - | let bG = (height - value(bE)) |
---|
550 | | - | let bH = max([0, (aw - bG)]) |
---|
551 | | - | if ((bH == 0)) |
---|
552 | | - | then unit |
---|
553 | | - | else h(makeString(["finalization will be possible in ", toString(bH), " blocks"], "")) |
---|
554 | | - | } |
---|
555 | | - | if ((bF == bF)) |
---|
556 | | - | then { |
---|
557 | | - | let bI = valueOrErrorMessage(aA(E), f("invalid asset")) |
---|
558 | | - | let bn = bI._1 |
---|
559 | | - | let aH = bI._2 |
---|
560 | | - | let bJ = valueOrErrorMessage({ |
---|
561 | | - | let aF = invoke(ap, "claimWxDoNotThrow", [p(aH)], nil) |
---|
562 | | - | if ($isInstanceOf(aF, "Int")) |
---|
563 | | - | then aF |
---|
564 | | - | else unit |
---|
565 | | - | }, f("invalid claimWx result")) |
---|
566 | | - | if ((bJ == bJ)) |
---|
567 | | - | then { |
---|
568 | | - | let br = valueOrElse(getInteger(K(E)), 0) |
---|
569 | | - | let bB = valueOrElse(getInteger(L(E)), 0) |
---|
570 | | - | let bK = { |
---|
571 | | - | let bL = if (if ((bJ > 0)) |
---|
572 | | - | then true |
---|
573 | | - | else (br > 0)) |
---|
574 | | - | then true |
---|
575 | | - | else (bB > 0) |
---|
576 | | - | if (bL) |
---|
577 | | - | then true |
---|
578 | | - | else h("nothing to finalize") |
---|
579 | | - | } |
---|
580 | | - | if ((bK == bK)) |
---|
581 | | - | then { |
---|
582 | | - | let bM = if ((bJ > 0)) |
---|
583 | | - | then { |
---|
584 | | - | let bN = fraction(bJ, az, ax) |
---|
585 | | - | let bO = (bJ - bN) |
---|
586 | | - | let bP = invoke(aq, "userMaxDurationREADONLY", [toString(this)], nil) |
---|
587 | | - | let bQ = if ((bN > 0)) |
---|
588 | | - | then { |
---|
589 | | - | let ad = bP |
---|
590 | | - | if (if (if ($isInstanceOf(ad._1, "String")) |
---|
591 | | - | then $isInstanceOf(ad._2, "Int") |
---|
592 | | - | else false) |
---|
593 | | - | then $isInstanceOf(ad, "(String, Int)") |
---|
594 | | - | else false) |
---|
595 | | - | then { |
---|
596 | | - | let bR = ad._1 |
---|
597 | | - | let bS = ad._2 |
---|
598 | | - | if ((bN > 0)) |
---|
599 | | - | then invoke(aq, bR, [bS], [AttachedPayment(au, bN)]) |
---|
600 | | - | else unit |
---|
601 | | - | } |
---|
602 | | - | else h("invalid lock params") |
---|
603 | | - | } |
---|
604 | | - | else unit |
---|
605 | | - | if ((bQ == bQ)) |
---|
606 | | - | then { |
---|
607 | | - | let bT = if ((bO > 0)) |
---|
608 | | - | then { |
---|
609 | | - | let bU = au |
---|
610 | | - | let bV = 0 |
---|
611 | | - | let bW = p(at) |
---|
612 | | - | let bX = toString(this) |
---|
613 | | - | valueOrErrorMessage({ |
---|
614 | | - | let aF = invoke(ar, "swap", [bV, bW, bX], [AttachedPayment(bU, bO)]) |
---|
615 | | - | if ($isInstanceOf(aF, "Int")) |
---|
616 | | - | then aF |
---|
617 | | - | else unit |
---|
618 | | - | }, f("invalid swap result")) |
---|
619 | | - | } |
---|
620 | | - | else 0 |
---|
621 | | - | if ((bT == bT)) |
---|
622 | | - | then { |
---|
623 | | - | let bY = if ((bT > 0)) |
---|
624 | | - | then { |
---|
625 | | - | let bZ = 0 |
---|
626 | | - | let ca = true |
---|
627 | | - | valueOrErrorMessage({ |
---|
628 | | - | let aF = invoke(bn, "putOneTknV2", [bZ, ca], [AttachedPayment(at, bT)]) |
---|
629 | | - | if ($isInstanceOf(aF, "Int")) |
---|
630 | | - | then aF |
---|
631 | | - | else unit |
---|
632 | | - | }, f("invalid putOneTknV2 result")) |
---|
633 | | - | } |
---|
634 | | - | else 0 |
---|
635 | | - | if ((bY == bY)) |
---|
636 | | - | then bY |
---|
637 | | - | else throw("Strict value is not equal to itself.") |
---|
638 | | - | } |
---|
639 | | - | else throw("Strict value is not equal to itself.") |
---|
640 | | - | } |
---|
641 | | - | else throw("Strict value is not equal to itself.") |
---|
642 | | - | } |
---|
643 | | - | else unit |
---|
644 | | - | if ((bM == bM)) |
---|
645 | | - | then { |
---|
646 | | - | let cb = if ((bB > 0)) |
---|
647 | | - | then { |
---|
648 | | - | let aL = aG(aH, G) |
---|
649 | | - | if ((aL == aL)) |
---|
650 | | - | then { |
---|
651 | | - | let cc = toInt(fraction(toBigInt(bB), aL, e, FLOOR)) |
---|
652 | | - | let bD = { |
---|
653 | | - | let cd = E |
---|
654 | | - | let bZ = 0 |
---|
655 | | - | valueOrErrorMessage({ |
---|
656 | | - | let aF = invoke(bn, "unstakeAndGetOneTknV2", [cc, p(cd), bZ], nil) |
---|
657 | | - | if ($isInstanceOf(aF, "Int")) |
---|
658 | | - | then aF |
---|
659 | | - | else unit |
---|
660 | | - | }, f("invalid unstakeAndGetOneTknV2 result")) |
---|
661 | | - | } |
---|
662 | | - | if ((bD == bD)) |
---|
663 | | - | then { |
---|
664 | | - | let ce = if ((aI.issuer == this)) |
---|
665 | | - | then invoke(this, "burn", [G, bB], nil) |
---|
666 | | - | else h("invalid share asset issuer") |
---|
667 | | - | if ((ce == ce)) |
---|
668 | | - | then { |
---|
669 | | - | let cf = fraction(toBigInt(bD), e, toBigInt(bB), FLOOR) |
---|
670 | | - | let cg = [BinaryEntry(V(E, J), toBytes(cf)), StringEntry(W(E), toString(cf))] |
---|
671 | | - | cg |
---|
672 | | - | } |
---|
673 | | - | else throw("Strict value is not equal to itself.") |
---|
674 | | - | } |
---|
675 | | - | else throw("Strict value is not equal to itself.") |
---|
676 | | - | } |
---|
677 | | - | else throw("Strict value is not equal to itself.") |
---|
678 | | - | } |
---|
679 | | - | else nil |
---|
680 | | - | if ((cb == cb)) |
---|
681 | | - | then { |
---|
682 | | - | let ch = if ((br > 0)) |
---|
683 | | - | then { |
---|
684 | | - | let bY = { |
---|
685 | | - | let bZ = 0 |
---|
686 | | - | let ca = true |
---|
687 | | - | valueOrErrorMessage({ |
---|
688 | | - | let aF = invoke(bn, "putOneTknV2", [bZ, ca], [AttachedPayment(E, br)]) |
---|
689 | | - | if ($isInstanceOf(aF, "Int")) |
---|
690 | | - | then aF |
---|
691 | | - | else unit |
---|
692 | | - | }, f("invalid putOneTknV2 result")) |
---|
693 | | - | } |
---|
694 | | - | if ((bY == bY)) |
---|
695 | | - | then { |
---|
696 | | - | let aL = aG(aH, G) |
---|
697 | | - | if ((aL == aL)) |
---|
698 | | - | then { |
---|
699 | | - | let bw = toInt(fraction(toBigInt(bY), e, aL, FLOOR)) |
---|
700 | | - | let ci = if ((aI.issuer == this)) |
---|
701 | | - | then invoke(this, "emit", [G, bw], nil) |
---|
702 | | - | else h("invalid share asset issuer") |
---|
703 | | - | if ((ci == ci)) |
---|
704 | | - | then { |
---|
705 | | - | let cj = fraction(toBigInt(br), e, toBigInt(bw)) |
---|
706 | | - | let ck = [BinaryEntry(T(E, J), toBytes(cj)), StringEntry(U(E), toString(cj))] |
---|
707 | | - | ck |
---|
708 | | - | } |
---|
709 | | - | else throw("Strict value is not equal to itself.") |
---|
710 | | - | } |
---|
711 | | - | else throw("Strict value is not equal to itself.") |
---|
712 | | - | } |
---|
713 | | - | else throw("Strict value is not equal to itself.") |
---|
714 | | - | } |
---|
715 | | - | else nil |
---|
716 | | - | if ((ch == ch)) |
---|
717 | | - | then { |
---|
718 | | - | let cl = (J + 1) |
---|
719 | | - | let cm = aG(aH, G) |
---|
720 | | - | let cn = (([IntegerEntry(H(E), cl), IntegerEntry(I(E, cl), height), IntegerEntry(L(E), 0), IntegerEntry(K(E), 0), BinaryEntry(R(E, J), toBytes(cm)), StringEntry(S(E), toString(cm))] ++ ch) ++ cb) |
---|
721 | | - | $Tuple2(cn, toBytes(cm)) |
---|
722 | | - | } |
---|
723 | | - | else throw("Strict value is not equal to itself.") |
---|
724 | | - | } |
---|
725 | | - | else throw("Strict value is not equal to itself.") |
---|
726 | | - | } |
---|
727 | | - | else throw("Strict value is not equal to itself.") |
---|
728 | | - | } |
---|
729 | | - | else throw("Strict value is not equal to itself.") |
---|
730 | | - | } |
---|
731 | | - | else throw("Strict value is not equal to itself.") |
---|
732 | | - | } |
---|
733 | | - | else throw("Strict value is not equal to itself.") |
---|
734 | | - | } |
---|
735 | | - | else throw("Strict value is not equal to itself.") |
---|
736 | | - | } |
---|
737 | | - | else throw("Strict value is not equal to itself.") |
---|
738 | | - | } |
---|
739 | | - | else throw("Strict value is not equal to itself.") |
---|
740 | | - | } |
---|
741 | | - | |
---|
742 | | - | |
---|
743 | | - | @Verifier(co) |
---|
744 | | - | func cp () = { |
---|
745 | | - | let cq = { |
---|
746 | | - | let ad = ac() |
---|
747 | | - | if ($isInstanceOf(ad, "ByteVector")) |
---|
748 | | - | then { |
---|
749 | | - | let ak = ad |
---|
750 | | - | ak |
---|
751 | | - | } |
---|
752 | | - | else if ($isInstanceOf(ad, "Unit")) |
---|
753 | | - | then co.senderPublicKey |
---|
754 | | - | else throw("Match error") |
---|
755 | | - | } |
---|
756 | | - | sigVerify(co.bodyBytes, co.proofs[0], cq) |
---|
757 | | - | } |
---|
758 | | - | |
---|
| 1 | + | # no script |
---|