tx · 94qzdrAm6k7J16siRBJtnDT48zHbSiEUMC4dXCe1RUnd 3N8aqXmsyH4LoDFyypgngYYKT49pQ8nB4dx: -0.04500000 Waves 2023.08.04 11:15 [2695585] smart account 3N8aqXmsyH4LoDFyypgngYYKT49pQ8nB4dx > SELF 0.00000000 Waves
{ "type": 13, "id": "94qzdrAm6k7J16siRBJtnDT48zHbSiEUMC4dXCe1RUnd", "fee": 4500000, "feeAssetId": null, "timestamp": 1691136983240, "version": 2, "chainId": 84, "sender": "3N8aqXmsyH4LoDFyypgngYYKT49pQ8nB4dx", "senderPublicKey": "Hn75Ffw1pMKXcKvsGG5tJsFa7E4qyApSvkYUP4j8KDnN", "proofs": [ "B6DFb3xKuLpF31fZwKkgbiXhdXHjaaweDZ66d3L8gsxThkPnpFsBgavHe1VwKYHmGTA17iJf8a5iixunxDEsV1v" ], "script": "base64:BgI1CAISABIAEgMKAQESBQoDAQEBEgkKBwEBCAgBAQESBAoCAQESBAoCAQESABIAEgASABIAEgA+AAxrX2Jhc2VPcmFjbGUCDGtfYmFzZU9yYWNsZQANa19pbml0aWFsaXplZAINa19pbml0aWFsaXplZAAIa19wYXVzZWQCCGtfcGF1c2VkAAVrX2ZlZQIFa19mZWUAEGtfbWF4UHJpY2VJbXBhY3QCEGtfbWF4UHJpY2VJbXBhY3QAEGtfbWF4UHJpY2VTcHJlYWQCEGtfbWF4UHJpY2VTcHJlYWQAEGtfbWF4T3JhY2xlRGVsYXkCEGtfbWF4T3JhY2xlRGVsYXkAE2tfcXVvdGVBc3NldFJlc2VydmUCCGtfcXRBc3RSABJrX2Jhc2VBc3NldFJlc2VydmUCCGtfYnNBc3RSABJrX3F1b3RlQXNzZXRXZWlnaHQCCGtfcXRBc3RXABFrX2Jhc2VBc3NldFdlaWdodAIIa19ic0FzdFcAE2tfdG90YWxQb3NpdGlvblNpemUCE2tfdG90YWxQb3NpdGlvblNpemUACGtfbGFzdFR4AghrX2xhc3RUeAAUa19jb29yZGluYXRvckFkZHJl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Bub3Qgc2V0IGluIGNvb3JkaW5hdG9yCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5y7flPw==", "height": 2695585, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5c4WjjNNnut1mZH3e1jJrfo1fwgEvZdrHQVAzs8y4KXx Next: BAUZ8M2BKZdid8yp4TpcYteD3pyVWjoaBjLwKLSZySEa Diff:
Old | New | Differences | |
---|---|---|---|
178 | 178 | let amountBaseAssetBought = if (_isAdd) | |
179 | 179 | then amountBaseAssetBoughtAbs | |
180 | 180 | else -(amountBaseAssetBoughtAbs) | |
181 | - | let $ | |
182 | - | let quoteAssetReserveAfter1 = $ | |
183 | - | let baseAssetReserveAfter1 = $ | |
184 | - | let totalPositionSizeAfter1 = $ | |
181 | + | let $t064036573 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs) | |
182 | + | let quoteAssetReserveAfter1 = $t064036573._1 | |
183 | + | let baseAssetReserveAfter1 = $t064036573._2 | |
184 | + | let totalPositionSizeAfter1 = $t064036573._3 | |
185 | 185 | let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
186 | 186 | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
187 | 187 | let priceDiff = abs((priceBefore - marketPrice)) | |
206 | 206 | let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve)) | |
207 | 207 | let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight) | |
208 | 208 | let maxPriceImpactValue = maxPriceImpact() | |
209 | - | let $ | |
210 | - | let quoteAssetReserveAfter1 = $ | |
211 | - | let baseAssetReserveAfter1 = $ | |
212 | - | let totalPositionSizeAfter1 = $ | |
209 | + | let $t086888850 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount) | |
210 | + | let quoteAssetReserveAfter1 = $t086888850._1 | |
211 | + | let baseAssetReserveAfter1 = $t086888850._2 | |
212 | + | let totalPositionSizeAfter1 = $t086888850._3 | |
213 | 213 | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
214 | 214 | let priceDiff = abs((priceBefore - marketPrice)) | |
215 | 215 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
262 | 262 | then $Tuple2(qtAstR(), bsAstR()) | |
263 | 263 | else { | |
264 | 264 | let direction = (_positionSize > 0) | |
265 | - | let $ | |
266 | - | let currentNetMarketValue = $ | |
267 | - | let terminalQuoteAssetReserve = $ | |
268 | - | let terminalBaseAssetReserve = $ | |
265 | + | let $t01179811977 = swapOutput(direction, abs(_positionSize), false) | |
266 | + | let currentNetMarketValue = $t01179811977._1 | |
267 | + | let terminalQuoteAssetReserve = $t01179811977._2 | |
268 | + | let terminalBaseAssetReserve = $t01179811977._3 | |
269 | 269 | $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve) | |
270 | 270 | } | |
271 | 271 | } | |
303 | 303 | func updateSettings (_maxPriceImpact,_maxPriceSpread,_maxOracleDelay) = [IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOracleDelay, _maxOracleDelay)] | |
304 | 304 | ||
305 | 305 | ||
306 | - | func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
306 | + | func updateAmmReserves (_qtAstR,_bsAstR) = if (if ((0 >= _qtAstR)) | |
307 | + | then true | |
308 | + | else (0 >= _bsAstR)) | |
309 | + | then throw("Can not updateAmmReserves: _qtAstR <= 0 || _bsAstR <= 0") | |
310 | + | else [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
307 | 311 | ||
308 | 312 | ||
309 | 313 | func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)] | |
344 | 348 | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
345 | 349 | let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR) | |
346 | 350 | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
347 | - | let $ | |
348 | - | let newQuoteAssetWeight = $ | |
349 | - | let newBaseAssetWeight = $ | |
351 | + | let $t01536215492 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
352 | + | let newQuoteAssetWeight = $t01536215492._1 | |
353 | + | let newBaseAssetWeight = $t01536215492._2 | |
350 | 354 | (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) | |
351 | 355 | } | |
352 | 356 | ||
400 | 404 | else (i.caller != spotAddress())) | |
401 | 405 | then throw("Invalid swapToBase parameters") | |
402 | 406 | else { | |
403 | - | let $ | |
404 | - | let amountBaseAssetBought = $ | |
405 | - | let quoteAssetReserveAfter = $ | |
406 | - | let baseAssetReserveAfter = $ | |
407 | - | let totalPositionSizeAfter = $ | |
407 | + | let $t01803918196 = swapInput(true, _amount) | |
408 | + | let amountBaseAssetBought = $t01803918196._1 | |
409 | + | let quoteAssetReserveAfter = $t01803918196._2 | |
410 | + | let baseAssetReserveAfter = $t01803918196._3 | |
411 | + | let totalPositionSizeAfter = $t01803918196._4 | |
408 | 412 | let update = updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter) | |
409 | 413 | $Tuple2(update, amountBaseAssetBought) | |
410 | 414 | } | |
429 | 433 | else (i.caller != spotAddress())) | |
430 | 434 | then throw("Invalid swapToQuote parameters") | |
431 | 435 | else { | |
432 | - | let $ | |
433 | - | let amountQuoteAssetBought = $ | |
434 | - | let quoteAssetReserveAfter = $ | |
435 | - | let baseAssetReserveAfter = $ | |
436 | + | let $t01874118899 = swapOutput(true, _amount, true) | |
437 | + | let amountQuoteAssetBought = $t01874118899._1 | |
438 | + | let quoteAssetReserveAfter = $t01874118899._2 | |
439 | + | let baseAssetReserveAfter = $t01874118899._3 | |
436 | 440 | let totalPositionSizeAfter = (totalPositionSize() - _amount) | |
437 | 441 | let update = updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter) | |
438 | 442 | $Tuple2(update, amountQuoteAssetBought) | |
448 | 452 | func syncTerminalPriceToOracle () = { | |
449 | 453 | let _qtAstR = qtAstR() | |
450 | 454 | let _bsAstR = bsAstR() | |
451 | - | let $ | |
452 | - | let newQuoteAssetWeight = $ | |
453 | - | let newBaseAssetWeight = $ | |
455 | + | let $t01954519661 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR) | |
456 | + | let newQuoteAssetWeight = $t01954519661._1 | |
457 | + | let newBaseAssetWeight = $t01954519661._2 | |
454 | 458 | updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight) | |
455 | 459 | } | |
456 | 460 | ||
471 | 475 | ||
472 | 476 | @Callable(i) | |
473 | 477 | func view_getTerminalAmmPrice () = { | |
474 | - | let $ | |
475 | - | let terminalQuoteAssetReserve = $ | |
476 | - | let terminalBaseAssetReserve = $ | |
478 | + | let $t02041520496 = getTerminalAmmState() | |
479 | + | let terminalQuoteAssetReserve = $t02041520496._1 | |
480 | + | let terminalBaseAssetReserve = $t02041520496._2 | |
477 | 481 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
478 | 482 | throw(toString(price)) | |
483 | + | } | |
484 | + | ||
485 | + | ||
486 | + | ||
487 | + | @Callable(i) | |
488 | + | func view_getPrices () = { | |
489 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
490 | + | if ((sync == sync)) | |
491 | + | then { | |
492 | + | let $t02081620897 = getTerminalAmmState() | |
493 | + | let terminalQuoteAssetReserve = $t02081620897._1 | |
494 | + | let terminalBaseAssetReserve = $t02081620897._2 | |
495 | + | let terminalPrice = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
496 | + | let spotPrice = getSpotPrice() | |
497 | + | throw(((toString(terminalPrice) + ",") + toString(spotPrice))) | |
498 | + | } | |
499 | + | else throw("Strict value is not equal to itself.") | |
479 | 500 | } | |
480 | 501 | ||
481 | 502 | ||
495 | 516 | ||
496 | 517 | @Callable(i) | |
497 | 518 | func computeTerminalAmmPrice () = { | |
498 | - | let $ | |
499 | - | let terminalQuoteAssetReserve = $ | |
500 | - | let terminalBaseAssetReserve = $ | |
519 | + | let $t02164821729 = getTerminalAmmState() | |
520 | + | let terminalQuoteAssetReserve = $t02164821729._1 | |
521 | + | let terminalBaseAssetReserve = $t02164821729._2 | |
501 | 522 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
502 | 523 | $Tuple2(nil, price) | |
503 | 524 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_baseOracle = "k_baseOracle" | |
5 | 5 | ||
6 | 6 | let k_initialized = "k_initialized" | |
7 | 7 | ||
8 | 8 | let k_paused = "k_paused" | |
9 | 9 | ||
10 | 10 | let k_fee = "k_fee" | |
11 | 11 | ||
12 | 12 | let k_maxPriceImpact = "k_maxPriceImpact" | |
13 | 13 | ||
14 | 14 | let k_maxPriceSpread = "k_maxPriceSpread" | |
15 | 15 | ||
16 | 16 | let k_maxOracleDelay = "k_maxOracleDelay" | |
17 | 17 | ||
18 | 18 | let k_quoteAssetReserve = "k_qtAstR" | |
19 | 19 | ||
20 | 20 | let k_baseAssetReserve = "k_bsAstR" | |
21 | 21 | ||
22 | 22 | let k_quoteAssetWeight = "k_qtAstW" | |
23 | 23 | ||
24 | 24 | let k_baseAssetWeight = "k_bsAstW" | |
25 | 25 | ||
26 | 26 | let k_totalPositionSize = "k_totalPositionSize" | |
27 | 27 | ||
28 | 28 | let k_lastTx = "k_lastTx" | |
29 | 29 | ||
30 | 30 | let k_coordinatorAddress = "k_coordinatorAddress" | |
31 | 31 | ||
32 | 32 | let k_vault_address = "k_vault_address" | |
33 | 33 | ||
34 | 34 | let k_admin_address = "k_admin_address" | |
35 | 35 | ||
36 | 36 | let k_quote_asset = "k_quote_asset" | |
37 | 37 | ||
38 | 38 | let k_spot_address = "k_spot_address" | |
39 | 39 | ||
40 | 40 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func adminAddress () = addressFromString(getStringValue(coordinator(), k_admin_address)) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func spotAddress () = addressFromString(valueOrErrorMessage(getString(coordinator(), k_spot_address), "Spot address not set")) | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | let DECIMAL_NUMBERS = 6 | |
56 | 56 | ||
57 | 57 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
58 | 58 | ||
59 | 59 | func s (_x) = (toString(_x) + ",") | |
60 | 60 | ||
61 | 61 | ||
62 | 62 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
66 | 66 | ||
67 | 67 | ||
68 | 68 | func bdivd (_x,_y) = fraction(_x, toBigInt(DECIMAL_UNIT), _y, HALFEVEN) | |
69 | 69 | ||
70 | 70 | ||
71 | 71 | func bmuld (_x,_y) = fraction(_x, _y, toBigInt(DECIMAL_UNIT), HALFEVEN) | |
72 | 72 | ||
73 | 73 | ||
74 | 74 | func abs (_x) = if ((_x > 0)) | |
75 | 75 | then _x | |
76 | 76 | else -(_x) | |
77 | 77 | ||
78 | 78 | ||
79 | 79 | func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k)) | |
80 | 80 | ||
81 | 81 | ||
82 | 82 | func intOr (k,def) = valueOrElse(getInteger(this, k), def) | |
83 | 83 | ||
84 | 84 | ||
85 | 85 | func intA (_address,_key) = { | |
86 | 86 | let val = valueOrErrorMessage(getInteger(_address, _key), ("No value for key " + _key)) | |
87 | 87 | val | |
88 | 88 | } | |
89 | 89 | ||
90 | 90 | ||
91 | 91 | func fee () = int(k_fee) | |
92 | 92 | ||
93 | 93 | ||
94 | 94 | func qtAstR () = int(k_quoteAssetReserve) | |
95 | 95 | ||
96 | 96 | ||
97 | 97 | func bsAstR () = int(k_baseAssetReserve) | |
98 | 98 | ||
99 | 99 | ||
100 | 100 | func qtAstW () = intOr(k_quoteAssetWeight, DECIMAL_UNIT) | |
101 | 101 | ||
102 | 102 | ||
103 | 103 | func bsAstW () = intOr(k_baseAssetWeight, DECIMAL_UNIT) | |
104 | 104 | ||
105 | 105 | ||
106 | 106 | func totalPositionSize () = int(k_totalPositionSize) | |
107 | 107 | ||
108 | 108 | ||
109 | 109 | func maxPriceImpact () = int(k_maxPriceImpact) | |
110 | 110 | ||
111 | 111 | ||
112 | 112 | func maxPriceSpread () = int(k_maxPriceSpread) | |
113 | 113 | ||
114 | 114 | ||
115 | 115 | func maxOracleDelay () = int(k_maxOracleDelay) | |
116 | 116 | ||
117 | 117 | ||
118 | 118 | func lastTimestamp () = lastBlock.timestamp | |
119 | 119 | ||
120 | 120 | ||
121 | 121 | func getOracleData (key) = { | |
122 | 122 | let oracleDataStr = getString(this, key) | |
123 | 123 | if (if (isDefined(oracleDataStr)) | |
124 | 124 | then (value(oracleDataStr) != "") | |
125 | 125 | else false) | |
126 | 126 | then { | |
127 | 127 | let oracleData = split(value(oracleDataStr), ",") | |
128 | 128 | let oracleAddress = valueOrErrorMessage(addressFromString(oracleData[0]), ("Invalid oracle address in: " + value(oracleDataStr))) | |
129 | 129 | let priceKey = oracleData[1] | |
130 | 130 | let blockKey = oracleData[2] | |
131 | 131 | let openKey = oracleData[3] | |
132 | 132 | $Tuple4(oracleAddress, priceKey, blockKey, openKey) | |
133 | 133 | } | |
134 | 134 | else unit | |
135 | 135 | } | |
136 | 136 | ||
137 | 137 | ||
138 | 138 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
139 | 139 | ||
140 | 140 | ||
141 | 141 | func paused () = valueOrElse(getBoolean(this, k_paused), false) | |
142 | 142 | ||
143 | 143 | ||
144 | 144 | func updateReserve (_isAdd,_quoteAssetAmount,_baseAssetAmount) = if (_isAdd) | |
145 | 145 | then { | |
146 | 146 | let newBase = (bsAstR() - _baseAssetAmount) | |
147 | 147 | if ((0 >= newBase)) | |
148 | 148 | then throw("Tx lead to base asset reserve <= 0, revert") | |
149 | 149 | else $Tuple3((qtAstR() + _quoteAssetAmount), newBase, (totalPositionSize() + _baseAssetAmount)) | |
150 | 150 | } | |
151 | 151 | else { | |
152 | 152 | let newQuote = (qtAstR() - _quoteAssetAmount) | |
153 | 153 | if ((0 >= newQuote)) | |
154 | 154 | then throw("Tx lead to base quote reserve <= 0, revert") | |
155 | 155 | else $Tuple3(newQuote, (bsAstR() + _baseAssetAmount), (totalPositionSize() - _baseAssetAmount)) | |
156 | 156 | } | |
157 | 157 | ||
158 | 158 | ||
159 | 159 | func calcInvariant (_qtAstR,_bsAstR) = { | |
160 | 160 | let bqtAstR = toBigInt(_qtAstR) | |
161 | 161 | let bbsAstR = toBigInt(_bsAstR) | |
162 | 162 | bmuld(bqtAstR, bbsAstR) | |
163 | 163 | } | |
164 | 164 | ||
165 | 165 | ||
166 | 166 | func swapInput (_isAdd,_quoteAssetAmount) = { | |
167 | 167 | let _qtAstR = qtAstR() | |
168 | 168 | let _bsAstR = bsAstR() | |
169 | 169 | let _qtAstW = qtAstW() | |
170 | 170 | let _bsAstW = bsAstW() | |
171 | 171 | let quoteAssetAmountAdjusted = divd(_quoteAssetAmount, _qtAstW) | |
172 | 172 | let k = calcInvariant(_qtAstR, _bsAstR) | |
173 | 173 | let quoteAssetReserveAfter = if (_isAdd) | |
174 | 174 | then (_qtAstR + quoteAssetAmountAdjusted) | |
175 | 175 | else (_qtAstR - quoteAssetAmountAdjusted) | |
176 | 176 | let baseAssetReserveAfter = toInt(bdivd(k, toBigInt(quoteAssetReserveAfter))) | |
177 | 177 | let amountBaseAssetBoughtAbs = abs((baseAssetReserveAfter - _bsAstR)) | |
178 | 178 | let amountBaseAssetBought = if (_isAdd) | |
179 | 179 | then amountBaseAssetBoughtAbs | |
180 | 180 | else -(amountBaseAssetBoughtAbs) | |
181 | - | let $ | |
182 | - | let quoteAssetReserveAfter1 = $ | |
183 | - | let baseAssetReserveAfter1 = $ | |
184 | - | let totalPositionSizeAfter1 = $ | |
181 | + | let $t064036573 = updateReserve(_isAdd, quoteAssetAmountAdjusted, amountBaseAssetBoughtAbs) | |
182 | + | let quoteAssetReserveAfter1 = $t064036573._1 | |
183 | + | let baseAssetReserveAfter1 = $t064036573._2 | |
184 | + | let totalPositionSizeAfter1 = $t064036573._3 | |
185 | 185 | let priceBefore = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
186 | 186 | let marketPrice = divd(_quoteAssetAmount, amountBaseAssetBoughtAbs) | |
187 | 187 | let priceDiff = abs((priceBefore - marketPrice)) | |
188 | 188 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
189 | 189 | let maxPriceImpactValue = maxPriceImpact() | |
190 | 190 | if ((priceImpact > maxPriceImpactValue)) | |
191 | 191 | then throw(((((((((((((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue)) + " before quote asset: ") + toString(_qtAstR)) + " before base asset: ") + toString(_bsAstR)) + " quote asset amount to exchange: ") + toString(_quoteAssetAmount)) + " price before: ") + toString(priceBefore)) + " marketPrice: ") + toString(marketPrice))) | |
192 | 192 | else $Tuple4(amountBaseAssetBought, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1) | |
193 | 193 | } | |
194 | 194 | ||
195 | 195 | ||
196 | 196 | func swapOutputWithReserves (_isAdd,_baseAssetAmount,_checkMaxPriceImpact,_quoteAssetReserve,_quoteAssetWeight,_baseAssetReserve,_baseAssetWeight) = { | |
197 | 197 | let priceBefore = divd(muld(_quoteAssetReserve, _quoteAssetWeight), muld(_baseAssetReserve, _baseAssetWeight)) | |
198 | 198 | if ((_baseAssetAmount == 0)) | |
199 | 199 | then throw("Invalid base asset amount") | |
200 | 200 | else { | |
201 | 201 | let k = calcInvariant(_quoteAssetReserve, _baseAssetReserve) | |
202 | 202 | let baseAssetPoolAmountAfter = if (_isAdd) | |
203 | 203 | then (_baseAssetReserve + _baseAssetAmount) | |
204 | 204 | else (_baseAssetReserve - _baseAssetAmount) | |
205 | 205 | let quoteAssetAfter = toInt(bdivd(k, toBigInt(baseAssetPoolAmountAfter))) | |
206 | 206 | let quoteAssetDelta = abs((quoteAssetAfter - _quoteAssetReserve)) | |
207 | 207 | let quoteAssetSold = muld(quoteAssetDelta, _quoteAssetWeight) | |
208 | 208 | let maxPriceImpactValue = maxPriceImpact() | |
209 | - | let $ | |
210 | - | let quoteAssetReserveAfter1 = $ | |
211 | - | let baseAssetReserveAfter1 = $ | |
212 | - | let totalPositionSizeAfter1 = $ | |
209 | + | let $t086888850 = updateReserve(!(_isAdd), quoteAssetDelta, _baseAssetAmount) | |
210 | + | let quoteAssetReserveAfter1 = $t086888850._1 | |
211 | + | let baseAssetReserveAfter1 = $t086888850._2 | |
212 | + | let totalPositionSizeAfter1 = $t086888850._3 | |
213 | 213 | let marketPrice = divd(quoteAssetSold, _baseAssetAmount) | |
214 | 214 | let priceDiff = abs((priceBefore - marketPrice)) | |
215 | 215 | let priceImpact = (DECIMAL_UNIT - divd(priceBefore, (priceBefore + priceDiff))) | |
216 | 216 | if (if ((priceImpact > maxPriceImpactValue)) | |
217 | 217 | then _checkMaxPriceImpact | |
218 | 218 | else false) | |
219 | 219 | then throw(((((((((((((("Price impact " + toString(priceImpact)) + " > max price impact ") + toString(maxPriceImpactValue)) + " before quote asset: ") + toString(_quoteAssetReserve)) + " before base asset: ") + toString(_baseAssetReserve)) + " base asset amount to exchange: ") + toString(_baseAssetAmount)) + " price before: ") + toString(priceBefore)) + " market price: ") + toString(marketPrice))) | |
220 | 220 | else $Tuple5(quoteAssetSold, quoteAssetReserveAfter1, baseAssetReserveAfter1, totalPositionSizeAfter1, priceImpact) | |
221 | 221 | } | |
222 | 222 | } | |
223 | 223 | ||
224 | 224 | ||
225 | 225 | func swapOutput (_isAdd,_baseAssetAmount,_checkMaxPriceImpact) = swapOutputWithReserves(_isAdd, _baseAssetAmount, _checkMaxPriceImpact, qtAstR(), qtAstW(), bsAstR(), bsAstW()) | |
226 | 226 | ||
227 | 227 | ||
228 | 228 | func getOraclePriceValue (oracle,priceKey,blockKey) = { | |
229 | 229 | let lastValue = valueOrErrorMessage(getInteger(oracle, priceKey), ((("Can not get oracle price. Oracle: " + toString(oracle)) + " key: ") + priceKey)) | |
230 | 230 | if ((blockKey != "")) | |
231 | 231 | then { | |
232 | 232 | let currentBlock = lastBlock.height | |
233 | 233 | let lastOracleBlock = valueOrErrorMessage(getInteger(oracle, blockKey), ((("Can not get oracle block. Oracle: " + toString(oracle)) + " key: ") + blockKey)) | |
234 | 234 | if (((currentBlock - lastOracleBlock) > maxOracleDelay())) | |
235 | 235 | then throw(((("Oracle stale data. Last oracle block: " + toString(lastOracleBlock)) + " current block: ") + toString(currentBlock))) | |
236 | 236 | else lastValue | |
237 | 237 | } | |
238 | 238 | else lastValue | |
239 | 239 | } | |
240 | 240 | ||
241 | 241 | ||
242 | 242 | func getOraclePrice () = { | |
243 | 243 | let baseOracle = valueOrErrorMessage(getOracleData(k_baseOracle), "No base asset oracle data") | |
244 | 244 | let baseOraclePrice = getOraclePriceValue(baseOracle._1, baseOracle._2, baseOracle._3) | |
245 | 245 | let quoteOraclePrice = DECIMAL_UNIT | |
246 | 246 | divd(baseOraclePrice, quoteOraclePrice) | |
247 | 247 | } | |
248 | 248 | ||
249 | 249 | ||
250 | 250 | func getSpotPrice () = { | |
251 | 251 | let _quoteAssetReserve = qtAstR() | |
252 | 252 | let _baseAssetReserve = bsAstR() | |
253 | 253 | let _qtAstW = qtAstW() | |
254 | 254 | let _bsAstW = bsAstW() | |
255 | 255 | divd(muld(_quoteAssetReserve, _qtAstW), muld(_baseAssetReserve, _bsAstW)) | |
256 | 256 | } | |
257 | 257 | ||
258 | 258 | ||
259 | 259 | func getTerminalAmmState () = { | |
260 | 260 | let _positionSize = totalPositionSize() | |
261 | 261 | if ((_positionSize == 0)) | |
262 | 262 | then $Tuple2(qtAstR(), bsAstR()) | |
263 | 263 | else { | |
264 | 264 | let direction = (_positionSize > 0) | |
265 | - | let $ | |
266 | - | let currentNetMarketValue = $ | |
267 | - | let terminalQuoteAssetReserve = $ | |
268 | - | let terminalBaseAssetReserve = $ | |
265 | + | let $t01179811977 = swapOutput(direction, abs(_positionSize), false) | |
266 | + | let currentNetMarketValue = $t01179811977._1 | |
267 | + | let terminalQuoteAssetReserve = $t01179811977._2 | |
268 | + | let terminalBaseAssetReserve = $t01179811977._3 | |
269 | 269 | $Tuple2(terminalQuoteAssetReserve, terminalBaseAssetReserve) | |
270 | 270 | } | |
271 | 271 | } | |
272 | 272 | ||
273 | 273 | ||
274 | 274 | func getQuoteAssetWeight (baseAssetReserve,totalPositionSize,quoteAssetReserve,targetPrice) = { | |
275 | 275 | let b = toBigInt(baseAssetReserve) | |
276 | 276 | let sz = toBigInt(totalPositionSize) | |
277 | 277 | let q = toBigInt(quoteAssetReserve) | |
278 | 278 | let p = toBigInt(targetPrice) | |
279 | 279 | let k = bmuld(q, b) | |
280 | 280 | let newB = (b + sz) | |
281 | 281 | let newQ = bdivd(k, newB) | |
282 | 282 | let z = bdivd(newQ, newB) | |
283 | 283 | let result = bdivd(p, z) | |
284 | 284 | toInt(result) | |
285 | 285 | } | |
286 | 286 | ||
287 | 287 | ||
288 | 288 | func getSyncTerminalPrice (_terminalPrice,_qtAstR,_bsAstR) = { | |
289 | 289 | let _positionSize = totalPositionSize() | |
290 | 290 | if ((_positionSize == 0)) | |
291 | 291 | then { | |
292 | 292 | let newQtAstW = divd(muld(_terminalPrice, _bsAstR), _qtAstR) | |
293 | 293 | $Tuple2(newQtAstW, DECIMAL_UNIT) | |
294 | 294 | } | |
295 | 295 | else { | |
296 | 296 | let newQtAstW = getQuoteAssetWeight(_bsAstR, _positionSize, _qtAstR, _terminalPrice) | |
297 | 297 | let newBsAstW = DECIMAL_UNIT | |
298 | 298 | $Tuple2(newQtAstW, newBsAstW) | |
299 | 299 | } | |
300 | 300 | } | |
301 | 301 | ||
302 | 302 | ||
303 | 303 | func updateSettings (_maxPriceImpact,_maxPriceSpread,_maxOracleDelay) = [IntegerEntry(k_maxPriceImpact, _maxPriceImpact), IntegerEntry(k_maxPriceSpread, _maxPriceSpread), IntegerEntry(k_maxOracleDelay, _maxOracleDelay)] | |
304 | 304 | ||
305 | 305 | ||
306 | - | func updateAmmReserves (_qtAstR,_bsAstR) = [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
306 | + | func updateAmmReserves (_qtAstR,_bsAstR) = if (if ((0 >= _qtAstR)) | |
307 | + | then true | |
308 | + | else (0 >= _bsAstR)) | |
309 | + | then throw("Can not updateAmmReserves: _qtAstR <= 0 || _bsAstR <= 0") | |
310 | + | else [IntegerEntry(k_quoteAssetReserve, _qtAstR), IntegerEntry(k_baseAssetReserve, _bsAstR)] | |
307 | 311 | ||
308 | 312 | ||
309 | 313 | func updateAmmWeights (_qtAstW,_bsAstW) = [IntegerEntry(k_quoteAssetWeight, _qtAstW), IntegerEntry(k_baseAssetWeight, _bsAstW)] | |
310 | 314 | ||
311 | 315 | ||
312 | 316 | func updateAmm (_qtAstR,_bsAstR,_totalPositionSizeAfter) = { | |
313 | 317 | let _qtAstW = qtAstW() | |
314 | 318 | let _bsAstW = bsAstW() | |
315 | 319 | (updateAmmReserves(_qtAstR, _bsAstR) ++ [IntegerEntry(k_totalPositionSize, _totalPositionSizeAfter)]) | |
316 | 320 | } | |
317 | 321 | ||
318 | 322 | ||
319 | 323 | @Callable(i) | |
320 | 324 | func pause () = if ((i.caller != adminAddress())) | |
321 | 325 | then throw("Invalid pause params") | |
322 | 326 | else [BooleanEntry(k_paused, true)] | |
323 | 327 | ||
324 | 328 | ||
325 | 329 | ||
326 | 330 | @Callable(i) | |
327 | 331 | func unpause () = if ((i.caller != adminAddress())) | |
328 | 332 | then throw("Invalid unpause params") | |
329 | 333 | else [BooleanEntry(k_paused, false)] | |
330 | 334 | ||
331 | 335 | ||
332 | 336 | ||
333 | 337 | @Callable(i) | |
334 | 338 | func changeLiquidity (_quoteAssetAmount) = if (!(if ((i.caller == spotAddress())) | |
335 | 339 | then true | |
336 | 340 | else (i.caller == adminAddress()))) | |
337 | 341 | then throw("Invalid changeLiquidity params") | |
338 | 342 | else { | |
339 | 343 | let _qtAstR = qtAstR() | |
340 | 344 | let _bsAstR = bsAstR() | |
341 | 345 | let _qtAstW = qtAstW() | |
342 | 346 | let _bsAstW = bsAstW() | |
343 | 347 | let price = divd(muld(_qtAstR, _qtAstW), muld(_bsAstR, _bsAstW)) | |
344 | 348 | let qtAstRAfter = (_qtAstR + _quoteAssetAmount) | |
345 | 349 | let baseAssetAmountToAdd = (divd(muld(qtAstRAfter, _qtAstW), price) - _bsAstR) | |
346 | 350 | let bsAstRAfter = (_bsAstR + baseAssetAmountToAdd) | |
347 | - | let $ | |
348 | - | let newQuoteAssetWeight = $ | |
349 | - | let newBaseAssetWeight = $ | |
351 | + | let $t01536215492 = getSyncTerminalPrice(getOraclePrice(), qtAstRAfter, bsAstRAfter) | |
352 | + | let newQuoteAssetWeight = $t01536215492._1 | |
353 | + | let newBaseAssetWeight = $t01536215492._2 | |
350 | 354 | (updateAmmReserves(qtAstRAfter, bsAstRAfter) ++ updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight)) | |
351 | 355 | } | |
352 | 356 | ||
353 | 357 | ||
354 | 358 | ||
355 | 359 | @Callable(i) | |
356 | 360 | func changeSettings (_maxPriceImpact,_maxPriceSpread,_maxOracleDelay) = if (if (if (if (if ((0 >= _maxPriceImpact)) | |
357 | 361 | then true | |
358 | 362 | else (0 >= _maxPriceSpread)) | |
359 | 363 | then true | |
360 | 364 | else (0 >= _maxOracleDelay)) | |
361 | 365 | then true | |
362 | 366 | else !(initialized())) | |
363 | 367 | then true | |
364 | 368 | else (i.caller != adminAddress())) | |
365 | 369 | then throw("Invalid changeSettings params") | |
366 | 370 | else updateSettings(_maxPriceImpact, _maxPriceSpread, _maxOracleDelay) | |
367 | 371 | ||
368 | 372 | ||
369 | 373 | ||
370 | 374 | @Callable(i) | |
371 | 375 | func initialize (_qtAstR,_bsAstR,_baseOracleData,_coordinator,_maxPriceImpact,_maxPriceSpread,_maxOracleDelay) = if (if (if (if (if (if (if ((0 >= _qtAstR)) | |
372 | 376 | then true | |
373 | 377 | else (0 >= _bsAstR)) | |
374 | 378 | then true | |
375 | 379 | else (0 >= _maxPriceImpact)) | |
376 | 380 | then true | |
377 | 381 | else (0 >= _maxPriceSpread)) | |
378 | 382 | then true | |
379 | 383 | else (0 >= _maxOracleDelay)) | |
380 | 384 | then true | |
381 | 385 | else initialized()) | |
382 | 386 | then true | |
383 | 387 | else (i.caller != this)) | |
384 | 388 | then throw("Invalid initialize parameters") | |
385 | 389 | else ((updateAmm(_qtAstR, _bsAstR, 0) ++ updateSettings(_maxPriceImpact, _maxPriceSpread, _maxOracleDelay)) ++ [BooleanEntry(k_initialized, true), StringEntry(k_baseOracle, _baseOracleData), StringEntry(k_coordinatorAddress, toString(addressFromStringValue(_coordinator)))]) | |
386 | 390 | ||
387 | 391 | ||
388 | 392 | ||
389 | 393 | @Callable(i) | |
390 | 394 | func swapToBase (_amount,_minBaseAssetAmount) = { | |
391 | 395 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
392 | 396 | if ((sync == sync)) | |
393 | 397 | then { | |
394 | 398 | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
395 | 399 | if ((ensureCalledOnce == ensureCalledOnce)) | |
396 | 400 | then if (if (if (!(initialized())) | |
397 | 401 | then true | |
398 | 402 | else paused()) | |
399 | 403 | then true | |
400 | 404 | else (i.caller != spotAddress())) | |
401 | 405 | then throw("Invalid swapToBase parameters") | |
402 | 406 | else { | |
403 | - | let $ | |
404 | - | let amountBaseAssetBought = $ | |
405 | - | let quoteAssetReserveAfter = $ | |
406 | - | let baseAssetReserveAfter = $ | |
407 | - | let totalPositionSizeAfter = $ | |
407 | + | let $t01803918196 = swapInput(true, _amount) | |
408 | + | let amountBaseAssetBought = $t01803918196._1 | |
409 | + | let quoteAssetReserveAfter = $t01803918196._2 | |
410 | + | let baseAssetReserveAfter = $t01803918196._3 | |
411 | + | let totalPositionSizeAfter = $t01803918196._4 | |
408 | 412 | let update = updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter) | |
409 | 413 | $Tuple2(update, amountBaseAssetBought) | |
410 | 414 | } | |
411 | 415 | else throw("Strict value is not equal to itself.") | |
412 | 416 | } | |
413 | 417 | else throw("Strict value is not equal to itself.") | |
414 | 418 | } | |
415 | 419 | ||
416 | 420 | ||
417 | 421 | ||
418 | 422 | @Callable(i) | |
419 | 423 | func swapToQuote (_amount,_minQuoteAssetAmount) = { | |
420 | 424 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
421 | 425 | if ((sync == sync)) | |
422 | 426 | then { | |
423 | 427 | let ensureCalledOnce = invoke(this, "ensureCalledOnce", nil, nil) | |
424 | 428 | if ((ensureCalledOnce == ensureCalledOnce)) | |
425 | 429 | then if (if (if (!(initialized())) | |
426 | 430 | then true | |
427 | 431 | else paused()) | |
428 | 432 | then true | |
429 | 433 | else (i.caller != spotAddress())) | |
430 | 434 | then throw("Invalid swapToQuote parameters") | |
431 | 435 | else { | |
432 | - | let $ | |
433 | - | let amountQuoteAssetBought = $ | |
434 | - | let quoteAssetReserveAfter = $ | |
435 | - | let baseAssetReserveAfter = $ | |
436 | + | let $t01874118899 = swapOutput(true, _amount, true) | |
437 | + | let amountQuoteAssetBought = $t01874118899._1 | |
438 | + | let quoteAssetReserveAfter = $t01874118899._2 | |
439 | + | let baseAssetReserveAfter = $t01874118899._3 | |
436 | 440 | let totalPositionSizeAfter = (totalPositionSize() - _amount) | |
437 | 441 | let update = updateAmm(quoteAssetReserveAfter, baseAssetReserveAfter, totalPositionSizeAfter) | |
438 | 442 | $Tuple2(update, amountQuoteAssetBought) | |
439 | 443 | } | |
440 | 444 | else throw("Strict value is not equal to itself.") | |
441 | 445 | } | |
442 | 446 | else throw("Strict value is not equal to itself.") | |
443 | 447 | } | |
444 | 448 | ||
445 | 449 | ||
446 | 450 | ||
447 | 451 | @Callable(i) | |
448 | 452 | func syncTerminalPriceToOracle () = { | |
449 | 453 | let _qtAstR = qtAstR() | |
450 | 454 | let _bsAstR = bsAstR() | |
451 | - | let $ | |
452 | - | let newQuoteAssetWeight = $ | |
453 | - | let newBaseAssetWeight = $ | |
455 | + | let $t01954519661 = getSyncTerminalPrice(getOraclePrice(), _qtAstR, _bsAstR) | |
456 | + | let newQuoteAssetWeight = $t01954519661._1 | |
457 | + | let newBaseAssetWeight = $t01954519661._2 | |
454 | 458 | updateAmmWeights(newQuoteAssetWeight, newBaseAssetWeight) | |
455 | 459 | } | |
456 | 460 | ||
457 | 461 | ||
458 | 462 | ||
459 | 463 | @Callable(i) | |
460 | 464 | func ensureCalledOnce () = if ((i.caller != this)) | |
461 | 465 | then throw("Invalid saveCurrentTxId parameters") | |
462 | 466 | else { | |
463 | 467 | let txId = toBase58String(i.transactionId) | |
464 | 468 | let lastTx = valueOrElse(getString(this, k_lastTx), "") | |
465 | 469 | if ((lastTx != txId)) | |
466 | 470 | then [StringEntry(k_lastTx, txId)] | |
467 | 471 | else throw("Can not call vAMM methods twice in one tx") | |
468 | 472 | } | |
469 | 473 | ||
470 | 474 | ||
471 | 475 | ||
472 | 476 | @Callable(i) | |
473 | 477 | func view_getTerminalAmmPrice () = { | |
474 | - | let $ | |
475 | - | let terminalQuoteAssetReserve = $ | |
476 | - | let terminalBaseAssetReserve = $ | |
478 | + | let $t02041520496 = getTerminalAmmState() | |
479 | + | let terminalQuoteAssetReserve = $t02041520496._1 | |
480 | + | let terminalBaseAssetReserve = $t02041520496._2 | |
477 | 481 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
478 | 482 | throw(toString(price)) | |
483 | + | } | |
484 | + | ||
485 | + | ||
486 | + | ||
487 | + | @Callable(i) | |
488 | + | func view_getPrices () = { | |
489 | + | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
490 | + | if ((sync == sync)) | |
491 | + | then { | |
492 | + | let $t02081620897 = getTerminalAmmState() | |
493 | + | let terminalQuoteAssetReserve = $t02081620897._1 | |
494 | + | let terminalBaseAssetReserve = $t02081620897._2 | |
495 | + | let terminalPrice = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
496 | + | let spotPrice = getSpotPrice() | |
497 | + | throw(((toString(terminalPrice) + ",") + toString(spotPrice))) | |
498 | + | } | |
499 | + | else throw("Strict value is not equal to itself.") | |
479 | 500 | } | |
480 | 501 | ||
481 | 502 | ||
482 | 503 | ||
483 | 504 | @Callable(i) | |
484 | 505 | func computeSpotPrice () = { | |
485 | 506 | let sync = invoke(this, "syncTerminalPriceToOracle", nil, nil) | |
486 | 507 | if ((sync == sync)) | |
487 | 508 | then { | |
488 | 509 | let result = getSpotPrice() | |
489 | 510 | $Tuple2(nil, result) | |
490 | 511 | } | |
491 | 512 | else throw("Strict value is not equal to itself.") | |
492 | 513 | } | |
493 | 514 | ||
494 | 515 | ||
495 | 516 | ||
496 | 517 | @Callable(i) | |
497 | 518 | func computeTerminalAmmPrice () = { | |
498 | - | let $ | |
499 | - | let terminalQuoteAssetReserve = $ | |
500 | - | let terminalBaseAssetReserve = $ | |
519 | + | let $t02164821729 = getTerminalAmmState() | |
520 | + | let terminalQuoteAssetReserve = $t02164821729._1 | |
521 | + | let terminalBaseAssetReserve = $t02164821729._2 | |
501 | 522 | let price = divd(muld(terminalQuoteAssetReserve, qtAstW()), muld(terminalBaseAssetReserve, bsAstW())) | |
502 | 523 | $Tuple2(nil, price) | |
503 | 524 | } | |
504 | 525 | ||
505 | 526 | ||
506 | 527 | @Verifier(tx) | |
507 | 528 | func verify () = { | |
508 | 529 | let coordinatorStr = getString(this, k_coordinatorAddress) | |
509 | 530 | if (isDefined(coordinatorStr)) | |
510 | 531 | then { | |
511 | 532 | let admin = getString(addressFromStringValue(value(coordinatorStr)), k_admin_address) | |
512 | 533 | if (isDefined(admin)) | |
513 | 534 | then valueOrElse(getBoolean(addressFromStringValue(value(admin)), ((("status_" + toString(this)) + "_") + toBase58String(tx.id))), false) | |
514 | 535 | else throw("unable to verify: admin not set in coordinator") | |
515 | 536 | } | |
516 | 537 | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
517 | 538 | } | |
518 | 539 |
github/deemru/w8io/169f3d6 73.94 ms ◑