tx · 2eRMakZAiTVoQTjgwM4DZZy2tdVZ6gmu1Yic1DngK2Pb 3MyiJb9yZnpyXJADhdEoNk3MT3FHKmbYRJX: -0.10000000 Waves 2020.04.01 15:32 [935078] smart account 3MyiJb9yZnpyXJADhdEoNk3MT3FHKmbYRJX > SELF 0.00000000 Waves
{ "type": 13, "id": "2eRMakZAiTVoQTjgwM4DZZy2tdVZ6gmu1Yic1DngK2Pb", "fee": 10000000, "feeAssetId": null, "timestamp": 1585744421842, "version": 1, "sender": "3MyiJb9yZnpyXJADhdEoNk3MT3FHKmbYRJX", "senderPublicKey": "HDqeggkNi96GMzyGv4AQMQms43nwSrvgMjTDznyivt8R", "proofs": [ "4Db3hHz42aNLME599UY4QKMutmQpjYju5bvADm3ZCF1P8VFYnWsrrzEnfQwkv6oUbRQg9x3Ae4eg6CXpf7ZkqdSX" ], "script": "base64:AAIDAAAAAAAAABUIARIDCgEIEgwKCgECAQIBAgECAQIAAAAYAQAAABZjb252ZXJ0V2F2ZXNUb05ldXRyaW5vAAAAAgAAAAZhbW91bnQAAAAFcHJpY2UJAABrAAAAAwkAAGsAAAADBQAAAAZhbW91bnQFAAAABXByaWNlAAAAAAAAAABkAAAAAAAAD0JAAAAAAAAF9eEAAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAgAAAAABAAAAGGdldE51bWJlckJ5QWRkcmVzc0FuZEtleQAAAAIAAAAHYWRkcmVzcwAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAAdhZGRyZXNzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUA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AAAAAAAAAAQkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgIAAAAFcHJpY2UFAAAACG5ld1ByaWNlCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQABLAAAAAICAAAABnByaWNlXwkAAaQAAAABBQAAAAZoZWlnaHQFAAAACG5ld1ByaWNlCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACAgAAAAtwcmljZV9pbmRleAUAAAANbmV3UHJpY2VJbmRleAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkAASwAAAACAgAAAAxwcmljZV9pbmRleF8JAAGkAAAAAQUAAAANbmV3UHJpY2VJbmRleAUAAAAGaGVpZ2h0CQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQABLAAAAAICAAAACGRlZmljaXRfCQABpAAAAAEFAAAABmhlaWdodAUAAAAHZGVmaWNpdAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkAASwAAAACAgAAAA9uZXV0cmlub1N1cHBseV8JAAGkAAAAAQUAAAAGaGVpZ2h0BQAAAA5uZXV0cmlub1N1cHBseQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkAASwAAAACAgAAABBkZWZpY2l0X3BlcmNlbnRfCQABpAAAAAEFAAAABmhlaWdodAMJAQAAAAIhPQAAAAIFAAAADm5ldXRyaW5vU3VwcGx5AAAAAAAAAAAACQAAaQAAAAIJAABoAAAAAgUAAAAHZGVmaWNpdAAAAAAAAAAAZAUAAAAObmV1dHJpbm9TdXBwbHkAAAAAAAAAAAAFAAAAA25pbAAAAADK2Fb0", "chainId": 84, "height": 935078, "spentComplexity": 0 } View: original | compacted Prev: 5WdRpAruCrvGsG8f4usC1W29JMVC9fTpWN1y3L4LxHny Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | func getNumberByKey (key) = match getInteger(this, key) { | |
5 | - | case a: Int => | |
6 | - | a | |
7 | - | case _ => | |
8 | - | 0 | |
9 | - | } | |
4 | + | func convertWavesToNeutrino (amount,price) = fraction(fraction(amount, price, 100), 1000000, 100000000) | |
10 | 5 | ||
11 | 6 | ||
12 | 7 | func getStringByKey (key) = match getString(this, key) { | |
17 | 12 | } | |
18 | 13 | ||
19 | 14 | ||
20 | - | func | |
21 | - | case a: | |
15 | + | func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) { | |
16 | + | case a: Int => | |
22 | 17 | a | |
23 | 18 | case _ => | |
24 | - | false | |
19 | + | 0 | |
20 | + | } | |
21 | + | ||
22 | + | ||
23 | + | func getOracleProvideHeight (ownerPub,height) = match getInteger(addressFromPublicKey(ownerPub), ("price_" + toString(height))) { | |
24 | + | case a: Int => | |
25 | + | a | |
26 | + | case _ => | |
27 | + | 0 | |
25 | 28 | } | |
26 | 29 | ||
27 | 30 | ||
33 | 36 | } | |
34 | 37 | ||
35 | 38 | ||
36 | - | func getNumberByAddressAndKey (address,key) = match getInteger(address, key) { | |
39 | + | func dropElementInJsonArray (array,element) = { | |
40 | + | let splitedArray = split(array, element) | |
41 | + | if ((take(splitedArray[1], 1) == ",")) | |
42 | + | then (splitedArray[0] + drop(splitedArray[1], 1)) | |
43 | + | else (dropRight(splitedArray[0], 1) + splitedArray[1]) | |
44 | + | } | |
45 | + | ||
46 | + | ||
47 | + | func convertJsonArrayToList (jsonArray) = split(jsonArray, ",") | |
48 | + | ||
49 | + | ||
50 | + | let price = match getInteger(this, "price") { | |
37 | 51 | case a: Int => | |
38 | 52 | a | |
39 | 53 | case _ => | |
40 | 54 | 0 | |
41 | 55 | } | |
42 | 56 | ||
57 | + | let priceIndex = match getInteger(this, "price_index") { | |
58 | + | case a: Int => | |
59 | + | a | |
60 | + | case _ => | |
61 | + | 0 | |
62 | + | } | |
43 | 63 | ||
44 | - | let WAVELET = 100000000 | |
64 | + | let isBlocked = match getBoolean(this, "is_blocked") { | |
65 | + | case a: Boolean => | |
66 | + | a | |
67 | + | case _ => | |
68 | + | false | |
69 | + | } | |
45 | 70 | ||
46 | - | let | |
71 | + | let percentPriceOffset = 7 | |
47 | 72 | ||
48 | - | let | |
73 | + | let pubKeyOracles = getStringByKey("oracles") | |
49 | 74 | ||
50 | - | let | |
75 | + | let pubKeyOraclesList = convertJsonArrayToList(pubKeyOracles) | |
51 | 76 | ||
52 | - | let | |
77 | + | let bftCoefficientOracle = 4 | |
53 | 78 | ||
54 | - | let | |
79 | + | let neutrinoAddress = addressFromPublicKey(fromBase58String("J4hU7VqLs2JAJXwFnjicQ97XShyZEqt8REC8fJHkTdKd")) | |
55 | 80 | ||
56 | - | let | |
81 | + | let liquidationAddress = addressFromPublicKey(fromBase58String("HDqeggkNi96GMzyGv4AQMQms43nwSrvgMjTDznyivt8R")) | |
57 | 82 | ||
58 | - | let | |
83 | + | let neutrinoAsset = fromBase58String("EyizrdEpB9yuh45Zv3f2UfxKLjcecrmvcq5DSP9fEwum") | |
59 | 84 | ||
60 | - | let NeutrinoContractKey = "neutrino_contract" | |
85 | + | let neutrinoLockedBalance = match getInteger(neutrinoAddress, "balance_lock_neutrino") { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
61 | 91 | ||
62 | - | let PriceKey = "price" | |
92 | + | let wavesLockedBalance = match getInteger(neutrinoAddress, "balance_lock_waves") { | |
93 | + | case a: Int => | |
94 | + | a | |
95 | + | case _ => | |
96 | + | 0 | |
97 | + | } | |
63 | 98 | ||
64 | - | let | |
99 | + | let reserve = (wavesBalance(neutrinoAddress) - wavesLockedBalance) | |
65 | 100 | ||
66 | - | let | |
101 | + | let neutrinoSupply = (((neutrinoLockedBalance + extract(assetInfo(neutrinoAsset)).quantity) - assetBalance(neutrinoAddress, neutrinoAsset)) - assetBalance(liquidationAddress, neutrinoAsset)) | |
67 | 102 | ||
68 | - | let | |
103 | + | let deficit = (neutrinoSupply - convertWavesToNeutrino(reserve, price)) | |
69 | 104 | ||
70 | - | let BalanceLockedkKey = "balance_lock_" | |
71 | - | ||
72 | - | let WavesLockedBalanceKey = (BalanceLockedkKey + "waves") | |
73 | - | ||
74 | - | let NeutrinoLockedBalanceKey = (BalanceLockedkKey + "neutrino") | |
75 | - | ||
76 | - | let FirstOrderKey = "order_first" | |
77 | - | ||
78 | - | let LastOrderKey = "order_last" | |
79 | - | ||
80 | - | func getOrderPrevKey (orderId) = ("order_prev_" + orderId) | |
105 | + | func findPricesInRange (prices) = { | |
106 | + | let minPercentBound = 90 | |
107 | + | let maxPercentBound = 110 | |
108 | + | let p0 = prices[0] | |
109 | + | let check0 = if ((0 >= prices[0])) | |
110 | + | then [0] | |
111 | + | else { | |
112 | + | let p01 = ((prices[1] * 100) / p0) | |
113 | + | let p02 = ((prices[2] * 100) / p0) | |
114 | + | let p03 = ((prices[3] * 100) / p0) | |
115 | + | let p04 = ((prices[4] * 100) / p0) | |
116 | + | let array1 = if (if ((maxPercentBound > p01)) | |
117 | + | then (p01 > minPercentBound) | |
118 | + | else false) | |
119 | + | then [1, 0] | |
120 | + | else [0] | |
121 | + | let array2 = if (if ((maxPercentBound > p02)) | |
122 | + | then (p02 > minPercentBound) | |
123 | + | else false) | |
124 | + | then 2 :: array1 | |
125 | + | else array1 | |
126 | + | let array3 = if (if ((maxPercentBound > p03)) | |
127 | + | then (p03 > minPercentBound) | |
128 | + | else false) | |
129 | + | then 3 :: array2 | |
130 | + | else array2 | |
131 | + | if (if ((maxPercentBound > p04)) | |
132 | + | then (p04 > minPercentBound) | |
133 | + | else false) | |
134 | + | then 4 :: array3 | |
135 | + | else array3 | |
136 | + | } | |
137 | + | let check1 = if ((size(check0) >= 3)) | |
138 | + | then check0 | |
139 | + | else { | |
140 | + | let p1 = prices[1] | |
141 | + | if ((0 >= p1)) | |
142 | + | then [1] | |
143 | + | else { | |
144 | + | let p10 = ((prices[0] * 100) / p1) | |
145 | + | let p12 = ((prices[2] * 100) / p1) | |
146 | + | let p13 = ((prices[3] * 100) / p1) | |
147 | + | let p14 = ((prices[4] * 100) / p1) | |
148 | + | let array1 = if (if ((maxPercentBound > p10)) | |
149 | + | then (p10 > minPercentBound) | |
150 | + | else false) | |
151 | + | then [0, 1] | |
152 | + | else [1] | |
153 | + | let array2 = if (if ((maxPercentBound > p12)) | |
154 | + | then (p12 > minPercentBound) | |
155 | + | else false) | |
156 | + | then 2 :: array1 | |
157 | + | else array1 | |
158 | + | let array3 = if (if ((maxPercentBound > p13)) | |
159 | + | then (p13 > minPercentBound) | |
160 | + | else false) | |
161 | + | then 3 :: array2 | |
162 | + | else array2 | |
163 | + | if (if ((maxPercentBound > p14)) | |
164 | + | then (p14 > minPercentBound) | |
165 | + | else false) | |
166 | + | then 4 :: array3 | |
167 | + | else array3 | |
168 | + | } | |
169 | + | } | |
170 | + | let check2 = if ((size(check1) >= 3)) | |
171 | + | then check1 | |
172 | + | else { | |
173 | + | let p2 = prices[2] | |
174 | + | if ((0 >= p2)) | |
175 | + | then [2] | |
176 | + | else { | |
177 | + | let p20 = ((prices[0] * 100) / p2) | |
178 | + | let p21 = ((prices[1] * 100) / p2) | |
179 | + | let p23 = ((prices[3] * 100) / p2) | |
180 | + | let p24 = ((prices[4] * 100) / p2) | |
181 | + | let array1 = if (if ((maxPercentBound > p20)) | |
182 | + | then (p20 > minPercentBound) | |
183 | + | else false) | |
184 | + | then [0, 2] | |
185 | + | else [2] | |
186 | + | let array2 = if (if ((maxPercentBound > p21)) | |
187 | + | then (p21 > minPercentBound) | |
188 | + | else false) | |
189 | + | then 1 :: array1 | |
190 | + | else array1 | |
191 | + | let array3 = if (if ((maxPercentBound > p23)) | |
192 | + | then (p23 > minPercentBound) | |
193 | + | else false) | |
194 | + | then 3 :: array2 | |
195 | + | else array2 | |
196 | + | if (if ((maxPercentBound > p24)) | |
197 | + | then (p24 > minPercentBound) | |
198 | + | else false) | |
199 | + | then 4 :: array3 | |
200 | + | else array3 | |
201 | + | } | |
202 | + | } | |
203 | + | let check3 = if ((size(check2) >= 3)) | |
204 | + | then check2 | |
205 | + | else { | |
206 | + | let p3 = prices[3] | |
207 | + | if ((0 >= p3)) | |
208 | + | then [3] | |
209 | + | else { | |
210 | + | let p30 = ((prices[0] * 100) / p3) | |
211 | + | let p31 = ((prices[1] * 100) / p3) | |
212 | + | let p32 = ((prices[2] * 100) / p3) | |
213 | + | let p34 = ((prices[4] * 100) / p3) | |
214 | + | let array1 = if (if ((maxPercentBound > p30)) | |
215 | + | then (p30 > minPercentBound) | |
216 | + | else false) | |
217 | + | then [0, 3] | |
218 | + | else [3] | |
219 | + | let array2 = if (if ((maxPercentBound > p31)) | |
220 | + | then (p31 > minPercentBound) | |
221 | + | else false) | |
222 | + | then 1 :: array1 | |
223 | + | else array1 | |
224 | + | let array3 = if (if ((maxPercentBound > p32)) | |
225 | + | then (p32 > minPercentBound) | |
226 | + | else false) | |
227 | + | then 2 :: array2 | |
228 | + | else array2 | |
229 | + | if (if ((maxPercentBound > p34)) | |
230 | + | then (p34 > minPercentBound) | |
231 | + | else false) | |
232 | + | then 4 :: array3 | |
233 | + | else array3 | |
234 | + | } | |
235 | + | } | |
236 | + | if ((size(check3) >= 3)) | |
237 | + | then check3 | |
238 | + | else { | |
239 | + | let p4 = prices[4] | |
240 | + | if ((0 >= p4)) | |
241 | + | then [4] | |
242 | + | else { | |
243 | + | let p40 = ((prices[0] * 100) / p4) | |
244 | + | let p41 = ((prices[1] * 100) / p4) | |
245 | + | let p42 = ((prices[2] * 100) / p4) | |
246 | + | let p43 = ((prices[3] * 100) / p4) | |
247 | + | let array1 = if (if ((maxPercentBound > p40)) | |
248 | + | then (p40 > minPercentBound) | |
249 | + | else false) | |
250 | + | then [0, 4] | |
251 | + | else [4] | |
252 | + | let array2 = if (if ((maxPercentBound > p41)) | |
253 | + | then (p41 > minPercentBound) | |
254 | + | else false) | |
255 | + | then 1 :: array1 | |
256 | + | else array1 | |
257 | + | let array3 = if (if ((maxPercentBound > p42)) | |
258 | + | then (p42 > minPercentBound) | |
259 | + | else false) | |
260 | + | then 2 :: array2 | |
261 | + | else array2 | |
262 | + | if (if ((maxPercentBound > p43)) | |
263 | + | then (p43 > minPercentBound) | |
264 | + | else false) | |
265 | + | then 3 :: array3 | |
266 | + | else array3 | |
267 | + | } | |
268 | + | } | |
269 | + | } | |
81 | 270 | ||
82 | 271 | ||
83 | - | func getOrderNextKey (orderId) = ("order_next_" + orderId) | |
84 | - | ||
85 | - | ||
86 | - | func getOrderTotalKey (orderId) = ("order_total_" + orderId) | |
87 | - | ||
88 | - | ||
89 | - | func getOrderOwnerKey (orderId) = ("order_owner_" + orderId) | |
90 | - | ||
91 | - | ||
92 | - | func getOrderHeightKey (orderId) = ("order_height_" + orderId) | |
93 | - | ||
94 | - | ||
95 | - | func getOrderStatusKey (orderId) = ("order_status_" + orderId) | |
96 | - | ||
97 | - | ||
98 | - | func getOrderFilledTotalKey (orderId) = ("order_filled_total_" + orderId) | |
99 | - | ||
100 | - | ||
101 | - | func getLastOrderOwnerKey (owner) = ("last_order_owner_" + owner) | |
102 | - | ||
103 | - | ||
104 | - | func convertNeutrinoToWaves (amount,price) = fraction(fraction(amount, 100, price), WAVELET, PAULI) | |
105 | - | ||
106 | - | ||
107 | - | func convertWavesToNeutrino (amount,price) = fraction(fraction(amount, price, 100), PAULI, WAVELET) | |
108 | - | ||
109 | - | ||
110 | - | func convertWavesToBond (amount,price) = convertWavesToNeutrino(amount, price) | |
111 | - | ||
112 | - | ||
113 | - | let neutrinoContract = addressFromStringValue(getStringByKey(NeutrinoContractKey)) | |
114 | - | ||
115 | - | let controlContract = addressFromStringValue(getStringByAddressAndKey(neutrinoContract, ControlContractKey)) | |
116 | - | ||
117 | - | let liquidationContract = this | |
118 | - | ||
119 | - | let neutrinoAssetId = fromBase58String(getStringByAddressAndKey(neutrinoContract, NeutrinoAssetIdKey)) | |
120 | - | ||
121 | - | let bondAssetId = fromBase58String("Qh28HvUAcFboD1GsAcyURQjNW6mdpuGvXVgFS9e3CzC") | |
122 | - | ||
123 | - | let firstOrder = getStringByKey(FirstOrderKey) | |
124 | - | ||
125 | - | let lastOrder = getStringByKey(LastOrderKey) | |
126 | - | ||
127 | - | let isBlocked = getBoolByAddressAndKey(controlContract, "is_blocked") | |
128 | - | ||
129 | - | let currentPrice = getNumberByAddressAndKey(controlContract, PriceKey) | |
130 | - | ||
131 | - | let neutrinoLockedBalance = getNumberByAddressAndKey(neutrinoContract, NeutrinoLockedBalanceKey) | |
132 | - | ||
133 | - | let wavesLockedBalance = getNumberByAddressAndKey(neutrinoContract, WavesLockedBalanceKey) | |
134 | - | ||
135 | - | let reserve = (wavesBalance(neutrinoContract) - wavesLockedBalance) | |
136 | - | ||
137 | - | let neutrinoSupply = (((neutrinoLockedBalance + extract(assetInfo(neutrinoAssetId)).quantity) - assetBalance(neutrinoContract, neutrinoAssetId)) - assetBalance(liquidationContract, neutrinoAssetId)) | |
138 | - | ||
139 | - | let surplus = (convertWavesToNeutrino(reserve, currentPrice) - neutrinoSupply) | |
140 | - | ||
141 | - | func getOrderTotal (id) = getNumberByKey(getOrderTotalKey(id)) | |
142 | - | ||
143 | - | ||
144 | - | func getOrderOwner (id) = getStringByKey(getOrderOwnerKey(id)) | |
145 | - | ||
146 | - | ||
147 | - | func getOrderStatus (id) = getStringByKey(getOrderStatusKey(id)) | |
148 | - | ||
149 | - | ||
150 | - | func getOrderFilledTotal (id) = getNumberByKey(getOrderFilledTotalKey(id)) | |
151 | - | ||
152 | - | ||
153 | - | func getOrderPrev (id) = getStringByKey(getOrderPrevKey(id)) | |
154 | - | ||
155 | - | ||
156 | - | func getOrderNext (id) = getStringByKey(getOrderNextKey(id)) | |
157 | - | ||
158 | - | ||
159 | - | func getOrderHeight (id) = getNumberByKey(getOrderHeightKey(id)) | |
160 | - | ||
161 | - | ||
162 | - | func getLastOrderOwner (owner) = getStringByKey(getLastOrderOwnerKey(owner)) | |
272 | + | func formattingPriceMsg (price,height) = toBytes((((("WAVESNEUTRINOPREFIX" + "_") + toString(height)) + "_") + toString(price))) | |
163 | 273 | ||
164 | 274 | ||
165 | 275 | @Callable(i) | |
166 | - | func addLiquidationOrder () = { | |
167 | - | let pmt = extract(i.payment) | |
168 | - | let newOrderId = toBase58String(keccak256((((toBytes(pmt.amount) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
169 | - | let nextOrder = getOrderNext(lastOrder) | |
170 | - | let orderStatus = getOrderStatus(lastOrder) | |
171 | - | let owner = toString(i.caller) | |
172 | - | if (isBlocked) | |
173 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
174 | - | else if ((pmt.assetId != bondAssetId)) | |
175 | - | then throw("can use appropriate neutrino bonds tokens only") | |
176 | - | else if ((getOrderOwner(newOrderId) != "")) | |
177 | - | then throw("an order is already exists") | |
178 | - | else if ((nextOrder != "")) | |
179 | - | then throw(("nextOrder is not last. Info:" + nextOrder)) | |
180 | - | else if (if ((firstOrder != "")) | |
181 | - | then (lastOrder == "") | |
182 | - | else false) | |
183 | - | then throw("invalid last order") | |
184 | - | else if (if ((firstOrder != "")) | |
185 | - | then (orderStatus != NEW) | |
186 | - | else false) | |
187 | - | then throw("last order status is not new") | |
188 | - | else if ((PAULI > pmt.amount)) | |
189 | - | then throw("order amount must be higher than 1 NSBT") | |
190 | - | else WriteSet([DataEntry(getLastOrderOwnerKey(owner), newOrderId), DataEntry(getOrderPrevKey(newOrderId), lastOrder), DataEntry(getOrderNextKey(lastOrder), if ((lastOrder == "")) | |
191 | - | then "" | |
192 | - | else newOrderId), DataEntry(FirstOrderKey, if ((firstOrder == "")) | |
193 | - | then newOrderId | |
194 | - | else firstOrder), DataEntry(LastOrderKey, newOrderId), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW)]) | |
276 | + | func callEmergencyShutdown (reason) = { | |
277 | + | let AutoEmergencyOracleAddress = "3Mwho43kPZa9w1y91NJsAoYxgQpsg3JjGby" | |
278 | + | let callerAddress = toString(i.caller) | |
279 | + | if ((AutoEmergencyOracleAddress != callerAddress)) | |
280 | + | then throw("caller must be one an emergency oracle") | |
281 | + | else WriteSet([DataEntry("is_blocked", true), DataEntry("is_blocked_caller", callerAddress), DataEntry("is_blocked_reason", reason)]) | |
195 | 282 | } | |
196 | 283 | ||
197 | 284 | ||
198 | 285 | ||
199 | 286 | @Callable(i) | |
200 | - | func addLiquidationOrderTest () = { | |
201 | - | let pmt = extract(i.payment) | |
202 | - | let newOrderId = toBase58String(keccak256((((toBytes(pmt.amount) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
203 | - | let owner = toString(i.caller) | |
204 | - | let nextOrder = getOrderNext(lastOrder) | |
205 | - | let orderStatus = getOrderStatus(lastOrder) | |
206 | - | if (isBlocked) | |
207 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
208 | - | else if (((1 + 1) > 1)) | |
209 | - | then throw("running here!") | |
210 | - | else WriteSet([DataEntry(getLastOrderOwnerKey(owner), newOrderId)]) | |
211 | - | } | |
212 | - | ||
213 | - | ||
214 | - | ||
215 | - | @Callable(i) | |
216 | - | func cancelOrder (orderId) = { | |
217 | - | let owner = getOrderOwner(orderId) | |
218 | - | let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId)) | |
219 | - | let nextOrder = getOrderNext(orderId) | |
220 | - | let prevOrder = getOrderPrev(orderId) | |
221 | - | if (isBlocked) | |
222 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
223 | - | else if ((owner != toString(i.caller))) | |
224 | - | then throw("permission denied") | |
225 | - | else if ((getOrderStatus(orderId) != NEW)) | |
226 | - | then throw("invalid order status") | |
227 | - | else ScriptResult(WriteSet([DataEntry(FirstOrderKey, if ((firstOrder == orderId)) | |
228 | - | then nextOrder | |
229 | - | else firstOrder), DataEntry(LastOrderKey, if ((lastOrder == orderId)) | |
230 | - | then prevOrder | |
231 | - | else lastOrder), DataEntry(getOrderNextKey(prevOrder), nextOrder), DataEntry(getOrderPrevKey(nextOrder), prevOrder), DataEntry(getOrderStatusKey(orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, bondAssetId)])) | |
232 | - | } | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func liquidateBond () = { | |
238 | - | let surplusPositive = if ((0 >= surplus)) | |
239 | - | then 0 | |
240 | - | else surplus | |
241 | - | let liquidationBalance = assetBalance(this, neutrinoAssetId) | |
242 | - | let returnAmount = if ((surplusPositive >= liquidationBalance)) | |
243 | - | then 0 | |
244 | - | else (liquidationBalance - surplusPositive) | |
245 | - | let surplusBond = surplusPositive | |
246 | - | if (isBlocked) | |
247 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
248 | - | else if (if ((returnAmount == 0)) | |
249 | - | then (liquidationBalance == 0) | |
250 | - | else false) | |
251 | - | then throw("cannot liquidate order without neutrino on the smart contract") | |
252 | - | else if ((returnAmount > 0)) | |
253 | - | then TransferSet([ScriptTransfer(neutrinoContract, returnAmount, neutrinoAssetId)]) | |
254 | - | else if ((0 >= surplusBond)) | |
255 | - | then throw("there is no proficit on the smart contract now") | |
256 | - | else if ((firstOrder == "")) | |
257 | - | then throw("empty orderbook") | |
258 | - | else { | |
259 | - | let nextOrder = getOrderNext(firstOrder) | |
260 | - | let orderTotal = getOrderTotal(firstOrder) | |
261 | - | let orderOwner = getOrderOwner(firstOrder) | |
262 | - | let filledTotal = getOrderFilledTotal(firstOrder) | |
263 | - | let amount = (orderTotal - filledTotal) | |
264 | - | let newStatus = if ((surplusBond >= amount)) | |
265 | - | then FILLED | |
266 | - | else NEW | |
267 | - | let fillableOrderAmount = if ((surplusBond >= amount)) | |
268 | - | then amount | |
269 | - | else surplusBond | |
270 | - | ScriptResult(WriteSet([DataEntry(getOrderPrevKey(nextOrder), if ((newStatus == FILLED)) | |
271 | - | then "" | |
272 | - | else firstOrder), DataEntry(FirstOrderKey, if ((newStatus == FILLED)) | |
273 | - | then nextOrder | |
274 | - | else firstOrder), DataEntry(LastOrderKey, if (if ((newStatus == FILLED)) | |
275 | - | then (firstOrder == lastOrder) | |
276 | - | else false) | |
277 | - | then "" | |
278 | - | else lastOrder), DataEntry(getOrderFilledTotalKey(firstOrder), (filledTotal + fillableOrderAmount)), DataEntry(getOrderStatusKey(firstOrder), newStatus)]), TransferSet([ScriptTransfer(addressFromStringValue(orderOwner), fillableOrderAmount, neutrinoAssetId)])) | |
279 | - | } | |
280 | - | } | |
287 | + | func finalizeCurrentPrice (price1,sign1,price2,sign2,price3,sign3,price4,sign4,price5,sign5) = if (isBlocked) | |
288 | + | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
289 | + | else if (( match getInteger(this, ("price_" + toString(height))) { | |
290 | + | case a: Int => | |
291 | + | a | |
292 | + | case _ => | |
293 | + | 0 | |
294 | + | } != 0)) | |
295 | + | then throw("wait next block") | |
296 | + | else if ((pubKeyOraclesList[(height % 5)] != toBase58String(i.callerPublicKey))) | |
297 | + | then throw(((("Out of turn finalization: " + toString(height)) + " block should be finalize by ") + pubKeyOraclesList[(height % 5)])) | |
298 | + | else { | |
299 | + | let prices = [if ((price1 > 0)) | |
300 | + | then price1 | |
301 | + | else 0, if ((price2 > 0)) | |
302 | + | then price2 | |
303 | + | else 0, if ((price3 > 0)) | |
304 | + | then price3 | |
305 | + | else 0, if ((price4 > 0)) | |
306 | + | then price4 | |
307 | + | else 0, if ((price5 > 0)) | |
308 | + | then price5 | |
309 | + | else 0] | |
310 | + | let pricesInRange = findPricesInRange(prices) | |
311 | + | let priceProvidingCount = size(pricesInRange) | |
312 | + | if ((3 > priceProvidingCount)) | |
313 | + | then throw(((((((((((((((((((((("Could not finalize price because of big variation: height=" + toString(height)) + " | |
314 | + | ") + pubKeyOraclesList[0]) + "=") + toString(prices[0])) + " | |
315 | + | ") + pubKeyOraclesList[1]) + "=") + toString(prices[1])) + " | |
316 | + | ") + pubKeyOraclesList[2]) + "=") + toString(prices[2])) + " | |
317 | + | ") + pubKeyOraclesList[3]) + "=") + toString(prices[3])) + " | |
318 | + | ") + pubKeyOraclesList[4]) + "=") + toString(prices[4]))) | |
319 | + | else { | |
320 | + | let sum1 = ((prices[pricesInRange[0]] + prices[pricesInRange[1]]) + prices[pricesInRange[2]]) | |
321 | + | let sum2 = if ((priceProvidingCount >= 4)) | |
322 | + | then (sum1 + prices[pricesInRange[3]]) | |
323 | + | else sum1 | |
324 | + | let priceSum = if ((priceProvidingCount >= 5)) | |
325 | + | then (sum2 + prices[pricesInRange[4]]) | |
326 | + | else sum2 | |
327 | + | if ((priceProvidingCount >= 6)) | |
328 | + | then throw("Invalid pricesInRange creation") | |
329 | + | else { | |
330 | + | let newPrice = (priceSum / priceProvidingCount) | |
331 | + | if (if ((newPrice >= (price + ((price * percentPriceOffset) / 100)))) | |
332 | + | then true | |
333 | + | else ((price - ((price * percentPriceOffset) / 100)) >= newPrice)) | |
334 | + | then WriteSet([DataEntry("is_blocked", true), DataEntry((("black_swarm_price" + "_") + toString(height)), newPrice)]) | |
335 | + | else { | |
336 | + | let newPriceIndex = (priceIndex + 1) | |
337 | + | WriteSet([DataEntry("price", newPrice), DataEntry(("price_" + toString(height)), newPrice), DataEntry("price_index", newPriceIndex), DataEntry(("price_index_" + toString(newPriceIndex)), height), DataEntry(("deficit_" + toString(height)), deficit), DataEntry(("neutrinoSupply_" + toString(height)), neutrinoSupply), DataEntry(("deficit_percent_" + toString(height)), if ((neutrinoSupply != 0)) | |
338 | + | then ((deficit * 100) / neutrinoSupply) | |
339 | + | else 0)]) | |
340 | + | } | |
341 | + | } | |
342 | + | } | |
343 | + | } | |
281 | 344 | ||
282 | 345 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | func getNumberByKey (key) = match getInteger(this, key) { | |
5 | - | case a: Int => | |
6 | - | a | |
7 | - | case _ => | |
8 | - | 0 | |
9 | - | } | |
4 | + | func convertWavesToNeutrino (amount,price) = fraction(fraction(amount, price, 100), 1000000, 100000000) | |
10 | 5 | ||
11 | 6 | ||
12 | 7 | func getStringByKey (key) = match getString(this, key) { | |
13 | 8 | case a: String => | |
14 | 9 | a | |
15 | 10 | case _ => | |
16 | 11 | "" | |
17 | 12 | } | |
18 | 13 | ||
19 | 14 | ||
20 | - | func | |
21 | - | case a: | |
15 | + | func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) { | |
16 | + | case a: Int => | |
22 | 17 | a | |
23 | 18 | case _ => | |
24 | - | false | |
19 | + | 0 | |
20 | + | } | |
21 | + | ||
22 | + | ||
23 | + | func getOracleProvideHeight (ownerPub,height) = match getInteger(addressFromPublicKey(ownerPub), ("price_" + toString(height))) { | |
24 | + | case a: Int => | |
25 | + | a | |
26 | + | case _ => | |
27 | + | 0 | |
25 | 28 | } | |
26 | 29 | ||
27 | 30 | ||
28 | 31 | func getStringByAddressAndKey (address,key) = match getString(address, key) { | |
29 | 32 | case a: String => | |
30 | 33 | a | |
31 | 34 | case _ => | |
32 | 35 | "" | |
33 | 36 | } | |
34 | 37 | ||
35 | 38 | ||
36 | - | func getNumberByAddressAndKey (address,key) = match getInteger(address, key) { | |
39 | + | func dropElementInJsonArray (array,element) = { | |
40 | + | let splitedArray = split(array, element) | |
41 | + | if ((take(splitedArray[1], 1) == ",")) | |
42 | + | then (splitedArray[0] + drop(splitedArray[1], 1)) | |
43 | + | else (dropRight(splitedArray[0], 1) + splitedArray[1]) | |
44 | + | } | |
45 | + | ||
46 | + | ||
47 | + | func convertJsonArrayToList (jsonArray) = split(jsonArray, ",") | |
48 | + | ||
49 | + | ||
50 | + | let price = match getInteger(this, "price") { | |
37 | 51 | case a: Int => | |
38 | 52 | a | |
39 | 53 | case _ => | |
40 | 54 | 0 | |
41 | 55 | } | |
42 | 56 | ||
57 | + | let priceIndex = match getInteger(this, "price_index") { | |
58 | + | case a: Int => | |
59 | + | a | |
60 | + | case _ => | |
61 | + | 0 | |
62 | + | } | |
43 | 63 | ||
44 | - | let WAVELET = 100000000 | |
64 | + | let isBlocked = match getBoolean(this, "is_blocked") { | |
65 | + | case a: Boolean => | |
66 | + | a | |
67 | + | case _ => | |
68 | + | false | |
69 | + | } | |
45 | 70 | ||
46 | - | let | |
71 | + | let percentPriceOffset = 7 | |
47 | 72 | ||
48 | - | let | |
73 | + | let pubKeyOracles = getStringByKey("oracles") | |
49 | 74 | ||
50 | - | let | |
75 | + | let pubKeyOraclesList = convertJsonArrayToList(pubKeyOracles) | |
51 | 76 | ||
52 | - | let | |
77 | + | let bftCoefficientOracle = 4 | |
53 | 78 | ||
54 | - | let | |
79 | + | let neutrinoAddress = addressFromPublicKey(fromBase58String("J4hU7VqLs2JAJXwFnjicQ97XShyZEqt8REC8fJHkTdKd")) | |
55 | 80 | ||
56 | - | let | |
81 | + | let liquidationAddress = addressFromPublicKey(fromBase58String("HDqeggkNi96GMzyGv4AQMQms43nwSrvgMjTDznyivt8R")) | |
57 | 82 | ||
58 | - | let | |
83 | + | let neutrinoAsset = fromBase58String("EyizrdEpB9yuh45Zv3f2UfxKLjcecrmvcq5DSP9fEwum") | |
59 | 84 | ||
60 | - | let NeutrinoContractKey = "neutrino_contract" | |
85 | + | let neutrinoLockedBalance = match getInteger(neutrinoAddress, "balance_lock_neutrino") { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
61 | 91 | ||
62 | - | let PriceKey = "price" | |
92 | + | let wavesLockedBalance = match getInteger(neutrinoAddress, "balance_lock_waves") { | |
93 | + | case a: Int => | |
94 | + | a | |
95 | + | case _ => | |
96 | + | 0 | |
97 | + | } | |
63 | 98 | ||
64 | - | let | |
99 | + | let reserve = (wavesBalance(neutrinoAddress) - wavesLockedBalance) | |
65 | 100 | ||
66 | - | let | |
101 | + | let neutrinoSupply = (((neutrinoLockedBalance + extract(assetInfo(neutrinoAsset)).quantity) - assetBalance(neutrinoAddress, neutrinoAsset)) - assetBalance(liquidationAddress, neutrinoAsset)) | |
67 | 102 | ||
68 | - | let | |
103 | + | let deficit = (neutrinoSupply - convertWavesToNeutrino(reserve, price)) | |
69 | 104 | ||
70 | - | let BalanceLockedkKey = "balance_lock_" | |
71 | - | ||
72 | - | let WavesLockedBalanceKey = (BalanceLockedkKey + "waves") | |
73 | - | ||
74 | - | let NeutrinoLockedBalanceKey = (BalanceLockedkKey + "neutrino") | |
75 | - | ||
76 | - | let FirstOrderKey = "order_first" | |
77 | - | ||
78 | - | let LastOrderKey = "order_last" | |
79 | - | ||
80 | - | func getOrderPrevKey (orderId) = ("order_prev_" + orderId) | |
105 | + | func findPricesInRange (prices) = { | |
106 | + | let minPercentBound = 90 | |
107 | + | let maxPercentBound = 110 | |
108 | + | let p0 = prices[0] | |
109 | + | let check0 = if ((0 >= prices[0])) | |
110 | + | then [0] | |
111 | + | else { | |
112 | + | let p01 = ((prices[1] * 100) / p0) | |
113 | + | let p02 = ((prices[2] * 100) / p0) | |
114 | + | let p03 = ((prices[3] * 100) / p0) | |
115 | + | let p04 = ((prices[4] * 100) / p0) | |
116 | + | let array1 = if (if ((maxPercentBound > p01)) | |
117 | + | then (p01 > minPercentBound) | |
118 | + | else false) | |
119 | + | then [1, 0] | |
120 | + | else [0] | |
121 | + | let array2 = if (if ((maxPercentBound > p02)) | |
122 | + | then (p02 > minPercentBound) | |
123 | + | else false) | |
124 | + | then 2 :: array1 | |
125 | + | else array1 | |
126 | + | let array3 = if (if ((maxPercentBound > p03)) | |
127 | + | then (p03 > minPercentBound) | |
128 | + | else false) | |
129 | + | then 3 :: array2 | |
130 | + | else array2 | |
131 | + | if (if ((maxPercentBound > p04)) | |
132 | + | then (p04 > minPercentBound) | |
133 | + | else false) | |
134 | + | then 4 :: array3 | |
135 | + | else array3 | |
136 | + | } | |
137 | + | let check1 = if ((size(check0) >= 3)) | |
138 | + | then check0 | |
139 | + | else { | |
140 | + | let p1 = prices[1] | |
141 | + | if ((0 >= p1)) | |
142 | + | then [1] | |
143 | + | else { | |
144 | + | let p10 = ((prices[0] * 100) / p1) | |
145 | + | let p12 = ((prices[2] * 100) / p1) | |
146 | + | let p13 = ((prices[3] * 100) / p1) | |
147 | + | let p14 = ((prices[4] * 100) / p1) | |
148 | + | let array1 = if (if ((maxPercentBound > p10)) | |
149 | + | then (p10 > minPercentBound) | |
150 | + | else false) | |
151 | + | then [0, 1] | |
152 | + | else [1] | |
153 | + | let array2 = if (if ((maxPercentBound > p12)) | |
154 | + | then (p12 > minPercentBound) | |
155 | + | else false) | |
156 | + | then 2 :: array1 | |
157 | + | else array1 | |
158 | + | let array3 = if (if ((maxPercentBound > p13)) | |
159 | + | then (p13 > minPercentBound) | |
160 | + | else false) | |
161 | + | then 3 :: array2 | |
162 | + | else array2 | |
163 | + | if (if ((maxPercentBound > p14)) | |
164 | + | then (p14 > minPercentBound) | |
165 | + | else false) | |
166 | + | then 4 :: array3 | |
167 | + | else array3 | |
168 | + | } | |
169 | + | } | |
170 | + | let check2 = if ((size(check1) >= 3)) | |
171 | + | then check1 | |
172 | + | else { | |
173 | + | let p2 = prices[2] | |
174 | + | if ((0 >= p2)) | |
175 | + | then [2] | |
176 | + | else { | |
177 | + | let p20 = ((prices[0] * 100) / p2) | |
178 | + | let p21 = ((prices[1] * 100) / p2) | |
179 | + | let p23 = ((prices[3] * 100) / p2) | |
180 | + | let p24 = ((prices[4] * 100) / p2) | |
181 | + | let array1 = if (if ((maxPercentBound > p20)) | |
182 | + | then (p20 > minPercentBound) | |
183 | + | else false) | |
184 | + | then [0, 2] | |
185 | + | else [2] | |
186 | + | let array2 = if (if ((maxPercentBound > p21)) | |
187 | + | then (p21 > minPercentBound) | |
188 | + | else false) | |
189 | + | then 1 :: array1 | |
190 | + | else array1 | |
191 | + | let array3 = if (if ((maxPercentBound > p23)) | |
192 | + | then (p23 > minPercentBound) | |
193 | + | else false) | |
194 | + | then 3 :: array2 | |
195 | + | else array2 | |
196 | + | if (if ((maxPercentBound > p24)) | |
197 | + | then (p24 > minPercentBound) | |
198 | + | else false) | |
199 | + | then 4 :: array3 | |
200 | + | else array3 | |
201 | + | } | |
202 | + | } | |
203 | + | let check3 = if ((size(check2) >= 3)) | |
204 | + | then check2 | |
205 | + | else { | |
206 | + | let p3 = prices[3] | |
207 | + | if ((0 >= p3)) | |
208 | + | then [3] | |
209 | + | else { | |
210 | + | let p30 = ((prices[0] * 100) / p3) | |
211 | + | let p31 = ((prices[1] * 100) / p3) | |
212 | + | let p32 = ((prices[2] * 100) / p3) | |
213 | + | let p34 = ((prices[4] * 100) / p3) | |
214 | + | let array1 = if (if ((maxPercentBound > p30)) | |
215 | + | then (p30 > minPercentBound) | |
216 | + | else false) | |
217 | + | then [0, 3] | |
218 | + | else [3] | |
219 | + | let array2 = if (if ((maxPercentBound > p31)) | |
220 | + | then (p31 > minPercentBound) | |
221 | + | else false) | |
222 | + | then 1 :: array1 | |
223 | + | else array1 | |
224 | + | let array3 = if (if ((maxPercentBound > p32)) | |
225 | + | then (p32 > minPercentBound) | |
226 | + | else false) | |
227 | + | then 2 :: array2 | |
228 | + | else array2 | |
229 | + | if (if ((maxPercentBound > p34)) | |
230 | + | then (p34 > minPercentBound) | |
231 | + | else false) | |
232 | + | then 4 :: array3 | |
233 | + | else array3 | |
234 | + | } | |
235 | + | } | |
236 | + | if ((size(check3) >= 3)) | |
237 | + | then check3 | |
238 | + | else { | |
239 | + | let p4 = prices[4] | |
240 | + | if ((0 >= p4)) | |
241 | + | then [4] | |
242 | + | else { | |
243 | + | let p40 = ((prices[0] * 100) / p4) | |
244 | + | let p41 = ((prices[1] * 100) / p4) | |
245 | + | let p42 = ((prices[2] * 100) / p4) | |
246 | + | let p43 = ((prices[3] * 100) / p4) | |
247 | + | let array1 = if (if ((maxPercentBound > p40)) | |
248 | + | then (p40 > minPercentBound) | |
249 | + | else false) | |
250 | + | then [0, 4] | |
251 | + | else [4] | |
252 | + | let array2 = if (if ((maxPercentBound > p41)) | |
253 | + | then (p41 > minPercentBound) | |
254 | + | else false) | |
255 | + | then 1 :: array1 | |
256 | + | else array1 | |
257 | + | let array3 = if (if ((maxPercentBound > p42)) | |
258 | + | then (p42 > minPercentBound) | |
259 | + | else false) | |
260 | + | then 2 :: array2 | |
261 | + | else array2 | |
262 | + | if (if ((maxPercentBound > p43)) | |
263 | + | then (p43 > minPercentBound) | |
264 | + | else false) | |
265 | + | then 3 :: array3 | |
266 | + | else array3 | |
267 | + | } | |
268 | + | } | |
269 | + | } | |
81 | 270 | ||
82 | 271 | ||
83 | - | func getOrderNextKey (orderId) = ("order_next_" + orderId) | |
84 | - | ||
85 | - | ||
86 | - | func getOrderTotalKey (orderId) = ("order_total_" + orderId) | |
87 | - | ||
88 | - | ||
89 | - | func getOrderOwnerKey (orderId) = ("order_owner_" + orderId) | |
90 | - | ||
91 | - | ||
92 | - | func getOrderHeightKey (orderId) = ("order_height_" + orderId) | |
93 | - | ||
94 | - | ||
95 | - | func getOrderStatusKey (orderId) = ("order_status_" + orderId) | |
96 | - | ||
97 | - | ||
98 | - | func getOrderFilledTotalKey (orderId) = ("order_filled_total_" + orderId) | |
99 | - | ||
100 | - | ||
101 | - | func getLastOrderOwnerKey (owner) = ("last_order_owner_" + owner) | |
102 | - | ||
103 | - | ||
104 | - | func convertNeutrinoToWaves (amount,price) = fraction(fraction(amount, 100, price), WAVELET, PAULI) | |
105 | - | ||
106 | - | ||
107 | - | func convertWavesToNeutrino (amount,price) = fraction(fraction(amount, price, 100), PAULI, WAVELET) | |
108 | - | ||
109 | - | ||
110 | - | func convertWavesToBond (amount,price) = convertWavesToNeutrino(amount, price) | |
111 | - | ||
112 | - | ||
113 | - | let neutrinoContract = addressFromStringValue(getStringByKey(NeutrinoContractKey)) | |
114 | - | ||
115 | - | let controlContract = addressFromStringValue(getStringByAddressAndKey(neutrinoContract, ControlContractKey)) | |
116 | - | ||
117 | - | let liquidationContract = this | |
118 | - | ||
119 | - | let neutrinoAssetId = fromBase58String(getStringByAddressAndKey(neutrinoContract, NeutrinoAssetIdKey)) | |
120 | - | ||
121 | - | let bondAssetId = fromBase58String("Qh28HvUAcFboD1GsAcyURQjNW6mdpuGvXVgFS9e3CzC") | |
122 | - | ||
123 | - | let firstOrder = getStringByKey(FirstOrderKey) | |
124 | - | ||
125 | - | let lastOrder = getStringByKey(LastOrderKey) | |
126 | - | ||
127 | - | let isBlocked = getBoolByAddressAndKey(controlContract, "is_blocked") | |
128 | - | ||
129 | - | let currentPrice = getNumberByAddressAndKey(controlContract, PriceKey) | |
130 | - | ||
131 | - | let neutrinoLockedBalance = getNumberByAddressAndKey(neutrinoContract, NeutrinoLockedBalanceKey) | |
132 | - | ||
133 | - | let wavesLockedBalance = getNumberByAddressAndKey(neutrinoContract, WavesLockedBalanceKey) | |
134 | - | ||
135 | - | let reserve = (wavesBalance(neutrinoContract) - wavesLockedBalance) | |
136 | - | ||
137 | - | let neutrinoSupply = (((neutrinoLockedBalance + extract(assetInfo(neutrinoAssetId)).quantity) - assetBalance(neutrinoContract, neutrinoAssetId)) - assetBalance(liquidationContract, neutrinoAssetId)) | |
138 | - | ||
139 | - | let surplus = (convertWavesToNeutrino(reserve, currentPrice) - neutrinoSupply) | |
140 | - | ||
141 | - | func getOrderTotal (id) = getNumberByKey(getOrderTotalKey(id)) | |
142 | - | ||
143 | - | ||
144 | - | func getOrderOwner (id) = getStringByKey(getOrderOwnerKey(id)) | |
145 | - | ||
146 | - | ||
147 | - | func getOrderStatus (id) = getStringByKey(getOrderStatusKey(id)) | |
148 | - | ||
149 | - | ||
150 | - | func getOrderFilledTotal (id) = getNumberByKey(getOrderFilledTotalKey(id)) | |
151 | - | ||
152 | - | ||
153 | - | func getOrderPrev (id) = getStringByKey(getOrderPrevKey(id)) | |
154 | - | ||
155 | - | ||
156 | - | func getOrderNext (id) = getStringByKey(getOrderNextKey(id)) | |
157 | - | ||
158 | - | ||
159 | - | func getOrderHeight (id) = getNumberByKey(getOrderHeightKey(id)) | |
160 | - | ||
161 | - | ||
162 | - | func getLastOrderOwner (owner) = getStringByKey(getLastOrderOwnerKey(owner)) | |
272 | + | func formattingPriceMsg (price,height) = toBytes((((("WAVESNEUTRINOPREFIX" + "_") + toString(height)) + "_") + toString(price))) | |
163 | 273 | ||
164 | 274 | ||
165 | 275 | @Callable(i) | |
166 | - | func addLiquidationOrder () = { | |
167 | - | let pmt = extract(i.payment) | |
168 | - | let newOrderId = toBase58String(keccak256((((toBytes(pmt.amount) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
169 | - | let nextOrder = getOrderNext(lastOrder) | |
170 | - | let orderStatus = getOrderStatus(lastOrder) | |
171 | - | let owner = toString(i.caller) | |
172 | - | if (isBlocked) | |
173 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
174 | - | else if ((pmt.assetId != bondAssetId)) | |
175 | - | then throw("can use appropriate neutrino bonds tokens only") | |
176 | - | else if ((getOrderOwner(newOrderId) != "")) | |
177 | - | then throw("an order is already exists") | |
178 | - | else if ((nextOrder != "")) | |
179 | - | then throw(("nextOrder is not last. Info:" + nextOrder)) | |
180 | - | else if (if ((firstOrder != "")) | |
181 | - | then (lastOrder == "") | |
182 | - | else false) | |
183 | - | then throw("invalid last order") | |
184 | - | else if (if ((firstOrder != "")) | |
185 | - | then (orderStatus != NEW) | |
186 | - | else false) | |
187 | - | then throw("last order status is not new") | |
188 | - | else if ((PAULI > pmt.amount)) | |
189 | - | then throw("order amount must be higher than 1 NSBT") | |
190 | - | else WriteSet([DataEntry(getLastOrderOwnerKey(owner), newOrderId), DataEntry(getOrderPrevKey(newOrderId), lastOrder), DataEntry(getOrderNextKey(lastOrder), if ((lastOrder == "")) | |
191 | - | then "" | |
192 | - | else newOrderId), DataEntry(FirstOrderKey, if ((firstOrder == "")) | |
193 | - | then newOrderId | |
194 | - | else firstOrder), DataEntry(LastOrderKey, newOrderId), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW)]) | |
276 | + | func callEmergencyShutdown (reason) = { | |
277 | + | let AutoEmergencyOracleAddress = "3Mwho43kPZa9w1y91NJsAoYxgQpsg3JjGby" | |
278 | + | let callerAddress = toString(i.caller) | |
279 | + | if ((AutoEmergencyOracleAddress != callerAddress)) | |
280 | + | then throw("caller must be one an emergency oracle") | |
281 | + | else WriteSet([DataEntry("is_blocked", true), DataEntry("is_blocked_caller", callerAddress), DataEntry("is_blocked_reason", reason)]) | |
195 | 282 | } | |
196 | 283 | ||
197 | 284 | ||
198 | 285 | ||
199 | 286 | @Callable(i) | |
200 | - | func addLiquidationOrderTest () = { | |
201 | - | let pmt = extract(i.payment) | |
202 | - | let newOrderId = toBase58String(keccak256((((toBytes(pmt.amount) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
203 | - | let owner = toString(i.caller) | |
204 | - | let nextOrder = getOrderNext(lastOrder) | |
205 | - | let orderStatus = getOrderStatus(lastOrder) | |
206 | - | if (isBlocked) | |
207 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
208 | - | else if (((1 + 1) > 1)) | |
209 | - | then throw("running here!") | |
210 | - | else WriteSet([DataEntry(getLastOrderOwnerKey(owner), newOrderId)]) | |
211 | - | } | |
212 | - | ||
213 | - | ||
214 | - | ||
215 | - | @Callable(i) | |
216 | - | func cancelOrder (orderId) = { | |
217 | - | let owner = getOrderOwner(orderId) | |
218 | - | let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId)) | |
219 | - | let nextOrder = getOrderNext(orderId) | |
220 | - | let prevOrder = getOrderPrev(orderId) | |
221 | - | if (isBlocked) | |
222 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
223 | - | else if ((owner != toString(i.caller))) | |
224 | - | then throw("permission denied") | |
225 | - | else if ((getOrderStatus(orderId) != NEW)) | |
226 | - | then throw("invalid order status") | |
227 | - | else ScriptResult(WriteSet([DataEntry(FirstOrderKey, if ((firstOrder == orderId)) | |
228 | - | then nextOrder | |
229 | - | else firstOrder), DataEntry(LastOrderKey, if ((lastOrder == orderId)) | |
230 | - | then prevOrder | |
231 | - | else lastOrder), DataEntry(getOrderNextKey(prevOrder), nextOrder), DataEntry(getOrderPrevKey(nextOrder), prevOrder), DataEntry(getOrderStatusKey(orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, bondAssetId)])) | |
232 | - | } | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func liquidateBond () = { | |
238 | - | let surplusPositive = if ((0 >= surplus)) | |
239 | - | then 0 | |
240 | - | else surplus | |
241 | - | let liquidationBalance = assetBalance(this, neutrinoAssetId) | |
242 | - | let returnAmount = if ((surplusPositive >= liquidationBalance)) | |
243 | - | then 0 | |
244 | - | else (liquidationBalance - surplusPositive) | |
245 | - | let surplusBond = surplusPositive | |
246 | - | if (isBlocked) | |
247 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
248 | - | else if (if ((returnAmount == 0)) | |
249 | - | then (liquidationBalance == 0) | |
250 | - | else false) | |
251 | - | then throw("cannot liquidate order without neutrino on the smart contract") | |
252 | - | else if ((returnAmount > 0)) | |
253 | - | then TransferSet([ScriptTransfer(neutrinoContract, returnAmount, neutrinoAssetId)]) | |
254 | - | else if ((0 >= surplusBond)) | |
255 | - | then throw("there is no proficit on the smart contract now") | |
256 | - | else if ((firstOrder == "")) | |
257 | - | then throw("empty orderbook") | |
258 | - | else { | |
259 | - | let nextOrder = getOrderNext(firstOrder) | |
260 | - | let orderTotal = getOrderTotal(firstOrder) | |
261 | - | let orderOwner = getOrderOwner(firstOrder) | |
262 | - | let filledTotal = getOrderFilledTotal(firstOrder) | |
263 | - | let amount = (orderTotal - filledTotal) | |
264 | - | let newStatus = if ((surplusBond >= amount)) | |
265 | - | then FILLED | |
266 | - | else NEW | |
267 | - | let fillableOrderAmount = if ((surplusBond >= amount)) | |
268 | - | then amount | |
269 | - | else surplusBond | |
270 | - | ScriptResult(WriteSet([DataEntry(getOrderPrevKey(nextOrder), if ((newStatus == FILLED)) | |
271 | - | then "" | |
272 | - | else firstOrder), DataEntry(FirstOrderKey, if ((newStatus == FILLED)) | |
273 | - | then nextOrder | |
274 | - | else firstOrder), DataEntry(LastOrderKey, if (if ((newStatus == FILLED)) | |
275 | - | then (firstOrder == lastOrder) | |
276 | - | else false) | |
277 | - | then "" | |
278 | - | else lastOrder), DataEntry(getOrderFilledTotalKey(firstOrder), (filledTotal + fillableOrderAmount)), DataEntry(getOrderStatusKey(firstOrder), newStatus)]), TransferSet([ScriptTransfer(addressFromStringValue(orderOwner), fillableOrderAmount, neutrinoAssetId)])) | |
279 | - | } | |
280 | - | } | |
287 | + | func finalizeCurrentPrice (price1,sign1,price2,sign2,price3,sign3,price4,sign4,price5,sign5) = if (isBlocked) | |
288 | + | then throw("contract is blocked by EMERGENCY SHUTDOWN actions untill reactivation by emergency oracles") | |
289 | + | else if (( match getInteger(this, ("price_" + toString(height))) { | |
290 | + | case a: Int => | |
291 | + | a | |
292 | + | case _ => | |
293 | + | 0 | |
294 | + | } != 0)) | |
295 | + | then throw("wait next block") | |
296 | + | else if ((pubKeyOraclesList[(height % 5)] != toBase58String(i.callerPublicKey))) | |
297 | + | then throw(((("Out of turn finalization: " + toString(height)) + " block should be finalize by ") + pubKeyOraclesList[(height % 5)])) | |
298 | + | else { | |
299 | + | let prices = [if ((price1 > 0)) | |
300 | + | then price1 | |
301 | + | else 0, if ((price2 > 0)) | |
302 | + | then price2 | |
303 | + | else 0, if ((price3 > 0)) | |
304 | + | then price3 | |
305 | + | else 0, if ((price4 > 0)) | |
306 | + | then price4 | |
307 | + | else 0, if ((price5 > 0)) | |
308 | + | then price5 | |
309 | + | else 0] | |
310 | + | let pricesInRange = findPricesInRange(prices) | |
311 | + | let priceProvidingCount = size(pricesInRange) | |
312 | + | if ((3 > priceProvidingCount)) | |
313 | + | then throw(((((((((((((((((((((("Could not finalize price because of big variation: height=" + toString(height)) + " | |
314 | + | ") + pubKeyOraclesList[0]) + "=") + toString(prices[0])) + " | |
315 | + | ") + pubKeyOraclesList[1]) + "=") + toString(prices[1])) + " | |
316 | + | ") + pubKeyOraclesList[2]) + "=") + toString(prices[2])) + " | |
317 | + | ") + pubKeyOraclesList[3]) + "=") + toString(prices[3])) + " | |
318 | + | ") + pubKeyOraclesList[4]) + "=") + toString(prices[4]))) | |
319 | + | else { | |
320 | + | let sum1 = ((prices[pricesInRange[0]] + prices[pricesInRange[1]]) + prices[pricesInRange[2]]) | |
321 | + | let sum2 = if ((priceProvidingCount >= 4)) | |
322 | + | then (sum1 + prices[pricesInRange[3]]) | |
323 | + | else sum1 | |
324 | + | let priceSum = if ((priceProvidingCount >= 5)) | |
325 | + | then (sum2 + prices[pricesInRange[4]]) | |
326 | + | else sum2 | |
327 | + | if ((priceProvidingCount >= 6)) | |
328 | + | then throw("Invalid pricesInRange creation") | |
329 | + | else { | |
330 | + | let newPrice = (priceSum / priceProvidingCount) | |
331 | + | if (if ((newPrice >= (price + ((price * percentPriceOffset) / 100)))) | |
332 | + | then true | |
333 | + | else ((price - ((price * percentPriceOffset) / 100)) >= newPrice)) | |
334 | + | then WriteSet([DataEntry("is_blocked", true), DataEntry((("black_swarm_price" + "_") + toString(height)), newPrice)]) | |
335 | + | else { | |
336 | + | let newPriceIndex = (priceIndex + 1) | |
337 | + | WriteSet([DataEntry("price", newPrice), DataEntry(("price_" + toString(height)), newPrice), DataEntry("price_index", newPriceIndex), DataEntry(("price_index_" + toString(newPriceIndex)), height), DataEntry(("deficit_" + toString(height)), deficit), DataEntry(("neutrinoSupply_" + toString(height)), neutrinoSupply), DataEntry(("deficit_percent_" + toString(height)), if ((neutrinoSupply != 0)) | |
338 | + | then ((deficit * 100) / neutrinoSupply) | |
339 | + | else 0)]) | |
340 | + | } | |
341 | + | } | |
342 | + | } | |
343 | + | } | |
281 | 344 | ||
282 | 345 |
github/deemru/w8io/169f3d6 53.29 ms ◑