tx · 2SEzJRmshq3ZAwwXwNDk4XD7jhWDUXABeVqgpxXvd6eQ 3Mx85sUMQFaaTcAjiQpd5sGUAdaCrNKxv7a: -0.12600000 Waves 2023.04.25 14:24 [2550011] smart account 3Mx85sUMQFaaTcAjiQpd5sGUAdaCrNKxv7a > SELF 0.00000000 Waves
{ "type": 13, "id": "2SEzJRmshq3ZAwwXwNDk4XD7jhWDUXABeVqgpxXvd6eQ", "fee": 12600000, "feeAssetId": null, "timestamp": 1682421537153, "version": 2, "chainId": 84, "sender": "3Mx85sUMQFaaTcAjiQpd5sGUAdaCrNKxv7a", "senderPublicKey": "6f5UpEaYxvWL2FTjo4b6CUu3VwSHJ9BvuodtSaSb5tJ8", "proofs": [ "4HjjXXSGgAVZ2eabGUFxQWHkaSvVetAAANxo8bdtvwCSnPe6prb3QeVqu2BHUyRatDPqAfAJ17FGk889oSxKx9Gd" ], "script": "base64:BgKoAQgCEgASBQoDAQQBEgcKBQEEAQgBEgMKAQgSABIECgIBBBIDCgEBEgQKAgEEEgQKAggBEgQKAggBEgQKAggBEgUKAwEIARIAEgQKAgEBEgMKAQESBQoDAQEBEgQKAggIEgASABIDCgEIEgUKAwEBARIECgIBARIECgIIARIECgIICBILCgkIAQECAQIIBAQSBgoECAgBCBIAEgMKAQESAwoBARIECgIIAYEBAApsUGRlY2ltYWxzAAgABnNjYWxlOACAwtcvAAxzY2FsZThCaWdJbnQJALYCAQCAwtcvAAdzY2FsZTE4CQC2AgEAgICQu7rWrfANAAp6ZXJvQmlnSW50CQC2AgEAAAAEYmlnMAkAtgIBAAAABGJpZzEJALYCAQABAARiaWcyCQC2AgEAAgALd2F2ZXNTdHJpbmcCBVdBVkVTAANTRVACAl9fAApQb29sQWN0aXZlAAEAD1Bvb2xQdXREaXNhYmxlZAACABNQb29sTWF0Y2hlckRpc2FibGVkAAMADFBvb2xTaHV0ZG93bgAEAA5pZHhQb29sQWRkcmVzcwABAA1pZHhQb29sU3RhdHVzAAIAEGlkeFBvb2xM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gFB25ld0hhc2gJAQIhPQIFC2N1cnJlbnRIYXNoBQduZXdIYXNoBwkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAUPdGFyZ2V0UHVibGljS2V55ILv3A==", "height": 2550011, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: E55pebjKENxbPi7q4LKoGgR5TdNaFg7kkBwB5ggDxLC8 Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let lPdecimals = 8 | |
5 | 5 | ||
6 | - | let shareAssetDecimals = 8 | |
6 | + | let scale8 = 100000000 | |
7 | + | ||
8 | + | let scale8BigInt = toBigInt(100000000) | |
9 | + | ||
10 | + | let scale18 = toBigInt(1000000000000000000) | |
11 | + | ||
12 | + | let zeroBigInt = toBigInt(0) | |
13 | + | ||
14 | + | let big0 = toBigInt(0) | |
15 | + | ||
16 | + | let big1 = toBigInt(1) | |
17 | + | ||
18 | + | let big2 = toBigInt(2) | |
7 | 19 | ||
8 | 20 | let wavesString = "WAVES" | |
9 | 21 | ||
10 | - | let | |
22 | + | let SEP = "__" | |
11 | 23 | ||
12 | - | let | |
24 | + | let PoolActive = 1 | |
13 | 25 | ||
14 | - | func wrapErr (msg) = makeString(["lp_staking_pools.ride:", msg], " ") | |
26 | + | let PoolPutDisabled = 2 | |
27 | + | ||
28 | + | let PoolMatcherDisabled = 3 | |
29 | + | ||
30 | + | let PoolShutdown = 4 | |
31 | + | ||
32 | + | let idxPoolAddress = 1 | |
33 | + | ||
34 | + | let idxPoolStatus = 2 | |
35 | + | ||
36 | + | let idxPoolLPAssetId = 3 | |
37 | + | ||
38 | + | let idxAmtAssetId = 4 | |
39 | + | ||
40 | + | let idxPriceAssetId = 5 | |
41 | + | ||
42 | + | let idxAmtAssetDcm = 6 | |
43 | + | ||
44 | + | let idxPriceAssetDcm = 7 | |
45 | + | ||
46 | + | let idxIAmtAssetId = 8 | |
47 | + | ||
48 | + | let idxIPriceAssetId = 9 | |
49 | + | ||
50 | + | let idxLPAssetDcm = 10 | |
51 | + | ||
52 | + | let idxPoolAmtAssetAmt = 1 | |
53 | + | ||
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)) | |
15 | 63 | ||
16 | 64 | ||
17 | - | func | |
65 | + | func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
18 | 66 | ||
19 | 67 | ||
20 | - | func | |
68 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
21 | 69 | ||
22 | 70 | ||
23 | - | func | |
71 | + | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
24 | 72 | ||
25 | 73 | ||
26 | - | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), errKeyIsNotDefined(address, key)) | |
74 | + | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
75 | + | ||
76 | + | ||
77 | + | func abs (val) = if ((0 > val)) | |
78 | + | then -(val) | |
79 | + | else val | |
80 | + | ||
81 | + | ||
82 | + | func absBigInt (val) = if ((zeroBigInt > val)) | |
83 | + | then -(val) | |
84 | + | else val | |
85 | + | ||
86 | + | ||
87 | + | func swapContract () = "%s__swapContract" | |
88 | + | ||
89 | + | ||
90 | + | func fc () = "%s__factoryContract" | |
91 | + | ||
92 | + | ||
93 | + | func mpk () = "%s__managerPublicKey" | |
94 | + | ||
95 | + | ||
96 | + | func pmpk () = "%s__pendingManagerPublicKey" | |
97 | + | ||
98 | + | ||
99 | + | func pl () = "%s%s__price__last" | |
100 | + | ||
101 | + | ||
102 | + | func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP) | |
103 | + | ||
104 | + | ||
105 | + | func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId) | |
106 | + | ||
107 | + | ||
108 | + | func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId) | |
109 | + | ||
110 | + | ||
111 | + | func aa () = "%s__amountAsset" | |
112 | + | ||
113 | + | ||
114 | + | func pa () = "%s__priceAsset" | |
115 | + | ||
116 | + | ||
117 | + | let keyFee = "%s__fee" | |
118 | + | ||
119 | + | let feeDefault = fraction(10, scale8, 10000) | |
120 | + | ||
121 | + | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
122 | + | ||
123 | + | let keyKLp = makeString(["%s", "kLp"], SEP) | |
124 | + | ||
125 | + | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
126 | + | ||
127 | + | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
128 | + | ||
129 | + | let kLpRefreshDelayDefault = 30 | |
130 | + | ||
131 | + | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
132 | + | ||
133 | + | func keyAdditionalBalance (assetId) = makeString(["%s%s", "stakedBalance", assetId], SEP) | |
134 | + | ||
135 | + | ||
136 | + | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "shareAssetBalance", assetId], SEP) | |
137 | + | ||
138 | + | ||
139 | + | func getAdditionalBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyAdditionalBalance(assetId)), 0) | |
140 | + | ||
141 | + | ||
142 | + | func getStakingAssetBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
143 | + | ||
144 | + | ||
145 | + | func keyFactoryConfig () = "%s__factoryConfig" | |
146 | + | ||
147 | + | ||
148 | + | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
149 | + | ||
150 | + | ||
151 | + | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") | |
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" | |
170 | + | ||
171 | + | func keySkipOrderValidation (poolAddress) = ("%s%s__skipOrderValidation__" + poolAddress) | |
172 | + | ||
173 | + | ||
174 | + | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
175 | + | ||
176 | + | ||
177 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
178 | + | ||
179 | + | ||
180 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
181 | + | ||
182 | + | ||
183 | + | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
184 | + | ||
185 | + | ||
186 | + | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
187 | + | ||
188 | + | ||
189 | + | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
190 | + | ||
191 | + | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
192 | + | ||
193 | + | let inFee = { | |
194 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
195 | + | if ($isInstanceOf(@, "Int")) | |
196 | + | then @ | |
197 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
198 | + | } | |
199 | + | ||
200 | + | let outFee = { | |
201 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
202 | + | if ($isInstanceOf(@, "Int")) | |
203 | + | then @ | |
204 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
205 | + | } | |
206 | + | ||
207 | + | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
208 | + | ||
209 | + | ||
210 | + | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
211 | + | ||
212 | + | ||
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) | |
219 | + | } | |
27 | 220 | ||
28 | 221 | ||
29 | 222 | func parseAssetId (input) = if ((input == wavesString)) | |
36 | 229 | else toBase58String(value(input)) | |
37 | 230 | ||
38 | 231 | ||
39 | - | func ensurePositive (v) = if ((v >= 0)) | |
40 | - | then v | |
41 | - | else throwErr("value should be positive") | |
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])) | |
42 | 233 | ||
43 | 234 | ||
44 | - | func keyFactoryContract () = makeString(["%s", "factoryContract"], separator) | |
235 | + | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
236 | + | ||
237 | + | let $t090589224 = poolConfigParsed | |
238 | + | ||
239 | + | let cfgPoolAddress = $t090589224._1 | |
240 | + | ||
241 | + | let cfgPoolStatus = $t090589224._2 | |
242 | + | ||
243 | + | let cfgLpAssetId = $t090589224._3 | |
244 | + | ||
245 | + | let cfgAmountAssetId = $t090589224._4 | |
246 | + | ||
247 | + | let cfgPriceAssetId = $t090589224._5 | |
248 | + | ||
249 | + | let cfgAmountAssetDecimals = $t090589224._6 | |
250 | + | ||
251 | + | let cfgPriceAssetDecimals = $t090589224._7 | |
252 | + | ||
253 | + | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
45 | 254 | ||
46 | 255 | ||
47 | - | func keyLpStakingContract () = makeString(["%s", "lpStakingContract"], separator) | |
256 | + | let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address") | |
257 | + | ||
258 | + | let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address") | |
259 | + | ||
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) | |
48 | 261 | ||
49 | 262 | ||
50 | - | func | |
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) | |
51 | 264 | ||
52 | 265 | ||
53 | - | func keyBoostingContract () = makeString(["%s", "boostingContract"], separator) | |
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 | + | } | |
54 | 273 | ||
55 | 274 | ||
56 | - | func | |
275 | + | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
57 | 276 | ||
58 | 277 | ||
59 | - | func | |
278 | + | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
60 | 279 | ||
61 | 280 | ||
62 | - | func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], separator) | |
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 | + | } | |
63 | 292 | ||
64 | 293 | ||
65 | - | func keyWxAssetId () = makeString(["%s", "wxAssetId"], separator) | |
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 | + | } | |
66 | 322 | ||
67 | 323 | ||
68 | - | func keyShutdown () = makeString(["%s", "shutdown"], separator) | |
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 | + | } | |
69 | 361 | ||
70 | 362 | ||
71 | - | func keyMinDelay () = makeString(["%s", "minDelay"], separator) | |
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 | + | } | |
72 | 369 | ||
73 | 370 | ||
74 | - | func keyLockFraction () = makeString(["%s", "lockFraction"], separator) | |
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 | + | } | |
75 | 397 | ||
76 | 398 | ||
77 | - | func keyShareAssetId (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetId"], separator) | |
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 | + | } | |
78 | 412 | ||
79 | 413 | ||
80 | - | func keyBaseAssetId (shareAssetId) = makeString(["%s%s", assetIdToString(shareAssetId), "baseAssetId"], separator) | |
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 | + | } | |
81 | 444 | ||
82 | 445 | ||
83 | - | func keyPeriod (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "period"], separator) | |
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 | + | } | |
84 | 451 | ||
85 | 452 | ||
86 | - | func keyPeriodStartHeight (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "periodStartHeight", toString(period)], separator) | |
453 | + | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
454 | + | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
455 | + | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
456 | + | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
457 | + | } | |
87 | 458 | ||
88 | 459 | ||
89 | - | func keyBaseAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "baseAssetAmountToConvert"], separator) | |
460 | + | func calcPrices (amAmt,prAmt,lpAmt) = { | |
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 | + | } | |
90 | 472 | ||
91 | 473 | ||
92 | - | func keyShareAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetAmountToConvert"], separator) | |
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 | + | } | |
93 | 478 | ||
94 | 479 | ||
95 | - | func keyUserBaseAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert"], separator) | |
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 | + | } | |
96 | 514 | ||
97 | 515 | ||
98 | - | func keyUserBaseAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert", "period"], separator) | |
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 | + | } | |
99 | 591 | ||
100 | 592 | ||
101 | - | func keyUserShareAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert"], separator) | |
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 | + | } | |
102 | 601 | ||
103 | 602 | ||
104 | - | func keyUserShareAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert", "period"], separator) | |
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 | + | } | |
105 | 610 | ||
106 | 611 | ||
107 | - | func keyPricePeriod (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "price", toString(period)], separator) | |
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 | + | } | |
108 | 620 | ||
109 | 621 | ||
110 | - | func | |
622 | + | func skipOrderValidation () = valueOrElse(getBoolean(factoryContract, keySkipOrderValidation(toString(this))), false) | |
111 | 623 | ||
112 | 624 | ||
113 | - | func keyPricePeriodPut (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "put"], separator) | |
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)], " ")) | |
114 | 628 | ||
115 | 629 | ||
116 | - | func keyPricePutHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], separator) | |
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 | + | } | |
117 | 660 | ||
118 | 661 | ||
119 | - | func keyPricePeriodGet (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "get"], separator) | |
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 | + | } | |
120 | 679 | ||
121 | 680 | ||
122 | - | func keyPriceGetHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], separator) | |
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 | + | } | |
123 | 696 | ||
124 | 697 | ||
125 | - | func keyHistoryEntry (baseAssetId,operation,period,userAddress,txId) = makeString(["%s%s%s%s", "history", toUtf8String(value(baseAssetId)), operation, toString(userAddress), toBase58String(txId), toString(height)], separator) | |
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.") | |
713 | + | } | |
126 | 714 | ||
127 | 715 | ||
128 | - | func keyManagerPublicKey () = "%s__managerPublicKey" | |
716 | + | func takeFee (amount,fee) = { | |
717 | + | let feeAmount = if ((fee == 0)) | |
718 | + | then 0 | |
719 | + | else fraction(amount, fee, scale8) | |
720 | + | $Tuple2((amount - feeAmount), feeAmount) | |
721 | + | } | |
129 | 722 | ||
130 | 723 | ||
131 | - | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
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) | |
779 | + | } | |
780 | + | $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset) | |
781 | + | } | |
782 | + | else throw("Strict value is not equal to itself.") | |
783 | + | } | |
132 | 784 | ||
133 | 785 | ||
134 | - | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
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)) | |
795 | + | then { | |
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) | |
838 | + | } | |
839 | + | else throw("Strict value is not equal to itself.") | |
840 | + | } | |
841 | + | ||
842 | + | ||
843 | + | func managerPublicKeyOrUnit () = match getString(mpk()) { | |
135 | 844 | case s: String => | |
136 | 845 | fromBase58String(s) | |
137 | 846 | case _: Unit => | |
141 | 850 | } | |
142 | 851 | ||
143 | 852 | ||
144 | - | func pendingManagerPublicKeyOrUnit () = match getString( | |
853 | + | func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) { | |
145 | 854 | case s: String => | |
146 | 855 | fromBase58String(s) | |
147 | 856 | case _: Unit => | |
151 | 860 | } | |
152 | 861 | ||
153 | 862 | ||
154 | - | let permissionDeniedError = throw("Permission denied") | |
155 | - | ||
156 | - | func mustThis (i) = if ((i.caller == this)) | |
157 | - | then true | |
158 | - | else permissionDeniedError | |
159 | - | ||
160 | - | ||
161 | - | func mustManager (i) = match managerPublicKeyOrUnit() { | |
863 | + | func isManager (i) = match managerPublicKeyOrUnit() { | |
162 | 864 | case pk: ByteVector => | |
163 | - | if ((i.callerPublicKey == pk)) | |
164 | - | then true | |
165 | - | else permissionDeniedError | |
865 | + | (i.callerPublicKey == pk) | |
166 | 866 | case _: Unit => | |
167 | - | | |
867 | + | (i.caller == this) | |
168 | 868 | case _ => | |
169 | 869 | throw("Match error") | |
170 | 870 | } | |
171 | 871 | ||
172 | 872 | ||
173 | - | let shutdown = valueOrElse(getBoolean(keyShutdown()), false) | |
174 | - | ||
175 | - | func shutdownCheck (i) = if (if (!(shutdown)) | |
176 | - | then true | |
177 | - | else mustManager(i)) | |
178 | - | then true | |
179 | - | else throw("operation is disabled") | |
180 | - | ||
181 | - | ||
182 | - | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract())) | |
183 | - | ||
184 | - | let lpStakingContract = addressFromStringValue(getStrOrFail(this, keyLpStakingContract())) | |
185 | - | ||
186 | - | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract())) | |
187 | - | ||
188 | - | let boostingContract = addressFromStringValue(getStrOrFail(this, keyBoostingContract())) | |
189 | - | ||
190 | - | let swapContract = addressFromStringValue(getStrOrFail(this, keySwapContract())) | |
191 | - | ||
192 | - | let assetsStoreContract = addressFromStringValue(getStrOrFail(this, keyAssetsStoreContract())) | |
193 | - | ||
194 | - | let usdtAssetId = parseAssetId(getStrOrFail(this, keyUsdtAssetId())) | |
195 | - | ||
196 | - | let wxAssetId = parseAssetId(getStrOrFail(this, keyWxAssetId())) | |
197 | - | ||
198 | - | let minDelayDefault = 1440 | |
199 | - | ||
200 | - | let minDelay = valueOrElse(getInteger(this, keyMinDelay()), minDelayDefault) | |
201 | - | ||
202 | - | let lockFractionMultiplier = 100000000 | |
203 | - | ||
204 | - | let lockFractionDefault = fraction(1, lockFractionMultiplier, 2) | |
205 | - | ||
206 | - | let lockFraction = valueOrElse(getInteger(this, keyLockFraction()), lockFractionDefault) | |
207 | - | ||
208 | - | func getPoolInfo (amountAssetId) = { | |
209 | - | let amountAssetIdStr = assetIdToString(amountAssetId) | |
210 | - | let priceAssetIdStr = assetIdToString(usdtAssetId) | |
211 | - | let poolInfoOption = { | |
212 | - | let @ = invoke(factoryContract, "poolInfoREADONLY", [amountAssetIdStr, priceAssetIdStr], nil) | |
213 | - | if ($isInstanceOf(@, "(Address, ByteVector)")) | |
214 | - | then @ | |
215 | - | else unit | |
216 | - | } | |
217 | - | poolInfoOption | |
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 | + | } | |
218 | 887 | } | |
219 | 888 | ||
220 | 889 | ||
221 | - | func calcPrice (lpAssetId,shareAssetId) = { | |
222 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), "failed to get share asset info") | |
223 | - | let shareAssetEmission = shareAssetInfo.quantity | |
224 | - | let stakedAmount = ensurePositive(valueOrErrorMessage({ | |
225 | - | let @ = invoke(stakingContract, "stakedByUserREADONLY", [assetIdToString(lpAssetId), toString(this)], nil) | |
226 | - | if ($isInstanceOf(@, "Int")) | |
890 | + | @Callable(i) | |
891 | + | func rebalance () = (rebalanceAsset(getStringOrFail(this, aa())) ++ rebalanceAsset(getStringOrFail(this, pa()))) | |
892 | + | ||
893 | + | ||
894 | + | ||
895 | + | @Callable(i) | |
896 | + | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
897 | + | let $t03912539430 = if ((isReverse == false)) | |
898 | + | then { | |
899 | + | let assetOut = getStringOrFail(this, pa()) | |
900 | + | let assetIn = getStringOrFail(this, aa()) | |
901 | + | $Tuple2(assetOut, assetIn) | |
902 | + | } | |
903 | + | else { | |
904 | + | let assetOut = getStringOrFail(this, aa()) | |
905 | + | let assetIn = getStringOrFail(this, pa()) | |
906 | + | $Tuple2(assetOut, assetIn) | |
907 | + | } | |
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)) | |
916 | + | then true | |
917 | + | else throw("new K is fewer error") | |
918 | + | if ((checkK == checkK)) | |
919 | + | then $Tuple2(nil, amountOut) | |
920 | + | else throw("Strict value is not equal to itself.") | |
921 | + | } | |
922 | + | ||
923 | + | ||
924 | + | ||
925 | + | @Callable(i) | |
926 | + | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
927 | + | let swapContact = { | |
928 | + | let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil) | |
929 | + | if ($isInstanceOf(@, "String")) | |
227 | 930 | then @ | |
228 | - | else unit | |
229 | - | }, wrapErr("invalid stakedByUserREADONLY result"))) | |
230 | - | let price = if ((shareAssetEmission == 0)) | |
231 | - | then scale18BigInt | |
232 | - | else fraction(toBigInt(stakedAmount), scale18BigInt, toBigInt(shareAssetEmission), FLOOR) | |
233 | - | price | |
931 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
932 | + | } | |
933 | + | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
934 | + | then true | |
935 | + | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
936 | + | then true | |
937 | + | else throwErr("Permission denied")] | |
938 | + | if ((checks == checks)) | |
939 | + | then { | |
940 | + | let pmt = value(i.payments[0]) | |
941 | + | let assetIn = assetIdToString(pmt.assetId) | |
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)) | |
954 | + | then { | |
955 | + | let checkMin = if ((amountOut >= amountOutMin)) | |
956 | + | then true | |
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 | + | } | |
970 | + | else throw("Strict value is not equal to itself.") | |
971 | + | } | |
972 | + | else throw("Strict value is not equal to itself.") | |
973 | + | } | |
974 | + | else throw("Strict value is not equal to itself.") | |
234 | 975 | } | |
976 | + | ||
235 | 977 | ||
236 | 978 | ||
237 | 979 | @Callable(i) | |
241 | 983 | then { | |
242 | 984 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
243 | 985 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
244 | - | then [StringEntry( | |
986 | + | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
245 | 987 | else throw("Strict value is not equal to itself.") | |
246 | 988 | } | |
247 | 989 | else throw("Strict value is not equal to itself.") | |
254 | 996 | let pm = pendingManagerPublicKeyOrUnit() | |
255 | 997 | let hasPM = if (isDefined(pm)) | |
256 | 998 | then true | |
257 | - | else | |
999 | + | else throw("No pending manager") | |
258 | 1000 | if ((hasPM == hasPM)) | |
259 | 1001 | then { | |
260 | 1002 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
261 | 1003 | then true | |
262 | - | else | |
1004 | + | else throw("You are not pending manager") | |
263 | 1005 | if ((checkPM == checkPM)) | |
264 | - | then [StringEntry( | |
1006 | + | then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())] | |
265 | 1007 | else throw("Strict value is not equal to itself.") | |
266 | 1008 | } | |
267 | 1009 | else throw("Strict value is not equal to itself.") | |
270 | 1012 | ||
271 | 1013 | ||
272 | 1014 | @Callable(i) | |
273 | - | func emit (assetId,amount) = { | |
274 | - | let checkCaller = mustThis(i) | |
275 | - | if ((checkCaller == checkCaller)) | |
276 | - | then { | |
277 | - | let isReissuable = true | |
278 | - | $Tuple2([Reissue(assetId, amount, isReissuable)], amount) | |
279 | - | } | |
280 | - | else throw("Strict value is not equal to itself.") | |
281 | - | } | |
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)) | |
1033 | + | then { | |
1034 | + | let emitInvLegacy = match emitInv { | |
1035 | + | case legacyFactoryContract: Address => | |
1036 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
1037 | + | case _ => | |
1038 | + | unit | |
1039 | + | } | |
1040 | + | if ((emitInvLegacy == emitInvLegacy)) | |
1041 | + | then { | |
1042 | + | let slippageAInv = if ((amDiff > 0)) | |
1043 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1044 | + | else nil | |
1045 | + | if ((slippageAInv == slippageAInv)) | |
1046 | + | then { | |
1047 | + | let slippagePInv = if ((prDiff > 0)) | |
1048 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1049 | + | else nil | |
1050 | + | if ((slippagePInv == slippagePInv)) | |
1051 | + | then { | |
1052 | + | let lpTransfer = if (shouldAutoStake) | |
1053 | + | then { | |
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.") | |
1058 | + | } | |
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)) | |
1067 | + | then { | |
1068 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1069 | + | if ((reb == reb)) | |
1070 | + | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
1071 | + | else throw("Strict value is not equal to itself.") | |
1072 | + | } | |
1073 | + | else throw("Strict value is not equal to itself.") | |
1074 | + | } | |
1075 | + | else throw("Strict value is not equal to itself.") | |
1076 | + | } | |
1077 | + | else throw("Strict value is not equal to itself.") | |
1078 | + | } | |
1079 | + | else throw("Strict value is not equal to itself.") | |
1080 | + | } | |
1081 | + | else throw("Strict value is not equal to itself.") | |
1082 | + | } | |
1083 | + | else throw("Strict value is not equal to itself.") | |
1084 | + | } | |
1085 | + | else throw("Strict value is not equal to itself.") | |
1086 | + | } | |
282 | 1087 | ||
283 | 1088 | ||
284 | 1089 | ||
285 | 1090 | @Callable(i) | |
286 | - | func burn (assetId,amount) = { | |
287 | - | let checkCaller = mustThis(i) | |
288 | - | if ((checkCaller == checkCaller)) | |
289 | - | then $Tuple2([Burn(assetId, amount)], amount) | |
290 | - | else throw("Strict value is not equal to itself.") | |
291 | - | } | |
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 | + | } | |
292 | 1111 | ||
293 | 1112 | ||
294 | 1113 | ||
295 | 1114 | @Callable(i) | |
296 | - | func create (baseAssetIdStr,shareAssetIdStr,shareAssetName,shareAssetDescription,shareAssetLogo) = { | |
297 | - | let shareAssetLabel = "STAKING_LP" | |
298 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
299 | - | let checks = [mustManager(i), if (isDefined(getPoolInfo(baseAssetId))) | |
1115 | + | func putOneTkn (minOutAmount,autoStake) = { | |
1116 | + | let isPoolOneTokenOperationsDisabled = { | |
1117 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1118 | + | if ($isInstanceOf(@, "Boolean")) | |
1119 | + | then @ | |
1120 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1121 | + | } | |
1122 | + | let isPutDisabled = if (if (if (isGlobalShutdown()) | |
300 | 1123 | then true | |
301 | - | else throwErr("invalid base asset")] | |
1124 | + | else (cfgPoolStatus == PoolPutDisabled)) | |
1125 | + | then true | |
1126 | + | else (cfgPoolStatus == PoolShutdown)) | |
1127 | + | then true | |
1128 | + | else isPoolOneTokenOperationsDisabled | |
1129 | + | let checks = [if (if (!(isPutDisabled)) | |
1130 | + | then true | |
1131 | + | else isManager(i)) | |
1132 | + | then true | |
1133 | + | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1134 | + | then true | |
1135 | + | else throwErr("exactly 1 payment are expected")] | |
302 | 1136 | if ((checks == checks)) | |
303 | 1137 | then { | |
304 | - | let commonState = [IntegerEntry(keyPeriod(baseAssetId), 0)] | |
305 | - | if ((shareAssetIdStr == "")) | |
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)) | |
306 | 1147 | then { | |
307 | - | let shareAssetIssueAmount = 1 | |
308 | - | let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescription, shareAssetIssueAmount, shareAssetDecimals, true) | |
309 | - | let calculatedShareAssetId = calculateAssetId(shareAssetIssueAction) | |
310 | - | let shareAssetBurnAction = Burn(calculatedShareAssetId, shareAssetIssueAmount) | |
311 | - | let calculatedShareAssetIdStr = toBase58String(calculatedShareAssetId) | |
312 | - | let createOrUpdate = invoke(assetsStoreContract, "createOrUpdate", [calculatedShareAssetIdStr, shareAssetLogo, false], nil) | |
313 | - | if ((createOrUpdate == createOrUpdate)) | |
1148 | + | let userAddress = i.caller | |
1149 | + | let txId = i.transactionId | |
1150 | + | let $t04680346955 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
1151 | + | if (($t04680346955 == $t04680346955)) | |
314 | 1152 | then { | |
315 | - | let addLabel = invoke(assetsStoreContract, "addLabel", [calculatedShareAssetIdStr, shareAssetLabel], nil) | |
316 | - | if ((addLabel == addLabel)) | |
317 | - | then $Tuple2((commonState ++ [shareAssetIssueAction, shareAssetBurnAction, StringEntry(keyShareAssetId(baseAssetId), calculatedShareAssetIdStr), StringEntry(keyBaseAssetId(calculatedShareAssetId), baseAssetIdStr)]), calculatedShareAssetIdStr) | |
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) | |
1160 | + | else false) | |
1161 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1162 | + | else emitAmountEstimated | |
1163 | + | let emitInv = emit(emitAmount) | |
1164 | + | if ((emitInv == emitInv)) | |
1165 | + | then { | |
1166 | + | let lpTransfer = if (autoStake) | |
1167 | + | then { | |
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) | |
1194 | + | else throw("Strict value is not equal to itself.") | |
1195 | + | } | |
1196 | + | else throw("Strict value is not equal to itself.") | |
1197 | + | } | |
318 | 1198 | else throw("Strict value is not equal to itself.") | |
319 | 1199 | } | |
320 | 1200 | else throw("Strict value is not equal to itself.") | |
321 | - | } | |
322 | - | else { | |
323 | - | let shareAssetId = fromBase58String(shareAssetIdStr) | |
324 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id")) | |
325 | - | let checkIssuer = if ((shareAssetInfo.issuer == lpStakingContract)) | |
326 | - | then true | |
327 | - | else throwErr("invalid share asset id issuer") | |
328 | - | if ((checkIssuer == checkIssuer)) | |
329 | - | then $Tuple2((commonState ++ [StringEntry(keyShareAssetId(baseAssetId), shareAssetIdStr), StringEntry(keyBaseAssetId(shareAssetId), baseAssetIdStr)]), shareAssetIdStr) | |
330 | - | else throw("Strict value is not equal to itself.") | |
331 | - | } | |
332 | - | } | |
333 | - | else throw("Strict value is not equal to itself.") | |
334 | - | } | |
335 | - | ||
336 | - | ||
337 | - | ||
338 | - | @Callable(i) | |
339 | - | func put () = { | |
340 | - | let pmt = if ((size(i.payments) == 1)) | |
341 | - | then i.payments[0] | |
342 | - | else throwErr("exactly 1 payment is expected") | |
343 | - | let baseAssetId = pmt.assetId | |
344 | - | let userAddress = i.caller | |
345 | - | let checks = [shutdownCheck(i), if (isDefined(getString(keyShareAssetId(baseAssetId)))) | |
346 | - | then true | |
347 | - | else throwErr("invalid asset")] | |
348 | - | if ((checks == checks)) | |
349 | - | then { | |
350 | - | let $t01167511778 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
351 | - | let poolAddress = $t01167511778._1 | |
352 | - | let lpAssetId = $t01167511778._2 | |
353 | - | let period = value(getInteger(keyPeriod(baseAssetId))) | |
354 | - | let userBaseAssetAmountToConvertPeriodOption = getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)) | |
355 | - | let claimShareAssetInvocation = if ((userBaseAssetAmountToConvertPeriodOption == unit)) | |
356 | - | then unit | |
357 | - | else { | |
358 | - | let userBaseAssetAmountToConvertPeriod = value(userBaseAssetAmountToConvertPeriodOption) | |
359 | - | if ((userBaseAssetAmountToConvertPeriod == period)) | |
360 | - | then unit | |
361 | - | else invoke(this, "claimShareAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil) | |
362 | - | } | |
363 | - | if ((claimShareAssetInvocation == claimShareAssetInvocation)) | |
364 | - | then { | |
365 | - | let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0) | |
366 | - | let userBaseAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
367 | - | $Tuple2([IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), (baseAssetAmountToConvert + pmt.amount)), StringEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString((userBaseAssetAmountToConvert + pmt.amount)), toString(lastBlock.timestamp)], separator)), IntegerEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "put", period, userAddress, i.transactionId), makeString(["%d%d%d", toString(pmt.amount), toString(lastBlock.timestamp), toString(userBaseAssetAmountToConvert)], separator))], unit) | |
368 | 1201 | } | |
369 | 1202 | else throw("Strict value is not equal to itself.") | |
370 | 1203 | } | |
374 | 1207 | ||
375 | 1208 | ||
376 | 1209 | @Callable(i) | |
377 | - | func claimShareAsset (baseAssetIdStr,userAddressStr) = { | |
378 | - | let checks = [shutdownCheck(i)] | |
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)) | |
1218 | + | } | |
1219 | + | ||
1220 | + | ||
1221 | + | ||
1222 | + | @Callable(i) | |
1223 | + | func getOneTkn (outAssetIdStr,minOutAmount) = { | |
1224 | + | let isPoolOneTokenOperationsDisabled = { | |
1225 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1226 | + | if ($isInstanceOf(@, "Boolean")) | |
1227 | + | then @ | |
1228 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1229 | + | } | |
1230 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1231 | + | then true | |
1232 | + | else (cfgPoolStatus == PoolShutdown)) | |
1233 | + | then true | |
1234 | + | else isPoolOneTokenOperationsDisabled | |
1235 | + | let checks = [if (if (!(isGetDisabled)) | |
1236 | + | then true | |
1237 | + | else isManager(i)) | |
1238 | + | then true | |
1239 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1240 | + | then true | |
1241 | + | else throwErr("exactly 1 payment are expected")] | |
379 | 1242 | if ((checks == checks)) | |
380 | 1243 | then { | |
381 | - | let userAddress = if ((userAddressStr == "")) | |
382 | - | then i.caller | |
383 | - | else { | |
384 | - | let checkCaller = mustThis(i) | |
385 | - | if ((checkCaller == checkCaller)) | |
386 | - | then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
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 | + | } | |
387 | 1294 | else throw("Strict value is not equal to itself.") | |
388 | 1295 | } | |
389 | - | if ((userAddress == userAddress)) | |
1296 | + | else throw("Strict value is not equal to itself.") | |
1297 | + | } | |
1298 | + | else throw("Strict value is not equal to itself.") | |
1299 | + | } | |
1300 | + | ||
1301 | + | ||
1302 | + | ||
1303 | + | @Callable(i) | |
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)) | |
1337 | + | then { | |
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)) | |
390 | 1343 | then { | |
391 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
392 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
393 | - | if ((shareAssetId == shareAssetId)) | |
1344 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1345 | + | if ((unstakeInv == unstakeInv)) | |
394 | 1346 | then { | |
395 | - | let | |
396 | - | if (( | |
1347 | + | let $t05176051911 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
1348 | + | if (($t05176051911 == $t05176051911)) | |
397 | 1349 | then { | |
398 | - | let userBaseAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
399 | - | let checkAmountToConvert = if ((userBaseAssetAmountToConvert > 0)) | |
400 | - | then true | |
401 | - | else throwErr("nothing to claim") | |
402 | - | if ((checkAmountToConvert == checkAmountToConvert)) | |
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)) | |
403 | 1362 | then { | |
404 | - | let userBaseAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period")) | |
405 | - | let checkPeriod = if ((period > userBaseAssetAmountToConvertPeriod)) | |
406 | - | then true | |
407 | - | else throwErr("invalid period") | |
408 | - | if ((checkPeriod == checkPeriod)) | |
409 | - | then { | |
410 | - | let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodPut(baseAssetId, userBaseAssetAmountToConvertPeriod)), wrapErr("failed to get price"))) | |
411 | - | let shareAssetAmount = toInt(fraction(toBigInt(userBaseAssetAmountToConvert), scale18BigInt, price)) | |
412 | - | $Tuple2([StringEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString(0), toString(lastBlock.timestamp)], separator)), DeleteEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, shareAssetAmount, shareAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimShareAsset", period, userAddress, i.transactionId), makeString(["%d%d%d%d", toString(shareAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userBaseAssetAmountToConvert)], separator))], unit) | |
413 | - | } | |
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) | |
414 | 1384 | else throw("Strict value is not equal to itself.") | |
415 | 1385 | } | |
416 | 1386 | else throw("Strict value is not equal to itself.") | |
428 | 1398 | ||
429 | 1399 | @Callable(i) | |
430 | 1400 | func get () = { | |
431 | - | let checks = [shutdownCheck(i)] | |
432 | - | if ((checks == checks)) | |
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)) | |
433 | 1410 | then { | |
434 | - | let pmt = if ((size(i.payments) == 1)) | |
435 | - | then i.payments[0] | |
436 | - | else throwErr("exactly 1 payment is expected") | |
437 | - | let shareAssetId = pmt.assetId | |
438 | - | let baseAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyBaseAssetId(shareAssetId)), wrapErr("invalid share asset id")))) | |
439 | - | if ((baseAssetId == baseAssetId)) | |
1411 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1412 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
440 | 1413 | then { | |
441 | - | let userAddress = i.caller | |
442 | - | let $t01612016309 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
443 | - | let poolAddress = $t01612016309._1 | |
444 | - | let lpAssetId = $t01612016309._2 | |
445 | - | let period = value(getInteger(keyPeriod(baseAssetId))) | |
446 | - | let userShareAssetAmountToConvertPeriodOption = getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)) | |
447 | - | let claimBaseAssetInvocation = if ((userShareAssetAmountToConvertPeriodOption == unit)) | |
448 | - | then unit | |
449 | - | else { | |
450 | - | let userShareAssetAmountToConvertPeriod = value(userShareAssetAmountToConvertPeriodOption) | |
451 | - | if ((userShareAssetAmountToConvertPeriod == period)) | |
452 | - | then unit | |
453 | - | else invoke(this, "claimBaseAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil) | |
454 | - | } | |
455 | - | if ((claimBaseAssetInvocation == claimBaseAssetInvocation)) | |
456 | - | then { | |
457 | - | let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0) | |
458 | - | let userShareAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserShareAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
459 | - | $Tuple2([IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), (shareAssetAmountToConvert + pmt.amount)), StringEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString((userShareAssetAmountToConvert + pmt.amount)), toString(lastBlock.timestamp)], separator)), IntegerEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "get", period, userAddress, i.transactionId), makeString(["%d%d%d", toString(pmt.amount), toString(lastBlock.timestamp), toString(userShareAssetAmountToConvert)], separator))], unit) | |
460 | - | } | |
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) | |
461 | 1420 | else throw("Strict value is not equal to itself.") | |
462 | 1421 | } | |
463 | 1422 | else throw("Strict value is not equal to itself.") | |
468 | 1427 | ||
469 | 1428 | ||
470 | 1429 | @Callable(i) | |
471 | - | func claimBaseAsset (baseAssetIdStr,userAddressStr) = { | |
472 | - | let checks = [shutdownCheck(i)] | |
473 | - | if ((checks == checks)) | |
1430 | + | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
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 | |
1437 | + | if ((noLessThenAmtAsset > outAmAmt)) | |
1438 | + | then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1439 | + | else if ((noLessThenPriceAsset > outPrAmt)) | |
1440 | + | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1441 | + | else { | |
1442 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1443 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1444 | + | if ((currentKLp == currentKLp)) | |
1445 | + | then { | |
1446 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1447 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1448 | + | 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) | |
1455 | + | else throw("Strict value is not equal to itself.") | |
1456 | + | } | |
1457 | + | else throw("Strict value is not equal to itself.") | |
1458 | + | } | |
1459 | + | else throw("Strict value is not equal to itself.") | |
1460 | + | } | |
1461 | + | } | |
1462 | + | ||
1463 | + | ||
1464 | + | ||
1465 | + | @Callable(i) | |
1466 | + | func unstakeAndGet (amount) = { | |
1467 | + | let checkPayments = if ((size(i.payments) != 0)) | |
1468 | + | then throw("No payments are expected") | |
1469 | + | else true | |
1470 | + | if ((checkPayments == checkPayments)) | |
474 | 1471 | then { | |
475 | - | let userAddress = if ((userAddressStr == "")) | |
476 | - | then i.caller | |
477 | - | else { | |
478 | - | let checkCaller = mustThis(i) | |
479 | - | if ((checkCaller == checkCaller)) | |
480 | - | then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
481 | - | else throw("Strict value is not equal to itself.") | |
482 | - | } | |
483 | - | if ((userAddress == userAddress)) | |
1472 | + | let cfg = getPoolConfig() | |
1473 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1474 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1475 | + | if ((currentKLp == currentKLp)) | |
484 | 1476 | then { | |
485 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
486 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
487 | - | if ((shareAssetId == shareAssetId)) | |
1477 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1478 | + | if ((unstakeInv == unstakeInv)) | |
488 | 1479 | then { | |
489 | - | let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period")) | |
490 | - | if ((period == period)) | |
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()) | |
1487 | + | then true | |
1488 | + | else (poolStatus == PoolShutdown)) | |
1489 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
1490 | + | else true | |
1491 | + | if ((checkPoolStatus == checkPoolStatus)) | |
491 | 1492 | then { | |
492 | - | let userShareAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserShareAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
493 | - | let userShareAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period")) | |
494 | - | let checkPeriod = if ((period > userShareAssetAmountToConvertPeriod)) | |
495 | - | then true | |
496 | - | else throwErr("invalid period") | |
497 | - | if ((checkPeriod == checkPeriod)) | |
1493 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1494 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
498 | 1495 | then { | |
499 | - | let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodGet(baseAssetId, userShareAssetAmountToConvertPeriod)), wrapErr("failed to get price"))) | |
500 | - | let baseAssetAmount = toInt(fraction(toBigInt(userShareAssetAmountToConvert), price, scale18BigInt)) | |
501 | - | $Tuple2([StringEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString(0), toString(lastBlock.timestamp)], separator)), DeleteEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, baseAssetAmount, baseAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimBaseAsset", period, userAddress, i.transactionId), makeString(["%d%d%d%d", toString(baseAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userShareAssetAmountToConvertPeriod)], separator))], unit) | |
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) | |
1502 | + | else throw("Strict value is not equal to itself.") | |
502 | 1503 | } | |
503 | 1504 | else throw("Strict value is not equal to itself.") | |
504 | 1505 | } | |
514 | 1515 | ||
515 | 1516 | ||
516 | 1517 | @Callable(i) | |
517 | - | func finalize (baseAssetIdStr) = { | |
518 | - | let checks = [shutdownCheck(i)] | |
1518 | + | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1519 | + | let isGetDisabled = if (isGlobalShutdown()) | |
1520 | + | then true | |
1521 | + | else (cfgPoolStatus == PoolShutdown) | |
1522 | + | let checks = [if (!(isGetDisabled)) | |
1523 | + | then true | |
1524 | + | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1525 | + | then true | |
1526 | + | else throw("no payments are expected")] | |
519 | 1527 | if ((checks == checks)) | |
520 | 1528 | then { | |
521 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
522 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
523 | - | if ((shareAssetId == shareAssetId)) | |
1529 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1530 | + | if ((currentKLp == currentKLp)) | |
524 | 1531 | then { | |
525 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id")) | |
526 | - | let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period")) | |
527 | - | if ((period == period)) | |
1532 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1533 | + | if ((unstakeInv == unstakeInv)) | |
528 | 1534 | then { | |
529 | - | let | |
530 | - | let | |
531 | - | | |
532 | - | | |
533 | - | ||
534 | - | ||
535 | - | | |
536 | - | | |
537 | - | | |
538 | - | | |
539 | - | if (( | |
1535 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1536 | + | let outAmAmt = res._1 | |
1537 | + | let outPrAmt = res._2 | |
1538 | + | let state = res._10 | |
1539 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1540 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1541 | + | then true | |
1542 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1543 | + | then true | |
1544 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1545 | + | if ((checkAmounts == checkAmounts)) | |
540 | 1546 | then { | |
541 | - | let $t02168021861 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
542 | - | let poolAddress = $t02168021861._1 | |
543 | - | let lpAssetId = $t02168021861._2 | |
544 | - | let stakingReward = valueOrErrorMessage({ | |
545 | - | let @ = invoke(stakingContract, "claimWxDoNotThrow", [assetIdToString(lpAssetId)], nil) | |
546 | - | if ($isInstanceOf(@, "Int")) | |
547 | - | then @ | |
548 | - | else unit | |
549 | - | }, wrapErr("invalid claimWx result")) | |
550 | - | if ((stakingReward == stakingReward)) | |
1547 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1548 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
551 | 1549 | then { | |
552 | - | let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0) | |
553 | - | let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0) | |
554 | - | let checkFinalizationIsRequired = { | |
555 | - | let isFinalizationRequired = if (if ((stakingReward > 0)) | |
556 | - | then true | |
557 | - | else (baseAssetAmountToConvert > 0)) | |
558 | - | then true | |
559 | - | else (shareAssetAmountToConvert > 0) | |
560 | - | if (isFinalizationRequired) | |
561 | - | then true | |
562 | - | else throwErr("nothing to finalize") | |
563 | - | } | |
564 | - | if ((checkFinalizationIsRequired == checkFinalizationIsRequired)) | |
565 | - | then { | |
566 | - | let useStakingReward = if ((stakingReward > 0)) | |
567 | - | then { | |
568 | - | let lockPart = fraction(stakingReward, lockFraction, lockFractionMultiplier) | |
569 | - | let convertPart = (stakingReward - lockPart) | |
570 | - | let r = invoke(boostingContract, "userMaxDurationREADONLY", [toString(this)], nil) | |
571 | - | let lock = if ((lockPart > 0)) | |
572 | - | then match r { | |
573 | - | case _ => | |
574 | - | if (if (if ($isInstanceOf($match0._1, "String")) | |
575 | - | then $isInstanceOf($match0._2, "Int") | |
576 | - | else false) | |
577 | - | then $isInstanceOf($match0, "(String, Int)") | |
578 | - | else false) | |
579 | - | then { | |
580 | - | let function = $match0._1 | |
581 | - | let duration = $match0._2 | |
582 | - | if ((lockPart > 0)) | |
583 | - | then invoke(boostingContract, function, [duration], [AttachedPayment(wxAssetId, lockPart)]) | |
584 | - | else unit | |
585 | - | } | |
586 | - | else throwErr("invalid lock params") | |
587 | - | } | |
588 | - | else unit | |
589 | - | if ((lock == lock)) | |
590 | - | then { | |
591 | - | let convertedAmount = if ((convertPart > 0)) | |
592 | - | then { | |
593 | - | let inAssetId = wxAssetId | |
594 | - | let minimumToReceive = 0 | |
595 | - | let outAssetIdStr = assetIdToString(usdtAssetId) | |
596 | - | let targetAddress = toString(this) | |
597 | - | valueOrErrorMessage({ | |
598 | - | let @ = invoke(swapContract, "swap", [minimumToReceive, outAssetIdStr, targetAddress], [AttachedPayment(inAssetId, convertPart)]) | |
599 | - | if ($isInstanceOf(@, "Int")) | |
600 | - | then @ | |
601 | - | else unit | |
602 | - | }, wrapErr("invalid swap result")) | |
603 | - | } | |
604 | - | else 0 | |
605 | - | if ((convertedAmount == convertedAmount)) | |
606 | - | then { | |
607 | - | let lpAssetAmount = if ((convertedAmount > 0)) | |
608 | - | then { | |
609 | - | let minOutAmount = 0 | |
610 | - | let autoStake = true | |
611 | - | valueOrErrorMessage({ | |
612 | - | let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(usdtAssetId, convertedAmount)]) | |
613 | - | if ($isInstanceOf(@, "Int")) | |
614 | - | then @ | |
615 | - | else unit | |
616 | - | }, wrapErr("invalid putOneTknV2 result")) | |
617 | - | } | |
618 | - | else 0 | |
619 | - | if ((lpAssetAmount == lpAssetAmount)) | |
620 | - | then lpAssetAmount | |
621 | - | else throw("Strict value is not equal to itself.") | |
622 | - | } | |
623 | - | else throw("Strict value is not equal to itself.") | |
624 | - | } | |
625 | - | else throw("Strict value is not equal to itself.") | |
626 | - | } | |
627 | - | else unit | |
628 | - | if ((useStakingReward == useStakingReward)) | |
629 | - | then { | |
630 | - | let getActions = if ((shareAssetAmountToConvert > 0)) | |
631 | - | then { | |
632 | - | let price = calcPrice(lpAssetId, shareAssetId) | |
633 | - | if ((price == price)) | |
634 | - | then { | |
635 | - | let unstakeAmount = toInt(fraction(toBigInt(shareAssetAmountToConvert), price, scale18BigInt, FLOOR)) | |
636 | - | let baseAssetAmount = { | |
637 | - | let outAssetId = baseAssetId | |
638 | - | let minOutAmount = 0 | |
639 | - | valueOrErrorMessage({ | |
640 | - | let @ = invoke(poolAddress, "unstakeAndGetOneTknV2", [unstakeAmount, assetIdToString(outAssetId), minOutAmount], nil) | |
641 | - | if ($isInstanceOf(@, "Int")) | |
642 | - | then @ | |
643 | - | else unit | |
644 | - | }, wrapErr("invalid unstakeAndGetOneTknV2 result")) | |
645 | - | } | |
646 | - | if ((baseAssetAmount == baseAssetAmount)) | |
647 | - | then { | |
648 | - | let shareAssetBurn = if ((shareAssetInfo.issuer == this)) | |
649 | - | then invoke(this, "burn", [shareAssetId, shareAssetAmountToConvert], nil) | |
650 | - | else throwErr("invalid share asset issuer") | |
651 | - | if ((shareAssetBurn == shareAssetBurn)) | |
652 | - | then { | |
653 | - | let priceGet = fraction(toBigInt(baseAssetAmount), scale18BigInt, toBigInt(shareAssetAmountToConvert), FLOOR) | |
654 | - | let priceGetUpdateActions = [BinaryEntry(keyPricePeriodGet(baseAssetId, period), toBytes(priceGet)), StringEntry(keyPriceGetHistory(baseAssetId), toString(priceGet))] | |
655 | - | priceGetUpdateActions | |
656 | - | } | |
657 | - | else throw("Strict value is not equal to itself.") | |
658 | - | } | |
659 | - | else throw("Strict value is not equal to itself.") | |
660 | - | } | |
661 | - | else throw("Strict value is not equal to itself.") | |
662 | - | } | |
663 | - | else nil | |
664 | - | if ((getActions == getActions)) | |
665 | - | then { | |
666 | - | let putActions = if ((baseAssetAmountToConvert > 0)) | |
667 | - | then { | |
668 | - | let lpAssetAmount = { | |
669 | - | let minOutAmount = 0 | |
670 | - | let autoStake = true | |
671 | - | valueOrErrorMessage({ | |
672 | - | let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(baseAssetId, baseAssetAmountToConvert)]) | |
673 | - | if ($isInstanceOf(@, "Int")) | |
674 | - | then @ | |
675 | - | else unit | |
676 | - | }, wrapErr("invalid putOneTknV2 result")) | |
677 | - | } | |
678 | - | if ((lpAssetAmount == lpAssetAmount)) | |
679 | - | then { | |
680 | - | let price = calcPrice(lpAssetId, shareAssetId) | |
681 | - | if ((price == price)) | |
682 | - | then { | |
683 | - | let checkPrice = if ((value(toInt(price)) != 0)) | |
684 | - | then true | |
685 | - | else throw("price is ZERO") | |
686 | - | if ((checkPrice == checkPrice)) | |
687 | - | then { | |
688 | - | let shareAssetAmount = toInt(fraction(toBigInt(lpAssetAmount), scale18BigInt, price, FLOOR)) | |
689 | - | let checkShareAssetAmount = if ((value(toInt(price)) != 0)) | |
690 | - | then true | |
691 | - | else throw("shareAssetAmount is ZERO") | |
692 | - | if ((checkShareAssetAmount == checkShareAssetAmount)) | |
693 | - | then { | |
694 | - | let shareAssetReissue = if ((shareAssetInfo.issuer == this)) | |
695 | - | then invoke(this, "emit", [shareAssetId, shareAssetAmount], nil) | |
696 | - | else throwErr("invalid share asset issuer") | |
697 | - | if ((shareAssetReissue == shareAssetReissue)) | |
698 | - | then { | |
699 | - | let pricePut = fraction(toBigInt(baseAssetAmountToConvert), scale18BigInt, toBigInt(shareAssetAmount)) | |
700 | - | let pricePutUpdateActions = [BinaryEntry(keyPricePeriodPut(baseAssetId, period), toBytes(pricePut)), StringEntry(keyPricePutHistory(baseAssetId), toString(pricePut))] | |
701 | - | pricePutUpdateActions | |
702 | - | } | |
703 | - | else throw("Strict value is not equal to itself.") | |
704 | - | } | |
705 | - | else throw("Strict value is not equal to itself.") | |
706 | - | } | |
707 | - | else throw("Strict value is not equal to itself.") | |
708 | - | } | |
709 | - | else throw("Strict value is not equal to itself.") | |
710 | - | } | |
711 | - | else throw("Strict value is not equal to itself.") | |
712 | - | } | |
713 | - | else nil | |
714 | - | if ((putActions == putActions)) | |
715 | - | then { | |
716 | - | let newPeriod = (period + 1) | |
717 | - | let lastPrice = calcPrice(lpAssetId, shareAssetId) | |
718 | - | let actions = (([IntegerEntry(keyPeriod(baseAssetId), newPeriod), IntegerEntry(keyPeriodStartHeight(baseAssetId, newPeriod), height), IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), 0), IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), 0), BinaryEntry(keyPricePeriod(baseAssetId, period), toBytes(lastPrice)), StringEntry(keyPriceHistory(baseAssetId), toString(lastPrice))] ++ putActions) ++ getActions) | |
719 | - | $Tuple2(actions, toBytes(lastPrice)) | |
720 | - | } | |
721 | - | else throw("Strict value is not equal to itself.") | |
722 | - | } | |
723 | - | else throw("Strict value is not equal to itself.") | |
724 | - | } | |
725 | - | else throw("Strict value is not equal to itself.") | |
726 | - | } | |
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) | |
727 | 1556 | else throw("Strict value is not equal to itself.") | |
728 | 1557 | } | |
729 | 1558 | else throw("Strict value is not equal to itself.") | |
738 | 1567 | } | |
739 | 1568 | ||
740 | 1569 | ||
1570 | + | ||
1571 | + | @Callable(i) | |
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)) | |
1585 | + | then { | |
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)) | |
1594 | + | } | |
1595 | + | else throw("Strict value is not equal to itself.") | |
1596 | + | } | |
1597 | + | ||
1598 | + | ||
1599 | + | ||
1600 | + | @Callable(i) | |
1601 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1602 | + | ||
1603 | + | ||
1604 | + | ||
1605 | + | @Callable(i) | |
1606 | + | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1607 | + | ||
1608 | + | ||
1609 | + | ||
1610 | + | @Callable(i) | |
1611 | + | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1612 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
1613 | + | $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])]) | |
1614 | + | } | |
1615 | + | ||
1616 | + | ||
1617 | + | ||
1618 | + | @Callable(i) | |
1619 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
1620 | + | ||
1621 | + | ||
1622 | + | ||
1623 | + | @Callable(i) | |
1624 | + | func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult)) | |
1625 | + | ||
1626 | + | ||
1627 | + | ||
1628 | + | @Callable(i) | |
1629 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1630 | + | ||
1631 | + | ||
1632 | + | ||
1633 | + | @Callable(i) | |
1634 | + | func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp)) | |
1635 | + | ||
1636 | + | ||
1637 | + | ||
1638 | + | @Callable(i) | |
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)) | |
1642 | + | } | |
1643 | + | ||
1644 | + | ||
1645 | + | ||
1646 | + | @Callable(i) | |
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)) | |
1667 | + | } | |
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)) | |
1748 | + | } | |
1749 | + | ||
1750 | + | ||
741 | 1751 | @Verifier(tx) | |
742 | 1752 | func verify () = { | |
743 | 1753 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
748 | 1758 | case _ => | |
749 | 1759 | throw("Match error") | |
750 | 1760 | } | |
751 | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1761 | + | match tx { | |
1762 | + | case order: Order => | |
1763 | + | let matcherPub = getMatcherPubOrFail() | |
1764 | + | let $t06808568202 = if (skipOrderValidation()) | |
1765 | + | then $Tuple2(true, "") | |
1766 | + | else validateMatcherOrderAllowed(order) | |
1767 | + | let orderValid = $t06808568202._1 | |
1768 | + | let orderValidInfo = $t06808568202._2 | |
1769 | + | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1770 | + | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1771 | + | if (if (if (orderValid) | |
1772 | + | then senderValid | |
1773 | + | else false) | |
1774 | + | then matcherValid | |
1775 | + | else false) | |
1776 | + | then true | |
1777 | + | else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid) | |
1778 | + | case s: SetScriptTransaction => | |
1779 | + | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1780 | + | then true | |
1781 | + | else { | |
1782 | + | let newHash = blake2b256(value(s.script)) | |
1783 | + | let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash()))) | |
1784 | + | let currentHash = scriptHash(this) | |
1785 | + | if ((allowedHash == newHash)) | |
1786 | + | then (currentHash != newHash) | |
1787 | + | else false | |
1788 | + | } | |
1789 | + | case _ => | |
1790 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1791 | + | } | |
752 | 1792 | } | |
753 | 1793 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let lPdecimals = 8 | |
5 | 5 | ||
6 | - | let shareAssetDecimals = 8 | |
6 | + | let scale8 = 100000000 | |
7 | + | ||
8 | + | let scale8BigInt = toBigInt(100000000) | |
9 | + | ||
10 | + | let scale18 = toBigInt(1000000000000000000) | |
11 | + | ||
12 | + | let zeroBigInt = toBigInt(0) | |
13 | + | ||
14 | + | let big0 = toBigInt(0) | |
15 | + | ||
16 | + | let big1 = toBigInt(1) | |
17 | + | ||
18 | + | let big2 = toBigInt(2) | |
7 | 19 | ||
8 | 20 | let wavesString = "WAVES" | |
9 | 21 | ||
10 | - | let | |
22 | + | let SEP = "__" | |
11 | 23 | ||
12 | - | let | |
24 | + | let PoolActive = 1 | |
13 | 25 | ||
14 | - | func wrapErr (msg) = makeString(["lp_staking_pools.ride:", msg], " ") | |
26 | + | let PoolPutDisabled = 2 | |
27 | + | ||
28 | + | let PoolMatcherDisabled = 3 | |
29 | + | ||
30 | + | let PoolShutdown = 4 | |
31 | + | ||
32 | + | let idxPoolAddress = 1 | |
33 | + | ||
34 | + | let idxPoolStatus = 2 | |
35 | + | ||
36 | + | let idxPoolLPAssetId = 3 | |
37 | + | ||
38 | + | let idxAmtAssetId = 4 | |
39 | + | ||
40 | + | let idxPriceAssetId = 5 | |
41 | + | ||
42 | + | let idxAmtAssetDcm = 6 | |
43 | + | ||
44 | + | let idxPriceAssetDcm = 7 | |
45 | + | ||
46 | + | let idxIAmtAssetId = 8 | |
47 | + | ||
48 | + | let idxIPriceAssetId = 9 | |
49 | + | ||
50 | + | let idxLPAssetDcm = 10 | |
51 | + | ||
52 | + | let idxPoolAmtAssetAmt = 1 | |
53 | + | ||
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)) | |
15 | 63 | ||
16 | 64 | ||
17 | - | func | |
65 | + | func toX18BigInt (origVal,origScaleMult) = fraction(origVal, scale18, origScaleMult) | |
18 | 66 | ||
19 | 67 | ||
20 | - | func | |
68 | + | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), scale18)) | |
21 | 69 | ||
22 | 70 | ||
23 | - | func | |
71 | + | func fromX18Round (val,resultScaleMult,round) = toInt(fraction(val, toBigInt(resultScaleMult), scale18, round)) | |
24 | 72 | ||
25 | 73 | ||
26 | - | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), errKeyIsNotDefined(address, key)) | |
74 | + | func toScale (amt,resScale,curScale) = fraction(amt, resScale, curScale) | |
75 | + | ||
76 | + | ||
77 | + | func abs (val) = if ((0 > val)) | |
78 | + | then -(val) | |
79 | + | else val | |
80 | + | ||
81 | + | ||
82 | + | func absBigInt (val) = if ((zeroBigInt > val)) | |
83 | + | then -(val) | |
84 | + | else val | |
85 | + | ||
86 | + | ||
87 | + | func swapContract () = "%s__swapContract" | |
88 | + | ||
89 | + | ||
90 | + | func fc () = "%s__factoryContract" | |
91 | + | ||
92 | + | ||
93 | + | func mpk () = "%s__managerPublicKey" | |
94 | + | ||
95 | + | ||
96 | + | func pmpk () = "%s__pendingManagerPublicKey" | |
97 | + | ||
98 | + | ||
99 | + | func pl () = "%s%s__price__last" | |
100 | + | ||
101 | + | ||
102 | + | func ph (h,timestamp) = makeString(["%s%s%d%d__price__history", toString(h), toString(timestamp)], SEP) | |
103 | + | ||
104 | + | ||
105 | + | func pau (userAddress,txId) = ((("%s%s%s__P__" + userAddress) + "__") + txId) | |
106 | + | ||
107 | + | ||
108 | + | func gau (userAddress,txId) = ((("%s%s%s__G__" + userAddress) + "__") + txId) | |
109 | + | ||
110 | + | ||
111 | + | func aa () = "%s__amountAsset" | |
112 | + | ||
113 | + | ||
114 | + | func pa () = "%s__priceAsset" | |
115 | + | ||
116 | + | ||
117 | + | let keyFee = "%s__fee" | |
118 | + | ||
119 | + | let feeDefault = fraction(10, scale8, 10000) | |
120 | + | ||
121 | + | let fee = valueOrElse(getInteger(this, keyFee), feeDefault) | |
122 | + | ||
123 | + | let keyKLp = makeString(["%s", "kLp"], SEP) | |
124 | + | ||
125 | + | let keyKLpRefreshedHeight = makeString(["%s", "kLpRefreshedHeight"], SEP) | |
126 | + | ||
127 | + | let keyKLpRefreshDelay = makeString(["%s", "refreshKLpDelay"], SEP) | |
128 | + | ||
129 | + | let kLpRefreshDelayDefault = 30 | |
130 | + | ||
131 | + | let kLpRefreshDelay = valueOrElse(getInteger(this, keyKLpRefreshDelay), kLpRefreshDelayDefault) | |
132 | + | ||
133 | + | func keyAdditionalBalance (assetId) = makeString(["%s%s", "stakedBalance", assetId], SEP) | |
134 | + | ||
135 | + | ||
136 | + | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "shareAssetBalance", assetId], SEP) | |
137 | + | ||
138 | + | ||
139 | + | func getAdditionalBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyAdditionalBalance(assetId)), 0) | |
140 | + | ||
141 | + | ||
142 | + | func getStakingAssetBalanceOrZero (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
143 | + | ||
144 | + | ||
145 | + | func keyFactoryConfig () = "%s__factoryConfig" | |
146 | + | ||
147 | + | ||
148 | + | func keyMatcherPub () = "%s%s__matcher__publicKey" | |
149 | + | ||
150 | + | ||
151 | + | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") | |
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" | |
170 | + | ||
171 | + | func keySkipOrderValidation (poolAddress) = ("%s%s__skipOrderValidation__" + poolAddress) | |
172 | + | ||
173 | + | ||
174 | + | func throwOrderError (orderValid,orderValidInfo,senderValid,matcherValid) = throw((((((((("order validation failed: orderValid=" + toString(orderValid)) + " (") + orderValidInfo) + ")") + " senderValid=") + toString(senderValid)) + " matcherValid=") + toString(matcherValid))) | |
175 | + | ||
176 | + | ||
177 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
178 | + | ||
179 | + | ||
180 | + | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
181 | + | ||
182 | + | ||
183 | + | func throwErr (msg) = throw(makeString(["lp.ride:", msg], " ")) | |
184 | + | ||
185 | + | ||
186 | + | func fmtErr (msg) = makeString(["lp.ride:", msg], " ") | |
187 | + | ||
188 | + | ||
189 | + | let factoryContract = addressFromStringValue(getStringOrFail(this, fc())) | |
190 | + | ||
191 | + | let feeCollectorAddress = addressFromStringValue(getStringOrFail(factoryContract, keyFeeCollectorAddress)) | |
192 | + | ||
193 | + | let inFee = { | |
194 | + | let @ = invoke(factoryContract, "getInFeeREADONLY", [toString(this)], nil) | |
195 | + | if ($isInstanceOf(@, "Int")) | |
196 | + | then @ | |
197 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
198 | + | } | |
199 | + | ||
200 | + | let outFee = { | |
201 | + | let @ = invoke(factoryContract, "getOutFeeREADONLY", [toString(this)], nil) | |
202 | + | if ($isInstanceOf(@, "Int")) | |
203 | + | then @ | |
204 | + | else throw(($getType(@) + " couldn't be cast to Int")) | |
205 | + | } | |
206 | + | ||
207 | + | func isGlobalShutdown () = valueOrElse(getBoolean(factoryContract, keyAllPoolsShutdown()), false) | |
208 | + | ||
209 | + | ||
210 | + | func getMatcherPubOrFail () = fromBase58String(getStringOrFail(factoryContract, keyMatcherPub())) | |
211 | + | ||
212 | + | ||
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) | |
219 | + | } | |
27 | 220 | ||
28 | 221 | ||
29 | 222 | func parseAssetId (input) = if ((input == wavesString)) | |
30 | 223 | then unit | |
31 | 224 | else fromBase58String(input) | |
32 | 225 | ||
33 | 226 | ||
34 | 227 | func assetIdToString (input) = if ((input == unit)) | |
35 | 228 | then wavesString | |
36 | 229 | else toBase58String(value(input)) | |
37 | 230 | ||
38 | 231 | ||
39 | - | func ensurePositive (v) = if ((v >= 0)) | |
40 | - | then v | |
41 | - | else throwErr("value should be positive") | |
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])) | |
42 | 233 | ||
43 | 234 | ||
44 | - | func keyFactoryContract () = makeString(["%s", "factoryContract"], separator) | |
235 | + | let poolConfigParsed = parsePoolConfig(getPoolConfig()) | |
236 | + | ||
237 | + | let $t090589224 = poolConfigParsed | |
238 | + | ||
239 | + | let cfgPoolAddress = $t090589224._1 | |
240 | + | ||
241 | + | let cfgPoolStatus = $t090589224._2 | |
242 | + | ||
243 | + | let cfgLpAssetId = $t090589224._3 | |
244 | + | ||
245 | + | let cfgAmountAssetId = $t090589224._4 | |
246 | + | ||
247 | + | let cfgPriceAssetId = $t090589224._5 | |
248 | + | ||
249 | + | let cfgAmountAssetDecimals = $t090589224._6 | |
250 | + | ||
251 | + | let cfgPriceAssetDecimals = $t090589224._7 | |
252 | + | ||
253 | + | func getFactoryConfig () = split(getStringOrFail(factoryContract, keyFactoryConfig()), SEP) | |
45 | 254 | ||
46 | 255 | ||
47 | - | func keyLpStakingContract () = makeString(["%s", "lpStakingContract"], separator) | |
256 | + | let stakingContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactoryStakingContract]), "incorrect staking address") | |
257 | + | ||
258 | + | let slippageContract = valueOrErrorMessage(addressFromString(getFactoryConfig()[idxFactorySlippageContract]), "incorrect staking address") | |
259 | + | ||
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) | |
48 | 261 | ||
49 | 262 | ||
50 | - | func | |
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) | |
51 | 264 | ||
52 | 265 | ||
53 | - | func keyBoostingContract () = makeString(["%s", "boostingContract"], separator) | |
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 | + | } | |
54 | 273 | ||
55 | 274 | ||
56 | - | func | |
275 | + | func calcPriceBigInt (prAmtX18,amAmtX18) = fraction(prAmtX18, scale18, amAmtX18) | |
57 | 276 | ||
58 | 277 | ||
59 | - | func | |
278 | + | func calcPriceBigIntRound (prAmtX18,amAmtX18,round) = fraction(prAmtX18, scale18, amAmtX18, round) | |
60 | 279 | ||
61 | 280 | ||
62 | - | func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], separator) | |
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 | + | } | |
63 | 292 | ||
64 | 293 | ||
65 | - | func keyWxAssetId () = makeString(["%s", "wxAssetId"], separator) | |
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 | + | } | |
66 | 322 | ||
67 | 323 | ||
68 | - | func keyShutdown () = makeString(["%s", "shutdown"], separator) | |
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 | + | } | |
69 | 361 | ||
70 | 362 | ||
71 | - | func keyMinDelay () = makeString(["%s", "minDelay"], separator) | |
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 | + | } | |
72 | 369 | ||
73 | 370 | ||
74 | - | func keyLockFraction () = makeString(["%s", "lockFraction"], separator) | |
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 | + | } | |
75 | 397 | ||
76 | 398 | ||
77 | - | func keyShareAssetId (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetId"], separator) | |
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 | + | } | |
78 | 412 | ||
79 | 413 | ||
80 | - | func keyBaseAssetId (shareAssetId) = makeString(["%s%s", assetIdToString(shareAssetId), "baseAssetId"], separator) | |
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 | + | } | |
81 | 444 | ||
82 | 445 | ||
83 | - | func keyPeriod (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "period"], separator) | |
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 | + | } | |
84 | 451 | ||
85 | 452 | ||
86 | - | func keyPeriodStartHeight (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "periodStartHeight", toString(period)], separator) | |
453 | + | func privateCalcPrice (amAssetDcm,prAssetDcm,amAmt,prAmt) = { | |
454 | + | let amtAssetAmtX18 = toX18(amAmt, amAssetDcm) | |
455 | + | let priceAssetAmtX18 = toX18(prAmt, prAssetDcm) | |
456 | + | calcPriceBigInt(priceAssetAmtX18, amtAssetAmtX18) | |
457 | + | } | |
87 | 458 | ||
88 | 459 | ||
89 | - | func keyBaseAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "baseAssetAmountToConvert"], separator) | |
460 | + | func calcPrices (amAmt,prAmt,lpAmt) = { | |
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 | + | } | |
90 | 472 | ||
91 | 473 | ||
92 | - | func keyShareAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetAmountToConvert"], separator) | |
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 | + | } | |
93 | 478 | ||
94 | 479 | ||
95 | - | func keyUserBaseAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert"], separator) | |
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 | + | } | |
96 | 514 | ||
97 | 515 | ||
98 | - | func keyUserBaseAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert", "period"], separator) | |
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 | + | } | |
99 | 591 | ||
100 | 592 | ||
101 | - | func keyUserShareAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert"], separator) | |
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 | + | } | |
102 | 601 | ||
103 | 602 | ||
104 | - | func keyUserShareAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert", "period"], separator) | |
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 | + | } | |
105 | 610 | ||
106 | 611 | ||
107 | - | func keyPricePeriod (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "price", toString(period)], separator) | |
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 | + | } | |
108 | 620 | ||
109 | 621 | ||
110 | - | func | |
622 | + | func skipOrderValidation () = valueOrElse(getBoolean(factoryContract, keySkipOrderValidation(toString(this))), false) | |
111 | 623 | ||
112 | 624 | ||
113 | - | func keyPricePeriodPut (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "put"], separator) | |
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)], " ")) | |
114 | 628 | ||
115 | 629 | ||
116 | - | func keyPricePutHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], separator) | |
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 | + | } | |
117 | 660 | ||
118 | 661 | ||
119 | - | func keyPricePeriodGet (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "get"], separator) | |
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 | + | } | |
120 | 679 | ||
121 | 680 | ||
122 | - | func keyPriceGetHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], separator) | |
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 | + | } | |
123 | 696 | ||
124 | 697 | ||
125 | - | func keyHistoryEntry (baseAssetId,operation,period,userAddress,txId) = makeString(["%s%s%s%s", "history", toUtf8String(value(baseAssetId)), operation, toString(userAddress), toBase58String(txId), toString(height)], separator) | |
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.") | |
713 | + | } | |
126 | 714 | ||
127 | 715 | ||
128 | - | func keyManagerPublicKey () = "%s__managerPublicKey" | |
716 | + | func takeFee (amount,fee) = { | |
717 | + | let feeAmount = if ((fee == 0)) | |
718 | + | then 0 | |
719 | + | else fraction(amount, fee, scale8) | |
720 | + | $Tuple2((amount - feeAmount), feeAmount) | |
721 | + | } | |
129 | 722 | ||
130 | 723 | ||
131 | - | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
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) | |
779 | + | } | |
780 | + | $Tuple5(issueAmount, commonState, feeAmount, loss, paymentInAmountAsset) | |
781 | + | } | |
782 | + | else throw("Strict value is not equal to itself.") | |
783 | + | } | |
132 | 784 | ||
133 | 785 | ||
134 | - | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
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)) | |
795 | + | then { | |
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) | |
838 | + | } | |
839 | + | else throw("Strict value is not equal to itself.") | |
840 | + | } | |
841 | + | ||
842 | + | ||
843 | + | func managerPublicKeyOrUnit () = match getString(mpk()) { | |
135 | 844 | case s: String => | |
136 | 845 | fromBase58String(s) | |
137 | 846 | case _: Unit => | |
138 | 847 | unit | |
139 | 848 | case _ => | |
140 | 849 | throw("Match error") | |
141 | 850 | } | |
142 | 851 | ||
143 | 852 | ||
144 | - | func pendingManagerPublicKeyOrUnit () = match getString( | |
853 | + | func pendingManagerPublicKeyOrUnit () = match getString(pmpk()) { | |
145 | 854 | case s: String => | |
146 | 855 | fromBase58String(s) | |
147 | 856 | case _: Unit => | |
148 | 857 | unit | |
149 | 858 | case _ => | |
150 | 859 | throw("Match error") | |
151 | 860 | } | |
152 | 861 | ||
153 | 862 | ||
154 | - | let permissionDeniedError = throw("Permission denied") | |
155 | - | ||
156 | - | func mustThis (i) = if ((i.caller == this)) | |
157 | - | then true | |
158 | - | else permissionDeniedError | |
159 | - | ||
160 | - | ||
161 | - | func mustManager (i) = match managerPublicKeyOrUnit() { | |
863 | + | func isManager (i) = match managerPublicKeyOrUnit() { | |
162 | 864 | case pk: ByteVector => | |
163 | - | if ((i.callerPublicKey == pk)) | |
164 | - | then true | |
165 | - | else permissionDeniedError | |
865 | + | (i.callerPublicKey == pk) | |
166 | 866 | case _: Unit => | |
167 | - | | |
867 | + | (i.caller == this) | |
168 | 868 | case _ => | |
169 | 869 | throw("Match error") | |
170 | 870 | } | |
171 | 871 | ||
172 | 872 | ||
173 | - | let shutdown = valueOrElse(getBoolean(keyShutdown()), false) | |
174 | - | ||
175 | - | func shutdownCheck (i) = if (if (!(shutdown)) | |
176 | - | then true | |
177 | - | else mustManager(i)) | |
178 | - | then true | |
179 | - | else throw("operation is disabled") | |
180 | - | ||
181 | - | ||
182 | - | let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract())) | |
183 | - | ||
184 | - | let lpStakingContract = addressFromStringValue(getStrOrFail(this, keyLpStakingContract())) | |
185 | - | ||
186 | - | let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract())) | |
187 | - | ||
188 | - | let boostingContract = addressFromStringValue(getStrOrFail(this, keyBoostingContract())) | |
189 | - | ||
190 | - | let swapContract = addressFromStringValue(getStrOrFail(this, keySwapContract())) | |
191 | - | ||
192 | - | let assetsStoreContract = addressFromStringValue(getStrOrFail(this, keyAssetsStoreContract())) | |
193 | - | ||
194 | - | let usdtAssetId = parseAssetId(getStrOrFail(this, keyUsdtAssetId())) | |
195 | - | ||
196 | - | let wxAssetId = parseAssetId(getStrOrFail(this, keyWxAssetId())) | |
197 | - | ||
198 | - | let minDelayDefault = 1440 | |
199 | - | ||
200 | - | let minDelay = valueOrElse(getInteger(this, keyMinDelay()), minDelayDefault) | |
201 | - | ||
202 | - | let lockFractionMultiplier = 100000000 | |
203 | - | ||
204 | - | let lockFractionDefault = fraction(1, lockFractionMultiplier, 2) | |
205 | - | ||
206 | - | let lockFraction = valueOrElse(getInteger(this, keyLockFraction()), lockFractionDefault) | |
207 | - | ||
208 | - | func getPoolInfo (amountAssetId) = { | |
209 | - | let amountAssetIdStr = assetIdToString(amountAssetId) | |
210 | - | let priceAssetIdStr = assetIdToString(usdtAssetId) | |
211 | - | let poolInfoOption = { | |
212 | - | let @ = invoke(factoryContract, "poolInfoREADONLY", [amountAssetIdStr, priceAssetIdStr], nil) | |
213 | - | if ($isInstanceOf(@, "(Address, ByteVector)")) | |
214 | - | then @ | |
215 | - | else unit | |
216 | - | } | |
217 | - | poolInfoOption | |
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 | + | } | |
218 | 887 | } | |
219 | 888 | ||
220 | 889 | ||
221 | - | func calcPrice (lpAssetId,shareAssetId) = { | |
222 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), "failed to get share asset info") | |
223 | - | let shareAssetEmission = shareAssetInfo.quantity | |
224 | - | let stakedAmount = ensurePositive(valueOrErrorMessage({ | |
225 | - | let @ = invoke(stakingContract, "stakedByUserREADONLY", [assetIdToString(lpAssetId), toString(this)], nil) | |
226 | - | if ($isInstanceOf(@, "Int")) | |
890 | + | @Callable(i) | |
891 | + | func rebalance () = (rebalanceAsset(getStringOrFail(this, aa())) ++ rebalanceAsset(getStringOrFail(this, pa()))) | |
892 | + | ||
893 | + | ||
894 | + | ||
895 | + | @Callable(i) | |
896 | + | func calculateAmountOutForSwapREADONLY (cleanAmountIn,isReverse,feePoolAmount) = { | |
897 | + | let $t03912539430 = if ((isReverse == false)) | |
898 | + | then { | |
899 | + | let assetOut = getStringOrFail(this, pa()) | |
900 | + | let assetIn = getStringOrFail(this, aa()) | |
901 | + | $Tuple2(assetOut, assetIn) | |
902 | + | } | |
903 | + | else { | |
904 | + | let assetOut = getStringOrFail(this, aa()) | |
905 | + | let assetIn = getStringOrFail(this, pa()) | |
906 | + | $Tuple2(assetOut, assetIn) | |
907 | + | } | |
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)) | |
916 | + | then true | |
917 | + | else throw("new K is fewer error") | |
918 | + | if ((checkK == checkK)) | |
919 | + | then $Tuple2(nil, amountOut) | |
920 | + | else throw("Strict value is not equal to itself.") | |
921 | + | } | |
922 | + | ||
923 | + | ||
924 | + | ||
925 | + | @Callable(i) | |
926 | + | func calculateAmountOutForSwapAndSendTokens (cleanAmountIn,isReverse,amountOutMin,addressTo,feePoolAmount) = { | |
927 | + | let swapContact = { | |
928 | + | let @ = invoke(factoryContract, "getSwapContractREADONLY", nil, nil) | |
929 | + | if ($isInstanceOf(@, "String")) | |
227 | 930 | then @ | |
228 | - | else unit | |
229 | - | }, wrapErr("invalid stakedByUserREADONLY result"))) | |
230 | - | let price = if ((shareAssetEmission == 0)) | |
231 | - | then scale18BigInt | |
232 | - | else fraction(toBigInt(stakedAmount), scale18BigInt, toBigInt(shareAssetEmission), FLOOR) | |
233 | - | price | |
931 | + | else throw(($getType(@) + " couldn't be cast to String")) | |
932 | + | } | |
933 | + | let checks = [if ((value(i.payments[0]).amount >= cleanAmountIn)) | |
934 | + | then true | |
935 | + | else throwErr("Wrong amount"), if ((i.caller == addressFromStringValue(swapContact))) | |
936 | + | then true | |
937 | + | else throwErr("Permission denied")] | |
938 | + | if ((checks == checks)) | |
939 | + | then { | |
940 | + | let pmt = value(i.payments[0]) | |
941 | + | let assetIn = assetIdToString(pmt.assetId) | |
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)) | |
954 | + | then { | |
955 | + | let checkMin = if ((amountOut >= amountOutMin)) | |
956 | + | then true | |
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 | + | } | |
970 | + | else throw("Strict value is not equal to itself.") | |
971 | + | } | |
972 | + | else throw("Strict value is not equal to itself.") | |
973 | + | } | |
974 | + | else throw("Strict value is not equal to itself.") | |
234 | 975 | } | |
976 | + | ||
235 | 977 | ||
236 | 978 | ||
237 | 979 | @Callable(i) | |
238 | 980 | func setManager (pendingManagerPublicKey) = { | |
239 | 981 | let checkCaller = mustManager(i) | |
240 | 982 | if ((checkCaller == checkCaller)) | |
241 | 983 | then { | |
242 | 984 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
243 | 985 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
244 | - | then [StringEntry( | |
986 | + | then [StringEntry(pmpk(), pendingManagerPublicKey)] | |
245 | 987 | else throw("Strict value is not equal to itself.") | |
246 | 988 | } | |
247 | 989 | else throw("Strict value is not equal to itself.") | |
248 | 990 | } | |
249 | 991 | ||
250 | 992 | ||
251 | 993 | ||
252 | 994 | @Callable(i) | |
253 | 995 | func confirmManager () = { | |
254 | 996 | let pm = pendingManagerPublicKeyOrUnit() | |
255 | 997 | let hasPM = if (isDefined(pm)) | |
256 | 998 | then true | |
257 | - | else | |
999 | + | else throw("No pending manager") | |
258 | 1000 | if ((hasPM == hasPM)) | |
259 | 1001 | then { | |
260 | 1002 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
261 | 1003 | then true | |
262 | - | else | |
1004 | + | else throw("You are not pending manager") | |
263 | 1005 | if ((checkPM == checkPM)) | |
264 | - | then [StringEntry( | |
1006 | + | then [StringEntry(mpk(), toBase58String(value(pm))), DeleteEntry(pmpk())] | |
265 | 1007 | else throw("Strict value is not equal to itself.") | |
266 | 1008 | } | |
267 | 1009 | else throw("Strict value is not equal to itself.") | |
268 | 1010 | } | |
269 | 1011 | ||
270 | 1012 | ||
271 | 1013 | ||
272 | 1014 | @Callable(i) | |
273 | - | func emit (assetId,amount) = { | |
274 | - | let checkCaller = mustThis(i) | |
275 | - | if ((checkCaller == checkCaller)) | |
276 | - | then { | |
277 | - | let isReissuable = true | |
278 | - | $Tuple2([Reissue(assetId, amount, isReissuable)], amount) | |
279 | - | } | |
280 | - | else throw("Strict value is not equal to itself.") | |
281 | - | } | |
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)) | |
1033 | + | then { | |
1034 | + | let emitInvLegacy = match emitInv { | |
1035 | + | case legacyFactoryContract: Address => | |
1036 | + | invoke(legacyFactoryContract, "emit", [emitLpAmt], nil) | |
1037 | + | case _ => | |
1038 | + | unit | |
1039 | + | } | |
1040 | + | if ((emitInvLegacy == emitInvLegacy)) | |
1041 | + | then { | |
1042 | + | let slippageAInv = if ((amDiff > 0)) | |
1043 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(amId, amDiff)]) | |
1044 | + | else nil | |
1045 | + | if ((slippageAInv == slippageAInv)) | |
1046 | + | then { | |
1047 | + | let slippagePInv = if ((prDiff > 0)) | |
1048 | + | then invoke(slippageContract, "put", nil, [AttachedPayment(prId, prDiff)]) | |
1049 | + | else nil | |
1050 | + | if ((slippagePInv == slippagePInv)) | |
1051 | + | then { | |
1052 | + | let lpTransfer = if (shouldAutoStake) | |
1053 | + | then { | |
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.") | |
1058 | + | } | |
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)) | |
1067 | + | then { | |
1068 | + | let reb = invoke(this, "rebalance", nil, nil) | |
1069 | + | if ((reb == reb)) | |
1070 | + | then ((state ++ lpTransfer) ++ refreshKLpActions) | |
1071 | + | else throw("Strict value is not equal to itself.") | |
1072 | + | } | |
1073 | + | else throw("Strict value is not equal to itself.") | |
1074 | + | } | |
1075 | + | else throw("Strict value is not equal to itself.") | |
1076 | + | } | |
1077 | + | else throw("Strict value is not equal to itself.") | |
1078 | + | } | |
1079 | + | else throw("Strict value is not equal to itself.") | |
1080 | + | } | |
1081 | + | else throw("Strict value is not equal to itself.") | |
1082 | + | } | |
1083 | + | else throw("Strict value is not equal to itself.") | |
1084 | + | } | |
1085 | + | else throw("Strict value is not equal to itself.") | |
1086 | + | } | |
282 | 1087 | ||
283 | 1088 | ||
284 | 1089 | ||
285 | 1090 | @Callable(i) | |
286 | - | func burn (assetId,amount) = { | |
287 | - | let checkCaller = mustThis(i) | |
288 | - | if ((checkCaller == checkCaller)) | |
289 | - | then $Tuple2([Burn(assetId, amount)], amount) | |
290 | - | else throw("Strict value is not equal to itself.") | |
291 | - | } | |
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 | + | } | |
292 | 1111 | ||
293 | 1112 | ||
294 | 1113 | ||
295 | 1114 | @Callable(i) | |
296 | - | func create (baseAssetIdStr,shareAssetIdStr,shareAssetName,shareAssetDescription,shareAssetLogo) = { | |
297 | - | let shareAssetLabel = "STAKING_LP" | |
298 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
299 | - | let checks = [mustManager(i), if (isDefined(getPoolInfo(baseAssetId))) | |
1115 | + | func putOneTkn (minOutAmount,autoStake) = { | |
1116 | + | let isPoolOneTokenOperationsDisabled = { | |
1117 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1118 | + | if ($isInstanceOf(@, "Boolean")) | |
1119 | + | then @ | |
1120 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1121 | + | } | |
1122 | + | let isPutDisabled = if (if (if (isGlobalShutdown()) | |
300 | 1123 | then true | |
301 | - | else throwErr("invalid base asset")] | |
1124 | + | else (cfgPoolStatus == PoolPutDisabled)) | |
1125 | + | then true | |
1126 | + | else (cfgPoolStatus == PoolShutdown)) | |
1127 | + | then true | |
1128 | + | else isPoolOneTokenOperationsDisabled | |
1129 | + | let checks = [if (if (!(isPutDisabled)) | |
1130 | + | then true | |
1131 | + | else isManager(i)) | |
1132 | + | then true | |
1133 | + | else throwErr("put operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1134 | + | then true | |
1135 | + | else throwErr("exactly 1 payment are expected")] | |
302 | 1136 | if ((checks == checks)) | |
303 | 1137 | then { | |
304 | - | let commonState = [IntegerEntry(keyPeriod(baseAssetId), 0)] | |
305 | - | if ((shareAssetIdStr == "")) | |
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)) | |
306 | 1147 | then { | |
307 | - | let shareAssetIssueAmount = 1 | |
308 | - | let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescription, shareAssetIssueAmount, shareAssetDecimals, true) | |
309 | - | let calculatedShareAssetId = calculateAssetId(shareAssetIssueAction) | |
310 | - | let shareAssetBurnAction = Burn(calculatedShareAssetId, shareAssetIssueAmount) | |
311 | - | let calculatedShareAssetIdStr = toBase58String(calculatedShareAssetId) | |
312 | - | let createOrUpdate = invoke(assetsStoreContract, "createOrUpdate", [calculatedShareAssetIdStr, shareAssetLogo, false], nil) | |
313 | - | if ((createOrUpdate == createOrUpdate)) | |
1148 | + | let userAddress = i.caller | |
1149 | + | let txId = i.transactionId | |
1150 | + | let $t04680346955 = calcPutOneToken(paymentAmountRaw, paymentAssetId, userAddress, txId) | |
1151 | + | if (($t04680346955 == $t04680346955)) | |
314 | 1152 | then { | |
315 | - | let addLabel = invoke(assetsStoreContract, "addLabel", [calculatedShareAssetIdStr, shareAssetLabel], nil) | |
316 | - | if ((addLabel == addLabel)) | |
317 | - | then $Tuple2((commonState ++ [shareAssetIssueAction, shareAssetBurnAction, StringEntry(keyShareAssetId(baseAssetId), calculatedShareAssetIdStr), StringEntry(keyBaseAssetId(calculatedShareAssetId), baseAssetIdStr)]), calculatedShareAssetIdStr) | |
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) | |
1160 | + | else false) | |
1161 | + | then throwErr(makeString(["amount to receive is less than ", toString(minOutAmount)], "")) | |
1162 | + | else emitAmountEstimated | |
1163 | + | let emitInv = emit(emitAmount) | |
1164 | + | if ((emitInv == emitInv)) | |
1165 | + | then { | |
1166 | + | let lpTransfer = if (autoStake) | |
1167 | + | then { | |
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) | |
1194 | + | else throw("Strict value is not equal to itself.") | |
1195 | + | } | |
1196 | + | else throw("Strict value is not equal to itself.") | |
1197 | + | } | |
318 | 1198 | else throw("Strict value is not equal to itself.") | |
319 | 1199 | } | |
320 | 1200 | else throw("Strict value is not equal to itself.") | |
321 | - | } | |
322 | - | else { | |
323 | - | let shareAssetId = fromBase58String(shareAssetIdStr) | |
324 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id")) | |
325 | - | let checkIssuer = if ((shareAssetInfo.issuer == lpStakingContract)) | |
326 | - | then true | |
327 | - | else throwErr("invalid share asset id issuer") | |
328 | - | if ((checkIssuer == checkIssuer)) | |
329 | - | then $Tuple2((commonState ++ [StringEntry(keyShareAssetId(baseAssetId), shareAssetIdStr), StringEntry(keyBaseAssetId(shareAssetId), baseAssetIdStr)]), shareAssetIdStr) | |
330 | - | else throw("Strict value is not equal to itself.") | |
331 | - | } | |
332 | - | } | |
333 | - | else throw("Strict value is not equal to itself.") | |
334 | - | } | |
335 | - | ||
336 | - | ||
337 | - | ||
338 | - | @Callable(i) | |
339 | - | func put () = { | |
340 | - | let pmt = if ((size(i.payments) == 1)) | |
341 | - | then i.payments[0] | |
342 | - | else throwErr("exactly 1 payment is expected") | |
343 | - | let baseAssetId = pmt.assetId | |
344 | - | let userAddress = i.caller | |
345 | - | let checks = [shutdownCheck(i), if (isDefined(getString(keyShareAssetId(baseAssetId)))) | |
346 | - | then true | |
347 | - | else throwErr("invalid asset")] | |
348 | - | if ((checks == checks)) | |
349 | - | then { | |
350 | - | let $t01167511778 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
351 | - | let poolAddress = $t01167511778._1 | |
352 | - | let lpAssetId = $t01167511778._2 | |
353 | - | let period = value(getInteger(keyPeriod(baseAssetId))) | |
354 | - | let userBaseAssetAmountToConvertPeriodOption = getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)) | |
355 | - | let claimShareAssetInvocation = if ((userBaseAssetAmountToConvertPeriodOption == unit)) | |
356 | - | then unit | |
357 | - | else { | |
358 | - | let userBaseAssetAmountToConvertPeriod = value(userBaseAssetAmountToConvertPeriodOption) | |
359 | - | if ((userBaseAssetAmountToConvertPeriod == period)) | |
360 | - | then unit | |
361 | - | else invoke(this, "claimShareAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil) | |
362 | - | } | |
363 | - | if ((claimShareAssetInvocation == claimShareAssetInvocation)) | |
364 | - | then { | |
365 | - | let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0) | |
366 | - | let userBaseAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
367 | - | $Tuple2([IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), (baseAssetAmountToConvert + pmt.amount)), StringEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString((userBaseAssetAmountToConvert + pmt.amount)), toString(lastBlock.timestamp)], separator)), IntegerEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "put", period, userAddress, i.transactionId), makeString(["%d%d%d", toString(pmt.amount), toString(lastBlock.timestamp), toString(userBaseAssetAmountToConvert)], separator))], unit) | |
368 | 1201 | } | |
369 | 1202 | else throw("Strict value is not equal to itself.") | |
370 | 1203 | } | |
371 | 1204 | else throw("Strict value is not equal to itself.") | |
372 | 1205 | } | |
373 | 1206 | ||
374 | 1207 | ||
375 | 1208 | ||
376 | 1209 | @Callable(i) | |
377 | - | func claimShareAsset (baseAssetIdStr,userAddressStr) = { | |
378 | - | let checks = [shutdownCheck(i)] | |
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)) | |
1218 | + | } | |
1219 | + | ||
1220 | + | ||
1221 | + | ||
1222 | + | @Callable(i) | |
1223 | + | func getOneTkn (outAssetIdStr,minOutAmount) = { | |
1224 | + | let isPoolOneTokenOperationsDisabled = { | |
1225 | + | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [toString(this)], nil) | |
1226 | + | if ($isInstanceOf(@, "Boolean")) | |
1227 | + | then @ | |
1228 | + | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
1229 | + | } | |
1230 | + | let isGetDisabled = if (if (isGlobalShutdown()) | |
1231 | + | then true | |
1232 | + | else (cfgPoolStatus == PoolShutdown)) | |
1233 | + | then true | |
1234 | + | else isPoolOneTokenOperationsDisabled | |
1235 | + | let checks = [if (if (!(isGetDisabled)) | |
1236 | + | then true | |
1237 | + | else isManager(i)) | |
1238 | + | then true | |
1239 | + | else throwErr("get operation is blocked by admin"), if ((size(i.payments) == 1)) | |
1240 | + | then true | |
1241 | + | else throwErr("exactly 1 payment are expected")] | |
379 | 1242 | if ((checks == checks)) | |
380 | 1243 | then { | |
381 | - | let userAddress = if ((userAddressStr == "")) | |
382 | - | then i.caller | |
383 | - | else { | |
384 | - | let checkCaller = mustThis(i) | |
385 | - | if ((checkCaller == checkCaller)) | |
386 | - | then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
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 | + | } | |
387 | 1294 | else throw("Strict value is not equal to itself.") | |
388 | 1295 | } | |
389 | - | if ((userAddress == userAddress)) | |
1296 | + | else throw("Strict value is not equal to itself.") | |
1297 | + | } | |
1298 | + | else throw("Strict value is not equal to itself.") | |
1299 | + | } | |
1300 | + | ||
1301 | + | ||
1302 | + | ||
1303 | + | @Callable(i) | |
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)) | |
1337 | + | then { | |
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)) | |
390 | 1343 | then { | |
391 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
392 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
393 | - | if ((shareAssetId == shareAssetId)) | |
1344 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1345 | + | if ((unstakeInv == unstakeInv)) | |
394 | 1346 | then { | |
395 | - | let | |
396 | - | if (( | |
1347 | + | let $t05176051911 = calcGetOneToken(outAssetId, unstakeAmount, cfgLpAssetId, userAddress, txId) | |
1348 | + | if (($t05176051911 == $t05176051911)) | |
397 | 1349 | then { | |
398 | - | let userBaseAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
399 | - | let checkAmountToConvert = if ((userBaseAssetAmountToConvert > 0)) | |
400 | - | then true | |
401 | - | else throwErr("nothing to claim") | |
402 | - | if ((checkAmountToConvert == checkAmountToConvert)) | |
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)) | |
403 | 1362 | then { | |
404 | - | let userBaseAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period")) | |
405 | - | let checkPeriod = if ((period > userBaseAssetAmountToConvertPeriod)) | |
406 | - | then true | |
407 | - | else throwErr("invalid period") | |
408 | - | if ((checkPeriod == checkPeriod)) | |
409 | - | then { | |
410 | - | let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodPut(baseAssetId, userBaseAssetAmountToConvertPeriod)), wrapErr("failed to get price"))) | |
411 | - | let shareAssetAmount = toInt(fraction(toBigInt(userBaseAssetAmountToConvert), scale18BigInt, price)) | |
412 | - | $Tuple2([StringEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString(0), toString(lastBlock.timestamp)], separator)), DeleteEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, shareAssetAmount, shareAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimShareAsset", period, userAddress, i.transactionId), makeString(["%d%d%d%d", toString(shareAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userBaseAssetAmountToConvert)], separator))], unit) | |
413 | - | } | |
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) | |
414 | 1384 | else throw("Strict value is not equal to itself.") | |
415 | 1385 | } | |
416 | 1386 | else throw("Strict value is not equal to itself.") | |
417 | 1387 | } | |
418 | 1388 | else throw("Strict value is not equal to itself.") | |
419 | 1389 | } | |
420 | 1390 | else throw("Strict value is not equal to itself.") | |
421 | 1391 | } | |
422 | 1392 | else throw("Strict value is not equal to itself.") | |
423 | 1393 | } | |
424 | 1394 | else throw("Strict value is not equal to itself.") | |
425 | 1395 | } | |
426 | 1396 | ||
427 | 1397 | ||
428 | 1398 | ||
429 | 1399 | @Callable(i) | |
430 | 1400 | func get () = { | |
431 | - | let checks = [shutdownCheck(i)] | |
432 | - | if ((checks == checks)) | |
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)) | |
433 | 1410 | then { | |
434 | - | let pmt = if ((size(i.payments) == 1)) | |
435 | - | then i.payments[0] | |
436 | - | else throwErr("exactly 1 payment is expected") | |
437 | - | let shareAssetId = pmt.assetId | |
438 | - | let baseAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyBaseAssetId(shareAssetId)), wrapErr("invalid share asset id")))) | |
439 | - | if ((baseAssetId == baseAssetId)) | |
1411 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1412 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
440 | 1413 | then { | |
441 | - | let userAddress = i.caller | |
442 | - | let $t01612016309 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
443 | - | let poolAddress = $t01612016309._1 | |
444 | - | let lpAssetId = $t01612016309._2 | |
445 | - | let period = value(getInteger(keyPeriod(baseAssetId))) | |
446 | - | let userShareAssetAmountToConvertPeriodOption = getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)) | |
447 | - | let claimBaseAssetInvocation = if ((userShareAssetAmountToConvertPeriodOption == unit)) | |
448 | - | then unit | |
449 | - | else { | |
450 | - | let userShareAssetAmountToConvertPeriod = value(userShareAssetAmountToConvertPeriodOption) | |
451 | - | if ((userShareAssetAmountToConvertPeriod == period)) | |
452 | - | then unit | |
453 | - | else invoke(this, "claimBaseAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil) | |
454 | - | } | |
455 | - | if ((claimBaseAssetInvocation == claimBaseAssetInvocation)) | |
456 | - | then { | |
457 | - | let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0) | |
458 | - | let userShareAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserShareAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
459 | - | $Tuple2([IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), (shareAssetAmountToConvert + pmt.amount)), StringEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString((userShareAssetAmountToConvert + pmt.amount)), toString(lastBlock.timestamp)], separator)), IntegerEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "get", period, userAddress, i.transactionId), makeString(["%d%d%d", toString(pmt.amount), toString(lastBlock.timestamp), toString(userShareAssetAmountToConvert)], separator))], unit) | |
460 | - | } | |
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) | |
461 | 1420 | else throw("Strict value is not equal to itself.") | |
462 | 1421 | } | |
463 | 1422 | else throw("Strict value is not equal to itself.") | |
464 | 1423 | } | |
465 | 1424 | else throw("Strict value is not equal to itself.") | |
466 | 1425 | } | |
467 | 1426 | ||
468 | 1427 | ||
469 | 1428 | ||
470 | 1429 | @Callable(i) | |
471 | - | func claimBaseAsset (baseAssetIdStr,userAddressStr) = { | |
472 | - | let checks = [shutdownCheck(i)] | |
473 | - | if ((checks == checks)) | |
1430 | + | func getNoLess (noLessThenAmtAsset,noLessThenPriceAsset) = { | |
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 | |
1437 | + | if ((noLessThenAmtAsset > outAmAmt)) | |
1438 | + | then throw(((("noLessThenAmtAsset failed: " + toString(outAmAmt)) + " < ") + toString(noLessThenAmtAsset))) | |
1439 | + | else if ((noLessThenPriceAsset > outPrAmt)) | |
1440 | + | then throw(((("noLessThenPriceAsset failed: " + toString(outPrAmt)) + " < ") + toString(noLessThenPriceAsset))) | |
1441 | + | else { | |
1442 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1443 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1444 | + | if ((currentKLp == currentKLp)) | |
1445 | + | then { | |
1446 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [pmtAmt], [AttachedPayment(pmtAssetId, pmtAmt)]) | |
1447 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
1448 | + | 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) | |
1455 | + | else throw("Strict value is not equal to itself.") | |
1456 | + | } | |
1457 | + | else throw("Strict value is not equal to itself.") | |
1458 | + | } | |
1459 | + | else throw("Strict value is not equal to itself.") | |
1460 | + | } | |
1461 | + | } | |
1462 | + | ||
1463 | + | ||
1464 | + | ||
1465 | + | @Callable(i) | |
1466 | + | func unstakeAndGet (amount) = { | |
1467 | + | let checkPayments = if ((size(i.payments) != 0)) | |
1468 | + | then throw("No payments are expected") | |
1469 | + | else true | |
1470 | + | if ((checkPayments == checkPayments)) | |
474 | 1471 | then { | |
475 | - | let userAddress = if ((userAddressStr == "")) | |
476 | - | then i.caller | |
477 | - | else { | |
478 | - | let checkCaller = mustThis(i) | |
479 | - | if ((checkCaller == checkCaller)) | |
480 | - | then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address")) | |
481 | - | else throw("Strict value is not equal to itself.") | |
482 | - | } | |
483 | - | if ((userAddress == userAddress)) | |
1472 | + | let cfg = getPoolConfig() | |
1473 | + | let lpAssetId = fromBase58String(cfg[idxPoolLPAssetId]) | |
1474 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1475 | + | if ((currentKLp == currentKLp)) | |
484 | 1476 | then { | |
485 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
486 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
487 | - | if ((shareAssetId == shareAssetId)) | |
1477 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(lpAssetId), amount], nil) | |
1478 | + | if ((unstakeInv == unstakeInv)) | |
488 | 1479 | then { | |
489 | - | let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period")) | |
490 | - | if ((period == period)) | |
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()) | |
1487 | + | then true | |
1488 | + | else (poolStatus == PoolShutdown)) | |
1489 | + | then throw(("Get operation is blocked by admin. Status = " + toString(poolStatus))) | |
1490 | + | else true | |
1491 | + | if ((checkPoolStatus == checkPoolStatus)) | |
491 | 1492 | then { | |
492 | - | let userShareAssetAmountToConvert = valueOrElse(parseInt(split(value(getString(keyUserShareAssetAmountToConvert(baseAssetId, userAddress))), separator)[1]), 0) | |
493 | - | let userShareAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period")) | |
494 | - | let checkPeriod = if ((period > userShareAssetAmountToConvertPeriod)) | |
495 | - | then true | |
496 | - | else throwErr("invalid period") | |
497 | - | if ((checkPeriod == checkPeriod)) | |
1493 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [amount], [AttachedPayment(lpAssetId, amount)]) | |
1494 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
498 | 1495 | then { | |
499 | - | let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodGet(baseAssetId, userShareAssetAmountToConvertPeriod)), wrapErr("failed to get price"))) | |
500 | - | let baseAssetAmount = toInt(fraction(toBigInt(userShareAssetAmountToConvert), price, scale18BigInt)) | |
501 | - | $Tuple2([StringEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), makeString(["%d%d", toString(0), toString(lastBlock.timestamp)], separator)), DeleteEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, baseAssetAmount, baseAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimBaseAsset", period, userAddress, i.transactionId), makeString(["%d%d%d%d", toString(baseAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userShareAssetAmountToConvertPeriod)], separator))], unit) | |
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) | |
1502 | + | else throw("Strict value is not equal to itself.") | |
502 | 1503 | } | |
503 | 1504 | else throw("Strict value is not equal to itself.") | |
504 | 1505 | } | |
505 | 1506 | else throw("Strict value is not equal to itself.") | |
506 | 1507 | } | |
507 | 1508 | else throw("Strict value is not equal to itself.") | |
508 | 1509 | } | |
509 | 1510 | else throw("Strict value is not equal to itself.") | |
510 | 1511 | } | |
511 | 1512 | else throw("Strict value is not equal to itself.") | |
512 | 1513 | } | |
513 | 1514 | ||
514 | 1515 | ||
515 | 1516 | ||
516 | 1517 | @Callable(i) | |
517 | - | func finalize (baseAssetIdStr) = { | |
518 | - | let checks = [shutdownCheck(i)] | |
1518 | + | func unstakeAndGetNoLess (unstakeAmount,noLessThenAmountAsset,noLessThenPriceAsset) = { | |
1519 | + | let isGetDisabled = if (isGlobalShutdown()) | |
1520 | + | then true | |
1521 | + | else (cfgPoolStatus == PoolShutdown) | |
1522 | + | let checks = [if (!(isGetDisabled)) | |
1523 | + | then true | |
1524 | + | else throw("get operation is blocked by admin"), if ((size(i.payments) == 0)) | |
1525 | + | then true | |
1526 | + | else throw("no payments are expected")] | |
519 | 1527 | if ((checks == checks)) | |
520 | 1528 | then { | |
521 | - | let baseAssetId = parseAssetId(baseAssetIdStr) | |
522 | - | let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id")))) | |
523 | - | if ((shareAssetId == shareAssetId)) | |
1529 | + | let currentKLp = calcCurrentKLp(toBigInt(0), toBigInt(0), toBigInt(0)) | |
1530 | + | if ((currentKLp == currentKLp)) | |
524 | 1531 | then { | |
525 | - | let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id")) | |
526 | - | let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period")) | |
527 | - | if ((period == period)) | |
1532 | + | let unstakeInv = invoke(stakingContract, "unstake", [toBase58String(cfgLpAssetId), unstakeAmount], nil) | |
1533 | + | if ((unstakeInv == unstakeInv)) | |
528 | 1534 | then { | |
529 | - | let | |
530 | - | let | |
531 | - | | |
532 | - | | |
533 | - | ||
534 | - | ||
535 | - | | |
536 | - | | |
537 | - | | |
538 | - | | |
539 | - | if (( | |
1535 | + | let res = estimateGetOperation(toBase58String(i.transactionId), toBase58String(cfgLpAssetId), unstakeAmount, i.caller) | |
1536 | + | let outAmAmt = res._1 | |
1537 | + | let outPrAmt = res._2 | |
1538 | + | let state = res._10 | |
1539 | + | let withdrawState = withdrawAndRebalanceAll(outAmAmt, outPrAmt) | |
1540 | + | let checkAmounts = [if ((outAmAmt >= noLessThenAmountAsset)) | |
1541 | + | then true | |
1542 | + | else throw(makeString(["amount asset amount to receive is less than ", toString(noLessThenAmountAsset)], "")), if ((outPrAmt >= noLessThenPriceAsset)) | |
1543 | + | then true | |
1544 | + | else throw(makeString(["price asset amount to receive is less than ", toString(noLessThenPriceAsset)], ""))] | |
1545 | + | if ((checkAmounts == checkAmounts)) | |
540 | 1546 | then { | |
541 | - | let $t02168021861 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset")) | |
542 | - | let poolAddress = $t02168021861._1 | |
543 | - | let lpAssetId = $t02168021861._2 | |
544 | - | let stakingReward = valueOrErrorMessage({ | |
545 | - | let @ = invoke(stakingContract, "claimWxDoNotThrow", [assetIdToString(lpAssetId)], nil) | |
546 | - | if ($isInstanceOf(@, "Int")) | |
547 | - | then @ | |
548 | - | else unit | |
549 | - | }, wrapErr("invalid claimWx result")) | |
550 | - | if ((stakingReward == stakingReward)) | |
1547 | + | let burnLPAssetOnFactory = invoke(factoryContract, "burn", [unstakeAmount], [AttachedPayment(cfgLpAssetId, unstakeAmount)]) | |
1548 | + | if ((burnLPAssetOnFactory == burnLPAssetOnFactory)) | |
551 | 1549 | then { | |
552 | - | let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0) | |
553 | - | let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0) | |
554 | - | let checkFinalizationIsRequired = { | |
555 | - | let isFinalizationRequired = if (if ((stakingReward > 0)) | |
556 | - | then true | |
557 | - | else (baseAssetAmountToConvert > 0)) | |
558 | - | then true | |
559 | - | else (shareAssetAmountToConvert > 0) | |
560 | - | if (isFinalizationRequired) | |
561 | - | then true | |
562 | - | else throwErr("nothing to finalize") | |
563 | - | } | |
564 | - | if ((checkFinalizationIsRequired == checkFinalizationIsRequired)) | |
565 | - | then { | |
566 | - | let useStakingReward = if ((stakingReward > 0)) | |
567 | - | then { | |
568 | - | let lockPart = fraction(stakingReward, lockFraction, lockFractionMultiplier) | |
569 | - | let convertPart = (stakingReward - lockPart) | |
570 | - | let r = invoke(boostingContract, "userMaxDurationREADONLY", [toString(this)], nil) | |
571 | - | let lock = if ((lockPart > 0)) | |
572 | - | then match r { | |
573 | - | case _ => | |
574 | - | if (if (if ($isInstanceOf($match0._1, "String")) | |
575 | - | then $isInstanceOf($match0._2, "Int") | |
576 | - | else false) | |
577 | - | then $isInstanceOf($match0, "(String, Int)") | |
578 | - | else false) | |
579 | - | then { | |
580 | - | let function = $match0._1 | |
581 | - | let duration = $match0._2 | |
582 | - | if ((lockPart > 0)) | |
583 | - | then invoke(boostingContract, function, [duration], [AttachedPayment(wxAssetId, lockPart)]) | |
584 | - | else unit | |
585 | - | } | |
586 | - | else throwErr("invalid lock params") | |
587 | - | } | |
588 | - | else unit | |
589 | - | if ((lock == lock)) | |
590 | - | then { | |
591 | - | let convertedAmount = if ((convertPart > 0)) | |
592 | - | then { | |
593 | - | let inAssetId = wxAssetId | |
594 | - | let minimumToReceive = 0 | |
595 | - | let outAssetIdStr = assetIdToString(usdtAssetId) | |
596 | - | let targetAddress = toString(this) | |
597 | - | valueOrErrorMessage({ | |
598 | - | let @ = invoke(swapContract, "swap", [minimumToReceive, outAssetIdStr, targetAddress], [AttachedPayment(inAssetId, convertPart)]) | |
599 | - | if ($isInstanceOf(@, "Int")) | |
600 | - | then @ | |
601 | - | else unit | |
602 | - | }, wrapErr("invalid swap result")) | |
603 | - | } | |
604 | - | else 0 | |
605 | - | if ((convertedAmount == convertedAmount)) | |
606 | - | then { | |
607 | - | let lpAssetAmount = if ((convertedAmount > 0)) | |
608 | - | then { | |
609 | - | let minOutAmount = 0 | |
610 | - | let autoStake = true | |
611 | - | valueOrErrorMessage({ | |
612 | - | let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(usdtAssetId, convertedAmount)]) | |
613 | - | if ($isInstanceOf(@, "Int")) | |
614 | - | then @ | |
615 | - | else unit | |
616 | - | }, wrapErr("invalid putOneTknV2 result")) | |
617 | - | } | |
618 | - | else 0 | |
619 | - | if ((lpAssetAmount == lpAssetAmount)) | |
620 | - | then lpAssetAmount | |
621 | - | else throw("Strict value is not equal to itself.") | |
622 | - | } | |
623 | - | else throw("Strict value is not equal to itself.") | |
624 | - | } | |
625 | - | else throw("Strict value is not equal to itself.") | |
626 | - | } | |
627 | - | else unit | |
628 | - | if ((useStakingReward == useStakingReward)) | |
629 | - | then { | |
630 | - | let getActions = if ((shareAssetAmountToConvert > 0)) | |
631 | - | then { | |
632 | - | let price = calcPrice(lpAssetId, shareAssetId) | |
633 | - | if ((price == price)) | |
634 | - | then { | |
635 | - | let unstakeAmount = toInt(fraction(toBigInt(shareAssetAmountToConvert), price, scale18BigInt, FLOOR)) | |
636 | - | let baseAssetAmount = { | |
637 | - | let outAssetId = baseAssetId | |
638 | - | let minOutAmount = 0 | |
639 | - | valueOrErrorMessage({ | |
640 | - | let @ = invoke(poolAddress, "unstakeAndGetOneTknV2", [unstakeAmount, assetIdToString(outAssetId), minOutAmount], nil) | |
641 | - | if ($isInstanceOf(@, "Int")) | |
642 | - | then @ | |
643 | - | else unit | |
644 | - | }, wrapErr("invalid unstakeAndGetOneTknV2 result")) | |
645 | - | } | |
646 | - | if ((baseAssetAmount == baseAssetAmount)) | |
647 | - | then { | |
648 | - | let shareAssetBurn = if ((shareAssetInfo.issuer == this)) | |
649 | - | then invoke(this, "burn", [shareAssetId, shareAssetAmountToConvert], nil) | |
650 | - | else throwErr("invalid share asset issuer") | |
651 | - | if ((shareAssetBurn == shareAssetBurn)) | |
652 | - | then { | |
653 | - | let priceGet = fraction(toBigInt(baseAssetAmount), scale18BigInt, toBigInt(shareAssetAmountToConvert), FLOOR) | |
654 | - | let priceGetUpdateActions = [BinaryEntry(keyPricePeriodGet(baseAssetId, period), toBytes(priceGet)), StringEntry(keyPriceGetHistory(baseAssetId), toString(priceGet))] | |
655 | - | priceGetUpdateActions | |
656 | - | } | |
657 | - | else throw("Strict value is not equal to itself.") | |
658 | - | } | |
659 | - | else throw("Strict value is not equal to itself.") | |
660 | - | } | |
661 | - | else throw("Strict value is not equal to itself.") | |
662 | - | } | |
663 | - | else nil | |
664 | - | if ((getActions == getActions)) | |
665 | - | then { | |
666 | - | let putActions = if ((baseAssetAmountToConvert > 0)) | |
667 | - | then { | |
668 | - | let lpAssetAmount = { | |
669 | - | let minOutAmount = 0 | |
670 | - | let autoStake = true | |
671 | - | valueOrErrorMessage({ | |
672 | - | let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(baseAssetId, baseAssetAmountToConvert)]) | |
673 | - | if ($isInstanceOf(@, "Int")) | |
674 | - | then @ | |
675 | - | else unit | |
676 | - | }, wrapErr("invalid putOneTknV2 result")) | |
677 | - | } | |
678 | - | if ((lpAssetAmount == lpAssetAmount)) | |
679 | - | then { | |
680 | - | let price = calcPrice(lpAssetId, shareAssetId) | |
681 | - | if ((price == price)) | |
682 | - | then { | |
683 | - | let checkPrice = if ((value(toInt(price)) != 0)) | |
684 | - | then true | |
685 | - | else throw("price is ZERO") | |
686 | - | if ((checkPrice == checkPrice)) | |
687 | - | then { | |
688 | - | let shareAssetAmount = toInt(fraction(toBigInt(lpAssetAmount), scale18BigInt, price, FLOOR)) | |
689 | - | let checkShareAssetAmount = if ((value(toInt(price)) != 0)) | |
690 | - | then true | |
691 | - | else throw("shareAssetAmount is ZERO") | |
692 | - | if ((checkShareAssetAmount == checkShareAssetAmount)) | |
693 | - | then { | |
694 | - | let shareAssetReissue = if ((shareAssetInfo.issuer == this)) | |
695 | - | then invoke(this, "emit", [shareAssetId, shareAssetAmount], nil) | |
696 | - | else throwErr("invalid share asset issuer") | |
697 | - | if ((shareAssetReissue == shareAssetReissue)) | |
698 | - | then { | |
699 | - | let pricePut = fraction(toBigInt(baseAssetAmountToConvert), scale18BigInt, toBigInt(shareAssetAmount)) | |
700 | - | let pricePutUpdateActions = [BinaryEntry(keyPricePeriodPut(baseAssetId, period), toBytes(pricePut)), StringEntry(keyPricePutHistory(baseAssetId), toString(pricePut))] | |
701 | - | pricePutUpdateActions | |
702 | - | } | |
703 | - | else throw("Strict value is not equal to itself.") | |
704 | - | } | |
705 | - | else throw("Strict value is not equal to itself.") | |
706 | - | } | |
707 | - | else throw("Strict value is not equal to itself.") | |
708 | - | } | |
709 | - | else throw("Strict value is not equal to itself.") | |
710 | - | } | |
711 | - | else throw("Strict value is not equal to itself.") | |
712 | - | } | |
713 | - | else nil | |
714 | - | if ((putActions == putActions)) | |
715 | - | then { | |
716 | - | let newPeriod = (period + 1) | |
717 | - | let lastPrice = calcPrice(lpAssetId, shareAssetId) | |
718 | - | let actions = (([IntegerEntry(keyPeriod(baseAssetId), newPeriod), IntegerEntry(keyPeriodStartHeight(baseAssetId, newPeriod), height), IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), 0), IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), 0), BinaryEntry(keyPricePeriod(baseAssetId, period), toBytes(lastPrice)), StringEntry(keyPriceHistory(baseAssetId), toString(lastPrice))] ++ putActions) ++ getActions) | |
719 | - | $Tuple2(actions, toBytes(lastPrice)) | |
720 | - | } | |
721 | - | else throw("Strict value is not equal to itself.") | |
722 | - | } | |
723 | - | else throw("Strict value is not equal to itself.") | |
724 | - | } | |
725 | - | else throw("Strict value is not equal to itself.") | |
726 | - | } | |
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) | |
727 | 1556 | else throw("Strict value is not equal to itself.") | |
728 | 1557 | } | |
729 | 1558 | else throw("Strict value is not equal to itself.") | |
730 | 1559 | } | |
731 | 1560 | else throw("Strict value is not equal to itself.") | |
732 | 1561 | } | |
733 | 1562 | else throw("Strict value is not equal to itself.") | |
734 | 1563 | } | |
735 | 1564 | else throw("Strict value is not equal to itself.") | |
736 | 1565 | } | |
737 | 1566 | else throw("Strict value is not equal to itself.") | |
738 | 1567 | } | |
739 | 1568 | ||
740 | 1569 | ||
1570 | + | ||
1571 | + | @Callable(i) | |
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)) | |
1585 | + | then { | |
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)) | |
1594 | + | } | |
1595 | + | else throw("Strict value is not equal to itself.") | |
1596 | + | } | |
1597 | + | ||
1598 | + | ||
1599 | + | ||
1600 | + | @Callable(i) | |
1601 | + | func getPoolConfigWrapperREADONLY () = $Tuple2(nil, getPoolConfig()) | |
1602 | + | ||
1603 | + | ||
1604 | + | ||
1605 | + | @Callable(i) | |
1606 | + | func getAccBalanceWrapperREADONLY (assetId) = $Tuple2(nil, getAccBalance(assetId)) | |
1607 | + | ||
1608 | + | ||
1609 | + | ||
1610 | + | @Callable(i) | |
1611 | + | func calcPricesWrapperREADONLY (amAmt,prAmt,lpAmt) = { | |
1612 | + | let prices = calcPrices(amAmt, prAmt, lpAmt) | |
1613 | + | $Tuple2(nil, [toString(prices[0]), toString(prices[1]), toString(prices[2])]) | |
1614 | + | } | |
1615 | + | ||
1616 | + | ||
1617 | + | ||
1618 | + | @Callable(i) | |
1619 | + | func toX18WrapperREADONLY (origVal,origScaleMult) = $Tuple2(nil, toString(toX18(origVal, origScaleMult))) | |
1620 | + | ||
1621 | + | ||
1622 | + | ||
1623 | + | @Callable(i) | |
1624 | + | func fromX18WrapperREADONLY (val,resultScaleMult) = $Tuple2(nil, fromX18(parseBigIntValue(val), resultScaleMult)) | |
1625 | + | ||
1626 | + | ||
1627 | + | ||
1628 | + | @Callable(i) | |
1629 | + | func calcPriceBigIntWrapperREADONLY (prAmtX18,amAmtX18) = $Tuple2(nil, toString(calcPriceBigInt(parseBigIntValue(prAmtX18), parseBigIntValue(amAmtX18)))) | |
1630 | + | ||
1631 | + | ||
1632 | + | ||
1633 | + | @Callable(i) | |
1634 | + | func estimatePutOperationWrapperREADONLY (txId58,slippageTolerance,inAmAssetAmt,inAmAssetId,inPrAssetAmt,inPrAssetId,userAddress,isEvaluate,emitLp) = $Tuple2(nil, estimatePutOperation(txId58, slippageTolerance, inAmAssetAmt, inAmAssetId, inPrAssetAmt, inPrAssetId, userAddress, isEvaluate, emitLp)) | |
1635 | + | ||
1636 | + | ||
1637 | + | ||
1638 | + | @Callable(i) | |
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)) | |
1642 | + | } | |
1643 | + | ||
1644 | + | ||
1645 | + | ||
1646 | + | @Callable(i) | |
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)) | |
1667 | + | } | |
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)) | |
1748 | + | } | |
1749 | + | ||
1750 | + | ||
741 | 1751 | @Verifier(tx) | |
742 | 1752 | func verify () = { | |
743 | 1753 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
744 | 1754 | case pk: ByteVector => | |
745 | 1755 | pk | |
746 | 1756 | case _: Unit => | |
747 | 1757 | tx.senderPublicKey | |
748 | 1758 | case _ => | |
749 | 1759 | throw("Match error") | |
750 | 1760 | } | |
751 | - | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1761 | + | match tx { | |
1762 | + | case order: Order => | |
1763 | + | let matcherPub = getMatcherPubOrFail() | |
1764 | + | let $t06808568202 = if (skipOrderValidation()) | |
1765 | + | then $Tuple2(true, "") | |
1766 | + | else validateMatcherOrderAllowed(order) | |
1767 | + | let orderValid = $t06808568202._1 | |
1768 | + | let orderValidInfo = $t06808568202._2 | |
1769 | + | let senderValid = sigVerify(order.bodyBytes, order.proofs[0], order.senderPublicKey) | |
1770 | + | let matcherValid = sigVerify(order.bodyBytes, order.proofs[1], matcherPub) | |
1771 | + | if (if (if (orderValid) | |
1772 | + | then senderValid | |
1773 | + | else false) | |
1774 | + | then matcherValid | |
1775 | + | else false) | |
1776 | + | then true | |
1777 | + | else throwOrderError(orderValid, orderValidInfo, senderValid, matcherValid) | |
1778 | + | case s: SetScriptTransaction => | |
1779 | + | if (sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)) | |
1780 | + | then true | |
1781 | + | else { | |
1782 | + | let newHash = blake2b256(value(s.script)) | |
1783 | + | let allowedHash = fromBase64String(value(getString(factoryContract, keyAllowedLpScriptHash()))) | |
1784 | + | let currentHash = scriptHash(this) | |
1785 | + | if ((allowedHash == newHash)) | |
1786 | + | then (currentHash != newHash) | |
1787 | + | else false | |
1788 | + | } | |
1789 | + | case _ => | |
1790 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
1791 | + | } | |
752 | 1792 | } | |
753 | 1793 |
github/deemru/w8io/026f985 182.52 ms ◑