24 | | - | let PoolActive = 1 |
---|
25 | | - | |
---|
26 | | - | let PoolPutDis = 2 |
---|
27 | | - | |
---|
28 | | - | let PoolMatcherDis = 3 |
---|
29 | | - | |
---|
30 | | - | let PoolShutdown = 4 |
---|
31 | | - | |
---|
32 | | - | let idxPoolAddress = 1 |
---|
33 | | - | |
---|
34 | | - | let idxPoolSt = 2 |
---|
35 | | - | |
---|
36 | | - | let idxLPAsId = 3 |
---|
37 | | - | |
---|
38 | | - | let idxAmAsId = 4 |
---|
39 | | - | |
---|
40 | | - | let idxPrAsId = 5 |
---|
41 | | - | |
---|
42 | | - | let idxAmtAsDcm = 6 |
---|
43 | | - | |
---|
44 | | - | let idxPriceAsDcm = 7 |
---|
45 | | - | |
---|
46 | | - | let idxIAmtAsId = 8 |
---|
47 | | - | |
---|
48 | | - | let idxIPriceAsId = 9 |
---|
49 | | - | |
---|
50 | | - | let idxFactStakCntr = 1 |
---|
51 | | - | |
---|
52 | | - | let idxFactSlippCntr = 7 |
---|
53 | | - | |
---|
54 | | - | let idxFactGwxRewCntr = 10 |
---|
55 | | - | |
---|
56 | | - | let delay = "%s__delay" |
---|
57 | | - | |
---|
58 | | - | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func f1 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func abs (val) = if ((zeroBigInt > val)) |
---|
68 | | - | then -(val) |
---|
69 | | - | else val |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func fc () = "%s__factoryContract" |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | func mpk () = "%s__managerPublicKey" |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | func pmpk () = "%s__pendingManagerPublicKey" |
---|
79 | | - | |
---|
80 | | - | |
---|
81 | | - | func pl () = "%s%s__price__last" |
---|
82 | | - | |
---|
83 | | - | |
---|
84 | | - | func ph (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | func pau (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | func gau (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) |
---|
91 | | - | |
---|
92 | | - | |
---|
93 | | - | func aa () = "%s__amountAsset" |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func pa () = "%s__priceAsset" |
---|
97 | | - | |
---|
98 | | - | |
---|
99 | | - | func amp () = "%s__amp" |
---|
100 | | - | |
---|
101 | | - | |
---|
102 | | - | func ada () = "%s__addonAddr" |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | func lgotc (caller) = makeString(["%s%s__lastGetOneTknCall", caller], SEP) |
---|
106 | | - | |
---|
107 | | - | |
---|
108 | | - | func lsotc (caller) = makeString(["%s%s__lastPutOneTknCall", caller], SEP) |
---|
109 | | - | |
---|
110 | | - | |
---|
111 | | - | func fcfg () = "%s__factoryConfig" |
---|
112 | | - | |
---|
113 | | - | |
---|
114 | | - | func mtpk () = "%s%s__matcher__publicKey" |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | func pc (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | func mba (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) |
---|
121 | | - | |
---|
122 | | - | |
---|
123 | | - | func aps () = "%s__shutdown" |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | func keyAllowedLpStableScriptHash () = "%s__allowedLpStableScriptHash" |
---|
127 | | - | |
---|
128 | | - | |
---|
129 | | - | func toe (orV,sendrV,matchV) = throw(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | func str (val) = match val { |
---|
133 | | - | case valStr: String => |
---|
134 | | - | valStr |
---|
135 | | - | case _ => |
---|
136 | | - | throw("fail cast to String") |
---|
137 | | - | } |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | func strf (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) |
---|
141 | | - | |
---|
142 | | - | |
---|
143 | | - | func intf (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) |
---|
144 | | - | |
---|
145 | | - | |
---|
146 | | - | let fca = addressFromStringValue(strf(this, fc())) |
---|
147 | | - | |
---|
148 | | - | let A = strf(this, amp()) |
---|
149 | | - | |
---|
150 | | - | func igs () = valueOrElse(getBoolean(fca, aps()), false) |
---|
151 | | - | |
---|
152 | | - | |
---|
153 | | - | func mp () = fromBase58String(strf(fca, mtpk())) |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | func gpc () = { |
---|
157 | | - | let amtAs = strf(this, aa()) |
---|
158 | | - | let priceAs = strf(this, pa()) |
---|
159 | | - | let iPriceAs = intf(fca, mba(priceAs)) |
---|
160 | | - | let iAmtAs = intf(fca, mba(amtAs)) |
---|
161 | | - | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) |
---|
162 | | - | } |
---|
163 | | - | |
---|
164 | | - | |
---|
165 | | - | func gfc () = split(strf(fca, fcfg()), SEP) |
---|
166 | | - | |
---|
167 | | - | |
---|
168 | | - | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slipByUser,slippageReal,txHeight,txTimestamp,slipageAmAmt,slipagePrAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slipByUser), toString(slippageReal), toString(txHeight), toString(txTimestamp), toString(slipageAmAmt), toString(slipagePrAmt)], SEP) |
---|
169 | | - | |
---|
170 | | - | |
---|
171 | | - | func dataGetActionInfo (outAmtAssetAmt,outPriceAssetAmt,inLpAmt,price,txHeight,txTimestamp) = makeString(["%d%d%d%d%d%d", toString(outAmtAssetAmt), toString(outPriceAssetAmt), toString(inLpAmt), toString(price), toString(txHeight), toString(txTimestamp)], SEP) |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | func getAccBalance (assetId) = if ((assetId == "WAVES")) |
---|
175 | | - | then wavesBalance(this).available |
---|
176 | | - | else assetBalance(this, fromBase58String(assetId)) |
---|
177 | | - | |
---|
178 | | - | |
---|
179 | | - | func cpbi (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) |
---|
180 | | - | |
---|
181 | | - | |
---|
182 | | - | func vad (A1,A2,slippage) = { |
---|
183 | | - | let diff = fraction((A1 - A2), scale8BigInt, A2) |
---|
184 | | - | let pass = ((slippage - abs(diff)) > zeroBigInt) |
---|
185 | | - | if (!(pass)) |
---|
186 | | - | then throw(("Big slpg: " + toString(diff))) |
---|
187 | | - | else $Tuple2(pass, min([A1, A2])) |
---|
188 | | - | } |
---|
189 | | - | |
---|
190 | | - | |
---|
191 | | - | func vd (D1,D0,slpg) = { |
---|
192 | | - | let diff = fraction(D0, scale8BigInt, D1) |
---|
193 | | - | let fail = (slpg > diff) |
---|
194 | | - | if (if (fail) |
---|
195 | | - | then true |
---|
196 | | - | else (D0 > D1)) |
---|
197 | | - | then throw(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slpg))) |
---|
198 | | - | else fail |
---|
199 | | - | } |
---|
200 | | - | |
---|
201 | | - | |
---|
202 | | - | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { |
---|
203 | | - | let amtAsAmtX18 = t1(amAmt, amAssetDcm) |
---|
204 | | - | let prAsAmtX18 = t1(prAmt, prAssetDcm) |
---|
205 | | - | cpbi(prAsAmtX18, amtAsAmtX18) |
---|
206 | | - | } |
---|
207 | | - | |
---|
208 | | - | |
---|
209 | | - | func calcPrices (amAmt,prAmt,lpAmt) = { |
---|
210 | | - | let cfg = gpc() |
---|
211 | | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) |
---|
212 | | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) |
---|
213 | | - | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) |
---|
214 | | - | let amAmtX18 = t1(amAmt, amtAsDcm) |
---|
215 | | - | let prAmtX18 = t1(prAmt, prAsDcm) |
---|
216 | | - | let lpAmtX18 = t1(lpAmt, scale8) |
---|
217 | | - | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) |
---|
218 | | - | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) |
---|
219 | | - | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] |
---|
220 | | - | } |
---|
221 | | - | |
---|
222 | | - | |
---|
223 | | - | func calculatePrices (amAmt,prAmt,lpAmt) = { |
---|
224 | | - | let p = calcPrices(amAmt, prAmt, lpAmt) |
---|
225 | | - | [f1(p[0], scale8), f1(p[1], scale8), f1(p[2], scale8)] |
---|
226 | | - | } |
---|
227 | | - | |
---|
228 | | - | |
---|
229 | | - | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { |
---|
230 | | - | let cfg = gpc() |
---|
231 | | - | let lpId = cfg[idxLPAsId] |
---|
232 | | - | let amId = cfg[idxAmAsId] |
---|
233 | | - | let prId = cfg[idxPrAsId] |
---|
234 | | - | let amDcm = parseIntValue(cfg[idxAmtAsDcm]) |
---|
235 | | - | let prDcm = parseIntValue(cfg[idxPriceAsDcm]) |
---|
236 | | - | let sts = cfg[idxPoolSt] |
---|
237 | | - | let lpEmiss = valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "Wrong LP id").quantity |
---|
238 | | - | if ((lpId != pmtAssetId)) |
---|
239 | | - | then throw("Wrong pmt asset") |
---|
240 | | - | else { |
---|
241 | | - | let amBalance = getAccBalance(amId) |
---|
242 | | - | let amBalanceX18 = t1(amBalance, amDcm) |
---|
243 | | - | let prBalance = getAccBalance(prId) |
---|
244 | | - | let prBalanceX18 = t1(prBalance, prDcm) |
---|
245 | | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) |
---|
246 | | - | let curPrice = f1(curPriceX18, scale8) |
---|
247 | | - | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) |
---|
248 | | - | let lpEmissX18 = t1(lpEmiss, scale8) |
---|
249 | | - | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) |
---|
250 | | - | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) |
---|
251 | | - | let outAmAmt = f1(outAmAmtX18, amDcm) |
---|
252 | | - | let outPrAmt = f1(outPrAmtX18, prDcm) |
---|
253 | | - | let state = if ((txId58 == "")) |
---|
254 | | - | then nil |
---|
255 | | - | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) |
---|
256 | | - | then unit |
---|
257 | | - | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) |
---|
258 | | - | then unit |
---|
259 | | - | else fromBase58String(prId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] |
---|
260 | | - | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) |
---|
261 | | - | } |
---|
262 | | - | } |
---|
263 | | - | |
---|
264 | | - | |
---|
265 | | - | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,pmtAmt,pmtId) = { |
---|
266 | | - | let cfg = gpc() |
---|
267 | | - | let lpId = fromBase58String(cfg[idxLPAsId]) |
---|
268 | | - | let amIdStr = cfg[idxAmAsId] |
---|
269 | | - | let prIdStr = cfg[idxPrAsId] |
---|
270 | | - | let inAmIdStr = cfg[idxIAmtAsId] |
---|
271 | | - | let inPrIdStr = cfg[idxIPriceAsId] |
---|
272 | | - | let amtDcm = parseIntValue(cfg[idxAmtAsDcm]) |
---|
273 | | - | let priceDcm = parseIntValue(cfg[idxPriceAsDcm]) |
---|
274 | | - | let sts = cfg[idxPoolSt] |
---|
275 | | - | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity |
---|
276 | | - | let amBalance = if (isEval) |
---|
277 | | - | then getAccBalance(amIdStr) |
---|
278 | | - | else if (if (isOneAsset) |
---|
279 | | - | then (pmtId == amIdStr) |
---|
280 | | - | else false) |
---|
281 | | - | then (getAccBalance(amIdStr) - pmtAmt) |
---|
282 | | - | else if (isOneAsset) |
---|
283 | | - | then getAccBalance(amIdStr) |
---|
284 | | - | else (getAccBalance(amIdStr) - inAmAmt) |
---|
285 | | - | let prBalance = if (isEval) |
---|
286 | | - | then getAccBalance(prIdStr) |
---|
287 | | - | else if (if (isOneAsset) |
---|
288 | | - | then (pmtId == prIdStr) |
---|
289 | | - | else false) |
---|
290 | | - | then (getAccBalance(prIdStr) - pmtAmt) |
---|
291 | | - | else if (isOneAsset) |
---|
292 | | - | then getAccBalance(prIdStr) |
---|
293 | | - | else (getAccBalance(prIdStr) - inPrAmt) |
---|
294 | | - | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) |
---|
295 | | - | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) |
---|
296 | | - | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) |
---|
297 | | - | let amBalanceX18 = t1(amBalance, amtDcm) |
---|
298 | | - | let prBalanceX18 = t1(prBalance, priceDcm) |
---|
299 | | - | let r = if ((lpEm == 0)) |
---|
300 | | - | then { |
---|
301 | | - | let curPriceX18 = zeroBigInt |
---|
302 | | - | let slippageX18 = zeroBigInt |
---|
303 | | - | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) |
---|
304 | | - | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) |
---|
305 | | - | } |
---|
306 | | - | else { |
---|
307 | | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) |
---|
308 | | - | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) |
---|
309 | | - | let slippageX18 = t1(slippage, scale8) |
---|
310 | | - | if (if ((curPriceX18 != zeroBigInt)) |
---|
311 | | - | then (slippageRealX18 > slippageX18) |
---|
312 | | - | else false) |
---|
313 | | - | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) |
---|
314 | | - | else { |
---|
315 | | - | let lpEmissionX18 = t1(lpEm, scale8) |
---|
316 | | - | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) |
---|
317 | | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) |
---|
318 | | - | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) |
---|
319 | | - | then $Tuple2(amViaPrX18, inPrAssetAmtX18) |
---|
320 | | - | else $Tuple2(inAmAssetAmtX18, prViaAmX18) |
---|
321 | | - | let expAmtAssetAmtX18 = expectedAmts._1 |
---|
322 | | - | let expPriceAssetAmtX18 = expectedAmts._2 |
---|
323 | | - | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) |
---|
324 | | - | $Tuple5(f1(lpAmtX18, scale8), f1(expAmtAssetAmtX18, amtDcm), f1(expPriceAssetAmtX18, priceDcm), curPriceX18, slippageX18) |
---|
325 | | - | } |
---|
326 | | - | } |
---|
327 | | - | let calcLpAmt = r._1 |
---|
328 | | - | let calcAmAssetPmt = r._2 |
---|
329 | | - | let calcPrAssetPmt = r._3 |
---|
330 | | - | let curPrice = f1(r._4, scale8) |
---|
331 | | - | let slippageCalc = f1(r._5, scale8) |
---|
332 | | - | if ((0 >= calcLpAmt)) |
---|
333 | | - | then throw("LP <= 0") |
---|
334 | | - | else { |
---|
335 | | - | let emitLpAmt = if (!(emitLp)) |
---|
336 | | - | then 0 |
---|
337 | | - | else calcLpAmt |
---|
338 | | - | let amDiff = (inAmAmt - calcAmAssetPmt) |
---|
339 | | - | let prDiff = (inPrAmt - calcPrAssetPmt) |
---|
340 | | - | let $t01560115946 = if (if (isOneAsset) |
---|
341 | | - | then (pmtId == amIdStr) |
---|
342 | | - | else false) |
---|
343 | | - | then $Tuple2(pmtAmt, 0) |
---|
344 | | - | else if (if (isOneAsset) |
---|
345 | | - | then (pmtId == prIdStr) |
---|
346 | | - | else false) |
---|
347 | | - | then $Tuple2(0, pmtAmt) |
---|
348 | | - | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) |
---|
349 | | - | let writeAmAmt = $t01560115946._1 |
---|
350 | | - | let writePrAmt = $t01560115946._2 |
---|
351 | | - | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmt, curPrice, slippage, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] |
---|
352 | | - | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) |
---|
353 | | - | } |
---|
354 | | - | } |
---|
355 | | - | |
---|
356 | | - | |
---|
357 | | - | func moa (order) = { |
---|
358 | | - | let cfg = gpc() |
---|
359 | | - | let amtAsId = cfg[idxAmAsId] |
---|
360 | | - | let prAsId = cfg[idxPrAsId] |
---|
361 | | - | let sts = parseIntValue(cfg[idxPoolSt]) |
---|
362 | | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) |
---|
363 | | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) |
---|
364 | | - | let accAmtAsBalance = getAccBalance(amtAsId) |
---|
365 | | - | let accPrAsBalance = getAccBalance(prAsId) |
---|
366 | | - | let curPriceX18 = if ((order.orderType == Buy)) |
---|
367 | | - | then pcp(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) |
---|
368 | | - | else pcp(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) |
---|
369 | | - | let curPrice = f1(curPriceX18, scale8) |
---|
370 | | - | if (if (if (igs()) |
---|
371 | | - | then true |
---|
372 | | - | else (sts == PoolMatcherDis)) |
---|
373 | | - | then true |
---|
374 | | - | else (sts == PoolShutdown)) |
---|
375 | | - | then throw("Admin blocked") |
---|
376 | | - | else { |
---|
377 | | - | let orAmtAsset = order.assetPair.amountAsset |
---|
378 | | - | let orAmtAsStr = if ((orAmtAsset == unit)) |
---|
379 | | - | then "WAVES" |
---|
380 | | - | else toBase58String(value(orAmtAsset)) |
---|
381 | | - | let orPrAsset = order.assetPair.priceAsset |
---|
382 | | - | let orPrAsStr = if ((orPrAsset == unit)) |
---|
383 | | - | then "WAVES" |
---|
384 | | - | else toBase58String(value(orPrAsset)) |
---|
385 | | - | if (if ((orAmtAsStr != amtAsId)) |
---|
386 | | - | then true |
---|
387 | | - | else (orPrAsStr != prAsId)) |
---|
388 | | - | then throw("Wr assets") |
---|
389 | | - | else { |
---|
390 | | - | let orderPrice = order.price |
---|
391 | | - | let priceDcm = fraction(scale8, prAsDcm, amtAsDcm) |
---|
392 | | - | let castOrderPrice = ts(orderPrice, scale8, priceDcm) |
---|
393 | | - | let isOrderPriceValid = if ((order.orderType == Buy)) |
---|
394 | | - | then (curPrice >= castOrderPrice) |
---|
395 | | - | else (castOrderPrice >= curPrice) |
---|
396 | | - | true |
---|
397 | | - | } |
---|
398 | | - | } |
---|
399 | | - | } |
---|
400 | | - | |
---|
401 | | - | |
---|
402 | | - | func cg (i) = if ((size(i.payments) != 1)) |
---|
403 | | - | then throw("1 pmnt exp") |
---|
404 | | - | else { |
---|
405 | | - | let pmt = value(i.payments[0]) |
---|
406 | | - | let pmtAssetId = value(pmt.assetId) |
---|
407 | | - | let pmtAmt = pmt.amount |
---|
408 | | - | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) |
---|
409 | | - | let outAmAmt = r._1 |
---|
410 | | - | let outPrAmt = r._2 |
---|
411 | | - | let sts = parseIntValue(r._9) |
---|
412 | | - | let state = r._10 |
---|
413 | | - | if (if (igs()) |
---|
414 | | - | then true |
---|
415 | | - | else (sts == PoolShutdown)) |
---|
416 | | - | then throw(("Admin blocked: " + toString(sts))) |
---|
417 | | - | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) |
---|
418 | | - | } |
---|
419 | | - | |
---|
420 | | - | |
---|
421 | | - | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,pmtAmt,pmtId) = { |
---|
422 | | - | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, false, emitLp, isOneAsset, pmtAmt, pmtId) |
---|
423 | | - | let sts = parseIntValue(r._8) |
---|
424 | | - | if (if (if (igs()) |
---|
425 | | - | then true |
---|
426 | | - | else (sts == PoolPutDis)) |
---|
427 | | - | then true |
---|
428 | | - | else (sts == PoolShutdown)) |
---|
429 | | - | then throw(("Blocked:" + toString(sts))) |
---|
430 | | - | else r |
---|
431 | | - | } |
---|
432 | | - | |
---|
433 | | - | |
---|
434 | | - | func m () = match getString(mpk()) { |
---|
435 | | - | case s: String => |
---|
436 | | - | fromBase58String(s) |
---|
437 | | - | case _: Unit => |
---|
438 | | - | unit |
---|
439 | | - | case _ => |
---|
440 | | - | throw("Match error") |
---|
441 | | - | } |
---|
442 | | - | |
---|
443 | | - | |
---|
444 | | - | func pm () = match getString(pmpk()) { |
---|
445 | | - | case s: String => |
---|
446 | | - | fromBase58String(s) |
---|
447 | | - | case _: Unit => |
---|
448 | | - | unit |
---|
449 | | - | case _ => |
---|
450 | | - | throw("Match error") |
---|
451 | | - | } |
---|
452 | | - | |
---|
453 | | - | |
---|
454 | | - | let pd = throw("Permission denied") |
---|
455 | | - | |
---|
456 | | - | func mm (i) = match m() { |
---|
457 | | - | case pk: ByteVector => |
---|
458 | | - | if ((i.callerPublicKey == pk)) |
---|
459 | | - | then true |
---|
460 | | - | else pd |
---|
461 | | - | case _: Unit => |
---|
462 | | - | if ((i.caller == this)) |
---|
463 | | - | then true |
---|
464 | | - | else pd |
---|
465 | | - | case _ => |
---|
466 | | - | throw("Match error") |
---|
467 | | - | } |
---|
468 | | - | |
---|
469 | | - | |
---|
470 | | - | @Callable(i) |
---|
471 | | - | func constructor (fc) = { |
---|
472 | | - | let c = mm(i) |
---|
473 | | - | if ((c == c)) |
---|
474 | | - | then [StringEntry(fc(), fc)] |
---|
475 | | - | else throw("Strict value is not equal to itself.") |
---|
476 | | - | } |
---|
477 | | - | |
---|
478 | | - | |
---|
479 | | - | |
---|
480 | | - | @Callable(i) |
---|
481 | | - | func setManager (pendingManagerPublicKey) = { |
---|
482 | | - | let c = mm(i) |
---|
483 | | - | if ((c == c)) |
---|
484 | | - | then { |
---|
485 | | - | let cm = fromBase58String(pendingManagerPublicKey) |
---|
486 | | - | if ((cm == cm)) |
---|
487 | | - | then [StringEntry(pmpk(), pendingManagerPublicKey)] |
---|
488 | | - | else throw("Strict value is not equal to itself.") |
---|
489 | | - | } |
---|
490 | | - | else throw("Strict value is not equal to itself.") |
---|
491 | | - | } |
---|
492 | | - | |
---|
493 | | - | |
---|
494 | | - | |
---|
495 | | - | @Callable(i) |
---|
496 | | - | func confirmManager () = { |
---|
497 | | - | let p = pm() |
---|
498 | | - | let hpm = if (isDefined(p)) |
---|
499 | | - | then true |
---|
500 | | - | else throw("No pending manager") |
---|
501 | | - | if ((hpm == hpm)) |
---|
502 | | - | then { |
---|
503 | | - | let cpm = if ((i.callerPublicKey == value(p))) |
---|
504 | | - | then true |
---|
505 | | - | else throw("You are not pending manager") |
---|
506 | | - | if ((cpm == cpm)) |
---|
507 | | - | then [StringEntry(mpk(), toBase58String(value(p))), DeleteEntry(pmpk())] |
---|
508 | | - | else throw("Strict value is not equal to itself.") |
---|
509 | | - | } |
---|
510 | | - | else throw("Strict value is not equal to itself.") |
---|
511 | | - | } |
---|
512 | | - | |
---|
513 | | - | |
---|
514 | | - | |
---|
515 | | - | @Callable(i) |
---|
516 | | - | func put (slip,autoStake) = { |
---|
517 | | - | let factCfg = gfc() |
---|
518 | | - | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") |
---|
519 | | - | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") |
---|
520 | | - | if ((0 > slip)) |
---|
521 | | - | then throw("Wrong slippage") |
---|
522 | | - | else if ((size(i.payments) != 2)) |
---|
523 | | - | then throw("2 pmnts expd") |
---|
524 | | - | else { |
---|
525 | | - | let e = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slip, true, false, 0, "") |
---|
526 | | - | let emitLpAmt = e._2 |
---|
527 | | - | let lpAssetId = e._7 |
---|
528 | | - | let state = e._9 |
---|
529 | | - | let amDiff = e._10 |
---|
530 | | - | let prDiff = e._11 |
---|
531 | | - | let amId = e._12 |
---|
532 | | - | let prId = e._13 |
---|
533 | | - | let r = invoke(fca, "emit", [emitLpAmt], nil) |
---|
534 | | - | if ((r == r)) |
---|
535 | | - | then { |
---|
536 | | - | let el = match r { |
---|
537 | | - | case legacy: Address => |
---|
538 | | - | invoke(legacy, "emit", [emitLpAmt], nil) |
---|
539 | | - | case _ => |
---|
540 | | - | unit |
---|
541 | | - | } |
---|
542 | | - | if ((el == el)) |
---|
543 | | - | then { |
---|
544 | | - | let sa = if ((amDiff > 0)) |
---|
545 | | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) |
---|
546 | | - | else nil |
---|
547 | | - | if ((sa == sa)) |
---|
548 | | - | then { |
---|
549 | | - | let sp = if ((prDiff > 0)) |
---|
550 | | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) |
---|
551 | | - | else nil |
---|
552 | | - | if ((sp == sp)) |
---|
553 | | - | then { |
---|
554 | | - | let lpTrnsfr = if (autoStake) |
---|
555 | | - | then { |
---|
556 | | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) |
---|
557 | | - | if ((ss == ss)) |
---|
558 | | - | then nil |
---|
559 | | - | else throw("Strict value is not equal to itself.") |
---|
560 | | - | } |
---|
561 | | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] |
---|
562 | | - | (state ++ lpTrnsfr) |
---|
563 | | - | } |
---|
564 | | - | else throw("Strict value is not equal to itself.") |
---|
565 | | - | } |
---|
566 | | - | else throw("Strict value is not equal to itself.") |
---|
567 | | - | } |
---|
568 | | - | else throw("Strict value is not equal to itself.") |
---|
569 | | - | } |
---|
570 | | - | else throw("Strict value is not equal to itself.") |
---|
571 | | - | } |
---|
572 | | - | } |
---|
573 | | - | |
---|
574 | | - | |
---|
575 | | - | |
---|
576 | | - | @Callable(i) |
---|
577 | | - | func putOneTkn (amAssetPart,prAssetPart,outLp,slippage,autoStake) = { |
---|
578 | | - | let cfg = gfc() |
---|
579 | | - | let stakingCntr = valueOrErrorMessage(addressFromString(cfg[idxFactStakCntr]), "Wr st addr") |
---|
580 | | - | let slipCntr = valueOrErrorMessage(addressFromString(cfg[idxFactSlippCntr]), "Wr sl addr") |
---|
581 | | - | let gwxCntr = valueOrErrorMessage(addressFromString(cfg[idxFactGwxRewCntr]), "Wr gwx addr") |
---|
582 | | - | let poolCfg = gpc() |
---|
583 | | - | let amId = poolCfg[idxAmAsId] |
---|
584 | | - | let prId = poolCfg[idxPrAsId] |
---|
585 | | - | let amDcm = parseIntValue(poolCfg[idxAmtAsDcm]) |
---|
586 | | - | let prDcm = parseIntValue(poolCfg[idxPriceAsDcm]) |
---|
587 | | - | let addon = valueOrElse(getString(this, ada()), "") |
---|
588 | | - | let userAddress = if ((addon == toString(i.caller))) |
---|
589 | | - | then i.originCaller |
---|
590 | | - | else i.caller |
---|
591 | | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(ada()), "no addons")), "addon address in not valid") |
---|
592 | | - | let check = reentrantInvoke(addonContract, "ensureCanPutOneTkn", [toString(userAddress)], nil) |
---|
593 | | - | if ((check == check)) |
---|
594 | | - | then if (if (if (if ((0 >= slippage)) |
---|
595 | | - | then true |
---|
596 | | - | else (0 >= amAssetPart)) |
---|
597 | | - | then true |
---|
598 | | - | else (0 >= prAssetPart)) |
---|
599 | | - | then true |
---|
600 | | - | else (0 >= outLp)) |
---|
601 | | - | then throw("Wrong params") |
---|
602 | | - | else if ((size(i.payments) != 1)) |
---|
603 | | - | then throw("1 pmnt expd") |
---|
604 | | - | else { |
---|
605 | | - | let pmt = value(i.payments[0]) |
---|
606 | | - | let pmtAssetId = toBase58String(value(pmt.assetId)) |
---|
607 | | - | let pmtAmt = pmt.amount |
---|
608 | | - | if ((10000000 > pmtAmt)) |
---|
609 | | - | then throw("Wrong pmt amt") |
---|
610 | | - | else { |
---|
611 | | - | let amBalance = getAccBalance(amId) |
---|
612 | | - | let prBalance = getAccBalance(prId) |
---|
613 | | - | let $t02485925435 = if ((pmtAssetId == amId)) |
---|
614 | | - | then if (if ((pmtAmt > amBalance)) |
---|
615 | | - | then true |
---|
616 | | - | else (amAssetPart > pmtAmt)) |
---|
617 | | - | then throw("invalid payment amount") |
---|
618 | | - | else $Tuple6((amBalance - pmtAmt), prBalance, (pmtAmt - amAssetPart), prAssetPart, 0, 0) |
---|
619 | | - | else if ((pmtAssetId == prId)) |
---|
620 | | - | then if (if ((pmtAmt > prBalance)) |
---|
621 | | - | then true |
---|
622 | | - | else (prAssetPart > pmtAmt)) |
---|
623 | | - | then throw("invalid payment amount") |
---|
624 | | - | else $Tuple6(amBalance, (prBalance - pmtAmt), 0, 0, (pmtAmt - prAssetPart), amAssetPart) |
---|
625 | | - | else throw("wrong pmtAssetId") |
---|
626 | | - | let amBalanceNow = $t02485925435._1 |
---|
627 | | - | let prBalanceNow = $t02485925435._2 |
---|
628 | | - | let virtSwapInAm = $t02485925435._3 |
---|
629 | | - | let virtSwapOutPr = $t02485925435._4 |
---|
630 | | - | let virtSwapInPr = $t02485925435._5 |
---|
631 | | - | let virtSwapOutAm = $t02485925435._6 |
---|
632 | | - | let D0 = invoke(gwxCntr, "calcD", [toString(amBalanceNow), toString(prBalanceNow), A, Amult, Dconv], nil) |
---|
633 | | - | let D1 = invoke(gwxCntr, "calcD", [toString(toBigInt(((amBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((prBalanceNow + virtSwapInPr) - virtSwapOutPr))), A, Amult, Dconv], nil) |
---|
634 | | - | let D0vsD1 = vd(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) |
---|
635 | | - | if ((D0vsD1 == D0vsD1)) |
---|
636 | | - | then { |
---|
637 | | - | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amId), amAssetPart), AttachedPayment(fromBase58String(prId), prAssetPart), slippage, true, true, pmtAmt, pmtAssetId) |
---|
638 | | - | let estimLP = estPut._2 |
---|
639 | | - | let lpAssetId = estPut._7 |
---|
640 | | - | let state = estPut._9 |
---|
641 | | - | let amDiff = estPut._10 |
---|
642 | | - | let prDiff = estPut._11 |
---|
643 | | - | let lpCalcRes = vad(toBigInt(estimLP), toBigInt(outLp), toBigInt(slippage)) |
---|
644 | | - | let emitLpAmt = toInt(lpCalcRes._2) |
---|
645 | | - | let e = invoke(fca, "emit", [emitLpAmt], nil) |
---|
646 | | - | if ((e == e)) |
---|
647 | | - | then { |
---|
648 | | - | let el = match e { |
---|
649 | | - | case legacy: Address => |
---|
650 | | - | invoke(legacy, "emit", [emitLpAmt], nil) |
---|
651 | | - | case _ => |
---|
652 | | - | unit |
---|
653 | | - | } |
---|
654 | | - | if ((el == el)) |
---|
655 | | - | then { |
---|
656 | | - | let sa = if ((amDiff > 0)) |
---|
657 | | - | then invoke(slipCntr, "put", nil, [AttachedPayment(fromBase58String(amId), amDiff)]) |
---|
658 | | - | else nil |
---|
659 | | - | if ((sa == sa)) |
---|
660 | | - | then { |
---|
661 | | - | let sp = if ((prDiff > 0)) |
---|
662 | | - | then invoke(slipCntr, "put", nil, [AttachedPayment(fromBase58String(prId), prDiff)]) |
---|
663 | | - | else nil |
---|
664 | | - | if ((sp == sp)) |
---|
665 | | - | then { |
---|
666 | | - | let lpTrnsfr = if (autoStake) |
---|
667 | | - | then { |
---|
668 | | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) |
---|
669 | | - | if ((ss == ss)) |
---|
670 | | - | then nil |
---|
671 | | - | else throw("Strict value is not equal to itself.") |
---|
672 | | - | } |
---|
673 | | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] |
---|
674 | | - | (state ++ lpTrnsfr) |
---|
675 | | - | } |
---|
676 | | - | else throw("Strict value is not equal to itself.") |
---|
677 | | - | } |
---|
678 | | - | else throw("Strict value is not equal to itself.") |
---|
679 | | - | } |
---|
680 | | - | else throw("Strict value is not equal to itself.") |
---|
681 | | - | } |
---|
682 | | - | else throw("Strict value is not equal to itself.") |
---|
683 | | - | } |
---|
684 | | - | else throw("Strict value is not equal to itself.") |
---|
685 | | - | } |
---|
686 | | - | } |
---|
687 | | - | else throw("Strict value is not equal to itself.") |
---|
688 | | - | } |
---|
689 | | - | |
---|
690 | | - | |
---|
691 | | - | |
---|
692 | | - | @Callable(i) |
---|
693 | | - | func putForFree (maxSlpg) = if ((0 > maxSlpg)) |
---|
694 | | - | then throw("Wrong slpg") |
---|
695 | | - | else if ((size(i.payments) != 2)) |
---|
696 | | - | then throw("2 pmnts expd") |
---|
697 | | - | else { |
---|
698 | | - | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxSlpg, false, false, 0, "") |
---|
699 | | - | estPut._9 |
---|
700 | | - | } |
---|
701 | | - | |
---|
702 | | - | |
---|
703 | | - | |
---|
704 | | - | @Callable(i) |
---|
705 | | - | func get () = { |
---|
706 | | - | let r = cg(i) |
---|
707 | | - | let outAmtAmt = r._1 |
---|
708 | | - | let outPrAmt = r._2 |
---|
709 | | - | let pmtAmt = r._3 |
---|
710 | | - | let pmtAssetId = r._4 |
---|
711 | | - | let state = r._5 |
---|
712 | | - | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) |
---|
713 | | - | if ((b == b)) |
---|
714 | | - | then state |
---|
715 | | - | else throw("Strict value is not equal to itself.") |
---|
716 | | - | } |
---|
717 | | - | |
---|
718 | | - | |
---|
719 | | - | |
---|
720 | | - | @Callable(i) |
---|
721 | | - | func getOneTkn (exchResult,notUsed,outAmount,outAssetId,slippage) = if ((size(i.payments) != 1)) |
---|
722 | | - | then throw("1 pmnt expd") |
---|
723 | | - | else { |
---|
724 | | - | let cfg = gpc() |
---|
725 | | - | let lpId = cfg[idxLPAsId] |
---|
726 | | - | let amId = cfg[idxAmAsId] |
---|
727 | | - | let prId = cfg[idxPrAsId] |
---|
728 | | - | let amDcm = parseIntValue(cfg[idxAmtAsDcm]) |
---|
729 | | - | let prDcm = parseIntValue(cfg[idxPriceAsDcm]) |
---|
730 | | - | let sts = cfg[idxPoolSt] |
---|
731 | | - | let factCfg = gfc() |
---|
732 | | - | let gwxCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactGwxRewCntr]), "Wr sl addr") |
---|
733 | | - | let pmt = value(i.payments[0]) |
---|
734 | | - | let addon = valueOrElse(getString(this, ada()), "") |
---|
735 | | - | let userAddress = if ((addon == toString(i.caller))) |
---|
736 | | - | then i.originCaller |
---|
737 | | - | else i.caller |
---|
738 | | - | let txId58 = toBase58String(i.transactionId) |
---|
739 | | - | let pmtAssetId = value(pmt.assetId) |
---|
740 | | - | let pmtAmt = pmt.amount |
---|
741 | | - | let addonContract = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(ada()), "no addons")), "addon address in not valid") |
---|
742 | | - | let check = reentrantInvoke(addonContract, "ensureCanGetOneTkn", [toString(userAddress)], nil) |
---|
743 | | - | if ((check == check)) |
---|
744 | | - | then if ((1000000000 > pmtAmt)) |
---|
745 | | - | then throw("Min pmt 10 LP") |
---|
746 | | - | else if (if (if ((0 > slippage)) |
---|
747 | | - | then true |
---|
748 | | - | else (0 > exchResult)) |
---|
749 | | - | then true |
---|
750 | | - | else (0 > outAmount)) |
---|
751 | | - | then throw("Wrong params") |
---|
752 | | - | else if ((lpId != toBase58String(pmtAssetId))) |
---|
753 | | - | then throw("Wrong LP") |
---|
754 | | - | else { |
---|
755 | | - | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) |
---|
756 | | - | let estimAmAmt = r._1 |
---|
757 | | - | let estimPrAmt = r._2 |
---|
758 | | - | let amBalance = getAccBalance(amId) |
---|
759 | | - | let prBalance = getAccBalance(prId) |
---|
760 | | - | let $t03046630923 = if ((outAssetId == amId)) |
---|
761 | | - | then $Tuple7((amBalance - estimAmAmt), (prBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) |
---|
762 | | - | else if ((outAssetId == prId)) |
---|
763 | | - | then $Tuple7((amBalance - estimAmAmt), (prBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) |
---|
764 | | - | else throw("wrong outAssetId") |
---|
765 | | - | let amBalanceNow = $t03046630923._1 |
---|
766 | | - | let prBalanceNow = $t03046630923._2 |
---|
767 | | - | let virtSwapInAm = $t03046630923._3 |
---|
768 | | - | let virtSwapOutPr = $t03046630923._4 |
---|
769 | | - | let virtSwapInPr = $t03046630923._5 |
---|
770 | | - | let virtSwapOutAm = $t03046630923._6 |
---|
771 | | - | let totalGet = $t03046630923._7 |
---|
772 | | - | if (if ((0 > virtSwapInAm)) |
---|
773 | | - | then true |
---|
774 | | - | else (0 > virtSwapInPr)) |
---|
775 | | - | then throw("Wrong calc") |
---|
776 | | - | else { |
---|
777 | | - | let D0 = invoke(gwxCntr, "calcD", [toString(amBalanceNow), toString(prBalanceNow), A, Amult, Dconv], nil) |
---|
778 | | - | let D1 = invoke(gwxCntr, "calcD", [toString(((amBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((prBalanceNow + virtSwapOutPr) - virtSwapInPr)), A, Amult, Dconv], nil) |
---|
779 | | - | let D0vsD1 = vd(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) |
---|
780 | | - | if ((D0vsD1 == D0vsD1)) |
---|
781 | | - | then { |
---|
782 | | - | let finalRes = vad(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) |
---|
783 | | - | if ((finalRes == finalRes)) |
---|
784 | | - | then { |
---|
785 | | - | let $t03162831732 = if ((outAssetId == amId)) |
---|
786 | | - | then $Tuple2(toInt(finalRes._2), 0) |
---|
787 | | - | else $Tuple2(0, toInt(finalRes._2)) |
---|
788 | | - | let outAm = $t03162831732._1 |
---|
789 | | - | let outPr = $t03162831732._2 |
---|
790 | | - | let curPrX18 = cpbi(t1(prBalance, prDcm), t1(amBalance, amDcm)) |
---|
791 | | - | let curPr = f1(curPrX18, scale8) |
---|
792 | | - | let state = [ScriptTransfer(userAddress, (outAm + outPr), if ((outAssetId == "WAVES")) |
---|
793 | | - | then unit |
---|
794 | | - | else fromBase58String(outAssetId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] |
---|
795 | | - | if ((state == state)) |
---|
796 | | - | then { |
---|
797 | | - | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) |
---|
798 | | - | if ((burn == burn)) |
---|
799 | | - | then state |
---|
800 | | - | else throw("Strict value is not equal to itself.") |
---|
801 | | - | } |
---|
802 | | - | else throw("Strict value is not equal to itself.") |
---|
803 | | - | } |
---|
804 | | - | else throw("Strict value is not equal to itself.") |
---|
805 | | - | } |
---|
806 | | - | else throw("Strict value is not equal to itself.") |
---|
807 | | - | } |
---|
808 | | - | } |
---|
809 | | - | else throw("Strict value is not equal to itself.") |
---|
810 | | - | } |
---|
811 | | - | |
---|
812 | | - | |
---|
813 | | - | |
---|
814 | | - | @Callable(i) |
---|
815 | | - | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { |
---|
816 | | - | let r = cg(i) |
---|
817 | | - | let outAmAmt = r._1 |
---|
818 | | - | let outPrAmt = r._2 |
---|
819 | | - | let pmtAmt = r._3 |
---|
820 | | - | let pmtAssetId = r._4 |
---|
821 | | - | let state = r._5 |
---|
822 | | - | if ((noLessThenAmtAsset > outAmAmt)) |
---|
823 | | - | then throw(((("Failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) |
---|
824 | | - | else if ((noLessThenPriceAsset > outPrAmt)) |
---|
825 | | - | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) |
---|
826 | | - | else { |
---|
827 | | - | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) |
---|
828 | | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) |
---|
829 | | - | then state |
---|
830 | | - | else throw("Strict value is not equal to itself.") |
---|
831 | | - | } |
---|
832 | | - | } |
---|
833 | | - | |
---|
834 | | - | |
---|
835 | | - | |
---|
836 | | - | @Callable(i) |
---|
837 | | - | func unstakeAndGet (amount) = { |
---|
838 | | - | let checkPayments = if ((size(i.payments) != 0)) |
---|
839 | | - | then throw("No pmnts expd") |
---|
840 | | - | else true |
---|
841 | | - | if ((checkPayments == checkPayments)) |
---|
842 | | - | then { |
---|
843 | | - | let cfg = gpc() |
---|
844 | | - | let factoryCfg = gfc() |
---|
845 | | - | let lpAssetId = fromBase58String(cfg[idxLPAsId]) |
---|
846 | | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") |
---|
847 | | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) |
---|
848 | | - | if ((unstakeInv == unstakeInv)) |
---|
849 | | - | then { |
---|
850 | | - | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) |
---|
851 | | - | let sts = parseIntValue(r._9) |
---|
852 | | - | let state = r._10 |
---|
853 | | - | let v = if (if (igs()) |
---|
854 | | - | then true |
---|
855 | | - | else (sts == PoolShutdown)) |
---|
856 | | - | then throw(("Blocked: " + toString(sts))) |
---|
857 | | - | else true |
---|
858 | | - | if ((v == v)) |
---|
859 | | - | then { |
---|
860 | | - | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) |
---|
861 | | - | if ((burnA == burnA)) |
---|
862 | | - | then state |
---|
863 | | - | else throw("Strict value is not equal to itself.") |
---|
864 | | - | } |
---|
865 | | - | else throw("Strict value is not equal to itself.") |
---|
866 | | - | } |
---|
867 | | - | else throw("Strict value is not equal to itself.") |
---|
868 | | - | } |
---|
869 | | - | else throw("Strict value is not equal to itself.") |
---|
870 | | - | } |
---|
871 | | - | |
---|
872 | | - | |
---|
873 | | - | |
---|
874 | | - | @Callable(i) |
---|
875 | | - | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) |
---|
876 | | - | then throw("denied") |
---|
877 | | - | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr)], "success") |
---|
878 | | - | |
---|
879 | | - | |
---|
880 | | - | |
---|
881 | | - | @Callable(i) |
---|
882 | | - | func setS (k,v) = if ((toString(i.caller) != strf(this, ada()))) |
---|
883 | | - | then pd |
---|
884 | | - | else [StringEntry(k, v)] |
---|
885 | | - | |
---|
886 | | - | |
---|
887 | | - | |
---|
888 | | - | @Callable(i) |
---|
889 | | - | func setI (k,v) = if ((toString(i.caller) != strf(this, ada()))) |
---|
890 | | - | then pd |
---|
891 | | - | else [IntegerEntry(k, v)] |
---|
892 | | - | |
---|
893 | | - | |
---|
894 | | - | |
---|
895 | | - | @Callable(i) |
---|
896 | | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) |
---|
897 | | - | |
---|
898 | | - | |
---|
899 | | - | |
---|
900 | | - | @Callable(i) |
---|
901 | | - | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) |
---|
902 | | - | |
---|
903 | | - | |
---|
904 | | - | |
---|
905 | | - | @Callable(i) |
---|
906 | | - | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { |
---|
907 | | - | let pr = calcPrices(amAmt, prAmt, lpAmt) |
---|
908 | | - | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) |
---|
909 | | - | } |
---|
910 | | - | |
---|
911 | | - | |
---|
912 | | - | |
---|
913 | | - | @Callable(i) |
---|
914 | | - | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, f1(parseBigIntValue(val), resScaleMult)) |
---|
915 | | - | |
---|
916 | | - | |
---|
917 | | - | |
---|
918 | | - | @Callable(i) |
---|
919 | | - | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(t1(origVal, origScaleMult))) |
---|
920 | | - | |
---|
921 | | - | |
---|
922 | | - | |
---|
923 | | - | @Callable(i) |
---|
924 | | - | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(cpbi(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) |
---|
925 | | - | |
---|
926 | | - | |
---|
927 | | - | |
---|
928 | | - | @Callable(i) |
---|
929 | | - | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,usrAddr,isEval,emitLp) = $Tuple2(nil, epo(txId58, slippage, inAmAmt, inAmId, inPrAmt, inPrId, usrAddr, isEval, emitLp, false, 0, "")) |
---|
930 | | - | |
---|
931 | | - | |
---|
932 | | - | |
---|
933 | | - | @Callable(i) |
---|
934 | | - | func estimateGetOperationWrapperREADONLY (txId58,pmtAsId,pmtLpAmt,usrAddr) = { |
---|
935 | | - | let r = ego(txId58, pmtAsId, pmtLpAmt, addressFromStringValue(usrAddr)) |
---|
936 | | - | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) |
---|
937 | | - | } |
---|
938 | | - | |
---|
939 | | - | |
---|
940 | | - | @Verifier(tx) |
---|
941 | | - | func verify () = { |
---|
942 | | - | let targetPublicKey = match m() { |
---|
943 | | - | case pk: ByteVector => |
---|
944 | | - | pk |
---|
945 | | - | case _: Unit => |
---|
946 | | - | tx.senderPublicKey |
---|
947 | | - | case _ => |
---|
948 | | - | throw("Match error") |
---|
949 | | - | } |
---|
950 | | - | match tx { |
---|
951 | | - | case order: Order => |
---|
952 | | - | let matcherPub = mp() |
---|
953 | | - | let orderValid = moa(order) |
---|
954 | | - | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) |
---|
955 | | - | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) |
---|
956 | | - | if (if (if (orderValid) |
---|
957 | | - | then senderValid |
---|
958 | | - | else false) |
---|
959 | | - | then matcherValid |
---|
960 | | - | else false) |
---|
961 | | - | then true |
---|
962 | | - | else toe(orderValid, senderValid, matcherValid) |
---|
963 | | - | case s: SetScriptTransaction => |
---|
964 | | - | let newHash = blake2b256(value(s.script)) |
---|
965 | | - | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) |
---|
966 | | - | let currentHash = scriptHash(this) |
---|
967 | | - | if (if ((allowedHash == newHash)) |
---|
968 | | - | then (currentHash != newHash) |
---|
969 | | - | else false) |
---|
970 | | - | then true |
---|
971 | | - | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
972 | | - | case _ => |
---|
973 | | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
974 | | - | } |
---|
975 | | - | } |
---|