tx · 4j976ShiPMtdC9trptN789z6C5PA1oHFqPbo1DJYo3Gi 3MyNwcgxhJfkfjzHh3Dd7QPhbpA26RR5QEo: -0.01000000 Waves 2020.04.17 19:21 [958712] smart account 3MyNwcgxhJfkfjzHh3Dd7QPhbpA26RR5QEo > SELF 0.00000000 Waves
{ "type": 13, "id": "4j976ShiPMtdC9trptN789z6C5PA1oHFqPbo1DJYo3Gi", "fee": 1000000, "feeAssetId": null, "timestamp": 1587140477913, "version": 1, "sender": "3MyNwcgxhJfkfjzHh3Dd7QPhbpA26RR5QEo", "senderPublicKey": "9sz2ABXPL4NsMiXAhC62LpFf131R9XKdnVtdrrRetX9p", "proofs": [ "3q4Fphzs3LfkryLcvG98MmrTZ5YCWJJ32SkdSX6NKGyew93Uic9TQuWoADmT192xq9CwDztRw2iSvDnpx3yZbyP" ], "script": "base64:AAIDAAAAAAAAABQIARIHCgUICAgICBIAEgMKAQgSAAAAACAAAAAAB0JVTExLZXkCAAAABkJVTExJZAAAAAAHQkVBUktleQIAAAAGQkVBUklkAAAAAAxtYWluVG9rZW5LZXkCAAAAC21haW5Ub2tlbklkAAAAABBvcmFjbGVBZGRyZXNzS2V5AgAAAAZvcmFjbGUAAAAAF29yYWNsZUN1cnJlbnRQcmljZUlkS2V5AgAAAAtsYXN0UHJpY2VJZAAAAAAXbGFzdFJlYmFsYW5jZVByaWNlSWRLZXkCAAAAFWxhc3RTZXR0bGVtZW50UHJpY2VJZAAAAAARYnVsbENvbGxhdGVyYWxLZXkCAAAADmJ1bGxDb2xsYXRlcmFsAAAAABFiZWFyQ29sbGF0ZXJhbEtleQIAAAAOYmVhckNvbGxhdGVyYWwAAAAAEmJ1bGxDaXJjdWxhdGlvbktleQIAAAAPYnVsbENpcmN1bGF0aW9uAAAAABJiZWFyQ2lyY3VsYXRpb25LZXkCAAAAD2JlYXJDaXJjdWxhdGlvbgAAAAAHYnVsbENvbAkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEGgA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ANpbnYAAAAHcGF5bWVudAAAAAZhbW91bnQFAAAAB3Rva2VuSWQJAABkAAAAAgUAAAANb3JhY2xlUHJpY2VJZAAAAAAAAAAAAQkABCUAAAABCAUAAAADaW52AAAABmNhbGxlcgAAAANpbnYBAAAABnNldHRsZQAAAAAEAAAACnF1ZXVlRW1wdHkJAAAAAAAAAgUAAAALaGVhZFBvaW50ZXICAAAAAAQAAAAMY2FuUmViYWxhbmNlCQAAZgAAAAIFAAAADW9yYWNsZVByaWNlSWQFAAAAEXJlYmFsYW5jZWRQcmljZUlkAwUAAAAKcXVldWVFbXB0eQMFAAAADGNhblJlYmFsYW5jZQkBAAAACXJlYmFsYW5jZQAAAAAJAAACAAAAAQIAAAAXW09LXSBhbGwgZG9uZSwgY2Fycnkgb24EAAAABGRhdGEJAAS1AAAAAgkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAABHRoaXMFAAAAC2hlYWRQb2ludGVyAgAAABBiYWQgaGVhZCBwb2ludGVyAgAAAAF8BAAAAAdwcmljZUlkCQEAAAANcGFyc2VJbnRWYWx1ZQAAAAEJAAGRAAAAAgUAAAAEZGF0YQAAAAAAAAAAAwMJAABmAAAAAgUAAAAHcHJpY2VJZAUAAAARcmViYWxhbmNlZFByaWNlSWQDBQAAAAxjYW5SZWJhbGFuY2UJAQAAAAlyZWJhbGFuY2UAAAAACQAAAgAAAAECAAAAEVtPS10gbmVlZCB0byB3YWl0AwkAAAAAAAACBQAAAAdwcmljZUlkBQAAABFyZWJhbGFuY2VkUHJpY2VJZAkBAAAAB2RlcXVldWUAAAAACQAAAgAAAAECAAAAMGNvcnJ1cHQgZGF0YSwgZnV0dXJlIHByaWNlIGlkIGFscmVhZHkgcmViYWxhbmNlZAAAAACDxp4i", "chainId": 84, "height": 958712, "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 3 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let BULLKey = "BULLId" | |
5 | + | ||
6 | + | let BEARKey = "BEARId" | |
7 | + | ||
8 | + | let mainTokenKey = "mainTokenId" | |
9 | + | ||
10 | + | let oracleAddressKey = "oracle" | |
11 | + | ||
12 | + | let oracleCurrentPriceIdKey = "lastPriceId" | |
13 | + | ||
14 | + | let lastRebalancePriceIdKey = "lastSettlementPriceId" | |
15 | + | ||
16 | + | let bullCollateralKey = "bullCollateral" | |
17 | + | ||
18 | + | let bearCollateralKey = "bearCollateral" | |
19 | + | ||
20 | + | let bullCirculationKey = "bullCirculation" | |
21 | + | ||
22 | + | let bearCirculationKey = "bearCirculation" | |
23 | + | ||
24 | + | let bullCol = valueOrErrorMessage(getInteger(this, bullCollateralKey), "no bullCollateralKey") | |
25 | + | ||
26 | + | let bearCol = valueOrErrorMessage(getInteger(this, bearCollateralKey), "no bearCollateralKey") | |
27 | + | ||
28 | + | let bullCirc = valueOrErrorMessage(getInteger(this, bullCirculationKey), "no bullCirculationKey") | |
29 | + | ||
30 | + | let bearCirc = valueOrErrorMessage(getInteger(this, bearCirculationKey), "no bearCirculationKey") | |
31 | + | ||
32 | + | let BULL = valueOrErrorMessage(getString(this, BULLKey), "no BULLKey") | |
33 | + | ||
34 | + | let BEAR = valueOrErrorMessage(getString(this, BEARKey), "no BEARKey") | |
35 | + | ||
36 | + | let mainToken = valueOrErrorMessage(getString(this, mainTokenKey), "no mainTokenKey") | |
37 | + | ||
38 | + | let oracle = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(this, oracleAddressKey), "no oracleAddressKey")), "bad oracle address") | |
39 | + | ||
40 | + | let rebalancedPriceId = valueOrErrorMessage(getInteger(this, lastRebalancePriceIdKey), "no last rebalance price") | |
41 | + | ||
42 | + | let oraclePriceId = valueOrErrorMessage(getInteger(oracle, oracleCurrentPriceIdKey), "bad oracle data") | |
43 | + | ||
44 | + | let headPointerKey = "headPointer" | |
45 | + | ||
46 | + | let tailPointerKey = "tailPointer" | |
47 | + | ||
48 | + | let queueSizeKey = "queueSize" | |
49 | + | ||
50 | + | let queueSize = match getInteger(this, queueSizeKey) { | |
51 | + | case i: Int => | |
52 | + | i | |
53 | + | case _ => | |
54 | + | 0 | |
55 | + | } | |
56 | + | ||
57 | + | let headPointer = match getString(this, headPointerKey) { | |
58 | + | case s: String => | |
59 | + | s | |
60 | + | case _ => | |
61 | + | "" | |
62 | + | } | |
63 | + | ||
64 | + | let tailPointer = match getString(this, tailPointerKey) { | |
65 | + | case s: String => | |
66 | + | s | |
67 | + | case _ => | |
68 | + | "" | |
69 | + | } | |
70 | + | ||
71 | + | let ISSUE = "ISSUE" | |
72 | + | ||
73 | + | let REDEEM = "REDEEM" | |
74 | + | ||
75 | + | func buildNewItem (action,amt,token,priceId,invoker) = (((((((((action + "|") + toString(amt)) + "|") + token) + "|") + toString(priceId)) + "|") + invoker) + "|") | |
76 | + | ||
77 | + | ||
78 | + | func enqueue (id,action,amt,token,priceId,invoker) = { | |
79 | + | let increaseQueueSize = DataEntry(queueSizeKey, (queueSize + 1)) | |
80 | + | if ((queueSize == 0)) | |
81 | + | then { | |
82 | + | let itm = buildNewItem(action, amt, token, priceId, invoker) | |
83 | + | WriteSet([DataEntry(headPointerKey, id), DataEntry(tailPointerKey, id), DataEntry(id, itm), increaseQueueSize]) | |
84 | + | } | |
85 | + | else { | |
86 | + | let prevId = valueOrErrorMessage(getString(this, tailPointerKey), "can't get tail pointer") | |
87 | + | let prevItm = split(valueOrErrorMessage(getString(this, prevId), "can't resolve pointer"), "|") | |
88 | + | let updatedPrevItm = ((((((((((prevItm[0] + "|") + prevItm[1]) + "|") + prevItm[2]) + "|") + prevItm[3]) + "|") + prevItm[4]) + "|") + id) | |
89 | + | let itm = buildNewItem(action, amt, token, priceId, invoker) | |
90 | + | WriteSet([DataEntry(prevId, updatedPrevItm), DataEntry(id, itm), DataEntry(tailPointerKey, id), increaseQueueSize]) | |
91 | + | } | |
92 | + | } | |
93 | + | ||
94 | + | ||
95 | + | func dequeue () = if ((queueSize == 0)) | |
96 | + | then throw("nothing to settle") | |
97 | + | else { | |
98 | + | let decreaseQueueSize = DataEntry(queueSizeKey, (queueSize - 1)) | |
99 | + | let isLastElement = (headPointer == tailPointer) | |
100 | + | let overwriteTail = DataEntry(tailPointerKey, "") | |
101 | + | let data = split(valueOrErrorMessage(getString(this, headPointer), "bad head pointer"), "|") | |
102 | + | let action = data[0] | |
103 | + | let amt = parseIntValue(data[1]) | |
104 | + | let token = data[2] | |
105 | + | let priceId = parseIntValue(data[3]) | |
106 | + | let invoker = addressFromStringValue(data[4]) | |
107 | + | let next = data[5] | |
108 | + | if ((rebalancedPriceId > priceId)) | |
109 | + | then throw(((("corrupt state, rebalancedPriceId=" + toString(rebalancedPriceId)) + ", request price id=") + toString(priceId))) | |
110 | + | else if ((priceId > rebalancedPriceId)) | |
111 | + | then throw("can't dequeue, too early, rebalance first") | |
112 | + | else if ((action == ISSUE)) | |
113 | + | then { | |
114 | + | let addedCollateral = amt | |
115 | + | if ((token == BULL)) | |
116 | + | then { | |
117 | + | let addedToCirculation = fraction(bullCirc, addedCollateral, bullCol) | |
118 | + | let items = [DataEntry(bullCollateralKey, (bullCol + addedCollateral)), DataEntry(bullCirculationKey, (bullCirc + addedToCirculation)), DataEntry(headPointerKey, next), decreaseQueueSize] | |
119 | + | ScriptResult(WriteSet(if (isLastElement) | |
120 | + | then overwriteTail :: items | |
121 | + | else items), TransferSet([ScriptTransfer(invoker, addedToCirculation, fromBase58String(BULL))])) | |
122 | + | } | |
123 | + | else if ((token == BEAR)) | |
124 | + | then { | |
125 | + | let addedToCirculation = fraction(bearCirc, addedCollateral, bearCol) | |
126 | + | let items = [DataEntry(bearCollateralKey, (bearCol + addedCollateral)), DataEntry(bearCirculationKey, (bearCirc + addedToCirculation)), DataEntry(headPointerKey, next), decreaseQueueSize] | |
127 | + | ScriptResult(WriteSet(if (isLastElement) | |
128 | + | then overwriteTail :: items | |
129 | + | else items), TransferSet([ScriptTransfer(invoker, addedToCirculation, fromBase58String(BEAR))])) | |
130 | + | } | |
131 | + | else throw("bad token id") | |
132 | + | } | |
133 | + | else if ((action == REDEEM)) | |
134 | + | then { | |
135 | + | let removedTokens = amt | |
136 | + | if ((token == BULL)) | |
137 | + | then { | |
138 | + | let removedCollateral = fraction(bullCol, removedTokens, bullCirc) | |
139 | + | let items = [DataEntry(bullCollateralKey, (bullCol - removedCollateral)), DataEntry(bullCirculationKey, (bullCirc - removedTokens)), DataEntry(headPointerKey, next), decreaseQueueSize] | |
140 | + | ScriptResult(WriteSet(if (isLastElement) | |
141 | + | then overwriteTail :: items | |
142 | + | else items), TransferSet([ScriptTransfer(invoker, removedCollateral, fromBase58String(mainToken))])) | |
143 | + | } | |
144 | + | else if ((token == BEAR)) | |
145 | + | then { | |
146 | + | let removedCollateral = fraction(bearCol, removedTokens, bearCirc) | |
147 | + | let items = [DataEntry(bearCollateralKey, (bearCol - removedCollateral)), DataEntry(bearCirculationKey, (bearCirc - removedTokens)), DataEntry(headPointerKey, next), decreaseQueueSize] | |
148 | + | ScriptResult(WriteSet(if (isLastElement) | |
149 | + | then overwriteTail :: items | |
150 | + | else items), TransferSet([ScriptTransfer(invoker, removedCollateral, fromBase58String(mainToken))])) | |
151 | + | } | |
152 | + | else throw("bad token id") | |
153 | + | } | |
154 | + | else throw(("bad action: " + action)) | |
155 | + | } | |
156 | + | ||
157 | + | ||
158 | + | func rebalance () = { | |
159 | + | func LV (v,p0,p1) = { | |
160 | + | let denom = 100 | |
161 | + | let pmax = ((if ((p1 > p0)) | |
162 | + | then p1 | |
163 | + | else p0) / denom) | |
164 | + | let pmin = ((if ((p0 > p1)) | |
165 | + | then p1 | |
166 | + | else p0) / denom) | |
167 | + | let a = (pmin * pmin) | |
168 | + | let b = (((9 * pmax) * pmax) - ((15 * pmax) * pmin)) | |
169 | + | fraction(v, ((6 * a) + b), ((7 * a) + b)) | |
170 | + | } | |
171 | + | ||
172 | + | let settledPriceId = valueOrErrorMessage(getInteger(this, lastRebalancePriceIdKey), "inconsistent data") | |
173 | + | let unsettledPriceId = (settledPriceId + 1) | |
174 | + | let settledPrice = valueOrErrorMessage(getInteger(oracle, toString(settledPriceId)), "bad oracle data for sellted price") | |
175 | + | let nextPrice = valueOrErrorMessage(getInteger(oracle, toString(unsettledPriceId)), "no next price") | |
176 | + | let minVol = if ((bearCol > bullCol)) | |
177 | + | then bullCol | |
178 | + | else bearCol | |
179 | + | let redist = LV(minVol, settledPrice, nextPrice) | |
180 | + | if ((nextPrice > settledPrice)) | |
181 | + | then WriteSet([DataEntry(bullCollateralKey, (bullCol + redist)), DataEntry(bearCollateralKey, (bearCol - redist)), DataEntry(lastRebalancePriceIdKey, unsettledPriceId)]) | |
182 | + | else if ((settledPrice > nextPrice)) | |
183 | + | then WriteSet([DataEntry(bullCollateralKey, (bullCol - redist)), DataEntry(bearCollateralKey, (bearCol + redist)), DataEntry(lastRebalancePriceIdKey, unsettledPriceId)]) | |
184 | + | else WriteSet([DataEntry(lastRebalancePriceIdKey, unsettledPriceId)]) | |
185 | + | } | |
186 | + | ||
187 | + | ||
188 | + | @Callable(inv) | |
189 | + | func init (bullId,bearId,mainTokenId,oracleAddress,initiator) = if (isDefined(getString(this, BULLKey))) | |
190 | + | then throw("already initialized") | |
191 | + | else if ((inv.caller != this)) | |
192 | + | then throw("only self can init") | |
193 | + | else { | |
194 | + | let totalOwnedMainToken = assetBalance(this, fromBase58String(mainTokenId)) | |
195 | + | let bulls = (totalOwnedMainToken / 2) | |
196 | + | let bears = (totalOwnedMainToken - bulls) | |
197 | + | if (if ((bears == 0)) | |
198 | + | then true | |
199 | + | else (bulls == 0)) | |
200 | + | then throw("can't init balances") | |
201 | + | else { | |
202 | + | let oracleCurrentPriceId = valueOrErrorMessage(getInteger(valueOrErrorMessage(addressFromString(oracleAddress), "bad oracle address"), oracleCurrentPriceIdKey), "can't find oracle price id") | |
203 | + | let recipient = addressFromStringValue(initiator) | |
204 | + | ScriptResult(WriteSet([DataEntry(BULLKey, bullId), DataEntry(BEARKey, bearId), DataEntry(mainTokenKey, mainTokenId), DataEntry(oracleAddressKey, oracleAddress), DataEntry(bullCollateralKey, bulls), DataEntry(bearCollateralKey, bears), DataEntry(bullCirculationKey, bulls), DataEntry(bearCirculationKey, bears), DataEntry(lastRebalancePriceIdKey, oracleCurrentPriceId)]), TransferSet([ScriptTransfer(recipient, bulls, fromBase58String(bullId)), ScriptTransfer(recipient, bears, fromBase58String(bearId))])) | |
205 | + | } | |
206 | + | } | |
207 | + | ||
208 | + | ||
209 | + | ||
210 | + | @Callable(inv) | |
211 | + | func requestRedeem () = if ((inv.caller == this)) | |
212 | + | then throw("can't do") | |
213 | + | else { | |
214 | + | func errorMessage (got) = throw(((((("only BULL(" + BULL) + ") or BEAR(") + BEAR) + ") tokens are accepted, received: ") + got)) | |
215 | + | ||
216 | + | if (!(isDefined(inv.payment))) | |
217 | + | then errorMessage("no attached payment") | |
218 | + | else { | |
219 | + | let assetId = toBase58String(valueOrErrorMessage(value(inv.payment).assetId, "waves are not accepted here")) | |
220 | + | if (if ((assetId != BEAR)) | |
221 | + | then (assetId != BULL) | |
222 | + | else false) | |
223 | + | then errorMessage(assetId) | |
224 | + | else enqueue(toBase58String(inv.transactionId), REDEEM, value(inv.payment).amount, assetId, (oraclePriceId + 1), toString(inv.caller)) | |
225 | + | } | |
226 | + | } | |
227 | + | ||
228 | + | ||
229 | + | ||
230 | + | @Callable(inv) | |
231 | + | func requestIssue (tokenId) = if ((inv.caller == this)) | |
232 | + | then throw("can't do") | |
233 | + | else { | |
234 | + | let errorMessage = throw((((((("only BULL(" + BULL) + ") or BEAR(") + BEAR) + ") tokens are available in exchange for USDN(") + mainToken) + ")")) | |
235 | + | if (if ((tokenId != BULL)) | |
236 | + | then (tokenId != BEAR) | |
237 | + | else false) | |
238 | + | then errorMessage | |
239 | + | else if (!(isDefined(inv.payment))) | |
240 | + | then errorMessage | |
241 | + | else if ((value(inv.payment).assetId != fromBase58String(mainToken))) | |
242 | + | then errorMessage | |
243 | + | else enqueue(toBase58String(inv.transactionId), ISSUE, value(inv.payment).amount, tokenId, (oraclePriceId + 1), toString(inv.caller)) | |
244 | + | } | |
245 | + | ||
246 | + | ||
247 | + | ||
248 | + | @Callable(inv) | |
249 | + | func settle () = { | |
250 | + | let queueEmpty = (headPointer == "") | |
251 | + | let canRebalance = (oraclePriceId > rebalancedPriceId) | |
252 | + | if (queueEmpty) | |
253 | + | then if (canRebalance) | |
254 | + | then rebalance() | |
255 | + | else throw("[OK] all done, carry on") | |
256 | + | else { | |
257 | + | let data = split(valueOrErrorMessage(getString(this, headPointer), "bad head pointer"), "|") | |
258 | + | let priceId = parseIntValue(data[3]) | |
259 | + | if ((priceId > rebalancedPriceId)) | |
260 | + | then if (canRebalance) | |
261 | + | then rebalance() | |
262 | + | else throw("[OK] need to wait") | |
263 | + | else if ((priceId == rebalancedPriceId)) | |
264 | + | then dequeue() | |
265 | + | else throw("corrupt data, future price id already rebalanced") | |
266 | + | } | |
267 | + | } | |
268 | + | ||
269 | + |
github/deemru/w8io/169f3d6 41.01 ms ◑