tx · 6GXZHfA8NZPnaFa5y2RYEZiTUwHuLPsUgrhYBaxeY9vG 3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr: -0.05000000 Waves 2020.12.28 16:31 [1328605] smart account 3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr > SELF 0.00000000 Waves
{ "type": 13, "id": "6GXZHfA8NZPnaFa5y2RYEZiTUwHuLPsUgrhYBaxeY9vG", "fee": 5000000, "feeAssetId": null, "timestamp": 1609162329866, "version": 2, "chainId": 84, "sender": "3NC5E3y11PtakmAUxN9Nfdvx7XjWsffcJrr", "senderPublicKey": "DuSyT6XMpGpexrez81rru35TfpmHJcYQP1WJxT9wjcry", "proofs": [ "3G866XZWhhYJTAjwyCfHw5upXsQizUzP9UJoyxmhmvJ2qi1s9Wz5wfc5ZrL9NGM1oxn7Rij9XdEvQDQoh4iaWR6C" ], "script": "base64:AAIDAAAAAAAAABYIARIDCgEBEgMKAQESAwoBARIDCgEBAAAABwAAAAANUkVDT1ZFUllQSEFTRQAAAAAAAAAAZAAAAAALUFJJQ0VPUkFDTEUCAAAAIzNONE5TN2Q0Sm85YTZGMTRMaUZVS0tZVmRVa2tmMmVQNFp4AQAAABJnZXREYXRhRW50cnlGb3JLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABeAUAAAAHJG1hdGNoMAUAAAABeAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAAAAAAAAAAAAAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAAMcGF5b3V0Q2FsbGVyAAAAAwAAAAZ0YXJnZXQAAAAGY2FsbGVyAAAABnBheW91dAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgkAASwAAAACCQABLAAA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ZXJ5IHBoYXNlIGFjdGl2ZS4gWW91IGNhbiBubyBsb25nZXIgZ28gbG9uZyB0b3dhcmRzIHRoaXMgbG9uZyB0YXJnZXQgLyBoZWlnaHQhCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACBQAAAA5sb25nQWRkcmVzc0tleQkAAGQAAAACBQAAABtjdXJyZW50TG9uZ0Ftb3VudEZvckFkZHJlc3MFAAAABmFtb3VudAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAANbG9uZ3NUb3RhbEtleQkAAGQAAAACBQAAAAxjdXJyZW50TG9uZ3MFAAAABmFtb3VudAUAAAADbmlsAAAAADJaJew=", "height": 1328605, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5ufjCRb8mag4i6s7bRHKrZguwfyGD1SDYUYf2RLfgNvP Next: 96brSitdNSyt7z9KfeL7B4ozCJ7izocQV9moMomD41NT Diff:
Old | New | Differences | |
---|---|---|---|
16 | 16 | ||
17 | 17 | ||
18 | 18 | func payoutCaller (target,caller,payout) = ScriptResult(WriteSet([DataEntry(((("long_" + toString(target)) + "_") + toString(caller)), 0), DataEntry(((("short_" + toString(target)) + "_") + toString(caller)), 0)]), TransferSet([ScriptTransfer(caller, payout, unit)])) | |
19 | + | ||
20 | + | ||
21 | + | func getPriceAtHeight (height) = { | |
22 | + | let currentPriceAtHeight = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(height))) | |
23 | + | currentPriceAtHeight | |
24 | + | } | |
25 | + | ||
26 | + | ||
27 | + | func comparePriceAtHeight (result,step) = { | |
28 | + | let priceAtHeight = getPriceAtHeight((height - step)) | |
29 | + | if ((priceAtHeight != 0)) | |
30 | + | then priceAtHeight | |
31 | + | else 0 | |
32 | + | } | |
33 | + | ||
34 | + | ||
35 | + | func getClosestPrice (height) = { | |
36 | + | let steps = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
37 | + | let closestPrice = { | |
38 | + | let $list11841223 = steps | |
39 | + | let $size11841223 = size($list11841223) | |
40 | + | let $acc011841223 = 0 | |
41 | + | if (($size11841223 == 0)) | |
42 | + | then $acc011841223 | |
43 | + | else { | |
44 | + | let $acc111841223 = comparePriceAtHeight($acc011841223, $list11841223[0]) | |
45 | + | if (($size11841223 == 1)) | |
46 | + | then $acc111841223 | |
47 | + | else { | |
48 | + | let $acc211841223 = comparePriceAtHeight($acc111841223, $list11841223[1]) | |
49 | + | if (($size11841223 == 2)) | |
50 | + | then $acc211841223 | |
51 | + | else { | |
52 | + | let $acc311841223 = comparePriceAtHeight($acc211841223, $list11841223[2]) | |
53 | + | if (($size11841223 == 3)) | |
54 | + | then $acc311841223 | |
55 | + | else { | |
56 | + | let $acc411841223 = comparePriceAtHeight($acc311841223, $list11841223[3]) | |
57 | + | if (($size11841223 == 4)) | |
58 | + | then $acc411841223 | |
59 | + | else { | |
60 | + | let $acc511841223 = comparePriceAtHeight($acc411841223, $list11841223[4]) | |
61 | + | if (($size11841223 == 5)) | |
62 | + | then $acc511841223 | |
63 | + | else { | |
64 | + | let $acc611841223 = comparePriceAtHeight($acc511841223, $list11841223[5]) | |
65 | + | throw("List size exceed 5") | |
66 | + | } | |
67 | + | } | |
68 | + | } | |
69 | + | } | |
70 | + | } | |
71 | + | } | |
72 | + | } | |
73 | + | closestPrice | |
74 | + | } | |
19 | 75 | ||
20 | 76 | ||
21 | 77 | @Callable(i) | |
56 | 112 | @Callable(i) | |
57 | 113 | func initiate (target) = { | |
58 | 114 | let currentPrice = getIntegerValue(addressFromStringValue(PRICEORACLE), "price") | |
115 | + | let initiated = match getInteger(this, ("target_price_" + toString(target))) { | |
116 | + | case x: Int => | |
117 | + | (x != 0) | |
118 | + | case _: Unit => | |
119 | + | false | |
120 | + | case _ => | |
121 | + | throw("Match error") | |
122 | + | } | |
59 | 123 | if (((height + RECOVERYPHASE) >= target)) | |
60 | 124 | then throw(("No new future instantiable for the given height: " + toString(target))) | |
61 | - | else WriteSet([DataEntry(("target_price_" + toString(target)), currentPrice), DataEntry(("shorts_total_" + toString(target)), 0), DataEntry(("longs_total_" + toString(target)), 0)]) | |
125 | + | else if (initiated) | |
126 | + | then throw("Target already initiated!") | |
127 | + | else WriteSet([DataEntry(("target_price_" + toString(target)), currentPrice), DataEntry(("shorts_total_" + toString(target)), 0), DataEntry(("longs_total_" + toString(target)), 0)]) | |
62 | 128 | } | |
63 | 129 | ||
64 | 130 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let RECOVERYPHASE = 100 | |
5 | 5 | ||
6 | 6 | let PRICEORACLE = "3N4NS7d4Jo9a6F14LiFUKKYVdUkkf2eP4Zx" | |
7 | 7 | ||
8 | 8 | func getDataEntryForKey (key) = match getInteger(this, key) { | |
9 | 9 | case x: Int => | |
10 | 10 | x | |
11 | 11 | case _: Unit => | |
12 | 12 | 0 | |
13 | 13 | case _ => | |
14 | 14 | throw("Match error") | |
15 | 15 | } | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func payoutCaller (target,caller,payout) = ScriptResult(WriteSet([DataEntry(((("long_" + toString(target)) + "_") + toString(caller)), 0), DataEntry(((("short_" + toString(target)) + "_") + toString(caller)), 0)]), TransferSet([ScriptTransfer(caller, payout, unit)])) | |
19 | + | ||
20 | + | ||
21 | + | func getPriceAtHeight (height) = { | |
22 | + | let currentPriceAtHeight = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(height))) | |
23 | + | currentPriceAtHeight | |
24 | + | } | |
25 | + | ||
26 | + | ||
27 | + | func comparePriceAtHeight (result,step) = { | |
28 | + | let priceAtHeight = getPriceAtHeight((height - step)) | |
29 | + | if ((priceAtHeight != 0)) | |
30 | + | then priceAtHeight | |
31 | + | else 0 | |
32 | + | } | |
33 | + | ||
34 | + | ||
35 | + | func getClosestPrice (height) = { | |
36 | + | let steps = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
37 | + | let closestPrice = { | |
38 | + | let $list11841223 = steps | |
39 | + | let $size11841223 = size($list11841223) | |
40 | + | let $acc011841223 = 0 | |
41 | + | if (($size11841223 == 0)) | |
42 | + | then $acc011841223 | |
43 | + | else { | |
44 | + | let $acc111841223 = comparePriceAtHeight($acc011841223, $list11841223[0]) | |
45 | + | if (($size11841223 == 1)) | |
46 | + | then $acc111841223 | |
47 | + | else { | |
48 | + | let $acc211841223 = comparePriceAtHeight($acc111841223, $list11841223[1]) | |
49 | + | if (($size11841223 == 2)) | |
50 | + | then $acc211841223 | |
51 | + | else { | |
52 | + | let $acc311841223 = comparePriceAtHeight($acc211841223, $list11841223[2]) | |
53 | + | if (($size11841223 == 3)) | |
54 | + | then $acc311841223 | |
55 | + | else { | |
56 | + | let $acc411841223 = comparePriceAtHeight($acc311841223, $list11841223[3]) | |
57 | + | if (($size11841223 == 4)) | |
58 | + | then $acc411841223 | |
59 | + | else { | |
60 | + | let $acc511841223 = comparePriceAtHeight($acc411841223, $list11841223[4]) | |
61 | + | if (($size11841223 == 5)) | |
62 | + | then $acc511841223 | |
63 | + | else { | |
64 | + | let $acc611841223 = comparePriceAtHeight($acc511841223, $list11841223[5]) | |
65 | + | throw("List size exceed 5") | |
66 | + | } | |
67 | + | } | |
68 | + | } | |
69 | + | } | |
70 | + | } | |
71 | + | } | |
72 | + | } | |
73 | + | closestPrice | |
74 | + | } | |
19 | 75 | ||
20 | 76 | ||
21 | 77 | @Callable(i) | |
22 | 78 | func withdraw (target) = if (((target + 1) > height)) | |
23 | 79 | then throw("End of predictions for this height not reached yet!") | |
24 | 80 | else { | |
25 | 81 | let priceAtTarget = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(target))) | |
26 | 82 | if ((priceAtTarget == 0)) | |
27 | 83 | then throw("Could not determine price at target height!") | |
28 | 84 | else { | |
29 | 85 | let caller = i.caller | |
30 | 86 | let targetPrice = getIntegerValue(this, ("target_price_" + toString(target))) | |
31 | 87 | let totalLongs = getDataEntryForKey(("longs_total_" + toString(target))) | |
32 | 88 | let totalShorts = getDataEntryForKey(("shorts_total_" + toString(target))) | |
33 | 89 | if ((priceAtTarget > targetPrice)) | |
34 | 90 | then { | |
35 | 91 | let precept = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller))) | |
36 | 92 | let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts)) | |
37 | 93 | payoutCaller(target, caller, payout) | |
38 | 94 | } | |
39 | 95 | else if ((targetPrice > priceAtTarget)) | |
40 | 96 | then { | |
41 | 97 | let precept = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller))) | |
42 | 98 | let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts)) | |
43 | 99 | payoutCaller(target, caller, payout) | |
44 | 100 | } | |
45 | 101 | else { | |
46 | 102 | let preceptLong = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller))) | |
47 | 103 | let preceptShort = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller))) | |
48 | 104 | let payout = (((preceptLong / totalLongs) * totalLongs) + ((preceptShort / totalShorts) * totalShorts)) | |
49 | 105 | payoutCaller(target, caller, payout) | |
50 | 106 | } | |
51 | 107 | } | |
52 | 108 | } | |
53 | 109 | ||
54 | 110 | ||
55 | 111 | ||
56 | 112 | @Callable(i) | |
57 | 113 | func initiate (target) = { | |
58 | 114 | let currentPrice = getIntegerValue(addressFromStringValue(PRICEORACLE), "price") | |
115 | + | let initiated = match getInteger(this, ("target_price_" + toString(target))) { | |
116 | + | case x: Int => | |
117 | + | (x != 0) | |
118 | + | case _: Unit => | |
119 | + | false | |
120 | + | case _ => | |
121 | + | throw("Match error") | |
122 | + | } | |
59 | 123 | if (((height + RECOVERYPHASE) >= target)) | |
60 | 124 | then throw(("No new future instantiable for the given height: " + toString(target))) | |
61 | - | else WriteSet([DataEntry(("target_price_" + toString(target)), currentPrice), DataEntry(("shorts_total_" + toString(target)), 0), DataEntry(("longs_total_" + toString(target)), 0)]) | |
125 | + | else if (initiated) | |
126 | + | then throw("Target already initiated!") | |
127 | + | else WriteSet([DataEntry(("target_price_" + toString(target)), currentPrice), DataEntry(("shorts_total_" + toString(target)), 0), DataEntry(("longs_total_" + toString(target)), 0)]) | |
62 | 128 | } | |
63 | 129 | ||
64 | 130 | ||
65 | 131 | ||
66 | 132 | @Callable(i) | |
67 | 133 | func short (shortTarget) = { | |
68 | 134 | let targetPrice = getDataEntryForKey(("target_price_" + toString(shortTarget))) | |
69 | 135 | if ((targetPrice == 0)) | |
70 | 136 | then throw("Target not initialized!") | |
71 | 137 | else { | |
72 | 138 | let caller = toString(i.caller) | |
73 | 139 | let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller) | |
74 | 140 | let shortsTotalKey = ("shorts_total_" + toString(shortTarget)) | |
75 | 141 | let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey) | |
76 | 142 | let currentShorts = getDataEntryForKey(shortsTotalKey) | |
77 | 143 | let payment = extract(i.payment) | |
78 | 144 | let amount = payment.amount | |
79 | 145 | if (isDefined(payment.assetId)) | |
80 | 146 | then throw("Only Waves payments allowed currently!") | |
81 | 147 | else if (((height + RECOVERYPHASE) >= shortTarget)) | |
82 | 148 | then throw("Recovery phase active. You can no longer go short towards this short target / height!") | |
83 | 149 | else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))]) | |
84 | 150 | } | |
85 | 151 | } | |
86 | 152 | ||
87 | 153 | ||
88 | 154 | ||
89 | 155 | @Callable(i) | |
90 | 156 | func long (longTarget) = { | |
91 | 157 | let targetPrice = getDataEntryForKey(("target_price_" + toString(longTarget))) | |
92 | 158 | if ((targetPrice == 0)) | |
93 | 159 | then throw("Target not initialized!") | |
94 | 160 | else { | |
95 | 161 | let caller = toString(i.caller) | |
96 | 162 | let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller) | |
97 | 163 | let longsTotalKey = ("longs_total_" + toString(longTarget)) | |
98 | 164 | let currentLongAmountForAddress = getDataEntryForKey(longAddressKey) | |
99 | 165 | let currentLongs = getDataEntryForKey(longsTotalKey) | |
100 | 166 | let payment = extract(i.payment) | |
101 | 167 | let amount = payment.amount | |
102 | 168 | if (isDefined(payment.assetId)) | |
103 | 169 | then throw("Only Waves payments allowed currently!") | |
104 | 170 | else if (((height + RECOVERYPHASE) >= longTarget)) | |
105 | 171 | then throw("Recovery phase active. You can no longer go long towards this long target / height!") | |
106 | 172 | else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))]) | |
107 | 173 | } | |
108 | 174 | } | |
109 | 175 | ||
110 | 176 |
github/deemru/w8io/169f3d6 34.96 ms ◑