tx · 6DkZf9aPnSu1y1Gx6TnUuW6PavzdRJQX3Hw3ohR3ESmE

3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb:  -0.01400000 Waves

2019.09.17 19:30 [680487] smart account 3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb > SELF 0.00000000 Waves

{ "type": 13, "id": "6DkZf9aPnSu1y1Gx6TnUuW6PavzdRJQX3Hw3ohR3ESmE", "fee": 1400000, "feeAssetId": null, "timestamp": 1568737826231, "version": 1, "sender": "3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb", "senderPublicKey": "5vyi92HdgdTabKCQzDHGrgQ4ASjtoT3XrCUXr459sWuc", "proofs": [ "2Li4DVC7MTWsh2E5viDD6e5tRnYSQLqVZDGnrfdu33C4Pn7JNPSPdPM9HDXZ6smt6XzRPdk7cJsjsVetSbAYsM6w" ], "script": "base64:AAIDAAAAAAAAAAAAAAAhAAAAAAROT05FAgAAAAABAAAAGGdldE51bWJlckJ5QWRkcmVzc0FuZEtleQAAAAIAAAAHYWRkcmVzcwAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAAdhZGRyZXNzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0U3RyaW5nQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAAB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ZEFzc2V0SWQFAAAAA25pbAAAAACvYU5P", "chainId": 84, "height": 680487, "spentComplexity": 0 } View: original | compacted Prev: BR6hHnQ4Wkd98ok6a5R2hW83z1J2paziSNBVHKw2dMtr Next: 2LNhkqHdu8dDu6fokVp2yCKKi93TG6oBpNp2GY2EEFNh Diff:
OldNewDifferences
170170 else (bondBalance - deficitPositive)
171171 if ((bondAmount == 0))
172172 then TransferSet([ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)])
173- else throw(((("errror:" + toString(bondAmount)) + " -> ") + toString(returnAmount)))
173+ else {
174+ let orderId = split(orderbook, OrderSplitSymbol)[0]
175+ let filledTotal = getOrderFilledTotal(orderId)
176+ let orderTotal = getOrderTotal(orderId)
177+ let orderPrice = getOrderPrice(orderId)
178+ let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
179+ let newOrderbook = if ((bondAmount >= amount))
180+ then split(orderbook, (orderId + OrderSplitSymbol))[1]
181+ else orderbook
182+ let filledAmount = if ((bondAmount >= amount))
183+ then amount
184+ else bondAmount
185+ let total = (((filledAmount * orderPrice) / 100) * Wavelet)
186+ let status = if ((bondAmount >= amount))
187+ then FILLED
188+ else NEW
189+ ScriptResult(WriteSet([DataEntry(OrderBookKey, newOrderbook), DataEntry((OrderFilledTotalKey + orderId), (filledTotal + total)), DataEntry((OrderStatusKey + orderId), status)]), TransferSet([ScriptTransfer(i.caller, filledAmount, BondAssetId), ScriptTransfer(addressFromStringValue(NeutrinoContract), total, NeutrinoAssetId), ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)]))
190+ }
174191 }
175192
176193
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = ""
55
66 func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) {
77 case a: Int =>
88 a
99 case _ =>
1010 0
1111 }
1212
1313
1414 func getNumberByKey (key) = match getInteger(this, key) {
1515 case a: Int =>
1616 a
1717 case _ =>
1818 0
1919 }
2020
2121
2222 func getStringByKey (key) = match getString(this, key) {
2323 case a: String =>
2424 a
2525 case _ =>
2626 NONE
2727 }
2828
2929
3030 let OrderBookKey = "orderbook"
3131
3232 let OrderPriceKey = "order_price_"
3333
3434 let OrderTotalKey = "order_total_"
3535
3636 let OrderFilledTotalKey = "order_filled_total_"
3737
3838 let OrderOwnerKey = "order_owner_"
3939
4040 let OrderHeightKey = "order_height_"
4141
4242 let OrderStatusKey = "order_status_"
4343
4444 let PriceKey = "price"
4545
4646 let BondAssetIdKey = "bond_asset_id"
4747
4848 let NeutrinoAssetIdKey = "neutrino_asset_id"
4949
5050 let NeutrinoContractKey = "neutrino_contract"
5151
5252 let orderbook = getStringByKey(OrderBookKey)
5353
5454 func getOrderPrice (id) = getNumberByKey((OrderPriceKey + id))
5555
5656
5757 func getOrderTotal (id) = getNumberByKey((OrderTotalKey + id))
5858
5959
6060 func getOrderOwner (id) = getStringByKey((OrderOwnerKey + id))
6161
6262
6363 func getOrderStatus (id) = getStringByKey((OrderStatusKey + id))
6464
6565
6666 func getOrderFilledTotal (id) = getNumberByKey((OrderFilledTotalKey + id))
6767
6868
6969 let NeutrinoAssetId = fromBase58String(getStringByKey(NeutrinoAssetIdKey))
7070
7171 let NeutrinoContract = getStringByKey(NeutrinoContractKey)
7272
7373 let reserve = wavesBalance(addressFromStringValue(NeutrinoContract))
7474
7575 let neutrinoSupply = {
7676 let info = extract(assetInfo(NeutrinoAssetId))
7777 (info.quantity - assetBalance(addressFromStringValue(NeutrinoContract), NeutrinoAssetId))
7878 }
7979
8080 let price = getNumberByAddressAndKey(NeutrinoContract, PriceKey)
8181
8282 let OrderSplitSymbol = "_"
8383
8484 let BondAssetId = fromBase58String(getStringByKey(BondAssetIdKey))
8585
8686 let Wavelet = 100000000
8787
8888 let CANCELED = "canceled"
8989
9090 let NEW = "new"
9191
9292 let FILLED = "filled"
9393
9494 func calculateOrderbook (orderId,position) = {
9595 let orders = split(orderbook, OrderSplitSymbol)
9696 let newOrder = (orderId + OrderSplitSymbol)
9797 if ((position == 0))
9898 then (newOrder + orderbook)
9999 else if ((position >= (size(orders) - 1)))
100100 then (orderbook + newOrder)
101101 else {
102102 let parts = split(orderbook, (orders[position] + OrderSplitSymbol))
103103 (((parts[0] + newOrder) + (orders[position] + OrderSplitSymbol)) + parts[1])
104104 }
105105 }
106106
107107
108108 @Callable(i)
109109 func setOrder (price,position) = {
110110 let pmt = extract(i.payment)
111111 let newOrderId = toBase58String(keccak256((((toBytes(price) + toBytes(pmt.amount)) + i.caller.bytes) + toBytes(height))))
112112 if ((pmt.assetId != NeutrinoAssetId))
113113 then throw("can use neutrino only")
114114 else if ((0 >= price))
115115 then throw("price less zero")
116116 else if ((getOrderOwner(newOrderId) != NONE))
117117 then throw("order exists")
118118 else {
119119 let orders = split(orderbook, OrderSplitSymbol)
120120 let nextOrderId = if ((position == 0))
121121 then ""
122122 else orders[(position - 1)]
123123 let nextOrderPrice = getOrderPrice(nextOrderId)
124124 let isNextOrderError = if (if ((nextOrderId != ""))
125125 then (price > nextOrderPrice)
126126 else false)
127127 then true
128128 else false
129129 let prevOrderId = orders[position]
130130 let prevOrderPrice = getOrderPrice(prevOrderId)
131131 let isPrevOrderError = if ((prevOrderPrice >= price))
132132 then true
133133 else false
134134 if (if (isNextOrderError)
135135 then true
136136 else isPrevOrderError)
137137 then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError)))
138138 else WriteSet([DataEntry(OrderBookKey, calculateOrderbook(newOrderId, position)), DataEntry((OrderPriceKey + newOrderId), price), DataEntry((OrderTotalKey + newOrderId), pmt.amount), DataEntry((OrderOwnerKey + newOrderId), toString(i.caller)), DataEntry((OrderHeightKey + newOrderId), height), DataEntry((OrderStatusKey + newOrderId), NEW)])
139139 }
140140 }
141141
142142
143143
144144 @Callable(i)
145145 func cancelOrder (orderId) = {
146146 let owner = getOrderOwner(orderId)
147147 let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId))
148148 if ((owner != toString(i.caller)))
149149 then throw("permission denied")
150150 else {
151151 let parts = split(orderbook, (orderId + OrderSplitSymbol))
152152 ScriptResult(WriteSet([DataEntry(OrderBookKey, (parts[0] + parts[1])), DataEntry((OrderStatusKey + orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, NeutrinoAssetId)]))
153153 }
154154 }
155155
156156
157157
158158 @Callable(i)
159159 func executeOrder () = {
160160 let bondBalance = assetBalance(this, BondAssetId)
161161 let deficit = ((neutrinoSupply - ((reserve * price) / 100)) / Wavelet)
162162 let deficitPositive = if ((0 >= deficit))
163163 then 0
164164 else deficit
165165 let bondAmount = if ((deficitPositive >= bondBalance))
166166 then bondBalance
167167 else deficitPositive
168168 let returnAmount = if ((deficitPositive >= bondBalance))
169169 then 0
170170 else (bondBalance - deficitPositive)
171171 if ((bondAmount == 0))
172172 then TransferSet([ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)])
173- else throw(((("errror:" + toString(bondAmount)) + " -> ") + toString(returnAmount)))
173+ else {
174+ let orderId = split(orderbook, OrderSplitSymbol)[0]
175+ let filledTotal = getOrderFilledTotal(orderId)
176+ let orderTotal = getOrderTotal(orderId)
177+ let orderPrice = getOrderPrice(orderId)
178+ let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
179+ let newOrderbook = if ((bondAmount >= amount))
180+ then split(orderbook, (orderId + OrderSplitSymbol))[1]
181+ else orderbook
182+ let filledAmount = if ((bondAmount >= amount))
183+ then amount
184+ else bondAmount
185+ let total = (((filledAmount * orderPrice) / 100) * Wavelet)
186+ let status = if ((bondAmount >= amount))
187+ then FILLED
188+ else NEW
189+ ScriptResult(WriteSet([DataEntry(OrderBookKey, newOrderbook), DataEntry((OrderFilledTotalKey + orderId), (filledTotal + total)), DataEntry((OrderStatusKey + orderId), status)]), TransferSet([ScriptTransfer(i.caller, filledAmount, BondAssetId), ScriptTransfer(addressFromStringValue(NeutrinoContract), total, NeutrinoAssetId), ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)]))
190+ }
174191 }
175192
176193

github/deemru/w8io/026f985 
42.07 ms