tx · 2xvABcx3A9ckkWt3o1qnJ3C6iTMQD1yqucS1UE2LDHWH

3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb:  -0.01400000 Waves

2019.09.17 17:38 [680375] smart account 3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb > SELF 0.00000000 Waves

{ "type": 13, "id": "2xvABcx3A9ckkWt3o1qnJ3C6iTMQD1yqucS1UE2LDHWH", "fee": 1400000, "feeAssetId": null, "timestamp": 1568731118218, "version": 1, "sender": "3NC8pQxcnDTtDkhzv5Eje8qqW4qoFawLnAb", "senderPublicKey": "5vyi92HdgdTabKCQzDHGrgQ4ASjtoT3XrCUXr459sWuc", "proofs": [ "5fCSxsLrXic3N2woj1YLrjAuN86v2hapJzQUXjDm61UgGjNy5CxjQjzTBvnkzsWKhwTgfLe8GYJpf58aQ3qjwg6" ], "script": "base64:AAIDAAAAAAAAAAAAAAAjAAAAAAROT05FAgAAAAABAAAAGGdldE51bWJlckJ5QWRkcmVzc0FuZEtleQAAAAIAAAAHYWRkcmVzcwAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAAdhZGRyZXNzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0U3RyaW5nQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAH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Apib25kQW1vdW50BQAAAAZhbW91bnQFAAAABkZJTExFRAUAAAADTkVXCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAMT3JkZXJCb29rS2V5BQAAAAxuZXdPcmRlcmJvb2sJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAATT3JkZXJGaWxsZWRUb3RhbEtleQUAAAAHb3JkZXJJZAkAAGQAAAACBQAAAAtmaWxsZWRUb3RhbAUAAAAFdG90YWwJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAAOT3JkZXJTdGF0dXNLZXkFAAAAB29yZGVySWQFAAAABnN0YXR1cwUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAMZmlsbGVkQW1vdW50BQAAAAtCb25kQXNzZXRJZAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCQEAAAAcQGV4dHJVc2VyKGFkZHJlc3NGcm9tU3RyaW5nKQAAAAEFAAAAEE5ldXRyaW5vQ29udHJhY3QFAAAABXRvdGFsBQAAAA9OZXV0cmlub0Fzc2V0SWQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAABBOZXV0cmlub0NvbnRyYWN0BQAAAAxyZXR1cm5BbW91bnQFAAAAC0JvbmRBc3NldElkBQAAAANuaWwAAAAAPE5WDA==", "chainId": 84, "height": 680375, "spentComplexity": 0 } View: original | compacted Prev: DvYcALBngra21P8isXrBZPbwuiZzU9PYFLuRHcUBcGwR Next: 6yq7WjkaBofqxGSfg3SF6Eetjb3gdHJ4tYRWYRdpmDDR Diff:
OldNewDifferences
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = ""
5+
6+func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) {
7+ case a: Int =>
8+ a
9+ case _ =>
10+ 0
11+}
12+
513
614 func getNumberByKey (key) = match getInteger(this, key) {
715 case a: Int =>
3341
3442 let OrderStatusKey = "order_status_"
3543
44+let PriceKey = "price"
45+
3646 let BondAssetIdKey = "bond_asset_id"
3747
3848 let NeutrinoAssetIdKey = "neutrino_asset_id"
3949
4050 let NeutrinoContractKey = "neutrino_contract"
51+
52+let NeutrinoSupplyKey = "neutrino_supply"
53+
54+let WavesReserveKey = "waves_reserve"
4155
4256 let orderbook = getStringByKey(OrderBookKey)
4357
5670 func getOrderFilledTotal (id) = getNumberByKey((OrderFilledTotalKey + id))
5771
5872
73+let NeutrinoContract = getStringByKey(NeutrinoContractKey)
74+
75+let reserve = getNumberByAddressAndKey(NeutrinoContract, WavesReserveKey)
76+
77+let neutrinoSupply = getNumberByAddressAndKey(NeutrinoContract, NeutrinoSupplyKey)
78+
79+let price = getNumberByAddressAndKey(NeutrinoContract, PriceKey)
80+
5981 let OrderSplitSymbol = "_"
6082
6183 let BondAssetId = fromBase58String(getStringByKey(BondAssetIdKey))
6284
6385 let NeutrinoAssetId = fromBase58String(getStringByKey(NeutrinoAssetIdKey))
64-
65-let NeutrinoContract = getStringByKey(NeutrinoContractKey)
6686
6787 let Wavelet = 100000000
6888
139159 @Callable(i)
140160 func executeOrder () = {
141161 let orderId = split(orderbook, OrderSplitSymbol)[0]
142- let bondAmount = assetBalance(this, BondAssetId)
143- let filledTotal = getOrderFilledTotal(orderId)
144- let orderTotal = getOrderTotal(orderId)
145- let orderPrice = getOrderPrice(orderId)
146- let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
147- let newOrderbook = if ((bondAmount >= amount))
148- then split(orderbook, (orderId + OrderSplitSymbol))[1]
149- else orderbook
150- let filledAmount = if ((bondAmount >= amount))
151- then amount
152- else bondAmount
153- let total = (((filledAmount * orderPrice) / 100) * Wavelet)
154- let status = if ((bondAmount >= amount))
155- then FILLED
156- else NEW
157- 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)]))
162+ let bondBalance = assetBalance(this, BondAssetId)
163+ let deficit = (neutrinoSupply - ((reserve * price) / 100))
164+ let bondAmount = if ((deficit >= bondBalance))
165+ then bondBalance
166+ else deficit
167+ let returnAmount = if ((deficit >= bondBalance))
168+ then 0
169+ else (bondBalance - deficit)
170+ if ((bondAmount == 0))
171+ then TransferSet([ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)])
172+ else {
173+ let filledTotal = getOrderFilledTotal(orderId)
174+ let orderTotal = getOrderTotal(orderId)
175+ let orderPrice = getOrderPrice(orderId)
176+ let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
177+ let newOrderbook = if ((bondAmount >= amount))
178+ then split(orderbook, (orderId + OrderSplitSymbol))[1]
179+ else orderbook
180+ let filledAmount = if ((bondAmount >= amount))
181+ then amount
182+ else bondAmount
183+ let total = (((filledAmount * orderPrice) / 100) * Wavelet)
184+ let status = if ((bondAmount >= amount))
185+ then FILLED
186+ else NEW
187+ 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)]))
188+ }
158189 }
159190
160191
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = ""
5+
6+func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) {
7+ case a: Int =>
8+ a
9+ case _ =>
10+ 0
11+}
12+
513
614 func getNumberByKey (key) = match getInteger(this, key) {
715 case a: Int =>
816 a
917 case _ =>
1018 0
1119 }
1220
1321
1422 func getStringByKey (key) = match getString(this, key) {
1523 case a: String =>
1624 a
1725 case _ =>
1826 NONE
1927 }
2028
2129
2230 let OrderBookKey = "orderbook"
2331
2432 let OrderPriceKey = "order_price_"
2533
2634 let OrderTotalKey = "order_total_"
2735
2836 let OrderFilledTotalKey = "order_filled_total_"
2937
3038 let OrderOwnerKey = "order_owner_"
3139
3240 let OrderHeightKey = "order_height_"
3341
3442 let OrderStatusKey = "order_status_"
3543
44+let PriceKey = "price"
45+
3646 let BondAssetIdKey = "bond_asset_id"
3747
3848 let NeutrinoAssetIdKey = "neutrino_asset_id"
3949
4050 let NeutrinoContractKey = "neutrino_contract"
51+
52+let NeutrinoSupplyKey = "neutrino_supply"
53+
54+let WavesReserveKey = "waves_reserve"
4155
4256 let orderbook = getStringByKey(OrderBookKey)
4357
4458 func getOrderPrice (id) = getNumberByKey((OrderPriceKey + id))
4559
4660
4761 func getOrderTotal (id) = getNumberByKey((OrderTotalKey + id))
4862
4963
5064 func getOrderOwner (id) = getStringByKey((OrderOwnerKey + id))
5165
5266
5367 func getOrderStatus (id) = getStringByKey((OrderStatusKey + id))
5468
5569
5670 func getOrderFilledTotal (id) = getNumberByKey((OrderFilledTotalKey + id))
5771
5872
73+let NeutrinoContract = getStringByKey(NeutrinoContractKey)
74+
75+let reserve = getNumberByAddressAndKey(NeutrinoContract, WavesReserveKey)
76+
77+let neutrinoSupply = getNumberByAddressAndKey(NeutrinoContract, NeutrinoSupplyKey)
78+
79+let price = getNumberByAddressAndKey(NeutrinoContract, PriceKey)
80+
5981 let OrderSplitSymbol = "_"
6082
6183 let BondAssetId = fromBase58String(getStringByKey(BondAssetIdKey))
6284
6385 let NeutrinoAssetId = fromBase58String(getStringByKey(NeutrinoAssetIdKey))
64-
65-let NeutrinoContract = getStringByKey(NeutrinoContractKey)
6686
6787 let Wavelet = 100000000
6888
6989 let CANCELED = "canceled"
7090
7191 let NEW = "new"
7292
7393 let FILLED = "filled"
7494
7595 func calculateOrderbook (orderId,position) = {
7696 let orders = split(orderbook, OrderSplitSymbol)
7797 let newOrder = (orderId + OrderSplitSymbol)
7898 if ((position == 0))
7999 then (newOrder + orderbook)
80100 else if ((position >= (size(orders) - 1)))
81101 then (orderbook + newOrder)
82102 else {
83103 let parts = split(orderbook, (orders[position] + OrderSplitSymbol))
84104 (((parts[0] + newOrder) + (orders[position] + OrderSplitSymbol)) + parts[1])
85105 }
86106 }
87107
88108
89109 @Callable(i)
90110 func setOrder (price,position) = {
91111 let pmt = extract(i.payment)
92112 let newOrderId = toBase58String(keccak256((((toBytes(price) + toBytes(pmt.amount)) + i.caller.bytes) + toBytes(height))))
93113 if ((pmt.assetId != NeutrinoAssetId))
94114 then throw("can use neutrino only")
95115 else if ((0 >= price))
96116 then throw("price less zero")
97117 else if ((getOrderOwner(newOrderId) != NONE))
98118 then throw("order exists")
99119 else {
100120 let orders = split(orderbook, OrderSplitSymbol)
101121 let nextOrderId = if ((position == 0))
102122 then ""
103123 else orders[(position - 1)]
104124 let nextOrderPrice = getOrderPrice(nextOrderId)
105125 let isNextOrderError = if (if ((nextOrderId != ""))
106126 then (price > nextOrderPrice)
107127 else false)
108128 then true
109129 else false
110130 let prevOrderId = orders[position]
111131 let prevOrderPrice = getOrderPrice(prevOrderId)
112132 let isPrevOrderError = if ((prevOrderPrice >= price))
113133 then true
114134 else false
115135 if (if (isNextOrderError)
116136 then true
117137 else isPrevOrderError)
118138 then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError)))
119139 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)])
120140 }
121141 }
122142
123143
124144
125145 @Callable(i)
126146 func cancelOrder (orderId) = {
127147 let owner = getOrderOwner(orderId)
128148 let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId))
129149 if ((owner != toString(i.caller)))
130150 then throw("permission denied")
131151 else {
132152 let parts = split(orderbook, (orderId + OrderSplitSymbol))
133153 ScriptResult(WriteSet([DataEntry(OrderBookKey, (parts[0] + parts[1])), DataEntry((OrderStatusKey + orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, NeutrinoAssetId)]))
134154 }
135155 }
136156
137157
138158
139159 @Callable(i)
140160 func executeOrder () = {
141161 let orderId = split(orderbook, OrderSplitSymbol)[0]
142- let bondAmount = assetBalance(this, BondAssetId)
143- let filledTotal = getOrderFilledTotal(orderId)
144- let orderTotal = getOrderTotal(orderId)
145- let orderPrice = getOrderPrice(orderId)
146- let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
147- let newOrderbook = if ((bondAmount >= amount))
148- then split(orderbook, (orderId + OrderSplitSymbol))[1]
149- else orderbook
150- let filledAmount = if ((bondAmount >= amount))
151- then amount
152- else bondAmount
153- let total = (((filledAmount * orderPrice) / 100) * Wavelet)
154- let status = if ((bondAmount >= amount))
155- then FILLED
156- else NEW
157- 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)]))
162+ let bondBalance = assetBalance(this, BondAssetId)
163+ let deficit = (neutrinoSupply - ((reserve * price) / 100))
164+ let bondAmount = if ((deficit >= bondBalance))
165+ then bondBalance
166+ else deficit
167+ let returnAmount = if ((deficit >= bondBalance))
168+ then 0
169+ else (bondBalance - deficit)
170+ if ((bondAmount == 0))
171+ then TransferSet([ScriptTransfer(addressFromStringValue(NeutrinoContract), returnAmount, BondAssetId)])
172+ else {
173+ let filledTotal = getOrderFilledTotal(orderId)
174+ let orderTotal = getOrderTotal(orderId)
175+ let orderPrice = getOrderPrice(orderId)
176+ let amount = ((((orderTotal - filledTotal) * 100) / orderPrice) / Wavelet)
177+ let newOrderbook = if ((bondAmount >= amount))
178+ then split(orderbook, (orderId + OrderSplitSymbol))[1]
179+ else orderbook
180+ let filledAmount = if ((bondAmount >= amount))
181+ then amount
182+ else bondAmount
183+ let total = (((filledAmount * orderPrice) / 100) * Wavelet)
184+ let status = if ((bondAmount >= amount))
185+ then FILLED
186+ else NEW
187+ 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)]))
188+ }
158189 }
159190
160191

github/deemru/w8io/169f3d6 
28.14 ms