tx · 3xvBfT2e68aAGGFdZFWpMKzVBbPW1Rm8rs8RkWjWMhTQ 3MxbR7b3gHF4XdQKNTT5aQMRiazHvrVWC8N: -0.02000000 Waves 2020.05.26 20:48 [1015625] smart account 3MxbR7b3gHF4XdQKNTT5aQMRiazHvrVWC8N > SELF 0.00000000 Waves
{ "type": 13, "id": "3xvBfT2e68aAGGFdZFWpMKzVBbPW1Rm8rs8RkWjWMhTQ", "fee": 2000000, "feeAssetId": null, "timestamp": 1590515382934, "version": 1, "sender": "3MxbR7b3gHF4XdQKNTT5aQMRiazHvrVWC8N", "senderPublicKey": "4bj7YXaphTC4Ldx7DqqMmrTjNshRtw1yNsej2XXZcAzS", "proofs": [ "59CmUzLpXDZvtY7Qnpb3ZWS8jFMyK1KLyDaX9iwE3aiik4pRHDMdBkYtyqMDn6DTo2o8TMTn8ZCkHu7SVWzpCGBY", "4PtPPYVADEiXSqJP2cAW7jtix8jc9RMFVwrbmgxTHhxzCmRf2uyE9Ki9soh2hJ5BCZpbkagupC5ieLhqBudz2ZQU", "4NgQ8n4E5hRZ6J9kna2NYJ4BPnbbe28MUaRbJLsokFucgDqCTbdmXoUFFAMWKNeGYNVMkjxFgc6a5NZFM1A2yc6J" ], "script": "base64:AAIDAAAAAAAAABcIARIECgIBCBIECgIBCBIDCgEIEgASAAAAADgBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAABAAAADmdldFN0cmluZ0J5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWECAAAAAAEAAAAWZ2V0Qm9vb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AAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAgkAAlkAAAABCQABkQAAAAIFAAAAEHB1YktleUFkbWluc0xpc3QAAAAAAAAAAAIAAAAAAAAAAAEAAAAAAAAAAAADCQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAwkAAlkAAAABCQABkQAAAAIFAAAAEHB1YktleUFkbWluc0xpc3QAAAAAAAAAAAMAAAAAAAAAAAIAAAAAAAAAAAAJAABnAAAAAgUAAAAFY291bnQAAAAAAAAAAAN5EW0y", "chainId": 84, "height": 1015625, "spentComplexity": 0 } View: original | compacted Prev: AWF637nDw3Dtjo4HLNw54mAm54WBSpwFo5inRsgfdr7m Next: GtW3gBibgPQcnsSgmknLb4U5k9D5tBemAfGF3V925YfL Diff:
Old | New | Differences | |
---|---|---|---|
114 | 114 | func convertBondToWaves (amount,price) = convertNeutrinoToWaves(amount, price) | |
115 | 115 | ||
116 | 116 | ||
117 | - | let neutrinoContract = | |
117 | + | let neutrinoContract = Address(base58'3Mzbx34Ex5rRbn39vUHx9kiwh3nneF8S5we') | |
118 | 118 | ||
119 | - | let controlContract = | |
119 | + | let controlContract = Address(base58'3N4NS7d4Jo9a6F14LiFUKKYVdUkkf2eP4Zx') | |
120 | 120 | ||
121 | - | let liquidationContract = | |
121 | + | let liquidationContract = Address(base58'3N5nmMvMH8o3RPEyCKCaoWahBTYTexnZy62') | |
122 | 122 | ||
123 | - | let neutrinoAssetId = | |
123 | + | let neutrinoAssetId = base58'25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT' | |
124 | 124 | ||
125 | - | let bondAssetId = | |
125 | + | let bondAssetId = base58'BGhPYquXSK6UYjnPLEn94gFhetp4Jvf7toekEY4x1VDH' | |
126 | 126 | ||
127 | 127 | let isBlocked = getBoolByAddressAndKey(controlContract, "is_blocked") | |
128 | 128 | ||
159 | 159 | func getNextOrder (id) = getStringByKey(getNextOrderKey(id)) | |
160 | 160 | ||
161 | 161 | ||
162 | - | @Callable(i) | |
163 | - | func addBuyBondOrder (price,prevOrder) = { | |
164 | - | let pmt = extract(i.payment) | |
165 | - | let newOrderId = toBase58String(keccak256(((((toBytes(price) + toBytes(pmt.amount)) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
166 | - | let priceWavesByBondCents = fraction(100, 100, price) | |
167 | - | let roi = fraction((priceWavesByBondCents - currentPrice), 100, currentPrice) | |
162 | + | func internalSellBond (pFirstOrder,pNextOrder,pFilledTotal,pRoi,pPaymentWavelets,orderOwnerAddress) = if ((pFirstOrder == "")) | |
163 | + | then throw("empty orderbook") | |
164 | + | else { | |
165 | + | let priceWavesByBondCents = fraction((100 + pRoi), currentPrice, 100) | |
166 | + | let remainedTotal = (pPaymentWavelets - pFilledTotal) | |
167 | + | let fillableOrderAmount = convertWavesToBond(remainedTotal, priceWavesByBondCents) | |
168 | + | let totalOrderWaveletesRequired = convertBondToWaves(fillableOrderAmount, priceWavesByBondCents) | |
169 | + | let nbTokensSellCondition = (fraction(deficit, 100, neutrinoSupply) >= pRoi) | |
170 | + | if (!(nbTokensSellCondition)) | |
171 | + | then throw(("innapropriate roi: " + toString(pRoi))) | |
172 | + | else if ((totalOrderWaveletesRequired == 0)) | |
173 | + | then throw("cannot fill order at the moment") | |
174 | + | else { | |
175 | + | let changeWavelets = (remainedTotal - totalOrderWaveletesRequired) | |
176 | + | let commonWriteSetData = [DataEntry(getOrderFilledTotalKey(firstOrder), (pFilledTotal + totalOrderWaveletesRequired)), DataEntry(getOrderStatusKey(firstOrder), FILLED)] | |
177 | + | let commonTransfers = [ScriptTransfer(orderOwnerAddress, fillableOrderAmount, bondAssetId), ScriptTransfer(neutrinoContract, totalOrderWaveletesRequired, unit), ScriptTransfer(orderOwnerAddress, changeWavelets, unit)] | |
178 | + | let writeSetData = if ((pFirstOrder == firstOrder)) | |
179 | + | then [DataEntry(getPrevOrderKey(pNextOrder), ""), DataEntry(FirstOrderKey, pNextOrder)] :: commonWriteSetData | |
180 | + | else commonWriteSetData | |
181 | + | ScriptResult(WriteSet(writeSetData), TransferSet(commonTransfers)) | |
182 | + | } | |
183 | + | } | |
184 | + | ||
185 | + | ||
186 | + | func internalAddBuyBondOrder (roi,prevOrder,inv,instant) = { | |
187 | + | let pmt = extract(inv.payment) | |
188 | + | let newOrderId = toBase58String(inv.transactionId) | |
168 | 189 | if (isBlocked) | |
169 | 190 | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
170 | 191 | else if ((MINORDERTOTAL > pmt.amount)) | |
181 | 202 | then throw("roi should not be equal to 0") | |
182 | 203 | else if (isDefined(pmt.assetId)) | |
183 | 204 | then throw("can use waves only") | |
184 | - | else if ((0 >= price)) | |
185 | - | then throw("price less zero") | |
186 | - | else if ((getOrderOwner(newOrderId) != "")) | |
187 | - | then throw("order exists") | |
188 | - | else if (if ((prevOrder != "")) | |
189 | - | then (getOrderStatus(prevOrder) != NEW) | |
190 | - | else false) | |
191 | - | then throw("prev order status is not new") | |
192 | - | else { | |
193 | - | let owner = toString(i.caller) | |
194 | - | let nextOrder = if ((prevOrder == "")) | |
195 | - | then firstOrder | |
196 | - | else getNextOrder(prevOrder) | |
197 | - | let nextOrderRoi = getNumberByKey(getRoiByOrderIdKey(nextOrder)) | |
198 | - | let isNextOrderError = if (if ((nextOrder != "")) | |
199 | - | then (roi >= nextOrderRoi) | |
205 | + | else if ((getOrderOwner(newOrderId) != "")) | |
206 | + | then throw("order exists") | |
207 | + | else if (if ((prevOrder != "")) | |
208 | + | then (getOrderStatus(prevOrder) != NEW) | |
209 | + | else false) | |
210 | + | then throw("prev order status is not new") | |
211 | + | else { | |
212 | + | let isNewOrderAtFirstPosition = (prevOrder == "") | |
213 | + | let owner = toString(inv.caller) | |
214 | + | let nextOrder = if (isNewOrderAtFirstPosition) | |
215 | + | then firstOrder | |
216 | + | else getNextOrder(prevOrder) | |
217 | + | let nextOrderRoi = getNumberByKey(getRoiByOrderIdKey(nextOrder)) | |
218 | + | let isNextOrderError = if (if ((nextOrder != "")) | |
219 | + | then (roi >= nextOrderRoi) | |
220 | + | else false) | |
221 | + | then true | |
222 | + | else false | |
223 | + | let prevOrderRoi = getNumberByKey(getRoiByOrderIdKey(prevOrder)) | |
224 | + | let isPrevOrderError = if (if ((prevOrder != "")) | |
225 | + | then (prevOrderRoi > roi) | |
226 | + | else false) | |
227 | + | then true | |
228 | + | else false | |
229 | + | if (if (isNextOrderError) | |
230 | + | then true | |
231 | + | else isPrevOrderError) | |
232 | + | then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError))) | |
233 | + | else if (if (isNewOrderAtFirstPosition) | |
234 | + | then instant | |
200 | 235 | else false) | |
201 | - | then true | |
202 | - | else false | |
203 | - | let prevOrderRoi = getNumberByKey(getRoiByOrderIdKey(prevOrder)) | |
204 | - | let isPrevOrderError = if (if ((prevOrder != "")) | |
205 | - | then (prevOrderRoi > roi) | |
206 | - | else false) | |
207 | - | then true | |
208 | - | else false | |
209 | - | if (if (isNextOrderError) | |
210 | - | then true | |
211 | - | else isPrevOrderError) | |
212 | - | then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError))) | |
213 | - | else WriteSet([DataEntry(getPrevOrderKey(newOrderId), prevOrder), DataEntry(getNextOrderKey(newOrderId), nextOrder), DataEntry(getNextOrderKey(prevOrder), if ((prevOrder == "")) | |
214 | - | then "" | |
215 | - | else newOrderId), DataEntry(getPrevOrderKey(nextOrder), if ((nextOrder == "")) | |
216 | - | then "" | |
217 | - | else newOrderId), DataEntry(FirstOrderKey, if (if ((firstOrder == "")) | |
218 | - | then true | |
219 | - | else (firstOrder == nextOrder)) | |
220 | - | then newOrderId | |
221 | - | else firstOrder), DataEntry(getOrderPriceKey(newOrderId), price), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW), DataEntry(("debug_order_currentPrice_" + newOrderId), currentPrice), DataEntry(getRoiByOrderIdKey(newOrderId), roi)]) | |
222 | - | } | |
236 | + | then internalSellBond(newOrderId, nextOrder, 0, roi, pmt.amount, inv.caller) | |
237 | + | else if (instant) | |
238 | + | then throw("Instant order couldn't be added into waiting queue") | |
239 | + | else WriteSet([DataEntry(getPrevOrderKey(newOrderId), prevOrder), DataEntry(getNextOrderKey(newOrderId), nextOrder), DataEntry(getNextOrderKey(prevOrder), if ((prevOrder == "")) | |
240 | + | then "" | |
241 | + | else newOrderId), DataEntry(getPrevOrderKey(nextOrder), if ((nextOrder == "")) | |
242 | + | then "" | |
243 | + | else newOrderId), DataEntry(FirstOrderKey, if (if ((firstOrder == "")) | |
244 | + | then true | |
245 | + | else (firstOrder == nextOrder)) | |
246 | + | then newOrderId | |
247 | + | else firstOrder), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW), DataEntry(("debug_order_currentPrice_" + newOrderId), currentPrice), DataEntry(getRoiByOrderIdKey(newOrderId), roi)]) | |
248 | + | } | |
249 | + | } | |
250 | + | ||
251 | + | ||
252 | + | @Callable(i) | |
253 | + | func instantBuyNsbtOrFail (roi,prevOrder) = { | |
254 | + | let pmt = extract(i.payment) | |
255 | + | internalAddBuyBondOrder(roi, prevOrder, i, true) | |
256 | + | } | |
257 | + | ||
258 | + | ||
259 | + | ||
260 | + | @Callable(i) | |
261 | + | func addBuyBondOrder (price,prevOrder) = { | |
262 | + | let pmt = extract(i.payment) | |
263 | + | let priceWavesByBondCents = fraction(100, 100, price) | |
264 | + | let roi = fraction((priceWavesByBondCents - currentPrice), 100, currentPrice) | |
265 | + | if ((0 >= price)) | |
266 | + | then throw("price less zero") | |
267 | + | else internalAddBuyBondOrder(roi, prevOrder, i, false) | |
223 | 268 | } | |
224 | 269 | ||
225 | 270 | ||
245 | 290 | ||
246 | 291 | ||
247 | 292 | @Callable(i) | |
248 | - | func sellBond () = { | |
249 | - | let bondBalance = assetBalance(this, bondAssetId) | |
250 | - | let returnAmount = (bondBalance - neutrinoSupply) | |
251 | - | if (isBlocked) | |
252 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
253 | - | else if ((bondBalance == 0)) | |
254 | - | then throw("without base tokens to sell") | |
255 | - | else if ((returnAmount > 0)) | |
256 | - | then TransferSet([ScriptTransfer(neutrinoContract, returnAmount, bondAssetId)]) | |
257 | - | else if ((firstOrder == "")) | |
258 | - | then throw("empty orderbook") | |
259 | - | else { | |
260 | - | let nextOrder = getNextOrder(firstOrder) | |
261 | - | let filledTotal = getOrderFilledTotal(firstOrder) | |
262 | - | let orderPrice = getOrderPrice(firstOrder) | |
263 | - | let roi = getNumberByKey(getRoiByOrderIdKey(firstOrder)) | |
264 | - | let priceWavesByBondCents = fraction((100 + roi), currentPrice, 100) | |
265 | - | let remainedTotal = (getOrderTotal(firstOrder) - filledTotal) | |
266 | - | let amountToExecuteOrder = convertWavesToBond(remainedTotal, priceWavesByBondCents) | |
267 | - | let fillOrderCondition = (bondBalance >= amountToExecuteOrder) | |
268 | - | let fillableOrderAmount = if (fillOrderCondition) | |
269 | - | then amountToExecuteOrder | |
270 | - | else bondBalance | |
271 | - | let totalOrderWaveletesRequired = convertBondToWaves(fillableOrderAmount, priceWavesByBondCents) | |
272 | - | let nbTokensSellCondition = (fraction(deficit, 100, neutrinoSupply) >= roi) | |
273 | - | if (!(nbTokensSellCondition)) | |
274 | - | then throw(("innapropriate roi: " + toString(roi))) | |
275 | - | else if ((amountToExecuteOrder == 0)) | |
276 | - | then ScriptResult(WriteSet([DataEntry(FirstOrderKey, nextOrder), DataEntry(getPrevOrderKey(nextOrder), ""), DataEntry(getOrderStatusKey(firstOrder), FILLED)]), TransferSet([ScriptTransfer(addressFromStringValue(getOrderOwner(firstOrder)), remainedTotal, unit)])) | |
277 | - | else if ((totalOrderWaveletesRequired == 0)) | |
278 | - | then throw("cannot fill order at the moment") | |
279 | - | else { | |
280 | - | let newStatus = if (if (fillOrderCondition) | |
281 | - | then if ((remainedTotal == 0)) | |
282 | - | then true | |
283 | - | else (remainedTotal == totalOrderWaveletesRequired) | |
284 | - | else false) | |
285 | - | then FILLED | |
286 | - | else NEW | |
287 | - | ScriptResult(WriteSet([DataEntry(getPrevOrderKey(nextOrder), if ((newStatus == FILLED)) | |
288 | - | then "" | |
289 | - | else firstOrder), DataEntry(FirstOrderKey, if ((newStatus == FILLED)) | |
290 | - | then nextOrder | |
291 | - | else firstOrder), DataEntry(getOrderFilledTotalKey(firstOrder), (filledTotal + totalOrderWaveletesRequired)), DataEntry(getOrderStatusKey(firstOrder), newStatus)]), TransferSet([ScriptTransfer(addressFromStringValue(getOrderOwner(firstOrder)), fillableOrderAmount, bondAssetId), ScriptTransfer(neutrinoContract, totalOrderWaveletesRequired, unit)])) | |
292 | - | } | |
293 | - | } | |
294 | - | } | |
293 | + | func sellBond () = if (isBlocked) | |
294 | + | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
295 | + | else if ((firstOrder == "")) | |
296 | + | then throw("empty orderbook") | |
297 | + | else { | |
298 | + | let nextOrder = getNextOrder(firstOrder) | |
299 | + | let filledTotal = getOrderFilledTotal(firstOrder) | |
300 | + | let orderPrice = getOrderPrice(firstOrder) | |
301 | + | let roi = getNumberByKey(getRoiByOrderIdKey(firstOrder)) | |
302 | + | let paymentWavelets = getOrderTotal(firstOrder) | |
303 | + | let orderOwnerAddress = Address(fromBase58String(getOrderOwner(firstOrder))) | |
304 | + | internalSellBond(firstOrder, nextOrder, filledTotal, roi, paymentWavelets, orderOwnerAddress) | |
305 | + | } | |
295 | 306 | ||
296 | 307 | ||
297 | 308 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | func getNumberByKey (key) = match getInteger(this, key) { | |
5 | 5 | case a: Int => | |
6 | 6 | a | |
7 | 7 | case _ => | |
8 | 8 | 0 | |
9 | 9 | } | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func getStringByKey (key) = match getString(this, key) { | |
13 | 13 | case a: String => | |
14 | 14 | a | |
15 | 15 | case _ => | |
16 | 16 | "" | |
17 | 17 | } | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func getBoolByAddressAndKey (address,key) = match getBoolean(address, key) { | |
21 | 21 | case a: Boolean => | |
22 | 22 | a | |
23 | 23 | case _ => | |
24 | 24 | false | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getStringByAddressAndKey (address,key) = match getString(address, key) { | |
29 | 29 | case a: String => | |
30 | 30 | a | |
31 | 31 | case _ => | |
32 | 32 | "" | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func getNumberByAddressAndKey (address,key) = match getInteger(address, key) { | |
37 | 37 | case a: Int => | |
38 | 38 | a | |
39 | 39 | case _ => | |
40 | 40 | 0 | |
41 | 41 | } | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | let WAVELET = 100000000 | |
45 | 45 | ||
46 | 46 | let PAULI = 1000000 | |
47 | 47 | ||
48 | 48 | let MINORDERTOTAL = (10 * WAVELET) | |
49 | 49 | ||
50 | 50 | let MAXROI = 95 | |
51 | 51 | ||
52 | 52 | let CANCELED = "canceled" | |
53 | 53 | ||
54 | 54 | let NEW = "new" | |
55 | 55 | ||
56 | 56 | let FILLED = "filled" | |
57 | 57 | ||
58 | 58 | let NeutrinoContractKey = "neutrino_contract" | |
59 | 59 | ||
60 | 60 | let PriceKey = "price" | |
61 | 61 | ||
62 | 62 | let BondAssetIdKey = "bond_asset_id" | |
63 | 63 | ||
64 | 64 | let NeutrinoAssetIdKey = "neutrino_asset_id" | |
65 | 65 | ||
66 | 66 | let ControlContractKey = "control_contract" | |
67 | 67 | ||
68 | 68 | let BalanceLockedkKey = "balance_lock_" | |
69 | 69 | ||
70 | 70 | let WavesLockedBalanceKey = (BalanceLockedkKey + "waves") | |
71 | 71 | ||
72 | 72 | let NeutrinoLockedBalanceKey = (BalanceLockedkKey + "neutrino") | |
73 | 73 | ||
74 | 74 | let LiquidationContractKey = "liquidation_contract" | |
75 | 75 | ||
76 | 76 | let FirstOrderKey = "order_first" | |
77 | 77 | ||
78 | 78 | func getRoiByOrderIdKey (orderId) = ("debug_order_roi_" + orderId) | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func getOrderPriceKey (orderId) = ("order_price_" + orderId) | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | func getOrderTotalKey (orderId) = ("order_total_" + orderId) | |
85 | 85 | ||
86 | 86 | ||
87 | 87 | func getOrderOwnerKey (orderId) = ("order_owner_" + orderId) | |
88 | 88 | ||
89 | 89 | ||
90 | 90 | func getOrderHeightKey (orderId) = ("order_height_" + orderId) | |
91 | 91 | ||
92 | 92 | ||
93 | 93 | func getOrderStatusKey (orderId) = ("order_status_" + orderId) | |
94 | 94 | ||
95 | 95 | ||
96 | 96 | func getOrderFilledTotalKey (orderId) = ("order_filled_total_" + orderId) | |
97 | 97 | ||
98 | 98 | ||
99 | 99 | func getPrevOrderKey (orderId) = ("order_prev_" + orderId) | |
100 | 100 | ||
101 | 101 | ||
102 | 102 | func getNextOrderKey (orderId) = ("order_next_" + orderId) | |
103 | 103 | ||
104 | 104 | ||
105 | 105 | func convertNeutrinoToWaves (amount,price) = fraction(fraction(amount, 100, price), WAVELET, PAULI) | |
106 | 106 | ||
107 | 107 | ||
108 | 108 | func convertWavesToNeutrino (amount,price) = fraction(fraction(amount, price, 100), PAULI, WAVELET) | |
109 | 109 | ||
110 | 110 | ||
111 | 111 | func convertWavesToBond (amount,price) = convertWavesToNeutrino(amount, price) | |
112 | 112 | ||
113 | 113 | ||
114 | 114 | func convertBondToWaves (amount,price) = convertNeutrinoToWaves(amount, price) | |
115 | 115 | ||
116 | 116 | ||
117 | - | let neutrinoContract = | |
117 | + | let neutrinoContract = Address(base58'3Mzbx34Ex5rRbn39vUHx9kiwh3nneF8S5we') | |
118 | 118 | ||
119 | - | let controlContract = | |
119 | + | let controlContract = Address(base58'3N4NS7d4Jo9a6F14LiFUKKYVdUkkf2eP4Zx') | |
120 | 120 | ||
121 | - | let liquidationContract = | |
121 | + | let liquidationContract = Address(base58'3N5nmMvMH8o3RPEyCKCaoWahBTYTexnZy62') | |
122 | 122 | ||
123 | - | let neutrinoAssetId = | |
123 | + | let neutrinoAssetId = base58'25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT' | |
124 | 124 | ||
125 | - | let bondAssetId = | |
125 | + | let bondAssetId = base58'BGhPYquXSK6UYjnPLEn94gFhetp4Jvf7toekEY4x1VDH' | |
126 | 126 | ||
127 | 127 | let isBlocked = getBoolByAddressAndKey(controlContract, "is_blocked") | |
128 | 128 | ||
129 | 129 | let currentPrice = getNumberByAddressAndKey(controlContract, PriceKey) | |
130 | 130 | ||
131 | 131 | let neutrinoLockedBalance = getNumberByAddressAndKey(neutrinoContract, NeutrinoLockedBalanceKey) | |
132 | 132 | ||
133 | 133 | let reserve = (wavesBalance(neutrinoContract) - getNumberByAddressAndKey(neutrinoContract, WavesLockedBalanceKey)) | |
134 | 134 | ||
135 | 135 | let neutrinoSupply = (((neutrinoLockedBalance + extract(assetInfo(neutrinoAssetId)).quantity) - assetBalance(neutrinoContract, neutrinoAssetId)) - assetBalance(liquidationContract, neutrinoAssetId)) | |
136 | 136 | ||
137 | 137 | let deficit = (neutrinoSupply - convertWavesToNeutrino(reserve, currentPrice)) | |
138 | 138 | ||
139 | 139 | let firstOrder = getStringByKey(FirstOrderKey) | |
140 | 140 | ||
141 | 141 | func getOrderPrice (id) = getNumberByKey(getOrderPriceKey(id)) | |
142 | 142 | ||
143 | 143 | ||
144 | 144 | func getOrderTotal (id) = getNumberByKey(getOrderTotalKey(id)) | |
145 | 145 | ||
146 | 146 | ||
147 | 147 | func getOrderOwner (id) = getStringByKey(getOrderOwnerKey(id)) | |
148 | 148 | ||
149 | 149 | ||
150 | 150 | func getOrderStatus (id) = getStringByKey(getOrderStatusKey(id)) | |
151 | 151 | ||
152 | 152 | ||
153 | 153 | func getOrderFilledTotal (id) = getNumberByKey(getOrderFilledTotalKey(id)) | |
154 | 154 | ||
155 | 155 | ||
156 | 156 | func getPrevOrder (id) = getStringByKey(getPrevOrderKey(id)) | |
157 | 157 | ||
158 | 158 | ||
159 | 159 | func getNextOrder (id) = getStringByKey(getNextOrderKey(id)) | |
160 | 160 | ||
161 | 161 | ||
162 | - | @Callable(i) | |
163 | - | func addBuyBondOrder (price,prevOrder) = { | |
164 | - | let pmt = extract(i.payment) | |
165 | - | let newOrderId = toBase58String(keccak256(((((toBytes(price) + toBytes(pmt.amount)) + i.caller.bytes) + toBytes(height)) + i.transactionId))) | |
166 | - | let priceWavesByBondCents = fraction(100, 100, price) | |
167 | - | let roi = fraction((priceWavesByBondCents - currentPrice), 100, currentPrice) | |
162 | + | func internalSellBond (pFirstOrder,pNextOrder,pFilledTotal,pRoi,pPaymentWavelets,orderOwnerAddress) = if ((pFirstOrder == "")) | |
163 | + | then throw("empty orderbook") | |
164 | + | else { | |
165 | + | let priceWavesByBondCents = fraction((100 + pRoi), currentPrice, 100) | |
166 | + | let remainedTotal = (pPaymentWavelets - pFilledTotal) | |
167 | + | let fillableOrderAmount = convertWavesToBond(remainedTotal, priceWavesByBondCents) | |
168 | + | let totalOrderWaveletesRequired = convertBondToWaves(fillableOrderAmount, priceWavesByBondCents) | |
169 | + | let nbTokensSellCondition = (fraction(deficit, 100, neutrinoSupply) >= pRoi) | |
170 | + | if (!(nbTokensSellCondition)) | |
171 | + | then throw(("innapropriate roi: " + toString(pRoi))) | |
172 | + | else if ((totalOrderWaveletesRequired == 0)) | |
173 | + | then throw("cannot fill order at the moment") | |
174 | + | else { | |
175 | + | let changeWavelets = (remainedTotal - totalOrderWaveletesRequired) | |
176 | + | let commonWriteSetData = [DataEntry(getOrderFilledTotalKey(firstOrder), (pFilledTotal + totalOrderWaveletesRequired)), DataEntry(getOrderStatusKey(firstOrder), FILLED)] | |
177 | + | let commonTransfers = [ScriptTransfer(orderOwnerAddress, fillableOrderAmount, bondAssetId), ScriptTransfer(neutrinoContract, totalOrderWaveletesRequired, unit), ScriptTransfer(orderOwnerAddress, changeWavelets, unit)] | |
178 | + | let writeSetData = if ((pFirstOrder == firstOrder)) | |
179 | + | then [DataEntry(getPrevOrderKey(pNextOrder), ""), DataEntry(FirstOrderKey, pNextOrder)] :: commonWriteSetData | |
180 | + | else commonWriteSetData | |
181 | + | ScriptResult(WriteSet(writeSetData), TransferSet(commonTransfers)) | |
182 | + | } | |
183 | + | } | |
184 | + | ||
185 | + | ||
186 | + | func internalAddBuyBondOrder (roi,prevOrder,inv,instant) = { | |
187 | + | let pmt = extract(inv.payment) | |
188 | + | let newOrderId = toBase58String(inv.transactionId) | |
168 | 189 | if (isBlocked) | |
169 | 190 | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
170 | 191 | else if ((MINORDERTOTAL > pmt.amount)) | |
171 | 192 | then throw(("min order total equals " + toString(MINORDERTOTAL))) | |
172 | 193 | else if ((roi > MAXROI)) | |
173 | 194 | then throw("max setOrder ROI is 95%") | |
174 | 195 | else if (if ((deficit > 0)) | |
175 | 196 | then (0 > roi) | |
176 | 197 | else false) | |
177 | 198 | then throw("can't place order with negative roi during deficit") | |
178 | 199 | else if ((-(MAXROI) > roi)) | |
179 | 200 | then throw("min setOrder ROI is -95%") | |
180 | 201 | else if ((roi == 0)) | |
181 | 202 | then throw("roi should not be equal to 0") | |
182 | 203 | else if (isDefined(pmt.assetId)) | |
183 | 204 | then throw("can use waves only") | |
184 | - | else if ((0 >= price)) | |
185 | - | then throw("price less zero") | |
186 | - | else if ((getOrderOwner(newOrderId) != "")) | |
187 | - | then throw("order exists") | |
188 | - | else if (if ((prevOrder != "")) | |
189 | - | then (getOrderStatus(prevOrder) != NEW) | |
190 | - | else false) | |
191 | - | then throw("prev order status is not new") | |
192 | - | else { | |
193 | - | let owner = toString(i.caller) | |
194 | - | let nextOrder = if ((prevOrder == "")) | |
195 | - | then firstOrder | |
196 | - | else getNextOrder(prevOrder) | |
197 | - | let nextOrderRoi = getNumberByKey(getRoiByOrderIdKey(nextOrder)) | |
198 | - | let isNextOrderError = if (if ((nextOrder != "")) | |
199 | - | then (roi >= nextOrderRoi) | |
205 | + | else if ((getOrderOwner(newOrderId) != "")) | |
206 | + | then throw("order exists") | |
207 | + | else if (if ((prevOrder != "")) | |
208 | + | then (getOrderStatus(prevOrder) != NEW) | |
209 | + | else false) | |
210 | + | then throw("prev order status is not new") | |
211 | + | else { | |
212 | + | let isNewOrderAtFirstPosition = (prevOrder == "") | |
213 | + | let owner = toString(inv.caller) | |
214 | + | let nextOrder = if (isNewOrderAtFirstPosition) | |
215 | + | then firstOrder | |
216 | + | else getNextOrder(prevOrder) | |
217 | + | let nextOrderRoi = getNumberByKey(getRoiByOrderIdKey(nextOrder)) | |
218 | + | let isNextOrderError = if (if ((nextOrder != "")) | |
219 | + | then (roi >= nextOrderRoi) | |
220 | + | else false) | |
221 | + | then true | |
222 | + | else false | |
223 | + | let prevOrderRoi = getNumberByKey(getRoiByOrderIdKey(prevOrder)) | |
224 | + | let isPrevOrderError = if (if ((prevOrder != "")) | |
225 | + | then (prevOrderRoi > roi) | |
226 | + | else false) | |
227 | + | then true | |
228 | + | else false | |
229 | + | if (if (isNextOrderError) | |
230 | + | then true | |
231 | + | else isPrevOrderError) | |
232 | + | then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError))) | |
233 | + | else if (if (isNewOrderAtFirstPosition) | |
234 | + | then instant | |
200 | 235 | else false) | |
201 | - | then true | |
202 | - | else false | |
203 | - | let prevOrderRoi = getNumberByKey(getRoiByOrderIdKey(prevOrder)) | |
204 | - | let isPrevOrderError = if (if ((prevOrder != "")) | |
205 | - | then (prevOrderRoi > roi) | |
206 | - | else false) | |
207 | - | then true | |
208 | - | else false | |
209 | - | if (if (isNextOrderError) | |
210 | - | then true | |
211 | - | else isPrevOrderError) | |
212 | - | then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError))) | |
213 | - | else WriteSet([DataEntry(getPrevOrderKey(newOrderId), prevOrder), DataEntry(getNextOrderKey(newOrderId), nextOrder), DataEntry(getNextOrderKey(prevOrder), if ((prevOrder == "")) | |
214 | - | then "" | |
215 | - | else newOrderId), DataEntry(getPrevOrderKey(nextOrder), if ((nextOrder == "")) | |
216 | - | then "" | |
217 | - | else newOrderId), DataEntry(FirstOrderKey, if (if ((firstOrder == "")) | |
218 | - | then true | |
219 | - | else (firstOrder == nextOrder)) | |
220 | - | then newOrderId | |
221 | - | else firstOrder), DataEntry(getOrderPriceKey(newOrderId), price), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW), DataEntry(("debug_order_currentPrice_" + newOrderId), currentPrice), DataEntry(getRoiByOrderIdKey(newOrderId), roi)]) | |
222 | - | } | |
236 | + | then internalSellBond(newOrderId, nextOrder, 0, roi, pmt.amount, inv.caller) | |
237 | + | else if (instant) | |
238 | + | then throw("Instant order couldn't be added into waiting queue") | |
239 | + | else WriteSet([DataEntry(getPrevOrderKey(newOrderId), prevOrder), DataEntry(getNextOrderKey(newOrderId), nextOrder), DataEntry(getNextOrderKey(prevOrder), if ((prevOrder == "")) | |
240 | + | then "" | |
241 | + | else newOrderId), DataEntry(getPrevOrderKey(nextOrder), if ((nextOrder == "")) | |
242 | + | then "" | |
243 | + | else newOrderId), DataEntry(FirstOrderKey, if (if ((firstOrder == "")) | |
244 | + | then true | |
245 | + | else (firstOrder == nextOrder)) | |
246 | + | then newOrderId | |
247 | + | else firstOrder), DataEntry(getOrderTotalKey(newOrderId), pmt.amount), DataEntry(getOrderOwnerKey(newOrderId), owner), DataEntry(getOrderHeightKey(newOrderId), height), DataEntry(getOrderStatusKey(newOrderId), NEW), DataEntry(("debug_order_currentPrice_" + newOrderId), currentPrice), DataEntry(getRoiByOrderIdKey(newOrderId), roi)]) | |
248 | + | } | |
249 | + | } | |
250 | + | ||
251 | + | ||
252 | + | @Callable(i) | |
253 | + | func instantBuyNsbtOrFail (roi,prevOrder) = { | |
254 | + | let pmt = extract(i.payment) | |
255 | + | internalAddBuyBondOrder(roi, prevOrder, i, true) | |
256 | + | } | |
257 | + | ||
258 | + | ||
259 | + | ||
260 | + | @Callable(i) | |
261 | + | func addBuyBondOrder (price,prevOrder) = { | |
262 | + | let pmt = extract(i.payment) | |
263 | + | let priceWavesByBondCents = fraction(100, 100, price) | |
264 | + | let roi = fraction((priceWavesByBondCents - currentPrice), 100, currentPrice) | |
265 | + | if ((0 >= price)) | |
266 | + | then throw("price less zero") | |
267 | + | else internalAddBuyBondOrder(roi, prevOrder, i, false) | |
223 | 268 | } | |
224 | 269 | ||
225 | 270 | ||
226 | 271 | ||
227 | 272 | @Callable(i) | |
228 | 273 | func cancelOrder (orderId) = { | |
229 | 274 | let owner = getOrderOwner(orderId) | |
230 | 275 | let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId)) | |
231 | 276 | let caller = toString(i.caller) | |
232 | 277 | let nextOrder = getNextOrder(orderId) | |
233 | 278 | let prevOrder = getPrevOrder(orderId) | |
234 | 279 | if (isBlocked) | |
235 | 280 | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
236 | 281 | else if ((owner != caller)) | |
237 | 282 | then throw("permission denied") | |
238 | 283 | else if ((getOrderStatus(orderId) != NEW)) | |
239 | 284 | then throw("invalid order status") | |
240 | 285 | else ScriptResult(WriteSet([DataEntry(FirstOrderKey, if ((firstOrder == orderId)) | |
241 | 286 | then nextOrder | |
242 | 287 | else firstOrder), DataEntry(getNextOrderKey(prevOrder), nextOrder), DataEntry(getPrevOrderKey(nextOrder), prevOrder), DataEntry(getOrderStatusKey(orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) | |
243 | 288 | } | |
244 | 289 | ||
245 | 290 | ||
246 | 291 | ||
247 | 292 | @Callable(i) | |
248 | - | func sellBond () = { | |
249 | - | let bondBalance = assetBalance(this, bondAssetId) | |
250 | - | let returnAmount = (bondBalance - neutrinoSupply) | |
251 | - | if (isBlocked) | |
252 | - | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
253 | - | else if ((bondBalance == 0)) | |
254 | - | then throw("without base tokens to sell") | |
255 | - | else if ((returnAmount > 0)) | |
256 | - | then TransferSet([ScriptTransfer(neutrinoContract, returnAmount, bondAssetId)]) | |
257 | - | else if ((firstOrder == "")) | |
258 | - | then throw("empty orderbook") | |
259 | - | else { | |
260 | - | let nextOrder = getNextOrder(firstOrder) | |
261 | - | let filledTotal = getOrderFilledTotal(firstOrder) | |
262 | - | let orderPrice = getOrderPrice(firstOrder) | |
263 | - | let roi = getNumberByKey(getRoiByOrderIdKey(firstOrder)) | |
264 | - | let priceWavesByBondCents = fraction((100 + roi), currentPrice, 100) | |
265 | - | let remainedTotal = (getOrderTotal(firstOrder) - filledTotal) | |
266 | - | let amountToExecuteOrder = convertWavesToBond(remainedTotal, priceWavesByBondCents) | |
267 | - | let fillOrderCondition = (bondBalance >= amountToExecuteOrder) | |
268 | - | let fillableOrderAmount = if (fillOrderCondition) | |
269 | - | then amountToExecuteOrder | |
270 | - | else bondBalance | |
271 | - | let totalOrderWaveletesRequired = convertBondToWaves(fillableOrderAmount, priceWavesByBondCents) | |
272 | - | let nbTokensSellCondition = (fraction(deficit, 100, neutrinoSupply) >= roi) | |
273 | - | if (!(nbTokensSellCondition)) | |
274 | - | then throw(("innapropriate roi: " + toString(roi))) | |
275 | - | else if ((amountToExecuteOrder == 0)) | |
276 | - | then ScriptResult(WriteSet([DataEntry(FirstOrderKey, nextOrder), DataEntry(getPrevOrderKey(nextOrder), ""), DataEntry(getOrderStatusKey(firstOrder), FILLED)]), TransferSet([ScriptTransfer(addressFromStringValue(getOrderOwner(firstOrder)), remainedTotal, unit)])) | |
277 | - | else if ((totalOrderWaveletesRequired == 0)) | |
278 | - | then throw("cannot fill order at the moment") | |
279 | - | else { | |
280 | - | let newStatus = if (if (fillOrderCondition) | |
281 | - | then if ((remainedTotal == 0)) | |
282 | - | then true | |
283 | - | else (remainedTotal == totalOrderWaveletesRequired) | |
284 | - | else false) | |
285 | - | then FILLED | |
286 | - | else NEW | |
287 | - | ScriptResult(WriteSet([DataEntry(getPrevOrderKey(nextOrder), if ((newStatus == FILLED)) | |
288 | - | then "" | |
289 | - | else firstOrder), DataEntry(FirstOrderKey, if ((newStatus == FILLED)) | |
290 | - | then nextOrder | |
291 | - | else firstOrder), DataEntry(getOrderFilledTotalKey(firstOrder), (filledTotal + totalOrderWaveletesRequired)), DataEntry(getOrderStatusKey(firstOrder), newStatus)]), TransferSet([ScriptTransfer(addressFromStringValue(getOrderOwner(firstOrder)), fillableOrderAmount, bondAssetId), ScriptTransfer(neutrinoContract, totalOrderWaveletesRequired, unit)])) | |
292 | - | } | |
293 | - | } | |
294 | - | } | |
293 | + | func sellBond () = if (isBlocked) | |
294 | + | then throw("contract is blocked by EMERGENCY SHUTDOWN actions until reactivation by emergency oracles") | |
295 | + | else if ((firstOrder == "")) | |
296 | + | then throw("empty orderbook") | |
297 | + | else { | |
298 | + | let nextOrder = getNextOrder(firstOrder) | |
299 | + | let filledTotal = getOrderFilledTotal(firstOrder) | |
300 | + | let orderPrice = getOrderPrice(firstOrder) | |
301 | + | let roi = getNumberByKey(getRoiByOrderIdKey(firstOrder)) | |
302 | + | let paymentWavelets = getOrderTotal(firstOrder) | |
303 | + | let orderOwnerAddress = Address(fromBase58String(getOrderOwner(firstOrder))) | |
304 | + | internalSellBond(firstOrder, nextOrder, filledTotal, roi, paymentWavelets, orderOwnerAddress) | |
305 | + | } | |
295 | 306 | ||
296 | 307 | ||
297 | 308 | ||
298 | 309 | @Callable(i) | |
299 | 310 | func updateReservesAndNeutrinoSupply () = { | |
300 | 311 | func getNumberByKeyInternal (key) = match getInteger(this, key) { | |
301 | 312 | case a: Int => | |
302 | 313 | a | |
303 | 314 | case _ => | |
304 | 315 | 0 | |
305 | 316 | } | |
306 | 317 | ||
307 | 318 | let idx = getNumberByKeyInternal("updateReservesAndNeutrinoSupplyIdx") | |
308 | 319 | let newIdx = (idx + 1) | |
309 | 320 | WriteSet([DataEntry("updateReservesAndNeutrinoSupplyIdx", newIdx), DataEntry("reserve", reserve), DataEntry("neutrinoSupply", neutrinoSupply), DataEntry("deficit", deficit)]) | |
310 | 321 | } | |
311 | 322 | ||
312 | 323 | ||
313 | 324 | @Verifier(tx) | |
314 | 325 | func verify () = { | |
315 | 326 | let pubKeyAdminsList = ["GXxmZaCigPgJsT6d1cLr8nUXA65nGX8V7FuAzzrY8wQE", "3xumx4hrPpeeoo79HLGbZCgfz95L39ZFdxxwWeSUC2Pu", "D4CqtK5fBsnzRo33ZMhrM7niLseDH2uRoK6weBq2JQ3A", "5WRXFSjwcTbNfKcJs8ZqXmSSWYsSVJUtMvMqZj5hH4Nc"] | |
316 | 327 | let count = ((((if (sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(pubKeyAdminsList[0]))) | |
317 | 328 | then 1 | |
318 | 329 | else 0) + (if (sigVerify(tx.bodyBytes, tx.proofs[1], fromBase58String(pubKeyAdminsList[1]))) | |
319 | 330 | then 1 | |
320 | 331 | else 0)) + (if (sigVerify(tx.bodyBytes, tx.proofs[2], fromBase58String(pubKeyAdminsList[2]))) | |
321 | 332 | then 1 | |
322 | 333 | else 0)) + (if (sigVerify(tx.bodyBytes, tx.proofs[3], fromBase58String(pubKeyAdminsList[3]))) | |
323 | 334 | then 2 | |
324 | 335 | else 0)) | |
325 | 336 | (count >= 3) | |
326 | 337 | } | |
327 | 338 |
github/deemru/w8io/169f3d6 72.01 ms ◑