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:AAIDAAAAAAAAABYIARIDCgEBEgMKAQESAwoBARIDCgEBAAAABwAAAAANUkVDT1ZFUllQSEFTRQAAAAAAAAAAZAAAAAALUFJJQ0VPUkFDTEUCAAAAIzNONE5TN2Q0Sm85YTZGMTRMaUZVS0tZVmRVa2tmMmVQNFp4AQAAABJnZXREYXRhRW50cnlGb3JLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABeAUAAAAHJG1hdGNoMAUAAAABeAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAEVW5pdAAAAAAAAAAAAAkAAAIAAAABAgAAAAtNYXRjaCBlcnJvcgEAAAAMcGF5b3V0Q2FsbGVyAAAAAwAAAAZ0YXJnZXQAAAAGY2FsbGVyAAAABnBheW91dAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgkAASwAAAACCQABLAA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ZXJ5IHBoYXNlIGFjdGl2ZS4gWW91IGNhbiBubyBsb25nZXIgZ28gbG9uZyB0b3dhcmRzIHRoaXMgbG9uZyB0YXJnZXQgLyBoZWlnaHQhCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACBQAAAA5sb25nQWRkcmVzc0tleQkAAGQAAAACBQAAABtjdXJyZW50TG9uZ0Ftb3VudEZvckFkZHJlc3MFAAAABmFtb3VudAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAANbG9uZ3NUb3RhbEtleQkAAGQAAAACBQAAAAxjdXJyZW50TG9uZ3MFAAAABmFtb3VudAUAAAADbmlsAAAAADJaJew=", "height": 1328605, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5ufjCRb8mag4i6s7bRHKrZguwfyGD1SDYUYf2RLfgNvP Next: 96brSitdNSyt7z9KfeL7B4ozCJ7izocQV9moMomD41NT Diff:
OldNewDifferences
1616
1717
1818 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+ }
1975
2076
2177 @Callable(i)
56112 @Callable(i)
57113 func initiate (target) = {
58114 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+ }
59123 if (((height + RECOVERYPHASE) >= target))
60124 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)])
62128 }
63129
64130
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let RECOVERYPHASE = 100
55
66 let PRICEORACLE = "3N4NS7d4Jo9a6F14LiFUKKYVdUkkf2eP4Zx"
77
88 func getDataEntryForKey (key) = match getInteger(this, key) {
99 case x: Int =>
1010 x
1111 case _: Unit =>
1212 0
1313 case _ =>
1414 throw("Match error")
1515 }
1616
1717
1818 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+ }
1975
2076
2177 @Callable(i)
2278 func withdraw (target) = if (((target + 1) > height))
2379 then throw("End of predictions for this height not reached yet!")
2480 else {
2581 let priceAtTarget = getIntegerValue(addressFromStringValue(PRICEORACLE), ("price_" + toString(target)))
2682 if ((priceAtTarget == 0))
2783 then throw("Could not determine price at target height!")
2884 else {
2985 let caller = i.caller
3086 let targetPrice = getIntegerValue(this, ("target_price_" + toString(target)))
3187 let totalLongs = getDataEntryForKey(("longs_total_" + toString(target)))
3288 let totalShorts = getDataEntryForKey(("shorts_total_" + toString(target)))
3389 if ((priceAtTarget > targetPrice))
3490 then {
3591 let precept = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
3692 let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
3793 payoutCaller(target, caller, payout)
3894 }
3995 else if ((targetPrice > priceAtTarget))
4096 then {
4197 let precept = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
4298 let payout = ((precept / (totalLongs + totalShorts)) * (totalLongs + totalShorts))
4399 payoutCaller(target, caller, payout)
44100 }
45101 else {
46102 let preceptLong = getDataEntryForKey(((("long_" + toString(target)) + "_") + toString(caller)))
47103 let preceptShort = getDataEntryForKey(((("short_" + toString(target)) + "_") + toString(caller)))
48104 let payout = (((preceptLong / totalLongs) * totalLongs) + ((preceptShort / totalShorts) * totalShorts))
49105 payoutCaller(target, caller, payout)
50106 }
51107 }
52108 }
53109
54110
55111
56112 @Callable(i)
57113 func initiate (target) = {
58114 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+ }
59123 if (((height + RECOVERYPHASE) >= target))
60124 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)])
62128 }
63129
64130
65131
66132 @Callable(i)
67133 func short (shortTarget) = {
68134 let targetPrice = getDataEntryForKey(("target_price_" + toString(shortTarget)))
69135 if ((targetPrice == 0))
70136 then throw("Target not initialized!")
71137 else {
72138 let caller = toString(i.caller)
73139 let shortAddressKey = ((("short_" + toString(shortTarget)) + "_") + caller)
74140 let shortsTotalKey = ("shorts_total_" + toString(shortTarget))
75141 let currentShortAmountForAddress = getDataEntryForKey(shortAddressKey)
76142 let currentShorts = getDataEntryForKey(shortsTotalKey)
77143 let payment = extract(i.payment)
78144 let amount = payment.amount
79145 if (isDefined(payment.assetId))
80146 then throw("Only Waves payments allowed currently!")
81147 else if (((height + RECOVERYPHASE) >= shortTarget))
82148 then throw("Recovery phase active. You can no longer go short towards this short target / height!")
83149 else WriteSet([DataEntry(shortAddressKey, (currentShortAmountForAddress + amount)), DataEntry(shortsTotalKey, (currentShorts + amount))])
84150 }
85151 }
86152
87153
88154
89155 @Callable(i)
90156 func long (longTarget) = {
91157 let targetPrice = getDataEntryForKey(("target_price_" + toString(longTarget)))
92158 if ((targetPrice == 0))
93159 then throw("Target not initialized!")
94160 else {
95161 let caller = toString(i.caller)
96162 let longAddressKey = ((("long_" + toString(longTarget)) + "_") + caller)
97163 let longsTotalKey = ("longs_total_" + toString(longTarget))
98164 let currentLongAmountForAddress = getDataEntryForKey(longAddressKey)
99165 let currentLongs = getDataEntryForKey(longsTotalKey)
100166 let payment = extract(i.payment)
101167 let amount = payment.amount
102168 if (isDefined(payment.assetId))
103169 then throw("Only Waves payments allowed currently!")
104170 else if (((height + RECOVERYPHASE) >= longTarget))
105171 then throw("Recovery phase active. You can no longer go long towards this long target / height!")
106172 else WriteSet([DataEntry(longAddressKey, (currentLongAmountForAddress + amount)), DataEntry(longsTotalKey, (currentLongs + amount))])
107173 }
108174 }
109175
110176

github/deemru/w8io/169f3d6 
34.96 ms