tx · 5h79haBY3wNJ973QYPMQwMwxpW97sPrBLXD1oYZcUaUv 3MtP3m8hWMxYcyDxXB6n299KrsLLyT8ehni: -0.03700000 Waves 2023.01.10 11:57 [2398631] smart account 3MtP3m8hWMxYcyDxXB6n299KrsLLyT8ehni > SELF 0.00000000 Waves
{ "type": 13, "id": "5h79haBY3wNJ973QYPMQwMwxpW97sPrBLXD1oYZcUaUv", "fee": 3700000, "feeAssetId": null, "timestamp": 1673341087846, "version": 1, "sender": "3MtP3m8hWMxYcyDxXB6n299KrsLLyT8ehni", "senderPublicKey": "BRyVaCURUMe7ssUbXucteig1g44bGwWirJQzugKahUQ1", "proofs": [ "3fW6VPx75cVdZP4RAFHPJ1D96NiHQYD8Do85ug3keZ1QGuvEuZojvN2EakV8QYPCrWZo928KMmGWDbRzogKgmd8M" ], "script": "base64:BgKoKQgCEgMKAQgSAwoBCBIAEgQKAgEEEgQKAgEEEgMKAQESABIECgIIARIAEgQKAggBEgQKAggBEgQKAgEBEgMKAQESBQoDAQEBEgUKAwEIARIECgIBCBIECgIBCBIECgIICBIECgIICBIECgIIARIAEgMKAQgSBQoDAQEBEgQKAggBEgQKAgEBEgQKAggIEgsKCQgBAQIBAggEBBIGCgQICAEIIgZzY2FsZTgiDHNjYWxlOEJpZ0ludCIHc2NhbGUxOCIKemVyb0JpZ0ludCIEYmlnMCIEYmlnMSIEYmlnMiIEYmlnMyIEYmlnNCIKc2xpcHBhZ2U0RCILd2F2ZXNTdHJpbmciBUFtdWx0IgVEY29udiIDU0VQIgVFTVBUWSIKUG9vbEFjdGl2ZSIKUG9vbFB1dERpcyIOUG9vbE1hdGNoZXJEaXMiDFBvb2xTaHV0ZG93biIOaWR4UG9vbEFkZHJlc3MiCWlkeFBvb2xTdCIJaWR4TFBBc0lkIglpZHhBbUFzSWQiCWlkeFByQXNJZCILaWR4QW10QXNEY20iDWlkeFByaWNlQXNEY20iC2lkeElBbXRBc0lkIg1pZHhJUHJpY2VBc0lkIg9pZHhGYWN0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hUCQD0AwMIBQJoUglib2R5Qnl0ZXMJAJEDAggFAmhSBnByb29mcwAABQJoVFgbN7s=", "chainId": 84, "height": 2398631, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: CoCTt5kDzrUWysarKp24YqEkt2YJXCRbiGasyrEeMeS1 Next: 8pUe4G6CMft4BcS29qBkRwiyCnpsmixyf6P1cZGAWEJD Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let lPdecimals = 8 | |
5 | - | ||
6 | 4 | let scale8 = 100000000 | |
7 | 5 | ||
8 | 6 | let scale8BigInt = toBigInt(100000000) | |
11 | 9 | ||
12 | 10 | let zeroBigInt = toBigInt(0) | |
13 | 11 | ||
12 | + | let big0 = toBigInt(0) | |
13 | + | ||
14 | + | let big1 = toBigInt(1) | |
15 | + | ||
16 | + | let big2 = toBigInt(2) | |
17 | + | ||
18 | + | let big3 = toBigInt(3) | |
19 | + | ||
20 | + | let big4 = toBigInt(4) | |
21 | + | ||
22 | + | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
23 | + | ||
24 | + | let wavesString = "WAVES" | |
25 | + | ||
26 | + | let Amult = "100" | |
27 | + | ||
28 | + | let Dconv = "1" | |
29 | + | ||
14 | 30 | let SEP = "__" | |
15 | 31 | ||
16 | 32 | let EMPTY = "" | |
17 | 33 | ||
18 | 34 | let PoolActive = 1 | |
19 | 35 | ||
20 | - | let | |
36 | + | let PoolPutDis = 2 | |
21 | 37 | ||
22 | - | let | |
38 | + | let PoolMatcherDis = 3 | |
23 | 39 | ||
24 | 40 | let PoolShutdown = 4 | |
25 | 41 | ||
26 | 42 | let idxPoolAddress = 1 | |
27 | 43 | ||
28 | - | let | |
44 | + | let idxPoolSt = 2 | |
29 | 45 | ||
30 | - | let | |
46 | + | let idxLPAsId = 3 | |
31 | 47 | ||
32 | - | let | |
48 | + | let idxAmAsId = 4 | |
33 | 49 | ||
34 | - | let | |
50 | + | let idxPrAsId = 5 | |
35 | 51 | ||
36 | - | let | |
52 | + | let idxAmtAsDcm = 6 | |
37 | 53 | ||
38 | - | let | |
54 | + | let idxPriceAsDcm = 7 | |
39 | 55 | ||
40 | - | let | |
56 | + | let idxIAmtAsId = 8 | |
41 | 57 | ||
42 | - | let | |
58 | + | let idxIPriceAsId = 9 | |
43 | 59 | ||
44 | - | let | |
60 | + | let idxFactStakCntr = 1 | |
45 | 61 | ||
46 | - | let | |
62 | + | let idxFactoryRestCntr = 6 | |
47 | 63 | ||
48 | - | let | |
64 | + | let idxFactSlippCntr = 7 | |
49 | 65 | ||
50 | - | let | |
66 | + | let idxFactGwxRewCntr = 10 | |
51 | 67 | ||
52 | - | let | |
68 | + | let feeDefault = fraction(10, scale8, 10000) | |
53 | 69 | ||
54 | - | let idxFactorySlippageContract = 7 | |
55 | - | ||
56 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
70 | + | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
57 | 71 | ||
58 | 72 | ||
59 | - | func | |
73 | + | func f1 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
60 | 74 | ||
61 | 75 | ||
62 | - | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
76 | + | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
77 | + | ||
78 | + | ||
79 | + | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
63 | 80 | ||
64 | 81 | ||
65 | 82 | func abs (val) = if ((zeroBigInt > val)) | |
67 | 84 | else val | |
68 | 85 | ||
69 | 86 | ||
70 | - | func keyFactoryContract () = "%s__factoryContract" | |
87 | + | func absBigInt (val) = if ((zeroBigInt > val)) | |
88 | + | then -(val) | |
89 | + | else val | |
71 | 90 | ||
72 | 91 | ||
73 | - | func | |
92 | + | func fc () = "%s__factoryContract" | |
74 | 93 | ||
75 | 94 | ||
76 | - | func | |
95 | + | func mpk () = "%s__managerPublicKey" | |
77 | 96 | ||
78 | 97 | ||
79 | - | func | |
98 | + | func pmpk () = "%s__pendingManagerPublicKey" | |
80 | 99 | ||
81 | 100 | ||
82 | - | func | |
101 | + | func pl () = "%s%s__price__last" | |
83 | 102 | ||
84 | 103 | ||
85 | - | func | |
104 | + | func ph (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
86 | 105 | ||
87 | 106 | ||
88 | - | func | |
107 | + | func pau (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
89 | 108 | ||
90 | 109 | ||
91 | - | func | |
110 | + | func gau (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
92 | 111 | ||
93 | 112 | ||
94 | - | func | |
113 | + | func aa () = "%s__amountAsset" | |
95 | 114 | ||
96 | 115 | ||
97 | - | func | |
116 | + | func pa () = "%s__priceAsset" | |
98 | 117 | ||
99 | 118 | ||
100 | - | func | |
119 | + | func amp () = "%s__amp" | |
101 | 120 | ||
102 | 121 | ||
103 | - | func | |
122 | + | func ada () = "%s__addonAddr" | |
104 | 123 | ||
105 | 124 | ||
106 | - | func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config") | |
125 | + | let keyFee = "%s__fee" | |
126 | + | ||
127 | + | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
128 | + | ||
129 | + | let keyDLp = makeString(["%s", "dLp"], SEP) | |
130 | + | ||
131 | + | let keyDLpRefreshedHeight = makeString(["%s", "dLpRefreshedHeight"], SEP) | |
132 | + | ||
133 | + | let keyDLpRefreshDelay = makeString(["%s", "refreshDLpDelay"], SEP) | |
134 | + | ||
135 | + | let dLpRefreshDelayDefault = 1 | |
136 | + | ||
137 | + | let dLpRefreshDelay = valueOrElse(getInteger(this, keyDLpRefreshDelay), dLpRefreshDelayDefault) | |
138 | + | ||
139 | + | func fcfg () = "%s__factoryConfig" | |
107 | 140 | ||
108 | 141 | ||
109 | - | func | |
142 | + | func mtpk () = "%s%s__matcher__publicKey" | |
110 | 143 | ||
111 | 144 | ||
112 | - | func | |
145 | + | func pc (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
113 | 146 | ||
114 | 147 | ||
115 | - | func | |
148 | + | func mba (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
116 | 149 | ||
117 | 150 | ||
118 | - | func | |
151 | + | func aps () = "%s__shutdown" | |
119 | 152 | ||
120 | 153 | ||
121 | - | func | |
154 | + | func keyAllowedLpStableScriptHash () = "%s__allowedLpStableScriptHash" | |
122 | 155 | ||
123 | 156 | ||
124 | - | func | |
157 | + | func keyFeeCollectorAddress () = "%s__feeCollectorAddress" | |
125 | 158 | ||
126 | 159 | ||
127 | - | let factoryContract = addressFromStringValue(getStringOrFail(this, keyFactoryContract())) | |
128 | - | ||
129 | - | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
160 | + | func toe (orV,sendrV,matchV) = throw(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
130 | 161 | ||
131 | 162 | ||
132 | - | func | |
163 | + | func strf (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
133 | 164 | ||
134 | 165 | ||
135 | - | func getPoolConfig () = { | |
136 | - | let amtAsset = getStringOrFail(this, keyAmtAsset()) | |
137 | - | let priceAsset = getStringOrFail(this, keyPriceAsset()) | |
138 | - | let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset)) | |
139 | - | let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset)) | |
140 | - | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP) | |
166 | + | func intf (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
167 | + | ||
168 | + | ||
169 | + | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
170 | + | ||
171 | + | ||
172 | + | func fmtErr (msg) = makeString(["lp_stable.ride:", msg], " ") | |
173 | + | ||
174 | + | ||
175 | + | let fca = addressFromStringValue(strf(this, fc())) | |
176 | + | ||
177 | + | let inFee = { | |
178 | + | let @ = invoke(fca, "getInFeeREADONLY", [toString(this)], nil) | |
179 | + | if ($isInstanceOf(@, "Int")) | |
180 | + | then @ | |
181 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
182 | + | } | |
183 | + | ||
184 | + | let outFee = { | |
185 | + | let @ = invoke(fca, "getOutFeeREADONLY", [toString(this)], nil) | |
186 | + | if ($isInstanceOf(@, "Int")) | |
187 | + | then @ | |
188 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
189 | + | } | |
190 | + | ||
191 | + | let A = strf(this, amp()) | |
192 | + | ||
193 | + | func igs () = valueOrElse(getBoolean(fca, aps()), false) | |
194 | + | ||
195 | + | ||
196 | + | func mp () = fromBase58String(strf(fca, mtpk())) | |
197 | + | ||
198 | + | ||
199 | + | let feeCollectorAddress = addressFromStringValue(strf(fca, keyFeeCollectorAddress())) | |
200 | + | ||
201 | + | func gpc () = { | |
202 | + | let amtAs = strf(this, aa()) | |
203 | + | let priceAs = strf(this, pa()) | |
204 | + | let iPriceAs = intf(fca, mba(priceAs)) | |
205 | + | let iAmtAs = intf(fca, mba(amtAs)) | |
206 | + | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
141 | 207 | } | |
142 | 208 | ||
143 | 209 | ||
144 | - | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
210 | + | func parseAssetId (input) = if ((input == wavesString)) | |
211 | + | then unit | |
212 | + | else fromBase58String(input) | |
145 | 213 | ||
146 | 214 | ||
147 | - | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slippageTolerancePassedByUser,slippageToleranceReal,txHeight,txTimestamp,slipageAmtAssetAmt,slipagePriceAssetAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slippageTolerancePassedByUser), toString(slippageToleranceReal), toString(txHeight), toString(txTimestamp), toString(slipageAmtAssetAmt), toString(slipagePriceAssetAmt)], SEP) | |
215 | + | func assetIdToString (input) = if ((input == unit)) | |
216 | + | then wavesString | |
217 | + | else toBase58String(value(input)) | |
218 | + | ||
219 | + | ||
220 | + | func parsePoolConfig (poolConfig) = $Tuple9(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolSt]), fromBase58String(poolConfig[idxLPAsId]), parseAssetId(poolConfig[idxAmAsId]), parseAssetId(poolConfig[idxPrAsId]), parseIntValue(poolConfig[idxAmtAsDcm]), parseIntValue(poolConfig[idxPriceAsDcm]), fromBase58String(poolConfig[idxIAmtAsId]), fromBase58String(poolConfig[idxIPriceAsId])) | |
221 | + | ||
222 | + | ||
223 | + | let poolConfigParsed = parsePoolConfig(gpc()) | |
224 | + | ||
225 | + | let $t075447773 = poolConfigParsed | |
226 | + | ||
227 | + | let cfgPoolAddress = $t075447773._1 | |
228 | + | ||
229 | + | let cfgPoolStatus = $t075447773._2 | |
230 | + | ||
231 | + | let cfgLpAssetId = $t075447773._3 | |
232 | + | ||
233 | + | let cfgAmountAssetId = $t075447773._4 | |
234 | + | ||
235 | + | let cfgPriceAssetId = $t075447773._5 | |
236 | + | ||
237 | + | let cfgAmountAssetDecimals = $t075447773._6 | |
238 | + | ||
239 | + | let cfgPriceAssetDecimals = $t075447773._7 | |
240 | + | ||
241 | + | let cfgInAmountAssedId = $t075447773._8 | |
242 | + | ||
243 | + | let cfgInPriceAssetId = $t075447773._9 | |
244 | + | ||
245 | + | func gfc () = split(strf(fca, fcfg()), SEP) | |
246 | + | ||
247 | + | ||
248 | + | let factoryConfig = gfc() | |
249 | + | ||
250 | + | let stakingContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactStakCntr]), "Invalid staking contract address") | |
251 | + | ||
252 | + | let slipageContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactSlippCntr]), "Invalid slipage contract address") | |
253 | + | ||
254 | + | let gwxContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactGwxRewCntr]), "Invalid gwx contract address") | |
255 | + | ||
256 | + | let restContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactoryRestCntr]), "Invalid gwx contract address") | |
257 | + | ||
258 | + | 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) | |
148 | 259 | ||
149 | 260 | ||
150 | 261 | 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) | |
155 | 266 | else assetBalance(this, fromBase58String(assetId)) | |
156 | 267 | ||
157 | 268 | ||
158 | - | func | |
269 | + | func cpbi (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
159 | 270 | ||
160 | 271 | ||
161 | - | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
162 | - | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
163 | - | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
164 | - | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
272 | + | func cpbir (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
273 | + | ||
274 | + | ||
275 | + | func vad (A1,A2,slippage) = { | |
276 | + | let diff = fraction((A1 - A2), scale8BigInt, A2) | |
277 | + | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
278 | + | if (!(pass)) | |
279 | + | then throw(("Big slpg: " + toString(diff))) | |
280 | + | else $Tuple2(pass, min([A1, A2])) | |
281 | + | } | |
282 | + | ||
283 | + | ||
284 | + | func vd (D1,D0,slpg) = { | |
285 | + | let diff = fraction(D0, scale8BigInt, D1) | |
286 | + | let fail = (slpg > diff) | |
287 | + | if (if (fail) | |
288 | + | then true | |
289 | + | else (D0 > D1)) | |
290 | + | then throw(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slpg))) | |
291 | + | else fail | |
292 | + | } | |
293 | + | ||
294 | + | ||
295 | + | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
296 | + | let amtAsAmtX18 = t1(amAmt, amAssetDcm) | |
297 | + | let prAsAmtX18 = t1(prAmt, prAssetDcm) | |
298 | + | cpbi(prAsAmtX18, amtAsAmtX18) | |
165 | 299 | } | |
166 | 300 | ||
167 | 301 | ||
168 | 302 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
169 | - | let cfg = getPoolConfig() | |
170 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
171 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
172 | - | let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt) | |
173 | - | let amAmtX18 = toX18(amAmt, amtAssetDcm) | |
174 | - | let prAmtX18 = toX18(prAmt, priceAssetDcm) | |
175 | - | let lpAmtX18 = toX18(lpAmt, scale8) | |
176 | - | let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
177 | - | let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
178 | - | [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18] | |
303 | + | let amtAsDcm = cfgAmountAssetDecimals | |
304 | + | let prAsDcm = cfgPriceAssetDecimals | |
305 | + | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
306 | + | let amAmtX18 = t1(amAmt, amtAsDcm) | |
307 | + | let prAmtX18 = t1(prAmt, prAsDcm) | |
308 | + | let lpAmtX18 = t1(lpAmt, scale8) | |
309 | + | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) | |
310 | + | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) | |
311 | + | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
179 | 312 | } | |
180 | 313 | ||
181 | 314 | ||
182 | 315 | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
183 | - | let | |
184 | - | [ | |
316 | + | let p = calcPrices(amAmt, prAmt, lpAmt) | |
317 | + | [f1(p[0], scale8), f1(p[1], scale8), f1(p[2], scale8)] | |
185 | 318 | } | |
186 | 319 | ||
187 | 320 | ||
188 | - | func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
189 | - | let cfg = getPoolConfig() | |
190 | - | let lpAssetId = cfg[idxPoolLPAssetId] | |
191 | - | let amAssetId = cfg[idxAmtAssetId] | |
192 | - | let prAssetId = cfg[idxPriceAssetId] | |
193 | - | let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
194 | - | let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
195 | - | let poolStatus = cfg[idxPoolStatus] | |
196 | - | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity | |
197 | - | if ((lpAssetId != pmtAssetId)) | |
198 | - | then throw("Invalid asset passed.") | |
321 | + | func takeFee (amount,fee) = { | |
322 | + | let feeAmount = if ((fee == 0)) | |
323 | + | then 0 | |
324 | + | else fraction(amount, fee, scale8) | |
325 | + | $Tuple2((amount - feeAmount), feeAmount) | |
326 | + | } | |
327 | + | ||
328 | + | ||
329 | + | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
330 | + | let lpId = cfgLpAssetId | |
331 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
332 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
333 | + | let amDcm = cfgAmountAssetDecimals | |
334 | + | let prDcm = cfgPriceAssetDecimals | |
335 | + | let sts = toString(cfgPoolStatus) | |
336 | + | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
337 | + | if ((toBase58String(lpId) != pmtAssetId)) | |
338 | + | then throw("Wrong pmt asset") | |
199 | 339 | else { | |
200 | - | let amBalance = getAccBalance( | |
201 | - | let amBalanceX18 = | |
202 | - | let prBalance = getAccBalance( | |
203 | - | let prBalanceX18 = | |
204 | - | let curPriceX18 = | |
205 | - | let curPrice = | |
206 | - | let pmtLpAmtX18 = | |
207 | - | let | |
208 | - | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, | |
209 | - | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, | |
210 | - | let outAmAmt = | |
211 | - | let outPrAmt = | |
340 | + | let amBalance = getAccBalance(amId) | |
341 | + | let amBalanceX18 = t1(amBalance, amDcm) | |
342 | + | let prBalance = getAccBalance(prId) | |
343 | + | let prBalanceX18 = t1(prBalance, prDcm) | |
344 | + | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
345 | + | let curPrice = f1(curPriceX18, scale8) | |
346 | + | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) | |
347 | + | let lpEmissX18 = t1(lpEmiss, scale8) | |
348 | + | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
349 | + | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
350 | + | let outAmAmt = fromX18Round(outAmAmtX18, amDcm, FLOOR) | |
351 | + | let outPrAmt = fromX18Round(outPrAmtX18, prDcm, FLOOR) | |
212 | 352 | let state = if ((txId58 == "")) | |
213 | 353 | then nil | |
214 | - | else [ScriptTransfer(userAddress, outAmAmt, if (( | |
354 | + | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
215 | 355 | then unit | |
216 | - | else fromBase58String( | |
356 | + | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) | |
217 | 357 | then unit | |
218 | - | else fromBase58String( | |
219 | - | $Tuple10(outAmAmt, outPrAmt, | |
358 | + | else fromBase58String(prId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
359 | + | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) | |
220 | 360 | } | |
221 | 361 | } | |
222 | 362 | ||
223 | 363 | ||
224 | - | func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = { | |
225 | - | let cfg = getPoolConfig() | |
226 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
227 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
228 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
229 | - | let iAmtAssetId = cfg[idxIAmtAssetId] | |
230 | - | let iPriceAssetId = cfg[idxIPriceAssetId] | |
231 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
232 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
233 | - | let poolStatus = cfg[idxPoolStatus] | |
234 | - | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
235 | - | let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES"))) | |
236 | - | let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES"))) | |
237 | - | if (if ((amAssetIdStr != inAmAssetIdStr)) | |
238 | - | then true | |
239 | - | else (prAssetIdStr != inPrAssetIdStr)) | |
240 | - | then throw("Invalid amt or price asset passed.") | |
364 | + | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
365 | + | let lpId = cfgLpAssetId | |
366 | + | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
367 | + | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
368 | + | let inAmIdStr = cfgInAmountAssedId | |
369 | + | let inPrIdStr = cfgInPriceAssetId | |
370 | + | let amtDcm = cfgAmountAssetDecimals | |
371 | + | let priceDcm = cfgPriceAssetDecimals | |
372 | + | let sts = toString(cfgPoolStatus) | |
373 | + | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
374 | + | let amBalance = if (isEval) | |
375 | + | then getAccBalance(amIdStr) | |
376 | + | else if (if (isOneAsset) | |
377 | + | then (pmtId == amIdStr) | |
378 | + | else false) | |
379 | + | then (getAccBalance(amIdStr) - pmtAmt) | |
380 | + | else if (isOneAsset) | |
381 | + | then getAccBalance(amIdStr) | |
382 | + | else (getAccBalance(amIdStr) - inAmAmt) | |
383 | + | let prBalance = if (isEval) | |
384 | + | then getAccBalance(prIdStr) | |
385 | + | else if (if (isOneAsset) | |
386 | + | then (pmtId == prIdStr) | |
387 | + | else false) | |
388 | + | then (getAccBalance(prIdStr) - pmtAmt) | |
389 | + | else if (isOneAsset) | |
390 | + | then getAccBalance(prIdStr) | |
391 | + | else (getAccBalance(prIdStr) - inPrAmt) | |
392 | + | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) | |
393 | + | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) | |
394 | + | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
395 | + | let amBalanceX18 = t1(amBalance, amtDcm) | |
396 | + | let prBalanceX18 = t1(prBalance, priceDcm) | |
397 | + | let r = if ((lpEm == 0)) | |
398 | + | then { | |
399 | + | let curPriceX18 = zeroBigInt | |
400 | + | let slippageX18 = zeroBigInt | |
401 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
402 | + | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
403 | + | } | |
241 | 404 | else { | |
242 | - | let amBalance = if (isEvaluate) | |
243 | - | then getAccBalance(amAssetIdStr) | |
244 | - | else (getAccBalance(amAssetIdStr) - inAmAssetAmt) | |
245 | - | let prBalance = if (isEvaluate) | |
246 | - | then getAccBalance(prAssetIdStr) | |
247 | - | else (getAccBalance(prAssetIdStr) - inPrAssetAmt) | |
248 | - | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
249 | - | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
250 | - | let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18) | |
251 | - | let amBalanceX18 = toX18(amBalance, amtAssetDcm) | |
252 | - | let prBalanceX18 = toX18(prBalance, priceAssetDcm) | |
253 | - | let res = if ((lpEmission == 0)) | |
254 | - | then { | |
255 | - | let curPriceX18 = zeroBigInt | |
256 | - | let slippageX18 = zeroBigInt | |
257 | - | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
258 | - | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
405 | + | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
406 | + | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
407 | + | let slippageX18 = t1(slippage, scale8) | |
408 | + | if (if (if (validateSlippage) | |
409 | + | then (curPriceX18 != zeroBigInt) | |
410 | + | else false) | |
411 | + | then (slippageRealX18 > slippageX18) | |
412 | + | else false) | |
413 | + | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
414 | + | else { | |
415 | + | let lpEmissionX18 = t1(lpEm, scale8) | |
416 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, cpbir(prBalanceX18, amBalanceX18, FLOOR), scale18, FLOOR) | |
417 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, cpbir(prBalanceX18, amBalanceX18, FLOOR), FLOOR) | |
418 | + | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
419 | + | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
420 | + | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
421 | + | let expAmtAssetAmtX18 = expectedAmts._1 | |
422 | + | let expPriceAssetAmtX18 = expectedAmts._2 | |
423 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR) | |
424 | + | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
259 | 425 | } | |
260 | - | else { | |
261 | - | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
262 | - | let slippageX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
263 | - | let slippageToleranceX18 = toX18(slippageTolerance, scale8) | |
264 | - | if (if ((curPriceX18 != zeroBigInt)) | |
265 | - | then (slippageX18 > slippageToleranceX18) | |
266 | - | else false) | |
267 | - | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
268 | - | else { | |
269 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
270 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
271 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
272 | - | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
273 | - | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
274 | - | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
275 | - | let expAmtAssetAmtX18 = expectedAmts._1 | |
276 | - | let expPriceAssetAmtX18 = expectedAmts._2 | |
277 | - | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
278 | - | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18) | |
279 | - | } | |
280 | - | } | |
281 | - | let calcLpAmt = res._1 | |
282 | - | let calcAmAssetPmt = res._2 | |
283 | - | let calcPrAssetPmt = res._3 | |
284 | - | let curPrice = fromX18(res._4, scale8) | |
285 | - | let slippageCalc = fromX18(res._5, scale8) | |
286 | - | if ((0 >= calcLpAmt)) | |
287 | - | then throw("Invalid calculations. LP calculated is less than zero.") | |
288 | - | else { | |
289 | - | let emitLpAmt = if (!(emitLp)) | |
290 | - | then 0 | |
291 | - | else calcLpAmt | |
292 | - | let amDiff = (inAmAssetAmt - calcAmAssetPmt) | |
293 | - | let prDiff = (inPrAssetAmt - calcPrAssetPmt) | |
294 | - | let commonState = [IntegerEntry(keyPriceLast(), curPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(calcAmAssetPmt, calcPrAssetPmt, emitLpAmt, curPrice, slippageTolerance, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
295 | - | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId) | |
296 | - | } | |
426 | + | } | |
427 | + | let calcLpAmt = r._1 | |
428 | + | let calcAmAssetPmt = r._2 | |
429 | + | let calcPrAssetPmt = r._3 | |
430 | + | let curPrice = f1(r._4, scale8) | |
431 | + | let slippageCalc = f1(r._5, scale8) | |
432 | + | if ((0 >= calcLpAmt)) | |
433 | + | then throw("LP <= 0") | |
434 | + | else { | |
435 | + | let emitLpAmt = if (!(emitLp)) | |
436 | + | then 0 | |
437 | + | else calcLpAmt | |
438 | + | let amDiff = (inAmAmt - calcAmAssetPmt) | |
439 | + | let prDiff = (inPrAmt - calcPrAssetPmt) | |
440 | + | let $t01841718762 = if (if (isOneAsset) | |
441 | + | then (pmtId == amIdStr) | |
442 | + | else false) | |
443 | + | then $Tuple2(pmtAmt, 0) | |
444 | + | else if (if (isOneAsset) | |
445 | + | then (pmtId == prIdStr) | |
446 | + | else false) | |
447 | + | then $Tuple2(0, pmtAmt) | |
448 | + | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
449 | + | let writeAmAmt = $t01841718762._1 | |
450 | + | let writePrAmt = $t01841718762._2 | |
451 | + | 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))] | |
452 | + | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
297 | 453 | } | |
298 | 454 | } | |
299 | 455 | ||
300 | 456 | ||
301 | - | func validateMatcherOrderAllowed (order) = { | |
302 | - | let cfg = getPoolConfig() | |
303 | - | let amtAssetId = cfg[idxAmtAssetId] | |
304 | - | let priceAssetId = cfg[idxPriceAssetId] | |
305 | - | let poolStatus = parseIntValue(cfg[idxPoolStatus]) | |
306 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
307 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
308 | - | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
309 | - | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
310 | - | let curPriceX18 = if ((order.orderType == Buy)) | |
311 | - | then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance) | |
312 | - | else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance) | |
313 | - | let curPrice = fromX18(curPriceX18, scale8) | |
314 | - | if (if (if (isGlobalShutdown()) | |
315 | - | then true | |
316 | - | else (poolStatus == PoolMatcherDisabled)) | |
317 | - | then true | |
318 | - | else (poolStatus == PoolShutdown)) | |
319 | - | then throw("Exchange operations disabled") | |
457 | + | func getD (xp) = { | |
458 | + | let xp0 = xp[0] | |
459 | + | let xp1 = xp[1] | |
460 | + | let s = (xp0 + xp1) | |
461 | + | if ((s == big0)) | |
462 | + | then big0 | |
320 | 463 | else { | |
321 | - | let orderAmtAsset = order.assetPair.amountAsset | |
322 | - | let orderAmtAssetStr = if ((orderAmtAsset == unit)) | |
323 | - | then "WAVES" | |
324 | - | else toBase58String(value(orderAmtAsset)) | |
325 | - | let orderPriceAsset = order.assetPair.priceAsset | |
326 | - | let orderPriceAssetStr = if ((orderPriceAsset == unit)) | |
327 | - | then "WAVES" | |
328 | - | else toBase58String(value(orderPriceAsset)) | |
329 | - | if (if ((orderAmtAssetStr != amtAssetId)) | |
330 | - | then true | |
331 | - | else (orderPriceAssetStr != priceAssetId)) | |
332 | - | then throw("Wrong order assets.") | |
464 | + | let a = parseIntValue(A) | |
465 | + | let ann = (a * 2) | |
466 | + | let p = fraction(xp0, xp1, big1) | |
467 | + | let xp0_xp1_n_n = fraction(p, big4, big1) | |
468 | + | let ann_s = fraction(toBigInt(ann), s, big1) | |
469 | + | let ann_1 = toBigInt((ann - 1)) | |
470 | + | func calcDNext (d) = { | |
471 | + | let dd = fraction(d, d, big1) | |
472 | + | let ddd = fraction(dd, d, big1) | |
473 | + | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
474 | + | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1)), CEILING) | |
475 | + | } | |
476 | + | ||
477 | + | func calc (acc,i) = if (acc._2) | |
478 | + | then acc | |
333 | 479 | else { | |
334 | - | let orderPrice = order.price | |
335 | - | let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm) | |
336 | - | let castedOrderPrice = toScale(orderPrice, scale8, priceDcm) | |
337 | - | let isOrderPriceValid = if ((order.orderType == Buy)) | |
338 | - | then (curPrice >= castedOrderPrice) | |
339 | - | else (castedOrderPrice >= curPrice) | |
340 | - | true | |
480 | + | let d = acc._1 | |
481 | + | let dNext = calcDNext(d) | |
482 | + | let dDiffRaw = toInt((dNext - value(d))) | |
483 | + | let dDiff = if ((0 > dDiffRaw)) | |
484 | + | then -(dDiffRaw) | |
485 | + | else dDiffRaw | |
486 | + | if ((1 >= dDiff)) | |
487 | + | then $Tuple2(dNext, true) | |
488 | + | else $Tuple2(dNext, false) | |
341 | 489 | } | |
490 | + | ||
491 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
492 | + | let $t02069020738 = { | |
493 | + | let $l = arr | |
494 | + | let $s = size($l) | |
495 | + | let $acc0 = $Tuple2(s, false) | |
496 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
497 | + | then $a | |
498 | + | else calc($a, $l[$i]) | |
499 | + | ||
500 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
501 | + | then $a | |
502 | + | else throw("List size exceeds 15") | |
503 | + | ||
504 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
505 | + | } | |
506 | + | let d = $t02069020738._1 | |
507 | + | let found = $t02069020738._2 | |
508 | + | if (found) | |
509 | + | then d | |
510 | + | else throw(("D calculation error, D = " + toString(d))) | |
342 | 511 | } | |
343 | 512 | } | |
344 | 513 | ||
345 | 514 | ||
346 | - | func commonGet (i) = if ((size(i.payments) != 1)) | |
347 | - | then throw("exactly 1 payment is expected") | |
515 | + | func getDOld (xp) = { | |
516 | + | let n = big2 | |
517 | + | let xp0 = xp[0] | |
518 | + | let xp1 = xp[1] | |
519 | + | let aPrecision = parseBigIntValue(Amult) | |
520 | + | let a = (parseBigIntValue(A) * aPrecision) | |
521 | + | let s = (xp0 + xp1) | |
522 | + | if ((s == big0)) | |
523 | + | then big0 | |
524 | + | else { | |
525 | + | let ann = (a * n) | |
526 | + | let xp0_xp1_n_n = (((xp0 * xp1) * n) * n) | |
527 | + | let ann_s_aPrecision = ((ann * s) / aPrecision) | |
528 | + | let ann_aPrecision = (ann - aPrecision) | |
529 | + | let n1 = (n + big1) | |
530 | + | func calc (acc,cur) = { | |
531 | + | let $t02136721387 = acc | |
532 | + | let d = $t02136721387._1 | |
533 | + | let found = $t02136721387._2 | |
534 | + | if ((found != unit)) | |
535 | + | then acc | |
536 | + | else { | |
537 | + | let dp = (((d * d) * d) / xp0_xp1_n_n) | |
538 | + | let dNext = (((ann_s_aPrecision + (dp * n)) * d) / (((ann_aPrecision * d) / aPrecision) + (n1 * dp))) | |
539 | + | let dDiff = absBigInt((dNext - value(d))) | |
540 | + | if ((big1 >= dDiff)) | |
541 | + | then $Tuple2(dNext, cur) | |
542 | + | else $Tuple2(dNext, unit) | |
543 | + | } | |
544 | + | } | |
545 | + | ||
546 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
547 | + | let $t02180821855 = { | |
548 | + | let $l = arr | |
549 | + | let $s = size($l) | |
550 | + | let $acc0 = $Tuple2(s, unit) | |
551 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
552 | + | then $a | |
553 | + | else calc($a, $l[$i]) | |
554 | + | ||
555 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
556 | + | then $a | |
557 | + | else throw("List size exceeds 15") | |
558 | + | ||
559 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
560 | + | } | |
561 | + | let d = $t02180821855._1 | |
562 | + | let found = $t02180821855._2 | |
563 | + | if ((found != unit)) | |
564 | + | then d | |
565 | + | else throw(("D calculation error, D = " + toString(d))) | |
566 | + | } | |
567 | + | } | |
568 | + | ||
569 | + | ||
570 | + | func getYD (xp,i,D) = { | |
571 | + | let n = big2 | |
572 | + | let x = xp[if ((i == 0)) | |
573 | + | then 1 | |
574 | + | else 0] | |
575 | + | let aPrecision = parseBigIntValue(Amult) | |
576 | + | let a = (parseBigIntValue(A) * aPrecision) | |
577 | + | let s = x | |
578 | + | let ann = (a * n) | |
579 | + | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
580 | + | let b = ((s + ((D * aPrecision) / ann)) - D) | |
581 | + | func calc (acc,cur) = { | |
582 | + | let $t02235522375 = acc | |
583 | + | let y = $t02235522375._1 | |
584 | + | let found = $t02235522375._2 | |
585 | + | if ((found != unit)) | |
586 | + | then acc | |
587 | + | else { | |
588 | + | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
589 | + | let yDiff = absBigInt((yNext - value(y))) | |
590 | + | if ((big1 >= yDiff)) | |
591 | + | then $Tuple2(yNext, cur) | |
592 | + | else $Tuple2(yNext, unit) | |
593 | + | } | |
594 | + | } | |
595 | + | ||
596 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
597 | + | let $t02268222729 = { | |
598 | + | let $l = arr | |
599 | + | let $s = size($l) | |
600 | + | let $acc0 = $Tuple2(D, unit) | |
601 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
602 | + | then $a | |
603 | + | else calc($a, $l[$i]) | |
604 | + | ||
605 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
606 | + | then $a | |
607 | + | else throw("List size exceeds 15") | |
608 | + | ||
609 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
610 | + | } | |
611 | + | let y = $t02268222729._1 | |
612 | + | let found = $t02268222729._2 | |
613 | + | if ((found != unit)) | |
614 | + | then y | |
615 | + | else throw(("Y calculation error, Y = " + toString(y))) | |
616 | + | } | |
617 | + | ||
618 | + | ||
619 | + | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
620 | + | let updatedDLp = fraction(getD([amountBalance, priceBalance]), scale18, lpEmission) | |
621 | + | if ((lpEmission == big0)) | |
622 | + | then big0 | |
623 | + | else updatedDLp | |
624 | + | } | |
625 | + | ||
626 | + | ||
627 | + | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
628 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
629 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
630 | + | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
631 | + | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
632 | + | currentDLp | |
633 | + | } | |
634 | + | ||
635 | + | ||
636 | + | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
637 | + | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
638 | + | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
639 | + | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
640 | + | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
641 | + | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
642 | + | $Tuple2(actions, updatedDLp) | |
643 | + | } | |
644 | + | ||
645 | + | ||
646 | + | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
647 | + | then true | |
648 | + | else throwErr("updated DLp lower than current DLp") | |
649 | + | ||
650 | + | ||
651 | + | func validateMatcherOrderAllowed (order) = { | |
652 | + | let amountAssetAmount = order.amount | |
653 | + | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
654 | + | let $t02466824880 = if ((order.orderType == Buy)) | |
655 | + | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
656 | + | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
657 | + | let amountAssetBalanceDelta = $t02466824880._1 | |
658 | + | let priceAssetBalanceDelta = $t02466824880._2 | |
659 | + | if (if (if (igs()) | |
660 | + | then true | |
661 | + | else (cfgPoolStatus == PoolMatcherDis)) | |
662 | + | then true | |
663 | + | else (cfgPoolStatus == PoolShutdown)) | |
664 | + | then throw("Admin blocked") | |
665 | + | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
666 | + | then true | |
667 | + | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
668 | + | then throw("Wr assets") | |
669 | + | else { | |
670 | + | let dLp = parseBigIntValue(getStringValue(this, keyDLp)) | |
671 | + | let $t02521025310 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
672 | + | let unusedActions = $t02521025310._1 | |
673 | + | let dLpNew = $t02521025310._2 | |
674 | + | let isOrderValid = (dLpNew >= dLp) | |
675 | + | isOrderValid | |
676 | + | } | |
677 | + | } | |
678 | + | ||
679 | + | ||
680 | + | func cg (i) = if ((size(i.payments) != 1)) | |
681 | + | then throw("1 pmnt exp") | |
348 | 682 | else { | |
349 | 683 | let pmt = value(i.payments[0]) | |
350 | 684 | let pmtAssetId = value(pmt.assetId) | |
351 | 685 | let pmtAmt = pmt.amount | |
352 | - | let | |
353 | - | let outAmAmt = | |
354 | - | let outPrAmt = | |
355 | - | let | |
356 | - | let state = | |
357 | - | if (if ( | |
686 | + | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
687 | + | let outAmAmt = r._1 | |
688 | + | let outPrAmt = r._2 | |
689 | + | let sts = parseIntValue(r._9) | |
690 | + | let state = r._10 | |
691 | + | if (if (igs()) | |
358 | 692 | then true | |
359 | - | else ( | |
360 | - | then throw((" | |
693 | + | else (sts == PoolShutdown)) | |
694 | + | then throw(("Admin blocked: " + toString(sts))) | |
361 | 695 | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
362 | 696 | } | |
363 | 697 | ||
364 | 698 | ||
365 | - | func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2)) | |
366 | - | then throw("exactly 2 payments are expected") | |
367 | - | else { | |
368 | - | let amAssetPmt = value(i.payments[0]) | |
369 | - | let prAssetPmt = value(i.payments[1]) | |
370 | - | let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp) | |
371 | - | let poolStatus = parseIntValue(estPut._8) | |
372 | - | if (if (if (isGlobalShutdown()) | |
699 | + | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
700 | + | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, (txId == ""), emitLp, isOneAsset, validateSlippage, pmtAmt, pmtId) | |
701 | + | let sts = parseIntValue(r._8) | |
702 | + | if (if (if (igs()) | |
703 | + | then true | |
704 | + | else (sts == PoolPutDis)) | |
705 | + | then true | |
706 | + | else (sts == PoolShutdown)) | |
707 | + | then throw(("Blocked:" + toString(sts))) | |
708 | + | else r | |
709 | + | } | |
710 | + | ||
711 | + | ||
712 | + | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
713 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
714 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
715 | + | let lpId = cfgLpAssetId | |
716 | + | let amtDcm = cfgAmountAssetDecimals | |
717 | + | let priceDcm = cfgPriceAssetDecimals | |
718 | + | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
719 | + | let chechEmission = if ((lpAssetEmission > big0)) | |
720 | + | then true | |
721 | + | else throw("initial deposit requires all coins") | |
722 | + | if ((chechEmission == chechEmission)) | |
723 | + | then { | |
724 | + | let amBalance = getAccBalance(amId) | |
725 | + | let prBalance = getAccBalance(prId) | |
726 | + | let $t02757628038 = if ((txId == "")) | |
727 | + | then $Tuple2(amBalance, prBalance) | |
728 | + | else if ((pmtAssetId == amId)) | |
729 | + | then if ((pmtAmtRaw > amBalance)) | |
730 | + | then throw("invalid payment amount") | |
731 | + | else $Tuple2((amBalance - pmtAmtRaw), prBalance) | |
732 | + | else if ((pmtAssetId == prId)) | |
733 | + | then if ((pmtAmtRaw > prBalance)) | |
734 | + | then throw("invalid payment amount") | |
735 | + | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
736 | + | else throw("wrong pmtAssetId") | |
737 | + | let amBalanceOld = $t02757628038._1 | |
738 | + | let prBalanceOld = $t02757628038._2 | |
739 | + | let $t02804428220 = if ((pmtAssetId == amId)) | |
740 | + | then $Tuple2(pmtAmtRaw, 0) | |
741 | + | else if ((pmtAssetId == prId)) | |
742 | + | then $Tuple2(0, pmtAmtRaw) | |
743 | + | else throw("invalid payment") | |
744 | + | let amAmountRaw = $t02804428220._1 | |
745 | + | let prAmountRaw = $t02804428220._2 | |
746 | + | let $t02822428478 = if (withTakeFee) | |
747 | + | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
748 | + | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
749 | + | let amAmount = $t02822428478._1 | |
750 | + | let prAmount = $t02822428478._2 | |
751 | + | let feeAmount = $t02822428478._3 | |
752 | + | let amBalanceNew = (amBalanceOld + amAmount) | |
753 | + | let prBalanceNew = (prBalanceOld + prAmount) | |
754 | + | let D0 = getD([toBigInt(amBalanceOld), toBigInt(prBalanceOld)]) | |
755 | + | let D1 = getD([toBigInt(amBalanceNew), toBigInt(prBalanceNew)]) | |
756 | + | let checkD = if ((D1 > D0)) | |
757 | + | then true | |
758 | + | else throw() | |
759 | + | if ((checkD == checkD)) | |
760 | + | then { | |
761 | + | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0, FLOOR) | |
762 | + | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
763 | + | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId), dataPutActionInfo(amAmountRaw, prAmountRaw, toInt(lpAmount), curPrice, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
764 | + | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
765 | + | let amountAssetPart = fraction(pmtAmtRaw, scale8, (poolProportion + scale8)) | |
766 | + | let priceAssetPart = (pmtAmtRaw - amountAssetPart) | |
767 | + | let lpAmtBoth = fraction(lpAssetEmission, toBigInt(priceAssetPart), toBigInt(prBalanceOld)) | |
768 | + | let bonus = toInt(fraction((lpAmount - lpAmtBoth), scale8BigInt, lpAmtBoth)) | |
769 | + | $Tuple4(toInt(lpAmount), commonState, feeAmount, bonus) | |
770 | + | } | |
771 | + | else throw("Strict value is not equal to itself.") | |
772 | + | } | |
773 | + | else throw("Strict value is not equal to itself.") | |
774 | + | } | |
775 | + | ||
776 | + | ||
777 | + | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
778 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
779 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
780 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
781 | + | let amDecimals = cfgAmountAssetDecimals | |
782 | + | let prDecimals = cfgPriceAssetDecimals | |
783 | + | let poolStatus = cfgPoolStatus | |
784 | + | let userAddress = if ((caller == restContract)) | |
785 | + | then originCaller | |
786 | + | else caller | |
787 | + | let pmt = value(payments[0]) | |
788 | + | let pmtAssetId = value(pmt.assetId) | |
789 | + | let pmtAmt = pmt.amount | |
790 | + | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
791 | + | if ((currentDLp == currentDLp)) | |
792 | + | then { | |
793 | + | let txId58 = toBase58String(transactionId) | |
794 | + | if ((lpId != toBase58String(pmtAssetId))) | |
795 | + | then throw("Wrong LP") | |
796 | + | else { | |
797 | + | let amBalance = getAccBalance(amId) | |
798 | + | let prBalance = getAccBalance(prId) | |
799 | + | let $t03052830639 = { | |
800 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
801 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
802 | + | then @ | |
803 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
804 | + | } | |
805 | + | if (($t03052830639 == $t03052830639)) | |
806 | + | then { | |
807 | + | let feeAmount = $t03052830639._2 | |
808 | + | let totalGet = $t03052830639._1 | |
809 | + | let totalAmount = if (if ((minOutAmount > 0)) | |
810 | + | then (minOutAmount > totalGet) | |
811 | + | else false) | |
812 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
813 | + | else totalGet | |
814 | + | let $t03082931136 = if ((outAssetId == amId)) | |
815 | + | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
816 | + | else if ((outAssetId == prId)) | |
817 | + | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
818 | + | else throw("invalid out asset id") | |
819 | + | let outAm = $t03082931136._1 | |
820 | + | let outPr = $t03082931136._2 | |
821 | + | let amBalanceNew = $t03082931136._3 | |
822 | + | let prBalanceNew = $t03082931136._4 | |
823 | + | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
824 | + | let curPr = f1(curPrX18, scale8) | |
825 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
826 | + | then unit | |
827 | + | else fromBase58String(outAssetId) | |
828 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
829 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
830 | + | else nil | |
831 | + | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
832 | + | if ((state == state)) | |
833 | + | then { | |
834 | + | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
835 | + | if ((burn == burn)) | |
836 | + | then { | |
837 | + | let $t03192132271 = { | |
838 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
839 | + | then 0 | |
840 | + | else feeAmount | |
841 | + | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
842 | + | then true | |
843 | + | else false | |
844 | + | if (outInAmountAsset) | |
845 | + | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
846 | + | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
847 | + | } | |
848 | + | let amountAssetBalanceDelta = $t03192132271._1 | |
849 | + | let priceAssetBalanceDelta = $t03192132271._2 | |
850 | + | let $t03227432382 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
851 | + | let refreshDLpActions = $t03227432382._1 | |
852 | + | let updatedDLp = $t03227432382._2 | |
853 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
854 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
855 | + | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
856 | + | else throw("Strict value is not equal to itself.") | |
857 | + | } | |
858 | + | else throw("Strict value is not equal to itself.") | |
859 | + | } | |
860 | + | else throw("Strict value is not equal to itself.") | |
861 | + | } | |
862 | + | else throw("Strict value is not equal to itself.") | |
863 | + | } | |
864 | + | } | |
865 | + | else throw("Strict value is not equal to itself.") | |
866 | + | } | |
867 | + | ||
868 | + | ||
869 | + | func m () = match getString(mpk()) { | |
870 | + | case s: String => | |
871 | + | fromBase58String(s) | |
872 | + | case _: Unit => | |
873 | + | unit | |
874 | + | case _ => | |
875 | + | throw("Match error") | |
876 | + | } | |
877 | + | ||
878 | + | ||
879 | + | func pm () = match getString(pmpk()) { | |
880 | + | case s: String => | |
881 | + | fromBase58String(s) | |
882 | + | case _: Unit => | |
883 | + | unit | |
884 | + | case _ => | |
885 | + | throw("Match error") | |
886 | + | } | |
887 | + | ||
888 | + | ||
889 | + | let pd = throw("Permission denied") | |
890 | + | ||
891 | + | func isManager (i) = match m() { | |
892 | + | case pk: ByteVector => | |
893 | + | (i.callerPublicKey == pk) | |
894 | + | case _: Unit => | |
895 | + | (i.caller == this) | |
896 | + | case _ => | |
897 | + | throw("Match error") | |
898 | + | } | |
899 | + | ||
900 | + | ||
901 | + | func mm (i) = match m() { | |
902 | + | case pk: ByteVector => | |
903 | + | if ((i.callerPublicKey == pk)) | |
373 | 904 | then true | |
374 | - | else (poolStatus == PoolPutDisabled)) | |
905 | + | else pd | |
906 | + | case _: Unit => | |
907 | + | if ((i.caller == this)) | |
375 | 908 | then true | |
376 | - | else | |
377 | - | | |
378 | - | | |
379 | - | ||
909 | + | else pd | |
910 | + | case _ => | |
911 | + | throw("Match error") | |
912 | + | } | |
380 | 913 | ||
381 | 914 | ||
382 | 915 | @Callable(i) | |
383 | - | func constructor (factoryContract,managerPublicKey) = if ((i.caller != this)) | |
384 | - | then throw("permissions denied") | |
385 | - | else [StringEntry(keyFactoryContract(), factoryContract), StringEntry(keyManagerPublicKey(), managerPublicKey)] | |
916 | + | func constructor (fc) = { | |
917 | + | let c = mm(i) | |
918 | + | if ((c == c)) | |
919 | + | then [StringEntry(fc(), fc)] | |
920 | + | else throw("Strict value is not equal to itself.") | |
921 | + | } | |
386 | 922 | ||
387 | 923 | ||
388 | 924 | ||
389 | 925 | @Callable(i) | |
390 | - | func put (slippageTolerance,shouldAutoStake) = { | |
391 | - | let factoryCfg = getFactoryConfig() | |
392 | - | let stakingContract = valueOrErrorMessage(addressFromString(factoryCfg[idxFactoryStakingContract]), "Error. Incorrect staking address.") | |
393 | - | let slippageContract = valueOrErrorMessage(addressFromString(factoryCfg[idxFactorySlippageContract]), "Error. Incorrect slippage contract address.") | |
394 | - | if ((0 > slippageTolerance)) | |
395 | - | then throw("Invalid slippageTolerance passed") | |
396 | - | else { | |
397 | - | let estPut = commonPut(i, slippageTolerance, true) | |
398 | - | let emitLpAmt = estPut._2 | |
399 | - | let lpAssetId = estPut._7 | |
400 | - | let state = estPut._9 | |
401 | - | let amDiff = estPut._10 | |
402 | - | let prDiff = estPut._11 | |
403 | - | let amId = estPut._12 | |
404 | - | let prId = estPut._13 | |
405 | - | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
406 | - | if ((emitInv == emitInv)) | |
926 | + | func setManager (pendingManagerPublicKey) = { | |
927 | + | let c = mm(i) | |
928 | + | if ((c == c)) | |
929 | + | then { | |
930 | + | let cm = fromBase58String(pendingManagerPublicKey) | |
931 | + | if ((cm == cm)) | |
932 | + | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
933 | + | else throw("Strict value is not equal to itself.") | |
934 | + | } | |
935 | + | else throw("Strict value is not equal to itself.") | |
936 | + | } | |
937 | + | ||
938 | + | ||
939 | + | ||
940 | + | @Callable(i) | |
941 | + | func confirmManager () = { | |
942 | + | let p = pm() | |
943 | + | let hpm = if (isDefined(p)) | |
944 | + | then true | |
945 | + | else throw("No pending manager") | |
946 | + | if ((hpm == hpm)) | |
947 | + | then { | |
948 | + | let cpm = if ((i.callerPublicKey == value(p))) | |
949 | + | then true | |
950 | + | else throw("You are not pending manager") | |
951 | + | if ((cpm == cpm)) | |
952 | + | then [StringEntry(mpk(), toBase58String(value(p))), DeleteEntry(pmpk())] | |
953 | + | else throw("Strict value is not equal to itself.") | |
954 | + | } | |
955 | + | else throw("Strict value is not equal to itself.") | |
956 | + | } | |
957 | + | ||
958 | + | ||
959 | + | ||
960 | + | @Callable(i) | |
961 | + | func put (slip,autoStake) = { | |
962 | + | let factCfg = gfc() | |
963 | + | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
964 | + | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
965 | + | if ((0 > slip)) | |
966 | + | then throw("Wrong slippage") | |
967 | + | else if ((size(i.payments) != 2)) | |
968 | + | then throw("2 pmnts expd") | |
969 | + | else { | |
970 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
971 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
972 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
973 | + | if ((amountAssetBalance == amountAssetBalance)) | |
974 | + | then { | |
975 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
976 | + | if ((priceAssetBalance == priceAssetBalance)) | |
977 | + | then { | |
978 | + | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
979 | + | if ((lpAssetEmission == lpAssetEmission)) | |
980 | + | then { | |
981 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
982 | + | if ((currentDLp == currentDLp)) | |
983 | + | then { | |
984 | + | 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, true, 0, "") | |
985 | + | let emitLpAmt = e._2 | |
986 | + | let lpAssetId = e._7 | |
987 | + | let state = e._9 | |
988 | + | let amDiff = e._10 | |
989 | + | let prDiff = e._11 | |
990 | + | let amId = e._12 | |
991 | + | let prId = e._13 | |
992 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
993 | + | if ((r == r)) | |
994 | + | then { | |
995 | + | let el = match r { | |
996 | + | case legacy: Address => | |
997 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
998 | + | case _ => | |
999 | + | unit | |
1000 | + | } | |
1001 | + | if ((el == el)) | |
1002 | + | then { | |
1003 | + | let sa = if ((amDiff > 0)) | |
1004 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1005 | + | else nil | |
1006 | + | if ((sa == sa)) | |
1007 | + | then { | |
1008 | + | let sp = if ((prDiff > 0)) | |
1009 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1010 | + | else nil | |
1011 | + | if ((sp == sp)) | |
1012 | + | then { | |
1013 | + | let lpTrnsfr = if (autoStake) | |
1014 | + | then { | |
1015 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1016 | + | if ((ss == ss)) | |
1017 | + | then nil | |
1018 | + | else throw("Strict value is not equal to itself.") | |
1019 | + | } | |
1020 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1021 | + | let $t03653136673 = refreshDLpInternal(0, 0, 0) | |
1022 | + | let refreshDLpActions = $t03653136673._1 | |
1023 | + | let updatedDLp = $t03653136673._2 | |
1024 | + | let check = if ((updatedDLp >= currentDLp)) | |
1025 | + | then true | |
1026 | + | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1027 | + | if ((check == check)) | |
1028 | + | then { | |
1029 | + | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1030 | + | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1031 | + | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1032 | + | else throw("Strict value is not equal to itself.") | |
1033 | + | } | |
1034 | + | else throw("Strict value is not equal to itself.") | |
1035 | + | } | |
1036 | + | else throw("Strict value is not equal to itself.") | |
1037 | + | } | |
1038 | + | else throw("Strict value is not equal to itself.") | |
1039 | + | } | |
1040 | + | else throw("Strict value is not equal to itself.") | |
1041 | + | } | |
1042 | + | else throw("Strict value is not equal to itself.") | |
1043 | + | } | |
1044 | + | else throw("Strict value is not equal to itself.") | |
1045 | + | } | |
1046 | + | else throw("Strict value is not equal to itself.") | |
1047 | + | } | |
1048 | + | else throw("Strict value is not equal to itself.") | |
1049 | + | } | |
1050 | + | else throw("Strict value is not equal to itself.") | |
1051 | + | } | |
1052 | + | } | |
1053 | + | ||
1054 | + | ||
1055 | + | ||
1056 | + | @Callable(i) | |
1057 | + | func putOneTknV2 (minOutAmount,autoStake) = { | |
1058 | + | let isPoolOneTokenOperationsDisabled = { | |
1059 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1060 | + | if ($isInstanceOf(@, "Boolean")) | |
1061 | + | then @ | |
1062 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1063 | + | } | |
1064 | + | let isPutDisabled = if (if (if (igs()) | |
1065 | + | then true | |
1066 | + | else (cfgPoolStatus == PoolPutDis)) | |
1067 | + | then true | |
1068 | + | else (cfgPoolStatus == PoolShutdown)) | |
1069 | + | then true | |
1070 | + | else isPoolOneTokenOperationsDisabled | |
1071 | + | let checks = [if (if (!(isPutDisabled)) | |
1072 | + | then true | |
1073 | + | else isManager(i)) | |
1074 | + | then true | |
1075 | + | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1076 | + | then true | |
1077 | + | else throwErr("exactly 1 payment are expected")] | |
1078 | + | if ((checks == checks)) | |
1079 | + | then { | |
1080 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1081 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1082 | + | let lpId = cfgLpAssetId | |
1083 | + | let amDecimals = cfgAmountAssetDecimals | |
1084 | + | let prDecimals = cfgPriceAssetDecimals | |
1085 | + | let userAddress = if ((i.caller == this)) | |
1086 | + | then i.originCaller | |
1087 | + | else i.caller | |
1088 | + | let pmt = value(i.payments[0]) | |
1089 | + | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1090 | + | let pmtAmt = pmt.amount | |
1091 | + | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1092 | + | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1093 | + | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1094 | + | if ((currentDLp == currentDLp)) | |
407 | 1095 | then { | |
408 | - | let slippageAInv = if ((amDiff > 0)) | |
409 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
410 | - | else nil | |
411 | - | if ((slippageAInv == slippageAInv)) | |
1096 | + | let $t03831438472 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1097 | + | if (($t03831438472 == $t03831438472)) | |
412 | 1098 | then { | |
413 | - | let slippagePInv = if ((prDiff > 0)) | |
414 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
415 | - | else nil | |
416 | - | if ((slippagePInv == slippagePInv)) | |
1099 | + | let feeAmount = $t03831438472._3 | |
1100 | + | let state = $t03831438472._2 | |
1101 | + | let estimLP = $t03831438472._1 | |
1102 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1103 | + | then (minOutAmount > estimLP) | |
1104 | + | else false) | |
1105 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1106 | + | else estimLP | |
1107 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1108 | + | if ((e == e)) | |
417 | 1109 | then { | |
418 | - | let lpTransfer = if (shouldAutoStake) | |
1110 | + | let el = match e { | |
1111 | + | case legacy: Address => | |
1112 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1113 | + | case _ => | |
1114 | + | unit | |
1115 | + | } | |
1116 | + | if ((el == el)) | |
419 | 1117 | then { | |
420 | - | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
421 | - | if ((slpStakeInv == slpStakeInv)) | |
422 | - | then nil | |
1118 | + | let lpTrnsfr = if (autoStake) | |
1119 | + | then { | |
1120 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1121 | + | if ((ss == ss)) | |
1122 | + | then nil | |
1123 | + | else throw("Strict value is not equal to itself.") | |
1124 | + | } | |
1125 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1126 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1127 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1128 | + | else nil | |
1129 | + | let $t03928739636 = if ((this == feeCollectorAddress)) | |
1130 | + | then $Tuple2(0, 0) | |
1131 | + | else { | |
1132 | + | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1133 | + | then true | |
1134 | + | else false | |
1135 | + | if (paymentInAmountAsset) | |
1136 | + | then $Tuple2(-(feeAmount), 0) | |
1137 | + | else $Tuple2(0, -(feeAmount)) | |
1138 | + | } | |
1139 | + | let amountAssetBalanceDelta = $t03928739636._1 | |
1140 | + | let priceAssetBalanceDelta = $t03928739636._2 | |
1141 | + | let $t03963939747 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1142 | + | let refreshDLpActions = $t03963939747._1 | |
1143 | + | let updatedDLp = $t03963939747._2 | |
1144 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1145 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1146 | + | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
423 | 1147 | else throw("Strict value is not equal to itself.") | |
424 | 1148 | } | |
425 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
426 | - | (state ++ lpTransfer) | |
1149 | + | else throw("Strict value is not equal to itself.") | |
427 | 1150 | } | |
428 | 1151 | else throw("Strict value is not equal to itself.") | |
429 | 1152 | } | |
431 | 1154 | } | |
432 | 1155 | else throw("Strict value is not equal to itself.") | |
433 | 1156 | } | |
434 | - | } | |
435 | - | ||
436 | - | ||
437 | - | ||
438 | - | @Callable(i) | |
439 | - | func putForFree (maxSlippage) = if ((0 > maxSlippage)) | |
440 | - | then throw("Invalid value passed") | |
441 | - | else { | |
442 | - | let estPut = commonPut(i, maxSlippage, false) | |
443 | - | estPut._9 | |
444 | - | } | |
445 | - | ||
446 | - | ||
447 | - | ||
448 | - | @Callable(i) | |
449 | - | func get () = { | |
450 | - | let res = commonGet(i) | |
451 | - | let outAmtAmt = res._1 | |
452 | - | let outPrAmt = res._2 | |
453 | - | let pmtAmt = res._3 | |
454 | - | let pmtAssetId = res._4 | |
455 | - | let state = res._5 | |
456 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
457 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
458 | - | then state | |
459 | 1157 | else throw("Strict value is not equal to itself.") | |
460 | 1158 | } | |
461 | 1159 | ||
462 | 1160 | ||
463 | 1161 | ||
464 | 1162 | @Callable(i) | |
1163 | + | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1164 | + | then throw("Wrong slpg") | |
1165 | + | else if ((size(i.payments) != 2)) | |
1166 | + | then throw("2 pmnts expd") | |
1167 | + | else { | |
1168 | + | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxSlpg, false, false, true, 0, "") | |
1169 | + | let state = estPut._9 | |
1170 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1171 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1172 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1173 | + | if ((currentDLp == currentDLp)) | |
1174 | + | then { | |
1175 | + | let $t04077740842 = refreshDLpInternal(0, 0, 0) | |
1176 | + | let refreshDLpActions = $t04077740842._1 | |
1177 | + | let updatedDLp = $t04077740842._2 | |
1178 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1179 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1180 | + | then (state ++ refreshDLpActions) | |
1181 | + | else throw("Strict value is not equal to itself.") | |
1182 | + | } | |
1183 | + | else throw("Strict value is not equal to itself.") | |
1184 | + | } | |
1185 | + | ||
1186 | + | ||
1187 | + | ||
1188 | + | @Callable(i) | |
1189 | + | func get () = { | |
1190 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1191 | + | if ((currentDLp == currentDLp)) | |
1192 | + | then { | |
1193 | + | let r = cg(i) | |
1194 | + | let outAmtAmt = r._1 | |
1195 | + | let outPrAmt = r._2 | |
1196 | + | let pmtAmt = r._3 | |
1197 | + | let pmtAssetId = r._4 | |
1198 | + | let state = r._5 | |
1199 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1200 | + | if ((b == b)) | |
1201 | + | then { | |
1202 | + | let $t04201542097 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1203 | + | let refreshDLpActions = $t04201542097._1 | |
1204 | + | let updatedDLp = $t04201542097._2 | |
1205 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1206 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1207 | + | then (state ++ refreshDLpActions) | |
1208 | + | else throw("Strict value is not equal to itself.") | |
1209 | + | } | |
1210 | + | else throw("Strict value is not equal to itself.") | |
1211 | + | } | |
1212 | + | else throw("Strict value is not equal to itself.") | |
1213 | + | } | |
1214 | + | ||
1215 | + | ||
1216 | + | ||
1217 | + | @Callable(i) | |
1218 | + | func getOneTknV2 (outAssetId,minOutAmount) = { | |
1219 | + | let isPoolOneTokenOperationsDisabled = { | |
1220 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1221 | + | if ($isInstanceOf(@, "Boolean")) | |
1222 | + | then @ | |
1223 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1224 | + | } | |
1225 | + | let isGetDisabled = if (if (igs()) | |
1226 | + | then true | |
1227 | + | else (cfgPoolStatus == PoolShutdown)) | |
1228 | + | then true | |
1229 | + | else isPoolOneTokenOperationsDisabled | |
1230 | + | let checks = [if (if (!(isGetDisabled)) | |
1231 | + | then true | |
1232 | + | else isManager(i)) | |
1233 | + | then true | |
1234 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1235 | + | then true | |
1236 | + | else throwErr("exactly 1 payment are expected")] | |
1237 | + | if ((checks == checks)) | |
1238 | + | then { | |
1239 | + | let $t04271542870 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1240 | + | let state = $t04271542870._1 | |
1241 | + | let totalAmount = $t04271542870._2 | |
1242 | + | $Tuple2(state, totalAmount) | |
1243 | + | } | |
1244 | + | else throw("Strict value is not equal to itself.") | |
1245 | + | } | |
1246 | + | ||
1247 | + | ||
1248 | + | ||
1249 | + | @Callable(i) | |
1250 | + | func refreshDLp () = { | |
1251 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1252 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1253 | + | then unit | |
1254 | + | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1255 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1256 | + | then { | |
1257 | + | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1258 | + | let $t04339443458 = refreshDLpInternal(0, 0, 0) | |
1259 | + | let dLpUpdateActions = $t04339443458._1 | |
1260 | + | let updatedDLp = $t04339443458._2 | |
1261 | + | let actions = if ((dLp != updatedDLp)) | |
1262 | + | then dLpUpdateActions | |
1263 | + | else throwErr("nothing to refresh") | |
1264 | + | $Tuple2(actions, toString(updatedDLp)) | |
1265 | + | } | |
1266 | + | else throw("Strict value is not equal to itself.") | |
1267 | + | } | |
1268 | + | ||
1269 | + | ||
1270 | + | ||
1271 | + | @Callable(i) | |
1272 | + | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1273 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1274 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1275 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1276 | + | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1277 | + | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1278 | + | let D0 = getD(xp) | |
1279 | + | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1280 | + | let index = if ((outAssetId == amId)) | |
1281 | + | then 0 | |
1282 | + | else if ((outAssetId == prId)) | |
1283 | + | then 1 | |
1284 | + | else throw("invalid out asset id") | |
1285 | + | let newY = getYD(xp, index, D1) | |
1286 | + | let dy = (xp[index] - newY) | |
1287 | + | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1288 | + | let $t04438844443 = takeFee(totalGetRaw, outFee) | |
1289 | + | let totalGet = $t04438844443._1 | |
1290 | + | let feeAmount = $t04438844443._2 | |
1291 | + | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1292 | + | } | |
1293 | + | ||
1294 | + | ||
1295 | + | ||
1296 | + | @Callable(i) | |
1297 | + | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1298 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1299 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1300 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1301 | + | let amBalance = getAccBalance(amId) | |
1302 | + | let prBalance = getAccBalance(prId) | |
1303 | + | let $t04481844933 = { | |
1304 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1305 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
1306 | + | then @ | |
1307 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1308 | + | } | |
1309 | + | let totalGet = $t04481844933._1 | |
1310 | + | let feeAmount = $t04481844933._2 | |
1311 | + | let r = ego("", lpId, lpAssetAmount, this) | |
1312 | + | let outAmAmt = r._1 | |
1313 | + | let outPrAmt = r._2 | |
1314 | + | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1315 | + | let bonus = if ((sumOfGetAssets == 0)) | |
1316 | + | then if ((totalGet == 0)) | |
1317 | + | then 0 | |
1318 | + | else throw("bonus calculation error") | |
1319 | + | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1320 | + | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1321 | + | } | |
1322 | + | ||
1323 | + | ||
1324 | + | ||
1325 | + | @Callable(i) | |
465 | 1326 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
466 | - | let | |
467 | - | let outAmAmt = | |
468 | - | let outPrAmt = | |
469 | - | let pmtAmt = | |
470 | - | let pmtAssetId = | |
471 | - | let state = | |
1327 | + | let r = cg(i) | |
1328 | + | let outAmAmt = r._1 | |
1329 | + | let outPrAmt = r._2 | |
1330 | + | let pmtAmt = r._3 | |
1331 | + | let pmtAssetId = r._4 | |
1332 | + | let state = r._5 | |
472 | 1333 | if ((noLessThenAmtAsset > outAmAmt)) | |
473 | - | then throw((((" | |
1334 | + | then throw(((("Failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
474 | 1335 | else if ((noLessThenPriceAsset > outPrAmt)) | |
475 | - | then throw((((" | |
1336 | + | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
476 | 1337 | else { | |
477 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
478 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
479 | - | then state | |
1338 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1339 | + | if ((currentDLp == currentDLp)) | |
1340 | + | then { | |
1341 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1342 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1343 | + | then { | |
1344 | + | let $t04609946180 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1345 | + | let refreshDLpActions = $t04609946180._1 | |
1346 | + | let updatedDLp = $t04609946180._2 | |
1347 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1348 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1349 | + | then (state ++ refreshDLpActions) | |
1350 | + | else throw("Strict value is not equal to itself.") | |
1351 | + | } | |
1352 | + | else throw("Strict value is not equal to itself.") | |
1353 | + | } | |
480 | 1354 | else throw("Strict value is not equal to itself.") | |
481 | 1355 | } | |
482 | 1356 | } | |
484 | 1358 | ||
485 | 1359 | ||
486 | 1360 | @Callable(i) | |
487 | - | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
488 | - | then throw("permissions denied") | |
489 | - | else $Tuple2([StringEntry(keyAmtAsset(), amtAssetStr), StringEntry(keyPriceAsset(), priceAssetStr)], "success") | |
1361 | + | func unstakeAndGet (amount) = { | |
1362 | + | let checkPayments = if ((size(i.payments) != 0)) | |
1363 | + | then throw("No pmnts expd") | |
1364 | + | else true | |
1365 | + | if ((checkPayments == checkPayments)) | |
1366 | + | then { | |
1367 | + | let factoryCfg = gfc() | |
1368 | + | let lpAssetId = cfgLpAssetId | |
1369 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1370 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1371 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1372 | + | if ((unstakeInv == unstakeInv)) | |
1373 | + | then { | |
1374 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1375 | + | let outAmAmt = r._1 | |
1376 | + | let outPrAmt = r._2 | |
1377 | + | let sts = parseIntValue(r._9) | |
1378 | + | let state = r._10 | |
1379 | + | let v = if (if (igs()) | |
1380 | + | then true | |
1381 | + | else (sts == PoolShutdown)) | |
1382 | + | then throw(("Blocked: " + toString(sts))) | |
1383 | + | else true | |
1384 | + | if ((v == v)) | |
1385 | + | then { | |
1386 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1387 | + | if ((burnA == burnA)) | |
1388 | + | then { | |
1389 | + | let $t04720447285 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1390 | + | let refreshDLpActions = $t04720447285._1 | |
1391 | + | let updatedDLp = $t04720447285._2 | |
1392 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1393 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1394 | + | then (state ++ refreshDLpActions) | |
1395 | + | else throw("Strict value is not equal to itself.") | |
1396 | + | } | |
1397 | + | else throw("Strict value is not equal to itself.") | |
1398 | + | } | |
1399 | + | else throw("Strict value is not equal to itself.") | |
1400 | + | } | |
1401 | + | else throw("Strict value is not equal to itself.") | |
1402 | + | } | |
1403 | + | else throw("Strict value is not equal to itself.") | |
1404 | + | } | |
490 | 1405 | ||
491 | 1406 | ||
492 | 1407 | ||
493 | 1408 | @Callable(i) | |
494 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1409 | + | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1410 | + | let isGetDisabled = if (igs()) | |
1411 | + | then true | |
1412 | + | else (cfgPoolStatus == PoolShutdown) | |
1413 | + | let checks = [if (!(isGetDisabled)) | |
1414 | + | then true | |
1415 | + | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1416 | + | then true | |
1417 | + | else throw("no payments are expected")] | |
1418 | + | if ((checks == checks)) | |
1419 | + | then { | |
1420 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1421 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1422 | + | if ((unstakeInv == unstakeInv)) | |
1423 | + | then { | |
1424 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1425 | + | let outAmAmt = res._1 | |
1426 | + | let outPrAmt = res._2 | |
1427 | + | let state = res._10 | |
1428 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1429 | + | then true | |
1430 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1431 | + | then true | |
1432 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1433 | + | if ((checkAmounts == checkAmounts)) | |
1434 | + | then { | |
1435 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1436 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1437 | + | then { | |
1438 | + | let $t04853348614 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1439 | + | let refreshDLpActions = $t04853348614._1 | |
1440 | + | let updatedDLp = $t04853348614._2 | |
1441 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1442 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1443 | + | then (state ++ refreshDLpActions) | |
1444 | + | else throw("Strict value is not equal to itself.") | |
1445 | + | } | |
1446 | + | else throw("Strict value is not equal to itself.") | |
1447 | + | } | |
1448 | + | else throw("Strict value is not equal to itself.") | |
1449 | + | } | |
1450 | + | else throw("Strict value is not equal to itself.") | |
1451 | + | } | |
1452 | + | else throw("Strict value is not equal to itself.") | |
1453 | + | } | |
1454 | + | ||
1455 | + | ||
1456 | + | ||
1457 | + | @Callable(i) | |
1458 | + | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1459 | + | let isPoolOneTokenOperationsDisabled = { | |
1460 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1461 | + | if ($isInstanceOf(@, "Boolean")) | |
1462 | + | then @ | |
1463 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1464 | + | } | |
1465 | + | let isGetDisabled = if (if (igs()) | |
1466 | + | then true | |
1467 | + | else (cfgPoolStatus == PoolShutdown)) | |
1468 | + | then true | |
1469 | + | else isPoolOneTokenOperationsDisabled | |
1470 | + | let checks = [if (if (!(isGetDisabled)) | |
1471 | + | then true | |
1472 | + | else isManager(i)) | |
1473 | + | then true | |
1474 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1475 | + | then true | |
1476 | + | else throwErr("no payments are expected")] | |
1477 | + | if ((checks == checks)) | |
1478 | + | then { | |
1479 | + | let factoryCfg = gfc() | |
1480 | + | let lpAssetId = cfgLpAssetId | |
1481 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1482 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1483 | + | if ((unstakeInv == unstakeInv)) | |
1484 | + | then { | |
1485 | + | let $t04950949697 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1486 | + | let state = $t04950949697._1 | |
1487 | + | let totalAmount = $t04950949697._2 | |
1488 | + | $Tuple2(state, totalAmount) | |
1489 | + | } | |
1490 | + | else throw("Strict value is not equal to itself.") | |
1491 | + | } | |
1492 | + | else throw("Strict value is not equal to itself.") | |
1493 | + | } | |
1494 | + | ||
1495 | + | ||
1496 | + | ||
1497 | + | @Callable(i) | |
1498 | + | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1499 | + | let $t04982549928 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1500 | + | let lpAmount = $t04982549928._1 | |
1501 | + | let state = $t04982549928._2 | |
1502 | + | let feeAmount = $t04982549928._3 | |
1503 | + | let bonus = $t04982549928._4 | |
1504 | + | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1505 | + | } | |
1506 | + | ||
1507 | + | ||
1508 | + | ||
1509 | + | @Callable(i) | |
1510 | + | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1511 | + | let $t05007650180 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1512 | + | let lpAmount = $t05007650180._1 | |
1513 | + | let state = $t05007650180._2 | |
1514 | + | let feeAmount = $t05007650180._3 | |
1515 | + | let bonus = $t05007650180._4 | |
1516 | + | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1517 | + | } | |
1518 | + | ||
1519 | + | ||
1520 | + | ||
1521 | + | @Callable(i) | |
1522 | + | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1523 | + | then throw("denied") | |
1524 | + | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr)], "success") | |
1525 | + | ||
1526 | + | ||
1527 | + | ||
1528 | + | @Callable(i) | |
1529 | + | func setS (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1530 | + | then pd | |
1531 | + | else [StringEntry(k, v)] | |
1532 | + | ||
1533 | + | ||
1534 | + | ||
1535 | + | @Callable(i) | |
1536 | + | func setI (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1537 | + | then pd | |
1538 | + | else [IntegerEntry(k, v)] | |
1539 | + | ||
1540 | + | ||
1541 | + | ||
1542 | + | @Callable(i) | |
1543 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
495 | 1544 | ||
496 | 1545 | ||
497 | 1546 | ||
502 | 1551 | ||
503 | 1552 | @Callable(i) | |
504 | 1553 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
505 | - | let | |
506 | - | $Tuple2(nil, [toString( | |
1554 | + | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
1555 | + | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
507 | 1556 | } | |
508 | 1557 | ||
509 | 1558 | ||
510 | 1559 | ||
511 | 1560 | @Callable(i) | |
512 | - | func fromX18WrapperREADONLY (val, | |
1561 | + | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, f1(parseBigIntValue(val), resScaleMult)) | |
513 | 1562 | ||
514 | 1563 | ||
515 | 1564 | ||
516 | 1565 | @Callable(i) | |
517 | - | func statsREADONLY () = { | |
518 | - | let cfg = getPoolConfig() | |
519 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
520 | - | let amtAssetId = cfg[idxAmtAssetId] | |
521 | - | let priceAssetId = cfg[idxPriceAssetId] | |
522 | - | let iAmtAssetId = cfg[idxIAmtAssetId] | |
523 | - | let iPriceAssetId = cfg[idxIPriceAssetId] | |
524 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
525 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
526 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
527 | - | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
528 | - | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
529 | - | let pricesList = if ((poolLPBalance == 0)) | |
530 | - | then [zeroBigInt, zeroBigInt, zeroBigInt] | |
531 | - | else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance) | |
532 | - | let curPrice = 0 | |
533 | - | let lpAmtAssetShare = fromX18(pricesList[1], scale8) | |
534 | - | let lpPriceAssetShare = fromX18(pricesList[2], scale8) | |
535 | - | let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this)))) | |
536 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight)], SEP)) | |
537 | - | } | |
1566 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(t1(origVal, origScaleMult))) | |
538 | 1567 | ||
539 | 1568 | ||
540 | 1569 | ||
541 | 1570 | @Callable(i) | |
542 | - | func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = { | |
543 | - | let cfg = getPoolConfig() | |
544 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
545 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
546 | - | let amAssetId = fromBase58String(amAssetIdStr) | |
547 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
548 | - | let prAssetId = fromBase58String(prAssetIdStr) | |
549 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
550 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
551 | - | let poolStatus = cfg[idxPoolStatus] | |
552 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
553 | - | let accAmtAssetBalance = getAccBalance(amAssetIdStr) | |
554 | - | let accPriceAssetBalance = getAccBalance(prAssetIdStr) | |
555 | - | let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm) | |
556 | - | let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm) | |
557 | - | let curPriceX18 = if ((poolLPBalance == 0)) | |
558 | - | then zeroBigInt | |
559 | - | else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
560 | - | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
561 | - | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
562 | - | let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm) | |
563 | - | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
564 | - | let calcLpAmt = estPut._1 | |
565 | - | let curPriceCalc = estPut._3 | |
566 | - | let amBalance = estPut._4 | |
567 | - | let prBalance = estPut._5 | |
568 | - | let lpEmission = estPut._6 | |
569 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
570 | - | } | |
1571 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(cpbi(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
571 | 1572 | ||
572 | 1573 | ||
573 | 1574 | ||
574 | 1575 | @Callable(i) | |
575 | - | func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = { | |
576 | - | let cfg = getPoolConfig() | |
577 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
578 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
579 | - | let amAssetId = fromBase58String(amAssetIdStr) | |
580 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
581 | - | let prAssetId = fromBase58String(prAssetIdStr) | |
582 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
583 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
584 | - | let poolStatus = cfg[idxPoolStatus] | |
585 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
586 | - | let amBalanceRaw = getAccBalance(amAssetIdStr) | |
587 | - | let prBalanceRaw = getAccBalance(prAssetIdStr) | |
588 | - | let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm) | |
589 | - | let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm) | |
590 | - | let curPriceX18 = if ((poolLPBalance == 0)) | |
591 | - | then zeroBigInt | |
592 | - | else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18) | |
593 | - | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
594 | - | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
595 | - | let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm) | |
596 | - | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
597 | - | let calcLpAmt = estPut._1 | |
598 | - | let curPriceCalc = estPut._3 | |
599 | - | let amBalance = estPut._4 | |
600 | - | let prBalance = estPut._5 | |
601 | - | let lpEmission = estPut._6 | |
602 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
603 | - | } | |
1576 | + | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,usrAddr,isEval,emitLp) = $Tuple2(nil, epo(txId58, slippage, inAmAmt, inAmId, inPrAmt, inPrId, usrAddr, isEval, emitLp, true, false, 0, "")) | |
604 | 1577 | ||
605 | 1578 | ||
606 | 1579 | ||
607 | 1580 | @Callable(i) | |
608 | - | func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { | |
609 | - | let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this) | |
610 | - | let outAmAmt = res._1 | |
611 | - | let outPrAmt = res._2 | |
612 | - | let amBalance = res._5 | |
613 | - | let prBalance = res._6 | |
614 | - | let lpEmission = res._7 | |
615 | - | let curPrice = res._8 | |
616 | - | let poolStatus = parseIntValue(res._9) | |
617 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), toString(curPrice), toString(poolStatus)], SEP)) | |
1581 | + | func estimateGetOperationWrapperREADONLY (txId58,pmtAsId,pmtLpAmt,usrAddr) = { | |
1582 | + | let r = ego(txId58, pmtAsId, pmtLpAmt, addressFromStringValue(usrAddr)) | |
1583 | + | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
618 | 1584 | } | |
619 | 1585 | ||
620 | 1586 | ||
621 | 1587 | @Verifier(tx) | |
622 | - | func verify () = match tx { | |
623 | - | case order: Order => | |
624 | - | let matcherPub = getMatcherPubOrFail() | |
625 | - | let orderValid = validateMatcherOrderAllowed(order) | |
626 | - | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
627 | - | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
628 | - | if (if (if (orderValid) | |
629 | - | then senderValid | |
630 | - | else false) | |
631 | - | then matcherValid | |
632 | - | else false) | |
633 | - | then true | |
634 | - | else throwOrderError(orderValid, senderValid, matcherValid) | |
635 | - | case _ => | |
636 | - | let managerPublic = valueOrElse(getString(this, keyManagerPublicKey()), EMPTY) | |
637 | - | if ((managerPublic == EMPTY)) | |
638 | - | then sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
639 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(managerPublic)) | |
640 | - | } | |
1588 | + | func verify () = { | |
1589 | + | let targetPublicKey = match m() { | |
1590 | + | case pk: ByteVector => | |
1591 | + | pk | |
1592 | + | case _: Unit => | |
1593 | + | tx.senderPublicKey | |
1594 | + | case _ => | |
1595 | + | throw("Match error") | |
1596 | + | } | |
1597 | + | match tx { | |
1598 | + | case order: Order => | |
1599 | + | let matcherPub = mp() | |
1600 | + | let orderValid = validateMatcherOrderAllowed(order) | |
1601 | + | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1602 | + | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1603 | + | if (if (if (orderValid) | |
1604 | + | then senderValid | |
1605 | + | else false) | |
1606 | + | then matcherValid | |
1607 | + | else false) | |
1608 | + | then true | |
1609 | + | else toe(orderValid, senderValid, matcherValid) | |
1610 | + | case s: SetScriptTransaction => | |
1611 | + | let newHash = blake2b256(value(s.script)) | |
1612 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1613 | + | let currentHash = scriptHash(this) | |
1614 | + | if (if ((allowedHash == newHash)) | |
1615 | + | then (currentHash != newHash) | |
1616 | + | else false) | |
1617 | + | then true | |
1618 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1619 | + | case _ => | |
1620 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1621 | + | } | |
1622 | + | } | |
641 | 1623 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let lPdecimals = 8 | |
5 | - | ||
6 | 4 | let scale8 = 100000000 | |
7 | 5 | ||
8 | 6 | let scale8BigInt = toBigInt(100000000) | |
9 | 7 | ||
10 | 8 | let scale18 = toBigInt(1000000000000000000) | |
11 | 9 | ||
12 | 10 | let zeroBigInt = toBigInt(0) | |
13 | 11 | ||
12 | + | let big0 = toBigInt(0) | |
13 | + | ||
14 | + | let big1 = toBigInt(1) | |
15 | + | ||
16 | + | let big2 = toBigInt(2) | |
17 | + | ||
18 | + | let big3 = toBigInt(3) | |
19 | + | ||
20 | + | let big4 = toBigInt(4) | |
21 | + | ||
22 | + | let slippage4D = toBigInt((scale8 - ((scale8 * 1) / scale8))) | |
23 | + | ||
24 | + | let wavesString = "WAVES" | |
25 | + | ||
26 | + | let Amult = "100" | |
27 | + | ||
28 | + | let Dconv = "1" | |
29 | + | ||
14 | 30 | let SEP = "__" | |
15 | 31 | ||
16 | 32 | let EMPTY = "" | |
17 | 33 | ||
18 | 34 | let PoolActive = 1 | |
19 | 35 | ||
20 | - | let | |
36 | + | let PoolPutDis = 2 | |
21 | 37 | ||
22 | - | let | |
38 | + | let PoolMatcherDis = 3 | |
23 | 39 | ||
24 | 40 | let PoolShutdown = 4 | |
25 | 41 | ||
26 | 42 | let idxPoolAddress = 1 | |
27 | 43 | ||
28 | - | let | |
44 | + | let idxPoolSt = 2 | |
29 | 45 | ||
30 | - | let | |
46 | + | let idxLPAsId = 3 | |
31 | 47 | ||
32 | - | let | |
48 | + | let idxAmAsId = 4 | |
33 | 49 | ||
34 | - | let | |
50 | + | let idxPrAsId = 5 | |
35 | 51 | ||
36 | - | let | |
52 | + | let idxAmtAsDcm = 6 | |
37 | 53 | ||
38 | - | let | |
54 | + | let idxPriceAsDcm = 7 | |
39 | 55 | ||
40 | - | let | |
56 | + | let idxIAmtAsId = 8 | |
41 | 57 | ||
42 | - | let | |
58 | + | let idxIPriceAsId = 9 | |
43 | 59 | ||
44 | - | let | |
60 | + | let idxFactStakCntr = 1 | |
45 | 61 | ||
46 | - | let | |
62 | + | let idxFactoryRestCntr = 6 | |
47 | 63 | ||
48 | - | let | |
64 | + | let idxFactSlippCntr = 7 | |
49 | 65 | ||
50 | - | let | |
66 | + | let idxFactGwxRewCntr = 10 | |
51 | 67 | ||
52 | - | let | |
68 | + | let feeDefault = fraction(10, scale8, 10000) | |
53 | 69 | ||
54 | - | let idxFactorySlippageContract = 7 | |
55 | - | ||
56 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
70 | + | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
57 | 71 | ||
58 | 72 | ||
59 | - | func | |
73 | + | func f1 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
60 | 74 | ||
61 | 75 | ||
62 | - | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
76 | + | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
77 | + | ||
78 | + | ||
79 | + | func ts (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
63 | 80 | ||
64 | 81 | ||
65 | 82 | func abs (val) = if ((zeroBigInt > val)) | |
66 | 83 | then -(val) | |
67 | 84 | else val | |
68 | 85 | ||
69 | 86 | ||
70 | - | func keyFactoryContract () = "%s__factoryContract" | |
87 | + | func absBigInt (val) = if ((zeroBigInt > val)) | |
88 | + | then -(val) | |
89 | + | else val | |
71 | 90 | ||
72 | 91 | ||
73 | - | func | |
92 | + | func fc () = "%s__factoryContract" | |
74 | 93 | ||
75 | 94 | ||
76 | - | func | |
95 | + | func mpk () = "%s__managerPublicKey" | |
77 | 96 | ||
78 | 97 | ||
79 | - | func | |
98 | + | func pmpk () = "%s__pendingManagerPublicKey" | |
80 | 99 | ||
81 | 100 | ||
82 | - | func | |
101 | + | func pl () = "%s%s__price__last" | |
83 | 102 | ||
84 | 103 | ||
85 | - | func | |
104 | + | func ph (h,t) = makeString(["%s%s%d%d__price__history", toString(h), toString(t)], SEP) | |
86 | 105 | ||
87 | 106 | ||
88 | - | func | |
107 | + | func pau (ua,txId) = ((("%s%s%s__P__" + ua) + "__") + txId) | |
89 | 108 | ||
90 | 109 | ||
91 | - | func | |
110 | + | func gau (ua,txId) = ((("%s%s%s__G__" + ua) + "__") + txId) | |
92 | 111 | ||
93 | 112 | ||
94 | - | func | |
113 | + | func aa () = "%s__amountAsset" | |
95 | 114 | ||
96 | 115 | ||
97 | - | func | |
116 | + | func pa () = "%s__priceAsset" | |
98 | 117 | ||
99 | 118 | ||
100 | - | func | |
119 | + | func amp () = "%s__amp" | |
101 | 120 | ||
102 | 121 | ||
103 | - | func | |
122 | + | func ada () = "%s__addonAddr" | |
104 | 123 | ||
105 | 124 | ||
106 | - | func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config") | |
125 | + | let keyFee = "%s__fee" | |
126 | + | ||
127 | + | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
128 | + | ||
129 | + | let keyDLp = makeString(["%s", "dLp"], SEP) | |
130 | + | ||
131 | + | let keyDLpRefreshedHeight = makeString(["%s", "dLpRefreshedHeight"], SEP) | |
132 | + | ||
133 | + | let keyDLpRefreshDelay = makeString(["%s", "refreshDLpDelay"], SEP) | |
134 | + | ||
135 | + | let dLpRefreshDelayDefault = 1 | |
136 | + | ||
137 | + | let dLpRefreshDelay = valueOrElse(getInteger(this, keyDLpRefreshDelay), dLpRefreshDelayDefault) | |
138 | + | ||
139 | + | func fcfg () = "%s__factoryConfig" | |
107 | 140 | ||
108 | 141 | ||
109 | - | func | |
142 | + | func mtpk () = "%s%s__matcher__publicKey" | |
110 | 143 | ||
111 | 144 | ||
112 | - | func | |
145 | + | func pc (iAmtAs,iPrAs) = (((("%d%d%s__" + iAmtAs) + "__") + iPrAs) + "__config") | |
113 | 146 | ||
114 | 147 | ||
115 | - | func | |
148 | + | func mba (bAStr) = ("%s%s%s__mappings__baseAsset2internalId__" + bAStr) | |
116 | 149 | ||
117 | 150 | ||
118 | - | func | |
151 | + | func aps () = "%s__shutdown" | |
119 | 152 | ||
120 | 153 | ||
121 | - | func | |
154 | + | func keyAllowedLpStableScriptHash () = "%s__allowedLpStableScriptHash" | |
122 | 155 | ||
123 | 156 | ||
124 | - | func | |
157 | + | func keyFeeCollectorAddress () = "%s__feeCollectorAddress" | |
125 | 158 | ||
126 | 159 | ||
127 | - | let factoryContract = addressFromStringValue(getStringOrFail(this, keyFactoryContract())) | |
128 | - | ||
129 | - | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
160 | + | func toe (orV,sendrV,matchV) = throw(((((("Failed: ordValid=" + toString(orV)) + " sndrValid=") + toString(sendrV)) + " mtchrValid=") + toString(matchV))) | |
130 | 161 | ||
131 | 162 | ||
132 | - | func | |
163 | + | func strf (addr,key) = valueOrErrorMessage(getString(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
133 | 164 | ||
134 | 165 | ||
135 | - | func getPoolConfig () = { | |
136 | - | let amtAsset = getStringOrFail(this, keyAmtAsset()) | |
137 | - | let priceAsset = getStringOrFail(this, keyPriceAsset()) | |
138 | - | let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset)) | |
139 | - | let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset)) | |
140 | - | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP) | |
166 | + | func intf (addr,key) = valueOrErrorMessage(getInteger(addr, key), makeString(["mandatory ", toString(addr), ".", key, " not defined"], "")) | |
167 | + | ||
168 | + | ||
169 | + | func throwErr (msg) = throw(makeString(["lp_stable.ride:", msg], " ")) | |
170 | + | ||
171 | + | ||
172 | + | func fmtErr (msg) = makeString(["lp_stable.ride:", msg], " ") | |
173 | + | ||
174 | + | ||
175 | + | let fca = addressFromStringValue(strf(this, fc())) | |
176 | + | ||
177 | + | let inFee = { | |
178 | + | let @ = invoke(fca, "getInFeeREADONLY", [toString(this)], nil) | |
179 | + | if ($isInstanceOf(@, "Int")) | |
180 | + | then @ | |
181 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
182 | + | } | |
183 | + | ||
184 | + | let outFee = { | |
185 | + | let @ = invoke(fca, "getOutFeeREADONLY", [toString(this)], nil) | |
186 | + | if ($isInstanceOf(@, "Int")) | |
187 | + | then @ | |
188 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
189 | + | } | |
190 | + | ||
191 | + | let A = strf(this, amp()) | |
192 | + | ||
193 | + | func igs () = valueOrElse(getBoolean(fca, aps()), false) | |
194 | + | ||
195 | + | ||
196 | + | func mp () = fromBase58String(strf(fca, mtpk())) | |
197 | + | ||
198 | + | ||
199 | + | let feeCollectorAddress = addressFromStringValue(strf(fca, keyFeeCollectorAddress())) | |
200 | + | ||
201 | + | func gpc () = { | |
202 | + | let amtAs = strf(this, aa()) | |
203 | + | let priceAs = strf(this, pa()) | |
204 | + | let iPriceAs = intf(fca, mba(priceAs)) | |
205 | + | let iAmtAs = intf(fca, mba(amtAs)) | |
206 | + | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
141 | 207 | } | |
142 | 208 | ||
143 | 209 | ||
144 | - | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
210 | + | func parseAssetId (input) = if ((input == wavesString)) | |
211 | + | then unit | |
212 | + | else fromBase58String(input) | |
145 | 213 | ||
146 | 214 | ||
147 | - | func dataPutActionInfo (inAmtAssetAmt,inPriceAssetAmt,outLpAmt,price,slippageTolerancePassedByUser,slippageToleranceReal,txHeight,txTimestamp,slipageAmtAssetAmt,slipagePriceAssetAmt) = makeString(["%d%d%d%d%d%d%d%d%d%d", toString(inAmtAssetAmt), toString(inPriceAssetAmt), toString(outLpAmt), toString(price), toString(slippageTolerancePassedByUser), toString(slippageToleranceReal), toString(txHeight), toString(txTimestamp), toString(slipageAmtAssetAmt), toString(slipagePriceAssetAmt)], SEP) | |
215 | + | func assetIdToString (input) = if ((input == unit)) | |
216 | + | then wavesString | |
217 | + | else toBase58String(value(input)) | |
218 | + | ||
219 | + | ||
220 | + | func parsePoolConfig (poolConfig) = $Tuple9(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolSt]), fromBase58String(poolConfig[idxLPAsId]), parseAssetId(poolConfig[idxAmAsId]), parseAssetId(poolConfig[idxPrAsId]), parseIntValue(poolConfig[idxAmtAsDcm]), parseIntValue(poolConfig[idxPriceAsDcm]), fromBase58String(poolConfig[idxIAmtAsId]), fromBase58String(poolConfig[idxIPriceAsId])) | |
221 | + | ||
222 | + | ||
223 | + | let poolConfigParsed = parsePoolConfig(gpc()) | |
224 | + | ||
225 | + | let $t075447773 = poolConfigParsed | |
226 | + | ||
227 | + | let cfgPoolAddress = $t075447773._1 | |
228 | + | ||
229 | + | let cfgPoolStatus = $t075447773._2 | |
230 | + | ||
231 | + | let cfgLpAssetId = $t075447773._3 | |
232 | + | ||
233 | + | let cfgAmountAssetId = $t075447773._4 | |
234 | + | ||
235 | + | let cfgPriceAssetId = $t075447773._5 | |
236 | + | ||
237 | + | let cfgAmountAssetDecimals = $t075447773._6 | |
238 | + | ||
239 | + | let cfgPriceAssetDecimals = $t075447773._7 | |
240 | + | ||
241 | + | let cfgInAmountAssedId = $t075447773._8 | |
242 | + | ||
243 | + | let cfgInPriceAssetId = $t075447773._9 | |
244 | + | ||
245 | + | func gfc () = split(strf(fca, fcfg()), SEP) | |
246 | + | ||
247 | + | ||
248 | + | let factoryConfig = gfc() | |
249 | + | ||
250 | + | let stakingContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactStakCntr]), "Invalid staking contract address") | |
251 | + | ||
252 | + | let slipageContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactSlippCntr]), "Invalid slipage contract address") | |
253 | + | ||
254 | + | let gwxContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactGwxRewCntr]), "Invalid gwx contract address") | |
255 | + | ||
256 | + | let restContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactoryRestCntr]), "Invalid gwx contract address") | |
257 | + | ||
258 | + | 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) | |
148 | 259 | ||
149 | 260 | ||
150 | 261 | 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) | |
151 | 262 | ||
152 | 263 | ||
153 | 264 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
154 | 265 | then wavesBalance(this).available | |
155 | 266 | else assetBalance(this, fromBase58String(assetId)) | |
156 | 267 | ||
157 | 268 | ||
158 | - | func | |
269 | + | func cpbi (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
159 | 270 | ||
160 | 271 | ||
161 | - | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
162 | - | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
163 | - | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
164 | - | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
272 | + | func cpbir (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
273 | + | ||
274 | + | ||
275 | + | func vad (A1,A2,slippage) = { | |
276 | + | let diff = fraction((A1 - A2), scale8BigInt, A2) | |
277 | + | let pass = ((slippage - abs(diff)) > zeroBigInt) | |
278 | + | if (!(pass)) | |
279 | + | then throw(("Big slpg: " + toString(diff))) | |
280 | + | else $Tuple2(pass, min([A1, A2])) | |
281 | + | } | |
282 | + | ||
283 | + | ||
284 | + | func vd (D1,D0,slpg) = { | |
285 | + | let diff = fraction(D0, scale8BigInt, D1) | |
286 | + | let fail = (slpg > diff) | |
287 | + | if (if (fail) | |
288 | + | then true | |
289 | + | else (D0 > D1)) | |
290 | + | then throw(((((((toString(D0) + " ") + toString(D1)) + " ") + toString(diff)) + " ") + toString(slpg))) | |
291 | + | else fail | |
292 | + | } | |
293 | + | ||
294 | + | ||
295 | + | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
296 | + | let amtAsAmtX18 = t1(amAmt, amAssetDcm) | |
297 | + | let prAsAmtX18 = t1(prAmt, prAssetDcm) | |
298 | + | cpbi(prAsAmtX18, amtAsAmtX18) | |
165 | 299 | } | |
166 | 300 | ||
167 | 301 | ||
168 | 302 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
169 | - | let cfg = getPoolConfig() | |
170 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
171 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
172 | - | let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt) | |
173 | - | let amAmtX18 = toX18(amAmt, amtAssetDcm) | |
174 | - | let prAmtX18 = toX18(prAmt, priceAssetDcm) | |
175 | - | let lpAmtX18 = toX18(lpAmt, scale8) | |
176 | - | let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
177 | - | let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
178 | - | [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18] | |
303 | + | let amtAsDcm = cfgAmountAssetDecimals | |
304 | + | let prAsDcm = cfgPriceAssetDecimals | |
305 | + | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
306 | + | let amAmtX18 = t1(amAmt, amtAsDcm) | |
307 | + | let prAmtX18 = t1(prAmt, prAsDcm) | |
308 | + | let lpAmtX18 = t1(lpAmt, scale8) | |
309 | + | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) | |
310 | + | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) | |
311 | + | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
179 | 312 | } | |
180 | 313 | ||
181 | 314 | ||
182 | 315 | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
183 | - | let | |
184 | - | [ | |
316 | + | let p = calcPrices(amAmt, prAmt, lpAmt) | |
317 | + | [f1(p[0], scale8), f1(p[1], scale8), f1(p[2], scale8)] | |
185 | 318 | } | |
186 | 319 | ||
187 | 320 | ||
188 | - | func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
189 | - | let cfg = getPoolConfig() | |
190 | - | let lpAssetId = cfg[idxPoolLPAssetId] | |
191 | - | let amAssetId = cfg[idxAmtAssetId] | |
192 | - | let prAssetId = cfg[idxPriceAssetId] | |
193 | - | let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
194 | - | let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
195 | - | let poolStatus = cfg[idxPoolStatus] | |
196 | - | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity | |
197 | - | if ((lpAssetId != pmtAssetId)) | |
198 | - | then throw("Invalid asset passed.") | |
321 | + | func takeFee (amount,fee) = { | |
322 | + | let feeAmount = if ((fee == 0)) | |
323 | + | then 0 | |
324 | + | else fraction(amount, fee, scale8) | |
325 | + | $Tuple2((amount - feeAmount), feeAmount) | |
326 | + | } | |
327 | + | ||
328 | + | ||
329 | + | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
330 | + | let lpId = cfgLpAssetId | |
331 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
332 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
333 | + | let amDcm = cfgAmountAssetDecimals | |
334 | + | let prDcm = cfgPriceAssetDecimals | |
335 | + | let sts = toString(cfgPoolStatus) | |
336 | + | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
337 | + | if ((toBase58String(lpId) != pmtAssetId)) | |
338 | + | then throw("Wrong pmt asset") | |
199 | 339 | else { | |
200 | - | let amBalance = getAccBalance( | |
201 | - | let amBalanceX18 = | |
202 | - | let prBalance = getAccBalance( | |
203 | - | let prBalanceX18 = | |
204 | - | let curPriceX18 = | |
205 | - | let curPrice = | |
206 | - | let pmtLpAmtX18 = | |
207 | - | let | |
208 | - | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, | |
209 | - | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, | |
210 | - | let outAmAmt = | |
211 | - | let outPrAmt = | |
340 | + | let amBalance = getAccBalance(amId) | |
341 | + | let amBalanceX18 = t1(amBalance, amDcm) | |
342 | + | let prBalance = getAccBalance(prId) | |
343 | + | let prBalanceX18 = t1(prBalance, prDcm) | |
344 | + | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
345 | + | let curPrice = f1(curPriceX18, scale8) | |
346 | + | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) | |
347 | + | let lpEmissX18 = t1(lpEmiss, scale8) | |
348 | + | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
349 | + | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
350 | + | let outAmAmt = fromX18Round(outAmAmtX18, amDcm, FLOOR) | |
351 | + | let outPrAmt = fromX18Round(outPrAmtX18, prDcm, FLOOR) | |
212 | 352 | let state = if ((txId58 == "")) | |
213 | 353 | then nil | |
214 | - | else [ScriptTransfer(userAddress, outAmAmt, if (( | |
354 | + | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
215 | 355 | then unit | |
216 | - | else fromBase58String( | |
356 | + | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) | |
217 | 357 | then unit | |
218 | - | else fromBase58String( | |
219 | - | $Tuple10(outAmAmt, outPrAmt, | |
358 | + | else fromBase58String(prId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
359 | + | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) | |
220 | 360 | } | |
221 | 361 | } | |
222 | 362 | ||
223 | 363 | ||
224 | - | func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = { | |
225 | - | let cfg = getPoolConfig() | |
226 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
227 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
228 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
229 | - | let iAmtAssetId = cfg[idxIAmtAssetId] | |
230 | - | let iPriceAssetId = cfg[idxIPriceAssetId] | |
231 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
232 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
233 | - | let poolStatus = cfg[idxPoolStatus] | |
234 | - | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
235 | - | let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES"))) | |
236 | - | let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES"))) | |
237 | - | if (if ((amAssetIdStr != inAmAssetIdStr)) | |
238 | - | then true | |
239 | - | else (prAssetIdStr != inPrAssetIdStr)) | |
240 | - | then throw("Invalid amt or price asset passed.") | |
364 | + | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
365 | + | let lpId = cfgLpAssetId | |
366 | + | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
367 | + | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
368 | + | let inAmIdStr = cfgInAmountAssedId | |
369 | + | let inPrIdStr = cfgInPriceAssetId | |
370 | + | let amtDcm = cfgAmountAssetDecimals | |
371 | + | let priceDcm = cfgPriceAssetDecimals | |
372 | + | let sts = toString(cfgPoolStatus) | |
373 | + | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
374 | + | let amBalance = if (isEval) | |
375 | + | then getAccBalance(amIdStr) | |
376 | + | else if (if (isOneAsset) | |
377 | + | then (pmtId == amIdStr) | |
378 | + | else false) | |
379 | + | then (getAccBalance(amIdStr) - pmtAmt) | |
380 | + | else if (isOneAsset) | |
381 | + | then getAccBalance(amIdStr) | |
382 | + | else (getAccBalance(amIdStr) - inAmAmt) | |
383 | + | let prBalance = if (isEval) | |
384 | + | then getAccBalance(prIdStr) | |
385 | + | else if (if (isOneAsset) | |
386 | + | then (pmtId == prIdStr) | |
387 | + | else false) | |
388 | + | then (getAccBalance(prIdStr) - pmtAmt) | |
389 | + | else if (isOneAsset) | |
390 | + | then getAccBalance(prIdStr) | |
391 | + | else (getAccBalance(prIdStr) - inPrAmt) | |
392 | + | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) | |
393 | + | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) | |
394 | + | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
395 | + | let amBalanceX18 = t1(amBalance, amtDcm) | |
396 | + | let prBalanceX18 = t1(prBalance, priceDcm) | |
397 | + | let r = if ((lpEm == 0)) | |
398 | + | then { | |
399 | + | let curPriceX18 = zeroBigInt | |
400 | + | let slippageX18 = zeroBigInt | |
401 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
402 | + | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
403 | + | } | |
241 | 404 | else { | |
242 | - | let amBalance = if (isEvaluate) | |
243 | - | then getAccBalance(amAssetIdStr) | |
244 | - | else (getAccBalance(amAssetIdStr) - inAmAssetAmt) | |
245 | - | let prBalance = if (isEvaluate) | |
246 | - | then getAccBalance(prAssetIdStr) | |
247 | - | else (getAccBalance(prAssetIdStr) - inPrAssetAmt) | |
248 | - | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
249 | - | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
250 | - | let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18) | |
251 | - | let amBalanceX18 = toX18(amBalance, amtAssetDcm) | |
252 | - | let prBalanceX18 = toX18(prBalance, priceAssetDcm) | |
253 | - | let res = if ((lpEmission == 0)) | |
254 | - | then { | |
255 | - | let curPriceX18 = zeroBigInt | |
256 | - | let slippageX18 = zeroBigInt | |
257 | - | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
258 | - | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
405 | + | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
406 | + | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
407 | + | let slippageX18 = t1(slippage, scale8) | |
408 | + | if (if (if (validateSlippage) | |
409 | + | then (curPriceX18 != zeroBigInt) | |
410 | + | else false) | |
411 | + | then (slippageRealX18 > slippageX18) | |
412 | + | else false) | |
413 | + | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
414 | + | else { | |
415 | + | let lpEmissionX18 = t1(lpEm, scale8) | |
416 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, cpbir(prBalanceX18, amBalanceX18, FLOOR), scale18, FLOOR) | |
417 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, cpbir(prBalanceX18, amBalanceX18, FLOOR), FLOOR) | |
418 | + | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
419 | + | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
420 | + | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
421 | + | let expAmtAssetAmtX18 = expectedAmts._1 | |
422 | + | let expPriceAssetAmtX18 = expectedAmts._2 | |
423 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR) | |
424 | + | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
259 | 425 | } | |
260 | - | else { | |
261 | - | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
262 | - | let slippageX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
263 | - | let slippageToleranceX18 = toX18(slippageTolerance, scale8) | |
264 | - | if (if ((curPriceX18 != zeroBigInt)) | |
265 | - | then (slippageX18 > slippageToleranceX18) | |
266 | - | else false) | |
267 | - | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
268 | - | else { | |
269 | - | let lpEmissionX18 = toX18(lpEmission, scale8) | |
270 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
271 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
272 | - | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
273 | - | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
274 | - | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
275 | - | let expAmtAssetAmtX18 = expectedAmts._1 | |
276 | - | let expPriceAssetAmtX18 = expectedAmts._2 | |
277 | - | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18) | |
278 | - | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(expAmtAssetAmtX18, amtAssetDcm), fromX18(expPriceAssetAmtX18, priceAssetDcm), curPriceX18, slippageX18) | |
279 | - | } | |
280 | - | } | |
281 | - | let calcLpAmt = res._1 | |
282 | - | let calcAmAssetPmt = res._2 | |
283 | - | let calcPrAssetPmt = res._3 | |
284 | - | let curPrice = fromX18(res._4, scale8) | |
285 | - | let slippageCalc = fromX18(res._5, scale8) | |
286 | - | if ((0 >= calcLpAmt)) | |
287 | - | then throw("Invalid calculations. LP calculated is less than zero.") | |
288 | - | else { | |
289 | - | let emitLpAmt = if (!(emitLp)) | |
290 | - | then 0 | |
291 | - | else calcLpAmt | |
292 | - | let amDiff = (inAmAssetAmt - calcAmAssetPmt) | |
293 | - | let prDiff = (inPrAssetAmt - calcPrAssetPmt) | |
294 | - | let commonState = [IntegerEntry(keyPriceLast(), curPrice), IntegerEntry(keyPriceHistory(height, lastBlock.timestamp), curPrice), StringEntry(keyPutActionByUser(userAddress, txId58), dataPutActionInfo(calcAmAssetPmt, calcPrAssetPmt, emitLpAmt, curPrice, slippageTolerance, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
295 | - | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId) | |
296 | - | } | |
426 | + | } | |
427 | + | let calcLpAmt = r._1 | |
428 | + | let calcAmAssetPmt = r._2 | |
429 | + | let calcPrAssetPmt = r._3 | |
430 | + | let curPrice = f1(r._4, scale8) | |
431 | + | let slippageCalc = f1(r._5, scale8) | |
432 | + | if ((0 >= calcLpAmt)) | |
433 | + | then throw("LP <= 0") | |
434 | + | else { | |
435 | + | let emitLpAmt = if (!(emitLp)) | |
436 | + | then 0 | |
437 | + | else calcLpAmt | |
438 | + | let amDiff = (inAmAmt - calcAmAssetPmt) | |
439 | + | let prDiff = (inPrAmt - calcPrAssetPmt) | |
440 | + | let $t01841718762 = if (if (isOneAsset) | |
441 | + | then (pmtId == amIdStr) | |
442 | + | else false) | |
443 | + | then $Tuple2(pmtAmt, 0) | |
444 | + | else if (if (isOneAsset) | |
445 | + | then (pmtId == prIdStr) | |
446 | + | else false) | |
447 | + | then $Tuple2(0, pmtAmt) | |
448 | + | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
449 | + | let writeAmAmt = $t01841718762._1 | |
450 | + | let writePrAmt = $t01841718762._2 | |
451 | + | 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))] | |
452 | + | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
297 | 453 | } | |
298 | 454 | } | |
299 | 455 | ||
300 | 456 | ||
301 | - | func validateMatcherOrderAllowed (order) = { | |
302 | - | let cfg = getPoolConfig() | |
303 | - | let amtAssetId = cfg[idxAmtAssetId] | |
304 | - | let priceAssetId = cfg[idxPriceAssetId] | |
305 | - | let poolStatus = parseIntValue(cfg[idxPoolStatus]) | |
306 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
307 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
308 | - | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
309 | - | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
310 | - | let curPriceX18 = if ((order.orderType == Buy)) | |
311 | - | then privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance + order.amount), accPriceAssetBalance) | |
312 | - | else privateCalcPrice(amtAssetDcm, priceAssetDcm, (accAmtAssetBalance - order.amount), accPriceAssetBalance) | |
313 | - | let curPrice = fromX18(curPriceX18, scale8) | |
314 | - | if (if (if (isGlobalShutdown()) | |
315 | - | then true | |
316 | - | else (poolStatus == PoolMatcherDisabled)) | |
317 | - | then true | |
318 | - | else (poolStatus == PoolShutdown)) | |
319 | - | then throw("Exchange operations disabled") | |
457 | + | func getD (xp) = { | |
458 | + | let xp0 = xp[0] | |
459 | + | let xp1 = xp[1] | |
460 | + | let s = (xp0 + xp1) | |
461 | + | if ((s == big0)) | |
462 | + | then big0 | |
320 | 463 | else { | |
321 | - | let orderAmtAsset = order.assetPair.amountAsset | |
322 | - | let orderAmtAssetStr = if ((orderAmtAsset == unit)) | |
323 | - | then "WAVES" | |
324 | - | else toBase58String(value(orderAmtAsset)) | |
325 | - | let orderPriceAsset = order.assetPair.priceAsset | |
326 | - | let orderPriceAssetStr = if ((orderPriceAsset == unit)) | |
327 | - | then "WAVES" | |
328 | - | else toBase58String(value(orderPriceAsset)) | |
329 | - | if (if ((orderAmtAssetStr != amtAssetId)) | |
330 | - | then true | |
331 | - | else (orderPriceAssetStr != priceAssetId)) | |
332 | - | then throw("Wrong order assets.") | |
464 | + | let a = parseIntValue(A) | |
465 | + | let ann = (a * 2) | |
466 | + | let p = fraction(xp0, xp1, big1) | |
467 | + | let xp0_xp1_n_n = fraction(p, big4, big1) | |
468 | + | let ann_s = fraction(toBigInt(ann), s, big1) | |
469 | + | let ann_1 = toBigInt((ann - 1)) | |
470 | + | func calcDNext (d) = { | |
471 | + | let dd = fraction(d, d, big1) | |
472 | + | let ddd = fraction(dd, d, big1) | |
473 | + | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
474 | + | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1)), CEILING) | |
475 | + | } | |
476 | + | ||
477 | + | func calc (acc,i) = if (acc._2) | |
478 | + | then acc | |
333 | 479 | else { | |
334 | - | let orderPrice = order.price | |
335 | - | let priceDcm = fraction(scale8, priceAssetDcm, amtAssetDcm) | |
336 | - | let castedOrderPrice = toScale(orderPrice, scale8, priceDcm) | |
337 | - | let isOrderPriceValid = if ((order.orderType == Buy)) | |
338 | - | then (curPrice >= castedOrderPrice) | |
339 | - | else (castedOrderPrice >= curPrice) | |
340 | - | true | |
480 | + | let d = acc._1 | |
481 | + | let dNext = calcDNext(d) | |
482 | + | let dDiffRaw = toInt((dNext - value(d))) | |
483 | + | let dDiff = if ((0 > dDiffRaw)) | |
484 | + | then -(dDiffRaw) | |
485 | + | else dDiffRaw | |
486 | + | if ((1 >= dDiff)) | |
487 | + | then $Tuple2(dNext, true) | |
488 | + | else $Tuple2(dNext, false) | |
341 | 489 | } | |
490 | + | ||
491 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
492 | + | let $t02069020738 = { | |
493 | + | let $l = arr | |
494 | + | let $s = size($l) | |
495 | + | let $acc0 = $Tuple2(s, false) | |
496 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
497 | + | then $a | |
498 | + | else calc($a, $l[$i]) | |
499 | + | ||
500 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
501 | + | then $a | |
502 | + | else throw("List size exceeds 15") | |
503 | + | ||
504 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
505 | + | } | |
506 | + | let d = $t02069020738._1 | |
507 | + | let found = $t02069020738._2 | |
508 | + | if (found) | |
509 | + | then d | |
510 | + | else throw(("D calculation error, D = " + toString(d))) | |
342 | 511 | } | |
343 | 512 | } | |
344 | 513 | ||
345 | 514 | ||
346 | - | func commonGet (i) = if ((size(i.payments) != 1)) | |
347 | - | then throw("exactly 1 payment is expected") | |
515 | + | func getDOld (xp) = { | |
516 | + | let n = big2 | |
517 | + | let xp0 = xp[0] | |
518 | + | let xp1 = xp[1] | |
519 | + | let aPrecision = parseBigIntValue(Amult) | |
520 | + | let a = (parseBigIntValue(A) * aPrecision) | |
521 | + | let s = (xp0 + xp1) | |
522 | + | if ((s == big0)) | |
523 | + | then big0 | |
524 | + | else { | |
525 | + | let ann = (a * n) | |
526 | + | let xp0_xp1_n_n = (((xp0 * xp1) * n) * n) | |
527 | + | let ann_s_aPrecision = ((ann * s) / aPrecision) | |
528 | + | let ann_aPrecision = (ann - aPrecision) | |
529 | + | let n1 = (n + big1) | |
530 | + | func calc (acc,cur) = { | |
531 | + | let $t02136721387 = acc | |
532 | + | let d = $t02136721387._1 | |
533 | + | let found = $t02136721387._2 | |
534 | + | if ((found != unit)) | |
535 | + | then acc | |
536 | + | else { | |
537 | + | let dp = (((d * d) * d) / xp0_xp1_n_n) | |
538 | + | let dNext = (((ann_s_aPrecision + (dp * n)) * d) / (((ann_aPrecision * d) / aPrecision) + (n1 * dp))) | |
539 | + | let dDiff = absBigInt((dNext - value(d))) | |
540 | + | if ((big1 >= dDiff)) | |
541 | + | then $Tuple2(dNext, cur) | |
542 | + | else $Tuple2(dNext, unit) | |
543 | + | } | |
544 | + | } | |
545 | + | ||
546 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
547 | + | let $t02180821855 = { | |
548 | + | let $l = arr | |
549 | + | let $s = size($l) | |
550 | + | let $acc0 = $Tuple2(s, unit) | |
551 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
552 | + | then $a | |
553 | + | else calc($a, $l[$i]) | |
554 | + | ||
555 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
556 | + | then $a | |
557 | + | else throw("List size exceeds 15") | |
558 | + | ||
559 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
560 | + | } | |
561 | + | let d = $t02180821855._1 | |
562 | + | let found = $t02180821855._2 | |
563 | + | if ((found != unit)) | |
564 | + | then d | |
565 | + | else throw(("D calculation error, D = " + toString(d))) | |
566 | + | } | |
567 | + | } | |
568 | + | ||
569 | + | ||
570 | + | func getYD (xp,i,D) = { | |
571 | + | let n = big2 | |
572 | + | let x = xp[if ((i == 0)) | |
573 | + | then 1 | |
574 | + | else 0] | |
575 | + | let aPrecision = parseBigIntValue(Amult) | |
576 | + | let a = (parseBigIntValue(A) * aPrecision) | |
577 | + | let s = x | |
578 | + | let ann = (a * n) | |
579 | + | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
580 | + | let b = ((s + ((D * aPrecision) / ann)) - D) | |
581 | + | func calc (acc,cur) = { | |
582 | + | let $t02235522375 = acc | |
583 | + | let y = $t02235522375._1 | |
584 | + | let found = $t02235522375._2 | |
585 | + | if ((found != unit)) | |
586 | + | then acc | |
587 | + | else { | |
588 | + | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
589 | + | let yDiff = absBigInt((yNext - value(y))) | |
590 | + | if ((big1 >= yDiff)) | |
591 | + | then $Tuple2(yNext, cur) | |
592 | + | else $Tuple2(yNext, unit) | |
593 | + | } | |
594 | + | } | |
595 | + | ||
596 | + | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
597 | + | let $t02268222729 = { | |
598 | + | let $l = arr | |
599 | + | let $s = size($l) | |
600 | + | let $acc0 = $Tuple2(D, unit) | |
601 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
602 | + | then $a | |
603 | + | else calc($a, $l[$i]) | |
604 | + | ||
605 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
606 | + | then $a | |
607 | + | else throw("List size exceeds 15") | |
608 | + | ||
609 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
610 | + | } | |
611 | + | let y = $t02268222729._1 | |
612 | + | let found = $t02268222729._2 | |
613 | + | if ((found != unit)) | |
614 | + | then y | |
615 | + | else throw(("Y calculation error, Y = " + toString(y))) | |
616 | + | } | |
617 | + | ||
618 | + | ||
619 | + | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
620 | + | let updatedDLp = fraction(getD([amountBalance, priceBalance]), scale18, lpEmission) | |
621 | + | if ((lpEmission == big0)) | |
622 | + | then big0 | |
623 | + | else updatedDLp | |
624 | + | } | |
625 | + | ||
626 | + | ||
627 | + | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
628 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
629 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
630 | + | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
631 | + | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
632 | + | currentDLp | |
633 | + | } | |
634 | + | ||
635 | + | ||
636 | + | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
637 | + | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
638 | + | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
639 | + | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
640 | + | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
641 | + | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
642 | + | $Tuple2(actions, updatedDLp) | |
643 | + | } | |
644 | + | ||
645 | + | ||
646 | + | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
647 | + | then true | |
648 | + | else throwErr("updated DLp lower than current DLp") | |
649 | + | ||
650 | + | ||
651 | + | func validateMatcherOrderAllowed (order) = { | |
652 | + | let amountAssetAmount = order.amount | |
653 | + | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
654 | + | let $t02466824880 = if ((order.orderType == Buy)) | |
655 | + | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
656 | + | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
657 | + | let amountAssetBalanceDelta = $t02466824880._1 | |
658 | + | let priceAssetBalanceDelta = $t02466824880._2 | |
659 | + | if (if (if (igs()) | |
660 | + | then true | |
661 | + | else (cfgPoolStatus == PoolMatcherDis)) | |
662 | + | then true | |
663 | + | else (cfgPoolStatus == PoolShutdown)) | |
664 | + | then throw("Admin blocked") | |
665 | + | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
666 | + | then true | |
667 | + | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
668 | + | then throw("Wr assets") | |
669 | + | else { | |
670 | + | let dLp = parseBigIntValue(getStringValue(this, keyDLp)) | |
671 | + | let $t02521025310 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
672 | + | let unusedActions = $t02521025310._1 | |
673 | + | let dLpNew = $t02521025310._2 | |
674 | + | let isOrderValid = (dLpNew >= dLp) | |
675 | + | isOrderValid | |
676 | + | } | |
677 | + | } | |
678 | + | ||
679 | + | ||
680 | + | func cg (i) = if ((size(i.payments) != 1)) | |
681 | + | then throw("1 pmnt exp") | |
348 | 682 | else { | |
349 | 683 | let pmt = value(i.payments[0]) | |
350 | 684 | let pmtAssetId = value(pmt.assetId) | |
351 | 685 | let pmtAmt = pmt.amount | |
352 | - | let | |
353 | - | let outAmAmt = | |
354 | - | let outPrAmt = | |
355 | - | let | |
356 | - | let state = | |
357 | - | if (if ( | |
686 | + | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
687 | + | let outAmAmt = r._1 | |
688 | + | let outPrAmt = r._2 | |
689 | + | let sts = parseIntValue(r._9) | |
690 | + | let state = r._10 | |
691 | + | if (if (igs()) | |
358 | 692 | then true | |
359 | - | else ( | |
360 | - | then throw((" | |
693 | + | else (sts == PoolShutdown)) | |
694 | + | then throw(("Admin blocked: " + toString(sts))) | |
361 | 695 | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
362 | 696 | } | |
363 | 697 | ||
364 | 698 | ||
365 | - | func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2)) | |
366 | - | then throw("exactly 2 payments are expected") | |
367 | - | else { | |
368 | - | let amAssetPmt = value(i.payments[0]) | |
369 | - | let prAssetPmt = value(i.payments[1]) | |
370 | - | let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp) | |
371 | - | let poolStatus = parseIntValue(estPut._8) | |
372 | - | if (if (if (isGlobalShutdown()) | |
699 | + | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
700 | + | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, (txId == ""), emitLp, isOneAsset, validateSlippage, pmtAmt, pmtId) | |
701 | + | let sts = parseIntValue(r._8) | |
702 | + | if (if (if (igs()) | |
703 | + | then true | |
704 | + | else (sts == PoolPutDis)) | |
705 | + | then true | |
706 | + | else (sts == PoolShutdown)) | |
707 | + | then throw(("Blocked:" + toString(sts))) | |
708 | + | else r | |
709 | + | } | |
710 | + | ||
711 | + | ||
712 | + | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
713 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
714 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
715 | + | let lpId = cfgLpAssetId | |
716 | + | let amtDcm = cfgAmountAssetDecimals | |
717 | + | let priceDcm = cfgPriceAssetDecimals | |
718 | + | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
719 | + | let chechEmission = if ((lpAssetEmission > big0)) | |
720 | + | then true | |
721 | + | else throw("initial deposit requires all coins") | |
722 | + | if ((chechEmission == chechEmission)) | |
723 | + | then { | |
724 | + | let amBalance = getAccBalance(amId) | |
725 | + | let prBalance = getAccBalance(prId) | |
726 | + | let $t02757628038 = if ((txId == "")) | |
727 | + | then $Tuple2(amBalance, prBalance) | |
728 | + | else if ((pmtAssetId == amId)) | |
729 | + | then if ((pmtAmtRaw > amBalance)) | |
730 | + | then throw("invalid payment amount") | |
731 | + | else $Tuple2((amBalance - pmtAmtRaw), prBalance) | |
732 | + | else if ((pmtAssetId == prId)) | |
733 | + | then if ((pmtAmtRaw > prBalance)) | |
734 | + | then throw("invalid payment amount") | |
735 | + | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
736 | + | else throw("wrong pmtAssetId") | |
737 | + | let amBalanceOld = $t02757628038._1 | |
738 | + | let prBalanceOld = $t02757628038._2 | |
739 | + | let $t02804428220 = if ((pmtAssetId == amId)) | |
740 | + | then $Tuple2(pmtAmtRaw, 0) | |
741 | + | else if ((pmtAssetId == prId)) | |
742 | + | then $Tuple2(0, pmtAmtRaw) | |
743 | + | else throw("invalid payment") | |
744 | + | let amAmountRaw = $t02804428220._1 | |
745 | + | let prAmountRaw = $t02804428220._2 | |
746 | + | let $t02822428478 = if (withTakeFee) | |
747 | + | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
748 | + | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
749 | + | let amAmount = $t02822428478._1 | |
750 | + | let prAmount = $t02822428478._2 | |
751 | + | let feeAmount = $t02822428478._3 | |
752 | + | let amBalanceNew = (amBalanceOld + amAmount) | |
753 | + | let prBalanceNew = (prBalanceOld + prAmount) | |
754 | + | let D0 = getD([toBigInt(amBalanceOld), toBigInt(prBalanceOld)]) | |
755 | + | let D1 = getD([toBigInt(amBalanceNew), toBigInt(prBalanceNew)]) | |
756 | + | let checkD = if ((D1 > D0)) | |
757 | + | then true | |
758 | + | else throw() | |
759 | + | if ((checkD == checkD)) | |
760 | + | then { | |
761 | + | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0, FLOOR) | |
762 | + | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
763 | + | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId), dataPutActionInfo(amAmountRaw, prAmountRaw, toInt(lpAmount), curPrice, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
764 | + | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
765 | + | let amountAssetPart = fraction(pmtAmtRaw, scale8, (poolProportion + scale8)) | |
766 | + | let priceAssetPart = (pmtAmtRaw - amountAssetPart) | |
767 | + | let lpAmtBoth = fraction(lpAssetEmission, toBigInt(priceAssetPart), toBigInt(prBalanceOld)) | |
768 | + | let bonus = toInt(fraction((lpAmount - lpAmtBoth), scale8BigInt, lpAmtBoth)) | |
769 | + | $Tuple4(toInt(lpAmount), commonState, feeAmount, bonus) | |
770 | + | } | |
771 | + | else throw("Strict value is not equal to itself.") | |
772 | + | } | |
773 | + | else throw("Strict value is not equal to itself.") | |
774 | + | } | |
775 | + | ||
776 | + | ||
777 | + | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
778 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
779 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
780 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
781 | + | let amDecimals = cfgAmountAssetDecimals | |
782 | + | let prDecimals = cfgPriceAssetDecimals | |
783 | + | let poolStatus = cfgPoolStatus | |
784 | + | let userAddress = if ((caller == restContract)) | |
785 | + | then originCaller | |
786 | + | else caller | |
787 | + | let pmt = value(payments[0]) | |
788 | + | let pmtAssetId = value(pmt.assetId) | |
789 | + | let pmtAmt = pmt.amount | |
790 | + | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
791 | + | if ((currentDLp == currentDLp)) | |
792 | + | then { | |
793 | + | let txId58 = toBase58String(transactionId) | |
794 | + | if ((lpId != toBase58String(pmtAssetId))) | |
795 | + | then throw("Wrong LP") | |
796 | + | else { | |
797 | + | let amBalance = getAccBalance(amId) | |
798 | + | let prBalance = getAccBalance(prId) | |
799 | + | let $t03052830639 = { | |
800 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
801 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
802 | + | then @ | |
803 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
804 | + | } | |
805 | + | if (($t03052830639 == $t03052830639)) | |
806 | + | then { | |
807 | + | let feeAmount = $t03052830639._2 | |
808 | + | let totalGet = $t03052830639._1 | |
809 | + | let totalAmount = if (if ((minOutAmount > 0)) | |
810 | + | then (minOutAmount > totalGet) | |
811 | + | else false) | |
812 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
813 | + | else totalGet | |
814 | + | let $t03082931136 = if ((outAssetId == amId)) | |
815 | + | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
816 | + | else if ((outAssetId == prId)) | |
817 | + | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
818 | + | else throw("invalid out asset id") | |
819 | + | let outAm = $t03082931136._1 | |
820 | + | let outPr = $t03082931136._2 | |
821 | + | let amBalanceNew = $t03082931136._3 | |
822 | + | let prBalanceNew = $t03082931136._4 | |
823 | + | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
824 | + | let curPr = f1(curPrX18, scale8) | |
825 | + | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
826 | + | then unit | |
827 | + | else fromBase58String(outAssetId) | |
828 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
829 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
830 | + | else nil | |
831 | + | let state = ([ScriptTransfer(userAddress, totalAmount, outAssetIdOrWaves), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAm, outPr, pmtAmt, curPr, height, lastBlock.timestamp)), IntegerEntry(pl(), curPr), IntegerEntry(ph(height, lastBlock.timestamp), curPr)] ++ sendFeeToMatcher) | |
832 | + | if ((state == state)) | |
833 | + | then { | |
834 | + | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
835 | + | if ((burn == burn)) | |
836 | + | then { | |
837 | + | let $t03192132271 = { | |
838 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
839 | + | then 0 | |
840 | + | else feeAmount | |
841 | + | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
842 | + | then true | |
843 | + | else false | |
844 | + | if (outInAmountAsset) | |
845 | + | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
846 | + | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
847 | + | } | |
848 | + | let amountAssetBalanceDelta = $t03192132271._1 | |
849 | + | let priceAssetBalanceDelta = $t03192132271._2 | |
850 | + | let $t03227432382 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
851 | + | let refreshDLpActions = $t03227432382._1 | |
852 | + | let updatedDLp = $t03227432382._2 | |
853 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
854 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
855 | + | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
856 | + | else throw("Strict value is not equal to itself.") | |
857 | + | } | |
858 | + | else throw("Strict value is not equal to itself.") | |
859 | + | } | |
860 | + | else throw("Strict value is not equal to itself.") | |
861 | + | } | |
862 | + | else throw("Strict value is not equal to itself.") | |
863 | + | } | |
864 | + | } | |
865 | + | else throw("Strict value is not equal to itself.") | |
866 | + | } | |
867 | + | ||
868 | + | ||
869 | + | func m () = match getString(mpk()) { | |
870 | + | case s: String => | |
871 | + | fromBase58String(s) | |
872 | + | case _: Unit => | |
873 | + | unit | |
874 | + | case _ => | |
875 | + | throw("Match error") | |
876 | + | } | |
877 | + | ||
878 | + | ||
879 | + | func pm () = match getString(pmpk()) { | |
880 | + | case s: String => | |
881 | + | fromBase58String(s) | |
882 | + | case _: Unit => | |
883 | + | unit | |
884 | + | case _ => | |
885 | + | throw("Match error") | |
886 | + | } | |
887 | + | ||
888 | + | ||
889 | + | let pd = throw("Permission denied") | |
890 | + | ||
891 | + | func isManager (i) = match m() { | |
892 | + | case pk: ByteVector => | |
893 | + | (i.callerPublicKey == pk) | |
894 | + | case _: Unit => | |
895 | + | (i.caller == this) | |
896 | + | case _ => | |
897 | + | throw("Match error") | |
898 | + | } | |
899 | + | ||
900 | + | ||
901 | + | func mm (i) = match m() { | |
902 | + | case pk: ByteVector => | |
903 | + | if ((i.callerPublicKey == pk)) | |
373 | 904 | then true | |
374 | - | else (poolStatus == PoolPutDisabled)) | |
905 | + | else pd | |
906 | + | case _: Unit => | |
907 | + | if ((i.caller == this)) | |
375 | 908 | then true | |
376 | - | else | |
377 | - | | |
378 | - | | |
379 | - | ||
909 | + | else pd | |
910 | + | case _ => | |
911 | + | throw("Match error") | |
912 | + | } | |
380 | 913 | ||
381 | 914 | ||
382 | 915 | @Callable(i) | |
383 | - | func constructor (factoryContract,managerPublicKey) = if ((i.caller != this)) | |
384 | - | then throw("permissions denied") | |
385 | - | else [StringEntry(keyFactoryContract(), factoryContract), StringEntry(keyManagerPublicKey(), managerPublicKey)] | |
916 | + | func constructor (fc) = { | |
917 | + | let c = mm(i) | |
918 | + | if ((c == c)) | |
919 | + | then [StringEntry(fc(), fc)] | |
920 | + | else throw("Strict value is not equal to itself.") | |
921 | + | } | |
386 | 922 | ||
387 | 923 | ||
388 | 924 | ||
389 | 925 | @Callable(i) | |
390 | - | func put (slippageTolerance,shouldAutoStake) = { | |
391 | - | let factoryCfg = getFactoryConfig() | |
392 | - | let stakingContract = valueOrErrorMessage(addressFromString(factoryCfg[idxFactoryStakingContract]), "Error. Incorrect staking address.") | |
393 | - | let slippageContract = valueOrErrorMessage(addressFromString(factoryCfg[idxFactorySlippageContract]), "Error. Incorrect slippage contract address.") | |
394 | - | if ((0 > slippageTolerance)) | |
395 | - | then throw("Invalid slippageTolerance passed") | |
396 | - | else { | |
397 | - | let estPut = commonPut(i, slippageTolerance, true) | |
398 | - | let emitLpAmt = estPut._2 | |
399 | - | let lpAssetId = estPut._7 | |
400 | - | let state = estPut._9 | |
401 | - | let amDiff = estPut._10 | |
402 | - | let prDiff = estPut._11 | |
403 | - | let amId = estPut._12 | |
404 | - | let prId = estPut._13 | |
405 | - | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
406 | - | if ((emitInv == emitInv)) | |
926 | + | func setManager (pendingManagerPublicKey) = { | |
927 | + | let c = mm(i) | |
928 | + | if ((c == c)) | |
929 | + | then { | |
930 | + | let cm = fromBase58String(pendingManagerPublicKey) | |
931 | + | if ((cm == cm)) | |
932 | + | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
933 | + | else throw("Strict value is not equal to itself.") | |
934 | + | } | |
935 | + | else throw("Strict value is not equal to itself.") | |
936 | + | } | |
937 | + | ||
938 | + | ||
939 | + | ||
940 | + | @Callable(i) | |
941 | + | func confirmManager () = { | |
942 | + | let p = pm() | |
943 | + | let hpm = if (isDefined(p)) | |
944 | + | then true | |
945 | + | else throw("No pending manager") | |
946 | + | if ((hpm == hpm)) | |
947 | + | then { | |
948 | + | let cpm = if ((i.callerPublicKey == value(p))) | |
949 | + | then true | |
950 | + | else throw("You are not pending manager") | |
951 | + | if ((cpm == cpm)) | |
952 | + | then [StringEntry(mpk(), toBase58String(value(p))), DeleteEntry(pmpk())] | |
953 | + | else throw("Strict value is not equal to itself.") | |
954 | + | } | |
955 | + | else throw("Strict value is not equal to itself.") | |
956 | + | } | |
957 | + | ||
958 | + | ||
959 | + | ||
960 | + | @Callable(i) | |
961 | + | func put (slip,autoStake) = { | |
962 | + | let factCfg = gfc() | |
963 | + | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
964 | + | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
965 | + | if ((0 > slip)) | |
966 | + | then throw("Wrong slippage") | |
967 | + | else if ((size(i.payments) != 2)) | |
968 | + | then throw("2 pmnts expd") | |
969 | + | else { | |
970 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
971 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
972 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
973 | + | if ((amountAssetBalance == amountAssetBalance)) | |
974 | + | then { | |
975 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
976 | + | if ((priceAssetBalance == priceAssetBalance)) | |
977 | + | then { | |
978 | + | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
979 | + | if ((lpAssetEmission == lpAssetEmission)) | |
980 | + | then { | |
981 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
982 | + | if ((currentDLp == currentDLp)) | |
983 | + | then { | |
984 | + | 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, true, 0, "") | |
985 | + | let emitLpAmt = e._2 | |
986 | + | let lpAssetId = e._7 | |
987 | + | let state = e._9 | |
988 | + | let amDiff = e._10 | |
989 | + | let prDiff = e._11 | |
990 | + | let amId = e._12 | |
991 | + | let prId = e._13 | |
992 | + | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
993 | + | if ((r == r)) | |
994 | + | then { | |
995 | + | let el = match r { | |
996 | + | case legacy: Address => | |
997 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
998 | + | case _ => | |
999 | + | unit | |
1000 | + | } | |
1001 | + | if ((el == el)) | |
1002 | + | then { | |
1003 | + | let sa = if ((amDiff > 0)) | |
1004 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1005 | + | else nil | |
1006 | + | if ((sa == sa)) | |
1007 | + | then { | |
1008 | + | let sp = if ((prDiff > 0)) | |
1009 | + | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1010 | + | else nil | |
1011 | + | if ((sp == sp)) | |
1012 | + | then { | |
1013 | + | let lpTrnsfr = if (autoStake) | |
1014 | + | then { | |
1015 | + | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1016 | + | if ((ss == ss)) | |
1017 | + | then nil | |
1018 | + | else throw("Strict value is not equal to itself.") | |
1019 | + | } | |
1020 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1021 | + | let $t03653136673 = refreshDLpInternal(0, 0, 0) | |
1022 | + | let refreshDLpActions = $t03653136673._1 | |
1023 | + | let updatedDLp = $t03653136673._2 | |
1024 | + | let check = if ((updatedDLp >= currentDLp)) | |
1025 | + | then true | |
1026 | + | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1027 | + | if ((check == check)) | |
1028 | + | then { | |
1029 | + | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1030 | + | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1031 | + | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1032 | + | else throw("Strict value is not equal to itself.") | |
1033 | + | } | |
1034 | + | else throw("Strict value is not equal to itself.") | |
1035 | + | } | |
1036 | + | else throw("Strict value is not equal to itself.") | |
1037 | + | } | |
1038 | + | else throw("Strict value is not equal to itself.") | |
1039 | + | } | |
1040 | + | else throw("Strict value is not equal to itself.") | |
1041 | + | } | |
1042 | + | else throw("Strict value is not equal to itself.") | |
1043 | + | } | |
1044 | + | else throw("Strict value is not equal to itself.") | |
1045 | + | } | |
1046 | + | else throw("Strict value is not equal to itself.") | |
1047 | + | } | |
1048 | + | else throw("Strict value is not equal to itself.") | |
1049 | + | } | |
1050 | + | else throw("Strict value is not equal to itself.") | |
1051 | + | } | |
1052 | + | } | |
1053 | + | ||
1054 | + | ||
1055 | + | ||
1056 | + | @Callable(i) | |
1057 | + | func putOneTknV2 (minOutAmount,autoStake) = { | |
1058 | + | let isPoolOneTokenOperationsDisabled = { | |
1059 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1060 | + | if ($isInstanceOf(@, "Boolean")) | |
1061 | + | then @ | |
1062 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1063 | + | } | |
1064 | + | let isPutDisabled = if (if (if (igs()) | |
1065 | + | then true | |
1066 | + | else (cfgPoolStatus == PoolPutDis)) | |
1067 | + | then true | |
1068 | + | else (cfgPoolStatus == PoolShutdown)) | |
1069 | + | then true | |
1070 | + | else isPoolOneTokenOperationsDisabled | |
1071 | + | let checks = [if (if (!(isPutDisabled)) | |
1072 | + | then true | |
1073 | + | else isManager(i)) | |
1074 | + | then true | |
1075 | + | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1076 | + | then true | |
1077 | + | else throwErr("exactly 1 payment are expected")] | |
1078 | + | if ((checks == checks)) | |
1079 | + | then { | |
1080 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1081 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1082 | + | let lpId = cfgLpAssetId | |
1083 | + | let amDecimals = cfgAmountAssetDecimals | |
1084 | + | let prDecimals = cfgPriceAssetDecimals | |
1085 | + | let userAddress = if ((i.caller == this)) | |
1086 | + | then i.originCaller | |
1087 | + | else i.caller | |
1088 | + | let pmt = value(i.payments[0]) | |
1089 | + | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1090 | + | let pmtAmt = pmt.amount | |
1091 | + | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1092 | + | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1093 | + | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1094 | + | if ((currentDLp == currentDLp)) | |
407 | 1095 | then { | |
408 | - | let slippageAInv = if ((amDiff > 0)) | |
409 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
410 | - | else nil | |
411 | - | if ((slippageAInv == slippageAInv)) | |
1096 | + | let $t03831438472 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1097 | + | if (($t03831438472 == $t03831438472)) | |
412 | 1098 | then { | |
413 | - | let slippagePInv = if ((prDiff > 0)) | |
414 | - | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
415 | - | else nil | |
416 | - | if ((slippagePInv == slippagePInv)) | |
1099 | + | let feeAmount = $t03831438472._3 | |
1100 | + | let state = $t03831438472._2 | |
1101 | + | let estimLP = $t03831438472._1 | |
1102 | + | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1103 | + | then (minOutAmount > estimLP) | |
1104 | + | else false) | |
1105 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1106 | + | else estimLP | |
1107 | + | let e = invoke(fca, "emit", [emitLpAmt], nil) | |
1108 | + | if ((e == e)) | |
417 | 1109 | then { | |
418 | - | let lpTransfer = if (shouldAutoStake) | |
1110 | + | let el = match e { | |
1111 | + | case legacy: Address => | |
1112 | + | invoke(legacy, "emit", [emitLpAmt], nil) | |
1113 | + | case _ => | |
1114 | + | unit | |
1115 | + | } | |
1116 | + | if ((el == el)) | |
419 | 1117 | then { | |
420 | - | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
421 | - | if ((slpStakeInv == slpStakeInv)) | |
422 | - | then nil | |
1118 | + | let lpTrnsfr = if (autoStake) | |
1119 | + | then { | |
1120 | + | let ss = invoke(stakingContract, "stake", nil, [AttachedPayment(lpId, emitLpAmt)]) | |
1121 | + | if ((ss == ss)) | |
1122 | + | then nil | |
1123 | + | else throw("Strict value is not equal to itself.") | |
1124 | + | } | |
1125 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1126 | + | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1127 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1128 | + | else nil | |
1129 | + | let $t03928739636 = if ((this == feeCollectorAddress)) | |
1130 | + | then $Tuple2(0, 0) | |
1131 | + | else { | |
1132 | + | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1133 | + | then true | |
1134 | + | else false | |
1135 | + | if (paymentInAmountAsset) | |
1136 | + | then $Tuple2(-(feeAmount), 0) | |
1137 | + | else $Tuple2(0, -(feeAmount)) | |
1138 | + | } | |
1139 | + | let amountAssetBalanceDelta = $t03928739636._1 | |
1140 | + | let priceAssetBalanceDelta = $t03928739636._2 | |
1141 | + | let $t03963939747 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1142 | + | let refreshDLpActions = $t03963939747._1 | |
1143 | + | let updatedDLp = $t03963939747._2 | |
1144 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1145 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1146 | + | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
423 | 1147 | else throw("Strict value is not equal to itself.") | |
424 | 1148 | } | |
425 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
426 | - | (state ++ lpTransfer) | |
1149 | + | else throw("Strict value is not equal to itself.") | |
427 | 1150 | } | |
428 | 1151 | else throw("Strict value is not equal to itself.") | |
429 | 1152 | } | |
430 | 1153 | else throw("Strict value is not equal to itself.") | |
431 | 1154 | } | |
432 | 1155 | else throw("Strict value is not equal to itself.") | |
433 | 1156 | } | |
434 | - | } | |
435 | - | ||
436 | - | ||
437 | - | ||
438 | - | @Callable(i) | |
439 | - | func putForFree (maxSlippage) = if ((0 > maxSlippage)) | |
440 | - | then throw("Invalid value passed") | |
441 | - | else { | |
442 | - | let estPut = commonPut(i, maxSlippage, false) | |
443 | - | estPut._9 | |
444 | - | } | |
445 | - | ||
446 | - | ||
447 | - | ||
448 | - | @Callable(i) | |
449 | - | func get () = { | |
450 | - | let res = commonGet(i) | |
451 | - | let outAmtAmt = res._1 | |
452 | - | let outPrAmt = res._2 | |
453 | - | let pmtAmt = res._3 | |
454 | - | let pmtAssetId = res._4 | |
455 | - | let state = res._5 | |
456 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
457 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
458 | - | then state | |
459 | 1157 | else throw("Strict value is not equal to itself.") | |
460 | 1158 | } | |
461 | 1159 | ||
462 | 1160 | ||
463 | 1161 | ||
464 | 1162 | @Callable(i) | |
1163 | + | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1164 | + | then throw("Wrong slpg") | |
1165 | + | else if ((size(i.payments) != 2)) | |
1166 | + | then throw("2 pmnts expd") | |
1167 | + | else { | |
1168 | + | let estPut = cp(toString(i.caller), toBase58String(i.transactionId), AttachedPayment(value(i.payments[0]).assetId, value(i.payments[0]).amount), i.payments[1], maxSlpg, false, false, true, 0, "") | |
1169 | + | let state = estPut._9 | |
1170 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1171 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1172 | + | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1173 | + | if ((currentDLp == currentDLp)) | |
1174 | + | then { | |
1175 | + | let $t04077740842 = refreshDLpInternal(0, 0, 0) | |
1176 | + | let refreshDLpActions = $t04077740842._1 | |
1177 | + | let updatedDLp = $t04077740842._2 | |
1178 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1179 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1180 | + | then (state ++ refreshDLpActions) | |
1181 | + | else throw("Strict value is not equal to itself.") | |
1182 | + | } | |
1183 | + | else throw("Strict value is not equal to itself.") | |
1184 | + | } | |
1185 | + | ||
1186 | + | ||
1187 | + | ||
1188 | + | @Callable(i) | |
1189 | + | func get () = { | |
1190 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1191 | + | if ((currentDLp == currentDLp)) | |
1192 | + | then { | |
1193 | + | let r = cg(i) | |
1194 | + | let outAmtAmt = r._1 | |
1195 | + | let outPrAmt = r._2 | |
1196 | + | let pmtAmt = r._3 | |
1197 | + | let pmtAssetId = r._4 | |
1198 | + | let state = r._5 | |
1199 | + | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1200 | + | if ((b == b)) | |
1201 | + | then { | |
1202 | + | let $t04201542097 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1203 | + | let refreshDLpActions = $t04201542097._1 | |
1204 | + | let updatedDLp = $t04201542097._2 | |
1205 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1206 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1207 | + | then (state ++ refreshDLpActions) | |
1208 | + | else throw("Strict value is not equal to itself.") | |
1209 | + | } | |
1210 | + | else throw("Strict value is not equal to itself.") | |
1211 | + | } | |
1212 | + | else throw("Strict value is not equal to itself.") | |
1213 | + | } | |
1214 | + | ||
1215 | + | ||
1216 | + | ||
1217 | + | @Callable(i) | |
1218 | + | func getOneTknV2 (outAssetId,minOutAmount) = { | |
1219 | + | let isPoolOneTokenOperationsDisabled = { | |
1220 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1221 | + | if ($isInstanceOf(@, "Boolean")) | |
1222 | + | then @ | |
1223 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1224 | + | } | |
1225 | + | let isGetDisabled = if (if (igs()) | |
1226 | + | then true | |
1227 | + | else (cfgPoolStatus == PoolShutdown)) | |
1228 | + | then true | |
1229 | + | else isPoolOneTokenOperationsDisabled | |
1230 | + | let checks = [if (if (!(isGetDisabled)) | |
1231 | + | then true | |
1232 | + | else isManager(i)) | |
1233 | + | then true | |
1234 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1235 | + | then true | |
1236 | + | else throwErr("exactly 1 payment are expected")] | |
1237 | + | if ((checks == checks)) | |
1238 | + | then { | |
1239 | + | let $t04271542870 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1240 | + | let state = $t04271542870._1 | |
1241 | + | let totalAmount = $t04271542870._2 | |
1242 | + | $Tuple2(state, totalAmount) | |
1243 | + | } | |
1244 | + | else throw("Strict value is not equal to itself.") | |
1245 | + | } | |
1246 | + | ||
1247 | + | ||
1248 | + | ||
1249 | + | @Callable(i) | |
1250 | + | func refreshDLp () = { | |
1251 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1252 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1253 | + | then unit | |
1254 | + | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1255 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1256 | + | then { | |
1257 | + | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1258 | + | let $t04339443458 = refreshDLpInternal(0, 0, 0) | |
1259 | + | let dLpUpdateActions = $t04339443458._1 | |
1260 | + | let updatedDLp = $t04339443458._2 | |
1261 | + | let actions = if ((dLp != updatedDLp)) | |
1262 | + | then dLpUpdateActions | |
1263 | + | else throwErr("nothing to refresh") | |
1264 | + | $Tuple2(actions, toString(updatedDLp)) | |
1265 | + | } | |
1266 | + | else throw("Strict value is not equal to itself.") | |
1267 | + | } | |
1268 | + | ||
1269 | + | ||
1270 | + | ||
1271 | + | @Callable(i) | |
1272 | + | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1273 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1274 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1275 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1276 | + | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1277 | + | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1278 | + | let D0 = getD(xp) | |
1279 | + | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1280 | + | let index = if ((outAssetId == amId)) | |
1281 | + | then 0 | |
1282 | + | else if ((outAssetId == prId)) | |
1283 | + | then 1 | |
1284 | + | else throw("invalid out asset id") | |
1285 | + | let newY = getYD(xp, index, D1) | |
1286 | + | let dy = (xp[index] - newY) | |
1287 | + | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1288 | + | let $t04438844443 = takeFee(totalGetRaw, outFee) | |
1289 | + | let totalGet = $t04438844443._1 | |
1290 | + | let feeAmount = $t04438844443._2 | |
1291 | + | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1292 | + | } | |
1293 | + | ||
1294 | + | ||
1295 | + | ||
1296 | + | @Callable(i) | |
1297 | + | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1298 | + | let amId = toBase58String(value(cfgAmountAssetId)) | |
1299 | + | let prId = toBase58String(value(cfgPriceAssetId)) | |
1300 | + | let lpId = toBase58String(value(cfgLpAssetId)) | |
1301 | + | let amBalance = getAccBalance(amId) | |
1302 | + | let prBalance = getAccBalance(prId) | |
1303 | + | let $t04481844933 = { | |
1304 | + | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1305 | + | if ($isInstanceOf(@, "(Int, Int)")) | |
1306 | + | then @ | |
1307 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1308 | + | } | |
1309 | + | let totalGet = $t04481844933._1 | |
1310 | + | let feeAmount = $t04481844933._2 | |
1311 | + | let r = ego("", lpId, lpAssetAmount, this) | |
1312 | + | let outAmAmt = r._1 | |
1313 | + | let outPrAmt = r._2 | |
1314 | + | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1315 | + | let bonus = if ((sumOfGetAssets == 0)) | |
1316 | + | then if ((totalGet == 0)) | |
1317 | + | then 0 | |
1318 | + | else throw("bonus calculation error") | |
1319 | + | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1320 | + | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1321 | + | } | |
1322 | + | ||
1323 | + | ||
1324 | + | ||
1325 | + | @Callable(i) | |
465 | 1326 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
466 | - | let | |
467 | - | let outAmAmt = | |
468 | - | let outPrAmt = | |
469 | - | let pmtAmt = | |
470 | - | let pmtAssetId = | |
471 | - | let state = | |
1327 | + | let r = cg(i) | |
1328 | + | let outAmAmt = r._1 | |
1329 | + | let outPrAmt = r._2 | |
1330 | + | let pmtAmt = r._3 | |
1331 | + | let pmtAssetId = r._4 | |
1332 | + | let state = r._5 | |
472 | 1333 | if ((noLessThenAmtAsset > outAmAmt)) | |
473 | - | then throw((((" | |
1334 | + | then throw(((("Failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
474 | 1335 | else if ((noLessThenPriceAsset > outPrAmt)) | |
475 | - | then throw((((" | |
1336 | + | then throw(((("Failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
476 | 1337 | else { | |
477 | - | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
478 | - | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
479 | - | then state | |
1338 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1339 | + | if ((currentDLp == currentDLp)) | |
1340 | + | then { | |
1341 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1342 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1343 | + | then { | |
1344 | + | let $t04609946180 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1345 | + | let refreshDLpActions = $t04609946180._1 | |
1346 | + | let updatedDLp = $t04609946180._2 | |
1347 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1348 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1349 | + | then (state ++ refreshDLpActions) | |
1350 | + | else throw("Strict value is not equal to itself.") | |
1351 | + | } | |
1352 | + | else throw("Strict value is not equal to itself.") | |
1353 | + | } | |
480 | 1354 | else throw("Strict value is not equal to itself.") | |
481 | 1355 | } | |
482 | 1356 | } | |
483 | 1357 | ||
484 | 1358 | ||
485 | 1359 | ||
486 | 1360 | @Callable(i) | |
487 | - | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
488 | - | then throw("permissions denied") | |
489 | - | else $Tuple2([StringEntry(keyAmtAsset(), amtAssetStr), StringEntry(keyPriceAsset(), priceAssetStr)], "success") | |
1361 | + | func unstakeAndGet (amount) = { | |
1362 | + | let checkPayments = if ((size(i.payments) != 0)) | |
1363 | + | then throw("No pmnts expd") | |
1364 | + | else true | |
1365 | + | if ((checkPayments == checkPayments)) | |
1366 | + | then { | |
1367 | + | let factoryCfg = gfc() | |
1368 | + | let lpAssetId = cfgLpAssetId | |
1369 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1370 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1371 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1372 | + | if ((unstakeInv == unstakeInv)) | |
1373 | + | then { | |
1374 | + | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1375 | + | let outAmAmt = r._1 | |
1376 | + | let outPrAmt = r._2 | |
1377 | + | let sts = parseIntValue(r._9) | |
1378 | + | let state = r._10 | |
1379 | + | let v = if (if (igs()) | |
1380 | + | then true | |
1381 | + | else (sts == PoolShutdown)) | |
1382 | + | then throw(("Blocked: " + toString(sts))) | |
1383 | + | else true | |
1384 | + | if ((v == v)) | |
1385 | + | then { | |
1386 | + | let burnA = invoke(fca, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1387 | + | if ((burnA == burnA)) | |
1388 | + | then { | |
1389 | + | let $t04720447285 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1390 | + | let refreshDLpActions = $t04720447285._1 | |
1391 | + | let updatedDLp = $t04720447285._2 | |
1392 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1393 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1394 | + | then (state ++ refreshDLpActions) | |
1395 | + | else throw("Strict value is not equal to itself.") | |
1396 | + | } | |
1397 | + | else throw("Strict value is not equal to itself.") | |
1398 | + | } | |
1399 | + | else throw("Strict value is not equal to itself.") | |
1400 | + | } | |
1401 | + | else throw("Strict value is not equal to itself.") | |
1402 | + | } | |
1403 | + | else throw("Strict value is not equal to itself.") | |
1404 | + | } | |
490 | 1405 | ||
491 | 1406 | ||
492 | 1407 | ||
493 | 1408 | @Callable(i) | |
494 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1409 | + | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1410 | + | let isGetDisabled = if (igs()) | |
1411 | + | then true | |
1412 | + | else (cfgPoolStatus == PoolShutdown) | |
1413 | + | let checks = [if (!(isGetDisabled)) | |
1414 | + | then true | |
1415 | + | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1416 | + | then true | |
1417 | + | else throw("no payments are expected")] | |
1418 | + | if ((checks == checks)) | |
1419 | + | then { | |
1420 | + | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1421 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1422 | + | if ((unstakeInv == unstakeInv)) | |
1423 | + | then { | |
1424 | + | let res = ego(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1425 | + | let outAmAmt = res._1 | |
1426 | + | let outPrAmt = res._2 | |
1427 | + | let state = res._10 | |
1428 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1429 | + | then true | |
1430 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1431 | + | then true | |
1432 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1433 | + | if ((checkAmounts == checkAmounts)) | |
1434 | + | then { | |
1435 | + | let burnLPAssetOnFactory = invoke(fca, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1436 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1437 | + | then { | |
1438 | + | let $t04853348614 = refreshDLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1439 | + | let refreshDLpActions = $t04853348614._1 | |
1440 | + | let updatedDLp = $t04853348614._2 | |
1441 | + | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1442 | + | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1443 | + | then (state ++ refreshDLpActions) | |
1444 | + | else throw("Strict value is not equal to itself.") | |
1445 | + | } | |
1446 | + | else throw("Strict value is not equal to itself.") | |
1447 | + | } | |
1448 | + | else throw("Strict value is not equal to itself.") | |
1449 | + | } | |
1450 | + | else throw("Strict value is not equal to itself.") | |
1451 | + | } | |
1452 | + | else throw("Strict value is not equal to itself.") | |
1453 | + | } | |
1454 | + | ||
1455 | + | ||
1456 | + | ||
1457 | + | @Callable(i) | |
1458 | + | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1459 | + | let isPoolOneTokenOperationsDisabled = { | |
1460 | + | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1461 | + | if ($isInstanceOf(@, "Boolean")) | |
1462 | + | then @ | |
1463 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1464 | + | } | |
1465 | + | let isGetDisabled = if (if (igs()) | |
1466 | + | then true | |
1467 | + | else (cfgPoolStatus == PoolShutdown)) | |
1468 | + | then true | |
1469 | + | else isPoolOneTokenOperationsDisabled | |
1470 | + | let checks = [if (if (!(isGetDisabled)) | |
1471 | + | then true | |
1472 | + | else isManager(i)) | |
1473 | + | then true | |
1474 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1475 | + | then true | |
1476 | + | else throwErr("no payments are expected")] | |
1477 | + | if ((checks == checks)) | |
1478 | + | then { | |
1479 | + | let factoryCfg = gfc() | |
1480 | + | let lpAssetId = cfgLpAssetId | |
1481 | + | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1482 | + | let unstakeInv = invoke(staking, "unstake", [toBase58String(lpAssetId), unstakeAmount], nil) | |
1483 | + | if ((unstakeInv == unstakeInv)) | |
1484 | + | then { | |
1485 | + | let $t04950949697 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1486 | + | let state = $t04950949697._1 | |
1487 | + | let totalAmount = $t04950949697._2 | |
1488 | + | $Tuple2(state, totalAmount) | |
1489 | + | } | |
1490 | + | else throw("Strict value is not equal to itself.") | |
1491 | + | } | |
1492 | + | else throw("Strict value is not equal to itself.") | |
1493 | + | } | |
1494 | + | ||
1495 | + | ||
1496 | + | ||
1497 | + | @Callable(i) | |
1498 | + | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1499 | + | let $t04982549928 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1500 | + | let lpAmount = $t04982549928._1 | |
1501 | + | let state = $t04982549928._2 | |
1502 | + | let feeAmount = $t04982549928._3 | |
1503 | + | let bonus = $t04982549928._4 | |
1504 | + | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1505 | + | } | |
1506 | + | ||
1507 | + | ||
1508 | + | ||
1509 | + | @Callable(i) | |
1510 | + | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1511 | + | let $t05007650180 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1512 | + | let lpAmount = $t05007650180._1 | |
1513 | + | let state = $t05007650180._2 | |
1514 | + | let feeAmount = $t05007650180._3 | |
1515 | + | let bonus = $t05007650180._4 | |
1516 | + | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1517 | + | } | |
1518 | + | ||
1519 | + | ||
1520 | + | ||
1521 | + | @Callable(i) | |
1522 | + | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1523 | + | then throw("denied") | |
1524 | + | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr)], "success") | |
1525 | + | ||
1526 | + | ||
1527 | + | ||
1528 | + | @Callable(i) | |
1529 | + | func setS (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1530 | + | then pd | |
1531 | + | else [StringEntry(k, v)] | |
1532 | + | ||
1533 | + | ||
1534 | + | ||
1535 | + | @Callable(i) | |
1536 | + | func setI (k,v) = if ((toString(i.caller) != strf(this, ada()))) | |
1537 | + | then pd | |
1538 | + | else [IntegerEntry(k, v)] | |
1539 | + | ||
1540 | + | ||
1541 | + | ||
1542 | + | @Callable(i) | |
1543 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
495 | 1544 | ||
496 | 1545 | ||
497 | 1546 | ||
498 | 1547 | @Callable(i) | |
499 | 1548 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
500 | 1549 | ||
501 | 1550 | ||
502 | 1551 | ||
503 | 1552 | @Callable(i) | |
504 | 1553 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
505 | - | let | |
506 | - | $Tuple2(nil, [toString( | |
1554 | + | let pr = calcPrices(amAmt, prAmt, lpAmt) | |
1555 | + | $Tuple2(nil, [toString(pr[0]), toString(pr[1]), toString(pr[2])]) | |
507 | 1556 | } | |
508 | 1557 | ||
509 | 1558 | ||
510 | 1559 | ||
511 | 1560 | @Callable(i) | |
512 | - | func fromX18WrapperREADONLY (val, | |
1561 | + | func fromX18WrapperREADONLY (val,resScaleMult) = $Tuple2(nil, f1(parseBigIntValue(val), resScaleMult)) | |
513 | 1562 | ||
514 | 1563 | ||
515 | 1564 | ||
516 | 1565 | @Callable(i) | |
517 | - | func statsREADONLY () = { | |
518 | - | let cfg = getPoolConfig() | |
519 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
520 | - | let amtAssetId = cfg[idxAmtAssetId] | |
521 | - | let priceAssetId = cfg[idxPriceAssetId] | |
522 | - | let iAmtAssetId = cfg[idxIAmtAssetId] | |
523 | - | let iPriceAssetId = cfg[idxIPriceAssetId] | |
524 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
525 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
526 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
527 | - | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
528 | - | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
529 | - | let pricesList = if ((poolLPBalance == 0)) | |
530 | - | then [zeroBigInt, zeroBigInt, zeroBigInt] | |
531 | - | else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance) | |
532 | - | let curPrice = 0 | |
533 | - | let lpAmtAssetShare = fromX18(pricesList[1], scale8) | |
534 | - | let lpPriceAssetShare = fromX18(pricesList[2], scale8) | |
535 | - | let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this)))) | |
536 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(accAmtAssetBalance), toString(accPriceAssetBalance), toString(poolLPBalance), toString(curPrice), toString(lpAmtAssetShare), toString(lpPriceAssetShare), toString(poolWeight)], SEP)) | |
537 | - | } | |
1566 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(t1(origVal, origScaleMult))) | |
538 | 1567 | ||
539 | 1568 | ||
540 | 1569 | ||
541 | 1570 | @Callable(i) | |
542 | - | func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = { | |
543 | - | let cfg = getPoolConfig() | |
544 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
545 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
546 | - | let amAssetId = fromBase58String(amAssetIdStr) | |
547 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
548 | - | let prAssetId = fromBase58String(prAssetIdStr) | |
549 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
550 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
551 | - | let poolStatus = cfg[idxPoolStatus] | |
552 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
553 | - | let accAmtAssetBalance = getAccBalance(amAssetIdStr) | |
554 | - | let accPriceAssetBalance = getAccBalance(prAssetIdStr) | |
555 | - | let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm) | |
556 | - | let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm) | |
557 | - | let curPriceX18 = if ((poolLPBalance == 0)) | |
558 | - | then zeroBigInt | |
559 | - | else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
560 | - | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
561 | - | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
562 | - | let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm) | |
563 | - | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
564 | - | let calcLpAmt = estPut._1 | |
565 | - | let curPriceCalc = estPut._3 | |
566 | - | let amBalance = estPut._4 | |
567 | - | let prBalance = estPut._5 | |
568 | - | let lpEmission = estPut._6 | |
569 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
570 | - | } | |
1571 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(cpbi(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
571 | 1572 | ||
572 | 1573 | ||
573 | 1574 | ||
574 | 1575 | @Callable(i) | |
575 | - | func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = { | |
576 | - | let cfg = getPoolConfig() | |
577 | - | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
578 | - | let amAssetIdStr = cfg[idxAmtAssetId] | |
579 | - | let amAssetId = fromBase58String(amAssetIdStr) | |
580 | - | let prAssetIdStr = cfg[idxPriceAssetId] | |
581 | - | let prAssetId = fromBase58String(prAssetIdStr) | |
582 | - | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
583 | - | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
584 | - | let poolStatus = cfg[idxPoolStatus] | |
585 | - | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
586 | - | let amBalanceRaw = getAccBalance(amAssetIdStr) | |
587 | - | let prBalanceRaw = getAccBalance(prAssetIdStr) | |
588 | - | let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm) | |
589 | - | let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm) | |
590 | - | let curPriceX18 = if ((poolLPBalance == 0)) | |
591 | - | then zeroBigInt | |
592 | - | else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18) | |
593 | - | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
594 | - | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
595 | - | let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm) | |
596 | - | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
597 | - | let calcLpAmt = estPut._1 | |
598 | - | let curPriceCalc = estPut._3 | |
599 | - | let amBalance = estPut._4 | |
600 | - | let prBalance = estPut._5 | |
601 | - | let lpEmission = estPut._6 | |
602 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d%d", toString(calcLpAmt), toString(fromX18(curPriceX18, scale8)), toString(amBalance), toString(prBalance), toString(lpEmission), poolStatus, toString(inAmAssetAmt), toString(inPrAssetAmt)], SEP)) | |
603 | - | } | |
1576 | + | func estimatePutOperationWrapperREADONLY (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,usrAddr,isEval,emitLp) = $Tuple2(nil, epo(txId58, slippage, inAmAmt, inAmId, inPrAmt, inPrId, usrAddr, isEval, emitLp, true, false, 0, "")) | |
604 | 1577 | ||
605 | 1578 | ||
606 | 1579 | ||
607 | 1580 | @Callable(i) | |
608 | - | func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { | |
609 | - | let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this) | |
610 | - | let outAmAmt = res._1 | |
611 | - | let outPrAmt = res._2 | |
612 | - | let amBalance = res._5 | |
613 | - | let prBalance = res._6 | |
614 | - | let lpEmission = res._7 | |
615 | - | let curPrice = res._8 | |
616 | - | let poolStatus = parseIntValue(res._9) | |
617 | - | $Tuple2(nil, makeString(["%d%d%d%d%d%d%d", toString(outAmAmt), toString(outPrAmt), toString(amBalance), toString(prBalance), toString(lpEmission), toString(curPrice), toString(poolStatus)], SEP)) | |
1581 | + | func estimateGetOperationWrapperREADONLY (txId58,pmtAsId,pmtLpAmt,usrAddr) = { | |
1582 | + | let r = ego(txId58, pmtAsId, pmtLpAmt, addressFromStringValue(usrAddr)) | |
1583 | + | $Tuple2(nil, $Tuple10(r._1, r._2, r._3, r._4, r._5, r._6, r._7, toString(r._8), r._9, r._10)) | |
618 | 1584 | } | |
619 | 1585 | ||
620 | 1586 | ||
621 | 1587 | @Verifier(tx) | |
622 | - | func verify () = match tx { | |
623 | - | case order: Order => | |
624 | - | let matcherPub = getMatcherPubOrFail() | |
625 | - | let orderValid = validateMatcherOrderAllowed(order) | |
626 | - | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
627 | - | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
628 | - | if (if (if (orderValid) | |
629 | - | then senderValid | |
630 | - | else false) | |
631 | - | then matcherValid | |
632 | - | else false) | |
633 | - | then true | |
634 | - | else throwOrderError(orderValid, senderValid, matcherValid) | |
635 | - | case _ => | |
636 | - | let managerPublic = valueOrElse(getString(this, keyManagerPublicKey()), EMPTY) | |
637 | - | if ((managerPublic == EMPTY)) | |
638 | - | then sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
639 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(managerPublic)) | |
640 | - | } | |
1588 | + | func verify () = { | |
1589 | + | let targetPublicKey = match m() { | |
1590 | + | case pk: ByteVector => | |
1591 | + | pk | |
1592 | + | case _: Unit => | |
1593 | + | tx.senderPublicKey | |
1594 | + | case _ => | |
1595 | + | throw("Match error") | |
1596 | + | } | |
1597 | + | match tx { | |
1598 | + | case order: Order => | |
1599 | + | let matcherPub = mp() | |
1600 | + | let orderValid = validateMatcherOrderAllowed(order) | |
1601 | + | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1602 | + | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1603 | + | if (if (if (orderValid) | |
1604 | + | then senderValid | |
1605 | + | else false) | |
1606 | + | then matcherValid | |
1607 | + | else false) | |
1608 | + | then true | |
1609 | + | else toe(orderValid, senderValid, matcherValid) | |
1610 | + | case s: SetScriptTransaction => | |
1611 | + | let newHash = blake2b256(value(s.script)) | |
1612 | + | let allowedHash = fromBase64String(value(getString(fca, keyAllowedLpStableScriptHash()))) | |
1613 | + | let currentHash = scriptHash(this) | |
1614 | + | if (if ((allowedHash == newHash)) | |
1615 | + | then (currentHash != newHash) | |
1616 | + | else false) | |
1617 | + | then true | |
1618 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1619 | + | case _ => | |
1620 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1621 | + | } | |
1622 | + | } | |
641 | 1623 |
github/deemru/w8io/169f3d6 188.72 ms ◑