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:AAIDAAAAAAAAAAAAAAAhAAAAAAROT05FAgAAAAABAAAAGGdldE51bWJlckJ5QWRkcmVzc0FuZEtleQAAAAIAAAAHYWRkcmVzcwAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAAdhZGRyZXNzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0U3RyaW5nQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABY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EFzc2V0SWQFAAAAA25pbAAAAACvYU5P", "chainId": 84, "height": 680487, "spentComplexity": 0 } View: original | compacted Prev: BR6hHnQ4Wkd98ok6a5R2hW83z1J2paziSNBVHKw2dMtr Next: 2LNhkqHdu8dDu6fokVp2yCKKi93TG6oBpNp2GY2EEFNh Diff:
Old | New | Differences | |
---|---|---|---|
170 | 170 | else (bondBalance - deficitPositive) | |
171 | 171 | if ((bondAmount == 0)) | |
172 | 172 | 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 | + | } | |
174 | 191 | } | |
175 | 192 | ||
176 | 193 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "" | |
5 | 5 | ||
6 | 6 | func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) { | |
7 | 7 | case a: Int => | |
8 | 8 | a | |
9 | 9 | case _ => | |
10 | 10 | 0 | |
11 | 11 | } | |
12 | 12 | ||
13 | 13 | ||
14 | 14 | func getNumberByKey (key) = match getInteger(this, key) { | |
15 | 15 | case a: Int => | |
16 | 16 | a | |
17 | 17 | case _ => | |
18 | 18 | 0 | |
19 | 19 | } | |
20 | 20 | ||
21 | 21 | ||
22 | 22 | func getStringByKey (key) = match getString(this, key) { | |
23 | 23 | case a: String => | |
24 | 24 | a | |
25 | 25 | case _ => | |
26 | 26 | NONE | |
27 | 27 | } | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | let OrderBookKey = "orderbook" | |
31 | 31 | ||
32 | 32 | let OrderPriceKey = "order_price_" | |
33 | 33 | ||
34 | 34 | let OrderTotalKey = "order_total_" | |
35 | 35 | ||
36 | 36 | let OrderFilledTotalKey = "order_filled_total_" | |
37 | 37 | ||
38 | 38 | let OrderOwnerKey = "order_owner_" | |
39 | 39 | ||
40 | 40 | let OrderHeightKey = "order_height_" | |
41 | 41 | ||
42 | 42 | let OrderStatusKey = "order_status_" | |
43 | 43 | ||
44 | 44 | let PriceKey = "price" | |
45 | 45 | ||
46 | 46 | let BondAssetIdKey = "bond_asset_id" | |
47 | 47 | ||
48 | 48 | let NeutrinoAssetIdKey = "neutrino_asset_id" | |
49 | 49 | ||
50 | 50 | let NeutrinoContractKey = "neutrino_contract" | |
51 | 51 | ||
52 | 52 | let orderbook = getStringByKey(OrderBookKey) | |
53 | 53 | ||
54 | 54 | func getOrderPrice (id) = getNumberByKey((OrderPriceKey + id)) | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func getOrderTotal (id) = getNumberByKey((OrderTotalKey + id)) | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func getOrderOwner (id) = getStringByKey((OrderOwnerKey + id)) | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | func getOrderStatus (id) = getStringByKey((OrderStatusKey + id)) | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func getOrderFilledTotal (id) = getNumberByKey((OrderFilledTotalKey + id)) | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | let NeutrinoAssetId = fromBase58String(getStringByKey(NeutrinoAssetIdKey)) | |
70 | 70 | ||
71 | 71 | let NeutrinoContract = getStringByKey(NeutrinoContractKey) | |
72 | 72 | ||
73 | 73 | let reserve = wavesBalance(addressFromStringValue(NeutrinoContract)) | |
74 | 74 | ||
75 | 75 | let neutrinoSupply = { | |
76 | 76 | let info = extract(assetInfo(NeutrinoAssetId)) | |
77 | 77 | (info.quantity - assetBalance(addressFromStringValue(NeutrinoContract), NeutrinoAssetId)) | |
78 | 78 | } | |
79 | 79 | ||
80 | 80 | let price = getNumberByAddressAndKey(NeutrinoContract, PriceKey) | |
81 | 81 | ||
82 | 82 | let OrderSplitSymbol = "_" | |
83 | 83 | ||
84 | 84 | let BondAssetId = fromBase58String(getStringByKey(BondAssetIdKey)) | |
85 | 85 | ||
86 | 86 | let Wavelet = 100000000 | |
87 | 87 | ||
88 | 88 | let CANCELED = "canceled" | |
89 | 89 | ||
90 | 90 | let NEW = "new" | |
91 | 91 | ||
92 | 92 | let FILLED = "filled" | |
93 | 93 | ||
94 | 94 | func calculateOrderbook (orderId,position) = { | |
95 | 95 | let orders = split(orderbook, OrderSplitSymbol) | |
96 | 96 | let newOrder = (orderId + OrderSplitSymbol) | |
97 | 97 | if ((position == 0)) | |
98 | 98 | then (newOrder + orderbook) | |
99 | 99 | else if ((position >= (size(orders) - 1))) | |
100 | 100 | then (orderbook + newOrder) | |
101 | 101 | else { | |
102 | 102 | let parts = split(orderbook, (orders[position] + OrderSplitSymbol)) | |
103 | 103 | (((parts[0] + newOrder) + (orders[position] + OrderSplitSymbol)) + parts[1]) | |
104 | 104 | } | |
105 | 105 | } | |
106 | 106 | ||
107 | 107 | ||
108 | 108 | @Callable(i) | |
109 | 109 | func setOrder (price,position) = { | |
110 | 110 | let pmt = extract(i.payment) | |
111 | 111 | let newOrderId = toBase58String(keccak256((((toBytes(price) + toBytes(pmt.amount)) + i.caller.bytes) + toBytes(height)))) | |
112 | 112 | if ((pmt.assetId != NeutrinoAssetId)) | |
113 | 113 | then throw("can use neutrino only") | |
114 | 114 | else if ((0 >= price)) | |
115 | 115 | then throw("price less zero") | |
116 | 116 | else if ((getOrderOwner(newOrderId) != NONE)) | |
117 | 117 | then throw("order exists") | |
118 | 118 | else { | |
119 | 119 | let orders = split(orderbook, OrderSplitSymbol) | |
120 | 120 | let nextOrderId = if ((position == 0)) | |
121 | 121 | then "" | |
122 | 122 | else orders[(position - 1)] | |
123 | 123 | let nextOrderPrice = getOrderPrice(nextOrderId) | |
124 | 124 | let isNextOrderError = if (if ((nextOrderId != "")) | |
125 | 125 | then (price > nextOrderPrice) | |
126 | 126 | else false) | |
127 | 127 | then true | |
128 | 128 | else false | |
129 | 129 | let prevOrderId = orders[position] | |
130 | 130 | let prevOrderPrice = getOrderPrice(prevOrderId) | |
131 | 131 | let isPrevOrderError = if ((prevOrderPrice >= price)) | |
132 | 132 | then true | |
133 | 133 | else false | |
134 | 134 | if (if (isNextOrderError) | |
135 | 135 | then true | |
136 | 136 | else isPrevOrderError) | |
137 | 137 | then throw(((("invalid order isPrevOrderError:" + toString(isPrevOrderError)) + " isNextOrderError:") + toString(isNextOrderError))) | |
138 | 138 | 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)]) | |
139 | 139 | } | |
140 | 140 | } | |
141 | 141 | ||
142 | 142 | ||
143 | 143 | ||
144 | 144 | @Callable(i) | |
145 | 145 | func cancelOrder (orderId) = { | |
146 | 146 | let owner = getOrderOwner(orderId) | |
147 | 147 | let amount = (getOrderTotal(orderId) - getOrderFilledTotal(orderId)) | |
148 | 148 | if ((owner != toString(i.caller))) | |
149 | 149 | then throw("permission denied") | |
150 | 150 | else { | |
151 | 151 | let parts = split(orderbook, (orderId + OrderSplitSymbol)) | |
152 | 152 | ScriptResult(WriteSet([DataEntry(OrderBookKey, (parts[0] + parts[1])), DataEntry((OrderStatusKey + orderId), CANCELED)]), TransferSet([ScriptTransfer(i.caller, amount, NeutrinoAssetId)])) | |
153 | 153 | } | |
154 | 154 | } | |
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | 158 | @Callable(i) | |
159 | 159 | func executeOrder () = { | |
160 | 160 | let bondBalance = assetBalance(this, BondAssetId) | |
161 | 161 | let deficit = ((neutrinoSupply - ((reserve * price) / 100)) / Wavelet) | |
162 | 162 | let deficitPositive = if ((0 >= deficit)) | |
163 | 163 | then 0 | |
164 | 164 | else deficit | |
165 | 165 | let bondAmount = if ((deficitPositive >= bondBalance)) | |
166 | 166 | then bondBalance | |
167 | 167 | else deficitPositive | |
168 | 168 | let returnAmount = if ((deficitPositive >= bondBalance)) | |
169 | 169 | then 0 | |
170 | 170 | else (bondBalance - deficitPositive) | |
171 | 171 | if ((bondAmount == 0)) | |
172 | 172 | 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 | + | } | |
174 | 191 | } | |
175 | 192 | ||
176 | 193 |
github/deemru/w8io/026f985 42.07 ms ◑