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