tx · BKQuFviKjXvX831vGSc8VCHrUhW2Cpy1o1v6xfhJzP4i 3N4nTJ5sSp5X5ChS2bBBmwNMn1eeRzT1FoP: -0.01100000 Waves 2022.08.30 11:54 [2206974] smart account 3N4nTJ5sSp5X5ChS2bBBmwNMn1eeRzT1FoP > SELF 0.00000000 Waves
{ "type": 13, "id": "BKQuFviKjXvX831vGSc8VCHrUhW2Cpy1o1v6xfhJzP4i", "fee": 1100000, "feeAssetId": null, "timestamp": 1661849643812, "version": 2, "chainId": 84, "sender": "3N4nTJ5sSp5X5ChS2bBBmwNMn1eeRzT1FoP", "senderPublicKey": "EsqRXDXnACFAdXz6EPhF1SbKyeV7MVuoyDqmXsMz7ySv", "proofs": [ "49aZBzUjmhzwxrJE1sBgdpctmSQzUna2RyhJq6h6ePdZY16GhQEKk22B4yFRBpktu8RoootrXroJ4naXtKdXose9" ], "script": "base64:AAIFAAAAAAAAACIIAhIDCgEIEgMKAQgSABIDCgEYEggKBgEBAQEIARIDCgEIAAAAHwAAAAADU0VQAgAAAAJfXwAAAAAFRU1QVFkCAAAAAAAAAAAOaWR4UG9vbEFkZHJlc3MAAAAAAAAAAAEAAAAACWlkeExQQXNJZAAAAAAAAAAAAwAAAAAJaWR4QW1Bc0lkAAAAAAAAAAAEAAAAAAlpZHhQckFzSWQAAAAAAAAAAAUAAAAAD2lkeEZhY3RTdGFrQ250cgAAAAAAAAAAAQEAAAALa2V5RmFjdENudHIAAAAAAgAAABMlc19fZmFjdG9yeUNvbnRyYWN0AQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAIAAAAUJXNfX21hbmFnZXJQdWJsaWNLZXkBAAAAGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5AAAAAAIAAAAbJXNfX3BlbmRpbmdNYW5hZ2VyUHVibGljS2V5AQAAAAtrZXlQb29sQWRkcgAAAAACAAAADyVzX19wb29sQWRkcmVzcwEAAAALa2V5QW10QXNzZXQAAAAAAgAAAA8lc19fYW1vdW50QXN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wkABEwAAAACCQEAAAAGa2V5QW1wAAAAAAkABEwAAAACBQAAAANhbXAFAAAAA25pbAUAAAADbmlsBAAAAARyZXMyCQAD/AAAAAQFAAAADHBvb2xDb250cmFjdAIAAAAEc2V0UwkABEwAAAACCQEAAAANa2V5QW1wSGlzdG9yeQAAAAEFAAAABmhlaWdodAkABEwAAAACBQAAAANhbXAFAAAAA25pbAUAAAADbmlsCQAFFAAAAAIFAAAAA25pbAkABRQAAAACBQAAAARyZXMxBQAAAARyZXMyCQAAAgAAAAECAAAAJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAEAAAAD3RhcmdldFB1YmxpY0tleQQAAAAHJG1hdGNoMAkBAAAAFm1hbmFnZXJQdWJsaWNLZXlPclVuaXQAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAApCeXRlVmVjdG9yBAAAAAJwawUAAAAHJG1hdGNoMAUAAAACcGsDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABFVuaXQIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkJAAACAAAAAQIAAAALTWF0Y2ggZXJyb3IJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAAA90YXJnZXRQdWJsaWNLZXmJkpk6", "height": 2206974, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: A7PmE6KHwyMxT8rT8cvjSBGwG6UMyHDVLLWovkD9q9w2 Next: 7uf1i3VGBdpJQMbwpQHqwh3SbW2vCWdhV2k9NZY7yzwC Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let defaultDecimals = 1000000 | |
5 | - | ||
6 | - | let scale8 = 100000000 | |
7 | - | ||
8 | - | let scale8BigInt = toBigInt(100000000) | |
9 | - | ||
10 | - | let scale18 = toBigInt(1000000000000000000) | |
11 | - | ||
12 | - | let thousand = 1000 | |
13 | - | ||
14 | - | let zeroBigInt = toBigInt(0) | |
15 | - | ||
16 | - | let oneBigInt = toBigInt(1) | |
17 | - | ||
18 | - | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
19 | - | ||
20 | - | let Amult = "100" | |
21 | - | ||
22 | - | let Dconv = "1" | |
23 | - | ||
24 | 4 | let SEP = "__" | |
25 | 5 | ||
26 | 6 | let EMPTY = "" | |
27 | 7 | ||
28 | - | let PoolActive = 1 | |
29 | - | ||
30 | - | let PoolPutDis = 2 | |
31 | - | ||
32 | - | let PoolMatcherDis = 3 | |
33 | - | ||
34 | - | let PoolShutdown = 4 | |
35 | - | ||
36 | 8 | let idxPoolAddress = 1 | |
37 | - | ||
38 | - | let idxPoolSt = 2 | |
39 | 9 | ||
40 | 10 | let idxLPAsId = 3 | |
41 | 11 | ||
43 | 13 | ||
44 | 14 | let idxPrAsId = 5 | |
45 | 15 | ||
46 | - | let idxAmtAsDcm = 6 | |
47 | - | ||
48 | - | let idxPriceAsDcm = 7 | |
49 | - | ||
50 | - | let idxIAmtAsId = 8 | |
51 | - | ||
52 | - | let idxIPriceAsId = 9 | |
53 | - | ||
54 | 16 | let idxFactStakCntr = 1 | |
55 | 17 | ||
56 | - | let idxFactSlippCntr = 7 | |
57 | - | ||
58 | - | let idxFactGwxRewCntr = 10 | |
59 | - | ||
60 | - | let feePermilleDefault = 0 | |
61 | - | ||
62 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
63 | - | ||
64 | - | ||
65 | - | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
66 | - | ||
67 | - | ||
68 | - | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
69 | - | ||
70 | - | ||
71 | - | func abs (val) = if ((zeroBigInt > val)) | |
72 | - | then -(val) | |
73 | - | else val | |
74 | - | ||
75 | - | ||
76 | - | func keyFactoryContact () = "%s__factoryContract" | |
18 | + | func keyFactCntr () = "%s__factoryContract" | |
77 | 19 | ||
78 | 20 | ||
79 | 21 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
82 | 24 | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
83 | 25 | ||
84 | 26 | ||
85 | - | func | |
27 | + | func keyPoolAddr () = "%s__poolAddress" | |
86 | 28 | ||
87 | 29 | ||
88 | - | func keyPriceHistory (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
89 | - | ||
90 | - | ||
91 | - | func keyPutActionByUser (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
92 | - | ||
93 | - | ||
94 | - | func keyGetActionByUser (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
95 | - | ||
96 | - | ||
97 | - | func keyAmountAsset () = "%s__amountAsset" | |
30 | + | func keyAmtAsset () = "%s__amountAsset" | |
98 | 31 | ||
99 | 32 | ||
100 | 33 | func keyPriceAsset () = "%s__priceAsset" | |
101 | 34 | ||
102 | 35 | ||
103 | - | func | |
36 | + | func keyAdminPubKeys () = "%s__adminPubKeys" | |
104 | 37 | ||
105 | 38 | ||
106 | - | func | |
39 | + | func keyAmp () = "%s__amp" | |
107 | 40 | ||
108 | 41 | ||
109 | - | ||
42 | + | func keyAmpHistory (height) = ("%s%d__amp__" + toString(height)) | |
110 | 43 | ||
111 | - | let feePermille = valueOrElse(getInteger(this, keyFeePermille), feePermilleDefault) | |
112 | 44 | ||
113 | 45 | func keyFactoryConfig () = "%s__factoryConfig" | |
114 | - | ||
115 | - | ||
116 | - | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
117 | 46 | ||
118 | 47 | ||
119 | 48 | func keyPoolConfig (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
122 | 51 | func keyMappingsBaseAsset2internalId (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
123 | 52 | ||
124 | 53 | ||
125 | - | func keyAllPoolsShutdown () = "%s__shutdown" | |
126 | - | ||
127 | - | ||
128 | - | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
129 | - | ||
130 | - | ||
131 | - | func throwOrderError (orV,sendrV,matchV) = throwErr(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
132 | - | ||
133 | - | ||
134 | - | func str (val) = match val { | |
135 | - | case valStr: String => | |
136 | - | valStr | |
137 | - | case _ => | |
138 | - | throwErr("fail cast to String") | |
139 | - | } | |
140 | - | ||
141 | - | ||
142 | 54 | func getStringOrFail (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
143 | 55 | ||
144 | 56 | ||
145 | 57 | func getIntOrFail (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
146 | 58 | ||
147 | 59 | ||
148 | - | let | |
60 | + | let poolContract = addressFromStringValue(getStringOrFail(this, keyPoolAddr())) | |
149 | 61 | ||
150 | - | let amplificator = getStringOrFail(this, keyAmplificator()) | |
151 | - | ||
152 | - | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
153 | - | ||
154 | - | ||
155 | - | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
156 | - | ||
157 | - | ||
158 | - | let matcherAddress = addressFromPublicKey(getMatcherPubOrFail()) | |
62 | + | let factoryContract = addressFromStringValue(getStringOrFail(poolContract, keyFactCntr())) | |
159 | 63 | ||
160 | 64 | func getPoolConfig () = { | |
161 | - | let amtAs = getStringOrFail( | |
162 | - | let priceAs = getStringOrFail( | |
65 | + | let amtAs = getStringOrFail(poolContract, keyAmtAsset()) | |
66 | + | let priceAs = getStringOrFail(poolContract, keyPriceAsset()) | |
163 | 67 | let iPriceAs = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAs)) | |
164 | 68 | let iAmtAs = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAs)) | |
165 | 69 | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAs), toString(iPriceAs))), SEP) | |
167 | 71 | ||
168 | 72 | ||
169 | 73 | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
170 | - | ||
171 | - | ||
172 | - | 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) | |
173 | - | ||
174 | - | ||
175 | - | 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) | |
176 | - | ||
177 | - | ||
178 | - | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
179 | - | then wavesBalance(this).available | |
180 | - | else assetBalance(this, fromBase58String(assetId)) | |
181 | - | ||
182 | - | ||
183 | - | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
184 | - | ||
185 | - | ||
186 | - | func validateAbsDiff (estimateLP,outLp,slippage) = { | |
187 | - | let diff = fraction((estimateLP - outLp), scale8BigInt, outLp) | |
188 | - | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
189 | - | if (!(pass)) | |
190 | - | then throwErr(("Big slippage: " + toString(diff))) | |
191 | - | else $Tuple2(pass, min([estimateLP, outLp])) | |
192 | - | } | |
193 | - | ||
194 | - | ||
195 | - | func validateD (D1,D0,slippage) = { | |
196 | - | let diff = fraction(D0, scale8BigInt, D1) | |
197 | - | let fail = (slippage > diff) | |
198 | - | if (if (fail) | |
199 | - | then true | |
200 | - | else (D0 > D1)) | |
201 | - | then throwErr(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slippage))) | |
202 | - | else fail | |
203 | - | } | |
204 | - | ||
205 | - | ||
206 | - | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
207 | - | let amtAsAmtX18 = toX18(amAmt, amAssetDcm) | |
208 | - | let prAsAmtX18 = toX18(prAmt, prAssetDcm) | |
209 | - | calcPriceBigInt(prAsAmtX18, amtAsAmtX18) | |
210 | - | } | |
211 | - | ||
212 | - | ||
213 | - | func calcPrices (amAmt,prAmt,lpAmt) = { | |
214 | - | let cfg = getPoolConfig() | |
215 | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
216 | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
217 | - | let priceX18 = privateCalcPrice(amtAsDcm, prAsDcm, amAmt, prAmt) | |
218 | - | let amAmtX18 = toX18(amAmt, amtAsDcm) | |
219 | - | let prAmtX18 = toX18(prAmt, prAsDcm) | |
220 | - | let lpAmtX18 = toX18(lpAmt, scale8) | |
221 | - | let lpPrInAmAsX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
222 | - | let lpPrInPrAsX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
223 | - | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
224 | - | } | |
225 | - | ||
226 | - | ||
227 | - | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
228 | - | let p = calcPrices(amAmt, prAmt, lpAmt) | |
229 | - | [fromX18(p[0], scale8), fromX18(p[1], scale8), fromX18(p[2], scale8)] | |
230 | - | } | |
231 | - | ||
232 | - | ||
233 | - | func estimateGetOperation (txId58,paymentAssetId,paymentLpAmount,userAddress) = { | |
234 | - | let cfg = getPoolConfig() | |
235 | - | let lpAssetId = cfg[idxLPAsId] | |
236 | - | let amountId = cfg[idxAmAsId] | |
237 | - | let priceId = cfg[idxPrAsId] | |
238 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
239 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
240 | - | let sts = cfg[idxPoolSt] | |
241 | - | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), "Wrong LP id").quantity | |
242 | - | let validationBlock = if ((lpAssetId == paymentAssetId)) | |
243 | - | then true | |
244 | - | else throwErr("Wrong payment asset") | |
245 | - | if ((validationBlock == validationBlock)) | |
246 | - | then { | |
247 | - | let amountBalance = getAccBalance(amountId) | |
248 | - | let priceBalance = getAccBalance(priceId) | |
249 | - | let amountBalanceDefaultDecimals = fraction(amountBalance, defaultDecimals, amountDecimals) | |
250 | - | let priceBalanceDefaultDecimals = fraction(priceBalance, defaultDecimals, priceDecimals) | |
251 | - | let amountBalanceX18 = toX18(amountBalanceDefaultDecimals, defaultDecimals) | |
252 | - | let priceBalanceX18 = toX18(priceBalanceDefaultDecimals, defaultDecimals) | |
253 | - | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
254 | - | let curPrice = fromX18(currentPriceX18, scale8) | |
255 | - | let paymentLpAmountX18 = toX18(paymentLpAmount, scale8) | |
256 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
257 | - | let outAmountAmountX18 = fraction(amountBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
258 | - | let outPriceAmountX18 = fraction(priceBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
259 | - | let outAmountAmountDefaultDecimals = fromX18(outAmountAmountX18, defaultDecimals) | |
260 | - | let outPriceAmountDefaultDecimals = fromX18(outPriceAmountX18, defaultDecimals) | |
261 | - | let outAmountAmount = fraction(outAmountAmountDefaultDecimals, amountDecimals, defaultDecimals) | |
262 | - | let outPriceAmount = fraction(outPriceAmountDefaultDecimals, priceDecimals, defaultDecimals) | |
263 | - | let state = if ((txId58 == "")) | |
264 | - | then nil | |
265 | - | else [ScriptTransfer(userAddress, outAmountAmount, if ((amountId == "WAVES")) | |
266 | - | then unit | |
267 | - | else fromBase58String(amountId)), ScriptTransfer(userAddress, outPriceAmount, if ((priceId == "WAVES")) | |
268 | - | then unit | |
269 | - | else fromBase58String(priceId)), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAmountAmount, outPriceAmount, paymentLpAmount, curPrice, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPrice)] | |
270 | - | $Tuple10(outAmountAmount, outPriceAmount, amountId, priceId, amountBalance, priceBalance, lpEmission, currentPriceX18, sts, state) | |
271 | - | } | |
272 | - | else throw("Strict value is not equal to itself.") | |
273 | - | } | |
274 | - | ||
275 | - | ||
276 | - | func estimatePutOperation (txId58,slippageTolerance,inAmountAssetAmount,inAmountAssetId,inPriceAssetAmount,inPriceAssetId,userAddress,isEvaluate,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
277 | - | let cfg = getPoolConfig() | |
278 | - | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
279 | - | let amountIdStr = cfg[idxAmAsId] | |
280 | - | let priceIdStr = cfg[idxPrAsId] | |
281 | - | let inAmountIdStr = cfg[idxIAmtAsId] | |
282 | - | let inPriceIdStr = cfg[idxIPriceAsId] | |
283 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
284 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
285 | - | let sts = cfg[idxPoolSt] | |
286 | - | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), "Wrong lp asset").quantity | |
287 | - | let amountBalance = if (isEvaluate) | |
288 | - | then getAccBalance(amountIdStr) | |
289 | - | else if (if (isOneAsset) | |
290 | - | then (paymentId == amountIdStr) | |
291 | - | else false) | |
292 | - | then (getAccBalance(amountIdStr) - paymentAmount) | |
293 | - | else if (isOneAsset) | |
294 | - | then getAccBalance(amountIdStr) | |
295 | - | else (getAccBalance(amountIdStr) - inAmountAssetAmount) | |
296 | - | let priceBalance = if (isEvaluate) | |
297 | - | then getAccBalance(priceIdStr) | |
298 | - | else if (if (isOneAsset) | |
299 | - | then (paymentId == priceIdStr) | |
300 | - | else false) | |
301 | - | then (getAccBalance(priceIdStr) - paymentAmount) | |
302 | - | else if (isOneAsset) | |
303 | - | then getAccBalance(priceIdStr) | |
304 | - | else (getAccBalance(priceIdStr) - inPriceAssetAmount) | |
305 | - | let amountBalanceDefaultDecimals = fraction(amountBalance, defaultDecimals, amountDecimals) | |
306 | - | let priceBalanceDefaultDecimals = fraction(priceBalance, defaultDecimals, priceDecimals) | |
307 | - | let inAmountAssetAmountDefaultDecimals = fraction(inAmountAssetAmount, defaultDecimals, amountDecimals) | |
308 | - | let inPriceAssetAmountDefaultDecimals = fraction(inPriceAssetAmount, defaultDecimals, priceDecimals) | |
309 | - | let inAmountAssetAmountX18 = toX18(inAmountAssetAmountDefaultDecimals, defaultDecimals) | |
310 | - | let inPriceAssetAmountX18 = toX18(inPriceAssetAmountDefaultDecimals, defaultDecimals) | |
311 | - | let userPriceX18 = calcPriceBigInt(inPriceAssetAmountX18, inAmountAssetAmountX18) | |
312 | - | let amountBalanceX18 = toX18(amountBalanceDefaultDecimals, defaultDecimals) | |
313 | - | let priceBalanceX18 = toX18(priceBalanceDefaultDecimals, defaultDecimals) | |
314 | - | let r = if ((lpEmission == 0)) | |
315 | - | then { | |
316 | - | let currentPriceX18 = zeroBigInt | |
317 | - | let slippageX18 = zeroBigInt | |
318 | - | let lpAmountX18 = pow((inAmountAssetAmountX18 * inPriceAssetAmountX18), 0, toBigInt(5), 1, 0, DOWN) | |
319 | - | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(inAmountAssetAmountX18, defaultDecimals), fromX18(inPriceAssetAmountX18, defaultDecimals), calcPriceBigInt((priceBalanceX18 + inPriceAssetAmountX18), (amountBalanceX18 + inAmountAssetAmountX18)), slippageX18) | |
320 | - | } | |
321 | - | else { | |
322 | - | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
323 | - | let slippageRealX18 = fraction(abs((currentPriceX18 - userPriceX18)), scale18, currentPriceX18) | |
324 | - | let slippageX18 = toX18(slippageTolerance, scale8) | |
325 | - | let validateSlippage = if (((if ((currentPriceX18 != zeroBigInt)) | |
326 | - | then (slippageRealX18 > slippageX18) | |
327 | - | else false) == false)) | |
328 | - | then true | |
329 | - | else throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
330 | - | if ((validateSlippage == validateSlippage)) | |
331 | - | then { | |
332 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
333 | - | let prViaAmX18 = fraction(inAmountAssetAmountX18, currentPriceX18, scale18) | |
334 | - | let amViaPrX18 = fraction(inPriceAssetAmountX18, scale18, currentPriceX18) | |
335 | - | let expectedAmounts = if ((prViaAmX18 > inPriceAssetAmountX18)) | |
336 | - | then $Tuple2(amViaPrX18, inAmountAssetAmountX18) | |
337 | - | else $Tuple2(inAmountAssetAmountX18, prViaAmX18) | |
338 | - | let expectedAmountAssetAmountX18 = expectedAmounts._1 | |
339 | - | let expectedPriceAssetAmountX18 = expectedAmounts._2 | |
340 | - | let lpAmountX18 = fraction(lpEmissionX18, expectedPriceAssetAmountX18, priceBalanceX18) | |
341 | - | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(expectedAmountAssetAmountX18, defaultDecimals), fromX18(expectedPriceAssetAmountX18, defaultDecimals), currentPriceX18, slippageX18) | |
342 | - | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | - | } | |
345 | - | let calculateLpAmount = r._1 | |
346 | - | let calculateAmountAssetPayment = fraction(r._2, amountDecimals, defaultDecimals) | |
347 | - | let calculatePriceAssetPayment = fraction(r._3, priceDecimals, defaultDecimals) | |
348 | - | let currentPrice = fromX18(r._4, scale8) | |
349 | - | let slippageCalculate = fromX18(r._5, scale8) | |
350 | - | let checkCalcLpAmount = if ((calculateLpAmount > 0)) | |
351 | - | then true | |
352 | - | else throwErr("LP <= 0") | |
353 | - | if ((checkCalcLpAmount == checkCalcLpAmount)) | |
354 | - | then { | |
355 | - | let emitLpAmount = if (!(emitLp)) | |
356 | - | then 0 | |
357 | - | else calculateLpAmount | |
358 | - | let amountDiff = (inAmountAssetAmount - calculateAmountAssetPayment) | |
359 | - | let priceDiff = (inPriceAssetAmount - calculatePriceAssetPayment) | |
360 | - | let $t01715017409 = if (if (isOneAsset) | |
361 | - | then (paymentId == amountIdStr) | |
362 | - | else false) | |
363 | - | then $Tuple2(paymentAmount, 0) | |
364 | - | else if (if (isOneAsset) | |
365 | - | then (paymentId == priceIdStr) | |
366 | - | else false) | |
367 | - | then $Tuple2(0, paymentAmount) | |
368 | - | else $Tuple2(calculateAmountAssetPayment, calculatePriceAssetPayment) | |
369 | - | let writeAmAmt = $t01715017409._1 | |
370 | - | let writePrAmt = $t01715017409._2 | |
371 | - | let commonState = [IntegerEntry(keyPriceLast(), currentPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), currentPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmount, currentPrice, slippageTolerance, slippageCalculate, height, lastBlock.timestamp, amountDiff, priceDiff))] | |
372 | - | $Tuple13(calculateLpAmount, emitLpAmount, currentPrice, amountBalance, priceBalance, lpEmission, lpAssetId, sts, commonState, amountDiff, priceDiff, inAmountAssetId, inPriceAssetId) | |
373 | - | } | |
374 | - | else throw("Strict value is not equal to itself.") | |
375 | - | } | |
376 | - | ||
377 | - | ||
378 | - | func validateMatcherOrderAllowed (order) = { | |
379 | - | let cfg = getPoolConfig() | |
380 | - | let amtAsId = cfg[idxAmAsId] | |
381 | - | let prAsId = cfg[idxPrAsId] | |
382 | - | let sts = parseIntValue(cfg[idxPoolSt]) | |
383 | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
384 | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
385 | - | let accAmtAsBalance = getAccBalance(amtAsId) | |
386 | - | let accPrAsBalance = getAccBalance(prAsId) | |
387 | - | let currentPriceX18 = if ((order.orderType == Buy)) | |
388 | - | then privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) | |
389 | - | else privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) | |
390 | - | let curPrice = fromX18(currentPriceX18, scale8) | |
391 | - | if (if (if (isGlobalShutdown()) | |
392 | - | then true | |
393 | - | else (sts == PoolMatcherDis)) | |
394 | - | then true | |
395 | - | else (sts == PoolShutdown)) | |
396 | - | then throwErr("Admin blocked") | |
397 | - | else { | |
398 | - | let orAmtAsset = order.assetPair.amountAsset | |
399 | - | let orAmtAsStr = if ((orAmtAsset == unit)) | |
400 | - | then "WAVES" | |
401 | - | else toBase58String(value(orAmtAsset)) | |
402 | - | let orPrAsset = order.assetPair.priceAsset | |
403 | - | let orPrAsStr = if ((orPrAsset == unit)) | |
404 | - | then "WAVES" | |
405 | - | else toBase58String(value(orPrAsset)) | |
406 | - | if (if ((orAmtAsStr != amtAsId)) | |
407 | - | then true | |
408 | - | else (orPrAsStr != prAsId)) | |
409 | - | then throwErr("Wr assets") | |
410 | - | else { | |
411 | - | let orderPrice = order.price | |
412 | - | let priceDecimals = fraction(scale8, prAsDcm, amtAsDcm) | |
413 | - | let castOrderPrice = ts(orderPrice, scale8, priceDecimals) | |
414 | - | let isOrderPriceValid = if ((order.orderType == Buy)) | |
415 | - | then (curPrice >= castOrderPrice) | |
416 | - | else (castOrderPrice >= curPrice) | |
417 | - | true | |
418 | - | } | |
419 | - | } | |
420 | - | } | |
421 | - | ||
422 | - | ||
423 | - | func commonGet (i) = { | |
424 | - | let checkPayments = if ((size(i.payments) == 1)) | |
425 | - | then true | |
426 | - | else throwErr("1 payment expected") | |
427 | - | if ((checkPayments == checkPayments)) | |
428 | - | then { | |
429 | - | let payment = value(i.payments[0]) | |
430 | - | let paymentAssetId = value(payment.assetId) | |
431 | - | let paymentAmount = payment.amount | |
432 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
433 | - | let outAmountAmount = r._1 | |
434 | - | let outPriceAmount = r._2 | |
435 | - | let sts = parseIntValue(r._9) | |
436 | - | let state = r._10 | |
437 | - | if (if (isGlobalShutdown()) | |
438 | - | then true | |
439 | - | else (sts == PoolShutdown)) | |
440 | - | then throwErr(("Admin blocked: " + toString(sts))) | |
441 | - | else $Tuple5(outAmountAmount, outPriceAmount, paymentAmount, paymentAssetId, state) | |
442 | - | } | |
443 | - | else throw("Strict value is not equal to itself.") | |
444 | - | } | |
445 | - | ||
446 | - | ||
447 | - | func commonPut (caller,txId,amountAssetPayment,priceAssetPayment,slippage,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
448 | - | let r = estimatePutOperation(txId, slippage, value(amountAssetPayment).amount, value(amountAssetPayment).assetId, value(priceAssetPayment).amount, value(priceAssetPayment).assetId, caller, false, emitLp, isOneAsset, paymentAmount, paymentId) | |
449 | - | let sts = parseIntValue(r._8) | |
450 | - | if (if (if (isGlobalShutdown()) | |
451 | - | then true | |
452 | - | else (sts == PoolPutDis)) | |
453 | - | then true | |
454 | - | else (sts == PoolShutdown)) | |
455 | - | then throwErr(("Blocked:" + toString(sts))) | |
456 | - | else r | |
457 | - | } | |
458 | - | ||
459 | - | ||
460 | - | func takeFee (amount) = { | |
461 | - | let fee = fraction(amount, feePermille, thousand) | |
462 | - | $Tuple2((amount - fee), fee) | |
463 | - | } | |
464 | 74 | ||
465 | 75 | ||
466 | 76 | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
483 | 93 | } | |
484 | 94 | ||
485 | 95 | ||
486 | - | let pd = throwErr("Permission denied") | |
96 | + | func mustManager (i) = { | |
97 | + | let pd = throw("Permission denied") | |
98 | + | match managerPublicKeyOrUnit() { | |
99 | + | case pk: ByteVector => | |
100 | + | if ((i.callerPublicKey == pk)) | |
101 | + | then true | |
102 | + | else pd | |
103 | + | case _: Unit => | |
104 | + | if ((i.caller == this)) | |
105 | + | then true | |
106 | + | else pd | |
107 | + | case _ => | |
108 | + | throw("Match error") | |
109 | + | } | |
110 | + | } | |
487 | 111 | ||
488 | - | func mustManager (i) = match managerPublicKeyOrUnit() { | |
489 | - | case pk: ByteVector => | |
490 | - | if ((i.callerPublicKey == pk)) | |
491 | - | then true | |
492 | - | else pd | |
493 | - | case _: Unit => | |
494 | - | if ((i.caller == this)) | |
495 | - | then true | |
496 | - | else pd | |
112 | + | ||
113 | + | func getAdmins () = match getString(keyAdminPubKeys()) { | |
114 | + | case s: String => | |
115 | + | if ((size(s) == 0)) | |
116 | + | then nil | |
117 | + | else split(s, SEP) | |
497 | 118 | case _ => | |
498 | - | | |
119 | + | nil | |
499 | 120 | } | |
500 | 121 | ||
501 | 122 | ||
123 | + | func mustAdmin (i) = if (containsElement(getAdmins(), toBase58String(i.callerPublicKey))) | |
124 | + | then true | |
125 | + | else mustManager(i) | |
126 | + | ||
127 | + | ||
128 | + | func mustPool (i) = if ((i.caller == poolContract)) | |
129 | + | then true | |
130 | + | else throw("caller must be the pool") | |
131 | + | ||
132 | + | ||
502 | 133 | @Callable(i) | |
503 | - | func constructor ( | |
134 | + | func constructor (poolAddress) = { | |
504 | 135 | let checkCaller = mustManager(i) | |
505 | 136 | if ((checkCaller == checkCaller)) | |
506 | - | then [StringEntry( | |
137 | + | then [StringEntry(keyPoolAddr(), poolAddress)] | |
507 | 138 | else throw("Strict value is not equal to itself.") | |
508 | 139 | } | |
509 | 140 | ||
529 | 160 | let pm = pendingManagerPublicKeyOrUnit() | |
530 | 161 | let hasPM = if (isDefined(pm)) | |
531 | 162 | then true | |
532 | - | else | |
163 | + | else throw("No pending manager") | |
533 | 164 | if ((hasPM == hasPM)) | |
534 | 165 | then { | |
535 | 166 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
536 | 167 | then true | |
537 | - | else | |
168 | + | else throw("You are not pending manager") | |
538 | 169 | if ((checkPM == checkPM)) | |
539 | 170 | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
540 | 171 | else throw("Strict value is not equal to itself.") | |
545 | 176 | ||
546 | 177 | ||
547 | 178 | @Callable(i) | |
548 | - | func put (slippage,autoStake) = { | |
549 | - | let factCfg = getFactoryConfig() | |
550 | - | let stakingContract = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wrong staking contract") | |
551 | - | let slippageContract = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wrogn slippage contract") | |
552 | - | let slippageCheck = if ((slippage >= 0)) | |
553 | - | then true | |
554 | - | else throwErr("wrong slippage") | |
555 | - | if ((slippageCheck == slippageCheck)) | |
179 | + | func setAdmins (adminPubKeys) = { | |
180 | + | let checkCaller = mustManager(i) | |
181 | + | if ((checkCaller == checkCaller)) | |
182 | + | then [StringEntry(keyAdminPubKeys(), makeString(adminPubKeys, SEP))] | |
183 | + | else throw("Strict value is not equal to itself.") | |
184 | + | } | |
185 | + | ||
186 | + | ||
187 | + | ||
188 | + | @Callable(i) | |
189 | + | func unstakeAndGetOneTkn (amount,exchResult,notUsed,outAmount,outAssetId,slippage) = { | |
190 | + | let checkPayments = if ((size(i.payments) != 0)) | |
191 | + | then throw("No pmnts expd") | |
192 | + | else true | |
193 | + | if ((checkPayments == checkPayments)) | |
556 | 194 | then { | |
557 | - | let paymentsCheck = if ((size(i.payments) == 2)) | |
558 | - | then true | |
559 | - | else throwErr("2 payments expected") | |
560 | - | if ((paymentsCheck == paymentsCheck)) | |
195 | + | let cfg = getPoolConfig() | |
196 | + | let factoryCfg = getFactoryConfig() | |
197 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
198 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
199 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
200 | + | if ((unstakeInv == unstakeInv)) | |
561 | 201 | then { | |
562 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slippage, true, false, 0, "") | |
563 | - | let emitLpAmount = estimatePut._2 | |
564 | - | let lpAssetId = estimatePut._7 | |
565 | - | let state = estimatePut._9 | |
566 | - | let amountDiff = estimatePut._10 | |
567 | - | let priceDiff = estimatePut._11 | |
568 | - | let amountId = estimatePut._12 | |
569 | - | let priceId = estimatePut._13 | |
570 | - | let r = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
571 | - | if ((r == r)) | |
572 | - | then { | |
573 | - | let el = match r { | |
574 | - | case legacy: Address => | |
575 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
576 | - | case _ => | |
577 | - | unit | |
578 | - | } | |
579 | - | if ((el == el)) | |
580 | - | then { | |
581 | - | let sa = if ((amountDiff > 0)) | |
582 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(amountId, amountDiff)]) | |
583 | - | else nil | |
584 | - | if ((sa == sa)) | |
585 | - | then { | |
586 | - | let sp = if ((priceDiff > 0)) | |
587 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(priceId, priceDiff)]) | |
588 | - | else nil | |
589 | - | if ((sp == sp)) | |
590 | - | then { | |
591 | - | let lpTrasfer = if (autoStake) | |
592 | - | then { | |
593 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
594 | - | if ((ss == ss)) | |
595 | - | then nil | |
596 | - | else throw("Strict value is not equal to itself.") | |
597 | - | } | |
598 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
599 | - | (state ++ lpTrasfer) | |
600 | - | } | |
601 | - | else throw("Strict value is not equal to itself.") | |
602 | - | } | |
603 | - | else throw("Strict value is not equal to itself.") | |
604 | - | } | |
605 | - | else throw("Strict value is not equal to itself.") | |
606 | - | } | |
202 | + | let getOneTkn = invoke(poolContract, "getOneTkn", [exchResult, notUsed, outAmount, outAssetId, slippage], [AttachedPayment(lpAssetId, amount)]) | |
203 | + | if ((getOneTkn == getOneTkn)) | |
204 | + | then nil | |
607 | 205 | else throw("Strict value is not equal to itself.") | |
608 | 206 | } | |
609 | 207 | else throw("Strict value is not equal to itself.") | |
614 | 212 | ||
615 | 213 | ||
616 | 214 | @Callable(i) | |
617 | - | func putOneTkn (amountAssetPart,priceAssetPart,outLp,slippage,autoStake) = { | |
618 | - | let cfg = getFactoryConfig() | |
619 | - | let stakingContract = valueOrErrorMessage(addressFromString(cfg[idxFactStakCntr]), "Wrong staking contract") | |
620 | - | let slippageContract = valueOrErrorMessage(addressFromString(cfg[idxFactSlippCntr]), "Wrong slippage contract") | |
621 | - | let gwxRewardContract = valueOrErrorMessage(addressFromString(cfg[idxFactGwxRewCntr]), "Wrong gwx reward contract") | |
622 | - | let poolCfg = getPoolConfig() | |
623 | - | let amountId = poolCfg[idxAmAsId] | |
624 | - | let priceId = poolCfg[idxPrAsId] | |
625 | - | let amountDecimals = parseIntValue(poolCfg[idxAmtAsDcm]) | |
626 | - | let priceDecimals = parseIntValue(poolCfg[idxPriceAsDcm]) | |
627 | - | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
628 | - | let userAddress = if ((addon == toString(i.caller))) | |
629 | - | then i.originCaller | |
630 | - | else i.caller | |
631 | - | if (if (if (if ((0 >= slippage)) | |
632 | - | then true | |
633 | - | else (0 >= amountAssetPart)) | |
634 | - | then true | |
635 | - | else (0 >= priceAssetPart)) | |
636 | - | then true | |
637 | - | else (0 >= outLp)) | |
638 | - | then throwErr("Wrong params") | |
639 | - | else if ((size(i.payments) != 1)) | |
640 | - | then throwErr("1 payment expected") | |
641 | - | else { | |
642 | - | let payment = value(i.payments[0]) | |
643 | - | let paymentAssetId = toBase58String(value(payment.assetId)) | |
644 | - | let paymentAmountRaw = payment.amount | |
645 | - | let $t02656926628 = takeFee(paymentAmountRaw) | |
646 | - | let paymentAmount = $t02656926628._1 | |
647 | - | let feeAmount = $t02656926628._2 | |
648 | - | if (if (if ((amountAssetPart > paymentAmount)) | |
649 | - | then true | |
650 | - | else (priceAssetPart > paymentAmount)) | |
651 | - | then true | |
652 | - | else (10000000 > paymentAmount)) | |
653 | - | then throwErr("wrong payment amount") | |
654 | - | else { | |
655 | - | let amountBalance = getAccBalance(amountId) | |
656 | - | let priceBalance = getAccBalance(priceId) | |
657 | - | let $t02689327348 = if ((paymentAssetId == amountId)) | |
658 | - | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
659 | - | else if ((paymentAssetId == priceId)) | |
660 | - | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
661 | - | else throwErr("wrong paymentAssetId") | |
662 | - | let amountBalanceNow = $t02689327348._1 | |
663 | - | let priceBalanceNow = $t02689327348._2 | |
664 | - | let virtSwapInAm = $t02689327348._3 | |
665 | - | let virtSwapOutPr = $t02689327348._4 | |
666 | - | let virtSwapInPr = $t02689327348._5 | |
667 | - | let virtSwapOutAm = $t02689327348._6 | |
668 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
669 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
670 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
671 | - | if ((D0vsD1 == D0vsD1)) | |
672 | - | then { | |
673 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
674 | - | let estimateLP = estimatePut._2 | |
675 | - | let lpAssetId = estimatePut._7 | |
676 | - | let state = estimatePut._9 | |
677 | - | let amountDiff = estimatePut._10 | |
678 | - | let priceDiff = estimatePut._11 | |
679 | - | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
680 | - | let emitLpAmount = toInt(lpCalcRes._2) | |
681 | - | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
682 | - | if ((e == e)) | |
683 | - | then { | |
684 | - | let el = match e { | |
685 | - | case legacy: Address => | |
686 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
687 | - | case _ => | |
688 | - | unit | |
689 | - | } | |
690 | - | if ((el == el)) | |
691 | - | then { | |
692 | - | let sa = if ((amountDiff > 0)) | |
693 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
694 | - | else nil | |
695 | - | if ((sa == sa)) | |
696 | - | then { | |
697 | - | let sp = if ((priceDiff > 0)) | |
698 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
699 | - | else nil | |
700 | - | if ((sp == sp)) | |
701 | - | then { | |
702 | - | let lpTrasfer = if (autoStake) | |
703 | - | then { | |
704 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
705 | - | if ((ss == ss)) | |
706 | - | then nil | |
707 | - | else throw("Strict value is not equal to itself.") | |
708 | - | } | |
709 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
710 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
711 | - | then [ScriptTransfer(matcherAddress, feeAmount, fromBase58String(paymentAssetId))] | |
712 | - | else nil | |
713 | - | ((state ++ lpTrasfer) ++ sendFeeToMatcher) | |
714 | - | } | |
715 | - | else throw("Strict value is not equal to itself.") | |
716 | - | } | |
717 | - | else throw("Strict value is not equal to itself.") | |
718 | - | } | |
719 | - | else throw("Strict value is not equal to itself.") | |
720 | - | } | |
721 | - | else throw("Strict value is not equal to itself.") | |
722 | - | } | |
723 | - | else throw("Strict value is not equal to itself.") | |
724 | - | } | |
725 | - | } | |
726 | - | } | |
727 | - | ||
728 | - | ||
729 | - | ||
730 | - | @Callable(i) | |
731 | - | func putForFree (maxslippage) = if ((0 > maxslippage)) | |
732 | - | then throwErr("wrong slippage") | |
733 | - | else if ((size(i.payments) != 2)) | |
734 | - | then throwErr("2 payments expected") | |
735 | - | else { | |
736 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxslippage, false, false, 0, "") | |
737 | - | estimatePut._9 | |
738 | - | } | |
739 | - | ||
740 | - | ||
741 | - | ||
742 | - | @Callable(i) | |
743 | - | func get () = { | |
744 | - | let r = commonGet(i) | |
745 | - | let outAmtAmt = r._1 | |
746 | - | let outPriceAmount = r._2 | |
747 | - | let paymentAmount = r._3 | |
748 | - | let paymentAssetId = r._4 | |
749 | - | let state = r._5 | |
750 | - | let b = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
751 | - | if ((b == b)) | |
752 | - | then state | |
753 | - | else throw("Strict value is not equal to itself.") | |
754 | - | } | |
755 | - | ||
756 | - | ||
757 | - | ||
758 | - | @Callable(i) | |
759 | - | func getOneTkn (exchResult,notUsed,outAmount,outAssetId,slippage) = if ((size(i.payments) != 1)) | |
760 | - | then throwErr("1 payment expected") | |
761 | - | else { | |
762 | - | let cfg = getPoolConfig() | |
763 | - | let lpAssetId = cfg[idxLPAsId] | |
764 | - | let amountId = cfg[idxAmAsId] | |
765 | - | let priceId = cfg[idxPrAsId] | |
766 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
767 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
768 | - | let sts = cfg[idxPoolSt] | |
769 | - | let factCfg = getFactoryConfig() | |
770 | - | let gwxRewardContract = valueOrErrorMessage(addressFromString(factCfg[idxFactGwxRewCntr]), "Wrong gwxRewardContract address") | |
771 | - | let payment = value(i.payments[0]) | |
772 | - | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
773 | - | let userAddress = if ((addon == toString(i.caller))) | |
774 | - | then i.originCaller | |
775 | - | else i.caller | |
776 | - | let txId58 = toBase58String(i.transactionId) | |
777 | - | let paymentAssetId = value(payment.assetId) | |
778 | - | let paymentAmount = payment.amount | |
779 | - | if ((1000000000 > paymentAmount)) | |
780 | - | then throwErr("Min payment 10 LP") | |
781 | - | else if (if (if ((0 > slippage)) | |
782 | - | then true | |
783 | - | else (0 > exchResult)) | |
784 | - | then true | |
785 | - | else (0 > outAmount)) | |
786 | - | then throwErr("Wrong params") | |
787 | - | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
788 | - | then throwErr("Wrong LP") | |
789 | - | else { | |
790 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
791 | - | let estimAmAmt = r._1 | |
792 | - | let estimPrAmt = r._2 | |
793 | - | let amountBalance = getAccBalance(amountId) | |
794 | - | let priceBalance = getAccBalance(priceId) | |
795 | - | let $t03249632964 = if ((outAssetId == amountId)) | |
796 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
797 | - | else if ((outAssetId == priceId)) | |
798 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
799 | - | else throwErr("wrong outAssetId") | |
800 | - | let amountBalanceNow = $t03249632964._1 | |
801 | - | let priceBalanceNow = $t03249632964._2 | |
802 | - | let virtSwapInAm = $t03249632964._3 | |
803 | - | let virtSwapOutPr = $t03249632964._4 | |
804 | - | let virtSwapInPr = $t03249632964._5 | |
805 | - | let virtSwapOutAm = $t03249632964._6 | |
806 | - | let totalGet = $t03249632964._7 | |
807 | - | if (if ((0 > virtSwapInAm)) | |
808 | - | then true | |
809 | - | else (0 > virtSwapInPr)) | |
810 | - | then throwErr("Wrong calc") | |
811 | - | else { | |
812 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
813 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
814 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
815 | - | if ((D0vsD1 == D0vsD1)) | |
816 | - | then { | |
817 | - | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
818 | - | if ((finalRes == finalRes)) | |
819 | - | then { | |
820 | - | let $t03363333741 = if ((outAssetId == amountId)) | |
821 | - | then $Tuple2(toInt(finalRes._2), 0) | |
822 | - | else $Tuple2(0, toInt(finalRes._2)) | |
823 | - | let outAm = $t03363333741._1 | |
824 | - | let outPr = $t03363333741._2 | |
825 | - | let totalAmountRaw = (outAm + outPr) | |
826 | - | let $t03378133836 = takeFee(totalAmountRaw) | |
827 | - | let totalAmount = $t03378133836._1 | |
828 | - | let feeAmount = $t03378133836._2 | |
829 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
830 | - | then unit | |
831 | - | else fromBase58String(outAssetId) | |
832 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
833 | - | then [ScriptTransfer(matcherAddress, feeAmount, outAssetIdOrWaves)] | |
834 | - | else nil | |
835 | - | let decimals = if ((amountDecimals >= priceDecimals)) | |
836 | - | then amountDecimals | |
837 | - | else priceDecimals | |
838 | - | if ((decimals == decimals)) | |
839 | - | then { | |
840 | - | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
841 | - | let curPr = fromX18(curPrX18, scale8) | |
842 | - | let state = [ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
843 | - | if ((state == state)) | |
844 | - | then { | |
845 | - | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
846 | - | if ((burn == burn)) | |
847 | - | then (state ++ sendFeeToMatcher) | |
848 | - | else throw("Strict value is not equal to itself.") | |
849 | - | } | |
850 | - | else throw("Strict value is not equal to itself.") | |
851 | - | } | |
852 | - | else throw("Strict value is not equal to itself.") | |
853 | - | } | |
854 | - | else throw("Strict value is not equal to itself.") | |
855 | - | } | |
856 | - | else throw("Strict value is not equal to itself.") | |
857 | - | } | |
858 | - | } | |
859 | - | } | |
860 | - | ||
861 | - | ||
862 | - | ||
863 | - | @Callable(i) | |
864 | - | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
865 | - | let r = commonGet(i) | |
866 | - | let outAmountAmount = r._1 | |
867 | - | let outPriceAmount = r._2 | |
868 | - | let paymentAmount = r._3 | |
869 | - | let paymentAssetId = r._4 | |
870 | - | let state = r._5 | |
871 | - | let checkOutAmountAmount = if ((outAmountAmount >= noLessThenAmtAsset)) | |
872 | - | then true | |
873 | - | else throwErr(((("Failed: " + toString(outAmountAmount)) + " < ") + toString(noLessThenAmtAsset))) | |
874 | - | if ((checkOutAmountAmount == checkOutAmountAmount)) | |
215 | + | func setAmp (amp) = { | |
216 | + | let checkCaller = mustAdmin(i) | |
217 | + | if ((checkCaller == checkCaller)) | |
875 | 218 | then { | |
876 | - | let checkOutPriceAmount = if ((outPriceAmount >= noLessThenPriceAsset)) | |
877 | - | then true | |
878 | - | else throwErr(((("Failed: " + toString(outPriceAmount)) + " < ") + toString(noLessThenPriceAsset))) | |
879 | - | if ((checkOutPriceAmount == checkOutPriceAmount)) | |
880 | - | then { | |
881 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
882 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
883 | - | then state | |
884 | - | else throw("Strict value is not equal to itself.") | |
885 | - | } | |
886 | - | else throw("Strict value is not equal to itself.") | |
219 | + | let res1 = invoke(poolContract, "setS", [keyAmp(), amp], nil) | |
220 | + | let res2 = invoke(poolContract, "setS", [keyAmpHistory(height), amp], nil) | |
221 | + | $Tuple2(nil, $Tuple2(res1, res2)) | |
887 | 222 | } | |
888 | 223 | else throw("Strict value is not equal to itself.") | |
889 | 224 | } | |
890 | 225 | ||
891 | 226 | ||
892 | - | ||
893 | - | @Callable(i) | |
894 | - | func unstakeAndGet (amount) = { | |
895 | - | let checkPayments = if ((size(i.payments) != 0)) | |
896 | - | then throwErr("no payments expected") | |
897 | - | else true | |
898 | - | if ((checkPayments == checkPayments)) | |
899 | - | then { | |
900 | - | let cfg = getPoolConfig() | |
901 | - | let factoryCfg = getFactoryConfig() | |
902 | - | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
903 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "wrong") | |
904 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
905 | - | if ((unstakeInv == unstakeInv)) | |
906 | - | then { | |
907 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
908 | - | let sts = parseIntValue(r._9) | |
909 | - | let state = r._10 | |
910 | - | let v = if (if (isGlobalShutdown()) | |
911 | - | then true | |
912 | - | else (sts == PoolShutdown)) | |
913 | - | then throwErr(("Blocked: " + toString(sts))) | |
914 | - | else true | |
915 | - | if ((v == v)) | |
916 | - | then { | |
917 | - | let burnA = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
918 | - | if ((burnA == burnA)) | |
919 | - | then state | |
920 | - | else throw("Strict value is not equal to itself.") | |
921 | - | } | |
922 | - | else throw("Strict value is not equal to itself.") | |
923 | - | } | |
924 | - | else throw("Strict value is not equal to itself.") | |
925 | - | } | |
926 | - | else throw("Strict value is not equal to itself.") | |
227 | + | @Verifier(tx) | |
228 | + | func verify () = { | |
229 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
230 | + | case pk: ByteVector => | |
231 | + | pk | |
232 | + | case _: Unit => | |
233 | + | tx.senderPublicKey | |
234 | + | case _ => | |
235 | + | throw("Match error") | |
927 | 236 | } | |
928 | - | ||
929 | - | ||
930 | - | ||
931 | - | @Callable(i) | |
932 | - | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(factoryContract))) | |
933 | - | then throwErr("denied") | |
934 | - | else $Tuple2([StringEntry(keyAmountAsset(), amtAsStr), StringEntry(keyPriceAsset(), prAsStr)], "success") | |
935 | - | ||
936 | - | ||
937 | - | ||
938 | - | @Callable(i) | |
939 | - | func setS (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
940 | - | then pd | |
941 | - | else [StringEntry(k, v)] | |
942 | - | ||
943 | - | ||
944 | - | ||
945 | - | @Callable(i) | |
946 | - | func setI (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
947 | - | then pd | |
948 | - | else [IntegerEntry(k, v)] | |
949 | - | ||
950 | - | ||
951 | - | ||
952 | - | @Callable(i) | |
953 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
954 | - | ||
955 | - | ||
956 | - | ||
957 | - | @Callable(i) | |
958 | - | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
959 | - | ||
960 | - | ||
961 | - | ||
962 | - | @Callable(i) | |
963 | - | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
964 | - | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
965 | - | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
237 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
966 | 238 | } | |
967 | - | ||
968 | - | ||
969 | - | ||
970 | - | @Callable(i) | |
971 | - | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resScaleMult)) | |
972 | - | ||
973 | - | ||
974 | - | ||
975 | - | @Callable(i) | |
976 | - | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
977 | - | ||
978 | - | ||
979 | - | ||
980 | - | @Callable(i) | |
981 | - | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
982 | - | ||
983 | - | ||
984 | - | ||
985 | - | @Callable(i) | |
986 | - | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmountAssetAmount,inAmId,inPriceAssetAmount,inPrId,usrAddr,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippage, inAmountAssetAmount, inAmId, inPriceAssetAmount, inPrId, usrAddr, isEvaluate, emitLp, false, 0, "")) | |
987 | - | ||
988 | - | ||
989 | - | ||
990 | - | @Callable(i) | |
991 | - | func estimateGetOperationWrapperREADONLY (txId58,paymentAsId,paymentLpAmount,usrAddr) = { | |
992 | - | let r = estimateGetOperation(txId58, paymentAsId, paymentLpAmount, addressFromStringValue(usrAddr)) | |
993 | - | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
994 | - | } | |
995 | - | ||
996 | - | ||
997 | - | @Verifier(tx) | |
998 | - | func verify () = match tx { | |
999 | - | case order: Order => | |
1000 | - | let mtchPub = getMatcherPubOrFail() | |
1001 | - | let orV = validateMatcherOrderAllowed(order) | |
1002 | - | let sndrV = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1003 | - | let mtchV = sigVerify(order.bodyBytes, order.proofs[1], mtchPub) | |
1004 | - | if (if (if (orV) | |
1005 | - | then sndrV | |
1006 | - | else false) | |
1007 | - | then mtchV | |
1008 | - | else false) | |
1009 | - | then true | |
1010 | - | else throwOrderError(orV, sndrV, mtchV) | |
1011 | - | case _ => | |
1012 | - | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1013 | - | case pk: ByteVector => | |
1014 | - | pk | |
1015 | - | case _: Unit => | |
1016 | - | tx.senderPublicKey | |
1017 | - | case _ => | |
1018 | - | throw("Match error") | |
1019 | - | } | |
1020 | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1021 | - | } | |
1022 | 239 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let defaultDecimals = 1000000 | |
5 | - | ||
6 | - | let scale8 = 100000000 | |
7 | - | ||
8 | - | let scale8BigInt = toBigInt(100000000) | |
9 | - | ||
10 | - | let scale18 = toBigInt(1000000000000000000) | |
11 | - | ||
12 | - | let thousand = 1000 | |
13 | - | ||
14 | - | let zeroBigInt = toBigInt(0) | |
15 | - | ||
16 | - | let oneBigInt = toBigInt(1) | |
17 | - | ||
18 | - | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
19 | - | ||
20 | - | let Amult = "100" | |
21 | - | ||
22 | - | let Dconv = "1" | |
23 | - | ||
24 | 4 | let SEP = "__" | |
25 | 5 | ||
26 | 6 | let EMPTY = "" | |
27 | 7 | ||
28 | - | let PoolActive = 1 | |
29 | - | ||
30 | - | let PoolPutDis = 2 | |
31 | - | ||
32 | - | let PoolMatcherDis = 3 | |
33 | - | ||
34 | - | let PoolShutdown = 4 | |
35 | - | ||
36 | 8 | let idxPoolAddress = 1 | |
37 | - | ||
38 | - | let idxPoolSt = 2 | |
39 | 9 | ||
40 | 10 | let idxLPAsId = 3 | |
41 | 11 | ||
42 | 12 | let idxAmAsId = 4 | |
43 | 13 | ||
44 | 14 | let idxPrAsId = 5 | |
45 | 15 | ||
46 | - | let idxAmtAsDcm = 6 | |
47 | - | ||
48 | - | let idxPriceAsDcm = 7 | |
49 | - | ||
50 | - | let idxIAmtAsId = 8 | |
51 | - | ||
52 | - | let idxIPriceAsId = 9 | |
53 | - | ||
54 | 16 | let idxFactStakCntr = 1 | |
55 | 17 | ||
56 | - | let idxFactSlippCntr = 7 | |
57 | - | ||
58 | - | let idxFactGwxRewCntr = 10 | |
59 | - | ||
60 | - | let feePermilleDefault = 0 | |
61 | - | ||
62 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
63 | - | ||
64 | - | ||
65 | - | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
66 | - | ||
67 | - | ||
68 | - | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
69 | - | ||
70 | - | ||
71 | - | func abs (val) = if ((zeroBigInt > val)) | |
72 | - | then -(val) | |
73 | - | else val | |
74 | - | ||
75 | - | ||
76 | - | func keyFactoryContact () = "%s__factoryContract" | |
18 | + | func keyFactCntr () = "%s__factoryContract" | |
77 | 19 | ||
78 | 20 | ||
79 | 21 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
80 | 22 | ||
81 | 23 | ||
82 | 24 | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
83 | 25 | ||
84 | 26 | ||
85 | - | func | |
27 | + | func keyPoolAddr () = "%s__poolAddress" | |
86 | 28 | ||
87 | 29 | ||
88 | - | func keyPriceHistory (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
89 | - | ||
90 | - | ||
91 | - | func keyPutActionByUser (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
92 | - | ||
93 | - | ||
94 | - | func keyGetActionByUser (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
95 | - | ||
96 | - | ||
97 | - | func keyAmountAsset () = "%s__amountAsset" | |
30 | + | func keyAmtAsset () = "%s__amountAsset" | |
98 | 31 | ||
99 | 32 | ||
100 | 33 | func keyPriceAsset () = "%s__priceAsset" | |
101 | 34 | ||
102 | 35 | ||
103 | - | func | |
36 | + | func keyAdminPubKeys () = "%s__adminPubKeys" | |
104 | 37 | ||
105 | 38 | ||
106 | - | func | |
39 | + | func keyAmp () = "%s__amp" | |
107 | 40 | ||
108 | 41 | ||
109 | - | ||
42 | + | func keyAmpHistory (height) = ("%s%d__amp__" + toString(height)) | |
110 | 43 | ||
111 | - | let feePermille = valueOrElse(getInteger(this, keyFeePermille), feePermilleDefault) | |
112 | 44 | ||
113 | 45 | func keyFactoryConfig () = "%s__factoryConfig" | |
114 | - | ||
115 | - | ||
116 | - | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
117 | 46 | ||
118 | 47 | ||
119 | 48 | func keyPoolConfig (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
120 | 49 | ||
121 | 50 | ||
122 | 51 | func keyMappingsBaseAsset2internalId (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
123 | 52 | ||
124 | 53 | ||
125 | - | func keyAllPoolsShutdown () = "%s__shutdown" | |
126 | - | ||
127 | - | ||
128 | - | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
129 | - | ||
130 | - | ||
131 | - | func throwOrderError (orV,sendrV,matchV) = throwErr(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
132 | - | ||
133 | - | ||
134 | - | func str (val) = match val { | |
135 | - | case valStr: String => | |
136 | - | valStr | |
137 | - | case _ => | |
138 | - | throwErr("fail cast to String") | |
139 | - | } | |
140 | - | ||
141 | - | ||
142 | 54 | func getStringOrFail (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
143 | 55 | ||
144 | 56 | ||
145 | 57 | func getIntOrFail (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
146 | 58 | ||
147 | 59 | ||
148 | - | let | |
60 | + | let poolContract = addressFromStringValue(getStringOrFail(this, keyPoolAddr())) | |
149 | 61 | ||
150 | - | let amplificator = getStringOrFail(this, keyAmplificator()) | |
151 | - | ||
152 | - | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
153 | - | ||
154 | - | ||
155 | - | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
156 | - | ||
157 | - | ||
158 | - | let matcherAddress = addressFromPublicKey(getMatcherPubOrFail()) | |
62 | + | let factoryContract = addressFromStringValue(getStringOrFail(poolContract, keyFactCntr())) | |
159 | 63 | ||
160 | 64 | func getPoolConfig () = { | |
161 | - | let amtAs = getStringOrFail( | |
162 | - | let priceAs = getStringOrFail( | |
65 | + | let amtAs = getStringOrFail(poolContract, keyAmtAsset()) | |
66 | + | let priceAs = getStringOrFail(poolContract, keyPriceAsset()) | |
163 | 67 | let iPriceAs = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAs)) | |
164 | 68 | let iAmtAs = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAs)) | |
165 | 69 | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAs), toString(iPriceAs))), SEP) | |
166 | 70 | } | |
167 | 71 | ||
168 | 72 | ||
169 | 73 | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
170 | - | ||
171 | - | ||
172 | - | 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) | |
173 | - | ||
174 | - | ||
175 | - | 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) | |
176 | - | ||
177 | - | ||
178 | - | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
179 | - | then wavesBalance(this).available | |
180 | - | else assetBalance(this, fromBase58String(assetId)) | |
181 | - | ||
182 | - | ||
183 | - | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
184 | - | ||
185 | - | ||
186 | - | func validateAbsDiff (estimateLP,outLp,slippage) = { | |
187 | - | let diff = fraction((estimateLP - outLp), scale8BigInt, outLp) | |
188 | - | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
189 | - | if (!(pass)) | |
190 | - | then throwErr(("Big slippage: " + toString(diff))) | |
191 | - | else $Tuple2(pass, min([estimateLP, outLp])) | |
192 | - | } | |
193 | - | ||
194 | - | ||
195 | - | func validateD (D1,D0,slippage) = { | |
196 | - | let diff = fraction(D0, scale8BigInt, D1) | |
197 | - | let fail = (slippage > diff) | |
198 | - | if (if (fail) | |
199 | - | then true | |
200 | - | else (D0 > D1)) | |
201 | - | then throwErr(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slippage))) | |
202 | - | else fail | |
203 | - | } | |
204 | - | ||
205 | - | ||
206 | - | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
207 | - | let amtAsAmtX18 = toX18(amAmt, amAssetDcm) | |
208 | - | let prAsAmtX18 = toX18(prAmt, prAssetDcm) | |
209 | - | calcPriceBigInt(prAsAmtX18, amtAsAmtX18) | |
210 | - | } | |
211 | - | ||
212 | - | ||
213 | - | func calcPrices (amAmt,prAmt,lpAmt) = { | |
214 | - | let cfg = getPoolConfig() | |
215 | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
216 | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
217 | - | let priceX18 = privateCalcPrice(amtAsDcm, prAsDcm, amAmt, prAmt) | |
218 | - | let amAmtX18 = toX18(amAmt, amtAsDcm) | |
219 | - | let prAmtX18 = toX18(prAmt, prAsDcm) | |
220 | - | let lpAmtX18 = toX18(lpAmt, scale8) | |
221 | - | let lpPrInAmAsX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
222 | - | let lpPrInPrAsX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
223 | - | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
224 | - | } | |
225 | - | ||
226 | - | ||
227 | - | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
228 | - | let p = calcPrices(amAmt, prAmt, lpAmt) | |
229 | - | [fromX18(p[0], scale8), fromX18(p[1], scale8), fromX18(p[2], scale8)] | |
230 | - | } | |
231 | - | ||
232 | - | ||
233 | - | func estimateGetOperation (txId58,paymentAssetId,paymentLpAmount,userAddress) = { | |
234 | - | let cfg = getPoolConfig() | |
235 | - | let lpAssetId = cfg[idxLPAsId] | |
236 | - | let amountId = cfg[idxAmAsId] | |
237 | - | let priceId = cfg[idxPrAsId] | |
238 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
239 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
240 | - | let sts = cfg[idxPoolSt] | |
241 | - | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), "Wrong LP id").quantity | |
242 | - | let validationBlock = if ((lpAssetId == paymentAssetId)) | |
243 | - | then true | |
244 | - | else throwErr("Wrong payment asset") | |
245 | - | if ((validationBlock == validationBlock)) | |
246 | - | then { | |
247 | - | let amountBalance = getAccBalance(amountId) | |
248 | - | let priceBalance = getAccBalance(priceId) | |
249 | - | let amountBalanceDefaultDecimals = fraction(amountBalance, defaultDecimals, amountDecimals) | |
250 | - | let priceBalanceDefaultDecimals = fraction(priceBalance, defaultDecimals, priceDecimals) | |
251 | - | let amountBalanceX18 = toX18(amountBalanceDefaultDecimals, defaultDecimals) | |
252 | - | let priceBalanceX18 = toX18(priceBalanceDefaultDecimals, defaultDecimals) | |
253 | - | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
254 | - | let curPrice = fromX18(currentPriceX18, scale8) | |
255 | - | let paymentLpAmountX18 = toX18(paymentLpAmount, scale8) | |
256 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
257 | - | let outAmountAmountX18 = fraction(amountBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
258 | - | let outPriceAmountX18 = fraction(priceBalanceX18, paymentLpAmountX18, lpEmissionX18) | |
259 | - | let outAmountAmountDefaultDecimals = fromX18(outAmountAmountX18, defaultDecimals) | |
260 | - | let outPriceAmountDefaultDecimals = fromX18(outPriceAmountX18, defaultDecimals) | |
261 | - | let outAmountAmount = fraction(outAmountAmountDefaultDecimals, amountDecimals, defaultDecimals) | |
262 | - | let outPriceAmount = fraction(outPriceAmountDefaultDecimals, priceDecimals, defaultDecimals) | |
263 | - | let state = if ((txId58 == "")) | |
264 | - | then nil | |
265 | - | else [ScriptTransfer(userAddress, outAmountAmount, if ((amountId == "WAVES")) | |
266 | - | then unit | |
267 | - | else fromBase58String(amountId)), ScriptTransfer(userAddress, outPriceAmount, if ((priceId == "WAVES")) | |
268 | - | then unit | |
269 | - | else fromBase58String(priceId)), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAmountAmount, outPriceAmount, paymentLpAmount, curPrice, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPrice)] | |
270 | - | $Tuple10(outAmountAmount, outPriceAmount, amountId, priceId, amountBalance, priceBalance, lpEmission, currentPriceX18, sts, state) | |
271 | - | } | |
272 | - | else throw("Strict value is not equal to itself.") | |
273 | - | } | |
274 | - | ||
275 | - | ||
276 | - | func estimatePutOperation (txId58,slippageTolerance,inAmountAssetAmount,inAmountAssetId,inPriceAssetAmount,inPriceAssetId,userAddress,isEvaluate,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
277 | - | let cfg = getPoolConfig() | |
278 | - | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
279 | - | let amountIdStr = cfg[idxAmAsId] | |
280 | - | let priceIdStr = cfg[idxPrAsId] | |
281 | - | let inAmountIdStr = cfg[idxIAmtAsId] | |
282 | - | let inPriceIdStr = cfg[idxIPriceAsId] | |
283 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
284 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
285 | - | let sts = cfg[idxPoolSt] | |
286 | - | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), "Wrong lp asset").quantity | |
287 | - | let amountBalance = if (isEvaluate) | |
288 | - | then getAccBalance(amountIdStr) | |
289 | - | else if (if (isOneAsset) | |
290 | - | then (paymentId == amountIdStr) | |
291 | - | else false) | |
292 | - | then (getAccBalance(amountIdStr) - paymentAmount) | |
293 | - | else if (isOneAsset) | |
294 | - | then getAccBalance(amountIdStr) | |
295 | - | else (getAccBalance(amountIdStr) - inAmountAssetAmount) | |
296 | - | let priceBalance = if (isEvaluate) | |
297 | - | then getAccBalance(priceIdStr) | |
298 | - | else if (if (isOneAsset) | |
299 | - | then (paymentId == priceIdStr) | |
300 | - | else false) | |
301 | - | then (getAccBalance(priceIdStr) - paymentAmount) | |
302 | - | else if (isOneAsset) | |
303 | - | then getAccBalance(priceIdStr) | |
304 | - | else (getAccBalance(priceIdStr) - inPriceAssetAmount) | |
305 | - | let amountBalanceDefaultDecimals = fraction(amountBalance, defaultDecimals, amountDecimals) | |
306 | - | let priceBalanceDefaultDecimals = fraction(priceBalance, defaultDecimals, priceDecimals) | |
307 | - | let inAmountAssetAmountDefaultDecimals = fraction(inAmountAssetAmount, defaultDecimals, amountDecimals) | |
308 | - | let inPriceAssetAmountDefaultDecimals = fraction(inPriceAssetAmount, defaultDecimals, priceDecimals) | |
309 | - | let inAmountAssetAmountX18 = toX18(inAmountAssetAmountDefaultDecimals, defaultDecimals) | |
310 | - | let inPriceAssetAmountX18 = toX18(inPriceAssetAmountDefaultDecimals, defaultDecimals) | |
311 | - | let userPriceX18 = calcPriceBigInt(inPriceAssetAmountX18, inAmountAssetAmountX18) | |
312 | - | let amountBalanceX18 = toX18(amountBalanceDefaultDecimals, defaultDecimals) | |
313 | - | let priceBalanceX18 = toX18(priceBalanceDefaultDecimals, defaultDecimals) | |
314 | - | let r = if ((lpEmission == 0)) | |
315 | - | then { | |
316 | - | let currentPriceX18 = zeroBigInt | |
317 | - | let slippageX18 = zeroBigInt | |
318 | - | let lpAmountX18 = pow((inAmountAssetAmountX18 * inPriceAssetAmountX18), 0, toBigInt(5), 1, 0, DOWN) | |
319 | - | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(inAmountAssetAmountX18, defaultDecimals), fromX18(inPriceAssetAmountX18, defaultDecimals), calcPriceBigInt((priceBalanceX18 + inPriceAssetAmountX18), (amountBalanceX18 + inAmountAssetAmountX18)), slippageX18) | |
320 | - | } | |
321 | - | else { | |
322 | - | let currentPriceX18 = calcPriceBigInt(priceBalanceX18, amountBalanceX18) | |
323 | - | let slippageRealX18 = fraction(abs((currentPriceX18 - userPriceX18)), scale18, currentPriceX18) | |
324 | - | let slippageX18 = toX18(slippageTolerance, scale8) | |
325 | - | let validateSlippage = if (((if ((currentPriceX18 != zeroBigInt)) | |
326 | - | then (slippageRealX18 > slippageX18) | |
327 | - | else false) == false)) | |
328 | - | then true | |
329 | - | else throwErr(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
330 | - | if ((validateSlippage == validateSlippage)) | |
331 | - | then { | |
332 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
333 | - | let prViaAmX18 = fraction(inAmountAssetAmountX18, currentPriceX18, scale18) | |
334 | - | let amViaPrX18 = fraction(inPriceAssetAmountX18, scale18, currentPriceX18) | |
335 | - | let expectedAmounts = if ((prViaAmX18 > inPriceAssetAmountX18)) | |
336 | - | then $Tuple2(amViaPrX18, inAmountAssetAmountX18) | |
337 | - | else $Tuple2(inAmountAssetAmountX18, prViaAmX18) | |
338 | - | let expectedAmountAssetAmountX18 = expectedAmounts._1 | |
339 | - | let expectedPriceAssetAmountX18 = expectedAmounts._2 | |
340 | - | let lpAmountX18 = fraction(lpEmissionX18, expectedPriceAssetAmountX18, priceBalanceX18) | |
341 | - | $Tuple5(fromX18(lpAmountX18, scale8), fromX18(expectedAmountAssetAmountX18, defaultDecimals), fromX18(expectedPriceAssetAmountX18, defaultDecimals), currentPriceX18, slippageX18) | |
342 | - | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | - | } | |
345 | - | let calculateLpAmount = r._1 | |
346 | - | let calculateAmountAssetPayment = fraction(r._2, amountDecimals, defaultDecimals) | |
347 | - | let calculatePriceAssetPayment = fraction(r._3, priceDecimals, defaultDecimals) | |
348 | - | let currentPrice = fromX18(r._4, scale8) | |
349 | - | let slippageCalculate = fromX18(r._5, scale8) | |
350 | - | let checkCalcLpAmount = if ((calculateLpAmount > 0)) | |
351 | - | then true | |
352 | - | else throwErr("LP <= 0") | |
353 | - | if ((checkCalcLpAmount == checkCalcLpAmount)) | |
354 | - | then { | |
355 | - | let emitLpAmount = if (!(emitLp)) | |
356 | - | then 0 | |
357 | - | else calculateLpAmount | |
358 | - | let amountDiff = (inAmountAssetAmount - calculateAmountAssetPayment) | |
359 | - | let priceDiff = (inPriceAssetAmount - calculatePriceAssetPayment) | |
360 | - | let $t01715017409 = if (if (isOneAsset) | |
361 | - | then (paymentId == amountIdStr) | |
362 | - | else false) | |
363 | - | then $Tuple2(paymentAmount, 0) | |
364 | - | else if (if (isOneAsset) | |
365 | - | then (paymentId == priceIdStr) | |
366 | - | else false) | |
367 | - | then $Tuple2(0, paymentAmount) | |
368 | - | else $Tuple2(calculateAmountAssetPayment, calculatePriceAssetPayment) | |
369 | - | let writeAmAmt = $t01715017409._1 | |
370 | - | let writePrAmt = $t01715017409._2 | |
371 | - | let commonState = [IntegerEntry(keyPriceLast(), currentPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), currentPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(writeAmAmt, writePrAmt, emitLpAmount, currentPrice, slippageTolerance, slippageCalculate, height, lastBlock.timestamp, amountDiff, priceDiff))] | |
372 | - | $Tuple13(calculateLpAmount, emitLpAmount, currentPrice, amountBalance, priceBalance, lpEmission, lpAssetId, sts, commonState, amountDiff, priceDiff, inAmountAssetId, inPriceAssetId) | |
373 | - | } | |
374 | - | else throw("Strict value is not equal to itself.") | |
375 | - | } | |
376 | - | ||
377 | - | ||
378 | - | func validateMatcherOrderAllowed (order) = { | |
379 | - | let cfg = getPoolConfig() | |
380 | - | let amtAsId = cfg[idxAmAsId] | |
381 | - | let prAsId = cfg[idxPrAsId] | |
382 | - | let sts = parseIntValue(cfg[idxPoolSt]) | |
383 | - | let amtAsDcm = parseIntValue(cfg[idxAmtAsDcm]) | |
384 | - | let prAsDcm = parseIntValue(cfg[idxPriceAsDcm]) | |
385 | - | let accAmtAsBalance = getAccBalance(amtAsId) | |
386 | - | let accPrAsBalance = getAccBalance(prAsId) | |
387 | - | let currentPriceX18 = if ((order.orderType == Buy)) | |
388 | - | then privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance + order.amount), accPrAsBalance) | |
389 | - | else privateCalcPrice(amtAsDcm, prAsDcm, (accAmtAsBalance - order.amount), accPrAsBalance) | |
390 | - | let curPrice = fromX18(currentPriceX18, scale8) | |
391 | - | if (if (if (isGlobalShutdown()) | |
392 | - | then true | |
393 | - | else (sts == PoolMatcherDis)) | |
394 | - | then true | |
395 | - | else (sts == PoolShutdown)) | |
396 | - | then throwErr("Admin blocked") | |
397 | - | else { | |
398 | - | let orAmtAsset = order.assetPair.amountAsset | |
399 | - | let orAmtAsStr = if ((orAmtAsset == unit)) | |
400 | - | then "WAVES" | |
401 | - | else toBase58String(value(orAmtAsset)) | |
402 | - | let orPrAsset = order.assetPair.priceAsset | |
403 | - | let orPrAsStr = if ((orPrAsset == unit)) | |
404 | - | then "WAVES" | |
405 | - | else toBase58String(value(orPrAsset)) | |
406 | - | if (if ((orAmtAsStr != amtAsId)) | |
407 | - | then true | |
408 | - | else (orPrAsStr != prAsId)) | |
409 | - | then throwErr("Wr assets") | |
410 | - | else { | |
411 | - | let orderPrice = order.price | |
412 | - | let priceDecimals = fraction(scale8, prAsDcm, amtAsDcm) | |
413 | - | let castOrderPrice = ts(orderPrice, scale8, priceDecimals) | |
414 | - | let isOrderPriceValid = if ((order.orderType == Buy)) | |
415 | - | then (curPrice >= castOrderPrice) | |
416 | - | else (castOrderPrice >= curPrice) | |
417 | - | true | |
418 | - | } | |
419 | - | } | |
420 | - | } | |
421 | - | ||
422 | - | ||
423 | - | func commonGet (i) = { | |
424 | - | let checkPayments = if ((size(i.payments) == 1)) | |
425 | - | then true | |
426 | - | else throwErr("1 payment expected") | |
427 | - | if ((checkPayments == checkPayments)) | |
428 | - | then { | |
429 | - | let payment = value(i.payments[0]) | |
430 | - | let paymentAssetId = value(payment.assetId) | |
431 | - | let paymentAmount = payment.amount | |
432 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
433 | - | let outAmountAmount = r._1 | |
434 | - | let outPriceAmount = r._2 | |
435 | - | let sts = parseIntValue(r._9) | |
436 | - | let state = r._10 | |
437 | - | if (if (isGlobalShutdown()) | |
438 | - | then true | |
439 | - | else (sts == PoolShutdown)) | |
440 | - | then throwErr(("Admin blocked: " + toString(sts))) | |
441 | - | else $Tuple5(outAmountAmount, outPriceAmount, paymentAmount, paymentAssetId, state) | |
442 | - | } | |
443 | - | else throw("Strict value is not equal to itself.") | |
444 | - | } | |
445 | - | ||
446 | - | ||
447 | - | func commonPut (caller,txId,amountAssetPayment,priceAssetPayment,slippage,emitLp,isOneAsset,paymentAmount,paymentId) = { | |
448 | - | let r = estimatePutOperation(txId, slippage, value(amountAssetPayment).amount, value(amountAssetPayment).assetId, value(priceAssetPayment).amount, value(priceAssetPayment).assetId, caller, false, emitLp, isOneAsset, paymentAmount, paymentId) | |
449 | - | let sts = parseIntValue(r._8) | |
450 | - | if (if (if (isGlobalShutdown()) | |
451 | - | then true | |
452 | - | else (sts == PoolPutDis)) | |
453 | - | then true | |
454 | - | else (sts == PoolShutdown)) | |
455 | - | then throwErr(("Blocked:" + toString(sts))) | |
456 | - | else r | |
457 | - | } | |
458 | - | ||
459 | - | ||
460 | - | func takeFee (amount) = { | |
461 | - | let fee = fraction(amount, feePermille, thousand) | |
462 | - | $Tuple2((amount - fee), fee) | |
463 | - | } | |
464 | 74 | ||
465 | 75 | ||
466 | 76 | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
467 | 77 | case s: String => | |
468 | 78 | fromBase58String(s) | |
469 | 79 | case _: Unit => | |
470 | 80 | unit | |
471 | 81 | case _ => | |
472 | 82 | throw("Match error") | |
473 | 83 | } | |
474 | 84 | ||
475 | 85 | ||
476 | 86 | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { | |
477 | 87 | case s: String => | |
478 | 88 | fromBase58String(s) | |
479 | 89 | case _: Unit => | |
480 | 90 | unit | |
481 | 91 | case _ => | |
482 | 92 | throw("Match error") | |
483 | 93 | } | |
484 | 94 | ||
485 | 95 | ||
486 | - | let pd = throwErr("Permission denied") | |
96 | + | func mustManager (i) = { | |
97 | + | let pd = throw("Permission denied") | |
98 | + | match managerPublicKeyOrUnit() { | |
99 | + | case pk: ByteVector => | |
100 | + | if ((i.callerPublicKey == pk)) | |
101 | + | then true | |
102 | + | else pd | |
103 | + | case _: Unit => | |
104 | + | if ((i.caller == this)) | |
105 | + | then true | |
106 | + | else pd | |
107 | + | case _ => | |
108 | + | throw("Match error") | |
109 | + | } | |
110 | + | } | |
487 | 111 | ||
488 | - | func mustManager (i) = match managerPublicKeyOrUnit() { | |
489 | - | case pk: ByteVector => | |
490 | - | if ((i.callerPublicKey == pk)) | |
491 | - | then true | |
492 | - | else pd | |
493 | - | case _: Unit => | |
494 | - | if ((i.caller == this)) | |
495 | - | then true | |
496 | - | else pd | |
112 | + | ||
113 | + | func getAdmins () = match getString(keyAdminPubKeys()) { | |
114 | + | case s: String => | |
115 | + | if ((size(s) == 0)) | |
116 | + | then nil | |
117 | + | else split(s, SEP) | |
497 | 118 | case _ => | |
498 | - | | |
119 | + | nil | |
499 | 120 | } | |
500 | 121 | ||
501 | 122 | ||
123 | + | func mustAdmin (i) = if (containsElement(getAdmins(), toBase58String(i.callerPublicKey))) | |
124 | + | then true | |
125 | + | else mustManager(i) | |
126 | + | ||
127 | + | ||
128 | + | func mustPool (i) = if ((i.caller == poolContract)) | |
129 | + | then true | |
130 | + | else throw("caller must be the pool") | |
131 | + | ||
132 | + | ||
502 | 133 | @Callable(i) | |
503 | - | func constructor ( | |
134 | + | func constructor (poolAddress) = { | |
504 | 135 | let checkCaller = mustManager(i) | |
505 | 136 | if ((checkCaller == checkCaller)) | |
506 | - | then [StringEntry( | |
137 | + | then [StringEntry(keyPoolAddr(), poolAddress)] | |
507 | 138 | else throw("Strict value is not equal to itself.") | |
508 | 139 | } | |
509 | 140 | ||
510 | 141 | ||
511 | 142 | ||
512 | 143 | @Callable(i) | |
513 | 144 | func setManager (pendingManagerPublicKey) = { | |
514 | 145 | let checkCaller = mustManager(i) | |
515 | 146 | if ((checkCaller == checkCaller)) | |
516 | 147 | then { | |
517 | 148 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
518 | 149 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
519 | 150 | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
520 | 151 | else throw("Strict value is not equal to itself.") | |
521 | 152 | } | |
522 | 153 | else throw("Strict value is not equal to itself.") | |
523 | 154 | } | |
524 | 155 | ||
525 | 156 | ||
526 | 157 | ||
527 | 158 | @Callable(i) | |
528 | 159 | func confirmManager () = { | |
529 | 160 | let pm = pendingManagerPublicKeyOrUnit() | |
530 | 161 | let hasPM = if (isDefined(pm)) | |
531 | 162 | then true | |
532 | - | else | |
163 | + | else throw("No pending manager") | |
533 | 164 | if ((hasPM == hasPM)) | |
534 | 165 | then { | |
535 | 166 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
536 | 167 | then true | |
537 | - | else | |
168 | + | else throw("You are not pending manager") | |
538 | 169 | if ((checkPM == checkPM)) | |
539 | 170 | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
540 | 171 | else throw("Strict value is not equal to itself.") | |
541 | 172 | } | |
542 | 173 | else throw("Strict value is not equal to itself.") | |
543 | 174 | } | |
544 | 175 | ||
545 | 176 | ||
546 | 177 | ||
547 | 178 | @Callable(i) | |
548 | - | func put (slippage,autoStake) = { | |
549 | - | let factCfg = getFactoryConfig() | |
550 | - | let stakingContract = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wrong staking contract") | |
551 | - | let slippageContract = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wrogn slippage contract") | |
552 | - | let slippageCheck = if ((slippage >= 0)) | |
553 | - | then true | |
554 | - | else throwErr("wrong slippage") | |
555 | - | if ((slippageCheck == slippageCheck)) | |
179 | + | func setAdmins (adminPubKeys) = { | |
180 | + | let checkCaller = mustManager(i) | |
181 | + | if ((checkCaller == checkCaller)) | |
182 | + | then [StringEntry(keyAdminPubKeys(), makeString(adminPubKeys, SEP))] | |
183 | + | else throw("Strict value is not equal to itself.") | |
184 | + | } | |
185 | + | ||
186 | + | ||
187 | + | ||
188 | + | @Callable(i) | |
189 | + | func unstakeAndGetOneTkn (amount,exchResult,notUsed,outAmount,outAssetId,slippage) = { | |
190 | + | let checkPayments = if ((size(i.payments) != 0)) | |
191 | + | then throw("No pmnts expd") | |
192 | + | else true | |
193 | + | if ((checkPayments == checkPayments)) | |
556 | 194 | then { | |
557 | - | let paymentsCheck = if ((size(i.payments) == 2)) | |
558 | - | then true | |
559 | - | else throwErr("2 payments expected") | |
560 | - | if ((paymentsCheck == paymentsCheck)) | |
195 | + | let cfg = getPoolConfig() | |
196 | + | let factoryCfg = getFactoryConfig() | |
197 | + | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
198 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
199 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
200 | + | if ((unstakeInv == unstakeInv)) | |
561 | 201 | then { | |
562 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], slippage, true, false, 0, "") | |
563 | - | let emitLpAmount = estimatePut._2 | |
564 | - | let lpAssetId = estimatePut._7 | |
565 | - | let state = estimatePut._9 | |
566 | - | let amountDiff = estimatePut._10 | |
567 | - | let priceDiff = estimatePut._11 | |
568 | - | let amountId = estimatePut._12 | |
569 | - | let priceId = estimatePut._13 | |
570 | - | let r = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
571 | - | if ((r == r)) | |
572 | - | then { | |
573 | - | let el = match r { | |
574 | - | case legacy: Address => | |
575 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
576 | - | case _ => | |
577 | - | unit | |
578 | - | } | |
579 | - | if ((el == el)) | |
580 | - | then { | |
581 | - | let sa = if ((amountDiff > 0)) | |
582 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(amountId, amountDiff)]) | |
583 | - | else nil | |
584 | - | if ((sa == sa)) | |
585 | - | then { | |
586 | - | let sp = if ((priceDiff > 0)) | |
587 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(priceId, priceDiff)]) | |
588 | - | else nil | |
589 | - | if ((sp == sp)) | |
590 | - | then { | |
591 | - | let lpTrasfer = if (autoStake) | |
592 | - | then { | |
593 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
594 | - | if ((ss == ss)) | |
595 | - | then nil | |
596 | - | else throw("Strict value is not equal to itself.") | |
597 | - | } | |
598 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
599 | - | (state ++ lpTrasfer) | |
600 | - | } | |
601 | - | else throw("Strict value is not equal to itself.") | |
602 | - | } | |
603 | - | else throw("Strict value is not equal to itself.") | |
604 | - | } | |
605 | - | else throw("Strict value is not equal to itself.") | |
606 | - | } | |
202 | + | let getOneTkn = invoke(poolContract, "getOneTkn", [exchResult, notUsed, outAmount, outAssetId, slippage], [AttachedPayment(lpAssetId, amount)]) | |
203 | + | if ((getOneTkn == getOneTkn)) | |
204 | + | then nil | |
607 | 205 | else throw("Strict value is not equal to itself.") | |
608 | 206 | } | |
609 | 207 | else throw("Strict value is not equal to itself.") | |
610 | 208 | } | |
611 | 209 | else throw("Strict value is not equal to itself.") | |
612 | 210 | } | |
613 | 211 | ||
614 | 212 | ||
615 | 213 | ||
616 | 214 | @Callable(i) | |
617 | - | func putOneTkn (amountAssetPart,priceAssetPart,outLp,slippage,autoStake) = { | |
618 | - | let cfg = getFactoryConfig() | |
619 | - | let stakingContract = valueOrErrorMessage(addressFromString(cfg[idxFactStakCntr]), "Wrong staking contract") | |
620 | - | let slippageContract = valueOrErrorMessage(addressFromString(cfg[idxFactSlippCntr]), "Wrong slippage contract") | |
621 | - | let gwxRewardContract = valueOrErrorMessage(addressFromString(cfg[idxFactGwxRewCntr]), "Wrong gwx reward contract") | |
622 | - | let poolCfg = getPoolConfig() | |
623 | - | let amountId = poolCfg[idxAmAsId] | |
624 | - | let priceId = poolCfg[idxPrAsId] | |
625 | - | let amountDecimals = parseIntValue(poolCfg[idxAmtAsDcm]) | |
626 | - | let priceDecimals = parseIntValue(poolCfg[idxPriceAsDcm]) | |
627 | - | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
628 | - | let userAddress = if ((addon == toString(i.caller))) | |
629 | - | then i.originCaller | |
630 | - | else i.caller | |
631 | - | if (if (if (if ((0 >= slippage)) | |
632 | - | then true | |
633 | - | else (0 >= amountAssetPart)) | |
634 | - | then true | |
635 | - | else (0 >= priceAssetPart)) | |
636 | - | then true | |
637 | - | else (0 >= outLp)) | |
638 | - | then throwErr("Wrong params") | |
639 | - | else if ((size(i.payments) != 1)) | |
640 | - | then throwErr("1 payment expected") | |
641 | - | else { | |
642 | - | let payment = value(i.payments[0]) | |
643 | - | let paymentAssetId = toBase58String(value(payment.assetId)) | |
644 | - | let paymentAmountRaw = payment.amount | |
645 | - | let $t02656926628 = takeFee(paymentAmountRaw) | |
646 | - | let paymentAmount = $t02656926628._1 | |
647 | - | let feeAmount = $t02656926628._2 | |
648 | - | if (if (if ((amountAssetPart > paymentAmount)) | |
649 | - | then true | |
650 | - | else (priceAssetPart > paymentAmount)) | |
651 | - | then true | |
652 | - | else (10000000 > paymentAmount)) | |
653 | - | then throwErr("wrong payment amount") | |
654 | - | else { | |
655 | - | let amountBalance = getAccBalance(amountId) | |
656 | - | let priceBalance = getAccBalance(priceId) | |
657 | - | let $t02689327348 = if ((paymentAssetId == amountId)) | |
658 | - | then $Tuple6((amountBalance - paymentAmount), priceBalance, (paymentAmount - amountAssetPart), priceAssetPart, 0, 0) | |
659 | - | else if ((paymentAssetId == priceId)) | |
660 | - | then $Tuple6(amountBalance, (priceBalance - paymentAmount), 0, 0, (paymentAmount - priceAssetPart), amountAssetPart) | |
661 | - | else throwErr("wrong paymentAssetId") | |
662 | - | let amountBalanceNow = $t02689327348._1 | |
663 | - | let priceBalanceNow = $t02689327348._2 | |
664 | - | let virtSwapInAm = $t02689327348._3 | |
665 | - | let virtSwapOutPr = $t02689327348._4 | |
666 | - | let virtSwapInPr = $t02689327348._5 | |
667 | - | let virtSwapOutAm = $t02689327348._6 | |
668 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
669 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(toBigInt(((amountBalanceNow + virtSwapInAm) - virtSwapOutAm))), toString(toBigInt(((priceBalanceNow + virtSwapInPr) - virtSwapOutPr))), amplificator, Amult, Dconv], nil) | |
670 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
671 | - | if ((D0vsD1 == D0vsD1)) | |
672 | - | then { | |
673 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(fromBase58String(amountId), amountAssetPart), AttachedPayment(fromBase58String(priceId), priceAssetPart), slippage, true, true, paymentAmount, paymentAssetId) | |
674 | - | let estimateLP = estimatePut._2 | |
675 | - | let lpAssetId = estimatePut._7 | |
676 | - | let state = estimatePut._9 | |
677 | - | let amountDiff = estimatePut._10 | |
678 | - | let priceDiff = estimatePut._11 | |
679 | - | let lpCalcRes = validateAbsDiff(toBigInt(estimateLP), toBigInt(outLp), toBigInt(slippage)) | |
680 | - | let emitLpAmount = toInt(lpCalcRes._2) | |
681 | - | let e = invoke(factoryContract, "emit", [emitLpAmount], nil) | |
682 | - | if ((e == e)) | |
683 | - | then { | |
684 | - | let el = match e { | |
685 | - | case legacy: Address => | |
686 | - | invoke(legacy, "emit", [emitLpAmount], nil) | |
687 | - | case _ => | |
688 | - | unit | |
689 | - | } | |
690 | - | if ((el == el)) | |
691 | - | then { | |
692 | - | let sa = if ((amountDiff > 0)) | |
693 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(amountId), amountDiff)]) | |
694 | - | else nil | |
695 | - | if ((sa == sa)) | |
696 | - | then { | |
697 | - | let sp = if ((priceDiff > 0)) | |
698 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(fromBase58String(priceId), priceDiff)]) | |
699 | - | else nil | |
700 | - | if ((sp == sp)) | |
701 | - | then { | |
702 | - | let lpTrasfer = if (autoStake) | |
703 | - | then { | |
704 | - | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmount)]) | |
705 | - | if ((ss == ss)) | |
706 | - | then nil | |
707 | - | else throw("Strict value is not equal to itself.") | |
708 | - | } | |
709 | - | else [ScriptTransfer(i.caller, emitLpAmount, lpAssetId)] | |
710 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
711 | - | then [ScriptTransfer(matcherAddress, feeAmount, fromBase58String(paymentAssetId))] | |
712 | - | else nil | |
713 | - | ((state ++ lpTrasfer) ++ sendFeeToMatcher) | |
714 | - | } | |
715 | - | else throw("Strict value is not equal to itself.") | |
716 | - | } | |
717 | - | else throw("Strict value is not equal to itself.") | |
718 | - | } | |
719 | - | else throw("Strict value is not equal to itself.") | |
720 | - | } | |
721 | - | else throw("Strict value is not equal to itself.") | |
722 | - | } | |
723 | - | else throw("Strict value is not equal to itself.") | |
724 | - | } | |
725 | - | } | |
726 | - | } | |
727 | - | ||
728 | - | ||
729 | - | ||
730 | - | @Callable(i) | |
731 | - | func putForFree (maxslippage) = if ((0 > maxslippage)) | |
732 | - | then throwErr("wrong slippage") | |
733 | - | else if ((size(i.payments) != 2)) | |
734 | - | then throwErr("2 payments expected") | |
735 | - | else { | |
736 | - | let estimatePut = commonPut(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxslippage, false, false, 0, "") | |
737 | - | estimatePut._9 | |
738 | - | } | |
739 | - | ||
740 | - | ||
741 | - | ||
742 | - | @Callable(i) | |
743 | - | func get () = { | |
744 | - | let r = commonGet(i) | |
745 | - | let outAmtAmt = r._1 | |
746 | - | let outPriceAmount = r._2 | |
747 | - | let paymentAmount = r._3 | |
748 | - | let paymentAssetId = r._4 | |
749 | - | let state = r._5 | |
750 | - | let b = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
751 | - | if ((b == b)) | |
752 | - | then state | |
753 | - | else throw("Strict value is not equal to itself.") | |
754 | - | } | |
755 | - | ||
756 | - | ||
757 | - | ||
758 | - | @Callable(i) | |
759 | - | func getOneTkn (exchResult,notUsed,outAmount,outAssetId,slippage) = if ((size(i.payments) != 1)) | |
760 | - | then throwErr("1 payment expected") | |
761 | - | else { | |
762 | - | let cfg = getPoolConfig() | |
763 | - | let lpAssetId = cfg[idxLPAsId] | |
764 | - | let amountId = cfg[idxAmAsId] | |
765 | - | let priceId = cfg[idxPrAsId] | |
766 | - | let amountDecimals = parseIntValue(cfg[idxAmtAsDcm]) | |
767 | - | let priceDecimals = parseIntValue(cfg[idxPriceAsDcm]) | |
768 | - | let sts = cfg[idxPoolSt] | |
769 | - | let factCfg = getFactoryConfig() | |
770 | - | let gwxRewardContract = valueOrErrorMessage(addressFromString(factCfg[idxFactGwxRewCntr]), "Wrong gwxRewardContract address") | |
771 | - | let payment = value(i.payments[0]) | |
772 | - | let addon = valueOrElse(getString(this, keyAddonAddress()), "") | |
773 | - | let userAddress = if ((addon == toString(i.caller))) | |
774 | - | then i.originCaller | |
775 | - | else i.caller | |
776 | - | let txId58 = toBase58String(i.transactionId) | |
777 | - | let paymentAssetId = value(payment.assetId) | |
778 | - | let paymentAmount = payment.amount | |
779 | - | if ((1000000000 > paymentAmount)) | |
780 | - | then throwErr("Min payment 10 LP") | |
781 | - | else if (if (if ((0 > slippage)) | |
782 | - | then true | |
783 | - | else (0 > exchResult)) | |
784 | - | then true | |
785 | - | else (0 > outAmount)) | |
786 | - | then throwErr("Wrong params") | |
787 | - | else if ((lpAssetId != toBase58String(paymentAssetId))) | |
788 | - | then throwErr("Wrong LP") | |
789 | - | else { | |
790 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(paymentAssetId), paymentAmount, i.caller) | |
791 | - | let estimAmAmt = r._1 | |
792 | - | let estimPrAmt = r._2 | |
793 | - | let amountBalance = getAccBalance(amountId) | |
794 | - | let priceBalance = getAccBalance(priceId) | |
795 | - | let $t03249632964 = if ((outAssetId == amountId)) | |
796 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), exchResult, estimPrAmt, 0, 0, (estimAmAmt + exchResult)) | |
797 | - | else if ((outAssetId == priceId)) | |
798 | - | then $Tuple7((amountBalance - estimAmAmt), (priceBalance - estimPrAmt), 0, 0, exchResult, estimAmAmt, (estimPrAmt + exchResult)) | |
799 | - | else throwErr("wrong outAssetId") | |
800 | - | let amountBalanceNow = $t03249632964._1 | |
801 | - | let priceBalanceNow = $t03249632964._2 | |
802 | - | let virtSwapInAm = $t03249632964._3 | |
803 | - | let virtSwapOutPr = $t03249632964._4 | |
804 | - | let virtSwapInPr = $t03249632964._5 | |
805 | - | let virtSwapOutAm = $t03249632964._6 | |
806 | - | let totalGet = $t03249632964._7 | |
807 | - | if (if ((0 > virtSwapInAm)) | |
808 | - | then true | |
809 | - | else (0 > virtSwapInPr)) | |
810 | - | then throwErr("Wrong calc") | |
811 | - | else { | |
812 | - | let D0 = invoke(gwxRewardContract, "calcD", [toString(amountBalanceNow), toString(priceBalanceNow), amplificator, Amult, Dconv], nil) | |
813 | - | let D1 = invoke(gwxRewardContract, "calcD", [toString(((amountBalanceNow - virtSwapInAm) + virtSwapOutAm)), toString(((priceBalanceNow + virtSwapOutPr) - virtSwapInPr)), amplificator, Amult, Dconv], nil) | |
814 | - | let D0vsD1 = validateD(parseBigIntValue(str(D1)), parseBigIntValue(str(D0)), slippage4D) | |
815 | - | if ((D0vsD1 == D0vsD1)) | |
816 | - | then { | |
817 | - | let finalRes = validateAbsDiff(toBigInt(totalGet), toBigInt(outAmount), toBigInt(slippage)) | |
818 | - | if ((finalRes == finalRes)) | |
819 | - | then { | |
820 | - | let $t03363333741 = if ((outAssetId == amountId)) | |
821 | - | then $Tuple2(toInt(finalRes._2), 0) | |
822 | - | else $Tuple2(0, toInt(finalRes._2)) | |
823 | - | let outAm = $t03363333741._1 | |
824 | - | let outPr = $t03363333741._2 | |
825 | - | let totalAmountRaw = (outAm + outPr) | |
826 | - | let $t03378133836 = takeFee(totalAmountRaw) | |
827 | - | let totalAmount = $t03378133836._1 | |
828 | - | let feeAmount = $t03378133836._2 | |
829 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
830 | - | then unit | |
831 | - | else fromBase58String(outAssetId) | |
832 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
833 | - | then [ScriptTransfer(matcherAddress, feeAmount, outAssetIdOrWaves)] | |
834 | - | else nil | |
835 | - | let decimals = if ((amountDecimals >= priceDecimals)) | |
836 | - | then amountDecimals | |
837 | - | else priceDecimals | |
838 | - | if ((decimals == decimals)) | |
839 | - | then { | |
840 | - | let curPrX18 = calcPriceBigInt(toX18(priceBalance, decimals), toX18(amountBalance, decimals)) | |
841 | - | let curPr = fromX18(curPrX18, scale8) | |
842 | - | let state = [ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(keyGetActionByUser(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, paymentAmount, curPr, height, lastBlock.timestamp)), IntegerEntry(keyPriceLast(), curPr), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPr)] | |
843 | - | if ((state == state)) | |
844 | - | then { | |
845 | - | let burn = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
846 | - | if ((burn == burn)) | |
847 | - | then (state ++ sendFeeToMatcher) | |
848 | - | else throw("Strict value is not equal to itself.") | |
849 | - | } | |
850 | - | else throw("Strict value is not equal to itself.") | |
851 | - | } | |
852 | - | else throw("Strict value is not equal to itself.") | |
853 | - | } | |
854 | - | else throw("Strict value is not equal to itself.") | |
855 | - | } | |
856 | - | else throw("Strict value is not equal to itself.") | |
857 | - | } | |
858 | - | } | |
859 | - | } | |
860 | - | ||
861 | - | ||
862 | - | ||
863 | - | @Callable(i) | |
864 | - | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
865 | - | let r = commonGet(i) | |
866 | - | let outAmountAmount = r._1 | |
867 | - | let outPriceAmount = r._2 | |
868 | - | let paymentAmount = r._3 | |
869 | - | let paymentAssetId = r._4 | |
870 | - | let state = r._5 | |
871 | - | let checkOutAmountAmount = if ((outAmountAmount >= noLessThenAmtAsset)) | |
872 | - | then true | |
873 | - | else throwErr(((("Failed: " + toString(outAmountAmount)) + " < ") + toString(noLessThenAmtAsset))) | |
874 | - | if ((checkOutAmountAmount == checkOutAmountAmount)) | |
215 | + | func setAmp (amp) = { | |
216 | + | let checkCaller = mustAdmin(i) | |
217 | + | if ((checkCaller == checkCaller)) | |
875 | 218 | then { | |
876 | - | let checkOutPriceAmount = if ((outPriceAmount >= noLessThenPriceAsset)) | |
877 | - | then true | |
878 | - | else throwErr(((("Failed: " + toString(outPriceAmount)) + " < ") + toString(noLessThenPriceAsset))) | |
879 | - | if ((checkOutPriceAmount == checkOutPriceAmount)) | |
880 | - | then { | |
881 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
882 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
883 | - | then state | |
884 | - | else throw("Strict value is not equal to itself.") | |
885 | - | } | |
886 | - | else throw("Strict value is not equal to itself.") | |
219 | + | let res1 = invoke(poolContract, "setS", [keyAmp(), amp], nil) | |
220 | + | let res2 = invoke(poolContract, "setS", [keyAmpHistory(height), amp], nil) | |
221 | + | $Tuple2(nil, $Tuple2(res1, res2)) | |
887 | 222 | } | |
888 | 223 | else throw("Strict value is not equal to itself.") | |
889 | 224 | } | |
890 | 225 | ||
891 | 226 | ||
892 | - | ||
893 | - | @Callable(i) | |
894 | - | func unstakeAndGet (amount) = { | |
895 | - | let checkPayments = if ((size(i.payments) != 0)) | |
896 | - | then throwErr("no payments expected") | |
897 | - | else true | |
898 | - | if ((checkPayments == checkPayments)) | |
899 | - | then { | |
900 | - | let cfg = getPoolConfig() | |
901 | - | let factoryCfg = getFactoryConfig() | |
902 | - | let lpAssetId = fromBase58String(cfg[idxLPAsId]) | |
903 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "wrong") | |
904 | - | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
905 | - | if ((unstakeInv == unstakeInv)) | |
906 | - | then { | |
907 | - | let r = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
908 | - | let sts = parseIntValue(r._9) | |
909 | - | let state = r._10 | |
910 | - | let v = if (if (isGlobalShutdown()) | |
911 | - | then true | |
912 | - | else (sts == PoolShutdown)) | |
913 | - | then throwErr(("Blocked: " + toString(sts))) | |
914 | - | else true | |
915 | - | if ((v == v)) | |
916 | - | then { | |
917 | - | let burnA = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
918 | - | if ((burnA == burnA)) | |
919 | - | then state | |
920 | - | else throw("Strict value is not equal to itself.") | |
921 | - | } | |
922 | - | else throw("Strict value is not equal to itself.") | |
923 | - | } | |
924 | - | else throw("Strict value is not equal to itself.") | |
925 | - | } | |
926 | - | else throw("Strict value is not equal to itself.") | |
227 | + | @Verifier(tx) | |
228 | + | func verify () = { | |
229 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
230 | + | case pk: ByteVector => | |
231 | + | pk | |
232 | + | case _: Unit => | |
233 | + | tx.senderPublicKey | |
234 | + | case _ => | |
235 | + | throw("Match error") | |
927 | 236 | } | |
928 | - | ||
929 | - | ||
930 | - | ||
931 | - | @Callable(i) | |
932 | - | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(factoryContract))) | |
933 | - | then throwErr("denied") | |
934 | - | else $Tuple2([StringEntry(keyAmountAsset(), amtAsStr), StringEntry(keyPriceAsset(), prAsStr)], "success") | |
935 | - | ||
936 | - | ||
937 | - | ||
938 | - | @Callable(i) | |
939 | - | func setS (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
940 | - | then pd | |
941 | - | else [StringEntry(k, v)] | |
942 | - | ||
943 | - | ||
944 | - | ||
945 | - | @Callable(i) | |
946 | - | func setI (k,v) = if ((toString(i.caller) != getStringOrFail(this, keyAddonAddress()))) | |
947 | - | then pd | |
948 | - | else [IntegerEntry(k, v)] | |
949 | - | ||
950 | - | ||
951 | - | ||
952 | - | @Callable(i) | |
953 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
954 | - | ||
955 | - | ||
956 | - | ||
957 | - | @Callable(i) | |
958 | - | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
959 | - | ||
960 | - | ||
961 | - | ||
962 | - | @Callable(i) | |
963 | - | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
964 | - | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
965 | - | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
237 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
966 | 238 | } | |
967 | - | ||
968 | - | ||
969 | - | ||
970 | - | @Callable(i) | |
971 | - | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resScaleMult)) | |
972 | - | ||
973 | - | ||
974 | - | ||
975 | - | @Callable(i) | |
976 | - | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
977 | - | ||
978 | - | ||
979 | - | ||
980 | - | @Callable(i) | |
981 | - | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
982 | - | ||
983 | - | ||
984 | - | ||
985 | - | @Callable(i) | |
986 | - | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmountAssetAmount,inAmId,inPriceAssetAmount,inPrId,usrAddr,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippage, inAmountAssetAmount, inAmId, inPriceAssetAmount, inPrId, usrAddr, isEvaluate, emitLp, false, 0, "")) | |
987 | - | ||
988 | - | ||
989 | - | ||
990 | - | @Callable(i) | |
991 | - | func estimateGetOperationWrapperREADONLY (txId58,paymentAsId,paymentLpAmount,usrAddr) = { | |
992 | - | let r = estimateGetOperation(txId58, paymentAsId, paymentLpAmount, addressFromStringValue(usrAddr)) | |
993 | - | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
994 | - | } | |
995 | - | ||
996 | - | ||
997 | - | @Verifier(tx) | |
998 | - | func verify () = match tx { | |
999 | - | case order: Order => | |
1000 | - | let mtchPub = getMatcherPubOrFail() | |
1001 | - | let orV = validateMatcherOrderAllowed(order) | |
1002 | - | let sndrV = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1003 | - | let mtchV = sigVerify(order.bodyBytes, order.proofs[1], mtchPub) | |
1004 | - | if (if (if (orV) | |
1005 | - | then sndrV | |
1006 | - | else false) | |
1007 | - | then mtchV | |
1008 | - | else false) | |
1009 | - | then true | |
1010 | - | else throwOrderError(orV, sndrV, mtchV) | |
1011 | - | case _ => | |
1012 | - | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1013 | - | case pk: ByteVector => | |
1014 | - | pk | |
1015 | - | case _: Unit => | |
1016 | - | tx.senderPublicKey | |
1017 | - | case _ => | |
1018 | - | throw("Match error") | |
1019 | - | } | |
1020 | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1021 | - | } | |
1022 | 239 |
github/deemru/w8io/026f985 76.03 ms ◑