tx · 5uQwzpnfzzVeAj3sR4JWNdDQw4zCjXk4o36DX4pPzYFk 3MuibHtY4WMNqE2AgpPjm9fuDar6TUNCThP: -0.04300000 Waves 2023.05.05 11:40 [2564284] smart account 3MuibHtY4WMNqE2AgpPjm9fuDar6TUNCThP > SELF 0.00000000 Waves
{ "type": 13, "id": "5uQwzpnfzzVeAj3sR4JWNdDQw4zCjXk4o36DX4pPzYFk", "fee": 4300000, "feeAssetId": null, "timestamp": 1683276013048, "version": 2, "chainId": 84, "sender": "3MuibHtY4WMNqE2AgpPjm9fuDar6TUNCThP", "senderPublicKey": "5K6j2MTCQttt7Dt3hR4msP7sjtJ4LWVPHbUjbG485Lxw", "proofs": [ "5aYSH1FWZvuu3eF5vDiikAjV8iSBoQ9HRZrTQwT3RCGe8mJxrb99kDdu1gEMiEkBoWAHKALC2UzMyQsHd4AGTRnH" ], "script": "base64:BgL3NwgCEgASBQoDAQQBEgcKBQEEAQgBEgMKAQgSABIECgIBBBIDCgEBEgQKAgEEEgQKAggBEgQKAggBEgQKAggBEgUKAwEIARIAEgQKAgEBEgMKAQESBQoDAQEBEgQKAggIEgASABIDCgEIEgUKAwEBARIECgIBARIECgIIARIECgIICBILCgkIAQECAQIIBAQSBgoECAgBCBIAEgMKAQESAwoBARIECgIIASIKbFBkZWNpbWFscyIGc2NhbGU4IgxzY2FsZThCaWdJbnQiB3NjYWxlMTgiCnplcm9CaWdJbnQiBGJpZzAiBGJpZzEiBGJpZzIiC3dhdmVzU3RyaW5nIgNTRVAiClBvb2xBY3RpdmUiD1Bvb2xQdXREaXNhYmxlZCITUG9vbE1hdGNoZXJEaXNhYmxlZCIMUG9vbFNodXRkb3duIg5pZHhQb29sQWRkcmVzcyINaWR4UG9vbFN0YXR1cyIQaWR4UG9vbExQQXNzZXRJZCINaWR4QW10QXNzZXRJZCIPaWR4UHJpY2VBc3NldElkIg5pZHhBbXRBc3NldERjbSIQaWR4UHJpY2VBc3NldERjbSIOaWR4SUFtdEFzc2V0SW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zAAEFAmltAwMDBQJhSwUCYU0HBQJhTgcGCQECYUoEBQJhSwUCYUwFAmFNBQJhTgMJAAECBQJiVgIUU2V0U2NyaXB0VHJhbnNhY3Rpb24EAmdpBQJiVgMJAPQDAwgFAmlqCWJvZHlCeXRlcwkAkQMCCAUCaWoGcHJvb2ZzAAAFAmlsBgQCaW8JAPYDAQkBBXZhbHVlAQgFAmdpBnNjcmlwdAQCaXAJANsEAQkBBXZhbHVlAQkAnQgCBQJhVgkBAmFGAAQCaXEJAPEHAQUEdGhpcwMJAAACBQJpcAUCaW8JAQIhPQIFAmlxBQJpbwcJAPQDAwgFAmlqCWJvZHlCeXRlcwkAkQMCCAUCaWoGcHJvb2ZzAAAFAmlsLmY3kQ==", "height": 2564284, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7w7DCGoHSiAGtfZ642bWpA4qyHp38nVx7emus16mV5zg Next: 7CKTRDBXJapoTymAYJxmVuixMZQjBmZQLAVetc33Yct3 Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let lPdecimals = 8 | |
5 | + | ||
4 | 6 | let scale8 = 100000000 | |
5 | 7 | ||
6 | 8 | let scale8BigInt = toBigInt(100000000) | |
15 | 17 | ||
16 | 18 | let big2 = toBigInt(2) | |
17 | 19 | ||
18 | - | let big3 = toBigInt(3) | |
19 | - | ||
20 | - | let big4 = toBigInt(4) | |
21 | - | ||
22 | 20 | let wavesString = "WAVES" | |
23 | - | ||
24 | - | let ampInitial = 50 | |
25 | - | ||
26 | - | let Amult = "100" | |
27 | 21 | ||
28 | 22 | let SEP = "__" | |
29 | 23 | ||
30 | - | let | |
24 | + | let PoolActive = 1 | |
31 | 25 | ||
32 | - | let PoolMatcherDis = 3 | |
26 | + | let PoolPutDisabled = 2 | |
27 | + | ||
28 | + | let PoolMatcherDisabled = 3 | |
33 | 29 | ||
34 | 30 | let PoolShutdown = 4 | |
35 | 31 | ||
36 | 32 | let idxPoolAddress = 1 | |
37 | 33 | ||
38 | - | let | |
34 | + | let idxPoolStatus = 2 | |
39 | 35 | ||
40 | - | let | |
36 | + | let idxPoolLPAssetId = 3 | |
41 | 37 | ||
42 | - | let | |
38 | + | let idxAmtAssetId = 4 | |
43 | 39 | ||
44 | - | let | |
40 | + | let idxPriceAssetId = 5 | |
45 | 41 | ||
46 | - | let | |
42 | + | let idxAmtAssetDcm = 6 | |
47 | 43 | ||
48 | - | let | |
44 | + | let idxPriceAssetDcm = 7 | |
49 | 45 | ||
50 | - | let | |
46 | + | let idxIAmtAssetId = 8 | |
51 | 47 | ||
52 | - | let | |
48 | + | let idxIPriceAssetId = 9 | |
53 | 49 | ||
54 | - | let | |
50 | + | let idxLPAssetDcm = 10 | |
55 | 51 | ||
56 | - | let | |
52 | + | let idxPoolAmtAssetAmt = 1 | |
57 | 53 | ||
58 | - | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
54 | + | let idxPoolPriceAssetAmt = 2 | |
55 | + | ||
56 | + | let idxPoolLPAssetAmt = 3 | |
57 | + | ||
58 | + | let idxFactoryStakingContract = 1 | |
59 | + | ||
60 | + | let idxFactorySlippageContract = 7 | |
61 | + | ||
62 | + | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
59 | 63 | ||
60 | 64 | ||
61 | - | func | |
65 | + | func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
62 | 66 | ||
63 | 67 | ||
64 | - | func | |
68 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
65 | 69 | ||
66 | 70 | ||
67 | 71 | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
68 | 72 | ||
69 | 73 | ||
70 | - | func abs (val) = if ((zeroBigInt > val)) | |
74 | + | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
75 | + | ||
76 | + | ||
77 | + | func abs (val) = if ((0 > val)) | |
71 | 78 | then -(val) | |
72 | 79 | else val | |
73 | 80 | ||
75 | 82 | func absBigInt (val) = if ((zeroBigInt > val)) | |
76 | 83 | then -(val) | |
77 | 84 | else val | |
85 | + | ||
86 | + | ||
87 | + | func swapContract () = "%s__swapContract" | |
78 | 88 | ||
79 | 89 | ||
80 | 90 | func fc () = "%s__factoryContract" | |
89 | 99 | func pl () = "%s%s__price__last" | |
90 | 100 | ||
91 | 101 | ||
92 | - | func ph (h, | |
102 | + | func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP) | |
93 | 103 | ||
94 | 104 | ||
95 | - | func pau ( | |
105 | + | func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId) | |
96 | 106 | ||
97 | 107 | ||
98 | - | func gau ( | |
108 | + | func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId) | |
99 | 109 | ||
100 | 110 | ||
101 | 111 | func aa () = "%s__amountAsset" | |
104 | 114 | func pa () = "%s__priceAsset" | |
105 | 115 | ||
106 | 116 | ||
107 | - | ||
117 | + | let keyFee = "%s__fee" | |
108 | 118 | ||
109 | - | ||
110 | - | func keyAmpHistory (heightBlocks) = ("%s%d__amp__" + toString(heightBlocks)) | |
111 | - | ||
112 | - | ||
113 | - | func keyChangeAmpLastCall () = "%s__changeAmpLastCall" | |
114 | - | ||
115 | - | ||
116 | - | let keyFee = "%s__fee" | |
119 | + | let feeDefault = fraction(10, scale8, 10000) | |
117 | 120 | ||
118 | 121 | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
119 | 122 | ||
120 | - | let | |
123 | + | let keyKLp = makeString(["%s", "kLp"], SEP) | |
121 | 124 | ||
122 | - | let | |
125 | + | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
123 | 126 | ||
124 | - | let | |
127 | + | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
125 | 128 | ||
126 | - | let | |
129 | + | let kLpRefreshDelayDefault = 30 | |
127 | 130 | ||
128 | - | let | |
131 | + | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
129 | 132 | ||
130 | - | func | |
133 | + | func keyAdditionalBalance (assetId) = makeString(["%s%s", "stakedBalance", assetId], SEP) | |
131 | 134 | ||
132 | 135 | ||
133 | - | func | |
136 | + | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "shareAssetBalance", assetId], SEP) | |
134 | 137 | ||
135 | 138 | ||
136 | - | func | |
139 | + | func getAdditionalBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyAdditionalBalance(assetId)), 0) | |
137 | 140 | ||
138 | 141 | ||
139 | - | func | |
142 | + | func getStakingAssetBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
140 | 143 | ||
141 | 144 | ||
142 | - | func | |
145 | + | func keyFactoryConfig () = "%s__factoryConfig" | |
143 | 146 | ||
144 | 147 | ||
145 | - | func | |
148 | + | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
146 | 149 | ||
147 | 150 | ||
148 | - | func | |
151 | + | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") | |
149 | 152 | ||
153 | + | ||
154 | + | func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config") | |
155 | + | ||
156 | + | ||
157 | + | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) | |
158 | + | ||
159 | + | ||
160 | + | func keyAllPoolsShutdown () = "%s__shutdown" | |
161 | + | ||
162 | + | ||
163 | + | func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress) | |
164 | + | ||
165 | + | ||
166 | + | func keyAllowedLpScriptHash () = "%s__allowedLpScriptHash" | |
167 | + | ||
168 | + | ||
169 | + | let keyFeeCollectorAddress = "%s__feeCollectorAddress" | |
150 | 170 | ||
151 | 171 | func keySkipOrderValidation (poolAddress) = ("%s%s__skipOrderValidation__" + poolAddress) | |
152 | 172 | ||
154 | 174 | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
155 | 175 | ||
156 | 176 | ||
157 | - | func | |
177 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
158 | 178 | ||
159 | 179 | ||
160 | - | func | |
180 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
161 | 181 | ||
162 | 182 | ||
163 | - | func throwErr (msg) = throw(makeString(["lp | |
183 | + | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
164 | 184 | ||
165 | 185 | ||
166 | - | func fmtErr (msg) = makeString(["lp | |
186 | + | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
167 | 187 | ||
168 | 188 | ||
169 | - | let fca = addressFromStringValue(strf(this, fc())) | |
189 | + | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
190 | + | ||
191 | + | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
170 | 192 | ||
171 | 193 | let inFee = { | |
172 | - | let @ = invoke( | |
194 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
173 | 195 | if ($isInstanceOf(@, "Int")) | |
174 | 196 | then @ | |
175 | 197 | else throw(($getType(@) + " couldn't be cast to Int")) | |
176 | 198 | } | |
177 | 199 | ||
178 | 200 | let outFee = { | |
179 | - | let @ = invoke( | |
201 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
180 | 202 | if ($isInstanceOf(@, "Int")) | |
181 | 203 | then @ | |
182 | 204 | else throw(($getType(@) + " couldn't be cast to Int")) | |
183 | 205 | } | |
184 | 206 | ||
185 | - | let A = strf(this, amp()) | |
186 | - | ||
187 | - | func igs () = valueOrElse(getBoolean(fca, aps()), false) | |
207 | + | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
188 | 208 | ||
189 | 209 | ||
190 | - | func | |
210 | + | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
191 | 211 | ||
192 | 212 | ||
193 | - | let feeCollectorAddress = addressFromStringValue(strf(fca, keyFeeCollectorAddress())) | |
194 | - | ||
195 | - | func gpc () = { | |
196 | - | let amtAs = strf(this, aa()) | |
197 | - | let priceAs = strf(this, pa()) | |
198 | - | let iPriceAs = intf(fca, mba(priceAs)) | |
199 | - | let iAmtAs = intf(fca, mba(amtAs)) | |
200 | - | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
213 | + | func getPoolConfig () = { | |
214 | + | let amtAsset = getStringOrFail(this, aa()) | |
215 | + | let priceAsset = getStringOrFail(this, pa()) | |
216 | + | let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset)) | |
217 | + | let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset)) | |
218 | + | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP) | |
201 | 219 | } | |
202 | 220 | ||
203 | 221 | ||
211 | 229 | else toBase58String(value(input)) | |
212 | 230 | ||
213 | 231 | ||
214 | - | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[ | |
232 | + | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolStatus]), fromBase58String(poolConfig[idxPoolLPAssetId]), parseAssetId(poolConfig[idxAmtAssetId]), parseAssetId(poolConfig[idxPriceAssetId]), parseIntValue(poolConfig[idxAmtAssetDcm]), parseIntValue(poolConfig[idxPriceAssetDcm])) | |
215 | 233 | ||
216 | 234 | ||
217 | - | let poolConfigParsed = parsePoolConfig( | |
235 | + | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
218 | 236 | ||
219 | - | let $ | |
237 | + | let $t090589224 = poolConfigParsed | |
220 | 238 | ||
221 | - | let | |
239 | + | let cfgPoolAddress = $t090589224._1 | |
222 | 240 | ||
223 | - | let | |
241 | + | let cfgPoolStatus = $t090589224._2 | |
224 | 242 | ||
225 | - | let | |
243 | + | let cfgLpAssetId = $t090589224._3 | |
226 | 244 | ||
227 | - | let | |
245 | + | let cfgAmountAssetId = $t090589224._4 | |
228 | 246 | ||
229 | - | let | |
247 | + | let cfgPriceAssetId = $t090589224._5 | |
230 | 248 | ||
231 | - | let | |
249 | + | let cfgAmountAssetDecimals = $t090589224._6 | |
232 | 250 | ||
233 | - | func gfc () = split(strf(fca, fcfg()), SEP) | |
251 | + | let cfgPriceAssetDecimals = $t090589224._7 | |
252 | + | ||
253 | + | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
234 | 254 | ||
235 | 255 | ||
236 | - | let | |
256 | + | let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address") | |
237 | 257 | ||
238 | - | let | |
258 | + | let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address") | |
239 | 259 | ||
240 | - | let restContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactoryRestCntr]), "Invalid gwx contract address") | |
241 | - | ||
242 | - | 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) | |
260 | + | 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) | |
243 | 261 | ||
244 | 262 | ||
245 | 263 | 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) | |
246 | 264 | ||
247 | 265 | ||
248 | - | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
249 | - | then wavesBalance(this).available | |
250 | - | else assetBalance(this, fromBase58String(assetId)) | |
266 | + | func getAccBalance (assetId) = { | |
267 | + | let balanceOnPool = if ((assetId == "WAVES")) | |
268 | + | then wavesBalance(this).available | |
269 | + | else assetBalance(this, fromBase58String(assetId)) | |
270 | + | let totalBalance = ((balanceOnPool + getAdditionalBalanceOrZero(assetId)) - getStakingAssetBalanceOrZero(assetId)) | |
271 | + | max([0, totalBalance]) | |
272 | + | } | |
251 | 273 | ||
252 | 274 | ||
253 | - | func | |
275 | + | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
254 | 276 | ||
255 | 277 | ||
256 | - | func | |
278 | + | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
257 | 279 | ||
258 | 280 | ||
259 | - | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
260 | - | let amtAsAmtX18 = t1(amAmt, amAssetDcm) | |
261 | - | let prAsAmtX18 = t1(prAmt, prAssetDcm) | |
262 | - | cpbi(prAsAmtX18, amtAsAmtX18) | |
281 | + | func getRate (proxy) = { | |
282 | + | let inv = invoke(proxy, "getRate", nil, nil) | |
283 | + | if ((inv == inv)) | |
284 | + | then match inv { | |
285 | + | case r: Int => | |
286 | + | r | |
287 | + | case _ => | |
288 | + | throwErr("proxy.getRate() unexpected value") | |
289 | + | } | |
290 | + | else throw("Strict value is not equal to itself.") | |
291 | + | } | |
292 | + | ||
293 | + | ||
294 | + | func deposit (assetId,amount,stakingAssetId,proxy) = { | |
295 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
296 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
297 | + | then { | |
298 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
299 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
300 | + | then { | |
301 | + | let asset = parseAssetId(assetId) | |
302 | + | if ((amount > 0)) | |
303 | + | then { | |
304 | + | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(asset, amount)]) | |
305 | + | if ((depositInvoke == depositInvoke)) | |
306 | + | then match depositInvoke { | |
307 | + | case receivedStakingAsset: Int => | |
308 | + | let newAdditionalBalance = (currentAdditionalBalance + amount) | |
309 | + | let newStakingAssetBalance = (currentStakingAssetBalance + receivedStakingAsset) | |
310 | + | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newStakingAssetBalance)] | |
311 | + | case _ => | |
312 | + | nil | |
313 | + | } | |
314 | + | else throw("Strict value is not equal to itself.") | |
315 | + | } | |
316 | + | else nil | |
317 | + | } | |
318 | + | else throw("Strict value is not equal to itself.") | |
319 | + | } | |
320 | + | else throw("Strict value is not equal to itself.") | |
321 | + | } | |
322 | + | ||
323 | + | ||
324 | + | func withdraw (assetId,amount,stakingAssetId,proxy,proxyRateMul,profitAddress) = { | |
325 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
326 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
327 | + | then { | |
328 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
329 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
330 | + | then { | |
331 | + | let currentProxyRate = getRate(proxy) | |
332 | + | if ((currentProxyRate == currentProxyRate)) | |
333 | + | then { | |
334 | + | let oldRate = fraction(proxyRateMul, currentAdditionalBalance, currentStakingAssetBalance) | |
335 | + | let stakingAsset = parseAssetId(stakingAssetId) | |
336 | + | let oldSendStakingAmount = fraction(proxyRateMul, amount, oldRate) | |
337 | + | let sendStakingAssetAmount = fraction(proxyRateMul, amount, currentProxyRate) | |
338 | + | let profitAmount = max([0, (oldSendStakingAmount - sendStakingAssetAmount)]) | |
339 | + | if ((sendStakingAssetAmount > 0)) | |
340 | + | then { | |
341 | + | let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(stakingAsset, sendStakingAssetAmount)]) | |
342 | + | if ((withdrawInvoke == withdrawInvoke)) | |
343 | + | then match withdrawInvoke { | |
344 | + | case receivedAssets: Int => | |
345 | + | let newAdditionalBalance = (currentAdditionalBalance - receivedAssets) | |
346 | + | let newStakingAssetBalance = ((currentStakingAssetBalance - sendStakingAssetAmount) - profitAmount) | |
347 | + | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newStakingAssetBalance), ScriptTransfer(profitAddress, profitAmount, parseAssetId(stakingAssetId))] | |
348 | + | case _ => | |
349 | + | nil | |
350 | + | } | |
351 | + | else throw("Strict value is not equal to itself.") | |
352 | + | } | |
353 | + | else nil | |
354 | + | } | |
355 | + | else throw("Strict value is not equal to itself.") | |
356 | + | } | |
357 | + | else throw("Strict value is not equal to itself.") | |
358 | + | } | |
359 | + | else throw("Strict value is not equal to itself.") | |
360 | + | } | |
361 | + | ||
362 | + | ||
363 | + | func getLeaseProxyConfig (assetId) = match invoke(factoryContract, "getPoolLeaseConfigREADONLY", [toString(this), assetId], nil) { | |
364 | + | case a: (Boolean, Int, Int, String, String, Int, String) => | |
365 | + | a | |
366 | + | case _ => | |
367 | + | throwErr((("[" + assetId) + "] getLeaseProxyConfig() error")) | |
368 | + | } | |
369 | + | ||
370 | + | ||
371 | + | func rebalanceInternal (targetRatio,assetId,stakingAssetId,minBalance,proxy,proxyRateMul,profitAddress) = { | |
372 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
373 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
374 | + | then { | |
375 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
376 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
377 | + | then { | |
378 | + | let leasableTotalBalance = max([0, (getAccBalance(assetId) - minBalance)]) | |
379 | + | let targetAdditionalBalance = fraction(targetRatio, leasableTotalBalance, 100) | |
380 | + | let diff = (currentAdditionalBalance - targetAdditionalBalance) | |
381 | + | if ((diff == 0)) | |
382 | + | then nil | |
383 | + | else if ((0 > diff)) | |
384 | + | then { | |
385 | + | let sendAssetAmount = -(diff) | |
386 | + | deposit(assetId, sendAssetAmount, stakingAssetId, proxy) | |
387 | + | } | |
388 | + | else { | |
389 | + | let getAssetAmount = diff | |
390 | + | withdraw(assetId, getAssetAmount, stakingAssetId, proxy, proxyRateMul, profitAddress) | |
391 | + | } | |
392 | + | } | |
393 | + | else throw("Strict value is not equal to itself.") | |
394 | + | } | |
395 | + | else throw("Strict value is not equal to itself.") | |
396 | + | } | |
397 | + | ||
398 | + | ||
399 | + | func rebalanceAsset (assetId) = { | |
400 | + | let $t01546015596 = getLeaseProxyConfig(assetId) | |
401 | + | let isLeasable = $t01546015596._1 | |
402 | + | let leasedRatio = $t01546015596._2 | |
403 | + | let minBalance = $t01546015596._3 | |
404 | + | let proxyAddress = $t01546015596._4 | |
405 | + | let proxyAssetId = $t01546015596._5 | |
406 | + | let proxyRateMul = $t01546015596._6 | |
407 | + | let stakingProfitAddress = $t01546015596._7 | |
408 | + | if (isLeasable) | |
409 | + | then rebalanceInternal(leasedRatio, assetId, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul, addressFromStringValue(stakingProfitAddress)) | |
410 | + | else nil | |
411 | + | } | |
412 | + | ||
413 | + | ||
414 | + | func withdrawAndRebalanceAsset (assetId,getAmount) = { | |
415 | + | let $t01599516131 = getLeaseProxyConfig(assetId) | |
416 | + | let isLeasable = $t01599516131._1 | |
417 | + | let leasedRatio = $t01599516131._2 | |
418 | + | let minBalance = $t01599516131._3 | |
419 | + | let proxyAddress = $t01599516131._4 | |
420 | + | let proxyAssetId = $t01599516131._5 | |
421 | + | let proxyRateMul = $t01599516131._6 | |
422 | + | let stakingProfitAddress = $t01599516131._7 | |
423 | + | if (isLeasable) | |
424 | + | then { | |
425 | + | let newTotalLeasableBalance = max([0, ((getAccBalance(assetId) - getAmount) - minBalance)]) | |
426 | + | if ((newTotalLeasableBalance == newTotalLeasableBalance)) | |
427 | + | then { | |
428 | + | let newAdditionalBalance = fraction(leasedRatio, newTotalLeasableBalance, 100) | |
429 | + | if ((newAdditionalBalance == newAdditionalBalance)) | |
430 | + | then { | |
431 | + | let withdrawAmount = (getAdditionalBalanceOrZero(assetId) - newAdditionalBalance) | |
432 | + | if ((withdrawAmount == withdrawAmount)) | |
433 | + | then if ((0 > withdrawAmount)) | |
434 | + | then deposit(assetId, -(withdrawAmount), proxyAssetId, addressFromStringValue(proxyAddress)) | |
435 | + | else withdraw(assetId, withdrawAmount, proxyAssetId, addressFromStringValue(proxyAddress), proxyRateMul, addressFromStringValue(stakingProfitAddress)) | |
436 | + | else throw("Strict value is not equal to itself.") | |
437 | + | } | |
438 | + | else throw("Strict value is not equal to itself.") | |
439 | + | } | |
440 | + | else throw("Strict value is not equal to itself.") | |
441 | + | } | |
442 | + | else nil | |
443 | + | } | |
444 | + | ||
445 | + | ||
446 | + | func withdrawAndRebalanceAll (amountAssetOutAmount,priceAssetOutAmount) = { | |
447 | + | let AmAmtWithdrawState = withdrawAndRebalanceAsset(getStringOrFail(this, aa()), amountAssetOutAmount) | |
448 | + | let PrAmtWithdrawState = withdrawAndRebalanceAsset(getStringOrFail(this, pa()), priceAssetOutAmount) | |
449 | + | (AmAmtWithdrawState ++ PrAmtWithdrawState) | |
450 | + | } | |
451 | + | ||
452 | + | ||
453 | + | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
454 | + | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
455 | + | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
456 | + | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
263 | 457 | } | |
264 | 458 | ||
265 | 459 | ||
266 | 460 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
267 | - | let amtAsDcm = cfgAmountAssetDecimals | |
268 | - | let prAsDcm = cfgPriceAssetDecimals | |
269 | - | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
270 | - | let amAmtX18 = t1(amAmt, amtAsDcm) | |
271 | - | let prAmtX18 = t1(prAmt, prAsDcm) | |
272 | - | let lpAmtX18 = t1(lpAmt, scale8) | |
273 | - | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) | |
274 | - | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) | |
275 | - | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
461 | + | let cfg = getPoolConfig() | |
462 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
463 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
464 | + | let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt) | |
465 | + | let amAmtX18 = toX18(amAmt, amtAssetDcm) | |
466 | + | let prAmtX18 = toX18(prAmt, priceAssetDcm) | |
467 | + | let lpAmtX18 = toX18(lpAmt, scale8) | |
468 | + | let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
469 | + | let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
470 | + | [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18] | |
471 | + | } | |
472 | + | ||
473 | + | ||
474 | + | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
475 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
476 | + | [fromX18(prices[0], scale8), fromX18(prices[1], scale8), fromX18(prices[2], scale8)] | |
477 | + | } | |
478 | + | ||
479 | + | ||
480 | + | func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
481 | + | let cfg = getPoolConfig() | |
482 | + | let lpAssetId = cfg[idxPoolLPAssetId] | |
483 | + | let amAssetId = cfg[idxAmtAssetId] | |
484 | + | let prAssetId = cfg[idxPriceAssetId] | |
485 | + | let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
486 | + | let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
487 | + | let poolStatus = cfg[idxPoolStatus] | |
488 | + | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity | |
489 | + | if ((lpAssetId != pmtAssetId)) | |
490 | + | then throw("Invalid asset passed.") | |
491 | + | else { | |
492 | + | let amBalance = getAccBalance(amAssetId) | |
493 | + | let amBalanceX18 = toX18(amBalance, amAssetDcm) | |
494 | + | let prBalance = getAccBalance(prAssetId) | |
495 | + | let prBalanceX18 = toX18(prBalance, prAssetDcm) | |
496 | + | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
497 | + | let curPrice = fromX18(curPriceX18, scale8) | |
498 | + | let pmtLpAmtX18 = toX18(pmtLpAmt, scale8) | |
499 | + | let lpEmissionX18 = toX18(lpEmission, scale8) | |
500 | + | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
501 | + | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
502 | + | let outAmAmt = fromX18Round(outAmAmtX18, amAssetDcm, FLOOR) | |
503 | + | let outPrAmt = fromX18Round(outPrAmtX18, prAssetDcm, FLOOR) | |
504 | + | let state = if ((txId58 == "")) | |
505 | + | then nil | |
506 | + | else [ScriptTransfer(userAddress, outAmAmt, if ((amAssetId == "WAVES")) | |
507 | + | then unit | |
508 | + | else fromBase58String(amAssetId)), ScriptTransfer(userAddress, outPrAmt, if ((prAssetId == "WAVES")) | |
509 | + | then unit | |
510 | + | else fromBase58String(prAssetId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
511 | + | $Tuple10(outAmAmt, outPrAmt, amAssetId, prAssetId, amBalance, prBalance, lpEmission, curPriceX18, poolStatus, state) | |
512 | + | } | |
513 | + | } | |
514 | + | ||
515 | + | ||
516 | + | func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = { | |
517 | + | let cfg = getPoolConfig() | |
518 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
519 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
520 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
521 | + | let iAmtAssetId = cfg[idxIAmtAssetId] | |
522 | + | let iPriceAssetId = cfg[idxIPriceAssetId] | |
523 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
524 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
525 | + | let poolStatus = cfg[idxPoolStatus] | |
526 | + | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
527 | + | let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES"))) | |
528 | + | let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES"))) | |
529 | + | if (if ((amAssetIdStr != inAmAssetIdStr)) | |
530 | + | then true | |
531 | + | else (prAssetIdStr != inPrAssetIdStr)) | |
532 | + | then throw("Invalid amt or price asset passed.") | |
533 | + | else { | |
534 | + | let amBalance = if (isEvaluate) | |
535 | + | then getAccBalance(amAssetIdStr) | |
536 | + | else (getAccBalance(amAssetIdStr) - inAmAssetAmt) | |
537 | + | let prBalance = if (isEvaluate) | |
538 | + | then getAccBalance(prAssetIdStr) | |
539 | + | else (getAccBalance(prAssetIdStr) - inPrAssetAmt) | |
540 | + | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
541 | + | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
542 | + | let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18) | |
543 | + | let amBalanceX18 = toX18(amBalance, amtAssetDcm) | |
544 | + | let prBalanceX18 = toX18(prBalance, priceAssetDcm) | |
545 | + | let res = if ((lpEmission == 0)) | |
546 | + | then { | |
547 | + | let curPriceX18 = zeroBigInt | |
548 | + | let slippageX18 = zeroBigInt | |
549 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
550 | + | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
551 | + | } | |
552 | + | else { | |
553 | + | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
554 | + | let slippageX18 = fraction(absBigInt((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
555 | + | let slippageToleranceX18 = toX18(slippageTolerance, scale8) | |
556 | + | if (if ((curPriceX18 != zeroBigInt)) | |
557 | + | then (slippageX18 > slippageToleranceX18) | |
558 | + | else false) | |
559 | + | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
560 | + | else { | |
561 | + | let lpEmissionX18 = toX18(lpEmission, scale8) | |
562 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING) | |
563 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, FLOOR), CEILING) | |
564 | + | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
565 | + | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
566 | + | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
567 | + | let expAmtAssetAmtX18 = expectedAmts._1 | |
568 | + | let expPriceAssetAmtX18 = expectedAmts._2 | |
569 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR) | |
570 | + | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtAssetDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceAssetDcm, CEILING), curPriceX18, slippageX18) | |
571 | + | } | |
572 | + | } | |
573 | + | let calcLpAmt = res._1 | |
574 | + | let calcAmAssetPmt = res._2 | |
575 | + | let calcPrAssetPmt = res._3 | |
576 | + | let curPrice = fromX18(res._4, scale8) | |
577 | + | let slippageCalc = fromX18(res._5, scale8) | |
578 | + | if ((0 >= calcLpAmt)) | |
579 | + | then throw("Invalid calculations. LP calculated is less than zero.") | |
580 | + | else { | |
581 | + | let emitLpAmt = if (!(emitLp)) | |
582 | + | then 0 | |
583 | + | else calcLpAmt | |
584 | + | let amDiff = (inAmAssetAmt - calcAmAssetPmt) | |
585 | + | let prDiff = (inPrAssetAmt - calcPrAssetPmt) | |
586 | + | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(calcAmAssetPmt, calcPrAssetPmt, emitLpAmt, curPrice, slippageTolerance, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
587 | + | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId) | |
588 | + | } | |
589 | + | } | |
590 | + | } | |
591 | + | ||
592 | + | ||
593 | + | func calcKLp (amountBalance,priceBalance,lpEmission) = { | |
594 | + | let amountBalanceX18 = toX18BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)) | |
595 | + | let priceBalanceX18 = toX18BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals)) | |
596 | + | let updatedKLp = fraction(pow((amountBalanceX18 * priceBalanceX18), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission) | |
597 | + | if ((lpEmission == big0)) | |
598 | + | then big0 | |
599 | + | else updatedKLp | |
600 | + | } | |
601 | + | ||
602 | + | ||
603 | + | func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
604 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
605 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
606 | + | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
607 | + | let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
608 | + | currentKLp | |
609 | + | } | |
610 | + | ||
611 | + | ||
612 | + | func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
613 | + | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
614 | + | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
615 | + | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
616 | + | let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
617 | + | let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))] | |
618 | + | $Tuple2(actions, updatedKLp) | |
619 | + | } | |
620 | + | ||
621 | + | ||
622 | + | func skipOrderValidation () = valueOrElse(getBoolean(factoryContract, keySkipOrderValidation(toString(this))), false) | |
623 | + | ||
624 | + | ||
625 | + | func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp)) | |
626 | + | then true | |
627 | + | else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " ")) | |
628 | + | ||
629 | + | ||
630 | + | func validateMatcherOrderAllowed (order) = { | |
631 | + | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
632 | + | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
633 | + | let amountAssetAmount = order.amount | |
634 | + | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
635 | + | let $t02852028732 = if ((order.orderType == Buy)) | |
636 | + | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
637 | + | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
638 | + | let amountAssetBalanceDelta = $t02852028732._1 | |
639 | + | let priceAssetBalanceDelta = $t02852028732._2 | |
640 | + | if (if (if (isGlobalShutdown()) | |
641 | + | then true | |
642 | + | else (cfgPoolStatus == PoolMatcherDisabled)) | |
643 | + | then true | |
644 | + | else (cfgPoolStatus == PoolShutdown)) | |
645 | + | then throw("Exchange operations disabled") | |
646 | + | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
647 | + | then true | |
648 | + | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
649 | + | then throw("Wrong order assets.") | |
650 | + | else { | |
651 | + | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
652 | + | let $t02917229272 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
653 | + | let unusedActions = $t02917229272._1 | |
654 | + | let kLpNew = $t02917229272._2 | |
655 | + | let isOrderValid = (kLpNew >= kLp) | |
656 | + | let info = makeString(["kLp=", toString(kLp), " kLpNew=", toString(kLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
657 | + | $Tuple2(isOrderValid, info) | |
658 | + | } | |
659 | + | } | |
660 | + | ||
661 | + | ||
662 | + | func commonGet (i) = if ((size(i.payments) != 1)) | |
663 | + | then throw("exactly 1 payment is expected") | |
664 | + | else { | |
665 | + | let pmt = value(i.payments[0]) | |
666 | + | let pmtAssetId = value(pmt.assetId) | |
667 | + | let pmtAmt = pmt.amount | |
668 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
669 | + | let outAmAmt = res._1 | |
670 | + | let outPrAmt = res._2 | |
671 | + | let poolStatus = parseIntValue(res._9) | |
672 | + | let state = res._10 | |
673 | + | if (if (isGlobalShutdown()) | |
674 | + | then true | |
675 | + | else (poolStatus == PoolShutdown)) | |
676 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
677 | + | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
678 | + | } | |
679 | + | ||
680 | + | ||
681 | + | func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2)) | |
682 | + | then throw("exactly 2 payments are expected") | |
683 | + | else { | |
684 | + | let amAssetPmt = value(i.payments[0]) | |
685 | + | let prAssetPmt = value(i.payments[1]) | |
686 | + | let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp) | |
687 | + | let poolStatus = parseIntValue(estPut._8) | |
688 | + | if (if (if (isGlobalShutdown()) | |
689 | + | then true | |
690 | + | else (poolStatus == PoolPutDisabled)) | |
691 | + | then true | |
692 | + | else (poolStatus == PoolShutdown)) | |
693 | + | then throw(("Put operation is blocked by admin. Status = " + toString(poolStatus))) | |
694 | + | else estPut | |
695 | + | } | |
696 | + | ||
697 | + | ||
698 | + | func emit (amount) = { | |
699 | + | let emitInv = invoke(factoryContract, "emit", [amount], nil) | |
700 | + | if ((emitInv == emitInv)) | |
701 | + | then { | |
702 | + | let emitInvLegacy = match emitInv { | |
703 | + | case legacyFactoryContract: Address => | |
704 | + | invoke(legacyFactoryContract, "emit", [amount], nil) | |
705 | + | case _ => | |
706 | + | unit | |
707 | + | } | |
708 | + | if ((emitInvLegacy == emitInvLegacy)) | |
709 | + | then amount | |
710 | + | else throw("Strict value is not equal to itself.") | |
711 | + | } | |
712 | + | else throw("Strict value is not equal to itself.") | |
276 | 713 | } | |
277 | 714 | ||
278 | 715 | ||
284 | 721 | } | |
285 | 722 | ||
286 | 723 | ||
287 | - | func getD (xp) = { | |
288 | - | let xp0 = xp[0] | |
289 | - | let xp1 = xp[1] | |
290 | - | let s = (xp0 + xp1) | |
291 | - | if ((s == big0)) | |
292 | - | then big0 | |
293 | - | else { | |
294 | - | let a = parseIntValue(A) | |
295 | - | let ann = (a * 2) | |
296 | - | let p = fraction(xp0, xp1, big1) | |
297 | - | let xp0_xp1_n_n = fraction(p, big4, big1) | |
298 | - | let ann_s = fraction(toBigInt(ann), s, big1) | |
299 | - | let ann_1 = toBigInt((ann - 1)) | |
300 | - | func calcDNext (d) = { | |
301 | - | let dd = fraction(d, d, big1) | |
302 | - | let ddd = fraction(dd, d, big1) | |
303 | - | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
304 | - | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1))) | |
724 | + | func calcPutOneToken (paymentAmountRaw,paymentAssetId,userAddress,txId) = { | |
725 | + | let isEval = (txId == unit) | |
726 | + | let amountBalanceRaw = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
727 | + | let priceBalanceRaw = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
728 | + | let paymentInAmountAsset = if ((paymentAssetId == cfgAmountAssetId)) | |
729 | + | then true | |
730 | + | else if ((paymentAssetId == cfgPriceAssetId)) | |
731 | + | then false | |
732 | + | else throwErr("invalid asset") | |
733 | + | let $t03238532678 = if (isEval) | |
734 | + | then $Tuple2(amountBalanceRaw, priceBalanceRaw) | |
735 | + | else if (paymentInAmountAsset) | |
736 | + | then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw) | |
737 | + | else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw)) | |
738 | + | let amountBalanceOld = $t03238532678._1 | |
739 | + | let priceBalanceOld = $t03238532678._2 | |
740 | + | let $t03268232831 = if (paymentInAmountAsset) | |
741 | + | then $Tuple2(paymentAmountRaw, 0) | |
742 | + | else $Tuple2(0, paymentAmountRaw) | |
743 | + | let amountAssetAmountRaw = $t03268232831._1 | |
744 | + | let priceAssetAmountRaw = $t03268232831._2 | |
745 | + | let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1 | |
746 | + | let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1 | |
747 | + | let $t03296333027 = takeFee(paymentAmountRaw, inFee) | |
748 | + | let paymentAmount = $t03296333027._1 | |
749 | + | let feeAmount = $t03296333027._2 | |
750 | + | let amountBalanceNew = (amountBalanceOld + amountAssetAmount) | |
751 | + | let priceBalanceNew = (priceBalanceOld + priceAssetAmount) | |
752 | + | let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals)) | |
753 | + | let priceNew = fromX18(priceNewX18, scale8) | |
754 | + | let paymentBalance = if (paymentInAmountAsset) | |
755 | + | then amountBalanceOld | |
756 | + | else priceBalanceOld | |
757 | + | let paymentBalanceBigInt = toBigInt(paymentBalance) | |
758 | + | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
759 | + | let chechSupply = if ((supplyBigInt > big0)) | |
760 | + | then true | |
761 | + | else throwErr("initial deposit requires all coins") | |
762 | + | if ((chechSupply == chechSupply)) | |
763 | + | then { | |
764 | + | let depositBigInt = toBigInt(paymentAmount) | |
765 | + | let issueAmount = max([0, toInt(((supplyBigInt * (sqrtBigInt((scale18 + ((depositBigInt * scale18) / paymentBalanceBigInt)), 18, 18, DOWN) - scale18)) / scale18))]) | |
766 | + | let commonState = if (isEval) | |
767 | + | then nil | |
768 | + | else [IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew), StringEntry(pau(toString(value(userAddress)), toBase58String(value(txId))), dataPutActionInfo(amountAssetAmountRaw, priceAssetAmountRaw, issueAmount, priceNew, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
769 | + | let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals)) | |
770 | + | let priceOld = fromX18(priceOldX18, scale8) | |
771 | + | let loss = { | |
772 | + | let $t03470834875 = if (paymentInAmountAsset) | |
773 | + | then $Tuple2(amountAssetAmountRaw, amountBalanceOld) | |
774 | + | else $Tuple2(priceAssetAmountRaw, priceBalanceOld) | |
775 | + | let amount = $t03470834875._1 | |
776 | + | let balance = $t03470834875._2 | |
777 | + | let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance))) | |
778 | + | fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth) | |
305 | 779 | } | |
306 | - | ||
307 | - | func calc (acc,i) = if (acc._2) | |
308 | - | then acc | |
309 | - | else { | |
310 | - | let d = acc._1 | |
311 | - | let dNext = calcDNext(d) | |
312 | - | let dDiffRaw = (dNext - value(d)) | |
313 | - | let dDiff = if ((big0 > dDiffRaw)) | |
314 | - | then -(dDiffRaw) | |
315 | - | else dDiffRaw | |
316 | - | if ((big1 >= dDiff)) | |
317 | - | then $Tuple2(dNext, true) | |
318 | - | else $Tuple2(dNext, false) | |
319 | - | } | |
320 | - | ||
321 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
322 | - | let $t01277812826 = { | |
323 | - | let $l = arr | |
324 | - | let $s = size($l) | |
325 | - | let $acc0 = $Tuple2(s, false) | |
326 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
327 | - | then $a | |
328 | - | else calc($a, $l[$i]) | |
329 | - | ||
330 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
331 | - | then $a | |
332 | - | else throw("List size exceeds 17") | |
333 | - | ||
334 | - | $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($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
335 | - | } | |
336 | - | let d = $t01277812826._1 | |
337 | - | let found = $t01277812826._2 | |
338 | - | if (found) | |
339 | - | then d | |
340 | - | else throw(("D calculation error, D = " + toString(d))) | |
341 | - | } | |
342 | - | } | |
343 | - | ||
344 | - | ||
345 | - | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
346 | - | let lpId = cfgLpAssetId | |
347 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
348 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
349 | - | let amDcm = cfgAmountAssetDecimals | |
350 | - | let prDcm = cfgPriceAssetDecimals | |
351 | - | let sts = toString(cfgPoolStatus) | |
352 | - | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
353 | - | if ((toBase58String(lpId) != pmtAssetId)) | |
354 | - | then throw("Wrong pmt asset") | |
355 | - | else { | |
356 | - | let amBalance = getAccBalance(amId) | |
357 | - | let amBalanceX18 = t1(amBalance, amDcm) | |
358 | - | let prBalance = getAccBalance(prId) | |
359 | - | let prBalanceX18 = t1(prBalance, prDcm) | |
360 | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
361 | - | let curPrice = f1(curPriceX18, scale8) | |
362 | - | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) | |
363 | - | let lpEmissX18 = t1(lpEmiss, scale8) | |
364 | - | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
365 | - | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
366 | - | let outAmAmt = fromX18Round(outAmAmtX18, amDcm, FLOOR) | |
367 | - | let outPrAmt = fromX18Round(outPrAmtX18, prDcm, FLOOR) | |
368 | - | let state = if ((txId58 == "")) | |
369 | - | then nil | |
370 | - | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
371 | - | then unit | |
372 | - | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) | |
373 | - | then unit | |
374 | - | 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)] | |
375 | - | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) | |
376 | - | } | |
377 | - | } | |
378 | - | ||
379 | - | ||
380 | - | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
381 | - | let lpId = cfgLpAssetId | |
382 | - | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
383 | - | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
384 | - | let amtDcm = cfgAmountAssetDecimals | |
385 | - | let priceDcm = cfgPriceAssetDecimals | |
386 | - | let sts = toString(cfgPoolStatus) | |
387 | - | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
388 | - | let amBalance = if (isEval) | |
389 | - | then getAccBalance(amIdStr) | |
390 | - | else if (if (isOneAsset) | |
391 | - | then (pmtId == amIdStr) | |
392 | - | else false) | |
393 | - | then (getAccBalance(amIdStr) - pmtAmt) | |
394 | - | else if (isOneAsset) | |
395 | - | then getAccBalance(amIdStr) | |
396 | - | else (getAccBalance(amIdStr) - inAmAmt) | |
397 | - | let prBalance = if (isEval) | |
398 | - | then getAccBalance(prIdStr) | |
399 | - | else if (if (isOneAsset) | |
400 | - | then (pmtId == prIdStr) | |
401 | - | else false) | |
402 | - | then (getAccBalance(prIdStr) - pmtAmt) | |
403 | - | else if (isOneAsset) | |
404 | - | then getAccBalance(prIdStr) | |
405 | - | else (getAccBalance(prIdStr) - inPrAmt) | |
406 | - | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) | |
407 | - | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) | |
408 | - | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
409 | - | let amBalanceX18 = t1(amBalance, amtDcm) | |
410 | - | let prBalanceX18 = t1(prBalance, priceDcm) | |
411 | - | let D0 = getD([amBalanceX18, prBalanceX18]) | |
412 | - | let r = if ((lpEm == 0)) | |
413 | - | then { | |
414 | - | let D1 = getD([(amBalanceX18 + inAmAssetAmtX18), (prBalanceX18 + inPrAssetAmtX18)]) | |
415 | - | let checkD = if ((D1 > D0)) | |
416 | - | then true | |
417 | - | else throw("D1 should be greater than D0") | |
418 | - | if ((checkD == checkD)) | |
419 | - | then { | |
420 | - | let curPriceX18 = zeroBigInt | |
421 | - | let slippageX18 = zeroBigInt | |
422 | - | let lpAmtX18 = D1 | |
423 | - | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
424 | - | } | |
425 | - | else throw("Strict value is not equal to itself.") | |
426 | - | } | |
427 | - | else { | |
428 | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
429 | - | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
430 | - | let slippageX18 = t1(slippage, scale8) | |
431 | - | if (if (if (validateSlippage) | |
432 | - | then (curPriceX18 != zeroBigInt) | |
433 | - | else false) | |
434 | - | then (slippageRealX18 > slippageX18) | |
435 | - | else false) | |
436 | - | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
437 | - | else { | |
438 | - | let lpEmissionX18 = t1(lpEm, scale8) | |
439 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, cpbir(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING) | |
440 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, cpbir(prBalanceX18, amBalanceX18, FLOOR), CEILING) | |
441 | - | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
442 | - | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
443 | - | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
444 | - | let expAmtAssetAmtX18 = expectedAmts._1 | |
445 | - | let expPriceAssetAmtX18 = expectedAmts._2 | |
446 | - | let D1 = getD([(amBalanceX18 + expAmtAssetAmtX18), (prBalanceX18 + expPriceAssetAmtX18)]) | |
447 | - | let checkD = if ((D1 > D0)) | |
448 | - | then true | |
449 | - | else throw("D1 should be greater than D0") | |
450 | - | if ((checkD == checkD)) | |
451 | - | then { | |
452 | - | let lpAmtX18 = fraction(lpEmissionX18, (D1 - D0), D0) | |
453 | - | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
454 | - | } | |
455 | - | else throw("Strict value is not equal to itself.") | |
456 | - | } | |
457 | - | } | |
458 | - | let calcLpAmt = r._1 | |
459 | - | let calcAmAssetPmt = r._2 | |
460 | - | let calcPrAssetPmt = r._3 | |
461 | - | let curPrice = f1(r._4, scale8) | |
462 | - | let slippageCalc = f1(r._5, scale8) | |
463 | - | if ((0 >= calcLpAmt)) | |
464 | - | then throw("LP <= 0") | |
465 | - | else { | |
466 | - | let emitLpAmt = if (!(emitLp)) | |
467 | - | then 0 | |
468 | - | else calcLpAmt | |
469 | - | let amDiff = (inAmAmt - calcAmAssetPmt) | |
470 | - | let prDiff = (inPrAmt - calcPrAssetPmt) | |
471 | - | let $t02058820933 = if (if (isOneAsset) | |
472 | - | then (pmtId == amIdStr) | |
473 | - | else false) | |
474 | - | then $Tuple2(pmtAmt, 0) | |
475 | - | else if (if (isOneAsset) | |
476 | - | then (pmtId == prIdStr) | |
477 | - | else false) | |
478 | - | then $Tuple2(0, pmtAmt) | |
479 | - | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
480 | - | let writeAmAmt = $t02058820933._1 | |
481 | - | let writePrAmt = $t02058820933._2 | |
482 | - | 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))] | |
483 | - | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
484 | - | } | |
485 | - | } | |
486 | - | ||
487 | - | ||
488 | - | func getYD (xp,i,D) = { | |
489 | - | let n = big2 | |
490 | - | let x = xp[if ((i == 0)) | |
491 | - | then 1 | |
492 | - | else 0] | |
493 | - | let aPrecision = parseBigIntValue(Amult) | |
494 | - | let a = (parseBigIntValue(A) * aPrecision) | |
495 | - | let s = x | |
496 | - | let ann = (a * n) | |
497 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
498 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
499 | - | func calc (acc,cur) = { | |
500 | - | let $t02212822148 = acc | |
501 | - | let y = $t02212822148._1 | |
502 | - | let found = $t02212822148._2 | |
503 | - | if ((found != unit)) | |
504 | - | then acc | |
505 | - | else { | |
506 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
507 | - | let yDiff = absBigInt((yNext - value(y))) | |
508 | - | if ((big1 >= yDiff)) | |
509 | - | then $Tuple2(yNext, cur) | |
510 | - | else $Tuple2(yNext, unit) | |
511 | - | } | |
512 | - | } | |
513 | - | ||
514 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
515 | - | let $t02245522502 = { | |
516 | - | let $l = arr | |
517 | - | let $s = size($l) | |
518 | - | let $acc0 = $Tuple2(D, unit) | |
519 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
520 | - | then $a | |
521 | - | else calc($a, $l[$i]) | |
522 | - | ||
523 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
524 | - | then $a | |
525 | - | else throw("List size exceeds 15") | |
526 | - | ||
527 | - | $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) | |
528 | - | } | |
529 | - | let y = $t02245522502._1 | |
530 | - | let found = $t02245522502._2 | |
531 | - | if ((found != unit)) | |
532 | - | then y | |
533 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
534 | - | } | |
535 | - | ||
536 | - | ||
537 | - | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
538 | - | let updatedDLp = fraction(getD([t1BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)), t1BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))]), scale18, lpEmission) | |
539 | - | if ((lpEmission == big0)) | |
540 | - | then big0 | |
541 | - | else updatedDLp | |
542 | - | } | |
543 | - | ||
544 | - | ||
545 | - | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
546 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
547 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
548 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
549 | - | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
550 | - | currentDLp | |
551 | - | } | |
552 | - | ||
553 | - | ||
554 | - | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
555 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
556 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
557 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
558 | - | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
559 | - | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
560 | - | $Tuple2(actions, updatedDLp) | |
561 | - | } | |
562 | - | ||
563 | - | ||
564 | - | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
565 | - | then true | |
566 | - | else throwErr("updated DLp lower than current DLp") | |
567 | - | ||
568 | - | ||
569 | - | func validateMatcherOrderAllowed (order) = { | |
570 | - | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
571 | - | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
572 | - | let amountAssetAmount = order.amount | |
573 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
574 | - | let $t02470024912 = if ((order.orderType == Buy)) | |
575 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
576 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
577 | - | let amountAssetBalanceDelta = $t02470024912._1 | |
578 | - | let priceAssetBalanceDelta = $t02470024912._2 | |
579 | - | if (if (if (igs()) | |
580 | - | then true | |
581 | - | else (cfgPoolStatus == PoolMatcherDis)) | |
582 | - | then true | |
583 | - | else (cfgPoolStatus == PoolShutdown)) | |
584 | - | then throw("Admin blocked") | |
585 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
586 | - | then true | |
587 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
588 | - | then throw("Wr assets") | |
589 | - | else { | |
590 | - | let dLp = parseBigIntValue(valueOrElse(getString(this, keyDLp), "0")) | |
591 | - | let $t02525425354 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
592 | - | let unusedActions = $t02525425354._1 | |
593 | - | let dLpNew = $t02525425354._2 | |
594 | - | let isOrderValid = (dLpNew >= dLp) | |
595 | - | let info = makeString(["dLp=", toString(dLp), " dLpNew=", toString(dLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
596 | - | $Tuple2(isOrderValid, info) | |
597 | - | } | |
598 | - | } | |
599 | - | ||
600 | - | ||
601 | - | func cg (i) = if ((size(i.payments) != 1)) | |
602 | - | then throw("1 pmnt exp") | |
603 | - | else { | |
604 | - | let pmt = value(i.payments[0]) | |
605 | - | let pmtAssetId = value(pmt.assetId) | |
606 | - | let pmtAmt = pmt.amount | |
607 | - | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
608 | - | let outAmAmt = r._1 | |
609 | - | let outPrAmt = r._2 | |
610 | - | let sts = parseIntValue(r._9) | |
611 | - | let state = r._10 | |
612 | - | if (if (igs()) | |
613 | - | then true | |
614 | - | else (sts == PoolShutdown)) | |
615 | - | then throw(("Admin blocked: " + toString(sts))) | |
616 | - | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
617 | - | } | |
618 | - | ||
619 | - | ||
620 | - | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
621 | - | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, (txId == ""), emitLp, isOneAsset, validateSlippage, pmtAmt, pmtId) | |
622 | - | let sts = parseIntValue(r._8) | |
623 | - | if (if (if (igs()) | |
624 | - | then true | |
625 | - | else (sts == PoolPutDis)) | |
626 | - | then true | |
627 | - | else (sts == PoolShutdown)) | |
628 | - | then throw(("Blocked:" + toString(sts))) | |
629 | - | else r | |
630 | - | } | |
631 | - | ||
632 | - | ||
633 | - | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
634 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
635 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
636 | - | let lpId = cfgLpAssetId | |
637 | - | let amtDcm = cfgAmountAssetDecimals | |
638 | - | let priceDcm = cfgPriceAssetDecimals | |
639 | - | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
640 | - | let chechEmission = if ((lpAssetEmission > big0)) | |
641 | - | then true | |
642 | - | else throw("initial deposit requires all coins") | |
643 | - | if ((chechEmission == chechEmission)) | |
644 | - | then { | |
645 | - | let amBalance = getAccBalance(amId) | |
646 | - | let prBalance = getAccBalance(prId) | |
647 | - | let $t02801028472 = if ((txId == "")) | |
648 | - | then $Tuple2(amBalance, prBalance) | |
649 | - | else if ((pmtAssetId == amId)) | |
650 | - | then if ((pmtAmtRaw > amBalance)) | |
651 | - | then throw("invalid payment amount") | |
652 | - | else $Tuple2((amBalance - pmtAmtRaw), prBalance) | |
653 | - | else if ((pmtAssetId == prId)) | |
654 | - | then if ((pmtAmtRaw > prBalance)) | |
655 | - | then throw("invalid payment amount") | |
656 | - | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
657 | - | else throw("wrong pmtAssetId") | |
658 | - | let amBalanceOld = $t02801028472._1 | |
659 | - | let prBalanceOld = $t02801028472._2 | |
660 | - | let $t02847828654 = if ((pmtAssetId == amId)) | |
661 | - | then $Tuple2(pmtAmtRaw, 0) | |
662 | - | else if ((pmtAssetId == prId)) | |
663 | - | then $Tuple2(0, pmtAmtRaw) | |
664 | - | else throw("invalid payment") | |
665 | - | let amAmountRaw = $t02847828654._1 | |
666 | - | let prAmountRaw = $t02847828654._2 | |
667 | - | let $t02865828912 = if (withTakeFee) | |
668 | - | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
669 | - | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
670 | - | let amAmount = $t02865828912._1 | |
671 | - | let prAmount = $t02865828912._2 | |
672 | - | let feeAmount = $t02865828912._3 | |
673 | - | let amBalanceNew = (amBalanceOld + amAmount) | |
674 | - | let prBalanceNew = (prBalanceOld + prAmount) | |
675 | - | let D0 = getD([t1(amBalanceOld, cfgAmountAssetDecimals), t1(prBalanceOld, cfgPriceAssetDecimals)]) | |
676 | - | let D1 = getD([t1(amBalanceNew, cfgAmountAssetDecimals), t1(prBalanceNew, cfgPriceAssetDecimals)]) | |
677 | - | let checkD = if ((D1 > D0)) | |
678 | - | then true | |
679 | - | else throw() | |
680 | - | if ((checkD == checkD)) | |
681 | - | then { | |
682 | - | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0, FLOOR) | |
683 | - | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
684 | - | 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))] | |
685 | - | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
686 | - | let amountAssetPart = fraction(pmtAmtRaw, scale8, (poolProportion + scale8)) | |
687 | - | let priceAssetPart = (pmtAmtRaw - amountAssetPart) | |
688 | - | let lpAmtBoth = fraction(lpAssetEmission, toBigInt(priceAssetPart), toBigInt(prBalanceOld)) | |
689 | - | let bonus = toInt(fraction((lpAmount - lpAmtBoth), scale8BigInt, lpAmtBoth)) | |
690 | - | $Tuple4(toInt(lpAmount), commonState, feeAmount, bonus) | |
691 | - | } | |
692 | - | else throw("Strict value is not equal to itself.") | |
780 | + | $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset) | |
693 | 781 | } | |
694 | 782 | else throw("Strict value is not equal to itself.") | |
695 | 783 | } | |
696 | 784 | ||
697 | 785 | ||
698 | - | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
699 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
700 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
701 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
702 | - | let amDecimals = cfgAmountAssetDecimals | |
703 | - | let prDecimals = cfgPriceAssetDecimals | |
704 | - | let poolStatus = cfgPoolStatus | |
705 | - | let userAddress = if ((caller == restContract)) | |
706 | - | then originCaller | |
707 | - | else caller | |
708 | - | let pmt = value(payments[0]) | |
709 | - | let pmtAssetId = value(pmt.assetId) | |
710 | - | let pmtAmt = pmt.amount | |
711 | - | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
712 | - | if ((currentDLp == currentDLp)) | |
786 | + | func calcGetOneToken (outAssetId,paymentAmount,paymentAssetId,userAddress,txId) = { | |
787 | + | let isEval = (txId == unit) | |
788 | + | let cfg = getPoolConfig() | |
789 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
790 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
791 | + | let checks = [if ((paymentAssetId == cfgLpAssetId)) | |
792 | + | then true | |
793 | + | else throwErr("invalid lp asset")] | |
794 | + | if ((checks == checks)) | |
713 | 795 | then { | |
714 | - | let txId58 = toBase58String(transactionId) | |
715 | - | if ((lpId != toBase58String(pmtAssetId))) | |
716 | - | then throw("Wrong LP") | |
717 | - | else { | |
718 | - | let amBalance = getAccBalance(amId) | |
719 | - | let prBalance = getAccBalance(prId) | |
720 | - | let $t03102431135 = { | |
721 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
722 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
723 | - | then @ | |
724 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
725 | - | } | |
726 | - | if (($t03102431135 == $t03102431135)) | |
727 | - | then { | |
728 | - | let feeAmount = $t03102431135._2 | |
729 | - | let totalGet = $t03102431135._1 | |
730 | - | let totalAmount = if (if ((minOutAmount > 0)) | |
731 | - | then (minOutAmount > totalGet) | |
732 | - | else false) | |
733 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
734 | - | else totalGet | |
735 | - | let $t03132531632 = if ((outAssetId == amId)) | |
736 | - | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
737 | - | else if ((outAssetId == prId)) | |
738 | - | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
739 | - | else throw("invalid out asset id") | |
740 | - | let outAm = $t03132531632._1 | |
741 | - | let outPr = $t03132531632._2 | |
742 | - | let amBalanceNew = $t03132531632._3 | |
743 | - | let prBalanceNew = $t03132531632._4 | |
744 | - | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
745 | - | let curPr = f1(curPrX18, scale8) | |
746 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
747 | - | then unit | |
748 | - | else fromBase58String(outAssetId) | |
749 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
750 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
751 | - | else nil | |
752 | - | 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) | |
753 | - | if ((state == state)) | |
754 | - | then { | |
755 | - | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
756 | - | if ((burn == burn)) | |
757 | - | then { | |
758 | - | let $t03241732767 = { | |
759 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
760 | - | then 0 | |
761 | - | else feeAmount | |
762 | - | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
763 | - | then true | |
764 | - | else false | |
765 | - | if (outInAmountAsset) | |
766 | - | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
767 | - | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
768 | - | } | |
769 | - | let amountAssetBalanceDelta = $t03241732767._1 | |
770 | - | let priceAssetBalanceDelta = $t03241732767._2 | |
771 | - | let $t03277032878 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
772 | - | let refreshDLpActions = $t03277032878._1 | |
773 | - | let updatedDLp = $t03277032878._2 | |
774 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
775 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
776 | - | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
777 | - | else throw("Strict value is not equal to itself.") | |
778 | - | } | |
779 | - | else throw("Strict value is not equal to itself.") | |
780 | - | } | |
781 | - | else throw("Strict value is not equal to itself.") | |
782 | - | } | |
783 | - | else throw("Strict value is not equal to itself.") | |
784 | - | } | |
796 | + | let outInAmountAsset = if ((outAssetId == cfgAmountAssetId)) | |
797 | + | then true | |
798 | + | else if ((outAssetId == cfgPriceAssetId)) | |
799 | + | then false | |
800 | + | else throwErr("invalid asset") | |
801 | + | let balanceBigInt = if (outInAmountAsset) | |
802 | + | then toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) | |
803 | + | else toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) | |
804 | + | let outInAmountAssetDecimals = if (outInAmountAsset) | |
805 | + | then amtAssetDcm | |
806 | + | else priceAssetDcm | |
807 | + | let amBalanceOld = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
808 | + | let prBalanceOld = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
809 | + | let outBalance = if (outInAmountAsset) | |
810 | + | then amBalanceOld | |
811 | + | else prBalanceOld | |
812 | + | let outBalanceBigInt = toBigInt(outBalance) | |
813 | + | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
814 | + | let redeemedBigInt = toBigInt(paymentAmount) | |
815 | + | let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))]) | |
816 | + | let $t03695337009 = takeFee(amountRaw, outFee) | |
817 | + | let totalAmount = $t03695337009._1 | |
818 | + | let feeAmount = $t03695337009._2 | |
819 | + | let $t03701337239 = if (outInAmountAsset) | |
820 | + | then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld) | |
821 | + | else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw)) | |
822 | + | let outAmAmount = $t03701337239._1 | |
823 | + | let outPrAmount = $t03701337239._2 | |
824 | + | let amBalanceNew = $t03701337239._3 | |
825 | + | let prBalanceNew = $t03701337239._4 | |
826 | + | let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals)) | |
827 | + | let priceNew = fromX18(priceNewX18, scale8) | |
828 | + | let commonState = if (isEval) | |
829 | + | then nil | |
830 | + | else [StringEntry(gau(toString(value(userAddress)), toBase58String(value(txId))), dataGetActionInfo(outAmAmount, outPrAmount, paymentAmount, priceNew, height, lastBlock.timestamp)), IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew)] | |
831 | + | let priceOldX18 = calcPriceBigInt(toX18(prBalanceOld, cfgPriceAssetDecimals), toX18(amBalanceOld, cfgAmountAssetDecimals)) | |
832 | + | let priceOld = fromX18(priceOldX18, scale8) | |
833 | + | let loss = { | |
834 | + | let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2) | |
835 | + | fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset) | |
836 | + | } | |
837 | + | $Tuple5(totalAmount, commonState, feeAmount, loss, outInAmountAsset) | |
785 | 838 | } | |
786 | 839 | else throw("Strict value is not equal to itself.") | |
787 | 840 | } | |
788 | 841 | ||
789 | 842 | ||
790 | - | func | |
843 | + | func managerPublicKeyOrUnit () = match getString(mpk()) { | |
791 | 844 | case s: String => | |
792 | 845 | fromBase58String(s) | |
793 | 846 | case _: Unit => | |
797 | 850 | } | |
798 | 851 | ||
799 | 852 | ||
800 | - | func | |
853 | + | func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) { | |
801 | 854 | case s: String => | |
802 | 855 | fromBase58String(s) | |
803 | 856 | case _: Unit => | |
807 | 860 | } | |
808 | 861 | ||
809 | 862 | ||
810 | - | let pd = throw("Permission denied") | |
811 | - | ||
812 | - | func isManager (i) = match m() { | |
863 | + | func isManager (i) = match managerPublicKeyOrUnit() { | |
813 | 864 | case pk: ByteVector => | |
814 | 865 | (i.callerPublicKey == pk) | |
815 | 866 | case _: Unit => | |
819 | 870 | } | |
820 | 871 | ||
821 | 872 | ||
822 | - | func mm (i) = match m() { | |
823 | - | case pk: ByteVector => | |
824 | - | if ((i.callerPublicKey == pk)) | |
825 | - | then true | |
826 | - | else pd | |
827 | - | case _: Unit => | |
828 | - | if ((i.caller == this)) | |
829 | - | then true | |
830 | - | else pd | |
831 | - | case _ => | |
832 | - | throw("Match error") | |
833 | - | } | |
834 | - | ||
835 | - | ||
836 | - | func getY (isReverse,D,poolAmountInBalance) = { | |
837 | - | let poolConfig = gpc() | |
838 | - | let amId = poolConfig[idxAmAsId] | |
839 | - | let prId = poolConfig[idxPrAsId] | |
840 | - | let n = big2 | |
841 | - | let aPrecision = parseBigIntValue(Amult) | |
842 | - | let a = (parseBigIntValue(A) * aPrecision) | |
843 | - | let xp = if ((isReverse == false)) | |
844 | - | then [(toBigInt(getAccBalance(amId)) + poolAmountInBalance), toBigInt(getAccBalance(prId))] | |
845 | - | else [(toBigInt(getAccBalance(prId)) + poolAmountInBalance), toBigInt(getAccBalance(amId))] | |
846 | - | let x = xp[0] | |
847 | - | let s = x | |
848 | - | let ann = (a * n) | |
849 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
850 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
851 | - | func calc (acc,cur) = { | |
852 | - | let $t03432534345 = acc | |
853 | - | let y = $t03432534345._1 | |
854 | - | let found = $t03432534345._2 | |
855 | - | if ((found != unit)) | |
856 | - | then acc | |
857 | - | else { | |
858 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
859 | - | let yDiff = absBigInt((yNext - value(y))) | |
860 | - | if ((big1 >= yDiff)) | |
861 | - | then $Tuple2(yNext, cur) | |
862 | - | else $Tuple2(yNext, unit) | |
863 | - | } | |
864 | - | } | |
865 | - | ||
866 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
867 | - | let $t03467634723 = { | |
868 | - | let $l = arr | |
869 | - | let $s = size($l) | |
870 | - | let $acc0 = $Tuple2(D, unit) | |
871 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
872 | - | then $a | |
873 | - | else calc($a, $l[$i]) | |
874 | - | ||
875 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
876 | - | then $a | |
877 | - | else throw("List size exceeds 15") | |
878 | - | ||
879 | - | $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) | |
880 | - | } | |
881 | - | let y = $t03467634723._1 | |
882 | - | let found = $t03467634723._2 | |
883 | - | if ((found != unit)) | |
884 | - | then y | |
885 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
873 | + | func mustManager (i) = { | |
874 | + | let pd = throw("Permission denied") | |
875 | + | match managerPublicKeyOrUnit() { | |
876 | + | case pk: ByteVector => | |
877 | + | if ((i.callerPublicKey == pk)) | |
878 | + | then true | |
879 | + | else pd | |
880 | + | case _: Unit => | |
881 | + | if ((i.caller == this)) | |
882 | + | then true | |
883 | + | else pd | |
884 | + | case _ => | |
885 | + | throw("Match error") | |
886 | + | } | |
886 | 887 | } | |
887 | 888 | ||
888 | 889 | ||
889 | - | func skipOrderValidation () = valueOrElse(getBoolean(fca, keySkipOrderValidation(toString(this))), false) | |
890 | + | @Callable(i) | |
891 | + | func rebalance () = (rebalanceAsset(getStringOrFail(this, aa())) ++ rebalanceAsset(getStringOrFail(this, pa()))) | |
892 | + | ||
890 | 893 | ||
891 | 894 | ||
892 | 895 | @Callable(i) | |
893 | 896 | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
894 | - | let $ | |
897 | + | let $t03912539430 = if ((isReverse == false)) | |
895 | 898 | then { | |
896 | - | let assetOut = | |
897 | - | let | |
898 | - | $Tuple2(assetOut, | |
899 | + | let assetOut = getStringOrFail(this, pa()) | |
900 | + | let assetIn = getStringOrFail(this, aa()) | |
901 | + | $Tuple2(assetOut, assetIn) | |
899 | 902 | } | |
900 | 903 | else { | |
901 | - | let assetOut = | |
902 | - | let | |
903 | - | $Tuple2(assetOut, | |
904 | + | let assetOut = getStringOrFail(this, aa()) | |
905 | + | let assetIn = getStringOrFail(this, pa()) | |
906 | + | $Tuple2(assetOut, assetIn) | |
904 | 907 | } | |
905 | - | let assetOut = $t03507535499._1 | |
906 | - | let poolAmountInBalance = $t03507535499._2 | |
907 | - | let poolConfig = gpc() | |
908 | - | let amId = poolConfig[idxAmAsId] | |
909 | - | let prId = poolConfig[idxPrAsId] | |
910 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
911 | - | let D = getD(xp) | |
912 | - | let y = getY(isReverse, D, toBigInt(cleanAmountIn)) | |
913 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
914 | - | let totalGetRaw = max([0, toInt(dy)]) | |
915 | - | let newXp = if ((isReverse == false)) | |
916 | - | then [((toBigInt(getAccBalance(amId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
917 | - | else [(toBigInt(getAccBalance(amId)) - dy), ((toBigInt(getAccBalance(prId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount))] | |
918 | - | let newD = getD(newXp) | |
919 | - | let checkD = if ((newD >= D)) | |
908 | + | let assetOut = $t03912539430._1 | |
909 | + | let assetIn = $t03912539430._2 | |
910 | + | let poolAssetInBalance = getAccBalance(assetIn) | |
911 | + | let poolAssetOutBalance = getAccBalance(assetOut) | |
912 | + | let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn)) | |
913 | + | let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance)) | |
914 | + | let newK = (((toBigInt(getAccBalance(assetIn)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut))) | |
915 | + | let checkK = if ((newK >= oldK)) | |
920 | 916 | then true | |
921 | - | else throw( | |
922 | - | if (( | |
923 | - | then $Tuple2(nil, | |
917 | + | else throw("new K is fewer error") | |
918 | + | if ((checkK == checkK)) | |
919 | + | then $Tuple2(nil, amountOut) | |
924 | 920 | else throw("Strict value is not equal to itself.") | |
925 | 921 | } | |
926 | 922 | ||
929 | 925 | @Callable(i) | |
930 | 926 | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
931 | 927 | let swapContact = { | |
932 | - | let @ = invoke( | |
928 | + | let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil) | |
933 | 929 | if ($isInstanceOf(@, "String")) | |
934 | 930 | then @ | |
935 | 931 | else throw(($getType(@) + " couldn't be cast to String")) | |
943 | 939 | then { | |
944 | 940 | let pmt = value(i.payments[0]) | |
945 | 941 | let assetIn = assetIdToString(pmt.assetId) | |
946 | - | let $t03693537329 = if ((isReverse == false)) | |
942 | + | let assetOut = if ((isReverse == false)) | |
943 | + | then getStringOrFail(this, pa()) | |
944 | + | else getStringOrFail(this, aa()) | |
945 | + | let poolAssetInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
946 | + | let poolAssetOutBalance = getAccBalance(assetOut) | |
947 | + | let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn)) | |
948 | + | let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance)) | |
949 | + | let newK = ((toBigInt(getAccBalance(assetIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut))) | |
950 | + | let checkK = if ((newK >= oldK)) | |
951 | + | then true | |
952 | + | else throw("new K is fewer error") | |
953 | + | if ((checkK == checkK)) | |
947 | 954 | then { | |
948 | - | let assetOut = strf(this, pa()) | |
949 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
950 | - | $Tuple2(assetOut, poolAmountInBalance) | |
951 | - | } | |
952 | - | else { | |
953 | - | let assetOut = strf(this, aa()) | |
954 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
955 | - | $Tuple2(assetOut, poolAmountInBalance) | |
956 | - | } | |
957 | - | let assetOut = $t03693537329._1 | |
958 | - | let poolAmountInBalance = $t03693537329._2 | |
959 | - | let poolConfig = gpc() | |
960 | - | let amId = poolConfig[idxAmAsId] | |
961 | - | let prId = poolConfig[idxPrAsId] | |
962 | - | let xp = if ((isReverse == false)) | |
963 | - | then [(toBigInt(getAccBalance(amId)) - toBigInt(value(i.payments[0]).amount)), toBigInt(getAccBalance(prId))] | |
964 | - | else [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - toBigInt(value(i.payments[0]).amount))] | |
965 | - | let D = getD(xp) | |
966 | - | let y = getY(isReverse, D, toBigInt(0)) | |
967 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
968 | - | let totalGetRaw = max([0, toInt(dy)]) | |
969 | - | let checkMin = if ((totalGetRaw >= amountOutMin)) | |
970 | - | then true | |
971 | - | else throw("Exchange result is fewer coins than expected") | |
972 | - | if ((checkMin == checkMin)) | |
973 | - | then { | |
974 | - | let newXp = if ((isReverse == false)) | |
975 | - | then [(toBigInt(getAccBalance(amId)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
976 | - | else [(toBigInt(getAccBalance(amId)) - dy), (toBigInt(getAccBalance(prId)) + toBigInt(feePoolAmount))] | |
977 | - | let newD = getD(newXp) | |
978 | - | let checkD = if ((newD >= D)) | |
955 | + | let checkMin = if ((amountOut >= amountOutMin)) | |
979 | 956 | then true | |
980 | - | else throw("new D is fewer error") | |
981 | - | if ((checkD == checkD)) | |
982 | - | then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), totalGetRaw, parseAssetId(assetOut))], totalGetRaw) | |
957 | + | else throw("Exchange result is fewer coins than expected") | |
958 | + | if ((checkMin == checkMin)) | |
959 | + | then { | |
960 | + | let rebalanceState = rebalanceAsset(assetIn) | |
961 | + | if ((rebalanceState == rebalanceState)) | |
962 | + | then { | |
963 | + | let withdrawState = withdrawAndRebalanceAsset(assetOut, amountOut) | |
964 | + | if ((withdrawState == withdrawState)) | |
965 | + | then $Tuple2(((withdrawState ++ rebalanceState) ++ [ScriptTransfer(addressFromStringValue(addressTo), amountOut, parseAssetId(assetOut))]), amountOut) | |
966 | + | else throw("Strict value is not equal to itself.") | |
967 | + | } | |
968 | + | else throw("Strict value is not equal to itself.") | |
969 | + | } | |
983 | 970 | else throw("Strict value is not equal to itself.") | |
984 | 971 | } | |
985 | 972 | else throw("Strict value is not equal to itself.") | |
990 | 977 | ||
991 | 978 | ||
992 | 979 | @Callable(i) | |
993 | - | func constructor (fc) = { | |
994 | - | let c = mm(i) | |
995 | - | if ((c == c)) | |
996 | - | then [StringEntry(fc(), fc)] | |
997 | - | else throw("Strict value is not equal to itself.") | |
998 | - | } | |
999 | - | ||
1000 | - | ||
1001 | - | ||
1002 | - | @Callable(i) | |
1003 | 980 | func setManager (pendingManagerPublicKey) = { | |
1004 | - | let | |
1005 | - | if (( | |
981 | + | let checkCaller = mustManager(i) | |
982 | + | if ((checkCaller == checkCaller)) | |
1006 | 983 | then { | |
1007 | - | let | |
1008 | - | if (( | |
984 | + | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
985 | + | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
1009 | 986 | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
1010 | 987 | else throw("Strict value is not equal to itself.") | |
1011 | 988 | } | |
1016 | 993 | ||
1017 | 994 | @Callable(i) | |
1018 | 995 | func confirmManager () = { | |
1019 | - | let | |
1020 | - | let | |
996 | + | let pm = pendingManagerPublicKeyOrUnit() | |
997 | + | let hasPM = if (isDefined(pm)) | |
1021 | 998 | then true | |
1022 | 999 | else throw("No pending manager") | |
1023 | - | if (( | |
1000 | + | if ((hasPM == hasPM)) | |
1024 | 1001 | then { | |
1025 | - | let | |
1002 | + | let checkPM = if ((i.callerPublicKey == value(pm))) | |
1026 | 1003 | then true | |
1027 | 1004 | else throw("You are not pending manager") | |
1028 | - | if (( | |
1029 | - | then [StringEntry(mpk(), toBase58String(value( | |
1005 | + | if ((checkPM == checkPM)) | |
1006 | + | then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())] | |
1030 | 1007 | else throw("Strict value is not equal to itself.") | |
1031 | 1008 | } | |
1032 | 1009 | else throw("Strict value is not equal to itself.") | |
1035 | 1012 | ||
1036 | 1013 | ||
1037 | 1014 | @Callable(i) | |
1038 | - | func put (slip,autoStake) = { | |
1039 | - | let factCfg = gfc() | |
1040 | - | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
1041 | - | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
1042 | - | if ((0 > slip)) | |
1043 | - | then throw("Wrong slippage") | |
1044 | - | else if ((size(i.payments) != 2)) | |
1045 | - | then throw("2 pmnts expd") | |
1046 | - | else { | |
1047 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1048 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1049 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1050 | - | if ((amountAssetBalance == amountAssetBalance)) | |
1015 | + | func put (slippageTolerance,shouldAutoStake) = if ((0 > slippageTolerance)) | |
1016 | + | then throw("Invalid slippageTolerance passed") | |
1017 | + | else { | |
1018 | + | let estPut = commonPut(i, slippageTolerance, true) | |
1019 | + | let emitLpAmt = estPut._2 | |
1020 | + | let lpAssetId = estPut._7 | |
1021 | + | let state = estPut._9 | |
1022 | + | let amDiff = estPut._10 | |
1023 | + | let prDiff = estPut._11 | |
1024 | + | let amId = estPut._12 | |
1025 | + | let prId = estPut._13 | |
1026 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1027 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1028 | + | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1029 | + | if ((currentKLp == currentKLp)) | |
1030 | + | then { | |
1031 | + | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
1032 | + | if ((emitInv == emitInv)) | |
1051 | 1033 | then { | |
1052 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1053 | - | if ((priceAssetBalance == priceAssetBalance)) | |
1034 | + | let emitInvLegacy = match emitInv { | |
1035 | + | case legacyFactoryContract: Address => | |
1036 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
1037 | + | case _ => | |
1038 | + | unit | |
1039 | + | } | |
1040 | + | if ((emitInvLegacy == emitInvLegacy)) | |
1054 | 1041 | then { | |
1055 | - | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1056 | - | if ((lpAssetEmission == lpAssetEmission)) | |
1042 | + | let slippageAInv = if ((amDiff > 0)) | |
1043 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1044 | + | else nil | |
1045 | + | if ((slippageAInv == slippageAInv)) | |
1057 | 1046 | then { | |
1058 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1059 | - | if ((currentDLp == currentDLp)) | |
1047 | + | let slippagePInv = if ((prDiff > 0)) | |
1048 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1049 | + | else nil | |
1050 | + | if ((slippagePInv == slippagePInv)) | |
1060 | 1051 | then { | |
1061 | - | 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, "") | |
1062 | - | let emitLpAmt = e._2 | |
1063 | - | let lpAssetId = e._7 | |
1064 | - | let state = e._9 | |
1065 | - | let amDiff = e._10 | |
1066 | - | let prDiff = e._11 | |
1067 | - | let amId = e._12 | |
1068 | - | let prId = e._13 | |
1069 | - | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1070 | - | if ((r == r)) | |
1052 | + | let lpTransfer = if (shouldAutoStake) | |
1071 | 1053 | then { | |
1072 | - | let el = match r { | |
1073 | - | case legacy: Address => | |
1074 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1075 | - | case _ => | |
1076 | - | unit | |
1054 | + | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1055 | + | if ((slpStakeInv == slpStakeInv)) | |
1056 | + | then nil | |
1057 | + | else throw("Strict value is not equal to itself.") | |
1077 | 1058 | } | |
1078 | - | if ((el == el)) | |
1059 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1060 | + | let $t04447644938 = refreshKLpInternal(0, 0, 0) | |
1061 | + | if (($t04447644938 == $t04447644938)) | |
1062 | + | then { | |
1063 | + | let updatedKLp = $t04447644938._2 | |
1064 | + | let refreshKLpActions = $t04447644938._1 | |
1065 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1066 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1079 | 1067 | then { | |
1080 | - | let sa = if ((amDiff > 0)) | |
1081 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1082 | - | else nil | |
1083 | - | if ((sa == sa)) | |
1084 | - | then { | |
1085 | - | let sp = if ((prDiff > 0)) | |
1086 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1087 | - | else nil | |
1088 | - | if ((sp == sp)) | |
1089 | - | then { | |
1090 | - | let lpTrnsfr = if (autoStake) | |
1091 | - | then { | |
1092 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1093 | - | if ((ss == ss)) | |
1094 | - | then nil | |
1095 | - | else throw("Strict value is not equal to itself.") | |
1096 | - | } | |
1097 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1098 | - | let $t04194842090 = refreshDLpInternal(0, 0, 0) | |
1099 | - | let refreshDLpActions = $t04194842090._1 | |
1100 | - | let updatedDLp = $t04194842090._2 | |
1101 | - | let check = if ((updatedDLp >= currentDLp)) | |
1102 | - | then true | |
1103 | - | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1104 | - | if ((check == check)) | |
1105 | - | then { | |
1106 | - | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1107 | - | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1108 | - | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1109 | - | else throw("Strict value is not equal to itself.") | |
1110 | - | } | |
1111 | - | else throw("Strict value is not equal to itself.") | |
1112 | - | } | |
1113 | - | else throw("Strict value is not equal to itself.") | |
1114 | - | } | |
1068 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1069 | + | if ((reb == reb)) | |
1070 | + | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
1115 | 1071 | else throw("Strict value is not equal to itself.") | |
1116 | 1072 | } | |
1117 | 1073 | else throw("Strict value is not equal to itself.") | |
1126 | 1082 | } | |
1127 | 1083 | else throw("Strict value is not equal to itself.") | |
1128 | 1084 | } | |
1129 | - | } | |
1085 | + | else throw("Strict value is not equal to itself.") | |
1086 | + | } | |
1130 | 1087 | ||
1131 | 1088 | ||
1132 | 1089 | ||
1133 | 1090 | @Callable(i) | |
1134 | - | func putOneTknV2 (minOutAmount,autoStake) = { | |
1091 | + | func putForFree (maxSlippage) = if ((0 > maxSlippage)) | |
1092 | + | then throw("Invalid value passed") | |
1093 | + | else { | |
1094 | + | let estPut = commonPut(i, maxSlippage, false) | |
1095 | + | let state = estPut._9 | |
1096 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1097 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1098 | + | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1099 | + | if ((currentKLp == currentKLp)) | |
1100 | + | then { | |
1101 | + | let $t04555045615 = refreshKLpInternal(0, 0, 0) | |
1102 | + | let refreshKLpActions = $t04555045615._1 | |
1103 | + | let updatedKLp = $t04555045615._2 | |
1104 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1105 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1106 | + | then (state ++ refreshKLpActions) | |
1107 | + | else throw("Strict value is not equal to itself.") | |
1108 | + | } | |
1109 | + | else throw("Strict value is not equal to itself.") | |
1110 | + | } | |
1111 | + | ||
1112 | + | ||
1113 | + | ||
1114 | + | @Callable(i) | |
1115 | + | func putOneTkn (minOutAmount,autoStake) = { | |
1135 | 1116 | let isPoolOneTokenOperationsDisabled = { | |
1136 | - | let @ = invoke( | |
1117 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1137 | 1118 | if ($isInstanceOf(@, "Boolean")) | |
1138 | 1119 | then @ | |
1139 | 1120 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1140 | 1121 | } | |
1141 | - | let isPutDisabled = if (if (if ( | |
1122 | + | let isPutDisabled = if (if (if (isGlobalShutdown()) | |
1142 | 1123 | then true | |
1143 | - | else (cfgPoolStatus == | |
1124 | + | else (cfgPoolStatus == PoolPutDisabled)) | |
1144 | 1125 | then true | |
1145 | 1126 | else (cfgPoolStatus == PoolShutdown)) | |
1146 | 1127 | then true | |
1154 | 1135 | else throwErr("exactly 1 payment are expected")] | |
1155 | 1136 | if ((checks == checks)) | |
1156 | 1137 | then { | |
1157 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1158 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1159 | - | let lpId = cfgLpAssetId | |
1160 | - | let amDecimals = cfgAmountAssetDecimals | |
1161 | - | let prDecimals = cfgPriceAssetDecimals | |
1162 | - | let userAddress = if ((i.caller == this)) | |
1163 | - | then i.originCaller | |
1164 | - | else i.caller | |
1165 | - | let pmt = value(i.payments[0]) | |
1166 | - | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1167 | - | let pmtAmt = pmt.amount | |
1168 | - | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1169 | - | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1170 | - | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1171 | - | if ((currentDLp == currentDLp)) | |
1138 | + | let payment = i.payments[0] | |
1139 | + | let paymentAssetId = payment.assetId | |
1140 | + | let paymentAmountRaw = payment.amount | |
1141 | + | let currentKLp = if ((paymentAssetId == cfgAmountAssetId)) | |
1142 | + | then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0)) | |
1143 | + | else if ((paymentAssetId == cfgPriceAssetId)) | |
1144 | + | then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0)) | |
1145 | + | else throwErr("payment asset is not supported") | |
1146 | + | if ((currentKLp == currentKLp)) | |
1172 | 1147 | then { | |
1173 | - | let $t04373143889 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1174 | - | if (($t04373143889 == $t04373143889)) | |
1148 | + | let userAddress = i.caller | |
1149 | + | let txId = i.transactionId | |
1150 | + | let $t04680346955 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
1151 | + | if (($t04680346955 == $t04680346955)) | |
1175 | 1152 | then { | |
1176 | - | let feeAmount = $t04373143889._3 | |
1177 | - | let state = $t04373143889._2 | |
1178 | - | let estimLP = $t04373143889._1 | |
1179 | - | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1180 | - | then (minOutAmount > estimLP) | |
1153 | + | let paymentInAmountAsset = $t04680346955._5 | |
1154 | + | let bonus = $t04680346955._4 | |
1155 | + | let feeAmount = $t04680346955._3 | |
1156 | + | let commonState = $t04680346955._2 | |
1157 | + | let emitAmountEstimated = $t04680346955._1 | |
1158 | + | let emitAmount = if (if ((minOutAmount > 0)) | |
1159 | + | then (minOutAmount > emitAmountEstimated) | |
1181 | 1160 | else false) | |
1182 | 1161 | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1183 | - | else | |
1184 | - | let | |
1185 | - | if (( | |
1162 | + | else emitAmountEstimated | |
1163 | + | let emitInv = emit(emitAmount) | |
1164 | + | if ((emitInv == emitInv)) | |
1186 | 1165 | then { | |
1187 | - | let el = match e { | |
1188 | - | case legacy: Address => | |
1189 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1190 | - | case _ => | |
1191 | - | unit | |
1192 | - | } | |
1193 | - | if ((el == el)) | |
1166 | + | let lpTransfer = if (autoStake) | |
1194 | 1167 | then { | |
1195 | - | let lpTrnsfr = if (autoStake) | |
1196 | - | then { | |
1197 | - | let ss = invoke(stakingContract, "stakeFor", [toString(i.caller)], [AttachedPayment(lpId, emitLpAmt)]) | |
1198 | - | if ((ss == ss)) | |
1199 | - | then nil | |
1200 | - | else throw("Strict value is not equal to itself.") | |
1201 | - | } | |
1202 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1203 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1204 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1205 | - | else nil | |
1206 | - | let $t04477445123 = if ((this == feeCollectorAddress)) | |
1207 | - | then $Tuple2(0, 0) | |
1208 | - | else { | |
1209 | - | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1210 | - | then true | |
1211 | - | else false | |
1212 | - | if (paymentInAmountAsset) | |
1213 | - | then $Tuple2(-(feeAmount), 0) | |
1214 | - | else $Tuple2(0, -(feeAmount)) | |
1215 | - | } | |
1216 | - | let amountAssetBalanceDelta = $t04477445123._1 | |
1217 | - | let priceAssetBalanceDelta = $t04477445123._2 | |
1218 | - | let $t04512645234 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1219 | - | let refreshDLpActions = $t04512645234._1 | |
1220 | - | let updatedDLp = $t04512645234._2 | |
1221 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1222 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1223 | - | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
1168 | + | let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)]) | |
1169 | + | if ((stakeInv == stakeInv)) | |
1170 | + | then nil | |
1171 | + | else throw("Strict value is not equal to itself.") | |
1172 | + | } | |
1173 | + | else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)] | |
1174 | + | let sendFee = if ((feeAmount > 0)) | |
1175 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)] | |
1176 | + | else nil | |
1177 | + | let $t04754147738 = if ((this == feeCollectorAddress)) | |
1178 | + | then $Tuple2(0, 0) | |
1179 | + | else if (paymentInAmountAsset) | |
1180 | + | then $Tuple2(-(feeAmount), 0) | |
1181 | + | else $Tuple2(0, -(feeAmount)) | |
1182 | + | let amountAssetBalanceDelta = $t04754147738._1 | |
1183 | + | let priceAssetBalanceDelta = $t04754147738._2 | |
1184 | + | let $t04774147849 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1185 | + | let refreshKLpActions = $t04774147849._1 | |
1186 | + | let updatedKLp = $t04774147849._2 | |
1187 | + | let kLp = value(getString(keyKLp)) | |
1188 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1189 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1190 | + | then { | |
1191 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1192 | + | if ((reb == reb)) | |
1193 | + | then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount) | |
1224 | 1194 | else throw("Strict value is not equal to itself.") | |
1225 | 1195 | } | |
1226 | 1196 | else throw("Strict value is not equal to itself.") | |
1237 | 1207 | ||
1238 | 1208 | ||
1239 | 1209 | @Callable(i) | |
1240 | - | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1241 | - | then throw("Wrong slpg") | |
1242 | - | else if ((size(i.payments) != 2)) | |
1243 | - | then throw("2 pmnts expd") | |
1244 | - | else { | |
1245 | - | 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, "") | |
1246 | - | let state = estPut._9 | |
1247 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1248 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1249 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1250 | - | if ((currentDLp == currentDLp)) | |
1251 | - | then { | |
1252 | - | let $t04626446329 = refreshDLpInternal(0, 0, 0) | |
1253 | - | let refreshDLpActions = $t04626446329._1 | |
1254 | - | let updatedDLp = $t04626446329._2 | |
1255 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1256 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1257 | - | then (state ++ refreshDLpActions) | |
1258 | - | else throw("Strict value is not equal to itself.") | |
1259 | - | } | |
1260 | - | else throw("Strict value is not equal to itself.") | |
1261 | - | } | |
1262 | - | ||
1263 | - | ||
1264 | - | ||
1265 | - | @Callable(i) | |
1266 | - | func get () = { | |
1267 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1268 | - | if ((currentDLp == currentDLp)) | |
1269 | - | then { | |
1270 | - | let r = cg(i) | |
1271 | - | let outAmtAmt = r._1 | |
1272 | - | let outPrAmt = r._2 | |
1273 | - | let pmtAmt = r._3 | |
1274 | - | let pmtAssetId = r._4 | |
1275 | - | let state = r._5 | |
1276 | - | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1277 | - | if ((b == b)) | |
1278 | - | then { | |
1279 | - | let $t04750247584 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1280 | - | let refreshDLpActions = $t04750247584._1 | |
1281 | - | let updatedDLp = $t04750247584._2 | |
1282 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1283 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1284 | - | then (state ++ refreshDLpActions) | |
1285 | - | else throw("Strict value is not equal to itself.") | |
1286 | - | } | |
1287 | - | else throw("Strict value is not equal to itself.") | |
1288 | - | } | |
1289 | - | else throw("Strict value is not equal to itself.") | |
1210 | + | func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = { | |
1211 | + | let $t04820448361 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
1212 | + | let emitAmountEstimated = $t04820448361._1 | |
1213 | + | let commonState = $t04820448361._2 | |
1214 | + | let feeAmount = $t04820448361._3 | |
1215 | + | let bonus = $t04820448361._4 | |
1216 | + | let paymentInAmountAsset = $t04820448361._5 | |
1217 | + | $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus)) | |
1290 | 1218 | } | |
1291 | 1219 | ||
1292 | 1220 | ||
1293 | 1221 | ||
1294 | 1222 | @Callable(i) | |
1295 | - | func | |
1223 | + | func getOneTkn (outAssetIdStr,minOutAmount) = { | |
1296 | 1224 | let isPoolOneTokenOperationsDisabled = { | |
1297 | - | let @ = invoke( | |
1225 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1298 | 1226 | if ($isInstanceOf(@, "Boolean")) | |
1299 | 1227 | then @ | |
1300 | 1228 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1301 | 1229 | } | |
1302 | - | let isGetDisabled = if (if ( | |
1230 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1303 | 1231 | then true | |
1304 | 1232 | else (cfgPoolStatus == PoolShutdown)) | |
1305 | 1233 | then true | |
1313 | 1241 | else throwErr("exactly 1 payment are expected")] | |
1314 | 1242 | if ((checks == checks)) | |
1315 | 1243 | then { | |
1316 | - | let $t04820248357 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1317 | - | let state = $t04820248357._1 | |
1318 | - | let totalAmount = $t04820248357._2 | |
1319 | - | $Tuple2(state, totalAmount) | |
1244 | + | let outAssetId = parseAssetId(outAssetIdStr) | |
1245 | + | let payment = i.payments[0] | |
1246 | + | let paymentAssetId = payment.assetId | |
1247 | + | let paymentAmount = payment.amount | |
1248 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1249 | + | if ((currentKLp == currentKLp)) | |
1250 | + | then { | |
1251 | + | let userAddress = i.caller | |
1252 | + | let txId = i.transactionId | |
1253 | + | let $t04924649399 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId) | |
1254 | + | if (($t04924649399 == $t04924649399)) | |
1255 | + | then { | |
1256 | + | let outInAmountAsset = $t04924649399._5 | |
1257 | + | let bonus = $t04924649399._4 | |
1258 | + | let feeAmount = $t04924649399._3 | |
1259 | + | let commonState = $t04924649399._2 | |
1260 | + | let amountEstimated = $t04924649399._1 | |
1261 | + | let amount = if (if ((minOutAmount > 0)) | |
1262 | + | then (minOutAmount > amountEstimated) | |
1263 | + | else false) | |
1264 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1265 | + | else amountEstimated | |
1266 | + | let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
1267 | + | if ((burnInv == burnInv)) | |
1268 | + | then { | |
1269 | + | let withdrawState = withdrawAndRebalanceAsset(outAssetIdStr, (amount + max([0, feeAmount]))) | |
1270 | + | let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)] | |
1271 | + | let sendFee = if ((feeAmount > 0)) | |
1272 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1273 | + | else nil | |
1274 | + | let $t05006350310 = { | |
1275 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1276 | + | then 0 | |
1277 | + | else feeAmount | |
1278 | + | if (outInAmountAsset) | |
1279 | + | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1280 | + | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1281 | + | } | |
1282 | + | let amountAssetBalanceDelta = $t05006350310._1 | |
1283 | + | let priceAssetBalanceDelta = $t05006350310._2 | |
1284 | + | let $t05031350421 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1285 | + | let refreshKLpActions = $t05031350421._1 | |
1286 | + | let updatedKLp = $t05031350421._2 | |
1287 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1288 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1289 | + | then $Tuple2(((((commonState ++ withdrawState) ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1290 | + | else throw("Strict value is not equal to itself.") | |
1291 | + | } | |
1292 | + | else throw("Strict value is not equal to itself.") | |
1293 | + | } | |
1294 | + | else throw("Strict value is not equal to itself.") | |
1295 | + | } | |
1296 | + | else throw("Strict value is not equal to itself.") | |
1320 | 1297 | } | |
1321 | 1298 | else throw("Strict value is not equal to itself.") | |
1322 | 1299 | } | |
1324 | 1301 | ||
1325 | 1302 | ||
1326 | 1303 | @Callable(i) | |
1327 | - | func refreshDLp () = { | |
1328 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1329 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1330 | - | then unit | |
1331 | - | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1332 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1304 | + | func getOneTknREADONLY (outAssetId,paymentAmount) = { | |
1305 | + | let $t05069950855 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
1306 | + | let amountEstimated = $t05069950855._1 | |
1307 | + | let commonState = $t05069950855._2 | |
1308 | + | let feeAmount = $t05069950855._3 | |
1309 | + | let bonus = $t05069950855._4 | |
1310 | + | let outInAmountAsset = $t05069950855._5 | |
1311 | + | $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus)) | |
1312 | + | } | |
1313 | + | ||
1314 | + | ||
1315 | + | ||
1316 | + | @Callable(i) | |
1317 | + | func unstakeAndGetOneTkn (unstakeAmount,outAssetIdStr,minOutAmount) = { | |
1318 | + | let isPoolOneTokenOperationsDisabled = { | |
1319 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1320 | + | if ($isInstanceOf(@, "Boolean")) | |
1321 | + | then @ | |
1322 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1323 | + | } | |
1324 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1325 | + | then true | |
1326 | + | else (cfgPoolStatus == PoolShutdown)) | |
1327 | + | then true | |
1328 | + | else isPoolOneTokenOperationsDisabled | |
1329 | + | let checks = [if (if (!(isGetDisabled)) | |
1330 | + | then true | |
1331 | + | else isManager(i)) | |
1332 | + | then true | |
1333 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1334 | + | then true | |
1335 | + | else throwErr("no payments are expected")] | |
1336 | + | if ((checks == checks)) | |
1333 | 1337 | then { | |
1334 | - | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1335 | - | let $t04888148945 = refreshDLpInternal(0, 0, 0) | |
1336 | - | let dLpUpdateActions = $t04888148945._1 | |
1337 | - | let updatedDLp = $t04888148945._2 | |
1338 | - | let actions = if ((dLp != updatedDLp)) | |
1339 | - | then dLpUpdateActions | |
1340 | - | else throwErr("nothing to refresh") | |
1341 | - | $Tuple2(actions, toString(updatedDLp)) | |
1338 | + | let outAssetId = parseAssetId(outAssetIdStr) | |
1339 | + | let userAddress = i.caller | |
1340 | + | let txId = i.transactionId | |
1341 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1342 | + | if ((currentKLp == currentKLp)) | |
1343 | + | then { | |
1344 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1345 | + | if ((unstakeInv == unstakeInv)) | |
1346 | + | then { | |
1347 | + | let $t05176051911 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
1348 | + | if (($t05176051911 == $t05176051911)) | |
1349 | + | then { | |
1350 | + | let outInAmountAsset = $t05176051911._5 | |
1351 | + | let bonus = $t05176051911._4 | |
1352 | + | let feeAmount = $t05176051911._3 | |
1353 | + | let commonState = $t05176051911._2 | |
1354 | + | let amountEstimated = $t05176051911._1 | |
1355 | + | let amount = if (if ((minOutAmount > 0)) | |
1356 | + | then (minOutAmount > amountEstimated) | |
1357 | + | else false) | |
1358 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1359 | + | else amountEstimated | |
1360 | + | let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1361 | + | if ((burnInv == burnInv)) | |
1362 | + | then { | |
1363 | + | let withdrawState = withdrawAndRebalanceAsset(outAssetIdStr, (amount + max([0, feeAmount]))) | |
1364 | + | let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)] | |
1365 | + | let sendFee = if ((feeAmount > 0)) | |
1366 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1367 | + | else nil | |
1368 | + | let $t05257052817 = { | |
1369 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1370 | + | then 0 | |
1371 | + | else feeAmount | |
1372 | + | if (outInAmountAsset) | |
1373 | + | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1374 | + | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1375 | + | } | |
1376 | + | let amountAssetBalanceDelta = $t05257052817._1 | |
1377 | + | let priceAssetBalanceDelta = $t05257052817._2 | |
1378 | + | let $t05282052928 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1379 | + | let refreshKLpActions = $t05282052928._1 | |
1380 | + | let updatedKLp = $t05282052928._2 | |
1381 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1382 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1383 | + | then $Tuple2(((((commonState ++ withdrawState) ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1384 | + | else throw("Strict value is not equal to itself.") | |
1385 | + | } | |
1386 | + | else throw("Strict value is not equal to itself.") | |
1387 | + | } | |
1388 | + | else throw("Strict value is not equal to itself.") | |
1389 | + | } | |
1390 | + | else throw("Strict value is not equal to itself.") | |
1391 | + | } | |
1392 | + | else throw("Strict value is not equal to itself.") | |
1342 | 1393 | } | |
1343 | 1394 | else throw("Strict value is not equal to itself.") | |
1344 | 1395 | } | |
1346 | 1397 | ||
1347 | 1398 | ||
1348 | 1399 | @Callable(i) | |
1349 | - | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1350 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1351 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1352 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1353 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1354 | - | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1355 | - | let D0 = getD(xp) | |
1356 | - | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1357 | - | let index = if ((outAssetId == amId)) | |
1358 | - | then 0 | |
1359 | - | else if ((outAssetId == prId)) | |
1360 | - | then 1 | |
1361 | - | else throw("invalid out asset id") | |
1362 | - | let newY = getYD(xp, index, D1) | |
1363 | - | let dy = (xp[index] - newY) | |
1364 | - | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1365 | - | let $t04995550010 = takeFee(totalGetRaw, outFee) | |
1366 | - | let totalGet = $t04995550010._1 | |
1367 | - | let feeAmount = $t04995550010._2 | |
1368 | - | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1369 | - | } | |
1370 | - | ||
1371 | - | ||
1372 | - | ||
1373 | - | @Callable(i) | |
1374 | - | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1375 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1376 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1377 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1378 | - | let amBalance = getAccBalance(amId) | |
1379 | - | let prBalance = getAccBalance(prId) | |
1380 | - | let $t05038550500 = { | |
1381 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1382 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
1383 | - | then @ | |
1384 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1385 | - | } | |
1386 | - | let totalGet = $t05038550500._1 | |
1387 | - | let feeAmount = $t05038550500._2 | |
1388 | - | let r = ego("", lpId, lpAssetAmount, this) | |
1389 | - | let outAmAmt = r._1 | |
1390 | - | let outPrAmt = r._2 | |
1391 | - | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1392 | - | let bonus = if ((sumOfGetAssets == 0)) | |
1393 | - | then if ((totalGet == 0)) | |
1394 | - | then 0 | |
1395 | - | else throw("bonus calculation error") | |
1396 | - | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1397 | - | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1400 | + | func get () = { | |
1401 | + | let res = commonGet(i) | |
1402 | + | let outAmAmt = res._1 | |
1403 | + | let outPrAmt = res._2 | |
1404 | + | let pmtAmt = res._3 | |
1405 | + | let pmtAssetId = res._4 | |
1406 | + | let state = res._5 | |
1407 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1408 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1409 | + | if ((currentKLp == currentKLp)) | |
1410 | + | then { | |
1411 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1412 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1413 | + | then { | |
1414 | + | let $t05402354104 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1415 | + | let refreshKLpActions = $t05402354104._1 | |
1416 | + | let updatedKLp = $t05402354104._2 | |
1417 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1418 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1419 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1420 | + | else throw("Strict value is not equal to itself.") | |
1421 | + | } | |
1422 | + | else throw("Strict value is not equal to itself.") | |
1423 | + | } | |
1424 | + | else throw("Strict value is not equal to itself.") | |
1398 | 1425 | } | |
1399 | 1426 | ||
1400 | 1427 | ||
1401 | 1428 | ||
1402 | 1429 | @Callable(i) | |
1403 | 1430 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
1404 | - | let | |
1405 | - | let outAmAmt = | |
1406 | - | let outPrAmt = | |
1407 | - | let pmtAmt = | |
1408 | - | let pmtAssetId = | |
1409 | - | let state = | |
1431 | + | let res = commonGet(i) | |
1432 | + | let outAmAmt = res._1 | |
1433 | + | let outPrAmt = res._2 | |
1434 | + | let pmtAmt = res._3 | |
1435 | + | let pmtAssetId = res._4 | |
1436 | + | let state = res._5 | |
1410 | 1437 | if ((noLessThenAmtAsset > outAmAmt)) | |
1411 | - | then throw((((" | |
1438 | + | then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1412 | 1439 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1413 | - | then throw((((" | |
1440 | + | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1414 | 1441 | else { | |
1415 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1416 | - | if ((currentDLp == currentDLp)) | |
1442 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1443 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1444 | + | if ((currentKLp == currentKLp)) | |
1417 | 1445 | then { | |
1418 | - | let burnLPAssetOnFactory = invoke( | |
1446 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1419 | 1447 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1420 | 1448 | then { | |
1421 | - | let $ | |
1422 | - | let | |
1423 | - | let | |
1424 | - | let | |
1425 | - | if (( | |
1426 | - | then ( | |
1449 | + | let $t05519955280 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1450 | + | let refreshKLpActions = $t05519955280._1 | |
1451 | + | let updatedKLp = $t05519955280._2 | |
1452 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1453 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1454 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1427 | 1455 | else throw("Strict value is not equal to itself.") | |
1428 | 1456 | } | |
1429 | 1457 | else throw("Strict value is not equal to itself.") | |
1437 | 1465 | @Callable(i) | |
1438 | 1466 | func unstakeAndGet (amount) = { | |
1439 | 1467 | let checkPayments = if ((size(i.payments) != 0)) | |
1440 | - | then throw("No | |
1468 | + | then throw("No payments are expected") | |
1441 | 1469 | else true | |
1442 | 1470 | if ((checkPayments == checkPayments)) | |
1443 | 1471 | then { | |
1444 | - | let factoryCfg = gfc() | |
1445 | - | let lpAssetId = cfgLpAssetId | |
1446 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1447 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1448 | - | if ((currentDLp == currentDLp)) | |
1472 | + | let cfg = getPoolConfig() | |
1473 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1474 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1475 | + | if ((currentKLp == currentKLp)) | |
1449 | 1476 | then { | |
1450 | - | let unstakeInv = invoke( | |
1477 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1451 | 1478 | if ((unstakeInv == unstakeInv)) | |
1452 | 1479 | then { | |
1453 | - | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1454 | - | let outAmAmt = r._1 | |
1455 | - | let outPrAmt = r._2 | |
1456 | - | let sts = parseIntValue(r._9) | |
1457 | - | let state = r._10 | |
1458 | - | let v = if (if (igs()) | |
1480 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1481 | + | let outAmAmt = res._1 | |
1482 | + | let outPrAmt = res._2 | |
1483 | + | let poolStatus = parseIntValue(res._9) | |
1484 | + | let state = res._10 | |
1485 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1486 | + | let checkPoolStatus = if (if (isGlobalShutdown()) | |
1459 | 1487 | then true | |
1460 | - | else ( | |
1461 | - | then throw((" | |
1488 | + | else (poolStatus == PoolShutdown)) | |
1489 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
1462 | 1490 | else true | |
1463 | - | if (( | |
1491 | + | if ((checkPoolStatus == checkPoolStatus)) | |
1464 | 1492 | then { | |
1465 | - | let | |
1466 | - | if (( | |
1493 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1494 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1467 | 1495 | then { | |
1468 | - | let $ | |
1469 | - | let | |
1470 | - | let | |
1471 | - | let | |
1472 | - | if (( | |
1473 | - | then ( | |
1496 | + | let $t05655256633 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1497 | + | let refreshKLpActions = $t05655256633._1 | |
1498 | + | let updatedKLp = $t05655256633._2 | |
1499 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1500 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1501 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1474 | 1502 | else throw("Strict value is not equal to itself.") | |
1475 | 1503 | } | |
1476 | 1504 | else throw("Strict value is not equal to itself.") | |
1488 | 1516 | ||
1489 | 1517 | @Callable(i) | |
1490 | 1518 | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1491 | - | let isGetDisabled = if ( | |
1519 | + | let isGetDisabled = if (isGlobalShutdown()) | |
1492 | 1520 | then true | |
1493 | 1521 | else (cfgPoolStatus == PoolShutdown) | |
1494 | 1522 | let checks = [if (!(isGetDisabled)) | |
1498 | 1526 | else throw("no payments are expected")] | |
1499 | 1527 | if ((checks == checks)) | |
1500 | 1528 | then { | |
1501 | - | let | |
1502 | - | if (( | |
1529 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1530 | + | if ((currentKLp == currentKLp)) | |
1503 | 1531 | then { | |
1504 | 1532 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1505 | 1533 | if ((unstakeInv == unstakeInv)) | |
1506 | 1534 | then { | |
1507 | - | let res = | |
1535 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1508 | 1536 | let outAmAmt = res._1 | |
1509 | 1537 | let outPrAmt = res._2 | |
1510 | 1538 | let state = res._10 | |
1539 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1511 | 1540 | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1512 | 1541 | then true | |
1513 | 1542 | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1515 | 1544 | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1516 | 1545 | if ((checkAmounts == checkAmounts)) | |
1517 | 1546 | then { | |
1518 | - | let burnLPAssetOnFactory = invoke( | |
1547 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1519 | 1548 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1520 | 1549 | then { | |
1521 | - | let $ | |
1522 | - | let | |
1523 | - | let | |
1524 | - | let | |
1525 | - | if (( | |
1526 | - | then ( | |
1550 | + | let $t05807458155 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1551 | + | let refreshKLpActions = $t05807458155._1 | |
1552 | + | let updatedKLp = $t05807458155._2 | |
1553 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1554 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1555 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1527 | 1556 | else throw("Strict value is not equal to itself.") | |
1528 | 1557 | } | |
1529 | 1558 | else throw("Strict value is not equal to itself.") | |
1540 | 1569 | ||
1541 | 1570 | ||
1542 | 1571 | @Callable(i) | |
1543 | - | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1544 | - | let isPoolOneTokenOperationsDisabled = { | |
1545 | - | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1546 | - | if ($isInstanceOf(@, "Boolean")) | |
1547 | - | then @ | |
1548 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1549 | - | } | |
1550 | - | let isGetDisabled = if (if (igs()) | |
1551 | - | then true | |
1552 | - | else (cfgPoolStatus == PoolShutdown)) | |
1553 | - | then true | |
1554 | - | else isPoolOneTokenOperationsDisabled | |
1555 | - | let checks = [if (if (!(isGetDisabled)) | |
1556 | - | then true | |
1557 | - | else isManager(i)) | |
1558 | - | then true | |
1559 | - | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1560 | - | then true | |
1561 | - | else throwErr("no payments are expected")] | |
1562 | - | if ((checks == checks)) | |
1572 | + | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
1573 | + | then throw("permissions denied") | |
1574 | + | else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success") | |
1575 | + | ||
1576 | + | ||
1577 | + | ||
1578 | + | @Callable(i) | |
1579 | + | func refreshKLp () = { | |
1580 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0) | |
1581 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay)) | |
1582 | + | then unit | |
1583 | + | else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1584 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1563 | 1585 | then { | |
1564 | - | let factoryCfg = gfc() | |
1565 | - | let lpAssetId = cfgLpAssetId | |
1566 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1567 | - | let userAddress = i.caller | |
1568 | - | let lpAssetRecipientAddress = this | |
1569 | - | let unstakeInv = invoke(staking, "unstakeINTERNAL", [lpAssetId, unstakeAmount, userAddress.bytes, lpAssetRecipientAddress.bytes], nil) | |
1570 | - | if ((unstakeInv == unstakeInv)) | |
1571 | - | then { | |
1572 | - | let $t05520955397 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1573 | - | let state = $t05520955397._1 | |
1574 | - | let totalAmount = $t05520955397._2 | |
1575 | - | $Tuple2(state, totalAmount) | |
1576 | - | } | |
1577 | - | else throw("Strict value is not equal to itself.") | |
1586 | + | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
1587 | + | let $t05935959423 = refreshKLpInternal(0, 0, 0) | |
1588 | + | let kLpUpdateActions = $t05935959423._1 | |
1589 | + | let updatedKLp = $t05935959423._2 | |
1590 | + | let actions = if ((kLp != updatedKLp)) | |
1591 | + | then kLpUpdateActions | |
1592 | + | else throwErr("nothing to refresh") | |
1593 | + | $Tuple2(actions, toString(updatedKLp)) | |
1578 | 1594 | } | |
1579 | 1595 | else throw("Strict value is not equal to itself.") | |
1580 | 1596 | } | |
1582 | 1598 | ||
1583 | 1599 | ||
1584 | 1600 | @Callable(i) | |
1585 | - | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1586 | - | let $t05552555628 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1587 | - | let lpAmount = $t05552555628._1 | |
1588 | - | let state = $t05552555628._2 | |
1589 | - | let feeAmount = $t05552555628._3 | |
1590 | - | let bonus = $t05552555628._4 | |
1591 | - | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1592 | - | } | |
1593 | - | ||
1594 | - | ||
1595 | - | ||
1596 | - | @Callable(i) | |
1597 | - | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1598 | - | let $t05577655880 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1599 | - | let lpAmount = $t05577655880._1 | |
1600 | - | let state = $t05577655880._2 | |
1601 | - | let feeAmount = $t05577655880._3 | |
1602 | - | let bonus = $t05577655880._4 | |
1603 | - | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1604 | - | } | |
1605 | - | ||
1606 | - | ||
1607 | - | ||
1608 | - | @Callable(i) | |
1609 | - | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1610 | - | then throw("denied") | |
1611 | - | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr), StringEntry(amp(), toString(ampInitial))], "success") | |
1612 | - | ||
1613 | - | ||
1614 | - | ||
1615 | - | @Callable(i) | |
1616 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
1601 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1617 | 1602 | ||
1618 | 1603 | ||
1619 | 1604 | ||
1624 | 1609 | ||
1625 | 1610 | @Callable(i) | |
1626 | 1611 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1627 | - | let | |
1628 | - | $Tuple2(nil, [toString( | |
1612 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
1613 | + | $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])]) | |
1629 | 1614 | } | |
1630 | 1615 | ||
1631 | 1616 | ||
1632 | 1617 | ||
1633 | 1618 | @Callable(i) | |
1634 | - | func | |
1619 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
1635 | 1620 | ||
1636 | 1621 | ||
1637 | 1622 | ||
1638 | 1623 | @Callable(i) | |
1639 | - | func | |
1624 | + | func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult)) | |
1640 | 1625 | ||
1641 | 1626 | ||
1642 | 1627 | ||
1643 | 1628 | @Callable(i) | |
1644 | - | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString( | |
1629 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1645 | 1630 | ||
1646 | 1631 | ||
1647 | 1632 | ||
1648 | 1633 | @Callable(i) | |
1649 | - | func estimatePutOperationWrapperREADONLY (txId58, | |
1634 | + | func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp)) | |
1650 | 1635 | ||
1651 | 1636 | ||
1652 | 1637 | ||
1653 | 1638 | @Callable(i) | |
1654 | - | func estimateGetOperationWrapperREADONLY (txId58, | |
1655 | - | let | |
1656 | - | $Tuple2(nil, $Tuple10( | |
1639 | + | func estimateGetOperationWrapperREADONLY (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
1640 | + | let res = estimateGetOperation(txId58, pmtAssetId, pmtLpAmt, addressFromStringValue(userAddress)) | |
1641 | + | $Tuple2(nil, $Tuple10(res._1, res._2, res._3, res._4, res._5, res._6, res._7, toString(res._8), res._9, res._10)) | |
1657 | 1642 | } | |
1658 | 1643 | ||
1659 | 1644 | ||
1660 | 1645 | ||
1661 | 1646 | @Callable(i) | |
1662 | - | func changeAmp () = { | |
1663 | - | let cfg = invoke(fca, "getChangeAmpConfigREADONLY", [toString(this)], nil) | |
1664 | - | let $t05828958488 = match cfg { | |
1665 | - | case list: List[Any] => | |
1666 | - | $Tuple3({ | |
1667 | - | let @ = list[0] | |
1668 | - | if ($isInstanceOf(@, "Int")) | |
1669 | - | then @ | |
1670 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1671 | - | }, { | |
1672 | - | let @ = list[1] | |
1673 | - | if ($isInstanceOf(@, "Int")) | |
1674 | - | then @ | |
1675 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1676 | - | }, { | |
1677 | - | let @ = list[2] | |
1678 | - | if ($isInstanceOf(@, "Int")) | |
1679 | - | then @ | |
1680 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1681 | - | }) | |
1682 | - | case _ => | |
1683 | - | throwErr("invalid entry type") | |
1647 | + | func statsREADONLY () = { | |
1648 | + | let cfg = getPoolConfig() | |
1649 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1650 | + | let amtAssetId = cfg[idxAmtAssetId] | |
1651 | + | let priceAssetId = cfg[idxPriceAssetId] | |
1652 | + | let iAmtAssetId = cfg[idxIAmtAssetId] | |
1653 | + | let iPriceAssetId = cfg[idxIPriceAssetId] | |
1654 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1655 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1656 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1657 | + | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
1658 | + | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
1659 | + | let pricesList = if ((poolLPBalance == 0)) | |
1660 | + | then [zeroBigInt, zeroBigInt, zeroBigInt] | |
1661 | + | else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance) | |
1662 | + | let curPrice = 0 | |
1663 | + | let lpAmtAssetShare = fromX18(pricesList[1], scale8) | |
1664 | + | let lpPriceAssetShare = fromX18(pricesList[2], scale8) | |
1665 | + | let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this)))) | |
1666 | + | $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)) | |
1684 | 1667 | } | |
1685 | - | let delay = $t05828958488._1 | |
1686 | - | let delta = $t05828958488._2 | |
1687 | - | let target = $t05828958488._3 | |
1688 | - | let curAmp = parseIntValue(getStringValue(amp())) | |
1689 | - | let newAmpRaw = (curAmp + delta) | |
1690 | - | let newAmp = if ((0 > delta)) | |
1691 | - | then if ((target > newAmpRaw)) | |
1692 | - | then target | |
1693 | - | else newAmpRaw | |
1694 | - | else if ((newAmpRaw > target)) | |
1695 | - | then target | |
1696 | - | else newAmpRaw | |
1697 | - | let lastCall = valueOrElse(getInteger(keyChangeAmpLastCall()), 0) | |
1698 | - | let wait = (lastCall + delay) | |
1699 | - | let checks = [if ((height > wait)) | |
1700 | - | then true | |
1701 | - | else throwErr("try again in few blocks"), if ((curAmp != newAmp)) | |
1702 | - | then true | |
1703 | - | else throwErr("already reached target")] | |
1704 | - | if ((checks == checks)) | |
1705 | - | then [IntegerEntry(keyChangeAmpLastCall(), height), StringEntry(amp(), toString(newAmp)), StringEntry(keyAmpHistory(height), toString(newAmp))] | |
1706 | - | else throw("Strict value is not equal to itself.") | |
1668 | + | ||
1669 | + | ||
1670 | + | ||
1671 | + | @Callable(i) | |
1672 | + | func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = { | |
1673 | + | let cfg = getPoolConfig() | |
1674 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1675 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
1676 | + | let amAssetId = fromBase58String(amAssetIdStr) | |
1677 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
1678 | + | let prAssetId = fromBase58String(prAssetIdStr) | |
1679 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1680 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1681 | + | let poolStatus = cfg[idxPoolStatus] | |
1682 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1683 | + | let accAmtAssetBalance = getAccBalance(amAssetIdStr) | |
1684 | + | let accPriceAssetBalance = getAccBalance(prAssetIdStr) | |
1685 | + | let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm) | |
1686 | + | let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm) | |
1687 | + | let curPriceX18 = if ((poolLPBalance == 0)) | |
1688 | + | then zeroBigInt | |
1689 | + | else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
1690 | + | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
1691 | + | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
1692 | + | let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm) | |
1693 | + | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1694 | + | let calcLpAmt = estPut._1 | |
1695 | + | let curPriceCalc = estPut._3 | |
1696 | + | let amBalance = estPut._4 | |
1697 | + | let prBalance = estPut._5 | |
1698 | + | let lpEmission = estPut._6 | |
1699 | + | $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)) | |
1700 | + | } | |
1701 | + | ||
1702 | + | ||
1703 | + | ||
1704 | + | @Callable(i) | |
1705 | + | func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = { | |
1706 | + | let cfg = getPoolConfig() | |
1707 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1708 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
1709 | + | let amAssetId = fromBase58String(amAssetIdStr) | |
1710 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
1711 | + | let prAssetId = fromBase58String(prAssetIdStr) | |
1712 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1713 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1714 | + | let poolStatus = cfg[idxPoolStatus] | |
1715 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1716 | + | let amBalanceRaw = getAccBalance(amAssetIdStr) | |
1717 | + | let prBalanceRaw = getAccBalance(prAssetIdStr) | |
1718 | + | let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm) | |
1719 | + | let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm) | |
1720 | + | let curPriceX18 = if ((poolLPBalance == 0)) | |
1721 | + | then zeroBigInt | |
1722 | + | else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18) | |
1723 | + | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
1724 | + | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
1725 | + | let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm) | |
1726 | + | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1727 | + | let calcLpAmt = estPut._1 | |
1728 | + | let curPriceCalc = estPut._3 | |
1729 | + | let amBalance = estPut._4 | |
1730 | + | let prBalance = estPut._5 | |
1731 | + | let lpEmission = estPut._6 | |
1732 | + | $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)) | |
1733 | + | } | |
1734 | + | ||
1735 | + | ||
1736 | + | ||
1737 | + | @Callable(i) | |
1738 | + | func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { | |
1739 | + | let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this) | |
1740 | + | let outAmAmt = res._1 | |
1741 | + | let outPrAmt = res._2 | |
1742 | + | let amBalance = res._5 | |
1743 | + | let prBalance = res._6 | |
1744 | + | let lpEmission = res._7 | |
1745 | + | let curPrice = res._8 | |
1746 | + | let poolStatus = parseIntValue(res._9) | |
1747 | + | $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)) | |
1707 | 1748 | } | |
1708 | 1749 | ||
1709 | 1750 | ||
1710 | 1751 | @Verifier(tx) | |
1711 | 1752 | func verify () = { | |
1712 | - | let targetPublicKey = match | |
1753 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1713 | 1754 | case pk: ByteVector => | |
1714 | 1755 | pk | |
1715 | 1756 | case _: Unit => | |
1719 | 1760 | } | |
1720 | 1761 | match tx { | |
1721 | 1762 | case order: Order => | |
1722 | - | let matcherPub = | |
1723 | - | let $ | |
1763 | + | let matcherPub = getMatcherPubOrFail() | |
1764 | + | let $t06808568202 = if (skipOrderValidation()) | |
1724 | 1765 | then $Tuple2(true, "") | |
1725 | 1766 | else validateMatcherOrderAllowed(order) | |
1726 | - | let orderValid = $ | |
1727 | - | let orderValidInfo = $ | |
1767 | + | let orderValid = $t06808568202._1 | |
1768 | + | let orderValidInfo = $t06808568202._2 | |
1728 | 1769 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1729 | 1770 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1730 | 1771 | if (if (if (orderValid) | |
1739 | 1780 | then true | |
1740 | 1781 | else { | |
1741 | 1782 | let newHash = blake2b256(value(s.script)) | |
1742 | - | let allowedHash = fromBase64String(value(getString( | |
1783 | + | let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash()))) | |
1743 | 1784 | let currentHash = scriptHash(this) | |
1744 | 1785 | if ((allowedHash == newHash)) | |
1745 | 1786 | then (currentHash != newHash) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let lPdecimals = 8 | |
5 | + | ||
4 | 6 | let scale8 = 100000000 | |
5 | 7 | ||
6 | 8 | let scale8BigInt = toBigInt(100000000) | |
7 | 9 | ||
8 | 10 | let scale18 = toBigInt(1000000000000000000) | |
9 | 11 | ||
10 | 12 | let zeroBigInt = toBigInt(0) | |
11 | 13 | ||
12 | 14 | let big0 = toBigInt(0) | |
13 | 15 | ||
14 | 16 | let big1 = toBigInt(1) | |
15 | 17 | ||
16 | 18 | let big2 = toBigInt(2) | |
17 | 19 | ||
18 | - | let big3 = toBigInt(3) | |
19 | - | ||
20 | - | let big4 = toBigInt(4) | |
21 | - | ||
22 | 20 | let wavesString = "WAVES" | |
23 | - | ||
24 | - | let ampInitial = 50 | |
25 | - | ||
26 | - | let Amult = "100" | |
27 | 21 | ||
28 | 22 | let SEP = "__" | |
29 | 23 | ||
30 | - | let | |
24 | + | let PoolActive = 1 | |
31 | 25 | ||
32 | - | let PoolMatcherDis = 3 | |
26 | + | let PoolPutDisabled = 2 | |
27 | + | ||
28 | + | let PoolMatcherDisabled = 3 | |
33 | 29 | ||
34 | 30 | let PoolShutdown = 4 | |
35 | 31 | ||
36 | 32 | let idxPoolAddress = 1 | |
37 | 33 | ||
38 | - | let | |
34 | + | let idxPoolStatus = 2 | |
39 | 35 | ||
40 | - | let | |
36 | + | let idxPoolLPAssetId = 3 | |
41 | 37 | ||
42 | - | let | |
38 | + | let idxAmtAssetId = 4 | |
43 | 39 | ||
44 | - | let | |
40 | + | let idxPriceAssetId = 5 | |
45 | 41 | ||
46 | - | let | |
42 | + | let idxAmtAssetDcm = 6 | |
47 | 43 | ||
48 | - | let | |
44 | + | let idxPriceAssetDcm = 7 | |
49 | 45 | ||
50 | - | let | |
46 | + | let idxIAmtAssetId = 8 | |
51 | 47 | ||
52 | - | let | |
48 | + | let idxIPriceAssetId = 9 | |
53 | 49 | ||
54 | - | let | |
50 | + | let idxLPAssetDcm = 10 | |
55 | 51 | ||
56 | - | let | |
52 | + | let idxPoolAmtAssetAmt = 1 | |
57 | 53 | ||
58 | - | func t1 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
54 | + | let idxPoolPriceAssetAmt = 2 | |
55 | + | ||
56 | + | let idxPoolLPAssetAmt = 3 | |
57 | + | ||
58 | + | let idxFactoryStakingContract = 1 | |
59 | + | ||
60 | + | let idxFactorySlippageContract = 7 | |
61 | + | ||
62 | + | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), scale18, toBigInt(origScaleMult)) | |
59 | 63 | ||
60 | 64 | ||
61 | - | func | |
65 | + | func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
62 | 66 | ||
63 | 67 | ||
64 | - | func | |
68 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
65 | 69 | ||
66 | 70 | ||
67 | 71 | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
68 | 72 | ||
69 | 73 | ||
70 | - | func abs (val) = if ((zeroBigInt > val)) | |
74 | + | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
75 | + | ||
76 | + | ||
77 | + | func abs (val) = if ((0 > val)) | |
71 | 78 | then -(val) | |
72 | 79 | else val | |
73 | 80 | ||
74 | 81 | ||
75 | 82 | func absBigInt (val) = if ((zeroBigInt > val)) | |
76 | 83 | then -(val) | |
77 | 84 | else val | |
85 | + | ||
86 | + | ||
87 | + | func swapContract () = "%s__swapContract" | |
78 | 88 | ||
79 | 89 | ||
80 | 90 | func fc () = "%s__factoryContract" | |
81 | 91 | ||
82 | 92 | ||
83 | 93 | func mpk () = "%s__managerPublicKey" | |
84 | 94 | ||
85 | 95 | ||
86 | 96 | func pmpk () = "%s__pendingManagerPublicKey" | |
87 | 97 | ||
88 | 98 | ||
89 | 99 | func pl () = "%s%s__price__last" | |
90 | 100 | ||
91 | 101 | ||
92 | - | func ph (h, | |
102 | + | func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP) | |
93 | 103 | ||
94 | 104 | ||
95 | - | func pau ( | |
105 | + | func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId) | |
96 | 106 | ||
97 | 107 | ||
98 | - | func gau ( | |
108 | + | func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId) | |
99 | 109 | ||
100 | 110 | ||
101 | 111 | func aa () = "%s__amountAsset" | |
102 | 112 | ||
103 | 113 | ||
104 | 114 | func pa () = "%s__priceAsset" | |
105 | 115 | ||
106 | 116 | ||
107 | - | ||
117 | + | let keyFee = "%s__fee" | |
108 | 118 | ||
109 | - | ||
110 | - | func keyAmpHistory (heightBlocks) = ("%s%d__amp__" + toString(heightBlocks)) | |
111 | - | ||
112 | - | ||
113 | - | func keyChangeAmpLastCall () = "%s__changeAmpLastCall" | |
114 | - | ||
115 | - | ||
116 | - | let keyFee = "%s__fee" | |
119 | + | let feeDefault = fraction(10, scale8, 10000) | |
117 | 120 | ||
118 | 121 | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
119 | 122 | ||
120 | - | let | |
123 | + | let keyKLp = makeString(["%s", "kLp"], SEP) | |
121 | 124 | ||
122 | - | let | |
125 | + | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
123 | 126 | ||
124 | - | let | |
127 | + | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
125 | 128 | ||
126 | - | let | |
129 | + | let kLpRefreshDelayDefault = 30 | |
127 | 130 | ||
128 | - | let | |
131 | + | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
129 | 132 | ||
130 | - | func | |
133 | + | func keyAdditionalBalance (assetId) = makeString(["%s%s", "stakedBalance", assetId], SEP) | |
131 | 134 | ||
132 | 135 | ||
133 | - | func | |
136 | + | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "shareAssetBalance", assetId], SEP) | |
134 | 137 | ||
135 | 138 | ||
136 | - | func | |
139 | + | func getAdditionalBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyAdditionalBalance(assetId)), 0) | |
137 | 140 | ||
138 | 141 | ||
139 | - | func | |
142 | + | func getStakingAssetBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
140 | 143 | ||
141 | 144 | ||
142 | - | func | |
145 | + | func keyFactoryConfig () = "%s__factoryConfig" | |
143 | 146 | ||
144 | 147 | ||
145 | - | func | |
148 | + | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
146 | 149 | ||
147 | 150 | ||
148 | - | func | |
151 | + | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") | |
149 | 152 | ||
153 | + | ||
154 | + | func keyPoolConfig (iAmtAsset,iPriceAsset) = (((("%d%d%s__" + iAmtAsset) + "__") + iPriceAsset) + "__config") | |
155 | + | ||
156 | + | ||
157 | + | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) | |
158 | + | ||
159 | + | ||
160 | + | func keyAllPoolsShutdown () = "%s__shutdown" | |
161 | + | ||
162 | + | ||
163 | + | func keyPoolWeight (contractAddress) = ("%s%s__poolWeight__" + contractAddress) | |
164 | + | ||
165 | + | ||
166 | + | func keyAllowedLpScriptHash () = "%s__allowedLpScriptHash" | |
167 | + | ||
168 | + | ||
169 | + | let keyFeeCollectorAddress = "%s__feeCollectorAddress" | |
150 | 170 | ||
151 | 171 | func keySkipOrderValidation (poolAddress) = ("%s%s__skipOrderValidation__" + poolAddress) | |
152 | 172 | ||
153 | 173 | ||
154 | 174 | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
155 | 175 | ||
156 | 176 | ||
157 | - | func | |
177 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
158 | 178 | ||
159 | 179 | ||
160 | - | func | |
180 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
161 | 181 | ||
162 | 182 | ||
163 | - | func throwErr (msg) = throw(makeString(["lp | |
183 | + | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
164 | 184 | ||
165 | 185 | ||
166 | - | func fmtErr (msg) = makeString(["lp | |
186 | + | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
167 | 187 | ||
168 | 188 | ||
169 | - | let fca = addressFromStringValue(strf(this, fc())) | |
189 | + | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
190 | + | ||
191 | + | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
170 | 192 | ||
171 | 193 | let inFee = { | |
172 | - | let @ = invoke( | |
194 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
173 | 195 | if ($isInstanceOf(@, "Int")) | |
174 | 196 | then @ | |
175 | 197 | else throw(($getType(@) + " couldn't be cast to Int")) | |
176 | 198 | } | |
177 | 199 | ||
178 | 200 | let outFee = { | |
179 | - | let @ = invoke( | |
201 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
180 | 202 | if ($isInstanceOf(@, "Int")) | |
181 | 203 | then @ | |
182 | 204 | else throw(($getType(@) + " couldn't be cast to Int")) | |
183 | 205 | } | |
184 | 206 | ||
185 | - | let A = strf(this, amp()) | |
186 | - | ||
187 | - | func igs () = valueOrElse(getBoolean(fca, aps()), false) | |
207 | + | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
188 | 208 | ||
189 | 209 | ||
190 | - | func | |
210 | + | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
191 | 211 | ||
192 | 212 | ||
193 | - | let feeCollectorAddress = addressFromStringValue(strf(fca, keyFeeCollectorAddress())) | |
194 | - | ||
195 | - | func gpc () = { | |
196 | - | let amtAs = strf(this, aa()) | |
197 | - | let priceAs = strf(this, pa()) | |
198 | - | let iPriceAs = intf(fca, mba(priceAs)) | |
199 | - | let iAmtAs = intf(fca, mba(amtAs)) | |
200 | - | split(strf(fca, pc(toString(iAmtAs), toString(iPriceAs))), SEP) | |
213 | + | func getPoolConfig () = { | |
214 | + | let amtAsset = getStringOrFail(this, aa()) | |
215 | + | let priceAsset = getStringOrFail(this, pa()) | |
216 | + | let iPriceAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(priceAsset)) | |
217 | + | let iAmtAsset = getIntOrFail(factoryContract, keyMappingsBaseAsset2internalId(amtAsset)) | |
218 | + | split(getStringOrFail(factoryContract, keyPoolConfig(toString(iAmtAsset), toString(iPriceAsset))), SEP) | |
201 | 219 | } | |
202 | 220 | ||
203 | 221 | ||
204 | 222 | func parseAssetId (input) = if ((input == wavesString)) | |
205 | 223 | then unit | |
206 | 224 | else fromBase58String(input) | |
207 | 225 | ||
208 | 226 | ||
209 | 227 | func assetIdToString (input) = if ((input == unit)) | |
210 | 228 | then wavesString | |
211 | 229 | else toBase58String(value(input)) | |
212 | 230 | ||
213 | 231 | ||
214 | - | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[ | |
232 | + | func parsePoolConfig (poolConfig) = $Tuple7(addressFromStringValue(poolConfig[idxPoolAddress]), parseIntValue(poolConfig[idxPoolStatus]), fromBase58String(poolConfig[idxPoolLPAssetId]), parseAssetId(poolConfig[idxAmtAssetId]), parseAssetId(poolConfig[idxPriceAssetId]), parseIntValue(poolConfig[idxAmtAssetDcm]), parseIntValue(poolConfig[idxPriceAssetDcm])) | |
215 | 233 | ||
216 | 234 | ||
217 | - | let poolConfigParsed = parsePoolConfig( | |
235 | + | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
218 | 236 | ||
219 | - | let $ | |
237 | + | let $t090589224 = poolConfigParsed | |
220 | 238 | ||
221 | - | let | |
239 | + | let cfgPoolAddress = $t090589224._1 | |
222 | 240 | ||
223 | - | let | |
241 | + | let cfgPoolStatus = $t090589224._2 | |
224 | 242 | ||
225 | - | let | |
243 | + | let cfgLpAssetId = $t090589224._3 | |
226 | 244 | ||
227 | - | let | |
245 | + | let cfgAmountAssetId = $t090589224._4 | |
228 | 246 | ||
229 | - | let | |
247 | + | let cfgPriceAssetId = $t090589224._5 | |
230 | 248 | ||
231 | - | let | |
249 | + | let cfgAmountAssetDecimals = $t090589224._6 | |
232 | 250 | ||
233 | - | func gfc () = split(strf(fca, fcfg()), SEP) | |
251 | + | let cfgPriceAssetDecimals = $t090589224._7 | |
252 | + | ||
253 | + | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
234 | 254 | ||
235 | 255 | ||
236 | - | let | |
256 | + | let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address") | |
237 | 257 | ||
238 | - | let | |
258 | + | let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address") | |
239 | 259 | ||
240 | - | let restContract = valueOrErrorMessage(addressFromString(factoryConfig[idxFactoryRestCntr]), "Invalid gwx contract address") | |
241 | - | ||
242 | - | 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) | |
260 | + | 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) | |
243 | 261 | ||
244 | 262 | ||
245 | 263 | 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) | |
246 | 264 | ||
247 | 265 | ||
248 | - | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
249 | - | then wavesBalance(this).available | |
250 | - | else assetBalance(this, fromBase58String(assetId)) | |
266 | + | func getAccBalance (assetId) = { | |
267 | + | let balanceOnPool = if ((assetId == "WAVES")) | |
268 | + | then wavesBalance(this).available | |
269 | + | else assetBalance(this, fromBase58String(assetId)) | |
270 | + | let totalBalance = ((balanceOnPool + getAdditionalBalanceOrZero(assetId)) - getStakingAssetBalanceOrZero(assetId)) | |
271 | + | max([0, totalBalance]) | |
272 | + | } | |
251 | 273 | ||
252 | 274 | ||
253 | - | func | |
275 | + | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
254 | 276 | ||
255 | 277 | ||
256 | - | func | |
278 | + | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
257 | 279 | ||
258 | 280 | ||
259 | - | func pcp (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
260 | - | let amtAsAmtX18 = t1(amAmt, amAssetDcm) | |
261 | - | let prAsAmtX18 = t1(prAmt, prAssetDcm) | |
262 | - | cpbi(prAsAmtX18, amtAsAmtX18) | |
281 | + | func getRate (proxy) = { | |
282 | + | let inv = invoke(proxy, "getRate", nil, nil) | |
283 | + | if ((inv == inv)) | |
284 | + | then match inv { | |
285 | + | case r: Int => | |
286 | + | r | |
287 | + | case _ => | |
288 | + | throwErr("proxy.getRate() unexpected value") | |
289 | + | } | |
290 | + | else throw("Strict value is not equal to itself.") | |
291 | + | } | |
292 | + | ||
293 | + | ||
294 | + | func deposit (assetId,amount,stakingAssetId,proxy) = { | |
295 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
296 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
297 | + | then { | |
298 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
299 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
300 | + | then { | |
301 | + | let asset = parseAssetId(assetId) | |
302 | + | if ((amount > 0)) | |
303 | + | then { | |
304 | + | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(asset, amount)]) | |
305 | + | if ((depositInvoke == depositInvoke)) | |
306 | + | then match depositInvoke { | |
307 | + | case receivedStakingAsset: Int => | |
308 | + | let newAdditionalBalance = (currentAdditionalBalance + amount) | |
309 | + | let newStakingAssetBalance = (currentStakingAssetBalance + receivedStakingAsset) | |
310 | + | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newStakingAssetBalance)] | |
311 | + | case _ => | |
312 | + | nil | |
313 | + | } | |
314 | + | else throw("Strict value is not equal to itself.") | |
315 | + | } | |
316 | + | else nil | |
317 | + | } | |
318 | + | else throw("Strict value is not equal to itself.") | |
319 | + | } | |
320 | + | else throw("Strict value is not equal to itself.") | |
321 | + | } | |
322 | + | ||
323 | + | ||
324 | + | func withdraw (assetId,amount,stakingAssetId,proxy,proxyRateMul,profitAddress) = { | |
325 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
326 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
327 | + | then { | |
328 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
329 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
330 | + | then { | |
331 | + | let currentProxyRate = getRate(proxy) | |
332 | + | if ((currentProxyRate == currentProxyRate)) | |
333 | + | then { | |
334 | + | let oldRate = fraction(proxyRateMul, currentAdditionalBalance, currentStakingAssetBalance) | |
335 | + | let stakingAsset = parseAssetId(stakingAssetId) | |
336 | + | let oldSendStakingAmount = fraction(proxyRateMul, amount, oldRate) | |
337 | + | let sendStakingAssetAmount = fraction(proxyRateMul, amount, currentProxyRate) | |
338 | + | let profitAmount = max([0, (oldSendStakingAmount - sendStakingAssetAmount)]) | |
339 | + | if ((sendStakingAssetAmount > 0)) | |
340 | + | then { | |
341 | + | let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(stakingAsset, sendStakingAssetAmount)]) | |
342 | + | if ((withdrawInvoke == withdrawInvoke)) | |
343 | + | then match withdrawInvoke { | |
344 | + | case receivedAssets: Int => | |
345 | + | let newAdditionalBalance = (currentAdditionalBalance - receivedAssets) | |
346 | + | let newStakingAssetBalance = ((currentStakingAssetBalance - sendStakingAssetAmount) - profitAmount) | |
347 | + | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newStakingAssetBalance), ScriptTransfer(profitAddress, profitAmount, parseAssetId(stakingAssetId))] | |
348 | + | case _ => | |
349 | + | nil | |
350 | + | } | |
351 | + | else throw("Strict value is not equal to itself.") | |
352 | + | } | |
353 | + | else nil | |
354 | + | } | |
355 | + | else throw("Strict value is not equal to itself.") | |
356 | + | } | |
357 | + | else throw("Strict value is not equal to itself.") | |
358 | + | } | |
359 | + | else throw("Strict value is not equal to itself.") | |
360 | + | } | |
361 | + | ||
362 | + | ||
363 | + | func getLeaseProxyConfig (assetId) = match invoke(factoryContract, "getPoolLeaseConfigREADONLY", [toString(this), assetId], nil) { | |
364 | + | case a: (Boolean, Int, Int, String, String, Int, String) => | |
365 | + | a | |
366 | + | case _ => | |
367 | + | throwErr((("[" + assetId) + "] getLeaseProxyConfig() error")) | |
368 | + | } | |
369 | + | ||
370 | + | ||
371 | + | func rebalanceInternal (targetRatio,assetId,stakingAssetId,minBalance,proxy,proxyRateMul,profitAddress) = { | |
372 | + | let currentAdditionalBalance = getAdditionalBalanceOrZero(assetId) | |
373 | + | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
374 | + | then { | |
375 | + | let currentStakingAssetBalance = getStakingAssetBalanceOrZero(stakingAssetId) | |
376 | + | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
377 | + | then { | |
378 | + | let leasableTotalBalance = max([0, (getAccBalance(assetId) - minBalance)]) | |
379 | + | let targetAdditionalBalance = fraction(targetRatio, leasableTotalBalance, 100) | |
380 | + | let diff = (currentAdditionalBalance - targetAdditionalBalance) | |
381 | + | if ((diff == 0)) | |
382 | + | then nil | |
383 | + | else if ((0 > diff)) | |
384 | + | then { | |
385 | + | let sendAssetAmount = -(diff) | |
386 | + | deposit(assetId, sendAssetAmount, stakingAssetId, proxy) | |
387 | + | } | |
388 | + | else { | |
389 | + | let getAssetAmount = diff | |
390 | + | withdraw(assetId, getAssetAmount, stakingAssetId, proxy, proxyRateMul, profitAddress) | |
391 | + | } | |
392 | + | } | |
393 | + | else throw("Strict value is not equal to itself.") | |
394 | + | } | |
395 | + | else throw("Strict value is not equal to itself.") | |
396 | + | } | |
397 | + | ||
398 | + | ||
399 | + | func rebalanceAsset (assetId) = { | |
400 | + | let $t01546015596 = getLeaseProxyConfig(assetId) | |
401 | + | let isLeasable = $t01546015596._1 | |
402 | + | let leasedRatio = $t01546015596._2 | |
403 | + | let minBalance = $t01546015596._3 | |
404 | + | let proxyAddress = $t01546015596._4 | |
405 | + | let proxyAssetId = $t01546015596._5 | |
406 | + | let proxyRateMul = $t01546015596._6 | |
407 | + | let stakingProfitAddress = $t01546015596._7 | |
408 | + | if (isLeasable) | |
409 | + | then rebalanceInternal(leasedRatio, assetId, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul, addressFromStringValue(stakingProfitAddress)) | |
410 | + | else nil | |
411 | + | } | |
412 | + | ||
413 | + | ||
414 | + | func withdrawAndRebalanceAsset (assetId,getAmount) = { | |
415 | + | let $t01599516131 = getLeaseProxyConfig(assetId) | |
416 | + | let isLeasable = $t01599516131._1 | |
417 | + | let leasedRatio = $t01599516131._2 | |
418 | + | let minBalance = $t01599516131._3 | |
419 | + | let proxyAddress = $t01599516131._4 | |
420 | + | let proxyAssetId = $t01599516131._5 | |
421 | + | let proxyRateMul = $t01599516131._6 | |
422 | + | let stakingProfitAddress = $t01599516131._7 | |
423 | + | if (isLeasable) | |
424 | + | then { | |
425 | + | let newTotalLeasableBalance = max([0, ((getAccBalance(assetId) - getAmount) - minBalance)]) | |
426 | + | if ((newTotalLeasableBalance == newTotalLeasableBalance)) | |
427 | + | then { | |
428 | + | let newAdditionalBalance = fraction(leasedRatio, newTotalLeasableBalance, 100) | |
429 | + | if ((newAdditionalBalance == newAdditionalBalance)) | |
430 | + | then { | |
431 | + | let withdrawAmount = (getAdditionalBalanceOrZero(assetId) - newAdditionalBalance) | |
432 | + | if ((withdrawAmount == withdrawAmount)) | |
433 | + | then if ((0 > withdrawAmount)) | |
434 | + | then deposit(assetId, -(withdrawAmount), proxyAssetId, addressFromStringValue(proxyAddress)) | |
435 | + | else withdraw(assetId, withdrawAmount, proxyAssetId, addressFromStringValue(proxyAddress), proxyRateMul, addressFromStringValue(stakingProfitAddress)) | |
436 | + | else throw("Strict value is not equal to itself.") | |
437 | + | } | |
438 | + | else throw("Strict value is not equal to itself.") | |
439 | + | } | |
440 | + | else throw("Strict value is not equal to itself.") | |
441 | + | } | |
442 | + | else nil | |
443 | + | } | |
444 | + | ||
445 | + | ||
446 | + | func withdrawAndRebalanceAll (amountAssetOutAmount,priceAssetOutAmount) = { | |
447 | + | let AmAmtWithdrawState = withdrawAndRebalanceAsset(getStringOrFail(this, aa()), amountAssetOutAmount) | |
448 | + | let PrAmtWithdrawState = withdrawAndRebalanceAsset(getStringOrFail(this, pa()), priceAssetOutAmount) | |
449 | + | (AmAmtWithdrawState ++ PrAmtWithdrawState) | |
450 | + | } | |
451 | + | ||
452 | + | ||
453 | + | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
454 | + | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
455 | + | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
456 | + | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
263 | 457 | } | |
264 | 458 | ||
265 | 459 | ||
266 | 460 | func calcPrices (amAmt,prAmt,lpAmt) = { | |
267 | - | let amtAsDcm = cfgAmountAssetDecimals | |
268 | - | let prAsDcm = cfgPriceAssetDecimals | |
269 | - | let priceX18 = pcp(amtAsDcm, prAsDcm, amAmt, prAmt) | |
270 | - | let amAmtX18 = t1(amAmt, amtAsDcm) | |
271 | - | let prAmtX18 = t1(prAmt, prAsDcm) | |
272 | - | let lpAmtX18 = t1(lpAmt, scale8) | |
273 | - | let lpPrInAmAsX18 = cpbi(amAmtX18, lpAmtX18) | |
274 | - | let lpPrInPrAsX18 = cpbi(prAmtX18, lpAmtX18) | |
275 | - | [priceX18, lpPrInAmAsX18, lpPrInPrAsX18] | |
461 | + | let cfg = getPoolConfig() | |
462 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
463 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
464 | + | let priceX18 = privateCalcPrice(amtAssetDcm, priceAssetDcm, amAmt, prAmt) | |
465 | + | let amAmtX18 = toX18(amAmt, amtAssetDcm) | |
466 | + | let prAmtX18 = toX18(prAmt, priceAssetDcm) | |
467 | + | let lpAmtX18 = toX18(lpAmt, scale8) | |
468 | + | let lpPriceInAmAssetX18 = calcPriceBigInt(amAmtX18, lpAmtX18) | |
469 | + | let lpPriceInPrAssetX18 = calcPriceBigInt(prAmtX18, lpAmtX18) | |
470 | + | [priceX18, lpPriceInAmAssetX18, lpPriceInPrAssetX18] | |
471 | + | } | |
472 | + | ||
473 | + | ||
474 | + | func calculatePrices (amAmt,prAmt,lpAmt) = { | |
475 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
476 | + | [fromX18(prices[0], scale8), fromX18(prices[1], scale8), fromX18(prices[2], scale8)] | |
477 | + | } | |
478 | + | ||
479 | + | ||
480 | + | func estimateGetOperation (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
481 | + | let cfg = getPoolConfig() | |
482 | + | let lpAssetId = cfg[idxPoolLPAssetId] | |
483 | + | let amAssetId = cfg[idxAmtAssetId] | |
484 | + | let prAssetId = cfg[idxPriceAssetId] | |
485 | + | let amAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
486 | + | let prAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
487 | + | let poolStatus = cfg[idxPoolStatus] | |
488 | + | let lpEmission = valueOrErrorMessage(assetInfo(fromBase58String(lpAssetId)), (("Asset " + lpAssetId) + " doesn't exist")).quantity | |
489 | + | if ((lpAssetId != pmtAssetId)) | |
490 | + | then throw("Invalid asset passed.") | |
491 | + | else { | |
492 | + | let amBalance = getAccBalance(amAssetId) | |
493 | + | let amBalanceX18 = toX18(amBalance, amAssetDcm) | |
494 | + | let prBalance = getAccBalance(prAssetId) | |
495 | + | let prBalanceX18 = toX18(prBalance, prAssetDcm) | |
496 | + | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
497 | + | let curPrice = fromX18(curPriceX18, scale8) | |
498 | + | let pmtLpAmtX18 = toX18(pmtLpAmt, scale8) | |
499 | + | let lpEmissionX18 = toX18(lpEmission, scale8) | |
500 | + | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
501 | + | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissionX18) | |
502 | + | let outAmAmt = fromX18Round(outAmAmtX18, amAssetDcm, FLOOR) | |
503 | + | let outPrAmt = fromX18Round(outPrAmtX18, prAssetDcm, FLOOR) | |
504 | + | let state = if ((txId58 == "")) | |
505 | + | then nil | |
506 | + | else [ScriptTransfer(userAddress, outAmAmt, if ((amAssetId == "WAVES")) | |
507 | + | then unit | |
508 | + | else fromBase58String(amAssetId)), ScriptTransfer(userAddress, outPrAmt, if ((prAssetId == "WAVES")) | |
509 | + | then unit | |
510 | + | else fromBase58String(prAssetId)), StringEntry(gau(toString(userAddress), txId58), dataGetActionInfo(outAmAmt, outPrAmt, pmtLpAmt, curPrice, height, lastBlock.timestamp)), IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice)] | |
511 | + | $Tuple10(outAmAmt, outPrAmt, amAssetId, prAssetId, amBalance, prBalance, lpEmission, curPriceX18, poolStatus, state) | |
512 | + | } | |
513 | + | } | |
514 | + | ||
515 | + | ||
516 | + | func estimatePutOperation (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = { | |
517 | + | let cfg = getPoolConfig() | |
518 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
519 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
520 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
521 | + | let iAmtAssetId = cfg[idxIAmtAssetId] | |
522 | + | let iPriceAssetId = cfg[idxIPriceAssetId] | |
523 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
524 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
525 | + | let poolStatus = cfg[idxPoolStatus] | |
526 | + | let lpEmission = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
527 | + | let inAmAssetIdStr = toBase58String(valueOrElse(inAmAssetId, fromBase58String("WAVES"))) | |
528 | + | let inPrAssetIdStr = toBase58String(valueOrElse(inPrAssetId, fromBase58String("WAVES"))) | |
529 | + | if (if ((amAssetIdStr != inAmAssetIdStr)) | |
530 | + | then true | |
531 | + | else (prAssetIdStr != inPrAssetIdStr)) | |
532 | + | then throw("Invalid amt or price asset passed.") | |
533 | + | else { | |
534 | + | let amBalance = if (isEvaluate) | |
535 | + | then getAccBalance(amAssetIdStr) | |
536 | + | else (getAccBalance(amAssetIdStr) - inAmAssetAmt) | |
537 | + | let prBalance = if (isEvaluate) | |
538 | + | then getAccBalance(prAssetIdStr) | |
539 | + | else (getAccBalance(prAssetIdStr) - inPrAssetAmt) | |
540 | + | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
541 | + | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
542 | + | let userPriceX18 = calcPriceBigInt(inPrAssetAmtX18, inAmAssetAmtX18) | |
543 | + | let amBalanceX18 = toX18(amBalance, amtAssetDcm) | |
544 | + | let prBalanceX18 = toX18(prBalance, priceAssetDcm) | |
545 | + | let res = if ((lpEmission == 0)) | |
546 | + | then { | |
547 | + | let curPriceX18 = zeroBigInt | |
548 | + | let slippageX18 = zeroBigInt | |
549 | + | let lpAmtX18 = pow((inAmAssetAmtX18 * inPrAssetAmtX18), 0, toBigInt(5), 1, 0, DOWN) | |
550 | + | $Tuple5(fromX18(lpAmtX18, scale8), fromX18(inAmAssetAmtX18, amtAssetDcm), fromX18(inPrAssetAmtX18, priceAssetDcm), calcPriceBigInt((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
551 | + | } | |
552 | + | else { | |
553 | + | let curPriceX18 = calcPriceBigInt(prBalanceX18, amBalanceX18) | |
554 | + | let slippageX18 = fraction(absBigInt((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
555 | + | let slippageToleranceX18 = toX18(slippageTolerance, scale8) | |
556 | + | if (if ((curPriceX18 != zeroBigInt)) | |
557 | + | then (slippageX18 > slippageToleranceX18) | |
558 | + | else false) | |
559 | + | then throw(((("Price slippage " + toString(slippageX18)) + " exceeded the passed limit of ") + toString(slippageToleranceX18))) | |
560 | + | else { | |
561 | + | let lpEmissionX18 = toX18(lpEmission, scale8) | |
562 | + | let prViaAmX18 = fraction(inAmAssetAmtX18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING) | |
563 | + | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, calcPriceBigIntRound(prBalanceX18, amBalanceX18, FLOOR), CEILING) | |
564 | + | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
565 | + | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
566 | + | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
567 | + | let expAmtAssetAmtX18 = expectedAmts._1 | |
568 | + | let expPriceAssetAmtX18 = expectedAmts._2 | |
569 | + | let lpAmtX18 = fraction(lpEmissionX18, expPriceAssetAmtX18, prBalanceX18, FLOOR) | |
570 | + | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtAssetDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceAssetDcm, CEILING), curPriceX18, slippageX18) | |
571 | + | } | |
572 | + | } | |
573 | + | let calcLpAmt = res._1 | |
574 | + | let calcAmAssetPmt = res._2 | |
575 | + | let calcPrAssetPmt = res._3 | |
576 | + | let curPrice = fromX18(res._4, scale8) | |
577 | + | let slippageCalc = fromX18(res._5, scale8) | |
578 | + | if ((0 >= calcLpAmt)) | |
579 | + | then throw("Invalid calculations. LP calculated is less than zero.") | |
580 | + | else { | |
581 | + | let emitLpAmt = if (!(emitLp)) | |
582 | + | then 0 | |
583 | + | else calcLpAmt | |
584 | + | let amDiff = (inAmAssetAmt - calcAmAssetPmt) | |
585 | + | let prDiff = (inPrAssetAmt - calcPrAssetPmt) | |
586 | + | let commonState = [IntegerEntry(pl(), curPrice), IntegerEntry(ph(height, lastBlock.timestamp), curPrice), StringEntry(pau(userAddress, txId58), dataPutActionInfo(calcAmAssetPmt, calcPrAssetPmt, emitLpAmt, curPrice, slippageTolerance, slippageCalc, height, lastBlock.timestamp, amDiff, prDiff))] | |
587 | + | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEmission, lpAssetId, poolStatus, commonState, amDiff, prDiff, inAmAssetId, inPrAssetId) | |
588 | + | } | |
589 | + | } | |
590 | + | } | |
591 | + | ||
592 | + | ||
593 | + | func calcKLp (amountBalance,priceBalance,lpEmission) = { | |
594 | + | let amountBalanceX18 = toX18BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)) | |
595 | + | let priceBalanceX18 = toX18BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals)) | |
596 | + | let updatedKLp = fraction(pow((amountBalanceX18 * priceBalanceX18), 0, toBigInt(5), 1, 18, DOWN), big1, lpEmission) | |
597 | + | if ((lpEmission == big0)) | |
598 | + | then big0 | |
599 | + | else updatedKLp | |
600 | + | } | |
601 | + | ||
602 | + | ||
603 | + | func calcCurrentKLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
604 | + | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
605 | + | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
606 | + | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
607 | + | let currentKLp = calcKLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
608 | + | currentKLp | |
609 | + | } | |
610 | + | ||
611 | + | ||
612 | + | func refreshKLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
613 | + | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
614 | + | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
615 | + | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
616 | + | let updatedKLp = calcKLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
617 | + | let actions = [IntegerEntry(keyKLpRefreshedHeight, height), StringEntry(keyKLp, toString(updatedKLp))] | |
618 | + | $Tuple2(actions, updatedKLp) | |
619 | + | } | |
620 | + | ||
621 | + | ||
622 | + | func skipOrderValidation () = valueOrElse(getBoolean(factoryContract, keySkipOrderValidation(toString(this))), false) | |
623 | + | ||
624 | + | ||
625 | + | func validateUpdatedKLp (oldKLp,updatedKLp) = if ((updatedKLp >= oldKLp)) | |
626 | + | then true | |
627 | + | else throwErr(makeString(["updated KLp lower than current KLp", toString(oldKLp), toString(updatedKLp)], " ")) | |
628 | + | ||
629 | + | ||
630 | + | func validateMatcherOrderAllowed (order) = { | |
631 | + | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
632 | + | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
633 | + | let amountAssetAmount = order.amount | |
634 | + | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
635 | + | let $t02852028732 = if ((order.orderType == Buy)) | |
636 | + | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
637 | + | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
638 | + | let amountAssetBalanceDelta = $t02852028732._1 | |
639 | + | let priceAssetBalanceDelta = $t02852028732._2 | |
640 | + | if (if (if (isGlobalShutdown()) | |
641 | + | then true | |
642 | + | else (cfgPoolStatus == PoolMatcherDisabled)) | |
643 | + | then true | |
644 | + | else (cfgPoolStatus == PoolShutdown)) | |
645 | + | then throw("Exchange operations disabled") | |
646 | + | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
647 | + | then true | |
648 | + | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
649 | + | then throw("Wrong order assets.") | |
650 | + | else { | |
651 | + | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
652 | + | let $t02917229272 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
653 | + | let unusedActions = $t02917229272._1 | |
654 | + | let kLpNew = $t02917229272._2 | |
655 | + | let isOrderValid = (kLpNew >= kLp) | |
656 | + | let info = makeString(["kLp=", toString(kLp), " kLpNew=", toString(kLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
657 | + | $Tuple2(isOrderValid, info) | |
658 | + | } | |
659 | + | } | |
660 | + | ||
661 | + | ||
662 | + | func commonGet (i) = if ((size(i.payments) != 1)) | |
663 | + | then throw("exactly 1 payment is expected") | |
664 | + | else { | |
665 | + | let pmt = value(i.payments[0]) | |
666 | + | let pmtAssetId = value(pmt.assetId) | |
667 | + | let pmtAmt = pmt.amount | |
668 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
669 | + | let outAmAmt = res._1 | |
670 | + | let outPrAmt = res._2 | |
671 | + | let poolStatus = parseIntValue(res._9) | |
672 | + | let state = res._10 | |
673 | + | if (if (isGlobalShutdown()) | |
674 | + | then true | |
675 | + | else (poolStatus == PoolShutdown)) | |
676 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
677 | + | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
678 | + | } | |
679 | + | ||
680 | + | ||
681 | + | func commonPut (i,slippageTolerance,emitLp) = if ((size(i.payments) != 2)) | |
682 | + | then throw("exactly 2 payments are expected") | |
683 | + | else { | |
684 | + | let amAssetPmt = value(i.payments[0]) | |
685 | + | let prAssetPmt = value(i.payments[1]) | |
686 | + | let estPut = estimatePutOperation(toBase58String(i.transactionId), slippageTolerance, amAssetPmt.amount, amAssetPmt.assetId, prAssetPmt.amount, prAssetPmt.assetId, toString(i.caller), false, emitLp) | |
687 | + | let poolStatus = parseIntValue(estPut._8) | |
688 | + | if (if (if (isGlobalShutdown()) | |
689 | + | then true | |
690 | + | else (poolStatus == PoolPutDisabled)) | |
691 | + | then true | |
692 | + | else (poolStatus == PoolShutdown)) | |
693 | + | then throw(("Put operation is blocked by admin. Status = " + toString(poolStatus))) | |
694 | + | else estPut | |
695 | + | } | |
696 | + | ||
697 | + | ||
698 | + | func emit (amount) = { | |
699 | + | let emitInv = invoke(factoryContract, "emit", [amount], nil) | |
700 | + | if ((emitInv == emitInv)) | |
701 | + | then { | |
702 | + | let emitInvLegacy = match emitInv { | |
703 | + | case legacyFactoryContract: Address => | |
704 | + | invoke(legacyFactoryContract, "emit", [amount], nil) | |
705 | + | case _ => | |
706 | + | unit | |
707 | + | } | |
708 | + | if ((emitInvLegacy == emitInvLegacy)) | |
709 | + | then amount | |
710 | + | else throw("Strict value is not equal to itself.") | |
711 | + | } | |
712 | + | else throw("Strict value is not equal to itself.") | |
276 | 713 | } | |
277 | 714 | ||
278 | 715 | ||
279 | 716 | func takeFee (amount,fee) = { | |
280 | 717 | let feeAmount = if ((fee == 0)) | |
281 | 718 | then 0 | |
282 | 719 | else fraction(amount, fee, scale8) | |
283 | 720 | $Tuple2((amount - feeAmount), feeAmount) | |
284 | 721 | } | |
285 | 722 | ||
286 | 723 | ||
287 | - | func getD (xp) = { | |
288 | - | let xp0 = xp[0] | |
289 | - | let xp1 = xp[1] | |
290 | - | let s = (xp0 + xp1) | |
291 | - | if ((s == big0)) | |
292 | - | then big0 | |
293 | - | else { | |
294 | - | let a = parseIntValue(A) | |
295 | - | let ann = (a * 2) | |
296 | - | let p = fraction(xp0, xp1, big1) | |
297 | - | let xp0_xp1_n_n = fraction(p, big4, big1) | |
298 | - | let ann_s = fraction(toBigInt(ann), s, big1) | |
299 | - | let ann_1 = toBigInt((ann - 1)) | |
300 | - | func calcDNext (d) = { | |
301 | - | let dd = fraction(d, d, big1) | |
302 | - | let ddd = fraction(dd, d, big1) | |
303 | - | let dp = fraction(ddd, big1, xp0_xp1_n_n) | |
304 | - | fraction((ann_s + fraction(dp, big2, big1)), d, (fraction(ann_1, d, big1) + fraction(big3, dp, big1))) | |
724 | + | func calcPutOneToken (paymentAmountRaw,paymentAssetId,userAddress,txId) = { | |
725 | + | let isEval = (txId == unit) | |
726 | + | let amountBalanceRaw = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
727 | + | let priceBalanceRaw = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
728 | + | let paymentInAmountAsset = if ((paymentAssetId == cfgAmountAssetId)) | |
729 | + | then true | |
730 | + | else if ((paymentAssetId == cfgPriceAssetId)) | |
731 | + | then false | |
732 | + | else throwErr("invalid asset") | |
733 | + | let $t03238532678 = if (isEval) | |
734 | + | then $Tuple2(amountBalanceRaw, priceBalanceRaw) | |
735 | + | else if (paymentInAmountAsset) | |
736 | + | then $Tuple2((amountBalanceRaw - paymentAmountRaw), priceBalanceRaw) | |
737 | + | else $Tuple2(amountBalanceRaw, (priceBalanceRaw - paymentAmountRaw)) | |
738 | + | let amountBalanceOld = $t03238532678._1 | |
739 | + | let priceBalanceOld = $t03238532678._2 | |
740 | + | let $t03268232831 = if (paymentInAmountAsset) | |
741 | + | then $Tuple2(paymentAmountRaw, 0) | |
742 | + | else $Tuple2(0, paymentAmountRaw) | |
743 | + | let amountAssetAmountRaw = $t03268232831._1 | |
744 | + | let priceAssetAmountRaw = $t03268232831._2 | |
745 | + | let amountAssetAmount = takeFee(amountAssetAmountRaw, inFee)._1 | |
746 | + | let priceAssetAmount = takeFee(priceAssetAmountRaw, inFee)._1 | |
747 | + | let $t03296333027 = takeFee(paymentAmountRaw, inFee) | |
748 | + | let paymentAmount = $t03296333027._1 | |
749 | + | let feeAmount = $t03296333027._2 | |
750 | + | let amountBalanceNew = (amountBalanceOld + amountAssetAmount) | |
751 | + | let priceBalanceNew = (priceBalanceOld + priceAssetAmount) | |
752 | + | let priceNewX18 = calcPriceBigInt(toX18(priceBalanceNew, cfgPriceAssetDecimals), toX18(amountBalanceNew, cfgAmountAssetDecimals)) | |
753 | + | let priceNew = fromX18(priceNewX18, scale8) | |
754 | + | let paymentBalance = if (paymentInAmountAsset) | |
755 | + | then amountBalanceOld | |
756 | + | else priceBalanceOld | |
757 | + | let paymentBalanceBigInt = toBigInt(paymentBalance) | |
758 | + | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
759 | + | let chechSupply = if ((supplyBigInt > big0)) | |
760 | + | then true | |
761 | + | else throwErr("initial deposit requires all coins") | |
762 | + | if ((chechSupply == chechSupply)) | |
763 | + | then { | |
764 | + | let depositBigInt = toBigInt(paymentAmount) | |
765 | + | let issueAmount = max([0, toInt(((supplyBigInt * (sqrtBigInt((scale18 + ((depositBigInt * scale18) / paymentBalanceBigInt)), 18, 18, DOWN) - scale18)) / scale18))]) | |
766 | + | let commonState = if (isEval) | |
767 | + | then nil | |
768 | + | else [IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew), StringEntry(pau(toString(value(userAddress)), toBase58String(value(txId))), dataPutActionInfo(amountAssetAmountRaw, priceAssetAmountRaw, issueAmount, priceNew, 0, 0, height, lastBlock.timestamp, 0, 0))] | |
769 | + | let priceOldX18 = calcPriceBigInt(toX18(priceBalanceOld, cfgPriceAssetDecimals), toX18(amountBalanceOld, cfgAmountAssetDecimals)) | |
770 | + | let priceOld = fromX18(priceOldX18, scale8) | |
771 | + | let loss = { | |
772 | + | let $t03470834875 = if (paymentInAmountAsset) | |
773 | + | then $Tuple2(amountAssetAmountRaw, amountBalanceOld) | |
774 | + | else $Tuple2(priceAssetAmountRaw, priceBalanceOld) | |
775 | + | let amount = $t03470834875._1 | |
776 | + | let balance = $t03470834875._2 | |
777 | + | let issueAmountBoth = toInt(fraction(supplyBigInt, toBigInt((amount / 2)), toBigInt(balance))) | |
778 | + | fraction((issueAmount - issueAmountBoth), scale8, issueAmountBoth) | |
305 | 779 | } | |
306 | - | ||
307 | - | func calc (acc,i) = if (acc._2) | |
308 | - | then acc | |
309 | - | else { | |
310 | - | let d = acc._1 | |
311 | - | let dNext = calcDNext(d) | |
312 | - | let dDiffRaw = (dNext - value(d)) | |
313 | - | let dDiff = if ((big0 > dDiffRaw)) | |
314 | - | then -(dDiffRaw) | |
315 | - | else dDiffRaw | |
316 | - | if ((big1 >= dDiff)) | |
317 | - | then $Tuple2(dNext, true) | |
318 | - | else $Tuple2(dNext, false) | |
319 | - | } | |
320 | - | ||
321 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
322 | - | let $t01277812826 = { | |
323 | - | let $l = arr | |
324 | - | let $s = size($l) | |
325 | - | let $acc0 = $Tuple2(s, false) | |
326 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
327 | - | then $a | |
328 | - | else calc($a, $l[$i]) | |
329 | - | ||
330 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
331 | - | then $a | |
332 | - | else throw("List size exceeds 17") | |
333 | - | ||
334 | - | $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($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
335 | - | } | |
336 | - | let d = $t01277812826._1 | |
337 | - | let found = $t01277812826._2 | |
338 | - | if (found) | |
339 | - | then d | |
340 | - | else throw(("D calculation error, D = " + toString(d))) | |
341 | - | } | |
342 | - | } | |
343 | - | ||
344 | - | ||
345 | - | func ego (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
346 | - | let lpId = cfgLpAssetId | |
347 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
348 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
349 | - | let amDcm = cfgAmountAssetDecimals | |
350 | - | let prDcm = cfgPriceAssetDecimals | |
351 | - | let sts = toString(cfgPoolStatus) | |
352 | - | let lpEmiss = valueOrErrorMessage(assetInfo(lpId), "Wrong LP id").quantity | |
353 | - | if ((toBase58String(lpId) != pmtAssetId)) | |
354 | - | then throw("Wrong pmt asset") | |
355 | - | else { | |
356 | - | let amBalance = getAccBalance(amId) | |
357 | - | let amBalanceX18 = t1(amBalance, amDcm) | |
358 | - | let prBalance = getAccBalance(prId) | |
359 | - | let prBalanceX18 = t1(prBalance, prDcm) | |
360 | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
361 | - | let curPrice = f1(curPriceX18, scale8) | |
362 | - | let pmtLpAmtX18 = t1(pmtLpAmt, scale8) | |
363 | - | let lpEmissX18 = t1(lpEmiss, scale8) | |
364 | - | let outAmAmtX18 = fraction(amBalanceX18, pmtLpAmtX18, lpEmissX18) | |
365 | - | let outPrAmtX18 = fraction(prBalanceX18, pmtLpAmtX18, lpEmissX18) | |
366 | - | let outAmAmt = fromX18Round(outAmAmtX18, amDcm, FLOOR) | |
367 | - | let outPrAmt = fromX18Round(outPrAmtX18, prDcm, FLOOR) | |
368 | - | let state = if ((txId58 == "")) | |
369 | - | then nil | |
370 | - | else [ScriptTransfer(userAddress, outAmAmt, if ((amId == "WAVES")) | |
371 | - | then unit | |
372 | - | else fromBase58String(amId)), ScriptTransfer(userAddress, outPrAmt, if ((prId == "WAVES")) | |
373 | - | then unit | |
374 | - | 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)] | |
375 | - | $Tuple10(outAmAmt, outPrAmt, amId, prId, amBalance, prBalance, lpEmiss, curPriceX18, sts, state) | |
376 | - | } | |
377 | - | } | |
378 | - | ||
379 | - | ||
380 | - | func epo (txId58,slippage,inAmAmt,inAmId,inPrAmt,inPrId,userAddress,isEval,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
381 | - | let lpId = cfgLpAssetId | |
382 | - | let amIdStr = toBase58String(value(cfgAmountAssetId)) | |
383 | - | let prIdStr = toBase58String(value(cfgPriceAssetId)) | |
384 | - | let amtDcm = cfgAmountAssetDecimals | |
385 | - | let priceDcm = cfgPriceAssetDecimals | |
386 | - | let sts = toString(cfgPoolStatus) | |
387 | - | let lpEm = valueOrErrorMessage(assetInfo(lpId), "Wr lp as").quantity | |
388 | - | let amBalance = if (isEval) | |
389 | - | then getAccBalance(amIdStr) | |
390 | - | else if (if (isOneAsset) | |
391 | - | then (pmtId == amIdStr) | |
392 | - | else false) | |
393 | - | then (getAccBalance(amIdStr) - pmtAmt) | |
394 | - | else if (isOneAsset) | |
395 | - | then getAccBalance(amIdStr) | |
396 | - | else (getAccBalance(amIdStr) - inAmAmt) | |
397 | - | let prBalance = if (isEval) | |
398 | - | then getAccBalance(prIdStr) | |
399 | - | else if (if (isOneAsset) | |
400 | - | then (pmtId == prIdStr) | |
401 | - | else false) | |
402 | - | then (getAccBalance(prIdStr) - pmtAmt) | |
403 | - | else if (isOneAsset) | |
404 | - | then getAccBalance(prIdStr) | |
405 | - | else (getAccBalance(prIdStr) - inPrAmt) | |
406 | - | let inAmAssetAmtX18 = t1(inAmAmt, amtDcm) | |
407 | - | let inPrAssetAmtX18 = t1(inPrAmt, priceDcm) | |
408 | - | let userPriceX18 = cpbi(inPrAssetAmtX18, inAmAssetAmtX18) | |
409 | - | let amBalanceX18 = t1(amBalance, amtDcm) | |
410 | - | let prBalanceX18 = t1(prBalance, priceDcm) | |
411 | - | let D0 = getD([amBalanceX18, prBalanceX18]) | |
412 | - | let r = if ((lpEm == 0)) | |
413 | - | then { | |
414 | - | let D1 = getD([(amBalanceX18 + inAmAssetAmtX18), (prBalanceX18 + inPrAssetAmtX18)]) | |
415 | - | let checkD = if ((D1 > D0)) | |
416 | - | then true | |
417 | - | else throw("D1 should be greater than D0") | |
418 | - | if ((checkD == checkD)) | |
419 | - | then { | |
420 | - | let curPriceX18 = zeroBigInt | |
421 | - | let slippageX18 = zeroBigInt | |
422 | - | let lpAmtX18 = D1 | |
423 | - | $Tuple5(f1(lpAmtX18, scale8), f1(inAmAssetAmtX18, amtDcm), f1(inPrAssetAmtX18, priceDcm), cpbi((prBalanceX18 + inPrAssetAmtX18), (amBalanceX18 + inAmAssetAmtX18)), slippageX18) | |
424 | - | } | |
425 | - | else throw("Strict value is not equal to itself.") | |
426 | - | } | |
427 | - | else { | |
428 | - | let curPriceX18 = cpbi(prBalanceX18, amBalanceX18) | |
429 | - | let slippageRealX18 = fraction(abs((curPriceX18 - userPriceX18)), scale18, curPriceX18) | |
430 | - | let slippageX18 = t1(slippage, scale8) | |
431 | - | if (if (if (validateSlippage) | |
432 | - | then (curPriceX18 != zeroBigInt) | |
433 | - | else false) | |
434 | - | then (slippageRealX18 > slippageX18) | |
435 | - | else false) | |
436 | - | then throw(((("Price slippage " + toString(slippageRealX18)) + " > ") + toString(slippageX18))) | |
437 | - | else { | |
438 | - | let lpEmissionX18 = t1(lpEm, scale8) | |
439 | - | let prViaAmX18 = fraction(inAmAssetAmtX18, cpbir(prBalanceX18, amBalanceX18, CEILING), scale18, CEILING) | |
440 | - | let amViaPrX18 = fraction(inPrAssetAmtX18, scale18, cpbir(prBalanceX18, amBalanceX18, FLOOR), CEILING) | |
441 | - | let expectedAmts = if ((prViaAmX18 > inPrAssetAmtX18)) | |
442 | - | then $Tuple2(amViaPrX18, inPrAssetAmtX18) | |
443 | - | else $Tuple2(inAmAssetAmtX18, prViaAmX18) | |
444 | - | let expAmtAssetAmtX18 = expectedAmts._1 | |
445 | - | let expPriceAssetAmtX18 = expectedAmts._2 | |
446 | - | let D1 = getD([(amBalanceX18 + expAmtAssetAmtX18), (prBalanceX18 + expPriceAssetAmtX18)]) | |
447 | - | let checkD = if ((D1 > D0)) | |
448 | - | then true | |
449 | - | else throw("D1 should be greater than D0") | |
450 | - | if ((checkD == checkD)) | |
451 | - | then { | |
452 | - | let lpAmtX18 = fraction(lpEmissionX18, (D1 - D0), D0) | |
453 | - | $Tuple5(fromX18Round(lpAmtX18, scale8, FLOOR), fromX18Round(expAmtAssetAmtX18, amtDcm, CEILING), fromX18Round(expPriceAssetAmtX18, priceDcm, CEILING), curPriceX18, slippageX18) | |
454 | - | } | |
455 | - | else throw("Strict value is not equal to itself.") | |
456 | - | } | |
457 | - | } | |
458 | - | let calcLpAmt = r._1 | |
459 | - | let calcAmAssetPmt = r._2 | |
460 | - | let calcPrAssetPmt = r._3 | |
461 | - | let curPrice = f1(r._4, scale8) | |
462 | - | let slippageCalc = f1(r._5, scale8) | |
463 | - | if ((0 >= calcLpAmt)) | |
464 | - | then throw("LP <= 0") | |
465 | - | else { | |
466 | - | let emitLpAmt = if (!(emitLp)) | |
467 | - | then 0 | |
468 | - | else calcLpAmt | |
469 | - | let amDiff = (inAmAmt - calcAmAssetPmt) | |
470 | - | let prDiff = (inPrAmt - calcPrAssetPmt) | |
471 | - | let $t02058820933 = if (if (isOneAsset) | |
472 | - | then (pmtId == amIdStr) | |
473 | - | else false) | |
474 | - | then $Tuple2(pmtAmt, 0) | |
475 | - | else if (if (isOneAsset) | |
476 | - | then (pmtId == prIdStr) | |
477 | - | else false) | |
478 | - | then $Tuple2(0, pmtAmt) | |
479 | - | else $Tuple2(calcAmAssetPmt, calcPrAssetPmt) | |
480 | - | let writeAmAmt = $t02058820933._1 | |
481 | - | let writePrAmt = $t02058820933._2 | |
482 | - | 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))] | |
483 | - | $Tuple13(calcLpAmt, emitLpAmt, curPrice, amBalance, prBalance, lpEm, lpId, sts, commonState, amDiff, prDiff, inAmId, inPrId) | |
484 | - | } | |
485 | - | } | |
486 | - | ||
487 | - | ||
488 | - | func getYD (xp,i,D) = { | |
489 | - | let n = big2 | |
490 | - | let x = xp[if ((i == 0)) | |
491 | - | then 1 | |
492 | - | else 0] | |
493 | - | let aPrecision = parseBigIntValue(Amult) | |
494 | - | let a = (parseBigIntValue(A) * aPrecision) | |
495 | - | let s = x | |
496 | - | let ann = (a * n) | |
497 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
498 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
499 | - | func calc (acc,cur) = { | |
500 | - | let $t02212822148 = acc | |
501 | - | let y = $t02212822148._1 | |
502 | - | let found = $t02212822148._2 | |
503 | - | if ((found != unit)) | |
504 | - | then acc | |
505 | - | else { | |
506 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
507 | - | let yDiff = absBigInt((yNext - value(y))) | |
508 | - | if ((big1 >= yDiff)) | |
509 | - | then $Tuple2(yNext, cur) | |
510 | - | else $Tuple2(yNext, unit) | |
511 | - | } | |
512 | - | } | |
513 | - | ||
514 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
515 | - | let $t02245522502 = { | |
516 | - | let $l = arr | |
517 | - | let $s = size($l) | |
518 | - | let $acc0 = $Tuple2(D, unit) | |
519 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
520 | - | then $a | |
521 | - | else calc($a, $l[$i]) | |
522 | - | ||
523 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
524 | - | then $a | |
525 | - | else throw("List size exceeds 15") | |
526 | - | ||
527 | - | $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) | |
528 | - | } | |
529 | - | let y = $t02245522502._1 | |
530 | - | let found = $t02245522502._2 | |
531 | - | if ((found != unit)) | |
532 | - | then y | |
533 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
534 | - | } | |
535 | - | ||
536 | - | ||
537 | - | func calcDLp (amountBalance,priceBalance,lpEmission) = { | |
538 | - | let updatedDLp = fraction(getD([t1BigInt(amountBalance, toBigInt(cfgAmountAssetDecimals)), t1BigInt(priceBalance, toBigInt(cfgPriceAssetDecimals))]), scale18, lpEmission) | |
539 | - | if ((lpEmission == big0)) | |
540 | - | then big0 | |
541 | - | else updatedDLp | |
542 | - | } | |
543 | - | ||
544 | - | ||
545 | - | func calcCurrentDLp (amountAssetDelta,priceAssetDelta,lpAssetEmissionDelta) = { | |
546 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amountAssetDelta) | |
547 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - priceAssetDelta) | |
548 | - | let lpAssetEmission = (toBigInt(value(assetInfo(cfgLpAssetId)).quantity) - lpAssetEmissionDelta) | |
549 | - | let currentDLp = calcDLp(amountAssetBalance, priceAssetBalance, lpAssetEmission) | |
550 | - | currentDLp | |
551 | - | } | |
552 | - | ||
553 | - | ||
554 | - | func refreshDLpInternal (amountAssetBalanceDelta,priceAssetBalanceDelta,lpAssetEmissionDelta) = { | |
555 | - | let amountAssetBalance = (getAccBalance(assetIdToString(cfgAmountAssetId)) + amountAssetBalanceDelta) | |
556 | - | let priceAssetBalance = (getAccBalance(assetIdToString(cfgPriceAssetId)) + priceAssetBalanceDelta) | |
557 | - | let lpAssetEmission = (value(assetInfo(cfgLpAssetId)).quantity + lpAssetEmissionDelta) | |
558 | - | let updatedDLp = calcDLp(toBigInt(amountAssetBalance), toBigInt(priceAssetBalance), toBigInt(lpAssetEmission)) | |
559 | - | let actions = [IntegerEntry(keyDLpRefreshedHeight, height), StringEntry(keyDLp, toString(updatedDLp))] | |
560 | - | $Tuple2(actions, updatedDLp) | |
561 | - | } | |
562 | - | ||
563 | - | ||
564 | - | func validateUpdatedDLp (oldDLp,updatedDLp) = if ((updatedDLp >= oldDLp)) | |
565 | - | then true | |
566 | - | else throwErr("updated DLp lower than current DLp") | |
567 | - | ||
568 | - | ||
569 | - | func validateMatcherOrderAllowed (order) = { | |
570 | - | let amountAssetBalance = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
571 | - | let priceAssetBalance = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
572 | - | let amountAssetAmount = order.amount | |
573 | - | let priceAssetAmount = fraction(order.amount, order.price, scale8, FLOOR) | |
574 | - | let $t02470024912 = if ((order.orderType == Buy)) | |
575 | - | then $Tuple2(amountAssetAmount, -(priceAssetAmount)) | |
576 | - | else $Tuple2(-(amountAssetAmount), priceAssetAmount) | |
577 | - | let amountAssetBalanceDelta = $t02470024912._1 | |
578 | - | let priceAssetBalanceDelta = $t02470024912._2 | |
579 | - | if (if (if (igs()) | |
580 | - | then true | |
581 | - | else (cfgPoolStatus == PoolMatcherDis)) | |
582 | - | then true | |
583 | - | else (cfgPoolStatus == PoolShutdown)) | |
584 | - | then throw("Admin blocked") | |
585 | - | else if (if ((order.assetPair.amountAsset != cfgAmountAssetId)) | |
586 | - | then true | |
587 | - | else (order.assetPair.priceAsset != cfgPriceAssetId)) | |
588 | - | then throw("Wr assets") | |
589 | - | else { | |
590 | - | let dLp = parseBigIntValue(valueOrElse(getString(this, keyDLp), "0")) | |
591 | - | let $t02525425354 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
592 | - | let unusedActions = $t02525425354._1 | |
593 | - | let dLpNew = $t02525425354._2 | |
594 | - | let isOrderValid = (dLpNew >= dLp) | |
595 | - | let info = makeString(["dLp=", toString(dLp), " dLpNew=", toString(dLpNew), " amountAssetBalance=", toString(amountAssetBalance), " priceAssetBalance=", toString(priceAssetBalance), " amountAssetBalanceDelta=", toString(amountAssetBalanceDelta), " priceAssetBalanceDelta=", toString(priceAssetBalanceDelta), " height=", toString(height)], "") | |
596 | - | $Tuple2(isOrderValid, info) | |
597 | - | } | |
598 | - | } | |
599 | - | ||
600 | - | ||
601 | - | func cg (i) = if ((size(i.payments) != 1)) | |
602 | - | then throw("1 pmnt exp") | |
603 | - | else { | |
604 | - | let pmt = value(i.payments[0]) | |
605 | - | let pmtAssetId = value(pmt.assetId) | |
606 | - | let pmtAmt = pmt.amount | |
607 | - | let r = ego(toBase58String(i.transactionId), toBase58String(pmtAssetId), pmtAmt, i.caller) | |
608 | - | let outAmAmt = r._1 | |
609 | - | let outPrAmt = r._2 | |
610 | - | let sts = parseIntValue(r._9) | |
611 | - | let state = r._10 | |
612 | - | if (if (igs()) | |
613 | - | then true | |
614 | - | else (sts == PoolShutdown)) | |
615 | - | then throw(("Admin blocked: " + toString(sts))) | |
616 | - | else $Tuple5(outAmAmt, outPrAmt, pmtAmt, pmtAssetId, state) | |
617 | - | } | |
618 | - | ||
619 | - | ||
620 | - | func cp (caller,txId,amAsPmt,prAsPmt,slippage,emitLp,isOneAsset,validateSlippage,pmtAmt,pmtId) = { | |
621 | - | let r = epo(txId, slippage, value(amAsPmt).amount, value(amAsPmt).assetId, value(prAsPmt).amount, value(prAsPmt).assetId, caller, (txId == ""), emitLp, isOneAsset, validateSlippage, pmtAmt, pmtId) | |
622 | - | let sts = parseIntValue(r._8) | |
623 | - | if (if (if (igs()) | |
624 | - | then true | |
625 | - | else (sts == PoolPutDis)) | |
626 | - | then true | |
627 | - | else (sts == PoolShutdown)) | |
628 | - | then throw(("Blocked:" + toString(sts))) | |
629 | - | else r | |
630 | - | } | |
631 | - | ||
632 | - | ||
633 | - | func calcPutOneTkn (pmtAmtRaw,pmtAssetId,userAddress,txId,withTakeFee) = { | |
634 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
635 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
636 | - | let lpId = cfgLpAssetId | |
637 | - | let amtDcm = cfgAmountAssetDecimals | |
638 | - | let priceDcm = cfgPriceAssetDecimals | |
639 | - | let lpAssetEmission = toBigInt(valueOrErrorMessage(assetInfo(lpId), "invalid lp asset").quantity) | |
640 | - | let chechEmission = if ((lpAssetEmission > big0)) | |
641 | - | then true | |
642 | - | else throw("initial deposit requires all coins") | |
643 | - | if ((chechEmission == chechEmission)) | |
644 | - | then { | |
645 | - | let amBalance = getAccBalance(amId) | |
646 | - | let prBalance = getAccBalance(prId) | |
647 | - | let $t02801028472 = if ((txId == "")) | |
648 | - | then $Tuple2(amBalance, prBalance) | |
649 | - | else if ((pmtAssetId == amId)) | |
650 | - | then if ((pmtAmtRaw > amBalance)) | |
651 | - | then throw("invalid payment amount") | |
652 | - | else $Tuple2((amBalance - pmtAmtRaw), prBalance) | |
653 | - | else if ((pmtAssetId == prId)) | |
654 | - | then if ((pmtAmtRaw > prBalance)) | |
655 | - | then throw("invalid payment amount") | |
656 | - | else $Tuple2(amBalance, (prBalance - pmtAmtRaw)) | |
657 | - | else throw("wrong pmtAssetId") | |
658 | - | let amBalanceOld = $t02801028472._1 | |
659 | - | let prBalanceOld = $t02801028472._2 | |
660 | - | let $t02847828654 = if ((pmtAssetId == amId)) | |
661 | - | then $Tuple2(pmtAmtRaw, 0) | |
662 | - | else if ((pmtAssetId == prId)) | |
663 | - | then $Tuple2(0, pmtAmtRaw) | |
664 | - | else throw("invalid payment") | |
665 | - | let amAmountRaw = $t02847828654._1 | |
666 | - | let prAmountRaw = $t02847828654._2 | |
667 | - | let $t02865828912 = if (withTakeFee) | |
668 | - | then $Tuple3(takeFee(amAmountRaw, inFee)._1, takeFee(prAmountRaw, inFee)._1, takeFee(pmtAmtRaw, inFee)._2) | |
669 | - | else $Tuple3(amAmountRaw, prAmountRaw, 0) | |
670 | - | let amAmount = $t02865828912._1 | |
671 | - | let prAmount = $t02865828912._2 | |
672 | - | let feeAmount = $t02865828912._3 | |
673 | - | let amBalanceNew = (amBalanceOld + amAmount) | |
674 | - | let prBalanceNew = (prBalanceOld + prAmount) | |
675 | - | let D0 = getD([t1(amBalanceOld, cfgAmountAssetDecimals), t1(prBalanceOld, cfgPriceAssetDecimals)]) | |
676 | - | let D1 = getD([t1(amBalanceNew, cfgAmountAssetDecimals), t1(prBalanceNew, cfgPriceAssetDecimals)]) | |
677 | - | let checkD = if ((D1 > D0)) | |
678 | - | then true | |
679 | - | else throw() | |
680 | - | if ((checkD == checkD)) | |
681 | - | then { | |
682 | - | let lpAmount = fraction(lpAssetEmission, (D1 - D0), D0, FLOOR) | |
683 | - | let curPrice = f1(cpbi(t1(prBalanceNew, priceDcm), t1(amBalanceNew, amtDcm)), scale8) | |
684 | - | 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))] | |
685 | - | let poolProportion = fraction(prBalanceOld, scale8, amBalanceOld) | |
686 | - | let amountAssetPart = fraction(pmtAmtRaw, scale8, (poolProportion + scale8)) | |
687 | - | let priceAssetPart = (pmtAmtRaw - amountAssetPart) | |
688 | - | let lpAmtBoth = fraction(lpAssetEmission, toBigInt(priceAssetPart), toBigInt(prBalanceOld)) | |
689 | - | let bonus = toInt(fraction((lpAmount - lpAmtBoth), scale8BigInt, lpAmtBoth)) | |
690 | - | $Tuple4(toInt(lpAmount), commonState, feeAmount, bonus) | |
691 | - | } | |
692 | - | else throw("Strict value is not equal to itself.") | |
780 | + | $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset) | |
693 | 781 | } | |
694 | 782 | else throw("Strict value is not equal to itself.") | |
695 | 783 | } | |
696 | 784 | ||
697 | 785 | ||
698 | - | func getOneTknV2Internal (outAssetId,minOutAmount,payments,caller,originCaller,transactionId) = { | |
699 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
700 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
701 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
702 | - | let amDecimals = cfgAmountAssetDecimals | |
703 | - | let prDecimals = cfgPriceAssetDecimals | |
704 | - | let poolStatus = cfgPoolStatus | |
705 | - | let userAddress = if ((caller == restContract)) | |
706 | - | then originCaller | |
707 | - | else caller | |
708 | - | let pmt = value(payments[0]) | |
709 | - | let pmtAssetId = value(pmt.assetId) | |
710 | - | let pmtAmt = pmt.amount | |
711 | - | let currentDLp = calcCurrentDLp(big0, big0, big0) | |
712 | - | if ((currentDLp == currentDLp)) | |
786 | + | func calcGetOneToken (outAssetId,paymentAmount,paymentAssetId,userAddress,txId) = { | |
787 | + | let isEval = (txId == unit) | |
788 | + | let cfg = getPoolConfig() | |
789 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
790 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
791 | + | let checks = [if ((paymentAssetId == cfgLpAssetId)) | |
792 | + | then true | |
793 | + | else throwErr("invalid lp asset")] | |
794 | + | if ((checks == checks)) | |
713 | 795 | then { | |
714 | - | let txId58 = toBase58String(transactionId) | |
715 | - | if ((lpId != toBase58String(pmtAssetId))) | |
716 | - | then throw("Wrong LP") | |
717 | - | else { | |
718 | - | let amBalance = getAccBalance(amId) | |
719 | - | let prBalance = getAccBalance(prId) | |
720 | - | let $t03102431135 = { | |
721 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, pmtAmt], nil) | |
722 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
723 | - | then @ | |
724 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
725 | - | } | |
726 | - | if (($t03102431135 == $t03102431135)) | |
727 | - | then { | |
728 | - | let feeAmount = $t03102431135._2 | |
729 | - | let totalGet = $t03102431135._1 | |
730 | - | let totalAmount = if (if ((minOutAmount > 0)) | |
731 | - | then (minOutAmount > totalGet) | |
732 | - | else false) | |
733 | - | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
734 | - | else totalGet | |
735 | - | let $t03132531632 = if ((outAssetId == amId)) | |
736 | - | then $Tuple4(totalAmount, 0, ((amBalance - totalAmount) - feeAmount), prBalance) | |
737 | - | else if ((outAssetId == prId)) | |
738 | - | then $Tuple4(0, totalAmount, amBalance, ((prBalance - totalAmount) - feeAmount)) | |
739 | - | else throw("invalid out asset id") | |
740 | - | let outAm = $t03132531632._1 | |
741 | - | let outPr = $t03132531632._2 | |
742 | - | let amBalanceNew = $t03132531632._3 | |
743 | - | let prBalanceNew = $t03132531632._4 | |
744 | - | let curPrX18 = cpbi(t1(prBalanceNew, prDecimals), t1(amBalanceNew, amDecimals)) | |
745 | - | let curPr = f1(curPrX18, scale8) | |
746 | - | let outAssetIdOrWaves = if ((outAssetId == "WAVES")) | |
747 | - | then unit | |
748 | - | else fromBase58String(outAssetId) | |
749 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
750 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetIdOrWaves)] | |
751 | - | else nil | |
752 | - | 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) | |
753 | - | if ((state == state)) | |
754 | - | then { | |
755 | - | let burn = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
756 | - | if ((burn == burn)) | |
757 | - | then { | |
758 | - | let $t03241732767 = { | |
759 | - | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
760 | - | then 0 | |
761 | - | else feeAmount | |
762 | - | let outInAmountAsset = if ((parseAssetId(outAssetId) == cfgAmountAssetId)) | |
763 | - | then true | |
764 | - | else false | |
765 | - | if (outInAmountAsset) | |
766 | - | then $Tuple2(-((totalGet + feeAmountForCalc)), 0) | |
767 | - | else $Tuple2(0, -((totalGet + feeAmountForCalc))) | |
768 | - | } | |
769 | - | let amountAssetBalanceDelta = $t03241732767._1 | |
770 | - | let priceAssetBalanceDelta = $t03241732767._2 | |
771 | - | let $t03277032878 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
772 | - | let refreshDLpActions = $t03277032878._1 | |
773 | - | let updatedDLp = $t03277032878._2 | |
774 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
775 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
776 | - | then $Tuple2((state ++ refreshDLpActions), totalAmount) | |
777 | - | else throw("Strict value is not equal to itself.") | |
778 | - | } | |
779 | - | else throw("Strict value is not equal to itself.") | |
780 | - | } | |
781 | - | else throw("Strict value is not equal to itself.") | |
782 | - | } | |
783 | - | else throw("Strict value is not equal to itself.") | |
784 | - | } | |
796 | + | let outInAmountAsset = if ((outAssetId == cfgAmountAssetId)) | |
797 | + | then true | |
798 | + | else if ((outAssetId == cfgPriceAssetId)) | |
799 | + | then false | |
800 | + | else throwErr("invalid asset") | |
801 | + | let balanceBigInt = if (outInAmountAsset) | |
802 | + | then toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) | |
803 | + | else toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) | |
804 | + | let outInAmountAssetDecimals = if (outInAmountAsset) | |
805 | + | then amtAssetDcm | |
806 | + | else priceAssetDcm | |
807 | + | let amBalanceOld = getAccBalance(assetIdToString(cfgAmountAssetId)) | |
808 | + | let prBalanceOld = getAccBalance(assetIdToString(cfgPriceAssetId)) | |
809 | + | let outBalance = if (outInAmountAsset) | |
810 | + | then amBalanceOld | |
811 | + | else prBalanceOld | |
812 | + | let outBalanceBigInt = toBigInt(outBalance) | |
813 | + | let supplyBigInt = toBigInt(valueOrErrorMessage(assetInfo(cfgLpAssetId), (("asset " + toBase58String(cfgLpAssetId)) + " doesn't exist")).quantity) | |
814 | + | let redeemedBigInt = toBigInt(paymentAmount) | |
815 | + | let amountRaw = max([0, toInt(((balanceBigInt * (scale18 - pow((scale18 - ((redeemedBigInt * scale18) / supplyBigInt)), 18, big2, 0, 18, DOWN))) / scale18))]) | |
816 | + | let $t03695337009 = takeFee(amountRaw, outFee) | |
817 | + | let totalAmount = $t03695337009._1 | |
818 | + | let feeAmount = $t03695337009._2 | |
819 | + | let $t03701337239 = if (outInAmountAsset) | |
820 | + | then $Tuple4(totalAmount, 0, (amBalanceOld - amountRaw), prBalanceOld) | |
821 | + | else $Tuple4(0, totalAmount, amBalanceOld, (prBalanceOld - amountRaw)) | |
822 | + | let outAmAmount = $t03701337239._1 | |
823 | + | let outPrAmount = $t03701337239._2 | |
824 | + | let amBalanceNew = $t03701337239._3 | |
825 | + | let prBalanceNew = $t03701337239._4 | |
826 | + | let priceNewX18 = calcPriceBigInt(toX18(prBalanceNew, cfgPriceAssetDecimals), toX18(amBalanceNew, cfgAmountAssetDecimals)) | |
827 | + | let priceNew = fromX18(priceNewX18, scale8) | |
828 | + | let commonState = if (isEval) | |
829 | + | then nil | |
830 | + | else [StringEntry(gau(toString(value(userAddress)), toBase58String(value(txId))), dataGetActionInfo(outAmAmount, outPrAmount, paymentAmount, priceNew, height, lastBlock.timestamp)), IntegerEntry(pl(), priceNew), IntegerEntry(ph(height, lastBlock.timestamp), priceNew)] | |
831 | + | let priceOldX18 = calcPriceBigInt(toX18(prBalanceOld, cfgPriceAssetDecimals), toX18(amBalanceOld, cfgAmountAssetDecimals)) | |
832 | + | let priceOld = fromX18(priceOldX18, scale8) | |
833 | + | let loss = { | |
834 | + | let amountBothInPaymentAsset = (toInt(fraction(balanceBigInt, redeemedBigInt, supplyBigInt)) * 2) | |
835 | + | fraction((totalAmount - amountBothInPaymentAsset), scale8, amountBothInPaymentAsset) | |
836 | + | } | |
837 | + | $Tuple5(totalAmount, commonState, feeAmount, loss, outInAmountAsset) | |
785 | 838 | } | |
786 | 839 | else throw("Strict value is not equal to itself.") | |
787 | 840 | } | |
788 | 841 | ||
789 | 842 | ||
790 | - | func | |
843 | + | func managerPublicKeyOrUnit () = match getString(mpk()) { | |
791 | 844 | case s: String => | |
792 | 845 | fromBase58String(s) | |
793 | 846 | case _: Unit => | |
794 | 847 | unit | |
795 | 848 | case _ => | |
796 | 849 | throw("Match error") | |
797 | 850 | } | |
798 | 851 | ||
799 | 852 | ||
800 | - | func | |
853 | + | func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) { | |
801 | 854 | case s: String => | |
802 | 855 | fromBase58String(s) | |
803 | 856 | case _: Unit => | |
804 | 857 | unit | |
805 | 858 | case _ => | |
806 | 859 | throw("Match error") | |
807 | 860 | } | |
808 | 861 | ||
809 | 862 | ||
810 | - | let pd = throw("Permission denied") | |
811 | - | ||
812 | - | func isManager (i) = match m() { | |
863 | + | func isManager (i) = match managerPublicKeyOrUnit() { | |
813 | 864 | case pk: ByteVector => | |
814 | 865 | (i.callerPublicKey == pk) | |
815 | 866 | case _: Unit => | |
816 | 867 | (i.caller == this) | |
817 | 868 | case _ => | |
818 | 869 | throw("Match error") | |
819 | 870 | } | |
820 | 871 | ||
821 | 872 | ||
822 | - | func mm (i) = match m() { | |
823 | - | case pk: ByteVector => | |
824 | - | if ((i.callerPublicKey == pk)) | |
825 | - | then true | |
826 | - | else pd | |
827 | - | case _: Unit => | |
828 | - | if ((i.caller == this)) | |
829 | - | then true | |
830 | - | else pd | |
831 | - | case _ => | |
832 | - | throw("Match error") | |
833 | - | } | |
834 | - | ||
835 | - | ||
836 | - | func getY (isReverse,D,poolAmountInBalance) = { | |
837 | - | let poolConfig = gpc() | |
838 | - | let amId = poolConfig[idxAmAsId] | |
839 | - | let prId = poolConfig[idxPrAsId] | |
840 | - | let n = big2 | |
841 | - | let aPrecision = parseBigIntValue(Amult) | |
842 | - | let a = (parseBigIntValue(A) * aPrecision) | |
843 | - | let xp = if ((isReverse == false)) | |
844 | - | then [(toBigInt(getAccBalance(amId)) + poolAmountInBalance), toBigInt(getAccBalance(prId))] | |
845 | - | else [(toBigInt(getAccBalance(prId)) + poolAmountInBalance), toBigInt(getAccBalance(amId))] | |
846 | - | let x = xp[0] | |
847 | - | let s = x | |
848 | - | let ann = (a * n) | |
849 | - | let c = (((((D * D) / (x * n)) * D) * aPrecision) / (ann * n)) | |
850 | - | let b = ((s + ((D * aPrecision) / ann)) - D) | |
851 | - | func calc (acc,cur) = { | |
852 | - | let $t03432534345 = acc | |
853 | - | let y = $t03432534345._1 | |
854 | - | let found = $t03432534345._2 | |
855 | - | if ((found != unit)) | |
856 | - | then acc | |
857 | - | else { | |
858 | - | let yNext = (((y * y) + c) / ((big2 * y) + b)) | |
859 | - | let yDiff = absBigInt((yNext - value(y))) | |
860 | - | if ((big1 >= yDiff)) | |
861 | - | then $Tuple2(yNext, cur) | |
862 | - | else $Tuple2(yNext, unit) | |
863 | - | } | |
864 | - | } | |
865 | - | ||
866 | - | let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
867 | - | let $t03467634723 = { | |
868 | - | let $l = arr | |
869 | - | let $s = size($l) | |
870 | - | let $acc0 = $Tuple2(D, unit) | |
871 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
872 | - | then $a | |
873 | - | else calc($a, $l[$i]) | |
874 | - | ||
875 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
876 | - | then $a | |
877 | - | else throw("List size exceeds 15") | |
878 | - | ||
879 | - | $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) | |
880 | - | } | |
881 | - | let y = $t03467634723._1 | |
882 | - | let found = $t03467634723._2 | |
883 | - | if ((found != unit)) | |
884 | - | then y | |
885 | - | else throw(("Y calculation error, Y = " + toString(y))) | |
873 | + | func mustManager (i) = { | |
874 | + | let pd = throw("Permission denied") | |
875 | + | match managerPublicKeyOrUnit() { | |
876 | + | case pk: ByteVector => | |
877 | + | if ((i.callerPublicKey == pk)) | |
878 | + | then true | |
879 | + | else pd | |
880 | + | case _: Unit => | |
881 | + | if ((i.caller == this)) | |
882 | + | then true | |
883 | + | else pd | |
884 | + | case _ => | |
885 | + | throw("Match error") | |
886 | + | } | |
886 | 887 | } | |
887 | 888 | ||
888 | 889 | ||
889 | - | func skipOrderValidation () = valueOrElse(getBoolean(fca, keySkipOrderValidation(toString(this))), false) | |
890 | + | @Callable(i) | |
891 | + | func rebalance () = (rebalanceAsset(getStringOrFail(this, aa())) ++ rebalanceAsset(getStringOrFail(this, pa()))) | |
892 | + | ||
890 | 893 | ||
891 | 894 | ||
892 | 895 | @Callable(i) | |
893 | 896 | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
894 | - | let $ | |
897 | + | let $t03912539430 = if ((isReverse == false)) | |
895 | 898 | then { | |
896 | - | let assetOut = | |
897 | - | let | |
898 | - | $Tuple2(assetOut, | |
899 | + | let assetOut = getStringOrFail(this, pa()) | |
900 | + | let assetIn = getStringOrFail(this, aa()) | |
901 | + | $Tuple2(assetOut, assetIn) | |
899 | 902 | } | |
900 | 903 | else { | |
901 | - | let assetOut = | |
902 | - | let | |
903 | - | $Tuple2(assetOut, | |
904 | + | let assetOut = getStringOrFail(this, aa()) | |
905 | + | let assetIn = getStringOrFail(this, pa()) | |
906 | + | $Tuple2(assetOut, assetIn) | |
904 | 907 | } | |
905 | - | let assetOut = $t03507535499._1 | |
906 | - | let poolAmountInBalance = $t03507535499._2 | |
907 | - | let poolConfig = gpc() | |
908 | - | let amId = poolConfig[idxAmAsId] | |
909 | - | let prId = poolConfig[idxPrAsId] | |
910 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
911 | - | let D = getD(xp) | |
912 | - | let y = getY(isReverse, D, toBigInt(cleanAmountIn)) | |
913 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
914 | - | let totalGetRaw = max([0, toInt(dy)]) | |
915 | - | let newXp = if ((isReverse == false)) | |
916 | - | then [((toBigInt(getAccBalance(amId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
917 | - | else [(toBigInt(getAccBalance(amId)) - dy), ((toBigInt(getAccBalance(prId)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount))] | |
918 | - | let newD = getD(newXp) | |
919 | - | let checkD = if ((newD >= D)) | |
908 | + | let assetOut = $t03912539430._1 | |
909 | + | let assetIn = $t03912539430._2 | |
910 | + | let poolAssetInBalance = getAccBalance(assetIn) | |
911 | + | let poolAssetOutBalance = getAccBalance(assetOut) | |
912 | + | let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn)) | |
913 | + | let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance)) | |
914 | + | let newK = (((toBigInt(getAccBalance(assetIn)) + toBigInt(cleanAmountIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut))) | |
915 | + | let checkK = if ((newK >= oldK)) | |
920 | 916 | then true | |
921 | - | else throw( | |
922 | - | if (( | |
923 | - | then $Tuple2(nil, | |
917 | + | else throw("new K is fewer error") | |
918 | + | if ((checkK == checkK)) | |
919 | + | then $Tuple2(nil, amountOut) | |
924 | 920 | else throw("Strict value is not equal to itself.") | |
925 | 921 | } | |
926 | 922 | ||
927 | 923 | ||
928 | 924 | ||
929 | 925 | @Callable(i) | |
930 | 926 | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
931 | 927 | let swapContact = { | |
932 | - | let @ = invoke( | |
928 | + | let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil) | |
933 | 929 | if ($isInstanceOf(@, "String")) | |
934 | 930 | then @ | |
935 | 931 | else throw(($getType(@) + " couldn't be cast to String")) | |
936 | 932 | } | |
937 | 933 | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
938 | 934 | then true | |
939 | 935 | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
940 | 936 | then true | |
941 | 937 | else throwErr("Permission denied")] | |
942 | 938 | if ((checks == checks)) | |
943 | 939 | then { | |
944 | 940 | let pmt = value(i.payments[0]) | |
945 | 941 | let assetIn = assetIdToString(pmt.assetId) | |
946 | - | let $t03693537329 = if ((isReverse == false)) | |
942 | + | let assetOut = if ((isReverse == false)) | |
943 | + | then getStringOrFail(this, pa()) | |
944 | + | else getStringOrFail(this, aa()) | |
945 | + | let poolAssetInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
946 | + | let poolAssetOutBalance = getAccBalance(assetOut) | |
947 | + | let amountOut = fraction(poolAssetOutBalance, cleanAmountIn, (poolAssetInBalance + cleanAmountIn)) | |
948 | + | let oldK = (toBigInt(poolAssetInBalance) * toBigInt(poolAssetOutBalance)) | |
949 | + | let newK = ((toBigInt(getAccBalance(assetIn)) + toBigInt(feePoolAmount)) * (toBigInt(getAccBalance(assetOut)) - toBigInt(amountOut))) | |
950 | + | let checkK = if ((newK >= oldK)) | |
951 | + | then true | |
952 | + | else throw("new K is fewer error") | |
953 | + | if ((checkK == checkK)) | |
947 | 954 | then { | |
948 | - | let assetOut = strf(this, pa()) | |
949 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
950 | - | $Tuple2(assetOut, poolAmountInBalance) | |
951 | - | } | |
952 | - | else { | |
953 | - | let assetOut = strf(this, aa()) | |
954 | - | let poolAmountInBalance = (getAccBalance(assetIn) - value(i.payments[0]).amount) | |
955 | - | $Tuple2(assetOut, poolAmountInBalance) | |
956 | - | } | |
957 | - | let assetOut = $t03693537329._1 | |
958 | - | let poolAmountInBalance = $t03693537329._2 | |
959 | - | let poolConfig = gpc() | |
960 | - | let amId = poolConfig[idxAmAsId] | |
961 | - | let prId = poolConfig[idxPrAsId] | |
962 | - | let xp = if ((isReverse == false)) | |
963 | - | then [(toBigInt(getAccBalance(amId)) - toBigInt(value(i.payments[0]).amount)), toBigInt(getAccBalance(prId))] | |
964 | - | else [toBigInt(getAccBalance(amId)), (toBigInt(getAccBalance(prId)) - toBigInt(value(i.payments[0]).amount))] | |
965 | - | let D = getD(xp) | |
966 | - | let y = getY(isReverse, D, toBigInt(0)) | |
967 | - | let dy = ((toBigInt(getAccBalance(assetOut)) - y) - toBigInt(1)) | |
968 | - | let totalGetRaw = max([0, toInt(dy)]) | |
969 | - | let checkMin = if ((totalGetRaw >= amountOutMin)) | |
970 | - | then true | |
971 | - | else throw("Exchange result is fewer coins than expected") | |
972 | - | if ((checkMin == checkMin)) | |
973 | - | then { | |
974 | - | let newXp = if ((isReverse == false)) | |
975 | - | then [(toBigInt(getAccBalance(amId)) + toBigInt(feePoolAmount)), (toBigInt(getAccBalance(prId)) - dy)] | |
976 | - | else [(toBigInt(getAccBalance(amId)) - dy), (toBigInt(getAccBalance(prId)) + toBigInt(feePoolAmount))] | |
977 | - | let newD = getD(newXp) | |
978 | - | let checkD = if ((newD >= D)) | |
955 | + | let checkMin = if ((amountOut >= amountOutMin)) | |
979 | 956 | then true | |
980 | - | else throw("new D is fewer error") | |
981 | - | if ((checkD == checkD)) | |
982 | - | then $Tuple2([ScriptTransfer(addressFromStringValue(addressTo), totalGetRaw, parseAssetId(assetOut))], totalGetRaw) | |
957 | + | else throw("Exchange result is fewer coins than expected") | |
958 | + | if ((checkMin == checkMin)) | |
959 | + | then { | |
960 | + | let rebalanceState = rebalanceAsset(assetIn) | |
961 | + | if ((rebalanceState == rebalanceState)) | |
962 | + | then { | |
963 | + | let withdrawState = withdrawAndRebalanceAsset(assetOut, amountOut) | |
964 | + | if ((withdrawState == withdrawState)) | |
965 | + | then $Tuple2(((withdrawState ++ rebalanceState) ++ [ScriptTransfer(addressFromStringValue(addressTo), amountOut, parseAssetId(assetOut))]), amountOut) | |
966 | + | else throw("Strict value is not equal to itself.") | |
967 | + | } | |
968 | + | else throw("Strict value is not equal to itself.") | |
969 | + | } | |
983 | 970 | else throw("Strict value is not equal to itself.") | |
984 | 971 | } | |
985 | 972 | else throw("Strict value is not equal to itself.") | |
986 | 973 | } | |
987 | 974 | else throw("Strict value is not equal to itself.") | |
988 | 975 | } | |
989 | 976 | ||
990 | 977 | ||
991 | 978 | ||
992 | 979 | @Callable(i) | |
993 | - | func constructor (fc) = { | |
994 | - | let c = mm(i) | |
995 | - | if ((c == c)) | |
996 | - | then [StringEntry(fc(), fc)] | |
997 | - | else throw("Strict value is not equal to itself.") | |
998 | - | } | |
999 | - | ||
1000 | - | ||
1001 | - | ||
1002 | - | @Callable(i) | |
1003 | 980 | func setManager (pendingManagerPublicKey) = { | |
1004 | - | let | |
1005 | - | if (( | |
981 | + | let checkCaller = mustManager(i) | |
982 | + | if ((checkCaller == checkCaller)) | |
1006 | 983 | then { | |
1007 | - | let | |
1008 | - | if (( | |
984 | + | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
985 | + | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
1009 | 986 | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
1010 | 987 | else throw("Strict value is not equal to itself.") | |
1011 | 988 | } | |
1012 | 989 | else throw("Strict value is not equal to itself.") | |
1013 | 990 | } | |
1014 | 991 | ||
1015 | 992 | ||
1016 | 993 | ||
1017 | 994 | @Callable(i) | |
1018 | 995 | func confirmManager () = { | |
1019 | - | let | |
1020 | - | let | |
996 | + | let pm = pendingManagerPublicKeyOrUnit() | |
997 | + | let hasPM = if (isDefined(pm)) | |
1021 | 998 | then true | |
1022 | 999 | else throw("No pending manager") | |
1023 | - | if (( | |
1000 | + | if ((hasPM == hasPM)) | |
1024 | 1001 | then { | |
1025 | - | let | |
1002 | + | let checkPM = if ((i.callerPublicKey == value(pm))) | |
1026 | 1003 | then true | |
1027 | 1004 | else throw("You are not pending manager") | |
1028 | - | if (( | |
1029 | - | then [StringEntry(mpk(), toBase58String(value( | |
1005 | + | if ((checkPM == checkPM)) | |
1006 | + | then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())] | |
1030 | 1007 | else throw("Strict value is not equal to itself.") | |
1031 | 1008 | } | |
1032 | 1009 | else throw("Strict value is not equal to itself.") | |
1033 | 1010 | } | |
1034 | 1011 | ||
1035 | 1012 | ||
1036 | 1013 | ||
1037 | 1014 | @Callable(i) | |
1038 | - | func put (slip,autoStake) = { | |
1039 | - | let factCfg = gfc() | |
1040 | - | let stakingCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactStakCntr]), "Wr st addr") | |
1041 | - | let slipCntr = valueOrErrorMessage(addressFromString(factCfg[idxFactSlippCntr]), "Wr sl addr") | |
1042 | - | if ((0 > slip)) | |
1043 | - | then throw("Wrong slippage") | |
1044 | - | else if ((size(i.payments) != 2)) | |
1045 | - | then throw("2 pmnts expd") | |
1046 | - | else { | |
1047 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1048 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1049 | - | let amountAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgAmountAssetId))) - amAssetPmt) | |
1050 | - | if ((amountAssetBalance == amountAssetBalance)) | |
1015 | + | func put (slippageTolerance,shouldAutoStake) = if ((0 > slippageTolerance)) | |
1016 | + | then throw("Invalid slippageTolerance passed") | |
1017 | + | else { | |
1018 | + | let estPut = commonPut(i, slippageTolerance, true) | |
1019 | + | let emitLpAmt = estPut._2 | |
1020 | + | let lpAssetId = estPut._7 | |
1021 | + | let state = estPut._9 | |
1022 | + | let amDiff = estPut._10 | |
1023 | + | let prDiff = estPut._11 | |
1024 | + | let amId = estPut._12 | |
1025 | + | let prId = estPut._13 | |
1026 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1027 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1028 | + | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1029 | + | if ((currentKLp == currentKLp)) | |
1030 | + | then { | |
1031 | + | let emitInv = invoke(factoryContract, "emit", [emitLpAmt], nil) | |
1032 | + | if ((emitInv == emitInv)) | |
1051 | 1033 | then { | |
1052 | - | let priceAssetBalance = (toBigInt(getAccBalance(assetIdToString(cfgPriceAssetId))) - prAssetPmt) | |
1053 | - | if ((priceAssetBalance == priceAssetBalance)) | |
1034 | + | let emitInvLegacy = match emitInv { | |
1035 | + | case legacyFactoryContract: Address => | |
1036 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
1037 | + | case _ => | |
1038 | + | unit | |
1039 | + | } | |
1040 | + | if ((emitInvLegacy == emitInvLegacy)) | |
1054 | 1041 | then { | |
1055 | - | let lpAssetEmission = toBigInt(value(assetInfo(cfgLpAssetId)).quantity) | |
1056 | - | if ((lpAssetEmission == lpAssetEmission)) | |
1042 | + | let slippageAInv = if ((amDiff > 0)) | |
1043 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1044 | + | else nil | |
1045 | + | if ((slippageAInv == slippageAInv)) | |
1057 | 1046 | then { | |
1058 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1059 | - | if ((currentDLp == currentDLp)) | |
1047 | + | let slippagePInv = if ((prDiff > 0)) | |
1048 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1049 | + | else nil | |
1050 | + | if ((slippagePInv == slippagePInv)) | |
1060 | 1051 | then { | |
1061 | - | 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, "") | |
1062 | - | let emitLpAmt = e._2 | |
1063 | - | let lpAssetId = e._7 | |
1064 | - | let state = e._9 | |
1065 | - | let amDiff = e._10 | |
1066 | - | let prDiff = e._11 | |
1067 | - | let amId = e._12 | |
1068 | - | let prId = e._13 | |
1069 | - | let r = invoke(fca, "emit", [emitLpAmt], nil) | |
1070 | - | if ((r == r)) | |
1052 | + | let lpTransfer = if (shouldAutoStake) | |
1071 | 1053 | then { | |
1072 | - | let el = match r { | |
1073 | - | case legacy: Address => | |
1074 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1075 | - | case _ => | |
1076 | - | unit | |
1054 | + | let slpStakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1055 | + | if ((slpStakeInv == slpStakeInv)) | |
1056 | + | then nil | |
1057 | + | else throw("Strict value is not equal to itself.") | |
1077 | 1058 | } | |
1078 | - | if ((el == el)) | |
1059 | + | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1060 | + | let $t04447644938 = refreshKLpInternal(0, 0, 0) | |
1061 | + | if (($t04447644938 == $t04447644938)) | |
1062 | + | then { | |
1063 | + | let updatedKLp = $t04447644938._2 | |
1064 | + | let refreshKLpActions = $t04447644938._1 | |
1065 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1066 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1079 | 1067 | then { | |
1080 | - | let sa = if ((amDiff > 0)) | |
1081 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1082 | - | else nil | |
1083 | - | if ((sa == sa)) | |
1084 | - | then { | |
1085 | - | let sp = if ((prDiff > 0)) | |
1086 | - | then invoke(slipCntr, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1087 | - | else nil | |
1088 | - | if ((sp == sp)) | |
1089 | - | then { | |
1090 | - | let lpTrnsfr = if (autoStake) | |
1091 | - | then { | |
1092 | - | let ss = invoke(stakingCntr, "stake", nil, [AttachedPayment(lpAssetId, emitLpAmt)]) | |
1093 | - | if ((ss == ss)) | |
1094 | - | then nil | |
1095 | - | else throw("Strict value is not equal to itself.") | |
1096 | - | } | |
1097 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpAssetId)] | |
1098 | - | let $t04194842090 = refreshDLpInternal(0, 0, 0) | |
1099 | - | let refreshDLpActions = $t04194842090._1 | |
1100 | - | let updatedDLp = $t04194842090._2 | |
1101 | - | let check = if ((updatedDLp >= currentDLp)) | |
1102 | - | then true | |
1103 | - | else throwErr(makeString(["updated DLp lower than current DLp", toString(amountAssetBalance), toString(priceAssetBalance), toString(lpAssetEmission), toString(currentDLp), toString(updatedDLp), toString(amDiff), toString(prDiff)], " ")) | |
1104 | - | if ((check == check)) | |
1105 | - | then { | |
1106 | - | let lpAssetEmissionAfter = value(assetInfo(cfgLpAssetId)).quantity | |
1107 | - | if ((lpAssetEmissionAfter == lpAssetEmissionAfter)) | |
1108 | - | then ((state ++ lpTrnsfr) ++ refreshDLpActions) | |
1109 | - | else throw("Strict value is not equal to itself.") | |
1110 | - | } | |
1111 | - | else throw("Strict value is not equal to itself.") | |
1112 | - | } | |
1113 | - | else throw("Strict value is not equal to itself.") | |
1114 | - | } | |
1068 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1069 | + | if ((reb == reb)) | |
1070 | + | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
1115 | 1071 | else throw("Strict value is not equal to itself.") | |
1116 | 1072 | } | |
1117 | 1073 | else throw("Strict value is not equal to itself.") | |
1118 | 1074 | } | |
1119 | 1075 | else throw("Strict value is not equal to itself.") | |
1120 | 1076 | } | |
1121 | 1077 | else throw("Strict value is not equal to itself.") | |
1122 | 1078 | } | |
1123 | 1079 | else throw("Strict value is not equal to itself.") | |
1124 | 1080 | } | |
1125 | 1081 | else throw("Strict value is not equal to itself.") | |
1126 | 1082 | } | |
1127 | 1083 | else throw("Strict value is not equal to itself.") | |
1128 | 1084 | } | |
1129 | - | } | |
1085 | + | else throw("Strict value is not equal to itself.") | |
1086 | + | } | |
1130 | 1087 | ||
1131 | 1088 | ||
1132 | 1089 | ||
1133 | 1090 | @Callable(i) | |
1134 | - | func putOneTknV2 (minOutAmount,autoStake) = { | |
1091 | + | func putForFree (maxSlippage) = if ((0 > maxSlippage)) | |
1092 | + | then throw("Invalid value passed") | |
1093 | + | else { | |
1094 | + | let estPut = commonPut(i, maxSlippage, false) | |
1095 | + | let state = estPut._9 | |
1096 | + | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1097 | + | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1098 | + | let currentKLp = calcCurrentKLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1099 | + | if ((currentKLp == currentKLp)) | |
1100 | + | then { | |
1101 | + | let $t04555045615 = refreshKLpInternal(0, 0, 0) | |
1102 | + | let refreshKLpActions = $t04555045615._1 | |
1103 | + | let updatedKLp = $t04555045615._2 | |
1104 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1105 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1106 | + | then (state ++ refreshKLpActions) | |
1107 | + | else throw("Strict value is not equal to itself.") | |
1108 | + | } | |
1109 | + | else throw("Strict value is not equal to itself.") | |
1110 | + | } | |
1111 | + | ||
1112 | + | ||
1113 | + | ||
1114 | + | @Callable(i) | |
1115 | + | func putOneTkn (minOutAmount,autoStake) = { | |
1135 | 1116 | let isPoolOneTokenOperationsDisabled = { | |
1136 | - | let @ = invoke( | |
1117 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1137 | 1118 | if ($isInstanceOf(@, "Boolean")) | |
1138 | 1119 | then @ | |
1139 | 1120 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1140 | 1121 | } | |
1141 | - | let isPutDisabled = if (if (if ( | |
1122 | + | let isPutDisabled = if (if (if (isGlobalShutdown()) | |
1142 | 1123 | then true | |
1143 | - | else (cfgPoolStatus == | |
1124 | + | else (cfgPoolStatus == PoolPutDisabled)) | |
1144 | 1125 | then true | |
1145 | 1126 | else (cfgPoolStatus == PoolShutdown)) | |
1146 | 1127 | then true | |
1147 | 1128 | else isPoolOneTokenOperationsDisabled | |
1148 | 1129 | let checks = [if (if (!(isPutDisabled)) | |
1149 | 1130 | then true | |
1150 | 1131 | else isManager(i)) | |
1151 | 1132 | then true | |
1152 | 1133 | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1153 | 1134 | then true | |
1154 | 1135 | else throwErr("exactly 1 payment are expected")] | |
1155 | 1136 | if ((checks == checks)) | |
1156 | 1137 | then { | |
1157 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1158 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1159 | - | let lpId = cfgLpAssetId | |
1160 | - | let amDecimals = cfgAmountAssetDecimals | |
1161 | - | let prDecimals = cfgPriceAssetDecimals | |
1162 | - | let userAddress = if ((i.caller == this)) | |
1163 | - | then i.originCaller | |
1164 | - | else i.caller | |
1165 | - | let pmt = value(i.payments[0]) | |
1166 | - | let pmtAssetId = toBase58String(value(pmt.assetId)) | |
1167 | - | let pmtAmt = pmt.amount | |
1168 | - | let currentDLp = if ((pmt.assetId == cfgAmountAssetId)) | |
1169 | - | then calcCurrentDLp(toBigInt(pmtAmt), toBigInt(0), toBigInt(0)) | |
1170 | - | else calcCurrentDLp(toBigInt(0), toBigInt(pmtAmt), toBigInt(0)) | |
1171 | - | if ((currentDLp == currentDLp)) | |
1138 | + | let payment = i.payments[0] | |
1139 | + | let paymentAssetId = payment.assetId | |
1140 | + | let paymentAmountRaw = payment.amount | |
1141 | + | let currentKLp = if ((paymentAssetId == cfgAmountAssetId)) | |
1142 | + | then calcCurrentKLp(toBigInt(paymentAmountRaw), toBigInt(0), toBigInt(0)) | |
1143 | + | else if ((paymentAssetId == cfgPriceAssetId)) | |
1144 | + | then calcCurrentKLp(toBigInt(0), toBigInt(paymentAmountRaw), toBigInt(0)) | |
1145 | + | else throwErr("payment asset is not supported") | |
1146 | + | if ((currentKLp == currentKLp)) | |
1172 | 1147 | then { | |
1173 | - | let $t04373143889 = calcPutOneTkn(pmtAmt, pmtAssetId, toString(userAddress), toBase58String(i.transactionId), true) | |
1174 | - | if (($t04373143889 == $t04373143889)) | |
1148 | + | let userAddress = i.caller | |
1149 | + | let txId = i.transactionId | |
1150 | + | let $t04680346955 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
1151 | + | if (($t04680346955 == $t04680346955)) | |
1175 | 1152 | then { | |
1176 | - | let feeAmount = $t04373143889._3 | |
1177 | - | let state = $t04373143889._2 | |
1178 | - | let estimLP = $t04373143889._1 | |
1179 | - | let emitLpAmt = if (if ((minOutAmount > 0)) | |
1180 | - | then (minOutAmount > estimLP) | |
1153 | + | let paymentInAmountAsset = $t04680346955._5 | |
1154 | + | let bonus = $t04680346955._4 | |
1155 | + | let feeAmount = $t04680346955._3 | |
1156 | + | let commonState = $t04680346955._2 | |
1157 | + | let emitAmountEstimated = $t04680346955._1 | |
1158 | + | let emitAmount = if (if ((minOutAmount > 0)) | |
1159 | + | then (minOutAmount > emitAmountEstimated) | |
1181 | 1160 | else false) | |
1182 | 1161 | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1183 | - | else | |
1184 | - | let | |
1185 | - | if (( | |
1162 | + | else emitAmountEstimated | |
1163 | + | let emitInv = emit(emitAmount) | |
1164 | + | if ((emitInv == emitInv)) | |
1186 | 1165 | then { | |
1187 | - | let el = match e { | |
1188 | - | case legacy: Address => | |
1189 | - | invoke(legacy, "emit", [emitLpAmt], nil) | |
1190 | - | case _ => | |
1191 | - | unit | |
1192 | - | } | |
1193 | - | if ((el == el)) | |
1166 | + | let lpTransfer = if (autoStake) | |
1194 | 1167 | then { | |
1195 | - | let lpTrnsfr = if (autoStake) | |
1196 | - | then { | |
1197 | - | let ss = invoke(stakingContract, "stakeFor", [toString(i.caller)], [AttachedPayment(lpId, emitLpAmt)]) | |
1198 | - | if ((ss == ss)) | |
1199 | - | then nil | |
1200 | - | else throw("Strict value is not equal to itself.") | |
1201 | - | } | |
1202 | - | else [ScriptTransfer(i.caller, emitLpAmt, lpId)] | |
1203 | - | let sendFeeToMatcher = if ((feeAmount > 0)) | |
1204 | - | then [ScriptTransfer(feeCollectorAddress, feeAmount, fromBase58String(pmtAssetId))] | |
1205 | - | else nil | |
1206 | - | let $t04477445123 = if ((this == feeCollectorAddress)) | |
1207 | - | then $Tuple2(0, 0) | |
1208 | - | else { | |
1209 | - | let paymentInAmountAsset = if ((pmt.assetId == cfgAmountAssetId)) | |
1210 | - | then true | |
1211 | - | else false | |
1212 | - | if (paymentInAmountAsset) | |
1213 | - | then $Tuple2(-(feeAmount), 0) | |
1214 | - | else $Tuple2(0, -(feeAmount)) | |
1215 | - | } | |
1216 | - | let amountAssetBalanceDelta = $t04477445123._1 | |
1217 | - | let priceAssetBalanceDelta = $t04477445123._2 | |
1218 | - | let $t04512645234 = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1219 | - | let refreshDLpActions = $t04512645234._1 | |
1220 | - | let updatedDLp = $t04512645234._2 | |
1221 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1222 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1223 | - | then $Tuple2((((state ++ lpTrnsfr) ++ sendFeeToMatcher) ++ refreshDLpActions), emitLpAmt) | |
1168 | + | let stakeInv = invoke(stakingContract, "stake", nil, [AttachedPayment(cfgLpAssetId, emitAmount)]) | |
1169 | + | if ((stakeInv == stakeInv)) | |
1170 | + | then nil | |
1171 | + | else throw("Strict value is not equal to itself.") | |
1172 | + | } | |
1173 | + | else [ScriptTransfer(i.caller, emitAmount, cfgLpAssetId)] | |
1174 | + | let sendFee = if ((feeAmount > 0)) | |
1175 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, paymentAssetId)] | |
1176 | + | else nil | |
1177 | + | let $t04754147738 = if ((this == feeCollectorAddress)) | |
1178 | + | then $Tuple2(0, 0) | |
1179 | + | else if (paymentInAmountAsset) | |
1180 | + | then $Tuple2(-(feeAmount), 0) | |
1181 | + | else $Tuple2(0, -(feeAmount)) | |
1182 | + | let amountAssetBalanceDelta = $t04754147738._1 | |
1183 | + | let priceAssetBalanceDelta = $t04754147738._2 | |
1184 | + | let $t04774147849 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1185 | + | let refreshKLpActions = $t04774147849._1 | |
1186 | + | let updatedKLp = $t04774147849._2 | |
1187 | + | let kLp = value(getString(keyKLp)) | |
1188 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1189 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1190 | + | then { | |
1191 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1192 | + | if ((reb == reb)) | |
1193 | + | then $Tuple2((((commonState ++ lpTransfer) ++ sendFee) ++ refreshKLpActions), emitAmount) | |
1224 | 1194 | else throw("Strict value is not equal to itself.") | |
1225 | 1195 | } | |
1226 | 1196 | else throw("Strict value is not equal to itself.") | |
1227 | 1197 | } | |
1228 | 1198 | else throw("Strict value is not equal to itself.") | |
1229 | 1199 | } | |
1230 | 1200 | else throw("Strict value is not equal to itself.") | |
1231 | 1201 | } | |
1232 | 1202 | else throw("Strict value is not equal to itself.") | |
1233 | 1203 | } | |
1234 | 1204 | else throw("Strict value is not equal to itself.") | |
1235 | 1205 | } | |
1236 | 1206 | ||
1237 | 1207 | ||
1238 | 1208 | ||
1239 | 1209 | @Callable(i) | |
1240 | - | func putForFree (maxSlpg) = if ((0 > maxSlpg)) | |
1241 | - | then throw("Wrong slpg") | |
1242 | - | else if ((size(i.payments) != 2)) | |
1243 | - | then throw("2 pmnts expd") | |
1244 | - | else { | |
1245 | - | 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, "") | |
1246 | - | let state = estPut._9 | |
1247 | - | let amAssetPmt = toBigInt(value(i.payments[0]).amount) | |
1248 | - | let prAssetPmt = toBigInt(value(i.payments[1]).amount) | |
1249 | - | let currentDLp = calcCurrentDLp(amAssetPmt, prAssetPmt, toBigInt(0)) | |
1250 | - | if ((currentDLp == currentDLp)) | |
1251 | - | then { | |
1252 | - | let $t04626446329 = refreshDLpInternal(0, 0, 0) | |
1253 | - | let refreshDLpActions = $t04626446329._1 | |
1254 | - | let updatedDLp = $t04626446329._2 | |
1255 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1256 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1257 | - | then (state ++ refreshDLpActions) | |
1258 | - | else throw("Strict value is not equal to itself.") | |
1259 | - | } | |
1260 | - | else throw("Strict value is not equal to itself.") | |
1261 | - | } | |
1262 | - | ||
1263 | - | ||
1264 | - | ||
1265 | - | @Callable(i) | |
1266 | - | func get () = { | |
1267 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1268 | - | if ((currentDLp == currentDLp)) | |
1269 | - | then { | |
1270 | - | let r = cg(i) | |
1271 | - | let outAmtAmt = r._1 | |
1272 | - | let outPrAmt = r._2 | |
1273 | - | let pmtAmt = r._3 | |
1274 | - | let pmtAssetId = r._4 | |
1275 | - | let state = r._5 | |
1276 | - | let b = invoke(fca, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1277 | - | if ((b == b)) | |
1278 | - | then { | |
1279 | - | let $t04750247584 = refreshDLpInternal(-(outAmtAmt), -(outPrAmt), 0) | |
1280 | - | let refreshDLpActions = $t04750247584._1 | |
1281 | - | let updatedDLp = $t04750247584._2 | |
1282 | - | let isUpdatedDLpValid = validateUpdatedDLp(currentDLp, updatedDLp) | |
1283 | - | if ((isUpdatedDLpValid == isUpdatedDLpValid)) | |
1284 | - | then (state ++ refreshDLpActions) | |
1285 | - | else throw("Strict value is not equal to itself.") | |
1286 | - | } | |
1287 | - | else throw("Strict value is not equal to itself.") | |
1288 | - | } | |
1289 | - | else throw("Strict value is not equal to itself.") | |
1210 | + | func putOneTknREADONLY (paymentAssetId,paymentAmountRaw) = { | |
1211 | + | let $t04820448361 = calcPutOneToken(paymentAmountRaw, parseAssetId(paymentAssetId), unit, unit) | |
1212 | + | let emitAmountEstimated = $t04820448361._1 | |
1213 | + | let commonState = $t04820448361._2 | |
1214 | + | let feeAmount = $t04820448361._3 | |
1215 | + | let bonus = $t04820448361._4 | |
1216 | + | let paymentInAmountAsset = $t04820448361._5 | |
1217 | + | $Tuple2(nil, $Tuple3(emitAmountEstimated, feeAmount, bonus)) | |
1290 | 1218 | } | |
1291 | 1219 | ||
1292 | 1220 | ||
1293 | 1221 | ||
1294 | 1222 | @Callable(i) | |
1295 | - | func | |
1223 | + | func getOneTkn (outAssetIdStr,minOutAmount) = { | |
1296 | 1224 | let isPoolOneTokenOperationsDisabled = { | |
1297 | - | let @ = invoke( | |
1225 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1298 | 1226 | if ($isInstanceOf(@, "Boolean")) | |
1299 | 1227 | then @ | |
1300 | 1228 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1301 | 1229 | } | |
1302 | - | let isGetDisabled = if (if ( | |
1230 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1303 | 1231 | then true | |
1304 | 1232 | else (cfgPoolStatus == PoolShutdown)) | |
1305 | 1233 | then true | |
1306 | 1234 | else isPoolOneTokenOperationsDisabled | |
1307 | 1235 | let checks = [if (if (!(isGetDisabled)) | |
1308 | 1236 | then true | |
1309 | 1237 | else isManager(i)) | |
1310 | 1238 | then true | |
1311 | 1239 | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1312 | 1240 | then true | |
1313 | 1241 | else throwErr("exactly 1 payment are expected")] | |
1314 | 1242 | if ((checks == checks)) | |
1315 | 1243 | then { | |
1316 | - | let $t04820248357 = getOneTknV2Internal(outAssetId, minOutAmount, i.payments, i.caller, i.originCaller, i.transactionId) | |
1317 | - | let state = $t04820248357._1 | |
1318 | - | let totalAmount = $t04820248357._2 | |
1319 | - | $Tuple2(state, totalAmount) | |
1244 | + | let outAssetId = parseAssetId(outAssetIdStr) | |
1245 | + | let payment = i.payments[0] | |
1246 | + | let paymentAssetId = payment.assetId | |
1247 | + | let paymentAmount = payment.amount | |
1248 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1249 | + | if ((currentKLp == currentKLp)) | |
1250 | + | then { | |
1251 | + | let userAddress = i.caller | |
1252 | + | let txId = i.transactionId | |
1253 | + | let $t04924649399 = calcGetOneToken(outAssetId, paymentAmount, paymentAssetId, userAddress, txId) | |
1254 | + | if (($t04924649399 == $t04924649399)) | |
1255 | + | then { | |
1256 | + | let outInAmountAsset = $t04924649399._5 | |
1257 | + | let bonus = $t04924649399._4 | |
1258 | + | let feeAmount = $t04924649399._3 | |
1259 | + | let commonState = $t04924649399._2 | |
1260 | + | let amountEstimated = $t04924649399._1 | |
1261 | + | let amount = if (if ((minOutAmount > 0)) | |
1262 | + | then (minOutAmount > amountEstimated) | |
1263 | + | else false) | |
1264 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1265 | + | else amountEstimated | |
1266 | + | let burnInv = invoke(factoryContract, "burn", [paymentAmount], [AttachedPayment(paymentAssetId, paymentAmount)]) | |
1267 | + | if ((burnInv == burnInv)) | |
1268 | + | then { | |
1269 | + | let withdrawState = withdrawAndRebalanceAsset(outAssetIdStr, (amount + max([0, feeAmount]))) | |
1270 | + | let assetTransfer = [ScriptTransfer(userAddress, amount, outAssetId)] | |
1271 | + | let sendFee = if ((feeAmount > 0)) | |
1272 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1273 | + | else nil | |
1274 | + | let $t05006350310 = { | |
1275 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1276 | + | then 0 | |
1277 | + | else feeAmount | |
1278 | + | if (outInAmountAsset) | |
1279 | + | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1280 | + | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1281 | + | } | |
1282 | + | let amountAssetBalanceDelta = $t05006350310._1 | |
1283 | + | let priceAssetBalanceDelta = $t05006350310._2 | |
1284 | + | let $t05031350421 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1285 | + | let refreshKLpActions = $t05031350421._1 | |
1286 | + | let updatedKLp = $t05031350421._2 | |
1287 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1288 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1289 | + | then $Tuple2(((((commonState ++ withdrawState) ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1290 | + | else throw("Strict value is not equal to itself.") | |
1291 | + | } | |
1292 | + | else throw("Strict value is not equal to itself.") | |
1293 | + | } | |
1294 | + | else throw("Strict value is not equal to itself.") | |
1295 | + | } | |
1296 | + | else throw("Strict value is not equal to itself.") | |
1320 | 1297 | } | |
1321 | 1298 | else throw("Strict value is not equal to itself.") | |
1322 | 1299 | } | |
1323 | 1300 | ||
1324 | 1301 | ||
1325 | 1302 | ||
1326 | 1303 | @Callable(i) | |
1327 | - | func refreshDLp () = { | |
1328 | - | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyDLpRefreshedHeight), 0) | |
1329 | - | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= dLpRefreshDelay)) | |
1330 | - | then unit | |
1331 | - | else throwErr(makeString([toString(dLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1332 | - | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1304 | + | func getOneTknREADONLY (outAssetId,paymentAmount) = { | |
1305 | + | let $t05069950855 = calcGetOneToken(parseAssetId(outAssetId), paymentAmount, cfgLpAssetId, unit, unit) | |
1306 | + | let amountEstimated = $t05069950855._1 | |
1307 | + | let commonState = $t05069950855._2 | |
1308 | + | let feeAmount = $t05069950855._3 | |
1309 | + | let bonus = $t05069950855._4 | |
1310 | + | let outInAmountAsset = $t05069950855._5 | |
1311 | + | $Tuple2(nil, $Tuple3(amountEstimated, feeAmount, bonus)) | |
1312 | + | } | |
1313 | + | ||
1314 | + | ||
1315 | + | ||
1316 | + | @Callable(i) | |
1317 | + | func unstakeAndGetOneTkn (unstakeAmount,outAssetIdStr,minOutAmount) = { | |
1318 | + | let isPoolOneTokenOperationsDisabled = { | |
1319 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1320 | + | if ($isInstanceOf(@, "Boolean")) | |
1321 | + | then @ | |
1322 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1323 | + | } | |
1324 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1325 | + | then true | |
1326 | + | else (cfgPoolStatus == PoolShutdown)) | |
1327 | + | then true | |
1328 | + | else isPoolOneTokenOperationsDisabled | |
1329 | + | let checks = [if (if (!(isGetDisabled)) | |
1330 | + | then true | |
1331 | + | else isManager(i)) | |
1332 | + | then true | |
1333 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1334 | + | then true | |
1335 | + | else throwErr("no payments are expected")] | |
1336 | + | if ((checks == checks)) | |
1333 | 1337 | then { | |
1334 | - | let dLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyDLp), "0")), fmtErr("invalid dLp")) | |
1335 | - | let $t04888148945 = refreshDLpInternal(0, 0, 0) | |
1336 | - | let dLpUpdateActions = $t04888148945._1 | |
1337 | - | let updatedDLp = $t04888148945._2 | |
1338 | - | let actions = if ((dLp != updatedDLp)) | |
1339 | - | then dLpUpdateActions | |
1340 | - | else throwErr("nothing to refresh") | |
1341 | - | $Tuple2(actions, toString(updatedDLp)) | |
1338 | + | let outAssetId = parseAssetId(outAssetIdStr) | |
1339 | + | let userAddress = i.caller | |
1340 | + | let txId = i.transactionId | |
1341 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1342 | + | if ((currentKLp == currentKLp)) | |
1343 | + | then { | |
1344 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1345 | + | if ((unstakeInv == unstakeInv)) | |
1346 | + | then { | |
1347 | + | let $t05176051911 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
1348 | + | if (($t05176051911 == $t05176051911)) | |
1349 | + | then { | |
1350 | + | let outInAmountAsset = $t05176051911._5 | |
1351 | + | let bonus = $t05176051911._4 | |
1352 | + | let feeAmount = $t05176051911._3 | |
1353 | + | let commonState = $t05176051911._2 | |
1354 | + | let amountEstimated = $t05176051911._1 | |
1355 | + | let amount = if (if ((minOutAmount > 0)) | |
1356 | + | then (minOutAmount > amountEstimated) | |
1357 | + | else false) | |
1358 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1359 | + | else amountEstimated | |
1360 | + | let burnInv = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1361 | + | if ((burnInv == burnInv)) | |
1362 | + | then { | |
1363 | + | let withdrawState = withdrawAndRebalanceAsset(outAssetIdStr, (amount + max([0, feeAmount]))) | |
1364 | + | let assetTransfer = [ScriptTransfer(i.caller, amount, outAssetId)] | |
1365 | + | let sendFee = if ((feeAmount > 0)) | |
1366 | + | then [ScriptTransfer(feeCollectorAddress, feeAmount, outAssetId)] | |
1367 | + | else nil | |
1368 | + | let $t05257052817 = { | |
1369 | + | let feeAmountForCalc = if ((this == feeCollectorAddress)) | |
1370 | + | then 0 | |
1371 | + | else feeAmount | |
1372 | + | if (outInAmountAsset) | |
1373 | + | then $Tuple2(-((amount + feeAmountForCalc)), 0) | |
1374 | + | else $Tuple2(0, -((amount + feeAmountForCalc))) | |
1375 | + | } | |
1376 | + | let amountAssetBalanceDelta = $t05257052817._1 | |
1377 | + | let priceAssetBalanceDelta = $t05257052817._2 | |
1378 | + | let $t05282052928 = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0) | |
1379 | + | let refreshKLpActions = $t05282052928._1 | |
1380 | + | let updatedKLp = $t05282052928._2 | |
1381 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1382 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1383 | + | then $Tuple2(((((commonState ++ withdrawState) ++ assetTransfer) ++ sendFee) ++ refreshKLpActions), amount) | |
1384 | + | else throw("Strict value is not equal to itself.") | |
1385 | + | } | |
1386 | + | else throw("Strict value is not equal to itself.") | |
1387 | + | } | |
1388 | + | else throw("Strict value is not equal to itself.") | |
1389 | + | } | |
1390 | + | else throw("Strict value is not equal to itself.") | |
1391 | + | } | |
1392 | + | else throw("Strict value is not equal to itself.") | |
1342 | 1393 | } | |
1343 | 1394 | else throw("Strict value is not equal to itself.") | |
1344 | 1395 | } | |
1345 | 1396 | ||
1346 | 1397 | ||
1347 | 1398 | ||
1348 | 1399 | @Callable(i) | |
1349 | - | func getOneTknV2READONLY (outAssetId,lpAssetAmount) = { | |
1350 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1351 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1352 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1353 | - | let xp = [toBigInt(getAccBalance(amId)), toBigInt(getAccBalance(prId))] | |
1354 | - | let lpEmission = toBigInt(valueOrErrorMessage(assetInfo(fromBase58String(lpId)), "invalid lp asset").quantity) | |
1355 | - | let D0 = getD(xp) | |
1356 | - | let D1 = (D0 - fraction(toBigInt(lpAssetAmount), D0, lpEmission)) | |
1357 | - | let index = if ((outAssetId == amId)) | |
1358 | - | then 0 | |
1359 | - | else if ((outAssetId == prId)) | |
1360 | - | then 1 | |
1361 | - | else throw("invalid out asset id") | |
1362 | - | let newY = getYD(xp, index, D1) | |
1363 | - | let dy = (xp[index] - newY) | |
1364 | - | let totalGetRaw = max([0, toInt((dy - big1))]) | |
1365 | - | let $t04995550010 = takeFee(totalGetRaw, outFee) | |
1366 | - | let totalGet = $t04995550010._1 | |
1367 | - | let feeAmount = $t04995550010._2 | |
1368 | - | $Tuple2(nil, $Tuple2(totalGet, feeAmount)) | |
1369 | - | } | |
1370 | - | ||
1371 | - | ||
1372 | - | ||
1373 | - | @Callable(i) | |
1374 | - | func getOneTknV2WithBonusREADONLY (outAssetId,lpAssetAmount) = { | |
1375 | - | let amId = toBase58String(value(cfgAmountAssetId)) | |
1376 | - | let prId = toBase58String(value(cfgPriceAssetId)) | |
1377 | - | let lpId = toBase58String(value(cfgLpAssetId)) | |
1378 | - | let amBalance = getAccBalance(amId) | |
1379 | - | let prBalance = getAccBalance(prId) | |
1380 | - | let $t05038550500 = { | |
1381 | - | let @ = invoke(this, "getOneTknV2READONLY", [outAssetId, lpAssetAmount], nil) | |
1382 | - | if ($isInstanceOf(@, "(Int, Int)")) | |
1383 | - | then @ | |
1384 | - | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) | |
1385 | - | } | |
1386 | - | let totalGet = $t05038550500._1 | |
1387 | - | let feeAmount = $t05038550500._2 | |
1388 | - | let r = ego("", lpId, lpAssetAmount, this) | |
1389 | - | let outAmAmt = r._1 | |
1390 | - | let outPrAmt = r._2 | |
1391 | - | let sumOfGetAssets = (outAmAmt + outPrAmt) | |
1392 | - | let bonus = if ((sumOfGetAssets == 0)) | |
1393 | - | then if ((totalGet == 0)) | |
1394 | - | then 0 | |
1395 | - | else throw("bonus calculation error") | |
1396 | - | else fraction((totalGet - sumOfGetAssets), scale8, sumOfGetAssets) | |
1397 | - | $Tuple2(nil, $Tuple3(totalGet, feeAmount, bonus)) | |
1400 | + | func get () = { | |
1401 | + | let res = commonGet(i) | |
1402 | + | let outAmAmt = res._1 | |
1403 | + | let outPrAmt = res._2 | |
1404 | + | let pmtAmt = res._3 | |
1405 | + | let pmtAssetId = res._4 | |
1406 | + | let state = res._5 | |
1407 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1408 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1409 | + | if ((currentKLp == currentKLp)) | |
1410 | + | then { | |
1411 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1412 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1413 | + | then { | |
1414 | + | let $t05402354104 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1415 | + | let refreshKLpActions = $t05402354104._1 | |
1416 | + | let updatedKLp = $t05402354104._2 | |
1417 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1418 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1419 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1420 | + | else throw("Strict value is not equal to itself.") | |
1421 | + | } | |
1422 | + | else throw("Strict value is not equal to itself.") | |
1423 | + | } | |
1424 | + | else throw("Strict value is not equal to itself.") | |
1398 | 1425 | } | |
1399 | 1426 | ||
1400 | 1427 | ||
1401 | 1428 | ||
1402 | 1429 | @Callable(i) | |
1403 | 1430 | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
1404 | - | let | |
1405 | - | let outAmAmt = | |
1406 | - | let outPrAmt = | |
1407 | - | let pmtAmt = | |
1408 | - | let pmtAssetId = | |
1409 | - | let state = | |
1431 | + | let res = commonGet(i) | |
1432 | + | let outAmAmt = res._1 | |
1433 | + | let outPrAmt = res._2 | |
1434 | + | let pmtAmt = res._3 | |
1435 | + | let pmtAssetId = res._4 | |
1436 | + | let state = res._5 | |
1410 | 1437 | if ((noLessThenAmtAsset > outAmAmt)) | |
1411 | - | then throw((((" | |
1438 | + | then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1412 | 1439 | else if ((noLessThenPriceAsset > outPrAmt)) | |
1413 | - | then throw((((" | |
1440 | + | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1414 | 1441 | else { | |
1415 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1416 | - | if ((currentDLp == currentDLp)) | |
1442 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1443 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1444 | + | if ((currentKLp == currentKLp)) | |
1417 | 1445 | then { | |
1418 | - | let burnLPAssetOnFactory = invoke( | |
1446 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1419 | 1447 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1420 | 1448 | then { | |
1421 | - | let $ | |
1422 | - | let | |
1423 | - | let | |
1424 | - | let | |
1425 | - | if (( | |
1426 | - | then ( | |
1449 | + | let $t05519955280 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1450 | + | let refreshKLpActions = $t05519955280._1 | |
1451 | + | let updatedKLp = $t05519955280._2 | |
1452 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1453 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1454 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1427 | 1455 | else throw("Strict value is not equal to itself.") | |
1428 | 1456 | } | |
1429 | 1457 | else throw("Strict value is not equal to itself.") | |
1430 | 1458 | } | |
1431 | 1459 | else throw("Strict value is not equal to itself.") | |
1432 | 1460 | } | |
1433 | 1461 | } | |
1434 | 1462 | ||
1435 | 1463 | ||
1436 | 1464 | ||
1437 | 1465 | @Callable(i) | |
1438 | 1466 | func unstakeAndGet (amount) = { | |
1439 | 1467 | let checkPayments = if ((size(i.payments) != 0)) | |
1440 | - | then throw("No | |
1468 | + | then throw("No payments are expected") | |
1441 | 1469 | else true | |
1442 | 1470 | if ((checkPayments == checkPayments)) | |
1443 | 1471 | then { | |
1444 | - | let factoryCfg = gfc() | |
1445 | - | let lpAssetId = cfgLpAssetId | |
1446 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1447 | - | let currentDLp = calcCurrentDLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1448 | - | if ((currentDLp == currentDLp)) | |
1472 | + | let cfg = getPoolConfig() | |
1473 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1474 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1475 | + | if ((currentKLp == currentKLp)) | |
1449 | 1476 | then { | |
1450 | - | let unstakeInv = invoke( | |
1477 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1451 | 1478 | if ((unstakeInv == unstakeInv)) | |
1452 | 1479 | then { | |
1453 | - | let r = ego(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1454 | - | let outAmAmt = r._1 | |
1455 | - | let outPrAmt = r._2 | |
1456 | - | let sts = parseIntValue(r._9) | |
1457 | - | let state = r._10 | |
1458 | - | let v = if (if (igs()) | |
1480 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(lpAssetId), amount, i.caller) | |
1481 | + | let outAmAmt = res._1 | |
1482 | + | let outPrAmt = res._2 | |
1483 | + | let poolStatus = parseIntValue(res._9) | |
1484 | + | let state = res._10 | |
1485 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1486 | + | let checkPoolStatus = if (if (isGlobalShutdown()) | |
1459 | 1487 | then true | |
1460 | - | else ( | |
1461 | - | then throw((" | |
1488 | + | else (poolStatus == PoolShutdown)) | |
1489 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
1462 | 1490 | else true | |
1463 | - | if (( | |
1491 | + | if ((checkPoolStatus == checkPoolStatus)) | |
1464 | 1492 | then { | |
1465 | - | let | |
1466 | - | if (( | |
1493 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1494 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1467 | 1495 | then { | |
1468 | - | let $ | |
1469 | - | let | |
1470 | - | let | |
1471 | - | let | |
1472 | - | if (( | |
1473 | - | then ( | |
1496 | + | let $t05655256633 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1497 | + | let refreshKLpActions = $t05655256633._1 | |
1498 | + | let updatedKLp = $t05655256633._2 | |
1499 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1500 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1501 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1474 | 1502 | else throw("Strict value is not equal to itself.") | |
1475 | 1503 | } | |
1476 | 1504 | else throw("Strict value is not equal to itself.") | |
1477 | 1505 | } | |
1478 | 1506 | else throw("Strict value is not equal to itself.") | |
1479 | 1507 | } | |
1480 | 1508 | else throw("Strict value is not equal to itself.") | |
1481 | 1509 | } | |
1482 | 1510 | else throw("Strict value is not equal to itself.") | |
1483 | 1511 | } | |
1484 | 1512 | else throw("Strict value is not equal to itself.") | |
1485 | 1513 | } | |
1486 | 1514 | ||
1487 | 1515 | ||
1488 | 1516 | ||
1489 | 1517 | @Callable(i) | |
1490 | 1518 | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1491 | - | let isGetDisabled = if ( | |
1519 | + | let isGetDisabled = if (isGlobalShutdown()) | |
1492 | 1520 | then true | |
1493 | 1521 | else (cfgPoolStatus == PoolShutdown) | |
1494 | 1522 | let checks = [if (!(isGetDisabled)) | |
1495 | 1523 | then true | |
1496 | 1524 | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1497 | 1525 | then true | |
1498 | 1526 | else throw("no payments are expected")] | |
1499 | 1527 | if ((checks == checks)) | |
1500 | 1528 | then { | |
1501 | - | let | |
1502 | - | if (( | |
1529 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1530 | + | if ((currentKLp == currentKLp)) | |
1503 | 1531 | then { | |
1504 | 1532 | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1505 | 1533 | if ((unstakeInv == unstakeInv)) | |
1506 | 1534 | then { | |
1507 | - | let res = | |
1535 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1508 | 1536 | let outAmAmt = res._1 | |
1509 | 1537 | let outPrAmt = res._2 | |
1510 | 1538 | let state = res._10 | |
1539 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1511 | 1540 | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1512 | 1541 | then true | |
1513 | 1542 | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1514 | 1543 | then true | |
1515 | 1544 | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1516 | 1545 | if ((checkAmounts == checkAmounts)) | |
1517 | 1546 | then { | |
1518 | - | let burnLPAssetOnFactory = invoke( | |
1547 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1519 | 1548 | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1520 | 1549 | then { | |
1521 | - | let $ | |
1522 | - | let | |
1523 | - | let | |
1524 | - | let | |
1525 | - | if (( | |
1526 | - | then ( | |
1550 | + | let $t05807458155 = refreshKLpInternal(-(outAmAmt), -(outPrAmt), 0) | |
1551 | + | let refreshKLpActions = $t05807458155._1 | |
1552 | + | let updatedKLp = $t05807458155._2 | |
1553 | + | let isUpdatedKLpValid = validateUpdatedKLp(currentKLp, updatedKLp) | |
1554 | + | if ((isUpdatedKLpValid == isUpdatedKLpValid)) | |
1555 | + | then ((withdrawState ++ state) ++ refreshKLpActions) | |
1527 | 1556 | else throw("Strict value is not equal to itself.") | |
1528 | 1557 | } | |
1529 | 1558 | else throw("Strict value is not equal to itself.") | |
1530 | 1559 | } | |
1531 | 1560 | else throw("Strict value is not equal to itself.") | |
1532 | 1561 | } | |
1533 | 1562 | else throw("Strict value is not equal to itself.") | |
1534 | 1563 | } | |
1535 | 1564 | else throw("Strict value is not equal to itself.") | |
1536 | 1565 | } | |
1537 | 1566 | else throw("Strict value is not equal to itself.") | |
1538 | 1567 | } | |
1539 | 1568 | ||
1540 | 1569 | ||
1541 | 1570 | ||
1542 | 1571 | @Callable(i) | |
1543 | - | func unstakeAndGetOneTknV2 (unstakeAmount,outAssetId,minOutAmount) = { | |
1544 | - | let isPoolOneTokenOperationsDisabled = { | |
1545 | - | let @ = invoke(fca, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1546 | - | if ($isInstanceOf(@, "Boolean")) | |
1547 | - | then @ | |
1548 | - | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1549 | - | } | |
1550 | - | let isGetDisabled = if (if (igs()) | |
1551 | - | then true | |
1552 | - | else (cfgPoolStatus == PoolShutdown)) | |
1553 | - | then true | |
1554 | - | else isPoolOneTokenOperationsDisabled | |
1555 | - | let checks = [if (if (!(isGetDisabled)) | |
1556 | - | then true | |
1557 | - | else isManager(i)) | |
1558 | - | then true | |
1559 | - | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1560 | - | then true | |
1561 | - | else throwErr("no payments are expected")] | |
1562 | - | if ((checks == checks)) | |
1572 | + | func activate (amtAssetStr,priceAssetStr) = if ((toString(i.caller) != toString(factoryContract))) | |
1573 | + | then throw("permissions denied") | |
1574 | + | else $Tuple2([StringEntry(aa(), amtAssetStr), StringEntry(pa(), priceAssetStr)], "success") | |
1575 | + | ||
1576 | + | ||
1577 | + | ||
1578 | + | @Callable(i) | |
1579 | + | func refreshKLp () = { | |
1580 | + | let lastRefreshedBlockHeight = valueOrElse(getInteger(keyKLpRefreshedHeight), 0) | |
1581 | + | let checkLastRefreshedBlockHeight = if (((height - lastRefreshedBlockHeight) >= kLpRefreshDelay)) | |
1582 | + | then unit | |
1583 | + | else throwErr(makeString([toString(kLpRefreshDelay), " blocks have not passed since the previous call"], "")) | |
1584 | + | if ((checkLastRefreshedBlockHeight == checkLastRefreshedBlockHeight)) | |
1563 | 1585 | then { | |
1564 | - | let factoryCfg = gfc() | |
1565 | - | let lpAssetId = cfgLpAssetId | |
1566 | - | let staking = valueOrErrorMessage(addressFromString(factoryCfg[idxFactStakCntr]), "Wr st addr") | |
1567 | - | let userAddress = i.caller | |
1568 | - | let lpAssetRecipientAddress = this | |
1569 | - | let unstakeInv = invoke(staking, "unstakeINTERNAL", [lpAssetId, unstakeAmount, userAddress.bytes, lpAssetRecipientAddress.bytes], nil) | |
1570 | - | if ((unstakeInv == unstakeInv)) | |
1571 | - | then { | |
1572 | - | let $t05520955397 = getOneTknV2Internal(outAssetId, minOutAmount, [AttachedPayment(lpAssetId, unstakeAmount)], i.caller, i.originCaller, i.transactionId) | |
1573 | - | let state = $t05520955397._1 | |
1574 | - | let totalAmount = $t05520955397._2 | |
1575 | - | $Tuple2(state, totalAmount) | |
1576 | - | } | |
1577 | - | else throw("Strict value is not equal to itself.") | |
1586 | + | let kLp = valueOrErrorMessage(parseBigInt(valueOrElse(getString(this, keyKLp), "0")), fmtErr("invalid kLp")) | |
1587 | + | let $t05935959423 = refreshKLpInternal(0, 0, 0) | |
1588 | + | let kLpUpdateActions = $t05935959423._1 | |
1589 | + | let updatedKLp = $t05935959423._2 | |
1590 | + | let actions = if ((kLp != updatedKLp)) | |
1591 | + | then kLpUpdateActions | |
1592 | + | else throwErr("nothing to refresh") | |
1593 | + | $Tuple2(actions, toString(updatedKLp)) | |
1578 | 1594 | } | |
1579 | 1595 | else throw("Strict value is not equal to itself.") | |
1580 | 1596 | } | |
1581 | 1597 | ||
1582 | 1598 | ||
1583 | 1599 | ||
1584 | 1600 | @Callable(i) | |
1585 | - | func putOneTknV2WithBonusREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1586 | - | let $t05552555628 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", true) | |
1587 | - | let lpAmount = $t05552555628._1 | |
1588 | - | let state = $t05552555628._2 | |
1589 | - | let feeAmount = $t05552555628._3 | |
1590 | - | let bonus = $t05552555628._4 | |
1591 | - | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1592 | - | } | |
1593 | - | ||
1594 | - | ||
1595 | - | ||
1596 | - | @Callable(i) | |
1597 | - | func putOneTknV2WithoutTakeFeeREADONLY (paymentAmountRaw,paymentAssetId) = { | |
1598 | - | let $t05577655880 = calcPutOneTkn(paymentAmountRaw, paymentAssetId, "", "", false) | |
1599 | - | let lpAmount = $t05577655880._1 | |
1600 | - | let state = $t05577655880._2 | |
1601 | - | let feeAmount = $t05577655880._3 | |
1602 | - | let bonus = $t05577655880._4 | |
1603 | - | $Tuple2(nil, $Tuple3(lpAmount, feeAmount, bonus)) | |
1604 | - | } | |
1605 | - | ||
1606 | - | ||
1607 | - | ||
1608 | - | @Callable(i) | |
1609 | - | func activate (amtAsStr,prAsStr) = if ((toString(i.caller) != toString(fca))) | |
1610 | - | then throw("denied") | |
1611 | - | else $Tuple2([StringEntry(aa(), amtAsStr), StringEntry(pa(), prAsStr), StringEntry(amp(), toString(ampInitial))], "success") | |
1612 | - | ||
1613 | - | ||
1614 | - | ||
1615 | - | @Callable(i) | |
1616 | - | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, gpc()) | |
1601 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1617 | 1602 | ||
1618 | 1603 | ||
1619 | 1604 | ||
1620 | 1605 | @Callable(i) | |
1621 | 1606 | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1622 | 1607 | ||
1623 | 1608 | ||
1624 | 1609 | ||
1625 | 1610 | @Callable(i) | |
1626 | 1611 | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1627 | - | let | |
1628 | - | $Tuple2(nil, [toString( | |
1612 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
1613 | + | $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])]) | |
1629 | 1614 | } | |
1630 | 1615 | ||
1631 | 1616 | ||
1632 | 1617 | ||
1633 | 1618 | @Callable(i) | |
1634 | - | func | |
1619 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
1635 | 1620 | ||
1636 | 1621 | ||
1637 | 1622 | ||
1638 | 1623 | @Callable(i) | |
1639 | - | func | |
1624 | + | func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult)) | |
1640 | 1625 | ||
1641 | 1626 | ||
1642 | 1627 | ||
1643 | 1628 | @Callable(i) | |
1644 | - | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString( | |
1629 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1645 | 1630 | ||
1646 | 1631 | ||
1647 | 1632 | ||
1648 | 1633 | @Callable(i) | |
1649 | - | func estimatePutOperationWrapperREADONLY (txId58, | |
1634 | + | func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp)) | |
1650 | 1635 | ||
1651 | 1636 | ||
1652 | 1637 | ||
1653 | 1638 | @Callable(i) | |
1654 | - | func estimateGetOperationWrapperREADONLY (txId58, | |
1655 | - | let | |
1656 | - | $Tuple2(nil, $Tuple10( | |
1639 | + | func estimateGetOperationWrapperREADONLY (txId58,pmtAssetId,pmtLpAmt,userAddress) = { | |
1640 | + | let res = estimateGetOperation(txId58, pmtAssetId, pmtLpAmt, addressFromStringValue(userAddress)) | |
1641 | + | $Tuple2(nil, $Tuple10(res._1, res._2, res._3, res._4, res._5, res._6, res._7, toString(res._8), res._9, res._10)) | |
1657 | 1642 | } | |
1658 | 1643 | ||
1659 | 1644 | ||
1660 | 1645 | ||
1661 | 1646 | @Callable(i) | |
1662 | - | func changeAmp () = { | |
1663 | - | let cfg = invoke(fca, "getChangeAmpConfigREADONLY", [toString(this)], nil) | |
1664 | - | let $t05828958488 = match cfg { | |
1665 | - | case list: List[Any] => | |
1666 | - | $Tuple3({ | |
1667 | - | let @ = list[0] | |
1668 | - | if ($isInstanceOf(@, "Int")) | |
1669 | - | then @ | |
1670 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1671 | - | }, { | |
1672 | - | let @ = list[1] | |
1673 | - | if ($isInstanceOf(@, "Int")) | |
1674 | - | then @ | |
1675 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1676 | - | }, { | |
1677 | - | let @ = list[2] | |
1678 | - | if ($isInstanceOf(@, "Int")) | |
1679 | - | then @ | |
1680 | - | else throw(($getType(@) + " couldn't be cast to Int")) | |
1681 | - | }) | |
1682 | - | case _ => | |
1683 | - | throwErr("invalid entry type") | |
1647 | + | func statsREADONLY () = { | |
1648 | + | let cfg = getPoolConfig() | |
1649 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1650 | + | let amtAssetId = cfg[idxAmtAssetId] | |
1651 | + | let priceAssetId = cfg[idxPriceAssetId] | |
1652 | + | let iAmtAssetId = cfg[idxIAmtAssetId] | |
1653 | + | let iPriceAssetId = cfg[idxIPriceAssetId] | |
1654 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1655 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1656 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1657 | + | let accAmtAssetBalance = getAccBalance(amtAssetId) | |
1658 | + | let accPriceAssetBalance = getAccBalance(priceAssetId) | |
1659 | + | let pricesList = if ((poolLPBalance == 0)) | |
1660 | + | then [zeroBigInt, zeroBigInt, zeroBigInt] | |
1661 | + | else calcPrices(accAmtAssetBalance, accPriceAssetBalance, poolLPBalance) | |
1662 | + | let curPrice = 0 | |
1663 | + | let lpAmtAssetShare = fromX18(pricesList[1], scale8) | |
1664 | + | let lpPriceAssetShare = fromX18(pricesList[2], scale8) | |
1665 | + | let poolWeight = value(getInteger(factoryContract, keyPoolWeight(toString(this)))) | |
1666 | + | $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)) | |
1684 | 1667 | } | |
1685 | - | let delay = $t05828958488._1 | |
1686 | - | let delta = $t05828958488._2 | |
1687 | - | let target = $t05828958488._3 | |
1688 | - | let curAmp = parseIntValue(getStringValue(amp())) | |
1689 | - | let newAmpRaw = (curAmp + delta) | |
1690 | - | let newAmp = if ((0 > delta)) | |
1691 | - | then if ((target > newAmpRaw)) | |
1692 | - | then target | |
1693 | - | else newAmpRaw | |
1694 | - | else if ((newAmpRaw > target)) | |
1695 | - | then target | |
1696 | - | else newAmpRaw | |
1697 | - | let lastCall = valueOrElse(getInteger(keyChangeAmpLastCall()), 0) | |
1698 | - | let wait = (lastCall + delay) | |
1699 | - | let checks = [if ((height > wait)) | |
1700 | - | then true | |
1701 | - | else throwErr("try again in few blocks"), if ((curAmp != newAmp)) | |
1702 | - | then true | |
1703 | - | else throwErr("already reached target")] | |
1704 | - | if ((checks == checks)) | |
1705 | - | then [IntegerEntry(keyChangeAmpLastCall(), height), StringEntry(amp(), toString(newAmp)), StringEntry(keyAmpHistory(height), toString(newAmp))] | |
1706 | - | else throw("Strict value is not equal to itself.") | |
1668 | + | ||
1669 | + | ||
1670 | + | ||
1671 | + | @Callable(i) | |
1672 | + | func evaluatePutByAmountAssetREADONLY (inAmAssetAmt) = { | |
1673 | + | let cfg = getPoolConfig() | |
1674 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1675 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
1676 | + | let amAssetId = fromBase58String(amAssetIdStr) | |
1677 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
1678 | + | let prAssetId = fromBase58String(prAssetIdStr) | |
1679 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1680 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1681 | + | let poolStatus = cfg[idxPoolStatus] | |
1682 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1683 | + | let accAmtAssetBalance = getAccBalance(amAssetIdStr) | |
1684 | + | let accPriceAssetBalance = getAccBalance(prAssetIdStr) | |
1685 | + | let amtAssetAmtX18 = toX18(accAmtAssetBalance, amtAssetDcm) | |
1686 | + | let priceAssetAmtX18 = toX18(accPriceAssetBalance, priceAssetDcm) | |
1687 | + | let curPriceX18 = if ((poolLPBalance == 0)) | |
1688 | + | then zeroBigInt | |
1689 | + | else calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
1690 | + | let inAmAssetAmtX18 = toX18(inAmAssetAmt, amtAssetDcm) | |
1691 | + | let inPrAssetAmtX18 = fraction(inAmAssetAmtX18, curPriceX18, scale18) | |
1692 | + | let inPrAssetAmt = fromX18(inPrAssetAmtX18, priceAssetDcm) | |
1693 | + | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1694 | + | let calcLpAmt = estPut._1 | |
1695 | + | let curPriceCalc = estPut._3 | |
1696 | + | let amBalance = estPut._4 | |
1697 | + | let prBalance = estPut._5 | |
1698 | + | let lpEmission = estPut._6 | |
1699 | + | $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)) | |
1700 | + | } | |
1701 | + | ||
1702 | + | ||
1703 | + | ||
1704 | + | @Callable(i) | |
1705 | + | func evaluatePutByPriceAssetREADONLY (inPrAssetAmt) = { | |
1706 | + | let cfg = getPoolConfig() | |
1707 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1708 | + | let amAssetIdStr = cfg[idxAmtAssetId] | |
1709 | + | let amAssetId = fromBase58String(amAssetIdStr) | |
1710 | + | let prAssetIdStr = cfg[idxPriceAssetId] | |
1711 | + | let prAssetId = fromBase58String(prAssetIdStr) | |
1712 | + | let amtAssetDcm = parseIntValue(cfg[idxAmtAssetDcm]) | |
1713 | + | let priceAssetDcm = parseIntValue(cfg[idxPriceAssetDcm]) | |
1714 | + | let poolStatus = cfg[idxPoolStatus] | |
1715 | + | let poolLPBalance = valueOrErrorMessage(assetInfo(lpAssetId), (("Asset " + toBase58String(lpAssetId)) + " doesn't exist")).quantity | |
1716 | + | let amBalanceRaw = getAccBalance(amAssetIdStr) | |
1717 | + | let prBalanceRaw = getAccBalance(prAssetIdStr) | |
1718 | + | let amBalanceRawX18 = toX18(amBalanceRaw, amtAssetDcm) | |
1719 | + | let prBalanceRawX18 = toX18(prBalanceRaw, priceAssetDcm) | |
1720 | + | let curPriceX18 = if ((poolLPBalance == 0)) | |
1721 | + | then zeroBigInt | |
1722 | + | else calcPriceBigInt(prBalanceRawX18, amBalanceRawX18) | |
1723 | + | let inPrAssetAmtX18 = toX18(inPrAssetAmt, priceAssetDcm) | |
1724 | + | let inAmAssetAmtX18 = fraction(inPrAssetAmtX18, scale18, curPriceX18) | |
1725 | + | let inAmAssetAmt = fromX18(inAmAssetAmtX18, amtAssetDcm) | |
1726 | + | let estPut = estimatePutOperation("", 500000, inAmAssetAmt, amAssetId, inPrAssetAmt, prAssetId, "", true, false) | |
1727 | + | let calcLpAmt = estPut._1 | |
1728 | + | let curPriceCalc = estPut._3 | |
1729 | + | let amBalance = estPut._4 | |
1730 | + | let prBalance = estPut._5 | |
1731 | + | let lpEmission = estPut._6 | |
1732 | + | $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)) | |
1733 | + | } | |
1734 | + | ||
1735 | + | ||
1736 | + | ||
1737 | + | @Callable(i) | |
1738 | + | func evaluateGetREADONLY (paymentLpAssetId,paymentLpAmt) = { | |
1739 | + | let res = estimateGetOperation("", paymentLpAssetId, paymentLpAmt, this) | |
1740 | + | let outAmAmt = res._1 | |
1741 | + | let outPrAmt = res._2 | |
1742 | + | let amBalance = res._5 | |
1743 | + | let prBalance = res._6 | |
1744 | + | let lpEmission = res._7 | |
1745 | + | let curPrice = res._8 | |
1746 | + | let poolStatus = parseIntValue(res._9) | |
1747 | + | $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)) | |
1707 | 1748 | } | |
1708 | 1749 | ||
1709 | 1750 | ||
1710 | 1751 | @Verifier(tx) | |
1711 | 1752 | func verify () = { | |
1712 | - | let targetPublicKey = match | |
1753 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
1713 | 1754 | case pk: ByteVector => | |
1714 | 1755 | pk | |
1715 | 1756 | case _: Unit => | |
1716 | 1757 | tx.senderPublicKey | |
1717 | 1758 | case _ => | |
1718 | 1759 | throw("Match error") | |
1719 | 1760 | } | |
1720 | 1761 | match tx { | |
1721 | 1762 | case order: Order => | |
1722 | - | let matcherPub = | |
1723 | - | let $ | |
1763 | + | let matcherPub = getMatcherPubOrFail() | |
1764 | + | let $t06808568202 = if (skipOrderValidation()) | |
1724 | 1765 | then $Tuple2(true, "") | |
1725 | 1766 | else validateMatcherOrderAllowed(order) | |
1726 | - | let orderValid = $ | |
1727 | - | let orderValidInfo = $ | |
1767 | + | let orderValid = $t06808568202._1 | |
1768 | + | let orderValidInfo = $t06808568202._2 | |
1728 | 1769 | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1729 | 1770 | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1730 | 1771 | if (if (if (orderValid) | |
1731 | 1772 | then senderValid | |
1732 | 1773 | else false) | |
1733 | 1774 | then matcherValid | |
1734 | 1775 | else false) | |
1735 | 1776 | then true | |
1736 | 1777 | else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid) | |
1737 | 1778 | case s: SetScriptTransaction => | |
1738 | 1779 | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1739 | 1780 | then true | |
1740 | 1781 | else { | |
1741 | 1782 | let newHash = blake2b256(value(s.script)) | |
1742 | - | let allowedHash = fromBase64String(value(getString( | |
1783 | + | let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash()))) | |
1743 | 1784 | let currentHash = scriptHash(this) | |
1744 | 1785 | if ((allowedHash == newHash)) | |
1745 | 1786 | then (currentHash != newHash) | |
1746 | 1787 | else false | |
1747 | 1788 | } | |
1748 | 1789 | case _ => | |
1749 | 1790 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1750 | 1791 | } | |
1751 | 1792 | } | |
1752 | 1793 |
github/deemru/w8io/6500d08 435.03 ms ◑