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