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